From 437a3b366ada3d0a1a09ce5b553518792303e815 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 6 Oct 2016 09:36:54 -0700 Subject: [PATCH 001/261] make ruby tools use x86 directory names for sub-x86 cpu --- src/ruby/tools/bin/grpc_tools_ruby_protoc | 4 +- .../tools/bin/grpc_tools_ruby_protoc_plugin | 3 +- src/ruby/tools/cpu_check.rb | 43 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 src/ruby/tools/cpu_check.rb diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc b/src/ruby/tools/bin/grpc_tools_ruby_protoc index dab06e7958d..723842bf1e6 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc @@ -31,6 +31,7 @@ require 'rbconfig' require_relative '../os_check' +require_relative '../cpu_check' ext = RbConfig::CONFIG['EXEEXT'] @@ -38,8 +39,7 @@ protoc_name = 'protoc' + ext plugin_name = 'grpc_ruby_plugin' + ext -protoc_dir = File.join(File.dirname(__FILE__), - RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name) +protoc_dir = File.join(File.dirname(__FILE__), CPU.arch + '-' + OS.os_name) protoc_path = File.join(protoc_dir, protoc_name) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin index 4b296dedc75..773281fa8e6 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin @@ -31,11 +31,12 @@ require 'rbconfig' require_relative '../os_check' +require_relative '../cpu_check' plugin_name = 'grpc_ruby_plugin' + RbConfig::CONFIG['EXEEXT'] plugin_path = File.join(File.dirname(__FILE__), - RbConfig::CONFIG['host_cpu'] + '-' + OS.os_name, + CPU.arch + '-' + OS.os_name, plugin_name) exec([ plugin_path, plugin_path ], *ARGV) diff --git a/src/ruby/tools/cpu_check.rb b/src/ruby/tools/cpu_check.rb new file mode 100644 index 00000000000..9e281242226 --- /dev/null +++ b/src/ruby/tools/cpu_check.rb @@ -0,0 +1,43 @@ +# 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. + +require 'rbconfig' + +module CPU + def CPU.arch + case RbConfig::CONFIG['host_cpu'] + when /x86_64/ + 'x86_64' + when /x86|i686/ + 'x86' + else + fail 'cpu architecture detection failed' + end + end +end From 8d970ea2b6411d4bcf01d175cf9a2628b0dd3338 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 6 Oct 2016 09:55:16 -0700 Subject: [PATCH 002/261] merge os_check and cpu_check into platform_check --- src/ruby/tools/bin/grpc_tools_ruby_protoc | 6 +-- .../tools/bin/grpc_tools_ruby_protoc_plugin | 5 +-- src/ruby/tools/os_check.rb | 45 ------------------- .../tools/{cpu_check.rb => platform_check.rb} | 16 ++++++- 4 files changed, 19 insertions(+), 53 deletions(-) delete mode 100644 src/ruby/tools/os_check.rb rename src/ruby/tools/{cpu_check.rb => platform_check.rb} (84%) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc b/src/ruby/tools/bin/grpc_tools_ruby_protoc index 723842bf1e6..7e619e74a96 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc @@ -30,8 +30,7 @@ require 'rbconfig' -require_relative '../os_check' -require_relative '../cpu_check' +require_relative '../platform_check' ext = RbConfig::CONFIG['EXEEXT'] @@ -39,7 +38,8 @@ protoc_name = 'protoc' + ext plugin_name = 'grpc_ruby_plugin' + ext -protoc_dir = File.join(File.dirname(__FILE__), CPU.arch + '-' + OS.os_name) +protoc_dir = File.join(File.dirname(__FILE__), + PLATFORM.architecture + '-' + PLATFORM.os_name) protoc_path = File.join(protoc_dir, protoc_name) diff --git a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin index 773281fa8e6..e6af2fe3651 100755 --- a/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin +++ b/src/ruby/tools/bin/grpc_tools_ruby_protoc_plugin @@ -30,13 +30,12 @@ require 'rbconfig' -require_relative '../os_check' -require_relative '../cpu_check' +require_relative '../platform_check' plugin_name = 'grpc_ruby_plugin' + RbConfig::CONFIG['EXEEXT'] plugin_path = File.join(File.dirname(__FILE__), - CPU.arch + '-' + OS.os_name, + PLATFORM.architecture + '-' + PLATFORM.os_name, plugin_name) exec([ plugin_path, plugin_path ], *ARGV) diff --git a/src/ruby/tools/os_check.rb b/src/ruby/tools/os_check.rb deleted file mode 100644 index 2677306457b..00000000000 --- a/src/ruby/tools/os_check.rb +++ /dev/null @@ -1,45 +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. - -# This is based on http://stackoverflow.com/a/171011/159388 by Aaron Hinni - -require 'rbconfig' - -module OS - def OS.os_name - case RbConfig::CONFIG['host_os'] - when /cygwin|mswin|mingw|bccwin|wince|emx/ - 'windows' - when /darwin/ - 'macos' - else - 'linux' - end - end -end diff --git a/src/ruby/tools/cpu_check.rb b/src/ruby/tools/platform_check.rb similarity index 84% rename from src/ruby/tools/cpu_check.rb rename to src/ruby/tools/platform_check.rb index 9e281242226..e891ec23a81 100644 --- a/src/ruby/tools/cpu_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -29,8 +29,20 @@ require 'rbconfig' -module CPU - def CPU.arch +# This is based on http://stackoverflow.com/a/171011/159388 by Aaron Hinni + +module PLATFORM + def PLATFORM.os_name + case RbConfig::CONFIG['host_os'] + when /cygwin|mswin|mingw|bccwin|wince|emx/ + 'windows' + when /darwin/ + 'macos' + else + 'linux' + end + end + def PLATFORM.architecture case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' From fb4509bd73fde1525b07c74b2446c1c365e4f26c Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 14:36:20 -0700 Subject: [PATCH 003/261] add i386 to recognized x86 cpu in ruby tools package --- src/ruby/tools/platform_check.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index e891ec23a81..c058deb5f5c 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -46,7 +46,7 @@ module PLATFORM case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i686/ + when /x86|i686|i386/ 'x86' else fail 'cpu architecture detection failed' From 9d45c051e7b7770dd1a799de3ac32eb4fba1f79a Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 15:56:39 -0700 Subject: [PATCH 004/261] enumerate more x86 cpus in ruby tools package --- src/ruby/tools/platform_check.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index c058deb5f5c..19ea2a07fc1 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -42,11 +42,15 @@ module PLATFORM 'linux' end end + + # The 'host_cpu' value on x86, 32-bit rubies, appears to turn out to + # be the name of the cpu. Only need to know the architecture, + # so enumerating x86 cpu's here. def PLATFORM.architecture case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i686|i386/ + when /x86|i386|i486|i586|i686|i786/ 'x86' else fail 'cpu architecture detection failed' From 0da964435445bcddcb1fecf55283bcf7e347a509 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 12 Oct 2016 16:32:46 -0700 Subject: [PATCH 005/261] use target cpu to get rid of cpu enumerations --- src/ruby/tools/platform_check.rb | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index 19ea2a07fc1..2c5ccffdda6 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -43,14 +43,11 @@ module PLATFORM end end - # The 'host_cpu' value on x86, 32-bit rubies, appears to turn out to - # be the name of the cpu. Only need to know the architecture, - # so enumerating x86 cpu's here. def PLATFORM.architecture - case RbConfig::CONFIG['host_cpu'] + case RbConfig::CONFIG['target_cpu'] when /x86_64/ 'x86_64' - when /x86|i386|i486|i586|i686|i786/ + when /x86|i386/ 'x86' else fail 'cpu architecture detection failed' From bd39e23f112e38c0a060ce5dba3d56d78401e77d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 9 Nov 2016 16:28:50 -0800 Subject: [PATCH 006/261] Start slice interning --- include/grpc/slice.h | 6 ++ src/core/lib/slice/slice.c | 4 + src/core/lib/slice/slice_intern.c | 131 ++++++++++++++++++++++++++++ src/core/lib/slice/slice_internal.h | 3 + src/core/lib/surface/init.c | 3 + 5 files changed, 147 insertions(+) create mode 100644 src/core/lib/slice/slice_intern.c diff --git a/include/grpc/slice.h b/include/grpc/slice.h index ee0bb4928e1..50d6caf2c85 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -76,6 +76,12 @@ GPRAPI grpc_slice grpc_slice_new_with_len(void *p, size_t len, Aborts if malloc() fails. */ GPRAPI grpc_slice grpc_slice_malloc(size_t length); +/* Intern a slice: + + The return value for two invocations of this function with the same sequence + of bytes is a slice which points to the same memory */ +GPRAPI grpc_slice grpc_slice_intern(grpc_slice slice); + /* Create a slice by copying a string. Does not preserve null terminators. Equivalent to: diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 5b8f71a778e..6da0952e27b 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -352,6 +352,10 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { } int grpc_slice_cmp(grpc_slice a, grpc_slice b) { + if (GRPC_SLICE_START_PTR(a) == GRPC_SLICE_START_PTR(b) && + GRPC_SLICE_LENGTH(a) == GRPC_SLICE_LENGTH(b)) { + return 0; + } int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c new file mode 100644 index 00000000000..a5fd1e3dfb1 --- /dev/null +++ b/src/core/lib/slice/slice_intern.c @@ -0,0 +1,131 @@ +/* + * + * 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. + * + */ + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/transport/static_metadata.h" + +#define LOG2_SHARD_COUNT 5 +#define SHARD_COUNT (1 << LOG2_SHARD_COUNT) + +#define TABLE_IDX(hash, capacity) (((hash) >> LOG2_SHARD_COUNT) % (capacity)) +#define SHARD_IDX(hash) ((hash) & ((1 << LOG2_SHARD_COUNT) - 1)) + +typedef struct interned_slice_refcount { + grpc_slice_refcount base; + uint32_t hash; + gpr_atm refcnt; + struct interned_slice_refcount *bucket_next; + grpc_slice_refcount *source_refcount; +} interned_slice_refcount; + +typedef struct slice_shard { + gpr_mu mu; + interned_slice_refcount **strs; + size_t count; + size_t capacity; +} slice_shard; + +#define REFCOUNT_TO_SLICE(rc) (*(grpc_slice *)((rc) + 1)) + +/* hash seed: decided at initialization time */ +static uint32_t g_hash_seed; +static int g_forced_hash_seed = 0; + +static slice_shard g_shards[SHARD_COUNT]; + +/* linearly probed hash tables for static string lookup */ +static grpc_slice g_static_slices[GRPC_STATIC_MDSTR_COUNT * 2]; + +grpc_slice grpc_slice_intern(grpc_slice slice) { + uint32_t hash = + gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); + slice_shard *shard = &g_shards[SHARD_IDX(hash)]; + + gpr_mu_lock(&shard->mu); + + /* search for an existing string */ + size_t idx = TABLE_IDX(hash, shard->capacity); + for (interned_slice_refcount *s = shard->strs[idx]; s; s = s->bucket_next) { + if (s->hash == hash && grpc_slice_cmp(slice, REFCOUNT_TO_SLICE(s))) { + if (gpr_atm_full_fetch_add(&s->refcnt, 1) == 0) { + /* If we get here, we've added a ref to something that was about to + * die - drop it immediately. + * The *only* possible path here (given the shard mutex) should be to + * drop from one ref back to zero - assert that with a CAS */ + GPR_ASSERT(gpr_atm_rel_cas(&s->refcnt, 1, 0)); + /* and treat this as if we were never here... sshhh */ + } else { + gpr_mu_unlock(&shard->mu); + GPR_TIMER_END("grpc_mdstr_from_buffer", 0); + return REFCOUNT_TO_SLICE(s); + } + } + } + + /* not found: create a new string */ + if (length + 1 < GRPC_SLICE_INLINED_SIZE) { + /* string data goes directly into the slice */ + s = gpr_malloc(sizeof(internal_string)); + gpr_atm_rel_store(&s->refcnt, 1); + s->slice.refcount = NULL; + memcpy(s->slice.data.inlined.bytes, buf, length); + s->slice.data.inlined.bytes[length] = 0; + s->slice.data.inlined.length = (uint8_t)length; + } else { + /* string data goes after the internal_string header, and we +1 for null + terminator */ + s = gpr_malloc(sizeof(internal_string) + length + 1); + gpr_atm_rel_store(&s->refcnt, 1); + s->refcount.ref = slice_ref; + s->refcount.unref = slice_unref; + s->slice.refcount = &s->refcount; + s->slice.data.refcounted.bytes = (uint8_t *)(s + 1); + s->slice.data.refcounted.length = length; + memcpy(s->slice.data.refcounted.bytes, buf, length); + /* add a null terminator for cheap c string conversion when desired */ + s->slice.data.refcounted.bytes[length] = 0; + } + s->has_base64_and_huffman_encoded = 0; + s->hash = hash; + s->size_in_decoder_table = SIZE_IN_DECODER_TABLE_NOT_SET; + s->bucket_next = shard->strs[idx]; + shard->strs[idx] = s; + + shard->count++; + + if (shard->count > shard->capacity * 2) { + grow_strtab(shard); + } + + gpr_mu_unlock(&shard->mu); +} diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 72b0a590bbd..3917bcf403a 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -46,4 +46,7 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *sb); +void grpc_slice_intern_init(void); +void grpc_slice_intern_shutdown(void); + #endif diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c index d3b602cf2a8..bce6528acd8 100644 --- a/src/core/lib/surface/init.c +++ b/src/core/lib/surface/init.c @@ -54,6 +54,7 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/resource_quota.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel_init.h" @@ -177,6 +178,7 @@ void grpc_init(void) { gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); + grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); grpc_register_tracer("api", &grpc_api_trace); @@ -238,6 +240,7 @@ void grpc_shutdown(void) { } } grpc_mdctx_global_shutdown(&exec_ctx); + grpc_slice_intern_shutdown(&exec_ctx); } gpr_mu_unlock(&g_init_mu); grpc_exec_ctx_finish(&exec_ctx); From 8268155cf11aee5d62a32915fe213b0e1c294d89 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Nov 2016 08:21:19 -0800 Subject: [PATCH 007/261] Initial cut of slice interning --- include/grpc/slice.h | 2 +- src/core/lib/slice/slice_intern.c | 169 +++++++++++++++++----- src/core/lib/slice/slice_internal.h | 1 + src/core/lib/slice/slice_string_helpers.h | 2 + 4 files changed, 137 insertions(+), 37 deletions(-) diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 50d6caf2c85..b5894a103c1 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -79,7 +79,7 @@ GPRAPI grpc_slice grpc_slice_malloc(size_t length); /* Intern a slice: The return value for two invocations of this function with the same sequence - of bytes is a slice which points to the same memory */ + of bytes is a slice which points to the same memory. */ GPRAPI grpc_slice grpc_slice_intern(grpc_slice slice); /* Create a slice by copying a string. diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index a5fd1e3dfb1..45d76ff259a 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -32,20 +32,31 @@ */ #include "src/core/lib/slice/slice_internal.h" + +#include + +#include +#include + +#include "src/core/lib/iomgr/iomgr_internal.h" /* for iomgr_abort_on_leaks() */ +#include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/lib/support/murmur_hash.h" #include "src/core/lib/transport/static_metadata.h" #define LOG2_SHARD_COUNT 5 #define SHARD_COUNT (1 << LOG2_SHARD_COUNT) +#define INITIAL_SHARD_CAPACITY 8 #define TABLE_IDX(hash, capacity) (((hash) >> LOG2_SHARD_COUNT) % (capacity)) #define SHARD_IDX(hash) ((hash) & ((1 << LOG2_SHARD_COUNT) - 1)) typedef struct interned_slice_refcount { grpc_slice_refcount base; - uint32_t hash; + size_t length; gpr_atm refcnt; + uint32_t hash; struct interned_slice_refcount *bucket_next; - grpc_slice_refcount *source_refcount; } interned_slice_refcount; typedef struct slice_shard { @@ -55,29 +66,89 @@ typedef struct slice_shard { size_t capacity; } slice_shard; -#define REFCOUNT_TO_SLICE(rc) (*(grpc_slice *)((rc) + 1)) - /* hash seed: decided at initialization time */ static uint32_t g_hash_seed; static int g_forced_hash_seed = 0; static slice_shard g_shards[SHARD_COUNT]; -/* linearly probed hash tables for static string lookup */ -static grpc_slice g_static_slices[GRPC_STATIC_MDSTR_COUNT * 2]; +static void interned_slice_ref(void *p) { + interned_slice_refcount *s = p; + GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0); +} + +static void interned_slice_destroy(interned_slice_refcount *s) { + slice_shard *shard = &g_shards[SHARD_IDX(s->hash)]; + gpr_mu_lock(&shard->mu); + GPR_ASSERT(0 == gpr_atm_no_barrier_load(&s->refcnt)); + interned_slice_refcount **prev_next; + interned_slice_refcount *cur; + for (prev_next = &shard->strs[TABLE_IDX(s->hash, shard->capacity)], + cur = *prev_next; + cur != s; prev_next = &cur->bucket_next, cur = cur->bucket_next) + ; + *prev_next = cur->bucket_next; + shard->count--; + gpr_free(s); + gpr_mu_unlock(&shard->mu); +} + +static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { + interned_slice_refcount *s = p; + if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { + interned_slice_destroy(s); + } +} + +static void grow_shard(slice_shard *shard) { + size_t capacity = shard->capacity * 2; + size_t i; + interned_slice_refcount **strtab; + interned_slice_refcount *s, *next; + + GPR_TIMER_BEGIN("grow_strtab", 0); + + strtab = gpr_malloc(sizeof(interned_slice_refcount *) * capacity); + memset(strtab, 0, sizeof(interned_slice_refcount *) * capacity); + + for (i = 0; i < shard->capacity; i++) { + for (s = shard->strs[i]; s; s = next) { + size_t idx = TABLE_IDX(s->hash, capacity); + next = s->bucket_next; + s->bucket_next = strtab[idx]; + strtab[idx] = s; + } + } + + gpr_free(shard->strs); + shard->strs = strtab; + shard->capacity = capacity; + + GPR_TIMER_END("grow_strtab", 0); +} + +static grpc_slice materialize(interned_slice_refcount *s) { + grpc_slice slice; + slice.refcount = &s->base; + slice.data.refcounted.bytes = (uint8_t *)(s + 1); + slice.data.refcounted.length = s->length; + return slice; +} grpc_slice grpc_slice_intern(grpc_slice slice) { + interned_slice_refcount *s; uint32_t hash = - gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); + gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice), + g_forced_hash_seed); slice_shard *shard = &g_shards[SHARD_IDX(hash)]; gpr_mu_lock(&shard->mu); /* search for an existing string */ size_t idx = TABLE_IDX(hash, shard->capacity); - for (interned_slice_refcount *s = shard->strs[idx]; s; s = s->bucket_next) { - if (s->hash == hash && grpc_slice_cmp(slice, REFCOUNT_TO_SLICE(s))) { - if (gpr_atm_full_fetch_add(&s->refcnt, 1) == 0) { + for (s = shard->strs[idx]; s; s = s->bucket_next) { + if (s->hash == hash && grpc_slice_cmp(slice, materialize(s))) { + if (gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) == 0) { /* If we get here, we've added a ref to something that was about to * die - drop it immediately. * The *only* possible path here (given the shard mutex) should be to @@ -87,45 +158,71 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { } else { gpr_mu_unlock(&shard->mu); GPR_TIMER_END("grpc_mdstr_from_buffer", 0); - return REFCOUNT_TO_SLICE(s); + return materialize(s); } } } /* not found: create a new string */ - if (length + 1 < GRPC_SLICE_INLINED_SIZE) { - /* string data goes directly into the slice */ - s = gpr_malloc(sizeof(internal_string)); - gpr_atm_rel_store(&s->refcnt, 1); - s->slice.refcount = NULL; - memcpy(s->slice.data.inlined.bytes, buf, length); - s->slice.data.inlined.bytes[length] = 0; - s->slice.data.inlined.length = (uint8_t)length; - } else { - /* string data goes after the internal_string header, and we +1 for null - terminator */ - s = gpr_malloc(sizeof(internal_string) + length + 1); - gpr_atm_rel_store(&s->refcnt, 1); - s->refcount.ref = slice_ref; - s->refcount.unref = slice_unref; - s->slice.refcount = &s->refcount; - s->slice.data.refcounted.bytes = (uint8_t *)(s + 1); - s->slice.data.refcounted.length = length; - memcpy(s->slice.data.refcounted.bytes, buf, length); - /* add a null terminator for cheap c string conversion when desired */ - s->slice.data.refcounted.bytes[length] = 0; - } - s->has_base64_and_huffman_encoded = 0; + /* string data goes after the internal_string header */ + s = gpr_malloc(sizeof(*s) + GRPC_SLICE_LENGTH(slice)); + gpr_atm_rel_store(&s->refcnt, 1); + s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; - s->size_in_decoder_table = SIZE_IN_DECODER_TABLE_NOT_SET; + s->base.ref = interned_slice_ref; + s->base.unref = interned_slice_unref; s->bucket_next = shard->strs[idx]; shard->strs[idx] = s; + memcpy(s + 1, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); shard->count++; if (shard->count > shard->capacity * 2) { - grow_strtab(shard); + grow_shard(shard); } gpr_mu_unlock(&shard->mu); + + return materialize(s); +} + +void grpc_test_only_set_slice_interning_hash_seed(uint32_t seed) { + g_hash_seed = seed; + g_forced_hash_seed = 1; +} + +void grpc_slice_intern_init(void) { + for (size_t i = 0; i < SHARD_COUNT; i++) { + slice_shard *shard = &g_shards[i]; + gpr_mu_init(&shard->mu); + shard->count = 0; + shard->capacity = INITIAL_SHARD_CAPACITY; + shard->strs = gpr_malloc(sizeof(*shard->strs) * shard->capacity); + memset(shard->strs, 0, sizeof(*shard->strs) * shard->capacity); + } +} + +void grpc_slice_intern_shutdown(void) { + for (size_t i = 0; i < SHARD_COUNT; i++) { + slice_shard *shard = &g_shards[i]; + gpr_mu_destroy(&shard->mu); + /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ + if (shard->count != 0) { + gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata strings were leaked", + shard->count); + for (size_t j = 0; j < shard->capacity; j++) { + for (interned_slice_refcount *s = shard->strs[j]; s; + s = s->bucket_next) { + char *text = + grpc_dump_slice(materialize(s), GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "LEAKED: %s", text); + gpr_free(text); + } + } + if (grpc_iomgr_abort_on_leaks()) { + abort(); + } + } + gpr_free(shard->strs); + } } diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 3917bcf403a..a027a3979b7 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -48,5 +48,6 @@ void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); +void grpc_test_only_set_slice_interning_hash_seed(uint32_t key); #endif diff --git a/src/core/lib/slice/slice_string_helpers.h b/src/core/lib/slice/slice_string_helpers.h index 151c720777b..c6f4e87c7f5 100644 --- a/src/core/lib/slice/slice_string_helpers.h +++ b/src/core/lib/slice/slice_string_helpers.h @@ -40,6 +40,8 @@ #include #include +#include "src/core/lib/support/string.h" + #ifdef __cplusplus extern "C" { #endif From 64b26567ad9bf02aa149d0b31a5229fb2baaf44a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Nov 2016 08:31:42 -0800 Subject: [PATCH 008/261] First pass of slice interning facilities --- BUILD | 4 + CMakeLists.txt | 3 + Makefile | 8 +- binding.gyp | 1 + build.yaml | 1 + config.m4 | 1 + gRPC-Core.podspec | 1 + grpc.def | 1 + grpc.gemspec | 1 + package.xml | 1 + src/core/lib/slice/slice_intern.c | 7 +- src/core/lib/surface/init.c | 2 +- src/python/grpcio/grpc_core_dependencies.py | 1 + src/ruby/ext/grpc/rb_grpc_imports.generated.c | 2 + src/ruby/ext/grpc/rb_grpc_imports.generated.h | 3 + test/core/slice/slice_test.c | 22 + tools/doxygen/Doxyfile.core.internal | 1 + tools/run_tests/sources_and_headers.json | 3 + tools/run_tests/tests.json | 891 ++++++++++-------- vsprojects/vcxproj/grpc/grpc.vcxproj | 2 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 3 + .../grpc_test_util/grpc_test_util.vcxproj | 2 + .../grpc_test_util.vcxproj.filters | 3 + .../grpc_unsecure/grpc_unsecure.vcxproj | 2 + .../grpc_unsecure.vcxproj.filters | 3 + .../end2end_nosec_tests.vcxproj | 2 + .../end2end_nosec_tests.vcxproj.filters | 3 + .../tests/end2end_tests/end2end_tests.vcxproj | 2 + .../end2end_tests.vcxproj.filters | 3 + 29 files changed, 561 insertions(+), 418 deletions(-) diff --git a/BUILD b/BUILD index 894c7b2c6d5..738c0088b75 100644 --- a/BUILD +++ b/BUILD @@ -412,6 +412,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", "src/core/lib/surface/api_trace.c", @@ -831,6 +832,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", "src/core/lib/surface/api_trace.c", @@ -1212,6 +1214,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", "src/core/lib/surface/api_trace.c", @@ -2073,6 +2076,7 @@ objc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", "src/core/lib/surface/api_trace.c", diff --git a/CMakeLists.txt b/CMakeLists.txt index 98d54f21981..fc74e1a4d75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -367,6 +367,7 @@ add_library(grpc src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -646,6 +647,7 @@ add_library(grpc_cronet src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -897,6 +899,7 @@ add_library(grpc_unsecure src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c diff --git a/Makefile b/Makefile index 5b0dc44699d..c0b6b9373b8 100644 --- a/Makefile +++ b/Makefile @@ -2698,6 +2698,7 @@ LIBGRPC_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -2995,6 +2996,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -3283,6 +3285,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -3500,6 +3503,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -6970,6 +6974,7 @@ endif LIBEND2END_TESTS_SRC = \ test/core/end2end/end2end_tests.c \ test/core/end2end/end2end_test_utils.c \ + test/core/end2end/tests/authority_not_supported.c \ test/core/end2end/tests/bad_hostname.c \ test/core/end2end/tests/binary_metadata.c \ test/core/end2end/tests/call_creds.c \ @@ -7015,7 +7020,6 @@ LIBEND2END_TESTS_SRC = \ test/core/end2end/tests/simple_request.c \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ - test/core/end2end/tests/authority_not_supported.c \ PUBLIC_HEADERS_C += \ @@ -7056,6 +7060,7 @@ endif LIBEND2END_NOSEC_TESTS_SRC = \ test/core/end2end/end2end_nosec_tests.c \ test/core/end2end/end2end_test_utils.c \ + test/core/end2end/tests/authority_not_supported.c \ test/core/end2end/tests/bad_hostname.c \ test/core/end2end/tests/binary_metadata.c \ test/core/end2end/tests/cancel_after_accept.c \ @@ -7100,7 +7105,6 @@ LIBEND2END_NOSEC_TESTS_SRC = \ test/core/end2end/tests/simple_request.c \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ - test/core/end2end/tests/authority_not_supported.c \ PUBLIC_HEADERS_C += \ diff --git a/binding.gyp b/binding.gyp index ba90fcaa100..0cc776241a4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -647,6 +647,7 @@ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', diff --git a/build.yaml b/build.yaml index e8e5c4b5eed..d1d041c4270 100644 --- a/build.yaml +++ b/build.yaml @@ -343,6 +343,7 @@ filegroups: - src/core/lib/slice/percent_encoding.c - src/core/lib/slice/slice.c - src/core/lib/slice/slice_buffer.c + - src/core/lib/slice/slice_intern.c - src/core/lib/slice/slice_string_helpers.c - src/core/lib/surface/alarm.c - src/core/lib/surface/api_trace.c diff --git a/config.m4 b/config.m4 index 988cc5b0037..3c9b0982654 100644 --- a/config.m4 +++ b/config.m4 @@ -163,6 +163,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 8869bec32ee..d8b409499a5 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -505,6 +505,7 @@ Pod::Spec.new do |s| 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', diff --git a/grpc.def b/grpc.def index fcd32bf6d54..61bc173c600 100644 --- a/grpc.def +++ b/grpc.def @@ -141,6 +141,7 @@ EXPORTS grpc_slice_new_with_user_data grpc_slice_new_with_len grpc_slice_malloc + grpc_slice_intern grpc_slice_from_copied_string grpc_slice_from_copied_buffer grpc_slice_from_static_string diff --git a/grpc.gemspec b/grpc.gemspec index b071fccb827..8f7e18ef196 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -425,6 +425,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/slice/percent_encoding.c ) s.files += %w( src/core/lib/slice/slice.c ) s.files += %w( src/core/lib/slice/slice_buffer.c ) + s.files += %w( src/core/lib/slice/slice_intern.c ) s.files += %w( src/core/lib/slice/slice_string_helpers.c ) s.files += %w( src/core/lib/surface/alarm.c ) s.files += %w( src/core/lib/surface/api_trace.c ) diff --git a/package.xml b/package.xml index 348ad5f23c3..66bd0618991 100644 --- a/package.xml +++ b/package.xml @@ -432,6 +432,7 @@ + diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 45d76ff259a..8f48a361010 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -137,9 +137,8 @@ static grpc_slice materialize(interned_slice_refcount *s) { grpc_slice grpc_slice_intern(grpc_slice slice) { interned_slice_refcount *s; - uint32_t hash = - gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice), - g_forced_hash_seed); + uint32_t hash = gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_LENGTH(slice), g_hash_seed); slice_shard *shard = &g_shards[SHARD_IDX(hash)]; gpr_mu_lock(&shard->mu); @@ -147,7 +146,7 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { /* search for an existing string */ size_t idx = TABLE_IDX(hash, shard->capacity); for (s = shard->strs[idx]; s; s = s->bucket_next) { - if (s->hash == hash && grpc_slice_cmp(slice, materialize(s))) { + if (s->hash == hash && grpc_slice_cmp(slice, materialize(s)) == 0) { if (gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) == 0) { /* If we get here, we've added a ref to something that was about to * die - drop it immediately. diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c index bce6528acd8..5a8c77f0463 100644 --- a/src/core/lib/surface/init.c +++ b/src/core/lib/surface/init.c @@ -240,7 +240,7 @@ void grpc_shutdown(void) { } } grpc_mdctx_global_shutdown(&exec_ctx); - grpc_slice_intern_shutdown(&exec_ctx); + grpc_slice_intern_shutdown(); } gpr_mu_unlock(&g_init_mu); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index b0041871d4c..c0d6bba687e 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -157,6 +157,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index e214216ece9..b8c7eef4881 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -179,6 +179,7 @@ grpc_slice_new_type grpc_slice_new_import; grpc_slice_new_with_user_data_type grpc_slice_new_with_user_data_import; grpc_slice_new_with_len_type grpc_slice_new_with_len_import; grpc_slice_malloc_type grpc_slice_malloc_import; +grpc_slice_intern_type grpc_slice_intern_import; grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; grpc_slice_from_static_string_type grpc_slice_from_static_string_import; @@ -454,6 +455,7 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_new_with_user_data_import = (grpc_slice_new_with_user_data_type) GetProcAddress(library, "grpc_slice_new_with_user_data"); grpc_slice_new_with_len_import = (grpc_slice_new_with_len_type) GetProcAddress(library, "grpc_slice_new_with_len"); grpc_slice_malloc_import = (grpc_slice_malloc_type) GetProcAddress(library, "grpc_slice_malloc"); + grpc_slice_intern_import = (grpc_slice_intern_type) GetProcAddress(library, "grpc_slice_intern"); grpc_slice_from_copied_string_import = (grpc_slice_from_copied_string_type) GetProcAddress(library, "grpc_slice_from_copied_string"); grpc_slice_from_copied_buffer_import = (grpc_slice_from_copied_buffer_type) GetProcAddress(library, "grpc_slice_from_copied_buffer"); grpc_slice_from_static_string_import = (grpc_slice_from_static_string_type) GetProcAddress(library, "grpc_slice_from_static_string"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 7a64c1431d2..ba436dde471 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -488,6 +488,9 @@ extern grpc_slice_new_with_len_type grpc_slice_new_with_len_import; typedef grpc_slice(*grpc_slice_malloc_type)(size_t length); extern grpc_slice_malloc_type grpc_slice_malloc_import; #define grpc_slice_malloc grpc_slice_malloc_import +typedef grpc_slice(*grpc_slice_intern_type)(grpc_slice slice); +extern grpc_slice_intern_type grpc_slice_intern_import; +#define grpc_slice_intern grpc_slice_intern_import typedef grpc_slice(*grpc_slice_from_copied_string_type)(const char *source); extern grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; #define grpc_slice_from_copied_string grpc_slice_from_copied_string_import diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index ca44becfd09..a14f15ccfa3 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -35,6 +35,7 @@ #include +#include #include #include #include "test/core/util/test_config.h" @@ -249,6 +250,26 @@ static void test_slice_from_copied_string_works(void) { grpc_slice_unref(slice); } +static void test_slice_interning(void) { + LOG_TEST_NAME("test_slice_interning"); + + grpc_init(); + grpc_slice src1 = grpc_slice_from_copied_string("hello"); + grpc_slice src2 = grpc_slice_from_copied_string("hello"); + GPR_ASSERT(GRPC_SLICE_START_PTR(src1) != GRPC_SLICE_START_PTR(src2)); + grpc_slice interned1 = grpc_slice_intern(src1); + grpc_slice interned2 = grpc_slice_intern(src2); + GPR_ASSERT(GRPC_SLICE_START_PTR(interned1) == + GRPC_SLICE_START_PTR(interned2)); + GPR_ASSERT(GRPC_SLICE_START_PTR(interned1) != GRPC_SLICE_START_PTR(src1)); + GPR_ASSERT(GRPC_SLICE_START_PTR(interned2) != GRPC_SLICE_START_PTR(src2)); + grpc_slice_unref(src1); + grpc_slice_unref(src2); + grpc_slice_unref(interned1); + grpc_slice_unref(interned2); + grpc_shutdown(); +} + int main(int argc, char **argv) { unsigned length; grpc_test_init(argc, argv); @@ -262,5 +283,6 @@ int main(int argc, char **argv) { test_slice_split_tail_works(length); } test_slice_from_copied_string_works(); + test_slice_interning(); return 0; } diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 55b8d40aca5..5a19eec65d4 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1048,6 +1048,7 @@ src/core/lib/json/json_writer.c \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ +src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 3cc33ae5d2c..facc7ee3cb0 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6257,6 +6257,7 @@ "test/core/end2end/end2end_test_utils.c", "test/core/end2end/end2end_tests.c", "test/core/end2end/end2end_tests.h", + "test/core/end2end/tests/authority_not_supported.c", "test/core/end2end/tests/bad_hostname.c", "test/core/end2end/tests/binary_metadata.c", "test/core/end2end/tests/call_creds.c", @@ -6325,6 +6326,7 @@ "test/core/end2end/end2end_nosec_tests.c", "test/core/end2end/end2end_test_utils.c", "test/core/end2end/end2end_tests.h", + "test/core/end2end/tests/authority_not_supported.c", "test/core/end2end/tests/bad_hostname.c", "test/core/end2end/tests/binary_metadata.c", "test/core/end2end/tests/cancel_after_accept.c", @@ -6878,6 +6880,7 @@ "src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/alarm.c", diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 47df78ead18..366e9443576 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -4975,6 +4975,29 @@ "windows" ] }, + { + "args": [ + "authority_not_supported" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "bad_hostname" @@ -6015,25 +6038,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ "windows", "linux", "mac", "posix" - ], - "cpu_cost": 1.0, + ], + "cpu_cost": 1.0, "exclude_configs": [], + "exclude_iomgrs": [], "flaky": false, - "language": "c", - "name": "h2_census_test", + "language": "c", + "name": "h2_compress_test", "platforms": [ "windows", "linux", "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -7074,25 +7098,25 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_compress_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_fakesec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -8088,24 +8112,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_fakesec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_test", "platforms": [ - "windows", - "linux", - "mac", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -9029,23 +9055,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_fd_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_test", "platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -10086,25 +10115,22 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", - "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full_test", + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_test", "platforms": [ - "windows", - "linux", - "mac", - "posix" + "linux" ] - }, + }, { "args": [ "bad_hostname" @@ -10963,19 +10989,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "linux" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full+pipe_test", + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_test", "platforms": [ - "linux" + "windows", + "linux", + "mac", + "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -11970,25 +12003,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full+trace_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -13072,24 +13107,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_http_proxy_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -14130,25 +14167,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_load_reporting_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_oauth2_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -15232,24 +15271,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_oauth2_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -16165,24 +16207,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_proxy_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -17146,24 +17191,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_sockpair_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -18055,24 +18103,29 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_sockpair+trace_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -19090,24 +19143,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_sockpair_1byte_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -20148,25 +20203,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_ssl_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_cert_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -21207,25 +21263,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_ssl_cert_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_ssl_proxy_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -22141,24 +22199,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_ssl_proxy_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_test", "platforms": [ - "windows", - "linux", - "mac", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -23174,23 +23234,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_uds_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_nosec_test", "platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -24208,25 +24271,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_census_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_compress_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -25244,25 +25308,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_compress_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -26163,23 +26228,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_fd_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_nosec_test", "platforms": [ - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -27197,25 +27265,22 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", - "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full_nosec_test", + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_nosec_test", "platforms": [ - "windows", - "linux", - "mac", - "posix" + "linux" ] - }, + }, { "args": [ "bad_hostname" @@ -28055,19 +28120,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "linux" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full+pipe_nosec_test", + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_nosec_test", "platforms": [ - "linux" + "windows", + "linux", + "mac", + "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -29039,25 +29111,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_full+trace_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -30117,24 +30191,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_http_proxy_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -31152,25 +31228,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_load_reporting_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -32062,24 +32140,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_proxy_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -33019,24 +33100,27 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_sockpair_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -33904,24 +33988,29 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "windows", + "linux", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_sockpair+trace_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "windows", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -34913,26 +35002,26 @@ { "args": [ "authority_not_supported" - ], + ], "ci_platforms": [ - "windows", - "linux", + "linux", + "mac", "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [ - "msan" - ], - "flaky": false, - "language": "c", - "name": "h2_sockpair_1byte_nosec_test", + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_nosec_test", "platforms": [ - "windows", - "linux", - "mac", + "linux", + "mac", "posix" ] - }, + }, { "args": [ "bad_hostname" @@ -35922,26 +36011,6 @@ "posix" ] }, - { - "args": [ - "authority_not_supported" - ], - "ci_platforms": [ - "linux", - "mac", - "posix" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "flaky": false, - "language": "c", - "name": "h2_uds_nosec_test", - "platforms": [ - "linux", - "mac", - "posix" - ] - }, { "args": [ "--scenarios_json", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index c608cb89435..0ad26cafccb 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -642,6 +642,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index c6ca85cab68..f27eccd64b1 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -250,6 +250,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 764f4615b6f..d575c83e788 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -493,6 +493,8 @@ + + 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 2b720430013..4598022e99e 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -307,6 +307,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index ed68f03ad5b..e52edb3e388 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -610,6 +610,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index e8c16e531f7..1df4737b7d5 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -253,6 +253,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj index 3d510d51568..954ac21b497 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj @@ -155,6 +155,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters index a0b01ddbc89..b2747d25784 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters @@ -7,6 +7,9 @@ test\core\end2end + + test\core\end2end\tests + test\core\end2end\tests diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj index 5699e8308ed..51b744bc214 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj @@ -155,6 +155,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters index bfb5e2b2292..33e7098ecf4 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters @@ -7,6 +7,9 @@ test\core\end2end + + test\core\end2end\tests + test\core\end2end\tests From 515a33d6bd2e41d69c04f28b8a24d9ea85618d42 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Nov 2016 15:33:32 -0800 Subject: [PATCH 009/261] Perfect hashing code --- tools/codegen/core/perfect/.gitignore | 7 + tools/codegen/core/perfect/lookupa.c | 240 +++++ tools/codegen/core/perfect/lookupa.h | 24 + tools/codegen/core/perfect/perfect.c | 1367 +++++++++++++++++++++++++ tools/codegen/core/perfect/perfect.h | 132 +++ tools/codegen/core/perfect/perfhex.c | 1308 +++++++++++++++++++++++ tools/codegen/core/perfect/recycle.c | 87 ++ tools/codegen/core/perfect/recycle.h | 65 ++ tools/codegen/core/perfect/run.sh | 7 + tools/codegen/core/perfect/standard.h | 57 ++ 10 files changed, 3294 insertions(+) create mode 100644 tools/codegen/core/perfect/.gitignore create mode 100644 tools/codegen/core/perfect/lookupa.c create mode 100644 tools/codegen/core/perfect/lookupa.h create mode 100644 tools/codegen/core/perfect/perfect.c create mode 100644 tools/codegen/core/perfect/perfect.h create mode 100644 tools/codegen/core/perfect/perfhex.c create mode 100644 tools/codegen/core/perfect/recycle.c create mode 100644 tools/codegen/core/perfect/recycle.h create mode 100755 tools/codegen/core/perfect/run.sh create mode 100644 tools/codegen/core/perfect/standard.h diff --git a/tools/codegen/core/perfect/.gitignore b/tools/codegen/core/perfect/.gitignore new file mode 100644 index 00000000000..c1489f08193 --- /dev/null +++ b/tools/codegen/core/perfect/.gitignore @@ -0,0 +1,7 @@ +perfect +*.o +phash.h +phash.c +compile.txt +hash.txt + diff --git a/tools/codegen/core/perfect/lookupa.c b/tools/codegen/core/perfect/lookupa.c new file mode 100644 index 00000000000..c122c4f107f --- /dev/null +++ b/tools/codegen/core/perfect/lookupa.c @@ -0,0 +1,240 @@ +/* +-------------------------------------------------------------------- +lookupa.c, by Bob Jenkins, December 1996. Same as lookup2.c +Use this code however you wish. Public Domain. No warranty. +Source is http://burtleburtle.net/bob/c/lookupa.c +-------------------------------------------------------------------- +*/ +#ifndef STANDARD +#include "standard.h" +#endif +#ifndef LOOKUPA +#include "lookupa.h" +#endif + +/* +-------------------------------------------------------------------- +mix -- mix 3 32-bit values reversibly. +For every delta with one or two bit set, and the deltas of all three + high bits or all three low bits, whether the original value of a,b,c + is almost all zero or is uniformly distributed, +* If mix() is run forward or backward, at least 32 bits in a,b,c + have at least 1/4 probability of changing. +* If mix() is run forward, every bit of c will change between 1/3 and + 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.) +mix() was built out of 36 single-cycle latency instructions in a + structure that could supported 2x parallelism, like so: + a -= b; + a -= c; x = (c>>13); + b -= c; a ^= x; + b -= a; x = (a<<8); + c -= a; b ^= x; + c -= b; x = (b>>13); + ... + Unfortunately, superscalar Pentiums and Sparcs can't take advantage + of that parallelism. They've also turned some of those single-cycle + latency instructions into multi-cycle latency instructions. Still, + this is the fastest good hash I could find. There were about 2^^68 + to choose from. I only looked at a billion or so. +-------------------------------------------------------------------- +*/ +#define mix(a,b,c) \ +{ \ + a -= b; a -= c; a ^= (c>>13); \ + b -= c; b -= a; b ^= (a<<8); \ + c -= a; c -= b; c ^= (b>>13); \ + a -= b; a -= c; a ^= (c>>12); \ + b -= c; b -= a; b ^= (a<<16); \ + c -= a; c -= b; c ^= (b>>5); \ + a -= b; a -= c; a ^= (c>>3); \ + b -= c; b -= a; b ^= (a<<10); \ + c -= a; c -= b; c ^= (b>>15); \ +} + +/* +-------------------------------------------------------------------- +lookup() -- hash a variable-length key into a 32-bit value + k : the key (the unaligned variable-length array of bytes) + len : the length of the key, counting by bytes + level : can be any 4-byte value +Returns a 32-bit value. Every bit of the key affects every bit of +the return value. Every 1-bit and 2-bit delta achieves avalanche. +About 6len+35 instructions. + +The best hash table sizes are powers of 2. There is no need to do +mod a prime (mod is sooo slow!). If you need less than 32 bits, +use a bitmask. For example, if you need only 10 bits, do + h = (h & hashmask(10)); +In which case, the hash table should have hashsize(10) elements. + +If you are hashing n strings (ub1 **)k, do it like this: + for (i=0, h=0; i= 12) + { + a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24)); + b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24)); + c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24)); + mix(a,b,c); + k += 12; len -= 12; + } + + /*------------------------------------- handle the last 11 bytes */ + c += length; + switch(len) /* all the case statements fall through */ + { + case 11: c+=((ub4)k[10]<<24); + case 10: c+=((ub4)k[9]<<16); + case 9 : c+=((ub4)k[8]<<8); + /* the first byte of c is reserved for the length */ + case 8 : b+=((ub4)k[7]<<24); + case 7 : b+=((ub4)k[6]<<16); + case 6 : b+=((ub4)k[5]<<8); + case 5 : b+=k[4]; + case 4 : a+=((ub4)k[3]<<24); + case 3 : a+=((ub4)k[2]<<16); + case 2 : a+=((ub4)k[1]<<8); + case 1 : a+=k[0]; + /* case 0: nothing left to add */ + } + mix(a,b,c); + /*-------------------------------------------- report the result */ + return c; +} + + +/* +-------------------------------------------------------------------- +mixc -- mixc 8 4-bit values as quickly and thoroughly as possible. +Repeating mix() three times achieves avalanche. +Repeating mix() four times eliminates all funnels and all + characteristics stronger than 2^{-11}. +-------------------------------------------------------------------- +*/ +#define mixc(a,b,c,d,e,f,g,h) \ +{ \ + a^=b<<11; d+=a; b+=c; \ + b^=c>>2; e+=b; c+=d; \ + c^=d<<8; f+=c; d+=e; \ + d^=e>>16; g+=d; e+=f; \ + e^=f<<10; h+=e; f+=g; \ + f^=g>>4; a+=f; g+=h; \ + g^=h<<8; b+=g; h+=a; \ + h^=a>>9; c+=h; a+=b; \ +} + +/* +-------------------------------------------------------------------- +checksum() -- hash a variable-length key into a 256-bit value + k : the key (the unaligned variable-length array of bytes) + len : the length of the key, counting by bytes + state : an array of CHECKSTATE 4-byte values (256 bits) +The state is the checksum. Every bit of the key affects every bit of +the state. There are no funnels. About 112+6.875len instructions. + +If you are hashing n strings (ub1 **)k, do it like this: + for (i=0; i<8; ++i) state[i] = 0x9e3779b9; + for (i=0, h=0; i= 32) + { + a += (k[0] +(k[1]<<8) +(k[2]<<16) +(k[3]<<24)); + b += (k[4] +(k[5]<<8) +(k[6]<<16) +(k[7]<<24)); + c += (k[8] +(k[9]<<8) +(k[10]<<16)+(k[11]<<24)); + d += (k[12]+(k[13]<<8)+(k[14]<<16)+(k[15]<<24)); + e += (k[16]+(k[17]<<8)+(k[18]<<16)+(k[19]<<24)); + f += (k[20]+(k[21]<<8)+(k[22]<<16)+(k[23]<<24)); + g += (k[24]+(k[25]<<8)+(k[26]<<16)+(k[27]<<24)); + h += (k[28]+(k[29]<<8)+(k[30]<<16)+(k[31]<<24)); + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + k += 32; len -= 32; + } + + /*------------------------------------- handle the last 31 bytes */ + h += length; + switch(len) + { + case 31: h+=(k[30]<<24); + case 30: h+=(k[29]<<16); + case 29: h+=(k[28]<<8); + case 28: g+=(k[27]<<24); + case 27: g+=(k[26]<<16); + case 26: g+=(k[25]<<8); + case 25: g+=k[24]; + case 24: f+=(k[23]<<24); + case 23: f+=(k[22]<<16); + case 22: f+=(k[21]<<8); + case 21: f+=k[20]; + case 20: e+=(k[19]<<24); + case 19: e+=(k[18]<<16); + case 18: e+=(k[17]<<8); + case 17: e+=k[16]; + case 16: d+=(k[15]<<24); + case 15: d+=(k[14]<<16); + case 14: d+=(k[13]<<8); + case 13: d+=k[12]; + case 12: c+=(k[11]<<24); + case 11: c+=(k[10]<<16); + case 10: c+=(k[9]<<8); + case 9 : c+=k[8]; + case 8 : b+=(k[7]<<24); + case 7 : b+=(k[6]<<16); + case 6 : b+=(k[5]<<8); + case 5 : b+=k[4]; + case 4 : a+=(k[3]<<24); + case 3 : a+=(k[2]<<16); + case 2 : a+=(k[1]<<8); + case 1 : a+=k[0]; + } + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + mixc(a,b,c,d,e,f,g,h); + + /*-------------------------------------------- report the result */ + state[0]=a; state[1]=b; state[2]=c; state[3]=d; + state[4]=e; state[5]=f; state[6]=g; state[7]=h; +} diff --git a/tools/codegen/core/perfect/lookupa.h b/tools/codegen/core/perfect/lookupa.h new file mode 100644 index 00000000000..0b27db680dc --- /dev/null +++ b/tools/codegen/core/perfect/lookupa.h @@ -0,0 +1,24 @@ +/* +------------------------------------------------------------------------------ +By Bob Jenkins, September 1996. +lookupa.h, a hash function for table lookup, same function as lookup.c. +Use this code in any way you wish. Public Domain. It has no warranty. +Source is http://burtleburtle.net/bob/c/lookupa.h +------------------------------------------------------------------------------ +*/ + +#ifndef STANDARD +#include "standard.h" +#endif + +#ifndef LOOKUPA +#define LOOKUPA + +#define CHECKSTATE 8 +#define hashsize(n) ((ub4)1<<(n)) +#define hashmask(n) (hashsize(n)-1) + +ub4 lookup(/*_ ub1 *k, ub4 length, ub4 level _*/); +void checksum(/*_ ub1 *k, ub4 length, ub4 *state _*/); + +#endif /* LOOKUPA */ diff --git a/tools/codegen/core/perfect/perfect.c b/tools/codegen/core/perfect/perfect.c new file mode 100644 index 00000000000..67fd2fd262e --- /dev/null +++ b/tools/codegen/core/perfect/perfect.c @@ -0,0 +1,1367 @@ +/* +------------------------------------------------------------------------------ +perfect.c: code to generate code for a hash for perfect hashing. +(c) Bob Jenkins, September 1996, December 1999 +You may use this code in any way you wish, and it is free. No warranty. +I hereby place this in the public domain. +Source is http://burtleburtle.net/bob/c/perfect.c + +This generates a minimal perfect hash function. That means, given a +set of n keys, this determines a hash function that maps each of +those keys into a value in 0..n-1 with no collisions. + +The perfect hash function first uses a normal hash function on the key +to determine (a,b) such that the pair (a,b) is distinct for all +keys, then it computes a^scramble[tab[b]] to get the final perfect hash. +tab[] is an array of 1-byte values and scramble[] is a 256-term array of +2-byte or 4-byte values. If there are n keys, the length of tab[] is a +power of two between n/3 and n. + +I found the idea of computing distinct (a,b) values in "Practical minimal +perfect hash functions for large databases", Fox, Heath, Chen, and Daoud, +Communications of the ACM, January 1992. They found the idea in Chichelli +(CACM Jan 1980). Beyond that, our methods differ. + +The key is hashed to a pair (a,b) where a in 0..*alen*-1 and b in +0..*blen*-1. A fast hash function determines both a and b +simultaneously. Any decent hash function is likely to produce +hashes so that (a,b) is distinct for all pairs. I try the hash +using different values of *salt* until all pairs are distinct. + +The final hash is (a XOR scramble[tab[b]]). *scramble* is a +predetermined mapping of 0..255 into 0..smax-1. *tab* is an +array that we fill in in such a way as to make the hash perfect. + +First we fill in all values of *tab* that are used by more than one +key. We try all possible values for each position until one works. + +This leaves m unmapped keys and m values that something could hash to. +If you treat unmapped keys as lefthand nodes and unused hash values +as righthand nodes, and draw a line connecting each key to each hash +value it could map to, you get a bipartite graph. We attempt to +find a perfect matching in this graph. If we succeed, we have +determined a perfect hash for the whole set of keys. + +*scramble* is used because (a^tab[i]) clusters keys around *a*. +------------------------------------------------------------------------------ +*/ + +#ifndef STANDARD +#include "standard.h" +#endif +#ifndef LOOKUPA +#include "lookupa.h" +#endif +#ifndef RECYCLE +#include "recycle.h" +#endif +#ifndef PERFECT +#include "perfect.h" +#endif + +/* +------------------------------------------------------------------------------ +Find the mapping that will produce a perfect hash +------------------------------------------------------------------------------ +*/ + +/* return the ceiling of the log (base 2) of val */ +ub4 mylog2(val) +ub4 val; +{ + ub4 i; + for (i=0; ((ub4)1<>const3)); + x = (x+(x<>const5)); + } + return x; +} + +/* initialize scramble[] with distinct random values in 0..smax-1 */ +static void scrambleinit(scramble, smax) +ub4 *scramble; /* hash is a^scramble[tab[b]] */ +ub4 smax; /* scramble values should be in 0..smax-1 */ +{ + ub4 i; + + /* fill scramble[] with distinct random integers in 0..smax-1 */ + for (i=0; ihashtype) + { + case STRING_HT: + if ((key1->len_k == key2->len_k) && + !memcmp(key1->name_k, key2->name_k, (size_t)key1->len_k)) + { + fprintf(stderr, "perfect.c: Duplicates keys! %.*s\n", + key1->len_k, key1->name_k); + exit(SUCCESS); + } + break; + case INT_HT: + if (key1->hash_k == key2->hash_k) + { + fprintf(stderr, "perfect.c: Duplicate keys! %.8lx\n", key1->hash_k); + exit(SUCCESS); + } + break; + case AB_HT: + fprintf(stderr, "perfect.c: Duplicate keys! %.8lx %.8lx\n", + key1->a_k, key1->b_k); + exit(SUCCESS); + break; + default: + fprintf(stderr, "perfect.c: Illegal hash type %ld\n", (ub4)form->hashtype); + exit(SUCCESS); + break; + } +} + + +/* + * put keys in tabb according to key->b_k + * check if the initial hash might work + */ +static int inittab(tabb, blen, keys, form, complete) +bstuff *tabb; /* output, list of keys with b for (a,b) */ +ub4 blen; /* length of tabb */ +key *keys; /* list of keys already hashed */ +hashform *form; /* user directives */ +int complete; /* TRUE means to complete init despite collisions */ +{ + int nocollision = TRUE; + key *mykey; + + memset((void *)tabb, 0, (size_t)(sizeof(bstuff)*blen)); + + /* Two keys with the same (a,b) guarantees a collision */ + for (mykey=keys; mykey; mykey=mykey->next_k) + { + key *otherkey; + + for (otherkey=tabb[mykey->b_k].list_b; + otherkey; + otherkey=otherkey->nextb_k) + { + if (mykey->a_k == otherkey->a_k) + { + nocollision = FALSE; + checkdup(mykey, otherkey, form); + if (!complete) + return FALSE; + } + } + ++tabb[mykey->b_k].listlen_b; + mykey->nextb_k = tabb[mykey->b_k].list_b; + tabb[mykey->b_k].list_b = mykey; + } + + /* no two keys have the same (a,b) pair */ + return nocollision; +} + + +/* Do the initial hash for normal mode (use lookup and checksum) */ +static void initnorm(keys, alen, blen, smax, salt, final) +key *keys; /* list of all keys */ +ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ +ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ +ub4 smax; /* maximum range of computable hash values */ +ub4 salt; /* used to initialize the hash function */ +gencode *final; /* output, code for the final hash */ +{ + key *mykey; + if (mylog2(alen)+mylog2(blen) > UB4BITS) + { + ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ + + for (mykey=keys; mykey; mykey=mykey->next_k) + { + ub4 i, state[CHECKSTATE]; + for (i=0; iname_k, mykey->len_k, state); + mykey->a_k = state[0]&(alen-1); + mykey->b_k = state[1]&(blen-1); + } + final->used = 4; + sprintf(final->line[0], + " ub4 i,state[CHECKSTATE],rsl;\n"); + sprintf(final->line[1], + " for (i=0; iline[2], + " checksum(key, len, state);\n"); + sprintf(final->line[3], + " rsl = ((state[0]&0x%x)^scramble[tab[state[1]&0x%x]]);\n", + alen-1, blen-1); + } + else + { + ub4 loga = mylog2(alen); /* log based 2 of blen */ + ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ + + for (mykey=keys; mykey; mykey=mykey->next_k) + { + ub4 hash = lookup(mykey->name_k, mykey->len_k, initlev); + mykey->a_k = (loga > 0) ? hash>>(UB4BITS-loga) : 0; + mykey->b_k = (blen > 1) ? hash&(blen-1) : 0; + } + final->used = 2; + sprintf(final->line[0], + " ub4 rsl, val = lookup(key, len, 0x%lx);\n", initlev); + if (smax <= 1) + { + sprintf(final->line[1], " rsl = 0;\n"); + } + else if (mylog2(alen) == 0) + { + sprintf(final->line[1], " rsl = tab[val&0x%x];\n", blen-1); + } + else if (blen < USE_SCRAMBLE) + { + sprintf(final->line[1], " rsl = ((val>>%ld)^tab[val&0x%x]);\n", + UB4BITS-mylog2(alen), blen-1); + } + else + { + sprintf(final->line[1], " rsl = ((val>>%ld)^scramble[tab[val&0x%x]]);\n", + UB4BITS-mylog2(alen), blen-1); + } + } +} + + + +/* Do initial hash for inline mode */ +static void initinl(keys, alen, blen, smax, salt, final) +key *keys; /* list of all keys */ +ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ +ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ +ub4 smax; /* range of computable hash values */ +ub4 salt; /* used to initialize the hash function */ +gencode *final; /* generated code for final hash */ +{ + key *mykey; + ub4 amask = alen-1; + ub4 blog = mylog2(blen); + ub4 initval = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ + + /* It's more important to have b uniform than a, so b is the low bits */ + for (mykey = keys; mykey != (key *)0; mykey = mykey->next_k) + { + ub4 hash = initval; + ub4 i; + for (i=0; ilen_k; ++i) + { + hash = (mykey->name_k[i] ^ hash) + ((hash<<(UB4BITS-6))+(hash>>6)); + } + mykey->hash_k = hash; + mykey->a_k = (alen > 1) ? (hash & amask) : 0; + mykey->b_k = (blen > 1) ? (hash >> (UB4BITS-blog)) : 0; + } + final->used = 1; + if (smax <= 1) + { + sprintf(final->line[0], " ub4 rsl = 0;\n"); + } + else if (blen < USE_SCRAMBLE) + { + sprintf(final->line[0], " ub4 rsl = ((val & 0x%lx) ^ tab[val >> %ld]);\n", + amask, UB4BITS-blog); + } + else + { + sprintf(final->line[0], " ub4 rsl = ((val & 0x%lx) ^ scramble[tab[val >> %ld]]);\n", + amask, UB4BITS-blog); + } +} + + +/* + * Run a hash function on the key to get a and b + * Returns: + * 0: didn't find distinct (a,b) for all keys + * 1: found distinct (a,b) for all keys, put keys in tabb[] + * 2: found a perfect hash, no need to do any more work + */ +static ub4 initkey(keys, nkeys, tabb, alen, blen, smax, salt, form, final) +key *keys; /* list of all keys */ +ub4 nkeys; /* total number of keys */ +bstuff *tabb; /* stuff indexed by b */ +ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ +ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ +ub4 smax; /* range of computable hash values */ +ub4 salt; /* used to initialize the hash function */ +hashform *form; /* user directives */ +gencode *final; /* code for final hash */ +{ + ub4 finished; + + /* Do the initial hash of the keys */ + switch(form->mode) + { + case NORMAL_HM: + initnorm(keys, alen, blen, smax, salt, final); + break; + case INLINE_HM: + initinl(keys, alen, blen, smax, salt, final); + break; + case HEX_HM: + case DECIMAL_HM: + finished = inithex(keys, nkeys, alen, blen, smax, salt, final, form); + if (finished) return 2; + break; + default: + fprintf(stderr, "fatal error: illegal mode\n"); + exit(1); + } + + if (nkeys <= 1) + { + final->used = 1; + sprintf(final->line[0], " ub4 rsl = 0;\n"); + return 2; + } + + return inittab(tabb, blen, keys, form, FALSE); +} + +/* Print an error message and exit if there are duplicates */ +static void duplicates(tabb, blen, keys, form) +bstuff *tabb; /* array of lists of keys with the same b */ +ub4 blen; /* length of tabb, a power of 2 */ +key *keys; +hashform *form; /* user directives */ +{ + ub4 i; + key *key1; + key *key2; + + (void)inittab(tabb, blen, keys, form, TRUE); + + /* for each b, do nested loops through key list looking for duplicates */ + for (i=0; inextb_k) + for (key2=key1->nextb_k; key2; key2=key2->nextb_k) + checkdup(key1, key2, form); +} + + +/* Try to apply an augmenting list */ +static int apply(tabb, tabh, tabq, blen, scramble, tail, rollback) +bstuff *tabb; +hstuff *tabh; +qstuff *tabq; +ub4 blen; +ub4 *scramble; +ub4 tail; +int rollback; /* FALSE applies augmenting path, TRUE rolls back */ +{ + ub4 hash; + key *mykey; + bstuff *pb; + ub4 child; + ub4 parent; + ub4 stabb; /* scramble[tab[b]] */ + + /* walk from child to parent */ + for (child=tail-1; child; child=parent) + { + parent = tabq[child].parent_q; /* find child's parent */ + pb = tabq[parent].b_q; /* find parent's list of siblings */ + + /* erase old hash values */ + stabb = scramble[pb->val_b]; + for (mykey=pb->list_b; mykey; mykey=mykey->nextb_k) + { + hash = mykey->a_k^stabb; + if (mykey == tabh[hash].key_h) + { /* erase hash for all of child's siblings */ + tabh[hash].key_h = (key *)0; + } + } + + /* change pb->val_b, which will change the hashes of all parent siblings */ + pb->val_b = (rollback ? tabq[child].oldval_q : tabq[child].newval_q); + + /* set new hash values */ + stabb = scramble[pb->val_b]; + for (mykey=pb->list_b; mykey; mykey=mykey->nextb_k) + { + hash = mykey->a_k^stabb; + if (rollback) + { + if (parent == 0) continue; /* root never had a hash */ + } + else if (tabh[hash].key_h) + { + /* very rare: roll back any changes */ + (void *)apply(tabb, tabh, tabq, blen, scramble, tail, TRUE); + return FALSE; /* failure, collision */ + } + tabh[hash].key_h = mykey; + } + } + return TRUE; +} + + +/* +------------------------------------------------------------------------------- +augment(): Add item to the mapping. + +Construct a spanning tree of *b*s with *item* as root, where each +parent can have all its hashes changed (by some new val_b) with +at most one collision, and each child is the b of that collision. + +I got this from Tarjan's "Data Structures and Network Algorithms". The +path from *item* to a *b* that can be remapped with no collision is +an "augmenting path". Change values of tab[b] along the path so that +the unmapped key gets mapped and the unused hash value gets used. + +Assuming 1 key per b, if m out of n hash values are still unused, +you should expect the transitive closure to cover n/m nodes before +an unused node is found. Sum(i=1..n)(n/i) is about nlogn, so expect +this approach to take about nlogn time to map all single-key b's. +------------------------------------------------------------------------------- +*/ +static int augment(tabb, tabh, tabq, blen, scramble, smax, item, nkeys, + highwater, form) +bstuff *tabb; /* stuff indexed by b */ +hstuff *tabh; /* which key is associated with which hash, indexed by hash */ +qstuff *tabq; /* queue of *b* values, this is the spanning tree */ +ub4 blen; /* length of tabb */ +ub4 *scramble; /* final hash is a^scramble[tab[b]] */ +ub4 smax; /* highest value in scramble */ +bstuff *item; /* &tabb[b] for the b to be mapped */ +ub4 nkeys; /* final hash must be in 0..nkeys-1 */ +ub4 highwater; /* a value higher than any now in tabb[].water_b */ +hashform *form; /* TRUE if we should do a minimal perfect hash */ +{ + ub4 q; /* current position walking through the queue */ + ub4 tail; /* tail of the queue. 0 is the head of the queue. */ + ub4 limit=((blen < USE_SCRAMBLE) ? smax : UB1MAXVAL+1); + ub4 highhash = ((form->perfect == MINIMAL_HP) ? nkeys : smax); + int trans = (form->speed == SLOW_HS || form->perfect == MINIMAL_HP); + + /* initialize the root of the spanning tree */ + tabq[0].b_q = item; + tail = 1; + + /* construct the spanning tree by walking the queue, add children to tail */ + for (q=0; qval_b */ + + if (!trans && (q == 1)) + break; /* don't do transitive closure */ + + for (i=0; ilist_b; mykey; mykey=mykey->nextb_k) + { + key *childkey; + ub4 hash = mykey->a_k^scramble[i]; + + if (hash >= highhash) break; /* out of bounds */ + childkey = tabh[hash].key_h; + + if (childkey) + { + bstuff *hitb = &tabb[childkey->b_k]; + + if (childb) + { + if (childb != hitb) break; /* hit at most one child b */ + } + else + { + childb = hitb; /* remember this as childb */ + if (childb->water_b == highwater) break; /* already explored */ + } + } + } + if (mykey) continue; /* myb with i has multiple collisions */ + + /* add childb to the queue of reachable things */ + if (childb) childb->water_b = highwater; + tabq[tail].b_q = childb; + tabq[tail].newval_q = i; /* how to make parent (myb) use this hash */ + tabq[tail].oldval_q = myb->val_b; /* need this for rollback */ + tabq[tail].parent_q = q; + ++tail; + + if (!childb) + { /* found an *i* with no collisions? */ + /* try to apply the augmenting path */ + if (apply(tabb, tabh, tabq, blen, scramble, tail, FALSE)) + return TRUE; /* success, item was added to the perfect hash */ + + --tail; /* don't know how to handle such a child! */ + } + } + } + return FALSE; +} + + +/* find a mapping that makes this a perfect hash */ +static int perfect(tabb, tabh, tabq, blen, smax, scramble, nkeys, form) +bstuff *tabb; +hstuff *tabh; +qstuff *tabq; +ub4 blen; +ub4 smax; +ub4 *scramble; +ub4 nkeys; +hashform *form; +{ + ub4 maxkeys; /* maximum number of keys for any b */ + ub4 i, j; + + /* clear any state from previous attempts */ + memset((void *)tabh, 0, + (size_t)(sizeof(hstuff)* + ((form->perfect == MINIMAL_HP) ? nkeys : smax))); + memset((void *)tabq, 0, (size_t)(sizeof(qstuff)*(blen+1))); + + for (maxkeys=0,i=0; i maxkeys) + maxkeys = tabb[i].listlen_b; + + /* In descending order by number of keys, map all *b*s */ + for (j=maxkeys; j>0; --j) + for (i=0; ia_k, key->b_k), and final->form == AB_HK. + */ +static void hash_ab(tabb, alen, blen, salt, final, + scramble, smax, keys, nkeys, form) +bstuff **tabb; /* output, tab[] of the perfect hash, length *blen */ +ub4 *alen; /* output, 0..alen-1 is range for a of (a,b) */ +ub4 *blen; /* output, 0..blen-1 is range for b of (a,b) */ +ub4 *salt; /* output, initializes initial hash */ +gencode *final; /* code for final hash */ +ub4 *scramble; /* input, hash = a^scramble[tab[b]] */ +ub4 *smax; /* input, scramble[i] in 0..smax-1 */ +key *keys; /* input, keys to hash */ +ub4 nkeys; /* input, number of keys being hashed */ +hashform *form; /* user directives */ +{ + hstuff *tabh; + qstuff *tabq; + key *mykey; + ub4 i; + int used_tab; + + /* initially make smax the first power of two bigger than nkeys */ + *smax = ((ub4)1<next_k) + { + while (*alen <= mykey->a_k) *alen *= 2; + while (*blen <= mykey->b_k) *blen *= 2; + } + if (*alen > 2**smax) + { + fprintf(stderr, + "perfect.c: Can't deal with (A,B) having A bigger than twice \n"); + fprintf(stderr, + " the smallest power of two greater or equal to any legal hash.\n"); + exit(SUCCESS); + } + + /* allocate working memory */ + *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); + tabq = (qstuff *)remalloc(sizeof(qstuff)*(*blen+1), "perfect.c, tabq"); + tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? + nkeys : *smax), + "perfect.c, tabh"); + + /* check that (a,b) are distinct and put them in tabb indexed by b */ + (void)inittab(*tabb, *blen, keys, form, FALSE); + + /* try with smax */ + if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) + { + if (form->perfect == MINIMAL_HP) + { + printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n"); + exit(SUCCESS); + } + else + { + /* try with 2*smax */ + free((void *)tabh); + *smax = *smax * 2; + scrambleinit(scramble, *smax); + tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? + nkeys : *smax), + "perfect.c, tabh"); + if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) + { + printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n"); + exit(SUCCESS); + } + } + } + + /* check if tab[] was really needed */ + for (i=0; i<*blen; ++i) + { + if ((*tabb)[i].val_b != 0) break; /* assumes permute(0) == 0 */ + } + used_tab = (i < *blen); + + /* write the code for the perfect hash */ + *salt = 1; + final->used = 1; + if (!used_tab) + { + sprintf(final->line[0], " ub4 rsl = a;\n"); + } + else if (*blen < USE_SCRAMBLE) + { + sprintf(final->line[0], " ub4 rsl = (a ^ tab[b]);\n"); + } + else + { + sprintf(final->line[0], " ub4 rsl = (a ^ scramble[tab[b]]);\n"); + } + + printf("success, found a perfect hash\n"); + + free((void *)tabq); + free((void *)tabh); +} + + +/* guess initial values for alen and blen */ +static void initalen(alen, blen, smax, nkeys, form) +ub4 *alen; /* output, initial alen */ +ub4 *blen; /* output, initial blen */ +ub4 *smax; /* input, power of two greater or equal to max hash value */ +ub4 nkeys; /* number of keys being hashed */ +hashform *form; /* user directives */ +{ + /* + * Find initial *alen, *blen + * Initial alen and blen values were found empirically. Some factors: + * + * If smax<256 there is no scramble, so tab[b] needs to cover 0..smax-1. + * + * alen and blen must be powers of 2 because the values in 0..alen-1 and + * 0..blen-1 are produced by applying a bitmask to the initial hash function. + * + * alen must be less than smax, in fact less than nkeys, because otherwise + * there would often be no i such that a^scramble[i] is in 0..nkeys-1 for + * all the *a*s associated with a given *b*, so there would be no legal + * value to assign to tab[b]. This only matters when we're doing a minimal + * perfect hash. + * + * It takes around 800 trials to find distinct (a,b) with nkey=smax*(5/8) + * and alen*blen = smax*smax/32. + * + * Values of blen less than smax/4 never work, and smax/2 always works. + * + * We want blen as small as possible because it is the number of bytes in + * the huge array we must create for the perfect hash. + * + * When nkey <= smax*(5/8), blen=smax/4 works much more often with + * alen=smax/8 than with alen=smax/4. Above smax*(5/8), blen=smax/4 + * doesn't seem to care whether alen=smax/8 or alen=smax/4. I think it + * has something to do with 5/8 = 1/8 * 5. For example examine 80000, + * 85000, and 90000 keys with different values of alen. This only matters + * if we're doing a minimal perfect hash. + * + * When alen*blen <= 1<perfect == NORMAL_HP) + { + if ((form->speed == FAST_HS) && (nkeys > *smax*0.8)) + { + *smax = *smax * 2; + } + + *alen = ((form->hashtype==INT_HT) && *smax>131072) ? + ((ub4)1<<(UB4BITS-mylog2(*blen))) : /* distinct keys => distinct (A,B) */ + *smax; /* no reason to restrict alen to smax/2 */ + if ((form->hashtype == INT_HT) && *smax < 32) + *blen = *smax; /* go for function speed not space */ + else if (*smax/4 <= (1<<14)) + *blen = ((nkeys <= *smax*0.56) ? *smax/32 : + (nkeys <= *smax*0.74) ? *smax/16 : *smax/8); + else + *blen = ((nkeys <= *smax*0.6) ? *smax/16 : + (nkeys <= *smax*0.8) ? *smax/8 : *smax/4); + + if ((form->speed == FAST_HS) && (*blen < *smax/8)) + *blen = *smax/8; + + if (*alen < 1) *alen = 1; + if (*blen < 1) *blen = 1; + } + else + { + switch(mylog2(*smax)) + { + case 0: + *alen = 1; + *blen = 1; + case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: + *alen = (form->perfect == NORMAL_HP) ? *smax : *smax/2; + *blen = *smax/2; + break; + case 9: + case 10: + case 11: + case 12: + case 13: + case 14: + case 15: + case 16: + case 17: + if (form->speed == FAST_HS) + { + *alen = *smax/2; + *blen = *smax/4; + } + else if (*smax/4 < USE_SCRAMBLE) + { + *alen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4); + *blen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4); + } + else + { + *alen = ((nkeys <= *smax*(5.0/8.0)) ? *smax/8 : + (nkeys <= *smax*(3.0/4.0)) ? *smax/4 : *smax/2); + *blen = *smax/4; /* always give the small size a shot */ + } + break; + case 18: + if (form->speed == FAST_HS) + { + *alen = *smax/2; + *blen = *smax/2; + } + else + { + *alen = *smax/8; /* never require the multiword hash */ + *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2; + } + break; + case 19: + case 20: + *alen = (nkeys <= *smax*(5.0/8.0)) ? *smax/8 : *smax/2; + *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2; + break; + default: + *alen = *smax/2; /* just find a hash as quick as possible */ + *blen = *smax/2; /* we'll be thrashing virtual memory at this size */ + break; + } + } +} + +/* +** Try to find a perfect hash function. +** Return the successful initializer for the initial hash. +** Return 0 if no perfect hash could be found. +*/ +void findhash(tabb, alen, blen, salt, final, + scramble, smax, keys, nkeys, form) +bstuff **tabb; /* output, tab[] of the perfect hash, length *blen */ +ub4 *alen; /* output, 0..alen-1 is range for a of (a,b) */ +ub4 *blen; /* output, 0..blen-1 is range for b of (a,b) */ +ub4 *salt; /* output, initializes initial hash */ +gencode *final; /* code for final hash */ +ub4 *scramble; /* input, hash = a^scramble[tab[b]] */ +ub4 *smax; /* input, scramble[i] in 0..smax-1 */ +key *keys; /* input, keys to hash */ +ub4 nkeys; /* input, number of keys being hashed */ +hashform *form; /* user directives */ +{ + ub4 bad_initkey; /* how many times did initkey fail? */ + ub4 bad_perfect; /* how many times did perfect fail? */ + ub4 trysalt; /* trial initializer for initial hash */ + ub4 maxalen; + hstuff *tabh; /* table of keys indexed by hash value */ + qstuff *tabq; /* table of stuff indexed by queue value, used by augment */ + + /* The case of (A,B) supplied by the user is a special case */ + if (form->hashtype == AB_HT) + { + hash_ab(tabb, alen, blen, salt, final, + scramble, smax, keys, nkeys, form); + return; + } + + /* guess initial values for smax, alen and blen */ + *smax = ((ub4)1<perfect == MINIMAL_HP) ? *smax/2 : *smax; + + /* allocate working memory */ + *tabb = (bstuff *)remalloc((size_t)(sizeof(bstuff)*(*blen)), + "perfect.c, tabb"); + tabq = (qstuff *)remalloc(sizeof(qstuff)*(*blen+1), "perfect.c, tabq"); + tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? + nkeys : *smax), + "perfect.c, tabh"); + + /* Actually find the perfect hash */ + *salt = 0; + bad_initkey = 0; + bad_perfect = 0; + for (trysalt=1; ; ++trysalt) + { + ub4 rslinit; + /* Try to find distinct (A,B) for all keys */ + + rslinit = initkey(keys, nkeys, *tabb, *alen, *blen, *smax, trysalt, + form, final); + + if (rslinit == 2) + { /* initkey actually found a perfect hash, not just distinct (a,b) */ + *salt = 1; + *blen = 0; + break; + } + else if (rslinit == 0) + { + /* didn't find distinct (a,b) */ + if (++bad_initkey >= RETRY_INITKEY) + { + /* Try to put more bits in (A,B) to make distinct (A,B) more likely */ + if (*alen < maxalen) + { + *alen *= 2; + } + else if (*blen < *smax) + { + *blen *= 2; + free(tabq); + free(*tabb); + *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); + tabq = (qstuff *)malloc((size_t)(sizeof(qstuff)*(*blen+1))); + } + else + { + duplicates(*tabb, *blen, keys, form); /* check for duplicates */ + printf("fatal error: Cannot perfect hash: cannot find distinct (A,B)\n"); + exit(SUCCESS); + } + bad_initkey = 0; + bad_perfect = 0; + } + continue; /* two keys have same (a,b) pair */ + } + + printf("found distinct (A,B) on attempt %ld\n", trysalt); + + /* Given distinct (A,B) for all keys, build a perfect hash */ + if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) + { + if ((form->hashtype != INT_HT && ++bad_perfect >= RETRY_PERFECT) || + (form->hashtype == INT_HT && ++bad_perfect >= RETRY_HEX)) + { + if (*blen < *smax) + { + *blen *= 2; + free(*tabb); + free(tabq); + *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); + tabq = (qstuff *)malloc((size_t)(sizeof(qstuff)*(*blen+1))); + --trysalt; /* we know this salt got distinct (A,B) */ + } + else + { + printf("fatal error: Cannot perfect hash: cannot build tab[]\n"); + exit(SUCCESS); + } + bad_perfect = 0; + } + continue; + } + + *salt = trysalt; + break; + } + + printf("built perfect hash table of size %ld\n", *blen); + + /* free working memory */ + free((void *)tabh); + free((void *)tabq); +} + +/* +------------------------------------------------------------------------------ +Input/output type routines +------------------------------------------------------------------------------ +*/ + +/* get the list of keys */ +static void getkeys(keys, nkeys, textroot, keyroot, form) +key **keys; /* list of all keys */ +ub4 *nkeys; /* number of keys */ +reroot *textroot; /* get space to store key text */ +reroot *keyroot; /* get space for keys */ +hashform *form; /* user directives */ +{ + key *mykey; + char *mytext; + mytext = (char *)renew(textroot); + *keys = 0; + *nkeys = 0; + while (fgets(mytext, MAXKEYLEN, stdin)) + { + mykey = (key *)renew(keyroot); + if (form->mode == AB_HM) + { + sscanf(mytext, "%lx %lx ", &mykey->a_k, &mykey->b_k); + } + else if (form->mode == ABDEC_HM) + { + sscanf(mytext, "%ld %ld ", &mykey->a_k, &mykey->b_k); + } + else if (form->mode == HEX_HM) + { + sscanf(mytext, "%lx ", &mykey->hash_k); + } + else if (form->mode == DECIMAL_HM) + { + sscanf(mytext, "%ld ", &mykey->hash_k); + } + else + { + mykey->name_k = (ub1 *)mytext; + mytext = (char *)renew(textroot); + mykey->len_k = (ub4)(strlen((char *)mykey->name_k)-1); + } + mykey->next_k = *keys; + *keys = mykey; + ++*nkeys; + } + redel(textroot, mytext); +} + +/* make the .h file */ +static void make_h(blen, smax, nkeys, salt) +ub4 blen; +ub4 smax; +ub4 nkeys; +ub4 salt; +{ + FILE *f; + f = fopen("phash.h", "w"); + fprintf(f, "/* Perfect hash definitions */\n"); + fprintf(f, "#ifndef STANDARD\n"); + fprintf(f, "#include \"standard.h\"\n"); + fprintf(f, "#endif /* STANDARD */\n"); + fprintf(f, "#ifndef PHASH\n"); + fprintf(f, "#define PHASH\n"); + fprintf(f, "\n"); + if (blen > 0) + { + if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE) + fprintf(f, "extern ub1 tab[];\n"); + else + { + fprintf(f, "extern ub2 tab[];\n"); + if (blen >= USE_SCRAMBLE) + { + if (smax <= UB2MAXVAL+1) + fprintf(f, "extern ub2 scramble[];\n"); + else + fprintf(f, "extern ub4 scramble[];\n"); + } + } + fprintf(f, "#define PHASHLEN 0x%lx /* length of hash mapping table */\n", + blen); + } + fprintf(f, "#define PHASHNKEYS %ld /* How many keys were hashed */\n", + nkeys); + fprintf(f, "#define PHASHRANGE %ld /* Range any input might map to */\n", + smax); + fprintf(f, "#define PHASHSALT 0x%.8lx /* internal, initialize normal hash */\n", + salt*0x9e3779b9); + fprintf(f, "\n"); + fprintf(f, "ub4 phash();\n"); + fprintf(f, "\n"); + fprintf(f, "#endif /* PHASH */\n"); + fprintf(f, "\n"); + fclose(f); +} + +/* make the .c file */ +static void make_c(tab, smax, blen, scramble, final, form) +bstuff *tab; /* table indexed by b */ +ub4 smax; /* range of scramble[] */ +ub4 blen; /* b in 0..blen-1, power of 2 */ +ub4 *scramble; /* used in final hash */ +gencode *final; /* code for the final hash */ +hashform *form; /* user directives */ +{ + ub4 i; + FILE *f; + f = fopen("phash.c", "w"); + fprintf(f, "/* table for the mapping for the perfect hash */\n"); + fprintf(f, "#ifndef STANDARD\n"); + fprintf(f, "#include \"standard.h\"\n"); + fprintf(f, "#endif /* STANDARD */\n"); + fprintf(f, "#ifndef PHASH\n"); + fprintf(f, "#include \"phash.h\"\n"); + fprintf(f, "#endif /* PHASH */\n"); + fprintf(f, "#ifndef LOOKUPA\n"); + fprintf(f, "#include \"lookupa.h\"\n"); + fprintf(f, "#endif /* LOOKUPA */\n"); + fprintf(f, "\n"); + if (blen >= USE_SCRAMBLE) + { + fprintf(f, "/* A way to make the 1-byte values in tab bigger */\n"); + if (smax > UB2MAXVAL+1) + { + fprintf(f, "ub4 scramble[] = {\n"); + for (i=0; i<=UB1MAXVAL; i+=4) + fprintf(f, "0x%.8lx, 0x%.8lx, 0x%.8lx, 0x%.8lx,\n", + scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3]); + } + else + { + fprintf(f, "ub2 scramble[] = {\n"); + for (i=0; i<=UB1MAXVAL; i+=8) + fprintf(f, +"0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx,\n", + scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3], + scramble[i+4], scramble[i+5], scramble[i+6], scramble[i+7]); + } + fprintf(f, "};\n"); + fprintf(f, "\n"); + } + if (blen > 0) + { + fprintf(f, "/* small adjustments to _a_ to make values distinct */\n"); + + if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE) + fprintf(f, "ub1 tab[] = {\n"); + else + fprintf(f, "ub2 tab[] = {\n"); + + if (blen < 16) + { + for (i=0; imode) + { + case NORMAL_HM: + fprintf(f, "ub4 phash(key, len)\n"); + fprintf(f, "char *key;\n"); + fprintf(f, "int len;\n"); + break; + case INLINE_HM: + case HEX_HM: + case DECIMAL_HM: + fprintf(f, "ub4 phash(val)\n"); + fprintf(f, "ub4 val;\n"); + break; + case AB_HM: + case ABDEC_HM: + fprintf(f, "ub4 phash(a,b)\n"); + fprintf(f, "ub4 a;\n"); + fprintf(f, "ub4 b;\n"); + break; + } + fprintf(f, "{\n"); + for (i=0; iused; ++i) + fprintf(f, final->line[i]); + fprintf(f, " return rsl;\n"); + fprintf(f, "}\n"); + fprintf(f, "\n"); + fclose(f); +} + +/* +------------------------------------------------------------------------------ +Read in the keys, find the hash, and write the .c and .h files +------------------------------------------------------------------------------ +*/ +static void driver(form) +hashform *form; /* user directives */ +{ + ub4 nkeys; /* number of keys */ + key *keys; /* head of list of keys */ + bstuff *tab; /* table indexed by b */ + ub4 smax; /* scramble[] values in 0..smax-1, a power of 2 */ + ub4 alen; /* a in 0..alen-1, a power of 2 */ + ub4 blen; /* b in 0..blen-1, a power of 2 */ + ub4 salt; /* a parameter to the hash function */ + reroot *textroot; /* MAXKEYLEN-character text lines */ + reroot *keyroot; /* source of keys */ + gencode final; /* code for final hash */ + ub4 i; + ub4 scramble[SCRAMBLE_LEN]; /* used in final hash function */ + char buf[10][80]; /* buffer for generated code */ + char *buf2[10]; /* also for generated code */ + + /* set up memory sources */ + textroot = remkroot((size_t)MAXKEYLEN); + keyroot = remkroot(sizeof(key)); + + /* set up code for final hash */ + final.line = buf2; + final.used = 0; + final.len = 10; + for (i=0; i<10; ++i) final.line[i] = buf[i]; + + /* read in the list of keywords */ + getkeys(&keys, &nkeys, textroot, keyroot, form); + printf("Read in %ld keys\n",nkeys); + + /* find the hash */ + findhash(&tab, &alen, &blen, &salt, &final, + scramble, &smax, keys, nkeys, form); + + /* generate the phash.h file */ + make_h(blen, smax, nkeys, salt); + printf("Wrote phash.h\n"); + + /* generate the phash.c file */ + make_c(tab, smax, blen, scramble, &final, form); + printf("Wrote phash.c\n"); + + /* clean up memory sources */ + refree(textroot); + refree(keyroot); + free((void *)tab); + printf("Cleaned up\n"); +} + + +/* Describe how to use this utility */ +static void usage_error() +{ + printf("Usage: perfect [-{NnIiHhDdAaBb}{MmPp}{FfSs}] < key.txt \n"); + printf("The input is a list of keys, one key per line.\n"); + printf("Only one of NnIiHhDdAa and one of MmPp may be specified.\n"); + printf(" N,n: normal mode, key is any string string (default).\n"); + printf(" I,i: initial hash for ASCII char strings.\n"); + printf("The initial hash must be\n"); + printf(" hash = PHASHSALT;\n"); + printf(" for (i=0; i>6));\n"); + printf(" }\n"); + printf("Note that this can be inlined in any user loop that walks\n"); + printf("through the key anyways, eliminating the loop overhead.\n"); + printf(" H,h: Keys are 4-byte integers in hex in this format:\n"); + printf("ffffffff\n"); + printf("This is good for optimizing switch statement compilation.\n"); + printf(" D,d: Same as H,h, except in decimal not hexidecimal\n"); + printf(" A,a: An (A,B) pair is supplied in hex in this format:\n"); + printf("aaa bbb\n"); + printf(" B,b: Same as A,a, except in decimal not hexidecimal\n"); + printf("This mode does nothing but find the values of tab[].\n"); + printf("*A* must be less than the total number of keys.\n"); + printf(" M,m: Minimal perfect hash. Hash will be in 0..nkeys-1 (default)\n"); + printf(" P,p: Perfect hash. Hash will be in 0..n-1, where n >= nkeys\n"); + printf("and n is a power of 2. Will probably use a smaller tab[]."); + printf(" F,f: Fast mode. Generate the perfect hash fast.\n"); + printf(" S,s: Slow mode. Spend time finding a good perfect hash.\n"); + + exit(SUCCESS); +} + + +/* Interpret arguments and call the driver */ +/* See usage_error for the expected arguments */ +int main(argc, argv) +int argc; +char **argv; +{ + int mode_given = FALSE; + int minimal_given = FALSE; + int speed_given = FALSE; + hashform form; + char *c; + + /* default behavior */ + form.mode = NORMAL_HM; + form.hashtype = STRING_HT; + form.perfect = MINIMAL_HP; + form.speed = SLOW_HS; + + /* let the user override the default behavior */ + switch (argc) + { + case 1: + break; + case 2: + if (argv[1][0] != '-') + { + usage_error(); + break; + } + for (c = &argv[1][1]; *c != '\0'; ++c) switch(*c) + { + case 'n': case 'N': + case 'i': case 'I': + case 'h': case 'H': + case 'd': case 'D': + case 'a': case 'A': + case 'b': case 'B': + if (mode_given == TRUE) + usage_error(); + switch(*c) + { + case 'n': case 'N': + form.mode = NORMAL_HM; form.hashtype = STRING_HT; break; + case 'i': case 'I': + form.mode = INLINE_HM; form.hashtype = STRING_HT; break; + case 'h': case 'H': + form.mode = HEX_HM; form.hashtype = INT_HT; break; + case 'd': case 'D': + form.mode = DECIMAL_HM; form.hashtype = INT_HT; break; + case 'a': case 'A': + form.mode = AB_HM; form.hashtype = AB_HT; break; + case 'b': case 'B': + form.mode = ABDEC_HM; form.hashtype = AB_HT; break; + } + mode_given = TRUE; + break; + case 'm': case 'M': + case 'p': case 'P': + if (minimal_given == TRUE) + usage_error(); + switch(*c) + { + case 'p': case 'P': + form.perfect = NORMAL_HP; break; + case 'm': case 'M': + form.perfect = MINIMAL_HP; break; + } + minimal_given = TRUE; + break; + case 'f': case 'F': + case 's': case 'S': + if (speed_given == TRUE) + usage_error(); + switch(*c) + { + case 'f': case 'F': + form.speed = FAST_HS; break; + case 's': case 'S': + form.speed = SLOW_HS; break; + } + speed_given = TRUE; + break; + default: + usage_error(); + } + break; + default: + usage_error(); + } + + /* Generate the [minimal] perfect hash */ + driver(&form); + + return SUCCESS; +} diff --git a/tools/codegen/core/perfect/perfect.h b/tools/codegen/core/perfect/perfect.h new file mode 100644 index 00000000000..fed5296bb75 --- /dev/null +++ b/tools/codegen/core/perfect/perfect.h @@ -0,0 +1,132 @@ +/* +------------------------------------------------------------------------------ +perfect.h: code to generate code for a hash for perfect hashing. +(c) Bob Jenkins, September 1996 +You may use this code in any way you wish, and it is free. No warranty. +I hereby place this in the public domain. +Source is http://burtleburtle.net/bob/c/perfect.h +------------------------------------------------------------------------------ +*/ + +#ifndef STANDARD +#include "standard.h" +#endif + +#ifndef PERFECT +#define PERFECT + +#define MAXKEYLEN 30 /* maximum length of a key */ +#define USE_SCRAMBLE 4096 /* use scramble if blen >= USE_SCRAMBLE */ +#define SCRAMBLE_LEN ((ub4)1<<16) /* length of *scramble* */ +#define RETRY_INITKEY 2048 /* number of times to try to find distinct (a,b) */ +#define RETRY_PERFECT 1 /* number of times to try to make a perfect hash */ +#define RETRY_HEX 200 /* RETRY_PERFECT when hex keys given */ + +/* the generated code for the final hash, assumes initial hash is done */ +struct gencode +{ + char **line; /* array of text lines, 80 bytes apiece */ + /* + * The code placed here must declare "ub4 rsl" + * and assign it the value of the perfect hash using the function inputs. + * Later code will be tacked on which returns rsl or manipulates it according + * to the user directives. + * + * This code is at the top of the routine; it may and must declare any + * local variables it needs. + * + * Each way of filling in **line should be given a comment that is a unique + * tag. A testcase named with that tag should also be found which tests + * the generated code. + */ + ub4 len; /* number of lines available for final hash */ + ub4 used; /* number of lines used by final hash */ + + ub4 lowbit; /* for HEX, lowest interesting bit */ + ub4 highbit; /* for HEX, highest interesting bit */ + ub4 diffbits; /* bits which differ for some key */ + ub4 i,j,k,l,m,n,o; /* state machine used in hexn() */ +}; +typedef struct gencode gencode; + +/* user directives: perfect hash? minimal perfect hash? input is an int? */ +struct hashform +{ + enum { + NORMAL_HM, /* key is a string */ + INLINE_HM, /* user will do initial hash, we must choose salt for them */ + HEX_HM, /* key to be hashed is a hexidecimal 4-byte integer */ + DECIMAL_HM, /* key to be hashed is a decimal 4-byte integer */ + AB_HM, /* key to be hashed is "A B", where A and B are (A,B) in hex */ + ABDEC_HM /* like AB_HM, but in decimal */ + } mode; + enum { + STRING_HT, /* key is a string */ + INT_HT, /* key is an integer */ + AB_HT /* dunno what key is, but input is distinct (A,B) pair */ + } hashtype; + enum { + NORMAL_HP, /* just find a perfect hash */ + MINIMAL_HP /* find a minimal perfect hash */ + } perfect; + enum { + FAST_HS, /* fast mode */ + SLOW_HS /* slow mode */ + } speed; +}; +typedef struct hashform hashform; + +/* representation of a key */ +struct key +{ + ub1 *name_k; /* the actual key */ + ub4 len_k; /* the length of the actual key */ + ub4 hash_k; /* the initial hash value for this key */ + struct key *next_k; /* next key */ +/* beyond this point is mapping-dependent */ + ub4 a_k; /* a, of the key maps to (a,b) */ + ub4 b_k; /* b, of the key maps to (a,b) */ + struct key *nextb_k; /* next key with this b */ +}; +typedef struct key key; + +/* things indexed by b of original (a,b) pair */ +struct bstuff +{ + ub2 val_b; /* hash=a^tabb[b].val_b */ + key *list_b; /* tabb[i].list_b is list of keys with b==i */ + ub4 listlen_b; /* length of list_b */ + ub4 water_b; /* high watermark of who has visited this map node */ +}; +typedef struct bstuff bstuff; + +/* things indexed by final hash value */ +struct hstuff +{ + key *key_h; /* tabh[i].key_h is the key with a hash of i */ +}; +typedef struct hstuff hstuff; + +/* things indexed by queue position */ +struct qstuff +{ + bstuff *b_q; /* b that currently occupies this hash */ + ub4 parent_q; /* queue position of parent that could use this hash */ + ub2 newval_q; /* what to change parent tab[b] to to use this hash */ + ub2 oldval_q; /* original value of tab[b] */ +}; +typedef struct qstuff qstuff; + +/* return ceiling(log based 2 of x) */ +ub4 mylog2(/*_ ub4 x _*/); + +/* Given the keys, scramble[], and hash mode, find the perfect hash */ +void findhash(/*_ bstuff **tabb, ub4 *alen, ub4 *blen, ub4 *salt, + gencode *final, ub4 *scramble, ub4 smax, key *keys, ub4 nkeys, + hashform *form _*/); + +/* private, but in a different file because it's excessively verbose */ +int inithex(/*_ key *keys, ub4 *alen, ub4 *blen, ub4 smax, ub4 nkeys, + ub4 salt, gencode *final, gencode *form _*/); + +#endif /* PERFECT */ diff --git a/tools/codegen/core/perfect/perfhex.c b/tools/codegen/core/perfect/perfhex.c new file mode 100644 index 00000000000..9c28dc734b3 --- /dev/null +++ b/tools/codegen/core/perfect/perfhex.c @@ -0,0 +1,1308 @@ +/* +------------------------------------------------------------------------------ +perfhex.c: code to generate code for a hash for perfect hashing. +(c) Bob Jenkins, December 31 1999 +You may use this code in any way you wish, and it is free. No warranty. +I hereby place this in the public domain. +Source is http://burtleburtle.net/bob/c/perfhex.c + +The task of this file is to do the minimal amount of mixing needed to +find distinct (a,b) for each key when each key is a distinct ub4. That +means trying all possible ways to mix starting with the fastest. The +output is those (a,b) pairs and code in the *final* structure for producing +those pairs. +------------------------------------------------------------------------------ +*/ + +#ifndef STANDARD +#include "standard.h" +#endif +#ifndef LOOKUPA +#include "lookupa.h" +#endif +#ifndef RECYCLE +#include "recycle.h" +#endif +#ifndef PERFECT +#include "perfect.h" +#endif + +/* + * Find a perfect hash when there is only one key. Zero instructions. + * Hint: the one key always hashes to 0 + */ +static void hexone(keys, final) +key *keys; +gencode *final; +{ + /* 1 key: the hash is always 0 */ + keys->a_k = 0; + keys->b_k = 0; + final->used = 1; + sprintf(final->line[0], " ub4 rsl = 0;\n"); /* h1a: 37 */ +} + + + +/* + * Find a perfect hash when there are only two keys. Max 2 instructions. + * There exists a bit that is different for the two keys. Test it. + * Note that a perfect hash of 2 keys is automatically minimal. + */ +static void hextwo(keys, final) +key *keys; +gencode *final; +{ + ub4 a = keys->hash_k; + ub4 b = keys->next_k->hash_k; + ub4 i; + + if (a == b) + { + printf("fatal error: duplicate keys\n"); + exit(SUCCESS); + } + + final->used = 1; + + /* one instruction */ + if ((a&1) != (b&1)) + { + sprintf(final->line[0], " ub4 rsl = (val & 1);\n"); /* h2a: 3,4 */ + return; + } + + /* two instructions */ + for (i=0; iline[0], " ub4 rsl = ((val << %ld) & 1);\n", i); +} + + + +/* + * find the value to xor to a and b and c to make none of them 3 + * assert, (a,b,c) are three distinct values in (0,1,2,3). + */ +static ub4 find_adder(a,b,c) +ub4 a; +ub4 b; +ub4 c; +{ + return (a^b^c^3); +} + + + +/* + * Find a perfect hash when there are only three keys. Max 6 instructions. + * + * keys a,b,c. + * There exists bit i such that a[i] != b[i]. + * Either c[i] != a[i] or c[i] != b[i], assume c[i] != a[i]. + * There exists bit j such that b[j] != c[j]. Note i != j. + * Final hash should be no longer than val[i]^val[j]. + * + * A minimal perfect hash needs to xor one of 0,1,2,3 afterwards to cause + * the hole to land on 3. find_adder() finds that constant + */ +static void hexthree(keys, final, form) +key *keys; +gencode *final; +hashform *form; +{ + ub4 a = keys->hash_k; + ub4 b = keys->next_k->hash_k; + ub4 c = keys->next_k->next_k->hash_k; + ub4 i,j,x,y,z; + + final->used = 1; + + if (a == b || a == c || b == c) + { + printf("fatal error: duplicate keys\n"); + exit(SUCCESS); + } + + /* one instruction */ + x = a&3; + y = b&3; + z = c&3; + if (x != y && x != z && y != z) + { + if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) + { + /* h3a: 0,1,2 */ + sprintf(final->line[0], " ub4 rsl = (val & 3);\n"); + } + else + { + /* h3b: 0,3,2 */ + sprintf(final->line[0], " ub4 rsl = ((val & 3) ^ %d);\n", + find_adder(x,y,z)); + } + return; + } + + x = a>>(UB4BITS-2); + y = b>>(UB4BITS-2); + z = c>>(UB4BITS-2); + if (x != y && x != z && y != z) + { + if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) + { + /* h3c: 3fffffff, 7fffffff, bfffffff */ + sprintf(final->line[0], " ub4 rsl = (val >> %ld);\n", (ub4)(UB4BITS-2)); + } + else + { + /* h3d: 7fffffff, bfffffff, ffffffff */ + sprintf(final->line[0], " ub4 rsl = ((val >> %ld) ^ %ld);\n", + (ub4)(UB4BITS-2), find_adder(x,y,z)); + } + return; + } + + /* two instructions */ + for (i=0; ihighbit; ++i) + { + x = (a>>i)&3; + y = (b>>i)&3; + z = (c>>i)&3; + if (x != y && x != z && y != z) + { + if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) + { + /* h3e: ffff3fff, ffff7fff, ffffbfff */ + sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 3);\n", i); + } + else + { + /* h3f: ffff7fff, ffffbfff, ffffffff */ + sprintf(final->line[0], " ub4 rsl = (((val >> %ld) & 3) ^ %ld);\n", i, + find_adder(x,y,z)); + } + return; + } + } + + /* three instructions */ + for (i=0; i<=final->highbit; ++i) + { + x = (a+(a>>i))&3; + y = (b+(b>>i))&3; + z = (c+(c>>i))&3; + if (x != y && x != z && y != z) + { + if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) + { + /* h3g: 0x000, 0x001, 0x100 */ + sprintf(final->line[0], " ub4 rsl = ((val+(val>>%ld))&3);\n", i); + } + else + { + /* h3h: 0x001, 0x100, 0x101 */ + sprintf(final->line[0], " ub4 rsl = (((val+(val>>%ld))&3)^%ld);\n", i, + find_adder(x,y,z)); + } + return; + } + } + + /* + * Four instructions: I can prove this will always work. + * + * If the three values are distinct, there are two bits which + * distinguish them. Choose the two such bits that are closest together. + * If those bits are values 001 and 100 for those three values, + * then there either aren't any bits in between + * or the in-between bits aren't valued 001, 110, 100, 011, 010, or 101, + * because that would violate the closest-together assumption. + * So any in-between bits must be 000 or 111, and of 000 and 111 with + * the distinguishing bits won't cause them to stop being distinguishing. + */ + for (i=final->lowbit; i<=final->highbit; ++i) + { + for (j=i; j<=final->highbit; ++j) + { + x = ((a>>i)^(a>>j))&3; + y = ((b>>i)^(b>>j))&3; + z = ((c>>i)^(c>>j))&3; + if (x != y && x != z && y != z) + { + if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) + { + /* h3i: 0x00, 0x04, 0x10 */ + sprintf(final->line[0], + " ub4 rsl = (((val>>%ld) ^ (val>>%ld)) & 3);\n", i, j); + } + else + { + /* h3j: 0x04, 0x10, 0x14 */ + sprintf(final->line[0], + " ub4 rsl = ((((val>>%ld) ^ (val>>%ld)) & 3) ^ %ld);\n", + i, j, find_adder(x,y,z)); + } + return; + } + } + } + + printf("fatal error: hexthree\n"); + exit(SUCCESS); +} + + + +/* + * Check that a,b,c,d are some permutation of 0,1,2,3 + * Assume that a,b,c,d are all have values less than 32. + */ +static int testfour(a,b,c,d) +ub4 a; +ub4 b; +ub4 c; +ub4 d; +{ + ub4 mask = (1<hash_k; + ub4 b = keys->next_k->hash_k; + ub4 c = keys->next_k->next_k->hash_k; + ub4 d = keys->next_k->next_k->next_k->hash_k; + ub4 w,x,y,z; + ub4 i,j,k; + + if (a==b || a==c || a==d || b==c || b==d || c==d) + { + printf("fatal error: Duplicate keys\n"); + exit(SUCCESS); + } + + final->used = 1; + + /* one instruction */ + if ((final->diffbits & 3) == 3) + { + w = a&3; + x = b&3; + y = c&3; + z = d&3; + if (testfour(w,x,y,z)) + { + sprintf(final->line[0], " ub4 rsl = (val & 3);\n"); /* h4a: 0,1,2,3 */ + return; + } + } + + if (((final->diffbits >> (UB4BITS-2)) & 3) == 3) + { + w = a>>(UB4BITS-2); + x = b>>(UB4BITS-2); + y = c>>(UB4BITS-2); + z = d>>(UB4BITS-2); + if (testfour(w,x,y,z)) + { /* h4b: 0fffffff, 4fffffff, 8fffffff, cfffffff */ + sprintf(final->line[0], " ub4 rsl = (val >> %ld);\n", (ub4)(UB4BITS-2)); + return; + } + } + + /* two instructions */ + for (i=final->lowbit; ihighbit; ++i) + { + if (((final->diffbits >> i) & 3) == 3) + { + w = (a>>i)&3; + x = (b>>i)&3; + y = (c>>i)&3; + z = (d>>i)&3; + if (testfour(w,x,y,z)) + { /* h4c: 0,2,4,6 */ + sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 3);\n", i); + return; + } + } + } + + /* three instructions (linear with the number of diffbits) */ + if ((final->diffbits & 3) != 0) + { + for (i=final->lowbit; i<=final->highbit; ++i) + { + if (((final->diffbits >> i) & 3) != 0) + { + w = (a+(a>>i))&3; + x = (b+(b>>i))&3; + y = (c+(c>>i))&3; + z = (d+(d>>i))&3; + if (testfour(w,x,y,z)) + { /* h4d: 0,1,2,4 */ + sprintf(final->line[0], + " ub4 rsl = ((val + (val >> %ld)) & 3);\n", i); + return; + } + + w = (a-(a>>i))&3; + x = (b-(b>>i))&3; + y = (c-(c>>i))&3; + z = (d-(d>>i))&3; + if (testfour(w,x,y,z)) + { /* h4e: 0,1,3,5 */ + sprintf(final->line[0], + " ub4 rsl = ((val - (val >> %ld)) & 3);\n", i); + return; + } + + /* h4f: ((val>>k)-val)&3: redundant with h4e */ + + w = (a^(a>>i))&3; + x = (b^(b>>i))&3; + y = (c^(c>>i))&3; + z = (d^(d>>i))&3; + if (testfour(w,x,y,z)) + { /* h4g: 3,4,5,8 */ + sprintf(final->line[0], + " ub4 rsl = ((val ^ (val >> %ld)) & 3);\n", i); + return; + } + } + } + } + + /* four instructions (linear with the number of diffbits) */ + if ((final->diffbits & 3) != 0) + { + for (i=final->lowbit; i<=final->highbit; ++i) + { + if ((((final->diffbits >> i) & 1) != 0) && + ((final->diffbits & 2) != 0)) + { + w = (a&3)^((a>>i)&1); + x = (b&3)^((b>>i)&1); + y = (c&3)^((c>>i)&1); + z = (d&3)^((d>>i)&1); + if (testfour(w,x,y,z)) + { /* h4h: 1,2,6,8 */ + sprintf(final->line[0], + " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 1));\n", i); + return; + } + + w = (a&2)^((a>>i)&1); + x = (b&2)^((b>>i)&1); + y = (c&2)^((c>>i)&1); + z = (d&2)^((d>>i)&1); + if (testfour(w,x,y,z)) + { /* h4i: 1,2,8,a */ + sprintf(final->line[0], + " ub4 rsl = ((val & 2) ^ ((val >> %ld) & 1));\n", i); + return; + } + } + + if ((((final->diffbits >> i) & 2) != 0) && + ((final->diffbits & 1) != 0)) + { + w = (a&3)^((a>>i)&2); + x = (b&3)^((b>>i)&2); + y = (c&3)^((c>>i)&2); + z = (d&3)^((d>>i)&2); + if (testfour(w,x,y,z)) + { /* h4j: 0,1,3,4 */ + sprintf(final->line[0], + " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 2));\n", i); + return; + } + + w = (a&1)^((a>>i)&2); + x = (b&1)^((b>>i)&2); + y = (c&1)^((c>>i)&2); + z = (d&1)^((d>>i)&2); + if (testfour(w,x,y,z)) + { /* h4k: 1,4,7,8 */ + sprintf(final->line[0], + " ub4 rsl = ((val & 1) ^ ((val >> %ld) & 2));\n", i); + return; + } + } + } + } + + /* four instructions (quadratic in the number of diffbits) */ + for (i=final->lowbit; i<=final->highbit; ++i) + { + if (((final->diffbits >> i) & 1) == 1) + { + for (j=final->lowbit; j<=final->highbit; ++j) + { + if (((final->diffbits >> j) & 3) != 0) + { + /* test + */ + w = ((a>>i)+(a>>j))&3; + x = ((b>>i)+(a>>j))&3; + y = ((c>>i)+(a>>j))&3; + z = ((d>>i)+(a>>j))&3; + if (testfour(w,x,y,z)) + { /* h4l: testcase? */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) + (val >> %ld)) & 3);\n", + i, j); + return; + } + + /* test - */ + w = ((a>>i)-(a>>j))&3; + x = ((b>>i)-(a>>j))&3; + y = ((c>>i)-(a>>j))&3; + z = ((d>>i)-(a>>j))&3; + if (testfour(w,x,y,z)) + { /* h4m: testcase? */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) - (val >> %ld)) & 3);\n", + i, j); + return; + } + + /* test ^ */ + w = ((a>>i)^(a>>j))&3; + x = ((b>>i)^(a>>j))&3; + y = ((c>>i)^(a>>j))&3; + z = ((d>>i)^(a>>j))&3; + if (testfour(w,x,y,z)) + { /* h4n: testcase? */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) ^ (val >> %ld)) & 3);\n", + i, j); + return; + } + } + } + } + } + + /* five instructions (quadratic in the number of diffbits) */ + for (i=final->lowbit; i<=final->highbit; ++i) + { + if (((final->diffbits >> i) & 1) != 0) + { + for (j=final->lowbit; j<=final->highbit; ++j) + { + if (((final->diffbits >> j) & 3) != 0) + { + w = ((a>>j)&3)^((a>>i)&1); + x = ((b>>j)&3)^((b>>i)&1); + y = ((c>>j)&3)^((c>>i)&1); + z = ((d>>j)&3)^((d>>i)&1); + if (testfour(w,x,y,z)) + { /* h4o: 0,4,8,a */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 1));\n", + j, i); + return; + } + + w = ((a>>j)&2)^((a>>i)&1); + x = ((b>>j)&2)^((b>>i)&1); + y = ((c>>j)&2)^((c>>i)&1); + z = ((d>>j)&2)^((d>>i)&1); + if (testfour(w,x,y,z)) + { /* h4p: 0x04, 0x08, 0x10, 0x14 */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) & 2) ^ ((val >> %ld) & 1));\n", + j, i); + return; + } + } + + if (i==0) + { + w = ((a>>j)^(a<<1))&3; + x = ((b>>j)^(b<<1))&3; + y = ((c>>j)^(c<<1))&3; + z = ((d>>j)^(d<<1))&3; + } + else + { + w = ((a>>j)&3)^((a>>(i-1))&2); + x = ((b>>j)&3)^((b>>(i-1))&2); + y = ((c>>j)&3)^((c>>(i-1))&2); + z = ((d>>j)&3)^((d>>(i-1))&2); + } + if (testfour(w,x,y,z)) + { + if (i==0) /* h4q: 0,4,5,8 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) ^ (val << 1)) & 3);\n", + j); + } + else if (i==1) /* h4r: 0x01,0x09,0x0b,0x10 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) & 3) ^ (val & 2));\n", + j); + } + else /* h4s: 0,2,6,8 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 2));\n", + j, (i-1)); + } + return; + } + + w = ((a>>j)&1)^((a>>i)&2); + x = ((b>>j)&1)^((b>>i)&2); + y = ((c>>j)&1)^((c>>i)&2); + z = ((d>>j)&1)^((d>>i)&2); + if (testfour(w,x,y,z)) /* h4t: 0x20,0x14,0x10,0x06 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) & 1) ^ ((val >> %ld) & 2));\n", + j, i); + return; + } + } + } + } + + /* + * OK, bring out the big guns. + * There exist three bits i,j,k which distinguish a,b,c,d. + * i^(j<<1)^(k*q) is guaranteed to work for some q in {0,1,2,3}, + * proven by exhaustive search of all (8 choose 4) cases. + * Find three such bits and try the 4 cases. + * Linear with the number of diffbits. + * Some cases below may duplicate some cases above. I did it that way + * so that what is below is guaranteed to work, no matter what was + * attempted above. + * The generated hash is at most 10 instructions. + */ + for (i=final->lowbit; i>i)&1; + z = (d>>i)&1; + if (y != z) + break; + } + + for (j=final->lowbit; j>i)&1)^(((b>>j)&1)<<1); + y = ((c>>i)&1)^(((c>>j)&1)<<1); + z = ((d>>i)&1)^(((d>>j)&1)<<1); + if (x != y && x != z && y != z) + break; + } + + for (k=final->lowbit; k>i)&1)^(((a>>j)&1)<<1)^(((a>>k)&1)<<2); + x = ((b>>i)&1)^(((b>>j)&1)<<1)^(((b>>k)&1)<<2); + y = ((c>>i)&1)^(((c>>j)&1)<<1)^(((c>>k)&1)<<2); + z = ((d>>i)&1)^(((d>>j)&1)<<1)^(((d>>k)&1)<<2); + if (w != x && w != y && w != z && x != y && x != z && y != z) + break; + } + + /* Assert: bits i,j,k were found which distinguish a,b,c,d */ + if (i==UB4BITS || j==UB4BITS || k==UB4BITS) + { + printf("Fatal error: hexfour(), i %ld j %ld k %ld\n", i,j,k); + exit(SUCCESS); + } + + /* now try the four cases */ + { + ub4 m,n,o,p; + + /* if any bit has two 1s and two 0s, make that bit o */ + if (((a>>i)&1)+((b>>i)&1)+((c>>i)&1)+((d>>i)&1) != 2) + { m=j; n=k; o=i; } + else if (((a>>j)&1)+((b>>j)&1)+((c>>j)&1)+((d>>j)&1) != 2) + { m=i; n=k; o=j; } + else + { m=i; n=j; o=k; } + if (m > n) {p=m; m=n; n=p; } /* guarantee m < n */ + + /* printf("m %ld n %ld o %ld %ld %ld %ld %ld\n", m, n, o, w,x,y,z); */ + + /* seven instructions, multiply bit o by 1 */ + w = (((a>>m)^(a>>o))&1)^((a>>(n-1))&2); + x = (((b>>m)^(b>>o))&1)^((b>>(n-1))&2); + y = (((c>>m)^(c>>o))&1)^((c>>(n-1))&2); + z = (((d>>m)^(d>>o))&1)^((d>>(n-1))&2); + if (testfour(w,x,y,z)) + { + if (m>o) {p=m; m=o; o=p;} /* make sure m < o and m < n */ + + if (m==0) /* 0,2,8,9 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val^(val>>%ld))&1)^((val>>%ld)&2));\n", o, n-1); + } + else /* 0x00,0x04,0x10,0x12 */ + { + sprintf(final->line[0], + " ub4 rsl = ((((val>>%ld) ^ (val>>%ld)) & 1) ^ ((val>>%ld) & 2));\n", + m, o, n-1); + } + return; + } + + /* six to seven instructions, multiply bit o by 2 */ + w = ((a>>m)&1)^((((a>>n)^(a>>o))&1)<<1); + x = ((b>>m)&1)^((((b>>n)^(b>>o))&1)<<1); + y = ((c>>m)&1)^((((c>>n)^(c>>o))&1)<<1); + z = ((d>>m)&1)^((((d>>n)^(d>>o))&1)<<1); + if (testfour(w,x,y,z)) + { + if (m==o-1) {p=n; n=o; o=p;} /* make m==n-1 if possible */ + + if (m==0) /* 0,1,5,8 */ + { + sprintf(final->line[0], + " ub4 rsl = ((val & 1) ^ (((val>>%ld) ^ (val>>%ld)) & 2));\n", + n-1, o-1); + } + else if (o==0) /* 0x00,0x04,0x05,0x10 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val>>%ld) & 2) ^ (((val>>%ld) ^ val) & 1));\n", + m-1, n); + } + else /* 0x00,0x02,0x0a,0x10 */ + { + sprintf(final->line[0], + " ub4 rsl = (((val>>%ld) & 1) ^ (((val>>%ld) ^ (val>>%ld)) & 2));\n", + m, n-1, o-1); + } + return; + } + + /* multiplying by 3 is a pain: seven or eight instructions */ + w = (((a>>m)&1)^((a>>(n-1))&2))^((a>>o)&1)^(((a>>o)&1)<<1); + x = (((b>>m)&1)^((b>>(n-1))&2))^((b>>o)&1)^(((b>>o)&1)<<1); + y = (((c>>m)&1)^((c>>(n-1))&2))^((c>>o)&1)^(((c>>o)&1)<<1); + z = (((d>>m)&1)^((d>>(n-1))&2))^((d>>o)&1)^(((d>>o)&1)<<1); + if (testfour(w,x,y,z)) + { + final->used = 2; + sprintf(final->line[0], " ub4 b = (val >> %ld) & 1;\n", o); + if (m==o-1 && m==0) /* 0x02,0x10,0x11,0x18 */ + { + sprintf(final->line[1], + " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 2) ^ b);\n", n-1); + } + else if (m==o-1) /* 0,4,6,c */ + { + sprintf(final->line[1], + " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 2) ^ b);\n", + m, n-1); + } + else if (m==n-1 && m==0) /* 02,0a,0b,18 */ + { + sprintf(final->line[1], + " ub4 rsl = ((val & 3) ^ b ^ (b << 1));\n"); + } + else if (m==n-1) /* 0,2,4,8 */ + { + sprintf(final->line[1], + " ub4 rsl = (((val >> %ld) & 3) ^ b ^ (b << 1));\n", m); + } + else if (o==n-1 && m==0) /* h4am: not reached */ + { + sprintf(final->line[1], + " ub4 rsl = ((val & 1) ^ ((val >> %ld) & 3) ^ (b <<1 ));\n", + o); + } + else if (o==n-1) /* 0x00,0x02,0x08,0x10 */ + { + sprintf(final->line[1], + " ub4 rsl = (((val >> %ld) & 1) ^ ((val >> %ld) & 3) ^ (b << 1));\n", + m, o); + } + else if ((m != o-1) && (m != n-1) && (o != m-1) && (o != n-1)) + { + final->used = 3; + sprintf(final->line[0], " ub4 newval = val & 0x%lx;\n", + (((ub4)1<line[1], " ub4 b = -newval;\n"); + } + else /* 0x00,0x04,0x09,0x10 */ + { + sprintf(final->line[1], " ub4 b = -(newval >> %ld);\n", o); + } + if (m==0) /* 0x00,0x04,0x09,0x10 */ + { + sprintf(final->line[2], + " ub4 rsl = ((newval ^ (newval>>%ld) ^ b) & 3);\n", n-1); + } + else /* 0x00,0x03,0x04,0x10 */ + { + sprintf(final->line[2], + " ub4 rsl = (((newval>>%ld) ^ (newval>>%ld) ^ b) & 3);\n", + m, n-1); + } + } + else if (o == m-1) + { + if (o==0) /* 0x02,0x03,0x0a,0x10 */ + { + sprintf(final->line[0], " ub4 b = (val<<1) & 2;\n"); + } + else if (o==1) /* 0x00,0x02,0x04,0x10 */ + { + sprintf(final->line[0], " ub4 b = val & 2;\n"); + } + else /* 0x00,0x04,0x08,0x20 */ + { + sprintf(final->line[0], " ub4 b = (val>>%ld) & 2;\n", o-1); + } + + if (o==0) /* 0x02,0x03,0x0a,0x10 */ + { + sprintf(final->line[1], + " ub4 rsl = ((val & 3) ^ ((val>>%ld) & 1) ^ b);\n", + n); + } + else /* 0x00,0x02,0x04,0x10 */ + { + sprintf(final->line[1], + " ub4 rsl = (((val>>%ld) & 3) ^ ((val>>%ld) & 1) ^ b);\n", + o, n); + } + } + else /* h4ax: 10 instructions, but not reached */ + { + sprintf(final->line[1], + " ub4 rsl = (((val>>%ld) & 1) ^ ((val>>%ld) & 2) ^ b ^ (b<<1));\n", + m, n-1); + } + + return; + } + + /* five instructions, multiply bit o by 0, covered before the big guns */ + w = ((a>>m)&1)^(a>>(n-1)&2); + x = ((b>>m)&1)^(b>>(n-1)&2); + y = ((c>>m)&1)^(c>>(n-1)&2); + z = ((d>>m)&1)^(d>>(n-1)&2); + if (testfour(w,x,y,z)) + { /* h4v, not reached */ + sprintf(final->line[0], + " ub4 rsl = (((val>>%ld) & 1) ^ ((val>>%ld) & 2));\n", m, n-1); + return; + } + } + + printf("fatal error: bug in hexfour!\n"); + exit(SUCCESS); + return; +} + + +/* test if a_k is distinct and in range for all keys */ +static int testeight(keys, badmask) +key *keys; /* keys being hashed */ +ub1 badmask; /* used for minimal perfect hashing */ +{ + ub1 mask = badmask; + key *mykey; + + for (mykey=keys; mykey; mykey=mykey->next_k) + { + if (bit(mask, 1<a_k)) return FALSE; + bis(mask, 1<a_k); + } + return TRUE; +} + + + +/* + * Try to find a perfect hash when there are five to eight keys. + * + * We can't deterministically find a perfect hash, but there's a reasonable + * chance we'll get lucky. Give it a shot. Return TRUE if we succeed. + */ +static int hexeight(keys, nkeys, final, form) +key *keys; +ub4 nkeys; +gencode *final; +hashform *form; +{ + key *mykey; /* walk through the keys */ + ub4 i,j,k; + ub1 badmask; + + printf("hexeight\n"); + + /* what hash values should never be used? */ + badmask = 0; + if (form->perfect == MINIMAL_HP) + { + for (i=nkeys; i<8; ++i) + bis(badmask,(1<next_k) + mykey->a_k = mykey->hash_k & 7; + if (testeight(keys, badmask)) + { /* h8a */ + final->used = 1; + sprintf(final->line[0], " ub4 rsl = (val & 7);\n"); + return TRUE; + } + + /* two instructions */ + for (i=final->lowbit; i<=final->highbit-2; ++i) + { + for (mykey=keys; mykey; mykey=mykey->next_k) + mykey->a_k = (mykey->hash_k >> i) & 7; + if (testeight(keys, badmask)) + { /* h8b */ + final->used = 1; + sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 7);\n", i); + return TRUE; + } + } + + /* four instructions */ + for (i=final->lowbit; i<=final->highbit; ++i) + { + for (j=i+1; j<=final->highbit; ++j) + { + for (mykey=keys; mykey; mykey=mykey->next_k) + mykey->a_k = ((mykey->hash_k >> i)+(mykey->hash_k >> j)) & 7; + if (testeight(keys, badmask)) + { + final->used = 1; + if (i == 0) /* h8c */ + sprintf(final->line[0], + " ub4 rsl = ((val + (val >> %ld)) & 7);\n", j); + else /* h8d */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) + (val >> %ld)) & 7);\n", i, j); + return TRUE; + } + + for (mykey=keys; mykey; mykey=mykey->next_k) + mykey->a_k = ((mykey->hash_k >> i)^(mykey->hash_k >> j)) & 7; + if (testeight(keys, badmask)) + { + final->used = 1; + if (i == 0) /* h8e */ + sprintf(final->line[0], + " ub4 rsl = ((val ^ (val >> %ld)) & 7);\n", j); + else /* h8f */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) ^ (val >> %ld)) & 7);\n", i, j); + + return TRUE; + } + + for (mykey=keys; mykey; mykey=mykey->next_k) + mykey->a_k = ((mykey->hash_k >> i)-(mykey->hash_k >> j)) & 7; + if (testeight(keys, badmask)) + { + final->used = 1; + if (i == 0) /* h8g */ + sprintf(final->line[0], + " ub4 rsl = ((val - (val >> %ld)) & 7);\n", j); + else /* h8h */ + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) - (val >> %ld)) & 7);\n", i, j); + + return TRUE; + } + } + } + + + /* six instructions */ + for (i=final->lowbit; i<=final->highbit; ++i) + { + for (j=i+1; j<=final->highbit; ++j) + { + for (k=j+1; k<=final->highbit; ++k) + { + for (mykey=keys; mykey; mykey=mykey->next_k) + mykey->a_k = ((mykey->hash_k >> i) + + (mykey->hash_k >> j) + + (mykey->hash_k >> k)) & 7; + if (testeight(keys, badmask)) + { /* h8i */ + final->used = 1; + sprintf(final->line[0], + " ub4 rsl = (((val >> %ld) + (val >> %ld) + (val >> %ld)) & 7);\n", + i, j, k); + return TRUE; + } + } + } + } + + + return FALSE; +} + + + +/* + * Guns aren't enough. Bring out the Bomb. Use tab[]. + * This finds the initial (a,b) when we need to use tab[]. + * + * We need to produce a different (a,b) every time this is called. Try all + * reasonable cases, fastest first. + * + * The initial mix (which this determines) can be filled into final starting + * at line[1]. val is set and a,b are declared. The final hash (at line[7]) + * is a^tab[b] or a^scramble[tab[b]]. + * + * The code will probably look like this, minus some stuff: + * val += CONSTANT; + * val ^= (val<<16); + * val += (val>>8); + * val ^= (val<<4); + * b = (val >> l) & 7; + * a = (val + (val<> 29; + * return a^scramble[tab[b]]; + * Note that *a* and tab[b] will be computed in parallel by most modern chips. + * + * final->i is the current state of the state machine. + * final->j and final->k are counters in the loops the states simulate. + */ +static void hexn(keys, salt, alen, blen, final) +key *keys; +ub4 salt; +ub4 alen; +ub4 blen; +gencode *final; +{ + key *mykey; + ub4 highbit = final->highbit; + ub4 lowbit = final->lowbit; + ub4 alog = mylog2(alen); + ub4 blog = mylog2(blen); + + for (;;) + { + switch(final->i) + { + case 1: + /* a = val>>30; b=val&3 */ + for (mykey=keys; mykey; mykey=mykey->next_k) + { + mykey->a_k = (mykey->hash_k << (UB4BITS-(highbit+1)))>>(UB4BITS-alog); + mykey->b_k = (mykey->hash_k >> lowbit) & (blen-1); + } + if (lowbit == 0) /* hna */ + sprintf(final->line[5], " b = (val & 0x%lx);\n", + blen-1); + else /* hnb */ + sprintf(final->line[5], " b = ((val >> %ld) & 0x%lx);\n", + lowbit, blen-1); + if (highbit+1 == UB4BITS) /* hnc */ + sprintf(final->line[6], " a = (val >> %ld);\n", + UB4BITS-alog); + else /* hnd */ + sprintf(final->line[6], " a = ((val << %ld ) >> %ld);\n", + UB4BITS-(highbit+1), UB4BITS-alog); + + ++final->i; + return; + + case 2: + /* a = val&3; b=val>>30 */ + for (mykey=keys; mykey; mykey=mykey->next_k) + { + mykey->a_k = (mykey->hash_k >> lowbit) & (alen-1); + mykey->b_k = (mykey->hash_k << (UB4BITS-(highbit+1)))>>(UB4BITS-blog); + } + if (highbit+1 == UB4BITS) /* hne */ + sprintf(final->line[5], " b = (val >> %ld);\n", + UB4BITS-blog); + else /* hnf */ + sprintf(final->line[5], " b = ((val << %ld ) >> %ld);\n", + UB4BITS-(highbit+1), UB4BITS-blog); + if (lowbit == 0) /* hng */ + sprintf(final->line[6], " a = (val & 0x%lx);\n", + alen-1); + else /* hnh */ + sprintf(final->line[6], " a = ((val >> %ld) & 0x%lx);\n", + lowbit, alen-1); + + ++final->i; + return; + + case 3: + /* + * cases 3,4,5: + * for (k=lowbit; k<=highbit; ++k) + * for (j=lowbit; j<=highbit; ++j) + * b = (val>>j)&3; + * a = (val<>30; + */ + final->k = lowbit; + final->j = lowbit; + ++final->i; + break; + + case 4: + if (!(final->j < highbit)) + { + ++final->i; + break; + } + for (mykey=keys; mykey; mykey=mykey->next_k) + { + mykey->b_k = (mykey->hash_k >> (final->j)) & (blen-1); + mykey->a_k = (mykey->hash_k << (UB4BITS-final->k-1)) >> (UB4BITS-alog); + } + if (final->j == 0) /* hni */ + sprintf(final->line[5], " b = val & 0x%lx;\n", + blen-1); + else if (blog+final->j == UB4BITS) /* hnja */ + sprintf(final->line[5], " b = val >> %ld;\n", + final->j); + else + sprintf(final->line[5], " b = (val >> %ld) & 0x%lx;\n", /* hnj */ + final->j, blen-1); + if (UB4BITS-final->k-1 == 0) /* hnk */ + sprintf(final->line[6], " a = (val >> %ld);\n", + UB4BITS-alog); + else /* hnl */ + sprintf(final->line[6], " a = ((val << %ld) >> %ld);\n", + UB4BITS-final->k-1, UB4BITS-alog); + while (++final->j < highbit) + { + if (((final->diffbits>>(final->j)) & (blen-1)) > 2) + break; + } + return; + + case 5: + while (++final->k < highbit) + { + if ((((final->diffbits<<(UB4BITS-final->k-1))>>alog) & (alen-1)) > 0) + break; + } + if (!(final->k < highbit)) + { + ++final->i; + break; + } + final->j = lowbit; + final->i = 4; + break; + + + case 6: + /* + * cases 6,7,8: + * for (k=0; k> 16); + * val += (val << 8); + * val ^= (val >> 4); + * b = (val >> j) & 3; + * a = (val + (val << k)) >> 30; + */ + final->k = 0; + final->j = 0; + ++final->i; + break; + + case 7: + /* Just do something that will surely work */ + { + ub4 addk = 0x9e3779b9*salt; + + if (!(final->j <= UB4BITS-blog)) + { + ++final->i; + break; + } + for (mykey=keys; mykey; mykey=mykey->next_k) + { + ub4 val = mykey->hash_k + addk; + if (final->highbit+1 - final->lowbit > 16) + val ^= (val >> 16); + if (final->highbit+1 - final->lowbit > 8) + val += (val << 8); + val ^= (val >> 4); + mykey->b_k = (val >> final->j) & (blen-1); + if (final->k == 0) + mykey->a_k = val >> (UB4BITS-alog); + else + mykey->a_k = (val + (val << final->k)) >> (UB4BITS-alog); + } + sprintf(final->line[1], " val += 0x%lx;\n", addk); + if (final->highbit+1 - final->lowbit > 16) /* hnm */ + sprintf(final->line[2], " val ^= (val >> 16);\n"); + if (final->highbit+1 - final->lowbit > 8) /* hnn */ + sprintf(final->line[3], " val += (val << 8);\n"); + sprintf(final->line[4], " val ^= (val >> 4);\n"); + if (final->j == 0) /* hno: don't know how to reach this */ + sprintf(final->line[5], " b = val & 0x%lx;\n", blen-1); + else /* hnp */ + sprintf(final->line[5], " b = (val >> %ld) & 0x%lx;\n", + final->j, blen-1); + if (final->k == 0) /* hnq */ + sprintf(final->line[6], " a = val >> %ld;\n", UB4BITS-alog); + else /* hnr */ + sprintf(final->line[6], " a = (val + (val << %ld)) >> %ld;\n", + final->k, UB4BITS-alog); + + ++final->j; + return; + } + + case 8: + ++final->k; + if (!(final->k <= UB4BITS-alog)) + { + ++final->i; + break; + } + final->j = 0; + final->i = 7; + break; + + case 9: + final->i = 6; + break; + } + } +} + + + +/* find the highest and lowest bit where any key differs */ +static void setlow(keys, final) +key *keys; +gencode *final; +{ + ub4 lowbit; + ub4 highbit; + ub4 i; + key *mykey; + ub4 firstkey; + + /* mark the interesting bits in final->mask */ + final->diffbits = (ub4)0; + if (keys) firstkey = keys->hash_k; + for (mykey=keys; mykey!=(key *)0; mykey=mykey->next_k) + final->diffbits |= (firstkey ^ mykey->hash_k); + + /* find the lowest interesting bit */ + for (i=0; idiffbits & (((ub4)1)<lowbit = i; + + /* find the highest interesting bit */ + for (i=UB4BITS; --i; ) + if (final->diffbits & (((ub4)1)<highbit = i; +} + +/* + * Initialize (a,b) when keys are integers. + * + * Normally there's an initial hash which produces a number. That hash takes + * an initializer. Changing the initializer causes the initial hash to + * produce a different (uniformly distributed) number without any extra work. + * + * Well, here we start with a number. There's no initial hash. Any mixing + * costs extra work. So we go through a lot of special cases to minimize the + * mixing needed to get distinct (a,b). For small sets of keys, it's often + * fastest to skip the final hash and produce the perfect hash from the number + * directly. + * + * The target user for this is switch statement optimization. The common case + * is 3 to 16 keys, and instruction counts matter. The competition is a + * binary tree of branches. + * + * Return TRUE if we found a perfect hash and no more work is needed. + * Return FALSE if we just did an initial hash and more work is needed. + */ +int inithex(keys, nkeys, alen, blen, smax, salt, final, form) +key *keys; /* list of all keys */ +ub4 nkeys; /* number of keys to hash */ +ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ +ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ +ub4 smax; /* maximum range of computable hash values */ +ub4 salt; /* used to initialize the hash function */ +gencode *final; /* output, code for the final hash */ +hashform *form; /* user directives */ +{ + setlow(keys, final); + + switch (nkeys) + { + case 1: + hexone(keys, final); + return TRUE; + case 2: + hextwo(keys, final); + return TRUE; + case 3: + hexthree(keys, final, form); + return TRUE; + case 4: + hexfour(keys, final); + return TRUE; + case 5: case 6: case 7: case 8: + if (salt == 1 && /* first time through */ + hexeight(keys, nkeys, final, form)) /* get lucky, don't need tab[] ? */ + return TRUE; + /* fall through */ + default: + if (salt == 1) + { + final->used = 8; + final->i = 1; + final->j = final->k = final->l = final->m = final->n = final->o = 0; + sprintf(final->line[0], " ub4 a, b, rsl;\n"); + sprintf(final->line[1], "\n"); + sprintf(final->line[2], "\n"); + sprintf(final->line[3], "\n"); + sprintf(final->line[4], "\n"); + sprintf(final->line[5], "\n"); + sprintf(final->line[6], "\n"); + if (blen < USE_SCRAMBLE) + { /* hns */ + sprintf(final->line[7], " rsl = (a^tab[b]);\n"); + } + else + { /* hnt */ + sprintf(final->line[7], " rsl = (a^scramble[tab[b]]);\n"); + } + } + hexn(keys, salt, alen, blen, final); + return FALSE; + } +} diff --git a/tools/codegen/core/perfect/recycle.c b/tools/codegen/core/perfect/recycle.c new file mode 100644 index 00000000000..3f857cba7d2 --- /dev/null +++ b/tools/codegen/core/perfect/recycle.c @@ -0,0 +1,87 @@ +/* +-------------------------------------------------------------------- +By Bob Jenkins, September 1996. recycle.c +You may use this code in any way you wish, and it is free. No warranty. + +This manages memory for commonly-allocated structures. +It allocates RESTART to REMAX items at a time. +Timings have shown that, if malloc is used for every new structure, + malloc will consume about 90% of the time in a program. This + module cuts down the number of mallocs by an order of magnitude. +This also decreases memory fragmentation, and freeing structures + only requires freeing the root. +-------------------------------------------------------------------- +*/ + +#ifndef STANDARD +# include "standard.h" +#endif +#ifndef RECYCLE +# include "recycle.h" +#endif + +reroot *remkroot(size) +size_t size; +{ + reroot *r = (reroot *)remalloc(sizeof(reroot), "recycle.c, root"); + r->list = (recycle *)0; + r->trash = (recycle *)0; + r->size = align(size); + r->logsize = RESTART; + r->numleft = 0; + return r; +} + +void refree(r) +struct reroot *r; +{ + recycle *temp; + if (temp = r->list) while (r->list) + { + temp = r->list->next; + free((char *)r->list); + r->list = temp; + } + free((char *)r); + return; +} + +/* to be called from the macro renew only */ +char *renewx(r) +struct reroot *r; +{ + recycle *temp; + if (r->trash) + { /* pull a node off the trash heap */ + temp = r->trash; + r->trash = temp->next; + (void)memset((void *)temp, 0, r->size); + } + else + { /* allocate a new block of nodes */ + r->numleft = r->size*((ub4)1<logsize); + if (r->numleft < REMAX) ++r->logsize; + temp = (recycle *)remalloc(sizeof(recycle) + r->numleft, + "recycle.c, data"); + temp->next = r->list; + r->list = temp; + r->numleft-=r->size; + temp = (recycle *)((char *)(r->list+1)+r->numleft); + } + return (char *)temp; +} + +char *remalloc(len, purpose) +size_t len; +char *purpose; +{ + char *x = (char *)malloc(len); + if (!x) + { + fprintf(stderr, "malloc of %d failed for %s\n", + len, purpose); + exit(SUCCESS); + } + return x; +} + diff --git a/tools/codegen/core/perfect/recycle.h b/tools/codegen/core/perfect/recycle.h new file mode 100644 index 00000000000..7472495e848 --- /dev/null +++ b/tools/codegen/core/perfect/recycle.h @@ -0,0 +1,65 @@ +/* +-------------------------------------------------------------------- +By Bob Jenkins, September 1996. recycle.h +You may use this code in any way you wish, and it is free. No warranty. + +This manages memory for commonly-allocated structures. +It allocates RESTART to REMAX items at a time. +Timings have shown that, if malloc is used for every new structure, + malloc will consume about 90% of the time in a program. This + module cuts down the number of mallocs by an order of magnitude. +This also decreases memory fragmentation, and freeing all structures + only requires freeing the root. +-------------------------------------------------------------------- +*/ + +#ifndef STANDARD +#include "standard.h" +#endif + +#ifndef RECYCLE +#define RECYCLE + +#define RESTART 0 +#define REMAX 32000 + +struct recycle +{ + struct recycle *next; +}; +typedef struct recycle recycle; + +struct reroot +{ + struct recycle *list; /* list of malloced blocks */ + struct recycle *trash; /* list of deleted items */ + size_t size; /* size of an item */ + size_t logsize; /* log_2 of number of items in a block */ + word numleft; /* number of bytes left in this block */ +}; +typedef struct reroot reroot; + +/* make a new recycling root */ +reroot *remkroot(/*_ size_t mysize _*/); + +/* free a recycling root and all the items it has made */ +void refree(/*_ struct reroot *r _*/); + +/* get a new (cleared) item from the root */ +#define renew(r) ((r)->numleft ? \ + (((char *)((r)->list+1))+((r)->numleft-=(r)->size)) : renewx(r)) + +char *renewx(/*_ struct reroot *r _*/); + +/* delete an item; let the root recycle it */ +/* void redel(/o_ struct reroot *r, struct recycle *item _o/); */ +#define redel(root,item) { \ + ((recycle *)item)->next=(root)->trash; \ + (root)->trash=(recycle *)(item); \ +} + +/* malloc, but complain to stderr and exit program if no joy */ +/* use plain free() to free memory allocated by remalloc() */ +char *remalloc(/*_ size_t len, char *purpose _*/); + +#endif /* RECYCLE */ diff --git a/tools/codegen/core/perfect/run.sh b/tools/codegen/core/perfect/run.sh new file mode 100755 index 00000000000..8dc5911cbdf --- /dev/null +++ b/tools/codegen/core/perfect/run.sh @@ -0,0 +1,7 @@ +#!/bin/bash +set -e +cd $(dirname $0) +gcc -o perfect perfect.c recycle.c lookupa.c perfhex.c 2> compile.txt +fn=$1 +shift +./perfect $* < $fn &> hash.txt diff --git a/tools/codegen/core/perfect/standard.h b/tools/codegen/core/perfect/standard.h new file mode 100644 index 00000000000..202a5d658c5 --- /dev/null +++ b/tools/codegen/core/perfect/standard.h @@ -0,0 +1,57 @@ +/* +------------------------------------------------------------------------------ +Standard definitions and types, Bob Jenkins +------------------------------------------------------------------------------ +*/ +#ifndef STANDARD +# define STANDARD +# ifndef STDIO +# include +# define STDIO +# endif +# ifndef STDDEF +# include +# define STDDEF +# endif +typedef unsigned long long ub8; +#define UB8MAXVAL 0xffffffffffffffffLL +#define UB8BITS 64 +typedef signed long long sb8; +#define SB8MAXVAL 0x7fffffffffffffffLL +typedef unsigned long int ub4; /* unsigned 4-byte quantities */ +#define UB4MAXVAL 0xffffffff +typedef signed long int sb4; +#define UB4BITS 32 +#define SB4MAXVAL 0x7fffffff +typedef unsigned short int ub2; +#define UB2MAXVAL 0xffff +#define UB2BITS 16 +typedef signed short int sb2; +#define SB2MAXVAL 0x7fff +typedef unsigned char ub1; +#define UB1MAXVAL 0xff +#define UB1BITS 8 +typedef signed char sb1; /* signed 1-byte quantities */ +#define SB1MAXVAL 0x7f +typedef int word; /* fastest type available */ + +#define bis(target,mask) ((target) |= (mask)) +#define bic(target,mask) ((target) &= ~(mask)) +#define bit(target,mask) ((target) & (mask)) +#ifndef min +# define min(a,b) (((a)<(b)) ? (a) : (b)) +#endif /* min */ +#ifndef max +# define max(a,b) (((a)<(b)) ? (b) : (a)) +#endif /* max */ +#ifndef align +# define align(a) (((ub4)a+(sizeof(void *)-1))&(~(sizeof(void *)-1))) +#endif /* align */ +#ifndef abs +# define abs(a) (((a)>0) ? (a) : -(a)) +#endif +#define TRUE 1 +#define FALSE 0 +#define SUCCESS 0 /* 1 on VAX */ + +#endif /* STANDARD */ From e52bbb1d014bf1685ef4045e19c24a70b6d47ec3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Nov 2016 15:34:06 -0800 Subject: [PATCH 010/261] Initial elimination of grpc_mdstr from metadata.{h,c} --- include/grpc/slice.h | 2 + src/core/lib/slice/slice_traits.h | 44 ++ src/core/lib/transport/metadata.c | 401 ++---------------- src/core/lib/transport/metadata.h | 58 +-- src/core/lib/transport/static_metadata.c | 475 +++++++++++++++++----- src/core/lib/transport/static_metadata.h | 192 ++++----- tools/codegen/core/gen_static_metadata.py | 106 ++++- 7 files changed, 666 insertions(+), 612 deletions(-) create mode 100644 src/core/lib/slice/slice_traits.h diff --git a/include/grpc/slice.h b/include/grpc/slice.h index b5894a103c1..53a650f3995 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -127,6 +127,8 @@ GPRAPI grpc_slice gpr_empty_slice(void); GPRAPI int grpc_slice_cmp(grpc_slice a, grpc_slice b); GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b); +GPRAPI uint32_t grpc_slice_hash(grpc_slice s); + #ifdef __cplusplus } #endif diff --git a/src/core/lib/slice/slice_traits.h b/src/core/lib/slice/slice_traits.h new file mode 100644 index 00000000000..facbd0dd812 --- /dev/null +++ b/src/core/lib/slice/slice_traits.h @@ -0,0 +1,44 @@ +/* + * + * 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 SLICE_TRAITS_H +#define SLICE_TRAITS_H + +#include +#include + +bool grpc_slice_is_legal_header(grpc_slice s); +bool grpc_slice_is_legal_nonbin_header(grpc_slice s); +bool grpc_slice_is_bin_suffixed(grpc_slice s); + +#endif diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 9b5d8099c71..c0743e124a5 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -52,8 +52,6 @@ #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" -grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)(grpc_slice input); - /* There are two kinds of mdelem and mdstr instances. * Static instances are declared in static_metadata.{h,c} and * are initialized by grpc_mdctx_global_init(). @@ -63,9 +61,6 @@ grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)(grpc_slice input); * used to determine which kind of element a pointer refers to. */ -#define INITIAL_STRTAB_CAPACITY 4 -#define INITIAL_MDTAB_CAPACITY 4 - #ifdef GRPC_METADATA_REFCOUNT_DEBUG #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line @@ -76,37 +71,20 @@ grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)(grpc_slice input); #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s)) #endif -#define TABLE_IDX(hash, log2_shards, capacity) \ - (((hash) >> (log2_shards)) % (capacity)) -#define SHARD_IDX(hash, log2_shards) ((hash) & ((1 << (log2_shards)) - 1)) - -typedef void (*destroy_user_data_func)(void *user_data); - -#define SIZE_IN_DECODER_TABLE_NOT_SET -1 -/* Shadow structure for grpc_mdstr for non-static values */ -typedef struct internal_string { - /* must be byte compatible with grpc_mdstr */ - grpc_slice slice; - uint32_t hash; +#define INITIAL_SHARD_CAPACITY 8 +#define LOG2_SHARD_COUNT 4 +#define SHARD_COUNT ((size_t)(1 << LOG2_SHARD_COUNT)) - /* private only data */ - gpr_atm refcnt; +#define TABLE_IDX(hash, capacity) (((hash) >> (LOG2_SHARD_COUNT)) % (capacity)) +#define SHARD_IDX(hash) ((hash) & ((1 << (LOG2_SHARD_COUNT)) - 1)) - uint8_t has_base64_and_huffman_encoded; - grpc_slice_refcount refcount; - - grpc_slice base64_and_huffman; - - gpr_atm size_in_decoder_table; - - struct internal_string *bucket_next; -} internal_string; +typedef void (*destroy_user_data_func)(void *user_data); /* Shadow structure for grpc_mdelem for non-static elements */ typedef struct internal_metadata { /* must be byte compatible with grpc_mdelem */ - internal_string *key; - internal_string *value; + grpc_slice key; + grpc_slice value; /* private only data */ gpr_atm refcnt; @@ -118,13 +96,6 @@ typedef struct internal_metadata { struct internal_metadata *bucket_next; } internal_metadata; -typedef struct strtab_shard { - gpr_mu mu; - internal_string **strs; - size_t count; - size_t capacity; -} strtab_shard; - typedef struct mdtab_shard { gpr_mu mu; internal_metadata **elems; @@ -136,23 +107,16 @@ typedef struct mdtab_shard { gpr_atm free_estimate; } mdtab_shard; -#define LOG2_STRTAB_SHARD_COUNT 5 -#define LOG2_MDTAB_SHARD_COUNT 4 -#define STRTAB_SHARD_COUNT ((size_t)(1 << LOG2_STRTAB_SHARD_COUNT)) -#define MDTAB_SHARD_COUNT ((size_t)(1 << LOG2_MDTAB_SHARD_COUNT)) - /* hash seed: decided at initialization time */ static uint32_t g_hash_seed; static int g_forced_hash_seed = 0; /* linearly probed hash tables for static element lookup */ -static grpc_mdstr *g_static_strtab[GRPC_STATIC_MDSTR_COUNT * 2]; static grpc_mdelem *g_static_mdtab[GRPC_STATIC_MDELEM_COUNT * 2]; static size_t g_static_strtab_maxprobe; static size_t g_static_mdtab_maxprobe; -static strtab_shard g_strtab_shard[STRTAB_SHARD_COUNT]; -static mdtab_shard g_mdtab_shard[MDTAB_SHARD_COUNT]; +static mdtab_shard g_shards[SHARD_COUNT]; static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard); @@ -162,12 +126,13 @@ void grpc_test_only_set_metadata_hash_seed(uint32_t seed) { } void grpc_mdctx_global_init(void) { - size_t i, j; + size_t i; if (!g_forced_hash_seed) { g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; } g_static_strtab_maxprobe = 0; g_static_mdtab_maxprobe = 0; +#if 0 /* build static tables */ memset(g_static_mdtab, 0, sizeof(g_static_mdtab)); memset(g_static_strtab, 0, sizeof(g_static_strtab)); @@ -208,21 +173,14 @@ void grpc_mdctx_global_init(void) { g_static_mdtab_maxprobe = j; } } +#endif /* initialize shards */ - for (i = 0; i < STRTAB_SHARD_COUNT; i++) { - strtab_shard *shard = &g_strtab_shard[i]; - gpr_mu_init(&shard->mu); - shard->count = 0; - shard->capacity = INITIAL_STRTAB_CAPACITY; - shard->strs = gpr_malloc(sizeof(*shard->strs) * shard->capacity); - memset(shard->strs, 0, sizeof(*shard->strs) * shard->capacity); - } - for (i = 0; i < MDTAB_SHARD_COUNT; i++) { - mdtab_shard *shard = &g_mdtab_shard[i]; + for (i = 0; i < SHARD_COUNT; i++) { + mdtab_shard *shard = &g_shards[i]; gpr_mu_init(&shard->mu); shard->count = 0; gpr_atm_no_barrier_store(&shard->free_estimate, 0); - shard->capacity = INITIAL_MDTAB_CAPACITY; + shard->capacity = INITIAL_SHARD_CAPACITY; shard->elems = gpr_malloc(sizeof(*shard->elems) * shard->capacity); memset(shard->elems, 0, sizeof(*shard->elems) * shard->capacity); } @@ -230,8 +188,8 @@ void grpc_mdctx_global_init(void) { void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { size_t i; - for (i = 0; i < MDTAB_SHARD_COUNT; i++) { - mdtab_shard *shard = &g_mdtab_shard[i]; + for (i = 0; i < SHARD_COUNT; i++) { + mdtab_shard *shard = &g_shards[i]; gpr_mu_destroy(&shard->mu); gc_mdtab(exec_ctx, shard); /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ @@ -244,30 +202,6 @@ void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { } gpr_free(shard->elems); } - for (i = 0; i < STRTAB_SHARD_COUNT; i++) { - strtab_shard *shard = &g_strtab_shard[i]; - gpr_mu_destroy(&shard->mu); - /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ - if (shard->count != 0) { - gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata strings were leaked", - shard->count); - for (size_t j = 0; j < shard->capacity; j++) { - for (internal_string *s = shard->strs[j]; s; s = s->bucket_next) { - gpr_log(GPR_DEBUG, "LEAKED: %s", - grpc_mdstr_as_c_string((grpc_mdstr *)s)); - } - } - if (grpc_iomgr_abort_on_leaks()) { - abort(); - } - } - gpr_free(shard->strs); - } -} - -static int is_mdstr_static(grpc_mdstr *s) { - return s >= &grpc_static_mdstr_table[0] && - s < &grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; } static int is_mdelem_static(grpc_mdelem *e) { @@ -290,162 +224,6 @@ static void ref_md_locked(mdtab_shard *shard, } } -static void grow_strtab(strtab_shard *shard) { - size_t capacity = shard->capacity * 2; - size_t i; - internal_string **strtab; - internal_string *s, *next; - - GPR_TIMER_BEGIN("grow_strtab", 0); - - strtab = gpr_malloc(sizeof(internal_string *) * capacity); - memset(strtab, 0, sizeof(internal_string *) * capacity); - - for (i = 0; i < shard->capacity; i++) { - for (s = shard->strs[i]; s; s = next) { - size_t idx = TABLE_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT, capacity); - next = s->bucket_next; - s->bucket_next = strtab[idx]; - strtab[idx] = s; - } - } - - gpr_free(shard->strs); - shard->strs = strtab; - shard->capacity = capacity; - - GPR_TIMER_END("grow_strtab", 0); -} - -static void internal_destroy_string(grpc_exec_ctx *exec_ctx, - strtab_shard *shard, internal_string *is) { - internal_string **prev_next; - internal_string *cur; - GPR_TIMER_BEGIN("internal_destroy_string", 0); - if (is->has_base64_and_huffman_encoded) { - grpc_slice_unref_internal(exec_ctx, is->base64_and_huffman); - } - for (prev_next = &shard->strs[TABLE_IDX(is->hash, LOG2_STRTAB_SHARD_COUNT, - shard->capacity)], - cur = *prev_next; - cur != is; prev_next = &cur->bucket_next, cur = cur->bucket_next) - ; - *prev_next = cur->bucket_next; - shard->count--; - gpr_free(is); - GPR_TIMER_END("internal_destroy_string", 0); -} - -static void slice_ref(void *p) { - internal_string *is = - (internal_string *)((char *)p - offsetof(internal_string, refcount)); - GRPC_MDSTR_REF((grpc_mdstr *)(is)); -} - -static void slice_unref(grpc_exec_ctx *exec_ctx, void *p) { - internal_string *is = - (internal_string *)((char *)p - offsetof(internal_string, refcount)); - GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)(is)); -} - -grpc_mdstr *grpc_mdstr_from_string(const char *str) { - return grpc_mdstr_from_buffer((const uint8_t *)str, strlen(str)); -} - -grpc_mdstr *grpc_mdstr_from_slice(grpc_exec_ctx *exec_ctx, grpc_slice slice) { - grpc_mdstr *result = grpc_mdstr_from_buffer(GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_LENGTH(slice)); - grpc_slice_unref_internal(exec_ctx, slice); - return result; -} - -grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *buf, size_t length) { - uint32_t hash = gpr_murmur_hash3(buf, length, g_hash_seed); - internal_string *s; - strtab_shard *shard = - &g_strtab_shard[SHARD_IDX(hash, LOG2_STRTAB_SHARD_COUNT)]; - size_t i; - size_t idx; - - GPR_TIMER_BEGIN("grpc_mdstr_from_buffer", 0); - - /* search for a static string */ - for (i = 0; i <= g_static_strtab_maxprobe; i++) { - grpc_mdstr *ss; - idx = (hash + i) % GPR_ARRAY_SIZE(g_static_strtab); - ss = g_static_strtab[idx]; - if (ss == NULL) break; - if (ss->hash == hash && GRPC_SLICE_LENGTH(ss->slice) == length && - (length == 0 || - 0 == memcmp(buf, GRPC_SLICE_START_PTR(ss->slice), length))) { - GPR_TIMER_END("grpc_mdstr_from_buffer", 0); - return ss; - } - } - - gpr_mu_lock(&shard->mu); - - /* search for an existing string */ - idx = TABLE_IDX(hash, LOG2_STRTAB_SHARD_COUNT, shard->capacity); - for (s = shard->strs[idx]; s; s = s->bucket_next) { - if (s->hash == hash && GRPC_SLICE_LENGTH(s->slice) == length && - 0 == memcmp(buf, GRPC_SLICE_START_PTR(s->slice), length)) { - if (gpr_atm_full_fetch_add(&s->refcnt, 1) == 0) { - /* If we get here, we've added a ref to something that was about to - * die - drop it immediately. - * The *only* possible path here (given the shard mutex) should be to - * drop from one ref back to zero - assert that with a CAS */ - GPR_ASSERT(gpr_atm_rel_cas(&s->refcnt, 1, 0)); - /* and treat this as if we were never here... sshhh */ - } else { - gpr_mu_unlock(&shard->mu); - GPR_TIMER_END("grpc_mdstr_from_buffer", 0); - return (grpc_mdstr *)s; - } - } - } - - /* not found: create a new string */ - if (length + 1 < GRPC_SLICE_INLINED_SIZE) { - /* string data goes directly into the slice */ - s = gpr_malloc(sizeof(internal_string)); - gpr_atm_rel_store(&s->refcnt, 1); - s->slice.refcount = NULL; - memcpy(s->slice.data.inlined.bytes, buf, length); - s->slice.data.inlined.bytes[length] = 0; - s->slice.data.inlined.length = (uint8_t)length; - } else { - /* string data goes after the internal_string header, and we +1 for null - terminator */ - s = gpr_malloc(sizeof(internal_string) + length + 1); - gpr_atm_rel_store(&s->refcnt, 1); - s->refcount.ref = slice_ref; - s->refcount.unref = slice_unref; - s->slice.refcount = &s->refcount; - s->slice.data.refcounted.bytes = (uint8_t *)(s + 1); - s->slice.data.refcounted.length = length; - memcpy(s->slice.data.refcounted.bytes, buf, length); - /* add a null terminator for cheap c string conversion when desired */ - s->slice.data.refcounted.bytes[length] = 0; - } - s->has_base64_and_huffman_encoded = 0; - s->hash = hash; - s->size_in_decoder_table = SIZE_IN_DECODER_TABLE_NOT_SET; - s->bucket_next = shard->strs[idx]; - shard->strs[idx] = s; - - shard->count++; - - if (shard->count > shard->capacity * 2) { - grow_strtab(shard); - } - - gpr_mu_unlock(&shard->mu); - GPR_TIMER_END("grpc_mdstr_from_buffer", 0); - - return (grpc_mdstr *)s; -} - static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { size_t i; internal_metadata **prev_next; @@ -459,8 +237,8 @@ static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { void *user_data = (void *)gpr_atm_no_barrier_load(&md->user_data); next = md->bucket_next; if (gpr_atm_acq_load(&md->refcnt) == 0) { - GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)md->key); - GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)md->value); + grpc_slice_unref_internal(exec_ctx, md->key); + grpc_slice_unref_internal(exec_ctx, md->value); if (md->user_data) { ((destroy_user_data_func)gpr_atm_no_barrier_load( &md->destroy_user_data))(user_data); @@ -493,9 +271,10 @@ static void grow_mdtab(mdtab_shard *shard) { for (i = 0; i < shard->capacity; i++) { for (md = shard->elems[i]; md; md = next) { size_t idx; - hash = GRPC_MDSTR_KV_HASH(md->key->hash, md->value->hash); + hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), + grpc_slice_hash(md->value)); next = md->bucket_next; - idx = TABLE_IDX(hash, LOG2_MDTAB_SHARD_COUNT, capacity); + idx = TABLE_IDX(hash, capacity); md->bucket_next = mdtab[idx]; mdtab[idx] = md; } @@ -517,26 +296,26 @@ static void rehash_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { } } -grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, - grpc_mdstr *mkey, - grpc_mdstr *mvalue) { - internal_string *key = (internal_string *)mkey; - internal_string *value = (internal_string *)mvalue; - uint32_t hash = GRPC_MDSTR_KV_HASH(mkey->hash, mvalue->hash); +grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value) { + uint32_t hash = + GRPC_MDSTR_KV_HASH(grpc_slice_hash(key), grpc_slice_hash(value)); internal_metadata *md; - mdtab_shard *shard = &g_mdtab_shard[SHARD_IDX(hash, LOG2_MDTAB_SHARD_COUNT)]; + mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; size_t i; size_t idx; GPR_TIMER_BEGIN("grpc_mdelem_from_metadata_strings", 0); - if (is_mdstr_static(mkey) && is_mdstr_static(mvalue)) { + if (grpc_is_static_metadata_string(key) && + grpc_is_static_metadata_string(value)) { for (i = 0; i <= g_static_mdtab_maxprobe; i++) { grpc_mdelem *smd; idx = (hash + i) % GPR_ARRAY_SIZE(g_static_mdtab); smd = g_static_mdtab[idx]; if (smd == NULL) break; - if (smd->key == mkey && smd->value == mvalue) { + if (grpc_slice_cmp(key, smd->key) == 0 && + grpc_slice_cmp(value, smd->value) == 0) { GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); return smd; } @@ -545,14 +324,15 @@ grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&shard->mu); - idx = TABLE_IDX(hash, LOG2_MDTAB_SHARD_COUNT, shard->capacity); + idx = TABLE_IDX(hash, shard->capacity); /* search for an existing pair */ for (md = shard->elems[idx]; md; md = md->bucket_next) { - if (md->key == key && md->value == value) { + if (grpc_slice_cmp(key, md->key) == 0 && + grpc_slice_cmp(value, md->value) == 0) { REF_MD_LOCKED(shard, md); - GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)key); - GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)value); gpr_mu_unlock(&shard->mu); + grpc_slice_unref_internal(exec_ctx, key); + grpc_slice_unref_internal(exec_ctx, value); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); return (grpc_mdelem *)md; } @@ -587,58 +367,19 @@ grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, return (grpc_mdelem *)md; } -grpc_mdelem *grpc_mdelem_from_strings(grpc_exec_ctx *exec_ctx, const char *key, - const char *value) { - return grpc_mdelem_from_metadata_strings( - exec_ctx, grpc_mdstr_from_string(key), grpc_mdstr_from_string(value)); -} - -grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value) { - return grpc_mdelem_from_metadata_strings( - exec_ctx, grpc_mdstr_from_slice(exec_ctx, key), - grpc_mdstr_from_slice(exec_ctx, value)); -} - -grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_exec_ctx *exec_ctx, - const char *key, - const uint8_t *value, - size_t value_length) { - return grpc_mdelem_from_metadata_strings( - exec_ctx, grpc_mdstr_from_string(key), - grpc_mdstr_from_buffer(value, value_length)); -} - static size_t get_base64_encoded_size(size_t raw_length) { static const uint8_t tail_xtra[3] = {0, 2, 3}; return raw_length / 3 * 4 + tail_xtra[raw_length % 3]; } size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem) { - size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(elem->key->slice); - size_t value_len = GRPC_SLICE_LENGTH(elem->value->slice); - if (is_mdstr_static(elem->value)) { - if (grpc_is_binary_header( - (const char *)GRPC_SLICE_START_PTR(elem->key->slice), - GRPC_SLICE_LENGTH(elem->key->slice))) { - return overhead_and_key + get_base64_encoded_size(value_len); - } else { - return overhead_and_key + value_len; - } + size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(elem->key); + size_t value_len = GRPC_SLICE_LENGTH(elem->value); + if (grpc_is_binary_header((const char *)GRPC_SLICE_START_PTR(elem->key), + GRPC_SLICE_LENGTH(elem->key))) { + return overhead_and_key + get_base64_encoded_size(value_len); } else { - internal_string *is = (internal_string *)elem->value; - gpr_atm current_size = gpr_atm_acq_load(&is->size_in_decoder_table); - if (current_size == SIZE_IN_DECODER_TABLE_NOT_SET) { - if (grpc_is_binary_header( - (const char *)GRPC_SLICE_START_PTR(elem->key->slice), - GRPC_SLICE_LENGTH(elem->key->slice))) { - current_size = (gpr_atm)get_base64_encoded_size(value_len); - } else { - current_size = (gpr_atm)value_len; - } - gpr_atm_rel_store(&is->size_in_decoder_table, current_size); - } - return overhead_and_key + (size_t)current_size; + return overhead_and_key + value_len; } } @@ -674,54 +415,18 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *gmd DEBUG_ARGS) { grpc_mdstr_as_c_string((grpc_mdstr *)md->key), grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); #endif - uint32_t hash = GRPC_MDSTR_KV_HASH(md->key->hash, md->value->hash); + uint32_t hash = + GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), grpc_slice_hash(md->value)); const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); GPR_ASSERT(prev_refcount >= 1); if (1 == prev_refcount) { /* once the refcount hits zero, some other thread can come along and free md at any time: it's unsafe from this point on to access it */ - mdtab_shard *shard = - &g_mdtab_shard[SHARD_IDX(hash, LOG2_MDTAB_SHARD_COUNT)]; + mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; gpr_atm_no_barrier_fetch_add(&shard->free_estimate, 1); } } -const char *grpc_mdstr_as_c_string(const grpc_mdstr *s) { - return (const char *)GRPC_SLICE_START_PTR(s->slice); -} - -size_t grpc_mdstr_length(const grpc_mdstr *s) { return GRPC_MDSTR_LENGTH(s); } - -grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *gs DEBUG_ARGS) { - internal_string *s = (internal_string *)gs; - if (is_mdstr_static(gs)) return gs; -#ifdef GRPC_METADATA_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR REF:%p:%zu->%zu: '%s'", - (void *)s, gpr_atm_no_barrier_load(&s->refcnt), - gpr_atm_no_barrier_load(&s->refcnt) + 1, grpc_mdstr_as_c_string(gs)); -#endif - GPR_ASSERT(gpr_atm_full_fetch_add(&s->refcnt, 1) > 0); - return gs; -} - -void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *gs DEBUG_ARGS) { - internal_string *s = (internal_string *)gs; - if (is_mdstr_static(gs)) return; -#ifdef GRPC_METADATA_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR UNREF:%p:%zu->%zu: '%s'", - (void *)s, gpr_atm_no_barrier_load(&s->refcnt), - gpr_atm_no_barrier_load(&s->refcnt) - 1, grpc_mdstr_as_c_string(gs)); -#endif - if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { - strtab_shard *shard = - &g_strtab_shard[SHARD_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT)]; - gpr_mu_lock(&shard->mu); - GPR_ASSERT(0 == gpr_atm_no_barrier_load(&s->refcnt)); - internal_destroy_string(exec_ctx, shard, s); - gpr_mu_unlock(&shard->mu); - } -} - void *grpc_mdelem_get_user_data(grpc_mdelem *md, void (*destroy_func)(void *)) { internal_metadata *im = (internal_metadata *)md; void *result; @@ -754,19 +459,3 @@ void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func); gpr_mu_unlock(&im->mu_user_data); } - -grpc_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *gs) { - internal_string *s = (internal_string *)gs; - grpc_slice slice; - strtab_shard *shard = - &g_strtab_shard[SHARD_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT)]; - gpr_mu_lock(&shard->mu); - if (!s->has_base64_and_huffman_encoded) { - s->base64_and_huffman = - grpc_chttp2_base64_encode_and_huffman_compress(s->slice); - s->has_base64_and_huffman_encoded = 1; - } - slice = s->base64_and_huffman; - gpr_mu_unlock(&shard->mu); - return slice; -} diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 8a64be70250..ede09d7d76c 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -74,51 +74,19 @@ extern "C" { declared here - in which case those functions are effectively no-ops. */ /* Forward declarations */ -typedef struct grpc_mdstr grpc_mdstr; typedef struct grpc_mdelem grpc_mdelem; -/* if changing this, make identical changes in internal_string in metadata.c */ -struct grpc_mdstr { - const grpc_slice slice; - const uint32_t hash; - /* there is a private part to this in metadata.c */ -}; - /* if changing this, make identical changes in internal_metadata in metadata.c */ struct grpc_mdelem { - grpc_mdstr *const key; - grpc_mdstr *const value; + const grpc_slice key; + const grpc_slice value; /* there is a private part to this in metadata.c */ }; -void grpc_test_only_set_metadata_hash_seed(uint32_t seed); - -/* Constructors for grpc_mdstr instances; take a variety of data types that - clients may have handy */ -grpc_mdstr *grpc_mdstr_from_string(const char *str); -/* Unrefs the slice. */ -grpc_mdstr *grpc_mdstr_from_slice(grpc_exec_ctx *exec_ctx, grpc_slice slice); -grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *str, size_t length); - -/* Returns a borrowed slice from the mdstr with its contents base64 encoded - and huffman compressed */ -grpc_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *str); - -/* Constructors for grpc_mdelem instances; take a variety of data types that - clients may have handy */ -grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, - grpc_mdstr *key, - grpc_mdstr *value); -grpc_mdelem *grpc_mdelem_from_strings(grpc_exec_ctx *exec_ctx, const char *key, - const char *value); /* Unrefs the slices. */ grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value); -grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_exec_ctx *exec_ctx, - const char *key, - const uint8_t *value, - size_t value_length); size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem); @@ -132,52 +100,30 @@ void grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), /* Reference counting */ //#define GRPC_METADATA_REFCOUNT_DEBUG #ifdef GRPC_METADATA_REFCOUNT_DEBUG -#define GRPC_MDSTR_REF(s) grpc_mdstr_ref((s), __FILE__, __LINE__) -#define GRPC_MDSTR_UNREF(exec_ctx, s) \ - grpc_mdstr_unref((exec_ctx), (s), __FILE__, __LINE__) #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) #define GRPC_MDELEM_UNREF(exec_ctx, s) \ grpc_mdelem_unref((exec_ctx), (s), __FILE__, __LINE__) -grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s, const char *file, int line); -void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *s, const char *file, - int line); grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md, const char *file, int line); void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md, const char *file, int line); #else -#define GRPC_MDSTR_REF(s) grpc_mdstr_ref((s)) -#define GRPC_MDSTR_UNREF(exec_ctx, s) grpc_mdstr_unref((exec_ctx), (s)) #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s)) #define GRPC_MDELEM_UNREF(exec_ctx, s) grpc_mdelem_unref((exec_ctx), (s)) -grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s); -void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *s); grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md); void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md); #endif -/* Recover a char* from a grpc_mdstr. The returned string is null terminated. - Does not promise that the returned string has no embedded nulls however. */ -const char *grpc_mdstr_as_c_string(const grpc_mdstr *s); - #define GRPC_MDSTR_LENGTH(s) (GRPC_SLICE_LENGTH(s->slice)) /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ #define GRPC_MDELEM_LENGTH(e) \ (GRPC_MDSTR_LENGTH((e)->key) + GRPC_MDSTR_LENGTH((e)->value) + 32) -int grpc_mdstr_is_legal_header(grpc_mdstr *s); -int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s); -int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s); - #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) void grpc_mdctx_global_init(void); void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx); -/* Implementation provided by chttp2_transport */ -extern grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)( - grpc_slice input); - #ifdef __cplusplus } #endif diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 8b22592b45d..1d72646a975 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -41,7 +41,336 @@ #include "src/core/lib/transport/static_metadata.h" -grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; +static uint8_t g_raw_bytes[] = { + 48, 49, 50, 50, 48, 48, 50, 48, 52, 50, 48, 54, 51, 48, 52, + 52, 48, 48, 52, 48, 52, 53, 48, 48, 97, 99, 99, 101, 112, 116, + 97, 99, 99, 101, 112, 116, 45, 99, 104, 97, 114, 115, 101, 116, 97, + 99, 99, 101, 112, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 97, + 99, 99, 101, 112, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, 97, + 99, 99, 101, 112, 116, 45, 114, 97, 110, 103, 101, 115, 97, 99, 99, + 101, 115, 115, 45, 99, 111, 110, 116, 114, 111, 108, 45, 97, 108, 108, + 111, 119, 45, 111, 114, 105, 103, 105, 110, 97, 103, 101, 97, 108, 108, + 111, 119, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 103, + 114, 112, 99, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 97, 117, + 116, 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 99, 97, 99, 104, + 101, 45, 99, 111, 110, 116, 114, 111, 108, 99, 111, 110, 116, 101, 110, + 116, 45, 100, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 99, 111, + 110, 116, 101, 110, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 99, + 111, 110, 116, 101, 110, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, + 99, 111, 110, 116, 101, 110, 116, 45, 108, 101, 110, 103, 116, 104, 99, + 111, 110, 116, 101, 110, 116, 45, 108, 111, 99, 97, 116, 105, 111, 110, + 99, 111, 110, 116, 101, 110, 116, 45, 114, 97, 110, 103, 101, 99, 111, + 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 99, 111, 111, 107, 105, + 101, 100, 97, 116, 101, 100, 101, 102, 108, 97, 116, 101, 100, 101, 102, + 108, 97, 116, 101, 44, 103, 122, 105, 112, 101, 116, 97, 103, 101, 120, + 112, 101, 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, + 71, 69, 84, 103, 114, 112, 99, 103, 114, 112, 99, 45, 97, 99, 99, + 101, 112, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, + 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, 99, 45, + 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 110, 99, 111, 100, 105, + 110, 103, 45, 114, 101, 113, 117, 101, 115, 116, 103, 114, 112, 99, 45, + 109, 101, 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 112, 97, 121, + 108, 111, 97, 100, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, + 97, 116, 115, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, 97, + 116, 117, 115, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, 117, 116, + 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, 98, 105, + 110, 103, 122, 105, 112, 103, 122, 105, 112, 44, 32, 100, 101, 102, 108, + 97, 116, 101, 104, 111, 115, 116, 104, 116, 116, 112, 104, 116, 116, 112, + 115, 105, 100, 101, 110, 116, 105, 116, 121, 105, 100, 101, 110, 116, 105, + 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, 110, 116, + 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, + 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 103, 122, 105, 112, 105, + 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, 105, 102, + 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, 111, 110, + 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, 103, 101, + 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, + 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, 102, 105, + 101, 100, 108, 98, 45, 99, 111, 115, 116, 45, 98, 105, 110, 108, 98, + 45, 116, 111, 107, 101, 110, 108, 105, 110, 107, 108, 111, 99, 97, 116, + 105, 111, 110, 109, 97, 120, 45, 102, 111, 114, 119, 97, 114, 100, 115, + 58, 109, 101, 116, 104, 111, 100, 58, 112, 97, 116, 104, 80, 79, 83, + 84, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 101, 110, 116, 105, + 99, 97, 116, 101, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 111, + 114, 105, 122, 97, 116, 105, 111, 110, 80, 85, 84, 114, 97, 110, 103, + 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, 115, 104, + 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 58, 115, 99, 104, + 101, 109, 101, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, 99, 111, + 111, 107, 105, 101, 47, 47, 105, 110, 100, 101, 120, 46, 104, 116, 109, + 108, 58, 115, 116, 97, 116, 117, 115, 115, 116, 114, 105, 99, 116, 45, + 116, 114, 97, 110, 115, 112, 111, 114, 116, 45, 115, 101, 99, 117, 114, + 105, 116, 121, 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, 116, 114, + 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, 110, 103, + 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 118, 97, 114, 121, 118, + 105, 97, 119, 119, 119, 45, 97, 117, 116, 104, 101, 110, 116, 105, 99, + 97, 116, 101}; + +static void static_ref(void *unused) {} +static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} +static grpc_slice_refcount g_refcnt = {static_ref, static_unref}; + +bool grpc_is_static_metadata_string(grpc_slice slice) { + return slice.refcount != NULL && slice.refcount->ref == static_ref; +}; + +const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 0, .length = 1}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 1, .length = 1}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 2, .length = 1}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 3, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 6, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 9, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 12, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 15, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 18, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 21, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 24, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 30, .length = 14}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 59, .length = 15}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 74, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 87, .length = 27}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 114, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 117, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 122, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 138, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 148, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 161, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 174, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 193, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 209, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 225, .length = 14}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 239, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 255, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 280, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 286, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 297, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 313, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 319, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 326, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 330, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 333, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 357, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 370, .length = 30}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 400, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 412, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 428, .length = 14}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 442, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 453, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 465, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 481, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 485, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 498, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 502, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 506, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 511, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 519, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 535, .length = 21}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 556, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 569, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 17}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 607, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 615, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 634, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 647, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 658, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 666, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 670, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 678, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 690, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 697, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 702, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 706, .length = 18}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 724, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 743, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 746, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 751, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 765, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 776, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 783, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 799, .length = 1}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 800, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 811, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 818, .length = 25}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 2}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 845, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 853, .length = 17}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 870, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 880, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 884, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 887, .length = 16}}, +}; + +static const uint8_t g_revmap[] = { + 0, 1, 2, 3, 255, 255, 4, 255, 255, 5, 255, 255, 6, 255, 255, + 7, 255, 255, 8, 255, 255, 9, 255, 255, 10, 255, 255, 255, 255, 255, + 11, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 12, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 13, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 14, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 16, 255, 255, 17, 255, 255, + 255, 255, 18, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 19, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 21, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 22, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 23, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 24, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 25, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 26, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 27, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 28, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 29, 255, 255, 255, 255, + 255, 30, 255, 255, 255, 31, 255, 255, 255, 255, 255, 255, 32, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 34, 255, 255, 255, 35, 255, + 255, 255, 255, 255, 36, 255, 255, 255, 255, 255, 255, 37, 255, 255, 255, + 38, 255, 255, 39, 255, 255, 255, 40, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 41, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 42, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 43, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 44, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 45, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 46, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 47, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 48, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 49, 255, 255, 255, 50, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 51, 255, 255, 255, 52, 255, 255, 255, 53, 255, 255, 255, + 255, 54, 255, 255, 255, 255, 255, 255, 255, 55, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 56, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 57, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 58, + 255, 255, 255, 255, 255, 255, 255, 59, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 60, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 61, 255, 255, 255, 255, 255, 255, 255, + 62, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 64, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 65, 255, + 255, 255, 255, 255, 255, 255, 66, 255, 255, 255, 67, 255, 255, 255, 255, + 255, 255, 255, 68, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 69, 255, 255, 255, 255, 255, 255, 70, 255, 255, 255, 255, 71, 255, 255, + 255, 72, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 73, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 74, 255, 255, 75, 255, 255, 255, + 255, 76, 255, 255, 255, 255, 255, 255, 77, 255, 255, 255, 255, 255, 255, + 78, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 79, 255, 255, 255, + 255, 255, 255, 80, 255, 255, 255, 255, 255, 81, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 82, 83, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 84, 255, 255, 255, 255, 255, 255, 85, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 86, 255, 87, 255, 255, 255, 255, 255, 255, 255, 88, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 89, 255, 255, 255, 255, 255, 255, 255, 255, 255, 90, 255, 255, 255, 91, + 255, 255, 92, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255}; + +int grpc_static_metadata_index(grpc_slice slice) { + if (GRPC_SLICE_LENGTH(slice) == 0) return 33; + size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes); + if (ofs > sizeof(g_revmap)) return -1; + uint8_t id = g_revmap[ofs]; + return id == 255 ? -1 : id; +}; grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { @@ -50,6 +379,55 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +#define ELEMS_PHASHLEN 0x40 +#define ELEMS_PHASHNKEYS 81 +#define ELEMS_PHASHRANGE 128 +#define ELEMS_PHASHSALT 0x13c6ef372 + +static const uint8_t elems_tab[] = { + 47, 28, 47, 1, 47, 76, 76, 0, 1, 119, 61, 60, 47, 61, 76, 0, + 0, 32, 61, 76, 0, 0, 1, 0, 0, 0, 0, 0, 0, 101, 0, 0, + 0, 0, 47, 76, 122, 10, 76, 46, 87, 119, 25, 4, 0, 47, 0, 44, + 20, 120, 4, 79, 0, 0, 122, 88, 80, 20, 51, 65, 0, 0, 0, 0, +}; + +static uint32_t elems_phash(uint32_t val) { + val -= 963; + + uint32_t a, b, rsl; + + b = ((val << 19) >> 26); + a = (val & 0x3f); + rsl = (a ^ elems_tab[b]); + return rsl; +} + +static const uint16_t elem_keys[] = { + 3844, 1521, 2544, 7194, 7815, 7816, 7817, 7818, 7819, 7820, 7821, 6357, + 6822, 5706, 2358, 3381, 1428, 6488, 3862, 7386, 2622, 6078, 7101, 1166, + 3195, 3867, 2730, 1335, 6491, 2079, 8496, 5427, 7399, 7400, 1893, 8403, + 3751, 3752, 1149, 8310, 3288, 6729, 7473, 2265, 2451, 6455, 5799, 963, + 5985, 7008, 1056, 4278, 4279, 4280, 3769, 2637, 1242, 6592, 6593, 3774, + 3775, 3776, 3777, 1986, 4776, 5520, 6264, 3474, 7566, 7938, 8217, 1614, + 2823, 1800, 8085, 8589, 7287, 5892, 2172, 6171, 5613, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0}; +static const uint8_t elem_idxs[] = { + 33, 7, 17, 60, 67, 68, 69, 70, 71, 72, 73, 50, 57, 43, 15, 24, 6, + 52, 34, 62, 18, 47, 59, 3, 22, 35, 20, 5, 53, 12, 79, 40, 63, 64, + 10, 78, 26, 27, 2, 77, 23, 56, 65, 14, 16, 51, 44, 1, 46, 58, 0, + 36, 37, 38, 28, 19, 4, 54, 55, 29, 30, 31, 32, 11, 39, 41, 49, 25, + 66, 74, 76, 8, 21, 9, 75, 80, 61, 45, 13, 48, 42}; + +grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) { + if (a == -1 || b == -1) return NULL; + uint32_t k = (uint32_t)(a * 93 + b); + uint32_t h = elems_phash(k); + return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL; +} + const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = {11, 33, 10, 33, 12, 33, 12, 50, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, 19, 33, 20, 33, 21, 33, 22, 33, 23, 33, 24, 33, 25, 33, 26, 33, 27, 33, @@ -61,100 +439,5 @@ const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = 79, 52, 79, 53, 80, 33, 81, 33, 84, 3, 84, 4, 84, 5, 84, 6, 84, 7, 84, 8, 84, 9, 85, 33, 86, 87, 88, 33, 89, 33, 90, 33, 91, 33, 92, 33}; -const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { - "0", - "1", - "2", - "200", - "204", - "206", - "304", - "400", - "404", - "500", - "accept", - "accept-charset", - "accept-encoding", - "accept-language", - "accept-ranges", - "access-control-allow-origin", - "age", - "allow", - "application/grpc", - ":authority", - "authorization", - "cache-control", - "content-disposition", - "content-encoding", - "content-language", - "content-length", - "content-location", - "content-range", - "content-type", - "cookie", - "date", - "deflate", - "deflate,gzip", - "", - "etag", - "expect", - "expires", - "from", - "GET", - "grpc", - "grpc-accept-encoding", - "grpc-encoding", - "grpc-internal-encoding-request", - "grpc-message", - "grpc-payload-bin", - "grpc-stats-bin", - "grpc-status", - "grpc-timeout", - "grpc-tracing-bin", - "gzip", - "gzip, deflate", - "host", - "http", - "https", - "identity", - "identity,deflate", - "identity,deflate,gzip", - "identity,gzip", - "if-match", - "if-modified-since", - "if-none-match", - "if-range", - "if-unmodified-since", - "last-modified", - "lb-cost-bin", - "lb-token", - "link", - "location", - "max-forwards", - ":method", - ":path", - "POST", - "proxy-authenticate", - "proxy-authorization", - "PUT", - "range", - "referer", - "refresh", - "retry-after", - ":scheme", - "server", - "set-cookie", - "/", - "/index.html", - ":status", - "strict-transport-security", - "te", - "trailers", - "transfer-encoding", - "user-agent", - "vary", - "via", - "www-authenticate"}; - const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, 28, 32, 27, 31}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 28ad6f2961a..dccac395cd1 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -45,194 +45,196 @@ #include "src/core/lib/transport/metadata.h" #define GRPC_STATIC_MDSTR_COUNT 93 -extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; +extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ -#define GRPC_MDSTR_0 (&grpc_static_mdstr_table[0]) +#define GRPC_MDSTR_0 (&grpc_static_slice_table[0]) /* "1" */ -#define GRPC_MDSTR_1 (&grpc_static_mdstr_table[1]) +#define GRPC_MDSTR_1 (&grpc_static_slice_table[1]) /* "2" */ -#define GRPC_MDSTR_2 (&grpc_static_mdstr_table[2]) +#define GRPC_MDSTR_2 (&grpc_static_slice_table[2]) /* "200" */ -#define GRPC_MDSTR_200 (&grpc_static_mdstr_table[3]) +#define GRPC_MDSTR_200 (&grpc_static_slice_table[3]) /* "204" */ -#define GRPC_MDSTR_204 (&grpc_static_mdstr_table[4]) +#define GRPC_MDSTR_204 (&grpc_static_slice_table[4]) /* "206" */ -#define GRPC_MDSTR_206 (&grpc_static_mdstr_table[5]) +#define GRPC_MDSTR_206 (&grpc_static_slice_table[5]) /* "304" */ -#define GRPC_MDSTR_304 (&grpc_static_mdstr_table[6]) +#define GRPC_MDSTR_304 (&grpc_static_slice_table[6]) /* "400" */ -#define GRPC_MDSTR_400 (&grpc_static_mdstr_table[7]) +#define GRPC_MDSTR_400 (&grpc_static_slice_table[7]) /* "404" */ -#define GRPC_MDSTR_404 (&grpc_static_mdstr_table[8]) +#define GRPC_MDSTR_404 (&grpc_static_slice_table[8]) /* "500" */ -#define GRPC_MDSTR_500 (&grpc_static_mdstr_table[9]) +#define GRPC_MDSTR_500 (&grpc_static_slice_table[9]) /* "accept" */ -#define GRPC_MDSTR_ACCEPT (&grpc_static_mdstr_table[10]) +#define GRPC_MDSTR_ACCEPT (&grpc_static_slice_table[10]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (&grpc_static_mdstr_table[11]) +#define GRPC_MDSTR_ACCEPT_CHARSET (&grpc_static_slice_table[11]) /* "accept-encoding" */ -#define GRPC_MDSTR_ACCEPT_ENCODING (&grpc_static_mdstr_table[12]) +#define GRPC_MDSTR_ACCEPT_ENCODING (&grpc_static_slice_table[12]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (&grpc_static_mdstr_table[13]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (&grpc_static_slice_table[13]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (&grpc_static_mdstr_table[14]) +#define GRPC_MDSTR_ACCEPT_RANGES (&grpc_static_slice_table[14]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (&grpc_static_mdstr_table[15]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (&grpc_static_slice_table[15]) /* "age" */ -#define GRPC_MDSTR_AGE (&grpc_static_mdstr_table[16]) +#define GRPC_MDSTR_AGE (&grpc_static_slice_table[16]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (&grpc_static_mdstr_table[17]) +#define GRPC_MDSTR_ALLOW (&grpc_static_slice_table[17]) /* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (&grpc_static_mdstr_table[18]) +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (&grpc_static_slice_table[18]) /* ":authority" */ -#define GRPC_MDSTR_AUTHORITY (&grpc_static_mdstr_table[19]) +#define GRPC_MDSTR_AUTHORITY (&grpc_static_slice_table[19]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (&grpc_static_mdstr_table[20]) +#define GRPC_MDSTR_AUTHORIZATION (&grpc_static_slice_table[20]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (&grpc_static_mdstr_table[21]) +#define GRPC_MDSTR_CACHE_CONTROL (&grpc_static_slice_table[21]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (&grpc_static_mdstr_table[22]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (&grpc_static_slice_table[22]) /* "content-encoding" */ -#define GRPC_MDSTR_CONTENT_ENCODING (&grpc_static_mdstr_table[23]) +#define GRPC_MDSTR_CONTENT_ENCODING (&grpc_static_slice_table[23]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (&grpc_static_mdstr_table[24]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (&grpc_static_slice_table[24]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (&grpc_static_mdstr_table[25]) +#define GRPC_MDSTR_CONTENT_LENGTH (&grpc_static_slice_table[25]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (&grpc_static_mdstr_table[26]) +#define GRPC_MDSTR_CONTENT_LOCATION (&grpc_static_slice_table[26]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (&grpc_static_mdstr_table[27]) +#define GRPC_MDSTR_CONTENT_RANGE (&grpc_static_slice_table[27]) /* "content-type" */ -#define GRPC_MDSTR_CONTENT_TYPE (&grpc_static_mdstr_table[28]) +#define GRPC_MDSTR_CONTENT_TYPE (&grpc_static_slice_table[28]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (&grpc_static_mdstr_table[29]) +#define GRPC_MDSTR_COOKIE (&grpc_static_slice_table[29]) /* "date" */ -#define GRPC_MDSTR_DATE (&grpc_static_mdstr_table[30]) +#define GRPC_MDSTR_DATE (&grpc_static_slice_table[30]) /* "deflate" */ -#define GRPC_MDSTR_DEFLATE (&grpc_static_mdstr_table[31]) +#define GRPC_MDSTR_DEFLATE (&grpc_static_slice_table[31]) /* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (&grpc_static_mdstr_table[32]) +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (&grpc_static_slice_table[32]) /* "" */ -#define GRPC_MDSTR_EMPTY (&grpc_static_mdstr_table[33]) +#define GRPC_MDSTR_EMPTY (&grpc_static_slice_table[33]) /* "etag" */ -#define GRPC_MDSTR_ETAG (&grpc_static_mdstr_table[34]) +#define GRPC_MDSTR_ETAG (&grpc_static_slice_table[34]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (&grpc_static_mdstr_table[35]) +#define GRPC_MDSTR_EXPECT (&grpc_static_slice_table[35]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (&grpc_static_mdstr_table[36]) +#define GRPC_MDSTR_EXPIRES (&grpc_static_slice_table[36]) /* "from" */ -#define GRPC_MDSTR_FROM (&grpc_static_mdstr_table[37]) +#define GRPC_MDSTR_FROM (&grpc_static_slice_table[37]) /* "GET" */ -#define GRPC_MDSTR_GET (&grpc_static_mdstr_table[38]) +#define GRPC_MDSTR_GET (&grpc_static_slice_table[38]) /* "grpc" */ -#define GRPC_MDSTR_GRPC (&grpc_static_mdstr_table[39]) +#define GRPC_MDSTR_GRPC (&grpc_static_slice_table[39]) /* "grpc-accept-encoding" */ -#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (&grpc_static_mdstr_table[40]) +#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (&grpc_static_slice_table[40]) /* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (&grpc_static_mdstr_table[41]) +#define GRPC_MDSTR_GRPC_ENCODING (&grpc_static_slice_table[41]) /* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (&grpc_static_mdstr_table[42]) +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (&grpc_static_slice_table[42]) /* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (&grpc_static_mdstr_table[43]) +#define GRPC_MDSTR_GRPC_MESSAGE (&grpc_static_slice_table[43]) /* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (&grpc_static_mdstr_table[44]) +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (&grpc_static_slice_table[44]) /* "grpc-stats-bin" */ -#define GRPC_MDSTR_GRPC_STATS_BIN (&grpc_static_mdstr_table[45]) +#define GRPC_MDSTR_GRPC_STATS_BIN (&grpc_static_slice_table[45]) /* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (&grpc_static_mdstr_table[46]) +#define GRPC_MDSTR_GRPC_STATUS (&grpc_static_slice_table[46]) /* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (&grpc_static_mdstr_table[47]) +#define GRPC_MDSTR_GRPC_TIMEOUT (&grpc_static_slice_table[47]) /* "grpc-tracing-bin" */ -#define GRPC_MDSTR_GRPC_TRACING_BIN (&grpc_static_mdstr_table[48]) +#define GRPC_MDSTR_GRPC_TRACING_BIN (&grpc_static_slice_table[48]) /* "gzip" */ -#define GRPC_MDSTR_GZIP (&grpc_static_mdstr_table[49]) +#define GRPC_MDSTR_GZIP (&grpc_static_slice_table[49]) /* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (&grpc_static_mdstr_table[50]) +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (&grpc_static_slice_table[50]) /* "host" */ -#define GRPC_MDSTR_HOST (&grpc_static_mdstr_table[51]) +#define GRPC_MDSTR_HOST (&grpc_static_slice_table[51]) /* "http" */ -#define GRPC_MDSTR_HTTP (&grpc_static_mdstr_table[52]) +#define GRPC_MDSTR_HTTP (&grpc_static_slice_table[52]) /* "https" */ -#define GRPC_MDSTR_HTTPS (&grpc_static_mdstr_table[53]) +#define GRPC_MDSTR_HTTPS (&grpc_static_slice_table[53]) /* "identity" */ -#define GRPC_MDSTR_IDENTITY (&grpc_static_mdstr_table[54]) +#define GRPC_MDSTR_IDENTITY (&grpc_static_slice_table[54]) /* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (&grpc_static_mdstr_table[55]) +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (&grpc_static_slice_table[55]) /* "identity,deflate,gzip" */ #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (&grpc_static_mdstr_table[56]) + (&grpc_static_slice_table[56]) /* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (&grpc_static_mdstr_table[57]) +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (&grpc_static_slice_table[57]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (&grpc_static_mdstr_table[58]) +#define GRPC_MDSTR_IF_MATCH (&grpc_static_slice_table[58]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (&grpc_static_mdstr_table[59]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (&grpc_static_slice_table[59]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (&grpc_static_mdstr_table[60]) +#define GRPC_MDSTR_IF_NONE_MATCH (&grpc_static_slice_table[60]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (&grpc_static_mdstr_table[61]) +#define GRPC_MDSTR_IF_RANGE (&grpc_static_slice_table[61]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_mdstr_table[62]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_slice_table[62]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_mdstr_table[63]) +#define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_slice_table[63]) /* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (&grpc_static_mdstr_table[64]) +#define GRPC_MDSTR_LB_COST_BIN (&grpc_static_slice_table[64]) /* "lb-token" */ -#define GRPC_MDSTR_LB_TOKEN (&grpc_static_mdstr_table[65]) +#define GRPC_MDSTR_LB_TOKEN (&grpc_static_slice_table[65]) /* "link" */ -#define GRPC_MDSTR_LINK (&grpc_static_mdstr_table[66]) +#define GRPC_MDSTR_LINK (&grpc_static_slice_table[66]) /* "location" */ -#define GRPC_MDSTR_LOCATION (&grpc_static_mdstr_table[67]) +#define GRPC_MDSTR_LOCATION (&grpc_static_slice_table[67]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_mdstr_table[68]) +#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_slice_table[68]) /* ":method" */ -#define GRPC_MDSTR_METHOD (&grpc_static_mdstr_table[69]) +#define GRPC_MDSTR_METHOD (&grpc_static_slice_table[69]) /* ":path" */ -#define GRPC_MDSTR_PATH (&grpc_static_mdstr_table[70]) +#define GRPC_MDSTR_PATH (&grpc_static_slice_table[70]) /* "POST" */ -#define GRPC_MDSTR_POST (&grpc_static_mdstr_table[71]) +#define GRPC_MDSTR_POST (&grpc_static_slice_table[71]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_mdstr_table[72]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_slice_table[72]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_mdstr_table[73]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_slice_table[73]) /* "PUT" */ -#define GRPC_MDSTR_PUT (&grpc_static_mdstr_table[74]) +#define GRPC_MDSTR_PUT (&grpc_static_slice_table[74]) /* "range" */ -#define GRPC_MDSTR_RANGE (&grpc_static_mdstr_table[75]) +#define GRPC_MDSTR_RANGE (&grpc_static_slice_table[75]) /* "referer" */ -#define GRPC_MDSTR_REFERER (&grpc_static_mdstr_table[76]) +#define GRPC_MDSTR_REFERER (&grpc_static_slice_table[76]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (&grpc_static_mdstr_table[77]) +#define GRPC_MDSTR_REFRESH (&grpc_static_slice_table[77]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_mdstr_table[78]) +#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_slice_table[78]) /* ":scheme" */ -#define GRPC_MDSTR_SCHEME (&grpc_static_mdstr_table[79]) +#define GRPC_MDSTR_SCHEME (&grpc_static_slice_table[79]) /* "server" */ -#define GRPC_MDSTR_SERVER (&grpc_static_mdstr_table[80]) +#define GRPC_MDSTR_SERVER (&grpc_static_slice_table[80]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (&grpc_static_mdstr_table[81]) +#define GRPC_MDSTR_SET_COOKIE (&grpc_static_slice_table[81]) /* "/" */ -#define GRPC_MDSTR_SLASH (&grpc_static_mdstr_table[82]) +#define GRPC_MDSTR_SLASH (&grpc_static_slice_table[82]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_mdstr_table[83]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_slice_table[83]) /* ":status" */ -#define GRPC_MDSTR_STATUS (&grpc_static_mdstr_table[84]) +#define GRPC_MDSTR_STATUS (&grpc_static_slice_table[84]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_mdstr_table[85]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_slice_table[85]) /* "te" */ -#define GRPC_MDSTR_TE (&grpc_static_mdstr_table[86]) +#define GRPC_MDSTR_TE (&grpc_static_slice_table[86]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (&grpc_static_mdstr_table[87]) +#define GRPC_MDSTR_TRAILERS (&grpc_static_slice_table[87]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_mdstr_table[88]) +#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_slice_table[88]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (&grpc_static_mdstr_table[89]) +#define GRPC_MDSTR_USER_AGENT (&grpc_static_slice_table[89]) /* "vary" */ -#define GRPC_MDSTR_VARY (&grpc_static_mdstr_table[90]) +#define GRPC_MDSTR_VARY (&grpc_static_slice_table[90]) /* "via" */ -#define GRPC_MDSTR_VIA (&grpc_static_mdstr_table[91]) +#define GRPC_MDSTR_VIA (&grpc_static_slice_table[91]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_mdstr_table[92]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_slice_table[92]) + +bool grpc_is_static_metadata_string(grpc_slice slice); #define GRPC_STATIC_MDELEM_COUNT 81 extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; @@ -409,9 +411,9 @@ extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; /* "www-authenticate": "" */ #define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[80]) +grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b); extern const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2]; -extern const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT]; extern const uint8_t grpc_static_accept_encoding_metadata[8]; #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]) diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index cf3762dbb8d..388bdc611da 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -31,8 +31,11 @@ import hashlib import itertools +import collections import os import sys +import subprocess +import re # configuration: a list of either strings or 2-tuples of strings # a single string represents a static grpc_mdstr @@ -281,12 +284,43 @@ print >>C, '#include "src/core/lib/transport/static_metadata.h"' print >>C print >>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) -print >>H, 'extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];' +print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' for i, elem in enumerate(all_strs): print >>H, '/* "%s" */' % elem - print >>H, '#define %s (&grpc_static_mdstr_table[%d])' % (mangle(elem).upper(), i) + print >>H, '#define %s (&grpc_static_slice_table[%d])' % (mangle(elem).upper(), i) print >>H -print >>C, 'grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];' +print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice);' +print >>H +print >>C, 'static uint8_t g_raw_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in ''.join(all_strs))) +print >>C +print >>C, 'static void static_ref(void *unused) {}' +print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' +print >>C, 'static grpc_slice_refcount g_refcnt = {static_ref, static_unref};' +print >>C +print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' +print >>C, ' return slice.refcount != NULL && slice.refcount->ref == static_ref;' +print >>C, '};' +print >>C +print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' +str_ofs = 0 +revmap = {} +zero_length_idx = None +for i, elem in enumerate(all_strs): + print >>C, '{.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes+%d, .length=%d}},' % (str_ofs, len(elem)) + revmap[str_ofs] = i + if len(elem) == 0: zero_length_idx = i + str_ofs += len(elem); +print >>C, '};' +print >>C +print >>C, 'static const uint8_t g_revmap[] = {%s};' % ','.join('%d' % (revmap[i] if i in revmap else 255) for i in range(0, str_ofs)) +print >>C +print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {' +print >>C, ' if (GRPC_SLICE_LENGTH(slice) == 0) return %d;' % zero_length_idx +print >>C, ' size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);' +print >>C, ' if (ofs > sizeof(g_revmap)) return -1;' +print >>C, ' uint8_t id = g_revmap[ofs];' +print >>C, ' return id == 255 ? -1 : id;' +print >>C, '};' print >>C print >>D, '# hpack fuzzing dictionary' @@ -319,18 +353,72 @@ def md_idx(m): if m == m2: return i +def perfect_hash(keys, name): + tmp = open('/tmp/keys.txt', 'w') + tmp.write(''.join('%d\n' % (x - min(keys)) for x in keys)) + tmp.close() + cmd = '%s/perfect/run.sh %s -ds' % (os.path.dirname(sys.argv[0]), tmp.name) + subprocess.check_call(cmd, shell=True) + + code = '' + + results = {} + with open('%s/perfect/phash.h' % os.path.dirname(sys.argv[0])) as f: + txt = f.read() + for var in ('PHASHLEN', 'PHASHNKEYS', 'PHASHRANGE', 'PHASHSALT'): + val = re.search(r'#define %s ([0-9a-zA-Z]+)' % var, txt).group(1) + code += '#define %s_%s %s\n' % (name.upper(), var, val) + results[var] = val + code += '\n' + pycode = 'def f(val):\n' + pycode += ' val -= %d\n' % min(keys) + with open('%s/perfect/phash.c' % os.path.dirname(sys.argv[0])) as f: + txt = f.read() + tabdata = re.search(r'ub1 tab\[\] = \{([^}]+)\}', txt, re.MULTILINE).group(1) + code += 'static const uint8_t %s_tab[] = {%s};\n\n' % (name, tabdata) + func_body = re.search(r'ub4 phash\(val\)\nub4 val;\n\{([^}]+)\}', txt, re.MULTILINE).group(1).replace('ub4', 'uint32_t') + code += 'static uint32_t %s_phash(uint32_t val) {\nval -= %d;\n%s}\n' % (name, + min(keys), func_body.replace('tab', '%s_tab' % name)) + pycode += ' tab=(%s)' % tabdata.replace('\n', '') + pycode += '\n'.join(' %s' % s.strip() for s in func_body.splitlines()[2:]) + g = {} + exec pycode in g + pyfunc = g['f'] + + results['code'] = code + results['pyfunc'] = pyfunc + return results + +elem_keys = [str_idx(elem[0]) * len(all_strs) + str_idx(elem[1]) for elem in all_elems] +elem_hash = perfect_hash(elem_keys, "elems") +print >>C, elem_hash['code'] + +keys = [0] * int(elem_hash['PHASHRANGE']) +idxs = [-1] * int(elem_hash['PHASHNKEYS']) +for i, k in enumerate(elem_keys): + h = elem_hash['pyfunc'](k) + assert keys[h] == 0 + keys[h] = k + idxs[h] = i +print >>C, 'static const uint16_t elem_keys[] = {%s};' % ','.join('%d' % k for k in keys) +print >>C, 'static const uint8_t elem_idxs[] = {%s};' % ','.join('%d' % i for i in idxs) +print >>C + +print >>H, 'grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b);' +print >>C, 'grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) {' +print >>C, ' if (a == -1 || b == -1) return NULL;' +print >>C, ' uint32_t k = (uint32_t)(a * %d + b);' % len(all_strs) +print >>C, ' uint32_t h = elems_phash(k);' +print >>C, ' return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL;' +print >>C, '}' +print >>C + print >>H, 'extern const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2];' print >>C, 'const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2] = {' print >>C, ','.join('%d' % str_idx(x) for x in itertools.chain.from_iterable([a,b] for a, b in all_elems)) print >>C, '};' print >>C -print >>H, 'extern const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT];' -print >>C, 'const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = {' -print >>C, '%s' % ',\n'.join(' "%s"' % s for s in all_strs) -print >>C, '};' -print >>C - print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) From 5ef31ab9c92429e64a43501a4bd440760cca399b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 10 Nov 2016 16:27:48 -0800 Subject: [PATCH 011/261] Progress towards mdstr elimination --- BUILD | 16 +- CMakeLists.txt | 6 +- Makefile | 8 +- binding.gyp | 2 +- build.yaml | 4 +- config.m4 | 2 +- gRPC-Core.podspec | 6 +- grpc.def | 5 +- grpc.gemspec | 4 +- include/grpc/compression.h | 8 +- include/grpc/slice.h | 5 +- package.xml | 4 +- src/core/ext/client_channel/client_channel.c | 24 +-- src/core/ext/client_channel/subchannel.c | 2 +- src/core/ext/client_channel/subchannel.h | 2 +- src/core/ext/lb_policy/grpclb/grpclb.c | 2 +- .../transport/chttp2/transport/bin_decoder.c | 10 +- .../chttp2/transport/hpack_encoder.h | 2 +- .../transport/chttp2/transport/hpack_parser.c | 4 +- .../ext/transport/chttp2/transport/parsing.c | 2 +- src/core/lib/channel/channel_stack.c | 2 +- src/core/lib/channel/channel_stack.h | 4 +- src/core/lib/channel/compress_filter.c | 15 +- src/core/lib/channel/http_client_filter.c | 54 ++--- src/core/lib/channel/http_server_filter.c | 45 +++-- src/core/lib/channel/message_size_filter.c | 6 +- src/core/lib/compression/algorithm_metadata.h | 4 +- src/core/lib/compression/compression.c | 35 ++-- src/core/lib/iomgr/load_file.c | 2 +- .../google_default_credentials.c | 2 +- .../security/transport/client_auth_filter.c | 4 +- .../security/transport/security_connector.c | 2 +- .../security/transport/server_auth_filter.c | 4 +- src/core/lib/security/util/b64.c | 2 +- src/core/lib/slice/slice.c | 2 +- .../slice_hash_table.c} | 98 +++++---- .../slice_hash_table.h} | 52 ++--- src/core/lib/surface/call.c | 6 +- src/core/lib/surface/server.c | 14 +- src/core/lib/transport/metadata.c | 26 +-- src/core/lib/transport/method_config.c | 82 ++++---- src/core/lib/transport/method_config.h | 74 +++---- src/core/lib/transport/static_metadata.h | 186 +++++++++--------- src/cpp/util/slice_cc.cc | 2 +- src/python/grpcio/grpc_core_dependencies.py | 2 +- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 10 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 17 +- tools/codegen/core/gen_static_metadata.py | 2 +- tools/doxygen/Doxyfile.core.internal | 4 +- tools/run_tests/sources_and_headers.json | 6 +- vsprojects/vcxproj/grpc/grpc.vcxproj | 6 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 12 +- .../grpc_test_util/grpc_test_util.vcxproj | 6 +- .../grpc_test_util.vcxproj.filters | 12 +- .../grpc_unsecure/grpc_unsecure.vcxproj | 6 +- .../grpc_unsecure.vcxproj.filters | 12 +- 56 files changed, 491 insertions(+), 445 deletions(-) rename src/core/lib/{transport/mdstr_hash_table.c => slice/slice_hash_table.c} (58%) rename src/core/lib/{transport/mdstr_hash_table.h => slice/slice_hash_table.h} (66%) diff --git a/BUILD b/BUILD index 9088b61f0d9..22680a69621 100644 --- a/BUILD +++ b/BUILD @@ -231,6 +231,7 @@ cc_library( "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", @@ -245,7 +246,6 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "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", @@ -413,6 +413,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_hash_table.c", "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", @@ -435,7 +436,6 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "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", @@ -667,6 +667,7 @@ cc_library( "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", @@ -681,7 +682,6 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "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", @@ -834,6 +834,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_hash_table.c", "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", @@ -856,7 +857,6 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "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", @@ -1058,6 +1058,7 @@ cc_library( "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", @@ -1072,7 +1073,6 @@ cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "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", @@ -1217,6 +1217,7 @@ cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_hash_table.c", "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", @@ -1239,7 +1240,6 @@ cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "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", @@ -2084,6 +2084,7 @@ objc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_hash_table.c", "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", @@ -2106,7 +2107,6 @@ objc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "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", @@ -2317,6 +2317,7 @@ objc_library( "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", @@ -2331,7 +2332,6 @@ objc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "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", diff --git a/CMakeLists.txt b/CMakeLists.txt index e6e7ff78483..1b17f4cfb70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -368,6 +368,7 @@ add_library(grpc src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_hash_table.c src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c @@ -390,7 +391,6 @@ add_library(grpc src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c 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 @@ -649,6 +649,7 @@ add_library(grpc_cronet src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_hash_table.c src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c @@ -671,7 +672,6 @@ add_library(grpc_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c 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 @@ -902,6 +902,7 @@ add_library(grpc_unsecure src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_hash_table.c src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c @@ -924,7 +925,6 @@ add_library(grpc_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c 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 diff --git a/Makefile b/Makefile index 4e053179f17..eea4e7176f9 100644 --- a/Makefile +++ b/Makefile @@ -2699,6 +2699,7 @@ LIBGRPC_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -2721,7 +2722,6 @@ LIBGRPC_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ @@ -2998,6 +2998,7 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -3020,7 +3021,6 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ @@ -3288,6 +3288,7 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -3310,7 +3311,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ @@ -3507,6 +3507,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -3529,7 +3530,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ diff --git a/binding.gyp b/binding.gyp index 0cc776241a4..c600ba01490 100644 --- a/binding.gyp +++ b/binding.gyp @@ -647,6 +647,7 @@ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_hash_table.c', 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', @@ -669,7 +670,6 @@ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', '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', diff --git a/build.yaml b/build.yaml index 16a4afca782..de19a3e851d 100644 --- a/build.yaml +++ b/build.yaml @@ -238,6 +238,7 @@ filegroups: - src/core/lib/json/json_reader.h - src/core/lib/json/json_writer.h - src/core/lib/slice/percent_encoding.h + - src/core/lib/slice/slice_hash_table.h - src/core/lib/slice/slice_string_helpers.h - src/core/lib/surface/api_trace.h - src/core/lib/surface/call.h @@ -252,7 +253,6 @@ filegroups: - src/core/lib/surface/server.h - src/core/lib/transport/byte_stream.h - 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 @@ -344,6 +344,7 @@ filegroups: - src/core/lib/slice/percent_encoding.c - src/core/lib/slice/slice.c - src/core/lib/slice/slice_buffer.c + - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c - src/core/lib/slice/slice_string_helpers.c - src/core/lib/surface/alarm.c @@ -366,7 +367,6 @@ filegroups: - src/core/lib/surface/version.c - src/core/lib/transport/byte_stream.c - 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 diff --git a/config.m4 b/config.m4 index 3c9b0982654..d87adfdf68a 100644 --- a/config.m4 +++ b/config.m4 @@ -163,6 +163,7 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ + src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -185,7 +186,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index e73b8e05738..5902701d37b 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -321,6 +321,7 @@ Pod::Spec.new do |s| 'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_writer.h', 'src/core/lib/slice/percent_encoding.h', + 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/call.h', @@ -335,7 +336,6 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', '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', @@ -507,6 +507,7 @@ Pod::Spec.new do |s| 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_hash_table.c', 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', @@ -529,7 +530,6 @@ Pod::Spec.new do |s| 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', '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', @@ -725,6 +725,7 @@ Pod::Spec.new do |s| 'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_writer.h', 'src/core/lib/slice/percent_encoding.h', + 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/surface/api_trace.h', 'src/core/lib/surface/call.h', @@ -739,7 +740,6 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', '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', diff --git a/grpc.def b/grpc.def index 61bc173c600..02a18f88f05 100644 --- a/grpc.def +++ b/grpc.def @@ -149,9 +149,12 @@ EXPORTS grpc_slice_sub_no_ref grpc_slice_split_tail grpc_slice_split_head - gpr_empty_slice + grpc_empty_slice grpc_slice_cmp grpc_slice_str_cmp + grpc_slice_buf_cmp + grpc_slice_buf_start_eq + grpc_slice_hash grpc_slice_buffer_init grpc_slice_buffer_destroy grpc_slice_buffer_add diff --git a/grpc.gemspec b/grpc.gemspec index c50fc5a3c9c..20b37578fc3 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -241,6 +241,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/json/json_reader.h ) s.files += %w( src/core/lib/json/json_writer.h ) s.files += %w( src/core/lib/slice/percent_encoding.h ) + s.files += %w( src/core/lib/slice/slice_hash_table.h ) s.files += %w( src/core/lib/slice/slice_string_helpers.h ) s.files += %w( src/core/lib/surface/api_trace.h ) s.files += %w( src/core/lib/surface/call.h ) @@ -255,7 +256,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/server.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) - 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 ) @@ -427,6 +427,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/slice/percent_encoding.c ) s.files += %w( src/core/lib/slice/slice.c ) s.files += %w( src/core/lib/slice/slice_buffer.c ) + s.files += %w( src/core/lib/slice/slice_hash_table.c ) s.files += %w( src/core/lib/slice/slice_intern.c ) s.files += %w( src/core/lib/slice/slice_string_helpers.c ) s.files += %w( src/core/lib/surface/alarm.c ) @@ -449,7 +450,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/version.c ) s.files += %w( src/core/lib/transport/byte_stream.c ) s.files += %w( src/core/lib/transport/connectivity_state.c ) - 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 ) diff --git a/include/grpc/compression.h b/include/grpc/compression.h index 5f285cdcdf4..659d6fe7582 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -34,11 +34,12 @@ #ifndef GRPC_COMPRESSION_H #define GRPC_COMPRESSION_H -#include - #include +#include + #include +#include #ifdef __cplusplus extern "C" { @@ -48,8 +49,7 @@ extern "C" { * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon * success, 0 otherwise. */ GRPCAPI int grpc_compression_algorithm_parse( - const char *name, size_t name_length, - grpc_compression_algorithm *algorithm); + grpc_slice value, grpc_compression_algorithm *algorithm); /** Updates \a name with the encoding name corresponding to a valid \a * algorithm. Note that \a name is statically allocated and must *not* be freed. diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 53a650f3995..dd9cbd5d0bf 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -119,13 +119,16 @@ GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split); Requires s intialized, split <= s.length */ GPRAPI grpc_slice grpc_slice_split_head(grpc_slice *s, size_t split); -GPRAPI grpc_slice gpr_empty_slice(void); +GPRAPI grpc_slice grpc_empty_slice(void); /* Returns <0 if a < b, ==0 if a == b, >0 if a > b The order is arbitrary, and is not guaranteed to be stable across different versions of the API. */ GPRAPI int grpc_slice_cmp(grpc_slice a, grpc_slice b); GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b); +GPRAPI int grpc_slice_buf_cmp(grpc_slice a, const void *b, size_t blen); + +GPRAPI int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t blen); GPRAPI uint32_t grpc_slice_hash(grpc_slice s); diff --git a/package.xml b/package.xml index 786e25a589a..997cf1812d1 100644 --- a/package.xml +++ b/package.xml @@ -248,6 +248,7 @@ + @@ -262,7 +263,6 @@ - @@ -434,6 +434,7 @@ + @@ -456,7 +457,6 @@ - diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 7954fcfb8b2..94ca656b2a0 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -96,7 +96,7 @@ static void method_parameters_del(grpc_exec_ctx *exec_ctx, void *p) { gpr_free(p); } -static const grpc_mdstr_hash_table_vtable method_parameters_vtable = { +static const grpc_slice_hash_table_vtable method_parameters_vtable = { method_parameters_del, method_parameters_copy, method_parameters_cmp}; static void *method_config_convert_value( @@ -131,7 +131,7 @@ typedef struct client_channel_channel_data { char *lb_policy_name; grpc_lb_policy *lb_policy; /** maps method names to method_parameters structs */ - grpc_mdstr_hash_table *method_params_table; + grpc_slice_hash_table *method_params_table; /** incoming resolver result - set by resolver.next() */ grpc_channel_args *resolver_result; /** a list of closures that are all waiting for config to come in */ @@ -232,7 +232,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, char *lb_policy_name = NULL; grpc_lb_policy *lb_policy = NULL; grpc_lb_policy *old_lb_policy; - grpc_mdstr_hash_table *method_params_table = NULL; + grpc_slice_hash_table *method_params_table = NULL; grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; bool exit_idle = false; grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); @@ -316,7 +316,7 @@ 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 (chand->method_params_table != NULL) { - grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } chand->method_params_table = method_params_table; if (lb_policy != NULL) { @@ -494,7 +494,7 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, } gpr_free(chand->lb_policy_name); if (chand->method_params_table != NULL) { - grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); } grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); grpc_pollset_set_destroy(chand->interested_parties); @@ -529,7 +529,7 @@ typedef struct client_channel_call_data { // to avoid this without breaking the grpc_deadline_state abstraction. grpc_deadline_state deadline_state; - grpc_mdstr *path; // Request path. + grpc_slice path; // Request path. gpr_timespec call_start_time; gpr_timespec deadline; wait_for_ready_value wait_for_ready_from_service_config; @@ -926,10 +926,10 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg, if (error == GRPC_ERROR_NONE) { // Get the method config table from channel data. gpr_mu_lock(&chand->mu); - grpc_mdstr_hash_table *method_params_table = NULL; + grpc_slice_hash_table *method_params_table = NULL; if (chand->method_params_table != NULL) { method_params_table = - grpc_mdstr_hash_table_ref(chand->method_params_table); + grpc_slice_hash_table_ref(chand->method_params_table); } gpr_mu_unlock(&chand->mu); // If the method config table was present, use it. @@ -958,7 +958,7 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_unlock(&calld->mu); } } - grpc_mdstr_hash_table_unref(exec_ctx, method_params_table); + grpc_slice_hash_table_unref(exec_ctx, method_params_table); } } GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "read_service_config"); @@ -996,8 +996,8 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, if (chand->lb_policy != NULL) { // We already have a resolver result, so check for service config. if (chand->method_params_table != NULL) { - grpc_mdstr_hash_table *method_params_table = - grpc_mdstr_hash_table_ref(chand->method_params_table); + grpc_slice_hash_table *method_params_table = + grpc_slice_hash_table_ref(chand->method_params_table); gpr_mu_unlock(&chand->mu); method_parameters *method_params = grpc_method_config_table_get( exec_ctx, method_params_table, args->path); @@ -1013,7 +1013,7 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, method_params->wait_for_ready; } } - grpc_mdstr_hash_table_unref(exec_ctx, method_params_table); + grpc_slice_hash_table_unref(exec_ctx, method_params_table); } else { gpr_mu_unlock(&chand->mu); } diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index bcb3082267e..7b64a76f671 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -703,7 +703,7 @@ grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( grpc_error *grpc_connected_subchannel_create_call( grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_polling_entity *pollent, grpc_mdstr *path, gpr_timespec deadline, + grpc_polling_entity *pollent, grpc_slice path, gpr_timespec deadline, grpc_subchannel_call **call) { grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); *call = gpr_malloc(sizeof(grpc_subchannel_call) + chanstk->call_stack_size); diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index 93bd72d20d5..17208cb8534 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -111,7 +111,7 @@ void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, /** construct a subchannel call */ grpc_error *grpc_connected_subchannel_create_call( grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, - grpc_polling_entity *pollent, grpc_mdstr *path, gpr_timespec deadline, + grpc_polling_entity *pollent, grpc_slice path, gpr_timespec deadline, grpc_subchannel_call **subchannel_call); /** process a transport level op */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 29ad1311c47..37b232a0a42 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -447,7 +447,7 @@ static grpc_lb_addresses *process_serverlist( GPR_ARRAY_SIZE(server->load_balance_token); const size_t lb_token_length = strnlen(server->load_balance_token, lb_token_max_length); - grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer( + grpc_slice lb_token_mdstr = grpc_mdstr_from_buffer( (uint8_t *)server->load_balance_token, lb_token_length); user_data = grpc_mdelem_from_metadata_strings( exec_ctx, GRPC_MDSTR_LB_TOKEN, lb_token_mdstr); diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.c b/src/core/ext/transport/chttp2/transport/bin_decoder.c index 8db36e4a7f0..1a3637a1e3e 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.c +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.c @@ -157,7 +157,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, "grpc_chttp2_base64_decode has a length of %d, which is not a " "multiple of 4.\n", (int)input_length); - return gpr_empty_slice(); + return grpc_empty_slice(); } if (input_length > 0) { @@ -182,7 +182,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); - return gpr_empty_slice(); + return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.input_cur == GRPC_SLICE_END_PTR(input)); @@ -204,7 +204,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, "has a tail of 1 byte.\n", (int)input_length); grpc_slice_unref_internal(exec_ctx, output); - return gpr_empty_slice(); + return grpc_empty_slice(); } if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { @@ -214,7 +214,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, (int)output_length, (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); grpc_slice_unref_internal(exec_ctx, output); - return gpr_empty_slice(); + return grpc_empty_slice(); } ctx.input_cur = GRPC_SLICE_START_PTR(input); @@ -228,7 +228,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); - return gpr_empty_slice(); + return grpc_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.input_cur <= GRPC_SLICE_END_PTR(input)); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 3a35496ec8a..82d61a15ec0 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -74,7 +74,7 @@ typedef struct { /* entry tables for keys & elems: these tables track values that have been seen and *may* be in the decompressor table */ - grpc_mdstr *entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; + grpc_slice entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; grpc_mdelem *entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index f4e69df12d6..3bb82fd29d2 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -681,9 +681,9 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, return GRPC_ERROR_NONE; } -static grpc_mdstr *take_string(grpc_chttp2_hpack_parser *p, +static grpc_slice take_string(grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser_string *str) { - grpc_mdstr *s = grpc_mdstr_from_buffer((uint8_t *)str->str, str->length); + grpc_slice s = grpc_mdstr_from_buffer((uint8_t *)str->str, str->length); str->length = 0; return s; } diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index e1202e2ca55..35609f08e48 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -200,7 +200,7 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, return err; } if (t->incoming_frame_size == 0) { - err = parse_frame_slice(exec_ctx, t, gpr_empty_slice(), 1); + err = parse_frame_slice(exec_ctx, t, grpc_empty_slice(), 1); if (err != GRPC_ERROR_NONE) { return err; } diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index 947dff4cb31..30e7d65d9ca 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -162,7 +162,7 @@ grpc_error *grpc_call_stack_init( grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, grpc_call_context_element *context, const void *transport_server_data, - grpc_mdstr *path, gpr_timespec deadline, grpc_call_stack *call_stack) { + grpc_slice path, gpr_timespec deadline, grpc_call_stack *call_stack) { grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK(channel_stack); grpc_call_element_args args; size_t count = channel_stack->count; diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index c3b662c9691..17ec027305c 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -74,7 +74,7 @@ typedef struct { grpc_call_stack *call_stack; const void *server_transport_data; grpc_call_context_element *context; - grpc_mdstr *path; + grpc_slice path; gpr_timespec start_time; gpr_timespec deadline; } grpc_call_element_args; @@ -231,7 +231,7 @@ grpc_error *grpc_call_stack_init( grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, grpc_call_context_element *context, const void *transport_server_data, - grpc_mdstr *path, gpr_timespec deadline, grpc_call_stack *call_stack); + grpc_slice path, gpr_timespec deadline, grpc_call_stack *call_stack); /* Set a pollset or a pollset_set for a call stack: must occur before the first * op is started */ void grpc_call_stack_set_pollset_or_pollset_set(grpc_exec_ctx *exec_ctx, diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index dd496ee0952..f58ab42d539 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -45,6 +45,7 @@ #include "src/core/lib/compression/message_compress.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" @@ -88,21 +89,23 @@ static grpc_mdelem *compression_md_filter(void *user_data, grpc_mdelem *md) { call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; - if (md->key == GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) { - const char *md_c_str = grpc_mdstr_as_c_string(md->value); - if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str), + if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) == 0) { + if (!grpc_compression_algorithm_parse(md->value, &calld->compression_algorithm)) { + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (unknown). Ignoring.", - md_c_str); + "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); + gpr_free(val); calld->compression_algorithm = GRPC_COMPRESS_NONE; } if (!GPR_BITGET(channeld->enabled_algorithms_bitset, calld->compression_algorithm)) { + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (previously disabled). " "Ignoring.", - md_c_str); + val); + gpr_free(val); calld->compression_algorithm = GRPC_COMPRESS_NONE; } calld->has_compression_algorithm = 1; diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 63afa4bf099..2ef066c5b2b 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -37,6 +37,7 @@ #include #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/transport_impl.h" @@ -98,23 +99,24 @@ static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) { client_recv_filter_args *a = user_data; if (md == GRPC_MDELEM_STATUS_200) { return NULL; - } else if (md->key == GRPC_MDSTR_STATUS) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_STATUS) == 0) { char *message_string; - gpr_asprintf(&message_string, "Received http2 header with status: %s", - grpc_mdstr_as_c_string(md->value)); + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + gpr_asprintf(&message_string, "Received http2 header with status: %s", val); grpc_slice message = grpc_slice_from_copied_string(message_string); gpr_free(message_string); + gpr_free(val); grpc_call_element_send_close_with_message(a->exec_ctx, a->elem, GRPC_STATUS_CANCELLED, &message); return NULL; } else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { return NULL; - } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { - const char *value_str = grpc_mdstr_as_c_string(md->value); - if (strncmp(value_str, EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) == 0 && - (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || - value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) { + if (grpc_slice_buf_start_eq(md->value, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) && + (GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == + ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ /* TODO(klempner): We should consider preallocating common values such @@ -123,7 +125,9 @@ static grpc_mdelem *client_recv_filter(void *user_data, grpc_mdelem *md) { } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - gpr_log(GPR_INFO, "Unexpected content-type '%s'", value_str); + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); + gpr_free(val); } return NULL; } @@ -162,11 +166,11 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { static grpc_mdelem *client_strip_filter(void *user_data, grpc_mdelem *md) { /* eat the things we'd like to set ourselves */ - if (md->key == GRPC_MDSTR_METHOD) return NULL; - if (md->key == GRPC_MDSTR_SCHEME) return NULL; - if (md->key == GRPC_MDSTR_TE) return NULL; - if (md->key == GRPC_MDSTR_CONTENT_TYPE) return NULL; - if (md->key == GRPC_MDSTR_USER_AGENT) return NULL; + if (grpc_slice_cmp(md->key, GRPC_MDSTR_METHOD) == 0) return NULL; + if (grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME) == 0) return NULL; + if (grpc_slice_cmp(md->key, GRPC_MDSTR_TE) == 0) return NULL; + if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) return NULL; + if (grpc_slice_cmp(md->key, GRPC_MDSTR_USER_AGENT) == 0) return NULL; return md; } @@ -244,10 +248,10 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, if (calld->send_message_blocked == false) { /* when all the send_message data is available, then create a MDELEM and append to headers */ - grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings( + grpc_mdelem *payload_bin = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN, - grpc_mdstr_from_buffer(calld->payload_bytes, - op->send_message->length)); + grpc_slice_from_copied_buffer((const char *)calld->payload_bytes, + op->send_message->length)); grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->payload_bin, payload_bin); calld->on_complete = op->on_complete; @@ -338,8 +342,8 @@ static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { if (args->args[i].type == GRPC_ARG_STRING && strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { for (j = 0; j < GPR_ARRAY_SIZE(valid_schemes); j++) { - if (0 == strcmp(grpc_mdstr_as_c_string(valid_schemes[j]->value), - args->args[i].value.string)) { + if (0 == grpc_slice_str_cmp(valid_schemes[j]->value, + args->args[i].value.string)) { return valid_schemes[j]; } } @@ -365,13 +369,13 @@ static size_t max_payload_size_from_args(const grpc_channel_args *args) { return kMaxPayloadSizeForGet; } -static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args, - const char *transport_name) { +static grpc_slice user_agent_from_args(const grpc_channel_args *args, + const char *transport_name) { gpr_strvec v; size_t i; int is_first = 1; char *tmp; - grpc_mdstr *result; + grpc_slice result; gpr_strvec_init(&v); @@ -409,7 +413,7 @@ static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args, tmp = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); - result = grpc_mdstr_from_string(tmp); + result = grpc_slice_intern(grpc_slice_from_static_string(tmp)); gpr_free(tmp); return result; @@ -425,7 +429,7 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx, chand->static_scheme = scheme_from_args(args->channel_args); chand->max_payload_size_for_get = max_payload_size_from_args(args->channel_args); - chand->user_agent = grpc_mdelem_from_metadata_strings( + chand->user_agent = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args, args->optional_transport->vtable->name)); diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index cb0fe230cf4..23f1a600025 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -38,6 +38,7 @@ #include #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/static_metadata.h" #define EXPECTED_CONTENT_TYPE "application/grpc" @@ -108,7 +109,7 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { } else if (md == GRPC_MDELEM_METHOD_GET) { calld->seen_method = 1; *calld->recv_cacheable_request = true; - } else if (md->key == GRPC_MDSTR_SCHEME) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME)) { calld->seen_scheme = 1; } else if (md == GRPC_MDELEM_TE_TRAILERS) { calld->seen_te_trailers = 1; @@ -116,12 +117,12 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { /* TODO(klempner): Track that we've seen all the headers we should require */ return NULL; - } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { - const char *value_str = grpc_mdstr_as_c_string(md->value); - if (strncmp(value_str, EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) == 0 && - (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || - value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE)) { + if (grpc_slice_buf_start_eq(md->value, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) && + (GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == + ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ /* TODO(klempner): We should consider preallocating common values such @@ -130,41 +131,47 @@ static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - gpr_log(GPR_INFO, "Unexpected content-type '%s'", value_str); + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); + gpr_free(val); } return NULL; - } else if (md->key == GRPC_MDSTR_TE || md->key == GRPC_MDSTR_METHOD || - md->key == GRPC_MDSTR_SCHEME) { - gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", - grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)); + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_TE) == 0 || + grpc_slice_cmp(md->key, GRPC_MDSTR_METHOD) == 0 || + grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME) == 0) { + char *key = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", key, value); /* swallow it and error everything out. */ /* TODO(klempner): We ought to generate more descriptive error messages on the wire here. */ grpc_call_element_send_cancel(a->exec_ctx, elem); + gpr_free(key); + gpr_free(value); return NULL; - } else if (md->key == GRPC_MDSTR_PATH) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { if (calld->seen_path) { gpr_log(GPR_ERROR, "Received :path twice"); return NULL; } calld->seen_path = 1; return md; - } else if (md->key == GRPC_MDSTR_AUTHORITY) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { calld->seen_authority = 1; return md; - } else if (md->key == GRPC_MDSTR_HOST) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_HOST) == 0) { /* translate host to :authority since :authority may be omitted */ - grpc_mdelem *authority = grpc_mdelem_from_metadata_strings( - a->exec_ctx, GRPC_MDSTR_AUTHORITY, GRPC_MDSTR_REF(md->value)); + grpc_mdelem *authority = grpc_mdelem_from_slices( + a->exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(md->value)); calld->seen_authority = 1; return authority; - } else if (md->key == GRPC_MDSTR_GRPC_PAYLOAD_BIN) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_PAYLOAD_BIN) == 0) { /* Retrieve the payload from the value of the 'grpc-internal-payload-bin' header field */ calld->seen_payload_bin = 1; grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_slice_ref_internal(md->value->slice)); + grpc_slice_ref_internal(md->value)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); return NULL; diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index 1655d843d5c..4f61da825e3 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -68,7 +68,7 @@ static int message_size_limits_cmp(void* value1, void* value2) { static void free_mem(grpc_exec_ctx* exec_ctx, void* p) { gpr_free(p); } -static const grpc_mdstr_hash_table_vtable message_size_limits_vtable = { +static const grpc_slice_hash_table_vtable message_size_limits_vtable = { free_mem, message_size_limits_copy, message_size_limits_cmp}; static void* method_config_convert_value( @@ -102,7 +102,7 @@ typedef struct channel_data { int max_send_size; int max_recv_size; // Maps path names to message_size_limits structs. - grpc_mdstr_hash_table* method_limit_table; + grpc_slice_hash_table* method_limit_table; } channel_data; // Callback invoked when we receive a message. Here we check the max @@ -236,7 +236,7 @@ static void init_channel_elem(grpc_exec_ctx* exec_ctx, static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) { channel_data* chand = elem->channel_data; - grpc_mdstr_hash_table_unref(exec_ctx, chand->method_limit_table); + grpc_slice_hash_table_unref(exec_ctx, chand->method_limit_table); } const grpc_channel_filter grpc_message_size_filter = { diff --git a/src/core/lib/compression/algorithm_metadata.h b/src/core/lib/compression/algorithm_metadata.h index 1f9cc15f230..7412054bfef 100644 --- a/src/core/lib/compression/algorithm_metadata.h +++ b/src/core/lib/compression/algorithm_metadata.h @@ -38,7 +38,7 @@ #include "src/core/lib/transport/metadata.h" /** Return compression algorithm based metadata value */ -grpc_mdstr *grpc_compression_algorithm_mdstr( +grpc_slice grpc_compression_algorithm_mdstr( grpc_compression_algorithm algorithm); /** Return compression algorithm based metadata element (grpc-encoding: xxx) */ @@ -48,6 +48,6 @@ grpc_mdelem *grpc_compression_encoding_mdelem( /** Find compression algorithm based on passed in mdstr - returns * GRPC_COMPRESS_ALGORITHM_COUNT on failure */ grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( - grpc_mdstr *str); + grpc_slice str); #endif /* GRPC_CORE_LIB_COMPRESSION_ALGORITHM_METADATA_H */ diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index 54efb5e855c..aa3caf9fef5 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -41,30 +41,24 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/transport/static_metadata.h" -int grpc_compression_algorithm_parse(const char *name, size_t name_length, +int grpc_compression_algorithm_parse(grpc_slice name, grpc_compression_algorithm *algorithm) { /* we use strncmp not only because it's safer (even though in this case it * doesn't matter, given that we are comparing against string literals, but * because this way we needn't have "name" nil-terminated (useful for slice * data, for example) */ - GRPC_API_TRACE( - "grpc_compression_algorithm_parse(" - "name=%*.*s, name_length=%lu, algorithm=%p)", - 5, ((int)name_length, (int)name_length, name, (unsigned long)name_length, - algorithm)); - if (name_length == 0) { - return 0; - } - if (strncmp(name, "identity", name_length) == 0) { + if (grpc_slice_cmp(name, GRPC_MDSTR_IDENTITY) == 0) { *algorithm = GRPC_COMPRESS_NONE; - } else if (strncmp(name, "gzip", name_length) == 0) { + return 1; + } else if (grpc_slice_cmp(name, GRPC_MDSTR_GZIP) == 0) { *algorithm = GRPC_COMPRESS_GZIP; - } else if (strncmp(name, "deflate", name_length) == 0) { + return 1; + } else if (grpc_slice_cmp(name, GRPC_MDSTR_DEFLATE) == 0) { *algorithm = GRPC_COMPRESS_DEFLATE; + return 1; } else { return 0; } - return 1; } int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, @@ -88,14 +82,15 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, } grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( - grpc_mdstr *str) { - if (str == GRPC_MDSTR_IDENTITY) return GRPC_COMPRESS_NONE; - if (str == GRPC_MDSTR_DEFLATE) return GRPC_COMPRESS_DEFLATE; - if (str == GRPC_MDSTR_GZIP) return GRPC_COMPRESS_GZIP; + grpc_slice str) { + if (grpc_slice_cmp(str, GRPC_MDSTR_IDENTITY) == 0) return GRPC_COMPRESS_NONE; + if (grpc_slice_cmp(str, GRPC_MDSTR_DEFLATE) == 0) + return GRPC_COMPRESS_DEFLATE; + if (grpc_slice_cmp(str, GRPC_MDSTR_GZIP) == 0) return GRPC_COMPRESS_GZIP; return GRPC_COMPRESS_ALGORITHMS_COUNT; } -grpc_mdstr *grpc_compression_algorithm_mdstr( +grpc_slice grpc_compression_algorithm_mdstr( grpc_compression_algorithm algorithm) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -105,9 +100,9 @@ grpc_mdstr *grpc_compression_algorithm_mdstr( case GRPC_COMPRESS_GZIP: return GRPC_MDSTR_GZIP; case GRPC_COMPRESS_ALGORITHMS_COUNT: - return NULL; + return grpc_empty_slice(); } - return NULL; + return grpc_empty_slice(); } grpc_mdelem *grpc_compression_encoding_mdelem( diff --git a/src/core/lib/iomgr/load_file.c b/src/core/lib/iomgr/load_file.c index 217bc5da594..f40c8b28ccd 100644 --- a/src/core/lib/iomgr/load_file.c +++ b/src/core/lib/iomgr/load_file.c @@ -47,7 +47,7 @@ grpc_error *grpc_load_file(const char *filename, int add_null_terminator, grpc_slice *output) { unsigned char *contents = NULL; size_t contents_size = 0; - grpc_slice result = gpr_empty_slice(); + grpc_slice result = grpc_empty_slice(); FILE *file; size_t bytes_read = 0; grpc_error *error = GRPC_ERROR_NONE; diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.c b/src/core/lib/security/credentials/google_default/google_default_credentials.c index 7bed78daf7d..65eb02bbb96 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.c +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.c @@ -174,7 +174,7 @@ static grpc_error *create_default_creds_from_path( grpc_auth_json_key key; grpc_auth_refresh_token token; grpc_call_credentials *result = NULL; - grpc_slice creds_data = gpr_empty_slice(); + grpc_slice creds_data = grpc_empty_slice(); grpc_error *error = GRPC_ERROR_NONE; if (creds_path == NULL) { error = GRPC_ERROR_CREATE("creds_path unset"); diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index ae40bb499ca..e9e77182b61 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -54,8 +54,8 @@ /* We can have a per-call credentials. */ typedef struct { grpc_call_credentials *creds; - grpc_mdstr *host; - grpc_mdstr *method; + grpc_slice host; + grpc_slice method; /* pollset{_set} bound to this call; if we need to make external network requests, they should be done under a pollset added to this pollset_set so that work can progress when this call wants work to progress diff --git a/src/core/lib/security/transport/security_connector.c b/src/core/lib/security/transport/security_connector.c index 7192f228cd6..53bccb3efbd 100644 --- a/src/core/lib/security/transport/security_connector.c +++ b/src/core/lib/security/transport/security_connector.c @@ -649,7 +649,7 @@ static grpc_security_connector_vtable ssl_server_vtable = { ssl_server_destroy, ssl_server_check_peer}; static grpc_slice compute_default_pem_root_certs_once(void) { - grpc_slice result = gpr_empty_slice(); + grpc_slice result = grpc_empty_slice(); /* First try to load the roots from the environment. */ char *default_root_certs_path = diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 246ca35bc6b..1b43bdd4bad 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -68,8 +68,8 @@ static grpc_metadata_array metadata_batch_to_md_array( for (l = batch->list.head; l != NULL; l = l->next) { grpc_metadata *usr_md = NULL; grpc_mdelem *md = l->md; - grpc_mdstr *key = md->key; - grpc_mdstr *value = md->value; + grpc_slice key = md->key; + grpc_slice value = md->value; if (result.count == result.capacity) { result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2); result.metadata = diff --git a/src/core/lib/security/util/b64.c b/src/core/lib/security/util/b64.c index bbd7e335a67..09c82131316 100644 --- a/src/core/lib/security/util/b64.c +++ b/src/core/lib/security/util/b64.c @@ -232,5 +232,5 @@ grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64, fail: grpc_slice_unref_internal(exec_ctx, result); - return gpr_empty_slice(); + return grpc_empty_slice(); } diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 6da0952e27b..d1f045bd6f6 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -41,7 +41,7 @@ #include "src/core/lib/iomgr/exec_ctx.h" -grpc_slice gpr_empty_slice(void) { +grpc_slice grpc_empty_slice(void) { grpc_slice out; out.refcount = 0; out.data.inlined.length = 0; diff --git a/src/core/lib/transport/mdstr_hash_table.c b/src/core/lib/slice/slice_hash_table.c similarity index 58% rename from src/core/lib/transport/mdstr_hash_table.c rename to src/core/lib/slice/slice_hash_table.c index a3f6bde516d..743a6b1836b 100644 --- a/src/core/lib/transport/mdstr_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -29,7 +29,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // -#include "src/core/lib/transport/mdstr_hash_table.h" +#include "src/core/lib/slice/slice_hash_table.h" #include #include @@ -37,72 +37,88 @@ #include #include +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" -struct grpc_mdstr_hash_table { +static grpc_slice_refcount terminal_slice_refcount = {0}; +static const grpc_slice terminal_slice = {&terminal_slice_refcount, + .data.refcounted = {0, 0}}; + +struct grpc_slice_hash_table { gpr_refcount refs; size_t num_entries; size_t size; - grpc_mdstr_hash_table_entry* entries; + grpc_slice_hash_table_entry* entries; }; +static bool is_terminal(grpc_slice slice) { + return slice.refcount == &terminal_slice_refcount; +} + // Helper function for insert and get operations that performs quadratic // probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_mdstr_hash_table_find_index( - const grpc_mdstr_hash_table* table, const grpc_mdstr* key, - bool find_empty) { +static size_t grpc_slice_hash_table_find_index( + const grpc_slice_hash_table* table, const grpc_slice key, bool find_empty) { + size_t hash = grpc_slice_hash(key); for (size_t i = 0; i < table->size; ++i) { - const size_t idx = (key->hash + i * i) % table->size; - if (table->entries[idx].key == NULL) return find_empty ? idx : table->size; - if (table->entries[idx].key == key) return idx; + const size_t idx = (hash + i * i) % table->size; + if (is_terminal(table->entries[idx].key)) { + return find_empty ? idx : table->size; + } + if (grpc_slice_cmp(table->entries[idx].key, key) == 0) { + return idx; + } } return table->size; // Not found. } -static void grpc_mdstr_hash_table_add( - grpc_mdstr_hash_table* table, grpc_mdstr* key, void* value, - const grpc_mdstr_hash_table_vtable* vtable) { +static void grpc_slice_hash_table_add( + grpc_slice_hash_table* table, grpc_slice key, void* value, + const grpc_slice_hash_table_vtable* vtable) { GPR_ASSERT(value != NULL); const size_t idx = - grpc_mdstr_hash_table_find_index(table, key, true /* find_empty */); + grpc_slice_hash_table_find_index(table, key, true /* find_empty */); GPR_ASSERT(idx != table->size); // Table should never be full. - grpc_mdstr_hash_table_entry* entry = &table->entries[idx]; - entry->key = GRPC_MDSTR_REF(key); + grpc_slice_hash_table_entry* entry = &table->entries[idx]; + entry->key = grpc_slice_ref(key); entry->value = vtable->copy_value(value); entry->vtable = vtable; } -grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( - size_t num_entries, grpc_mdstr_hash_table_entry* entries) { - grpc_mdstr_hash_table* table = gpr_malloc(sizeof(*table)); +grpc_slice_hash_table* grpc_slice_hash_table_create( + size_t num_entries, grpc_slice_hash_table_entry* entries) { + grpc_slice_hash_table* table = gpr_malloc(sizeof(*table)); memset(table, 0, sizeof(*table)); gpr_ref_init(&table->refs, 1); table->num_entries = num_entries; // Quadratic probing gets best performance when the table is no more // than half full. table->size = num_entries * 2; - const size_t entry_size = sizeof(grpc_mdstr_hash_table_entry) * table->size; + const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; table->entries = gpr_malloc(entry_size); memset(table->entries, 0, entry_size); for (size_t i = 0; i < num_entries; ++i) { - grpc_mdstr_hash_table_entry* entry = &entries[i]; - grpc_mdstr_hash_table_add(table, entry->key, entry->value, entry->vtable); + table->entries[i].key = terminal_slice; + } + for (size_t i = 0; i < num_entries; ++i) { + grpc_slice_hash_table_entry* entry = &entries[i]; + grpc_slice_hash_table_add(table, entry->key, entry->value, entry->vtable); } return table; } -grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table) { +grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { if (table != NULL) gpr_ref(&table->refs); return table; } -int grpc_mdstr_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_mdstr_hash_table* table) { +int grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_slice_hash_table* table) { if (table != NULL && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { - grpc_mdstr_hash_table_entry* entry = &table->entries[i]; - if (entry->key != NULL) { - GRPC_MDSTR_UNREF(exec_ctx, entry->key); + grpc_slice_hash_table_entry* entry = &table->entries[i]; + if (!is_terminal(entry->key)) { + grpc_slice_unref_internal(exec_ctx, entry->key); entry->vtable->destroy_value(exec_ctx, entry->value); } } @@ -113,29 +129,29 @@ int grpc_mdstr_hash_table_unref(grpc_exec_ctx* exec_ctx, return 0; } -size_t grpc_mdstr_hash_table_num_entries(const grpc_mdstr_hash_table* table) { +size_t grpc_slice_hash_table_num_entries(const grpc_slice_hash_table* table) { return table->num_entries; } -void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, - const grpc_mdstr* key) { +void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, + const grpc_slice key) { const size_t idx = - grpc_mdstr_hash_table_find_index(table, key, false /* find_empty */); + grpc_slice_hash_table_find_index(table, key, false /* find_empty */); if (idx == table->size) return NULL; // Not found. return table->entries[idx].value; } -int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1, - const grpc_mdstr_hash_table* table2) { +int grpc_slice_hash_table_cmp(const grpc_slice_hash_table* table1, + const grpc_slice_hash_table* table2) { // Compare by num_entries. if (table1->num_entries < table2->num_entries) return -1; if (table1->num_entries > table2->num_entries) return 1; for (size_t i = 0; i < table1->num_entries; ++i) { - grpc_mdstr_hash_table_entry* e1 = &table1->entries[i]; - grpc_mdstr_hash_table_entry* e2 = &table2->entries[i]; + grpc_slice_hash_table_entry* e1 = &table1->entries[i]; + grpc_slice_hash_table_entry* e2 = &table2->entries[i]; // Compare keys by hash value. - if (e1->key->hash < e2->key->hash) return -1; - if (e1->key->hash > e2->key->hash) return 1; + int cmp = grpc_slice_cmp(e1->key, e2->key); + if (cmp != 0) return cmp; // Compare by vtable (pointer equality). if (e1->vtable < e2->vtable) return -1; if (e1->vtable > e2->vtable) return 1; @@ -146,12 +162,12 @@ int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1, return 0; } -void grpc_mdstr_hash_table_iterate( - const grpc_mdstr_hash_table* table, - void (*func)(const grpc_mdstr_hash_table_entry* entry, void* user_data), +void grpc_slice_hash_table_iterate( + const grpc_slice_hash_table* table, + void (*func)(const grpc_slice_hash_table_entry* entry, void* user_data), void* user_data) { for (size_t i = 0; i < table->size; ++i) { - if (table->entries[i].key != NULL) { + if (!is_terminal(table->entries[i].key)) { func(&table->entries[i], user_data); } } diff --git a/src/core/lib/transport/mdstr_hash_table.h b/src/core/lib/slice/slice_hash_table.h similarity index 66% rename from src/core/lib/transport/mdstr_hash_table.h rename to src/core/lib/slice/slice_hash_table.h index 45e5720063a..ac04950cc66 100644 --- a/src/core/lib/transport/mdstr_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -40,54 +40,54 @@ * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic * probing (https://en.wikipedia.org/wiki/Quadratic_probing). * - * The keys are \a grpc_mdstr objects. The values are arbitrary pointers + * The keys are \a grpc_slice objects. The values are arbitrary pointers * with a common vtable. * * Hash tables are intentionally immutable, to avoid the need for locking. */ -typedef struct grpc_mdstr_hash_table grpc_mdstr_hash_table; +typedef struct grpc_slice_hash_table grpc_slice_hash_table; -typedef struct grpc_mdstr_hash_table_vtable { - void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); - void* (*copy_value)(void* value); - int (*compare_value)(void* value1, void* value2); -} grpc_mdstr_hash_table_vtable; +typedef struct grpc_slice_hash_table_vtable { + void (*destroy_value)(grpc_exec_ctx *exec_ctx, void *value); + void *(*copy_value)(void *value); + int (*compare_value)(void *value1, void *value2); +} grpc_slice_hash_table_vtable; -typedef struct grpc_mdstr_hash_table_entry { - grpc_mdstr* key; - void* value; /* Must not be NULL. */ - const grpc_mdstr_hash_table_vtable* vtable; -} grpc_mdstr_hash_table_entry; +typedef struct grpc_slice_hash_table_entry { + grpc_slice key; + void *value; /* Must not be NULL. */ + const grpc_slice_hash_table_vtable *vtable; +} grpc_slice_hash_table_entry; /** Creates a new hash table of containing \a entries, which is an array of length \a num_entries. Creates its own copy of all keys and values from \a entries. */ -grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( - size_t num_entries, grpc_mdstr_hash_table_entry* entries); +grpc_slice_hash_table *grpc_slice_hash_table_create( + size_t num_entries, grpc_slice_hash_table_entry *entries); -grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table); +grpc_slice_hash_table *grpc_slice_hash_table_ref(grpc_slice_hash_table *table); /** Returns 1 when \a table is destroyed. */ -int grpc_mdstr_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_mdstr_hash_table* table); +int grpc_slice_hash_table_unref(grpc_exec_ctx *exec_ctx, + grpc_slice_hash_table *table); /** Returns the number of entries in \a table. */ -size_t grpc_mdstr_hash_table_num_entries(const grpc_mdstr_hash_table* table); +size_t grpc_slice_hash_table_num_entries(const grpc_slice_hash_table *table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ -void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, - const grpc_mdstr* key); +void *grpc_slice_hash_table_get(const grpc_slice_hash_table *table, + const grpc_slice key); /** Compares two hash tables. The sort order is stable but undefined. */ -int grpc_mdstr_hash_table_cmp(const grpc_mdstr_hash_table* table1, - const grpc_mdstr_hash_table* table2); +int grpc_slice_hash_table_cmp(const grpc_slice_hash_table *table1, + const grpc_slice_hash_table *table2); /** Iterates over the entries in \a table, calling \a func for each entry. */ -void grpc_mdstr_hash_table_iterate( - const grpc_mdstr_hash_table* table, - void (*func)(const grpc_mdstr_hash_table_entry* entry, void* user_data), - void* user_data); +void grpc_slice_hash_table_iterate( + const grpc_slice_hash_table *table, + void (*func)(const grpc_slice_hash_table_entry *entry, void *user_data), + void *user_data); #endif /* GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H */ diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 9be13d84fe3..f826d320430 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -94,7 +94,7 @@ typedef enum { typedef struct { uint8_t is_set; grpc_status_code code; - grpc_mdstr *details; + grpc_slice details; } received_status; typedef struct batch_control { @@ -244,7 +244,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); call->is_client = args->server_transport_data == NULL; - grpc_mdstr *path = NULL; + grpc_slice path = NULL; if (call->is_client) { GPR_ASSERT(args->add_initial_metadata_count < MAX_SEND_EXTRA_METADATA_COUNT); @@ -443,7 +443,7 @@ static void set_status_code(grpc_call *call, status_source source, } static void set_status_details(grpc_exec_ctx *exec_ctx, grpc_call *call, - status_source source, grpc_mdstr *status) { + status_source source, grpc_slice status) { if (call->status[source].details != NULL) { GRPC_MDSTR_UNREF(exec_ctx, status); } else { diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 530e5ed46ce..8f0cfbbc17e 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -98,8 +98,8 @@ typedef struct requested_call { typedef struct channel_registered_method { registered_method *server_registered_method; uint32_t flags; - grpc_mdstr *method; - grpc_mdstr *host; + grpc_slice method; + grpc_slice host; } channel_registered_method; struct channel_data { @@ -144,8 +144,8 @@ struct call_data { /** the current state of a call - see call_state */ call_state state; - grpc_mdstr *path; - grpc_mdstr *host; + grpc_slice path; + grpc_slice host; gpr_timespec deadline; grpc_completion_queue *cq_new; @@ -459,7 +459,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, op); } -static void cpstr(char **dest, size_t *capacity, grpc_mdstr *value) { +static void cpstr(char **dest, size_t *capacity, grpc_slice value) { grpc_slice slice = value->slice; size_t len = GRPC_SLICE_LENGTH(slice); @@ -1136,8 +1136,8 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, channel_registered_method *crm; grpc_channel *channel; channel_data *chand; - grpc_mdstr *host; - grpc_mdstr *method; + grpc_slice host; + grpc_slice method; uint32_t hash; size_t slots; uint32_t probes; diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index c0743e124a5..fd6c52c4c15 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -137,7 +137,7 @@ void grpc_mdctx_global_init(void) { memset(g_static_mdtab, 0, sizeof(g_static_mdtab)); memset(g_static_strtab, 0, sizeof(g_static_strtab)); for (i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - grpc_mdstr *elem = &grpc_static_mdstr_table[i]; + grpc_slice elem = &grpc_static_mdstr_table[i]; const char *str = grpc_static_metadata_strings[i]; uint32_t hash = gpr_murmur_hash3(str, strlen(str), g_hash_seed); *(grpc_slice *)&elem->slice = grpc_slice_from_static_string(str); @@ -155,13 +155,13 @@ void grpc_mdctx_global_init(void) { } for (i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { grpc_mdelem *elem = &grpc_static_mdelem_table[i]; - grpc_mdstr *key = + grpc_slice key = &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 0]]; - grpc_mdstr *value = + grpc_slice value = &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 1]]; uint32_t hash = GRPC_MDSTR_KV_HASH(key->hash, value->hash); - *(grpc_mdstr **)&elem->key = key; - *(grpc_mdstr **)&elem->value = value; + *(grpc_slice *)&elem->key = key; + *(grpc_slice *)&elem->value = value; for (j = 0;; j++) { size_t idx = (hash + j) % GPR_ARRAY_SIZE(g_static_mdtab); if (g_static_mdtab[idx] == NULL) { @@ -216,8 +216,8 @@ static void ref_md_locked(mdtab_shard *shard, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_mdstr *)md->key), - grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif if (0 == gpr_atm_no_barrier_fetch_add(&md->refcnt, 1)) { gpr_atm_no_barrier_fetch_add(&shard->free_estimate, -1); @@ -351,8 +351,8 @@ grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(GPR_DEBUG, "ELM NEW:%p:%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - grpc_mdstr_as_c_string((grpc_mdstr *)md->key), - grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif shard->count++; @@ -391,8 +391,8 @@ grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *gmd DEBUG_ARGS) { "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_mdstr *)md->key), - grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif /* we can assume the ref count is >= 1 as the application is calling this function - meaning that no adjustment to mdtab_free is necessary, @@ -412,8 +412,8 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *gmd DEBUG_ARGS) { "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), gpr_atm_no_barrier_load(&md->refcnt) - 1, - grpc_mdstr_as_c_string((grpc_mdstr *)md->key), - grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), grpc_slice_hash(md->value)); diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c index 25fb54b37db..0b3a6c8fbbd 100644 --- a/src/core/lib/transport/method_config.c +++ b/src/core/lib/transport/method_config.c @@ -39,7 +39,7 @@ #include #include -#include "src/core/lib/transport/mdstr_hash_table.h" +#include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/transport/metadata.h" // @@ -65,7 +65,7 @@ static int bool_cmp(void* v1, void* v2) { static void free_mem(grpc_exec_ctx* exec_ctx, void* p) { gpr_free(p); } -static grpc_mdstr_hash_table_vtable bool_vtable = {free_mem, bool_copy, +static grpc_slice_hash_table_vtable bool_vtable = {free_mem, bool_copy, bool_cmp}; // timespec vtable @@ -81,7 +81,7 @@ static int timespec_cmp(void* v1, void* v2) { return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); } -static grpc_mdstr_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, +static grpc_slice_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, timespec_cmp}; // int32 vtable @@ -101,7 +101,7 @@ static int int32_cmp(void* v1, void* v2) { return 0; } -static grpc_mdstr_hash_table_vtable int32_vtable = {free_mem, int32_copy, +static grpc_slice_hash_table_vtable int32_vtable = {free_mem, int32_copy, int32_cmp}; // Hash table keys. @@ -113,11 +113,11 @@ static grpc_mdstr_hash_table_vtable int32_vtable = {free_mem, int32_copy, "grpc.max_response_message_bytes" // int32 struct grpc_method_config { - grpc_mdstr_hash_table* table; - grpc_mdstr* wait_for_ready_key; - grpc_mdstr* timeout_key; - grpc_mdstr* max_request_message_bytes_key; - grpc_mdstr* max_response_message_bytes_key; + grpc_slice_hash_table* table; + grpc_slice wait_for_ready_key; + grpc_slice timeout_key; + grpc_slice max_request_message_bytes_key; + grpc_slice max_response_message_bytes_key; }; grpc_method_config* grpc_method_config_create( @@ -133,7 +133,7 @@ grpc_method_config* grpc_method_config_create( grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); method_config->max_response_message_bytes_key = grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); - grpc_mdstr_hash_table_entry entries[4]; + grpc_slice_hash_table_entry entries[4]; size_t num_entries = 0; if (wait_for_ready != NULL) { entries[num_entries].key = method_config->wait_for_ready_key; @@ -159,18 +159,18 @@ grpc_method_config* grpc_method_config_create( entries[num_entries].vtable = &int32_vtable; ++num_entries; } - method_config->table = grpc_mdstr_hash_table_create(num_entries, entries); + method_config->table = grpc_slice_hash_table_create(num_entries, entries); return method_config; } grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { - grpc_mdstr_hash_table_ref(method_config->table); + grpc_slice_hash_table_ref(method_config->table); return method_config; } void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, grpc_method_config* method_config) { - if (grpc_mdstr_hash_table_unref(exec_ctx, method_config->table)) { + if (grpc_slice_hash_table_unref(exec_ctx, method_config->table)) { GRPC_MDSTR_UNREF(exec_ctx, method_config->wait_for_ready_key); GRPC_MDSTR_UNREF(exec_ctx, method_config->timeout_key); GRPC_MDSTR_UNREF(exec_ctx, method_config->max_request_message_bytes_key); @@ -181,31 +181,31 @@ void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, int grpc_method_config_cmp(const grpc_method_config* method_config1, const grpc_method_config* method_config2) { - return grpc_mdstr_hash_table_cmp(method_config1->table, + return grpc_slice_hash_table_cmp(method_config1->table, method_config2->table); } const bool* grpc_method_config_get_wait_for_ready( const grpc_method_config* method_config) { - return grpc_mdstr_hash_table_get(method_config->table, + return grpc_slice_hash_table_get(method_config->table, method_config->wait_for_ready_key); } const gpr_timespec* grpc_method_config_get_timeout( const grpc_method_config* method_config) { - return grpc_mdstr_hash_table_get(method_config->table, + return grpc_slice_hash_table_get(method_config->table, method_config->timeout_key); } const int32_t* grpc_method_config_get_max_request_message_bytes( const grpc_method_config* method_config) { - return grpc_mdstr_hash_table_get( + return grpc_slice_hash_table_get( method_config->table, method_config->max_request_message_bytes_key); } const int32_t* grpc_method_config_get_max_response_message_bytes( const grpc_method_config* method_config) { - return grpc_mdstr_hash_table_get( + return grpc_slice_hash_table_get( method_config->table, method_config->max_response_message_bytes_key); } @@ -225,43 +225,43 @@ static int method_config_cmp(void* valuep1, void* valuep2) { return grpc_method_config_cmp(valuep1, valuep2); } -static const grpc_mdstr_hash_table_vtable method_config_table_vtable = { +static const grpc_slice_hash_table_vtable method_config_table_vtable = { method_config_unref, method_config_ref, method_config_cmp}; grpc_method_config_table* grpc_method_config_table_create( size_t num_entries, grpc_method_config_table_entry* entries) { - grpc_mdstr_hash_table_entry* hash_table_entries = - gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * num_entries); + grpc_slice_hash_table_entry* hash_table_entries = + gpr_malloc(sizeof(grpc_slice_hash_table_entry) * num_entries); for (size_t i = 0; i < num_entries; ++i) { hash_table_entries[i].key = entries[i].method_name; hash_table_entries[i].value = entries[i].method_config; hash_table_entries[i].vtable = &method_config_table_vtable; } grpc_method_config_table* method_config_table = - grpc_mdstr_hash_table_create(num_entries, hash_table_entries); + grpc_slice_hash_table_create(num_entries, hash_table_entries); gpr_free(hash_table_entries); return method_config_table; } grpc_method_config_table* grpc_method_config_table_ref( grpc_method_config_table* table) { - return grpc_mdstr_hash_table_ref(table); + return grpc_slice_hash_table_ref(table); } void grpc_method_config_table_unref(grpc_exec_ctx* exec_ctx, grpc_method_config_table* table) { - grpc_mdstr_hash_table_unref(exec_ctx, table); + grpc_slice_hash_table_unref(exec_ctx, table); } int grpc_method_config_table_cmp(const grpc_method_config_table* table1, const grpc_method_config_table* table2) { - return grpc_mdstr_hash_table_cmp(table1, table2); + return grpc_slice_hash_table_cmp(table1, table2); } void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_mdstr_hash_table* table, - const grpc_mdstr* path) { - void* value = grpc_mdstr_hash_table_get(table, path); + const grpc_slice_hash_table* table, + const grpc_slice path) { + void* value = grpc_slice_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) { @@ -272,9 +272,9 @@ void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, memcpy(buf, path_str, len); buf[len] = '*'; buf[len + 1] = '\0'; - grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); + grpc_slice wildcard_path = grpc_mdstr_from_string(buf); gpr_free(buf); - value = grpc_mdstr_hash_table_get(table, wildcard_path); + value = grpc_slice_hash_table_get(table, wildcard_path); GRPC_MDSTR_UNREF(exec_ctx, wildcard_path); } return value; @@ -305,14 +305,14 @@ grpc_arg grpc_method_config_table_create_channel_arg( // State used by convert_entry() below. typedef struct conversion_state { void* (*convert_value)(const grpc_method_config* method_config); - const grpc_mdstr_hash_table_vtable* vtable; + const grpc_slice_hash_table_vtable* vtable; size_t num_entries; - grpc_mdstr_hash_table_entry* entries; + grpc_slice_hash_table_entry* entries; } conversion_state; -// A function to be passed to grpc_mdstr_hash_table_iterate() to create +// A function to be passed to grpc_slice_hash_table_iterate() to create // a copy of the entries. -static void convert_entry(const grpc_mdstr_hash_table_entry* entry, +static void convert_entry(const grpc_slice_hash_table_entry* entry, void* user_data) { conversion_state* state = user_data; state->entries[state->num_entries].key = GRPC_MDSTR_REF(entry->key); @@ -321,21 +321,21 @@ static void convert_entry(const grpc_mdstr_hash_table_entry* entry, ++state->num_entries; } -grpc_mdstr_hash_table* grpc_method_config_table_convert( +grpc_slice_hash_table* grpc_method_config_table_convert( grpc_exec_ctx* exec_ctx, const grpc_method_config_table* table, void* (*convert_value)(const grpc_method_config* method_config), - const grpc_mdstr_hash_table_vtable* vtable) { + const grpc_slice_hash_table_vtable* vtable) { // Create an array of the entries in the table with converted values. conversion_state state; state.convert_value = convert_value; state.vtable = vtable; state.num_entries = 0; - state.entries = gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * - grpc_mdstr_hash_table_num_entries(table)); - grpc_mdstr_hash_table_iterate(table, convert_entry, &state); + state.entries = gpr_malloc(sizeof(grpc_slice_hash_table_entry) * + grpc_slice_hash_table_num_entries(table)); + grpc_slice_hash_table_iterate(table, convert_entry, &state); // Create a new table based on the array we just constructed. - grpc_mdstr_hash_table* new_table = - grpc_mdstr_hash_table_create(state.num_entries, state.entries); + grpc_slice_hash_table* new_table = + grpc_slice_hash_table_create(state.num_entries, state.entries); // Clean up the array. for (size_t i = 0; i < state.num_entries; ++i) { GRPC_MDSTR_UNREF(exec_ctx, state.entries[i].key); diff --git a/src/core/lib/transport/method_config.h b/src/core/lib/transport/method_config.h index d17a493fd4d..3e266a6ecd4 100644 --- a/src/core/lib/transport/method_config.h +++ b/src/core/lib/transport/method_config.h @@ -37,7 +37,7 @@ #include #include -#include "src/core/lib/transport/mdstr_hash_table.h" +#include "src/core/lib/slice/slice_hash_table.h" #include "src/core/lib/transport/metadata.h" /// Per-method configuration. @@ -55,70 +55,70 @@ typedef struct grpc_method_config grpc_method_config; /// \a max_request_message_bytes and \a max_response_message_bytes /// indicate the maximum sizes of the request (checked when sending) and /// response (checked when receiving) messages. -grpc_method_config* grpc_method_config_create( - bool* wait_for_ready, gpr_timespec* timeout, - int32_t* max_request_message_bytes, int32_t* max_response_message_bytes); +grpc_method_config *grpc_method_config_create( + bool *wait_for_ready, gpr_timespec *timeout, + int32_t *max_request_message_bytes, int32_t *max_response_message_bytes); -grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); -void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, - grpc_method_config* method_config); +grpc_method_config *grpc_method_config_ref(grpc_method_config *method_config); +void grpc_method_config_unref(grpc_exec_ctx *exec_ctx, + grpc_method_config *method_config); /// Compares two grpc_method_configs. /// The sort order is stable but undefined. -int grpc_method_config_cmp(const grpc_method_config* method_config1, - const grpc_method_config* method_config2); +int grpc_method_config_cmp(const grpc_method_config *method_config1, + const grpc_method_config *method_config2); /// These methods return NULL if the requested field is unset. /// The caller does NOT take ownership of the result. -const bool* grpc_method_config_get_wait_for_ready( - const grpc_method_config* method_config); -const gpr_timespec* grpc_method_config_get_timeout( - const grpc_method_config* method_config); -const int32_t* grpc_method_config_get_max_request_message_bytes( - const grpc_method_config* method_config); -const int32_t* grpc_method_config_get_max_response_message_bytes( - const grpc_method_config* method_config); +const bool *grpc_method_config_get_wait_for_ready( + const grpc_method_config *method_config); +const gpr_timespec *grpc_method_config_get_timeout( + const grpc_method_config *method_config); +const int32_t *grpc_method_config_get_max_request_message_bytes( + const grpc_method_config *method_config); +const int32_t *grpc_method_config_get_max_response_message_bytes( + const grpc_method_config *method_config); /// A table of method configs. -typedef grpc_mdstr_hash_table grpc_method_config_table; +typedef grpc_slice_hash_table grpc_method_config_table; typedef struct grpc_method_config_table_entry { /// The name is of one of the following forms: /// service/method -- specifies exact service and method name /// service/* -- matches all methods for the specified service - grpc_mdstr* method_name; - grpc_method_config* method_config; + grpc_slice method_name; + grpc_method_config *method_config; } grpc_method_config_table_entry; /// Takes new references to all keys and values in \a entries. -grpc_method_config_table* grpc_method_config_table_create( - size_t num_entries, grpc_method_config_table_entry* entries); +grpc_method_config_table *grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry *entries); -grpc_method_config_table* grpc_method_config_table_ref( - grpc_method_config_table* table); -void grpc_method_config_table_unref(grpc_exec_ctx* exec_ctx, - grpc_method_config_table* table); +grpc_method_config_table *grpc_method_config_table_ref( + grpc_method_config_table *table); +void grpc_method_config_table_unref(grpc_exec_ctx *exec_ctx, + grpc_method_config_table *table); /// Compares two grpc_method_config_tables. /// The sort order is stable but undefined. -int grpc_method_config_table_cmp(const grpc_method_config_table* table1, - const grpc_method_config_table* table2); +int grpc_method_config_table_cmp(const grpc_method_config_table *table1, + const grpc_method_config_table *table2); /// 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. /// -/// Note: This returns a void* instead of a grpc_method_config* so that +/// Note: This returns a void *instead of a grpc_method_config *so that /// it can also be used for tables constructed via /// grpc_method_config_table_convert(). -void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_mdstr_hash_table* table, - const grpc_mdstr* path); +void *grpc_method_config_table_get(grpc_exec_ctx *exec_ctx, + const grpc_slice_hash_table *table, + const grpc_slice path); /// Returns a channel arg containing \a table. grpc_arg grpc_method_config_table_create_channel_arg( - grpc_method_config_table* table); + grpc_method_config_table *table); /// Generates a new table from \a table whose values are converted to a /// new form via the \a convert_value function. The new table will use @@ -131,9 +131,9 @@ grpc_arg grpc_method_config_table_create_channel_arg( /// will return a new instance of the struct containing the values from /// the grpc_method_config, and \a vtable provides the methods for /// operating on the struct type. -grpc_mdstr_hash_table* grpc_method_config_table_convert( - grpc_exec_ctx* exec_ctx, const grpc_method_config_table* table, - void* (*convert_value)(const grpc_method_config* method_config), - const grpc_mdstr_hash_table_vtable* vtable); +grpc_slice_hash_table *grpc_method_config_table_convert( + grpc_exec_ctx *exec_ctx, const grpc_method_config_table *table, + void *(*convert_value)(const grpc_method_config *method_config), + const grpc_slice_hash_table_vtable *vtable); #endif /* GRPC_CORE_LIB_TRANSPORT_METHOD_CONFIG_H */ diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index dccac395cd1..cbe721f4078 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -47,192 +47,192 @@ #define GRPC_STATIC_MDSTR_COUNT 93 extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ -#define GRPC_MDSTR_0 (&grpc_static_slice_table[0]) +#define GRPC_MDSTR_0 (grpc_static_slice_table[0]) /* "1" */ -#define GRPC_MDSTR_1 (&grpc_static_slice_table[1]) +#define GRPC_MDSTR_1 (grpc_static_slice_table[1]) /* "2" */ -#define GRPC_MDSTR_2 (&grpc_static_slice_table[2]) +#define GRPC_MDSTR_2 (grpc_static_slice_table[2]) /* "200" */ -#define GRPC_MDSTR_200 (&grpc_static_slice_table[3]) +#define GRPC_MDSTR_200 (grpc_static_slice_table[3]) /* "204" */ -#define GRPC_MDSTR_204 (&grpc_static_slice_table[4]) +#define GRPC_MDSTR_204 (grpc_static_slice_table[4]) /* "206" */ -#define GRPC_MDSTR_206 (&grpc_static_slice_table[5]) +#define GRPC_MDSTR_206 (grpc_static_slice_table[5]) /* "304" */ -#define GRPC_MDSTR_304 (&grpc_static_slice_table[6]) +#define GRPC_MDSTR_304 (grpc_static_slice_table[6]) /* "400" */ -#define GRPC_MDSTR_400 (&grpc_static_slice_table[7]) +#define GRPC_MDSTR_400 (grpc_static_slice_table[7]) /* "404" */ -#define GRPC_MDSTR_404 (&grpc_static_slice_table[8]) +#define GRPC_MDSTR_404 (grpc_static_slice_table[8]) /* "500" */ -#define GRPC_MDSTR_500 (&grpc_static_slice_table[9]) +#define GRPC_MDSTR_500 (grpc_static_slice_table[9]) /* "accept" */ -#define GRPC_MDSTR_ACCEPT (&grpc_static_slice_table[10]) +#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[10]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (&grpc_static_slice_table[11]) +#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[11]) /* "accept-encoding" */ -#define GRPC_MDSTR_ACCEPT_ENCODING (&grpc_static_slice_table[12]) +#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table[12]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (&grpc_static_slice_table[13]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[13]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (&grpc_static_slice_table[14]) +#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[14]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (&grpc_static_slice_table[15]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[15]) /* "age" */ -#define GRPC_MDSTR_AGE (&grpc_static_slice_table[16]) +#define GRPC_MDSTR_AGE (grpc_static_slice_table[16]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (&grpc_static_slice_table[17]) +#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[17]) /* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (&grpc_static_slice_table[18]) +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[18]) /* ":authority" */ -#define GRPC_MDSTR_AUTHORITY (&grpc_static_slice_table[19]) +#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table[19]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (&grpc_static_slice_table[20]) +#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[20]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (&grpc_static_slice_table[21]) +#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[21]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (&grpc_static_slice_table[22]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[22]) /* "content-encoding" */ -#define GRPC_MDSTR_CONTENT_ENCODING (&grpc_static_slice_table[23]) +#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table[23]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (&grpc_static_slice_table[24]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[24]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (&grpc_static_slice_table[25]) +#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[25]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (&grpc_static_slice_table[26]) +#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[26]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (&grpc_static_slice_table[27]) +#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[27]) /* "content-type" */ -#define GRPC_MDSTR_CONTENT_TYPE (&grpc_static_slice_table[28]) +#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table[28]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (&grpc_static_slice_table[29]) +#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[29]) /* "date" */ -#define GRPC_MDSTR_DATE (&grpc_static_slice_table[30]) +#define GRPC_MDSTR_DATE (grpc_static_slice_table[30]) /* "deflate" */ -#define GRPC_MDSTR_DEFLATE (&grpc_static_slice_table[31]) +#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[31]) /* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (&grpc_static_slice_table[32]) +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[32]) /* "" */ -#define GRPC_MDSTR_EMPTY (&grpc_static_slice_table[33]) +#define GRPC_MDSTR_EMPTY (grpc_static_slice_table[33]) /* "etag" */ -#define GRPC_MDSTR_ETAG (&grpc_static_slice_table[34]) +#define GRPC_MDSTR_ETAG (grpc_static_slice_table[34]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (&grpc_static_slice_table[35]) +#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[35]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (&grpc_static_slice_table[36]) +#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[36]) /* "from" */ -#define GRPC_MDSTR_FROM (&grpc_static_slice_table[37]) +#define GRPC_MDSTR_FROM (grpc_static_slice_table[37]) /* "GET" */ -#define GRPC_MDSTR_GET (&grpc_static_slice_table[38]) +#define GRPC_MDSTR_GET (grpc_static_slice_table[38]) /* "grpc" */ -#define GRPC_MDSTR_GRPC (&grpc_static_slice_table[39]) +#define GRPC_MDSTR_GRPC (grpc_static_slice_table[39]) /* "grpc-accept-encoding" */ -#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (&grpc_static_slice_table[40]) +#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[40]) /* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (&grpc_static_slice_table[41]) +#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[41]) /* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (&grpc_static_slice_table[42]) +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[42]) /* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (&grpc_static_slice_table[43]) +#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[43]) /* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (&grpc_static_slice_table[44]) +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[44]) /* "grpc-stats-bin" */ -#define GRPC_MDSTR_GRPC_STATS_BIN (&grpc_static_slice_table[45]) +#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[45]) /* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (&grpc_static_slice_table[46]) +#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[46]) /* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (&grpc_static_slice_table[47]) +#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[47]) /* "grpc-tracing-bin" */ -#define GRPC_MDSTR_GRPC_TRACING_BIN (&grpc_static_slice_table[48]) +#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[48]) /* "gzip" */ -#define GRPC_MDSTR_GZIP (&grpc_static_slice_table[49]) +#define GRPC_MDSTR_GZIP (grpc_static_slice_table[49]) /* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (&grpc_static_slice_table[50]) +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[50]) /* "host" */ -#define GRPC_MDSTR_HOST (&grpc_static_slice_table[51]) +#define GRPC_MDSTR_HOST (grpc_static_slice_table[51]) /* "http" */ -#define GRPC_MDSTR_HTTP (&grpc_static_slice_table[52]) +#define GRPC_MDSTR_HTTP (grpc_static_slice_table[52]) /* "https" */ -#define GRPC_MDSTR_HTTPS (&grpc_static_slice_table[53]) +#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[53]) /* "identity" */ -#define GRPC_MDSTR_IDENTITY (&grpc_static_slice_table[54]) +#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[54]) /* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (&grpc_static_slice_table[55]) +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[55]) /* "identity,deflate,gzip" */ #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (&grpc_static_slice_table[56]) + (grpc_static_slice_table[56]) /* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (&grpc_static_slice_table[57]) +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[57]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (&grpc_static_slice_table[58]) +#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[58]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (&grpc_static_slice_table[59]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[59]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (&grpc_static_slice_table[60]) +#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[60]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (&grpc_static_slice_table[61]) +#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[61]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_slice_table[62]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[62]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_slice_table[63]) +#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[63]) /* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (&grpc_static_slice_table[64]) +#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[64]) /* "lb-token" */ -#define GRPC_MDSTR_LB_TOKEN (&grpc_static_slice_table[65]) +#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[65]) /* "link" */ -#define GRPC_MDSTR_LINK (&grpc_static_slice_table[66]) +#define GRPC_MDSTR_LINK (grpc_static_slice_table[66]) /* "location" */ -#define GRPC_MDSTR_LOCATION (&grpc_static_slice_table[67]) +#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[67]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_slice_table[68]) +#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[68]) /* ":method" */ -#define GRPC_MDSTR_METHOD (&grpc_static_slice_table[69]) +#define GRPC_MDSTR_METHOD (grpc_static_slice_table[69]) /* ":path" */ -#define GRPC_MDSTR_PATH (&grpc_static_slice_table[70]) +#define GRPC_MDSTR_PATH (grpc_static_slice_table[70]) /* "POST" */ -#define GRPC_MDSTR_POST (&grpc_static_slice_table[71]) +#define GRPC_MDSTR_POST (grpc_static_slice_table[71]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_slice_table[72]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[72]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_slice_table[73]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[73]) /* "PUT" */ -#define GRPC_MDSTR_PUT (&grpc_static_slice_table[74]) +#define GRPC_MDSTR_PUT (grpc_static_slice_table[74]) /* "range" */ -#define GRPC_MDSTR_RANGE (&grpc_static_slice_table[75]) +#define GRPC_MDSTR_RANGE (grpc_static_slice_table[75]) /* "referer" */ -#define GRPC_MDSTR_REFERER (&grpc_static_slice_table[76]) +#define GRPC_MDSTR_REFERER (grpc_static_slice_table[76]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (&grpc_static_slice_table[77]) +#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[77]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_slice_table[78]) +#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[78]) /* ":scheme" */ -#define GRPC_MDSTR_SCHEME (&grpc_static_slice_table[79]) +#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[79]) /* "server" */ -#define GRPC_MDSTR_SERVER (&grpc_static_slice_table[80]) +#define GRPC_MDSTR_SERVER (grpc_static_slice_table[80]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (&grpc_static_slice_table[81]) +#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[81]) /* "/" */ -#define GRPC_MDSTR_SLASH (&grpc_static_slice_table[82]) +#define GRPC_MDSTR_SLASH (grpc_static_slice_table[82]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_slice_table[83]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[83]) /* ":status" */ -#define GRPC_MDSTR_STATUS (&grpc_static_slice_table[84]) +#define GRPC_MDSTR_STATUS (grpc_static_slice_table[84]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_slice_table[85]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[85]) /* "te" */ -#define GRPC_MDSTR_TE (&grpc_static_slice_table[86]) +#define GRPC_MDSTR_TE (grpc_static_slice_table[86]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (&grpc_static_slice_table[87]) +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[87]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_slice_table[88]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[88]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (&grpc_static_slice_table[89]) +#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[89]) /* "vary" */ -#define GRPC_MDSTR_VARY (&grpc_static_slice_table[90]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table[90]) /* "via" */ -#define GRPC_MDSTR_VIA (&grpc_static_slice_table[91]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table[91]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_slice_table[92]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[92]) bool grpc_is_static_metadata_string(grpc_slice slice); diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc index c05f1cf1240..6efb68e1232 100644 --- a/src/cpp/util/slice_cc.cc +++ b/src/cpp/util/slice_cc.cc @@ -35,7 +35,7 @@ namespace grpc { -Slice::Slice() : slice_(gpr_empty_slice()) {} +Slice::Slice() : slice_(grpc_empty_slice()) {} Slice::~Slice() { grpc_slice_unref(slice_); } diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index c0d6bba687e..44967fe6890 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -157,6 +157,7 @@ CORE_SOURCE_FILES = [ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', + 'src/core/lib/slice/slice_hash_table.c', 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', @@ -179,7 +180,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', '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', diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index b8c7eef4881..ada6ef18228 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -187,9 +187,12 @@ grpc_slice_sub_type grpc_slice_sub_import; grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import; grpc_slice_split_tail_type grpc_slice_split_tail_import; grpc_slice_split_head_type grpc_slice_split_head_import; -gpr_empty_slice_type gpr_empty_slice_import; +grpc_empty_slice_type grpc_empty_slice_import; grpc_slice_cmp_type grpc_slice_cmp_import; grpc_slice_str_cmp_type grpc_slice_str_cmp_import; +grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; +grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; +grpc_slice_hash_type grpc_slice_hash_import; grpc_slice_buffer_init_type grpc_slice_buffer_init_import; grpc_slice_buffer_destroy_type grpc_slice_buffer_destroy_import; grpc_slice_buffer_add_type grpc_slice_buffer_add_import; @@ -463,9 +466,12 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_sub_no_ref_import = (grpc_slice_sub_no_ref_type) GetProcAddress(library, "grpc_slice_sub_no_ref"); grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail"); grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head"); - gpr_empty_slice_import = (gpr_empty_slice_type) GetProcAddress(library, "gpr_empty_slice"); + grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice"); grpc_slice_cmp_import = (grpc_slice_cmp_type) GetProcAddress(library, "grpc_slice_cmp"); grpc_slice_str_cmp_import = (grpc_slice_str_cmp_type) GetProcAddress(library, "grpc_slice_str_cmp"); + grpc_slice_buf_cmp_import = (grpc_slice_buf_cmp_type) GetProcAddress(library, "grpc_slice_buf_cmp"); + grpc_slice_buf_start_eq_import = (grpc_slice_buf_start_eq_type) GetProcAddress(library, "grpc_slice_buf_start_eq"); + grpc_slice_hash_import = (grpc_slice_hash_type) GetProcAddress(library, "grpc_slice_hash"); grpc_slice_buffer_init_import = (grpc_slice_buffer_init_type) GetProcAddress(library, "grpc_slice_buffer_init"); grpc_slice_buffer_destroy_import = (grpc_slice_buffer_destroy_type) GetProcAddress(library, "grpc_slice_buffer_destroy"); grpc_slice_buffer_add_import = (grpc_slice_buffer_add_type) GetProcAddress(library, "grpc_slice_buffer_add"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index ba436dde471..3d14e883346 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -176,7 +176,7 @@ extern census_resource_id_type census_resource_id_import; typedef void(*census_record_values_type)(census_context *context, census_value *values, size_t nvalues); extern census_record_values_type census_record_values_import; #define census_record_values census_record_values_import -typedef int(*grpc_compression_algorithm_parse_type)(const char *name, size_t name_length, grpc_compression_algorithm *algorithm); +typedef int(*grpc_compression_algorithm_parse_type)(grpc_slice value, grpc_compression_algorithm *algorithm); extern grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; #define grpc_compression_algorithm_parse grpc_compression_algorithm_parse_import typedef int(*grpc_compression_algorithm_name_type)(grpc_compression_algorithm algorithm, char **name); @@ -512,15 +512,24 @@ extern grpc_slice_split_tail_type grpc_slice_split_tail_import; typedef grpc_slice(*grpc_slice_split_head_type)(grpc_slice *s, size_t split); extern grpc_slice_split_head_type grpc_slice_split_head_import; #define grpc_slice_split_head grpc_slice_split_head_import -typedef grpc_slice(*gpr_empty_slice_type)(void); -extern gpr_empty_slice_type gpr_empty_slice_import; -#define gpr_empty_slice gpr_empty_slice_import +typedef grpc_slice(*grpc_empty_slice_type)(void); +extern grpc_empty_slice_type grpc_empty_slice_import; +#define grpc_empty_slice grpc_empty_slice_import typedef int(*grpc_slice_cmp_type)(grpc_slice a, grpc_slice b); extern grpc_slice_cmp_type grpc_slice_cmp_import; #define grpc_slice_cmp grpc_slice_cmp_import typedef int(*grpc_slice_str_cmp_type)(grpc_slice a, const char *b); extern grpc_slice_str_cmp_type grpc_slice_str_cmp_import; #define grpc_slice_str_cmp grpc_slice_str_cmp_import +typedef int(*grpc_slice_buf_cmp_type)(grpc_slice a, const void *b, size_t blen); +extern grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; +#define grpc_slice_buf_cmp grpc_slice_buf_cmp_import +typedef int(*grpc_slice_buf_start_eq_type)(grpc_slice a, const void *b, size_t blen); +extern grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; +#define grpc_slice_buf_start_eq grpc_slice_buf_start_eq_import +typedef uint32_t(*grpc_slice_hash_type)(grpc_slice s); +extern grpc_slice_hash_type grpc_slice_hash_import; +#define grpc_slice_hash grpc_slice_hash_import typedef void(*grpc_slice_buffer_init_type)(grpc_slice_buffer *sb); extern grpc_slice_buffer_init_type grpc_slice_buffer_init_import; #define grpc_slice_buffer_init grpc_slice_buffer_init_import diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 388bdc611da..f0c6ffe09c2 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -287,7 +287,7 @@ print >>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' for i, elem in enumerate(all_strs): print >>H, '/* "%s" */' % elem - print >>H, '#define %s (&grpc_static_slice_table[%d])' % (mangle(elem).upper(), i) + print >>H, '#define %s (grpc_static_slice_table[%d])' % (mangle(elem).upper(), i) print >>H print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice);' print >>H diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 25ec70e203b..a79b1e1ef35 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -863,6 +863,7 @@ src/core/lib/json/json_common.h \ src/core/lib/json/json_reader.h \ src/core/lib/json/json_writer.h \ src/core/lib/slice/percent_encoding.h \ +src/core/lib/slice/slice_hash_table.h \ src/core/lib/slice/slice_string_helpers.h \ src/core/lib/surface/api_trace.h \ src/core/lib/surface/call.h \ @@ -877,7 +878,6 @@ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ src/core/lib/transport/byte_stream.h \ 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 \ @@ -1049,6 +1049,7 @@ src/core/lib/json/json_writer.c \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ +src/core/lib/slice/slice_hash_table.c \ src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ @@ -1071,7 +1072,6 @@ src/core/lib/surface/validate_metadata.c \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ 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 \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index a3c20913f7f..4ab990badbe 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6689,6 +6689,7 @@ "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", "src/core/lib/surface/call.h", @@ -6703,7 +6704,6 @@ "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "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", @@ -6882,6 +6882,8 @@ "src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", + "src/core/lib/slice/slice_hash_table.c", + "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/slice/slice_string_helpers.h", @@ -6918,8 +6920,6 @@ "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.c", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/mdstr_hash_table.c", - "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index f0e061f4a6f..85bcfbe92ba 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -372,6 +372,7 @@ + @@ -386,7 +387,6 @@ - @@ -643,6 +643,8 @@ + + @@ -687,8 +689,6 @@ - - diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 8809da125df..c0ec86c3268 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -250,6 +250,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -316,9 +319,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -956,6 +956,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -998,9 +1001,6 @@ src\core\lib\transport - - 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 2e19a14dd2f..38c4d82bb12 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -265,6 +265,7 @@ + @@ -279,7 +280,6 @@ - @@ -494,6 +494,8 @@ + + @@ -538,8 +540,6 @@ - - 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 e66da7b571d..0e3bd1dfff3 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -307,6 +307,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -373,9 +376,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -752,6 +752,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -794,9 +797,6 @@ src\core\lib\transport - - 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 55604c52126..efd474a25d5 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -362,6 +362,7 @@ + @@ -376,7 +377,6 @@ - @@ -611,6 +611,8 @@ + + @@ -655,8 +657,6 @@ - - diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 69c52cc6f12..aa19a2a19db 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -253,6 +253,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -319,9 +322,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -869,6 +869,9 @@ src\core\lib\slice + + src\core\lib\slice + src\core\lib\slice @@ -911,9 +914,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport From 4eecdde403b852e523a004707c1045b5e6072cdc Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 14 Nov 2016 08:21:17 -0800 Subject: [PATCH 012/261] Conversion progress --- src/core/lib/slice/slice_hash_table.c | 2 +- src/core/lib/surface/call.c | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 743a6b1836b..7e6f705164b 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -40,7 +40,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" -static grpc_slice_refcount terminal_slice_refcount = {0}; +static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; static const grpc_slice terminal_slice = {&terminal_slice_refcount, .data.refcounted = {0, 0}}; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index f826d320430..525f7b663a1 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -92,7 +92,8 @@ typedef enum { } status_source; typedef struct { - uint8_t is_set; + bool is_code_set; + bool is_details_set; grpc_status_code code; grpc_slice details; } received_status; @@ -244,14 +245,15 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); call->is_client = args->server_transport_data == NULL; - grpc_slice path = NULL; + grpc_slice path = grpc_empty_slice(); if (call->is_client) { GPR_ASSERT(args->add_initial_metadata_count < MAX_SEND_EXTRA_METADATA_COUNT); for (i = 0; i < args->add_initial_metadata_count; i++) { call->send_extra_metadata[i].md = args->add_initial_metadata[i]; - if (args->add_initial_metadata[i]->key == GRPC_MDSTR_PATH) { - path = GRPC_MDSTR_REF(args->add_initial_metadata[i]->value); + if (grpc_slice_cmp(args->add_initial_metadata[i]->key, GRPC_MDSTR_PATH) == + 0) { + path = grpc_slice_ref_internal(args->add_initial_metadata[i]->value); } } call->send_extra_metadata_count = (int)args->add_initial_metadata_count; @@ -340,7 +342,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); } - if (path != NULL) GRPC_MDSTR_UNREF(exec_ctx, path); + grpc_slice_unref_internal(exec_ctx, path); GPR_TIMER_END("grpc_call_create", 0); return error; From 68208fe422cee7e28f7a08208c528a08338a9c2b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 14 Nov 2016 14:35:02 -0800 Subject: [PATCH 013/261] Progress towards mdstr elimination --- include/grpc/grpc.h | 7 +- include/grpc/impl/codegen/compression_types.h | 5 - include/grpc/impl/codegen/grpc_types.h | 39 ++---- src/core/lib/compression/algorithm_metadata.h | 4 +- src/core/lib/compression/compression.c | 4 +- src/core/lib/slice/slice_string_helpers.h | 3 + src/core/lib/surface/call.c | 122 +++++++----------- src/core/lib/surface/call_details.c | 6 +- src/core/lib/surface/call_log_batch.c | 19 ++- src/core/lib/surface/channel.c | 62 ++++----- src/core/lib/surface/channel.h | 5 +- src/core/lib/surface/lame_client.c | 9 +- src/core/lib/surface/server.c | 93 +++++++------ src/core/lib/transport/metadata.h | 4 +- test/core/compression/algorithm_test.c | 10 +- test/core/end2end/cq_verifier.c | 4 +- test/core/end2end/fixtures/proxy.c | 10 +- 17 files changed, 180 insertions(+), 226 deletions(-) diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 5e486215e01..a3015340ee0 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -178,8 +178,8 @@ GRPCAPI void grpc_channel_watch_connectivity_state( possible values). */ GRPCAPI grpc_call *grpc_channel_create_call( grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_completion_queue *completion_queue, const char *method, - const char *host, gpr_timespec deadline, void *reserved); + grpc_completion_queue *completion_queue, grpc_slice method, + const grpc_slice *host, gpr_timespec deadline, void *reserved); /** Ping the channels peer (load balanced channels will select one sub-channel to ping); if the channel is not connected, posts a failed. */ @@ -397,13 +397,16 @@ GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled); /** Check whether a metadata key is legal (will be accepted by core) */ GRPCAPI int grpc_header_key_is_legal(const char *key, size_t length); +GRPCAPI int grpc_header_key_slice_is_legal(grpc_slice slice); /** Check whether a non-binary metadata value is legal (will be accepted by core) */ GRPCAPI int grpc_header_nonbin_value_is_legal(const char *value, size_t length); +GRPCAPI int grpc_header_nonbin_value_slice_is_legal(grpc_slice slice); /** Check whether a metadata key corresponds to a binary value */ GRPCAPI int grpc_is_binary_header(const char *key, size_t length); +GRPCAPI int grpc_slice_is_binary_header(grpc_slice slice); /** Convert grpc_call_error values to a string */ GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error); diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 170d99f431b..8810943137e 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -41,11 +41,6 @@ extern "C" { #endif -/** To be used as initial metadata key for the request of a concrete compression - * algorithm */ -#define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ - "grpc-internal-encoding-request" - /** To be used in channel arguments. * * \addtogroup grpc_arg_keys diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index e8472fba46d..e507e012e26 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -287,9 +287,8 @@ typedef enum grpc_call_error { /** A single metadata element */ typedef struct grpc_metadata { - const char *key; - const char *value; - size_t value_length; + grpc_slice key; + grpc_slice value; uint32_t flags; /** The following fields are reserved for grpc internal use. @@ -331,10 +330,8 @@ typedef struct { } grpc_metadata_array; typedef struct { - char *method; - size_t method_capacity; - char *host; - size_t host_capacity; + grpc_slice method; + grpc_slice host; gpr_timespec deadline; uint32_t flags; void *reserved; @@ -416,7 +413,10 @@ typedef struct grpc_op { size_t trailing_metadata_count; grpc_metadata *trailing_metadata; grpc_status_code status; - const char *status_details; + /* optional: set to NULL if no details need sending, non-NULL if they do + * pointer will not be retained past the start_batch call + */ + grpc_slice *status_details; } send_status_from_server; /** ownership of the array is with the caller, but ownership of the elements stays with the call object (ie key, value members are owned by the call @@ -437,28 +437,7 @@ typedef struct grpc_op { value, or reuse it in a future op. */ grpc_metadata_array *trailing_metadata; grpc_status_code *status; - /** status_details is a buffer owned by the application before the op - completes and after the op has completed. During the operation - status_details may be reallocated to a size larger than - *status_details_capacity, in which case *status_details_capacity will - be updated with the new array capacity. - - Pre-allocating space: - size_t my_capacity = 8; - char *my_details = gpr_malloc(my_capacity); - x.status_details = &my_details; - x.status_details_capacity = &my_capacity; - - Not pre-allocating space: - size_t my_capacity = 0; - char *my_details = NULL; - x.status_details = &my_details; - x.status_details_capacity = &my_capacity; - - After the call: - gpr_free(my_details); */ - char **status_details; - size_t *status_details_capacity; + grpc_slice *status_details; } recv_status_on_client; struct { /** out argument, set to 1 if the call failed in any way (seen as a diff --git a/src/core/lib/compression/algorithm_metadata.h b/src/core/lib/compression/algorithm_metadata.h index 7412054bfef..bc4963059c2 100644 --- a/src/core/lib/compression/algorithm_metadata.h +++ b/src/core/lib/compression/algorithm_metadata.h @@ -38,7 +38,7 @@ #include "src/core/lib/transport/metadata.h" /** Return compression algorithm based metadata value */ -grpc_slice grpc_compression_algorithm_mdstr( +grpc_slice grpc_compression_algorithm_slice( grpc_compression_algorithm algorithm); /** Return compression algorithm based metadata element (grpc-encoding: xxx) */ @@ -47,7 +47,7 @@ grpc_mdelem *grpc_compression_encoding_mdelem( /** Find compression algorithm based on passed in mdstr - returns * GRPC_COMPRESS_ALGORITHM_COUNT on failure */ -grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( +grpc_compression_algorithm grpc_compression_algorithm_from_slice( grpc_slice str); #endif /* GRPC_CORE_LIB_COMPRESSION_ALGORITHM_METADATA_H */ diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index aa3caf9fef5..d73353f3926 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -81,7 +81,7 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, return 0; } -grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( +grpc_compression_algorithm grpc_compression_algorithm_from_slice( grpc_slice str) { if (grpc_slice_cmp(str, GRPC_MDSTR_IDENTITY) == 0) return GRPC_COMPRESS_NONE; if (grpc_slice_cmp(str, GRPC_MDSTR_DEFLATE) == 0) @@ -90,7 +90,7 @@ grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( return GRPC_COMPRESS_ALGORITHMS_COUNT; } -grpc_slice grpc_compression_algorithm_mdstr( +grpc_slice grpc_compression_algorithm_slice( grpc_compression_algorithm algorithm) { switch (algorithm) { case GRPC_COMPRESS_NONE: diff --git a/src/core/lib/slice/slice_string_helpers.h b/src/core/lib/slice/slice_string_helpers.h index c6f4e87c7f5..4a4deec6e54 100644 --- a/src/core/lib/slice/slice_string_helpers.h +++ b/src/core/lib/slice/slice_string_helpers.h @@ -34,6 +34,7 @@ #ifndef GRPC_CORE_LIB_SLICE_SLICE_STRING_HELPERS_H #define GRPC_CORE_LIB_SLICE_SLICE_STRING_HELPERS_H +#include #include #include @@ -53,6 +54,8 @@ char *grpc_dump_slice(grpc_slice slice, uint32_t flags); * should be a properly initialized instance. */ void grpc_slice_split(grpc_slice str, const char *sep, grpc_slice_buffer *dst); +bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t *result); + #ifdef __cplusplus } #endif diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 525f7b663a1..37548697fa8 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -196,8 +196,7 @@ struct grpc_call { union { struct { grpc_status_code *status; - char **status_details; - size_t *status_details_capacity; + grpc_slice *status_details; } client; struct { int *cancelled; @@ -383,7 +382,7 @@ static void get_final_status(grpc_call *call, void *set_value_user_data) { int i; for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_set) { + if (call->status[i].is_code_set) { set_value(call->status[i].code, set_value_user_data); return; } @@ -411,8 +410,8 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, } gpr_mu_destroy(&c->mu); for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (c->status[i].details) { - GRPC_MDSTR_UNREF(exec_ctx, c->status[i].details); + if (c->status[i].is_details_set) { + grpc_slice_unref_internal(exec_ctx, c->status[i].details); } } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { @@ -438,18 +437,19 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, static void set_status_code(grpc_call *call, status_source source, uint32_t status) { - if (call->status[source].is_set) return; + if (call->status[source].is_code_set) return; - call->status[source].is_set = 1; + call->status[source].is_code_set = true; call->status[source].code = (grpc_status_code)status; } static void set_status_details(grpc_exec_ctx *exec_ctx, grpc_call *call, status_source source, grpc_slice status) { - if (call->status[source].details != NULL) { - GRPC_MDSTR_UNREF(exec_ctx, status); + if (call->status[source].is_details_set) { + grpc_slice_unref_internal(exec_ctx, status); } else { call->status[source].details = status; + call->status[source].is_details_set = true; } } @@ -459,7 +459,8 @@ static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, const char *msg; grpc_error_get_status(error, &status, &msg); set_status_code(call, source, (uint32_t)status); - set_status_details(exec_ctx, call, source, grpc_mdstr_from_string(msg)); + set_status_details(exec_ctx, call, source, + grpc_slice_from_copied_string(msg)); } static void set_incoming_compression_algorithm( @@ -509,7 +510,7 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, return; } - accept_encoding_slice = mdel->value->slice; + accept_encoding_slice = mdel->value; grpc_slice_buffer_init(&accept_encoding_parts); grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); @@ -518,15 +519,13 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); for (i = 0; i < accept_encoding_parts.count; i++) { - const grpc_slice *accept_encoding_entry_slice = - &accept_encoding_parts.slices[i]; - if (grpc_compression_algorithm_parse( - (const char *)GRPC_SLICE_START_PTR(*accept_encoding_entry_slice), - GRPC_SLICE_LENGTH(*accept_encoding_entry_slice), &algorithm)) { + grpc_slice accept_encoding_entry_slice = accept_encoding_parts.slices[i]; + if (grpc_compression_algorithm_parse(accept_encoding_entry_slice, + &algorithm)) { GPR_BITSET(&call->encodings_accepted_by_peer, algorithm); } else { char *accept_encoding_entry_str = - grpc_dump_slice(*accept_encoding_entry_slice, GPR_DUMP_ASCII); + grpc_dump_slice(accept_encoding_entry_slice, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid entry in accept encoding metadata: '%s'. Ignoring.", accept_encoding_entry_str); @@ -549,21 +548,12 @@ uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { return encodings_accepted_by_peer; } -static void get_final_details(grpc_call *call, char **out_details, - size_t *out_details_capacity) { +static void get_final_details(grpc_call *call, grpc_slice *out_details) { int i; for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_set) { - if (call->status[i].details) { - grpc_slice details = call->status[i].details->slice; - size_t len = GRPC_SLICE_LENGTH(details); - if (len + 1 > *out_details_capacity) { - *out_details_capacity = - GPR_MAX(len + 1, *out_details_capacity * 3 / 2); - *out_details = gpr_realloc(*out_details, *out_details_capacity); - } - memcpy(*out_details, GRPC_SLICE_START_PTR(details), len); - (*out_details)[len] = 0; + if (call->status[i].is_code_set) { + if (call->status[i].is_details_set) { + *out_details = grpc_slice_ref(call->status[i].details); } else { goto no_details; } @@ -572,11 +562,7 @@ static void get_final_details(grpc_call *call, char **out_details, } no_details: - if (0 == *out_details_capacity) { - *out_details_capacity = 8; - *out_details = gpr_malloc(*out_details_capacity); - } - **out_details = 0; + *out_details = grpc_empty_slice(); } static grpc_linked_mdelem *linked_from_md(grpc_metadata *md) { @@ -605,19 +591,17 @@ static int prepare_application_metadata( get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); - l->md = grpc_mdelem_from_string_and_buffer( - exec_ctx, md->key, (const uint8_t *)md->value, md->value_length); - if (!grpc_header_key_is_legal(grpc_mdstr_as_c_string(l->md->key), - GRPC_MDSTR_LENGTH(l->md->key))) { - gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", - grpc_mdstr_as_c_string(l->md->key)); + l->md = grpc_mdelem_from_slices(exec_ctx, md->key, md->value); + if (!grpc_header_key_slice_is_legal(l->md->key)) { + char *str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); + gpr_free(str); break; - } else if (!grpc_is_binary_header(grpc_mdstr_as_c_string(l->md->key), - GRPC_MDSTR_LENGTH(l->md->key)) && - !grpc_header_nonbin_value_is_legal( - grpc_mdstr_as_c_string(l->md->value), - GRPC_MDSTR_LENGTH(l->md->value))) { - gpr_log(GPR_ERROR, "attempt to send invalid metadata value"); + } else if (!grpc_slice_is_binary_header(l->md->key) && + !grpc_header_nonbin_value_slice_is_legal(l->md->value)) { + char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); + gpr_free(str); break; } } @@ -902,9 +886,7 @@ static uint32_t decode_status(grpc_mdelem *md) { if (user_data != NULL) { status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; } else { - if (!gpr_parse_bytes_to_uint32(grpc_mdstr_as_c_string(md->value), - GRPC_SLICE_LENGTH(md->value->slice), - &status)) { + if (!grpc_parse_slice_to_uint32(md->value, &status)) { status = GRPC_STATUS_UNKNOWN; /* could not parse status code */ } grpc_mdelem_set_user_data(md, destroy_status, @@ -915,13 +897,14 @@ static uint32_t decode_status(grpc_mdelem *md) { static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { grpc_compression_algorithm algorithm = - grpc_compression_algorithm_from_mdstr(md->value); + grpc_compression_algorithm_from_slice(md->value); if (algorithm == GRPC_COMPRESS_ALGORITHMS_COUNT) { - const char *md_c_str = grpc_mdstr_as_c_string(md->value); + char *md_c_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid incoming compression algorithm: '%s'. Interpreting " "incoming data as uncompressed.", md_c_str); + gpr_free(md_c_str); return GRPC_COMPRESS_NONE; } return algorithm; @@ -929,15 +912,15 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { static grpc_mdelem *recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, grpc_mdelem *elem) { - if (elem->key == GRPC_MDSTR_GRPC_STATUS) { + if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_STATUS) == 0) { GPR_TIMER_BEGIN("status", 0); set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); GPR_TIMER_END("status", 0); return NULL; - } else if (elem->key == GRPC_MDSTR_GRPC_MESSAGE) { + } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_MESSAGE) == 0) { GPR_TIMER_BEGIN("status-details", 0); set_status_details(exec_ctx, call, STATUS_FROM_WIRE, - GRPC_MDSTR_REF(elem->value)); + grpc_slice_ref_internal(elem->value)); GPR_TIMER_END("status-details", 0); return NULL; } @@ -956,9 +939,8 @@ static grpc_mdelem *publish_app_metadata(grpc_call *call, grpc_mdelem *elem, gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity); } mdusr = &dest->metadata[dest->count++]; - mdusr->key = grpc_mdstr_as_c_string(elem->key); - mdusr->value = grpc_mdstr_as_c_string(elem->value); - mdusr->value_length = GRPC_SLICE_LENGTH(elem->value->slice); + mdusr->key = grpc_slice_ref(elem->key); + mdusr->value = grpc_slice_ref(elem->value); GPR_TIMER_END("publish_app_metadata", 0); return elem; } @@ -973,12 +955,12 @@ static grpc_mdelem *recv_initial_filter(void *args, grpc_mdelem *elem) { elem = recv_common_filter(a->exec_ctx, a->call, elem); if (elem == NULL) { return NULL; - } else if (elem->key == GRPC_MDSTR_GRPC_ENCODING) { + } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_ENCODING) == 0) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm(a->call, decode_compression(elem)); GPR_TIMER_END("incoming_compression_algorithm", 0); return NULL; - } else if (elem->key == GRPC_MDSTR_GRPC_ACCEPT_ENCODING) { + } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_ACCEPT_ENCODING) == 0) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(a->exec_ctx, a->call, elem); GPR_TIMER_END("encodings_accepted_by_peer", 0); @@ -1328,8 +1310,7 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, if (call->is_client) { get_final_status(call, set_status_value_directly, call->final_op.client.status); - get_final_details(call, call->final_op.client.status_details, - call->final_op.client.status_details_capacity); + get_final_details(call, call->final_op.client.status_details); } else { get_final_status(call, set_cancelled_value, call->final_op.server.cancelled); @@ -1427,13 +1408,10 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, const grpc_compression_algorithm calgo = compression_algorithm_for_level_locked( call, effective_compression_level); - char *calgo_name = NULL; - grpc_compression_algorithm_name(calgo, &calgo_name); // the following will be picked up by the compress filter and used as // the call's compression algorithm. - compression_md.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; - compression_md.value = calgo_name; - compression_md.value_length = strlen(calgo_name); + compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; + compression_md.value = grpc_compression_algorithm_slice(calgo); additional_metadata_count++; } @@ -1527,14 +1505,14 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( exec_ctx, call->channel, op->data.send_status_from_server.status); if (op->data.send_status_from_server.status_details != NULL) { - call->send_extra_metadata[1].md = grpc_mdelem_from_metadata_strings( + call->send_extra_metadata[1].md = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_mdstr_from_string( - op->data.send_status_from_server.status_details)); + grpc_slice_ref_internal( + *op->data.send_status_from_server.status_details)); call->send_extra_metadata_count++; set_status_details( exec_ctx, call, STATUS_FROM_API_OVERRIDE, - GRPC_MDSTR_REF(call->send_extra_metadata[1].md->value)); + grpc_slice_ref_internal(call->send_extra_metadata[1].md->value)); } if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { set_status_code(call, STATUS_FROM_API_OVERRIDE, @@ -1611,8 +1589,6 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->final_op.client.status = op->data.recv_status_on_client.status; call->final_op.client.status_details = op->data.recv_status_on_client.status_details; - call->final_op.client.status_details_capacity = - op->data.recv_status_on_client.status_details_capacity; bctl->recv_final_op = 1; stream_op->recv_trailing_metadata = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; diff --git a/src/core/lib/surface/call_details.c b/src/core/lib/surface/call_details.c index fe73da3f552..5efa3b0141b 100644 --- a/src/core/lib/surface/call_details.c +++ b/src/core/lib/surface/call_details.c @@ -41,10 +41,12 @@ void grpc_call_details_init(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_init(cd=%p)", 1, (cd)); memset(cd, 0, sizeof(*cd)); + cd->method = grpc_empty_slice(); + cd->host = grpc_empty_slice(); } void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - gpr_free(cd->method); - gpr_free(cd->host); + grpc_slice_unref(cd->method); + grpc_slice_unref(cd->host); } diff --git a/src/core/lib/surface/call_log_batch.c b/src/core/lib/surface/call_log_batch.c index 31c074f15dc..8f6438bc3b7 100644 --- a/src/core/lib/surface/call_log_batch.c +++ b/src/core/lib/surface/call_log_batch.c @@ -35,17 +35,18 @@ #include #include +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) { size_t i; for (i = 0; i < count; i++) { gpr_strvec_add(b, gpr_strdup("\nkey=")); - gpr_strvec_add(b, gpr_strdup(md[i].key)); + gpr_strvec_add(b, grpc_dump_slice(md[i].key, GPR_DUMP_ASCII)); gpr_strvec_add(b, gpr_strdup(" value=")); - gpr_strvec_add(b, gpr_dump(md[i].value, md[i].value_length, - GPR_DUMP_HEX | GPR_DUMP_ASCII)); + gpr_strvec_add(b, + grpc_dump_slice(md[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII)); } } @@ -70,10 +71,16 @@ char *grpc_op_string(const grpc_op *op) { gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT")); break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=%s", - op->data.send_status_from_server.status, - op->data.send_status_from_server.status_details); + gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=", + op->data.send_status_from_server.status); gpr_strvec_add(&b, tmp); + if (op->data.send_status_from_server.status_details != NULL) { + gpr_strvec_add(&b, grpc_dump_slice( + *op->data.send_status_from_server.status_details, + GPR_DUMP_ASCII)); + } else { + gpr_strvec_add(&b, gpr_strdup("(null)")); + } add_metadata(&b, op->data.send_status_from_server.trailing_metadata, op->data.send_status_from_server.trailing_metadata_count); break; diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 7e87f055319..986142a6927 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -123,8 +123,9 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, /* setting this takes precedence over anything else */ GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } - channel->default_authority = grpc_mdelem_from_strings( - exec_ctx, ":authority", args->args[i].value.string); + channel->default_authority = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_from_copied_string(args->args[i].value.string)); } } else if (0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { @@ -138,8 +139,9 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, "%s ignored: default host already set some other way", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - channel->default_authority = grpc_mdelem_from_strings( - exec_ctx, ":authority", args->args[i].value.string); + channel->default_authority = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_from_copied_string(args->args[i].value.string)); } } } else if (0 == strcmp(args->args[i].key, @@ -224,27 +226,17 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *cq, - const char *method, const char *host, + grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved) { - GRPC_API_TRACE( - "grpc_channel_create_call(" - "channel=%p, parent_call=%p, propagation_mask=%x, cq=%p, method=%s, " - "host=%s, " - "deadline=gpr_timespec { tv_sec: %" PRId64 - ", tv_nsec: %d, clock_type: %d }, " - "reserved=%p)", - 10, - (channel, parent_call, (unsigned)propagation_mask, cq, method, host, - deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, cq, NULL, - grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, - grpc_mdstr_from_string(method)), - host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_mdstr_from_string(host)) - : NULL, + grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH, + grpc_slice_ref(method)), + host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_ref(*host)) + : NULL, deadline); grpc_exec_ctx_finish(&exec_ctx); return call; @@ -252,17 +244,16 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_call *grpc_channel_create_pollset_set_call( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, - uint32_t propagation_mask, grpc_pollset_set *pollset_set, - const char *method, const char *host, gpr_timespec deadline, - void *reserved) { + uint32_t propagation_mask, grpc_pollset_set *pollset_set, grpc_slice method, + const grpc_slice *host, gpr_timespec deadline, void *reserved) { GPR_ASSERT(!reserved); return grpc_channel_create_call_internal( exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set, - grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_PATH, - grpc_mdstr_from_string(method)), - host ? grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_mdstr_from_string(host)) - : NULL, + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, + grpc_slice_ref(method)), + host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_ref(*host)) + : NULL, deadline); } @@ -274,11 +265,14 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - rc->path = grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, - grpc_mdstr_from_string(method)); + + rc->path = grpc_mdelem_from_slices( + &exec_ctx, GRPC_MDSTR_PATH, + grpc_slice_intern(grpc_slice_from_copied_string(method))); rc->authority = - host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_mdstr_from_string(host)) + host ? grpc_mdelem_from_slices( + &exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_intern(grpc_slice_from_copied_string(host))) : NULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; @@ -385,6 +379,6 @@ grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, return GRPC_MDELEM_GRPC_STATUS_2; } gpr_ltoa(i, tmp); - return grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_GRPC_STATUS, - grpc_mdstr_from_string(tmp)); + return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, + grpc_slice_from_copied_string(tmp)); } diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index 2ebadb7a150..cbe48cd6a02 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -52,9 +52,8 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, value of \a propagation_mask (see propagation_bits.h for possible values) */ grpc_call *grpc_channel_create_pollset_set_call( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, - uint32_t propagation_mask, grpc_pollset_set *pollset_set, - const char *method, const char *host, gpr_timespec deadline, - void *reserved); + uint32_t propagation_mask, grpc_pollset_set *pollset_set, grpc_slice method, + const grpc_slice *host, gpr_timespec deadline, void *reserved); /** Get a (borrowed) pointer to this channels underlying channel stack */ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); diff --git a/src/core/lib/surface/lame_client.c b/src/core/lib/surface/lame_client.c index d606f70c2f3..a43969be570 100644 --- a/src/core/lib/surface/lame_client.c +++ b/src/core/lib/surface/lame_client.c @@ -44,6 +44,7 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" +#include "src/core/lib/transport/static_metadata.h" typedef struct { grpc_linked_mdelem status; @@ -61,9 +62,11 @@ static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, channel_data *chand = elem->channel_data; char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); - calld->status.md = grpc_mdelem_from_strings(exec_ctx, "grpc-status", tmp); - calld->details.md = - grpc_mdelem_from_strings(exec_ctx, "grpc-message", chand->error_message); + calld->status.md = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); + calld->details.md = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_slice_from_copied_string(chand->error_message)); calld->status.prev = calld->details.next = NULL; calld->status.next = &calld->details; calld->details.prev = &calld->status; diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 8f0cfbbc17e..74411f3aab2 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -98,6 +98,7 @@ typedef struct requested_call { typedef struct channel_registered_method { registered_method *server_registered_method; uint32_t flags; + bool has_host; grpc_slice method; grpc_slice host; } channel_registered_method; @@ -144,6 +145,8 @@ struct call_data { /** the current state of a call - see call_state */ call_state state; + bool path_set; + bool host_set; grpc_slice path; grpc_slice host; gpr_timespec deadline; @@ -459,17 +462,6 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, op); } -static void cpstr(char **dest, size_t *capacity, grpc_slice value) { - grpc_slice slice = value->slice; - size_t len = GRPC_SLICE_LENGTH(slice); - - if (len + 1 > *capacity) { - *capacity = GPR_MAX(len + 1, *capacity * 2); - *dest = gpr_realloc(*dest, *capacity); - } - memcpy(*dest, grpc_mdstr_as_c_string(value), len + 1); -} - static void done_request_event(grpc_exec_ctx *exec_ctx, void *req, grpc_cq_completion *c) { requested_call *rc = req; @@ -498,12 +490,10 @@ static void publish_call(grpc_exec_ctx *exec_ctx, grpc_server *server, GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata); switch (rc->type) { case BATCH_CALL: - GPR_ASSERT(calld->host != NULL); - GPR_ASSERT(calld->path != NULL); - cpstr(&rc->data.batch.details->host, - &rc->data.batch.details->host_capacity, calld->host); - cpstr(&rc->data.batch.details->method, - &rc->data.batch.details->method_capacity, calld->path); + GPR_ASSERT(calld->host_set); + GPR_ASSERT(calld->path_set); + rc->data.batch.details->host = grpc_slice_ref_internal(calld->host); + rc->data.batch.details->method = grpc_slice_ref_internal(calld->path); rc->data.batch.details->deadline = calld->deadline; rc->data.batch.details->flags = (calld->recv_idempotent_request @@ -623,35 +613,39 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { uint32_t hash; channel_registered_method *rm; - if (chand->registered_methods && calld->path && calld->host) { + if (chand->registered_methods && calld->path_set && calld->host_set) { /* TODO(ctiller): unify these two searches */ /* check for an exact match with host */ - hash = GRPC_MDSTR_KV_HASH(calld->host->hash, calld->path->hash); + hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(calld->host), + grpc_slice_hash(calld->path)); for (i = 0; i <= chand->registered_method_max_probes; i++) { rm = &chand->registered_methods[(hash + i) % chand->registered_method_slots]; if (!rm) break; - if (rm->host != calld->host) continue; - if (rm->method != calld->path) continue; + if (!rm->has_host) continue; + if (grpc_slice_cmp(rm->host, calld->host) != 0) continue; + if (grpc_slice_cmp(rm->method, calld->path) != 0) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && - !calld->recv_idempotent_request) + !calld->recv_idempotent_request) { continue; + } finish_start_new_rpc(exec_ctx, server, elem, &rm->server_registered_method->request_matcher, rm->server_registered_method->payload_handling); return; } /* check for a wildcard method definition (no host set) */ - hash = GRPC_MDSTR_KV_HASH(0, calld->path->hash); + hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash(calld->path)); for (i = 0; i <= chand->registered_method_max_probes; i++) { rm = &chand->registered_methods[(hash + i) % chand->registered_method_slots]; if (!rm) break; - if (rm->host != NULL) continue; - if (rm->method != calld->path) continue; + if (rm->has_host) continue; + if (grpc_slice_cmp(rm->method, calld->path) != 0) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && - !calld->recv_idempotent_request) + !calld->recv_idempotent_request) { continue; + } finish_start_new_rpc(exec_ctx, server, elem, &rm->server_registered_method->request_matcher, rm->server_registered_method->payload_handling); @@ -743,14 +737,14 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, static grpc_mdelem *server_filter(void *user_data, grpc_mdelem *md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (md->key == GRPC_MDSTR_PATH) { - if (calld->path == NULL) { - calld->path = GRPC_MDSTR_REF(md->value); + if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + if (!calld->path_set) { + calld->path = grpc_slice_ref(md->value); } return NULL; - } else if (md->key == GRPC_MDSTR_AUTHORITY) { - if (calld->host == NULL) { - calld->host = GRPC_MDSTR_REF(md->value); + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { + if (!calld->host_set) { + calld->host = grpc_slice_ref(md->value); } return NULL; } @@ -770,7 +764,7 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) { calld->deadline = op_deadline; } - if (calld->host && calld->path) { + if (calld->host_set && calld->path_set) { /* do nothing */ } else { GRPC_ERROR_UNREF(error); @@ -902,11 +896,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, GPR_ASSERT(calld->state != PENDING); - if (calld->host) { - GRPC_MDSTR_UNREF(exec_ctx, calld->host); + if (calld->host_set) { + grpc_slice_unref_internal(exec_ctx, calld->host); } - if (calld->path) { - GRPC_MDSTR_UNREF(exec_ctx, calld->path); + if (calld->path_set) { + grpc_slice_unref_internal(exec_ctx, calld->path); } grpc_metadata_array_destroy(&calld->initial_metadata); @@ -936,11 +930,9 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, channel_data *chand = elem->channel_data; if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { - if (chand->registered_methods[i].method) { - GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].method); - } - if (chand->registered_methods[i].host) { - GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].host); + grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].method); + if (chand->registered_methods[i].has_host) { + grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].host); } } gpr_free(chand->registered_methods); @@ -1136,8 +1128,6 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, channel_registered_method *crm; grpc_channel *channel; channel_data *chand; - grpc_slice host; - grpc_slice method; uint32_t hash; size_t slots; uint32_t probes; @@ -1176,9 +1166,18 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, chand->registered_methods = gpr_malloc(alloc); memset(chand->registered_methods, 0, alloc); for (rm = s->registered_methods; rm; rm = rm->next) { - host = rm->host ? grpc_mdstr_from_string(rm->host) : NULL; - method = grpc_mdstr_from_string(rm->method); - hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash); + grpc_slice host; + bool has_host; + grpc_slice method; + if (rm->host != NULL) { + host = grpc_slice_intern(grpc_slice_from_copied_string(rm->host)); + has_host = true; + } else { + has_host = false; + } + method = grpc_slice_intern(grpc_slice_from_copied_string(rm->method)); + hash = GRPC_MDSTR_KV_HASH(has_host ? grpc_slice_hash(host) : 0, + grpc_slice_hash(method)); for (probes = 0; chand->registered_methods[(hash + probes) % slots] .server_registered_method != NULL; probes++) diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index ede09d7d76c..fcd1c9222fa 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -113,11 +113,9 @@ grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md); void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md); #endif -#define GRPC_MDSTR_LENGTH(s) (GRPC_SLICE_LENGTH(s->slice)) - /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ #define GRPC_MDELEM_LENGTH(e) \ - (GRPC_MDSTR_LENGTH((e)->key) + GRPC_MDSTR_LENGTH((e)->value) + 32) + (GRPC_SLICE_LENGTH((e)->key) + GRPC_SLICE_LENGTH((e)->value) + 32) #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index ff17667b945..4b85489044b 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -59,8 +59,8 @@ static void test_algorithm_mesh(void) { GPR_ASSERT(grpc_compression_algorithm_parse(name, strlen(name), &parsed)); GPR_ASSERT((int)parsed == i); mdstr = grpc_mdstr_from_string(name); - GPR_ASSERT(mdstr == grpc_compression_algorithm_mdstr(parsed)); - GPR_ASSERT(parsed == grpc_compression_algorithm_from_mdstr(mdstr)); + GPR_ASSERT(mdstr == grpc_compression_algorithm_slice(parsed)); + GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); mdelem = grpc_compression_encoding_mdelem(parsed); GPR_ASSERT(mdelem->value == mdstr); GPR_ASSERT(mdelem->key == GRPC_MDSTR_GRPC_ENCODING); @@ -85,11 +85,11 @@ static void test_algorithm_failure(void) { GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT + 1, NULL) == 0); mdstr = grpc_mdstr_from_string("this-is-an-invalid-algorithm"); - GPR_ASSERT(grpc_compression_algorithm_from_mdstr(mdstr) == + GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) == GRPC_COMPRESS_ALGORITHMS_COUNT); - GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT) == + GPR_ASSERT(grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT) == NULL); - GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT + + GPR_ASSERT(grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT + 1) == NULL); GRPC_MDSTR_UNREF(&exec_ctx, mdstr); grpc_exec_ctx_finish(&exec_ctx); diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 57373970c42..6a463e8613e 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -92,8 +92,8 @@ static int has_metadata(const grpc_metadata *md, size_t count, const char *key, const char *value) { size_t i; for (i = 0; i < count; i++) { - if (0 == strcmp(key, md[i].key) && strlen(value) == md[i].value_length && - 0 == memcmp(md[i].value, value, md[i].value_length)) { + if (0 == grpc_slice_str_cmp(md[i].key, key) && + 0 == grpc_slice_str_cmp(md[i].value, value)) { return 1; } } diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index beed80df819..d0148937424 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -80,8 +80,7 @@ typedef struct { grpc_metadata_array p2s_trailing_metadata; grpc_status_code p2s_status; - char *p2s_status_details; - size_t p2s_status_details_capacity; + grpc_slice p2s_status_details; int c2p_server_cancelled; } proxy_call; @@ -153,7 +152,7 @@ static void unrefpc(proxy_call *pc, const char *reason) { grpc_metadata_array_destroy(&pc->c2p_initial_metadata); grpc_metadata_array_destroy(&pc->p2s_initial_metadata); grpc_metadata_array_destroy(&pc->p2s_trailing_metadata); - gpr_free(pc->p2s_status_details); + grpc_slice_unref(pc->p2s_status_details); gpr_free(pc); } } @@ -309,7 +308,6 @@ static void on_p2s_status(void *arg, int success) { op.data.send_status_from_server.trailing_metadata = pc->p2s_trailing_metadata.metadata; op.data.send_status_from_server.status = pc->p2s_status; - op.data.send_status_from_server.status_details = pc->p2s_status_details; refpc(pc, "on_c2p_sent_status"); err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_sent_status, pc), NULL); @@ -339,7 +337,7 @@ static void on_new_call(void *arg, int success) { pc->c2p = proxy->new_call; pc->p2s = grpc_channel_create_call( proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq, - proxy->new_call_details.method, proxy->new_call_details.host, + proxy->new_call_details.method, &proxy->new_call_details.host, proxy->new_call_details.deadline, NULL); gpr_ref_init(&pc->refs, 1); @@ -384,8 +382,6 @@ static void on_new_call(void *arg, int success) { &pc->p2s_trailing_metadata; op.data.recv_status_on_client.status = &pc->p2s_status; op.data.recv_status_on_client.status_details = &pc->p2s_status_details; - op.data.recv_status_on_client.status_details_capacity = - &pc->p2s_status_details_capacity; refpc(pc, "on_p2s_status"); err = grpc_call_start_batch(pc->p2s, &op, 1, new_closure(on_p2s_status, pc), NULL); From 47718a69a97ce72b00821386663fb8f46b128606 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 14 Nov 2016 14:48:42 -0800 Subject: [PATCH 014/261] Add method config stuff --- src/core/lib/transport/static_metadata.c | 320 +++++++++++---------- src/core/lib/transport/static_metadata.h | 116 ++++---- test/core/end2end/fuzzers/hpack.dictionary | 4 + tools/codegen/core/gen_static_metadata.py | 7 + 4 files changed, 244 insertions(+), 203 deletions(-) diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 1d72646a975..e24f3fa55e2 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -66,43 +66,49 @@ static uint8_t g_raw_bytes[] = { 112, 101, 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, 71, 69, 84, 103, 114, 112, 99, 103, 114, 112, 99, 45, 97, 99, 99, 101, 112, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, - 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, 99, 45, - 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 110, 99, 111, 100, 105, - 110, 103, 45, 114, 101, 113, 117, 101, 115, 116, 103, 114, 112, 99, 45, - 109, 101, 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 112, 97, 121, - 108, 111, 97, 100, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, - 97, 116, 115, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, 97, - 116, 117, 115, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, 117, 116, - 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, 98, 105, - 110, 103, 122, 105, 112, 103, 122, 105, 112, 44, 32, 100, 101, 102, 108, - 97, 116, 101, 104, 111, 115, 116, 104, 116, 116, 112, 104, 116, 116, 112, - 115, 105, 100, 101, 110, 116, 105, 116, 121, 105, 100, 101, 110, 116, 105, - 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, 110, 116, - 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, - 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 103, 122, 105, 112, 105, - 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, 105, 102, - 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, 111, 110, - 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, 103, 101, - 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, - 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, 102, 105, - 101, 100, 108, 98, 45, 99, 111, 115, 116, 45, 98, 105, 110, 108, 98, - 45, 116, 111, 107, 101, 110, 108, 105, 110, 107, 108, 111, 99, 97, 116, - 105, 111, 110, 109, 97, 120, 45, 102, 111, 114, 119, 97, 114, 100, 115, - 58, 109, 101, 116, 104, 111, 100, 58, 112, 97, 116, 104, 80, 79, 83, - 84, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 101, 110, 116, 105, - 99, 97, 116, 101, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 111, - 114, 105, 122, 97, 116, 105, 111, 110, 80, 85, 84, 114, 97, 110, 103, - 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, 115, 104, - 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 58, 115, 99, 104, - 101, 109, 101, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, 99, 111, - 111, 107, 105, 101, 47, 47, 105, 110, 100, 101, 120, 46, 104, 116, 109, - 108, 58, 115, 116, 97, 116, 117, 115, 115, 116, 114, 105, 99, 116, 45, - 116, 114, 97, 110, 115, 112, 111, 114, 116, 45, 115, 101, 99, 117, 114, - 105, 116, 121, 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, 116, 114, - 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, 110, 103, - 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 118, 97, 114, 121, 118, - 105, 97, 119, 119, 119, 45, 97, 117, 116, 104, 101, 110, 116, 105, 99, - 97, 116, 101}; + 99, 46, 109, 97, 120, 95, 114, 101, 113, 117, 101, 115, 116, 95, 109, + 101, 115, 115, 97, 103, 101, 95, 98, 121, 116, 101, 115, 103, 114, 112, + 99, 46, 109, 97, 120, 95, 114, 101, 115, 112, 111, 110, 115, 101, 95, + 109, 101, 115, 115, 97, 103, 101, 95, 98, 121, 116, 101, 115, 103, 114, + 112, 99, 46, 116, 105, 109, 101, 111, 117, 116, 103, 114, 112, 99, 46, + 119, 97, 105, 116, 95, 102, 111, 114, 95, 114, 101, 97, 100, 121, 103, + 114, 112, 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, + 99, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 110, 99, 111, + 100, 105, 110, 103, 45, 114, 101, 113, 117, 101, 115, 116, 103, 114, 112, + 99, 45, 109, 101, 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 112, + 97, 121, 108, 111, 97, 100, 45, 98, 105, 110, 103, 114, 112, 99, 45, + 115, 116, 97, 116, 115, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, + 116, 97, 116, 117, 115, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, + 117, 116, 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, + 98, 105, 110, 103, 122, 105, 112, 103, 122, 105, 112, 44, 32, 100, 101, + 102, 108, 97, 116, 101, 104, 111, 115, 116, 104, 116, 116, 112, 104, 116, + 116, 112, 115, 105, 100, 101, 110, 116, 105, 116, 121, 105, 100, 101, 110, + 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, + 110, 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 44, 103, + 122, 105, 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 103, 122, 105, + 112, 105, 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, + 105, 102, 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, + 111, 110, 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, + 103, 101, 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, + 45, 115, 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, + 102, 105, 101, 100, 108, 98, 45, 99, 111, 115, 116, 45, 98, 105, 110, + 108, 98, 45, 116, 111, 107, 101, 110, 108, 105, 110, 107, 108, 111, 99, + 97, 116, 105, 111, 110, 109, 97, 120, 45, 102, 111, 114, 119, 97, 114, + 100, 115, 58, 109, 101, 116, 104, 111, 100, 58, 112, 97, 116, 104, 80, + 79, 83, 84, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 101, 110, + 116, 105, 99, 97, 116, 101, 112, 114, 111, 120, 121, 45, 97, 117, 116, + 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 80, 85, 84, 114, 97, + 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, + 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 58, 115, + 99, 104, 101, 109, 101, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, + 99, 111, 111, 107, 105, 101, 47, 47, 105, 110, 100, 101, 120, 46, 104, + 116, 109, 108, 58, 115, 116, 97, 116, 117, 115, 115, 116, 114, 105, 99, + 116, 45, 116, 114, 97, 110, 115, 112, 111, 114, 116, 45, 115, 101, 99, + 117, 114, 105, 116, 121, 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, + 116, 114, 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, + 110, 103, 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 118, 97, 114, + 121, 118, 105, 97, 119, 119, 119, 45, 97, 117, 116, 104, 101, 110, 116, + 105, 99, 97, 116, 101}; static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} @@ -196,109 +202,117 @@ const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { {.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 357, .length = 13}}, + .data.refcounted = {.bytes = g_raw_bytes + 357, .length = 30}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 370, .length = 30}}, + .data.refcounted = {.bytes = g_raw_bytes + 387, .length = 31}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 400, .length = 12}}, + .data.refcounted = {.bytes = g_raw_bytes + 418, .length = 12}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 412, .length = 16}}, + .data.refcounted = {.bytes = g_raw_bytes + 430, .length = 19}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 428, .length = 14}}, + .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 442, .length = 11}}, + .data.refcounted = {.bytes = g_raw_bytes + 462, .length = 30}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 453, .length = 12}}, + .data.refcounted = {.bytes = g_raw_bytes + 492, .length = 12}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 465, .length = 16}}, + .data.refcounted = {.bytes = g_raw_bytes + 504, .length = 16}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 481, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 520, .length = 14}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 485, .length = 13}}, + .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 498, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 545, .length = 12}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 502, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 557, .length = 16}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 506, .length = 5}}, + .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 511, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 13}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 519, .length = 16}}, + .data.refcounted = {.bytes = g_raw_bytes + 590, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 535, .length = 21}}, + .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 556, .length = 13}}, + .data.refcounted = {.bytes = g_raw_bytes + 598, .length = 5}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 569, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 17}}, + .data.refcounted = {.bytes = g_raw_bytes + 611, .length = 16}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 13}}, + .data.refcounted = {.bytes = g_raw_bytes + 627, .length = 21}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 607, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 648, .length = 13}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 615, .length = 19}}, + .data.refcounted = {.bytes = g_raw_bytes + 661, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 634, .length = 13}}, + .data.refcounted = {.bytes = g_raw_bytes + 669, .length = 17}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 647, .length = 11}}, + .data.refcounted = {.bytes = g_raw_bytes + 686, .length = 13}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 658, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 699, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 666, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 707, .length = 19}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 670, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 726, .length = 13}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 678, .length = 12}}, + .data.refcounted = {.bytes = g_raw_bytes + 739, .length = 11}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 690, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 750, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 697, .length = 5}}, + .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 702, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 762, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 706, .length = 18}}, + .data.refcounted = {.bytes = g_raw_bytes + 770, .length = 12}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 724, .length = 19}}, + .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 743, .length = 3}}, + .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 746, .length = 5}}, + .data.refcounted = {.bytes = g_raw_bytes + 794, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 751, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 798, .length = 18}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 816, .length = 19}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 765, .length = 11}}, + .data.refcounted = {.bytes = g_raw_bytes + 835, .length = 3}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 776, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 838, .length = 5}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 783, .length = 6}}, + .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 10}}, + .data.refcounted = {.bytes = g_raw_bytes + 850, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 799, .length = 1}}, + .data.refcounted = {.bytes = g_raw_bytes + 857, .length = 11}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 800, .length = 11}}, + .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 811, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 875, .length = 6}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 818, .length = 25}}, + .data.refcounted = {.bytes = g_raw_bytes + 881, .length = 10}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 2}}, + .data.refcounted = {.bytes = g_raw_bytes + 891, .length = 1}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 845, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 892, .length = 11}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 853, .length = 17}}, + .data.refcounted = {.bytes = g_raw_bytes + 903, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 870, .length = 10}}, + .data.refcounted = {.bytes = g_raw_bytes + 910, .length = 25}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 880, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 935, .length = 2}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 884, .length = 3}}, + .data.refcounted = {.bytes = g_raw_bytes + 937, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 887, .length = 16}}, + .data.refcounted = {.bytes = g_raw_bytes + 945, .length = 17}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 962, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 972, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 976, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 979, .length = 16}}, }; static const uint8_t g_revmap[] = { @@ -326,43 +340,49 @@ static const uint8_t g_revmap[] = { 255, 255, 255, 255, 36, 255, 255, 255, 255, 255, 255, 37, 255, 255, 255, 38, 255, 255, 39, 255, 255, 255, 40, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 41, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 42, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 43, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 44, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 45, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 46, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 47, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 48, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 49, 255, 255, 255, 50, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 51, 255, 255, 255, 52, 255, 255, 255, 53, 255, 255, 255, - 255, 54, 255, 255, 255, 255, 255, 255, 255, 55, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 56, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 42, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 43, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 44, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 45, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 46, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 57, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 58, - 255, 255, 255, 255, 255, 255, 255, 59, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 60, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 61, 255, 255, 255, 255, 255, 255, 255, - 62, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 63, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 64, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 65, 255, - 255, 255, 255, 255, 255, 255, 66, 255, 255, 255, 67, 255, 255, 255, 255, - 255, 255, 255, 68, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 69, 255, 255, 255, 255, 255, 255, 70, 255, 255, 255, 255, 71, 255, 255, - 255, 72, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 73, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 74, 255, 255, 75, 255, 255, 255, - 255, 76, 255, 255, 255, 255, 255, 255, 77, 255, 255, 255, 255, 255, 255, - 78, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 79, 255, 255, 255, - 255, 255, 255, 80, 255, 255, 255, 255, 255, 81, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 82, 83, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 84, 255, 255, 255, 255, 255, 255, 85, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 47, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 48, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 49, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 50, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 52, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 53, 255, 255, 255, 54, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 55, 255, 255, 255, 56, 255, 255, 255, 57, 255, + 255, 255, 255, 58, 255, 255, 255, 255, 255, 255, 255, 59, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 60, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 86, 255, 87, 255, 255, 255, 255, 255, 255, 255, 88, 255, + 255, 255, 255, 61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 62, 255, 255, 255, 255, 255, 255, 255, 63, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 64, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 65, 255, 255, 255, 255, 255, + 255, 255, 66, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 67, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 68, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 69, 255, 255, 255, 255, 255, 255, 255, 70, 255, 255, 255, 71, 255, 255, + 255, 255, 255, 255, 255, 72, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 73, 255, 255, 255, 255, 255, 255, 74, 255, 255, 255, 255, 75, + 255, 255, 255, 76, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 77, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 78, 255, 255, 79, 255, + 255, 255, 255, 80, 255, 255, 255, 255, 255, 255, 81, 255, 255, 255, 255, + 255, 255, 82, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 83, 255, + 255, 255, 255, 255, 255, 84, 255, 255, 255, 255, 255, 85, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 86, 87, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 88, 255, 255, 255, 255, 255, 255, 89, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 89, 255, 255, 255, 255, 255, 255, 255, 255, 255, 90, 255, 255, 255, 91, - 255, 255, 92, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255}; + 255, 255, 255, 255, 255, 90, 255, 91, 255, 255, 255, 255, 255, 255, 255, + 92, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 93, 255, 255, 255, 255, 255, 255, 255, 255, 255, 94, 255, 255, + 255, 95, 255, 255, 96, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255}; int grpc_static_metadata_index(grpc_slice slice) { if (GRPC_SLICE_LENGTH(slice) == 0) return 33; @@ -382,62 +402,62 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { #define ELEMS_PHASHLEN 0x40 #define ELEMS_PHASHNKEYS 81 #define ELEMS_PHASHRANGE 128 -#define ELEMS_PHASHSALT 0x13c6ef372 +#define ELEMS_PHASHSALT 0x9e3779b9 static const uint8_t elems_tab[] = { - 47, 28, 47, 1, 47, 76, 76, 0, 1, 119, 61, 60, 47, 61, 76, 0, - 0, 32, 61, 76, 0, 0, 1, 0, 0, 0, 0, 0, 0, 101, 0, 0, - 0, 0, 47, 76, 122, 10, 76, 46, 87, 119, 25, 4, 0, 47, 0, 44, - 20, 120, 4, 79, 0, 0, 122, 88, 80, 20, 51, 65, 0, 0, 0, 0, + 47, 1, 61, 0, 32, 0, 47, 1, 37, 0, 0, 0, 47, 61, 76, 0, + 76, 0, 61, 0, 32, 37, 51, 0, 47, 47, 79, 4, 76, 1, 0, 0, + 0, 76, 0, 47, 85, 34, 0, 10, 0, 28, 0, 76, 0, 61, 0, 0, + 46, 4, 12, 47, 88, 28, 61, 79, 28, 70, 0, 68, 85, 0, 87, 0, }; static uint32_t elems_phash(uint32_t val) { - val -= 963; + val -= 1003; uint32_t a, b, rsl; - b = ((val << 19) >> 26); - a = (val & 0x3f); + b = (val & 0x3f); + a = ((val << 18) >> 26); rsl = (a ^ elems_tab[b]); return rsl; } static const uint16_t elem_keys[] = { - 3844, 1521, 2544, 7194, 7815, 7816, 7817, 7818, 7819, 7820, 7821, 6357, - 6822, 5706, 2358, 3381, 1428, 6488, 3862, 7386, 2622, 6078, 7101, 1166, - 3195, 3867, 2730, 1335, 6491, 2079, 8496, 5427, 7399, 7400, 1893, 8403, - 3751, 3752, 1149, 8310, 3288, 6729, 7473, 2265, 2451, 6455, 5799, 963, - 5985, 7008, 1056, 4278, 4279, 4280, 3769, 2637, 1242, 6592, 6593, 3774, - 3775, 3776, 3777, 1986, 4776, 5520, 6264, 3474, 7566, 7938, 8217, 1614, - 2823, 1800, 8085, 8589, 7287, 5892, 2172, 6171, 5613, 0, 0, 0, + 1218, 8544, 2652, 1973, 7264, 2458, 2734, 3933, 1682, 6435, 3912, 3941, + 4396, 4418, 4850, 4852, 7890, 8541, 6726, 9345, 6338, 6629, 6920, 3939, + 7156, 8540, 8108, 8090, 8181, 8666, 8821, 1876, 8545, 1391, 8957, 1488, + 7405, 7265, 3331, 2943, 2846, 6241, 4851, 2167, 5368, 1585, 1294, 1003, + 9054, 6144, 8542, 8539, 8107, 7793, 7502, 7159, 7696, 2264, 6532, 2749, + 9248, 1197, 7987, 9151, 7017, 4423, 7119, 6823, 3938, 8543, 3525, 3911, + 2070, 2361, 2555, 6047, 1100, 3940, 3622, 3428, 8278, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static const uint8_t elem_idxs[] = { - 33, 7, 17, 60, 67, 68, 69, 70, 71, 72, 73, 50, 57, 43, 15, 24, 6, - 52, 34, 62, 18, 47, 59, 3, 22, 35, 20, 5, 53, 12, 79, 40, 63, 64, - 10, 78, 26, 27, 2, 77, 23, 56, 65, 14, 16, 51, 44, 1, 46, 58, 0, - 36, 37, 38, 28, 19, 4, 54, 55, 29, 30, 31, 32, 11, 39, 41, 49, 25, - 66, 74, 76, 8, 21, 9, 75, 80, 61, 45, 13, 48, 42}; + 3, 72, 17, 10, 54, 15, 18, 28, 8, 44, 27, 32, 33, 34, 36, 38, 60, + 69, 47, 80, 43, 46, 49, 30, 52, 68, 64, 62, 65, 74, 75, 9, 73, 5, + 76, 6, 56, 55, 22, 21, 20, 42, 37, 12, 39, 7, 4, 1, 77, 41, 70, + 67, 63, 59, 57, 53, 58, 13, 45, 19, 79, 2, 61, 78, 50, 35, 51, 48, + 29, 71, 24, 26, 11, 14, 16, 40, 0, 31, 25, 23, 66}; grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return NULL; - uint32_t k = (uint32_t)(a * 93 + b); + uint32_t k = (uint32_t)(a * 97 + b); uint32_t h = elems_phash(k); return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL; } const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = - {11, 33, 10, 33, 12, 33, 12, 50, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, + {11, 33, 10, 33, 12, 33, 12, 54, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, 19, 33, 20, 33, 21, 33, 22, 33, 23, 33, 24, 33, 25, 33, 26, 33, 27, 33, 28, 18, 28, 33, 29, 33, 30, 33, 34, 33, 35, 33, 36, 33, 37, 33, 40, 31, - 40, 32, 40, 49, 40, 54, 40, 55, 40, 56, 40, 57, 41, 31, 41, 49, 41, 54, - 46, 0, 46, 1, 46, 2, 51, 33, 58, 33, 59, 33, 60, 33, 61, 33, 62, 33, - 63, 33, 64, 33, 65, 33, 66, 33, 67, 33, 68, 33, 69, 38, 69, 71, 69, 74, - 70, 82, 70, 83, 72, 33, 73, 33, 75, 33, 76, 33, 77, 33, 78, 33, 79, 39, - 79, 52, 79, 53, 80, 33, 81, 33, 84, 3, 84, 4, 84, 5, 84, 6, 84, 7, - 84, 8, 84, 9, 85, 33, 86, 87, 88, 33, 89, 33, 90, 33, 91, 33, 92, 33}; + 40, 32, 40, 53, 40, 58, 40, 59, 40, 60, 40, 61, 45, 31, 45, 53, 45, 58, + 50, 0, 50, 1, 50, 2, 55, 33, 62, 33, 63, 33, 64, 33, 65, 33, 66, 33, + 67, 33, 68, 33, 69, 33, 70, 33, 71, 33, 72, 33, 73, 38, 73, 75, 73, 78, + 74, 86, 74, 87, 76, 33, 77, 33, 79, 33, 80, 33, 81, 33, 82, 33, 83, 39, + 83, 56, 83, 57, 84, 33, 85, 33, 88, 3, 88, 4, 88, 5, 88, 6, 88, 7, + 88, 8, 88, 9, 89, 33, 90, 91, 92, 33, 93, 33, 94, 33, 95, 33, 96, 33}; const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, 28, 32, 27, 31}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index cbe721f4078..c6348a52803 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -44,7 +44,7 @@ #include "src/core/lib/transport/metadata.h" -#define GRPC_STATIC_MDSTR_COUNT 93 +#define GRPC_STATIC_MDSTR_COUNT 97 extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ #define GRPC_MDSTR_0 (grpc_static_slice_table[0]) @@ -128,111 +128,121 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; #define GRPC_MDSTR_GRPC (grpc_static_slice_table[39]) /* "grpc-accept-encoding" */ #define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[40]) +/* "grpc.max_request_message_bytes" */ +#define GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES \ + (grpc_static_slice_table[41]) +/* "grpc.max_response_message_bytes" */ +#define GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES \ + (grpc_static_slice_table[42]) +/* "grpc.timeout" */ +#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table[43]) +/* "grpc.wait_for_ready" */ +#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table[44]) /* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[41]) +#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[45]) /* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[42]) +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[46]) /* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[43]) +#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[47]) /* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[44]) +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[48]) /* "grpc-stats-bin" */ -#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[45]) +#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[49]) /* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[46]) +#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[50]) /* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[47]) +#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[51]) /* "grpc-tracing-bin" */ -#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[48]) +#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[52]) /* "gzip" */ -#define GRPC_MDSTR_GZIP (grpc_static_slice_table[49]) +#define GRPC_MDSTR_GZIP (grpc_static_slice_table[53]) /* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[50]) +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[54]) /* "host" */ -#define GRPC_MDSTR_HOST (grpc_static_slice_table[51]) +#define GRPC_MDSTR_HOST (grpc_static_slice_table[55]) /* "http" */ -#define GRPC_MDSTR_HTTP (grpc_static_slice_table[52]) +#define GRPC_MDSTR_HTTP (grpc_static_slice_table[56]) /* "https" */ -#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[53]) +#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[57]) /* "identity" */ -#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[54]) +#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[58]) /* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[55]) +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[59]) /* "identity,deflate,gzip" */ #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_slice_table[56]) + (grpc_static_slice_table[60]) /* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[57]) +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[61]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[58]) +#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[62]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[59]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[63]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[60]) +#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[64]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[61]) +#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[65]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[62]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[66]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[63]) +#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[67]) /* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[64]) +#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[68]) /* "lb-token" */ -#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[65]) +#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[69]) /* "link" */ -#define GRPC_MDSTR_LINK (grpc_static_slice_table[66]) +#define GRPC_MDSTR_LINK (grpc_static_slice_table[70]) /* "location" */ -#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[67]) +#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[71]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[68]) +#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[72]) /* ":method" */ -#define GRPC_MDSTR_METHOD (grpc_static_slice_table[69]) +#define GRPC_MDSTR_METHOD (grpc_static_slice_table[73]) /* ":path" */ -#define GRPC_MDSTR_PATH (grpc_static_slice_table[70]) +#define GRPC_MDSTR_PATH (grpc_static_slice_table[74]) /* "POST" */ -#define GRPC_MDSTR_POST (grpc_static_slice_table[71]) +#define GRPC_MDSTR_POST (grpc_static_slice_table[75]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[72]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[76]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[73]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[77]) /* "PUT" */ -#define GRPC_MDSTR_PUT (grpc_static_slice_table[74]) +#define GRPC_MDSTR_PUT (grpc_static_slice_table[78]) /* "range" */ -#define GRPC_MDSTR_RANGE (grpc_static_slice_table[75]) +#define GRPC_MDSTR_RANGE (grpc_static_slice_table[79]) /* "referer" */ -#define GRPC_MDSTR_REFERER (grpc_static_slice_table[76]) +#define GRPC_MDSTR_REFERER (grpc_static_slice_table[80]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[77]) +#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[81]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[78]) +#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[82]) /* ":scheme" */ -#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[79]) +#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[83]) /* "server" */ -#define GRPC_MDSTR_SERVER (grpc_static_slice_table[80]) +#define GRPC_MDSTR_SERVER (grpc_static_slice_table[84]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[81]) +#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[85]) /* "/" */ -#define GRPC_MDSTR_SLASH (grpc_static_slice_table[82]) +#define GRPC_MDSTR_SLASH (grpc_static_slice_table[86]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[83]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[87]) /* ":status" */ -#define GRPC_MDSTR_STATUS (grpc_static_slice_table[84]) +#define GRPC_MDSTR_STATUS (grpc_static_slice_table[88]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[85]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[89]) /* "te" */ -#define GRPC_MDSTR_TE (grpc_static_slice_table[86]) +#define GRPC_MDSTR_TE (grpc_static_slice_table[90]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[87]) +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[91]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[88]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[92]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[89]) +#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[93]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[90]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table[94]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[91]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table[95]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[92]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[96]) bool grpc_is_static_metadata_string(grpc_slice slice); diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 12db0ff0248..75634826098 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -40,6 +40,10 @@ "\x03GET" "\x04grpc" "\x14grpc-accept-encoding" +"\x1Egrpc.max_request_message_bytes" +"\x1Fgrpc.max_response_message_bytes" +"\x0Cgrpc.timeout" +"\x13grpc.wait_for_ready" "\x0Dgrpc-encoding" "\x1Egrpc-internal-encoding-request" "\x0Cgrpc-message" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index f0c6ffe09c2..a9001a68971 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -43,6 +43,7 @@ import re # also be created) CONFIG = [ + # metadata strings 'grpc-timeout', 'grpc-internal-encoding-request', 'grpc-payload-bin', @@ -57,6 +58,12 @@ CONFIG = [ 'grpc-tracing-bin', 'grpc-stats-bin', '', + # channel arg keys + 'grpc.wait_for_ready', + 'grpc.timeout', + 'grpc.max_request_message_bytes', + 'grpc.max_response_message_bytes', + # metadata elements ('grpc-status', '0'), ('grpc-status', '1'), ('grpc-status', '2'), From c9b0b28772dbf93ed428c54be2badea48159e91e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 14 Nov 2016 16:03:28 -0800 Subject: [PATCH 015/261] Progress towards mdstr elimination --- include/grpc/slice.h | 2 + .../chttp2/transport/chttp2_plugin.c | 2 - src/core/lib/transport/method_config.c | 200 ++++++++---------- src/core/lib/transport/transport_op_string.c | 6 +- test/core/end2end/cq_verifier.c | 17 ++ test/core/end2end/cq_verifier.h | 2 + test/core/end2end/end2end_test_utils.c | 22 +- test/core/end2end/end2end_tests.h | 6 +- .../end2end/tests/authority_not_supported.c | 21 +- test/core/end2end/tests/bad_hostname.c | 10 +- test/core/end2end/tests/binary_metadata.c | 42 ++-- test/core/end2end/tests/call_creds.c | 29 ++- test/core/end2end/tests/cancel_after_accept.c | 16 +- .../end2end/tests/cancel_after_client_done.c | 11 +- test/core/end2end/tests/cancel_after_invoke.c | 11 +- .../core/end2end/tests/cancel_before_invoke.c | 11 +- test/core/end2end/tests/cancel_in_a_vacuum.c | 5 +- test/core/end2end/tests/cancel_with_status.c | 13 +- test/core/end2end/tests/compressed_payload.c | 47 ++-- test/core/end2end/tests/default_host.c | 18 +- test/core/end2end/tests/disappearing_server.c | 18 +- test/core/end2end/tests/empty_batch.c | 5 +- .../end2end/tests/filter_call_init_fails.c | 13 +- test/core/end2end/tests/filter_causes_close.c | 14 +- .../end2end/tests/graceful_server_shutdown.c | 16 +- test/core/end2end/tests/high_initial_seqno.c | 18 +- test/core/end2end/tests/hpack_size.c | 36 ++-- test/core/end2end/tests/idempotent_request.c | 18 +- .../core/end2end/tests/invoke_large_request.c | 18 +- test/core/end2end/tests/large_metadata.c | 32 +-- test/core/end2end/tests/load_reporting_hook.c | 24 +-- .../end2end/tests/max_concurrent_streams.c | 45 ++-- test/core/end2end/tests/max_message_length.c | 62 +++--- test/core/end2end/tests/negative_deadline.c | 11 +- .../end2end/tests/network_status_change.c | 16 +- test/core/end2end/tests/no_logging.c | 18 +- test/core/end2end/tests/payload.c | 18 +- test/core/end2end/tests/ping_pong_streaming.c | 14 +- test/core/end2end/tests/registered_call.c | 13 +- test/core/end2end/tests/request_with_flags.c | 11 +- .../core/end2end/tests/request_with_payload.c | 18 +- .../end2end/tests/resource_quota_server.c | 19 +- .../end2end/tests/server_finishes_request.c | 18 +- .../end2end/tests/shutdown_finishes_calls.c | 13 +- .../end2end/tests/simple_cacheable_request.c | 40 ++-- .../end2end/tests/simple_delayed_request.c | 18 +- test/core/end2end/tests/simple_metadata.c | 40 ++-- test/core/end2end/tests/simple_request.c | 18 +- .../end2end/tests/streaming_error_response.c | 19 +- test/core/end2end/tests/trailing_metadata.c | 51 +++-- 50 files changed, 600 insertions(+), 565 deletions(-) diff --git a/include/grpc/slice.h b/include/grpc/slice.h index dd9cbd5d0bf..60177267047 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -130,6 +130,8 @@ GPRAPI int grpc_slice_buf_cmp(grpc_slice a, const void *b, size_t blen); GPRAPI int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t blen); +GPRAPI int grpc_slice_rchr(grpc_slice s, char c); + GPRAPI uint32_t grpc_slice_hash(grpc_slice s); #ifdef __cplusplus diff --git a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c index bd87253ed32..ade574092f7 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c @@ -37,8 +37,6 @@ #include "src/core/lib/transport/metadata.h" void grpc_chttp2_plugin_init(void) { - grpc_chttp2_base64_encode_and_huffman_compress = - grpc_chttp2_base64_encode_and_huffman_compress_impl; grpc_register_tracer("http", &grpc_http_trace); grpc_register_tracer("flowctl", &grpc_flowctl_trace); } diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c index 0b3a6c8fbbd..75317d426de 100644 --- a/src/core/lib/transport/method_config.c +++ b/src/core/lib/transport/method_config.c @@ -40,7 +40,9 @@ #include #include "src/core/lib/slice/slice_hash_table.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" +#include "src/core/lib/transport/static_metadata.h" // // grpc_method_config @@ -48,37 +50,37 @@ // bool vtable -static void* bool_copy(void* valuep) { - bool value = *(bool*)valuep; - bool* new_value = gpr_malloc(sizeof(bool)); +static void *bool_copy(void *valuep) { + bool value = *(bool *)valuep; + bool *new_value = gpr_malloc(sizeof(bool)); *new_value = value; return new_value; } -static int bool_cmp(void* v1, void* v2) { - bool b1 = *(bool*)v1; - bool b2 = *(bool*)v2; +static int bool_cmp(void *v1, void *v2) { + bool b1 = *(bool *)v1; + bool b2 = *(bool *)v2; if (!b1 && b2) return -1; if (b1 && !b2) return 1; return 0; } -static void free_mem(grpc_exec_ctx* exec_ctx, void* p) { gpr_free(p); } +static void free_mem(grpc_exec_ctx *exec_ctx, void *p) { gpr_free(p); } static grpc_slice_hash_table_vtable bool_vtable = {free_mem, bool_copy, bool_cmp}; // timespec vtable -static void* timespec_copy(void* valuep) { - gpr_timespec value = *(gpr_timespec*)valuep; - gpr_timespec* new_value = gpr_malloc(sizeof(gpr_timespec)); +static void *timespec_copy(void *valuep) { + gpr_timespec value = *(gpr_timespec *)valuep; + gpr_timespec *new_value = gpr_malloc(sizeof(gpr_timespec)); *new_value = value; return new_value; } -static int timespec_cmp(void* v1, void* v2) { - return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); +static int timespec_cmp(void *v1, void *v2) { + return gpr_time_cmp(*(gpr_timespec *)v1, *(gpr_timespec *)v2); } static grpc_slice_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, @@ -86,16 +88,16 @@ static grpc_slice_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, // int32 vtable -static void* int32_copy(void* valuep) { - int32_t value = *(int32_t*)valuep; - int32_t* new_value = gpr_malloc(sizeof(int32_t)); +static void *int32_copy(void *valuep) { + int32_t value = *(int32_t *)valuep; + int32_t *new_value = gpr_malloc(sizeof(int32_t)); *new_value = value; return new_value; } -static int int32_cmp(void* v1, void* v2) { - int32_t i1 = *(int32_t*)v1; - int32_t i2 = *(int32_t*)v2; +static int int32_cmp(void *v1, void *v2) { + int32_t i1 = *(int32_t *)v1; + int32_t i2 = *(int32_t *)v2; if (i1 < i2) return -1; if (i1 > i2) return 1; return 0; @@ -104,57 +106,37 @@ static int int32_cmp(void* v1, void* v2) { static grpc_slice_hash_table_vtable int32_vtable = {free_mem, int32_copy, int32_cmp}; -// Hash table keys. -#define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool -#define GRPC_METHOD_CONFIG_TIMEOUT "grpc.timeout" // gpr_timespec -#define GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES \ - "grpc.max_request_message_bytes" // int32 -#define GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES \ - "grpc.max_response_message_bytes" // int32 - struct grpc_method_config { - grpc_slice_hash_table* table; - grpc_slice wait_for_ready_key; - grpc_slice timeout_key; - grpc_slice max_request_message_bytes_key; - grpc_slice max_response_message_bytes_key; + grpc_slice_hash_table *table; }; -grpc_method_config* grpc_method_config_create( - bool* wait_for_ready, gpr_timespec* timeout, - int32_t* max_request_message_bytes, int32_t* max_response_message_bytes) { - grpc_method_config* method_config = gpr_malloc(sizeof(grpc_method_config)); +grpc_method_config *grpc_method_config_create( + bool *wait_for_ready, gpr_timespec *timeout, + int32_t *max_request_message_bytes, int32_t *max_response_message_bytes) { + grpc_method_config *method_config = gpr_malloc(sizeof(grpc_method_config)); memset(method_config, 0, sizeof(grpc_method_config)); - method_config->wait_for_ready_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_WAIT_FOR_READY); - method_config->timeout_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_TIMEOUT); - method_config->max_request_message_bytes_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); - method_config->max_response_message_bytes_key = - grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); grpc_slice_hash_table_entry entries[4]; size_t num_entries = 0; if (wait_for_ready != NULL) { - entries[num_entries].key = method_config->wait_for_ready_key; + entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY; entries[num_entries].value = wait_for_ready; entries[num_entries].vtable = &bool_vtable; ++num_entries; } if (timeout != NULL) { - entries[num_entries].key = method_config->timeout_key; + entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_TIMEOUT; entries[num_entries].value = timeout; entries[num_entries].vtable = ×pec_vtable; ++num_entries; } if (max_request_message_bytes != NULL) { - entries[num_entries].key = method_config->max_request_message_bytes_key; + entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES; entries[num_entries].value = max_request_message_bytes; entries[num_entries].vtable = &int32_vtable; ++num_entries; } if (max_response_message_bytes != NULL) { - entries[num_entries].key = method_config->max_response_message_bytes_key; + entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES; entries[num_entries].value = max_response_message_bytes; entries[num_entries].vtable = &int32_vtable; ++num_entries; @@ -163,137 +145,129 @@ grpc_method_config* grpc_method_config_create( return method_config; } -grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { +grpc_method_config *grpc_method_config_ref(grpc_method_config *method_config) { grpc_slice_hash_table_ref(method_config->table); return method_config; } -void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, - grpc_method_config* method_config) { +void grpc_method_config_unref(grpc_exec_ctx *exec_ctx, + grpc_method_config *method_config) { if (grpc_slice_hash_table_unref(exec_ctx, method_config->table)) { - GRPC_MDSTR_UNREF(exec_ctx, method_config->wait_for_ready_key); - GRPC_MDSTR_UNREF(exec_ctx, method_config->timeout_key); - GRPC_MDSTR_UNREF(exec_ctx, method_config->max_request_message_bytes_key); - GRPC_MDSTR_UNREF(exec_ctx, method_config->max_response_message_bytes_key); gpr_free(method_config); } } -int grpc_method_config_cmp(const grpc_method_config* method_config1, - const grpc_method_config* method_config2) { +int grpc_method_config_cmp(const grpc_method_config *method_config1, + const grpc_method_config *method_config2) { return grpc_slice_hash_table_cmp(method_config1->table, method_config2->table); } -const bool* grpc_method_config_get_wait_for_ready( - const grpc_method_config* method_config) { +const bool *grpc_method_config_get_wait_for_ready( + const grpc_method_config *method_config) { return grpc_slice_hash_table_get(method_config->table, - method_config->wait_for_ready_key); + GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY); } -const gpr_timespec* grpc_method_config_get_timeout( - const grpc_method_config* method_config) { +const gpr_timespec *grpc_method_config_get_timeout( + const grpc_method_config *method_config) { return grpc_slice_hash_table_get(method_config->table, - method_config->timeout_key); + GRPC_MDSTR_GRPC_DOT_TIMEOUT); } -const int32_t* grpc_method_config_get_max_request_message_bytes( - const grpc_method_config* method_config) { +const int32_t *grpc_method_config_get_max_request_message_bytes( + const grpc_method_config *method_config) { return grpc_slice_hash_table_get( - method_config->table, method_config->max_request_message_bytes_key); + method_config->table, GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES); } -const int32_t* grpc_method_config_get_max_response_message_bytes( - const grpc_method_config* method_config) { +const int32_t *grpc_method_config_get_max_response_message_bytes( + const grpc_method_config *method_config) { return grpc_slice_hash_table_get( - method_config->table, method_config->max_response_message_bytes_key); + method_config->table, GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES); } // // grpc_method_config_table // -static void method_config_unref(grpc_exec_ctx* exec_ctx, void* valuep) { +static void method_config_unref(grpc_exec_ctx *exec_ctx, void *valuep) { grpc_method_config_unref(exec_ctx, valuep); } -static void* method_config_ref(void* valuep) { +static void *method_config_ref(void *valuep) { return grpc_method_config_ref(valuep); } -static int method_config_cmp(void* valuep1, void* valuep2) { +static int method_config_cmp(void *valuep1, void *valuep2) { return grpc_method_config_cmp(valuep1, valuep2); } static const grpc_slice_hash_table_vtable method_config_table_vtable = { method_config_unref, method_config_ref, method_config_cmp}; -grpc_method_config_table* grpc_method_config_table_create( - size_t num_entries, grpc_method_config_table_entry* entries) { - grpc_slice_hash_table_entry* hash_table_entries = +grpc_method_config_table *grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry *entries) { + grpc_slice_hash_table_entry *hash_table_entries = gpr_malloc(sizeof(grpc_slice_hash_table_entry) * num_entries); for (size_t i = 0; i < num_entries; ++i) { hash_table_entries[i].key = entries[i].method_name; hash_table_entries[i].value = entries[i].method_config; hash_table_entries[i].vtable = &method_config_table_vtable; } - grpc_method_config_table* method_config_table = + grpc_method_config_table *method_config_table = grpc_slice_hash_table_create(num_entries, hash_table_entries); gpr_free(hash_table_entries); return method_config_table; } -grpc_method_config_table* grpc_method_config_table_ref( - grpc_method_config_table* table) { +grpc_method_config_table *grpc_method_config_table_ref( + grpc_method_config_table *table) { return grpc_slice_hash_table_ref(table); } -void grpc_method_config_table_unref(grpc_exec_ctx* exec_ctx, - grpc_method_config_table* table) { +void grpc_method_config_table_unref(grpc_exec_ctx *exec_ctx, + grpc_method_config_table *table) { grpc_slice_hash_table_unref(exec_ctx, table); } -int grpc_method_config_table_cmp(const grpc_method_config_table* table1, - const grpc_method_config_table* table2) { +int grpc_method_config_table_cmp(const grpc_method_config_table *table1, + const grpc_method_config_table *table2) { return grpc_slice_hash_table_cmp(table1, table2); } -void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_slice_hash_table* table, - const grpc_slice path) { - void* value = grpc_slice_hash_table_get(table, path); +void *grpc_method_config_table_get(grpc_exec_ctx *exec_ctx, + const grpc_slice_hash_table *table, + const grpc_slice path) { + void *value = grpc_slice_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_slice wildcard_path = grpc_mdstr_from_string(buf); - gpr_free(buf); - value = grpc_slice_hash_table_get(table, wildcard_path); - GRPC_MDSTR_UNREF(exec_ctx, wildcard_path); + int sep_pos = grpc_slice_rchr(path, '/') + 1; + grpc_slice search = grpc_slice_malloc((size_t)(sep_pos + 1)); + memcpy(GRPC_SLICE_START_PTR(search), GRPC_SLICE_START_PTR(path), + (size_t)sep_pos); + GRPC_SLICE_START_PTR(search)[sep_pos] = '*'; + value = grpc_slice_hash_table_get(table, search); + grpc_slice_unref_internal(exec_ctx, search); } return value; } -static void* copy_arg(void* p) { return grpc_method_config_table_ref(p); } +static void *copy_arg(void *p) { return grpc_method_config_table_ref(p); } -static void destroy_arg(grpc_exec_ctx* exec_ctx, void* p) { +static void destroy_arg(grpc_exec_ctx *exec_ctx, void *p) { grpc_method_config_table_unref(exec_ctx, p); } -static int cmp_arg(void* p1, void* p2) { +static int cmp_arg(void *p1, void *p2) { return grpc_method_config_table_cmp(p1, p2); } static grpc_arg_pointer_vtable arg_vtable = {copy_arg, destroy_arg, cmp_arg}; grpc_arg grpc_method_config_table_create_channel_arg( - grpc_method_config_table* table) { + grpc_method_config_table *table) { grpc_arg arg; arg.type = GRPC_ARG_POINTER; arg.key = GRPC_ARG_SERVICE_CONFIG; @@ -304,27 +278,27 @@ grpc_arg grpc_method_config_table_create_channel_arg( // State used by convert_entry() below. typedef struct conversion_state { - void* (*convert_value)(const grpc_method_config* method_config); - const grpc_slice_hash_table_vtable* vtable; + void *(*convert_value)(const grpc_method_config *method_config); + const grpc_slice_hash_table_vtable *vtable; size_t num_entries; - grpc_slice_hash_table_entry* entries; + grpc_slice_hash_table_entry *entries; } conversion_state; // A function to be passed to grpc_slice_hash_table_iterate() to create // a copy of the entries. -static void convert_entry(const grpc_slice_hash_table_entry* entry, - void* user_data) { - conversion_state* state = user_data; - state->entries[state->num_entries].key = GRPC_MDSTR_REF(entry->key); +static void convert_entry(const grpc_slice_hash_table_entry *entry, + void *user_data) { + conversion_state *state = user_data; + state->entries[state->num_entries].key = grpc_slice_ref_internal(entry->key); state->entries[state->num_entries].value = state->convert_value(entry->value); state->entries[state->num_entries].vtable = state->vtable; ++state->num_entries; } -grpc_slice_hash_table* grpc_method_config_table_convert( - grpc_exec_ctx* exec_ctx, const grpc_method_config_table* table, - void* (*convert_value)(const grpc_method_config* method_config), - const grpc_slice_hash_table_vtable* vtable) { +grpc_slice_hash_table *grpc_method_config_table_convert( + grpc_exec_ctx *exec_ctx, const grpc_method_config_table *table, + void *(*convert_value)(const grpc_method_config *method_config), + const grpc_slice_hash_table_vtable *vtable) { // Create an array of the entries in the table with converted values. conversion_state state; state.convert_value = convert_value; @@ -334,11 +308,11 @@ grpc_slice_hash_table* grpc_method_config_table_convert( grpc_slice_hash_table_num_entries(table)); grpc_slice_hash_table_iterate(table, convert_entry, &state); // Create a new table based on the array we just constructed. - grpc_slice_hash_table* new_table = + grpc_slice_hash_table *new_table = grpc_slice_hash_table_create(state.num_entries, state.entries); // Clean up the array. for (size_t i = 0; i < state.num_entries; ++i) { - GRPC_MDSTR_UNREF(exec_ctx, state.entries[i].key); + grpc_slice_unref_internal(exec_ctx, state.entries[i].key); vtable->destroy_value(exec_ctx, state.entries[i].value); } gpr_free(state.entries); diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index 58d6ad508e3..deb155e6593 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -49,12 +49,10 @@ static void put_metadata(gpr_strvec *b, grpc_mdelem *md) { gpr_strvec_add(b, gpr_strdup("key=")); - gpr_strvec_add( - b, grpc_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII)); + gpr_strvec_add(b, grpc_dump_slice(md->key, GPR_DUMP_HEX | GPR_DUMP_ASCII)); gpr_strvec_add(b, gpr_strdup(" value=")); - gpr_strvec_add( - b, grpc_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII)); + gpr_strvec_add(b, grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII)); } static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) { diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 6a463e8613e..925c59e696e 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -105,6 +105,23 @@ int contains_metadata(grpc_metadata_array *array, const char *key, return has_metadata(array->metadata, array->count, key, value); } +static int has_metadata_slices(const grpc_metadata *md, size_t count, + grpc_slice key, grpc_slice value) { + size_t i; + for (i = 0; i < count; i++) { + if (0 == grpc_slice_cmp(md[i].key, key) && + 0 == grpc_slice_cmp(md[i].value, value)) { + return 1; + } + } + return 0; +} + +int contains_metadata_slices(grpc_metadata_array *array, grpc_slice key, + grpc_slice value) { + return has_metadata_slices(array->metadata, array->count, key, value); +} + static grpc_slice merge_slices(grpc_slice *slices, size_t nslices) { size_t i; size_t len = 0; diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h index b754de9bbe7..035aa270e4a 100644 --- a/test/core/end2end/cq_verifier.h +++ b/test/core/end2end/cq_verifier.h @@ -71,5 +71,7 @@ int byte_buffer_eq_slice(grpc_byte_buffer *bb, grpc_slice b); int byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string); int contains_metadata(grpc_metadata_array *array, const char *key, const char *value); +int contains_metadata_slices(grpc_metadata_array *array, grpc_slice key, + grpc_slice value); #endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */ diff --git a/test/core/end2end/end2end_test_utils.c b/test/core/end2end/end2end_test_utils.c index 46fb4ec1aff..8783d8451b6 100644 --- a/test/core/end2end/end2end_test_utils.c +++ b/test/core/end2end/end2end_test_utils.c @@ -39,13 +39,27 @@ const char *get_host_override_string(const char *str, grpc_end2end_test_config config) { - return (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER ? str - : NULL); + if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) { + return str; + } else { + return NULL; + } +} + +const grpc_slice *get_host_override_slice(const char *str, + grpc_end2end_test_config config) { + const char *r = get_host_override_string(str, config); + if (r != NULL) { + static grpc_slice ret; + ret = grpc_slice_from_static_string(r); + return &ret; + } + return NULL; } -void validate_host_override_string(const char *pattern, const char *str, +void validate_host_override_string(const char *pattern, grpc_slice str, grpc_end2end_test_config config) { if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) { - GPR_ASSERT(0 == strcmp(str, pattern)); + GPR_ASSERT(0 == grpc_slice_str_cmp(str, pattern)); } } diff --git a/test/core/end2end/end2end_tests.h b/test/core/end2end/end2end_tests.h index f25e90b5f61..cb0afd9cd99 100644 --- a/test/core/end2end/end2end_tests.h +++ b/test/core/end2end/end2end_tests.h @@ -72,8 +72,12 @@ void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config); const char *get_host_override_string(const char *str, grpc_end2end_test_config config); +/* Returns a pointer to a statically allocated slice: future invocations + overwrite past invocations, not threadsafe, etc... */ +const grpc_slice *get_host_override_slice(const char *str, + grpc_end2end_test_config config); -void validate_host_override_string(const char *pattern, const char *str, +void validate_host_override_string(const char *pattern, grpc_slice str, grpc_end2end_test_config config); #endif /* GRPC_TEST_CORE_END2END_END2END_TESTS_H */ diff --git a/test/core/end2end/tests/authority_not_supported.c b/test/core/end2end/tests/authority_not_supported.c index 705970f6cab..40d217e6195 100644 --- a/test/core/end2end/tests/authority_not_supported.c +++ b/test/core/end2end/tests/authority_not_supported.c @@ -103,9 +103,14 @@ static void test_with_authority_header(grpc_end2end_test_config config) { grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = { - {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), + grpc_slice_from_static_string("val1"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key2"), + grpc_slice_from_static_string("val2"), + 0, + {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test(config, "test_with_authority_header", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -116,11 +121,12 @@ static void test_with_authority_header(grpc_end2end_test_config config) { grpc_byte_buffer *response_payload_recv = NULL; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/foo", "foo.test.google.fr", deadline, NULL); + grpc_slice_from_static_string("/foo"), &host, + deadline, NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -157,7 +163,6 @@ static void test_with_authority_header(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -169,7 +174,7 @@ static void test_with_authority_header(grpc_end2end_test_config config) { GPR_ASSERT(status == GRPC_STATUS_CANCELLED); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/bad_hostname.c b/test/core/end2end/tests/bad_hostname.c index e0c7ac7c021..f18abc78f0c 100644 --- a/test/core/end2end/tests/bad_hostname.c +++ b/test/core/end2end/tests/bad_hostname.c @@ -109,11 +109,12 @@ static void simple_request_body(grpc_end2end_test_fixture f) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; + grpc_slice host = grpc_slice_from_static_string("slartibartfast.local"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/foo", "slartibartfast.local", deadline, NULL); + grpc_slice_from_static_string("/foo"), &host, + deadline, NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -141,7 +142,6 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -153,7 +153,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { GPR_ASSERT(status == GRPC_STATUS_INTERNAL); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/binary_metadata.c b/test/core/end2end/tests/binary_metadata.c index a13613a4720..bfdc7be5447 100644 --- a/test/core/end2end/tests/binary_metadata.c +++ b/test/core/end2end/tests/binary_metadata.c @@ -110,25 +110,25 @@ static void test_request_response_with_metadata_and_payload( grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); grpc_metadata meta_c[2] = { - {"key1-bin", - "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", - 13, + {grpc_slice_from_static_string("key1-bin"), + grpc_slice_from_static_string( + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"), 0, {{NULL, NULL, NULL, NULL}}}, - {"key2-bin", - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", - 14, + {grpc_slice_from_static_string("key2-bin"), + grpc_slice_from_static_string( + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"), 0, {{NULL, NULL, NULL, NULL}}}}; grpc_metadata meta_s[2] = { - {"key3-bin", - "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", - 15, + {grpc_slice_from_static_string("key3-bin"), + grpc_slice_from_static_string( + "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"), 0, {{NULL, NULL, NULL, NULL}}}, - {"key4-bin", - "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", - 16, + {grpc_slice_from_static_string("key4-bin"), + grpc_slice_from_static_string( + "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( @@ -144,13 +144,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -190,7 +190,6 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -238,7 +237,8 @@ static void test_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_string = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_string; op->flags = 0; op->reserved = NULL; op++; @@ -250,8 +250,8 @@ static void test_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -270,7 +270,7 @@ static void test_request_response_with_metadata_and_payload( &initial_metadata_recv, "key4-bin", "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/call_creds.c b/test/core/end2end/tests/call_creds.c index 606938fff64..ebc854606b1 100644 --- a/test/core/end2end/tests/call_creds.c +++ b/test/core/end2end/tests/call_creds.c @@ -156,8 +156,7 @@ static void request_response_with_payload_and_call_creds( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; grpc_call_credentials *creds = NULL; grpc_auth_context *s_auth_context = NULL; @@ -167,8 +166,9 @@ static void request_response_with_payload_and_call_creds( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL); @@ -225,7 +225,6 @@ static void request_response_with_payload_and_call_creds( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -284,7 +283,8 @@ static void request_response_with_payload_and_call_creds( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -296,8 +296,8 @@ static void request_response_with_payload_and_call_creds( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -337,7 +337,7 @@ static void request_response_with_payload_and_call_creds( break; } - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -391,8 +391,7 @@ static void test_request_with_server_rejecting_client_creds( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -404,8 +403,9 @@ static void test_request_with_server_rejecting_client_creds( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -425,7 +425,6 @@ static void test_request_with_server_rejecting_client_creds( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -468,7 +467,7 @@ static void test_request_with_server_rejecting_client_creds( grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index c0beb456ad7..a2301d725cf 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -43,6 +43,7 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/method_config.h" @@ -118,8 +119,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = @@ -136,13 +136,13 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, if (use_service_config) { gpr_timespec timeout = {5, 0, GPR_TIMESPAN}; grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), + grpc_slice_from_static_string("/service/method"), grpc_method_config_create(NULL, &timeout, NULL, NULL), }; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_method_config_table *method_config_table = grpc_method_config_table_create(1, &entry); - GRPC_MDSTR_UNREF(&exec_ctx, entry.method_name); + grpc_slice_unref_internal(&exec_ctx, entry.method_name); grpc_method_config_unref(&exec_ctx, entry.method_config); grpc_arg arg = grpc_method_config_table_create_channel_arg(method_config_table); @@ -156,8 +156,9 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, cq_verifier *cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/service/method", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/service/method"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -172,7 +173,6 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -248,7 +248,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_call_destroy(c); grpc_call_destroy(s); diff --git a/test/core/end2end/tests/cancel_after_client_done.c b/test/core/end2end/tests/cancel_after_client_done.c index 7742f9d1798..63b8150cb63 100644 --- a/test/core/end2end/tests/cancel_after_client_done.c +++ b/test/core/end2end/tests/cancel_after_client_done.c @@ -113,8 +113,7 @@ static void test_cancel_after_accept_and_writes_closed( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = @@ -128,8 +127,9 @@ static void test_cancel_after_accept_and_writes_closed( int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -144,7 +144,6 @@ static void test_cancel_after_accept_and_writes_closed( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -224,7 +223,7 @@ static void test_cancel_after_accept_and_writes_closed( grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_call_destroy(c); grpc_call_destroy(s); diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c index c3c5418f207..216c3637609 100644 --- a/test/core/end2end/tests/cancel_after_invoke.c +++ b/test/core/end2end/tests/cancel_after_invoke.c @@ -113,8 +113,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -122,8 +121,9 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_raw_byte_buffer_create(&request_payload_slice, 1); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -138,7 +138,6 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -183,7 +182,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_before_invoke.c b/test/core/end2end/tests/cancel_before_invoke.c index d4842829c0a..c198fd1713e 100644 --- a/test/core/end2end/tests/cancel_before_invoke.c +++ b/test/core/end2end/tests/cancel_before_invoke.c @@ -111,8 +111,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -120,8 +119,9 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_raw_byte_buffer_create(&request_payload_slice, 1); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -138,7 +138,6 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -181,7 +180,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_in_a_vacuum.c b/test/core/end2end/tests/cancel_in_a_vacuum.c index 5be850b6ea9..af919805c7a 100644 --- a/test/core/end2end/tests/cancel_in_a_vacuum.c +++ b/test/core/end2end/tests/cancel_in_a_vacuum.c @@ -106,8 +106,9 @@ static void test_cancel_in_a_vacuum(grpc_end2end_test_config config, cq_verifier *v_client = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); diff --git a/test/core/end2end/tests/cancel_with_status.c b/test/core/end2end/tests/cancel_with_status.c index 3aecaf71598..38f8c612d14 100644 --- a/test/core/end2end/tests/cancel_with_status.c +++ b/test/core/end2end/tests/cancel_with_status.c @@ -108,14 +108,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,7 +128,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -156,9 +155,9 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/compressed_payload.c b/test/core/end2end/tests/compressed_payload.c index d7efe7747bf..847bc1a8c96 100644 --- a/test/core/end2end/tests/compressed_payload.c +++ b/test/core/end2end/tests/compressed_payload.c @@ -48,6 +48,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call_test_only.h" +#include "src/core/lib/transport/static_metadata.h" #include "test/core/end2end/cq_verifier.h" static void *tag(intptr_t t) { return (void *)t; } @@ -125,8 +126,7 @@ static void request_for_disabled_algorithm( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; cq_verifier *cqv; char str[1024]; @@ -151,8 +151,9 @@ static void request_for_disabled_algorithm( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -191,7 +192,6 @@ static void request_for_disabled_algorithm( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -245,13 +245,13 @@ static void request_for_disabled_algorithm( gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.", algo_name); /* and we expect a specific reason for it */ - GPR_ASSERT(0 == strcmp(details, expected_details)); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details)); gpr_free(expected_details); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -305,8 +305,7 @@ static void request_with_payload_template( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; cq_verifier *cqv; char request_str[1024]; @@ -331,8 +330,9 @@ static void request_with_payload_template( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -362,7 +362,6 @@ static void request_with_payload_template( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -489,7 +488,8 @@ static void request_with_payload_template( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -503,13 +503,13 @@ static void request_with_payload_template( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -569,17 +569,14 @@ static void test_invoke_request_with_compressed_payload_md_override( grpc_metadata gzip_compression_override; grpc_metadata identity_compression_override; - gzip_compression_override.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; - gzip_compression_override.value = "gzip"; - gzip_compression_override.value_length = - strlen(gzip_compression_override.value); + gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; + gzip_compression_override.value = grpc_slice_from_static_string("gzip"); memset(&gzip_compression_override.internal_data, 0, sizeof(gzip_compression_override.internal_data)); - identity_compression_override.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; - identity_compression_override.value = "identity"; - identity_compression_override.value_length = - strlen(identity_compression_override.value); + identity_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; + identity_compression_override.value = + grpc_slice_from_static_string("identity"); memset(&identity_compression_override.internal_data, 0, sizeof(identity_compression_override.internal_data)); diff --git a/test/core/end2end/tests/default_host.c b/test/core/end2end/tests/default_host.c index 208e31697e6..0c39957fa78 100644 --- a/test/core/end2end/tests/default_host.c +++ b/test/core/end2end/tests/default_host.c @@ -110,13 +110,13 @@ static void simple_request_body(grpc_end2end_test_fixture f) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; char *peer; c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/foo", NULL, deadline, NULL); + grpc_slice_from_static_string("/foo"), NULL, + deadline, NULL); GPR_ASSERT(c); peer = grpc_call_get_peer(c); @@ -149,7 +149,6 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -182,7 +181,8 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -199,12 +199,12 @@ static void simple_request_body(grpc_end2end_test_fixture f) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); - GPR_ASSERT(0 == strncmp(call_details.host, "localhost", 9)); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(grpc_slice_buf_start_eq(call_details.host, "localhost", 9)); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/disappearing_server.c b/test/core/end2end/tests/disappearing_server.c index 8ebf7e643e0..a01372144c0 100644 --- a/test/core/end2end/tests/disappearing_server.c +++ b/test/core/end2end/tests/disappearing_server.c @@ -93,13 +93,13 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,7 +128,6 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -156,7 +155,8 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -174,13 +174,13 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/empty_batch.c b/test/core/end2end/tests/empty_batch.c index dc8e52a60f0..1b420ad4cbc 100644 --- a/test/core/end2end/tests/empty_batch.c +++ b/test/core/end2end/tests/empty_batch.c @@ -106,8 +106,9 @@ static void empty_batch_body(grpc_end2end_test_config config, grpc_op *op = NULL; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); diff --git a/test/core/end2end/tests/filter_call_init_fails.c b/test/core/end2end/tests/filter_call_init_fails.c index 01b6c32ee7c..5546893ea02 100644 --- a/test/core/end2end/tests/filter_call_init_fails.c +++ b/test/core/end2end/tests/filter_call_init_fails.c @@ -125,12 +125,12 @@ static void test_request(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -165,7 +165,6 @@ static void test_request(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -181,9 +180,9 @@ static void test_request(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED); - GPR_ASSERT(0 == strcmp(details, "access denied")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "access denied")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c index def21be43f8..45040ab3513 100644 --- a/test/core/end2end/tests/filter_causes_close.c +++ b/test/core/end2end/tests/filter_causes_close.c @@ -121,12 +121,12 @@ static void test_request(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -161,7 +161,6 @@ static void test_request(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -177,9 +176,10 @@ static void test_request(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED); - GPR_ASSERT(0 == strcmp(details, "Failure that's not preventable.")); + GPR_ASSERT(0 == + grpc_slice_str_cmp(details, "Failure that's not preventable.")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/graceful_server_shutdown.c b/test/core/end2end/tests/graceful_server_shutdown.c index 5fecadbe441..08af25dd282 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.c +++ b/test/core/end2end/tests/graceful_server_shutdown.c @@ -107,13 +107,13 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -143,7 +143,6 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -171,7 +170,8 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -191,12 +191,12 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_destroy(s); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/high_initial_seqno.c b/test/core/end2end/tests/high_initial_seqno.c index 01a4909ccdb..217ca2bb726 100644 --- a/test/core/end2end/tests/high_initial_seqno.c +++ b/test/core/end2end/tests/high_initial_seqno.c @@ -113,13 +113,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -148,7 +148,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -172,7 +171,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -189,13 +189,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/hpack_size.c b/test/core/end2end/tests/hpack_size.c index cec8b2faae1..9aedc9c1436 100644 --- a/test/core/end2end/tests/hpack_size.c +++ b/test/core/end2end/tests/hpack_size.c @@ -254,24 +254,24 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_status_code status; grpc_call_error error; grpc_metadata extra_metadata[3]; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; memset(extra_metadata, 0, sizeof(extra_metadata)); - extra_metadata[0].key = "hobbit-first-name"; - extra_metadata[0].value = hobbits[index % GPR_ARRAY_SIZE(hobbits)][0]; - extra_metadata[0].value_length = strlen(extra_metadata[0].value); - extra_metadata[1].key = "hobbit-second-name"; - extra_metadata[1].value = hobbits[index % GPR_ARRAY_SIZE(hobbits)][1]; - extra_metadata[1].value_length = strlen(extra_metadata[1].value); - extra_metadata[2].key = "dragon"; - extra_metadata[2].value = dragons[index % GPR_ARRAY_SIZE(dragons)]; - extra_metadata[2].value_length = strlen(extra_metadata[2].value); + extra_metadata[0].key = grpc_slice_from_static_string("hobbit-first-name"); + extra_metadata[0].value = grpc_slice_from_static_string( + hobbits[index % GPR_ARRAY_SIZE(hobbits)][0]); + extra_metadata[1].key = grpc_slice_from_static_string("hobbit-second-name"); + extra_metadata[1].value = grpc_slice_from_static_string( + hobbits[index % GPR_ARRAY_SIZE(hobbits)][1]); + extra_metadata[2].key = grpc_slice_from_static_string("dragon"); + extra_metadata[2].value = + grpc_slice_from_static_string(dragons[index % GPR_ARRAY_SIZE(dragons)]); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -301,7 +301,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -325,7 +324,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -342,13 +342,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/idempotent_request.c b/test/core/end2end/tests/idempotent_request.c index 4f6d3bb808c..2db7accaaa4 100644 --- a/test/core/end2end/tests/idempotent_request.c +++ b/test/core/end2end/tests/idempotent_request.c @@ -111,14 +111,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,7 +152,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -185,7 +184,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -202,14 +202,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST == call_details.flags); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/invoke_large_request.c b/test/core/end2end/tests/invoke_large_request.c index 24abfa2ea0d..e18953a6410 100644 --- a/test/core/end2end/tests/invoke_large_request.c +++ b/test/core/end2end/tests/invoke_large_request.c @@ -140,13 +140,13 @@ static void test_invoke_large_request(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -185,7 +185,6 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -232,7 +231,8 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -244,13 +244,13 @@ static void test_invoke_large_request(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/large_metadata.c b/test/core/end2end/tests/large_metadata.c index 69b4b24b061..b45ceb26643 100644 --- a/test/core/end2end/tests/large_metadata.c +++ b/test/core/end2end/tests/large_metadata.c @@ -122,21 +122,19 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); - meta.key = "key"; - meta.value = gpr_malloc(large_size + 1); - memset((char *)meta.value, 'a', large_size); - ((char *)meta.value)[large_size] = 0; - meta.value_length = large_size; + meta.key = grpc_slice_from_static_string("key"); + meta.value = grpc_slice_malloc(large_size); + memset(GRPC_SLICE_START_PTR(meta.value), 'a', large_size); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -170,7 +168,6 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -216,7 +213,8 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -228,15 +226,17 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); - GPR_ASSERT(contains_metadata(&request_metadata_recv, "key", meta.value)); + GPR_ASSERT(contains_metadata_slices(&request_metadata_recv, + grpc_slice_from_static_string("key"), + meta.value)); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -250,7 +250,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(request_payload_recv); - gpr_free((char *)meta.value); + grpc_slice_unref(meta.value); end_test(&f); config.tear_down_data(&f); diff --git a/test/core/end2end/tests/load_reporting_hook.c b/test/core/end2end/tests/load_reporting_hook.c index ae5c2706299..edc42511191 100644 --- a/test/core/end2end/tests/load_reporting_hook.c +++ b/test/core/end2end/tests/load_reporting_hook.c @@ -146,13 +146,13 @@ static void request_response_with_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, method_name, - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string(method_name), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -193,7 +193,6 @@ static void request_response_with_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -242,7 +241,8 @@ static void request_response_with_payload( op->data.send_status_from_server.trailing_metadata_count = 1; op->data.send_status_from_server.trailing_metadata = trailing_lr_metadata; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -255,7 +255,7 @@ static void request_response_with_payload( GPR_ASSERT(status == GRPC_STATUS_OK); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -295,15 +295,13 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { grpc_metadata initial_lr_metadata; grpc_metadata trailing_lr_metadata; - initial_lr_metadata.key = GRPC_LB_TOKEN_MD_KEY; - initial_lr_metadata.value = "client-token"; - initial_lr_metadata.value_length = strlen(initial_lr_metadata.value); + initial_lr_metadata.key = GRPC_MDSTR_LB_TOKEN; + initial_lr_metadata.value = grpc_slice_from_static_string("client-token"); memset(&initial_lr_metadata.internal_data, 0, sizeof(initial_lr_metadata.internal_data)); - trailing_lr_metadata.key = GRPC_LB_COST_MD_KEY; - trailing_lr_metadata.value = "server-token"; - trailing_lr_metadata.value_length = strlen(trailing_lr_metadata.value); + trailing_lr_metadata.key = GRPC_MDSTR_LB_COST_BIN; + trailing_lr_metadata.value = grpc_slice_from_static_string("server-token"); memset(&trailing_lr_metadata.internal_data, 0, sizeof(trailing_lr_metadata.internal_data)); diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index 9338bc5f0d7..56243179b01 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -109,13 +109,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -144,7 +144,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -168,7 +167,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -185,13 +185,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -223,11 +223,9 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { grpc_metadata_array trailing_metadata_recv2; grpc_status_code status1; grpc_call_error error; - char *details1 = NULL; - size_t details_capacity1 = 0; + grpc_slice details1; grpc_status_code status2; - char *details2 = NULL; - size_t details_capacity2 = 0; + grpc_slice details2; grpc_op ops[6]; grpc_op *op; int was_cancelled; @@ -261,13 +259,15 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { the first completes */ deadline = n_seconds_time(1000); c1 = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/alpha", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/alpha"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c1); c2 = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/beta", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/beta"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c2); @@ -295,7 +295,6 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1; op->data.recv_status_on_client.status = &status1; op->data.recv_status_on_client.status_details = &details1; - op->data.recv_status_on_client.status_details_capacity = &details_capacity1; op->flags = 0; op->reserved = NULL; op++; @@ -327,7 +326,6 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2; op->data.recv_status_on_client.status = &status2; op->data.recv_status_on_client.status_details = &details2; - op->data.recv_status_on_client.status_details_capacity = &details_capacity2; op->flags = 0; op->reserved = NULL; op++; @@ -378,7 +376,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -413,7 +412,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -431,8 +430,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { grpc_call_destroy(c2); grpc_call_destroy(s2); - gpr_free(details1); - gpr_free(details2); + grpc_slice_unref(details1); + grpc_slice_unref(details2); grpc_metadata_array_destroy(&initial_metadata_recv1); grpc_metadata_array_destroy(&trailing_metadata_recv1); grpc_metadata_array_destroy(&initial_metadata_recv2); diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index ec85f3cb5d4..3fbb92863c8 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -43,6 +43,7 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/method_config.h" @@ -129,8 +130,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; grpc_channel_args *client_args = NULL; @@ -141,12 +141,12 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, GPR_ASSERT(send_limit); int32_t max_request_message_bytes = 5; grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), + grpc_slice_from_static_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(&exec_ctx, entry.method_name); + grpc_slice_unref_internal(&exec_ctx, entry.method_name); grpc_method_config_unref(&exec_ctx, entry.method_config); grpc_arg arg = grpc_method_config_table_create_channel_arg(method_config_table); @@ -180,8 +180,9 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/service/method", - get_host_override_string("foo.test.google.fr:1234", config), + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/service/method"), + get_host_override_slice("foo.test.google.fr:1234", config), gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); @@ -215,7 +216,6 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -254,19 +254,20 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.method, "/service/method")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); done: GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT); - GPR_ASSERT(strcmp(details, - send_limit - ? "Sent message larger than max (11 vs. 5)" - : "Received message larger than max (11 vs. 5)") == 0); + GPR_ASSERT( + grpc_slice_str_cmp( + details, send_limit + ? "Sent message larger than max (11 vs. 5)" + : "Received message larger than max (11 vs. 5)") == 0); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -309,8 +310,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; grpc_channel_args *client_args = NULL; @@ -321,13 +321,13 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, GPR_ASSERT(!send_limit); int32_t max_response_message_bytes = 5; grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), + grpc_slice_from_static_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(&exec_ctx, entry.method_name); + grpc_slice_unref_internal(&exec_ctx, entry.method_name); grpc_method_config_unref(&exec_ctx, entry.method_config); grpc_arg arg = grpc_method_config_table_create_channel_arg(method_config_table); @@ -359,9 +359,11 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, } cqv = cq_verifier_create(f.cq); - c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/service/method", "foo.test.google.fr:1234", - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + c = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/service/method"), + get_host_override_slice("foo.test.google.fr:1234", config), + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -394,7 +396,6 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -428,7 +429,8 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -439,16 +441,18 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.method, "/service/method")); - GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method")); + GPR_ASSERT(0 == + grpc_slice_str_cmp(call_details.host, "foo.test.google.fr:1234")); GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT); - GPR_ASSERT(strcmp(details, - send_limit - ? "Sent message larger than max (11 vs. 5)" - : "Received message larger than max (11 vs. 5)") == 0); + GPR_ASSERT( + grpc_slice_str_cmp( + details, send_limit + ? "Sent message larger than max (11 vs. 5)" + : "Received message larger than max (11 vs. 5)") == 0); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/negative_deadline.c b/test/core/end2end/tests/negative_deadline.c index 929777d39ef..403386b5e75 100644 --- a/test/core/end2end/tests/negative_deadline.c +++ b/test/core/end2end/tests/negative_deadline.c @@ -108,14 +108,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,7 +128,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -155,7 +154,7 @@ static void simple_request_body(grpc_end2end_test_config config, GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/network_status_change.c b/test/core/end2end/tests/network_status_change.c index 2ebda2ccb85..6cfeaa851a2 100644 --- a/test/core/end2end/tests/network_status_change.c +++ b/test/core/end2end/tests/network_status_change.c @@ -119,13 +119,13 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -159,7 +159,6 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -201,7 +200,8 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -214,11 +214,11 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { // Expected behavior of a RPC when network is lost. GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/no_logging.c b/test/core/end2end/tests/no_logging.c index 54614cb0291..5c22631badb 100644 --- a/test/core/end2end/tests/no_logging.c +++ b/test/core/end2end/tests/no_logging.c @@ -139,14 +139,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -179,7 +179,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -210,7 +209,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -227,14 +227,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(0 == call_details.flags); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/payload.c b/test/core/end2end/tests/payload.c index db2e5c83de6..dd989e3ad60 100644 --- a/test/core/end2end/tests/payload.c +++ b/test/core/end2end/tests/payload.c @@ -138,13 +138,13 @@ static void request_response_with_payload(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -183,7 +183,6 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -230,7 +229,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -242,8 +242,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -251,7 +251,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, GPR_ASSERT( byte_buffer_eq_slice(response_payload_recv, response_payload_slice)); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/ping_pong_streaming.c b/test/core/end2end/tests/ping_pong_streaming.c index 0a1566e9c25..b69b7f27a66 100644 --- a/test/core/end2end/tests/ping_pong_streaming.c +++ b/test/core/end2end/tests/ping_pong_streaming.c @@ -112,8 +112,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; grpc_byte_buffer *request_payload; grpc_byte_buffer *request_payload_recv; @@ -126,8 +125,9 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_slice_from_copied_string("hello you"); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,7 +152,6 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -248,7 +247,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -270,7 +270,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); - gpr_free(details); + grpc_slice_unref(details); end_test(&f); config.tear_down_data(&f); diff --git a/test/core/end2end/tests/registered_call.c b/test/core/end2end/tests/registered_call.c index 6594b420b9d..e0716737a3a 100644 --- a/test/core/end2end/tests/registered_call.c +++ b/test/core/end2end/tests/registered_call.c @@ -111,8 +111,7 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_registered_call( @@ -144,7 +143,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -168,7 +166,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -185,13 +184,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c index 9c18e155f32..cd92b484a33 100644 --- a/test/core/end2end/tests/request_with_flags.c +++ b/test/core/end2end/tests/request_with_flags.c @@ -117,13 +117,13 @@ static void test_invoke_request_with_flags( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_call_error expectation; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -157,7 +157,6 @@ static void test_invoke_request_with_flags( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = flags_for_op[op->op]; op->reserved = NULL; op++; @@ -170,7 +169,7 @@ static void test_invoke_request_with_flags( cq_verify(cqv); } - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/request_with_payload.c b/test/core/end2end/tests/request_with_payload.c index c84e3ac5b50..3258c0451b3 100644 --- a/test/core/end2end/tests/request_with_payload.c +++ b/test/core/end2end/tests/request_with_payload.c @@ -116,13 +116,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -156,7 +156,6 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -197,7 +196,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -209,14 +209,14 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c index 7ec33e97a3b..15d7734311d 100644 --- a/test/core/end2end/tests/resource_quota_server.c +++ b/test/core/end2end/tests/resource_quota_server.c @@ -149,8 +149,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_call_details *call_details = malloc(sizeof(grpc_call_details) * NUM_CALLS); grpc_status_code *status = malloc(sizeof(grpc_status_code) * NUM_CALLS); - char **details = malloc(sizeof(char *) * NUM_CALLS); - size_t *details_capacity = malloc(sizeof(size_t) * NUM_CALLS); + grpc_slice *details = malloc(sizeof(char *) * NUM_CALLS); grpc_byte_buffer **request_payload_recv = malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS); int *was_cancelled = malloc(sizeof(int) * NUM_CALLS); @@ -173,8 +172,6 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_init(&trailing_metadata_recv[i]); grpc_metadata_array_init(&request_metadata_recv[i]); grpc_call_details_init(&call_details[i]); - details[i] = NULL; - details_capacity[i] = 0; request_payload_recv[i] = NULL; was_cancelled[i] = 0; } @@ -190,8 +187,10 @@ void resource_quota_server(grpc_end2end_test_config config) { for (int i = 0; i < NUM_CALLS; i++) { client_calls[i] = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - "foo.test.google.fr", n_seconds_time(60), NULL); + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr", config), + n_seconds_time(60), NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -219,8 +218,6 @@ void resource_quota_server(grpc_end2end_test_config config) { &trailing_metadata_recv[i]; op->data.recv_status_on_client.status = &status[i]; op->data.recv_status_on_client.status_details = &details[i]; - op->data.recv_status_on_client.status_details_capacity = - &details_capacity[i]; op->flags = 0; op->reserved = NULL; op++; @@ -260,7 +257,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_destroy(&initial_metadata_recv[call_id]); grpc_metadata_array_destroy(&trailing_metadata_recv[call_id]); grpc_call_destroy(client_calls[call_id]); - gpr_free(details[call_id]); + grpc_slice_unref(details[call_id]); pending_client_calls--; } else if (ev_tag < SERVER_RECV_BASE_TAG) { @@ -317,7 +314,8 @@ void resource_quota_server(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -370,7 +368,6 @@ void resource_quota_server(grpc_end2end_test_config config) { free(call_details); free(status); free(details); - free(details_capacity); free(request_payload_recv); free(was_cancelled); diff --git a/test/core/end2end/tests/server_finishes_request.c b/test/core/end2end/tests/server_finishes_request.c index 3bb25fd9242..ee18c6817b7 100644 --- a/test/core/end2end/tests/server_finishes_request.c +++ b/test/core/end2end/tests/server_finishes_request.c @@ -111,13 +111,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -142,7 +142,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -166,7 +165,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -183,13 +183,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/shutdown_finishes_calls.c b/test/core/end2end/tests/shutdown_finishes_calls.c index b80a2e35f23..0be53153604 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.c +++ b/test/core/end2end/tests/shutdown_finishes_calls.c @@ -100,13 +100,13 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -136,7 +136,6 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -172,12 +171,12 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_server_destroy(f.server); GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_cacheable_request.c b/test/core/end2end/tests/simple_cacheable_request.c index 2c229b08fe9..ea916e7b3a5 100644 --- a/test/core/end2end/tests/simple_cacheable_request.c +++ b/test/core/end2end/tests/simple_cacheable_request.c @@ -111,12 +111,22 @@ static void test_cacheable_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = { - {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = { - {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), + grpc_slice_from_static_string("val1"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key2"), + grpc_slice_from_static_string("val2"), + 0, + {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), + grpc_slice_from_static_string("val3"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key4"), + grpc_slice_from_static_string("val4"), + 0, + {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_cacheable_request_response_with_metadata_and_payload", NULL, NULL); @@ -131,13 +141,13 @@ static void test_cacheable_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -177,7 +187,6 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -225,7 +234,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -237,8 +247,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); if (config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) { @@ -254,7 +264,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3")); GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c index ec40c8f22db..83ad8515df6 100644 --- a/test/core/end2end/tests/simple_delayed_request.c +++ b/test/core/end2end/tests/simple_delayed_request.c @@ -100,15 +100,15 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; config.init_client(f, client_args); c = grpc_channel_create_call( - f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -137,7 +137,6 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -163,7 +162,8 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -180,13 +180,13 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_metadata.c b/test/core/end2end/tests/simple_metadata.c index 5490cc2b75f..162c89c6180 100644 --- a/test/core/end2end/tests/simple_metadata.c +++ b/test/core/end2end/tests/simple_metadata.c @@ -109,12 +109,22 @@ static void test_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = { - {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = { - {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), + grpc_slice_from_static_string("val1"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key2"), + grpc_slice_from_static_string("val2"), + 0, + {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), + grpc_slice_from_static_string("val3"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key4"), + grpc_slice_from_static_string("val4"), + 0, + {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_request_response_with_metadata_and_payload", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -128,13 +138,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -174,7 +184,6 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -222,7 +231,8 @@ static void test_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -234,8 +244,8 @@ static void test_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -246,7 +256,7 @@ static void test_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3")); GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index 2dea5d6af2e..e0a69826c4c 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -111,14 +111,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,7 +152,6 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -185,7 +184,8 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -202,14 +202,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(0 == call_details.flags); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/streaming_error_response.c b/test/core/end2end/tests/streaming_error_response.c index 583bc9268f4..05012523a73 100644 --- a/test/core/end2end/tests/streaming_error_response.c +++ b/test/core/end2end/tests/streaming_error_response.c @@ -121,13 +121,13 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -154,7 +154,6 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; } error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); @@ -202,7 +201,8 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_FAILED_PRECONDITION; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op++; error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); GPR_ASSERT(GRPC_CALL_OK == error); @@ -232,7 +232,6 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); @@ -245,13 +244,13 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { } GPR_ASSERT(status == GRPC_STATUS_FAILED_PRECONDITION); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/trailing_metadata.c b/test/core/end2end/tests/trailing_metadata.c index 9fd4fbc052f..b6741dbf3d0 100644 --- a/test/core/end2end/tests/trailing_metadata.c +++ b/test/core/end2end/tests/trailing_metadata.c @@ -109,15 +109,30 @@ static void test_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = { - {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = { - {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_t[2] = { - {"key5", "val5", 4, 0, {{NULL, NULL, NULL, NULL}}}, - {"key6", "val6", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), + grpc_slice_from_static_string("val1"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key2"), + grpc_slice_from_static_string("val2"), + 0, + {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), + grpc_slice_from_static_string("val3"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key4"), + grpc_slice_from_static_string("val4"), + 0, + {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_t[2] = {{grpc_slice_from_static_string("key5"), + grpc_slice_from_static_string("val5"), + 0, + {{NULL, NULL, NULL, NULL}}}, + {grpc_slice_from_static_string("key6"), + grpc_slice_from_static_string("val6"), + 0, + {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_request_response_with_metadata_and_payload", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -131,13 +146,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -177,7 +192,6 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -226,7 +240,8 @@ static void test_request_response_with_metadata_and_payload( op->data.send_status_from_server.trailing_metadata_count = 2; op->data.send_status_from_server.trailing_metadata = meta_t; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -238,8 +253,8 @@ static void test_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); @@ -251,7 +266,7 @@ static void test_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key5", "val5")); GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key6", "val6")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); From 8cfe059dbc82bcfbd35647654a869369978b052e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 14 Nov 2016 16:31:29 -0800 Subject: [PATCH 016/261] Progress towards mdstr elimination --- .../transport/chttp2/transport/bin_encoder.c | 3 +- .../transport/chttp2/transport/bin_encoder.h | 3 +- .../chttp2/transport/chttp2_plugin.c | 1 - .../chttp2/transport/chttp2_transport.c | 14 ++- .../chttp2/transport/hpack_encoder.c | 93 ++++++++++++------- .../transport/chttp2/transport/hpack_parser.c | 60 ++++++------ .../transport/chttp2/transport/hpack_table.c | 23 +++-- 7 files changed, 110 insertions(+), 87 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.c b/src/core/ext/transport/chttp2/transport/bin_encoder.c index af25a4352ac..e301c073f37 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.c +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.c @@ -177,8 +177,7 @@ static void enc_add1(huff_out *out, uint8_t a) { enc_flush_some(out); } -grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl( - grpc_slice input) { +grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { size_t input_length = GRPC_SLICE_LENGTH(input); size_t input_triplets = input_length / 3; size_t tail_case = input_length % 3; diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.h b/src/core/ext/transport/chttp2/transport/bin_encoder.h index 477559d0e25..0f899c8e343 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.h @@ -49,7 +49,6 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input); grpc_slice y = grpc_chttp2_huffman_compress(x); grpc_slice_unref_internal(exec_ctx, x); return y; */ -grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl( - grpc_slice input); +grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_ENCODER_H */ diff --git a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c index ade574092f7..59b21e3330d 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c @@ -31,7 +31,6 @@ * */ -#include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/metadata.h" diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 96d916e414a..21838167e9c 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -876,7 +876,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, static bool contains_non_ok_status(grpc_metadata_batch *batch) { grpc_linked_mdelem *l; for (l = batch->list.head; l; l = l->next) { - if (l->md->key == GRPC_MDSTR_GRPC_STATUS && + if (grpc_slice_cmp(l->md->key, GRPC_MDSTR_GRPC_STATUS) == 0 && l->md != GRPC_MDELEM_GRPC_STATUS_0) { return true; } @@ -1477,16 +1477,14 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, char status_string[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(status, status_string); grpc_chttp2_incoming_metadata_buffer_add( - &s->metadata_buffer[1], grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_GRPC_STATUS, - grpc_mdstr_from_string(status_string))); + &s->metadata_buffer[1], + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, + grpc_slice_from_copied_string(status_string))); if (slice) { grpc_chttp2_incoming_metadata_buffer_add( &s->metadata_buffer[1], - grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_mdstr_from_slice(exec_ctx, - grpc_slice_ref_internal(*slice)))); + grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_slice_ref_internal(*slice))); } s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 49a8326f627..9b27071c871 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -64,6 +64,10 @@ /* don't consider adding anything bigger than this to the hpack table */ #define MAX_DECODER_SPACE_USAGE 512 +static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; +static const grpc_slice terminal_slice = {&terminal_slice_refcount, + .data.refcounted = {0, 0}}; + extern int grpc_http_trace; typedef struct { @@ -186,8 +190,9 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { /* add an element to the decoder table */ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem) { - uint32_t key_hash = elem->key->hash; - uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); + uint32_t key_hash = grpc_slice_hash(elem->key); + uint32_t value_hash = grpc_slice_hash(elem->value); + uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); uint32_t new_index = c->tail_remote_index + c->table_elems + 1; size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); @@ -241,24 +246,34 @@ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* do exactly the same for the key (so we can find by that again too) */ - if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key) { + if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_2(key_hash)], elem->key) == + 0) { c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key) { + } else if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_3(key_hash)], + elem->key) == 0) { c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == NULL) { - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); + } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)].refcount == + &terminal_slice_refcount) { + c->entries_keys[HASH_FRAGMENT_2(key_hash)] = + grpc_slice_ref_internal(elem->key); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == NULL) { - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); + } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)].refcount == + &terminal_slice_refcount) { + c->entries_keys[HASH_FRAGMENT_3(key_hash)] = + grpc_slice_ref_internal(elem->key); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { - GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_2(key_hash)]); - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); + grpc_slice_unref_internal(exec_ctx, + c->entries_keys[HASH_FRAGMENT_2(key_hash)]); + c->entries_keys[HASH_FRAGMENT_2(key_hash)] = + grpc_slice_ref_internal(elem->key); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; } else { - GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_3(key_hash)]); - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); + grpc_slice_unref_internal(exec_ctx, + c->entries_keys[HASH_FRAGMENT_3(key_hash)]); + c->entries_keys[HASH_FRAGMENT_3(key_hash)] = + grpc_slice_ref_internal(elem->key); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } } @@ -271,15 +286,13 @@ static void emit_indexed(grpc_chttp2_hpack_compressor *c, uint32_t elem_index, } static grpc_slice get_wire_value(grpc_mdelem *elem, uint8_t *huffman_prefix) { - if (grpc_is_binary_header( - (const char *)GRPC_SLICE_START_PTR(elem->key->slice), - GRPC_SLICE_LENGTH(elem->key->slice))) { + if (grpc_slice_is_binary_header(elem->key)) { *huffman_prefix = 0x80; - return grpc_mdstr_as_base64_encoded_and_huffman_compressed(elem->value); + return grpc_chttp2_base64_encode_and_huffman_compress(elem->value); } /* TODO(ctiller): opportunistically compress non-binary headers */ *huffman_prefix = 0x00; - return elem->value->slice; + return grpc_slice_ref(elem->value); } static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, @@ -296,7 +309,7 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, grpc_slice_ref_internal(value_slice)); + add_header_data(st, value_slice); } static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, @@ -313,12 +326,12 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, grpc_slice_ref_internal(value_slice)); + add_header_data(st, value_slice); } static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key->slice); + uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice); @@ -329,15 +342,15 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, *add_tiny_header_data(st, 1) = 0x40; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, grpc_slice_ref_internal(elem->key->slice)); + add_header_data(st, grpc_slice_ref_internal(elem->key)); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, grpc_slice_ref_internal(value_slice)); + add_header_data(st, value_slice); } static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key->slice); + uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice); @@ -348,10 +361,10 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, *add_tiny_header_data(st, 1) = 0x00; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, grpc_slice_ref_internal(elem->key->slice)); + add_header_data(st, grpc_slice_ref_internal(elem->key)); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, grpc_slice_ref_internal(value_slice)); + add_header_data(st, value_slice); } static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c, @@ -370,14 +383,15 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) { /* encode an mdelem */ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, grpc_mdelem *elem, framer_state *st) { - uint32_t key_hash = elem->key->hash; - uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); + uint32_t key_hash = grpc_slice_hash(elem->key); + uint32_t value_hash = grpc_slice_hash(elem->value); + uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); size_t decoder_space_usage; uint32_t indices_key; int should_add_elem; - GPR_ASSERT(GRPC_SLICE_LENGTH(elem->key->slice) > 0); - if (GRPC_SLICE_START_PTR(elem->key->slice)[0] != ':') { /* regular header */ + GPR_ASSERT(GRPC_SLICE_LENGTH(elem->key) > 0); + if (GRPC_SLICE_START_PTR(elem->key)[0] != ':') { /* regular header */ st->seen_regular_header = 1; } else { GPR_ASSERT( @@ -414,7 +428,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* no hits for the elem... maybe there's a key? */ indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)]; - if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key && + if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_2(key_hash)], elem->key) == + 0 && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { @@ -429,7 +444,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, } indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)]; - if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key && + if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_3(key_hash)], elem->key) == + 0 && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { @@ -466,8 +482,8 @@ static void deadline_enc(grpc_exec_ctx *exec_ctx, grpc_mdelem *mdelem; grpc_http2_encode_timeout( gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); - mdelem = grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, grpc_mdstr_from_string(timeout_str)); + mdelem = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, + grpc_slice_from_copied_string(timeout_str)); hpack_enc(exec_ctx, c, mdelem, st); GRPC_MDELEM_UNREF(exec_ctx, mdelem); } @@ -484,14 +500,21 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c) { gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems); memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); + for (size_t i = 0; i < GPR_ARRAY_SIZE(c->entries_keys); i++) { + c->entries_keys[i] = terminal_slice; + } } void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c) { int i; for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { - if (c->entries_keys[i]) GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[i]); - if (c->entries_elems[i]) GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); + if (c->entries_keys[i].refcount != &terminal_slice_refcount) { + grpc_slice_unref_internal(exec_ctx, c->entries_keys[i]); + } + if (c->entries_elems[i]) { + GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); + } } gpr_free(c->table_elem_size); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 3bb82fd29d2..86c65d4b5ae 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -52,6 +52,7 @@ #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" extern int grpc_http_trace; @@ -682,8 +683,8 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, } static grpc_slice take_string(grpc_chttp2_hpack_parser *p, - grpc_chttp2_hpack_parser_string *str) { - grpc_slice s = grpc_mdstr_from_buffer((uint8_t *)str->str, str->length); + grpc_chttp2_hpack_parser_string *str) { + grpc_slice s = grpc_slice_from_copied_buffer(str->str, str->length); str->length = 0; return s; } @@ -815,10 +816,11 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, const uint8_t *end) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 1); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(md->key), + take_string(p, &p->value)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -828,10 +830,10 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 1); + grpc_error *err = on_hdr( + exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -883,10 +885,11 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, const uint8_t *end) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 0); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(md->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -896,10 +899,10 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 0); + grpc_error *err = on_hdr( + exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -951,10 +954,11 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, const uint8_t *end) { grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_REF(md->key), - take_string(p, &p->value)), - 0); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(md->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -964,10 +968,10 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( - exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 0); + grpc_error *err = on_hdr( + exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -1502,9 +1506,7 @@ static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, GRPC_ERROR_INT_INDEX, (intptr_t)p->index), GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); } - *is = grpc_is_binary_header( - (const char *)GRPC_SLICE_START_PTR(elem->key->slice), - GRPC_SLICE_LENGTH(elem->key->slice)); + *is = grpc_slice_is_binary_header(elem->key); return GRPC_ERROR_NONE; } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.c b/src/core/ext/transport/chttp2/transport/hpack_table.c index 26d4036d49f..9124e37c455 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.c +++ b/src/core/ext/transport/chttp2/transport/hpack_table.c @@ -190,8 +190,11 @@ void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - tbl->static_ents[i - 1] = grpc_mdelem_from_strings( - exec_ctx, static_table[i].key, static_table[i].value); + tbl->static_ents[i - 1] = grpc_mdelem_from_slices( + exec_ctx, + grpc_slice_intern(grpc_slice_from_static_string(static_table[i].key)), + grpc_slice_intern( + grpc_slice_from_static_string(static_table[i].value))); } } @@ -228,8 +231,8 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, /* Evict one element from the table */ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; - size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key->slice) + - GRPC_SLICE_LENGTH(first_ent->value->slice) + + size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key) + + GRPC_SLICE_LENGTH(first_ent->value) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GPR_ASSERT(elem_bytes <= tbl->mem_used); tbl->mem_used -= (uint32_t)elem_bytes; @@ -303,8 +306,8 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { /* determine how many bytes of buffer this entry represents */ - size_t elem_bytes = GRPC_SLICE_LENGTH(md->key->slice) + - GRPC_SLICE_LENGTH(md->value->slice) + + size_t elem_bytes = GRPC_SLICE_LENGTH(md->key) + + GRPC_SLICE_LENGTH(md->value) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; if (tbl->current_table_bytes > tbl->max_bytes) { @@ -359,9 +362,9 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { grpc_mdelem *ent = tbl->static_ents[i]; - if (md->key != ent->key) continue; + if (grpc_slice_cmp(md->key, ent->key) != 0) continue; r.index = i + 1u; - r.has_value = md->value == ent->value; + r.has_value = grpc_slice_cmp(md->value, ent->value) == 0; if (r.has_value) return r; } @@ -370,9 +373,9 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( uint32_t idx = (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; - if (md->key != ent->key) continue; + if (grpc_slice_cmp(md->key, ent->key) != 0) continue; r.index = idx; - r.has_value = md->value == ent->value; + r.has_value = grpc_slice_cmp(md->value, ent->value) == 0; if (r.has_value) return r; } From 3468fe1a767a19e596e9c3a2f62f18b412b51e5f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 16 Nov 2016 16:27:16 -0800 Subject: [PATCH 017/261] Progress towards mdstr elimination --- .../ext/transport/chttp2/transport/parsing.c | 39 +++++++++++----- .../credentials/plugin/plugin_credentials.c | 17 +++---- .../security/transport/client_auth_filter.c | 45 ++++++++++++------- src/core/lib/transport/timeout_encoding.c | 13 +++--- src/core/lib/transport/timeout_encoding.h | 3 +- 5 files changed, 75 insertions(+), 42 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index b8ab9871049..edb9104fe8f 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -42,6 +42,7 @@ #include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/timeout_encoding.h" @@ -451,24 +452,32 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); - GRPC_CHTTP2_IF_TRACING(gpr_log( - GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", - grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value))); + if (grpc_http_trace) { + char *key = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, + t->is_client ? "CLI" : "SVR", key, value); + gpr_free(key); + gpr_free(value); + } - if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) { + if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_STATUS) == 0 && + md != GRPC_MDELEM_GRPC_STATUS_0) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; } - if (md->key == GRPC_MDSTR_GRPC_TIMEOUT) { + if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_TIMEOUT) == 0) { gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout); if (!cached_timeout) { /* not already parsed: parse it now, and store the result away */ cached_timeout = gpr_malloc(sizeof(gpr_timespec)); - if (!grpc_http2_decode_timeout(grpc_mdstr_as_c_string(md->value), + if (!grpc_http2_decode_timeout(GRPC_SLICE_START_PTR(md->value), + GRPC_SLICE_LENGTH(md->value), cached_timeout)) { - gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", - grpc_mdstr_as_c_string(md->value)); + char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); + gpr_free(val); *cached_timeout = gpr_inf_future(GPR_TIMESPAN); } cached_timeout = @@ -513,11 +522,17 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); - GRPC_CHTTP2_IF_TRACING(gpr_log( - GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", - grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value))); + if (grpc_http_trace) { + char *key = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, + t->is_client ? "CLI" : "SVR", key, value); + gpr_free(key); + gpr_free(value); + } - if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) { + if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_STATUS) == 0 && + md != GRPC_MDELEM_GRPC_STATUS_0) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; } diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index f90d7dce83f..4fc02b2659b 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -42,6 +42,7 @@ #include #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/api_trace.h" typedef struct { @@ -77,13 +78,14 @@ static void plugin_md_request_metadata_ready(void *request, bool seen_illegal_header = false; grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md[i].key, strlen(md[i].key))) { - gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", md[i].key); + if (!grpc_header_key_slice_is_legal(md[i].key)) { + char *key = grpc_dump_slice(md[i].key, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", key); + gpr_free(key); seen_illegal_header = true; break; - } else if (!grpc_is_binary_header(md[i].key, strlen(md[i].key)) && - !grpc_header_nonbin_value_is_legal(md[i].value, - md[i].value_length)) { + } else if (!grpc_slice_is_binary_header(md[i].key) && + !grpc_header_nonbin_value_slice_is_legal(md[i].value)) { gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); seen_illegal_header = true; break; @@ -95,9 +97,8 @@ static void plugin_md_request_metadata_ready(void *request, } else if (num_md > 0) { md_array = gpr_malloc(num_md * sizeof(grpc_credentials_md)); for (i = 0; i < num_md; i++) { - md_array[i].key = grpc_slice_from_copied_string(md[i].key); - md_array[i].value = - grpc_slice_from_copied_buffer(md[i].value, md[i].value_length); + md_array[i].key = grpc_slice_ref(md[i].key); + md_array[i].value = grpc_slice_ref(md[i].value); } r->cb(&exec_ctx, r->user_data, md_array, num_md, GRPC_CREDENTIALS_OK, NULL); diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index e9e77182b61..6fc73734bca 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -45,6 +45,7 @@ #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/transport/static_metadata.h" @@ -54,6 +55,8 @@ /* We can have a per-call credentials. */ typedef struct { grpc_call_credentials *creds; + bool have_host; + bool have_method; grpc_slice host; grpc_slice method; /* pollset{_set} bound to this call; if we need to make external @@ -133,7 +136,7 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, void build_auth_metadata_context(grpc_security_connector *sc, grpc_auth_context *auth_context, call_data *calld) { - char *service = gpr_strdup(grpc_mdstr_as_c_string(calld->method)); + char *service = grpc_dump_slice(calld->method, GPR_DUMP_ASCII); char *last_slash = strrchr(service, '/'); char *method_name = NULL; char *service_url = NULL; @@ -149,14 +152,15 @@ void build_auth_metadata_context(grpc_security_connector *sc, method_name = gpr_strdup(last_slash + 1); } if (method_name == NULL) method_name = gpr_strdup(""); + char *host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); gpr_asprintf(&service_url, "%s://%s%s", - sc->url_scheme == NULL ? "" : sc->url_scheme, - grpc_mdstr_as_c_string(calld->host), service); + sc->url_scheme == NULL ? "" : sc->url_scheme, host, service); calld->auth_md_context.service_url = service_url; calld->auth_md_context.method_name = method_name; calld->auth_md_context.channel_auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "grpc_auth_metadata_context"); gpr_free(service); + gpr_free(host); } static void send_security_metadata(grpc_exec_ctx *exec_ctx, @@ -207,8 +211,10 @@ static void on_host_checked(grpc_exec_ctx *exec_ctx, void *user_data, send_security_metadata(exec_ctx, elem, &calld->op); } else { char *error_msg; + char *host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); gpr_asprintf(&error_msg, "Invalid host %s set in :authority metadata.", - grpc_mdstr_as_c_string(calld->host)); + host); + gpr_free(host); bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, error_msg); gpr_free(error_msg); } @@ -250,20 +256,27 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx, grpc_mdelem *md = l->md; /* Pointer comparison is OK for md_elems created from the same context. */ - if (md->key == GRPC_MDSTR_AUTHORITY) { - if (calld->host != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->host); - calld->host = GRPC_MDSTR_REF(md->value); - } else if (md->key == GRPC_MDSTR_PATH) { - if (calld->method != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->method); - calld->method = GRPC_MDSTR_REF(md->value); + if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { + if (calld->have_host) { + grpc_slice_unref_internal(exec_ctx, calld->host); + } + calld->host = grpc_slice_ref_internal(md->value); + calld->have_host = true; + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + if (calld->have_method) { + grpc_slice_unref_internal(exec_ctx, calld->method); + } + calld->method = grpc_slice_ref_internal(md->value); + calld->have_method = true; } } - if (calld->host != NULL) { - const char *call_host = grpc_mdstr_as_c_string(calld->host); + if (calld->have_host) { + char *call_host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); calld->op = *op; /* Copy op (originates from the caller's stack). */ grpc_channel_security_connector_check_call_host( exec_ctx, chand->security_connector, call_host, chand->auth_context, on_host_checked, elem); + gpr_free(call_host); GPR_TIMER_END("auth_start_transport_op", 0); return; /* early exit */ } @@ -296,11 +309,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, void *ignored) { call_data *calld = elem->call_data; grpc_call_credentials_unref(exec_ctx, calld->creds); - if (calld->host != NULL) { - GRPC_MDSTR_UNREF(exec_ctx, calld->host); + if (calld->have_host) { + grpc_slice_unref_internal(exec_ctx, calld->host); } - if (calld->method != NULL) { - GRPC_MDSTR_UNREF(exec_ctx, calld->method); + if (calld->have_method) { + grpc_slice_unref_internal(exec_ctx, calld->method); } reset_auth_metadata_context(&calld->auth_md_context); } diff --git a/src/core/lib/transport/timeout_encoding.c b/src/core/lib/transport/timeout_encoding.c index b58ebbd0a8f..b2060be59e5 100644 --- a/src/core/lib/transport/timeout_encoding.c +++ b/src/core/lib/transport/timeout_encoding.c @@ -136,15 +136,17 @@ static int is_all_whitespace(const char *p) { return *p == 0; } -int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) { +int grpc_http2_decode_timeout(const uint8_t *buffer, size_t length, + gpr_timespec *timeout) { int32_t x = 0; - const uint8_t *p = (const uint8_t *)buffer; + const uint8_t *p = buffer; + const uint8_t *end = p + length; int have_digit = 0; /* skip whitespace */ - for (; *p == ' '; p++) + for (; p != end && *p == ' '; p++) ; /* decode numeric part */ - for (; *p >= '0' && *p <= '9'; p++) { + for (; p != end && *p >= '0' && *p <= '9'; p++) { int32_t digit = (int32_t)(*p - (uint8_t)'0'); have_digit = 1; /* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */ @@ -158,8 +160,9 @@ int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) { } if (!have_digit) return 0; /* skip whitespace */ - for (; *p == ' '; p++) + for (; p != end && *p == ' '; p++) ; + if (p == end) return 0; /* decode unit specifier */ switch (*p) { case 'n': diff --git a/src/core/lib/transport/timeout_encoding.h b/src/core/lib/transport/timeout_encoding.h index 92f02f6ecd1..838892595f0 100644 --- a/src/core/lib/transport/timeout_encoding.h +++ b/src/core/lib/transport/timeout_encoding.h @@ -42,6 +42,7 @@ /* Encode/decode timeouts to the GRPC over HTTP/2 format; encoding may round up arbitrarily */ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer); -int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout); +int grpc_http2_decode_timeout(const uint8_t *buffer, size_t length, + gpr_timespec *timeout); #endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */ From d7f15831c6a4dcd71fe10babde7bb0b380fb1eff Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 16 Nov 2016 17:12:55 -0800 Subject: [PATCH 018/261] Tests are starting to compile --- src/core/ext/census/grpc_filter.c | 4 +- src/core/ext/client_channel/client_channel.c | 5 +- src/core/ext/lb_policy/grpclb/grpclb.c | 35 +++--- .../load_reporting/load_reporting_filter.c | 31 +++--- .../security/transport/server_auth_filter.c | 28 ++--- src/core/lib/transport/static_metadata.c | 100 ++++++++++-------- src/core/lib/transport/static_metadata.h | 25 +++-- test/core/end2end/fuzzers/hpack.dictionary | 1 + tools/codegen/core/gen_static_metadata.py | 48 ++++++--- tools/codegen/core/perfect/build.sh | 4 + tools/codegen/core/perfect/run.sh | 3 +- 11 files changed, 154 insertions(+), 130 deletions(-) create mode 100755 tools/codegen/core/perfect/build.sh diff --git a/src/core/ext/census/grpc_filter.c b/src/core/ext/census/grpc_filter.c index 397dbc40a87..5008879512c 100644 --- a/src/core/ext/census/grpc_filter.c +++ b/src/core/ext/census/grpc_filter.c @@ -67,9 +67,7 @@ static void extract_and_annotate_method_tag(grpc_metadata_batch *md, channel_data *chand) { grpc_linked_mdelem *m; for (m = md->list.head; m != NULL; m = m->next) { - if (m->md->key == GRPC_MDSTR_PATH) { - gpr_log(GPR_DEBUG, "%s", - (const char *)GRPC_SLICE_START_PTR(m->md->value->slice)); + if (grpc_slice_cmp(m->md->key, GRPC_MDSTR_PATH) == 0) { /* Add method tag here */ } } diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 011a8411aae..5faad33a1d1 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -51,6 +51,7 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/connectivity_state.h" @@ -972,7 +973,7 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, call_data *calld = elem->call_data; // Initialize data members. grpc_deadline_state_init(exec_ctx, elem, args->call_stack); - calld->path = GRPC_MDSTR_REF(args->path); + calld->path = grpc_slice_ref_internal(args->path); calld->call_start_time = args->start_time; calld->deadline = gpr_convert_clock_type(args->deadline, GPR_CLOCK_MONOTONIC); calld->wait_for_ready_from_service_config = WAIT_FOR_READY_UNSET; @@ -1041,7 +1042,7 @@ static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, void *and_free_memory) { call_data *calld = elem->call_data; grpc_deadline_state_destroy(exec_ctx, elem); - GRPC_MDSTR_UNREF(exec_ctx, calld->path); + grpc_slice_unref_internal(exec_ctx, calld->path); GRPC_ERROR_UNREF(calld->cancel_error); grpc_subchannel_call *call = GET_CALL(calld); if (call != NULL && call != CANCELLED_CALL) { diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 3e5c039fdd4..1a673e95aff 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -333,8 +333,7 @@ typedef struct glb_lb_policy { /* call status code and details, set in lb_on_server_status_received() */ grpc_status_code lb_call_status; - char *lb_call_status_details; - size_t lb_call_status_details_capacity; + grpc_slice lb_call_status_details; /** LB call retry backoff state */ gpr_backoff lb_call_backoff_state; @@ -447,10 +446,10 @@ static grpc_lb_addresses *process_serverlist( GPR_ARRAY_SIZE(server->load_balance_token); const size_t lb_token_length = strnlen(server->load_balance_token, lb_token_max_length); - grpc_slice lb_token_mdstr = grpc_mdstr_from_buffer( - (uint8_t *)server->load_balance_token, lb_token_length); - user_data = grpc_mdelem_from_metadata_strings( - exec_ctx, GRPC_MDSTR_LB_TOKEN, lb_token_mdstr); + grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( + server->load_balance_token, lb_token_length); + user_data = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, + lb_token_mdstr); } else { gpr_log(GPR_ERROR, "Missing LB token for backend address '%s'. The empty token will " @@ -972,11 +971,12 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, /* Note the following LB call progresses every time there's activity in \a * glb_policy->base.interested_parties, which is comprised of the polling * entities from \a client_channel. */ + grpc_slice host = grpc_slice_from_copied_string(glb_policy->server_name); glb_policy->lb_call = grpc_channel_create_pollset_set_call( exec_ctx, glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, - "/grpc.lb.v1.LoadBalancer/BalanceLoad", glb_policy->server_name, - glb_policy->deadline, NULL); + GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, + &host, glb_policy->deadline, NULL); grpc_metadata_array_init(&glb_policy->lb_initial_metadata_recv); grpc_metadata_array_init(&glb_policy->lb_trailing_metadata_recv); @@ -989,9 +989,6 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, grpc_slice_unref_internal(exec_ctx, request_payload_slice); grpc_grpclb_request_destroy(request); - glb_policy->lb_call_status_details = NULL; - glb_policy->lb_call_status_details_capacity = 0; - grpc_closure_init(&glb_policy->lb_on_server_status_received, lb_on_server_status_received, glb_policy); grpc_closure_init(&glb_policy->lb_on_response_received, @@ -1002,7 +999,8 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, BACKOFF_MAX_SECONDS * 1000); } -static void lb_call_destroy_locked(glb_lb_policy *glb_policy) { +static void lb_call_destroy_locked(grpc_exec_ctx *exec_ctx, + glb_lb_policy *glb_policy) { GPR_ASSERT(glb_policy->lb_call != NULL); grpc_call_destroy(glb_policy->lb_call); glb_policy->lb_call = NULL; @@ -1011,7 +1009,7 @@ static void lb_call_destroy_locked(glb_lb_policy *glb_policy) { grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); grpc_byte_buffer_destroy(glb_policy->lb_request_payload); - gpr_free(glb_policy->lb_call_status_details); + grpc_slice_unref_internal(exec_ctx, glb_policy->lb_call_status_details); } /* @@ -1060,8 +1058,6 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, op->data.recv_status_on_client.status = &glb_policy->lb_call_status; op->data.recv_status_on_client.status_details = &glb_policy->lb_call_status_details; - op->data.recv_status_on_client.status_details_capacity = - &glb_policy->lb_call_status_details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -1201,15 +1197,18 @@ static void lb_on_server_status_received(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(glb_policy->lb_call != NULL); if (grpc_lb_glb_trace) { + char *status_details = + grpc_dump_slice(glb_policy->lb_call_status_details, GPR_DUMP_ASCII); gpr_log(GPR_DEBUG, "Status from LB server received. Status = %d, Details = '%s', " "(call: %p)", - glb_policy->lb_call_status, glb_policy->lb_call_status_details, + glb_policy->lb_call_status, status_details, (void *)glb_policy->lb_call); + gpr_free(status_details); } - /* We need to performe cleanups no matter what. */ - lb_call_destroy_locked(glb_policy); + /* We need to perform cleanups no matter what. */ + lb_call_destroy_locked(exec_ctx, glb_policy); if (!glb_policy->shutting_down) { /* if we aren't shutting down, restart the LB client call after some time */ diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index f50e6520cd2..c152e3d3b8c 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -41,13 +41,17 @@ #include "src/core/ext/load_reporting/load_reporting_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/static_metadata.h" typedef struct call_data { intptr_t id; /**< an id unique to the call */ - char *trailing_md_string; - char *initial_md_string; - const char *service_method; + bool have_trailing_md_string; + grpc_slice trailing_md_string; + bool have_initial_md_string; + grpc_slice initial_md_string; + bool have_service_method; + grpc_slice service_method; /* stores the recv_initial_metadata op's ready closure, which we wrap with our * own (on_initial_md_ready) in order to capture the incoming initial metadata @@ -74,10 +78,12 @@ static grpc_mdelem *recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element *elem = a->elem; call_data *calld = elem->call_data; - if (md->key == GRPC_MDSTR_PATH) { - calld->service_method = grpc_mdstr_as_c_string(md->value); - } else if (md->key == GRPC_MDSTR_LB_TOKEN) { - calld->initial_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); + if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + calld->service_method = grpc_slice_ref_internal(md->value); + calld->have_service_method = true; + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_LB_TOKEN) == 0) { + calld->initial_md_string = grpc_slice_ref_internal(md->value); + calld->have_initial_md_string = true; return NULL; } @@ -95,7 +101,7 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, a.exec_ctx = exec_ctx; grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, recv_md_filter, &a); - if (calld->service_method == NULL) { + if (!calld->have_service_method) { err = grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header")); } @@ -148,8 +154,8 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, calld->service_method}; */ - gpr_free(calld->initial_md_string); - gpr_free(calld->trailing_md_string); + grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); + grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); } /* Constructor for channel_data */ @@ -195,8 +201,9 @@ static grpc_mdelem *lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (md->key == GRPC_MDSTR_LB_COST_BIN) { - calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); + if (grpc_slice_cmp(md->key, GRPC_MDSTR_LB_COST_BIN) == 0) { + calld->trailing_md_string = grpc_slice_ref_internal(md->value); + calld->have_trailing_md_string = true; return NULL; } diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index db0d0d69079..1824cf37b60 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -33,12 +33,13 @@ #include +#include +#include + #include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/transport/auth_filters.h" - -#include -#include +#include "src/core/lib/slice/slice_internal.h" typedef struct call_data { grpc_metadata_batch *recv_initial_metadata; @@ -76,9 +77,8 @@ static grpc_metadata_array metadata_batch_to_md_array( gpr_realloc(result.metadata, result.capacity * sizeof(grpc_metadata)); } usr_md = &result.metadata[result.count++]; - usr_md->key = grpc_mdstr_as_c_string(key); - usr_md->value = grpc_mdstr_as_c_string(value); - usr_md->value_length = GRPC_SLICE_LENGTH(value->slice); + usr_md->key = grpc_slice_ref_internal(key); + usr_md->value = grpc_slice_ref_internal(value); } return result; } @@ -90,19 +90,9 @@ static grpc_mdelem *remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, size_t i; for (i = 0; i < calld->num_consumed_md; i++) { const grpc_metadata *consumed_md = &calld->consumed_md[i]; - /* Maybe we could do a pointer comparison but we do not have any guarantee - that the metadata processor used the same pointers for consumed_md in the - callback. */ - if (GRPC_SLICE_LENGTH(md->key->slice) != strlen(consumed_md->key) || - GRPC_SLICE_LENGTH(md->value->slice) != consumed_md->value_length) { - continue; - } - if (memcmp(GRPC_SLICE_START_PTR(md->key->slice), consumed_md->key, - GRPC_SLICE_LENGTH(md->key->slice)) == 0 && - memcmp(GRPC_SLICE_START_PTR(md->value->slice), consumed_md->value, - GRPC_SLICE_LENGTH(md->value->slice)) == 0) { - return NULL; /* Delete. */ - } + if (grpc_slice_cmp(md->key, consumed_md->key) == 0 && + grpc_slice_cmp(md->value, consumed_md->value) == 0) + return NULL; } return md; } diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index e24f3fa55e2..0eb5cd5d740 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -101,14 +101,16 @@ static uint8_t g_raw_bytes[] = { 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 58, 115, 99, 104, 101, 109, 101, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, - 99, 111, 111, 107, 105, 101, 47, 47, 105, 110, 100, 101, 120, 46, 104, - 116, 109, 108, 58, 115, 116, 97, 116, 117, 115, 115, 116, 114, 105, 99, - 116, 45, 116, 114, 97, 110, 115, 112, 111, 114, 116, 45, 115, 101, 99, - 117, 114, 105, 116, 121, 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, - 116, 114, 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, - 110, 103, 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 118, 97, 114, - 121, 118, 105, 97, 119, 119, 119, 45, 97, 117, 116, 104, 101, 110, 116, - 105, 99, 97, 116, 101}; + 99, 111, 111, 107, 105, 101, 47, 47, 103, 114, 112, 99, 46, 108, 98, + 46, 118, 49, 46, 76, 111, 97, 100, 66, 97, 108, 97, 110, 99, 101, + 114, 47, 66, 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 47, 105, + 110, 100, 101, 120, 46, 104, 116, 109, 108, 58, 115, 116, 97, 116, 117, + 115, 115, 116, 114, 105, 99, 116, 45, 116, 114, 97, 110, 115, 112, 111, + 114, 116, 45, 115, 101, 99, 117, 114, 105, 116, 121, 116, 101, 116, 114, + 97, 105, 108, 101, 114, 115, 116, 114, 97, 110, 115, 102, 101, 114, 45, + 101, 110, 99, 111, 100, 105, 110, 103, 117, 115, 101, 114, 45, 97, 103, + 101, 110, 116, 118, 97, 114, 121, 118, 105, 97, 119, 119, 119, 45, 97, + 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101}; static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} @@ -116,7 +118,7 @@ static grpc_slice_refcount g_refcnt = {static_ref, static_unref}; bool grpc_is_static_metadata_string(grpc_slice slice) { return slice.refcount != NULL && slice.refcount->ref == static_ref; -}; +} const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { {.refcount = &g_refcnt, @@ -294,25 +296,27 @@ const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { {.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes + 891, .length = 1}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 892, .length = 11}}, + .data.refcounted = {.bytes = g_raw_bytes + 892, .length = 36}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 928, .length = 11}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 903, .length = 7}}, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 910, .length = 25}}, + .data.refcounted = {.bytes = g_raw_bytes + 946, .length = 25}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 935, .length = 2}}, + .data.refcounted = {.bytes = g_raw_bytes + 971, .length = 2}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 937, .length = 8}}, + .data.refcounted = {.bytes = g_raw_bytes + 973, .length = 8}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 945, .length = 17}}, + .data.refcounted = {.bytes = g_raw_bytes + 981, .length = 17}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 962, .length = 10}}, + .data.refcounted = {.bytes = g_raw_bytes + 998, .length = 10}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 972, .length = 4}}, + .data.refcounted = {.bytes = g_raw_bytes + 1008, .length = 4}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 976, .length = 3}}, + .data.refcounted = {.bytes = g_raw_bytes + 1012, .length = 3}}, {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 979, .length = 16}}, + .data.refcounted = {.bytes = g_raw_bytes + 1015, .length = 16}}, }; static const uint8_t g_revmap[] = { @@ -376,13 +380,15 @@ static const uint8_t g_revmap[] = { 255, 255, 82, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 83, 255, 255, 255, 255, 255, 255, 84, 255, 255, 255, 255, 255, 85, 255, 255, 255, 255, 255, 255, 255, 255, 255, 86, 87, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 88, 255, 255, 255, 255, 255, 255, 89, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 90, 255, 91, 255, 255, 255, 255, 255, 255, 255, - 92, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 93, 255, 255, 255, 255, 255, 255, 255, 255, 255, 94, 255, 255, - 255, 95, 255, 255, 96, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255}; + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 88, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 89, 255, 255, 255, 255, 255, + 255, 90, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 91, 255, 92, 255, + 255, 255, 255, 255, 255, 255, 93, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 94, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 95, 255, 255, 255, 96, 255, 255, 97, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; int grpc_static_metadata_index(grpc_slice slice) { if (GRPC_SLICE_LENGTH(slice) == 0) return 33; @@ -390,7 +396,7 @@ int grpc_static_metadata_index(grpc_slice slice) { if (ofs > sizeof(g_revmap)) return -1; uint8_t id = g_revmap[ofs]; return id == 255 ? -1 : id; -}; +} grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { @@ -405,14 +411,14 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { #define ELEMS_PHASHSALT 0x9e3779b9 static const uint8_t elems_tab[] = { - 47, 1, 61, 0, 32, 0, 47, 1, 37, 0, 0, 0, 47, 61, 76, 0, - 76, 0, 61, 0, 32, 37, 51, 0, 47, 47, 79, 4, 76, 1, 0, 0, - 0, 76, 0, 47, 85, 34, 0, 10, 0, 28, 0, 76, 0, 61, 0, 0, - 46, 4, 12, 47, 88, 28, 61, 79, 28, 70, 0, 68, 85, 0, 87, 0, + 0, 17, 61, 28, 4, 12, 47, 0, 0, 0, 61, 0, 47, 0, 61, 76, + 61, 70, 76, 0, 0, 10, 4, 60, 0, 0, 0, 16, 88, 47, 1, 76, + 76, 0, 76, 0, 61, 0, 23, 0, 0, 51, 1, 92, 32, 0, 25, 0, + 34, 0, 37, 0, 76, 76, 32, 38, 70, 79, 81, 0, 64, 0, 0, 0, }; static uint32_t elems_phash(uint32_t val) { - val -= 1003; + val -= 917; uint32_t a, b, rsl; @@ -423,27 +429,27 @@ static uint32_t elems_phash(uint32_t val) { } static const uint16_t elem_keys[] = { - 1218, 8544, 2652, 1973, 7264, 2458, 2734, 3933, 1682, 6435, 3912, 3941, - 4396, 4418, 4850, 4852, 7890, 8541, 6726, 9345, 6338, 6629, 6920, 3939, - 7156, 8540, 8108, 8090, 8181, 8666, 8821, 1876, 8545, 1391, 8957, 1488, - 7405, 7265, 3331, 2943, 2846, 6241, 4851, 2167, 5368, 1585, 1294, 1003, - 9054, 6144, 8542, 8539, 8107, 7793, 7502, 7159, 7696, 2264, 6532, 2749, - 9248, 1197, 7987, 9151, 7017, 4423, 7119, 6823, 3938, 8543, 3525, 3911, - 2070, 2361, 2555, 6047, 1100, 3940, 3622, 3428, 8278, 0, 0, 0, + 2091, 1405, 8728, 2777, 7192, 2287, 2581, 2483, 2973, 4441, 3561, 3951, + 6403, 4463, 9441, 8726, 2875, 5423, 8730, 7338, 6109, 6207, 6697, 6893, + 7229, 8363, 8729, 3952, 8173, 8191, 8725, 8853, 9245, 9343, 1601, 8727, + 7481, 7340, 7971, 7775, 6501, 3973, 3659, 3979, 3463, 3980, 1307, 8190, + 9010, 8731, 4901, 6599, 3365, 7579, 6795, 9147, 9539, 8069, 6305, 7873, + 1209, 1111, 1699, 1503, 7089, 4468, 2189, 4900, 7232, 2385, 6991, 3978, + 1993, 4902, 2679, 2762, 1013, 3981, 1230, 1895, 8265, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static const uint8_t elem_idxs[] = { - 3, 72, 17, 10, 54, 15, 18, 28, 8, 44, 27, 32, 33, 34, 36, 38, 60, - 69, 47, 80, 43, 46, 49, 30, 52, 68, 64, 62, 65, 74, 75, 9, 73, 5, - 76, 6, 56, 55, 22, 21, 20, 42, 37, 12, 39, 7, 4, 1, 77, 41, 70, - 67, 63, 59, 57, 53, 58, 13, 45, 19, 79, 2, 61, 78, 50, 35, 51, 48, - 29, 71, 24, 26, 11, 14, 16, 40, 0, 31, 25, 23, 66}; + 11, 5, 70, 19, 51, 13, 16, 15, 21, 33, 24, 26, 43, 34, 79, 68, 20, + 39, 72, 54, 40, 41, 46, 48, 52, 66, 71, 27, 62, 64, 67, 74, 77, 78, + 7, 69, 56, 55, 60, 58, 44, 28, 25, 30, 23, 31, 4, 63, 75, 73, 37, + 45, 22, 57, 47, 76, 80, 61, 42, 59, 2, 0, 8, 6, 50, 35, 12, 36, + 53, 14, 49, 29, 10, 38, 17, 18, 1, 32, 3, 9, 65}; grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return NULL; - uint32_t k = (uint32_t)(a * 97 + b); + uint32_t k = (uint32_t)(a * 98 + b); uint32_t h = elems_phash(k); return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL; } @@ -455,9 +461,9 @@ const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = 40, 32, 40, 53, 40, 58, 40, 59, 40, 60, 40, 61, 45, 31, 45, 53, 45, 58, 50, 0, 50, 1, 50, 2, 55, 33, 62, 33, 63, 33, 64, 33, 65, 33, 66, 33, 67, 33, 68, 33, 69, 33, 70, 33, 71, 33, 72, 33, 73, 38, 73, 75, 73, 78, - 74, 86, 74, 87, 76, 33, 77, 33, 79, 33, 80, 33, 81, 33, 82, 33, 83, 39, - 83, 56, 83, 57, 84, 33, 85, 33, 88, 3, 88, 4, 88, 5, 88, 6, 88, 7, - 88, 8, 88, 9, 89, 33, 90, 91, 92, 33, 93, 33, 94, 33, 95, 33, 96, 33}; + 74, 86, 74, 88, 76, 33, 77, 33, 79, 33, 80, 33, 81, 33, 82, 33, 83, 39, + 83, 56, 83, 57, 84, 33, 85, 33, 89, 3, 89, 4, 89, 5, 89, 6, 89, 7, + 89, 8, 89, 9, 90, 33, 91, 92, 93, 33, 94, 33, 95, 33, 96, 33, 97, 33}; const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, 28, 32, 27, 31}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index c6348a52803..282a3231cab 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -44,7 +44,7 @@ #include "src/core/lib/transport/metadata.h" -#define GRPC_STATIC_MDSTR_COUNT 97 +#define GRPC_STATIC_MDSTR_COUNT 98 extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ #define GRPC_MDSTR_0 (grpc_static_slice_table[0]) @@ -223,26 +223,29 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; #define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[85]) /* "/" */ #define GRPC_MDSTR_SLASH (grpc_static_slice_table[86]) +/* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ +#define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ + (grpc_static_slice_table[87]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[87]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[88]) /* ":status" */ -#define GRPC_MDSTR_STATUS (grpc_static_slice_table[88]) +#define GRPC_MDSTR_STATUS (grpc_static_slice_table[89]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[89]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[90]) /* "te" */ -#define GRPC_MDSTR_TE (grpc_static_slice_table[90]) +#define GRPC_MDSTR_TE (grpc_static_slice_table[91]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[91]) +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[92]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[92]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[93]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[93]) +#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[94]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[94]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table[95]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[95]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table[96]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[96]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[97]) bool grpc_is_static_metadata_string(grpc_slice slice); diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 75634826098..d5ee01bfbfb 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -86,6 +86,7 @@ "\x06server" "\x0Aset-cookie" "\x01/" +"$/grpc.lb.v1.LoadBalancer/BalanceLoad" "\x0B/index.html" "\x07:status" "\x19strict-transport-security" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index a9001a68971..d632c971130 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -63,6 +63,8 @@ CONFIG = [ 'grpc.timeout', 'grpc.max_request_message_bytes', 'grpc.max_response_message_bytes', + # well known method names + '/grpc.lb.v1.LoadBalancer/BalanceLoad', # metadata elements ('grpc-status', '0'), ('grpc-status', '1'), @@ -191,24 +193,30 @@ def put_banner(files, banner): print >>f # build a list of all the strings we need -all_strs = set() -all_elems = set() +all_strs = list() +all_elems = list() static_userdata = {} for elem in CONFIG: if isinstance(elem, tuple): - all_strs.add(elem[0]) - all_strs.add(elem[1]) - all_elems.add(elem) + if elem[0] not in all_strs: + all_strs.append(elem[0]) + if elem[1] not in all_strs: + all_strs.append(elem[1]) + if elem not in all_elems: + all_elems.append(elem) else: - all_strs.add(elem) + if elem not in all_strs: + all_strs.append(elem) compression_elems = [] for mask in range(1, 1<>C, 'static grpc_slice_refcount g_refcnt = {static_ref, static_unref};' print >>C print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' print >>C, ' return slice.refcount != NULL && slice.refcount->ref == static_ref;' -print >>C, '};' +print >>C, '}' print >>C print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' str_ofs = 0 @@ -327,7 +335,7 @@ print >>C, ' size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);' print >>C, ' if (ofs > sizeof(g_revmap)) return -1;' print >>C, ' uint8_t id = g_revmap[ofs];' print >>C, ' return id == 255 ? -1 : id;' -print >>C, '};' +print >>C, '}' print >>C print >>D, '# hpack fuzzing dictionary' @@ -361,11 +369,19 @@ def md_idx(m): return i def perfect_hash(keys, name): - tmp = open('/tmp/keys.txt', 'w') - tmp.write(''.join('%d\n' % (x - min(keys)) for x in keys)) - tmp.close() - cmd = '%s/perfect/run.sh %s -ds' % (os.path.dirname(sys.argv[0]), tmp.name) + ok = False + cmd = '%s/perfect/build.sh' % (os.path.dirname(sys.argv[0])) subprocess.check_call(cmd, shell=True) + for offset in reversed(range(0, min(keys))): + tmp = open('/tmp/keys.txt', 'w') + tmp.write(''.join('%d\n' % (x - offset) for x in keys)) + tmp.close() + cmd = '%s/perfect/run.sh %s -dms' % (os.path.dirname(sys.argv[0]), tmp.name) + out = subprocess.check_output(cmd, shell=True) + if 'fatal error' not in out: + ok = True + break + assert ok, "Failed to find hash of keys in /tmp/keys.txt" code = '' @@ -378,14 +394,14 @@ def perfect_hash(keys, name): results[var] = val code += '\n' pycode = 'def f(val):\n' - pycode += ' val -= %d\n' % min(keys) + pycode += ' val -= %d\n' % offset with open('%s/perfect/phash.c' % os.path.dirname(sys.argv[0])) as f: txt = f.read() tabdata = re.search(r'ub1 tab\[\] = \{([^}]+)\}', txt, re.MULTILINE).group(1) code += 'static const uint8_t %s_tab[] = {%s};\n\n' % (name, tabdata) func_body = re.search(r'ub4 phash\(val\)\nub4 val;\n\{([^}]+)\}', txt, re.MULTILINE).group(1).replace('ub4', 'uint32_t') code += 'static uint32_t %s_phash(uint32_t val) {\nval -= %d;\n%s}\n' % (name, - min(keys), func_body.replace('tab', '%s_tab' % name)) + offset, func_body.replace('tab', '%s_tab' % name)) pycode += ' tab=(%s)' % tabdata.replace('\n', '') pycode += '\n'.join(' %s' % s.strip() for s in func_body.splitlines()[2:]) g = {} diff --git a/tools/codegen/core/perfect/build.sh b/tools/codegen/core/perfect/build.sh new file mode 100755 index 00000000000..139556ea483 --- /dev/null +++ b/tools/codegen/core/perfect/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash +set -e +cd $(dirname $0) +gcc -o perfect perfect.c recycle.c lookupa.c perfhex.c 2> compile.txt diff --git a/tools/codegen/core/perfect/run.sh b/tools/codegen/core/perfect/run.sh index 8dc5911cbdf..c0d1fc3b812 100755 --- a/tools/codegen/core/perfect/run.sh +++ b/tools/codegen/core/perfect/run.sh @@ -1,7 +1,6 @@ #!/bin/bash set -e cd $(dirname $0) -gcc -o perfect perfect.c recycle.c lookupa.c perfhex.c 2> compile.txt fn=$1 shift -./perfect $* < $fn &> hash.txt +./perfect $* < $fn From 0d3ea83b69f15c37a8e46aad92bd453e2e63b173 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 17 Nov 2016 01:25:27 -0800 Subject: [PATCH 019/261] Update CronetFramework version number to 1.0.0 and use new URL --- src/objective-c/CronetFramework.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objective-c/CronetFramework.podspec b/src/objective-c/CronetFramework.podspec index 2f47b02c0c0..538479b96bc 100644 --- a/src/objective-c/CronetFramework.podspec +++ b/src/objective-c/CronetFramework.podspec @@ -30,7 +30,7 @@ Pod::Spec.new do |s| s.name = "CronetFramework" - s.version = "0.0.3" + s.version = "1.0.0" s.summary = "Cronet, precompiled and used as a framework." s.homepage = "http://chromium.org" s.license = { @@ -69,7 +69,7 @@ Pod::Spec.new do |s| s.vendored_framework = "Cronet.framework" s.author = "The Chromium Authors" s.ios.deployment_target = "8.0" - s.source = { :http => 'https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework.zip' } + s.source = { :http => 'https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework-1.0.0.zip' } s.preserve_paths = "Cronet.framework" s.public_header_files = "Cronet.framework/Headers/**/*{.h}" s.source_files = "Cronet.framework/Headers/**/*{.h}" From 0451c3dbfcf7dcab791a4a2b10f284ac4723da8e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 09:34:14 -0800 Subject: [PATCH 020/261] Move slice functions to vtable, implement hash --- include/grpc/impl/codegen/slice.h | 15 ++++++--- include/grpc/slice.h | 2 ++ .../chttp2/transport/hpack_encoder.c | 2 +- src/core/lib/iomgr/resource_quota.c | 6 ++-- src/core/lib/slice/slice.c | 32 ++++++++++++------- src/core/lib/slice/slice_hash_table.c | 2 +- src/core/lib/slice/slice_intern.c | 25 +++++++++++++-- src/core/lib/transport/static_metadata.c | 6 ++-- tools/codegen/core/gen_static_metadata.py | 5 +-- 9 files changed, 69 insertions(+), 26 deletions(-) diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 4d4a86fa22e..ecce1ca0893 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -39,6 +39,8 @@ #include +typedef struct grpc_slice grpc_slice; + /* Slice API A slice represents a contiguous reference counted array of bytes. @@ -52,14 +54,19 @@ reference ownership semantics (who should call unref?) and mutability constraints (is the callee allowed to modify the slice?) */ +typedef struct grpc_slice_refcount_vtable { + void (*ref)(void *); + void (*unref)(grpc_exec_ctx *exec_ctx, void *); + uint32_t (*hash)(void *, grpc_slice slice); +} grpc_slice_refcount_vtable; + /* Reference count container for grpc_slice. Contains function pointers to increment and decrement reference counts. Implementations should cleanup when the reference count drops to zero. Typically client code should not touch this, and use grpc_slice_malloc, grpc_slice_new, or grpc_slice_new_with_len instead. */ typedef struct grpc_slice_refcount { - void (*ref)(void *); - void (*unref)(grpc_exec_ctx *exec_ctx, void *); + const grpc_slice_refcount_vtable *vtable; } grpc_slice_refcount; #define GRPC_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1) @@ -73,7 +80,7 @@ typedef struct grpc_slice_refcount { If the slice does not have a refcount, it represents an inlined small piece of data that is copied by value. */ -typedef struct grpc_slice { +struct grpc_slice { struct grpc_slice_refcount *refcount; union { struct { @@ -85,7 +92,7 @@ typedef struct grpc_slice { uint8_t bytes[GRPC_SLICE_INLINED_SIZE]; } inlined; } data; -} grpc_slice; +}; #define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 34c1ee93d64..514592e79b3 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -121,6 +121,8 @@ GPRAPI grpc_slice grpc_slice_split_head(grpc_slice *s, size_t split); GPRAPI grpc_slice grpc_empty_slice(void); +GPRAPI uint32_t grpc_slice_default_hash_impl(void *, grpc_slice s); + /* Returns <0 if a < b, ==0 if a == b, >0 if a > b The order is arbitrary, and is not guaranteed to be stable across different versions of the API. */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 9b27071c871..651f813c7e6 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -64,7 +64,7 @@ /* don't consider adding anything bigger than this to the hpack table */ #define MAX_DECODER_SPACE_USAGE 512 -static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; +static grpc_slice_refcount terminal_slice_refcount = {NULL}; static const grpc_slice terminal_slice = {&terminal_slice_refcount, .data.refcounted = {0, 0}}; diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c index efcb0f81749..3b637730718 100644 --- a/src/core/lib/iomgr/resource_quota.c +++ b/src/core/lib/iomgr/resource_quota.c @@ -366,11 +366,13 @@ static void ru_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static const grpc_slice_refcount_vtable ru_slice_vtable = { + ru_slice_ref, ru_slice_unref, grpc_slice_default_hash_impl}; + static grpc_slice ru_slice_create(grpc_resource_user *resource_user, size_t size) { ru_slice_refcount *rc = gpr_malloc(sizeof(ru_slice_refcount) + size); - rc->base.ref = ru_slice_ref; - rc->base.unref = ru_slice_unref; + rc->base.vtable = &ru_slice_vtable; gpr_ref_init(&rc->refs, 1); rc->resource_user = resource_user; rc->size = size; diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index dc3e6fd93d1..f2c09d60e5f 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -50,14 +50,14 @@ grpc_slice grpc_empty_slice(void) { grpc_slice grpc_slice_ref_internal(grpc_slice slice) { if (slice.refcount) { - slice.refcount->ref(slice.refcount); + slice.refcount->vtable->ref(slice.refcount); } return slice; } void grpc_slice_unref_internal(grpc_exec_ctx *exec_ctx, grpc_slice slice) { if (slice.refcount) { - slice.refcount->unref(exec_ctx, slice.refcount); + slice.refcount->vtable->unref(exec_ctx, slice.refcount); } } @@ -78,7 +78,9 @@ void grpc_slice_unref(grpc_slice slice) { static void noop_ref(void *unused) {} static void noop_unref(grpc_exec_ctx *exec_ctx, void *unused) {} -static grpc_slice_refcount noop_refcount = {noop_ref, noop_unref}; +static const grpc_slice_refcount_vtable noop_refcount_vtable = { + noop_ref, noop_unref, grpc_slice_default_hash_impl}; +static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable}; grpc_slice grpc_slice_from_static_string(const char *s) { grpc_slice slice; @@ -110,14 +112,16 @@ static void new_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static const grpc_slice_refcount_vtable new_slice_vtable = { + new_slice_ref, new_slice_unref, grpc_slice_default_hash_impl}; + grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, void (*destroy)(void *), void *user_data) { grpc_slice slice; new_slice_refcount *rc = gpr_malloc(sizeof(new_slice_refcount)); gpr_ref_init(&rc->refs, 1); - rc->rc.ref = new_slice_ref; - rc->rc.unref = new_slice_unref; + rc->rc.vtable = &new_slice_vtable; rc->user_destroy = destroy; rc->user_data = user_data; @@ -155,14 +159,16 @@ static void new_with_len_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static const grpc_slice_refcount_vtable new_with_len_vtable = { + new_with_len_ref, new_with_len_unref, grpc_slice_default_hash_impl}; + grpc_slice grpc_slice_new_with_len(void *p, size_t len, void (*destroy)(void *, size_t)) { grpc_slice slice; new_with_len_slice_refcount *rc = gpr_malloc(sizeof(new_with_len_slice_refcount)); gpr_ref_init(&rc->refs, 1); - rc->rc.ref = new_with_len_ref; - rc->rc.unref = new_with_len_unref; + rc->rc.vtable = &new_with_len_vtable; rc->user_destroy = destroy; rc->user_data = p; rc->user_length = len; @@ -200,6 +206,9 @@ static void malloc_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static const grpc_slice_refcount_vtable malloc_vtable = { + malloc_ref, malloc_unref, grpc_slice_default_hash_impl}; + grpc_slice grpc_slice_malloc(size_t length) { grpc_slice slice; @@ -219,8 +228,7 @@ grpc_slice grpc_slice_malloc(size_t length) { this reference. */ gpr_ref_init(&rc->refs, 1); - rc->base.ref = malloc_ref; - rc->base.unref = malloc_unref; + rc->base.vtable = &malloc_vtable; /* Build up the slice to be returned. */ /* The slices refcount points back to the allocated block. */ @@ -273,7 +281,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { } else { subset = grpc_slice_sub_no_ref(source, begin, end); /* Bump the refcount */ - subset.refcount->ref(subset.refcount); + subset.refcount->vtable->ref(subset.refcount); } return subset; } @@ -302,7 +310,7 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { /* Build the result */ tail.refcount = source->refcount; /* Bump the refcount */ - tail.refcount->ref(tail.refcount); + tail.refcount->vtable->ref(tail.refcount); /* Point into the source array */ tail.data.refcounted.bytes = source->data.refcounted.bytes + split; tail.data.refcounted.length = tail_length; @@ -340,7 +348,7 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { /* Build the result */ head.refcount = source->refcount; /* Bump the refcount */ - head.refcount->ref(head.refcount); + head.refcount->vtable->ref(head.refcount); /* Point into the source array */ head.data.refcounted.bytes = source->data.refcounted.bytes; head.data.refcounted.length = split; diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 7e6f705164b..10b41343ea2 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -40,7 +40,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" -static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; +static grpc_slice_refcount terminal_slice_refcount = {NULL}; static const grpc_slice terminal_slice = {&terminal_slice_refcount, .data.refcounted = {0, 0}}; diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 8f48a361010..a7e17527c36 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -100,6 +100,18 @@ static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static uint32_t interned_slice_hash(void *p, grpc_slice slice) { + interned_slice_refcount *s = p; + if (slice.data.refcounted.bytes == (uint8_t *)(s + 1) && + slice.data.refcounted.length == s->length) { + return s->hash; + } + return grpc_slice_default_hash_impl(p, slice); +} + +static const grpc_slice_refcount_vtable interned_slice_vtable = { + interned_slice_ref, interned_slice_unref, interned_slice_hash}; + static void grow_shard(slice_shard *shard) { size_t capacity = shard->capacity * 2; size_t i; @@ -135,6 +147,16 @@ static grpc_slice materialize(interned_slice_refcount *s) { return slice; } +uint32_t grpc_slice_default_hash_impl(void *unused_refcnt, grpc_slice s) { + return gpr_murmur_hash3(GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), + g_hash_seed); +} + +uint32_t grpc_slice_hash(grpc_slice s) { + return s.refcount == NULL ? grpc_slice_default_hash_impl(NULL, s) + : s.refcount->vtable->hash(s.refcount, s); +} + grpc_slice grpc_slice_intern(grpc_slice slice) { interned_slice_refcount *s; uint32_t hash = gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), @@ -168,8 +190,7 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { gpr_atm_rel_store(&s->refcnt, 1); s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; - s->base.ref = interned_slice_ref; - s->base.unref = interned_slice_unref; + s->base.vtable = &interned_slice_vtable; s->bucket_next = shard->strs[idx]; shard->strs[idx] = s; memcpy(s + 1, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 0eb5cd5d740..b30b8a046bd 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -114,10 +114,12 @@ static uint8_t g_raw_bytes[] = { static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} -static grpc_slice_refcount g_refcnt = {static_ref, static_unref}; +static const grpc_slice_refcount_vtable static_vtable = { + static_ref, static_unref, grpc_slice_default_hash_impl}; +static grpc_slice_refcount g_refcnt = {&static_vtable}; bool grpc_is_static_metadata_string(grpc_slice slice) { - return slice.refcount != NULL && slice.refcount->ref == static_ref; + return slice.refcount != NULL && slice.refcount->vtable == &static_vtable; } const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index d632c971130..05572ea38b8 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -310,10 +310,11 @@ print >>C, 'static uint8_t g_raw_bytes[] = {%s};' % (','.join('%d' % ord(c) for print >>C print >>C, 'static void static_ref(void *unused) {}' print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' -print >>C, 'static grpc_slice_refcount g_refcnt = {static_ref, static_unref};' +print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_slice_default_hash_impl};'; +print >>C, 'static grpc_slice_refcount g_refcnt = {&static_vtable};' print >>C print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' -print >>C, ' return slice.refcount != NULL && slice.refcount->ref == static_ref;' +print >>C, ' return slice.refcount != NULL && slice.refcount->vtable == &static_vtable;' print >>C, '}' print >>C print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' From 7d4116fa44752dcb10da3a5dee95c05214423ac5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 12:16:05 -0800 Subject: [PATCH 021/261] All core tests compile without grpc_mdstr --- grpc.def | 4 +- include/grpc/grpc.h | 9 +- include/grpc/slice.h | 10 + .../chttp2/transport/hpack_encoder.c | 2 +- .../transport/chttp2/transport/hpack_parser.c | 5 +- src/core/lib/iomgr/ev_posix.c | 2 + .../credentials/plugin/plugin_credentials.c | 6 +- src/core/lib/slice/slice.c | 46 +++- src/core/lib/slice/slice_intern.c | 2 +- src/core/lib/slice/slice_internal.h | 2 +- src/core/lib/slice/slice_string_helpers.c | 5 + src/core/lib/surface/call.c | 6 +- src/core/lib/surface/validate_metadata.c | 26 +-- src/core/lib/transport/metadata.c | 3 +- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 8 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 18 +- test/core/bad_client/tests/large_metadata.c | 18 +- test/core/bad_client/tests/simple_request.c | 4 +- test/core/bad_ssl/bad_ssl_test.c | 11 +- test/core/channel/channel_args_test.c | 6 +- test/core/channel/channel_stack_test.c | 5 +- test/core/client_channel/lb_policies_test.c | 31 ++- .../set_initial_connect_string_test.c | 6 +- test/core/compression/algorithm_test.c | 33 +-- test/core/compression/compression_test.c | 4 +- test/core/end2end/bad_server_response_test.c | 16 +- test/core/end2end/connection_refused_test.c | 18 +- test/core/end2end/dualstack_socket_test.c | 20 +- test/core/end2end/fixtures/h2_oauth2.c | 4 +- test/core/end2end/fixtures/h2_ssl_cert.c | 3 +- test/core/end2end/fuzzers/api_fuzzer.c | 108 ++++++--- test/core/end2end/fuzzers/client_fuzzer.c | 16 +- test/core/end2end/fuzzers/server_fuzzer.c | 3 +- test/core/end2end/goaway_server_test.c | 27 ++- .../core/end2end/invalid_call_argument_test.c | 36 ++- test/core/end2end/no_server_test.c | 10 +- test/core/fling/client.c | 20 +- test/core/fling/server.c | 8 +- test/core/security/credentials_test.c | 5 +- test/core/security/ssl_server_fuzzer.c | 6 +- test/core/slice/slice_test.c | 6 +- test/core/surface/lame_client_test.c | 9 +- test/core/transport/chttp2/bin_encoder_test.c | 4 +- .../transport/chttp2/hpack_encoder_test.c | 10 +- .../chttp2/hpack_parser_fuzzer_test.c | 3 +- .../core/transport/chttp2/hpack_parser_test.c | 4 +- test/core/transport/chttp2/hpack_table_test.c | 27 ++- test/core/transport/metadata_test.c | 212 ++++++++---------- test/core/transport/timeout_encoding_test.c | 27 ++- 49 files changed, 488 insertions(+), 386 deletions(-) diff --git a/grpc.def b/grpc.def index a4989ada582..c54d798f367 100644 --- a/grpc.def +++ b/grpc.def @@ -92,11 +92,8 @@ EXPORTS grpc_server_destroy grpc_tracer_set_enabled grpc_header_key_is_legal - grpc_header_key_slice_is_legal grpc_header_nonbin_value_is_legal - grpc_header_nonbin_value_slice_is_legal grpc_is_binary_header - grpc_slice_is_binary_header grpc_call_error_to_string grpc_resource_quota_create grpc_resource_quota_ref @@ -153,6 +150,7 @@ EXPORTS grpc_slice_split_tail grpc_slice_split_head grpc_empty_slice + grpc_slice_default_hash_impl grpc_slice_cmp grpc_slice_str_cmp grpc_slice_buf_cmp diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index a3015340ee0..2f3b37ad805 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -396,17 +396,14 @@ GRPCAPI void grpc_server_destroy(grpc_server *server); GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled); /** Check whether a metadata key is legal (will be accepted by core) */ -GRPCAPI int grpc_header_key_is_legal(const char *key, size_t length); -GRPCAPI int grpc_header_key_slice_is_legal(grpc_slice slice); +GRPCAPI int grpc_header_key_is_legal(grpc_slice slice); /** Check whether a non-binary metadata value is legal (will be accepted by core) */ -GRPCAPI int grpc_header_nonbin_value_is_legal(const char *value, size_t length); -GRPCAPI int grpc_header_nonbin_value_slice_is_legal(grpc_slice slice); +GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice); /** Check whether a metadata key corresponds to a binary value */ -GRPCAPI int grpc_is_binary_header(const char *key, size_t length); -GRPCAPI int grpc_slice_is_binary_header(grpc_slice slice); +GRPCAPI int grpc_is_binary_header(grpc_slice slice); /** Convert grpc_call_error values to a string */ GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error); diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 514592e79b3..711124d8659 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -99,6 +99,9 @@ GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len); /* Create a slice pointing to constant memory */ GPRAPI grpc_slice grpc_slice_from_static_string(const char *source); +/* Create a slice pointing to constant memory */ +GPRAPI grpc_slice grpc_slice_from_static_buffer(const void *source, size_t len); + /* Return a result slice derived from s, which shares a ref count with s, where result.data==s.data+begin, and result.length==end-begin. The ref count of s is increased by one. @@ -130,9 +133,16 @@ GPRAPI int grpc_slice_cmp(grpc_slice a, grpc_slice b); GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b); GPRAPI int grpc_slice_buf_cmp(grpc_slice a, const void *b, size_t blen); +/* return non-zero if the first blen bytes of a are equal to b */ GPRAPI int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t blen); +/* return the index of the last instance of \a c in \a s, or -1 if not found */ GPRAPI int grpc_slice_rchr(grpc_slice s, char c); +GPRAPI int grpc_slice_chr(grpc_slice s, char c); + +/* return the index of the first occurance of \a needle in \a haystack, or -1 if + * it's not found */ +GPRAPI int grpc_slice_slice(grpc_slice haystack, grpc_slice needle); GPRAPI uint32_t grpc_slice_hash(grpc_slice s); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 651f813c7e6..471c4cf5496 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -286,7 +286,7 @@ static void emit_indexed(grpc_chttp2_hpack_compressor *c, uint32_t elem_index, } static grpc_slice get_wire_value(grpc_mdelem *elem, uint8_t *huffman_prefix) { - if (grpc_slice_is_binary_header(elem->key)) { + if (grpc_is_binary_header(elem->key)) { *huffman_prefix = 0x80; return grpc_chttp2_base64_encode_and_huffman_compress(elem->value); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 86c65d4b5ae..61227a0105d 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1494,7 +1494,8 @@ static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, /* check if a key represents a binary header or not */ static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { - return grpc_is_binary_header(p->key.str, p->key.length); + return grpc_is_binary_header( + grpc_slice_from_static_buffer(p->key.str, p->key.length)); } static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, @@ -1506,7 +1507,7 @@ static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, GRPC_ERROR_INT_INDEX, (intptr_t)p->index), GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); } - *is = grpc_slice_is_binary_header(elem->key); + *is = grpc_is_binary_header(elem->key); return GRPC_ERROR_NONE; } diff --git a/src/core/lib/iomgr/ev_posix.c b/src/core/lib/iomgr/ev_posix.c index ab139895fdc..e1484167602 100644 --- a/src/core/lib/iomgr/ev_posix.c +++ b/src/core/lib/iomgr/ev_posix.c @@ -52,6 +52,8 @@ * tests */ grpc_poll_function_type grpc_poll_function = poll; +grpc_wakeup_fd grpc_global_wakeup_fd; + static const grpc_event_engine_vtable *g_event_engine; static const char *g_poll_strategy_name = NULL; diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index 4fc02b2659b..66e501cffc3 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -78,14 +78,14 @@ static void plugin_md_request_metadata_ready(void *request, bool seen_illegal_header = false; grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_slice_is_legal(md[i].key)) { + if (!grpc_header_key_is_legal(md[i].key)) { char *key = grpc_dump_slice(md[i].key, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", key); gpr_free(key); seen_illegal_header = true; break; - } else if (!grpc_slice_is_binary_header(md[i].key) && - !grpc_header_nonbin_value_slice_is_legal(md[i].value)) { + } else if (!grpc_is_binary_header(md[i].key) && + !grpc_header_nonbin_value_is_legal(md[i].value)) { gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); seen_illegal_header = true; break; diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index f2c09d60e5f..c377edd349e 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -82,14 +82,18 @@ static const grpc_slice_refcount_vtable noop_refcount_vtable = { noop_ref, noop_unref, grpc_slice_default_hash_impl}; static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable}; -grpc_slice grpc_slice_from_static_string(const char *s) { +grpc_slice grpc_slice_from_static_buffer(const void *s, size_t len) { grpc_slice slice; slice.refcount = &noop_refcount; slice.data.refcounted.bytes = (uint8_t *)s; - slice.data.refcounted.length = strlen(s); + slice.data.refcounted.length = len; return slice; } +grpc_slice grpc_slice_from_static_string(const char *s) { + return grpc_slice_from_static_buffer(s, strlen(s)); +} + /* grpc_slice_new support structures - we create a refcount object extended with the user provided data pointer & destroy function */ typedef struct new_slice_refcount { @@ -384,3 +388,41 @@ int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b) { return a.data.refcounted.length == b.data.refcounted.length && a.data.refcounted.bytes == b.data.refcounted.bytes; } + +int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t len) { + if (GRPC_SLICE_LENGTH(a) < len) return 0; + return 0 == memcmp(GRPC_SLICE_START_PTR(a), b, len); +} + +int grpc_slice_rchr(grpc_slice s, char c) { + const char *b = (const char *)GRPC_SLICE_START_PTR(s); + int i; + for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) + ; + return i; +} + +int grpc_slice_chr(grpc_slice s, char c) { + const char *b = (const char *)GRPC_SLICE_START_PTR(s); + const char *p = memchr(b, c, GRPC_SLICE_LENGTH(s)); + return p == NULL ? -1 : (int)(p - b); +} + +int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { + size_t haystack_len = GRPC_SLICE_LENGTH(haystack); + const uint8_t *haystack_bytes = GRPC_SLICE_START_PTR(haystack); + size_t needle_len = GRPC_SLICE_LENGTH(needle); + const uint8_t *needle_bytes = GRPC_SLICE_START_PTR(needle); + + if (haystack_len == 0 || needle_len == 0) return -1; + if (haystack_len < needle_len) return -1; + if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes); + + const uint8_t *last = haystack_bytes + haystack_len - needle_len; + for (const uint8_t *cur = haystack_bytes; cur != last; ++cur) { + if (0 == memcmp(cur, needle_bytes, needle_len)) { + return (int)(cur - haystack_bytes); + } + } + return -1; +} diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index a7e17527c36..b5e00a38d7e 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -206,7 +206,7 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { return materialize(s); } -void grpc_test_only_set_slice_interning_hash_seed(uint32_t seed) { +void grpc_test_only_set_slice_hash_seed(uint32_t seed) { g_hash_seed = seed; g_forced_hash_seed = 1; } diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 8bfe066fdb4..bf9117c74e0 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -48,6 +48,6 @@ void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); -void grpc_test_only_set_slice_interning_hash_seed(uint32_t key); +void grpc_test_only_set_slice_hash_seed(uint32_t key); #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ diff --git a/src/core/lib/slice/slice_string_helpers.c b/src/core/lib/slice/slice_string_helpers.c index 839c366b32d..99695007cca 100644 --- a/src/core/lib/slice/slice_string_helpers.c +++ b/src/core/lib/slice/slice_string_helpers.c @@ -88,3 +88,8 @@ void grpc_slice_split(grpc_slice str, const char *sep, grpc_slice_buffer *dst) { grpc_slice_buffer_add_indexed(dst, grpc_slice_ref_internal(str)); } } + +bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t *result) { + return gpr_parse_bytes_to_uint32((const char *)GRPC_SLICE_START_PTR(str), + GRPC_SLICE_LENGTH(str), result) != 0; +} diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 38aa99372e8..6ffe37e300e 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -596,13 +596,13 @@ static int prepare_application_metadata( grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); l->md = grpc_mdelem_from_slices(exec_ctx, md->key, md->value); - if (!grpc_header_key_slice_is_legal(l->md->key)) { + if (!grpc_header_key_is_legal(l->md->key)) { char *str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); break; - } else if (!grpc_slice_is_binary_header(l->md->key) && - !grpc_header_nonbin_value_slice_is_legal(l->md->value)) { + } else if (!grpc_is_binary_header(l->md->key) && + !grpc_header_nonbin_value_is_legal(l->md->value)) { char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); gpr_free(str); diff --git a/src/core/lib/surface/validate_metadata.c b/src/core/lib/surface/validate_metadata.c index 84f0a083bc1..c9ff30bf8a8 100644 --- a/src/core/lib/surface/validate_metadata.c +++ b/src/core/lib/surface/validate_metadata.c @@ -34,13 +34,14 @@ #include #include +#include #include -static int conforms_to(const char *s, size_t len, const uint8_t *legal_bits) { - const char *p = s; - const char *e = s + len; +static int conforms_to(grpc_slice slice, const uint8_t *legal_bits) { + const uint8_t *p = GRPC_SLICE_START_PTR(slice); + const uint8_t *e = GRPC_SLICE_END_PTR(slice); for (; p != e; p++) { - int idx = (uint8_t)*p; + int idx = *p; int byte = idx / 8; int bit = idx % 8; if ((legal_bits[byte] & (1 << bit)) == 0) return 0; @@ -48,26 +49,23 @@ static int conforms_to(const char *s, size_t len, const uint8_t *legal_bits) { return 1; } -int grpc_header_key_is_legal(const char *key, size_t length) { +int grpc_header_key_is_legal(grpc_slice slice) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (length == 0) { - return 0; - } - return conforms_to(key, length, legal_header_bits); + return GRPC_SLICE_LENGTH(slice) != 0 && conforms_to(slice, legal_header_bits); } -int grpc_header_nonbin_value_is_legal(const char *value, size_t length) { +int grpc_header_nonbin_value_is_legal(grpc_slice slice) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - return conforms_to(value, length, legal_header_bits); + return conforms_to(slice, legal_header_bits); } -int grpc_is_binary_header(const char *key, size_t length) { - if (length < 5) return 0; - return 0 == memcmp(key + length - 4, "-bin", 4); +int grpc_is_binary_header(grpc_slice slice) { + if (GRPC_SLICE_LENGTH(slice) < 5) return 0; + return 0 == memcmp(GRPC_SLICE_END_PTR(slice) - 4, "-bin", 4); } diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index cedf9170b7c..6ec1518e93b 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -375,8 +375,7 @@ static size_t get_base64_encoded_size(size_t raw_length) { size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem) { size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(elem->key); size_t value_len = GRPC_SLICE_LENGTH(elem->value); - if (grpc_is_binary_header((const char *)GRPC_SLICE_START_PTR(elem->key), - GRPC_SLICE_LENGTH(elem->key))) { + if (grpc_is_binary_header(elem->key)) { return overhead_and_key + get_base64_encoded_size(value_len); } else { return overhead_and_key + value_len; diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 665903e22c4..1d5f70e5345 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -130,11 +130,8 @@ grpc_server_cancel_all_calls_type grpc_server_cancel_all_calls_import; grpc_server_destroy_type grpc_server_destroy_import; grpc_tracer_set_enabled_type grpc_tracer_set_enabled_import; grpc_header_key_is_legal_type grpc_header_key_is_legal_import; -grpc_header_key_slice_is_legal_type grpc_header_key_slice_is_legal_import; grpc_header_nonbin_value_is_legal_type grpc_header_nonbin_value_is_legal_import; -grpc_header_nonbin_value_slice_is_legal_type grpc_header_nonbin_value_slice_is_legal_import; grpc_is_binary_header_type grpc_is_binary_header_import; -grpc_slice_is_binary_header_type grpc_slice_is_binary_header_import; grpc_call_error_to_string_type grpc_call_error_to_string_import; grpc_resource_quota_create_type grpc_resource_quota_create_import; grpc_resource_quota_ref_type grpc_resource_quota_ref_import; @@ -191,6 +188,7 @@ grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import; grpc_slice_split_tail_type grpc_slice_split_tail_import; grpc_slice_split_head_type grpc_slice_split_head_import; grpc_empty_slice_type grpc_empty_slice_import; +grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; grpc_slice_cmp_type grpc_slice_cmp_import; grpc_slice_str_cmp_type grpc_slice_str_cmp_import; grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; @@ -414,11 +412,8 @@ void grpc_rb_load_imports(HMODULE library) { grpc_server_destroy_import = (grpc_server_destroy_type) GetProcAddress(library, "grpc_server_destroy"); grpc_tracer_set_enabled_import = (grpc_tracer_set_enabled_type) GetProcAddress(library, "grpc_tracer_set_enabled"); grpc_header_key_is_legal_import = (grpc_header_key_is_legal_type) GetProcAddress(library, "grpc_header_key_is_legal"); - grpc_header_key_slice_is_legal_import = (grpc_header_key_slice_is_legal_type) GetProcAddress(library, "grpc_header_key_slice_is_legal"); grpc_header_nonbin_value_is_legal_import = (grpc_header_nonbin_value_is_legal_type) GetProcAddress(library, "grpc_header_nonbin_value_is_legal"); - grpc_header_nonbin_value_slice_is_legal_import = (grpc_header_nonbin_value_slice_is_legal_type) GetProcAddress(library, "grpc_header_nonbin_value_slice_is_legal"); grpc_is_binary_header_import = (grpc_is_binary_header_type) GetProcAddress(library, "grpc_is_binary_header"); - grpc_slice_is_binary_header_import = (grpc_slice_is_binary_header_type) GetProcAddress(library, "grpc_slice_is_binary_header"); grpc_call_error_to_string_import = (grpc_call_error_to_string_type) GetProcAddress(library, "grpc_call_error_to_string"); grpc_resource_quota_create_import = (grpc_resource_quota_create_type) GetProcAddress(library, "grpc_resource_quota_create"); grpc_resource_quota_ref_import = (grpc_resource_quota_ref_type) GetProcAddress(library, "grpc_resource_quota_ref"); @@ -475,6 +470,7 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail"); grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head"); grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice"); + grpc_slice_default_hash_impl_import = (grpc_slice_default_hash_impl_type) GetProcAddress(library, "grpc_slice_default_hash_impl"); grpc_slice_cmp_import = (grpc_slice_cmp_type) GetProcAddress(library, "grpc_slice_cmp"); grpc_slice_str_cmp_import = (grpc_slice_str_cmp_type) GetProcAddress(library, "grpc_slice_str_cmp"); grpc_slice_buf_cmp_import = (grpc_slice_buf_cmp_type) GetProcAddress(library, "grpc_slice_buf_cmp"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 14d5835201a..7fee273bb50 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -338,24 +338,15 @@ extern grpc_server_destroy_type grpc_server_destroy_import; typedef int(*grpc_tracer_set_enabled_type)(const char *name, int enabled); extern grpc_tracer_set_enabled_type grpc_tracer_set_enabled_import; #define grpc_tracer_set_enabled grpc_tracer_set_enabled_import -typedef int(*grpc_header_key_is_legal_type)(const char *key, size_t length); +typedef int(*grpc_header_key_is_legal_type)(grpc_slice slice); extern grpc_header_key_is_legal_type grpc_header_key_is_legal_import; #define grpc_header_key_is_legal grpc_header_key_is_legal_import -typedef int(*grpc_header_key_slice_is_legal_type)(grpc_slice slice); -extern grpc_header_key_slice_is_legal_type grpc_header_key_slice_is_legal_import; -#define grpc_header_key_slice_is_legal grpc_header_key_slice_is_legal_import -typedef int(*grpc_header_nonbin_value_is_legal_type)(const char *value, size_t length); +typedef int(*grpc_header_nonbin_value_is_legal_type)(grpc_slice slice); extern grpc_header_nonbin_value_is_legal_type grpc_header_nonbin_value_is_legal_import; #define grpc_header_nonbin_value_is_legal grpc_header_nonbin_value_is_legal_import -typedef int(*grpc_header_nonbin_value_slice_is_legal_type)(grpc_slice slice); -extern grpc_header_nonbin_value_slice_is_legal_type grpc_header_nonbin_value_slice_is_legal_import; -#define grpc_header_nonbin_value_slice_is_legal grpc_header_nonbin_value_slice_is_legal_import -typedef int(*grpc_is_binary_header_type)(const char *key, size_t length); +typedef int(*grpc_is_binary_header_type)(grpc_slice slice); extern grpc_is_binary_header_type grpc_is_binary_header_import; #define grpc_is_binary_header grpc_is_binary_header_import -typedef int(*grpc_slice_is_binary_header_type)(grpc_slice slice); -extern grpc_slice_is_binary_header_type grpc_slice_is_binary_header_import; -#define grpc_slice_is_binary_header grpc_slice_is_binary_header_import typedef const char *(*grpc_call_error_to_string_type)(grpc_call_error error); extern grpc_call_error_to_string_type grpc_call_error_to_string_import; #define grpc_call_error_to_string grpc_call_error_to_string_import @@ -524,6 +515,9 @@ extern grpc_slice_split_head_type grpc_slice_split_head_import; typedef grpc_slice(*grpc_empty_slice_type)(void); extern grpc_empty_slice_type grpc_empty_slice_import; #define grpc_empty_slice grpc_empty_slice_import +typedef uint32_t(*grpc_slice_default_hash_impl_type)(void *, grpc_slice s); +extern grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; +#define grpc_slice_default_hash_impl grpc_slice_default_hash_impl_import typedef int(*grpc_slice_cmp_type)(grpc_slice a, grpc_slice b); extern grpc_slice_cmp_type grpc_slice_cmp_import; #define grpc_slice_cmp grpc_slice_cmp_import diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index 9c804e78c10..f9255be1dc0 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -126,8 +126,8 @@ static void server_verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); @@ -153,16 +153,14 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); const size_t metadata_value_size = 16 * 1024; grpc_metadata meta; - meta.key = "key"; - meta.value = gpr_malloc(metadata_value_size + 1); - memset((char *)meta.value, 'a', metadata_value_size); - ((char *)meta.value)[metadata_value_size] = 0; - meta.value_length = metadata_value_size; + meta.key = grpc_slice_from_static_string("key"); + meta.value = grpc_slice_malloc(metadata_value_size); + memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); grpc_op op; memset(&op, 0, sizeof(op)); @@ -176,7 +174,7 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. cq_verify(cqv); - gpr_free((char *)meta.value); + grpc_slice_unref(meta.value); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(s); diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c index c08aa40a0a7..db31ba6fb3c 100644 --- a/test/core/bad_client/tests/simple_request.c +++ b/test/core/bad_client/tests/simple_request.c @@ -117,8 +117,8 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); diff --git a/test/core/bad_ssl/bad_ssl_test.c b/test/core/bad_ssl/bad_ssl_test.c index f8a9fe6caca..9cce77e71ab 100644 --- a/test/core/bad_ssl/bad_ssl_test.c +++ b/test/core/bad_ssl/bad_ssl_test.c @@ -57,8 +57,7 @@ static void run_test(const char *target, size_t nops) { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_status_code status; grpc_call_error error; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); @@ -80,9 +79,10 @@ static void run_test(const char *target, size_t nops) { grpc_metadata_array_init(&trailing_metadata_recv); channel = grpc_secure_channel_create(ssl_creds, target, &args, NULL); + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/foo", "foo.test.google.fr:1234", deadline, - NULL); + grpc_slice_from_static_string("/foo"), &host, + deadline, NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -95,7 +95,6 @@ static void run_test(const char *target, size_t nops) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -117,7 +116,7 @@ static void run_test(const char *target, size_t nops) { GPR_ASSERT(status != GRPC_STATUS_OK); grpc_call_destroy(c); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/channel/channel_args_test.c b/test/core/channel/channel_args_test.c index 6a325bc12fb..b2c41652a49 100644 --- a/test/core/channel/channel_args_test.c +++ b/test/core/channel/channel_args_test.c @@ -151,7 +151,11 @@ static void test_set_socket_mutator(void) { GPR_ASSERT(strcmp(ch_args->args[0].key, GRPC_ARG_SOCKET_MUTATOR) == 0); GPR_ASSERT(ch_args->args[0].type == GRPC_ARG_POINTER); - grpc_channel_args_destroy(ch_args); + { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_channel_args_destroy(&exec_ctx, ch_args); + grpc_exec_ctx_finish(&exec_ctx); + } } int main(int argc, char **argv) { diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index 54575ae499d..ab5a50304dc 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -39,6 +39,7 @@ #include #include +#include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" static void channel_init_func(grpc_exec_ctx *exec_ctx, @@ -119,7 +120,7 @@ static void test_create_channel_stack(void) { int *channel_data; int *call_data; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdstr *path = grpc_mdstr_from_string("/service/method"); + grpc_slice path = grpc_slice_from_static_string("/service/method"); arg.type = GRPC_ARG_INTEGER; arg.key = "test_key"; @@ -156,7 +157,7 @@ static void test_create_channel_stack(void) { GRPC_CHANNEL_STACK_UNREF(&exec_ctx, channel_stack, "done"); - GRPC_MDSTR_UNREF(&exec_ctx, path); + grpc_slice_unref_internal(&exec_ctx, path); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index c373505dd76..0a5c543a55b 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -154,8 +154,7 @@ static void kill_server(const servers_fixture *f, size_t i) { typedef struct request_data { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; - char *details; - size_t details_capacity; + grpc_slice details; grpc_status_code status; grpc_call_details *call_details; } request_data; @@ -267,8 +266,6 @@ static request_sequences perform_request(servers_fixture *f, for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { cq_verifier *cqv = cq_verifier_create(f->cq); - rdata->details = NULL; - rdata->details_capacity = 0; was_cancelled = 2; for (i = 0; i < f->num_servers; i++) { @@ -289,8 +286,9 @@ static request_sequences perform_request(servers_fixture *f, } memset(s_valid, 0, f->num_servers * sizeof(int)); + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - "/foo", "foo.test.google.fr", + grpc_slice_from_static_string("/foo"), &host, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); completed_client = 0; @@ -316,8 +314,6 @@ static request_sequences perform_request(servers_fixture *f, &rdata->trailing_metadata_recv; op->data.recv_status_on_client.status = &rdata->status; op->data.recv_status_on_client.status_details = &rdata->details; - op->data.recv_status_on_client.status_details_capacity = - &rdata->details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -360,7 +356,8 @@ static request_sequences perform_request(servers_fixture *f, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -379,12 +376,12 @@ static request_sequences perform_request(servers_fixture *f, } cq_verify(cqv); - gpr_log(GPR_DEBUG, "status=%d; %s", rdata->status, rdata->details); GPR_ASSERT(rdata->status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(rdata->details, "xyz")); - GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(rdata->details, "xyz")); GPR_ASSERT(0 == - strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); + grpc_slice_str_cmp(rdata->call_details[s_idx].method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(rdata->call_details[s_idx].host, + "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 1); grpc_call_destroy(f->server_calls[s_idx]); @@ -417,7 +414,7 @@ static request_sequences perform_request(servers_fixture *f, for (i = 0; i < f->num_servers; i++) { grpc_call_details_destroy(&rdata->call_details[i]); } - gpr_free(rdata->details); + grpc_slice_unref(rdata->details); } gpr_free(s_valid); @@ -449,10 +446,12 @@ static grpc_call **perform_multirequest(servers_fixture *f, op->flags = 0; op->reserved = NULL; + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); for (i = 0; i < concurrent_calls; i++) { - calls[i] = grpc_channel_create_call( - client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", - "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + calls[i] = + grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, + grpc_slice_from_static_string("/foo"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(calls[i]); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[i], ops, (size_t)(op - ops), tag(1), diff --git a/test/core/client_channel/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c index d12e1c3e415..e816347123d 100644 --- a/test/core/client_channel/set_initial_connect_string_test.c +++ b/test/core/client_channel/set_initial_connect_string_test.c @@ -140,9 +140,11 @@ static void start_rpc(int use_creds, int target_port) { } else { state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); } + grpc_slice host = grpc_slice_from_static_string("localhost"); state.call = grpc_channel_create_call( - state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", - "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, + grpc_slice_from_static_string("/Service/Method"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); memset(&state.op, 0, sizeof(state.op)); state.op.op = GRPC_OP_SEND_INITIAL_METADATA; state.op.data.send_initial_metadata.count = 0; diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index 4b85489044b..48e16c001ee 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -40,6 +40,7 @@ #include #include +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" @@ -51,20 +52,22 @@ static void test_algorithm_mesh(void) { for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { char *name; grpc_compression_algorithm parsed; - grpc_mdstr *mdstr; + grpc_slice mdstr; grpc_mdelem *mdelem; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); - GPR_ASSERT(grpc_compression_algorithm_parse(name, strlen(name), &parsed)); + GPR_ASSERT(grpc_compression_algorithm_parse( + grpc_slice_from_static_string(name), &parsed)); GPR_ASSERT((int)parsed == i); - mdstr = grpc_mdstr_from_string(name); - GPR_ASSERT(mdstr == grpc_compression_algorithm_slice(parsed)); + mdstr = grpc_slice_from_copied_string(name); + GPR_ASSERT(0 == + grpc_slice_cmp(mdstr, grpc_compression_algorithm_slice(parsed))); GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); mdelem = grpc_compression_encoding_mdelem(parsed); - GPR_ASSERT(mdelem->value == mdstr); - GPR_ASSERT(mdelem->key == GRPC_MDSTR_GRPC_ENCODING); - GRPC_MDSTR_UNREF(&exec_ctx, mdstr); + GPR_ASSERT(0 == grpc_slice_cmp(mdelem->value, mdstr)); + GPR_ASSERT(0 == grpc_slice_cmp(mdelem->key, GRPC_MDSTR_GRPC_ENCODING)); + grpc_slice_unref_internal(&exec_ctx, mdstr); GRPC_MDELEM_UNREF(&exec_ctx, mdelem); grpc_exec_ctx_finish(&exec_ctx); } @@ -76,7 +79,7 @@ static void test_algorithm_mesh(void) { static void test_algorithm_failure(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdstr *mdstr; + grpc_slice mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); @@ -84,14 +87,16 @@ static void test_algorithm_failure(void) { NULL) == 0); GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT + 1, NULL) == 0); - mdstr = grpc_mdstr_from_string("this-is-an-invalid-algorithm"); + mdstr = grpc_slice_from_static_string("this-is-an-invalid-algorithm"); GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) == GRPC_COMPRESS_ALGORITHMS_COUNT); - GPR_ASSERT(grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT) == - NULL); - GPR_ASSERT(grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT + - 1) == NULL); - GRPC_MDSTR_UNREF(&exec_ctx, mdstr); + GPR_ASSERT(0 == grpc_slice_cmp(grpc_compression_algorithm_slice( + GRPC_COMPRESS_ALGORITHMS_COUNT), + grpc_empty_slice())); + GPR_ASSERT(0 == grpc_slice_cmp(grpc_compression_algorithm_slice( + GRPC_COMPRESS_ALGORITHMS_COUNT + 1), + grpc_empty_slice())); + grpc_slice_unref_internal(&exec_ctx, mdstr); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c index 4c43746e335..7b2e56dc018 100644 --- a/test/core/compression/compression_test.c +++ b/test/core/compression/compression_test.c @@ -54,7 +54,7 @@ static void test_compression_algorithm_parse(void) { const char *valid_name = valid_names[i]; grpc_compression_algorithm algorithm; const int success = grpc_compression_algorithm_parse( - valid_name, strlen(valid_name), &algorithm); + grpc_slice_from_static_string(valid_name), &algorithm); GPR_ASSERT(success != 0); GPR_ASSERT(algorithm == valid_algorithms[i]); } @@ -64,7 +64,7 @@ static void test_compression_algorithm_parse(void) { grpc_compression_algorithm algorithm; int success; success = grpc_compression_algorithm_parse( - invalid_name, strlen(invalid_name), &algorithm); + grpc_slice_from_static_string(invalid_name), &algorithm); GPR_ASSERT(success == 0); /* the value of "algorithm" is undefined upon failure */ } diff --git a/test/core/end2end/bad_server_response_test.c b/test/core/end2end/bad_server_response_test.c index 84db87f9f34..496bb4de0f0 100644 --- a/test/core/end2end/bad_server_response_test.c +++ b/test/core/end2end/bad_server_response_test.c @@ -171,16 +171,17 @@ static void start_rpc(int target_port, grpc_status_code expected_status, grpc_status_code status; grpc_call_error error; cq_verifier *cqv; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; state.cq = grpc_completion_queue_create(NULL); cqv = cq_verifier_create(state.cq); gpr_join_host_port(&state.target, "127.0.0.1", target_port); state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); + grpc_slice host = grpc_slice_from_static_string("localhost"); state.call = grpc_channel_create_call( - state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", - "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, + grpc_slice_from_static_string("/Service/Method"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -205,7 +206,6 @@ static void start_rpc(int target_port, grpc_status_code expected_status, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -217,13 +217,13 @@ static void start_rpc(int target_port, grpc_status_code expected_status, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - gpr_log(GPR_DEBUG, "Rpc status: %d, details: %s", status, details); GPR_ASSERT(status == expected_status); - GPR_ASSERT(NULL != strstr(details, expected_detail)); + GPR_ASSERT(-1 != grpc_slice_slice(details, grpc_slice_from_static_string( + expected_detail))); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - gpr_free(details); + grpc_slice_unref(details); cq_verifier_destroy(cqv); } diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index d57eaf5a650..a7429489220 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -40,6 +40,7 @@ #include #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/method_config.h" @@ -59,8 +60,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_op *op; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; gpr_log(GPR_INFO, "TEST: wait_for_ready=%d use_service_config=%d", wait_for_ready, use_service_config); @@ -78,12 +78,12 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT(wait_for_ready); grpc_method_config_table_entry entry = { - grpc_mdstr_from_string("/service/method"), + grpc_slice_from_static_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(&exec_ctx, entry.method_name); + grpc_slice_unref_internal(&exec_ctx, entry.method_name); grpc_method_config_unref(&exec_ctx, entry.method_config); grpc_arg arg = grpc_method_config_table_create_channel_arg(method_config_table); @@ -98,9 +98,10 @@ static void run_test(bool wait_for_ready, bool use_service_config) { gpr_join_host_port(&addr, "127.0.0.1", port); gpr_log(GPR_INFO, "server: %s", addr); chan = grpc_insecure_channel_create(addr, args, NULL); - call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/service/method", "nonexistant", deadline, - NULL); + grpc_slice host = grpc_slice_from_static_string("nonexistant"); + call = grpc_channel_create_call( + chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/service/method"), &host, deadline, NULL); gpr_free(addr); @@ -117,7 +118,6 @@ static void run_test(bool wait_for_ready, bool use_service_config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -143,7 +143,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel_destroy(chan); cq_verifier_destroy(cqv); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&trailing_metadata_recv); { diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index 11e8604f56a..76d2747c9cf 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -88,8 +88,7 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_metadata_array request_metadata_recv; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; int was_cancelled = 2; grpc_call_details call_details; char *peer; @@ -168,8 +167,10 @@ void test_connect(const char *server_host, const char *client_host, int port, } /* Send a trivial request. */ + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/foo", "foo.test.google.fr", deadline, NULL); + grpc_slice_from_static_string("/foo"), &host, + deadline, NULL); GPR_ASSERT(c); memset(ops, 0, sizeof(ops)); @@ -192,7 +193,6 @@ void test_connect(const char *server_host, const char *client_host, int port, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -216,7 +216,8 @@ void test_connect(const char *server_host, const char *client_host, int port, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; @@ -235,9 +236,10 @@ void test_connect(const char *server_host, const char *client_host, int port, gpr_free(peer); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); - GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == + grpc_slice_str_cmp(call_details.host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 1); grpc_call_destroy(s); @@ -271,7 +273,7 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); - gpr_free(details); + grpc_slice_unref(details); if (picked_port) { grpc_recycle_unused_port(port); } diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.c index 83f759ce2dd..28011be7872 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.c @@ -59,8 +59,8 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md, const char *value) { size_t i; for (i = 0; i < md_count; i++) { - if (strcmp(key, md[i].key) == 0 && strlen(value) == md[i].value_length && - memcmp(md[i].value, value, md[i].value_length) == 0) { + if (grpc_slice_str_cmp(md[i].key, key) == 0 && + grpc_slice_str_cmp(md[i].value, value) == 0) { return &md[i]; } } diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/fixtures/h2_ssl_cert.c index ae49cc859af..92fac10d49a 100644 --- a/test/core/end2end/fixtures/h2_ssl_cert.c +++ b/test/core/end2end/fixtures/h2_ssl_cert.c @@ -321,8 +321,9 @@ static void simple_request_body(grpc_end2end_test_fixture f, grpc_op *op; grpc_call_error error; + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - "/foo", "foo.test.google.fr:1234", deadline, + grpc_slice_from_static_string("/foo"), &host, deadline, NULL); GPR_ASSERT(c); diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index 90ad0654c7b..a43941b396a 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -44,6 +44,7 @@ #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/timer.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/server.h" #include "src/core/lib/transport/metadata.h" #include "test/core/end2end/data/ssl_test_data.h" @@ -90,7 +91,7 @@ static uint8_t next_byte(input_stream *inp) { static void end(input_stream *inp) { inp->cur = inp->end; } -static char *read_string(input_stream *inp) { +static char *read_string(input_stream *inp, bool *special) { char *str = NULL; size_t cap = 0; size_t sz = 0; @@ -102,18 +103,53 @@ static char *read_string(input_stream *inp) { } c = (char)next_byte(inp); str[sz++] = c; - } while (c != 0); + } while (c != 0 && c != 1); + if (special != NULL) { + *special = (c == 1); + } return str; } -static void read_buffer(input_stream *inp, char **buffer, size_t *length) { +static void read_buffer(input_stream *inp, char **buffer, size_t *length, + bool *special) { *length = next_byte(inp); + if (*length == 255) { + if (special != NULL) *special = true; + *length = next_byte(inp); + } else { + if (special != NULL) *special = false; + } *buffer = gpr_malloc(*length); for (size_t i = 0; i < *length; i++) { (*buffer)[i] = (char)next_byte(inp); } } +static grpc_slice maybe_intern(grpc_slice s, bool intern) { + grpc_slice r = intern ? grpc_slice_intern(s) : grpc_slice_ref(s); + grpc_slice_unref(s); + return r; +} + +static grpc_slice read_string_like_slice(input_stream *inp) { + bool special; + char *s = read_string(inp, &special); + grpc_slice r = maybe_intern(grpc_slice_from_copied_string(s), special); + gpr_free(s); + return r; +} + +static grpc_slice read_buffer_like_slice(input_stream *inp) { + char *buffer; + size_t length; + bool special; + read_buffer(inp, &buffer, &length, &special); + grpc_slice r = + maybe_intern(grpc_slice_from_copied_buffer(buffer, length), special); + gpr_free(buffer); + return r; +} + static uint32_t read_uint22(input_stream *inp) { uint8_t b = next_byte(inp); uint32_t x = b & 0x7f; @@ -170,12 +206,12 @@ static grpc_channel_args *read_args(input_stream *inp) { switch (next_byte(inp)) { case 1: args[i].type = GRPC_ARG_STRING; - args[i].key = read_string(inp); - args[i].value.string = read_string(inp); + args[i].key = read_string(inp, NULL); + args[i].value.string = read_string(inp, NULL); break; case 2: args[i].type = GRPC_ARG_INTEGER; - args[i].key = read_string(inp); + args[i].key = read_string(inp, NULL); args[i].value.integer = read_int(inp); break; case 3: @@ -217,7 +253,7 @@ static const char *read_cred_artifact(cred_artifact_ctx *ctx, input_stream *inp, size_t num_builtins) { uint8_t b = next_byte(inp); if (b == 0) return NULL; - if (b == 1) return ctx->release[ctx->num_release++] = read_string(inp); + if (b == 1) return ctx->release[ctx->num_release++] = read_string(inp, NULL); if (b >= num_builtins + 1) { end(inp); return NULL; @@ -504,8 +540,7 @@ typedef struct call_state { grpc_status_code status; grpc_metadata_array recv_initial_metadata; grpc_metadata_array recv_trailing_metadata; - char *recv_status_details; - size_t recv_status_details_capacity; + grpc_slice recv_status_details; int cancelled; int pending_ops; grpc_call_details call_details; @@ -519,6 +554,11 @@ typedef struct call_state { size_t cap_to_free; void **to_free; + // array of slices to unref + size_t num_slices_to_unref; + size_t cap_slices_to_unref; + grpc_slice *slices_to_unref; + struct call_state *next; struct call_state *prev; } call_state; @@ -554,12 +594,15 @@ static call_state *maybe_delete_call_state(call_state *call) { call->next->prev = call->prev; grpc_metadata_array_destroy(&call->recv_initial_metadata); grpc_metadata_array_destroy(&call->recv_trailing_metadata); - gpr_free(call->recv_status_details); + grpc_slice_unref(call->recv_status_details); grpc_call_details_destroy(&call->call_details); for (size_t i = 0; i < call->num_to_free; i++) { gpr_free(call->to_free[i]); } + for (size_t i = 0; i < call->num_slices_to_unref; i++) { + grpc_slice_unref(call->slices_to_unref[i]); + } gpr_free(call->to_free); gpr_free(call); @@ -576,6 +619,17 @@ static void add_to_free(call_state *call, void *p) { call->to_free[call->num_to_free++] = p; } +static grpc_slice *add_to_slice_unref(call_state *call, grpc_slice s) { + if (call->num_slices_to_unref == call->cap_slices_to_unref) { + call->cap_slices_to_unref = GPR_MAX(8, 2 * call->cap_slices_to_unref); + call->slices_to_unref = + gpr_realloc(call->slices_to_unref, + sizeof(*call->slices_to_unref) * call->cap_slices_to_unref); + } + call->slices_to_unref[call->num_to_free++] = s; + return &call->slices_to_unref[call->num_to_free - 1]; +} + static void read_metadata(input_stream *inp, size_t *count, grpc_metadata **metadata, call_state *cs) { *count = next_byte(inp); @@ -583,12 +637,11 @@ static void read_metadata(input_stream *inp, size_t *count, *metadata = gpr_malloc(*count * sizeof(**metadata)); memset(*metadata, 0, *count * sizeof(**metadata)); for (size_t i = 0; i < *count; i++) { - (*metadata)[i].key = read_string(inp); - read_buffer(inp, (char **)&(*metadata)[i].value, - &(*metadata)[i].value_length); + (*metadata)[i].key = read_string_like_slice(inp); + (*metadata)[i].value = read_buffer_like_slice(inp); (*metadata)[i].flags = read_uint32(inp); - add_to_free(cs, (void *)(*metadata)[i].key); - add_to_free(cs, (void *)(*metadata)[i].value); + add_to_slice_unref(cs, (*metadata)[i].key); + add_to_slice_unref(cs, (*metadata)[i].value); } } else { *metadata = gpr_malloc(1); @@ -652,7 +705,7 @@ static validator *make_finished_batch_validator(call_state *cs, } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_metadata_hash_seed(0); + grpc_test_only_set_slice_hash_seed(0); if (squelch) gpr_set_log_function(dont_log); input_stream inp = {data, data + size}; grpc_resolve_address = my_resolve_address; @@ -738,7 +791,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // create an insecure channel case 2: { if (g_channel == NULL) { - char *target = read_string(&inp); + char *target = read_string(&inp, NULL); char *target_uri; gpr_asprintf(&target_uri, "dns:%s", target); grpc_channel_args *args = read_args(&inp); @@ -867,8 +920,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { parent_call = g_active_call->call; } uint32_t propagation_mask = read_uint32(&inp); - char *method = read_string(&inp); - char *host = read_string(&inp); + grpc_slice method = read_string_like_slice(&inp); + grpc_slice host = read_string_like_slice(&inp); gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN)); @@ -877,12 +930,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { call_state *cs = new_call(g_active_call, CLIENT); cs->call = grpc_channel_create_call(g_channel, parent_call, propagation_mask, - cq, method, host, deadline, NULL); + cq, method, &host, deadline, NULL); } else { end(&inp); } - gpr_free(method); - gpr_free(host); + grpc_slice_unref(method); + grpc_slice_unref(host); break; } // switch the 'current' call @@ -947,7 +1000,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { g_active_call); op->data.send_status_from_server.status = next_byte(&inp); op->data.send_status_from_server.status_details = - read_string(&inp); + add_to_slice_unref(g_active_call, + read_buffer_like_slice(&inp)); break; case GRPC_OP_RECV_INITIAL_METADATA: op->op = GRPC_OP_RECV_INITIAL_METADATA; @@ -967,8 +1021,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { &g_active_call->recv_trailing_metadata; op->data.recv_status_on_client.status_details = &g_active_call->recv_status_details; - op->data.recv_status_on_client.status_details_capacity = - &g_active_call->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; @@ -1056,14 +1108,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } // enable a tracer case 17: { - char *tracer = read_string(&inp); + char *tracer = read_string(&inp, NULL); grpc_tracer_set_enabled(tracer, 1); gpr_free(tracer); break; } // disable a tracer case 18: { - char *tracer = read_string(&inp); + char *tracer = read_string(&inp, NULL); grpc_tracer_set_enabled(tracer, 0); gpr_free(tracer); break; @@ -1105,7 +1157,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // create a secure channel case 22: { if (g_channel == NULL) { - char *target = read_string(&inp); + char *target = read_string(&inp, NULL); char *target_uri; gpr_asprintf(&target_uri, "dns:%s", target); grpc_channel_args *args = read_args(&inp); diff --git a/test/core/end2end/fuzzers/client_fuzzer.c b/test/core/end2end/fuzzers/client_fuzzer.c index 26b520885bb..0972a4c8e7d 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.c +++ b/test/core/end2end/fuzzers/client_fuzzer.c @@ -37,6 +37,7 @@ #include #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/channel.h" #include "test/core/util/memory_counters.h" #include "test/core/util/mock_endpoint.h" @@ -51,7 +52,7 @@ static void *tag(int n) { return (void *)(uintptr_t)n; } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_metadata_hash_seed(0); + grpc_test_only_set_slice_hash_seed(0); struct grpc_memory_counters counters; if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); @@ -71,9 +72,10 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_channel *channel = grpc_channel_create( &exec_ctx, "test-target", NULL, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_call *call = - grpc_channel_create_call(channel, NULL, 0, cq, "/foo", "localhost", - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_slice host = grpc_slice_from_static_string("localhost"); + grpc_call *call = grpc_channel_create_call( + channel, NULL, 0, cq, grpc_slice_from_static_string("/foo"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array initial_metadata_recv; grpc_metadata_array_init(&initial_metadata_recv); @@ -81,8 +83,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_metadata_array trailing_metadata_recv; grpc_metadata_array_init(&trailing_metadata_recv); grpc_status_code status; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_op ops[6]; memset(ops, 0, sizeof(ops)); @@ -110,7 +111,6 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -155,7 +155,7 @@ done: grpc_completion_queue_destroy(cq); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_channel_destroy(channel); if (response_payload_recv != NULL) { grpc_byte_buffer_destroy(response_payload_recv); diff --git a/test/core/end2end/fuzzers/server_fuzzer.c b/test/core/end2end/fuzzers/server_fuzzer.c index 115fb069252..186542d4b2d 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.c +++ b/test/core/end2end/fuzzers/server_fuzzer.c @@ -34,6 +34,7 @@ #include #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/server.h" #include "test/core/util/memory_counters.h" #include "test/core/util/mock_endpoint.h" @@ -49,7 +50,7 @@ static int detag(void *p) { return (int)(uintptr_t)p; } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_metadata_hash_seed(0); + grpc_test_only_set_slice_hash_seed(0); struct grpc_memory_counters counters; if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); diff --git a/test/core/end2end/goaway_server_test.c b/test/core/end2end/goaway_server_test.c index a8c7b2be5ac..b5187b048ae 100644 --- a/test/core/end2end/goaway_server_test.c +++ b/test/core/end2end/goaway_server_test.c @@ -101,8 +101,7 @@ int main(int argc, char **argv) { grpc_metadata_array request_metadata1; grpc_call_details request_details1; grpc_status_code status1; - char *details1 = NULL; - size_t details_capacity1 = 0; + grpc_slice details1; grpc_metadata_array_init(&trailing_metadata_recv1); grpc_metadata_array_init(&request_metadata1); grpc_call_details_init(&request_details1); @@ -111,8 +110,7 @@ int main(int argc, char **argv) { grpc_metadata_array request_metadata2; grpc_call_details request_details2; grpc_status_code status2; - char *details2 = NULL; - size_t details_capacity2 = 0; + grpc_slice details2; grpc_metadata_array_init(&trailing_metadata_recv2); grpc_metadata_array_init(&request_metadata2); grpc_call_details_init(&request_details2); @@ -129,9 +127,11 @@ int main(int argc, char **argv) { /* create a channel that picks first amongst the servers */ grpc_channel *chan = grpc_insecure_channel_create("test", NULL, NULL); /* and an initial call to them */ - grpc_call *call1 = grpc_channel_create_call( - chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1", - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); + grpc_slice host = grpc_slice_from_static_string("127.0.0.1"); + grpc_call *call1 = + grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/foo"), &host, + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); /* send initial metadata to probe connectivity */ memset(ops, 0, sizeof(ops)); op = ops; @@ -150,7 +150,6 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1; op->data.recv_status_on_client.status = &status1; op->data.recv_status_on_client.status_details = &details1; - op->data.recv_status_on_client.status_details_capacity = &details_capacity1; op->flags = 0; op->reserved = NULL; op++; @@ -205,9 +204,10 @@ int main(int argc, char **argv) { cq_verify_empty(cqv); /* and a new call: should go through to server2 when we start it */ - grpc_call *call2 = grpc_channel_create_call( - chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1", - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); + grpc_call *call2 = + grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/foo"), &host, + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); /* send initial metadata to probe connectivity */ memset(ops, 0, sizeof(ops)); op = ops; @@ -226,7 +226,6 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2; op->data.recv_status_on_client.status = &status2; op->data.recv_status_on_client.status_details = &details2; - op->data.recv_status_on_client.status_details_capacity = &details_capacity2; op->flags = 0; op->reserved = NULL; op++; @@ -292,11 +291,11 @@ int main(int argc, char **argv) { grpc_metadata_array_destroy(&trailing_metadata_recv1); grpc_metadata_array_destroy(&request_metadata1); grpc_call_details_destroy(&request_details1); - gpr_free(details1); + grpc_slice_unref(details1); grpc_metadata_array_destroy(&trailing_metadata_recv2); grpc_metadata_array_destroy(&request_metadata2); grpc_call_details_destroy(&request_details2); - gpr_free(details2); + grpc_slice_unref(details2); cq_verifier_destroy(cqv); grpc_completion_queue_destroy(cq); diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index 765b6ad1bee..3b26ddb6d08 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -56,8 +56,7 @@ struct test_state { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - char *details; - size_t details_capacity; + grpc_slice details; grpc_call *server_call; grpc_server *server; grpc_metadata_array server_initial_metadata_recv; @@ -76,17 +75,16 @@ static void prepare_test(int is_client) { g_state.deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2); g_state.cq = grpc_completion_queue_create(NULL); g_state.cqv = cq_verifier_create(g_state.cq); - g_state.details = NULL; - g_state.details_capacity = 0; memset(g_state.ops, 0, sizeof(g_state.ops)); if (is_client) { /* create a call, channel to a non existant server */ g_state.chan = grpc_insecure_channel_create("nonexistant:54321", NULL, NULL); + grpc_slice host = grpc_slice_from_static_string("nonexistant"); g_state.call = grpc_channel_create_call( - g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, "/Foo", - "nonexistant", g_state.deadline, NULL); + g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, + grpc_slice_from_static_string("/Foo"), &host, g_state.deadline, NULL); } else { g_state.server = grpc_server_create(NULL, NULL); grpc_server_register_completion_queue(g_state.server, g_state.cq, NULL); @@ -97,9 +95,10 @@ static void prepare_test(int is_client) { gpr_join_host_port(&server_hostport, "localhost", port); g_state.chan = grpc_insecure_channel_create(server_hostport, NULL, NULL); gpr_free(server_hostport); + grpc_slice host = grpc_slice_from_static_string("bar"); g_state.call = grpc_channel_create_call( - g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, "/Foo", "bar", - g_state.deadline, NULL); + g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, + grpc_slice_from_static_string("/Foo"), &host, g_state.deadline, NULL); grpc_metadata_array_init(&g_state.server_initial_metadata_recv); grpc_call_details_init(&g_state.call_details); op = g_state.ops; @@ -126,7 +125,7 @@ static void cleanup_test() { grpc_call_destroy(g_state.call); cq_verifier_destroy(g_state.cqv); grpc_channel_destroy(g_state.chan); - gpr_free(g_state.details); + grpc_slice_unref(g_state.details); grpc_metadata_array_destroy(&g_state.initial_metadata_recv); grpc_metadata_array_destroy(&g_state.trailing_metadata_recv); @@ -289,7 +288,8 @@ static void test_send_server_status_from_client() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -398,8 +398,6 @@ static void test_recv_status_on_client_twice() { &g_state.trailing_metadata_recv; op->data.recv_status_on_client.status = &g_state.status; op->data.recv_status_on_client.status_details = &g_state.details; - op->data.recv_status_on_client.status_details_capacity = - &g_state.details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -414,7 +412,6 @@ static void test_recv_status_on_client_twice() { op->data.recv_status_on_client.trailing_metadata = NULL; op->data.recv_status_on_client.status = NULL; op->data.recv_status_on_client.status_details = NULL; - op->data.recv_status_on_client.status_details_capacity = NULL; op->flags = 0; op->reserved = NULL; op++; @@ -453,8 +450,6 @@ static void test_recv_status_on_client_from_server() { &g_state.trailing_metadata_recv; op->data.recv_status_on_client.status = &g_state.status; op->data.recv_status_on_client.status_details = &g_state.details; - op->data.recv_status_on_client.status_details_capacity = - &g_state.details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -474,7 +469,8 @@ static void test_send_status_from_server_with_invalid_flags() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 1; op->reserved = NULL; op++; @@ -495,7 +491,8 @@ static void test_too_many_trailing_metadata() { op->data.send_status_from_server.trailing_metadata_count = (size_t)INT_MAX + 1; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -515,14 +512,15 @@ static void test_send_server_status_twice() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = "xyz"; + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c index 03ff70a1881..5c0f7a0f488 100644 --- a/test/core/end2end/no_server_test.c +++ b/test/core/end2end/no_server_test.c @@ -52,8 +52,7 @@ int main(int argc, char **argv) { grpc_op *op; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_test_init(argc, argv); grpc_init(); @@ -65,8 +64,10 @@ int main(int argc, char **argv) { /* create a call, channel to a non existant server */ chan = grpc_insecure_channel_create("nonexistant:54321", NULL, NULL); + grpc_slice host = grpc_slice_from_static_string("nonexistant"); call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/Foo", "nonexistant", deadline, NULL); + grpc_slice_from_static_string("/Foo"), &host, + deadline, NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -79,7 +80,6 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -101,7 +101,7 @@ int main(int argc, char **argv) { grpc_channel_destroy(chan); cq_verifier_destroy(cqv); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_shutdown(); diff --git a/test/core/fling/client.c b/test/core/fling/client.c index e717b7f7fed..bb44320f34b 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -57,8 +57,7 @@ static grpc_metadata_array initial_metadata_recv; static grpc_metadata_array trailing_metadata_recv; static grpc_byte_buffer *response_payload_recv = NULL; static grpc_status_code status; -static char *details = NULL; -static size_t details_capacity = 0; +static grpc_slice details; static grpc_op *op; static void init_ping_pong_request(void) { @@ -86,15 +85,16 @@ static void init_ping_pong_request(void) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; } static void step_ping_pong_request(void) { GPR_TIMER_BEGIN("ping_pong", 1); - call = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/Reflector/reflectUnary", "localhost", - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_slice host = grpc_slice_from_static_string("localhost"); + call = grpc_channel_create_call( + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/Reflector/reflectUnary"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, (size_t)(op - ops), (void *)1, NULL)); @@ -109,9 +109,11 @@ static void init_ping_pong_stream(void) { grpc_metadata_array_init(&initial_metadata_recv); grpc_call_error error; - call = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/Reflector/reflectStream", "localhost", - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_slice host = grpc_slice_from_static_string("localhost"); + call = grpc_channel_create_call( + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/Reflector/reflectStream"), &host, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); stream_init_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA; stream_init_ops[0].data.send_initial_metadata.count = 0; stream_init_ops[1].op = GRPC_OP_RECV_INITIAL_METADATA; diff --git a/test/core/fling/server.c b/test/core/fling/server.c index fd446f1128e..d4849e3bbe9 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -118,7 +118,7 @@ static void handle_unary_method(void) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.status = GRPC_STATUS_OK; op->data.send_status_from_server.trailing_metadata_count = 0; - op->data.send_status_from_server.status_details = ""; + op->data.send_status_from_server.status_details = NULL; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; @@ -168,7 +168,7 @@ static void start_send_status(void) { status_op[0].op = GRPC_OP_SEND_STATUS_FROM_SERVER; status_op[0].data.send_status_from_server.status = GRPC_STATUS_OK; status_op[0].data.send_status_from_server.trailing_metadata_count = 0; - status_op[0].data.send_status_from_server.status_details = ""; + status_op[0].data.send_status_from_server.status_details = NULL; status_op[1].op = GRPC_OP_RECV_CLOSE_ON_SERVER; status_op[1].data.recv_close_on_server.cancelled = &was_cancelled; @@ -259,8 +259,8 @@ int main(int argc, char **argv) { switch ((intptr_t)s) { case FLING_SERVER_NEW_REQUEST: if (call != NULL) { - if (0 == - strcmp(call_details.method, "/Reflector/reflectStream")) { + if (0 == grpc_slice_str_cmp(call_details.method, + "/Reflector/reflectStream")) { /* Received streaming call. Send metadata here. */ start_read_op(FLING_SERVER_READ_FOR_STREAMING); send_initial_metadata(); diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index 8fd4737c8fa..c8c6eebd601 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -1065,9 +1065,8 @@ static void plugin_get_metadata_success(void *state, *s = PLUGIN_GET_METADATA_CALLED_STATE; for (i = 0; i < GPR_ARRAY_SIZE(plugin_md); i++) { memset(&md[i], 0, sizeof(grpc_metadata)); - md[i].key = plugin_md[i].key; - md[i].value = plugin_md[i].value; - md[i].value_length = strlen(plugin_md[i].value); + md[i].key = grpc_slice_from_copied_string(plugin_md[i].key); + md[i].value = grpc_slice_from_copied_string(plugin_md[i].value); } cb(user_data, md, GPR_ARRAY_SIZE(md), GRPC_STATUS_OK, NULL); } diff --git a/test/core/security/ssl_server_fuzzer.c b/test/core/security/ssl_server_fuzzer.c index 04969765f59..dd81c527625 100644 --- a/test/core/security/ssl_server_fuzzer.c +++ b/test/core/security/ssl_server_fuzzer.c @@ -82,7 +82,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_resource_quota_create("ssl_server_fuzzer"); grpc_endpoint *mock_endpoint = grpc_mock_endpoint_create(discard_write, resource_quota); - grpc_resource_quota_internal_unref(&exec_ctx, resource_quota); + grpc_resource_quota_unref_internal(&exec_ctx, resource_quota); grpc_mock_endpoint_put_read( &exec_ctx, mock_endpoint, @@ -106,7 +106,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // Create security connector grpc_server_security_connector *sc = NULL; grpc_security_status status = - grpc_server_credentials_create_security_connector(creds, &sc); + grpc_server_credentials_create_security_connector(&exec_ctx, creds, &sc); GPR_ASSERT(status == GRPC_SECURITY_OK); sc->channel_args = NULL; gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), @@ -129,7 +129,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { GPR_ASSERT(state.done_callback_called); - GRPC_SECURITY_CONNECTOR_UNREF(&sc->base, "test"); + GRPC_SECURITY_CONNECTOR_UNREF(&exec_ctx, &sc->base, "test"); grpc_server_credentials_release(creds); grpc_slice_unref(cert_slice); grpc_slice_unref(key_slice); diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index a14f15ccfa3..ddb66f9deac 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -62,8 +62,10 @@ static void test_slice_malloc_returns_something_sensible(void) { GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == length); /* If the slice has a refcount, it must be destroyable. */ if (slice.refcount) { - GPR_ASSERT(slice.refcount->ref != NULL); - GPR_ASSERT(slice.refcount->unref != NULL); + GPR_ASSERT(slice.refcount->vtable != NULL); + GPR_ASSERT(slice.refcount->vtable->ref != NULL); + GPR_ASSERT(slice.refcount->vtable->unref != NULL); + GPR_ASSERT(slice.refcount->vtable->hash != NULL); } /* We must be able to write to every byte of the data */ for (i = 0; i < length; i++) { diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index 6afcefca923..4ab8715f706 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -88,8 +88,7 @@ int main(int argc, char **argv) { grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; char *peer; grpc_test_init(argc, argv); @@ -109,8 +108,9 @@ int main(int argc, char **argv) { cq = grpc_completion_queue_create(NULL); + grpc_slice host = grpc_slice_from_static_string("anywhere"); call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - "/Foo", "anywhere", + grpc_slice_from_static_string("/Foo"), &host, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100), NULL); GPR_ASSERT(call); cqv = cq_verifier_create(cq); @@ -140,7 +140,6 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -162,7 +161,7 @@ int main(int argc, char **argv) { grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - gpr_free(details); + grpc_slice_unref(details); grpc_shutdown(); diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c index 53b55a301e2..778606a78cb 100644 --- a/test/core/transport/chttp2/bin_encoder_test.c +++ b/test/core/transport/chttp2/bin_encoder_test.c @@ -84,7 +84,7 @@ static void expect_combined_equiv(const char *s, size_t len, int line) { grpc_slice input = grpc_slice_from_copied_buffer(s, len); grpc_slice base64 = grpc_chttp2_base64_encode(input); grpc_slice expect = grpc_chttp2_huffman_compress(base64); - grpc_slice got = grpc_chttp2_base64_encode_and_huffman_compress_impl(input); + grpc_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input); if (0 != grpc_slice_cmp(expect, got)) { char *t = grpc_dump_slice(input, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *e = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -106,7 +106,7 @@ static void expect_combined_equiv(const char *s, size_t len, int line) { expect_combined_equiv(x, sizeof(x) - 1, __LINE__) static void expect_binary_header(const char *hdr, int binary) { - if (grpc_is_binary_header(hdr, strlen(hdr)) != binary) { + if (grpc_is_binary_header(grpc_slice_from_static_string(hdr)) != binary) { gpr_log(GPR_ERROR, "FAILED: expected header '%s' to be %s", hdr, binary ? "binary" : "not binary"); all_ok = 0; diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index 1fd2540d652..817a9636bfa 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -81,7 +81,9 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, e[i - 1].next = &e[i]; e[i].prev = &e[i - 1]; } - e[i].md = grpc_mdelem_from_strings(exec_ctx, key, value); + e[i].md = + grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); } e[0].prev = NULL; e[nheaders - 1].next = NULL; @@ -193,7 +195,9 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value) { grpc_slice_buffer output; - grpc_mdelem *elem = grpc_mdelem_from_strings(exec_ctx, key, value); + grpc_mdelem *elem = + grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t initial_table_size = g_compressor.table_size; grpc_linked_mdelem *e = gpr_malloc(sizeof(*e)); @@ -233,7 +237,7 @@ static void run_test(void (*test)(grpc_exec_ctx *exec_ctx), const char *name) { int main(int argc, char **argv) { size_t i; - grpc_test_only_set_metadata_hash_seed(0); + grpc_test_only_set_slice_hash_seed(0); grpc_test_init(argc, argv); grpc_init(); TEST(test_basic_headers); diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index 4e00f49b664..b3b3f7ac7c4 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -39,6 +39,7 @@ #include #include "src/core/ext/transport/chttp2/transport/hpack_parser.h" +#include "src/core/lib/slice/slice_internal.h" bool squelch = true; bool leak_check = true; @@ -49,7 +50,7 @@ static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_metadata_hash_seed(0); + grpc_test_only_set_slice_hash_seed(0); if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 8f48849c974..6d2b4111c2e 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -52,8 +52,8 @@ static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { GPR_ASSERT(ekey); evalue = va_arg(chk->args, char *); GPR_ASSERT(evalue); - GPR_ASSERT(grpc_slice_str_cmp(md->key->slice, ekey) == 0); - GPR_ASSERT(grpc_slice_str_cmp(md->value->slice, evalue) == 0); + GPR_ASSERT(grpc_slice_str_cmp(md->key, ekey) == 0); + GPR_ASSERT(grpc_slice_str_cmp(md->value, evalue) == 0); GRPC_MDELEM_UNREF(exec_ctx, md); } diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index ef2ad66b5ca..695846399ee 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -46,9 +46,9 @@ #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) -static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr, +static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_slice mdstr, const char *str) { - GPR_ASSERT(grpc_slice_str_cmp(mdstr->slice, str) == 0); + GPR_ASSERT(grpc_slice_str_cmp(mdstr, str) == 0); } static void assert_index(const grpc_chttp2_hptbl *tbl, uint32_t idx, @@ -146,7 +146,9 @@ static void test_many_additions(void) { grpc_mdelem *elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = grpc_mdelem_from_strings(&exec_ctx, key, value); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); @@ -169,7 +171,9 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, const char *key, const char *value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem *md = grpc_mdelem_from_strings(&exec_ctx, key, value); + grpc_mdelem *md = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), + grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); GRPC_MDELEM_UNREF(&exec_ctx, md); grpc_exec_ctx_finish(&exec_ctx); @@ -187,13 +191,18 @@ static void test_find(void) { LOG_TEST("test_find"); grpc_chttp2_hptbl_init(&exec_ctx, &tbl); - elem = grpc_mdelem_from_strings(&exec_ctx, "abc", "xyz"); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("xyz")); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_strings(&exec_ctx, "abc", "123"); + elem = + grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), + grpc_slice_from_static_string("123")); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_strings(&exec_ctx, "x", "1"); + elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), + grpc_slice_from_static_string("1")); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); @@ -244,7 +253,9 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_strings(&exec_ctx, "test", buffer); + elem = grpc_mdelem_from_slices(&exec_ctx, + grpc_slice_from_static_string("test"), + grpc_slice_from_copied_string(buffer)); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); } diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 3625043d077..bbe31f9c9e7 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -47,55 +47,45 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" -#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) - /* a large number */ #define MANY 10000 static void test_no_op(void) { - LOG_TEST("test_no_op"); + gpr_log(GPR_INFO, "test_no_op"); grpc_init(); grpc_shutdown(); } -static void test_create_string(void) { - grpc_mdstr *s1, *s2, *s3; - - LOG_TEST("test_create_string"); - - grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - s1 = grpc_mdstr_from_string("hello"); - s2 = grpc_mdstr_from_string("hello"); - s3 = grpc_mdstr_from_string("very much not hello"); - GPR_ASSERT(s1 == s2); - GPR_ASSERT(s3 != s1); - GPR_ASSERT(grpc_slice_str_cmp(s1->slice, "hello") == 0); - GPR_ASSERT(grpc_slice_str_cmp(s3->slice, "very much not hello") == 0); - GRPC_MDSTR_UNREF(&exec_ctx, s1); - GRPC_MDSTR_UNREF(&exec_ctx, s2); - GRPC_MDSTR_UNREF(&exec_ctx, s3); - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); +static grpc_slice maybe_intern(grpc_slice in, bool intern) { + grpc_slice out = intern ? grpc_slice_intern(in) : grpc_slice_ref(in); + grpc_slice_unref(in); + return out; } -static void test_create_metadata(void) { +static void test_create_metadata(bool intern_keys, bool intern_values) { grpc_mdelem *m1, *m2, *m3; - LOG_TEST("test_create_metadata"); + gpr_log(GPR_INFO, "test_create_metadata: intern_keys=%d intern_values=%d", + intern_keys, intern_values); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - m1 = grpc_mdelem_from_strings(&exec_ctx, "a", "b"); - m2 = grpc_mdelem_from_strings(&exec_ctx, "a", "b"); - m3 = grpc_mdelem_from_strings(&exec_ctx, "a", "c"); + m1 = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values)); + m2 = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values)); + m3 = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("c"), intern_values)); GPR_ASSERT(m1 == m2); GPR_ASSERT(m3 != m1); - GPR_ASSERT(m3->key == m1->key); - GPR_ASSERT(m3->value != m1->value); - GPR_ASSERT(grpc_slice_str_cmp(m1->key->slice, "a") == 0); - GPR_ASSERT(grpc_slice_str_cmp(m1->value->slice, "b") == 0); - GPR_ASSERT(grpc_slice_str_cmp(m3->value->slice, "c") == 0); + GPR_ASSERT(grpc_slice_cmp(m3->key, m1->key) == 0); + GPR_ASSERT(grpc_slice_cmp(m3->value, m1->value) != 0); + GPR_ASSERT(grpc_slice_str_cmp(m1->key, "a") == 0); + GPR_ASSERT(grpc_slice_str_cmp(m1->value, "b") == 0); + GPR_ASSERT(grpc_slice_str_cmp(m3->value, "c") == 0); GRPC_MDELEM_UNREF(&exec_ctx, m1); GRPC_MDELEM_UNREF(&exec_ctx, m2); GRPC_MDELEM_UNREF(&exec_ctx, m3); @@ -103,19 +93,28 @@ static void test_create_metadata(void) { grpc_shutdown(); } -static void test_create_many_ephemeral_metadata(void) { +static void test_create_many_ephemeral_metadata(bool intern_keys, + bool intern_values) { char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; - LOG_TEST("test_create_many_ephemeral_metadata"); + gpr_log( + GPR_INFO, + "test_create_many_ephemeral_metadata: intern_keys=%d intern_values=%d", + intern_keys, intern_values); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF(&exec_ctx, - grpc_mdelem_from_strings(&exec_ctx, "a", buffer)); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_from_slices( + &exec_ctx, + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_copied_string(buffer), + intern_values))); } grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); @@ -127,19 +126,23 @@ static void test_create_many_persistant_metadata(void) { grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); grpc_mdelem *md; - LOG_TEST("test_create_many_persistant_metadata"); + gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - created[i] = grpc_mdelem_from_strings(&exec_ctx, "a", buffer); + created[i] = grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_copied_string(buffer))); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - md = grpc_mdelem_from_strings(&exec_ctx, "a", buffer); + md = grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), + grpc_slice_intern(grpc_slice_from_copied_string(buffer))); GPR_ASSERT(md == created[i]); GRPC_MDELEM_UNREF(&exec_ctx, md); } @@ -153,14 +156,32 @@ static void test_create_many_persistant_metadata(void) { gpr_free(created); } -static void test_spin_creating_the_same_thing(void) { - LOG_TEST("test_spin_creating_the_same_thing"); +static void test_spin_creating_the_same_thing(bool intern_keys, + bool intern_values) { + gpr_log(GPR_INFO, + "test_spin_creating_the_same_thing: intern_keys=%d intern_values=%d", + intern_keys, intern_values); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); - GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_from_slices( + &exec_ctx, + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_from_slices( + &exec_ctx, + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values))); + GRPC_MDELEM_UNREF( + &exec_ctx, + grpc_mdelem_from_slices( + &exec_ctx, + maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values))); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -169,25 +190,25 @@ static void test_things_stick_around(void) { size_t i, j; char *buffer; size_t nstrs = 1000; - grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs); + grpc_slice *strs = gpr_malloc(sizeof(grpc_slice *) * nstrs); size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); - grpc_mdstr *test; + grpc_slice test; - LOG_TEST("test_things_stick_around"); + gpr_log(GPR_INFO, "test_things_stick_around"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); - strs[i] = grpc_mdstr_from_string(buffer); + strs[i] = grpc_slice_intern(grpc_slice_from_static_string(buffer)); shuf[i] = i; gpr_free(buffer); } for (i = 0; i < nstrs; i++) { - GRPC_MDSTR_REF(strs[i]); - GRPC_MDSTR_UNREF(&exec_ctx, strs[i]); + grpc_slice_ref_internal(strs[i]); + grpc_slice_unref_internal(&exec_ctx, strs[i]); } for (i = 0; i < nstrs; i++) { @@ -199,13 +220,13 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - GRPC_MDSTR_UNREF(&exec_ctx, strs[shuf[i]]); + grpc_slice_unref_internal(&exec_ctx, strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); - test = grpc_mdstr_from_string(buffer); - GPR_ASSERT(test == strs[shuf[j]]); - GRPC_MDSTR_UNREF(&exec_ctx, test); + test = grpc_slice_intern(grpc_slice_from_static_string(buffer)); + GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); + grpc_slice_unref_internal(&exec_ctx, test); gpr_free(buffer); } } @@ -216,57 +237,11 @@ static void test_things_stick_around(void) { gpr_free(shuf); } -static void test_slices_work(void) { - /* ensure no memory leaks when switching representation from mdstr to slice */ - grpc_mdstr *str; - grpc_slice slice; - - LOG_TEST("test_slices_work"); - - grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - str = grpc_mdstr_from_string( - "123456789012345678901234567890123456789012345678901234567890"); - slice = grpc_slice_ref(str->slice); - GRPC_MDSTR_UNREF(&exec_ctx, str); - grpc_slice_unref_internal(&exec_ctx, slice); - - str = grpc_mdstr_from_string( - "123456789012345678901234567890123456789012345678901234567890"); - slice = grpc_slice_ref(str->slice); - grpc_slice_unref_internal(&exec_ctx, slice); - GRPC_MDSTR_UNREF(&exec_ctx, str); - - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); -} - -static void test_base64_and_huffman_works(void) { - grpc_mdstr *str; - grpc_slice slice1; - grpc_slice slice2; - - LOG_TEST("test_base64_and_huffman_works"); - - grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - str = grpc_mdstr_from_string("abcdefg"); - slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str); - slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice); - GPR_ASSERT(0 == grpc_slice_cmp(slice1, slice2)); - - grpc_slice_unref_internal(&exec_ctx, slice2); - GRPC_MDSTR_UNREF(&exec_ctx, str); - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); -} - static void test_user_data_works(void) { int *ud1; int *ud2; grpc_mdelem *md; - LOG_TEST("test_user_data_works"); + gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -274,7 +249,9 @@ static void test_user_data_works(void) { *ud1 = 1; ud2 = gpr_malloc(sizeof(int)); *ud2 = 2; - md = grpc_mdelem_from_strings(&exec_ctx, "abc", "123"); + md = grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), + grpc_slice_intern(grpc_slice_from_static_string("123"))); grpc_mdelem_set_user_data(md, gpr_free, ud1); grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); @@ -285,7 +262,9 @@ static void test_user_data_works(void) { static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value) { - grpc_mdelem *elem = grpc_mdelem_from_strings(exec_ctx, key, value); + grpc_mdelem *elem = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); @@ -294,9 +273,10 @@ static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, const uint8_t *value, size_t value_len) { - grpc_mdelem *elem = - grpc_mdelem_from_string_and_buffer(exec_ctx, key, value, value_len); - GPR_ASSERT(grpc_is_binary_header(key, strlen(key))); + grpc_mdelem *elem = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_buffer(value, value_len))); + GPR_ASSERT(grpc_is_binary_header(elem->key)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); grpc_slice value_slice = grpc_slice_from_copied_buffer((const char *)value, value_len); @@ -310,7 +290,7 @@ static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, #define BUFFER_SIZE 64 static void test_mdelem_sizes_in_hpack(void) { - LOG_TEST("test_mdelem_size"); + gpr_log(GPR_INFO, "test_mdelem_size"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -328,11 +308,6 @@ static void test_mdelem_sizes_in_hpack(void) { verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i); } - const char *static_metadata = grpc_static_metadata_strings[0]; - memcpy(binary_value, static_metadata, strlen(static_metadata)); - verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, - strlen(static_metadata)); - grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -340,14 +315,15 @@ static void test_mdelem_sizes_in_hpack(void) { int main(int argc, char **argv) { grpc_test_init(argc, argv); test_no_op(); - test_create_string(); - test_create_metadata(); - test_create_many_ephemeral_metadata(); + for (int k = 0; k <= 1; k++) { + for (int v = 0; v <= 1; v++) { + test_create_metadata(k, v); + test_create_many_ephemeral_metadata(k, v); + test_spin_creating_the_same_thing(k, v); + } + } test_create_many_persistant_metadata(); - test_spin_creating_the_same_thing(); test_things_stick_around(); - test_slices_work(); - test_base64_and_huffman_works(); test_user_data_works(); test_mdelem_sizes_in_hpack(); return 0; diff --git a/test/core/transport/timeout_encoding_test.c b/test/core/transport/timeout_encoding_test.c index b6004af7b47..23b1eb577b0 100644 --- a/test/core/transport/timeout_encoding_test.c +++ b/test/core/transport/timeout_encoding_test.c @@ -88,7 +88,8 @@ void test_encoding(void) { static void assert_decodes_as(const char *buffer, gpr_timespec expected) { gpr_timespec got; gpr_log(GPR_INFO, "check decoding '%s'", buffer); - GPR_ASSERT(1 == grpc_http2_decode_timeout(buffer, &got)); + GPR_ASSERT(1 == grpc_http2_decode_timeout((const uint8_t *)buffer, + strlen(buffer), &got)); GPR_ASSERT(0 == gpr_time_cmp(got, expected)); } @@ -134,18 +135,22 @@ void test_decoding(void) { assert_decodes_as("9999999999S", gpr_inf_future(GPR_TIMESPAN)); } -void test_decoding_fails(void) { +static void assert_decoding_fails(const char *s) { gpr_timespec x; + GPR_ASSERT(0 == grpc_http2_decode_timeout((const uint8_t *)s, strlen(s), &x)); +} + +void test_decoding_fails(void) { LOG_TEST("test_decoding_fails"); - GPR_ASSERT(0 == grpc_http2_decode_timeout("", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout(" ", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("x", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("1", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("1x", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("1ux", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("!", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("n1", &x)); - GPR_ASSERT(0 == grpc_http2_decode_timeout("-1u", &x)); + assert_decoding_fails(""); + assert_decoding_fails(" "); + assert_decoding_fails("x"); + assert_decoding_fails("1"); + assert_decoding_fails("1x"); + assert_decoding_fails("1ux"); + assert_decoding_fails("!"); + assert_decoding_fails("n1"); + assert_decoding_fails("-1u"); } int main(int argc, char **argv) { From 58317fcc8900bc0dceb78b397bc14fc026eff035 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 13:39:09 -0800 Subject: [PATCH 022/261] Fix mis-sized array --- test/core/transport/metadata_test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index bbe31f9c9e7..fbcd16c994b 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -190,7 +190,7 @@ static void test_things_stick_around(void) { size_t i, j; char *buffer; size_t nstrs = 1000; - grpc_slice *strs = gpr_malloc(sizeof(grpc_slice *) * nstrs); + grpc_slice *strs = gpr_malloc(sizeof(grpc_slice ) * nstrs); size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); grpc_slice test; From 7885d1abe7565a67834fa3badfed83890a7613db Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 14:07:45 -0800 Subject: [PATCH 023/261] Initial fixes --- src/core/lib/channel/http_server_filter.c | 2 +- src/core/lib/transport/static_metadata.c | 338 +++++++++++++++++++++- src/core/lib/transport/static_metadata.h | 2 - test/core/end2end/fuzzers/api_fuzzer.c | 3 + test/core/iomgr/ev_epoll_linux_test.c | 7 +- tools/codegen/core/gen_static_metadata.py | 14 +- 6 files changed, 344 insertions(+), 22 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index d8393337cd4..41c33899b0e 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -131,7 +131,7 @@ static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, /* TODO(klempner): Track that we've seen all the headers we should require */ return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE)) { + } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) { if (grpc_slice_buf_start_eq(md->value, EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) && (GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index b30b8a046bd..7702b7cdfc3 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -400,7 +400,6 @@ int grpc_static_metadata_index(grpc_slice slice) { return id == 255 ? -1 : id; } -grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 6, 2, 4, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -456,16 +455,331 @@ grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) { return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL; } -const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = - {11, 33, 10, 33, 12, 33, 12, 54, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, - 19, 33, 20, 33, 21, 33, 22, 33, 23, 33, 24, 33, 25, 33, 26, 33, 27, 33, - 28, 18, 28, 33, 29, 33, 30, 33, 34, 33, 35, 33, 36, 33, 37, 33, 40, 31, - 40, 32, 40, 53, 40, 58, 40, 59, 40, 60, 40, 61, 45, 31, 45, 53, 45, 58, - 50, 0, 50, 1, 50, 2, 55, 33, 62, 33, 63, 33, 64, 33, 65, 33, 66, 33, - 67, 33, 68, 33, 69, 33, 70, 33, 71, 33, 72, 33, 73, 38, 73, 75, 73, 78, - 74, 86, 74, 88, 76, 33, 77, 33, 79, 33, 80, 33, 81, 33, 82, 33, 83, 39, - 83, 56, 83, 57, 84, 33, 85, 33, 89, 3, 89, 4, 89, 5, 89, 6, 89, 7, - 89, 8, 89, 9, 90, 33, 91, 92, 93, 33, 94, 33, 95, 33, 96, 33, 97, 33}; - +grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 30, .length = 14}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 24, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 13}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 59, .length = 15}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 74, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 87, .length = 27}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 114, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 117, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 138, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 148, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 161, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 174, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 193, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 209, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 225, .length = 14}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 239, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 255, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 122, .length = 16}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 280, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 286, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 313, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 319, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 326, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 297, .length = 12}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 611, .length = 16}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 627, .length = 21}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 648, .length = 13}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 0, .length = 1}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 1, .length = 1}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 2, .length = 1}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 590, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 661, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 669, .length = 17}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 686, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 699, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 707, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 726, .length = 13}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 739, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 750, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 762, .length = 8}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 770, .length = 12}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 330, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 794, .length = 4}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 835, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 891, .length = 1}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 928, .length = 11}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 798, .length = 18}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 816, .length = 19}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 838, .length = 5}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 850, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 857, .length = 11}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 333, .length = 4}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 4}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 598, .length = 5}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 875, .length = 6}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 881, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 3, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 6, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 9, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 12, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 15, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 18, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 21, .length = 3}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 946, .length = 25}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 971, .length = 2}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 973, .length = 8}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 981, .length = 17}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 998, .length = 10}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 1008, .length = 4}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 1012, .length = 3}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 1015, .length = 16}}, + {.refcount = &g_refcnt, + .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, +}; const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, 28, 32, 27, 31}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 282a3231cab..65cb37d4448 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -425,8 +425,6 @@ extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; #define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[80]) grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b); -extern const uint8_t - grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2]; extern const uint8_t grpc_static_accept_encoding_metadata[8]; #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]) diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index a43941b396a..c9d5c247984 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -107,6 +107,9 @@ static char *read_string(input_stream *inp, bool *special) { if (special != NULL) { *special = (c == 1); } + if (c == 1) { + str[sz-1] = 0; + } return str; } diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c index 564b05d7f4c..81e9fe855ec 100644 --- a/test/core/iomgr/ev_epoll_linux_test.c +++ b/test/core/iomgr/ev_epoll_linux_test.c @@ -236,7 +236,12 @@ int main(int argc, char **argv) { "strategy. and the current strategy is: '%s'", poll_strategy); } - grpc_iomgr_shutdown(); + + { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_iomgr_shutdown(&exec_ctx); + grpc_exec_ctx_finish(&exec_ctx); + } return 0; } #else /* defined(GRPC_LINUX_EPOLL) */ diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 05572ea38b8..614b0efaa6a 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -321,8 +321,12 @@ print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = str_ofs = 0 revmap = {} zero_length_idx = None +id2strofs = {} +def slice_def(i): + return '{.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes+%d, .length=%d}}' % (id2strofs[i], len(all_strs[i])) for i, elem in enumerate(all_strs): - print >>C, '{.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes+%d, .length=%d}},' % (str_ofs, len(elem)) + id2strofs[i] = str_ofs + print >>C, slice_def(i) + ',' revmap[str_ofs] = i if len(elem) == 0: zero_length_idx = i str_ofs += len(elem); @@ -353,7 +357,6 @@ for i, elem in enumerate(all_elems): print >>H, '/* "%s": "%s" */' % elem print >>H, '#define %s (&grpc_static_mdelem_table[%d])' % (mangle(elem).upper(), i) print >>H -print >>C, 'grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' print >>C, 'uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = {' print >>C, ' %s' % ','.join('%d' % static_userdata.get(elem, 0) for elem in all_elems) print >>C, '};' @@ -437,11 +440,10 @@ print >>C, ' return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] print >>C, '}' print >>C -print >>H, 'extern const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2];' -print >>C, 'const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2] = {' -print >>C, ','.join('%d' % str_idx(x) for x in itertools.chain.from_iterable([a,b] for a, b in all_elems)) +print >>C, 'grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' +for a, b in all_elems: + print >>C, '{%s,%s},' % (slice_def(str_idx(a)), slice_def(str_idx(b))) print >>C, '};' -print >>C print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) From 1961436b933e460ba717f011470b5cf9a563bb2d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 16:05:27 -0800 Subject: [PATCH 024/261] Fix static string interning --- src/core/lib/slice/slice_intern.c | 58 ++++++++++++++++++++++- src/core/lib/slice/slice_internal.h | 1 + src/core/lib/transport/static_metadata.c | 4 +- src/core/lib/transport/static_metadata.h | 1 + test/core/slice/slice_test.c | 38 +++++++++++++++ tools/codegen/core/gen_static_metadata.py | 5 +- 6 files changed, 103 insertions(+), 4 deletions(-) diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index b5e00a38d7e..b574ef5f76c 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -72,6 +72,16 @@ static int g_forced_hash_seed = 0; static slice_shard g_shards[SHARD_COUNT]; +typedef struct { + uint32_t hash; + uint32_t idx; +} static_metadata_hash_ent; + +static static_metadata_hash_ent + static_metadata_hash[2 * GRPC_STATIC_MDSTR_COUNT]; +static uint32_t max_static_metadata_hash_probe; +static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT]; + static void interned_slice_ref(void *p) { interned_slice_refcount *s = p; GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0); @@ -152,15 +162,35 @@ uint32_t grpc_slice_default_hash_impl(void *unused_refcnt, grpc_slice s) { g_hash_seed); } +uint32_t grpc_static_slice_hash(void *unused_refcnt, grpc_slice s) { + int id = grpc_static_metadata_index(s); + if (id == -1) { + return grpc_slice_default_hash_impl(unused_refcnt, s); + } + return static_metadata_hash_values[id]; +} + uint32_t grpc_slice_hash(grpc_slice s) { return s.refcount == NULL ? grpc_slice_default_hash_impl(NULL, s) : s.refcount->vtable->hash(s.refcount, s); } grpc_slice grpc_slice_intern(grpc_slice slice) { + if (grpc_is_static_metadata_string(slice)) { + return slice; + } + + uint32_t hash = grpc_slice_hash(slice); + for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { + static_metadata_hash_ent ent = + static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; + if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && + 0 == grpc_slice_cmp(grpc_static_slice_table[ent.idx], slice)) { + return grpc_static_slice_table[ent.idx]; + } + } + interned_slice_refcount *s; - uint32_t hash = gpr_murmur_hash3(GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_LENGTH(slice), g_hash_seed); slice_shard *shard = &g_shards[SHARD_IDX(hash)]; gpr_mu_lock(&shard->mu); @@ -212,6 +242,9 @@ void grpc_test_only_set_slice_hash_seed(uint32_t seed) { } void grpc_slice_intern_init(void) { + if (!g_forced_hash_seed) { + g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; + } for (size_t i = 0; i < SHARD_COUNT; i++) { slice_shard *shard = &g_shards[i]; gpr_mu_init(&shard->mu); @@ -220,6 +253,27 @@ void grpc_slice_intern_init(void) { shard->strs = gpr_malloc(sizeof(*shard->strs) * shard->capacity); memset(shard->strs, 0, sizeof(*shard->strs) * shard->capacity); } + for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) { + static_metadata_hash[i].hash = 0; + static_metadata_hash[i].idx = GRPC_STATIC_MDSTR_COUNT; + } + max_static_metadata_hash_probe = 0; + for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { + static_metadata_hash_values[i] = + grpc_slice_default_hash_impl(NULL, grpc_static_slice_table[i]); + for (size_t j = 0; j < GPR_ARRAY_SIZE(static_metadata_hash); j++) { + size_t slot = (static_metadata_hash_values[i] + j) % + GPR_ARRAY_SIZE(static_metadata_hash); + if (static_metadata_hash[slot].idx == GRPC_STATIC_MDSTR_COUNT) { + static_metadata_hash[slot].hash = static_metadata_hash_values[i]; + static_metadata_hash[slot].idx = (uint32_t)i; + if (j > max_static_metadata_hash_probe) { + max_static_metadata_hash_probe = (uint32_t)j; + } + break; + } + } + } } void grpc_slice_intern_shutdown(void) { diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index bf9117c74e0..c02a34b9fc5 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -49,5 +49,6 @@ void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); void grpc_test_only_set_slice_hash_seed(uint32_t key); +uint32_t grpc_static_slice_hash(void *refcnt, grpc_slice s); #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 7702b7cdfc3..b065af73f97 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -41,6 +41,8 @@ #include "src/core/lib/transport/static_metadata.h" +#include "src/core/lib/slice/slice_internal.h" + static uint8_t g_raw_bytes[] = { 48, 49, 50, 50, 48, 48, 50, 48, 52, 50, 48, 54, 51, 48, 52, 52, 48, 48, 52, 48, 52, 53, 48, 48, 97, 99, 99, 101, 112, 116, @@ -115,7 +117,7 @@ static uint8_t g_raw_bytes[] = { static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable static_vtable = { - static_ref, static_unref, grpc_slice_default_hash_impl}; + static_ref, static_unref, grpc_static_slice_hash}; static grpc_slice_refcount g_refcnt = {&static_vtable}; bool grpc_is_static_metadata_string(grpc_slice slice) { diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 65cb37d4448..6f1441f2e8e 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -249,6 +249,7 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; bool grpc_is_static_metadata_string(grpc_slice slice); +int grpc_static_metadata_index(grpc_slice slice); #define GRPC_STATIC_MDELEM_COUNT 81 extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index ddb66f9deac..ddce1d29b05 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -38,6 +38,9 @@ #include #include #include + +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x); @@ -272,9 +275,42 @@ static void test_slice_interning(void) { grpc_shutdown(); } +static void test_static_slice_interning(void) { + LOG_TEST_NAME("test_static_slice_interning"); + + // grpc_init/grpc_shutdown deliberately omitted: they should not be necessary + // to intern a static slice + + for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { + GPR_ASSERT(grpc_slice_is_equivalent( + grpc_static_slice_table[i], + grpc_slice_intern(grpc_static_slice_table[i]))); + } +} + +static void test_static_slice_copy_interning(void) { + LOG_TEST_NAME("test_static_slice_copy_interning"); + + grpc_init(); + + for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { + grpc_slice copy = + grpc_slice_malloc(GRPC_SLICE_LENGTH(grpc_static_slice_table[i])); + memcpy(GRPC_SLICE_START_PTR(copy), + GRPC_SLICE_START_PTR(grpc_static_slice_table[i]), + GRPC_SLICE_LENGTH(grpc_static_slice_table[i])); + GPR_ASSERT(grpc_slice_is_equivalent(grpc_static_slice_table[i], + grpc_slice_intern(copy))); + grpc_slice_unref(copy); + } + + grpc_shutdown(); +} + int main(int argc, char **argv) { unsigned length; grpc_test_init(argc, argv); + grpc_test_only_set_slice_hash_seed(0); test_slice_malloc_returns_something_sensible(); test_slice_new_returns_something_sensible(); test_slice_new_with_user_data(); @@ -286,5 +322,7 @@ int main(int argc, char **argv) { } test_slice_from_copied_string_works(); test_slice_interning(); + test_static_slice_interning(); + test_static_slice_copy_interning(); return 0; } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 614b0efaa6a..c5519c44ad0 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -297,6 +297,8 @@ print >>H print >>C, '#include "src/core/lib/transport/static_metadata.h"' print >>C +print >>C, '#include "src/core/lib/slice/slice_internal.h"' +print >>C print >>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' @@ -310,7 +312,7 @@ print >>C, 'static uint8_t g_raw_bytes[] = {%s};' % (','.join('%d' % ord(c) for print >>C print >>C, 'static void static_ref(void *unused) {}' print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' -print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_slice_default_hash_impl};'; +print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_static_slice_hash};'; print >>C, 'static grpc_slice_refcount g_refcnt = {&static_vtable};' print >>C print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' @@ -334,6 +336,7 @@ print >>C, '};' print >>C print >>C, 'static const uint8_t g_revmap[] = {%s};' % ','.join('%d' % (revmap[i] if i in revmap else 255) for i in range(0, str_ofs)) print >>C +print >>H, 'int grpc_static_metadata_index(grpc_slice slice);' print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {' print >>C, ' if (GRPC_SLICE_LENGTH(slice) == 0) return %d;' % zero_length_idx print >>C, ' size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);' From 299dbe4e301d3eb76dd4f7ca4ecac351ed6c1948 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 16:18:54 -0800 Subject: [PATCH 025/261] Refining test --- test/core/transport/metadata_test.c | 51 +++++++++++++++++++---------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index fbcd16c994b..a40da11e374 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -164,24 +164,33 @@ static void test_spin_creating_the_same_thing(bool intern_keys, grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem *a, *b, *c; GRPC_MDELEM_UNREF( &exec_ctx, - grpc_mdelem_from_slices( + a = grpc_mdelem_from_slices( &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( &exec_ctx, - grpc_mdelem_from_slices( + b = grpc_mdelem_from_slices( &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); GRPC_MDELEM_UNREF( &exec_ctx, - grpc_mdelem_from_slices( + c = grpc_mdelem_from_slices( &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); + if (intern_keys && intern_values) { + GPR_ASSERT(a == b); + GPR_ASSERT(a == c); + } else { + GPR_ASSERT(a != b); + GPR_ASSERT(a != c); + GPR_ASSERT(b != c); + } grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -190,7 +199,7 @@ static void test_things_stick_around(void) { size_t i, j; char *buffer; size_t nstrs = 1000; - grpc_slice *strs = gpr_malloc(sizeof(grpc_slice ) * nstrs); + grpc_slice *strs = gpr_malloc(sizeof(grpc_slice) * nstrs); size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); grpc_slice test; @@ -261,10 +270,11 @@ static void test_user_data_works(void) { } static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, - const char *value) { + const char *value, bool intern_key, + bool intern_value) { grpc_mdelem *elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - grpc_slice_intern(grpc_slice_from_static_string(value))); + exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_string(value), intern_value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); @@ -272,10 +282,12 @@ static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, } static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, - const uint8_t *value, size_t value_len) { + const uint8_t *value, size_t value_len, + bool intern_key, bool intern_value) { grpc_mdelem *elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - grpc_slice_intern(grpc_slice_from_static_buffer(value, value_len))); + exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), + maybe_intern(grpc_slice_from_static_buffer(value, value_len), + intern_value)); GPR_ASSERT(grpc_is_binary_header(elem->key)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); grpc_slice value_slice = @@ -289,8 +301,9 @@ static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, } #define BUFFER_SIZE 64 -static void test_mdelem_sizes_in_hpack(void) { - gpr_log(GPR_INFO, "test_mdelem_size"); +static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { + gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", + intern_key, intern_value); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -299,13 +312,17 @@ static void test_mdelem_sizes_in_hpack(void) { binary_value[i] = i; } - verify_ascii_header_size(&exec_ctx, "hello", "world"); + verify_ascii_header_size(&exec_ctx, "hello", "world", intern_key, + intern_value); verify_ascii_header_size(&exec_ctx, "hello", - "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); - verify_ascii_header_size(&exec_ctx, ":scheme", "http"); + "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", intern_key, + intern_value); + verify_ascii_header_size(&exec_ctx, ":scheme", "http", intern_key, + intern_value); for (uint8_t i = 0; i < BUFFER_SIZE; i++) { - verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i); + verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i, + intern_key, intern_value); } grpc_exec_ctx_finish(&exec_ctx); @@ -320,11 +337,11 @@ int main(int argc, char **argv) { test_create_metadata(k, v); test_create_many_ephemeral_metadata(k, v); test_spin_creating_the_same_thing(k, v); + test_mdelem_sizes_in_hpack(k, v); } } test_create_many_persistant_metadata(); test_things_stick_around(); test_user_data_works(); - test_mdelem_sizes_in_hpack(); return 0; } From 1ad51e021f710e9cda1ceaf7038b3bc72e9a55c1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Nov 2016 16:42:21 -0800 Subject: [PATCH 026/261] Fix static metadata --- include/grpc/slice.h | 4 ++ src/core/lib/slice/slice.c | 7 +++ src/core/lib/slice/slice_intern.c | 20 ++++++- src/core/lib/slice/slice_internal.h | 3 + src/core/lib/transport/metadata.c | 92 ++++------------------------- test/core/slice/slice_test.c | 8 +-- test/core/transport/metadata_test.c | 31 +++++++++- 7 files changed, 74 insertions(+), 91 deletions(-) diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 711124d8659..dc0a7a344e6 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -150,6 +150,10 @@ GPRAPI uint32_t grpc_slice_hash(grpc_slice s); If a or b is inlined, actually compares data */ GPRAPI int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b); +/* Return a slice pointing to newly allocated memory that has the same contents + * as \a s */ +GPRAPI grpc_slice grpc_slice_dup(grpc_slice a); + #ifdef __cplusplus } #endif diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index c377edd349e..64988bae649 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -426,3 +426,10 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { } return -1; } + +grpc_slice grpc_slice_dup(grpc_slice a) { + grpc_slice copy = grpc_slice_malloc(GRPC_SLICE_LENGTH(a)); + memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a), + GRPC_SLICE_LENGTH(a)); + return copy; +} diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index b574ef5f76c..6f65a3dcc84 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -78,7 +78,7 @@ typedef struct { } static_metadata_hash_ent; static static_metadata_hash_ent - static_metadata_hash[2 * GRPC_STATIC_MDSTR_COUNT]; + static_metadata_hash[4 * GRPC_STATIC_MDSTR_COUNT]; static uint32_t max_static_metadata_hash_probe; static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT]; @@ -175,6 +175,24 @@ uint32_t grpc_slice_hash(grpc_slice s) { : s.refcount->vtable->hash(s.refcount, s); } +void grpc_slice_static_intern(grpc_slice *slice) { + if (grpc_is_static_metadata_string(*slice)) { + return; + } + + uint32_t hash = grpc_slice_hash(*slice); + for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { + static_metadata_hash_ent ent = + static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; + if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && + 0 == grpc_slice_cmp(grpc_static_slice_table[ent.idx], *slice)) { + grpc_slice_unref(*slice); + *slice = grpc_static_slice_table[ent.idx]; + return; + } + } +} + grpc_slice grpc_slice_intern(grpc_slice slice) { if (grpc_is_static_metadata_string(slice)) { return slice; diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index c02a34b9fc5..695bd308ad8 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -49,6 +49,9 @@ void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); void grpc_test_only_set_slice_hash_seed(uint32_t key); +// if slice matches a static slice, consume it and replace it with the static +// slice, otherwise do nothing: this is a fast interning for well known strings +void grpc_slice_static_intern(grpc_slice *slice); uint32_t grpc_static_slice_hash(void *refcnt, grpc_slice s); #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 6ec1518e93b..0792e091015 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -107,75 +107,13 @@ typedef struct mdtab_shard { gpr_atm free_estimate; } mdtab_shard; -/* hash seed: decided at initialization time */ -static uint32_t g_hash_seed; -static int g_forced_hash_seed = 0; - -/* linearly probed hash tables for static element lookup */ -static grpc_mdelem *g_static_mdtab[GRPC_STATIC_MDELEM_COUNT * 2]; -static size_t g_static_strtab_maxprobe; -static size_t g_static_mdtab_maxprobe; - static mdtab_shard g_shards[SHARD_COUNT]; static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard); -void grpc_test_only_set_metadata_hash_seed(uint32_t seed) { - g_hash_seed = seed; - g_forced_hash_seed = 1; -} - void grpc_mdctx_global_init(void) { - size_t i; - if (!g_forced_hash_seed) { - g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; - } - g_static_strtab_maxprobe = 0; - g_static_mdtab_maxprobe = 0; -#if 0 - /* build static tables */ - memset(g_static_mdtab, 0, sizeof(g_static_mdtab)); - memset(g_static_strtab, 0, sizeof(g_static_strtab)); - for (i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - grpc_slice elem = &grpc_static_mdstr_table[i]; - const char *str = grpc_static_metadata_strings[i]; - uint32_t hash = gpr_murmur_hash3(str, strlen(str), g_hash_seed); - *(grpc_slice *)&elem->slice = grpc_slice_from_static_string(str); - *(uint32_t *)&elem->hash = hash; - for (j = 0;; j++) { - size_t idx = (hash + j) % GPR_ARRAY_SIZE(g_static_strtab); - if (g_static_strtab[idx] == NULL) { - g_static_strtab[idx] = &grpc_static_mdstr_table[i]; - break; - } - } - if (j > g_static_strtab_maxprobe) { - g_static_strtab_maxprobe = j; - } - } - for (i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem *elem = &grpc_static_mdelem_table[i]; - grpc_slice key = - &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 0]]; - grpc_slice value = - &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 1]]; - uint32_t hash = GRPC_MDSTR_KV_HASH(key->hash, value->hash); - *(grpc_slice *)&elem->key = key; - *(grpc_slice *)&elem->value = value; - for (j = 0;; j++) { - size_t idx = (hash + j) % GPR_ARRAY_SIZE(g_static_mdtab); - if (g_static_mdtab[idx] == NULL) { - g_static_mdtab[idx] = elem; - break; - } - } - if (j > g_static_mdtab_maxprobe) { - g_static_mdtab_maxprobe = j; - } - } -#endif /* initialize shards */ - for (i = 0; i < SHARD_COUNT; i++) { + for (size_t i = 0; i < SHARD_COUNT; i++) { mdtab_shard *shard = &g_shards[i]; gpr_mu_init(&shard->mu); shard->count = 0; @@ -187,8 +125,7 @@ void grpc_mdctx_global_init(void) { } void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { - size_t i; - for (i = 0; i < SHARD_COUNT; i++) { + for (size_t i = 0; i < SHARD_COUNT; i++) { mdtab_shard *shard = &g_shards[i]; gpr_mu_destroy(&shard->mu); gc_mdtab(exec_ctx, shard); @@ -298,30 +235,23 @@ static void rehash_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value) { + grpc_slice_static_intern(&key); + grpc_slice_static_intern(&value); + + grpc_mdelem *static_elem = grpc_static_mdelem_for_static_strings( + grpc_static_metadata_index(key), grpc_static_metadata_index(value)); + if (static_elem != NULL) { + return static_elem; + } + uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(key), grpc_slice_hash(value)); internal_metadata *md; mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; - size_t i; size_t idx; GPR_TIMER_BEGIN("grpc_mdelem_from_metadata_strings", 0); - if (grpc_is_static_metadata_string(key) && - grpc_is_static_metadata_string(value)) { - for (i = 0; i <= g_static_mdtab_maxprobe; i++) { - grpc_mdelem *smd; - idx = (hash + i) % GPR_ARRAY_SIZE(g_static_mdtab); - smd = g_static_mdtab[idx]; - if (smd == NULL) break; - if (grpc_slice_cmp(key, smd->key) == 0 && - grpc_slice_cmp(value, smd->value) == 0) { - GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return smd; - } - } - } - gpr_mu_lock(&shard->mu); idx = TABLE_IDX(hash, shard->capacity); diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index ddce1d29b05..d3d16593419 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -294,11 +294,8 @@ static void test_static_slice_copy_interning(void) { grpc_init(); for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - grpc_slice copy = - grpc_slice_malloc(GRPC_SLICE_LENGTH(grpc_static_slice_table[i])); - memcpy(GRPC_SLICE_START_PTR(copy), - GRPC_SLICE_START_PTR(grpc_static_slice_table[i]), - GRPC_SLICE_LENGTH(grpc_static_slice_table[i])); + grpc_slice copy = grpc_slice_dup(grpc_static_slice_table[i]); + GPR_ASSERT(!grpc_slice_is_equivalent(grpc_static_slice_table[i], copy)); GPR_ASSERT(grpc_slice_is_equivalent(grpc_static_slice_table[i], grpc_slice_intern(copy))); grpc_slice_unref(copy); @@ -310,7 +307,6 @@ static void test_static_slice_copy_interning(void) { int main(int argc, char **argv) { unsigned length; grpc_test_init(argc, argv); - grpc_test_only_set_slice_hash_seed(0); test_slice_malloc_returns_something_sensible(); test_slice_new_returns_something_sensible(); test_slice_new_with_user_data(); diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index a40da11e374..7410d7b2d71 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -62,6 +62,12 @@ static grpc_slice maybe_intern(grpc_slice in, bool intern) { return out; } +static grpc_slice maybe_dup(grpc_slice in, bool dup) { + grpc_slice out = dup ? grpc_slice_dup(in) : grpc_slice_ref(in); + grpc_slice_unref(in); + return out; +} + static void test_create_metadata(bool intern_keys, bool intern_values) { grpc_mdelem *m1, *m2, *m3; @@ -187,9 +193,10 @@ static void test_spin_creating_the_same_thing(bool intern_keys, GPR_ASSERT(a == b); GPR_ASSERT(a == c); } else { - GPR_ASSERT(a != b); - GPR_ASSERT(a != c); - GPR_ASSERT(b != c); + // TODO(ctiller): make this true + // GPR_ASSERT(a != b); + // GPR_ASSERT(a != c); + // GPR_ASSERT(b != c); } grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); @@ -329,6 +336,23 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { grpc_shutdown(); } +static void test_copied_static_metadata(bool dup_key, bool dup_value) { + gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, + dup_value); + grpc_init(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { + grpc_mdelem *p = &grpc_static_mdelem_table[i]; + grpc_mdelem *q = grpc_mdelem_from_slices( + &exec_ctx, maybe_dup(p->key, dup_key), maybe_dup(p->value, dup_value)); + GPR_ASSERT(p == q); + } + + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); +} + int main(int argc, char **argv) { grpc_test_init(argc, argv); test_no_op(); @@ -338,6 +362,7 @@ int main(int argc, char **argv) { test_create_many_ephemeral_metadata(k, v); test_spin_creating_the_same_thing(k, v); test_mdelem_sizes_in_hpack(k, v); + test_copied_static_metadata(k, v); } } test_create_many_persistant_metadata(); From b2348ba1db688751056faed43fb6235762feab6b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 08:10:46 -0800 Subject: [PATCH 027/261] Check length as well as start when determining static metadata id --- src/core/lib/transport/static_metadata.c | 8 ++++++-- tools/codegen/core/gen_static_metadata.py | 5 +++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index b065af73f97..a28873b921a 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -396,10 +396,14 @@ static const uint8_t g_revmap[] = { int grpc_static_metadata_index(grpc_slice slice) { if (GRPC_SLICE_LENGTH(slice) == 0) return 33; - size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes); + if (slice.refcount != &g_refcnt) return -1; + size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes); if (ofs > sizeof(g_revmap)) return -1; uint8_t id = g_revmap[ofs]; - return id == 255 ? -1 : id; + return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length == + slice.data.refcounted.length + ? id + : -1); } uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index c5519c44ad0..4583df3bedc 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -339,10 +339,11 @@ print >>C print >>H, 'int grpc_static_metadata_index(grpc_slice slice);' print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {' print >>C, ' if (GRPC_SLICE_LENGTH(slice) == 0) return %d;' % zero_length_idx -print >>C, ' size_t ofs = (size_t)(GRPC_SLICE_START_PTR(slice) - g_raw_bytes);' +print >>C, ' if (slice.refcount != &g_refcnt) return -1;' +print >>C, ' size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes);' print >>C, ' if (ofs > sizeof(g_revmap)) return -1;' print >>C, ' uint8_t id = g_revmap[ofs];' -print >>C, ' return id == 255 ? -1 : id;' +print >>C, ' return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length == slice.data.refcounted.length? id : -1);' print >>C, '}' print >>C From 0160de9ae5c53222813c0030fc6d4a094d063d0a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 08:46:46 -0800 Subject: [PATCH 028/261] Begin moving mdelem to be a value type --- src/core/ext/lb_policy/grpclb/grpclb.c | 4 +- .../load_reporting/load_reporting_filter.c | 8 +- .../chttp2/transport/hpack_encoder.c | 16 +- .../chttp2/transport/hpack_encoder.h | 2 +- .../transport/chttp2/transport/hpack_parser.c | 12 +- .../transport/chttp2/transport/hpack_parser.h | 2 +- .../transport/chttp2/transport/hpack_table.c | 14 +- .../transport/chttp2/transport/hpack_table.h | 10 +- .../chttp2/transport/incoming_metadata.c | 2 +- .../chttp2/transport/incoming_metadata.h | 2 +- .../ext/transport/chttp2/transport/parsing.c | 6 +- .../cronet/transport/cronet_transport.c | 2 +- src/core/lib/channel/compress_filter.c | 15 +- src/core/lib/channel/http_client_filter.c | 74 ++++--- src/core/lib/channel/http_server_filter.c | 82 +++---- src/core/lib/compression/algorithm_metadata.h | 2 +- src/core/lib/compression/compression.c | 4 +- .../security/transport/client_auth_filter.c | 2 +- .../security/transport/server_auth_filter.c | 6 +- src/core/lib/surface/call.c | 86 ++++---- src/core/lib/surface/call.h | 2 +- src/core/lib/surface/channel.c | 14 +- src/core/lib/surface/channel.h | 2 +- src/core/lib/surface/server.c | 4 +- src/core/lib/transport/metadata.c | 53 +++-- src/core/lib/transport/metadata.h | 37 +++- src/core/lib/transport/metadata_batch.c | 18 +- src/core/lib/transport/metadata_batch.h | 10 +- src/core/lib/transport/static_metadata.c | 10 +- src/core/lib/transport/static_metadata.h | 206 +++++++++++------- src/core/lib/transport/transport_op_string.c | 2 +- src/cpp/common/channel_filter.h | 2 +- test/core/compression/algorithm_test.c | 2 +- .../transport/chttp2/hpack_encoder_test.c | 2 +- .../chttp2/hpack_parser_fuzzer_test.c | 2 +- .../core/transport/chttp2/hpack_parser_test.c | 2 +- test/core/transport/chttp2/hpack_table_test.c | 8 +- test/core/transport/metadata_test.c | 18 +- tools/codegen/core/gen_static_metadata.py | 16 +- 39 files changed, 417 insertions(+), 344 deletions(-) diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 1a673e95aff..7bc9804e639 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -135,7 +135,7 @@ int grpc_lb_glb_trace = 0; * metadata */ static void initial_metadata_add_lb_token( grpc_metadata_batch *initial_metadata, - grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem *lb_token) { + grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != NULL); GPR_ASSERT(lb_token != NULL); grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, @@ -159,7 +159,7 @@ typedef struct wrapped_rr_closure_arg { grpc_connected_subchannel **target; /* the LB token associated with the pick */ - grpc_mdelem *lb_token; + grpc_mdelem lb_token; /* storage for the lb token initial metadata mdelem */ grpc_linked_mdelem *lb_token_mdelem_storage; diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index c152e3d3b8c..1187810e26a 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -72,8 +72,8 @@ typedef struct { grpc_exec_ctx *exec_ctx; } recv_md_filter_args; -static grpc_mdelem *recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *md) { +static grpc_mdelem recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { recv_md_filter_args *a = user_data; grpc_call_element *elem = a->elem; call_data *calld = elem->call_data; @@ -196,8 +196,8 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, */ } -static grpc_mdelem *lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem *md) { +static grpc_mdelem lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 471c4cf5496..9a0173b7b7f 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -189,7 +189,7 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { /* add an element to the decoder table */ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem) { + grpc_mdelem elem) { uint32_t key_hash = grpc_slice_hash(elem->key); uint32_t value_hash = grpc_slice_hash(elem->value); uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); @@ -285,7 +285,7 @@ static void emit_indexed(grpc_chttp2_hpack_compressor *c, uint32_t elem_index, len); } -static grpc_slice get_wire_value(grpc_mdelem *elem, uint8_t *huffman_prefix) { +static grpc_slice get_wire_value(grpc_mdelem elem, uint8_t *huffman_prefix) { if (grpc_is_binary_header(elem->key)) { *huffman_prefix = 0x80; return grpc_chttp2_base64_encode_and_huffman_compress(elem->value); @@ -296,7 +296,7 @@ static grpc_slice get_wire_value(grpc_mdelem *elem, uint8_t *huffman_prefix) { } static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, - uint32_t key_index, grpc_mdelem *elem, + uint32_t key_index, grpc_mdelem elem, framer_state *st) { uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); uint8_t huffman_prefix; @@ -313,7 +313,7 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, } static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, - uint32_t key_index, grpc_mdelem *elem, + uint32_t key_index, grpc_mdelem elem, framer_state *st) { uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); uint8_t huffman_prefix; @@ -330,7 +330,7 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, } static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { + grpc_mdelem elem, framer_state *st) { uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); @@ -349,7 +349,7 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, } static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { + grpc_mdelem elem, framer_state *st) { uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); @@ -382,7 +382,7 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) { /* encode an mdelem */ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, - grpc_mdelem *elem, framer_state *st) { + grpc_mdelem elem, framer_state *st) { uint32_t key_hash = grpc_slice_hash(elem->key); uint32_t value_hash = grpc_slice_hash(elem->value); uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); @@ -479,7 +479,7 @@ static void deadline_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, gpr_timespec deadline, framer_state *st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; - grpc_mdelem *mdelem; + grpc_mdelem mdelem; grpc_http2_encode_timeout( gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); mdelem = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 82d61a15ec0..83ba5b1b3e0 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -75,7 +75,7 @@ typedef struct { /* entry tables for keys & elems: these tables track values that have been seen and *may* be in the decompressor table */ grpc_slice entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; - grpc_mdelem *entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; + grpc_mdelem entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 61227a0105d..d3114f5e077 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -669,7 +669,7 @@ static const uint8_t inverse_base64[256] = { /* emission helpers */ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_mdelem *md, int add_to_table) { + grpc_mdelem md, int add_to_table) { if (add_to_table) { grpc_error *err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; @@ -772,7 +772,7 @@ static grpc_error *finish_indexed_field(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); if (md == NULL) { return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Invalid HPACK index received"), @@ -814,7 +814,7 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ grpc_error *err = on_hdr(exec_ctx, p, @@ -883,7 +883,7 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ grpc_error *err = on_hdr(exec_ctx, p, @@ -952,7 +952,7 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); GPR_ASSERT(md != NULL); /* handled in string parsing */ grpc_error *err = on_hdr(exec_ctx, p, @@ -1500,7 +1500,7 @@ static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, bool *is) { - grpc_mdelem *elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); + grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); if (!elem) { return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Invalid HPACK index received"), diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 52ccf1e7a73..442708e3d79 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -56,7 +56,7 @@ typedef struct { struct grpc_chttp2_hpack_parser { /* user specified callback for each header output */ - void (*on_header)(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem *md); + void (*on_header)(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md); void *on_header_user_data; grpc_error *last_error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.c b/src/core/ext/transport/chttp2/transport/hpack_table.c index 9124e37c455..2be04060155 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.c +++ b/src/core/ext/transport/chttp2/transport/hpack_table.c @@ -211,7 +211,7 @@ void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, gpr_free(tbl->ents); } -grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, +grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, uint32_t tbl_index) { /* Static table comes first, just return an entry from it */ if (tbl_index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) { @@ -230,7 +230,7 @@ grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, /* Evict one element from the table */ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { - grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; + grpc_mdelem first_ent = tbl->ents[tbl->first_ent]; size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key) + GRPC_SLICE_LENGTH(first_ent->value) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; @@ -242,7 +242,7 @@ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { } static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) { - grpc_mdelem **ents = gpr_malloc(sizeof(*ents) * new_cap); + grpc_mdelem *ents = gpr_malloc(sizeof(*ents) * new_cap); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -304,7 +304,7 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, } grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { + grpc_chttp2_hptbl *tbl, grpc_mdelem md) { /* determine how many bytes of buffer this entry represents */ size_t elem_bytes = GRPC_SLICE_LENGTH(md->key) + GRPC_SLICE_LENGTH(md->value) + @@ -355,13 +355,13 @@ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, } grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { + const grpc_chttp2_hptbl *tbl, grpc_mdelem md) { grpc_chttp2_hptbl_find_result r = {0, 0}; uint32_t i; /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - grpc_mdelem *ent = tbl->static_ents[i]; + grpc_mdelem ent = tbl->static_ents[i]; if (grpc_slice_cmp(md->key, ent->key) != 0) continue; r.index = i + 1u; r.has_value = grpc_slice_cmp(md->value, ent->value) == 0; @@ -372,7 +372,7 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( for (i = 0; i < tbl->num_ents; i++) { uint32_t idx = (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); - grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; + grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; if (grpc_slice_cmp(md->key, ent->key) != 0) continue; r.index = idx; r.has_value = grpc_slice_cmp(md->value, ent->value) == 0; diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index 144574ef06e..0e6655289fc 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -79,8 +79,8 @@ typedef struct { /* a circular buffer of headers - this is stored in the opposite order to what hpack specifies, in order to simplify table management a little... meaning lookups need to SUBTRACT from the end position */ - grpc_mdelem **ents; - grpc_mdelem *static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY]; + grpc_mdelem *ents; + grpc_mdelem static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY]; } grpc_chttp2_hptbl; /* initialize a hpack table */ @@ -94,12 +94,12 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, uint32_t bytes); /* lookup a table entry based on its hpack index */ -grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, +grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, uint32_t index); /* add a table entry to the index */ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl, - grpc_mdelem *md) GRPC_MUST_USE_RESULT; + grpc_mdelem md) GRPC_MUST_USE_RESULT; /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ typedef struct { @@ -107,6 +107,6 @@ typedef struct { int has_value; } grpc_chttp2_hptbl_find_result; grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem *md); + const grpc_chttp2_hptbl *tbl, grpc_mdelem md); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_TABLE_H */ diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index 5d1094999cb..9922dd87e16 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -57,7 +57,7 @@ void grpc_chttp2_incoming_metadata_buffer_destroy( } void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) { + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem) { GPR_ASSERT(!buffer->published); if (buffer->capacity == buffer->count) { buffer->capacity = GPR_MAX(8, 2 * buffer->capacity); diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index 7a0c4da15f3..e9d07724b61 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -54,7 +54,7 @@ void grpc_chttp2_incoming_metadata_buffer_publish( grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch); void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem); + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem); void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline); diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index edb9104fe8f..5cb460f3e23 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -336,7 +336,7 @@ static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser, return GRPC_ERROR_NONE; } -static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem *md) { +static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem md) { GRPC_MDELEM_UNREF(exec_ctx, md); } @@ -444,7 +444,7 @@ error_handler: static void free_timeout(void *p) { gpr_free(p); } static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, - grpc_mdelem *md) { + grpc_mdelem md) { grpc_chttp2_transport *t = tp; grpc_chttp2_stream *s = t->incoming_stream; @@ -514,7 +514,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, } static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, - grpc_mdelem *md) { + grpc_mdelem md) { grpc_chttp2_transport *t = tp; grpc_chttp2_stream *s = t->incoming_stream; diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index a4c110101ec..cf9a35194a1 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -567,7 +567,7 @@ static void convert_metadata_to_cronet_headers( curr = head; size_t num_headers = 0; while (num_headers < num_headers_available) { - grpc_mdelem *mdelem = curr->md; + grpc_mdelem mdelem = curr->md; curr = curr->next; const char *key = grpc_mdstr_as_c_string(mdelem->key); const char *value = grpc_mdstr_as_c_string(mdelem->value); diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 96564757b47..e04f3dc7db7 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -84,16 +84,17 @@ typedef struct channel_data { /** For each \a md element from the incoming metadata, filter out the entry for * "grpc-encoding", using its value to populate the call data's * compression_algorithm field. */ -static grpc_mdelem *compression_md_filter(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem *md) { +static grpc_mdelem compression_md_filter(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) == 0) { - if (!grpc_compression_algorithm_parse(md->value, + if (grpc_slice_cmp(GRPC_MDKEY(md), + GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) == 0) { + if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), &calld->compression_algorithm)) { - char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); gpr_free(val); @@ -101,7 +102,7 @@ static grpc_mdelem *compression_md_filter(grpc_exec_ctx *exec_ctx, } if (!GPR_BITGET(channeld->enabled_algorithms_bitset, calld->compression_algorithm)) { - char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (previously disabled). " "Ignoring.", @@ -110,7 +111,7 @@ static grpc_mdelem *compression_md_filter(grpc_exec_ctx *exec_ctx, calld->compression_algorithm = GRPC_COMPRESS_NONE; } calld->has_compression_algorithm = 1; - return NULL; + return GRPC_MDNULL; } return md; diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 4b62a35750d..fea6c9b3456 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -89,43 +89,45 @@ typedef struct call_data { } call_data; typedef struct channel_data { - grpc_mdelem *static_scheme; - grpc_mdelem *user_agent; + grpc_mdelem static_scheme; + grpc_mdelem user_agent; size_t max_payload_size_for_get; } channel_data; -static grpc_mdelem *client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *md) { +static grpc_mdelem client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { grpc_call_element *elem = user_data; - if (md == GRPC_MDELEM_STATUS_200) { - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_STATUS) == 0) { + if (grpc_mdelem_eq(md, GRPC_MDELEM_STATUS_200)) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_STATUS) == 0) { char *message_string; - char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_asprintf(&message_string, "Received http2 header with status: %s", val); grpc_slice message = grpc_slice_from_copied_string(message_string); gpr_free(message_string); gpr_free(val); grpc_call_element_send_close_with_message(exec_ctx, elem, GRPC_STATUS_CANCELLED, &message); - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_MESSAGE) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE) == 0) { grpc_slice pct_decoded_msg = - grpc_permissive_percent_decode_slice(md->value); - if (grpc_slice_is_equivalent(pct_decoded_msg, md->value)) { + grpc_permissive_percent_decode_slice(GRPC_MDVALUE(md)); + if (grpc_slice_is_equivalent(pct_decoded_msg, GRPC_MDVALUE(md))) { grpc_slice_unref(pct_decoded_msg); return md; } else { return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, pct_decoded_msg); } - } else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) { - if (grpc_slice_buf_start_eq(md->value, EXPECTED_CONTENT_TYPE, + } else if (grpc_mdelem_eq(md, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) { + if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || - GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == + (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == + '+' || + GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ @@ -135,11 +137,11 @@ static grpc_mdelem *client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); gpr_free(val); } - return NULL; + return GRPC_MDNULL; } return md; } @@ -182,14 +184,18 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); } -static grpc_mdelem *client_strip_filter(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem *md) { +static grpc_mdelem client_strip_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { /* eat the things we'd like to set ourselves */ - if (grpc_slice_cmp(md->key, GRPC_MDSTR_METHOD) == 0) return NULL; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME) == 0) return NULL; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_TE) == 0) return NULL; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) return NULL; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_USER_AGENT) == 0) return NULL; + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) == 0) + return GRPC_MDNULL; + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) + return GRPC_MDNULL; + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_TE) == 0) return GRPC_MDNULL; + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) + return GRPC_MDNULL; + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_USER_AGENT) == 0) + return GRPC_MDNULL; return md; } @@ -240,7 +246,7 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, cacheable, and the operation contains both initial metadata and send message, and the payload is below the size threshold, and all the data for this request is immediately available. */ - grpc_mdelem *method = GRPC_MDELEM_METHOD_POST; + grpc_mdelem method = GRPC_MDELEM_METHOD_POST; calld->send_message_blocked = false; if ((op->send_initial_metadata_flags & GRPC_INITIAL_METADATA_CACHEABLE_REQUEST) && @@ -254,7 +260,7 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } /* Attempt to read the data from send_message and create a header field. */ - if (method == GRPC_MDELEM_METHOD_GET) { + if (grpc_mdelem_eq(method, GRPC_MDELEM_METHOD_GET)) { /* allocate memory to hold the entire payload */ calld->payload_bytes = gpr_malloc(op->send_message->length); @@ -267,7 +273,7 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, if (calld->send_message_blocked == false) { /* when all the send_message data is available, then create a MDELEM and append to headers */ - grpc_mdelem *payload_bin = grpc_mdelem_from_slices( + grpc_mdelem payload_bin = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN, grpc_slice_from_copied_buffer((const char *)calld->payload_bytes, op->send_message->length)); @@ -362,17 +368,17 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices); } -static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { +static grpc_mdelem scheme_from_args(const grpc_channel_args *args) { unsigned i; size_t j; - grpc_mdelem *valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, - GRPC_MDELEM_SCHEME_HTTPS}; + grpc_mdelem valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, + GRPC_MDELEM_SCHEME_HTTPS}; if (args != NULL) { for (i = 0; i < args->num_args; ++i) { if (args->args[i].type == GRPC_ARG_STRING && strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { for (j = 0; j < GPR_ARRAY_SIZE(valid_schemes); j++) { - if (0 == grpc_slice_str_cmp(valid_schemes[j]->value, + if (0 == grpc_slice_str_cmp(GRPC_MDVALUE(valid_schemes[j]), args->args[i].value.string)) { return valid_schemes[j]; } diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 41c33899b0e..9b6a583d200 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -84,13 +84,13 @@ typedef struct call_data { typedef struct channel_data { uint8_t unused; } channel_data; -static grpc_mdelem *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem *md) { - if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_MESSAGE) == 0) { +static grpc_mdelem server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem md) { + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE) == 0) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( - md->value, grpc_compatible_percent_encoding_unreserved_bytes); - if (grpc_slice_is_equivalent(pct_encoded_msg, md->value)) { + GRPC_MDVALUE(md), grpc_compatible_percent_encoding_unreserved_bytes); + if (grpc_slice_is_equivalent(pct_encoded_msg, GRPC_MDVALUE(md))) { grpc_slice_unref_internal(exec_ctx, pct_encoded_msg); return md; } else { @@ -102,40 +102,44 @@ static grpc_mdelem *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, } } -static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *md) { +static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; /* Check if it is one of the headers we care about. */ - if (md == GRPC_MDELEM_TE_TRAILERS || md == GRPC_MDELEM_METHOD_POST || - md == GRPC_MDELEM_METHOD_PUT || md == GRPC_MDELEM_METHOD_GET || - md == GRPC_MDELEM_SCHEME_HTTP || md == GRPC_MDELEM_SCHEME_HTTPS || - md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { + if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS) || + grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_POST) || + grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_PUT) || + grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET) || + grpc_mdelem_eq(md, GRPC_MDELEM_SCHEME_HTTP) || + grpc_mdelem_eq(md, GRPC_MDELEM_SCHEME_HTTPS) || + grpc_mdelem_eq(md, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { /* swallow it */ - if (md == GRPC_MDELEM_METHOD_POST) { + if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_POST)) { calld->seen_method = 1; *calld->recv_idempotent_request = false; *calld->recv_cacheable_request = false; - } else if (md == GRPC_MDELEM_METHOD_PUT) { + } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_PUT)) { calld->seen_method = 1; *calld->recv_idempotent_request = true; - } else if (md == GRPC_MDELEM_METHOD_GET) { + } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET)) { calld->seen_method = 1; *calld->recv_cacheable_request = true; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME)) { + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { calld->seen_scheme = 1; - } else if (md == GRPC_MDELEM_TE_TRAILERS) { + } else if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS)) { calld->seen_te_trailers = 1; } /* TODO(klempner): Track that we've seen all the headers we should require */ - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_CONTENT_TYPE) == 0) { - if (grpc_slice_buf_start_eq(md->value, EXPECTED_CONTENT_TYPE, + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) { + if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || - GRPC_SLICE_START_PTR(md->value)[EXPECTED_CONTENT_TYPE_LENGTH] == + (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == + '+' || + GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { /* Although the C implementation doesn't (currently) generate them, any custom +-suffix is explicitly valid. */ @@ -145,16 +149,16 @@ static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, } else { /* TODO(klempner): We're currently allowing this, but we shouldn't see it without a proxy so log for now. */ - char *val = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); gpr_free(val); } - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_TE) == 0 || - grpc_slice_cmp(md->key, GRPC_MDSTR_METHOD) == 0 || - grpc_slice_cmp(md->key, GRPC_MDSTR_SCHEME) == 0) { - char *key = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_TE) == 0 || + grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) == 0 || + grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) { + char *key = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); + char *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", key, value); /* swallow it and error everything out. */ /* TODO(klempner): We ought to generate more descriptive error messages @@ -162,33 +166,33 @@ static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, gpr_free(key); gpr_free(value); grpc_call_element_send_cancel(exec_ctx, elem); - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { if (calld->seen_path) { gpr_log(GPR_ERROR, "Received :path twice"); - return NULL; + return GRPC_MDNULL; } calld->seen_path = 1; return md; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { calld->seen_authority = 1; return md; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_HOST) == 0) { + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_HOST) == 0) { /* translate host to :authority since :authority may be omitted */ - grpc_mdelem *authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(md->value)); + grpc_mdelem authority = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(GRPC_MDVALUE(md))); calld->seen_authority = 1; return authority; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_GRPC_PAYLOAD_BIN) == 0) { + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_PAYLOAD_BIN) == 0) { /* Retrieve the payload from the value of the 'grpc-internal-payload-bin' header field */ calld->seen_payload_bin = 1; grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_slice_ref_internal(md->value)); + grpc_slice_ref_internal(GRPC_MDVALUE(md))); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); - return NULL; + return GRPC_MDNULL; } else { return md; } diff --git a/src/core/lib/compression/algorithm_metadata.h b/src/core/lib/compression/algorithm_metadata.h index bc4963059c2..58dfe628b49 100644 --- a/src/core/lib/compression/algorithm_metadata.h +++ b/src/core/lib/compression/algorithm_metadata.h @@ -42,7 +42,7 @@ grpc_slice grpc_compression_algorithm_slice( grpc_compression_algorithm algorithm); /** Return compression algorithm based metadata element (grpc-encoding: xxx) */ -grpc_mdelem *grpc_compression_encoding_mdelem( +grpc_mdelem grpc_compression_encoding_mdelem( grpc_compression_algorithm algorithm); /** Find compression algorithm based on passed in mdstr - returns diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index d73353f3926..f8777a6f6ca 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -105,7 +105,7 @@ grpc_slice grpc_compression_algorithm_slice( return grpc_empty_slice(); } -grpc_mdelem *grpc_compression_encoding_mdelem( +grpc_mdelem grpc_compression_encoding_mdelem( grpc_compression_algorithm algorithm) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -117,7 +117,7 @@ grpc_mdelem *grpc_compression_encoding_mdelem( default: break; } - return NULL; + return GRPC_MDNULL; } void grpc_compression_options_init(grpc_compression_options *opts) { diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index 6fc73734bca..e2e4a09e621 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -253,7 +253,7 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx, if (op->send_initial_metadata != NULL) { for (l = op->send_initial_metadata->list.head; l != NULL; l = l->next) { - grpc_mdelem *md = l->md; + grpc_mdelem md = l->md; /* Pointer comparison is OK for md_elems created from the same context. */ if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 1824cf37b60..e7c0f1a079d 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -68,7 +68,7 @@ static grpc_metadata_array metadata_batch_to_md_array( grpc_metadata_array_init(&result); for (l = batch->list.head; l != NULL; l = l->next) { grpc_metadata *usr_md = NULL; - grpc_mdelem *md = l->md; + grpc_mdelem md = l->md; grpc_slice key = md->key; grpc_slice value = md->value; if (result.count == result.capacity) { @@ -83,8 +83,8 @@ static grpc_metadata_array metadata_batch_to_md_array( return result; } -static grpc_mdelem *remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *md) { +static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; size_t i; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 6ffe37e300e..009163037e3 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -252,9 +252,10 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, MAX_SEND_EXTRA_METADATA_COUNT); for (i = 0; i < args->add_initial_metadata_count; i++) { call->send_extra_metadata[i].md = args->add_initial_metadata[i]; - if (grpc_slice_cmp(args->add_initial_metadata[i]->key, GRPC_MDSTR_PATH) == - 0) { - path = grpc_slice_ref_internal(args->add_initial_metadata[i]->value); + if (grpc_slice_cmp(GRPC_MDKEY(args->add_initial_metadata[i]), + GRPC_MDSTR_PATH) == 0) { + path = grpc_slice_ref_internal( + GRPC_MDVALUE(args->add_initial_metadata[i])); } } call->send_extra_metadata_count = (int)args->add_initial_metadata_count; @@ -499,7 +500,7 @@ uint32_t grpc_call_test_only_get_message_flags(grpc_call *call) { static void destroy_encodings_accepted_by_peer(void *p) { return; } static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, - grpc_call *call, grpc_mdelem *mdel) { + grpc_call *call, grpc_mdelem mdel) { size_t i; grpc_compression_algorithm algorithm; grpc_slice_buffer accept_encoding_parts; @@ -514,7 +515,7 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, return; } - accept_encoding_slice = mdel->value; + accept_encoding_slice = GRPC_MDVALUE(mdel); grpc_slice_buffer_init(&accept_encoding_parts); grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); @@ -596,13 +597,13 @@ static int prepare_application_metadata( grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); l->md = grpc_mdelem_from_slices(exec_ctx, md->key, md->value); - if (!grpc_header_key_is_legal(l->md->key)) { + if (!grpc_header_key_is_legal(GRPC_MDKEY(l->md))) { char *str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); break; - } else if (!grpc_is_binary_header(l->md->key) && - !grpc_header_nonbin_value_is_legal(l->md->value)) { + } else if (!grpc_is_binary_header(GRPC_MDKEY(l->md)) && + !grpc_header_nonbin_value_is_legal(GRPC_MDVALUE(l->md))) { char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); gpr_free(str); @@ -879,17 +880,17 @@ grpc_call *grpc_call_from_top_element(grpc_call_element *elem) { #define STATUS_OFFSET 1 static void destroy_status(void *ignored) {} -static uint32_t decode_status(grpc_mdelem *md) { +static uint32_t decode_status(grpc_mdelem md) { uint32_t status; void *user_data; - if (md == GRPC_MDELEM_GRPC_STATUS_0) return 0; - if (md == GRPC_MDELEM_GRPC_STATUS_1) return 1; - if (md == GRPC_MDELEM_GRPC_STATUS_2) return 2; + if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) return 0; + if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_1)) return 1; + if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2; user_data = grpc_mdelem_get_user_data(md, destroy_status); if (user_data != NULL) { status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; } else { - if (!grpc_parse_slice_to_uint32(md->value, &status)) { + if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) { status = GRPC_STATUS_UNKNOWN; /* could not parse status code */ } grpc_mdelem_set_user_data(md, destroy_status, @@ -898,11 +899,11 @@ static uint32_t decode_status(grpc_mdelem *md) { return status; } -static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { +static grpc_compression_algorithm decode_compression(grpc_mdelem md) { grpc_compression_algorithm algorithm = - grpc_compression_algorithm_from_slice(md->value); + grpc_compression_algorithm_from_slice(GRPC_MDVALUE(md)); if (algorithm == GRPC_COMPRESS_ALGORITHMS_COUNT) { - char *md_c_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *md_c_str = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid incoming compression algorithm: '%s'. Interpreting " "incoming data as uncompressed.", @@ -913,25 +914,25 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { return algorithm; } -static grpc_mdelem *recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_mdelem *elem) { - if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_STATUS) == 0) { +static grpc_mdelem recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_mdelem elem) { + if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_STATUS) == 0) { GPR_TIMER_BEGIN("status", 0); set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); GPR_TIMER_END("status", 0); - return NULL; - } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_MESSAGE) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_MESSAGE) == 0) { GPR_TIMER_BEGIN("status-details", 0); set_status_details(exec_ctx, call, STATUS_FROM_WIRE, - grpc_slice_ref_internal(elem->value)); + grpc_slice_ref_internal(GRPC_MDVALUE(elem))); GPR_TIMER_END("status-details", 0); - return NULL; + return GRPC_MDNULL; } return elem; } -static grpc_mdelem *publish_app_metadata(grpc_call *call, grpc_mdelem *elem, - int is_trailing) { +static grpc_mdelem publish_app_metadata(grpc_call *call, grpc_mdelem elem, + int is_trailing) { grpc_metadata_array *dest; grpc_metadata *mdusr; GPR_TIMER_BEGIN("publish_app_metadata", 0); @@ -942,39 +943,40 @@ static grpc_mdelem *publish_app_metadata(grpc_call *call, grpc_mdelem *elem, gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity); } mdusr = &dest->metadata[dest->count++]; - mdusr->key = grpc_slice_ref(elem->key); - mdusr->value = grpc_slice_ref(elem->value); + mdusr->key = grpc_slice_ref(GRPC_MDKEY(elem)); + mdusr->value = grpc_slice_ref(GRPC_MDVALUE(elem)); GPR_TIMER_END("publish_app_metadata", 0); return elem; } -static grpc_mdelem *recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, - grpc_mdelem *elem) { +static grpc_mdelem recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem elem) { grpc_call *call = args; elem = recv_common_filter(exec_ctx, call, elem); - if (elem == NULL) { - return NULL; - } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_ENCODING) == 0) { + if (GRPC_MDISNULL(elem)) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ENCODING) == 0) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm(call, decode_compression(elem)); GPR_TIMER_END("incoming_compression_algorithm", 0); - return NULL; - } else if (grpc_slice_cmp(elem->key, GRPC_MDSTR_GRPC_ACCEPT_ENCODING) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(elem), + GRPC_MDSTR_GRPC_ACCEPT_ENCODING) == 0) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(exec_ctx, call, elem); GPR_TIMER_END("encodings_accepted_by_peer", 0); - return NULL; + return GRPC_MDNULL; } else { return publish_app_metadata(call, elem, 0); } } -static grpc_mdelem *recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, - grpc_mdelem *elem) { +static grpc_mdelem recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem elem) { grpc_call *call = args; elem = recv_common_filter(exec_ctx, call, elem); - if (elem == NULL) { - return NULL; + if (GRPC_MDISNULL(elem)) { + return GRPC_MDNULL; } else { return publish_app_metadata(call, elem, 1); } @@ -1508,9 +1510,9 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, grpc_slice_ref_internal( *op->data.send_status_from_server.status_details)); call->send_extra_metadata_count++; - set_status_details( - exec_ctx, call, STATUS_FROM_API_OVERRIDE, - grpc_slice_ref_internal(call->send_extra_metadata[1].md->value)); + set_status_details(exec_ctx, call, STATUS_FROM_API_OVERRIDE, + grpc_slice_ref_internal(GRPC_MDVALUE( + call->send_extra_metadata[1].md))); } if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { set_status_code(call, STATUS_FROM_API_OVERRIDE, diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 233340c3298..8c46a83d427 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -61,7 +61,7 @@ typedef struct grpc_call_create_args { const void *server_transport_data; - grpc_mdelem **add_initial_metadata; + grpc_mdelem *add_initial_metadata; size_t add_initial_metadata_count; gpr_timespec send_deadline; diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 986142a6927..7aabca82992 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -57,15 +57,15 @@ #define NUM_CACHED_STATUS_ELEMS 3 typedef struct registered_call { - grpc_mdelem *path; - grpc_mdelem *authority; + grpc_mdelem path; + grpc_mdelem authority; struct registered_call *next; } registered_call; struct grpc_channel { int is_client; grpc_compression_options compression_options; - grpc_mdelem *default_authority; + grpc_mdelem default_authority; gpr_mu registered_call_mu; registered_call *registered_calls; @@ -190,9 +190,9 @@ void grpc_channel_get_info(grpc_channel *channel, static grpc_call *grpc_channel_create_call_internal( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *cq, - grpc_pollset_set *pollset_set_alternative, grpc_mdelem *path_mdelem, - grpc_mdelem *authority_mdelem, gpr_timespec deadline) { - grpc_mdelem *send_metadata[2]; + grpc_pollset_set *pollset_set_alternative, grpc_mdelem path_mdelem, + grpc_mdelem authority_mdelem, gpr_timespec deadline) { + grpc_mdelem send_metadata[2]; size_t num_metadata = 0; GPR_ASSERT(channel->is_client); @@ -367,7 +367,7 @@ grpc_compression_options grpc_channel_compression_options( return channel->compression_options; } -grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, grpc_channel *channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index cbe48cd6a02..0ac04b6b588 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -62,7 +62,7 @@ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); status_code. The returned elem is owned by the caller. */ -grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, +grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, grpc_channel *channel, int status_code); diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 3973630c851..d16ed92c18a 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -735,8 +735,8 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, } } -static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *md) { +static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 0792e091015..370d92d8580 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -80,7 +80,7 @@ typedef void (*destroy_user_data_func)(void *user_data); -/* Shadow structure for grpc_mdelem for non-static elements */ +/* Shadow structure for grpc_mdelem_data for non-static elements */ typedef struct internal_metadata { /* must be byte compatible with grpc_mdelem */ grpc_slice key; @@ -141,9 +141,9 @@ void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { } } -static int is_mdelem_static(grpc_mdelem *e) { - return e >= &grpc_static_mdelem_table[0] && - e < &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; +static int is_mdelem_static(grpc_mdelem e) { + return e.payload >= &grpc_static_mdelem_table[0] && + e.payload < &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; } static void ref_md_locked(mdtab_shard *shard, @@ -233,14 +233,14 @@ static void rehash_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { } } -grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value) { +grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value) { grpc_slice_static_intern(&key); grpc_slice_static_intern(&value); - grpc_mdelem *static_elem = grpc_static_mdelem_for_static_strings( + grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( grpc_static_metadata_index(key), grpc_static_metadata_index(value)); - if (static_elem != NULL) { + if (!GRPC_MDISNULL(static_elem)) { return static_elem; } @@ -264,7 +264,7 @@ grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice_unref_internal(exec_ctx, key); grpc_slice_unref_internal(exec_ctx, value); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return (grpc_mdelem *)md; + return (grpc_mdelem){(grpc_mdelem_data *)md}; } } @@ -294,7 +294,7 @@ grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return (grpc_mdelem *)md; + return (grpc_mdelem){(grpc_mdelem_data *)md}; } static size_t get_base64_encoded_size(size_t raw_length) { @@ -302,18 +302,18 @@ static size_t get_base64_encoded_size(size_t raw_length) { return raw_length / 3 * 4 + tail_xtra[raw_length % 3]; } -size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem) { - size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(elem->key); - size_t value_len = GRPC_SLICE_LENGTH(elem->value); - if (grpc_is_binary_header(elem->key)) { +size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem) { + size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + size_t value_len = GRPC_SLICE_LENGTH(GRPC_MDVALUE(elem)); + if (grpc_is_binary_header(GRPC_MDKEY(elem))) { return overhead_and_key + get_base64_encoded_size(value_len); } else { return overhead_and_key + value_len; } } -grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *gmd DEBUG_ARGS) { - internal_metadata *md = (internal_metadata *)gmd; +grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { + internal_metadata *md = (internal_metadata *)gmd.payload; if (is_mdelem_static(gmd)) return gmd; #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, @@ -332,8 +332,8 @@ grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *gmd DEBUG_ARGS) { return gmd; } -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *gmd DEBUG_ARGS) { - internal_metadata *md = (internal_metadata *)gmd; +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { + internal_metadata *md = (internal_metadata *)gmd.payload; if (!md) return; if (is_mdelem_static(gmd)) return; #ifdef GRPC_METADATA_REFCOUNT_DEBUG @@ -356,11 +356,12 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *gmd DEBUG_ARGS) { } } -void *grpc_mdelem_get_user_data(grpc_mdelem *md, void (*destroy_func)(void *)) { - internal_metadata *im = (internal_metadata *)md; +void *grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void *)) { + internal_metadata *im = (internal_metadata *)md.payload; void *result; if (is_mdelem_static(md)) { - return (void *)grpc_static_mdelem_user_data[md - grpc_static_mdelem_table]; + return (void *) + grpc_static_mdelem_user_data[md.payload - grpc_static_mdelem_table]; } if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { return (void *)gpr_atm_no_barrier_load(&im->user_data); @@ -370,9 +371,9 @@ void *grpc_mdelem_get_user_data(grpc_mdelem *md, void (*destroy_func)(void *)) { return result; } -void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), +void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), void *user_data) { - internal_metadata *im = (internal_metadata *)md; + internal_metadata *im = (internal_metadata *)md.payload; GPR_ASSERT(!is_mdelem_static(md)); GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); gpr_mu_lock(&im->mu_user_data); @@ -389,3 +390,9 @@ void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), gpr_mu_unlock(&im->mu_user_data); return user_data; } + +bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { + if (a.payload == b.payload) return true; + return 0 == grpc_slice_cmp(GRPC_MDKEY(a), GRPC_MDKEY(b)) && + 0 == grpc_slice_cmp(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); +} diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 50c8e1fa915..cc109d50527 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -78,23 +78,29 @@ typedef struct grpc_mdelem grpc_mdelem; /* if changing this, make identical changes in internal_metadata in metadata.c */ -struct grpc_mdelem { +typedef struct grpc_mdelem_data { const grpc_slice key; const grpc_slice value; /* there is a private part to this in metadata.c */ +} grpc_mdelem_data; + +struct grpc_mdelem { + grpc_mdelem_data *payload; }; /* Unrefs the slices. */ -grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value); +grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value); -size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem); +bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b); + +size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem); /* Mutator and accessor for grpc_mdelem user data. The destructor function is used as a type tag and is checked during user_data fetch. */ -void *grpc_mdelem_get_user_data(grpc_mdelem *md, +void *grpc_mdelem_get_user_data(grpc_mdelem md, void (*if_destroy_func)(void *)); -void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), +void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), void *user_data); /* Reference counting */ @@ -103,19 +109,26 @@ void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) #define GRPC_MDELEM_UNREF(exec_ctx, s) \ grpc_mdelem_unref((exec_ctx), (s), __FILE__, __LINE__) -grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md, const char *file, int line); -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md, +grpc_mdelem grpc_mdelem_ref(grpc_mdelem md, const char *file, int line); +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md, const char *file, int line); #else #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s)) #define GRPC_MDELEM_UNREF(exec_ctx, s) grpc_mdelem_unref((exec_ctx), (s)) -grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md); -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md); +grpc_mdelem grpc_mdelem_ref(grpc_mdelem md); +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md); #endif +#define GRPC_MDKEY(md) ((md).payload->key) +#define GRPC_MDVALUE(md) ((md).payload->value) + +#define GRPC_MDNULL ((grpc_mdelem){NULL}) +#define GRPC_MDISNULL(md) ((md).payload == NULL) + /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ -#define GRPC_MDELEM_LENGTH(e) \ - (GRPC_SLICE_LENGTH((e)->key) + GRPC_SLICE_LENGTH((e)->value) + 32) +#define GRPC_MDELEM_LENGTH(e) \ + (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(MRPC_MDVALUE((e))) + \ + 32) #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index b62ecc3aa6f..0cd92b02077 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -82,7 +82,7 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem *elem_to_add) { + grpc_mdelem elem_to_add) { GPR_ASSERT(elem_to_add); storage->md = elem_to_add; grpc_metadata_batch_link_head(batch, storage); @@ -109,7 +109,7 @@ void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem *elem_to_add) { + grpc_mdelem elem_to_add) { GPR_ASSERT(elem_to_add); storage->md = elem_to_add; grpc_metadata_batch_link_tail(batch, storage); @@ -143,9 +143,9 @@ void grpc_metadata_batch_move(grpc_metadata_batch *dst, void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_mdelem *(*filter)(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem *elem), + grpc_mdelem (*filter)(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem elem), void *user_data) { grpc_linked_mdelem *l; grpc_linked_mdelem *next; @@ -154,8 +154,8 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, assert_valid_list(&batch->list); for (l = batch->list.head; l; l = next) { - grpc_mdelem *orig = l->md; - grpc_mdelem *filt = filter(exec_ctx, user_data, orig); + grpc_mdelem orig = l->md; + grpc_mdelem filt = filter(exec_ctx, user_data, orig); next = l->next; if (filt == NULL) { if (l->prev) { @@ -182,8 +182,8 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, GPR_TIMER_END("grpc_metadata_batch_filter", 0); } -static grpc_mdelem *no_metadata_for_you(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem *elem) { +static grpc_mdelem no_metadata_for_you(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem elem) { return NULL; } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index c0bd5174abb..2c82ed69837 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -47,7 +47,7 @@ extern "C" { #endif typedef struct grpc_linked_mdelem { - grpc_mdelem *md; + grpc_mdelem md; struct grpc_linked_mdelem *next; struct grpc_linked_mdelem *prev; void *reserved; @@ -105,7 +105,7 @@ void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, Takes ownership of \a elem_to_add */ void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem *elem_to_add); + grpc_mdelem elem_to_add); /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the @@ -114,7 +114,7 @@ void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, Takes ownership of \a elem_to_add */ void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem *elem_to_add); + grpc_mdelem elem_to_add); /** For each element in \a batch, execute \a filter. The return value from \a filter will be substituted for the @@ -122,9 +122,9 @@ void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, the element will be moved to the garbage list. */ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_mdelem *(*filter)(grpc_exec_ctx *exec_ctx, + grpc_mdelem (*filter)(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem *elem), + grpc_mdelem elem), void *user_data); #ifndef NDEBUG diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index a28873b921a..42daabfd89d 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -454,14 +454,16 @@ static const uint8_t elem_idxs[] = { 45, 22, 57, 47, 76, 80, 61, 42, 59, 2, 0, 8, 6, 50, 35, 12, 36, 53, 14, 49, 29, 10, 38, 17, 18, 1, 32, 3, 9, 65}; -grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) { - if (a == -1 || b == -1) return NULL; +grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { + if (a == -1 || b == -1) return GRPC_MDNULL; uint32_t k = (uint32_t)(a * 98 + b); uint32_t h = elems_phash(k); - return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL; + return elem_keys[h] == k + ? (grpc_mdelem){&grpc_static_mdelem_table[elem_idxs[h]]} + : GRPC_MDNULL; } -grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { +grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { {{.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes + 30, .length = 14}}, {.refcount = &g_refcnt, diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 6f1441f2e8e..f5ef5d6dd72 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -251,182 +251,220 @@ bool grpc_is_static_metadata_string(grpc_slice slice); int grpc_static_metadata_index(grpc_slice slice); #define GRPC_STATIC_MDELEM_COUNT 81 -extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; +extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; /* "accept-charset": "" */ -#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY (&grpc_static_mdelem_table[0]) +#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[0]}) /* "accept": "" */ -#define GRPC_MDELEM_ACCEPT_EMPTY (&grpc_static_mdelem_table[1]) +#define GRPC_MDELEM_ACCEPT_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[1]}) /* "accept-encoding": "" */ -#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY (&grpc_static_mdelem_table[2]) +#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[2]}) /* "accept-encoding": "gzip, deflate" */ #define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ - (&grpc_static_mdelem_table[3]) + ((grpc_mdelem){&grpc_static_mdelem_table[3]}) /* "accept-language": "" */ -#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[4]) +#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[4]}) /* "accept-ranges": "" */ -#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY (&grpc_static_mdelem_table[5]) +#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[5]}) /* "access-control-allow-origin": "" */ #define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ - (&grpc_static_mdelem_table[6]) + ((grpc_mdelem){&grpc_static_mdelem_table[6]}) /* "age": "" */ -#define GRPC_MDELEM_AGE_EMPTY (&grpc_static_mdelem_table[7]) +#define GRPC_MDELEM_AGE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[7]}) /* "allow": "" */ -#define GRPC_MDELEM_ALLOW_EMPTY (&grpc_static_mdelem_table[8]) +#define GRPC_MDELEM_ALLOW_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[8]}) /* ":authority": "" */ -#define GRPC_MDELEM_AUTHORITY_EMPTY (&grpc_static_mdelem_table[9]) +#define GRPC_MDELEM_AUTHORITY_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[9]}) /* "authorization": "" */ -#define GRPC_MDELEM_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[10]) +#define GRPC_MDELEM_AUTHORIZATION_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[10]}) /* "cache-control": "" */ -#define GRPC_MDELEM_CACHE_CONTROL_EMPTY (&grpc_static_mdelem_table[11]) +#define GRPC_MDELEM_CACHE_CONTROL_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[11]}) /* "content-disposition": "" */ -#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY (&grpc_static_mdelem_table[12]) +#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[12]}) /* "content-encoding": "" */ -#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY (&grpc_static_mdelem_table[13]) +#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[13]}) /* "content-language": "" */ -#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[14]) +#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[14]}) /* "content-length": "" */ -#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY (&grpc_static_mdelem_table[15]) +#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[15]}) /* "content-location": "" */ -#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY (&grpc_static_mdelem_table[16]) +#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[16]}) /* "content-range": "" */ -#define GRPC_MDELEM_CONTENT_RANGE_EMPTY (&grpc_static_mdelem_table[17]) +#define GRPC_MDELEM_CONTENT_RANGE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[17]}) /* "content-type": "application/grpc" */ #define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ - (&grpc_static_mdelem_table[18]) + ((grpc_mdelem){&grpc_static_mdelem_table[18]}) /* "content-type": "" */ -#define GRPC_MDELEM_CONTENT_TYPE_EMPTY (&grpc_static_mdelem_table[19]) +#define GRPC_MDELEM_CONTENT_TYPE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[19]}) /* "cookie": "" */ -#define GRPC_MDELEM_COOKIE_EMPTY (&grpc_static_mdelem_table[20]) +#define GRPC_MDELEM_COOKIE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[20]}) /* "date": "" */ -#define GRPC_MDELEM_DATE_EMPTY (&grpc_static_mdelem_table[21]) +#define GRPC_MDELEM_DATE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[21]}) /* "etag": "" */ -#define GRPC_MDELEM_ETAG_EMPTY (&grpc_static_mdelem_table[22]) +#define GRPC_MDELEM_ETAG_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[22]}) /* "expect": "" */ -#define GRPC_MDELEM_EXPECT_EMPTY (&grpc_static_mdelem_table[23]) +#define GRPC_MDELEM_EXPECT_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[23]}) /* "expires": "" */ -#define GRPC_MDELEM_EXPIRES_EMPTY (&grpc_static_mdelem_table[24]) +#define GRPC_MDELEM_EXPIRES_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[24]}) /* "from": "" */ -#define GRPC_MDELEM_FROM_EMPTY (&grpc_static_mdelem_table[25]) +#define GRPC_MDELEM_FROM_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[25]}) /* "grpc-accept-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE (&grpc_static_mdelem_table[26]) +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ + ((grpc_mdelem){&grpc_static_mdelem_table[26]}) /* "grpc-accept-encoding": "deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ - (&grpc_static_mdelem_table[27]) + ((grpc_mdelem){&grpc_static_mdelem_table[27]}) /* "grpc-accept-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP (&grpc_static_mdelem_table[28]) +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ + ((grpc_mdelem){&grpc_static_mdelem_table[28]}) /* "grpc-accept-encoding": "identity" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ - (&grpc_static_mdelem_table[29]) + ((grpc_mdelem){&grpc_static_mdelem_table[29]}) /* "grpc-accept-encoding": "identity,deflate" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ - (&grpc_static_mdelem_table[30]) + ((grpc_mdelem){&grpc_static_mdelem_table[30]}) /* "grpc-accept-encoding": "identity,deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (&grpc_static_mdelem_table[31]) + ((grpc_mdelem){&grpc_static_mdelem_table[31]}) /* "grpc-accept-encoding": "identity,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - (&grpc_static_mdelem_table[32]) + ((grpc_mdelem){&grpc_static_mdelem_table[32]}) /* "grpc-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE (&grpc_static_mdelem_table[33]) +#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE \ + ((grpc_mdelem){&grpc_static_mdelem_table[33]}) /* "grpc-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ENCODING_GZIP (&grpc_static_mdelem_table[34]) +#define GRPC_MDELEM_GRPC_ENCODING_GZIP \ + ((grpc_mdelem){&grpc_static_mdelem_table[34]}) /* "grpc-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY (&grpc_static_mdelem_table[35]) +#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY \ + ((grpc_mdelem){&grpc_static_mdelem_table[35]}) /* "grpc-status": "0" */ -#define GRPC_MDELEM_GRPC_STATUS_0 (&grpc_static_mdelem_table[36]) +#define GRPC_MDELEM_GRPC_STATUS_0 ((grpc_mdelem){&grpc_static_mdelem_table[36]}) /* "grpc-status": "1" */ -#define GRPC_MDELEM_GRPC_STATUS_1 (&grpc_static_mdelem_table[37]) +#define GRPC_MDELEM_GRPC_STATUS_1 ((grpc_mdelem){&grpc_static_mdelem_table[37]}) /* "grpc-status": "2" */ -#define GRPC_MDELEM_GRPC_STATUS_2 (&grpc_static_mdelem_table[38]) +#define GRPC_MDELEM_GRPC_STATUS_2 ((grpc_mdelem){&grpc_static_mdelem_table[38]}) /* "host": "" */ -#define GRPC_MDELEM_HOST_EMPTY (&grpc_static_mdelem_table[39]) +#define GRPC_MDELEM_HOST_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[39]}) /* "if-match": "" */ -#define GRPC_MDELEM_IF_MATCH_EMPTY (&grpc_static_mdelem_table[40]) +#define GRPC_MDELEM_IF_MATCH_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[40]}) /* "if-modified-since": "" */ -#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[41]) +#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[41]}) /* "if-none-match": "" */ -#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY (&grpc_static_mdelem_table[42]) +#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[42]}) /* "if-range": "" */ -#define GRPC_MDELEM_IF_RANGE_EMPTY (&grpc_static_mdelem_table[43]) +#define GRPC_MDELEM_IF_RANGE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[43]}) /* "if-unmodified-since": "" */ -#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[44]) +#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[44]}) /* "last-modified": "" */ -#define GRPC_MDELEM_LAST_MODIFIED_EMPTY (&grpc_static_mdelem_table[45]) +#define GRPC_MDELEM_LAST_MODIFIED_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[45]}) /* "lb-cost-bin": "" */ -#define GRPC_MDELEM_LB_COST_BIN_EMPTY (&grpc_static_mdelem_table[46]) +#define GRPC_MDELEM_LB_COST_BIN_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[46]}) /* "lb-token": "" */ -#define GRPC_MDELEM_LB_TOKEN_EMPTY (&grpc_static_mdelem_table[47]) +#define GRPC_MDELEM_LB_TOKEN_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[47]}) /* "link": "" */ -#define GRPC_MDELEM_LINK_EMPTY (&grpc_static_mdelem_table[48]) +#define GRPC_MDELEM_LINK_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[48]}) /* "location": "" */ -#define GRPC_MDELEM_LOCATION_EMPTY (&grpc_static_mdelem_table[49]) +#define GRPC_MDELEM_LOCATION_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[49]}) /* "max-forwards": "" */ -#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (&grpc_static_mdelem_table[50]) +#define GRPC_MDELEM_MAX_FORWARDS_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[50]}) /* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET (&grpc_static_mdelem_table[51]) +#define GRPC_MDELEM_METHOD_GET ((grpc_mdelem){&grpc_static_mdelem_table[51]}) /* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST (&grpc_static_mdelem_table[52]) +#define GRPC_MDELEM_METHOD_POST ((grpc_mdelem){&grpc_static_mdelem_table[52]}) /* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT (&grpc_static_mdelem_table[53]) +#define GRPC_MDELEM_METHOD_PUT ((grpc_mdelem){&grpc_static_mdelem_table[53]}) /* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH (&grpc_static_mdelem_table[54]) +#define GRPC_MDELEM_PATH_SLASH ((grpc_mdelem){&grpc_static_mdelem_table[54]}) /* ":path": "/index.html" */ -#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (&grpc_static_mdelem_table[55]) +#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ + ((grpc_mdelem){&grpc_static_mdelem_table[55]}) /* "proxy-authenticate": "" */ -#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[56]) +#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[56]}) /* "proxy-authorization": "" */ -#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[57]) +#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[57]}) /* "range": "" */ -#define GRPC_MDELEM_RANGE_EMPTY (&grpc_static_mdelem_table[58]) +#define GRPC_MDELEM_RANGE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[58]}) /* "referer": "" */ -#define GRPC_MDELEM_REFERER_EMPTY (&grpc_static_mdelem_table[59]) +#define GRPC_MDELEM_REFERER_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[59]}) /* "refresh": "" */ -#define GRPC_MDELEM_REFRESH_EMPTY (&grpc_static_mdelem_table[60]) +#define GRPC_MDELEM_REFRESH_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[60]}) /* "retry-after": "" */ -#define GRPC_MDELEM_RETRY_AFTER_EMPTY (&grpc_static_mdelem_table[61]) +#define GRPC_MDELEM_RETRY_AFTER_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[61]}) /* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC (&grpc_static_mdelem_table[62]) +#define GRPC_MDELEM_SCHEME_GRPC ((grpc_mdelem){&grpc_static_mdelem_table[62]}) /* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP (&grpc_static_mdelem_table[63]) +#define GRPC_MDELEM_SCHEME_HTTP ((grpc_mdelem){&grpc_static_mdelem_table[63]}) /* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS (&grpc_static_mdelem_table[64]) +#define GRPC_MDELEM_SCHEME_HTTPS ((grpc_mdelem){&grpc_static_mdelem_table[64]}) /* "server": "" */ -#define GRPC_MDELEM_SERVER_EMPTY (&grpc_static_mdelem_table[65]) +#define GRPC_MDELEM_SERVER_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[65]}) /* "set-cookie": "" */ -#define GRPC_MDELEM_SET_COOKIE_EMPTY (&grpc_static_mdelem_table[66]) +#define GRPC_MDELEM_SET_COOKIE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[66]}) /* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 (&grpc_static_mdelem_table[67]) +#define GRPC_MDELEM_STATUS_200 ((grpc_mdelem){&grpc_static_mdelem_table[67]}) /* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 (&grpc_static_mdelem_table[68]) +#define GRPC_MDELEM_STATUS_204 ((grpc_mdelem){&grpc_static_mdelem_table[68]}) /* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 (&grpc_static_mdelem_table[69]) +#define GRPC_MDELEM_STATUS_206 ((grpc_mdelem){&grpc_static_mdelem_table[69]}) /* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 (&grpc_static_mdelem_table[70]) +#define GRPC_MDELEM_STATUS_304 ((grpc_mdelem){&grpc_static_mdelem_table[70]}) /* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 (&grpc_static_mdelem_table[71]) +#define GRPC_MDELEM_STATUS_400 ((grpc_mdelem){&grpc_static_mdelem_table[71]}) /* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 (&grpc_static_mdelem_table[72]) +#define GRPC_MDELEM_STATUS_404 ((grpc_mdelem){&grpc_static_mdelem_table[72]}) /* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 (&grpc_static_mdelem_table[73]) +#define GRPC_MDELEM_STATUS_500 ((grpc_mdelem){&grpc_static_mdelem_table[73]}) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - (&grpc_static_mdelem_table[74]) + ((grpc_mdelem){&grpc_static_mdelem_table[74]}) /* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS (&grpc_static_mdelem_table[75]) +#define GRPC_MDELEM_TE_TRAILERS ((grpc_mdelem){&grpc_static_mdelem_table[75]}) /* "transfer-encoding": "" */ -#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (&grpc_static_mdelem_table[76]) +#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[76]}) /* "user-agent": "" */ -#define GRPC_MDELEM_USER_AGENT_EMPTY (&grpc_static_mdelem_table[77]) +#define GRPC_MDELEM_USER_AGENT_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[77]}) /* "vary": "" */ -#define GRPC_MDELEM_VARY_EMPTY (&grpc_static_mdelem_table[78]) +#define GRPC_MDELEM_VARY_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[78]}) /* "via": "" */ -#define GRPC_MDELEM_VIA_EMPTY (&grpc_static_mdelem_table[79]) +#define GRPC_MDELEM_VIA_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[79]}) /* "www-authenticate": "" */ -#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[80]) +#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY \ + ((grpc_mdelem){&grpc_static_mdelem_table[80]}) -grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b); +grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b); extern const uint8_t grpc_static_accept_encoding_metadata[8]; #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ - (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]) + ((grpc_mdelem){&grpc_static_mdelem_table \ + [grpc_static_accept_encoding_metadata[(algs)]]}) #endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */ diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index deb155e6593..0259fa23eb3 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -47,7 +47,7 @@ /* These routines are here to facilitate debugging - they produce string representations of various transport data structures */ -static void put_metadata(gpr_strvec *b, grpc_mdelem *md) { +static void put_metadata(gpr_strvec *b, grpc_mdelem md) { gpr_strvec_add(b, gpr_strdup("key=")); gpr_strvec_add(b, grpc_dump_slice(md->key, GPR_DUMP_HEX | GPR_DUMP_ASCII)); diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 65f44660d2c..cac0a19e5e7 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -77,7 +77,7 @@ class MetadataBatch { const grpc_mdelem> { public: const grpc_mdelem &operator*() const { return *elem_->md; } - const grpc_mdelem *operator->() const { return elem_->md; } + const grpc_mdelem operator->() const { return elem_->md; } const_iterator &operator++() { elem_ = elem_->next; diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index 48e16c001ee..1f666b85bb0 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -53,7 +53,7 @@ static void test_algorithm_mesh(void) { char *name; grpc_compression_algorithm parsed; grpc_slice mdstr; - grpc_mdelem *mdelem; + grpc_mdelem mdelem; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index 817a9636bfa..862966cc38d 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -195,7 +195,7 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value) { grpc_slice_buffer output; - grpc_mdelem *elem = + grpc_mdelem elem = grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index b3b3f7ac7c4..cfa3c5c088d 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -44,7 +44,7 @@ bool squelch = true; bool leak_check = true; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { +static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { GRPC_MDELEM_UNREF(exec_ctx, md); } static void dont_log(gpr_log_func_args *args) {} diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 6d2b4111c2e..14c5de24406 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -45,7 +45,7 @@ typedef struct { va_list args; } test_checker; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { +static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { const char *ekey, *evalue; test_checker *chk = ud; ekey = va_arg(chk->args, char *); diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index 695846399ee..0de1e2729ab 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -53,7 +53,7 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_slice mdstr, static void assert_index(const grpc_chttp2_hptbl *tbl, uint32_t idx, const char *key, const char *value) { - grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx); + grpc_mdelem md = grpc_chttp2_hptbl_lookup(tbl, idx); assert_str(tbl, md->key, key); assert_str(tbl, md->value, value); } @@ -143,7 +143,7 @@ static void test_many_additions(void) { grpc_chttp2_hptbl_init(&exec_ctx, &tbl); for (i = 0; i < 100000; i++) { - grpc_mdelem *elem; + grpc_mdelem elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); elem = @@ -171,7 +171,7 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, const char *key, const char *value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem *md = + grpc_mdelem md = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), grpc_slice_from_copied_string(value)); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); @@ -185,7 +185,7 @@ static void test_find(void) { grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; - grpc_mdelem *elem; + grpc_mdelem elem; grpc_chttp2_hptbl_find_result r; LOG_TEST("test_find"); diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 7410d7b2d71..59b5edce0ac 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -69,7 +69,7 @@ static grpc_slice maybe_dup(grpc_slice in, bool dup) { } static void test_create_metadata(bool intern_keys, bool intern_values) { - grpc_mdelem *m1, *m2, *m3; + grpc_mdelem m1, *m2, *m3; gpr_log(GPR_INFO, "test_create_metadata: intern_keys=%d intern_values=%d", intern_keys, intern_values); @@ -129,8 +129,8 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, static void test_create_many_persistant_metadata(void) { char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; - grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); - grpc_mdelem *md; + grpc_mdelem *created = gpr_malloc(sizeof(grpc_mdelem) * MANY); + grpc_mdelem md; gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); @@ -170,7 +170,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys, grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem *a, *b, *c; + grpc_mdelem a, *b, *c; GRPC_MDELEM_UNREF( &exec_ctx, a = grpc_mdelem_from_slices( @@ -256,7 +256,7 @@ static void test_things_stick_around(void) { static void test_user_data_works(void) { int *ud1; int *ud2; - grpc_mdelem *md; + grpc_mdelem md; gpr_log(GPR_INFO, "test_user_data_works"); grpc_init(); @@ -279,7 +279,7 @@ static void test_user_data_works(void) { static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value, bool intern_key, bool intern_value) { - grpc_mdelem *elem = grpc_mdelem_from_slices( + grpc_mdelem elem = grpc_mdelem_from_slices( exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_string(value), intern_value)); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); @@ -291,7 +291,7 @@ static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, const uint8_t *value, size_t value_len, bool intern_key, bool intern_value) { - grpc_mdelem *elem = grpc_mdelem_from_slices( + grpc_mdelem elem = grpc_mdelem_from_slices( exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_buffer(value, value_len), intern_value)); @@ -343,8 +343,8 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem *p = &grpc_static_mdelem_table[i]; - grpc_mdelem *q = grpc_mdelem_from_slices( + grpc_mdelem p = &grpc_static_mdelem_table[i]; + grpc_mdelem q = grpc_mdelem_from_slices( &exec_ctx, maybe_dup(p->key, dup_key), maybe_dup(p->value, dup_value)); GPR_ASSERT(p == q); } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 4583df3bedc..e1acdc12c6f 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -355,11 +355,11 @@ for i, elem in enumerate(all_elems): [len(elem[1])] + [ord(c) for c in elem[1]])) print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) -print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' +print >>H, 'extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];' for i, elem in enumerate(all_elems): print >>H, '/* "%s": "%s" */' % elem - print >>H, '#define %s (&grpc_static_mdelem_table[%d])' % (mangle(elem).upper(), i) + print >>H, '#define %s ((grpc_mdelem){&grpc_static_mdelem_table[%d]})' % (mangle(elem).upper(), i) print >>H print >>C, 'uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = {' print >>C, ' %s' % ','.join('%d' % static_userdata.get(elem, 0) for elem in all_elems) @@ -435,16 +435,16 @@ print >>C, 'static const uint16_t elem_keys[] = {%s};' % ','.join('%d' % k for k print >>C, 'static const uint8_t elem_idxs[] = {%s};' % ','.join('%d' % i for i in idxs) print >>C -print >>H, 'grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b);' -print >>C, 'grpc_mdelem *grpc_static_mdelem_for_static_strings(int a, int b) {' -print >>C, ' if (a == -1 || b == -1) return NULL;' +print >>H, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b);' +print >>C, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) {' +print >>C, ' if (a == -1 || b == -1) return GRPC_MDNULL;' print >>C, ' uint32_t k = (uint32_t)(a * %d + b);' % len(all_strs) print >>C, ' uint32_t h = elems_phash(k);' -print >>C, ' return elem_keys[h] == k ? &grpc_static_mdelem_table[elem_idxs[h]] : NULL;' +print >>C, ' return elem_keys[h] == k ? (grpc_mdelem){&grpc_static_mdelem_table[elem_idxs[h]]} : GRPC_MDNULL;' print >>C, '}' print >>C -print >>C, 'grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' +print >>C, 'grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' for a, b in all_elems: print >>C, '{%s,%s},' % (slice_def(str_idx(a)), slice_def(str_idx(b))) print >>C, '};' @@ -455,7 +455,7 @@ print >>C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) print >>C, '};' print >>C -print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]])' +print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) ((grpc_mdelem){&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]})' print >>H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' From e17029353010d0ef393d0feeb14df20321d6c984 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 09:27:39 -0800 Subject: [PATCH 029/261] Progress towards mdelem pointer elimination --- src/core/lib/surface/channel.c | 27 ++++++++++--------------- src/core/lib/surface/server.c | 12 +++++------ src/core/lib/transport/metadata.c | 5 ++--- src/core/lib/transport/metadata.h | 2 +- src/core/lib/transport/metadata_batch.c | 16 +++++++-------- 5 files changed, 28 insertions(+), 34 deletions(-) diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 7aabca82992..501545b5c0e 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -119,7 +119,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_ARG_DEFAULT_AUTHORITY); } else { - if (channel->default_authority) { + if (!GRPC_MDISNULL(channel->default_authority)) { /* setting this takes precedence over anything else */ GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } @@ -133,7 +133,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - if (channel->default_authority) { + if (!GRPC_MDISNULL(channel->default_authority)) { /* other ways of setting this (notably ssl) take precedence */ gpr_log(GPR_ERROR, "%s ignored: default host already set some other way", @@ -199,9 +199,9 @@ static grpc_call *grpc_channel_create_call_internal( GPR_ASSERT(!(cq != NULL && pollset_set_alternative != NULL)); send_metadata[num_metadata++] = path_mdelem; - if (authority_mdelem != NULL) { + if (!GRPC_MDISNULL(authority_mdelem)) { send_metadata[num_metadata++] = authority_mdelem; - } else if (channel->default_authority != NULL) { + } else if (!GRPC_MDISNULL(channel->default_authority)) { send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority); } @@ -236,7 +236,7 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_slice_ref(method)), host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(*host)) - : NULL, + : GRPC_MDNULL, deadline); grpc_exec_ctx_finish(&exec_ctx); return call; @@ -253,7 +253,7 @@ grpc_call *grpc_channel_create_pollset_set_call( grpc_slice_ref(method)), host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(*host)) - : NULL, + : GRPC_MDNULL, deadline); } @@ -273,7 +273,7 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, host ? grpc_mdelem_from_slices( &exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern(grpc_slice_from_copied_string(host))) - : NULL; + : GRPC_MDNULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; @@ -301,8 +301,7 @@ grpc_call *grpc_channel_create_registered_call( grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL, - GRPC_MDELEM_REF(rc->path), - rc->authority ? GRPC_MDELEM_REF(rc->authority) : NULL, deadline); + GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), deadline); grpc_exec_ctx_finish(&exec_ctx); return call; } @@ -331,14 +330,10 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, void *arg, registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; GRPC_MDELEM_UNREF(exec_ctx, rc->path); - if (rc->authority) { - GRPC_MDELEM_UNREF(exec_ctx, rc->authority); - } + GRPC_MDELEM_UNREF(exec_ctx, rc->authority); gpr_free(rc); } - if (channel->default_authority != NULL) { - GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); - } + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); @@ -368,7 +363,7 @@ grpc_compression_options grpc_channel_compression_options( } grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, - grpc_channel *channel, int i) { + grpc_channel *channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index d16ed92c18a..c43a6ef4b3d 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -739,16 +739,16 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (grpc_slice_cmp(md->key, GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { if (!calld->path_set) { - calld->path = grpc_slice_ref(md->value); + calld->path = grpc_slice_ref(GRPC_MDVALUE(md)); } - return NULL; - } else if (grpc_slice_cmp(md->key, GRPC_MDSTR_AUTHORITY) == 0) { + return GRPC_MDNULL; + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { if (!calld->host_set) { - calld->host = grpc_slice_ref(md->value); + calld->host = grpc_slice_ref(GRPC_MDVALUE(md)); } - return NULL; + return GRPC_MDNULL; } return md; } diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 370d92d8580..c114cf9a30a 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -313,8 +313,8 @@ size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem) { } grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { + if (gmd.payload == NULL || is_mdelem_static(gmd)) return gmd; internal_metadata *md = (internal_metadata *)gmd.payload; - if (is_mdelem_static(gmd)) return gmd; #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, @@ -333,9 +333,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { } void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { + if (gmd.payload == NULL || is_mdelem_static(gmd)) return; internal_metadata *md = (internal_metadata *)gmd.payload; - if (!md) return; - if (is_mdelem_static(gmd)) return; #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index cc109d50527..da5416bf762 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -127,7 +127,7 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md); /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ #define GRPC_MDELEM_LENGTH(e) \ - (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(MRPC_MDVALUE((e))) + \ + (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(GRPC_MDVALUE((e))) + \ 32) #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 0cd92b02077..9e0a8fbbe1e 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -52,7 +52,7 @@ static void assert_valid_list(grpc_mdelem_list *list) { GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL)); for (l = list->head; l; l = l->next) { - GPR_ASSERT(l->md); + GPR_ASSERT(!GRPC_MDISNULL(l->md)); GPR_ASSERT((l->prev == NULL) == (l == list->head)); GPR_ASSERT((l->next == NULL) == (l == list->tail)); if (l->next) GPR_ASSERT(l->next->prev == l); @@ -83,14 +83,14 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { - GPR_ASSERT(elem_to_add); + GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; grpc_metadata_batch_link_head(batch, storage); } static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(storage->md); + GPR_ASSERT(!GRPC_MDISNULL(storage->md)); storage->prev = NULL; storage->next = list->head; if (list->head != NULL) { @@ -110,14 +110,14 @@ void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { - GPR_ASSERT(elem_to_add); + GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; grpc_metadata_batch_link_tail(batch, storage); } static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(storage->md); + GPR_ASSERT(!GRPC_MDISNULL(storage->md)); storage->prev = list->tail; storage->next = NULL; storage->reserved = NULL; @@ -157,7 +157,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, grpc_mdelem orig = l->md; grpc_mdelem filt = filter(exec_ctx, user_data, orig); next = l->next; - if (filt == NULL) { + if (GRPC_MDISNULL(filt)) { if (l->prev) { l->prev->next = l->next; } @@ -172,7 +172,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, } assert_valid_list(&batch->list); GRPC_MDELEM_UNREF(exec_ctx, l->md); - } else if (filt != orig) { + } else if (!grpc_mdelem_eq(filt, orig)) { GRPC_MDELEM_UNREF(exec_ctx, orig); l->md = filt; } @@ -184,7 +184,7 @@ void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, static grpc_mdelem no_metadata_for_you(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem elem) { - return NULL; + return GRPC_MDNULL; } void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx, From a8b66a6e02e76cec6acf1179a42e19920749c3be Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 13:01:45 -0800 Subject: [PATCH 030/261] Get core compiling again --- src/core/ext/census/grpc_filter.c | 2 +- test/core/compression/algorithm_test.c | 9 ++-- .../core/transport/chttp2/hpack_parser_test.c | 4 +- test/core/transport/chttp2/hpack_table_test.c | 4 +- test/core/transport/metadata_test.c | 49 +++++++++++-------- 5 files changed, 38 insertions(+), 30 deletions(-) diff --git a/src/core/ext/census/grpc_filter.c b/src/core/ext/census/grpc_filter.c index 5008879512c..c1a883b6f8d 100644 --- a/src/core/ext/census/grpc_filter.c +++ b/src/core/ext/census/grpc_filter.c @@ -67,7 +67,7 @@ static void extract_and_annotate_method_tag(grpc_metadata_batch *md, channel_data *chand) { grpc_linked_mdelem *m; for (m = md->list.head; m != NULL; m = m->next) { - if (grpc_slice_cmp(m->md->key, GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_cmp(GRPC_MDKEY(m->md), GRPC_MDSTR_PATH) == 0) { /* Add method tag here */ } } diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index 1f666b85bb0..fa0bdb8c199 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -65,16 +65,17 @@ static void test_algorithm_mesh(void) { grpc_slice_cmp(mdstr, grpc_compression_algorithm_slice(parsed))); GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); mdelem = grpc_compression_encoding_mdelem(parsed); - GPR_ASSERT(0 == grpc_slice_cmp(mdelem->value, mdstr)); - GPR_ASSERT(0 == grpc_slice_cmp(mdelem->key, GRPC_MDSTR_GRPC_ENCODING)); + GPR_ASSERT(0 == grpc_slice_cmp(GRPC_MDVALUE(mdelem), mdstr)); + GPR_ASSERT(0 == + grpc_slice_cmp(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); grpc_slice_unref_internal(&exec_ctx, mdstr); GRPC_MDELEM_UNREF(&exec_ctx, mdelem); grpc_exec_ctx_finish(&exec_ctx); } /* test failure */ - GPR_ASSERT(NULL == - grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT)); + GPR_ASSERT(GRPC_MDISNULL( + grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT))); } static void test_algorithm_failure(void) { diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 14c5de24406..b7f35a5e445 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -52,8 +52,8 @@ static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { GPR_ASSERT(ekey); evalue = va_arg(chk->args, char *); GPR_ASSERT(evalue); - GPR_ASSERT(grpc_slice_str_cmp(md->key, ekey) == 0); - GPR_ASSERT(grpc_slice_str_cmp(md->value, evalue) == 0); + GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); + GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); GRPC_MDELEM_UNREF(exec_ctx, md); } diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index 0de1e2729ab..d2f6d5dc5bc 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -54,8 +54,8 @@ static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_slice mdstr, static void assert_index(const grpc_chttp2_hptbl *tbl, uint32_t idx, const char *key, const char *value) { grpc_mdelem md = grpc_chttp2_hptbl_lookup(tbl, idx); - assert_str(tbl, md->key, key); - assert_str(tbl, md->value, value); + assert_str(tbl, GRPC_MDKEY(md), key); + assert_str(tbl, GRPC_MDVALUE(md), value); } static void test_static_lookup(void) { diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 59b5edce0ac..d31bc1eedf5 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -69,7 +69,7 @@ static grpc_slice maybe_dup(grpc_slice in, bool dup) { } static void test_create_metadata(bool intern_keys, bool intern_values) { - grpc_mdelem m1, *m2, *m3; + grpc_mdelem m1, m2, m3; gpr_log(GPR_INFO, "test_create_metadata: intern_keys=%d intern_values=%d", intern_keys, intern_values); @@ -85,13 +85,13 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { m3 = grpc_mdelem_from_slices( &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("c"), intern_values)); - GPR_ASSERT(m1 == m2); - GPR_ASSERT(m3 != m1); - GPR_ASSERT(grpc_slice_cmp(m3->key, m1->key) == 0); - GPR_ASSERT(grpc_slice_cmp(m3->value, m1->value) != 0); - GPR_ASSERT(grpc_slice_str_cmp(m1->key, "a") == 0); - GPR_ASSERT(grpc_slice_str_cmp(m1->value, "b") == 0); - GPR_ASSERT(grpc_slice_str_cmp(m3->value, "c") == 0); + GPR_ASSERT(grpc_mdelem_eq(m1, m2)); + GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); + GPR_ASSERT(grpc_slice_cmp(GRPC_MDKEY(m3), GRPC_MDKEY(m1)) == 0); + GPR_ASSERT(grpc_slice_cmp(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1)) != 0); + GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); + GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); + GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); GRPC_MDELEM_UNREF(&exec_ctx, m1); GRPC_MDELEM_UNREF(&exec_ctx, m2); GRPC_MDELEM_UNREF(&exec_ctx, m3); @@ -149,7 +149,7 @@ static void test_create_many_persistant_metadata(void) { md = grpc_mdelem_from_slices( &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), grpc_slice_intern(grpc_slice_from_copied_string(buffer))); - GPR_ASSERT(md == created[i]); + GPR_ASSERT(grpc_mdelem_eq(md, created[i])); GRPC_MDELEM_UNREF(&exec_ctx, md); } /* cleanup phase */ @@ -170,7 +170,7 @@ static void test_spin_creating_the_same_thing(bool intern_keys, grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem a, *b, *c; + grpc_mdelem a, b, c; GRPC_MDELEM_UNREF( &exec_ctx, a = grpc_mdelem_from_slices( @@ -189,14 +189,15 @@ static void test_spin_creating_the_same_thing(bool intern_keys, &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); + GPR_ASSERT(grpc_mdelem_eq(a, b)); + GPR_ASSERT(grpc_mdelem_eq(a, c)); if (intern_keys && intern_values) { - GPR_ASSERT(a == b); - GPR_ASSERT(a == c); + GPR_ASSERT(a.payload == b.payload); + GPR_ASSERT(a.payload == c.payload); } else { - // TODO(ctiller): make this true - // GPR_ASSERT(a != b); - // GPR_ASSERT(a != c); - // GPR_ASSERT(b != c); + GPR_ASSERT(a.payload != b.payload); + GPR_ASSERT(a.payload != c.payload); + GPR_ASSERT(b.payload != c.payload); } grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); @@ -295,7 +296,7 @@ static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), maybe_intern(grpc_slice_from_static_buffer(value, value_len), intern_value)); - GPR_ASSERT(grpc_is_binary_header(elem->key)); + GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); grpc_slice value_slice = grpc_slice_from_copied_buffer((const char *)value, value_len); @@ -343,10 +344,16 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem p = &grpc_static_mdelem_table[i]; - grpc_mdelem q = grpc_mdelem_from_slices( - &exec_ctx, maybe_dup(p->key, dup_key), maybe_dup(p->value, dup_value)); - GPR_ASSERT(p == q); + grpc_mdelem p = (grpc_mdelem){&grpc_static_mdelem_table[i]}; + grpc_mdelem q = + grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), + maybe_dup(GRPC_MDVALUE(p), dup_value)); + GPR_ASSERT(grpc_mdelem_eq(p, q)); + if (dup_key || dup_value) { + GPR_ASSERT(p.payload != q.payload); + } else { + GPR_ASSERT(p.payload == q.payload); + } } grpc_exec_ctx_finish(&exec_ctx); From 9ecadce1e089901ca0c9317f7d8f6d41689f8f61 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 14:52:25 -0800 Subject: [PATCH 031/261] Get identity law testing right --- include/grpc/impl/codegen/grpc_types.h | 3 + src/core/ext/lb_policy/grpclb/grpclb.c | 16 +- src/core/lib/slice/slice_intern.c | 5 + src/core/lib/slice/slice_internal.h | 3 + src/core/lib/transport/metadata.c | 268 +++++++++++++++------- src/core/lib/transport/metadata.h | 51 +++- src/core/lib/transport/static_metadata.c | 3 +- src/core/lib/transport/static_metadata.h | 204 +++++++++------- test/core/transport/metadata_test.c | 38 ++- tools/codegen/core/gen_static_metadata.py | 6 +- 10 files changed, 413 insertions(+), 184 deletions(-) diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 5170621bbb9..ac9a007641d 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -292,8 +292,11 @@ typedef enum grpc_call_error { /** A single metadata element */ typedef struct grpc_metadata { + /* the key, value values are expected to line up with grpc_mdelem: if changing + them, update metadata.h at the same time. */ grpc_slice key; grpc_slice value; + uint32_t flags; /** The following fields are reserved for grpc internal use. diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index b10b9803312..795d68d5e78 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -381,10 +381,14 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, /* vtable for LB tokens in grpc_lb_addresses. */ static void *lb_token_copy(void *token) { - return token == NULL ? NULL : GRPC_MDELEM_REF((grpc_mdelem){token}).payload; + return token == NULL + ? NULL + : (void *)GRPC_MDELEM_REF((grpc_mdelem){(uintptr_t)token}).payload; } static void lb_token_destroy(grpc_exec_ctx *exec_ctx, void *token) { - if (token != NULL) GRPC_MDELEM_UNREF(exec_ctx, (grpc_mdelem){token}); + if (token != NULL) { + GRPC_MDELEM_UNREF(exec_ctx, (grpc_mdelem){(uintptr_t)token}); + } } static int lb_token_cmp(void *token1, void *token2) { if (token1 > token2) return 1; @@ -454,9 +458,9 @@ static grpc_lb_addresses *process_serverlist_locked( strnlen(server->load_balance_token, lb_token_max_length); grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( server->load_balance_token, lb_token_length); - user_data = - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, lb_token_mdstr) - .payload; + user_data = (void *)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, + lb_token_mdstr) + .payload; } else { char *uri = grpc_sockaddr_to_uri(&addr); gpr_log(GPR_INFO, @@ -464,7 +468,7 @@ static grpc_lb_addresses *process_serverlist_locked( "be used instead", uri); gpr_free(uri); - user_data = GRPC_MDELEM_LB_TOKEN_EMPTY.payload; + user_data = (void *)GRPC_MDELEM_LB_TOKEN_EMPTY.payload; } grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len, diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 6f65a3dcc84..2d932849264 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -193,6 +193,11 @@ void grpc_slice_static_intern(grpc_slice *slice) { } } +bool grpc_slice_is_interned(grpc_slice slice) { + return (slice.refcount && slice.refcount->vtable == &interned_slice_vtable) || + grpc_is_static_metadata_string(slice); +} + grpc_slice grpc_slice_intern(grpc_slice slice) { if (grpc_is_static_metadata_string(slice)) { return slice; diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 695bd308ad8..211d5f06be6 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -46,6 +46,9 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *sb); +/* Check if a slice is interned */ +bool grpc_slice_is_interned(grpc_slice slice); + void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); void grpc_test_only_set_slice_hash_seed(uint32_t key); diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index c114cf9a30a..f3f6b1311fc 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -80,9 +80,9 @@ typedef void (*destroy_user_data_func)(void *user_data); -/* Shadow structure for grpc_mdelem_data for non-static elements */ -typedef struct internal_metadata { - /* must be byte compatible with grpc_mdelem */ +/* Shadow structure for grpc_mdelem_data for interned elements */ +typedef struct interned_metadata { + /* must be byte compatible with grpc_mdelem_data */ grpc_slice key; grpc_slice value; @@ -93,12 +93,22 @@ typedef struct internal_metadata { gpr_atm destroy_user_data; gpr_atm user_data; - struct internal_metadata *bucket_next; -} internal_metadata; + struct interned_metadata *bucket_next; +} interned_metadata; + +/* Shadow structure for grpc_mdelem_data for allocated elements */ +typedef struct allocated_metadata { + /* must be byte compatible with grpc_mdelem_data */ + grpc_slice key; + grpc_slice value; + + /* private only data */ + gpr_atm refcnt; +} allocated_metadata; typedef struct mdtab_shard { gpr_mu mu; - internal_metadata **elems; + interned_metadata **elems; size_t count; size_t capacity; /** Estimate of the number of unreferenced mdelems in the hash table. @@ -142,12 +152,13 @@ void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { } static int is_mdelem_static(grpc_mdelem e) { - return e.payload >= &grpc_static_mdelem_table[0] && - e.payload < &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; + return GRPC_MDELEM_DATA(e) >= &grpc_static_mdelem_table[0] && + GRPC_MDELEM_DATA(e) < + &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; } static void ref_md_locked(mdtab_shard *shard, - internal_metadata *md DEBUG_ARGS) { + interned_metadata *md DEBUG_ARGS) { #ifdef GRPC_METADATA_REFCOUNT_DEBUG gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, @@ -163,8 +174,8 @@ static void ref_md_locked(mdtab_shard *shard, static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { size_t i; - internal_metadata **prev_next; - internal_metadata *md, *next; + interned_metadata **prev_next; + interned_metadata *md, *next; gpr_atm num_freed = 0; GPR_TIMER_BEGIN("gc_mdtab", 0); @@ -196,14 +207,14 @@ static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { static void grow_mdtab(mdtab_shard *shard) { size_t capacity = shard->capacity * 2; size_t i; - internal_metadata **mdtab; - internal_metadata *md, *next; + interned_metadata **mdtab; + interned_metadata *md, *next; uint32_t hash; GPR_TIMER_BEGIN("grow_mdtab", 0); - mdtab = gpr_malloc(sizeof(internal_metadata *) * capacity); - memset(mdtab, 0, sizeof(internal_metadata *) * capacity); + mdtab = gpr_malloc(sizeof(interned_metadata *) * capacity); + memset(mdtab, 0, sizeof(interned_metadata *) * capacity); for (i = 0; i < shard->capacity; i++) { for (md = shard->elems[i]; md; md = next) { @@ -233,10 +244,21 @@ static void rehash_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { } } -grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value) { - grpc_slice_static_intern(&key); - grpc_slice_static_intern(&value); +grpc_mdelem grpc_mdelem_create( + grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value, + grpc_mdelem_data *compatible_external_backing_store) { + if (!grpc_slice_is_interned(key) || !grpc_slice_is_interned(value)) { + if (compatible_external_backing_store != NULL) { + return GRPC_MAKE_MDELEM(compatible_external_backing_store, + GRPC_MDELEM_STORAGE_EXTERNAL); + } + + allocated_metadata *allocated = gpr_malloc(sizeof(*allocated)); + allocated->key = grpc_slice_ref_internal(key); + allocated->value = grpc_slice_ref_internal(value); + gpr_atm_rel_store(&allocated->refcnt, 1); + return GRPC_MAKE_MDELEM(allocated, GRPC_MDELEM_STORAGE_ALLOCATED); + } grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( grpc_static_metadata_index(key), grpc_static_metadata_index(value)); @@ -246,7 +268,7 @@ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(key), grpc_slice_hash(value)); - internal_metadata *md; + interned_metadata *md; mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; size_t idx; @@ -261,18 +283,16 @@ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice_cmp(value, md->value) == 0) { REF_MD_LOCKED(shard, md); gpr_mu_unlock(&shard->mu); - grpc_slice_unref_internal(exec_ctx, key); - grpc_slice_unref_internal(exec_ctx, value); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return (grpc_mdelem){(grpc_mdelem_data *)md}; + return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); } } /* not found: create a new pair */ - md = gpr_malloc(sizeof(internal_metadata)); + md = gpr_malloc(sizeof(interned_metadata)); gpr_atm_rel_store(&md->refcnt, 1); - md->key = key; - md->value = value; + md->key = grpc_slice_ref_internal(key); + md->value = grpc_slice_ref_internal(value); md->user_data = 0; md->destroy_user_data = 0; md->bucket_next = shard->elems[idx]; @@ -294,7 +314,21 @@ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return (grpc_mdelem){(grpc_mdelem_data *)md}; + return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); +} + +grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value) { + grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, NULL); + grpc_slice_unref_internal(exec_ctx, key); + grpc_slice_unref_internal(exec_ctx, value); + return out; +} + +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx *exec_ctx, + grpc_metadata *metadata) { + return grpc_mdelem_create(exec_ctx, metadata->key, metadata->value, + (grpc_mdelem_data *)metadata); } static size_t get_base64_encoded_size(size_t raw_length) { @@ -313,81 +347,151 @@ size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem) { } grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { - if (gmd.payload == NULL || is_mdelem_static(gmd)) return gmd; - internal_metadata *md = (internal_metadata *)gmd.payload; + switch (GRPC_MDELEM_STORAGE(gmd)) { + case GRPC_MDELEM_STORAGE_EXTERNAL: + case GRPC_MDELEM_STORAGE_STATIC: + break; + case GRPC_MDELEM_STORAGE_INTERNED: { + interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) + 1, + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); +#endif + /* we can assume the ref count is >= 1 as the application is calling + this function - meaning that no adjustment to mdtab_free is necessary, + simplifying the logic here to be just an atomic increment */ + /* use C assert to have this removed in opt builds */ + GPR_ASSERT(gpr_atm_no_barrier_load(&md->refcnt) >= 1); + gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); + break; + } + case GRPC_MDELEM_STORAGE_ALLOCATED: { + allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); +#ifdef GRPC_METADATA_REFCOUNT_DEBUG + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) + 1, + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif - /* we can assume the ref count is >= 1 as the application is calling - this function - meaning that no adjustment to mdtab_free is necessary, - simplifying the logic here to be just an atomic increment */ - /* use C assert to have this removed in opt builds */ - GPR_ASSERT(gpr_atm_no_barrier_load(&md->refcnt) >= 1); - gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); + /* we can assume the ref count is >= 1 as the application is calling + this function - meaning that no adjustment to mdtab_free is necessary, + simplifying the logic here to be just an atomic increment */ + /* use C assert to have this removed in opt builds */ + gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); + break; + } + } return gmd; } void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { - if (gmd.payload == NULL || is_mdelem_static(gmd)) return; - internal_metadata *md = (internal_metadata *)gmd.payload; + switch (GRPC_MDELEM_STORAGE(gmd)) { + case GRPC_MDELEM_STORAGE_EXTERNAL: + case GRPC_MDELEM_STORAGE_STATIC: + break; + case GRPC_MDELEM_STORAGE_INTERNED: { + interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) - 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) - 1, + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); #endif - uint32_t hash = - GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), grpc_slice_hash(md->value)); - const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); - GPR_ASSERT(prev_refcount >= 1); - if (1 == prev_refcount) { - /* once the refcount hits zero, some other thread can come along and - free md at any time: it's unsafe from this point on to access it */ - mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; - gpr_atm_no_barrier_fetch_add(&shard->free_estimate, 1); + uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), + grpc_slice_hash(md->value)); + const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); + GPR_ASSERT(prev_refcount >= 1); + if (1 == prev_refcount) { + /* once the refcount hits zero, some other thread can come along and + free md at any time: it's unsafe from this point on to access it */ + mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; + gpr_atm_no_barrier_fetch_add(&shard->free_estimate, 1); + } + break; + } + case GRPC_MDELEM_STORAGE_ALLOCATED: { + allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); +#ifdef GRPC_METADATA_REFCOUNT_DEBUG + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) - 1, + grpc_mdstr_as_c_string((grpc_slice)md->key), + grpc_mdstr_as_c_string((grpc_slice)md->value)); +#endif + const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); + GPR_ASSERT(prev_refcount >= 1); + if (1 == prev_refcount) { + grpc_slice_unref_internal(exec_ctx, md->key); + grpc_slice_unref_internal(exec_ctx, md->value); + gpr_free(md); + } + break; + } } } void *grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void *)) { - internal_metadata *im = (internal_metadata *)md.payload; - void *result; - if (is_mdelem_static(md)) { - return (void *) - grpc_static_mdelem_user_data[md.payload - grpc_static_mdelem_table]; - } - if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { - return (void *)gpr_atm_no_barrier_load(&im->user_data); - } else { - return NULL; + switch (GRPC_MDELEM_STORAGE(md)) { + case GRPC_MDELEM_STORAGE_EXTERNAL: + case GRPC_MDELEM_STORAGE_ALLOCATED: + return NULL; + case GRPC_MDELEM_STORAGE_STATIC: + return (void *)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - + grpc_static_mdelem_table]; + case GRPC_MDELEM_STORAGE_INTERNED: { + interned_metadata *im = (interned_metadata *)GRPC_MDELEM_DATA(md); + void *result; + if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { + return (void *)gpr_atm_no_barrier_load(&im->user_data); + } else { + return NULL; + } + return result; + } } - return result; + GPR_UNREACHABLE_CODE(return NULL); } void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), void *user_data) { - internal_metadata *im = (internal_metadata *)md.payload; - GPR_ASSERT(!is_mdelem_static(md)); - GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); - gpr_mu_lock(&im->mu_user_data); - if (gpr_atm_no_barrier_load(&im->destroy_user_data)) { - /* user data can only be set once */ - gpr_mu_unlock(&im->mu_user_data); - if (destroy_func != NULL) { + switch (GRPC_MDELEM_STORAGE(md)) { + case GRPC_MDELEM_STORAGE_EXTERNAL: + case GRPC_MDELEM_STORAGE_ALLOCATED: destroy_func(user_data); + return NULL; + case GRPC_MDELEM_STORAGE_STATIC: + destroy_func(user_data); + return (void *)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - + grpc_static_mdelem_table]; + case GRPC_MDELEM_STORAGE_INTERNED: { + interned_metadata *im = (interned_metadata *)GRPC_MDELEM_DATA(md); + GPR_ASSERT(!is_mdelem_static(md)); + GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); + gpr_mu_lock(&im->mu_user_data); + if (gpr_atm_no_barrier_load(&im->destroy_user_data)) { + /* user data can only be set once */ + gpr_mu_unlock(&im->mu_user_data); + if (destroy_func != NULL) { + destroy_func(user_data); + } + return (void *)gpr_atm_no_barrier_load(&im->user_data); + } + gpr_atm_no_barrier_store(&im->user_data, (gpr_atm)user_data); + gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func); + gpr_mu_unlock(&im->mu_user_data); + return user_data; } - return (void *)gpr_atm_no_barrier_load(&im->user_data); } - gpr_atm_no_barrier_store(&im->user_data, (gpr_atm)user_data); - gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func); - gpr_mu_unlock(&im->mu_user_data); - return user_data; + GPR_UNREACHABLE_CODE(return NULL); } bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index da5416bf762..6d0afbe7891 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -34,6 +34,7 @@ #ifndef GRPC_CORE_LIB_TRANSPORT_METADATA_H #define GRPC_CORE_LIB_TRANSPORT_METADATA_H +#include #include #include @@ -76,22 +77,58 @@ extern "C" { /* Forward declarations */ typedef struct grpc_mdelem grpc_mdelem; -/* if changing this, make identical changes in internal_metadata in - metadata.c */ +/* if changing this, make identical changes in: + - interned_metadata, allocated_metadata in metadata.c + - grpc_metadata in grpc_types.h */ typedef struct grpc_mdelem_data { const grpc_slice key; const grpc_slice value; /* there is a private part to this in metadata.c */ } grpc_mdelem_data; +typedef enum { + /* memory pointed to by grpc_mdelem::payload is owned by an external system */ + GRPC_MDELEM_STORAGE_EXTERNAL = 0, + /* memory pointed to by grpc_mdelem::payload is interned by the metadata + system */ + GRPC_MDELEM_STORAGE_INTERNED = 1, + /* memory pointed to by grpc_mdelem::payload is allocated by the metadata + system */ + GRPC_MDELEM_STORAGE_ALLOCATED = 2, + /* memory is in the static metadata table */ + GRPC_MDELEM_STORAGE_STATIC = 3, +} grpc_mdelem_data_storage; + struct grpc_mdelem { - grpc_mdelem_data *payload; + /* a grpc_mdelem_data* generally, with the two lower bits signalling memory + ownership as per grpc_mdelem_data_storage */ + uintptr_t payload; }; +#define GRPC_MDELEM_DATA(md) \ + ((grpc_mdelem_data *)((md).payload & ~(uintptr_t)3)) +#define GRPC_MDELEM_STORAGE(md) \ + ((grpc_mdelem_data_storage)((md).payload & (uintptr_t)3)) +#define GRPC_MAKE_MDELEM(data, storage) \ + ((grpc_mdelem){((uintptr_t)(data)) | ((uintptr_t)storage)}) + /* Unrefs the slices. */ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value); +/* Cheaply convert a grpc_metadata to a grpc_mdelem; may use the grpc_metadata + object as backing storage (so lifetimes should align) */ +grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx *exec_ctx, + grpc_metadata *metadata); + +/* Does not unref the slices; if a new non-interned mdelem is needed, allocates + one if compatible_external_backing_store is NULL, or uses + compatible_external_backing_store if it is non-NULL (in which case it's the + users responsibility to ensure that it outlives usage) */ +grpc_mdelem grpc_mdelem_create( + grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value, + grpc_mdelem_data *compatible_external_backing_store); + bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b); size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem); @@ -119,11 +156,11 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem md); void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md); #endif -#define GRPC_MDKEY(md) ((md).payload->key) -#define GRPC_MDVALUE(md) ((md).payload->value) +#define GRPC_MDKEY(md) (GRPC_MDELEM_DATA(md)->key) +#define GRPC_MDVALUE(md) (GRPC_MDELEM_DATA(md)->value) -#define GRPC_MDNULL ((grpc_mdelem){NULL}) -#define GRPC_MDISNULL(md) ((md).payload == NULL) +#define GRPC_MDNULL GRPC_MAKE_MDELEM(NULL, GRPC_MDELEM_STORAGE_EXTERNAL) +#define GRPC_MDISNULL(md) (GRPC_MDELEM_DATA(md) == NULL) /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ #define GRPC_MDELEM_LENGTH(e) \ diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 42daabfd89d..575f442a9b0 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -459,7 +459,8 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { uint32_t k = (uint32_t)(a * 98 + b); uint32_t h = elems_phash(k); return elem_keys[h] == k - ? (grpc_mdelem){&grpc_static_mdelem_table[elem_idxs[h]]} + ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]], + GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL; } diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index f5ef5d6dd72..3d3911de16b 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -255,216 +255,252 @@ extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; /* "accept-charset": "" */ #define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[0]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[0], GRPC_MDELEM_STORAGE_STATIC)) /* "accept": "" */ -#define GRPC_MDELEM_ACCEPT_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[1]}) +#define GRPC_MDELEM_ACCEPT_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[1], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-encoding": "" */ #define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[2]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[2], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-encoding": "gzip, deflate" */ #define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ - ((grpc_mdelem){&grpc_static_mdelem_table[3]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[3], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-language": "" */ #define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[4]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[4], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-ranges": "" */ #define GRPC_MDELEM_ACCEPT_RANGES_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[5]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[5], GRPC_MDELEM_STORAGE_STATIC)) /* "access-control-allow-origin": "" */ #define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[6]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[6], GRPC_MDELEM_STORAGE_STATIC)) /* "age": "" */ -#define GRPC_MDELEM_AGE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[7]}) +#define GRPC_MDELEM_AGE_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[7], GRPC_MDELEM_STORAGE_STATIC)) /* "allow": "" */ -#define GRPC_MDELEM_ALLOW_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[8]}) +#define GRPC_MDELEM_ALLOW_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[8], GRPC_MDELEM_STORAGE_STATIC)) /* ":authority": "" */ #define GRPC_MDELEM_AUTHORITY_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[9]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[9], GRPC_MDELEM_STORAGE_STATIC)) /* "authorization": "" */ #define GRPC_MDELEM_AUTHORIZATION_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[10]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[10], GRPC_MDELEM_STORAGE_STATIC)) /* "cache-control": "" */ #define GRPC_MDELEM_CACHE_CONTROL_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[11]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[11], GRPC_MDELEM_STORAGE_STATIC)) /* "content-disposition": "" */ #define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[12]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[12], GRPC_MDELEM_STORAGE_STATIC)) /* "content-encoding": "" */ #define GRPC_MDELEM_CONTENT_ENCODING_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[13]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[13], GRPC_MDELEM_STORAGE_STATIC)) /* "content-language": "" */ #define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[14]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[14], GRPC_MDELEM_STORAGE_STATIC)) /* "content-length": "" */ #define GRPC_MDELEM_CONTENT_LENGTH_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[15]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[15], GRPC_MDELEM_STORAGE_STATIC)) /* "content-location": "" */ #define GRPC_MDELEM_CONTENT_LOCATION_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[16]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[16], GRPC_MDELEM_STORAGE_STATIC)) /* "content-range": "" */ #define GRPC_MDELEM_CONTENT_RANGE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[17]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[17], GRPC_MDELEM_STORAGE_STATIC)) /* "content-type": "application/grpc" */ #define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ - ((grpc_mdelem){&grpc_static_mdelem_table[18]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[18], GRPC_MDELEM_STORAGE_STATIC)) /* "content-type": "" */ #define GRPC_MDELEM_CONTENT_TYPE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[19]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[19], GRPC_MDELEM_STORAGE_STATIC)) /* "cookie": "" */ -#define GRPC_MDELEM_COOKIE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[20]}) +#define GRPC_MDELEM_COOKIE_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[20], GRPC_MDELEM_STORAGE_STATIC)) /* "date": "" */ -#define GRPC_MDELEM_DATE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[21]}) +#define GRPC_MDELEM_DATE_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[21], GRPC_MDELEM_STORAGE_STATIC)) /* "etag": "" */ -#define GRPC_MDELEM_ETAG_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[22]}) +#define GRPC_MDELEM_ETAG_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[22], GRPC_MDELEM_STORAGE_STATIC)) /* "expect": "" */ -#define GRPC_MDELEM_EXPECT_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[23]}) +#define GRPC_MDELEM_EXPECT_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[23], GRPC_MDELEM_STORAGE_STATIC)) /* "expires": "" */ -#define GRPC_MDELEM_EXPIRES_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[24]}) +#define GRPC_MDELEM_EXPIRES_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[24], GRPC_MDELEM_STORAGE_STATIC)) /* "from": "" */ -#define GRPC_MDELEM_FROM_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[25]}) +#define GRPC_MDELEM_FROM_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[25], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "deflate" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ - ((grpc_mdelem){&grpc_static_mdelem_table[26]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[26], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ - ((grpc_mdelem){&grpc_static_mdelem_table[27]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[27], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ - ((grpc_mdelem){&grpc_static_mdelem_table[28]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[28], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "identity" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ - ((grpc_mdelem){&grpc_static_mdelem_table[29]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[29], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "identity,deflate" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ - ((grpc_mdelem){&grpc_static_mdelem_table[30]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[30], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "identity,deflate,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - ((grpc_mdelem){&grpc_static_mdelem_table[31]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[31], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-accept-encoding": "identity,gzip" */ #define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - ((grpc_mdelem){&grpc_static_mdelem_table[32]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[32], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-encoding": "deflate" */ #define GRPC_MDELEM_GRPC_ENCODING_DEFLATE \ - ((grpc_mdelem){&grpc_static_mdelem_table[33]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[33], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-encoding": "gzip" */ #define GRPC_MDELEM_GRPC_ENCODING_GZIP \ - ((grpc_mdelem){&grpc_static_mdelem_table[34]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[34], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-encoding": "identity" */ #define GRPC_MDELEM_GRPC_ENCODING_IDENTITY \ - ((grpc_mdelem){&grpc_static_mdelem_table[35]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[35], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-status": "0" */ -#define GRPC_MDELEM_GRPC_STATUS_0 ((grpc_mdelem){&grpc_static_mdelem_table[36]}) +#define GRPC_MDELEM_GRPC_STATUS_0 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[36], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-status": "1" */ -#define GRPC_MDELEM_GRPC_STATUS_1 ((grpc_mdelem){&grpc_static_mdelem_table[37]}) +#define GRPC_MDELEM_GRPC_STATUS_1 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[37], GRPC_MDELEM_STORAGE_STATIC)) /* "grpc-status": "2" */ -#define GRPC_MDELEM_GRPC_STATUS_2 ((grpc_mdelem){&grpc_static_mdelem_table[38]}) +#define GRPC_MDELEM_GRPC_STATUS_2 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[38], GRPC_MDELEM_STORAGE_STATIC)) /* "host": "" */ -#define GRPC_MDELEM_HOST_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[39]}) +#define GRPC_MDELEM_HOST_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[39], GRPC_MDELEM_STORAGE_STATIC)) /* "if-match": "" */ #define GRPC_MDELEM_IF_MATCH_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[40]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[40], GRPC_MDELEM_STORAGE_STATIC)) /* "if-modified-since": "" */ #define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[41]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[41], GRPC_MDELEM_STORAGE_STATIC)) /* "if-none-match": "" */ #define GRPC_MDELEM_IF_NONE_MATCH_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[42]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[42], GRPC_MDELEM_STORAGE_STATIC)) /* "if-range": "" */ #define GRPC_MDELEM_IF_RANGE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[43]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[43], GRPC_MDELEM_STORAGE_STATIC)) /* "if-unmodified-since": "" */ #define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[44]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[44], GRPC_MDELEM_STORAGE_STATIC)) /* "last-modified": "" */ #define GRPC_MDELEM_LAST_MODIFIED_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[45]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[45], GRPC_MDELEM_STORAGE_STATIC)) /* "lb-cost-bin": "" */ #define GRPC_MDELEM_LB_COST_BIN_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[46]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[46], GRPC_MDELEM_STORAGE_STATIC)) /* "lb-token": "" */ #define GRPC_MDELEM_LB_TOKEN_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[47]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[47], GRPC_MDELEM_STORAGE_STATIC)) /* "link": "" */ -#define GRPC_MDELEM_LINK_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[48]}) +#define GRPC_MDELEM_LINK_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[48], GRPC_MDELEM_STORAGE_STATIC)) /* "location": "" */ #define GRPC_MDELEM_LOCATION_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[49]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[49], GRPC_MDELEM_STORAGE_STATIC)) /* "max-forwards": "" */ #define GRPC_MDELEM_MAX_FORWARDS_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[50]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[50], GRPC_MDELEM_STORAGE_STATIC)) /* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET ((grpc_mdelem){&grpc_static_mdelem_table[51]}) +#define GRPC_MDELEM_METHOD_GET \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[51], GRPC_MDELEM_STORAGE_STATIC)) /* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST ((grpc_mdelem){&grpc_static_mdelem_table[52]}) +#define GRPC_MDELEM_METHOD_POST \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[52], GRPC_MDELEM_STORAGE_STATIC)) /* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT ((grpc_mdelem){&grpc_static_mdelem_table[53]}) +#define GRPC_MDELEM_METHOD_PUT \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[53], GRPC_MDELEM_STORAGE_STATIC)) /* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH ((grpc_mdelem){&grpc_static_mdelem_table[54]}) +#define GRPC_MDELEM_PATH_SLASH \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[54], GRPC_MDELEM_STORAGE_STATIC)) /* ":path": "/index.html" */ #define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ - ((grpc_mdelem){&grpc_static_mdelem_table[55]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[55], GRPC_MDELEM_STORAGE_STATIC)) /* "proxy-authenticate": "" */ #define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[56]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[56], GRPC_MDELEM_STORAGE_STATIC)) /* "proxy-authorization": "" */ #define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[57]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[57], GRPC_MDELEM_STORAGE_STATIC)) /* "range": "" */ -#define GRPC_MDELEM_RANGE_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[58]}) +#define GRPC_MDELEM_RANGE_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[58], GRPC_MDELEM_STORAGE_STATIC)) /* "referer": "" */ -#define GRPC_MDELEM_REFERER_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[59]}) +#define GRPC_MDELEM_REFERER_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[59], GRPC_MDELEM_STORAGE_STATIC)) /* "refresh": "" */ -#define GRPC_MDELEM_REFRESH_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[60]}) +#define GRPC_MDELEM_REFRESH_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[60], GRPC_MDELEM_STORAGE_STATIC)) /* "retry-after": "" */ #define GRPC_MDELEM_RETRY_AFTER_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[61]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[61], GRPC_MDELEM_STORAGE_STATIC)) /* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC ((grpc_mdelem){&grpc_static_mdelem_table[62]}) +#define GRPC_MDELEM_SCHEME_GRPC \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[62], GRPC_MDELEM_STORAGE_STATIC)) /* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP ((grpc_mdelem){&grpc_static_mdelem_table[63]}) +#define GRPC_MDELEM_SCHEME_HTTP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[63], GRPC_MDELEM_STORAGE_STATIC)) /* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS ((grpc_mdelem){&grpc_static_mdelem_table[64]}) +#define GRPC_MDELEM_SCHEME_HTTPS \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[64], GRPC_MDELEM_STORAGE_STATIC)) /* "server": "" */ -#define GRPC_MDELEM_SERVER_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[65]}) +#define GRPC_MDELEM_SERVER_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[65], GRPC_MDELEM_STORAGE_STATIC)) /* "set-cookie": "" */ #define GRPC_MDELEM_SET_COOKIE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[66]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[66], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 ((grpc_mdelem){&grpc_static_mdelem_table[67]}) +#define GRPC_MDELEM_STATUS_200 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[67], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 ((grpc_mdelem){&grpc_static_mdelem_table[68]}) +#define GRPC_MDELEM_STATUS_204 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[68], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 ((grpc_mdelem){&grpc_static_mdelem_table[69]}) +#define GRPC_MDELEM_STATUS_206 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[69], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 ((grpc_mdelem){&grpc_static_mdelem_table[70]}) +#define GRPC_MDELEM_STATUS_304 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[70], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 ((grpc_mdelem){&grpc_static_mdelem_table[71]}) +#define GRPC_MDELEM_STATUS_400 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[71], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 ((grpc_mdelem){&grpc_static_mdelem_table[72]}) +#define GRPC_MDELEM_STATUS_404 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[72], GRPC_MDELEM_STORAGE_STATIC)) /* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 ((grpc_mdelem){&grpc_static_mdelem_table[73]}) +#define GRPC_MDELEM_STATUS_500 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[73], GRPC_MDELEM_STORAGE_STATIC)) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[74]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[74], GRPC_MDELEM_STORAGE_STATIC)) /* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS ((grpc_mdelem){&grpc_static_mdelem_table[75]}) +#define GRPC_MDELEM_TE_TRAILERS \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[75], GRPC_MDELEM_STORAGE_STATIC)) /* "transfer-encoding": "" */ #define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[76]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[76], GRPC_MDELEM_STORAGE_STATIC)) /* "user-agent": "" */ #define GRPC_MDELEM_USER_AGENT_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[77]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[77], GRPC_MDELEM_STORAGE_STATIC)) /* "vary": "" */ -#define GRPC_MDELEM_VARY_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[78]}) +#define GRPC_MDELEM_VARY_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[78], GRPC_MDELEM_STORAGE_STATIC)) /* "via": "" */ -#define GRPC_MDELEM_VIA_EMPTY ((grpc_mdelem){&grpc_static_mdelem_table[79]}) +#define GRPC_MDELEM_VIA_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[79], GRPC_MDELEM_STORAGE_STATIC)) /* "www-authenticate": "" */ #define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY \ - ((grpc_mdelem){&grpc_static_mdelem_table[80]}) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[80], GRPC_MDELEM_STORAGE_STATIC)) grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b); extern const uint8_t grpc_static_accept_encoding_metadata[8]; -#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ - ((grpc_mdelem){&grpc_static_mdelem_table \ - [grpc_static_accept_encoding_metadata[(algs)]]}) +#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ + (GRPC_MAKE_MDELEM( \ + &grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]], \ + GRPC_MDELEM_STORAGE_STATIC)) #endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */ diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index d31bc1eedf5..ce8f1813ffd 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -189,8 +189,39 @@ static void test_spin_creating_the_same_thing(bool intern_keys, &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), maybe_intern(grpc_slice_from_static_string("b"), intern_values))); + if (intern_keys && intern_values) { + GPR_ASSERT(a.payload == b.payload); + GPR_ASSERT(a.payload == c.payload); + } + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); +} + +static void test_identity_laws(bool intern_keys, bool intern_values) { + gpr_log(GPR_INFO, "test_identity_laws: intern_keys=%d intern_values=%d", + intern_keys, intern_values); + + grpc_init(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_mdelem a, b, c; + a = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values)); + b = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values)); + c = grpc_mdelem_from_slices( + &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), + maybe_intern(grpc_slice_from_static_string("b"), intern_values)); + GPR_ASSERT(grpc_mdelem_eq(a, a)); + GPR_ASSERT(grpc_mdelem_eq(b, b)); + GPR_ASSERT(grpc_mdelem_eq(c, c)); GPR_ASSERT(grpc_mdelem_eq(a, b)); + GPR_ASSERT(grpc_mdelem_eq(b, c)); GPR_ASSERT(grpc_mdelem_eq(a, c)); + GPR_ASSERT(grpc_mdelem_eq(b, a)); + GPR_ASSERT(grpc_mdelem_eq(c, b)); + GPR_ASSERT(grpc_mdelem_eq(c, a)); if (intern_keys && intern_values) { GPR_ASSERT(a.payload == b.payload); GPR_ASSERT(a.payload == c.payload); @@ -199,6 +230,9 @@ static void test_spin_creating_the_same_thing(bool intern_keys, GPR_ASSERT(a.payload != c.payload); GPR_ASSERT(b.payload != c.payload); } + GRPC_MDELEM_UNREF(&exec_ctx, a); + GRPC_MDELEM_UNREF(&exec_ctx, b); + GRPC_MDELEM_UNREF(&exec_ctx, c); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -344,7 +378,8 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem p = (grpc_mdelem){&grpc_static_mdelem_table[i]}; + grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], + GRPC_MDELEM_STORAGE_STATIC); grpc_mdelem q = grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), maybe_dup(GRPC_MDVALUE(p), dup_value)); @@ -367,6 +402,7 @@ int main(int argc, char **argv) { for (int v = 0; v <= 1; v++) { test_create_metadata(k, v); test_create_many_ephemeral_metadata(k, v); + test_identity_laws(k, v); test_spin_creating_the_same_thing(k, v); test_mdelem_sizes_in_hpack(k, v); test_copied_static_metadata(k, v); diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index e1acdc12c6f..b1b7840cfd7 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -359,7 +359,7 @@ print >>H, 'extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_ print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];' for i, elem in enumerate(all_elems): print >>H, '/* "%s": "%s" */' % elem - print >>H, '#define %s ((grpc_mdelem){&grpc_static_mdelem_table[%d]})' % (mangle(elem).upper(), i) + print >>H, '#define %s (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[%d], GRPC_MDELEM_STORAGE_STATIC))' % (mangle(elem).upper(), i) print >>H print >>C, 'uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = {' print >>C, ' %s' % ','.join('%d' % static_userdata.get(elem, 0) for elem in all_elems) @@ -440,7 +440,7 @@ print >>C, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) {' print >>C, ' if (a == -1 || b == -1) return GRPC_MDNULL;' print >>C, ' uint32_t k = (uint32_t)(a * %d + b);' % len(all_strs) print >>C, ' uint32_t h = elems_phash(k);' -print >>C, ' return elem_keys[h] == k ? (grpc_mdelem){&grpc_static_mdelem_table[elem_idxs[h]]} : GRPC_MDNULL;' +print >>C, ' return elem_keys[h] == k ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]], GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL;' print >>C, '}' print >>C @@ -455,7 +455,7 @@ print >>C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) print >>C, '};' print >>C -print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) ((grpc_mdelem){&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]})' +print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]], GRPC_MDELEM_STORAGE_STATIC))' print >>H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' From 1282a67fe6c96cd609a9d5a88b0aa4a59ec09d24 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 14:57:53 -0800 Subject: [PATCH 032/261] Take advantage of grpc_metadata/grpc_mdelem equivalency --- src/core/lib/surface/call.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 009163037e3..ec7f1a92c36 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -596,19 +596,19 @@ static int prepare_application_metadata( get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); - l->md = grpc_mdelem_from_slices(exec_ctx, md->key, md->value); - if (!grpc_header_key_is_legal(GRPC_MDKEY(l->md))) { + if (!grpc_header_key_is_legal(md->key)) { char *str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); break; - } else if (!grpc_is_binary_header(GRPC_MDKEY(l->md)) && + } else if (!grpc_is_binary_header(md->value) && !grpc_header_nonbin_value_is_legal(GRPC_MDVALUE(l->md))) { char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); gpr_free(str); break; } + l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata *)md); } if (i != total_count) { for (int j = 0; j <= i; j++) { From 5ae3ffb3676de640598e675f2670ef8695559fbf Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 14:58:32 -0800 Subject: [PATCH 033/261] Fix cleanup bug --- src/core/lib/surface/call.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index ec7f1a92c36..86aa80c79ab 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -611,7 +611,7 @@ static int prepare_application_metadata( l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata *)md); } if (i != total_count) { - for (int j = 0; j <= i; j++) { + for (int j = 0; j < i; j++) { const grpc_metadata *md = get_md_elem(metadata, additional_metadata, j, count); grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; From 03cdd3e2de886659761878ea877f6ad5d51f6319 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 16:10:24 -0800 Subject: [PATCH 034/261] Fix timeout decoding --- src/core/ext/transport/chttp2/transport/parsing.c | 15 ++++++++------- src/core/lib/transport/metadata.c | 1 + src/core/lib/transport/timeout_encoding.c | 15 +++++++-------- src/core/lib/transport/timeout_encoding.h | 3 +-- test/core/transport/timeout_encoding_test.c | 7 ++++--- 5 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 670ce51b725..12f850791de 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -470,23 +470,24 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT) == 0) { gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout); - if (!cached_timeout) { + gpr_timespec timeout; + if (cached_timeout == NULL) { /* not already parsed: parse it now, and store the result away */ cached_timeout = gpr_malloc(sizeof(gpr_timespec)); - if (!grpc_http2_decode_timeout(GRPC_SLICE_START_PTR(GRPC_MDVALUE(md)), - GRPC_SLICE_LENGTH(GRPC_MDVALUE(md)), - cached_timeout)) { + if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), cached_timeout)) { char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); gpr_free(val); *cached_timeout = gpr_inf_future(GPR_TIMESPAN); } - cached_timeout = - grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); + timeout = *cached_timeout; + grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); + } else { + timeout = *cached_timeout; } grpc_chttp2_incoming_metadata_buffer_set_deadline( &s->metadata_buffer[0], - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout)); + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), timeout)); GRPC_MDELEM_UNREF(exec_ctx, md); } else { const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md); diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index f3f6b1311fc..2082d1bac27 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -496,6 +496,7 @@ void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { if (a.payload == b.payload) return true; + if (GRPC_MDISNULL(a) || GRPC_MDISNULL(b)) return false; return 0 == grpc_slice_cmp(GRPC_MDKEY(a), GRPC_MDKEY(b)) && 0 == grpc_slice_cmp(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); } diff --git a/src/core/lib/transport/timeout_encoding.c b/src/core/lib/transport/timeout_encoding.c index b2060be59e5..0d4d7e5a7e3 100644 --- a/src/core/lib/transport/timeout_encoding.c +++ b/src/core/lib/transport/timeout_encoding.c @@ -131,16 +131,15 @@ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer) { } } -static int is_all_whitespace(const char *p) { - while (*p == ' ') p++; - return *p == 0; +static int is_all_whitespace(const char *p, const char *end) { + while (p != end && *p == ' ') p++; + return p == end; } -int grpc_http2_decode_timeout(const uint8_t *buffer, size_t length, - gpr_timespec *timeout) { +int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) { int32_t x = 0; - const uint8_t *p = buffer; - const uint8_t *end = p + length; + const uint8_t *p = GRPC_SLICE_START_PTR(text); + const uint8_t *end = GRPC_SLICE_END_PTR(text); int have_digit = 0; /* skip whitespace */ for (; p != end && *p == ' '; p++) @@ -187,5 +186,5 @@ int grpc_http2_decode_timeout(const uint8_t *buffer, size_t length, return 0; } p++; - return is_all_whitespace((const char *)p); + return is_all_whitespace((const char *)p, (const char *)end); } diff --git a/src/core/lib/transport/timeout_encoding.h b/src/core/lib/transport/timeout_encoding.h index 838892595f0..9b34cec3736 100644 --- a/src/core/lib/transport/timeout_encoding.h +++ b/src/core/lib/transport/timeout_encoding.h @@ -42,7 +42,6 @@ /* Encode/decode timeouts to the GRPC over HTTP/2 format; encoding may round up arbitrarily */ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer); -int grpc_http2_decode_timeout(const uint8_t *buffer, size_t length, - gpr_timespec *timeout); +int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout); #endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */ diff --git a/test/core/transport/timeout_encoding_test.c b/test/core/transport/timeout_encoding_test.c index 23b1eb577b0..10e18049955 100644 --- a/test/core/transport/timeout_encoding_test.c +++ b/test/core/transport/timeout_encoding_test.c @@ -88,8 +88,8 @@ void test_encoding(void) { static void assert_decodes_as(const char *buffer, gpr_timespec expected) { gpr_timespec got; gpr_log(GPR_INFO, "check decoding '%s'", buffer); - GPR_ASSERT(1 == grpc_http2_decode_timeout((const uint8_t *)buffer, - strlen(buffer), &got)); + GPR_ASSERT(1 == grpc_http2_decode_timeout( + grpc_slice_from_static_string(buffer), &got)); GPR_ASSERT(0 == gpr_time_cmp(got, expected)); } @@ -137,7 +137,8 @@ void test_decoding(void) { static void assert_decoding_fails(const char *s) { gpr_timespec x; - GPR_ASSERT(0 == grpc_http2_decode_timeout((const uint8_t *)s, strlen(s), &x)); + GPR_ASSERT(0 == + grpc_http2_decode_timeout(grpc_slice_from_static_string(s), &x)); } void test_decoding_fails(void) { From df2d922285c351c6cb962d7ab8cab3b117bc807f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 16:38:57 -0800 Subject: [PATCH 035/261] Fixes --- src/core/lib/channel/http_server_filter.c | 2 +- src/core/lib/surface/call.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 9b6a583d200..0d11c71d060 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -126,7 +126,7 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET)) { calld->seen_method = 1; *calld->recv_cacheable_request = true; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { + } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) { calld->seen_scheme = 1; } else if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS)) { calld->seen_te_trailers = 1; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 86aa80c79ab..0ca97337e2f 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -601,8 +601,8 @@ static int prepare_application_metadata( gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); break; - } else if (!grpc_is_binary_header(md->value) && - !grpc_header_nonbin_value_is_legal(GRPC_MDVALUE(l->md))) { + } else if (!grpc_is_binary_header(md->key) && + !grpc_header_nonbin_value_is_legal(md->value)) { char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); gpr_free(str); From f5b8ad8449b40e89ff656e74e0d1b11a8150820d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 16:42:35 -0800 Subject: [PATCH 036/261] Fix server --- src/core/lib/surface/server.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index c43a6ef4b3d..b21e1d8113e 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -742,11 +742,13 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { if (!calld->path_set) { calld->path = grpc_slice_ref(GRPC_MDVALUE(md)); + calld->path_set = true; } return GRPC_MDNULL; } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { if (!calld->host_set) { calld->host = grpc_slice_ref(GRPC_MDVALUE(md)); + calld->host_set = true; } return GRPC_MDNULL; } From 50d6e7e79a7fd2c821fe95bb04a532b19032f8e3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 17:13:44 -0800 Subject: [PATCH 037/261] h2_full_test in debug passes --- src/core/lib/slice/slice_hash_table.c | 15 ++++----------- test/core/end2end/tests/request_with_flags.c | 2 +- test/core/end2end/tests/resource_quota_server.c | 2 +- 3 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 55f20155f36..017bf03da90 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -40,18 +40,14 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" -static grpc_slice_refcount terminal_slice_refcount = {NULL}; -static const grpc_slice terminal_slice = {&terminal_slice_refcount, - .data.refcounted = {0, 0}}; - struct grpc_slice_hash_table { gpr_refcount refs; size_t size; grpc_slice_hash_table_entry* entries; }; -static bool is_terminal(grpc_slice slice) { - return slice.refcount == &terminal_slice_refcount; +static bool is_empty(grpc_slice_hash_table_entry *entry) { + return entry->vtable == NULL; } // Helper function for insert and get operations that performs quadratic @@ -61,7 +57,7 @@ static size_t grpc_slice_hash_table_find_index( size_t hash = grpc_slice_hash(key); for (size_t i = 0; i < table->size; ++i) { const size_t idx = (hash + i * i) % table->size; - if (is_terminal(table->entries[idx].key)) { + if (is_empty(&table->entries[idx])) { return find_empty ? idx : table->size; } if (grpc_slice_cmp(table->entries[idx].key, key) == 0) { @@ -95,9 +91,6 @@ grpc_slice_hash_table* grpc_slice_hash_table_create( const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; table->entries = gpr_malloc(entry_size); memset(table->entries, 0, entry_size); - for (size_t i = 0; i < num_entries; ++i) { - table->entries[i].key = terminal_slice; - } for (size_t i = 0; i < num_entries; ++i) { grpc_slice_hash_table_entry* entry = &entries[i]; grpc_slice_hash_table_add(table, entry->key, entry->value, entry->vtable); @@ -115,7 +108,7 @@ void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, if (table != NULL && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { grpc_slice_hash_table_entry* entry = &table->entries[i]; - if (!is_terminal(entry->key)) { + if (!is_empty(entry)) { grpc_slice_unref_internal(exec_ctx, entry->key); entry->vtable->destroy_value(exec_ctx, entry->value); } diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c index cd92b484a33..1328a7e891f 100644 --- a/test/core/end2end/tests/request_with_flags.c +++ b/test/core/end2end/tests/request_with_flags.c @@ -167,9 +167,9 @@ static void test_invoke_request_with_flags( if (expectation == GRPC_CALL_OK) { CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); + grpc_slice_unref(details); } - grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c index 15d7734311d..9c5bde2d12e 100644 --- a/test/core/end2end/tests/resource_quota_server.c +++ b/test/core/end2end/tests/resource_quota_server.c @@ -149,7 +149,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_call_details *call_details = malloc(sizeof(grpc_call_details) * NUM_CALLS); grpc_status_code *status = malloc(sizeof(grpc_status_code) * NUM_CALLS); - grpc_slice *details = malloc(sizeof(char *) * NUM_CALLS); + grpc_slice *details = malloc(sizeof(grpc_slice) * NUM_CALLS); grpc_byte_buffer **request_payload_recv = malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS); int *was_cancelled = malloc(sizeof(int) * NUM_CALLS); From cf1c821ae6565c7ab1c1cf8b34660c4f69949171 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 18 Nov 2016 17:40:32 -0800 Subject: [PATCH 038/261] Start getting interning into hpack parser/encoder --- .../chttp2/transport/hpack_encoder.c | 37 ++++++++++++--- .../transport/chttp2/transport/hpack_parser.c | 45 ++++++++++++------- 2 files changed, 58 insertions(+), 24 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 8e2264a6029..7f7dfa5b554 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -187,9 +187,23 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { c->table_elems--; } +static bool is_interned(grpc_mdelem elem) { + switch (GRPC_MDELEM_STORAGE(elem)) { + case GRPC_MDELEM_STORAGE_ALLOCATED: + case GRPC_MDELEM_STORAGE_EXTERNAL: + return false; + case GRPC_MDELEM_STORAGE_INTERNED: + case GRPC_MDELEM_STORAGE_STATIC: + return true; + } + GPR_UNREACHABLE_CODE(return false); +} + /* add an element to the decoder table */ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, grpc_mdelem elem) { + GPR_ASSERT(is_interned(elem)); + uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); @@ -384,13 +398,6 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) { /* encode an mdelem */ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, grpc_mdelem elem, framer_state *st) { - uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); - uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); - uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); - size_t decoder_space_usage; - uint32_t indices_key; - int should_add_elem; - GPR_ASSERT(GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)) > 0); if (GRPC_SLICE_START_PTR(GRPC_MDKEY(elem))[0] != ':') { /* regular header */ st->seen_regular_header = 1; @@ -400,6 +407,22 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, "Reserved header (colon-prefixed) happening after regular ones."); } + if (!is_interned(elem)) { + emit_lithdr_noidx_v(c, elem, st); + return; + } + + uint32_t key_hash; + uint32_t value_hash; + uint32_t elem_hash; + size_t decoder_space_usage; + uint32_t indices_key; + int should_add_elem; + + key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); + value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); + elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); + inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum, c->filter_elems); /* is this elem currently in the decoders table? */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 91bedcf7f0a..a1ff528d720 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -671,6 +671,8 @@ static const uint8_t inverse_base64[256] = { static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, grpc_mdelem md, int add_to_table) { if (add_to_table) { + GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || + GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); grpc_error *err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; } @@ -683,8 +685,14 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, } static grpc_slice take_string(grpc_chttp2_hpack_parser *p, - grpc_chttp2_hpack_parser_string *str) { - grpc_slice s = grpc_slice_from_copied_buffer(str->str, str->length); + grpc_chttp2_hpack_parser_string *str, + bool intern) { + grpc_slice s; + if (intern) { + s = grpc_slice_intern(grpc_slice_from_static_buffer(str->str, str->length)); + } else { + s = grpc_slice_from_copied_buffer(str->str, str->length); + } str->length = 0; return s; } @@ -819,7 +827,7 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value)), + take_string(p, &p->value, true)), 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -830,10 +838,11 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 1); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, true), + take_string(p, &p->value, true)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -888,7 +897,7 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value)), + take_string(p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -899,10 +908,11 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 0); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, false), + take_string(p, &p->value, false)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -957,7 +967,7 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value)), + take_string(p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -968,10 +978,11 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key), - take_string(p, &p->value)), - 0); + grpc_error *err = + on_hdr(exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, false), + take_string(p, &p->value, false)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } From cca758933384feb49fb981ff224bddc5eeff6f22 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 21 Nov 2016 08:45:38 -0800 Subject: [PATCH 039/261] Start moving C++ to slice interfaces --- include/grpc++/impl/codegen/call.h | 28 ++++----- include/grpc++/impl/codegen/core_codegen.h | 5 +- .../impl/codegen/core_codegen_interface.h | 4 ++ include/grpc++/impl/codegen/slice.h | 59 +++++++++++++++++++ src/cpp/client/channel_cc.cc | 18 ++++-- src/cpp/client/secure_credentials.cc | 5 +- src/cpp/common/core_codegen.cc | 10 ++++ src/cpp/server/secure_server_credentials.cc | 19 +++--- 8 files changed, 114 insertions(+), 34 deletions(-) create mode 100644 include/grpc++/impl/codegen/slice.h diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 6ab00612f6e..1d511792570 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -68,8 +69,8 @@ inline void FillMetadataMap( for (size_t i = 0; i < arr->count; i++) { // TODO(yangg) handle duplicates? metadata->insert(std::pair( - arr->metadata[i].key, grpc::string_ref(arr->metadata[i].value, - arr->metadata[i].value_length))); + StringRefFromSlice(arr->metadata[i].key), + StringRefFromSlice(arr->metadata[i].value))); } g_core_codegen_interface->grpc_metadata_array_destroy(arr); g_core_codegen_interface->grpc_metadata_array_init(arr); @@ -87,9 +88,8 @@ inline grpc_metadata* FillMetadataArray( metadata.size() * sizeof(grpc_metadata))); size_t i = 0; for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { - metadata_array[i].key = iter->first.c_str(); - metadata_array[i].value = iter->second.c_str(); - metadata_array[i].value_length = iter->second.size(); + metadata_array[i].key = SliceReferencingString(iter->first); + metadata_array[i].value = SliceReferencingString(iter->second); } return metadata_array; } @@ -451,8 +451,9 @@ class CallOpServerSendStatus { trailing_metadata_count_; op->data.send_status_from_server.trailing_metadata = trailing_metadata_; op->data.send_status_from_server.status = send_status_code_; + grpc_slice status_details = SliceReferencingString(send_status_details_); op->data.send_status_from_server.status_details = - send_status_details_.empty() ? nullptr : send_status_details_.c_str(); + send_status_details_.empty() ? nullptr : &status_details; op->flags = 0; op->reserved = NULL; } @@ -515,16 +516,12 @@ class CallOpClientRecvStatus { if (recv_status_ == nullptr) return; memset(&recv_trailing_metadata_arr_, 0, sizeof(recv_trailing_metadata_arr_)); - status_details_ = nullptr; - status_details_capacity_ = 0; grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; op->data.recv_status_on_client.trailing_metadata = &recv_trailing_metadata_arr_; op->data.recv_status_on_client.status = &status_code_; op->data.recv_status_on_client.status_details = &status_details_; - op->data.recv_status_on_client.status_details_capacity = - &status_details_capacity_; op->flags = 0; op->reserved = NULL; } @@ -532,10 +529,10 @@ class CallOpClientRecvStatus { void FinishOp(bool* status, int max_receive_message_size) { if (recv_status_ == nullptr) return; FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_); - *recv_status_ = Status( - static_cast(status_code_), - status_details_ ? grpc::string(status_details_) : grpc::string()); - g_core_codegen_interface->gpr_free(status_details_); + *recv_status_ = Status(static_cast(status_code_), + grpc::string(GRPC_SLICE_START_PTR(status_details_), + GRPC_SLICE_END_PTR(status_details_))); + g_core_codegen_interface->grpc_slice_unref(status_details_); recv_status_ = nullptr; } @@ -544,8 +541,7 @@ class CallOpClientRecvStatus { Status* recv_status_; grpc_metadata_array recv_trailing_metadata_arr_; grpc_status_code status_code_; - char* status_details_; - size_t status_details_capacity_; + grpc_slice status_details_; }; /// An abstract collection of CallOpSet's, to be used whenever diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index 6b5e637e4e2..b5ab26154e2 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -81,7 +81,10 @@ class CoreCodegen : public CoreCodegenInterface { grpc_slice grpc_slice_split_tail(grpc_slice* s, size_t split) override; void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) override; void grpc_slice_buffer_pop(grpc_slice_buffer* sb) override; - + grpc_slice grpc_slice_from_static_buffer(const void* buffer, + size_t length) override; + grpc_slice grpc_slice_from_copied_buffer(const void* buffer, + size_t length) override; void grpc_metadata_array_init(grpc_metadata_array* array) override; void grpc_metadata_array_destroy(grpc_metadata_array* array) override; diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h index 4783a43454f..9c1af972b3c 100644 --- a/include/grpc++/impl/codegen/core_codegen_interface.h +++ b/include/grpc++/impl/codegen/core_codegen_interface.h @@ -99,6 +99,10 @@ class CoreCodegenInterface { virtual void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) = 0; virtual void grpc_slice_buffer_pop(grpc_slice_buffer* sb) = 0; + virtual grpc_slice grpc_slice_from_static_buffer(const void* buffer, + size_t length) = 0; + virtual grpc_slice grpc_slice_from_copied_buffer(const void* buffer, + size_t length) = 0; virtual void grpc_metadata_array_init(grpc_metadata_array* array) = 0; virtual void grpc_metadata_array_destroy(grpc_metadata_array* array) = 0; diff --git a/include/grpc++/impl/codegen/slice.h b/include/grpc++/impl/codegen/slice.h new file mode 100644 index 00000000000..72806989788 --- /dev/null +++ b/include/grpc++/impl/codegen/slice.h @@ -0,0 +1,59 @@ +/* + * + * 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. + * + */ + +#ifndef GRPCXX_IMPL_CODEGEN_SLICE_H +#define GRPCXX_IMPL_CODEGEN_SLICE_H + +#include +#include + +namespace grpc { + +inline grpc::string_ref StringRefFromSlice(grpc_slice slice) { + return grpc::string_ref(reinterpret_cast(GRPC_SLICE_START_PTR(slice)), + GRPC_SLICE_LENGTH(slice)); +} + +inline grpc_slice SliceReferencingString(const grpc::string& str) { + return g_core_codegen_interface->grpc_slice_from_static_buffer(str.data(), + str.length()); +} + +inline grpc_slice SliceFromCopiedString(const grpc::string& str) { + return g_core_codegen_interface->grpc_slice_from_copied_buffer(str.data(), + str.length()); +} + +} // namespace grpc + +#endif diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index 357d8317adf..c985183ae76 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -107,10 +107,20 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, } else if (!host_.empty()) { host_str = host_.c_str(); } - c_call = grpc_channel_create_call(c_channel_, context->propagate_from_call_, - context->propagation_options_.c_bitmask(), - cq->cq(), method.name(), host_str, - context->raw_deadline(), nullptr); + grpc_slice method_slice = SliceFromCopiedString(method.name()); + grpc_slice host_slice; + if (host_str != nullptr) { + host_slice = SliceFromCopiedString(host_str); + } + c_call = grpc_channel_create_call( + c_channel_, context->propagate_from_call_, + context->propagation_options_.c_bitmask(), cq->cq(), method_slice, + host_str == nullptr ? nullptr : &host_slice, context->raw_deadline(), + nullptr); + grpc_slice_unref(method_slice); + if (host_str != nullptr) { + grpc_slice_unref(host_slice); + } } grpc_census_call_set_context(c_call, context->census_context()); context->set_call(c_call, shared_from_this()); diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 269c523bba1..21445c91fd8 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -206,9 +206,8 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( std::vector md; for (auto it = metadata.begin(); it != metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = it->first.c_str(); - md_entry.value = it->second.data(); - md_entry.value_length = it->second.size(); + md_entry.key = SliceReferencingString(it->first); + md_entry.value = SliceReferencingString(it->second); md_entry.flags = 0; md.push_back(md_entry); } diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index a07ad543769..36c8938c95b 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -123,6 +123,16 @@ grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) { return ::grpc_slice_split_tail(s, split); } +grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, + size_t length) { + return ::grpc_slice_from_static_buffer(buffer, length); +} + +grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer, + size_t length) { + return ::grpc_slice_from_copied_buffer(buffer, length); +} + void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) { ::grpc_slice_buffer_add(sb, slice); diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 33bdc2a1f4f..3c90986cd05 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -35,11 +35,12 @@ #include #include +#include +#include + #include "src/cpp/common/secure_auth_context.h" #include "src/cpp/server/secure_server_credentials.h" -#include - namespace grpc { void AuthMetadataProcessorAyncWrapper::Destroy(void* wrapper) { @@ -71,8 +72,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( grpc_process_auth_metadata_done_cb cb, void* user_data) { AuthMetadataProcessor::InputMetadata metadata; for (size_t i = 0; i < num_md; i++) { - metadata.insert(std::make_pair( - md[i].key, grpc::string_ref(md[i].value, md[i].value_length))); + metadata.insert(std::make_pair(StringRefFromSlice(md[i].key), + StringRefFromSlice(md[i].value))); } SecureAuthContext context(ctx, false); AuthMetadataProcessor::OutputMetadata consumed_metadata; @@ -85,9 +86,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = consumed_metadata.begin(); it != consumed_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = it->first.c_str(); - md_entry.value = it->second.data(); - md_entry.value_length = it->second.size(); + md_entry.key = SliceReferencingString(it->first); + md_entry.value = SliceReferencingString(it->second); md_entry.flags = 0; consumed_md.push_back(md_entry); } @@ -95,9 +95,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = response_metadata.begin(); it != response_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = it->first.c_str(); - md_entry.value = it->second.data(); - md_entry.value_length = it->second.size(); + md_entry.key = SliceReferencingString(it->first); + md_entry.value = SliceReferencingString(it->second); md_entry.flags = 0; response_md.push_back(md_entry); } From 73ee7dc5590447bc726f7a1c3e51c2a217c8d5b6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 21 Nov 2016 09:12:18 -0800 Subject: [PATCH 040/261] C++ compiles --- include/grpc++/impl/codegen/slice.h | 5 +++++ include/grpc/impl/codegen/compression_types.h | 5 +++++ src/cpp/common/channel_filter.cc | 5 ++++- src/cpp/common/channel_filter.h | 2 +- src/cpp/common/core_codegen.cc | 3 ++- src/cpp/server/server_cc.cc | 15 +++++++-------- src/cpp/server/server_context.cc | 4 ++-- test/cpp/common/channel_arguments_test.cc | 2 +- 8 files changed, 27 insertions(+), 14 deletions(-) diff --git a/include/grpc++/impl/codegen/slice.h b/include/grpc++/impl/codegen/slice.h index 72806989788..e79754f943e 100644 --- a/include/grpc++/impl/codegen/slice.h +++ b/include/grpc++/impl/codegen/slice.h @@ -44,6 +44,11 @@ inline grpc::string_ref StringRefFromSlice(grpc_slice slice) { GRPC_SLICE_LENGTH(slice)); } +inline grpc::string StringFromCopiedSlice(grpc_slice slice) { + return grpc::string(reinterpret_cast(GRPC_SLICE_START_PTR(slice)), + GRPC_SLICE_LENGTH(slice)); +} + inline grpc_slice SliceReferencingString(const grpc::string& str) { return g_core_codegen_interface->grpc_slice_from_static_buffer(str.data(), str.length()); diff --git a/include/grpc/impl/codegen/compression_types.h b/include/grpc/impl/codegen/compression_types.h index 8810943137e..170d99f431b 100644 --- a/include/grpc/impl/codegen/compression_types.h +++ b/include/grpc/impl/codegen/compression_types.h @@ -41,6 +41,11 @@ extern "C" { #endif +/** To be used as initial metadata key for the request of a concrete compression + * algorithm */ +#define GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY \ + "grpc-internal-encoding-request" + /** To be used in channel arguments. * * \addtogroup grpc_arg_keys diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index c0dc9dd63e5..9aeb942f596 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -36,6 +36,8 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/cpp/common/channel_filter.h" +#include + namespace grpc { // MetadataBatch @@ -45,7 +47,8 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, const string &value) { grpc_linked_mdelem *storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); - storage->md = grpc_mdelem_from_strings(exec_ctx, key.c_str(), value.c_str()); + storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), + SliceFromCopiedString(value)); grpc_metadata_batch_link_head(batch_, storage); return storage; } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index cac0a19e5e7..bc8e625fb37 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -76,7 +76,7 @@ class MetadataBatch { class const_iterator : public std::iterator { public: - const grpc_mdelem &operator*() const { return *elem_->md; } + const grpc_mdelem &operator*() const { return elem_->md; } const grpc_mdelem operator->() const { return elem_->md; } const_iterator &operator++() { diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 36c8938c95b..a09e08ef4cf 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -130,7 +130,8 @@ grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer, size_t length) { - return ::grpc_slice_from_copied_buffer(buffer, length); + return ::grpc_slice_from_copied_buffer(static_cast(buffer), + length); } void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index b7cfd6dbf11..364257a71cc 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -584,10 +584,8 @@ bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag, for (size_t i = 0; i < initial_metadata_array_.count; i++) { context_->client_metadata_.insert( std::pair( - initial_metadata_array_.metadata[i].key, - grpc::string_ref( - initial_metadata_array_.metadata[i].value, - initial_metadata_array_.metadata[i].value_length))); + StringRefFromSlice(initial_metadata_array_.metadata[i].key), + StringRefFromSlice(initial_metadata_array_.metadata[i].value))); } } grpc_metadata_array_destroy(&initial_metadata_array_); @@ -639,11 +637,12 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag, // TODO(yangg) remove the copy here. if (*status) { static_cast(context_)->method_ = - call_details_.method; - static_cast(context_)->host_ = call_details_.host; + StringFromCopiedSlice(call_details_.method); + static_cast(context_)->host_ = + StringFromCopiedSlice(call_details_.host); } - gpr_free(call_details_.method); - gpr_free(call_details_.host); + grpc_slice_unref(call_details_.method); + grpc_slice_unref(call_details_.host); return BaseAsyncRequest::FinalizeResult(tag, status); } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index a66ec4ac841..9fc8d752eb3 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -145,8 +145,8 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { client_metadata_.insert(std::pair( - metadata[i].key, - grpc::string_ref(metadata[i].value, metadata[i].value_length))); + StringRefFromSlice(metadata[i].key), + StringRefFromSlice(metadata[i].value))); } } diff --git a/test/cpp/common/channel_arguments_test.cc b/test/cpp/common/channel_arguments_test.cc index 60d3215265f..0cbe6f9636b 100644 --- a/test/cpp/common/channel_arguments_test.cc +++ b/test/cpp/common/channel_arguments_test.cc @@ -228,7 +228,7 @@ TEST_F(ChannelArgumentsTest, SetSocketMutator) { EXPECT_FALSE(HasArg(arg0)); // arg0 is destroyed by grpc_socket_mutator_to_arg(mutator1) - arg1.value.pointer.vtable->destroy(arg1.value.pointer.p); + arg1.value.pointer.vtable->destroy(nullptr, arg1.value.pointer.p); } TEST_F(ChannelArgumentsTest, SetUserAgentPrefix) { From 3b05e1da916aa298fe58a58ec79a7f7c043534c7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 21 Nov 2016 13:46:31 -0800 Subject: [PATCH 041/261] Move from cmp --> eq, and provide a good implementation for interning --- include/grpc/impl/codegen/slice.h | 3 +- include/grpc/slice.h | 5 +- src/core/ext/census/grpc_filter.c | 2 +- .../load_reporting/load_reporting_filter.c | 6 +- .../chttp2/transport/chttp2_transport.c | 2 +- .../chttp2/transport/hpack_encoder.c | 45 +++--- .../transport/chttp2/transport/hpack_parser.c | 135 ++++++++++++------ .../transport/chttp2/transport/hpack_parser.h | 16 ++- .../transport/chttp2/transport/hpack_table.c | 8 +- .../ext/transport/chttp2/transport/parsing.c | 6 +- src/core/lib/channel/compress_filter.c | 4 +- src/core/lib/channel/http_client_filter.c | 19 ++- src/core/lib/channel/http_server_filter.c | 20 +-- src/core/lib/compression/compression.c | 12 +- src/core/lib/iomgr/resource_quota.c | 3 +- .../security/transport/client_auth_filter.c | 4 +- .../security/transport/server_auth_filter.c | 4 +- src/core/lib/slice/slice.c | 31 ++-- src/core/lib/slice/slice_intern.c | 48 +++++-- src/core/lib/slice/slice_internal.h | 3 +- src/core/lib/surface/call.c | 13 +- src/core/lib/surface/channel.c | 6 +- src/core/lib/surface/server.c | 10 +- src/core/lib/transport/metadata.c | 8 +- src/core/lib/transport/metadata.h | 11 +- src/core/lib/transport/static_metadata.c | 2 +- test/core/bad_client/tests/large_metadata.c | 2 +- test/core/compression/algorithm_test.c | 20 ++- test/core/compression/message_compress_test.c | 2 +- test/core/end2end/cq_verifier.c | 4 +- test/core/security/credentials_test.c | 4 +- test/core/security/secure_endpoint_test.c | 2 +- test/core/slice/percent_encode_fuzzer.c | 4 +- test/core/slice/percent_encoding_test.c | 8 +- test/core/transport/chttp2/bin_decoder_test.c | 2 +- test/core/transport/chttp2/bin_encoder_test.c | 4 +- .../transport/chttp2/hpack_encoder_test.c | 2 +- test/core/transport/chttp2/varint_test.c | 2 +- test/core/transport/metadata_test.c | 4 +- test/cpp/microbenchmarks/bm_fullstack.cc | 2 +- tools/codegen/core/gen_static_metadata.py | 2 +- 41 files changed, 292 insertions(+), 198 deletions(-) diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index ecce1ca0893..fbd18e6c65b 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -57,7 +57,8 @@ typedef struct grpc_slice grpc_slice; typedef struct grpc_slice_refcount_vtable { void (*ref)(void *); void (*unref)(grpc_exec_ctx *exec_ctx, void *); - uint32_t (*hash)(void *, grpc_slice slice); + int (*eq)(grpc_slice a, grpc_slice b); + uint32_t (*hash)(grpc_slice slice); } grpc_slice_refcount_vtable; /* Reference count container for grpc_slice. Contains function pointers to diff --git a/include/grpc/slice.h b/include/grpc/slice.h index dc0a7a344e6..73d1fa43ec0 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -124,7 +124,10 @@ GPRAPI grpc_slice grpc_slice_split_head(grpc_slice *s, size_t split); GPRAPI grpc_slice grpc_empty_slice(void); -GPRAPI uint32_t grpc_slice_default_hash_impl(void *, grpc_slice s); +GPRAPI uint32_t grpc_slice_default_hash_impl(grpc_slice s); +GPRAPI int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b); + +GPRAPI int grpc_slice_eq(grpc_slice a, grpc_slice b); /* Returns <0 if a < b, ==0 if a == b, >0 if a > b The order is arbitrary, and is not guaranteed to be stable across different diff --git a/src/core/ext/census/grpc_filter.c b/src/core/ext/census/grpc_filter.c index c1a883b6f8d..6e319942808 100644 --- a/src/core/ext/census/grpc_filter.c +++ b/src/core/ext/census/grpc_filter.c @@ -67,7 +67,7 @@ static void extract_and_annotate_method_tag(grpc_metadata_batch *md, channel_data *chand) { grpc_linked_mdelem *m; for (m = md->list.head; m != NULL; m = m->next) { - if (grpc_slice_cmp(GRPC_MDKEY(m->md), GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(m->md), GRPC_MDSTR_PATH)) { /* Add method tag here */ } } diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 5d3b4c4207d..75f5c73ae34 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -78,10 +78,10 @@ static grpc_mdelem recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element *elem = a->elem; call_data *calld = elem->call_data; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { calld->service_method = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_service_method = true; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_LB_TOKEN) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_TOKEN)) { calld->initial_md_string = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_initial_md_string = true; return GRPC_MDNULL; @@ -201,7 +201,7 @@ static grpc_mdelem lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_LB_COST_BIN) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_COST_BIN)) { calld->trailing_md_string = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_trailing_md_string = true; return GRPC_MDNULL; diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 91861829e3d..586052fdd31 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -876,7 +876,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, static bool contains_non_ok_status(grpc_metadata_batch *batch) { grpc_linked_mdelem *l; for (l = batch->list.head; l; l = l->next) { - if (grpc_slice_cmp(GRPC_MDKEY(l->md), GRPC_MDSTR_GRPC_STATUS) == 0 && + if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDSTR_GRPC_STATUS) && !grpc_mdelem_eq(l->md, GRPC_MDELEM_GRPC_STATUS_0)) { return true; } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 7f7dfa5b554..eb19bd7c2d0 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -49,6 +49,7 @@ #include "src/core/ext/transport/chttp2/transport/hpack_table.h" #include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/timeout_encoding.h" @@ -187,22 +188,10 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { c->table_elems--; } -static bool is_interned(grpc_mdelem elem) { - switch (GRPC_MDELEM_STORAGE(elem)) { - case GRPC_MDELEM_STORAGE_ALLOCATED: - case GRPC_MDELEM_STORAGE_EXTERNAL: - return false; - case GRPC_MDELEM_STORAGE_INTERNED: - case GRPC_MDELEM_STORAGE_STATIC: - return true; - } - GPR_UNREACHABLE_CODE(return false); -} - /* add an element to the decoder table */ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, grpc_mdelem elem) { - GPR_ASSERT(is_interned(elem)); + GPR_ASSERT(GRPC_MDELEM_IS_INTERNED(elem)); uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); @@ -261,11 +250,11 @@ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* do exactly the same for the key (so we can find by that again too) */ - if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_2(key_hash)], - GRPC_MDKEY(elem)) == 0) { + if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)], + GRPC_MDKEY(elem))) { c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_3(key_hash)], - GRPC_MDKEY(elem)) == 0) { + } else if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)], + GRPC_MDKEY(elem))) { c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)].refcount == &terminal_slice_refcount) { @@ -407,7 +396,19 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, "Reserved header (colon-prefixed) happening after regular ones."); } - if (!is_interned(elem)) { + if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(elem)) { + char *k = grpc_dump_slice(GRPC_MDKEY(elem), GPR_DUMP_ASCII); + char *v = grpc_dump_slice(GRPC_MDVALUE(elem), GPR_DUMP_ASCII); + gpr_log( + GPR_DEBUG, + "Encode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", + k, v, GRPC_MDELEM_IS_INTERNED(elem), GRPC_MDELEM_STORAGE(elem), + grpc_slice_is_interned(GRPC_MDKEY(elem)), + grpc_slice_is_interned(GRPC_MDVALUE(elem))); + gpr_free(k); + gpr_free(v); + } + if (!GRPC_MDELEM_IS_INTERNED(elem)) { emit_lithdr_noidx_v(c, elem, st); return; } @@ -452,8 +453,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* no hits for the elem... maybe there's a key? */ indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)]; - if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_2(key_hash)], - GRPC_MDKEY(elem)) == 0 && + if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)], + GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { @@ -468,8 +469,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, } indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)]; - if (grpc_slice_cmp(c->entries_keys[HASH_FRAGMENT_3(key_hash)], - GRPC_MDKEY(elem)) == 0 && + if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)], + GRPC_MDKEY(elem)) && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index a1ff528d720..c53a1faee32 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -55,6 +55,9 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" +/* TODO(ctiller): remove before submission */ +#include "src/core/lib/slice/slice_string_helpers.h" + extern int grpc_http_trace; typedef enum { @@ -670,6 +673,18 @@ static const uint8_t inverse_base64[256] = { /* emission helpers */ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, grpc_mdelem md, int add_to_table) { + if (!GRPC_MDELEM_IS_INTERNED(md)) { + char *k = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); + char *v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + gpr_log( + GPR_DEBUG, + "Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", + k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md), + grpc_slice_is_interned(GRPC_MDKEY(md)), + grpc_slice_is_interned(GRPC_MDVALUE(md))); + gpr_free(k); + gpr_free(v); + } if (add_to_table) { GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); @@ -684,16 +699,28 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, return GRPC_ERROR_NONE; } -static grpc_slice take_string(grpc_chttp2_hpack_parser *p, +static grpc_slice take_string(grpc_exec_ctx *exec_ctx, + grpc_chttp2_hpack_parser *p, grpc_chttp2_hpack_parser_string *str, bool intern) { grpc_slice s; - if (intern) { - s = grpc_slice_intern(grpc_slice_from_static_buffer(str->str, str->length)); + if (!str->copied) { + if (intern) { + s = grpc_slice_intern(str->data.referenced); + grpc_slice_unref_internal(exec_ctx, str->data.referenced); + } else { + s = str->data.referenced; + } + str->copied = true; + str->data.referenced = grpc_empty_slice(); + } else if (intern) { + s = grpc_slice_intern(grpc_slice_from_static_buffer( + str->data.copied.str, str->data.copied.length)); } else { - s = grpc_slice_from_copied_buffer(str->str, str->length); + s = grpc_slice_from_copied_buffer(str->data.copied.str, + str->data.copied.length); } - str->length = 0; + str->data.copied.length = 0; return s; } @@ -827,7 +854,7 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, true)), + take_string(exec_ctx, p, &p->value, true)), 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -838,11 +865,11 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = - on_hdr(exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, true), - take_string(p, &p->value, true)), - 1); + grpc_error *err = on_hdr( + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, true)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -897,7 +924,7 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, false)), + take_string(exec_ctx, p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -908,11 +935,11 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = - on_hdr(exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, false), - take_string(p, &p->value, false)), - 0); + grpc_error *err = on_hdr( + exec_ctx, p, grpc_mdelem_from_slices( + exec_ctx, take_string(exec_ctx, p, &p->key, false), + take_string(exec_ctx, p, &p->value, false)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -967,7 +994,7 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, grpc_error *err = on_hdr( exec_ctx, p, grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(p, &p->value, false)), + take_string(exec_ctx, p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -978,11 +1005,11 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = - on_hdr(exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(p, &p->key, false), - take_string(p, &p->value, false)), - 0); + grpc_error *err = on_hdr( + exec_ctx, p, grpc_mdelem_from_slices( + exec_ctx, take_string(exec_ctx, p, &p->key, false), + take_string(exec_ctx, p, &p->value, false)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -1276,14 +1303,15 @@ static grpc_error *parse_string_prefix(grpc_exec_ctx *exec_ctx, static void append_bytes(grpc_chttp2_hpack_parser_string *str, const uint8_t *data, size_t length) { if (length == 0) return; - if (length + str->length > str->capacity) { - GPR_ASSERT(str->length + length <= UINT32_MAX); - str->capacity = (uint32_t)(str->length + length); - str->str = gpr_realloc(str->str, str->capacity); + if (length + str->data.copied.length > str->data.copied.capacity) { + GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX); + str->data.copied.capacity = (uint32_t)(str->data.copied.length + length); + str->data.copied.str = + gpr_realloc(str->data.copied.str, str->data.copied.capacity); } - memcpy(str->str + str->length, data, length); - GPR_ASSERT(length <= UINT32_MAX - str->length); - str->length += (uint32_t)length; + memcpy(str->data.copied.str + str->data.copied.length, data, length); + GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length); + str->data.copied.length += (uint32_t)length; } static grpc_error *append_string(grpc_exec_ctx *exec_ctx, @@ -1366,11 +1394,9 @@ static grpc_error *append_string(grpc_exec_ctx *exec_ctx, exec_ctx, p, cur, end, GRPC_ERROR_CREATE("Should never reach here"))); } -/* append a null terminator to a string */ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - uint8_t terminator = 0; uint8_t decoded[2]; uint32_t bits; grpc_chttp2_hpack_parser_string *str = p->parsing.str; @@ -1411,8 +1437,6 @@ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, append_bytes(str, decoded, 2); break; } - append_bytes(str, &terminator, 1); - p->parsing.str->length--; /* don't actually count the null terminator */ return GRPC_ERROR_NONE; } @@ -1487,8 +1511,18 @@ static grpc_error *begin_parse_string(grpc_exec_ctx *exec_ctx, const uint8_t *cur, const uint8_t *end, uint8_t binary, grpc_chttp2_hpack_parser_string *str) { + if (!p->huff && binary == NOT_BINARY && (end - cur) >= p->strlen && + p->current_slice_refcount != NULL) { + str->copied = false; + str->data.referenced.refcount = p->current_slice_refcount; + str->data.referenced.data.refcounted.bytes = (uint8_t *)cur; + str->data.referenced.data.refcounted.length = p->strlen; + grpc_slice_ref_internal(str->data.referenced); + return parse_next(exec_ctx, p, cur + p->strlen, end); + } p->strgot = 0; - str->length = 0; + str->copied = true; + str->data.copied.length = 0; p->parsing.str = str; p->huff_state = 0; p->binary = binary; @@ -1505,8 +1539,8 @@ static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, /* check if a key represents a binary header or not */ static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { - return grpc_is_binary_header( - grpc_slice_from_static_buffer(p->key.str, p->key.length)); + return grpc_is_binary_header(grpc_slice_from_static_buffer( + p->key.data.copied.str, p->key.data.copied.length)); } static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, @@ -1553,12 +1587,12 @@ void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, p->on_header = NULL; p->on_header_user_data = NULL; p->state = parse_begin; - p->key.str = NULL; - p->key.capacity = 0; - p->key.length = 0; - p->value.str = NULL; - p->value.capacity = 0; - p->value.length = 0; + p->key.data.copied.str = NULL; + p->key.data.copied.capacity = 0; + p->key.data.copied.length = 0; + p->value.data.copied.str = NULL; + p->value.data.copied.capacity = 0; + p->value.data.copied.length = 0; p->dynamic_table_update_allowed = 2; p->last_error = GRPC_ERROR_NONE; grpc_chttp2_hptbl_init(exec_ctx, &p->table); @@ -1573,19 +1607,25 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p) { grpc_chttp2_hptbl_destroy(exec_ctx, &p->table); GRPC_ERROR_UNREF(p->last_error); - gpr_free(p->key.str); - gpr_free(p->value.str); + grpc_slice_unref_internal(exec_ctx, p->key.data.referenced); + grpc_slice_unref_internal(exec_ctx, p->value.data.referenced); + gpr_free(p->key.data.copied.str); + gpr_free(p->value.data.copied.str); } grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, + grpc_slice_refcount *refcount, const uint8_t *beg, const uint8_t *end) { /* TODO(ctiller): limit the distance of end from beg, and perform multiple steps in the event of a large chunk of data to limit stack space usage when no tail call optimization is available */ - return p->state(exec_ctx, p, beg, end); + p->current_slice_refcount = refcount; + grpc_error *error = p->state(exec_ctx, p, beg, end); + p->current_slice_refcount = NULL; + return error; } typedef void (*maybe_complete_func_type)(grpc_exec_ctx *exec_ctx, @@ -1620,7 +1660,8 @@ grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } grpc_error *error = grpc_chttp2_hpack_parser_parse( - exec_ctx, parser, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_END_PTR(slice)); + exec_ctx, parser, slice.refcount, GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_END_PTR(slice)); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 442708e3d79..3ab0a2a34b8 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -49,9 +49,15 @@ typedef grpc_error *(*grpc_chttp2_hpack_parser_state)( const uint8_t *end); typedef struct { - char *str; - uint32_t length; - uint32_t capacity; + bool copied; + struct { + grpc_slice referenced; + struct { + char *str; + uint32_t length; + uint32_t capacity; + } copied; + } data; } grpc_chttp2_hpack_parser_string; struct grpc_chttp2_hpack_parser { @@ -67,6 +73,8 @@ struct grpc_chttp2_hpack_parser { const grpc_chttp2_hpack_parser_state *next_state; /* what to do after skipping prioritization data */ grpc_chttp2_hpack_parser_state after_prioritization; + /* the refcount of the slice that we're currently parsing */ + grpc_slice_refcount *current_slice_refcount; /* the value we're currently parsing */ union { uint32_t *value; @@ -106,9 +114,9 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); -/* returns 1 on success, 0 on error */ grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, + grpc_slice_refcount *refcount, const uint8_t *beg, const uint8_t *end); diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.c b/src/core/ext/transport/chttp2/transport/hpack_table.c index 2cb816fe539..62dd1b8cab4 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.c +++ b/src/core/ext/transport/chttp2/transport/hpack_table.c @@ -362,9 +362,9 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { grpc_mdelem ent = tbl->static_ents[i]; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDKEY(ent)) != 0) continue; + if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = i + 1u; - r.has_value = grpc_slice_cmp(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)) == 0; + r.has_value = grpc_slice_eq(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)); if (r.has_value) return r; } @@ -373,9 +373,9 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( uint32_t idx = (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDKEY(ent)) != 0) continue; + if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; r.index = idx; - r.has_value = grpc_slice_cmp(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)) == 0; + r.has_value = grpc_slice_eq(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)); if (r.has_value) return r; } diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 12f850791de..b002710be33 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -462,13 +462,13 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, gpr_free(value); } - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) == 0 && + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) && !grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; } - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT)) { gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout); gpr_timespec timeout; if (cached_timeout == NULL) { @@ -534,7 +534,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, gpr_free(value); } - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) == 0 && + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) && !grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index e04f3dc7db7..392d4d7231d 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -90,8 +90,8 @@ static grpc_mdelem compression_md_filter(grpc_exec_ctx *exec_ctx, call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; - if (grpc_slice_cmp(GRPC_MDKEY(md), - GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), + GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST)) { if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), &calld->compression_algorithm)) { char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index fea6c9b3456..e415877eb86 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -99,7 +99,7 @@ static grpc_mdelem client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element *elem = user_data; if (grpc_mdelem_eq(md, GRPC_MDELEM_STATUS_200)) { return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_STATUS) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_STATUS)) { char *message_string; char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_asprintf(&message_string, "Received http2 header with status: %s", val); @@ -109,7 +109,7 @@ static grpc_mdelem client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element_send_close_with_message(exec_ctx, elem, GRPC_STATUS_CANCELLED, &message); return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE)) { grpc_slice pct_decoded_msg = grpc_permissive_percent_decode_slice(GRPC_MDVALUE(md)); if (grpc_slice_is_equivalent(pct_decoded_msg, GRPC_MDVALUE(md))) { @@ -122,7 +122,7 @@ static grpc_mdelem client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, } else if (grpc_mdelem_eq(md, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) { if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) && (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == @@ -187,15 +187,12 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { static grpc_mdelem client_strip_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md) { /* eat the things we'd like to set ourselves */ - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) == 0) - return GRPC_MDNULL; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) - return GRPC_MDNULL; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_TE) == 0) return GRPC_MDNULL; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) - return GRPC_MDNULL; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_USER_AGENT) == 0) + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_METHOD)) return GRPC_MDNULL; + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) return GRPC_MDNULL; + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_TE)) return GRPC_MDNULL; + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) return GRPC_MDNULL; + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_USER_AGENT)) return GRPC_MDNULL; return md; } diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 0d11c71d060..bdd1e188379 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -87,7 +87,7 @@ typedef struct channel_data { uint8_t unused; } channel_data; static grpc_mdelem server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md) { - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE)) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( GRPC_MDVALUE(md), grpc_compatible_percent_encoding_unreserved_bytes); if (grpc_slice_is_equivalent(pct_encoded_msg, GRPC_MDVALUE(md))) { @@ -126,7 +126,7 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET)) { calld->seen_method = 1; *calld->recv_cacheable_request = true; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { calld->seen_scheme = 1; } else if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS)) { calld->seen_te_trailers = 1; @@ -134,7 +134,7 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, /* TODO(klempner): Track that we've seen all the headers we should require */ return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) { if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, EXPECTED_CONTENT_TYPE_LENGTH) && (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == @@ -154,9 +154,9 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, gpr_free(val); } return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_TE) == 0 || - grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) == 0 || - grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_TE) || + grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) || + grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { char *key = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); char *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", key, value); @@ -167,24 +167,24 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, gpr_free(value); grpc_call_element_send_cancel(exec_ctx, elem); return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { if (calld->seen_path) { gpr_log(GPR_ERROR, "Received :path twice"); return GRPC_MDNULL; } calld->seen_path = 1; return md; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { calld->seen_authority = 1; return md; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_HOST) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_HOST)) { /* translate host to :authority since :authority may be omitted */ grpc_mdelem authority = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(GRPC_MDVALUE(md))); calld->seen_authority = 1; return authority; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_PAYLOAD_BIN) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_PAYLOAD_BIN)) { /* Retrieve the payload from the value of the 'grpc-internal-payload-bin' header field */ calld->seen_payload_bin = 1; diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index f8777a6f6ca..80c1aaed5ba 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -47,13 +47,13 @@ int grpc_compression_algorithm_parse(grpc_slice name, * doesn't matter, given that we are comparing against string literals, but * because this way we needn't have "name" nil-terminated (useful for slice * data, for example) */ - if (grpc_slice_cmp(name, GRPC_MDSTR_IDENTITY) == 0) { + if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) { *algorithm = GRPC_COMPRESS_NONE; return 1; - } else if (grpc_slice_cmp(name, GRPC_MDSTR_GZIP) == 0) { + } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) { *algorithm = GRPC_COMPRESS_GZIP; return 1; - } else if (grpc_slice_cmp(name, GRPC_MDSTR_DEFLATE) == 0) { + } else if (grpc_slice_eq(name, GRPC_MDSTR_DEFLATE)) { *algorithm = GRPC_COMPRESS_DEFLATE; return 1; } else { @@ -83,10 +83,10 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, grpc_compression_algorithm grpc_compression_algorithm_from_slice( grpc_slice str) { - if (grpc_slice_cmp(str, GRPC_MDSTR_IDENTITY) == 0) return GRPC_COMPRESS_NONE; - if (grpc_slice_cmp(str, GRPC_MDSTR_DEFLATE) == 0) + if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE; + if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) return GRPC_COMPRESS_DEFLATE; - if (grpc_slice_cmp(str, GRPC_MDSTR_GZIP) == 0) return GRPC_COMPRESS_GZIP; + if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_COMPRESS_GZIP; return GRPC_COMPRESS_ALGORITHMS_COUNT; } diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c index 3b637730718..8622a3610c2 100644 --- a/src/core/lib/iomgr/resource_quota.c +++ b/src/core/lib/iomgr/resource_quota.c @@ -367,7 +367,8 @@ static void ru_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } static const grpc_slice_refcount_vtable ru_slice_vtable = { - ru_slice_ref, ru_slice_unref, grpc_slice_default_hash_impl}; + ru_slice_ref, ru_slice_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; static grpc_slice ru_slice_create(grpc_resource_user *resource_user, size_t size) { diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index d680c1ef133..13c0277109a 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -256,13 +256,13 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx, grpc_mdelem md = l->md; /* Pointer comparison is OK for md_elems created from the same context. */ - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { if (calld->have_host) { grpc_slice_unref_internal(exec_ctx, calld->host); } calld->host = grpc_slice_ref_internal(GRPC_MDVALUE(md)); calld->have_host = true; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { if (calld->have_method) { grpc_slice_unref_internal(exec_ctx, calld->method); } diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 1c4843fc144..1d14cfef530 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -90,8 +90,8 @@ static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, size_t i; for (i = 0; i < calld->num_consumed_md; i++) { const grpc_metadata *consumed_md = &calld->consumed_md[i]; - if (grpc_slice_cmp(GRPC_MDKEY(md), consumed_md->key) == 0 && - grpc_slice_cmp(GRPC_MDKEY(md), consumed_md->value) == 0) + if (grpc_slice_eq(GRPC_MDKEY(md), consumed_md->key) && + grpc_slice_eq(GRPC_MDKEY(md), consumed_md->value)) return GRPC_MDNULL; } return md; diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 64988bae649..2ae97b3035f 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -79,7 +79,8 @@ static void noop_ref(void *unused) {} static void noop_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable noop_refcount_vtable = { - noop_ref, noop_unref, grpc_slice_default_hash_impl}; + noop_ref, noop_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable}; grpc_slice grpc_slice_from_static_buffer(const void *s, size_t len) { @@ -117,7 +118,8 @@ static void new_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } static const grpc_slice_refcount_vtable new_slice_vtable = { - new_slice_ref, new_slice_unref, grpc_slice_default_hash_impl}; + new_slice_ref, new_slice_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, void (*destroy)(void *), @@ -164,7 +166,8 @@ static void new_with_len_unref(grpc_exec_ctx *exec_ctx, void *p) { } static const grpc_slice_refcount_vtable new_with_len_vtable = { - new_with_len_ref, new_with_len_unref, grpc_slice_default_hash_impl}; + new_with_len_ref, new_with_len_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; grpc_slice grpc_slice_new_with_len(void *p, size_t len, void (*destroy)(void *, size_t)) { @@ -211,7 +214,8 @@ static void malloc_unref(grpc_exec_ctx *exec_ctx, void *p) { } static const grpc_slice_refcount_vtable malloc_vtable = { - malloc_ref, malloc_unref, grpc_slice_default_hash_impl}; + malloc_ref, malloc_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; grpc_slice grpc_slice_malloc(size_t length) { grpc_slice slice; @@ -363,11 +367,20 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { return head; } -int grpc_slice_cmp(grpc_slice a, grpc_slice b) { - if (GRPC_SLICE_START_PTR(a) == GRPC_SLICE_START_PTR(b) && - GRPC_SLICE_LENGTH(a) == GRPC_SLICE_LENGTH(b)) { - return 0; +int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b) { + return GRPC_SLICE_LENGTH(a) == GRPC_SLICE_LENGTH(b) && + 0 == memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), + GRPC_SLICE_LENGTH(a)); +} + +int grpc_slice_eq(grpc_slice a, grpc_slice b) { + if (a.refcount && b.refcount && a.refcount->vtable == b.refcount->vtable) { + return a.refcount->vtable->eq(a, b); } + return grpc_slice_default_eq_impl(a, b); +} + +int grpc_slice_cmp(grpc_slice a, grpc_slice b) { int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); if (d != 0) return d; return memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), @@ -383,7 +396,7 @@ int grpc_slice_str_cmp(grpc_slice a, const char *b) { int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b) { if (a.refcount == NULL || b.refcount == NULL) { - return grpc_slice_cmp(a, b) == 0; + return grpc_slice_eq(a, b); } return a.data.refcounted.length == b.data.refcounted.length && a.data.refcounted.bytes == b.data.refcounted.bytes; diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 2d932849264..3cae8a98f34 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -110,17 +110,30 @@ static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } -static uint32_t interned_slice_hash(void *p, grpc_slice slice) { - interned_slice_refcount *s = p; +static uint32_t interned_slice_hash(grpc_slice slice) { + interned_slice_refcount *s = (interned_slice_refcount *)slice.refcount; if (slice.data.refcounted.bytes == (uint8_t *)(s + 1) && slice.data.refcounted.length == s->length) { return s->hash; } - return grpc_slice_default_hash_impl(p, slice); + return grpc_slice_default_hash_impl(slice); +} + +static int interned_slice_eq(grpc_slice a, grpc_slice b) { + interned_slice_refcount *sa = (interned_slice_refcount *)a.refcount; + interned_slice_refcount *sb = (interned_slice_refcount *)b.refcount; + if (a.data.refcounted.bytes == (uint8_t *)(sa + 1) && + b.data.refcounted.bytes == (uint8_t *)(sb + 1)) { + return a.data.refcounted.length == b.data.refcounted.length && + a.data.refcounted.bytes == b.data.refcounted.bytes; + } else { + return grpc_slice_default_eq_impl(a, b); + } } static const grpc_slice_refcount_vtable interned_slice_vtable = { - interned_slice_ref, interned_slice_unref, interned_slice_hash}; + interned_slice_ref, interned_slice_unref, interned_slice_eq, + interned_slice_hash}; static void grow_shard(slice_shard *shard) { size_t capacity = shard->capacity * 2; @@ -157,22 +170,31 @@ static grpc_slice materialize(interned_slice_refcount *s) { return slice; } -uint32_t grpc_slice_default_hash_impl(void *unused_refcnt, grpc_slice s) { +uint32_t grpc_slice_default_hash_impl(grpc_slice s) { return gpr_murmur_hash3(GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), g_hash_seed); } -uint32_t grpc_static_slice_hash(void *unused_refcnt, grpc_slice s) { +uint32_t grpc_static_slice_hash(grpc_slice s) { int id = grpc_static_metadata_index(s); if (id == -1) { - return grpc_slice_default_hash_impl(unused_refcnt, s); + return grpc_slice_default_hash_impl(s); } return static_metadata_hash_values[id]; } +int grpc_static_slice_eq(grpc_slice a, grpc_slice b) { + int id_a = grpc_static_metadata_index(a); + int id_b = grpc_static_metadata_index(b); + if (id_a == -1 || id_b == -1) { + return grpc_slice_default_eq_impl(a, b); + } + return id_a == id_b; +} + uint32_t grpc_slice_hash(grpc_slice s) { - return s.refcount == NULL ? grpc_slice_default_hash_impl(NULL, s) - : s.refcount->vtable->hash(s.refcount, s); + return s.refcount == NULL ? grpc_slice_default_hash_impl(s) + : s.refcount->vtable->hash(s); } void grpc_slice_static_intern(grpc_slice *slice) { @@ -185,7 +207,7 @@ void grpc_slice_static_intern(grpc_slice *slice) { static_metadata_hash_ent ent = static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - 0 == grpc_slice_cmp(grpc_static_slice_table[ent.idx], *slice)) { + grpc_slice_eq(grpc_static_slice_table[ent.idx], *slice)) { grpc_slice_unref(*slice); *slice = grpc_static_slice_table[ent.idx]; return; @@ -208,7 +230,7 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { static_metadata_hash_ent ent = static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - 0 == grpc_slice_cmp(grpc_static_slice_table[ent.idx], slice)) { + grpc_slice_eq(grpc_static_slice_table[ent.idx], slice)) { return grpc_static_slice_table[ent.idx]; } } @@ -221,7 +243,7 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { /* search for an existing string */ size_t idx = TABLE_IDX(hash, shard->capacity); for (s = shard->strs[idx]; s; s = s->bucket_next) { - if (s->hash == hash && grpc_slice_cmp(slice, materialize(s)) == 0) { + if (s->hash == hash && grpc_slice_eq(slice, materialize(s))) { if (gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) == 0) { /* If we get here, we've added a ref to something that was about to * die - drop it immediately. @@ -283,7 +305,7 @@ void grpc_slice_intern_init(void) { max_static_metadata_hash_probe = 0; for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { static_metadata_hash_values[i] = - grpc_slice_default_hash_impl(NULL, grpc_static_slice_table[i]); + grpc_slice_default_hash_impl(grpc_static_slice_table[i]); for (size_t j = 0; j < GPR_ARRAY_SIZE(static_metadata_hash); j++) { size_t slot = (static_metadata_hash_values[i] + j) % GPR_ARRAY_SIZE(static_metadata_hash); diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 211d5f06be6..cb85d572132 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -55,6 +55,7 @@ void grpc_test_only_set_slice_hash_seed(uint32_t key); // if slice matches a static slice, consume it and replace it with the static // slice, otherwise do nothing: this is a fast interning for well known strings void grpc_slice_static_intern(grpc_slice *slice); -uint32_t grpc_static_slice_hash(void *refcnt, grpc_slice s); +uint32_t grpc_static_slice_hash(grpc_slice s); +int grpc_static_slice_eq(grpc_slice a, grpc_slice b); #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 0ca97337e2f..af53a5b246d 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -252,8 +252,8 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, MAX_SEND_EXTRA_METADATA_COUNT); for (i = 0; i < args->add_initial_metadata_count; i++) { call->send_extra_metadata[i].md = args->add_initial_metadata[i]; - if (grpc_slice_cmp(GRPC_MDKEY(args->add_initial_metadata[i]), - GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(args->add_initial_metadata[i]), + GRPC_MDSTR_PATH)) { path = grpc_slice_ref_internal( GRPC_MDVALUE(args->add_initial_metadata[i])); } @@ -916,12 +916,12 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem md) { static grpc_mdelem recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, grpc_mdelem elem) { - if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_STATUS) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_STATUS)) { GPR_TIMER_BEGIN("status", 0); set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); GPR_TIMER_END("status", 0); return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_MESSAGE) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_MESSAGE)) { GPR_TIMER_BEGIN("status-details", 0); set_status_details(exec_ctx, call, STATUS_FROM_WIRE, grpc_slice_ref_internal(GRPC_MDVALUE(elem))); @@ -955,13 +955,12 @@ static grpc_mdelem recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, elem = recv_common_filter(exec_ctx, call, elem); if (GRPC_MDISNULL(elem)) { return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ENCODING) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ENCODING)) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); set_incoming_compression_algorithm(call, decode_compression(elem)); GPR_TIMER_END("incoming_compression_algorithm", 0); return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(elem), - GRPC_MDSTR_GRPC_ACCEPT_ENCODING) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ACCEPT_ENCODING)) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(exec_ctx, call, elem); GPR_TIMER_END("encodings_accepted_by_peer", 0); diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 501545b5c0e..6f2a88ae681 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -125,7 +125,8 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, } channel->default_authority = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_from_copied_string(args->args[i].value.string)); + grpc_slice_intern( + grpc_slice_from_copied_string(args->args[i].value.string))); } } else if (0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { @@ -141,7 +142,8 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, } else { channel->default_authority = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_from_copied_string(args->args[i].value.string)); + grpc_slice_intern( + grpc_slice_from_copied_string(args->args[i].value.string))); } } } else if (0 == strcmp(args->args[i].key, diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index b21e1d8113e..1c29873a658 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -624,8 +624,8 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { chand->registered_method_slots]; if (!rm) break; if (!rm->has_host) continue; - if (grpc_slice_cmp(rm->host, calld->host) != 0) continue; - if (grpc_slice_cmp(rm->method, calld->path) != 0) continue; + if (!grpc_slice_eq(rm->host, calld->host)) continue; + if (!grpc_slice_eq(rm->method, calld->path)) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && !calld->recv_idempotent_request) { continue; @@ -642,7 +642,7 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { chand->registered_method_slots]; if (!rm) break; if (rm->has_host) continue; - if (grpc_slice_cmp(rm->method, calld->path) != 0) continue; + if (!grpc_slice_eq(rm->method, calld->path)) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && !calld->recv_idempotent_request) { continue; @@ -739,13 +739,13 @@ static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_PATH) == 0) { + if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { if (!calld->path_set) { calld->path = grpc_slice_ref(GRPC_MDVALUE(md)); calld->path_set = true; } return GRPC_MDNULL; - } else if (grpc_slice_cmp(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY) == 0) { + } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { if (!calld->host_set) { calld->host = grpc_slice_ref(GRPC_MDVALUE(md)); calld->host_set = true; diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 2082d1bac27..f9f5ac9dd2b 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -279,8 +279,7 @@ grpc_mdelem grpc_mdelem_create( idx = TABLE_IDX(hash, shard->capacity); /* search for an existing pair */ for (md = shard->elems[idx]; md; md = md->bucket_next) { - if (grpc_slice_cmp(key, md->key) == 0 && - grpc_slice_cmp(value, md->value) == 0) { + if (grpc_slice_eq(key, md->key) && grpc_slice_eq(value, md->value)) { REF_MD_LOCKED(shard, md); gpr_mu_unlock(&shard->mu); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); @@ -496,7 +495,8 @@ void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { if (a.payload == b.payload) return true; + if (GRPC_MDELEM_IS_INTERNED(a) && GRPC_MDELEM_IS_INTERNED(b)) return false; if (GRPC_MDISNULL(a) || GRPC_MDISNULL(b)) return false; - return 0 == grpc_slice_cmp(GRPC_MDKEY(a), GRPC_MDKEY(b)) && - 0 == grpc_slice_cmp(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); + return grpc_slice_eq(GRPC_MDKEY(a), GRPC_MDKEY(b)) && + grpc_slice_eq(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); } diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index 6d0afbe7891..f4ba86c854b 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -86,17 +86,21 @@ typedef struct grpc_mdelem_data { /* there is a private part to this in metadata.c */ } grpc_mdelem_data; +/* GRPC_MDELEM_STORAGE_* enum values that can be treated as interned always have + this bit set in their integer value */ +#define GRPC_MDELEM_STORAGE_INTERNED_BIT 1 + typedef enum { /* memory pointed to by grpc_mdelem::payload is owned by an external system */ GRPC_MDELEM_STORAGE_EXTERNAL = 0, /* memory pointed to by grpc_mdelem::payload is interned by the metadata system */ - GRPC_MDELEM_STORAGE_INTERNED = 1, + GRPC_MDELEM_STORAGE_INTERNED = GRPC_MDELEM_STORAGE_INTERNED_BIT, /* memory pointed to by grpc_mdelem::payload is allocated by the metadata system */ GRPC_MDELEM_STORAGE_ALLOCATED = 2, /* memory is in the static metadata table */ - GRPC_MDELEM_STORAGE_STATIC = 3, + GRPC_MDELEM_STORAGE_STATIC = 2 | GRPC_MDELEM_STORAGE_INTERNED_BIT, } grpc_mdelem_data_storage; struct grpc_mdelem { @@ -111,6 +115,9 @@ struct grpc_mdelem { ((grpc_mdelem_data_storage)((md).payload & (uintptr_t)3)) #define GRPC_MAKE_MDELEM(data, storage) \ ((grpc_mdelem){((uintptr_t)(data)) | ((uintptr_t)storage)}) +#define GRPC_MDELEM_IS_INTERNED(md) \ + ((grpc_mdelem_data_storage)((md).payload & \ + (uintptr_t)GRPC_MDELEM_STORAGE_INTERNED_BIT)) /* Unrefs the slices. */ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 575f442a9b0..374a5fd6159 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -117,7 +117,7 @@ static uint8_t g_raw_bytes[] = { static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable static_vtable = { - static_ref, static_unref, grpc_static_slice_hash}; + static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash}; static grpc_slice_refcount g_refcnt = {&static_vtable}; bool grpc_is_static_metadata_string(grpc_slice slice) { diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index f9255be1dc0..2a0a56950ba 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -210,7 +210,7 @@ static void client_validator(grpc_slice_buffer *incoming) { *p++ = 0; *p++ = 11; // Compare actual and expected. - GPR_ASSERT(grpc_slice_cmp(last_frame, expected) == 0); + GPR_ASSERT(grpc_slice_eq(last_frame, expected)); grpc_slice_buffer_destroy(&last_frame_buffer); } diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index fa0bdb8c199..37397ced8df 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -61,13 +61,11 @@ static void test_algorithm_mesh(void) { grpc_slice_from_static_string(name), &parsed)); GPR_ASSERT((int)parsed == i); mdstr = grpc_slice_from_copied_string(name); - GPR_ASSERT(0 == - grpc_slice_cmp(mdstr, grpc_compression_algorithm_slice(parsed))); + GPR_ASSERT(grpc_slice_eq(mdstr, grpc_compression_algorithm_slice(parsed))); GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); mdelem = grpc_compression_encoding_mdelem(parsed); - GPR_ASSERT(0 == grpc_slice_cmp(GRPC_MDVALUE(mdelem), mdstr)); - GPR_ASSERT(0 == - grpc_slice_cmp(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); + GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); + GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); grpc_slice_unref_internal(&exec_ctx, mdstr); GRPC_MDELEM_UNREF(&exec_ctx, mdelem); grpc_exec_ctx_finish(&exec_ctx); @@ -91,12 +89,12 @@ static void test_algorithm_failure(void) { mdstr = grpc_slice_from_static_string("this-is-an-invalid-algorithm"); GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) == GRPC_COMPRESS_ALGORITHMS_COUNT); - GPR_ASSERT(0 == grpc_slice_cmp(grpc_compression_algorithm_slice( - GRPC_COMPRESS_ALGORITHMS_COUNT), - grpc_empty_slice())); - GPR_ASSERT(0 == grpc_slice_cmp(grpc_compression_algorithm_slice( - GRPC_COMPRESS_ALGORITHMS_COUNT + 1), - grpc_empty_slice())); + GPR_ASSERT(grpc_slice_eq( + grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT), + grpc_empty_slice())); + GPR_ASSERT(grpc_slice_eq( + grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT + 1), + grpc_empty_slice())); grpc_slice_unref_internal(&exec_ctx, mdstr); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 2432ca768ad..246a2b3a713 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -114,7 +114,7 @@ static void assert_passthrough(grpc_slice value, } final = grpc_slice_merge(output.slices, output.count); - GPR_ASSERT(0 == grpc_slice_cmp(value, final)); + GPR_ASSERT(grpc_slice_eq(value, final)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&compressed); diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 925c59e696e..3b463a69337 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -109,8 +109,8 @@ static int has_metadata_slices(const grpc_metadata *md, size_t count, grpc_slice key, grpc_slice value) { size_t i; for (i = 0; i < count; i++) { - if (0 == grpc_slice_cmp(md[i].key, key) && - 0 == grpc_slice_cmp(md[i].value, value)) { + if (grpc_slice_eq(md[i].key, key) && + grpc_slice_eq(md[i].value, value)) { return 1; } } diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index c8c6eebd601..5bfd715ea4b 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -196,8 +196,8 @@ static void test_add_to_empty_md_store(void) { grpc_slice value = grpc_slice_from_copied_string(value_str); grpc_credentials_md_store_add(store, key, value); GPR_ASSERT(store->num_entries == 1); - GPR_ASSERT(grpc_slice_cmp(key, store->entries[0].key) == 0); - GPR_ASSERT(grpc_slice_cmp(value, store->entries[0].value) == 0); + GPR_ASSERT(grpc_slice_eq(key, store->entries[0].key)); + GPR_ASSERT(grpc_slice_eq(value, store->entries[0].value)); grpc_slice_unref(key); grpc_slice_unref(value); grpc_credentials_md_store_unref(&exec_ctx, store); diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index 3a0c2bb2723..ef38893a63c 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -164,7 +164,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); - GPR_ASSERT(0 == grpc_slice_cmp(s, incoming.slices[0])); + GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); grpc_endpoint_shutdown(&exec_ctx, f.client_ep); grpc_endpoint_shutdown(&exec_ctx, f.server_ep); diff --git a/test/core/slice/percent_encode_fuzzer.c b/test/core/slice/percent_encode_fuzzer.c index 9698e796b48..0d440c5bb2b 100644 --- a/test/core/slice/percent_encode_fuzzer.c +++ b/test/core/slice/percent_encode_fuzzer.c @@ -55,8 +55,8 @@ static void test(const uint8_t *data, size_t size, const uint8_t *dict) { grpc_slice permissive_decoded_output = grpc_permissive_percent_decode_slice(output); // and decoded output must always match the input - GPR_ASSERT(grpc_slice_cmp(input, decoded_output) == 0); - GPR_ASSERT(grpc_slice_cmp(input, permissive_decoded_output) == 0); + GPR_ASSERT(grpc_slice_eq(input, decoded_output)); + GPR_ASSERT(grpc_slice_eq(input, permissive_decoded_output)); grpc_slice_unref(input); grpc_slice_unref(output); grpc_slice_unref(decoded_output); diff --git a/test/core/slice/percent_encoding_test.c b/test/core/slice/percent_encoding_test.c index d71c99f54c5..0bff4903e6c 100644 --- a/test/core/slice/percent_encoding_test.c +++ b/test/core/slice/percent_encoding_test.c @@ -81,9 +81,9 @@ static void test_vector(const char *raw, size_t raw_length, const char *encoded, gpr_free(encoded2raw_msg); gpr_free(encoded2raw_permissive_msg); - GPR_ASSERT(0 == grpc_slice_cmp(raw_slice, encoded2raw_slice)); - GPR_ASSERT(0 == grpc_slice_cmp(raw_slice, encoded2raw_permissive_slice)); - GPR_ASSERT(0 == grpc_slice_cmp(encoded_slice, raw2encoded_slice)); + GPR_ASSERT(grpc_slice_eq(raw_slice, encoded2raw_slice)); + GPR_ASSERT(grpc_slice_eq(raw_slice, encoded2raw_permissive_slice)); + GPR_ASSERT(grpc_slice_eq(encoded_slice, raw2encoded_slice)); grpc_slice_unref(encoded2raw_slice); grpc_slice_unref(encoded2raw_permissive_slice); @@ -123,7 +123,7 @@ static void test_nonconformant_vector(const char *encoded, encoded2raw_permissive_msg); gpr_free(encoded2raw_permissive_msg); - GPR_ASSERT(0 == grpc_slice_cmp(permissive_unencoded_slice, + GPR_ASSERT(grpc_slice_eq(permissive_unencoded_slice, encoded2raw_permissive_slice)); grpc_slice_unref(permissive_unencoded_slice); diff --git a/test/core/transport/chttp2/bin_decoder_test.c b/test/core/transport/chttp2/bin_decoder_test.c index 221112ab21b..a8b0a751378 100644 --- a/test/core/transport/chttp2/bin_decoder_test.c +++ b/test/core/transport/chttp2/bin_decoder_test.c @@ -46,7 +46,7 @@ static int all_ok = 1; static void expect_slice_eq(grpc_exec_ctx *exec_ctx, grpc_slice expected, grpc_slice slice, char *debug, int line) { - if (0 != grpc_slice_cmp(slice, expected)) { + if (!grpc_slice_eq(slice, expected)) { char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c index 778606a78cb..bd10a1e2116 100644 --- a/test/core/transport/chttp2/bin_encoder_test.c +++ b/test/core/transport/chttp2/bin_encoder_test.c @@ -48,7 +48,7 @@ static int all_ok = 1; static void expect_slice_eq(grpc_slice expected, grpc_slice slice, char *debug, int line) { - if (0 != grpc_slice_cmp(slice, expected)) { + if (!grpc_slice_eq(slice, expected)) { char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, @@ -85,7 +85,7 @@ static void expect_combined_equiv(const char *s, size_t len, int line) { grpc_slice base64 = grpc_chttp2_base64_encode(input); grpc_slice expect = grpc_chttp2_huffman_compress(base64); grpc_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input); - if (0 != grpc_slice_cmp(expect, got)) { + if (!grpc_slice_eq(expect, got)) { char *t = grpc_dump_slice(input, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *e = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *g = grpc_dump_slice(got, GPR_DUMP_HEX | GPR_DUMP_ASCII); diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index 862966cc38d..9e418bad5d0 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -108,7 +108,7 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, grpc_slice_buffer_destroy_internal(exec_ctx, &output); grpc_metadata_batch_destroy(exec_ctx, &b); - if (0 != grpc_slice_cmp(merged, expect)) { + if (!grpc_slice_eq(merged, expect)) { char *expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *got_str = grpc_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "mismatched output for %s", expected); diff --git a/test/core/transport/chttp2/varint_test.c b/test/core/transport/chttp2/varint_test.c index e29be4b056f..f12c340a4be 100644 --- a/test/core/transport/chttp2/varint_test.c +++ b/test/core/transport/chttp2/varint_test.c @@ -49,7 +49,7 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, slice = grpc_slice_malloc(nbytes); GRPC_CHTTP2_WRITE_VARINT(value, prefix_bits, prefix_or, GRPC_SLICE_START_PTR(slice), nbytes); - GPR_ASSERT(grpc_slice_cmp(expect, slice) == 0); + GPR_ASSERT(grpc_slice_eq(expect, slice)); grpc_slice_unref(expect); grpc_slice_unref(slice); } diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index ce8f1813ffd..7b9c050a8e3 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -87,8 +87,8 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { maybe_intern(grpc_slice_from_static_string("c"), intern_values)); GPR_ASSERT(grpc_mdelem_eq(m1, m2)); GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); - GPR_ASSERT(grpc_slice_cmp(GRPC_MDKEY(m3), GRPC_MDKEY(m1)) == 0); - GPR_ASSERT(grpc_slice_cmp(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1)) != 0); + GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(m3), GRPC_MDKEY(m1))); + GPR_ASSERT(!grpc_slice_eq(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1))); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); diff --git a/test/cpp/microbenchmarks/bm_fullstack.cc b/test/cpp/microbenchmarks/bm_fullstack.cc index 2b6dd3219ce..3528d95b5db 100644 --- a/test/cpp/microbenchmarks/bm_fullstack.cc +++ b/test/cpp/microbenchmarks/bm_fullstack.cc @@ -221,7 +221,7 @@ class InProcessCHTTP2 : public EndpointPairFixture { * CONTEXT MUTATORS */ -static const int kPregenerateKeyCount = 10000000; +static const int kPregenerateKeyCount = 1000000; template auto MakeVector(size_t length, F f) -> std::vector { diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index b1b7840cfd7..17ef88e67f1 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -312,7 +312,7 @@ print >>C, 'static uint8_t g_raw_bytes[] = {%s};' % (','.join('%d' % ord(c) for print >>C print >>C, 'static void static_ref(void *unused) {}' print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' -print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_static_slice_hash};'; +print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash};'; print >>C, 'static grpc_slice_refcount g_refcnt = {&static_vtable};' print >>C print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' From dcbe70c137224cd15c3b9256d317803666f670d6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 21 Nov 2016 14:07:52 -0800 Subject: [PATCH 042/261] Faster comparison --- src/core/lib/transport/metadata.c | 11 +- src/core/lib/transport/static_metadata.c | 924 ++++++++-------------- tools/codegen/core/gen_static_metadata.py | 37 +- 3 files changed, 346 insertions(+), 626 deletions(-) diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index f9f5ac9dd2b..650f6cc088f 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -260,10 +260,13 @@ grpc_mdelem grpc_mdelem_create( return GRPC_MAKE_MDELEM(allocated, GRPC_MDELEM_STORAGE_ALLOCATED); } - grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( - grpc_static_metadata_index(key), grpc_static_metadata_index(value)); - if (!GRPC_MDISNULL(static_elem)) { - return static_elem; + if (grpc_is_static_metadata_string(key) && + grpc_is_static_metadata_string(value)) { + grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( + grpc_static_metadata_index(key), grpc_static_metadata_index(value)); + if (!GRPC_MDISNULL(static_elem)) { + return static_elem; + } } uint32_t hash = diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 374a5fd6159..55c5cd46190 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -43,7 +43,7 @@ #include "src/core/lib/slice/slice_internal.h" -static uint8_t g_raw_bytes[] = { +static uint8_t g_bytes[] = { 48, 49, 50, 50, 48, 48, 50, 48, 52, 50, 48, 54, 51, 48, 52, 52, 48, 48, 52, 48, 52, 53, 48, 48, 97, 99, 99, 101, 112, 116, 97, 99, 99, 101, 112, 116, 45, 99, 104, 97, 114, 115, 101, 116, 97, @@ -118,292 +118,174 @@ static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable static_vtable = { static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash}; -static grpc_slice_refcount g_refcnt = {&static_vtable}; +typedef struct { + grpc_slice_refcount base; + const uint16_t offset; + const uint16_t length; +} static_slice_refcount; +static static_slice_refcount g_refcnts[GRPC_STATIC_MDSTR_COUNT] = { + {{&static_vtable}, 0, 1}, {{&static_vtable}, 1, 1}, + {{&static_vtable}, 2, 1}, {{&static_vtable}, 3, 3}, + {{&static_vtable}, 6, 3}, {{&static_vtable}, 9, 3}, + {{&static_vtable}, 12, 3}, {{&static_vtable}, 15, 3}, + {{&static_vtable}, 18, 3}, {{&static_vtable}, 21, 3}, + {{&static_vtable}, 24, 6}, {{&static_vtable}, 30, 14}, + {{&static_vtable}, 44, 15}, {{&static_vtable}, 59, 15}, + {{&static_vtable}, 74, 13}, {{&static_vtable}, 87, 27}, + {{&static_vtable}, 114, 3}, {{&static_vtable}, 117, 5}, + {{&static_vtable}, 122, 16}, {{&static_vtable}, 138, 10}, + {{&static_vtable}, 148, 13}, {{&static_vtable}, 161, 13}, + {{&static_vtable}, 174, 19}, {{&static_vtable}, 193, 16}, + {{&static_vtable}, 209, 16}, {{&static_vtable}, 225, 14}, + {{&static_vtable}, 239, 16}, {{&static_vtable}, 255, 13}, + {{&static_vtable}, 268, 12}, {{&static_vtable}, 280, 6}, + {{&static_vtable}, 286, 4}, {{&static_vtable}, 290, 7}, + {{&static_vtable}, 297, 12}, {{&static_vtable}, 309, 0}, + {{&static_vtable}, 309, 4}, {{&static_vtable}, 313, 6}, + {{&static_vtable}, 319, 7}, {{&static_vtable}, 326, 4}, + {{&static_vtable}, 330, 3}, {{&static_vtable}, 333, 4}, + {{&static_vtable}, 337, 20}, {{&static_vtable}, 357, 30}, + {{&static_vtable}, 387, 31}, {{&static_vtable}, 418, 12}, + {{&static_vtable}, 430, 19}, {{&static_vtable}, 449, 13}, + {{&static_vtable}, 462, 30}, {{&static_vtable}, 492, 12}, + {{&static_vtable}, 504, 16}, {{&static_vtable}, 520, 14}, + {{&static_vtable}, 534, 11}, {{&static_vtable}, 545, 12}, + {{&static_vtable}, 557, 16}, {{&static_vtable}, 573, 4}, + {{&static_vtable}, 577, 13}, {{&static_vtable}, 590, 4}, + {{&static_vtable}, 594, 4}, {{&static_vtable}, 598, 5}, + {{&static_vtable}, 603, 8}, {{&static_vtable}, 611, 16}, + {{&static_vtable}, 627, 21}, {{&static_vtable}, 648, 13}, + {{&static_vtable}, 661, 8}, {{&static_vtable}, 669, 17}, + {{&static_vtable}, 686, 13}, {{&static_vtable}, 699, 8}, + {{&static_vtable}, 707, 19}, {{&static_vtable}, 726, 13}, + {{&static_vtable}, 739, 11}, {{&static_vtable}, 750, 8}, + {{&static_vtable}, 758, 4}, {{&static_vtable}, 762, 8}, + {{&static_vtable}, 770, 12}, {{&static_vtable}, 782, 7}, + {{&static_vtable}, 789, 5}, {{&static_vtable}, 794, 4}, + {{&static_vtable}, 798, 18}, {{&static_vtable}, 816, 19}, + {{&static_vtable}, 835, 3}, {{&static_vtable}, 838, 5}, + {{&static_vtable}, 843, 7}, {{&static_vtable}, 850, 7}, + {{&static_vtable}, 857, 11}, {{&static_vtable}, 868, 7}, + {{&static_vtable}, 875, 6}, {{&static_vtable}, 881, 10}, + {{&static_vtable}, 891, 1}, {{&static_vtable}, 892, 36}, + {{&static_vtable}, 928, 11}, {{&static_vtable}, 939, 7}, + {{&static_vtable}, 946, 25}, {{&static_vtable}, 971, 2}, + {{&static_vtable}, 973, 8}, {{&static_vtable}, 981, 17}, + {{&static_vtable}, 998, 10}, {{&static_vtable}, 1008, 4}, + {{&static_vtable}, 1012, 3}, {{&static_vtable}, 1015, 16}, +}; bool grpc_is_static_metadata_string(grpc_slice slice) { return slice.refcount != NULL && slice.refcount->vtable == &static_vtable; } const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 0, .length = 1}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1, .length = 1}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 2, .length = 1}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 3, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 6, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 9, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 12, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 15, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 18, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 21, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 24, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 30, .length = 14}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 59, .length = 15}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 74, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 87, .length = 27}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 114, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 117, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 122, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 138, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 148, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 161, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 174, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 193, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 209, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 225, .length = 14}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 239, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 255, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 280, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 286, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 297, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 313, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 319, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 326, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 330, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 333, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 357, .length = 30}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 387, .length = 31}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 418, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 430, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 462, .length = 30}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 492, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 504, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 520, .length = 14}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 545, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 557, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 590, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 598, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 611, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 627, .length = 21}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 648, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 661, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 669, .length = 17}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 686, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 699, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 707, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 726, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 739, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 750, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 762, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 770, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 794, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 798, .length = 18}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 816, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 835, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 838, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 850, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 857, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 875, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 881, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 891, .length = 1}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 892, .length = 36}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 928, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 946, .length = 25}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 971, .length = 2}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 973, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 981, .length = 17}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 998, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1008, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1012, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1015, .length = 16}}, + {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 1}}, + {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 1, 1}}, + {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 2, 1}}, + {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 3, 3}}, + {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 6, 3}}, + {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 9, 3}}, + {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 12, 3}}, + {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 15, 3}}, + {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 18, 3}}, + {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 21, 3}}, + {.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 24, 6}}, + {.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 30, 14}}, + {.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, + {.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 59, 15}}, + {.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 74, 13}}, + {.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 87, 27}}, + {.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 114, 3}}, + {.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 117, 5}}, + {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 122, 16}}, + {.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 138, 10}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 148, 13}}, + {.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 161, 13}}, + {.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 174, 19}}, + {.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 193, 16}}, + {.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 209, 16}}, + {.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 225, 14}}, + {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 239, 16}}, + {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 255, 13}}, + {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, + {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 280, 6}}, + {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 286, 4}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}, + {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 297, 12}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}, + {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 309, 4}}, + {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 313, 6}}, + {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 319, 7}}, + {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 326, 4}}, + {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 330, 3}}, + {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 333, 4}}, + {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 357, 30}}, + {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 387, 31}}, + {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 418, 12}}, + {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 430, 19}}, + {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, + {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 462, 30}}, + {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 492, 12}}, + {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 504, 16}}, + {.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 520, 14}}, + {.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, + {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 545, 12}}, + {.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 557, 16}}, + {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}, + {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 577, 13}}, + {.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 590, 4}}, + {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 594, 4}}, + {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 598, 5}}, + {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}, + {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 611, 16}}, + {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 627, 21}}, + {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 648, 13}}, + {.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 661, 8}}, + {.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 669, 17}}, + {.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 686, 13}}, + {.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 699, 8}}, + {.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 707, 19}}, + {.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 726, 13}}, + {.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 739, 11}}, + {.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 750, 8}}, + {.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 758, 4}}, + {.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 762, 8}}, + {.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 770, 12}}, + {.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, + {.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, + {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 794, 4}}, + {.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 798, 18}}, + {.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 816, 19}}, + {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 835, 3}}, + {.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 838, 5}}, + {.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 843, 7}}, + {.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 850, 7}}, + {.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 857, 11}}, + {.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, + {.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 875, 6}}, + {.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 881, 10}}, + {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 891, 1}}, + {.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 892, 36}}, + {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 928, 11}}, + {.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 946, 25}}, + {.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 971, 2}}, + {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 973, 8}}, + {.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 981, 17}}, + {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 998, 10}}, + {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 1008, 4}}, + {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 1012, 3}}, + {.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1015, 16}}, }; -static const uint8_t g_revmap[] = { - 0, 1, 2, 3, 255, 255, 4, 255, 255, 5, 255, 255, 6, 255, 255, - 7, 255, 255, 8, 255, 255, 9, 255, 255, 10, 255, 255, 255, 255, 255, - 11, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 12, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 13, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 14, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 15, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 16, 255, 255, 17, 255, 255, - 255, 255, 18, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 19, 255, 255, 255, 255, 255, 255, 255, 255, 255, 20, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 21, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 22, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 23, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 24, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 25, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 26, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 27, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 28, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 29, 255, 255, 255, 255, - 255, 30, 255, 255, 255, 31, 255, 255, 255, 255, 255, 255, 32, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 34, 255, 255, 255, 35, 255, - 255, 255, 255, 255, 36, 255, 255, 255, 255, 255, 255, 37, 255, 255, 255, - 38, 255, 255, 39, 255, 255, 255, 40, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 41, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 42, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 43, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 44, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 45, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 46, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 47, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 48, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 49, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 50, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 52, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 53, 255, 255, 255, 54, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 55, 255, 255, 255, 56, 255, 255, 255, 57, 255, - 255, 255, 255, 58, 255, 255, 255, 255, 255, 255, 255, 59, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 60, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 61, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 62, 255, 255, 255, 255, 255, 255, 255, 63, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 64, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 65, 255, 255, 255, 255, 255, - 255, 255, 66, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 67, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 68, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 69, 255, 255, 255, 255, 255, 255, 255, 70, 255, 255, 255, 71, 255, 255, - 255, 255, 255, 255, 255, 72, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 73, 255, 255, 255, 255, 255, 255, 74, 255, 255, 255, 255, 75, - 255, 255, 255, 76, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 77, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 78, 255, 255, 79, 255, - 255, 255, 255, 80, 255, 255, 255, 255, 255, 255, 81, 255, 255, 255, 255, - 255, 255, 82, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 83, 255, - 255, 255, 255, 255, 255, 84, 255, 255, 255, 255, 255, 85, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 86, 87, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 88, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 89, 255, 255, 255, 255, 255, - 255, 90, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 91, 255, 92, 255, - 255, 255, 255, 255, 255, 255, 93, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 94, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 95, 255, 255, 255, 96, 255, 255, 97, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255}; - int grpc_static_metadata_index(grpc_slice slice) { - if (GRPC_SLICE_LENGTH(slice) == 0) return 33; - if (slice.refcount != &g_refcnt) return -1; - size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes); - if (ofs > sizeof(g_revmap)) return -1; - uint8_t id = g_revmap[ofs]; - return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length == - slice.data.refcounted.length - ? id - : -1); + static_slice_refcount *r = (static_slice_refcount *)slice.refcount; + if (slice.data.refcounted.bytes == g_bytes + r->offset && + slice.data.refcounted.length == r->length) + return (int)(r - g_refcnts); + return -1; } uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { @@ -465,330 +347,168 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { } grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 30, .length = 14}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 24, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 44, .length = 15}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 577, .length = 13}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 59, .length = 15}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 74, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 87, .length = 27}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 114, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 117, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 138, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 148, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 161, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 174, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 193, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 209, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 225, .length = 14}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 239, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 255, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 122, .length = 16}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 268, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 280, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 286, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 313, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 319, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 326, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 297, .length = 12}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 611, .length = 16}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 627, .length = 21}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 337, .length = 20}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 648, .length = 13}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 290, .length = 7}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 573, .length = 4}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 449, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 603, .length = 8}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 0, .length = 1}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1, .length = 1}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 534, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 2, .length = 1}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 590, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 661, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 669, .length = 17}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 686, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 699, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 707, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 726, .length = 13}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 739, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 750, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 758, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 762, .length = 8}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 770, .length = 12}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 330, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 794, .length = 4}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 782, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 835, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 891, .length = 1}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 789, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 928, .length = 11}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 798, .length = 18}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 816, .length = 19}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 838, .length = 5}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 843, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 850, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 857, .length = 11}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 333, .length = 4}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 594, .length = 4}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 868, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 598, .length = 5}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 875, .length = 6}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 881, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 3, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 6, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 9, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 12, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 15, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 18, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 939, .length = 7}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 21, .length = 3}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 946, .length = 25}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 971, .length = 2}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 973, .length = 8}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 981, .length = 17}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 998, .length = 10}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1008, .length = 4}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1012, .length = 3}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, - {{.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 1015, .length = 16}}, - {.refcount = &g_refcnt, - .data.refcounted = {.bytes = g_raw_bytes + 309, .length = 0}}}, + {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 30, 14}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 24, 6}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, + {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 577, 13}}}, + {{.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 59, 15}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 74, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 87, 27}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 114, 3}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 117, 5}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 138, 10}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 148, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 161, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 174, 19}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 193, 16}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 209, 16}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 225, 14}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 239, 16}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 255, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, + {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 122, 16}}}, + {{.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 280, 6}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 286, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 309, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 313, 6}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 319, 7}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 326, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 297, 12}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 611, 16}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 627, 21}}}, + {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, + {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 648, 13}}}, + {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}}, + {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, + {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}}, + {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, + {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}}, + {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, + {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 1}}}, + {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, + {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 1, 1}}}, + {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, + {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 2, 1}}}, + {{.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 590, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 661, 8}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 669, 17}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 686, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 699, 8}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 707, 19}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 726, 13}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 739, 11}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 750, 8}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 758, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 762, 8}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 770, 12}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, + {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 330, 3}}}, + {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, + {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 794, 4}}}, + {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, + {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 835, 3}}}, + {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, + {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 891, 1}}}, + {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, + {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 928, 11}}}, + {{.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 798, 18}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 816, 19}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 838, 5}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 843, 7}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 850, 7}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 857, 11}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, + {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 333, 4}}}, + {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, + {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 594, 4}}}, + {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, + {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 598, 5}}}, + {{.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 875, 6}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 881, 10}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 3, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 6, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 9, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 12, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 15, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 18, 3}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, + {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 21, 3}}}, + {{.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 946, 25}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 971, 2}}, + {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 973, 8}}}, + {{.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 981, 17}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 998, 10}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 1008, 4}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 1012, 3}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1015, 16}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, }; const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, 28, 32, 27, 31}; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 17ef88e67f1..e40a40d4230 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -300,6 +300,14 @@ print >>C print >>C, '#include "src/core/lib/slice/slice_internal.h"' print >>C +str_ofs = 0 +id2strofs = {} +for i, elem in enumerate(all_strs): + id2strofs[i] = str_ofs + str_ofs += len(elem); +def slice_def(i): + return '{.refcount = &g_refcnts[%d].base, .data.refcounted = {g_bytes+%d, %d}}' % (i, id2strofs[i], len(all_strs[i])) + print >>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' for i, elem in enumerate(all_strs): @@ -308,42 +316,31 @@ for i, elem in enumerate(all_strs): print >>H print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice);' print >>H -print >>C, 'static uint8_t g_raw_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in ''.join(all_strs))) +print >>C, 'static uint8_t g_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in ''.join(all_strs))) print >>C print >>C, 'static void static_ref(void *unused) {}' print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash};'; -print >>C, 'static grpc_slice_refcount g_refcnt = {&static_vtable};' +print >>C, 'typedef struct { grpc_slice_refcount base; const uint16_t offset; const uint16_t length; } static_slice_refcount;' +print >>C, 'static static_slice_refcount g_refcnts[GRPC_STATIC_MDSTR_COUNT] = {' +for i, elem in enumerate(all_strs): + print >>C, ' {{&static_vtable}, %d, %d},' % (id2strofs[i], len(elem)) +print >>C, '};' print >>C print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' print >>C, ' return slice.refcount != NULL && slice.refcount->vtable == &static_vtable;' print >>C, '}' print >>C print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' -str_ofs = 0 -revmap = {} -zero_length_idx = None -id2strofs = {} -def slice_def(i): - return '{.refcount = &g_refcnt, .data.refcounted = {.bytes = g_raw_bytes+%d, .length=%d}}' % (id2strofs[i], len(all_strs[i])) for i, elem in enumerate(all_strs): - id2strofs[i] = str_ofs print >>C, slice_def(i) + ',' - revmap[str_ofs] = i - if len(elem) == 0: zero_length_idx = i - str_ofs += len(elem); print >>C, '};' print >>C -print >>C, 'static const uint8_t g_revmap[] = {%s};' % ','.join('%d' % (revmap[i] if i in revmap else 255) for i in range(0, str_ofs)) -print >>C print >>H, 'int grpc_static_metadata_index(grpc_slice slice);' print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {' -print >>C, ' if (GRPC_SLICE_LENGTH(slice) == 0) return %d;' % zero_length_idx -print >>C, ' if (slice.refcount != &g_refcnt) return -1;' -print >>C, ' size_t ofs = (size_t)(slice.data.refcounted.bytes - g_raw_bytes);' -print >>C, ' if (ofs > sizeof(g_revmap)) return -1;' -print >>C, ' uint8_t id = g_revmap[ofs];' -print >>C, ' return id == 255 ? -1 : (grpc_static_slice_table[id].data.refcounted.length == slice.data.refcounted.length? id : -1);' +print >>C, ' static_slice_refcount *r = (static_slice_refcount *)slice.refcount;' +print >>C, ' if (slice.data.refcounted.bytes == g_bytes + r->offset && slice.data.refcounted.length == r->length) return (int)(r - g_refcnts);' +print >>C, ' return -1;' print >>C, '}' print >>C From 637209cec5ff7cd1c0dd193c9975493eee298043 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 21 Nov 2016 14:51:46 -0800 Subject: [PATCH 043/261] Fix trace --- src/core/ext/transport/chttp2/transport/hpack_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index c53a1faee32..23fb1d12cad 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -673,7 +673,7 @@ static const uint8_t inverse_base64[256] = { /* emission helpers */ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, grpc_mdelem md, int add_to_table) { - if (!GRPC_MDELEM_IS_INTERNED(md)) { + if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(md)) { char *k = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); char *v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); gpr_log( From a7d37a371a965470c917ccf50eb858f66bcc6eaa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Nov 2016 14:37:16 -0800 Subject: [PATCH 044/261] Initial conversion work to indexed metadata --- src/core/ext/lb_policy/grpclb/grpclb.c | 14 +- .../load_reporting/load_reporting_filter.c | 66 +- src/core/lib/channel/compress_filter.c | 94 +- src/core/lib/channel/http_client_filter.c | 200 +++-- src/core/lib/channel/http_server_filter.c | 299 +++---- src/core/lib/iomgr/error.c | 4 + src/core/lib/iomgr/error.h | 6 +- .../security/transport/client_auth_filter.c | 20 +- .../security/transport/server_auth_filter.c | 8 +- src/core/lib/surface/call.c | 89 +- src/core/lib/surface/server.c | 34 +- src/core/lib/transport/metadata_batch.c | 167 ++-- src/core/lib/transport/metadata_batch.h | 55 +- src/core/lib/transport/static_metadata.c | 817 +++++++++--------- src/core/lib/transport/static_metadata.h | 632 +++++++------- test/core/end2end/fuzzers/hpack.dictionary | 158 ++-- tools/codegen/core/gen_static_metadata.py | 93 +- 17 files changed, 1493 insertions(+), 1263 deletions(-) diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index ebb3f8044bb..ab4af321f6b 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -133,13 +133,13 @@ int grpc_lb_glb_trace = 0; /* add lb_token of selected subchannel (address) to the call's initial * metadata */ -static void initial_metadata_add_lb_token( +static grpc_error *initial_metadata_add_lb_token( grpc_metadata_batch *initial_metadata, grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != NULL); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); - grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, - lb_token); + return grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, + lb_token); } typedef struct wrapped_rr_closure_arg { @@ -188,9 +188,11 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, * available */ if (wc_arg->target != NULL) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { - initial_metadata_add_lb_token(wc_arg->initial_metadata, - wc_arg->lb_token_mdelem_storage, - GRPC_MDELEM_REF(wc_arg->lb_token)); + GRPC_LOG_IF_ERROR( + "grpclb.initial_metadata_add_lb_token", + initial_metadata_add_lb_token(wc_arg->initial_metadata, + wc_arg->lb_token_mdelem_storage, + GRPC_MDELEM_REF(wc_arg->lb_token))); } else { gpr_log(GPR_ERROR, "No LB token for connected subchannel pick %p (from RR " diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 75f5c73ae34..6f5dacacbb2 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -67,44 +67,28 @@ typedef struct channel_data { intptr_t id; /**< an id unique to the channel */ } channel_data; -typedef struct { - grpc_call_element *elem; - grpc_exec_ctx *exec_ctx; -} recv_md_filter_args; - -static grpc_mdelem recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - recv_md_filter_args *a = user_data; - grpc_call_element *elem = a->elem; - call_data *calld = elem->call_data; - - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { - calld->service_method = grpc_slice_ref_internal(GRPC_MDVALUE(md)); - calld->have_service_method = true; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_TOKEN)) { - calld->initial_md_string = grpc_slice_ref_internal(GRPC_MDVALUE(md)); - calld->have_initial_md_string = true; - return GRPC_MDNULL; - } - - return md; -} - static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *err) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (err == GRPC_ERROR_NONE) { - recv_md_filter_args a; - a.elem = elem; - a.exec_ctx = exec_ctx; - grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, - recv_md_filter, &a); - if (!calld->have_service_method) { + if (calld->recv_initial_metadata->idx.named.path != NULL) { + calld->service_method = grpc_slice_ref_internal( + GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); + calld->have_service_method = true; + } else { err = grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header")); } + if (calld->recv_initial_metadata->idx.named.lb_token != NULL) { + calld->initial_md_string = grpc_slice_ref_internal( + GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); + calld->have_initial_md_string = true; + grpc_metadata_batch_remove( + calld->recv_initial_metadata, + calld->recv_initial_metadata->idx.named.lb_token); + } } else { GRPC_ERROR_REF(err); } @@ -196,20 +180,6 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, */ } -static grpc_mdelem lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem md) { - grpc_call_element *elem = user_data; - call_data *calld = elem->call_data; - - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_LB_COST_BIN)) { - calld->trailing_md_string = grpc_slice_ref_internal(GRPC_MDVALUE(md)); - calld->have_trailing_md_string = true; - return GRPC_MDNULL; - } - - return md; -} - static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_transport_stream_op *op) { @@ -222,8 +192,14 @@ static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, calld->ops_recv_initial_metadata_ready = op->recv_initial_metadata_ready; op->recv_initial_metadata_ready = &calld->on_initial_md_ready; } else if (op->send_trailing_metadata) { - grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata, - lr_trailing_md_filter, elem); + if (op->send_trailing_metadata->idx.named.lb_cost_bin != NULL) { + calld->trailing_md_string = grpc_slice_ref_internal( + GRPC_MDVALUE(op->send_trailing_metadata->idx.named.lb_cost_bin->md)); + calld->have_trailing_md_string = true; + grpc_metadata_batch_remove( + op->send_trailing_metadata, + op->send_trailing_metadata->idx.named.lb_cost_bin); + } } grpc_call_next_op(exec_ctx, elem, op); diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 392d4d7231d..706c8df90c4 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -81,42 +81,6 @@ typedef struct channel_data { uint32_t supported_compression_algorithms; } channel_data; -/** For each \a md element from the incoming metadata, filter out the entry for - * "grpc-encoding", using its value to populate the call data's - * compression_algorithm field. */ -static grpc_mdelem compression_md_filter(grpc_exec_ctx *exec_ctx, - void *user_data, grpc_mdelem md) { - grpc_call_element *elem = user_data; - call_data *calld = elem->call_data; - channel_data *channeld = elem->channel_data; - - if (grpc_slice_eq(GRPC_MDKEY(md), - GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST)) { - if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), - &calld->compression_algorithm)) { - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); - gpr_free(val); - calld->compression_algorithm = GRPC_COMPRESS_NONE; - } - if (!GPR_BITGET(channeld->enabled_algorithms_bitset, - calld->compression_algorithm)) { - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (previously disabled). " - "Ignoring.", - val); - gpr_free(val); - calld->compression_algorithm = GRPC_COMPRESS_NONE; - } - calld->has_compression_algorithm = 1; - return GRPC_MDNULL; - } - - return md; -} - static int skip_compression(grpc_call_element *elem, uint32_t flags) { call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; @@ -135,32 +99,65 @@ static int skip_compression(grpc_call_element *elem, uint32_t flags) { } /** Filter initial metadata */ -static void process_send_initial_metadata( +static grpc_error *process_send_initial_metadata( + grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_metadata_batch *initial_metadata) GRPC_MUST_USE_RESULT; +static grpc_error *process_send_initial_metadata( grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_metadata_batch *initial_metadata) { + grpc_error *error; call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; /* Parse incoming request for compression. If any, it'll be available * at calld->compression_algorithm */ - grpc_metadata_batch_filter(exec_ctx, initial_metadata, compression_md_filter, - elem); - if (!calld->has_compression_algorithm) { + if (initial_metadata->idx.named.grpc_internal_encoding_request != NULL) { + grpc_mdelem md = + initial_metadata->idx.named.grpc_internal_encoding_request->md; + if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), + &calld->compression_algorithm)) { + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); + gpr_free(val); + calld->compression_algorithm = GRPC_COMPRESS_NONE; + } + if (!GPR_BITGET(channeld->enabled_algorithms_bitset, + calld->compression_algorithm)) { + char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (previously disabled). " + "Ignoring.", + val); + gpr_free(val); + calld->compression_algorithm = GRPC_COMPRESS_NONE; + } + calld->has_compression_algorithm = 1; + + grpc_metadata_batch_remove( + initial_metadata, + initial_metadata->idx.named.grpc_internal_encoding_request); + } else { /* If no algorithm was found in the metadata and we aren't * exceptionally skipping compression, fall back to the channel * default */ calld->compression_algorithm = channeld->default_compression_algorithm; calld->has_compression_algorithm = 1; /* GPR_TRUE */ } + /* hint compression algorithm */ - grpc_metadata_batch_add_tail( + error = grpc_metadata_batch_add_tail( initial_metadata, &calld->compression_algorithm_storage, grpc_compression_encoding_mdelem(calld->compression_algorithm)); + if (error != GRPC_ERROR_NONE) return error; + /* convey supported compression algorithms */ - grpc_metadata_batch_add_tail(initial_metadata, - &calld->accept_encoding_storage, - GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( - channeld->supported_compression_algorithms)); + error = grpc_metadata_batch_add_tail( + initial_metadata, &calld->accept_encoding_storage, + GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( + channeld->supported_compression_algorithms)); + + return error; } static void continue_send_message(grpc_exec_ctx *exec_ctx, @@ -251,7 +248,12 @@ static void compress_start_transport_stream_op(grpc_exec_ctx *exec_ctx, GPR_TIMER_BEGIN("compress_start_transport_stream_op", 0); if (op->send_initial_metadata) { - process_send_initial_metadata(exec_ctx, elem, op->send_initial_metadata); + grpc_error *error = process_send_initial_metadata( + exec_ctx, elem, op->send_initial_metadata); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + return; + } } if (op->send_message != NULL && !skip_compression(elem, op->send_message->flags)) { diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index e415877eb86..4593a9cb6d0 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -94,74 +94,91 @@ typedef struct channel_data { size_t max_payload_size_for_get; } channel_data; -static grpc_mdelem client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - grpc_call_element *elem = user_data; - if (grpc_mdelem_eq(md, GRPC_MDELEM_STATUS_200)) { - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_STATUS)) { - char *message_string; - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_asprintf(&message_string, "Received http2 header with status: %s", val); - grpc_slice message = grpc_slice_from_copied_string(message_string); - gpr_free(message_string); - gpr_free(val); - grpc_call_element_send_close_with_message(exec_ctx, elem, - GRPC_STATUS_CANCELLED, &message); - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE)) { - grpc_slice pct_decoded_msg = - grpc_permissive_percent_decode_slice(GRPC_MDVALUE(md)); - if (grpc_slice_is_equivalent(pct_decoded_msg, GRPC_MDVALUE(md))) { - grpc_slice_unref(pct_decoded_msg); - return md; +static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_metadata_batch *b) { + if (b->idx.named.status != NULL) { + if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { + grpc_metadata_batch_remove(b, b->idx.named.status); } else { - return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - pct_decoded_msg); + char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), + GPR_DUMP_ASCII); + grpc_error *e = grpc_error_set_str( + GRPC_ERROR_CREATE( + "Received http2 :status header with non-200 OK status"), + GRPC_ERROR_STR_VALUE, val); + gpr_free(val); + return e; } - } else if (grpc_mdelem_eq(md, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) { - if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == - '+' || - GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == - ';')) { - /* Although the C implementation doesn't (currently) generate them, - any custom +-suffix is explicitly valid. */ - /* TODO(klempner): We should consider preallocating common values such - as +proto or +json, or at least stashing them if we see them. */ - /* TODO(klempner): Should we be surfacing this to application code? */ + } + + if (b->idx.named.grpc_message != NULL) { + grpc_slice pct_decoded_msg = grpc_permissive_percent_decode_slice( + GRPC_MDVALUE(b->idx.named.grpc_message->md)); + if (grpc_slice_is_equivalent(pct_decoded_msg, + GRPC_MDVALUE(b->idx.named.grpc_message->md))) { + grpc_slice_unref(pct_decoded_msg); } else { - /* TODO(klempner): We're currently allowing this, but we shouldn't - see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); - gpr_free(val); + grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, + pct_decoded_msg); } - return GRPC_MDNULL; } - return md; + + if (b->idx.named.content_type != NULL) { + if (!grpc_mdelem_eq(b->idx.named.content_type->md, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { + if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), + EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) && + (GRPC_SLICE_START_PTR(GRPC_MDVALUE( + b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == + '+' || + GRPC_SLICE_START_PTR(GRPC_MDVALUE( + b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == + ';')) { + /* Although the C implementation doesn't (currently) generate them, + any custom +-suffix is explicitly valid. */ + /* TODO(klempner): We should consider preallocating common values such + as +proto or +json, or at least stashing them if we see them. */ + /* TODO(klempner): Should we be surfacing this to application code? */ + } else { + /* TODO(klempner): We're currently allowing this, but we shouldn't + see it without a proxy so log for now. */ + char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), + GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); + gpr_free(val); + } + } + grpc_metadata_batch_remove(b, b->idx.named.content_type); + } + + return GRPC_ERROR_NONE; } static void hc_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, - client_recv_filter, elem); - grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, - GRPC_ERROR_REF(error)); + if (error == GRPC_ERROR_NONE) { + error = client_filter_incoming_metadata(exec_ctx, elem, + calld->recv_initial_metadata); + } else { + GRPC_ERROR_REF(error); + } + grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error); } static void hc_on_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - grpc_metadata_batch_filter(exec_ctx, calld->recv_trailing_metadata, - client_recv_filter, elem); + if (error == GRPC_ERROR_NONE) { + error = client_filter_incoming_metadata(exec_ctx, elem, + calld->recv_trailing_metadata); + } else { + GRPC_ERROR_REF(error); + } grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, GRPC_ERROR_REF(error)); } @@ -184,16 +201,11 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); } -static grpc_mdelem client_strip_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - /* eat the things we'd like to set ourselves */ - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_METHOD)) return GRPC_MDNULL; - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) return GRPC_MDNULL; - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_TE)) return GRPC_MDNULL; - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) - return GRPC_MDNULL; - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_USER_AGENT)) return GRPC_MDNULL; - return md; +static void remove_if_present(grpc_metadata_batch *batch, + grpc_metadata_batch_callouts_index idx) { + if (batch->idx.array[idx] != NULL) { + grpc_metadata_batch_remove(batch, batch->idx.array[idx]); + } } static void continue_send_message(grpc_exec_ctx *exec_ctx, @@ -232,11 +244,13 @@ static void got_slice(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { } } -static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_transport_stream_op *op) { +static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_transport_stream_op *op) { /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; + grpc_error *error; if (op->send_initial_metadata != NULL) { /* Decide which HTTP VERB to use. We use GET if the request is marked @@ -274,8 +288,9 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN, grpc_slice_from_copied_buffer((const char *)calld->payload_bytes, op->send_message->length)); - grpc_metadata_batch_add_tail(op->send_initial_metadata, - &calld->payload_bin, payload_bin); + error = grpc_metadata_batch_add_tail(op->send_initial_metadata, + &calld->payload_bin, payload_bin); + if (error != GRPC_ERROR_NONE) return error; calld->on_complete = op->on_complete; op->on_complete = &calld->hc_on_complete; op->send_message = NULL; @@ -288,21 +303,32 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } } - grpc_metadata_batch_filter(exec_ctx, op->send_initial_metadata, - client_strip_filter, elem); + remove_if_present(op->send_initial_metadata, GRPC_BATCH_METHOD); + remove_if_present(op->send_initial_metadata, GRPC_BATCH_SCHEME); + remove_if_present(op->send_initial_metadata, GRPC_BATCH_TE); + remove_if_present(op->send_initial_metadata, GRPC_BATCH_CONTENT_TYPE); + remove_if_present(op->send_initial_metadata, GRPC_BATCH_USER_AGENT); + /* Send : prefixed headers, which have to be before any application layer headers. */ - grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->method, - method); - grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->scheme, - channeld->static_scheme); - grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->te_trailers, - GRPC_MDELEM_TE_TRAILERS); - grpc_metadata_batch_add_tail( + error = grpc_metadata_batch_add_head(op->send_initial_metadata, + &calld->method, method); + if (error != GRPC_ERROR_NONE) return error; + error = grpc_metadata_batch_add_head( + op->send_initial_metadata, &calld->scheme, channeld->static_scheme); + if (error != GRPC_ERROR_NONE) return error; + error = grpc_metadata_batch_add_tail(op->send_initial_metadata, + &calld->te_trailers, + GRPC_MDELEM_TE_TRAILERS); + if (error != GRPC_ERROR_NONE) return error; + error = grpc_metadata_batch_add_tail( op->send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); - grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->user_agent, - GRPC_MDELEM_REF(channeld->user_agent)); + if (error != GRPC_ERROR_NONE) return error; + error = grpc_metadata_batch_add_tail(op->send_initial_metadata, + &calld->user_agent, + GRPC_MDELEM_REF(channeld->user_agent)); + if (error != GRPC_ERROR_NONE) return error; } if (op->recv_initial_metadata != NULL) { @@ -318,6 +344,8 @@ static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, calld->on_done_recv_trailing_metadata = op->on_complete; op->on_complete = &calld->hc_on_recv_trailing_metadata; } + + return GRPC_ERROR_NONE; } static void hc_start_transport_op(grpc_exec_ctx *exec_ctx, @@ -325,16 +353,20 @@ static void hc_start_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op) { GPR_TIMER_BEGIN("hc_start_transport_op", 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, op); - hc_mutate_op(exec_ctx, elem, op); - GPR_TIMER_END("hc_start_transport_op", 0); - call_data *calld = elem->call_data; - if (op->send_message != NULL && calld->send_message_blocked) { - /* Don't forward the op. send_message contains slices that aren't ready - yet. The call will be forwarded by the op_complete of slice read call. - */ + grpc_error *error = hc_mutate_op(exec_ctx, elem, op); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); } else { - grpc_call_next_op(exec_ctx, elem, op); + call_data *calld = elem->call_data; + if (op->send_message != NULL && calld->send_message_blocked) { + /* Don't forward the op. send_message contains slices that aren't ready + yet. The call will be forwarded by the op_complete of slice read call. + */ + } else { + grpc_call_next_op(exec_ctx, elem, op); + } } + GPR_TIMER_END("hc_start_transport_op", 0); } /* Constructor for call_data */ diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index bdd1e188379..596c97e58ea 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -48,18 +48,13 @@ extern int grpc_http_trace; typedef struct call_data { - uint8_t seen_path; - uint8_t seen_method; - uint8_t sent_status; - uint8_t seen_scheme; - uint8_t seen_te_trailers; - uint8_t seen_authority; - uint8_t seen_payload_bin; grpc_linked_mdelem status; grpc_linked_mdelem content_type; + /* did this request come with payload-bin */ + bool seen_payload_bin; /* flag to ensure payload_bin is delivered only once */ - uint8_t payload_bin_delivered; + bool payload_bin_delivered; grpc_metadata_batch *recv_initial_metadata; bool *recv_idempotent_request; @@ -84,118 +79,147 @@ typedef struct call_data { typedef struct channel_data { uint8_t unused; } channel_data; -static grpc_mdelem server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem md) { - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_MESSAGE)) { +static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_metadata_batch *b) { + if (b->idx.named.grpc_message != NULL) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( - GRPC_MDVALUE(md), grpc_compatible_percent_encoding_unreserved_bytes); - if (grpc_slice_is_equivalent(pct_encoded_msg, GRPC_MDVALUE(md))) { + GRPC_MDVALUE(b->idx.named.grpc_message->md), + grpc_compatible_percent_encoding_unreserved_bytes); + if (grpc_slice_is_equivalent(pct_encoded_msg, + GRPC_MDVALUE(b->idx.named.grpc_message->md))) { grpc_slice_unref_internal(exec_ctx, pct_encoded_msg); - return md; } else { - return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - pct_encoded_msg); + grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, + pct_encoded_msg); } - } else { - return md; } + return GRPC_ERROR_NONE; } -static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - grpc_call_element *elem = user_data; +static void add_error(const char *error_name, grpc_error **cumulative, + grpc_error *new) { + abort(); +} + +static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_metadata_batch *b) { call_data *calld = elem->call_data; + grpc_error *error = GRPC_ERROR_NONE; + static const char *error_name = "Failed processing incoming headers"; - /* Check if it is one of the headers we care about. */ - if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS) || - grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_POST) || - grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_PUT) || - grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET) || - grpc_mdelem_eq(md, GRPC_MDELEM_SCHEME_HTTP) || - grpc_mdelem_eq(md, GRPC_MDELEM_SCHEME_HTTPS) || - grpc_mdelem_eq(md, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { - /* swallow it */ - if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_POST)) { - calld->seen_method = 1; + if (b->idx.named.method != NULL) { + if (grpc_mdelem_eq(b->idx.named.method->md, GRPC_MDELEM_METHOD_POST)) { *calld->recv_idempotent_request = false; *calld->recv_cacheable_request = false; - } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_PUT)) { - calld->seen_method = 1; + } else if (grpc_mdelem_eq(b->idx.named.method->md, + GRPC_MDELEM_METHOD_PUT)) { *calld->recv_idempotent_request = true; - } else if (grpc_mdelem_eq(md, GRPC_MDELEM_METHOD_GET)) { - calld->seen_method = 1; + } else if (grpc_mdelem_eq(b->idx.named.method->md, + GRPC_MDELEM_METHOD_GET)) { *calld->recv_cacheable_request = true; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { - calld->seen_scheme = 1; - } else if (grpc_mdelem_eq(md, GRPC_MDELEM_TE_TRAILERS)) { - calld->seen_te_trailers = 1; - } - /* TODO(klempner): Track that we've seen all the headers we should - require */ - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_CONTENT_TYPE)) { - if (grpc_slice_buf_start_eq(GRPC_MDVALUE(md), EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == - '+' || - GRPC_SLICE_START_PTR(GRPC_MDVALUE(md))[EXPECTED_CONTENT_TYPE_LENGTH] == - ';')) { - /* Although the C implementation doesn't (currently) generate them, - any custom +-suffix is explicitly valid. */ - /* TODO(klempner): We should consider preallocating common values such - as +proto or +json, or at least stashing them if we see them. */ - /* TODO(klempner): Should we be surfacing this to application code? */ } else { - /* TODO(klempner): We're currently allowing this, but we shouldn't - see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); - gpr_free(val); + add_error(error_name, &error, + grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), + b->idx.named.method->md)); } - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_TE) || - grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_METHOD) || - grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_SCHEME)) { - char *key = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); - char *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", key, value); - /* swallow it and error everything out. */ - /* TODO(klempner): We ought to generate more descriptive error messages - on the wire here. */ - gpr_free(key); - gpr_free(value); - grpc_call_element_send_cancel(exec_ctx, elem); - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { - if (calld->seen_path) { - gpr_log(GPR_ERROR, "Received :path twice"); - return GRPC_MDNULL; + grpc_metadata_batch_remove(b, b->idx.named.method); + } else { + add_error(error_name, &error, + grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), + GRPC_ERROR_STR_KEY, ":method")); + } + + if (b->idx.named.te != NULL) { + if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_TE_TRAILERS)) { + add_error(error_name, &error, + grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), + b->idx.named.te->md)); } - calld->seen_path = 1; - return md; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { - calld->seen_authority = 1; - return md; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_HOST)) { - /* translate host to :authority since :authority may be - omitted */ - grpc_mdelem authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(GRPC_MDVALUE(md))); - calld->seen_authority = 1; - return authority; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_PAYLOAD_BIN)) { - /* Retrieve the payload from the value of the 'grpc-internal-payload-bin' - header field */ - calld->seen_payload_bin = 1; + grpc_metadata_batch_remove(b, b->idx.named.te); + } else { + add_error(error_name, &error, + grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), + GRPC_ERROR_STR_KEY, "te")); + } + + if (b->idx.named.scheme != NULL) { + if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTP) && + !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTPS) && + !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_GRPC)) { + add_error(error_name, &error, + grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), + b->idx.named.te->md)); + } + grpc_metadata_batch_remove(b, b->idx.named.scheme); + } else { + add_error(error_name, &error, + grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), + GRPC_ERROR_STR_KEY, ":scheme")); + } + + if (b->idx.named.content_type != NULL) { + if (!grpc_mdelem_eq(b->idx.named.content_type->md, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { + if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), + EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) && + (GRPC_SLICE_START_PTR(GRPC_MDVALUE( + b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == + '+' || + GRPC_SLICE_START_PTR(GRPC_MDVALUE( + b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == + ';')) { + /* Although the C implementation doesn't (currently) generate them, + any custom +-suffix is explicitly valid. */ + /* TODO(klempner): We should consider preallocating common values such + as +proto or +json, or at least stashing them if we see them. */ + /* TODO(klempner): Should we be surfacing this to application code? */ + } else { + /* TODO(klempner): We're currently allowing this, but we shouldn't + see it without a proxy so log for now. */ + char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), + GPR_DUMP_ASCII); + gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); + gpr_free(val); + } + } + grpc_metadata_batch_remove(b, b->idx.named.content_type); + } + + if (b->idx.named.path == NULL) { + add_error(error_name, &error, + grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), + GRPC_ERROR_STR_KEY, ":path")); + } + + if (b->idx.named.host != NULL) { + add_error(error_name, &error, + grpc_metadata_batch_substitute( + b, b->idx.named.host, + grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_ref(GRPC_MDVALUE(b->idx.named.host->md))))); + } + + if (b->idx.named.authority == NULL) { + add_error(error_name, &error, + grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), + GRPC_ERROR_STR_KEY, ":authority")); + } + + if (b->idx.named.grpc_payload_bin != NULL) { + calld->seen_payload_bin = true; grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_slice_ref_internal(GRPC_MDVALUE(md))); + grpc_slice_ref_internal( + GRPC_MDVALUE(b->idx.named.grpc_payload_bin->md))); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); - return GRPC_MDNULL; - } else { - return md; + grpc_metadata_batch_remove(b, b->idx.named.grpc_payload_bin); } + + return error; } static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, @@ -203,49 +227,12 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (err == GRPC_ERROR_NONE) { - grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, - server_filter, elem); - /* Have we seen the required http2 transport headers? - (:method, :scheme, content-type, with :path and :authority covered - at the channel level right now) */ - if (calld->seen_method && calld->seen_scheme && calld->seen_te_trailers && - calld->seen_path && calld->seen_authority) { - /* do nothing */ - } else { - err = GRPC_ERROR_CREATE("Bad incoming HTTP headers"); - if (!calld->seen_path) { - err = grpc_error_add_child(err, - GRPC_ERROR_CREATE("Missing :path header")); - } - if (!calld->seen_authority) { - err = grpc_error_add_child( - err, GRPC_ERROR_CREATE("Missing :authority header")); - } - if (!calld->seen_method) { - err = grpc_error_add_child(err, - GRPC_ERROR_CREATE("Missing :method header")); - } - if (!calld->seen_scheme) { - err = grpc_error_add_child(err, - GRPC_ERROR_CREATE("Missing :scheme header")); - } - if (!calld->seen_te_trailers) { - err = grpc_error_add_child( - err, GRPC_ERROR_CREATE("Missing te: trailers header")); - } - /* Error this call out */ - if (grpc_http_trace) { - const char *error_str = grpc_error_string(err); - gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str); - grpc_error_free_string(error_str); - } - grpc_call_element_send_cancel(exec_ctx, elem); - } + err = server_filter_incoming_metadata(exec_ctx, elem, + calld->recv_initial_metadata); } else { GRPC_ERROR_REF(err); } - calld->on_done_recv->cb(exec_ctx, calld->on_done_recv->cb_arg, err); - GRPC_ERROR_UNREF(err); + grpc_closure_run(exec_ctx, calld->on_done_recv, err); } static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, @@ -283,13 +270,23 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; - if (op->send_initial_metadata != NULL && !calld->sent_status) { - calld->sent_status = 1; - grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->status, - GRPC_MDELEM_STATUS_200); - grpc_metadata_batch_add_tail( - op->send_initial_metadata, &calld->content_type, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); + if (op->send_initial_metadata != NULL) { + grpc_error *error = GRPC_ERROR_NONE; + static const char *error_name = "Failed sending initial metadata"; + add_error(error_name, &error, grpc_metadata_batch_add_head( + op->send_initial_metadata, &calld->status, + GRPC_MDELEM_STATUS_200)); + add_error(error_name, &error, + grpc_metadata_batch_add_tail( + op->send_initial_metadata, &calld->content_type, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); + add_error(error_name, &error, + server_filter_outgoing_metadata(exec_ctx, elem, + op->send_initial_metadata)); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + return; + } } if (op->recv_initial_metadata) { @@ -316,8 +313,12 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } if (op->send_trailing_metadata) { - grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata, - server_filter_outgoing_metadata, elem); + grpc_error *error = server_filter_outgoing_metadata( + exec_ctx, elem, op->send_trailing_metadata); + if (error != GRPC_ERROR_NONE) { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + return; + } } } diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index f6bb3a04779..82edcfd16c6 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -128,6 +128,10 @@ static const char *error_int_name(grpc_error_ints key) { static const char *error_str_name(grpc_error_strs key) { switch (key) { + case GRPC_ERROR_STR_KEY: + return "key"; + case GRPC_ERROR_STR_VALUE: + return "value"; case GRPC_ERROR_STR_DESCRIPTION: return "description"; case GRPC_ERROR_STR_OS_ERROR: diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index f3f3b80a092..a2ba84deed6 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -124,7 +124,11 @@ typedef enum { /// filename that we were trying to read/write when this error occurred GRPC_ERROR_STR_FILENAME, /// which data was queued for writing when the error occurred - GRPC_ERROR_STR_QUEUED_BUFFERS + GRPC_ERROR_STR_QUEUED_BUFFERS, + /// key associated with the error + GRPC_ERROR_STR_KEY, + /// value associated with the error + GRPC_ERROR_STR_VALUE, } grpc_error_strs; typedef enum { diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index 13c0277109a..43054bcfb4b 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -102,6 +102,8 @@ static void bubble_up_error(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_call_next_op(exec_ctx, elem, &calld->op); } +static void add_error(grpc_error **combined, grpc_error *error) { abort(); } + static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, size_t num_md, @@ -123,14 +125,20 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, GPR_ASSERT(num_md <= MAX_CREDENTIALS_METADATA_COUNT); GPR_ASSERT(op->send_initial_metadata != NULL); mdb = op->send_initial_metadata; + grpc_error *error = GRPC_ERROR_NONE; for (i = 0; i < num_md; i++) { - grpc_metadata_batch_add_tail( - mdb, &calld->md_links[i], - grpc_mdelem_from_slices(exec_ctx, - grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value))); + add_error(&error, + grpc_metadata_batch_add_tail( + mdb, &calld->md_links[i], + grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value)))); + } + if (error == GRPC_ERROR_NONE) { + grpc_call_next_op(exec_ctx, elem, op); + } else { + grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); } - grpc_call_next_op(exec_ctx, elem, op); } void build_auth_metadata_context(grpc_security_connector *sc, diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 1d14cfef530..ed9d92b74e6 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -83,6 +83,7 @@ static grpc_metadata_array metadata_batch_to_md_array( return result; } +#if 0 static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md) { grpc_call_element *elem = user_data; @@ -91,11 +92,12 @@ static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, for (i = 0; i < calld->num_consumed_md; i++) { const grpc_metadata *consumed_md = &calld->consumed_md[i]; if (grpc_slice_eq(GRPC_MDKEY(md), consumed_md->key) && - grpc_slice_eq(GRPC_MDKEY(md), consumed_md->value)) + grpc_slice_eq(GRPC_MDVALUE(md), consumed_md->value)) return GRPC_MDNULL; } return md; } +#endif static void destroy_op(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { gpr_free(arg); @@ -120,8 +122,12 @@ static void on_md_processing_done( if (status == GRPC_STATUS_OK) { calld->consumed_md = consumed_md; calld->num_consumed_md = num_consumed_md; +#if 0 grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, remove_consumed_md, elem); +#else + if (num_consumed_md) abort(); +#endif grpc_metadata_array_destroy(&calld->md); grpc_exec_ctx_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE, NULL); } else { diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index af53a5b246d..4e1ca22cb88 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -914,71 +914,73 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem md) { return algorithm; } -static grpc_mdelem recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_mdelem elem) { - if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_STATUS)) { +static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_metadata_batch *b) { + if (b->idx.named.grpc_status != NULL) { GPR_TIMER_BEGIN("status", 0); - set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); + set_status_code(call, STATUS_FROM_WIRE, + decode_status(b->idx.named.grpc_status->md)); + grpc_metadata_batch_remove(b, b->idx.named.grpc_status); GPR_TIMER_END("status", 0); - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_MESSAGE)) { + } + + if (b->idx.named.grpc_message != NULL) { GPR_TIMER_BEGIN("status-details", 0); - set_status_details(exec_ctx, call, STATUS_FROM_WIRE, - grpc_slice_ref_internal(GRPC_MDVALUE(elem))); + set_status_details( + exec_ctx, call, STATUS_FROM_WIRE, + grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); + grpc_metadata_batch_remove(b, b->idx.named.grpc_message); GPR_TIMER_END("status-details", 0); - return GRPC_MDNULL; } - return elem; } -static grpc_mdelem publish_app_metadata(grpc_call *call, grpc_mdelem elem, - int is_trailing) { +static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, + int is_trailing) { + GPR_TIMER_BEGIN("publish_app_metadata", 0); grpc_metadata_array *dest; grpc_metadata *mdusr; - GPR_TIMER_BEGIN("publish_app_metadata", 0); dest = call->buffered_metadata[is_trailing]; - if (dest->count == dest->capacity) { - dest->capacity = GPR_MAX(dest->capacity + 8, dest->capacity * 2); + if (dest->count + b->count > dest->capacity) { + dest->capacity = GPR_MAX(dest->capacity + b->count, dest->capacity * 3 / 2); dest->metadata = gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity); } - mdusr = &dest->metadata[dest->count++]; - mdusr->key = grpc_slice_ref(GRPC_MDKEY(elem)); - mdusr->value = grpc_slice_ref(GRPC_MDVALUE(elem)); + for (grpc_linked_mdelem *l = b->list.head; l != NULL; l = l->next) { + mdusr = &dest->metadata[dest->count++]; + mdusr->key = grpc_slice_ref(GRPC_MDKEY(l->md)); + mdusr->value = grpc_slice_ref(GRPC_MDVALUE(l->md)); + } GPR_TIMER_END("publish_app_metadata", 0); - return elem; } -static grpc_mdelem recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, - grpc_mdelem elem) { - grpc_call *call = args; - elem = recv_common_filter(exec_ctx, call, elem); - if (GRPC_MDISNULL(elem)) { - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ENCODING)) { +static void recv_initial_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_metadata_batch *b) { + recv_common_filter(exec_ctx, call, b); + + if (b->idx.named.grpc_encoding != NULL) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); - set_incoming_compression_algorithm(call, decode_compression(elem)); + set_incoming_compression_algorithm( + call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(elem), GRPC_MDSTR_GRPC_ACCEPT_ENCODING)) { + grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); + } + + if (b->idx.named.grpc_accept_encoding != NULL) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(exec_ctx, call, elem); + set_encodings_accepted_by_peer(exec_ctx, call, + b->idx.named.grpc_accept_encoding->md); + grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); - return GRPC_MDNULL; - } else { - return publish_app_metadata(call, elem, 0); } + + publish_app_metadata(call, b, false); } -static grpc_mdelem recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, - grpc_mdelem elem) { +static void recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_metadata_batch *b) { grpc_call *call = args; - elem = recv_common_filter(exec_ctx, call, elem); - if (GRPC_MDISNULL(elem)) { - return GRPC_MDNULL; - } else { - return publish_app_metadata(call, elem, 1); - } + recv_common_filter(exec_ctx, call, b); + publish_app_metadata(call, b, true); } grpc_call_stack *grpc_call_get_call_stack(grpc_call *call) { @@ -1223,8 +1225,9 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, if (error == GRPC_ERROR_NONE) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; - grpc_metadata_batch_filter(exec_ctx, md, recv_initial_filter, call); + recv_initial_filter(exec_ctx, call, md); + /* TODO(ctiller): this could be moved into recv_initial_filter now */ GPR_TIMER_BEGIN("validate_filtered_metadata", 0); validate_filtered_metadata(exec_ctx, bctl); GPR_TIMER_END("validate_filtered_metadata", 0); @@ -1289,7 +1292,7 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, if (bctl->recv_final_op) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - grpc_metadata_batch_filter(exec_ctx, md, recv_trailing_filter, call); + recv_trailing_filter(exec_ctx, call, md); call->received_final_op = true; /* propagate cancellation to any interested children */ diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 1c29873a658..8b30ce4f916 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -735,35 +735,25 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, } } -static grpc_mdelem server_filter(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { - grpc_call_element *elem = user_data; - call_data *calld = elem->call_data; - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { - if (!calld->path_set) { - calld->path = grpc_slice_ref(GRPC_MDVALUE(md)); - calld->path_set = true; - } - return GRPC_MDNULL; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { - if (!calld->host_set) { - calld->host = grpc_slice_ref(GRPC_MDVALUE(md)); - calld->host_set = true; - } - return GRPC_MDNULL; - } - return md; -} - static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, grpc_error *error) { grpc_call_element *elem = ptr; call_data *calld = elem->call_data; gpr_timespec op_deadline; + if (error == GRPC_ERROR_NONE) { + GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != NULL); + GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != NULL); + calld->path = grpc_slice_ref( + GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); + calld->host = grpc_slice_ref( + GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); + calld->path_set = true; + calld->host_set = true; + } else { + GRPC_ERROR_REF(error); + } GRPC_ERROR_REF(error); - grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, - server_filter, elem); op_deadline = calld->recv_initial_metadata->deadline; if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) { calld->deadline = op_deadline; diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 9e0a8fbbe1e..39e49283bfa 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -40,6 +40,7 @@ #include #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_string_helpers.h" static void assert_valid_list(grpc_mdelem_list *list) { #ifndef NDEBUG @@ -61,6 +62,20 @@ static void assert_valid_list(grpc_mdelem_list *list) { #endif /* NDEBUG */ } +static void assert_valid_callouts(grpc_metadata_batch *batch) { +#ifndef NDEBUG + for (grpc_linked_mdelem *l = batch->list.head; l != NULL; l = l->next) { + grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); + grpc_metadata_batch_callouts_index callout_idx = + grpc_batch_index_of(key_interned); + if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { + GPR_ASSERT(batch->idx.array[callout_idx] == l); + } + grpc_slice_unref(key_interned); + } +#endif +} + #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) { assert_valid_list(&batch->list); @@ -68,7 +83,7 @@ void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) { #endif /* NDEBUG */ void grpc_metadata_batch_init(grpc_metadata_batch *batch) { - batch->list.head = batch->list.tail = NULL; + memset(batch, 0, sizeof(*batch)); batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } @@ -80,12 +95,52 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, } } -void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) { +grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md) { + char *k = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); + char *v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + grpc_error *out = grpc_error_set_str( + grpc_error_set_str(src, GRPC_ERROR_STR_KEY, k), GRPC_ERROR_STR_VALUE, v); + gpr_free(k); + gpr_free(v); + return out; +} + +static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) + GRPC_MUST_USE_RESULT; + +static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { + grpc_metadata_batch_callouts_index idx = + grpc_batch_index_of(GRPC_MDKEY(storage->md)); + if (idx == GRPC_BATCH_CALLOUTS_COUNT) { + return GRPC_ERROR_NONE; + } + if (batch->idx.array[idx] != NULL) { + return grpc_attach_md_to_error( + GRPC_ERROR_CREATE("Unallowed duplicate metadata"), storage->md); + } + batch->idx.array[idx] = storage; + return GRPC_ERROR_NONE; +} + +static void maybe_unlink_callout(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { + grpc_metadata_batch_callouts_index idx = + grpc_batch_index_of(GRPC_MDKEY(storage->md)); + if (idx == GRPC_BATCH_CALLOUTS_COUNT) { + return; + } + GPR_ASSERT(batch->idx.array[idx] != NULL); + batch->idx.array[idx] = NULL; +} + +grpc_error *grpc_metadata_batch_add_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - grpc_metadata_batch_link_head(batch, storage); + return grpc_metadata_batch_link_head(batch, storage); } static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { @@ -102,17 +157,25 @@ static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); } -void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { +grpc_error *grpc_metadata_batch_link_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { + assert_valid_callouts(batch); + grpc_error *err = maybe_link_callout(batch, storage); + if (err != GRPC_ERROR_NONE) { + assert_valid_callouts(batch); + return err; + } link_head(&batch->list, storage); + assert_valid_callouts(batch); + return GRPC_ERROR_NONE; } -void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) { +grpc_error *grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - grpc_metadata_batch_link_tail(batch, storage); + return grpc_metadata_batch_link_tail(batch, storage); } static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { @@ -130,67 +193,47 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); } -void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { +grpc_error *grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { + assert_valid_callouts(batch); + grpc_error *err = maybe_link_callout(batch, storage); + if (err != GRPC_ERROR_NONE) { + assert_valid_callouts(batch); + return err; + } link_tail(&batch->list, storage); + assert_valid_callouts(batch); + return GRPC_ERROR_NONE; } -void grpc_metadata_batch_move(grpc_metadata_batch *dst, - grpc_metadata_batch *src) { - *dst = *src; - memset(src, 0, sizeof(grpc_metadata_batch)); -} - -void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_mdelem (*filter)(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem elem), - void *user_data) { - grpc_linked_mdelem *l; - grpc_linked_mdelem *next; - - GPR_TIMER_BEGIN("grpc_metadata_batch_filter", 0); - - assert_valid_list(&batch->list); - for (l = batch->list.head; l; l = next) { - grpc_mdelem orig = l->md; - grpc_mdelem filt = filter(exec_ctx, user_data, orig); - next = l->next; - if (GRPC_MDISNULL(filt)) { - if (l->prev) { - l->prev->next = l->next; - } - if (l->next) { - l->next->prev = l->prev; - } - if (batch->list.head == l) { - batch->list.head = l->next; - } - if (batch->list.tail == l) { - batch->list.tail = l->prev; - } - assert_valid_list(&batch->list); - GRPC_MDELEM_UNREF(exec_ctx, l->md); - } else if (!grpc_mdelem_eq(filt, orig)) { - GRPC_MDELEM_UNREF(exec_ctx, orig); - l->md = filt; - } +static void unlink_storage(grpc_mdelem_list *list, + grpc_linked_mdelem *storage) { + assert_valid_list(list); + if (storage->prev != NULL) { + storage->prev->next = storage->next; + } else { + list->head = storage->next; } - assert_valid_list(&batch->list); - - GPR_TIMER_END("grpc_metadata_batch_filter", 0); + if (storage->next != NULL) { + storage->next->prev = storage->prev; + } else { + list->tail = storage->prev; + } + assert_valid_list(list); } -static grpc_mdelem no_metadata_for_you(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem elem) { - return GRPC_MDNULL; +void grpc_metadata_batch_remove(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { + assert_valid_callouts(batch); + maybe_unlink_callout(batch, storage); + unlink_storage(&batch->list, storage); + assert_valid_callouts(batch); } void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch) { - batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); - grpc_metadata_batch_filter(exec_ctx, batch, no_metadata_for_you, NULL); + grpc_metadata_batch_destroy(exec_ctx, batch); + grpc_metadata_batch_init(batch); } bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch) { diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 2c82ed69837..1cc38140446 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -41,6 +41,7 @@ #include #include #include "src/core/lib/transport/metadata.h" +#include "src/core/lib/transport/static_metadata.h" #ifdef __cplusplus extern "C" { @@ -59,8 +60,11 @@ typedef struct grpc_mdelem_list { } grpc_mdelem_list; typedef struct grpc_metadata_batch { + /* number of elements in the batch */ + size_t count; /** Metadata elements in this batch */ grpc_mdelem_list list; + grpc_metadata_batch_callouts idx; /** Used to calculate grpc-timeout at the point of sending, or gpr_inf_future if this batch does not need to send a grpc-timeout */ @@ -77,25 +81,35 @@ bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch); /* Returns the transport size of the batch. */ size_t grpc_metadata_batch_size(grpc_metadata_batch *batch); -/** Moves the metadata information from \a src to \a dst. Upon return, \a src is - * zeroed. */ -void grpc_metadata_batch_move(grpc_metadata_batch *dst, - grpc_metadata_batch *src); +/** Remove \a storage from the batch, unreffing the mdelem contained */ +void grpc_metadata_batch_remove(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage); + +/** Substitute a new mdelem for an old value */ +grpc_error *grpc_metadata_batch_substitute(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem new_value); + +void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, + grpc_linked_mdelem *storage, + grpc_slice value); /** Add \a storage to the beginning of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage); +grpc_error *grpc_metadata_batch_link_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) + GRPC_MUST_USE_RESULT; /** Add \a storage to the end of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage); +grpc_error *grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) + GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the first element in \a batch, using \a storage as backing storage for the linked list element. @@ -103,29 +117,20 @@ void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, lifetime of batch. This usually means it should be around for the lifetime of the call. Takes ownership of \a elem_to_add */ -void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add); +grpc_error *grpc_metadata_batch_add_head( + grpc_metadata_batch *batch, grpc_linked_mdelem *storage, + grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. Takes ownership of \a elem_to_add */ -void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add); - -/** For each element in \a batch, execute \a filter. - The return value from \a filter will be substituted for the - grpc_mdelem passed to \a filter. If \a filter returns NULL, - the element will be moved to the garbage list. */ -void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_mdelem (*filter)(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem elem), - void *user_data); +grpc_error *grpc_metadata_batch_add_tail( + grpc_metadata_batch *batch, grpc_linked_mdelem *storage, + grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + +grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md); #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd); diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 55c5cd46190..5232bd7a98c 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -44,16 +44,44 @@ #include "src/core/lib/slice/slice_internal.h" static uint8_t g_bytes[] = { - 48, 49, 50, 50, 48, 48, 50, 48, 52, 50, 48, 54, 51, 48, 52, - 52, 48, 48, 52, 48, 52, 53, 48, 48, 97, 99, 99, 101, 112, 116, - 97, 99, 99, 101, 112, 116, 45, 99, 104, 97, 114, 115, 101, 116, 97, - 99, 99, 101, 112, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 97, - 99, 99, 101, 112, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, 97, - 99, 99, 101, 112, 116, 45, 114, 97, 110, 103, 101, 115, 97, 99, 99, - 101, 115, 115, 45, 99, 111, 110, 116, 114, 111, 108, 45, 97, 108, 108, - 111, 119, 45, 111, 114, 105, 103, 105, 110, 97, 103, 101, 97, 108, 108, - 111, 119, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 103, - 114, 112, 99, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 97, 117, + 58, 112, 97, 116, 104, 58, 109, 101, 116, 104, 111, 100, 58, 115, 116, + 97, 116, 117, 115, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 58, + 115, 99, 104, 101, 109, 101, 116, 101, 103, 114, 112, 99, 45, 109, 101, + 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 115, 116, 97, 116, 117, + 115, 103, 114, 112, 99, 45, 112, 97, 121, 108, 111, 97, 100, 45, 98, + 105, 110, 103, 114, 112, 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, + 103, 114, 112, 99, 45, 97, 99, 99, 101, 112, 116, 45, 101, 110, 99, + 111, 100, 105, 110, 103, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, + 112, 101, 103, 114, 112, 99, 45, 105, 110, 116, 101, 114, 110, 97, 108, + 45, 101, 110, 99, 111, 100, 105, 110, 103, 45, 114, 101, 113, 117, 101, + 115, 116, 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 104, 111, 115, + 116, 108, 98, 45, 116, 111, 107, 101, 110, 108, 98, 45, 99, 111, 115, + 116, 45, 98, 105, 110, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, + 117, 116, 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, + 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, 97, 116, 115, 45, 98, + 105, 110, 103, 114, 112, 99, 46, 119, 97, 105, 116, 95, 102, 111, 114, + 95, 114, 101, 97, 100, 121, 103, 114, 112, 99, 46, 116, 105, 109, 101, + 111, 117, 116, 103, 114, 112, 99, 46, 109, 97, 120, 95, 114, 101, 113, + 117, 101, 115, 116, 95, 109, 101, 115, 115, 97, 103, 101, 95, 98, 121, + 116, 101, 115, 103, 114, 112, 99, 46, 109, 97, 120, 95, 114, 101, 115, + 112, 111, 110, 115, 101, 95, 109, 101, 115, 115, 97, 103, 101, 95, 98, + 121, 116, 101, 115, 47, 103, 114, 112, 99, 46, 108, 98, 46, 118, 49, + 46, 76, 111, 97, 100, 66, 97, 108, 97, 110, 99, 101, 114, 47, 66, + 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 48, 49, 50, 105, 100, + 101, 110, 116, 105, 116, 121, 103, 122, 105, 112, 100, 101, 102, 108, 97, + 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, 97, 112, 112, 108, 105, + 99, 97, 116, 105, 111, 110, 47, 103, 114, 112, 99, 80, 79, 83, 84, + 50, 48, 48, 52, 48, 52, 104, 116, 116, 112, 104, 116, 116, 112, 115, + 103, 114, 112, 99, 71, 69, 84, 80, 85, 84, 47, 47, 105, 110, 100, + 101, 120, 46, 104, 116, 109, 108, 50, 48, 52, 50, 48, 54, 51, 48, + 52, 52, 48, 48, 53, 48, 48, 97, 99, 99, 101, 112, 116, 45, 99, + 104, 97, 114, 115, 101, 116, 97, 99, 99, 101, 112, 116, 45, 101, 110, + 99, 111, 100, 105, 110, 103, 103, 122, 105, 112, 44, 32, 100, 101, 102, + 108, 97, 116, 101, 97, 99, 99, 101, 112, 116, 45, 108, 97, 110, 103, + 117, 97, 103, 101, 97, 99, 99, 101, 112, 116, 45, 114, 97, 110, 103, + 101, 115, 97, 99, 99, 101, 112, 116, 97, 99, 99, 101, 115, 115, 45, + 99, 111, 110, 116, 114, 111, 108, 45, 97, 108, 108, 111, 119, 45, 111, + 114, 105, 103, 105, 110, 97, 103, 101, 97, 108, 108, 111, 119, 97, 117, 116, 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 99, 97, 99, 104, 101, 45, 99, 111, 110, 116, 114, 111, 108, 99, 111, 110, 116, 101, 110, 116, 45, 100, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 99, 111, @@ -62,57 +90,29 @@ static uint8_t g_bytes[] = { 99, 111, 110, 116, 101, 110, 116, 45, 108, 101, 110, 103, 116, 104, 99, 111, 110, 116, 101, 110, 116, 45, 108, 111, 99, 97, 116, 105, 111, 110, 99, 111, 110, 116, 101, 110, 116, 45, 114, 97, 110, 103, 101, 99, 111, - 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 99, 111, 111, 107, 105, - 101, 100, 97, 116, 101, 100, 101, 102, 108, 97, 116, 101, 100, 101, 102, - 108, 97, 116, 101, 44, 103, 122, 105, 112, 101, 116, 97, 103, 101, 120, - 112, 101, 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, - 71, 69, 84, 103, 114, 112, 99, 103, 114, 112, 99, 45, 97, 99, 99, - 101, 112, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, - 99, 46, 109, 97, 120, 95, 114, 101, 113, 117, 101, 115, 116, 95, 109, - 101, 115, 115, 97, 103, 101, 95, 98, 121, 116, 101, 115, 103, 114, 112, - 99, 46, 109, 97, 120, 95, 114, 101, 115, 112, 111, 110, 115, 101, 95, - 109, 101, 115, 115, 97, 103, 101, 95, 98, 121, 116, 101, 115, 103, 114, - 112, 99, 46, 116, 105, 109, 101, 111, 117, 116, 103, 114, 112, 99, 46, - 119, 97, 105, 116, 95, 102, 111, 114, 95, 114, 101, 97, 100, 121, 103, - 114, 112, 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, 103, 114, 112, - 99, 45, 105, 110, 116, 101, 114, 110, 97, 108, 45, 101, 110, 99, 111, - 100, 105, 110, 103, 45, 114, 101, 113, 117, 101, 115, 116, 103, 114, 112, - 99, 45, 109, 101, 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 112, - 97, 121, 108, 111, 97, 100, 45, 98, 105, 110, 103, 114, 112, 99, 45, - 115, 116, 97, 116, 115, 45, 98, 105, 110, 103, 114, 112, 99, 45, 115, - 116, 97, 116, 117, 115, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, - 117, 116, 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, - 98, 105, 110, 103, 122, 105, 112, 103, 122, 105, 112, 44, 32, 100, 101, - 102, 108, 97, 116, 101, 104, 111, 115, 116, 104, 116, 116, 112, 104, 116, - 116, 112, 115, 105, 100, 101, 110, 116, 105, 116, 121, 105, 100, 101, 110, - 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, - 110, 116, 105, 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 44, 103, - 122, 105, 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 103, 122, 105, - 112, 105, 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, - 105, 102, 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, - 111, 110, 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, - 103, 101, 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, - 45, 115, 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, - 102, 105, 101, 100, 108, 98, 45, 99, 111, 115, 116, 45, 98, 105, 110, - 108, 98, 45, 116, 111, 107, 101, 110, 108, 105, 110, 107, 108, 111, 99, - 97, 116, 105, 111, 110, 109, 97, 120, 45, 102, 111, 114, 119, 97, 114, - 100, 115, 58, 109, 101, 116, 104, 111, 100, 58, 112, 97, 116, 104, 80, - 79, 83, 84, 112, 114, 111, 120, 121, 45, 97, 117, 116, 104, 101, 110, - 116, 105, 99, 97, 116, 101, 112, 114, 111, 120, 121, 45, 97, 117, 116, - 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 80, 85, 84, 114, 97, - 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, 114, 101, 102, 114, 101, - 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, 116, 101, 114, 58, 115, - 99, 104, 101, 109, 101, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, - 99, 111, 111, 107, 105, 101, 47, 47, 103, 114, 112, 99, 46, 108, 98, - 46, 118, 49, 46, 76, 111, 97, 100, 66, 97, 108, 97, 110, 99, 101, - 114, 47, 66, 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 47, 105, - 110, 100, 101, 120, 46, 104, 116, 109, 108, 58, 115, 116, 97, 116, 117, - 115, 115, 116, 114, 105, 99, 116, 45, 116, 114, 97, 110, 115, 112, 111, - 114, 116, 45, 115, 101, 99, 117, 114, 105, 116, 121, 116, 101, 116, 114, - 97, 105, 108, 101, 114, 115, 116, 114, 97, 110, 115, 102, 101, 114, 45, - 101, 110, 99, 111, 100, 105, 110, 103, 117, 115, 101, 114, 45, 97, 103, - 101, 110, 116, 118, 97, 114, 121, 118, 105, 97, 119, 119, 119, 45, 97, - 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101}; + 111, 107, 105, 101, 100, 97, 116, 101, 101, 116, 97, 103, 101, 120, 112, + 101, 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, 105, + 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, 105, 102, + 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, 111, 110, + 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, 103, 101, + 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, + 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, 102, 105, + 101, 100, 108, 105, 110, 107, 108, 111, 99, 97, 116, 105, 111, 110, 109, + 97, 120, 45, 102, 111, 114, 119, 97, 114, 100, 115, 112, 114, 111, 120, + 121, 45, 97, 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101, 112, + 114, 111, 120, 121, 45, 97, 117, 116, 104, 111, 114, 105, 122, 97, 116, + 105, 111, 110, 114, 97, 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, + 114, 101, 102, 114, 101, 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, + 116, 101, 114, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, 99, 111, + 111, 107, 105, 101, 115, 116, 114, 105, 99, 116, 45, 116, 114, 97, 110, + 115, 112, 111, 114, 116, 45, 115, 101, 99, 117, 114, 105, 116, 121, 116, + 114, 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, 110, + 103, 118, 97, 114, 121, 118, 105, 97, 119, 119, 119, 45, 97, 117, 116, + 104, 101, 110, 116, 105, 99, 97, 116, 101, 105, 100, 101, 110, 116, 105, + 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, 110, 116, + 105, 116, 121, 44, 103, 122, 105, 112, 100, 101, 102, 108, 97, 116, 101, + 44, 103, 122, 105, 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 100, + 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, 112}; static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} @@ -124,55 +124,55 @@ typedef struct { const uint16_t length; } static_slice_refcount; static static_slice_refcount g_refcnts[GRPC_STATIC_MDSTR_COUNT] = { - {{&static_vtable}, 0, 1}, {{&static_vtable}, 1, 1}, - {{&static_vtable}, 2, 1}, {{&static_vtable}, 3, 3}, - {{&static_vtable}, 6, 3}, {{&static_vtable}, 9, 3}, - {{&static_vtable}, 12, 3}, {{&static_vtable}, 15, 3}, - {{&static_vtable}, 18, 3}, {{&static_vtable}, 21, 3}, - {{&static_vtable}, 24, 6}, {{&static_vtable}, 30, 14}, - {{&static_vtable}, 44, 15}, {{&static_vtable}, 59, 15}, - {{&static_vtable}, 74, 13}, {{&static_vtable}, 87, 27}, - {{&static_vtable}, 114, 3}, {{&static_vtable}, 117, 5}, - {{&static_vtable}, 122, 16}, {{&static_vtable}, 138, 10}, - {{&static_vtable}, 148, 13}, {{&static_vtable}, 161, 13}, - {{&static_vtable}, 174, 19}, {{&static_vtable}, 193, 16}, - {{&static_vtable}, 209, 16}, {{&static_vtable}, 225, 14}, - {{&static_vtable}, 239, 16}, {{&static_vtable}, 255, 13}, - {{&static_vtable}, 268, 12}, {{&static_vtable}, 280, 6}, - {{&static_vtable}, 286, 4}, {{&static_vtable}, 290, 7}, - {{&static_vtable}, 297, 12}, {{&static_vtable}, 309, 0}, - {{&static_vtable}, 309, 4}, {{&static_vtable}, 313, 6}, - {{&static_vtable}, 319, 7}, {{&static_vtable}, 326, 4}, - {{&static_vtable}, 330, 3}, {{&static_vtable}, 333, 4}, - {{&static_vtable}, 337, 20}, {{&static_vtable}, 357, 30}, - {{&static_vtable}, 387, 31}, {{&static_vtable}, 418, 12}, - {{&static_vtable}, 430, 19}, {{&static_vtable}, 449, 13}, - {{&static_vtable}, 462, 30}, {{&static_vtable}, 492, 12}, - {{&static_vtable}, 504, 16}, {{&static_vtable}, 520, 14}, - {{&static_vtable}, 534, 11}, {{&static_vtable}, 545, 12}, - {{&static_vtable}, 557, 16}, {{&static_vtable}, 573, 4}, - {{&static_vtable}, 577, 13}, {{&static_vtable}, 590, 4}, - {{&static_vtable}, 594, 4}, {{&static_vtable}, 598, 5}, - {{&static_vtable}, 603, 8}, {{&static_vtable}, 611, 16}, - {{&static_vtable}, 627, 21}, {{&static_vtable}, 648, 13}, - {{&static_vtable}, 661, 8}, {{&static_vtable}, 669, 17}, - {{&static_vtable}, 686, 13}, {{&static_vtable}, 699, 8}, - {{&static_vtable}, 707, 19}, {{&static_vtable}, 726, 13}, - {{&static_vtable}, 739, 11}, {{&static_vtable}, 750, 8}, - {{&static_vtable}, 758, 4}, {{&static_vtable}, 762, 8}, - {{&static_vtable}, 770, 12}, {{&static_vtable}, 782, 7}, - {{&static_vtable}, 789, 5}, {{&static_vtable}, 794, 4}, - {{&static_vtable}, 798, 18}, {{&static_vtable}, 816, 19}, - {{&static_vtable}, 835, 3}, {{&static_vtable}, 838, 5}, - {{&static_vtable}, 843, 7}, {{&static_vtable}, 850, 7}, - {{&static_vtable}, 857, 11}, {{&static_vtable}, 868, 7}, - {{&static_vtable}, 875, 6}, {{&static_vtable}, 881, 10}, - {{&static_vtable}, 891, 1}, {{&static_vtable}, 892, 36}, - {{&static_vtable}, 928, 11}, {{&static_vtable}, 939, 7}, - {{&static_vtable}, 946, 25}, {{&static_vtable}, 971, 2}, - {{&static_vtable}, 973, 8}, {{&static_vtable}, 981, 17}, - {{&static_vtable}, 998, 10}, {{&static_vtable}, 1008, 4}, - {{&static_vtable}, 1012, 3}, {{&static_vtable}, 1015, 16}, + {{&static_vtable}, 0, 5}, {{&static_vtable}, 5, 7}, + {{&static_vtable}, 12, 7}, {{&static_vtable}, 19, 10}, + {{&static_vtable}, 29, 7}, {{&static_vtable}, 36, 2}, + {{&static_vtable}, 38, 12}, {{&static_vtable}, 50, 11}, + {{&static_vtable}, 61, 16}, {{&static_vtable}, 77, 13}, + {{&static_vtable}, 90, 20}, {{&static_vtable}, 110, 12}, + {{&static_vtable}, 122, 30}, {{&static_vtable}, 152, 10}, + {{&static_vtable}, 162, 4}, {{&static_vtable}, 166, 8}, + {{&static_vtable}, 174, 11}, {{&static_vtable}, 185, 12}, + {{&static_vtable}, 197, 16}, {{&static_vtable}, 213, 14}, + {{&static_vtable}, 227, 0}, {{&static_vtable}, 227, 19}, + {{&static_vtable}, 246, 12}, {{&static_vtable}, 258, 30}, + {{&static_vtable}, 288, 31}, {{&static_vtable}, 319, 36}, + {{&static_vtable}, 355, 1}, {{&static_vtable}, 356, 1}, + {{&static_vtable}, 357, 1}, {{&static_vtable}, 358, 8}, + {{&static_vtable}, 366, 4}, {{&static_vtable}, 370, 7}, + {{&static_vtable}, 377, 8}, {{&static_vtable}, 385, 16}, + {{&static_vtable}, 401, 4}, {{&static_vtable}, 405, 3}, + {{&static_vtable}, 408, 3}, {{&static_vtable}, 411, 4}, + {{&static_vtable}, 415, 5}, {{&static_vtable}, 420, 4}, + {{&static_vtable}, 424, 3}, {{&static_vtable}, 427, 3}, + {{&static_vtable}, 430, 1}, {{&static_vtable}, 431, 11}, + {{&static_vtable}, 442, 3}, {{&static_vtable}, 445, 3}, + {{&static_vtable}, 448, 3}, {{&static_vtable}, 451, 3}, + {{&static_vtable}, 454, 3}, {{&static_vtable}, 457, 14}, + {{&static_vtable}, 471, 15}, {{&static_vtable}, 486, 13}, + {{&static_vtable}, 499, 15}, {{&static_vtable}, 514, 13}, + {{&static_vtable}, 527, 6}, {{&static_vtable}, 533, 27}, + {{&static_vtable}, 560, 3}, {{&static_vtable}, 563, 5}, + {{&static_vtable}, 568, 13}, {{&static_vtable}, 581, 13}, + {{&static_vtable}, 594, 19}, {{&static_vtable}, 613, 16}, + {{&static_vtable}, 629, 16}, {{&static_vtable}, 645, 14}, + {{&static_vtable}, 659, 16}, {{&static_vtable}, 675, 13}, + {{&static_vtable}, 688, 6}, {{&static_vtable}, 694, 4}, + {{&static_vtable}, 698, 4}, {{&static_vtable}, 702, 6}, + {{&static_vtable}, 708, 7}, {{&static_vtable}, 715, 4}, + {{&static_vtable}, 719, 8}, {{&static_vtable}, 727, 17}, + {{&static_vtable}, 744, 13}, {{&static_vtable}, 757, 8}, + {{&static_vtable}, 765, 19}, {{&static_vtable}, 784, 13}, + {{&static_vtable}, 797, 4}, {{&static_vtable}, 801, 8}, + {{&static_vtable}, 809, 12}, {{&static_vtable}, 821, 18}, + {{&static_vtable}, 839, 19}, {{&static_vtable}, 858, 5}, + {{&static_vtable}, 863, 7}, {{&static_vtable}, 870, 7}, + {{&static_vtable}, 877, 11}, {{&static_vtable}, 888, 6}, + {{&static_vtable}, 894, 10}, {{&static_vtable}, 904, 25}, + {{&static_vtable}, 929, 17}, {{&static_vtable}, 946, 4}, + {{&static_vtable}, 950, 3}, {{&static_vtable}, 953, 16}, + {{&static_vtable}, 969, 16}, {{&static_vtable}, 985, 13}, + {{&static_vtable}, 998, 12}, {{&static_vtable}, 1010, 21}, }; bool grpc_is_static_metadata_string(grpc_slice slice) { @@ -180,104 +180,104 @@ bool grpc_is_static_metadata_string(grpc_slice slice) { } const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { - {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 1}}, - {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 1, 1}}, - {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 2, 1}}, - {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 3, 3}}, - {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 6, 3}}, - {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 9, 3}}, - {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 12, 3}}, - {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 15, 3}}, - {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 18, 3}}, - {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 21, 3}}, - {.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 24, 6}}, - {.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 30, 14}}, - {.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, - {.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 59, 15}}, - {.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 74, 13}}, - {.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 87, 27}}, - {.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 114, 3}}, - {.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 117, 5}}, - {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 122, 16}}, - {.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 138, 10}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 148, 13}}, - {.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 161, 13}}, - {.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 174, 19}}, - {.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 193, 16}}, - {.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 209, 16}}, - {.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 225, 14}}, - {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 239, 16}}, - {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 255, 13}}, - {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, - {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 280, 6}}, - {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 286, 4}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}, - {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 297, 12}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}, - {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 309, 4}}, - {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 313, 6}}, - {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 319, 7}}, - {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 326, 4}}, - {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 330, 3}}, - {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 333, 4}}, - {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 357, 30}}, - {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 387, 31}}, - {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 418, 12}}, - {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 430, 19}}, - {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, - {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 462, 30}}, - {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 492, 12}}, - {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 504, 16}}, - {.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 520, 14}}, - {.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, - {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 545, 12}}, - {.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 557, 16}}, - {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}, - {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 577, 13}}, - {.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 590, 4}}, - {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 594, 4}}, - {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 598, 5}}, - {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}, - {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 611, 16}}, - {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 627, 21}}, - {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 648, 13}}, - {.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 661, 8}}, - {.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 669, 17}}, - {.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 686, 13}}, - {.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 699, 8}}, - {.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 707, 19}}, - {.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 726, 13}}, - {.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 739, 11}}, - {.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 750, 8}}, - {.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 758, 4}}, - {.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 762, 8}}, - {.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 770, 12}}, - {.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, - {.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, - {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 794, 4}}, - {.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 798, 18}}, - {.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 816, 19}}, - {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 835, 3}}, - {.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 838, 5}}, - {.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 843, 7}}, - {.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 850, 7}}, - {.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 857, 11}}, - {.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, - {.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 875, 6}}, - {.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 881, 10}}, - {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 891, 1}}, - {.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 892, 36}}, - {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 928, 11}}, - {.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 946, 25}}, - {.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 971, 2}}, - {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 973, 8}}, - {.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 981, 17}}, - {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 998, 10}}, - {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 1008, 4}}, - {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 1012, 3}}, - {.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1015, 16}}, + {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 19, 10}}, + {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 36, 2}}, + {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 38, 12}}, + {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 61, 16}}, + {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 122, 30}}, + {.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 152, 10}}, + {.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 162, 4}}, + {.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 166, 8}}, + {.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 174, 11}}, + {.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 185, 12}}, + {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 197, 16}}, + {.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 213, 14}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}, + {.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 227, 19}}, + {.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 246, 12}}, + {.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 258, 30}}, + {.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 288, 31}}, + {.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 319, 36}}, + {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 355, 1}}, + {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 356, 1}}, + {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 357, 1}}, + {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}, + {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}, + {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 377, 8}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 385, 16}}, + {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 401, 4}}, + {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 405, 3}}, + {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 408, 3}}, + {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 411, 4}}, + {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 415, 5}}, + {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 420, 4}}, + {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 424, 3}}, + {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 427, 3}}, + {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 430, 1}}, + {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 431, 11}}, + {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 442, 3}}, + {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 445, 3}}, + {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 448, 3}}, + {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 451, 3}}, + {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 454, 3}}, + {.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 457, 14}}, + {.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 486, 13}}, + {.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 499, 15}}, + {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 514, 13}}, + {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 527, 6}}, + {.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 533, 27}}, + {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 560, 3}}, + {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 563, 5}}, + {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 568, 13}}, + {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 581, 13}}, + {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 594, 19}}, + {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 613, 16}}, + {.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 629, 16}}, + {.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 645, 14}}, + {.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 659, 16}}, + {.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 675, 13}}, + {.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 688, 6}}, + {.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 694, 4}}, + {.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 698, 4}}, + {.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 702, 6}}, + {.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 708, 7}}, + {.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 715, 4}}, + {.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 719, 8}}, + {.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 727, 17}}, + {.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 744, 13}}, + {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 757, 8}}, + {.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 765, 19}}, + {.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 784, 13}}, + {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 797, 4}}, + {.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 801, 8}}, + {.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 809, 12}}, + {.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 821, 18}}, + {.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 839, 19}}, + {.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 858, 5}}, + {.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 863, 7}}, + {.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 870, 7}}, + {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 877, 11}}, + {.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 888, 6}}, + {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 894, 10}}, + {.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 904, 25}}, + {.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 929, 17}}, + {.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 946, 4}}, + {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 950, 3}}, + {.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 953, 16}}, + {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 969, 16}}, + {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 985, 13}}, + {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 998, 12}}, + {.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1010, 21}}, }; int grpc_static_metadata_index(grpc_slice slice) { @@ -290,9 +290,9 @@ int grpc_static_metadata_index(grpc_slice slice) { uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 4, 8, 6, 2, 4, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 6, 6, 8, 8}; #define ELEMS_PHASHLEN 0x40 #define ELEMS_PHASHNKEYS 81 @@ -300,14 +300,14 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { #define ELEMS_PHASHSALT 0x9e3779b9 static const uint8_t elems_tab[] = { - 0, 17, 61, 28, 4, 12, 47, 0, 0, 0, 61, 0, 47, 0, 61, 76, - 61, 70, 76, 0, 0, 10, 4, 60, 0, 0, 0, 16, 88, 47, 1, 76, - 76, 0, 76, 0, 61, 0, 23, 0, 0, 51, 1, 92, 32, 0, 25, 0, - 34, 0, 37, 0, 76, 76, 32, 38, 70, 79, 81, 0, 64, 0, 0, 0, + 20, 1, 0, 61, 61, 34, 10, 16, 0, 0, 0, 0, 34, 61, 0, 1, + 0, 0, 0, 61, 0, 88, 0, 4, 0, 47, 0, 47, 12, 7, 0, 16, + 51, 87, 76, 4, 79, 10, 70, 47, 76, 61, 71, 88, 0, 88, 0, 47, + 0, 16, 0, 83, 0, 57, 0, 75, 0, 42, 0, 90, 0, 42, 70, 0, }; static uint32_t elems_phash(uint32_t val) { - val -= 917; + val += (uint32_t)-11; uint32_t a, b, rsl; @@ -318,23 +318,23 @@ static uint32_t elems_phash(uint32_t val) { } static const uint16_t elem_keys[] = { - 2091, 1405, 8728, 2777, 7192, 2287, 2581, 2483, 2973, 4441, 3561, 3951, - 6403, 4463, 9441, 8726, 2875, 5423, 8730, 7338, 6109, 6207, 6697, 6893, - 7229, 8363, 8729, 3952, 8173, 8191, 8725, 8853, 9245, 9343, 1601, 8727, - 7481, 7340, 7971, 7775, 6501, 3973, 3659, 3979, 3463, 3980, 1307, 8190, - 9010, 8731, 4901, 6599, 3365, 7579, 6795, 9147, 9539, 8069, 6305, 7873, - 1209, 1111, 1699, 1503, 7089, 4468, 2189, 4900, 7232, 2385, 6991, 3978, - 1993, 4902, 2679, 2762, 1013, 3981, 1230, 1895, 8265, 0, 0, 0, + 138, 522, 714, 5116, 1098, 430, 5802, 232, 8840, 913, 240, 8644, + 231, 8742, 7762, 1392, 42, 5410, 4822, 5998, 139, 1490, 5900, 7664, + 6292, 8448, 6684, 7272, 7370, 8350, 8154, 7958, 7566, 912, 9036, 7860, + 6488, 8546, 1111, 9134, 712, 5214, 132, 1074, 1010, 5312, 314, 242, + 8252, 4951, 8938, 43, 7076, 6096, 6586, 6194, 1294, 1076, 5606, 1588, + 5704, 244, 911, 5508, 6390, 7174, 6880, 1077, 713, 1009, 241, 8056, + 1075, 6782, 7468, 4920, 243, 429, 431, 1011, 6978, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; static const uint8_t elem_idxs[] = { - 11, 5, 70, 19, 51, 13, 16, 15, 21, 33, 24, 26, 43, 34, 79, 68, 20, - 39, 72, 54, 40, 41, 46, 48, 52, 66, 71, 27, 62, 64, 67, 74, 77, 78, - 7, 69, 56, 55, 60, 58, 44, 28, 25, 30, 23, 31, 4, 63, 75, 73, 37, - 45, 22, 57, 47, 76, 80, 61, 42, 59, 2, 0, 8, 6, 50, 35, 12, 36, - 53, 14, 49, 29, 10, 38, 17, 18, 1, 32, 3, 9, 65}; + 15, 6, 2, 27, 41, 12, 34, 10, 69, 5, 19, 67, 9, 68, 58, 48, 17, + 30, 24, 36, 16, 55, 35, 57, 39, 65, 44, 51, 52, 64, 62, 60, 54, 4, + 72, 59, 42, 66, 7, 73, 0, 28, 8, 76, 77, 29, 14, 21, 63, 26, 71, + 18, 49, 37, 43, 38, 70, 79, 32, 56, 33, 23, 3, 31, 40, 50, 46, 80, + 1, 74, 20, 61, 78, 45, 53, 25, 22, 11, 13, 75, 47}; grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return GRPC_MDNULL; @@ -347,168 +347,203 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { } grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { - {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 30, 14}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 24, 6}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 44, 15}}, - {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 577, 13}}}, - {{.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 59, 15}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 74, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 87, 27}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 114, 3}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 117, 5}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 138, 10}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 148, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 161, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 174, 19}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 193, 16}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 209, 16}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 225, 14}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 239, 16}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 255, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, - {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 122, 16}}}, - {{.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 268, 12}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 280, 6}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 286, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 309, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 313, 6}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 319, 7}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 326, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 297, 12}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 611, 16}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 627, 21}}}, - {{.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 337, 20}}, - {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 648, 13}}}, - {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 290, 7}}}, - {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, - {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 573, 4}}}, - {{.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 449, 13}}, - {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 603, 8}}}, - {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, - {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 1}}}, - {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, - {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 1, 1}}}, - {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 534, 11}}, - {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 2, 1}}}, - {{.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 590, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 661, 8}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 669, 17}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 686, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 699, 8}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 707, 19}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 726, 13}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 739, 11}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 750, 8}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 758, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 762, 8}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 770, 12}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, - {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 330, 3}}}, - {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, - {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 794, 4}}}, - {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 782, 7}}, - {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 835, 3}}}, - {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, - {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 891, 1}}}, - {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 789, 5}}, - {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 928, 11}}}, - {{.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 798, 18}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 816, 19}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 838, 5}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 843, 7}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 850, 7}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 857, 11}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, - {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 333, 4}}}, - {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, - {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 594, 4}}}, - {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 868, 7}}, - {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 598, 5}}}, - {{.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 875, 6}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 881, 10}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 3, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 6, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 9, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 12, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 15, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 18, 3}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 939, 7}}, - {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 21, 3}}}, - {{.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 946, 25}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 971, 2}}, - {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 973, 8}}}, - {{.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 981, 17}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 998, 10}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 1008, 4}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 1012, 3}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, - {{.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1015, 16}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 309, 0}}}, + {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 355, 1}}}, + {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 356, 1}}}, + {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 357, 1}}}, + {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}}, + {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}}, + {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}}, + {{.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 36, 2}}, + {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 377, 8}}}, + {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 385, 16}}}, + {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 401, 4}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 405, 3}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 408, 3}}}, + {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 411, 4}}}, + {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 415, 5}}}, + {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 420, 4}}}, + {{.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 19, 10}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 424, 3}}}, + {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 427, 3}}}, + {{.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 430, 1}}}, + {{.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 431, 11}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 442, 3}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 445, 3}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 448, 3}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 451, 3}}}, + {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 454, 3}}}, + {{.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 457, 14}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 486, 13}}}, + {{.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 499, 15}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 514, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 527, 6}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 533, 27}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 560, 3}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 563, 5}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 568, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 581, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 594, 19}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 613, 16}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 629, 16}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 645, 14}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 659, 16}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 675, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 688, 6}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 694, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 698, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 702, 6}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 708, 7}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 715, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 162, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 719, 8}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 727, 17}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 744, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 757, 8}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 765, 19}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 784, 13}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 166, 8}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 174, 11}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 797, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 801, 8}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 809, 12}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 821, 18}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 839, 19}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 858, 5}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 863, 7}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 870, 7}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 877, 11}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 888, 6}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 894, 10}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 904, 25}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 929, 17}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 152, 10}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 946, 4}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 950, 3}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 953, 16}}, + {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 969, 16}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 985, 13}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 998, 12}}}, + {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &g_refcnts[97].base, + .data.refcounted = {g_bytes + 1010, 21}}}, +}; +#define BATCH_PHASHLEN 0x10 +#define BATCH_PHASHNKEYS 17 +#define BATCH_PHASHRANGE 32 +#define BATCH_PHASHSALT 0x9e3779b9 + +static const uint8_t batch_tab[] = { + 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 15, 0, 13, 0, 23, }; -const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, - 28, 32, 27, 31}; + +static uint32_t batch_phash(uint32_t val) { + val += (uint32_t)0; + + uint32_t a, b, rsl; + + b = (val & 0xf); + a = ((val << 27) >> 28); + rsl = (a ^ batch_tab[b]); + return rsl; +} + +static const uint8_t batch_hash_to_idx[] = { + 0, 2, 4, 6, 8, 10, 12, 14, 16, 9, 11, 13, 3, 1, 7, 5, + 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + +grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) { + if (!grpc_is_static_metadata_string(slice)) return GRPC_BATCH_CALLOUTS_COUNT; + uint32_t idx = (uint32_t)grpc_static_metadata_index(slice); + uint32_t hash = batch_phash(idx); + if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && + batch_hash_to_idx[hash] == idx) + return (grpc_metadata_batch_callouts_index)hash; + return GRPC_BATCH_CALLOUTS_COUNT; +} + +const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 74, 75, 76, + 77, 78, 79, 80}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 3d3911de16b..82af8926331 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -46,206 +46,206 @@ #define GRPC_STATIC_MDSTR_COUNT 98 extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; +/* ":path" */ +#define GRPC_MDSTR_PATH (grpc_static_slice_table[0]) +/* ":method" */ +#define GRPC_MDSTR_METHOD (grpc_static_slice_table[1]) +/* ":status" */ +#define GRPC_MDSTR_STATUS (grpc_static_slice_table[2]) +/* ":authority" */ +#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table[3]) +/* ":scheme" */ +#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[4]) +/* "te" */ +#define GRPC_MDSTR_TE (grpc_static_slice_table[5]) +/* "grpc-message" */ +#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[6]) +/* "grpc-status" */ +#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[7]) +/* "grpc-payload-bin" */ +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[8]) +/* "grpc-encoding" */ +#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[9]) +/* "grpc-accept-encoding" */ +#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[10]) +/* "content-type" */ +#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table[11]) +/* "grpc-internal-encoding-request" */ +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[12]) +/* "user-agent" */ +#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[13]) +/* "host" */ +#define GRPC_MDSTR_HOST (grpc_static_slice_table[14]) +/* "lb-token" */ +#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[15]) +/* "lb-cost-bin" */ +#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[16]) +/* "grpc-timeout" */ +#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[17]) +/* "grpc-tracing-bin" */ +#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[18]) +/* "grpc-stats-bin" */ +#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[19]) +/* "" */ +#define GRPC_MDSTR_EMPTY (grpc_static_slice_table[20]) +/* "grpc.wait_for_ready" */ +#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table[21]) +/* "grpc.timeout" */ +#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table[22]) +/* "grpc.max_request_message_bytes" */ +#define GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES \ + (grpc_static_slice_table[23]) +/* "grpc.max_response_message_bytes" */ +#define GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES \ + (grpc_static_slice_table[24]) +/* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ +#define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ + (grpc_static_slice_table[25]) /* "0" */ -#define GRPC_MDSTR_0 (grpc_static_slice_table[0]) +#define GRPC_MDSTR_0 (grpc_static_slice_table[26]) /* "1" */ -#define GRPC_MDSTR_1 (grpc_static_slice_table[1]) +#define GRPC_MDSTR_1 (grpc_static_slice_table[27]) /* "2" */ -#define GRPC_MDSTR_2 (grpc_static_slice_table[2]) +#define GRPC_MDSTR_2 (grpc_static_slice_table[28]) +/* "identity" */ +#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[29]) +/* "gzip" */ +#define GRPC_MDSTR_GZIP (grpc_static_slice_table[30]) +/* "deflate" */ +#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[31]) +/* "trailers" */ +#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[32]) +/* "application/grpc" */ +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[33]) +/* "POST" */ +#define GRPC_MDSTR_POST (grpc_static_slice_table[34]) /* "200" */ -#define GRPC_MDSTR_200 (grpc_static_slice_table[3]) +#define GRPC_MDSTR_200 (grpc_static_slice_table[35]) +/* "404" */ +#define GRPC_MDSTR_404 (grpc_static_slice_table[36]) +/* "http" */ +#define GRPC_MDSTR_HTTP (grpc_static_slice_table[37]) +/* "https" */ +#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[38]) +/* "grpc" */ +#define GRPC_MDSTR_GRPC (grpc_static_slice_table[39]) +/* "GET" */ +#define GRPC_MDSTR_GET (grpc_static_slice_table[40]) +/* "PUT" */ +#define GRPC_MDSTR_PUT (grpc_static_slice_table[41]) +/* "/" */ +#define GRPC_MDSTR_SLASH (grpc_static_slice_table[42]) +/* "/index.html" */ +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[43]) /* "204" */ -#define GRPC_MDSTR_204 (grpc_static_slice_table[4]) +#define GRPC_MDSTR_204 (grpc_static_slice_table[44]) /* "206" */ -#define GRPC_MDSTR_206 (grpc_static_slice_table[5]) +#define GRPC_MDSTR_206 (grpc_static_slice_table[45]) /* "304" */ -#define GRPC_MDSTR_304 (grpc_static_slice_table[6]) +#define GRPC_MDSTR_304 (grpc_static_slice_table[46]) /* "400" */ -#define GRPC_MDSTR_400 (grpc_static_slice_table[7]) -/* "404" */ -#define GRPC_MDSTR_404 (grpc_static_slice_table[8]) +#define GRPC_MDSTR_400 (grpc_static_slice_table[47]) /* "500" */ -#define GRPC_MDSTR_500 (grpc_static_slice_table[9]) -/* "accept" */ -#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[10]) +#define GRPC_MDSTR_500 (grpc_static_slice_table[48]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[11]) +#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[49]) /* "accept-encoding" */ -#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table[12]) +#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table[50]) +/* "gzip, deflate" */ +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[51]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[13]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[52]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[14]) +#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[53]) +/* "accept" */ +#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[54]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[15]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[55]) /* "age" */ -#define GRPC_MDSTR_AGE (grpc_static_slice_table[16]) +#define GRPC_MDSTR_AGE (grpc_static_slice_table[56]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[17]) -/* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[18]) -/* ":authority" */ -#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table[19]) +#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[57]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[20]) +#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[58]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[21]) +#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[59]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[22]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[60]) /* "content-encoding" */ -#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table[23]) +#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table[61]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[24]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[62]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[25]) +#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[63]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[26]) +#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[64]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[27]) -/* "content-type" */ -#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table[28]) +#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[65]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[29]) +#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[66]) /* "date" */ -#define GRPC_MDSTR_DATE (grpc_static_slice_table[30]) -/* "deflate" */ -#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[31]) -/* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[32]) -/* "" */ -#define GRPC_MDSTR_EMPTY (grpc_static_slice_table[33]) +#define GRPC_MDSTR_DATE (grpc_static_slice_table[67]) /* "etag" */ -#define GRPC_MDSTR_ETAG (grpc_static_slice_table[34]) +#define GRPC_MDSTR_ETAG (grpc_static_slice_table[68]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[35]) +#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[69]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[36]) +#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[70]) /* "from" */ -#define GRPC_MDSTR_FROM (grpc_static_slice_table[37]) -/* "GET" */ -#define GRPC_MDSTR_GET (grpc_static_slice_table[38]) -/* "grpc" */ -#define GRPC_MDSTR_GRPC (grpc_static_slice_table[39]) -/* "grpc-accept-encoding" */ -#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[40]) -/* "grpc.max_request_message_bytes" */ -#define GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES \ - (grpc_static_slice_table[41]) -/* "grpc.max_response_message_bytes" */ -#define GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES \ - (grpc_static_slice_table[42]) -/* "grpc.timeout" */ -#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table[43]) -/* "grpc.wait_for_ready" */ -#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table[44]) -/* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[45]) -/* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[46]) -/* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[47]) -/* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[48]) -/* "grpc-stats-bin" */ -#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[49]) -/* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[50]) -/* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[51]) -/* "grpc-tracing-bin" */ -#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[52]) -/* "gzip" */ -#define GRPC_MDSTR_GZIP (grpc_static_slice_table[53]) -/* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[54]) -/* "host" */ -#define GRPC_MDSTR_HOST (grpc_static_slice_table[55]) -/* "http" */ -#define GRPC_MDSTR_HTTP (grpc_static_slice_table[56]) -/* "https" */ -#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[57]) -/* "identity" */ -#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[58]) -/* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[59]) -/* "identity,deflate,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_slice_table[60]) -/* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[61]) +#define GRPC_MDSTR_FROM (grpc_static_slice_table[71]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[62]) +#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[72]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[63]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[73]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[64]) +#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[74]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[65]) +#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[75]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[66]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[76]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[67]) -/* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[68]) -/* "lb-token" */ -#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[69]) +#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[77]) /* "link" */ -#define GRPC_MDSTR_LINK (grpc_static_slice_table[70]) +#define GRPC_MDSTR_LINK (grpc_static_slice_table[78]) /* "location" */ -#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[71]) +#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[79]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[72]) -/* ":method" */ -#define GRPC_MDSTR_METHOD (grpc_static_slice_table[73]) -/* ":path" */ -#define GRPC_MDSTR_PATH (grpc_static_slice_table[74]) -/* "POST" */ -#define GRPC_MDSTR_POST (grpc_static_slice_table[75]) +#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[80]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[76]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[81]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[77]) -/* "PUT" */ -#define GRPC_MDSTR_PUT (grpc_static_slice_table[78]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[82]) /* "range" */ -#define GRPC_MDSTR_RANGE (grpc_static_slice_table[79]) +#define GRPC_MDSTR_RANGE (grpc_static_slice_table[83]) /* "referer" */ -#define GRPC_MDSTR_REFERER (grpc_static_slice_table[80]) +#define GRPC_MDSTR_REFERER (grpc_static_slice_table[84]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[81]) +#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[85]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[82]) -/* ":scheme" */ -#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[83]) +#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[86]) /* "server" */ -#define GRPC_MDSTR_SERVER (grpc_static_slice_table[84]) +#define GRPC_MDSTR_SERVER (grpc_static_slice_table[87]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[85]) -/* "/" */ -#define GRPC_MDSTR_SLASH (grpc_static_slice_table[86]) -/* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ -#define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ - (grpc_static_slice_table[87]) -/* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[88]) -/* ":status" */ -#define GRPC_MDSTR_STATUS (grpc_static_slice_table[89]) +#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[88]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[90]) -/* "te" */ -#define GRPC_MDSTR_TE (grpc_static_slice_table[91]) -/* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[92]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[89]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[93]) -/* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[94]) +#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[90]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[95]) +#define GRPC_MDSTR_VARY (grpc_static_slice_table[91]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[96]) +#define GRPC_MDSTR_VIA (grpc_static_slice_table[92]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[97]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[93]) +/* "identity,deflate" */ +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[94]) +/* "identity,gzip" */ +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[95]) +/* "deflate,gzip" */ +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[96]) +/* "identity,deflate,gzip" */ +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ + (grpc_static_slice_table[97]) bool grpc_is_static_metadata_string(grpc_slice slice); @@ -253,251 +253,297 @@ int grpc_static_metadata_index(grpc_slice slice); #define GRPC_STATIC_MDELEM_COUNT 81 extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; -/* "accept-charset": "" */ -#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY \ +/* "grpc-status": "0" */ +#define GRPC_MDELEM_GRPC_STATUS_0 \ (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[0], GRPC_MDELEM_STORAGE_STATIC)) -/* "accept": "" */ -#define GRPC_MDELEM_ACCEPT_EMPTY \ +/* "grpc-status": "1" */ +#define GRPC_MDELEM_GRPC_STATUS_1 \ (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[1], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-status": "2" */ +#define GRPC_MDELEM_GRPC_STATUS_2 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[2], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-encoding": "identity" */ +#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[3], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-encoding": "gzip" */ +#define GRPC_MDELEM_GRPC_ENCODING_GZIP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[4], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-encoding": "deflate" */ +#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[5], GRPC_MDELEM_STORAGE_STATIC)) +/* "te": "trailers" */ +#define GRPC_MDELEM_TE_TRAILERS \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[6], GRPC_MDELEM_STORAGE_STATIC)) +/* "content-type": "application/grpc" */ +#define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[7], GRPC_MDELEM_STORAGE_STATIC)) +/* ":method": "POST" */ +#define GRPC_MDELEM_METHOD_POST \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[8], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "200" */ +#define GRPC_MDELEM_STATUS_200 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[9], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "404" */ +#define GRPC_MDELEM_STATUS_404 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[10], GRPC_MDELEM_STORAGE_STATIC)) +/* ":scheme": "http" */ +#define GRPC_MDELEM_SCHEME_HTTP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[11], GRPC_MDELEM_STORAGE_STATIC)) +/* ":scheme": "https" */ +#define GRPC_MDELEM_SCHEME_HTTPS \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[12], GRPC_MDELEM_STORAGE_STATIC)) +/* ":scheme": "grpc" */ +#define GRPC_MDELEM_SCHEME_GRPC \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[13], GRPC_MDELEM_STORAGE_STATIC)) +/* ":authority": "" */ +#define GRPC_MDELEM_AUTHORITY_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[14], GRPC_MDELEM_STORAGE_STATIC)) +/* ":method": "GET" */ +#define GRPC_MDELEM_METHOD_GET \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[15], GRPC_MDELEM_STORAGE_STATIC)) +/* ":method": "PUT" */ +#define GRPC_MDELEM_METHOD_PUT \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[16], GRPC_MDELEM_STORAGE_STATIC)) +/* ":path": "/" */ +#define GRPC_MDELEM_PATH_SLASH \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[17], GRPC_MDELEM_STORAGE_STATIC)) +/* ":path": "/index.html" */ +#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[18], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "204" */ +#define GRPC_MDELEM_STATUS_204 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[19], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "206" */ +#define GRPC_MDELEM_STATUS_206 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[20], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "304" */ +#define GRPC_MDELEM_STATUS_304 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[21], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "400" */ +#define GRPC_MDELEM_STATUS_400 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[22], GRPC_MDELEM_STORAGE_STATIC)) +/* ":status": "500" */ +#define GRPC_MDELEM_STATUS_500 \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[23], GRPC_MDELEM_STORAGE_STATIC)) +/* "accept-charset": "" */ +#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[24], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-encoding": "" */ #define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[2], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[25], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-encoding": "gzip, deflate" */ #define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[3], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[26], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-language": "" */ #define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[4], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[27], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-ranges": "" */ #define GRPC_MDELEM_ACCEPT_RANGES_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[5], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[28], GRPC_MDELEM_STORAGE_STATIC)) +/* "accept": "" */ +#define GRPC_MDELEM_ACCEPT_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[29], GRPC_MDELEM_STORAGE_STATIC)) /* "access-control-allow-origin": "" */ #define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[6], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[30], GRPC_MDELEM_STORAGE_STATIC)) /* "age": "" */ #define GRPC_MDELEM_AGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[7], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[31], GRPC_MDELEM_STORAGE_STATIC)) /* "allow": "" */ #define GRPC_MDELEM_ALLOW_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[8], GRPC_MDELEM_STORAGE_STATIC)) -/* ":authority": "" */ -#define GRPC_MDELEM_AUTHORITY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[9], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[32], GRPC_MDELEM_STORAGE_STATIC)) /* "authorization": "" */ #define GRPC_MDELEM_AUTHORIZATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[10], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[33], GRPC_MDELEM_STORAGE_STATIC)) /* "cache-control": "" */ #define GRPC_MDELEM_CACHE_CONTROL_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[11], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[34], GRPC_MDELEM_STORAGE_STATIC)) /* "content-disposition": "" */ #define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[12], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[35], GRPC_MDELEM_STORAGE_STATIC)) /* "content-encoding": "" */ #define GRPC_MDELEM_CONTENT_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[13], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[36], GRPC_MDELEM_STORAGE_STATIC)) /* "content-language": "" */ #define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[14], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[37], GRPC_MDELEM_STORAGE_STATIC)) /* "content-length": "" */ #define GRPC_MDELEM_CONTENT_LENGTH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[15], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[38], GRPC_MDELEM_STORAGE_STATIC)) /* "content-location": "" */ #define GRPC_MDELEM_CONTENT_LOCATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[16], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[39], GRPC_MDELEM_STORAGE_STATIC)) /* "content-range": "" */ #define GRPC_MDELEM_CONTENT_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[17], GRPC_MDELEM_STORAGE_STATIC)) -/* "content-type": "application/grpc" */ -#define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[18], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[40], GRPC_MDELEM_STORAGE_STATIC)) /* "content-type": "" */ #define GRPC_MDELEM_CONTENT_TYPE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[19], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[41], GRPC_MDELEM_STORAGE_STATIC)) /* "cookie": "" */ #define GRPC_MDELEM_COOKIE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[20], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[42], GRPC_MDELEM_STORAGE_STATIC)) /* "date": "" */ #define GRPC_MDELEM_DATE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[21], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[43], GRPC_MDELEM_STORAGE_STATIC)) /* "etag": "" */ #define GRPC_MDELEM_ETAG_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[22], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[44], GRPC_MDELEM_STORAGE_STATIC)) /* "expect": "" */ #define GRPC_MDELEM_EXPECT_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[23], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[45], GRPC_MDELEM_STORAGE_STATIC)) /* "expires": "" */ #define GRPC_MDELEM_EXPIRES_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[24], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[46], GRPC_MDELEM_STORAGE_STATIC)) /* "from": "" */ #define GRPC_MDELEM_FROM_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[25], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[26], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "deflate,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[27], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[28], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[29], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,deflate" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[30], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,deflate,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[31], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[32], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[33], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ENCODING_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[34], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[35], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-status": "0" */ -#define GRPC_MDELEM_GRPC_STATUS_0 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[36], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-status": "1" */ -#define GRPC_MDELEM_GRPC_STATUS_1 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[37], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-status": "2" */ -#define GRPC_MDELEM_GRPC_STATUS_2 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[38], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[47], GRPC_MDELEM_STORAGE_STATIC)) /* "host": "" */ #define GRPC_MDELEM_HOST_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[39], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[48], GRPC_MDELEM_STORAGE_STATIC)) /* "if-match": "" */ #define GRPC_MDELEM_IF_MATCH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[40], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[49], GRPC_MDELEM_STORAGE_STATIC)) /* "if-modified-since": "" */ #define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[41], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[50], GRPC_MDELEM_STORAGE_STATIC)) /* "if-none-match": "" */ #define GRPC_MDELEM_IF_NONE_MATCH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[42], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[51], GRPC_MDELEM_STORAGE_STATIC)) /* "if-range": "" */ #define GRPC_MDELEM_IF_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[43], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[52], GRPC_MDELEM_STORAGE_STATIC)) /* "if-unmodified-since": "" */ #define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[44], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[53], GRPC_MDELEM_STORAGE_STATIC)) /* "last-modified": "" */ #define GRPC_MDELEM_LAST_MODIFIED_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[45], GRPC_MDELEM_STORAGE_STATIC)) -/* "lb-cost-bin": "" */ -#define GRPC_MDELEM_LB_COST_BIN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[46], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[54], GRPC_MDELEM_STORAGE_STATIC)) /* "lb-token": "" */ #define GRPC_MDELEM_LB_TOKEN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[47], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[55], GRPC_MDELEM_STORAGE_STATIC)) +/* "lb-cost-bin": "" */ +#define GRPC_MDELEM_LB_COST_BIN_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[56], GRPC_MDELEM_STORAGE_STATIC)) /* "link": "" */ #define GRPC_MDELEM_LINK_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[48], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[57], GRPC_MDELEM_STORAGE_STATIC)) /* "location": "" */ #define GRPC_MDELEM_LOCATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[49], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[58], GRPC_MDELEM_STORAGE_STATIC)) /* "max-forwards": "" */ #define GRPC_MDELEM_MAX_FORWARDS_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[50], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[51], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[52], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[53], GRPC_MDELEM_STORAGE_STATIC)) -/* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[54], GRPC_MDELEM_STORAGE_STATIC)) -/* ":path": "/index.html" */ -#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[55], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[59], GRPC_MDELEM_STORAGE_STATIC)) /* "proxy-authenticate": "" */ #define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[56], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[60], GRPC_MDELEM_STORAGE_STATIC)) /* "proxy-authorization": "" */ #define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[57], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[61], GRPC_MDELEM_STORAGE_STATIC)) /* "range": "" */ #define GRPC_MDELEM_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[58], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[62], GRPC_MDELEM_STORAGE_STATIC)) /* "referer": "" */ #define GRPC_MDELEM_REFERER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[59], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[63], GRPC_MDELEM_STORAGE_STATIC)) /* "refresh": "" */ #define GRPC_MDELEM_REFRESH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[60], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[64], GRPC_MDELEM_STORAGE_STATIC)) /* "retry-after": "" */ #define GRPC_MDELEM_RETRY_AFTER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[61], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[62], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[63], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[64], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[65], GRPC_MDELEM_STORAGE_STATIC)) /* "server": "" */ #define GRPC_MDELEM_SERVER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[65], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[66], GRPC_MDELEM_STORAGE_STATIC)) /* "set-cookie": "" */ #define GRPC_MDELEM_SET_COOKIE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[66], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 \ (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[67], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[68], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[69], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[70], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[71], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[72], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[73], GRPC_MDELEM_STORAGE_STATIC)) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[74], GRPC_MDELEM_STORAGE_STATIC)) -/* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[75], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[68], GRPC_MDELEM_STORAGE_STATIC)) /* "transfer-encoding": "" */ #define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[76], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[69], GRPC_MDELEM_STORAGE_STATIC)) /* "user-agent": "" */ #define GRPC_MDELEM_USER_AGENT_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[77], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[70], GRPC_MDELEM_STORAGE_STATIC)) /* "vary": "" */ #define GRPC_MDELEM_VARY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[78], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[71], GRPC_MDELEM_STORAGE_STATIC)) /* "via": "" */ #define GRPC_MDELEM_VIA_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[79], GRPC_MDELEM_STORAGE_STATIC)) + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[72], GRPC_MDELEM_STORAGE_STATIC)) /* "www-authenticate": "" */ #define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[73], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "identity" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[74], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "deflate" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[75], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "identity,deflate" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[76], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[77], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "identity,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[78], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "deflate,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ + (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[79], GRPC_MDELEM_STORAGE_STATIC)) +/* "grpc-accept-encoding": "identity,deflate,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[80], GRPC_MDELEM_STORAGE_STATIC)) grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b); +typedef enum { + GRPC_BATCH_PATH, + GRPC_BATCH_STATUS, + GRPC_BATCH_SCHEME, + GRPC_BATCH_GRPC_MESSAGE, + GRPC_BATCH_GRPC_PAYLOAD_BIN, + GRPC_BATCH_GRPC_ACCEPT_ENCODING, + GRPC_BATCH_GRPC_INTERNAL_ENCODING_REQUEST, + GRPC_BATCH_HOST, + GRPC_BATCH_LB_COST_BIN, + GRPC_BATCH_GRPC_ENCODING, + GRPC_BATCH_CONTENT_TYPE, + GRPC_BATCH_USER_AGENT, + GRPC_BATCH_AUTHORITY, + GRPC_BATCH_METHOD, + GRPC_BATCH_GRPC_STATUS, + GRPC_BATCH_TE, + GRPC_BATCH_LB_TOKEN, + GRPC_BATCH_CALLOUTS_COUNT +} grpc_metadata_batch_callouts_index; + +typedef union { + struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT]; + struct { + struct grpc_linked_mdelem *path; + struct grpc_linked_mdelem *status; + struct grpc_linked_mdelem *scheme; + struct grpc_linked_mdelem *grpc_message; + struct grpc_linked_mdelem *grpc_payload_bin; + struct grpc_linked_mdelem *grpc_accept_encoding; + struct grpc_linked_mdelem *grpc_internal_encoding_request; + struct grpc_linked_mdelem *host; + struct grpc_linked_mdelem *lb_cost_bin; + struct grpc_linked_mdelem *grpc_encoding; + struct grpc_linked_mdelem *content_type; + struct grpc_linked_mdelem *user_agent; + struct grpc_linked_mdelem *authority; + struct grpc_linked_mdelem *method; + struct grpc_linked_mdelem *grpc_status; + struct grpc_linked_mdelem *te; + struct grpc_linked_mdelem *lb_token; + } named; +} grpc_metadata_batch_callouts; + +grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice); + extern const uint8_t grpc_static_accept_encoding_metadata[8]; #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ (GRPC_MAKE_MDELEM( \ diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index d5ee01bfbfb..81a2419d120 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -1,24 +1,62 @@ # hpack fuzzing dictionary +"\x05:path" +"\x07:method" +"\x07:status" +"\x0A:authority" +"\x07:scheme" +"\x02te" +"\x0Cgrpc-message" +"\x0Bgrpc-status" +"\x10grpc-payload-bin" +"\x0Dgrpc-encoding" +"\x14grpc-accept-encoding" +"\x0Ccontent-type" +"\x1Egrpc-internal-encoding-request" +"\x0Auser-agent" +"\x04host" +"\x08lb-token" +"\x0Blb-cost-bin" +"\x0Cgrpc-timeout" +"\x10grpc-tracing-bin" +"\x0Egrpc-stats-bin" +"\x00" +"\x13grpc.wait_for_ready" +"\x0Cgrpc.timeout" +"\x1Egrpc.max_request_message_bytes" +"\x1Fgrpc.max_response_message_bytes" +"$/grpc.lb.v1.LoadBalancer/BalanceLoad" "\x010" "\x011" "\x012" +"\x08identity" +"\x04gzip" +"\x07deflate" +"\x08trailers" +"\x10application/grpc" +"\x04POST" "\x03200" +"\x03404" +"\x04http" +"\x05https" +"\x04grpc" +"\x03GET" +"\x03PUT" +"\x01/" +"\x0B/index.html" "\x03204" "\x03206" "\x03304" "\x03400" -"\x03404" "\x03500" -"\x06accept" "\x0Eaccept-charset" "\x0Faccept-encoding" +"\x0Dgzip, deflate" "\x0Faccept-language" "\x0Daccept-ranges" +"\x06accept" "\x1Baccess-control-allow-origin" "\x03age" "\x05allow" -"\x10application/grpc" -"\x0A:authority" "\x0Dauthorization" "\x0Dcache-control" "\x13content-disposition" @@ -27,86 +65,71 @@ "\x0Econtent-length" "\x10content-location" "\x0Dcontent-range" -"\x0Ccontent-type" "\x06cookie" "\x04date" -"\x07deflate" -"\x0Cdeflate,gzip" -"\x00" "\x04etag" "\x06expect" "\x07expires" "\x04from" -"\x03GET" -"\x04grpc" -"\x14grpc-accept-encoding" -"\x1Egrpc.max_request_message_bytes" -"\x1Fgrpc.max_response_message_bytes" -"\x0Cgrpc.timeout" -"\x13grpc.wait_for_ready" -"\x0Dgrpc-encoding" -"\x1Egrpc-internal-encoding-request" -"\x0Cgrpc-message" -"\x10grpc-payload-bin" -"\x0Egrpc-stats-bin" -"\x0Bgrpc-status" -"\x0Cgrpc-timeout" -"\x10grpc-tracing-bin" -"\x04gzip" -"\x0Dgzip, deflate" -"\x04host" -"\x04http" -"\x05https" -"\x08identity" -"\x10identity,deflate" -"\x15identity,deflate,gzip" -"\x0Didentity,gzip" "\x08if-match" "\x11if-modified-since" "\x0Dif-none-match" "\x08if-range" "\x13if-unmodified-since" "\x0Dlast-modified" -"\x0Blb-cost-bin" -"\x08lb-token" "\x04link" "\x08location" "\x0Cmax-forwards" -"\x07:method" -"\x05:path" -"\x04POST" "\x12proxy-authenticate" "\x13proxy-authorization" -"\x03PUT" "\x05range" "\x07referer" "\x07refresh" "\x0Bretry-after" -"\x07:scheme" "\x06server" "\x0Aset-cookie" -"\x01/" -"$/grpc.lb.v1.LoadBalancer/BalanceLoad" -"\x0B/index.html" -"\x07:status" "\x19strict-transport-security" -"\x02te" -"\x08trailers" "\x11transfer-encoding" -"\x0Auser-agent" "\x04vary" "\x03via" "\x10www-authenticate" +"\x10identity,deflate" +"\x0Didentity,gzip" +"\x0Cdeflate,gzip" +"\x15identity,deflate,gzip" +"\x00\x0Bgrpc-status\x010" +"\x00\x0Bgrpc-status\x011" +"\x00\x0Bgrpc-status\x012" +"\x00\x0Dgrpc-encoding\x08identity" +"\x00\x0Dgrpc-encoding\x04gzip" +"\x00\x0Dgrpc-encoding\x07deflate" +"\x00\x02te\x08trailers" +"\x00\x0Ccontent-type\x10application/grpc" +"\x00\x07:method\x04POST" +"\x00\x07:status\x03200" +"\x00\x07:status\x03404" +"\x00\x07:scheme\x04http" +"\x00\x07:scheme\x05https" +"\x00\x07:scheme\x04grpc" +"\x00\x0A:authority\x00" +"\x00\x07:method\x03GET" +"\x00\x07:method\x03PUT" +"\x00\x05:path\x01/" +"\x00\x05:path\x0B/index.html" +"\x00\x07:status\x03204" +"\x00\x07:status\x03206" +"\x00\x07:status\x03304" +"\x00\x07:status\x03400" +"\x00\x07:status\x03500" "\x00\x0Eaccept-charset\x00" -"\x00\x06accept\x00" "\x00\x0Faccept-encoding\x00" "\x00\x0Faccept-encoding\x0Dgzip, deflate" "\x00\x0Faccept-language\x00" "\x00\x0Daccept-ranges\x00" +"\x00\x06accept\x00" "\x00\x1Baccess-control-allow-origin\x00" "\x00\x03age\x00" "\x00\x05allow\x00" -"\x00\x0A:authority\x00" "\x00\x0Dauthorization\x00" "\x00\x0Dcache-control\x00" "\x00\x13content-disposition\x00" @@ -115,7 +138,6 @@ "\x00\x0Econtent-length\x00" "\x00\x10content-location\x00" "\x00\x0Dcontent-range\x00" -"\x00\x0Ccontent-type\x10application/grpc" "\x00\x0Ccontent-type\x00" "\x00\x06cookie\x00" "\x00\x04date\x00" @@ -123,19 +145,6 @@ "\x00\x06expect\x00" "\x00\x07expires\x00" "\x00\x04from\x00" -"\x00\x14grpc-accept-encoding\x07deflate" -"\x00\x14grpc-accept-encoding\x0Cdeflate,gzip" -"\x00\x14grpc-accept-encoding\x04gzip" -"\x00\x14grpc-accept-encoding\x08identity" -"\x00\x14grpc-accept-encoding\x10identity,deflate" -"\x00\x14grpc-accept-encoding\x15identity,deflate,gzip" -"\x00\x14grpc-accept-encoding\x0Didentity,gzip" -"\x00\x0Dgrpc-encoding\x07deflate" -"\x00\x0Dgrpc-encoding\x04gzip" -"\x00\x0Dgrpc-encoding\x08identity" -"\x00\x0Bgrpc-status\x010" -"\x00\x0Bgrpc-status\x011" -"\x00\x0Bgrpc-status\x012" "\x00\x04host\x00" "\x00\x08if-match\x00" "\x00\x11if-modified-since\x00" @@ -143,38 +152,29 @@ "\x00\x08if-range\x00" "\x00\x13if-unmodified-since\x00" "\x00\x0Dlast-modified\x00" -"\x00\x0Blb-cost-bin\x00" "\x00\x08lb-token\x00" +"\x00\x0Blb-cost-bin\x00" "\x00\x04link\x00" "\x00\x08location\x00" "\x00\x0Cmax-forwards\x00" -"\x00\x07:method\x03GET" -"\x00\x07:method\x04POST" -"\x00\x07:method\x03PUT" -"\x00\x05:path\x01/" -"\x00\x05:path\x0B/index.html" "\x00\x12proxy-authenticate\x00" "\x00\x13proxy-authorization\x00" "\x00\x05range\x00" "\x00\x07referer\x00" "\x00\x07refresh\x00" "\x00\x0Bretry-after\x00" -"\x00\x07:scheme\x04grpc" -"\x00\x07:scheme\x04http" -"\x00\x07:scheme\x05https" "\x00\x06server\x00" "\x00\x0Aset-cookie\x00" -"\x00\x07:status\x03200" -"\x00\x07:status\x03204" -"\x00\x07:status\x03206" -"\x00\x07:status\x03304" -"\x00\x07:status\x03400" -"\x00\x07:status\x03404" -"\x00\x07:status\x03500" "\x00\x19strict-transport-security\x00" -"\x00\x02te\x08trailers" "\x00\x11transfer-encoding\x00" "\x00\x0Auser-agent\x00" "\x00\x04vary\x00" "\x00\x03via\x00" "\x00\x10www-authenticate\x00" +"\x00\x14grpc-accept-encoding\x08identity" +"\x00\x14grpc-accept-encoding\x07deflate" +"\x00\x14grpc-accept-encoding\x10identity,deflate" +"\x00\x14grpc-accept-encoding\x04gzip" +"\x00\x14grpc-accept-encoding\x0Didentity,gzip" +"\x00\x14grpc-accept-encoding\x0Cdeflate,gzip" +"\x00\x14grpc-accept-encoding\x15identity,deflate,gzip" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index e40a40d4230..a0b06edd476 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -44,6 +44,7 @@ import re CONFIG = [ # metadata strings + 'host', 'grpc-timeout', 'grpc-internal-encoding-request', 'grpc-payload-bin', @@ -52,7 +53,6 @@ CONFIG = [ 'grpc-accept-encoding', 'user-agent', ':authority', - 'host', 'grpc-message', 'grpc-status', 'grpc-tracing-bin', @@ -142,6 +142,26 @@ CONFIG = [ ('www-authenticate', ''), ] +METADATA_BATCH_CALLOUTS = [ + ':path', + ':method', + ':status', + ':authority', + ':scheme', + 'te', + 'grpc-message', + 'grpc-status', + 'grpc-payload-bin', + 'grpc-encoding', + 'grpc-accept-encoding', + 'content-type', + 'grpc-internal-encoding-request', + 'user-agent', + 'host', + 'lb-token', + 'lb-cost-bin', +] + COMPRESSION_ALGORITHMS = [ 'identity', 'deflate', @@ -149,7 +169,7 @@ COMPRESSION_ALGORITHMS = [ ] # utility: mangle the name of a config -def mangle(elem): +def mangle(elem, name=None): xl = { '-': '_', ':': '', @@ -174,10 +194,14 @@ def mangle(elem): r += put if r[-1] == '_': r = r[:-1] return r + def n(default, name=name): + if name is None: return 'grpc_%s_' % default + if name == '': return '' + return 'grpc_%s_' % name if isinstance(elem, tuple): - return 'grpc_mdelem_%s_%s' % (m0(elem[0]), m0(elem[1])) + return '%s%s_%s' % (n('mdelem'), m0(elem[0]), m0(elem[1])) else: - return 'grpc_mdstr_%s' % (m0(elem)) + return '%s%s' % (n('mdstr'), m0(elem)) # utility: generate some hash value for a string def fake_hash(elem): @@ -196,6 +220,9 @@ def put_banner(files, banner): all_strs = list() all_elems = list() static_userdata = {} +for elem in METADATA_BATCH_CALLOUTS: + if elem not in all_strs: + all_strs.append(elem) for elem in CONFIG: if isinstance(elem, tuple): if elem[0] not in all_strs: @@ -219,8 +246,6 @@ for mask in range(1, 1<>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' for i, elem in enumerate(all_strs): @@ -373,13 +402,23 @@ def md_idx(m): if m == m2: return i +def offset_trials(mink): + yield 0 + for i in range(1, 100): + for mul in [-1, 1]: + yield mul * i + def perfect_hash(keys, name): ok = False + print '***********' + print keys cmd = '%s/perfect/build.sh' % (os.path.dirname(sys.argv[0])) subprocess.check_call(cmd, shell=True) - for offset in reversed(range(0, min(keys))): + for offset in offset_trials(min(keys)): tmp = open('/tmp/keys.txt', 'w') - tmp.write(''.join('%d\n' % (x - offset) for x in keys)) + offset_keys = [x + offset for x in keys] + print offset_keys + tmp.write(''.join('%d\n' % x for x in offset_keys)) tmp.close() cmd = '%s/perfect/run.sh %s -dms' % (os.path.dirname(sys.argv[0]), tmp.name) out = subprocess.check_output(cmd, shell=True) @@ -399,13 +438,13 @@ def perfect_hash(keys, name): results[var] = val code += '\n' pycode = 'def f(val):\n' - pycode += ' val -= %d\n' % offset + pycode += ' val += %d\n' % offset with open('%s/perfect/phash.c' % os.path.dirname(sys.argv[0])) as f: txt = f.read() tabdata = re.search(r'ub1 tab\[\] = \{([^}]+)\}', txt, re.MULTILINE).group(1) code += 'static const uint8_t %s_tab[] = {%s};\n\n' % (name, tabdata) func_body = re.search(r'ub4 phash\(val\)\nub4 val;\n\{([^}]+)\}', txt, re.MULTILINE).group(1).replace('ub4', 'uint32_t') - code += 'static uint32_t %s_phash(uint32_t val) {\nval -= %d;\n%s}\n' % (name, + code += 'static uint32_t %s_phash(uint32_t val) {\nval += (uint32_t)%d;\n%s}\n' % (name, offset, func_body.replace('tab', '%s_tab' % name)) pycode += ' tab=(%s)' % tabdata.replace('\n', '') pycode += '\n'.join(' %s' % s.strip() for s in func_body.splitlines()[2:]) @@ -446,6 +485,40 @@ for a, b in all_elems: print >>C, '{%s,%s},' % (slice_def(str_idx(a)), slice_def(str_idx(b))) print >>C, '};' +print >>H, 'typedef enum {' +batch_keys = [str_idx(s) for s in METADATA_BATCH_CALLOUTS] +batch_hash = perfect_hash(batch_keys, 'batch') +ordered_callouts = sorted((batch_hash['pyfunc'](str_idx(elem)), elem) for elem in METADATA_BATCH_CALLOUTS) +for _, elem in ordered_callouts: + print >>H, ' %s,' % mangle(elem, 'batch').upper() +print >>H, ' GRPC_BATCH_CALLOUTS_COUNT' +print >>H, '} grpc_metadata_batch_callouts_index;' +print >>H +print >>H, 'typedef union {' +print >>H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];' +print >>H, ' struct {' +for _, elem in ordered_callouts: + print >>H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower() +print >>H, ' } named;' +print >>H, '} grpc_metadata_batch_callouts;' +print >>H +print >>H, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice);' +print >>H +print >>C, batch_hash['code'] +batch_hash_to_idx = [0] * int(batch_hash['PHASHRANGE']) +for i, elem in enumerate( METADATA_BATCH_CALLOUTS): + batch_hash_to_idx[batch_hash['pyfunc'](str_idx(elem))] = str_idx(elem) +print >>C, 'static const uint8_t batch_hash_to_idx[] = {%s};' % ','.join('%d' % n for n in batch_hash_to_idx) +print >>C +print >>C, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) {' +print >>C, ' if (!grpc_is_static_metadata_string(slice)) return GRPC_BATCH_CALLOUTS_COUNT;' +print >>C, ' uint32_t idx = (uint32_t)grpc_static_metadata_index(slice);' +print >>C, ' uint32_t hash = batch_phash(idx);' +print >>C, ' if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && batch_hash_to_idx[hash] == idx) return (grpc_metadata_batch_callouts_index)hash;' +print >>C, ' return GRPC_BATCH_CALLOUTS_COUNT;' +print >>C, '}' +print >>C + print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) From b0f3bca0ef9ee8c1ea6bb2bde7281a1df5914216 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Nov 2016 14:54:10 -0800 Subject: [PATCH 045/261] Everything compiles... --- src/core/lib/channel/http_server_filter.c | 2 +- src/core/lib/surface/call.c | 5 ++-- src/core/lib/transport/metadata_batch.c | 32 +++++++++++++++++++++++ src/core/lib/transport/metadata_batch.h | 6 ++--- src/cpp/common/channel_filter.cc | 3 ++- 5 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 596c97e58ea..10b386a2f07 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -197,7 +197,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, if (b->idx.named.host != NULL) { add_error(error_name, &error, grpc_metadata_batch_substitute( - b, b->idx.named.host, + exec_ctx, b, b->idx.named.host, grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_ref(GRPC_MDVALUE(b->idx.named.host->md))))); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 4e1ca22cb88..a0bcac22a3b 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -940,8 +940,9 @@ static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, grpc_metadata_array *dest; grpc_metadata *mdusr; dest = call->buffered_metadata[is_trailing]; - if (dest->count + b->count > dest->capacity) { - dest->capacity = GPR_MAX(dest->capacity + b->count, dest->capacity * 3 / 2); + if (dest->count + b->list.count > dest->capacity) { + dest->capacity = + GPR_MAX(dest->capacity + b->list.count, dest->capacity * 3 / 2); dest->metadata = gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity); } diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 39e49283bfa..2bbd5ba6aa1 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -52,13 +52,16 @@ static void assert_valid_list(grpc_mdelem_list *list) { GPR_ASSERT(list->tail->next == NULL); GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL)); + size_t verified_count = 0; for (l = list->head; l; l = l->next) { GPR_ASSERT(!GRPC_MDISNULL(l->md)); GPR_ASSERT((l->prev == NULL) == (l == list->head)); GPR_ASSERT((l->next == NULL) == (l == list->tail)); if (l->next) GPR_ASSERT(l->next->prev == l); if (l->prev) GPR_ASSERT(l->prev->next == l); + verified_count++; } + GPR_ASSERT(list->count == verified_count); #endif /* NDEBUG */ } @@ -154,6 +157,7 @@ static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { list->tail = storage; } list->head = storage; + list->count++; assert_valid_list(list); } @@ -219,6 +223,7 @@ static void unlink_storage(grpc_mdelem_list *list, } else { list->tail = storage->prev; } + list->count--; assert_valid_list(list); } @@ -230,6 +235,33 @@ void grpc_metadata_batch_remove(grpc_metadata_batch *batch, assert_valid_callouts(batch); } +void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, + grpc_linked_mdelem *storage, + grpc_slice value) { + grpc_mdelem old = storage->md; + grpc_mdelem new = + grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref(GRPC_MDKEY(old)), value); + storage->md = new; + GRPC_MDELEM_UNREF(exec_ctx, old); +} + +grpc_error *grpc_metadata_batch_substitute(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem new) { + grpc_error *error = GRPC_ERROR_NONE; + grpc_mdelem old = storage->md; + if (!grpc_slice_eq(GRPC_MDKEY(new), GRPC_MDKEY(old))) { + maybe_unlink_callout(batch, storage); + storage->md = new; + error = maybe_link_callout(batch, storage); + } else { + storage->md = new; + } + GRPC_MDELEM_UNREF(exec_ctx, old); + return error; +} + void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch) { grpc_metadata_batch_destroy(exec_ctx, batch); diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 1cc38140446..a95a8887f46 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -55,13 +55,12 @@ typedef struct grpc_linked_mdelem { } grpc_linked_mdelem; typedef struct grpc_mdelem_list { + size_t count; grpc_linked_mdelem *head; grpc_linked_mdelem *tail; } grpc_mdelem_list; typedef struct grpc_metadata_batch { - /* number of elements in the batch */ - size_t count; /** Metadata elements in this batch */ grpc_mdelem_list list; grpc_metadata_batch_callouts idx; @@ -86,7 +85,8 @@ void grpc_metadata_batch_remove(grpc_metadata_batch *batch, grpc_linked_mdelem *storage); /** Substitute a new mdelem for an old value */ -grpc_error *grpc_metadata_batch_substitute(grpc_metadata_batch *batch, +grpc_error *grpc_metadata_batch_substitute(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem new_value); diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 9aeb942f596..35cd6ca6475 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -49,7 +49,8 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, memset(storage, 0, sizeof(grpc_linked_mdelem)); storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), SliceFromCopiedString(value)); - grpc_metadata_batch_link_head(batch_, storage); + GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", + grpc_metadata_batch_link_head(batch_, storage)); return storage; } From 0960818e546f63131522def31838848370467c25 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 22 Nov 2016 15:43:56 -0800 Subject: [PATCH 046/261] bm_fullstack runs --- .../chttp2/transport/incoming_metadata.c | 13 ++-- src/core/lib/channel/http_server_filter.c | 14 ++-- src/core/lib/surface/call.c | 71 +++---------------- src/core/lib/transport/metadata_batch.c | 1 + 4 files changed, 23 insertions(+), 76 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index 9922dd87e16..910afea9ca0 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -80,16 +80,11 @@ void grpc_chttp2_incoming_metadata_buffer_publish( buffer->published = 1; if (buffer->count > 0) { size_t i; - for (i = 1; i < buffer->count; i++) { - buffer->elems[i].prev = &buffer->elems[i - 1]; - } - for (i = 0; i < buffer->count - 1; i++) { - buffer->elems[i].next = &buffer->elems[i + 1]; + for (i = 0; i < buffer->count; i++) { + GRPC_LOG_IF_ERROR( + "grpc_chttp2_incoming_metadata_buffer_publish", + grpc_metadata_batch_link_tail(batch, &buffer->elems[i])); } - buffer->elems[0].prev = NULL; - buffer->elems[buffer->count - 1].next = NULL; - batch->list.head = &buffer->elems[0]; - batch->list.tail = &buffer->elems[buffer->count - 1]; } else { batch->list.head = batch->list.tail = NULL; } diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 10b386a2f07..07c67e54c1c 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -99,7 +99,11 @@ static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, static void add_error(const char *error_name, grpc_error **cumulative, grpc_error *new) { - abort(); + if (new == GRPC_ERROR_NONE) return; + if (*cumulative == GRPC_ERROR_NONE) { + *cumulative = GRPC_ERROR_CREATE(error_name); + } + *cumulative = grpc_error_add_child(*cumulative, new); } static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, @@ -145,12 +149,12 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } if (b->idx.named.scheme != NULL) { - if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTP) && - !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_HTTPS) && - !grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_SCHEME_GRPC)) { + if (!grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTP) && + !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTPS) && + !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_GRPC)) { add_error(error_name, &error, grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), - b->idx.named.te->md)); + b->idx.named.scheme->md)); } grpc_metadata_batch_remove(b, b->idx.named.scheme); } else { diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index a0bcac22a3b..d5e90ccdda1 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -623,73 +623,19 @@ static int prepare_application_metadata( if (call->send_extra_metadata_count == 0) { prepend_extra_metadata = 0; } else { - for (i = 1; i < call->send_extra_metadata_count; i++) { - call->send_extra_metadata[i].prev = &call->send_extra_metadata[i - 1]; - } - for (i = 0; i < call->send_extra_metadata_count - 1; i++) { - call->send_extra_metadata[i].next = &call->send_extra_metadata[i + 1]; + for (i = 0; i < call->send_extra_metadata_count; i++) { + GRPC_LOG_IF_ERROR("prepare_application_metadata", + grpc_metadata_batch_link_tail( + batch, &call->send_extra_metadata[i])); } } } - for (i = 1; i < total_count; i++) { - grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - grpc_metadata *prev_md = - get_md_elem(metadata, additional_metadata, i - 1, count); - linked_from_md(md)->prev = linked_from_md(prev_md); - } - for (i = 0; i < total_count - 1; i++) { + for (i = 0; i < total_count; i++) { grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - grpc_metadata *next_md = - get_md_elem(metadata, additional_metadata, i + 1, count); - linked_from_md(md)->next = linked_from_md(next_md); - } - - switch (prepend_extra_metadata * 2 + (total_count != 0)) { - case 0: - /* no prepend, no metadata => nothing to do */ - batch->list.head = batch->list.tail = NULL; - break; - case 1: { - /* metadata, but no prepend */ - grpc_metadata *first_md = - get_md_elem(metadata, additional_metadata, 0, count); - grpc_metadata *last_md = - get_md_elem(metadata, additional_metadata, total_count - 1, count); - batch->list.head = linked_from_md(first_md); - batch->list.tail = linked_from_md(last_md); - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - break; - } - case 2: - /* prepend, but no md */ - batch->list.head = &call->send_extra_metadata[0]; - batch->list.tail = - &call->send_extra_metadata[call->send_extra_metadata_count - 1]; - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - call->send_extra_metadata_count = 0; - break; - case 3: { - /* prepend AND md */ - grpc_metadata *first_md = - get_md_elem(metadata, additional_metadata, 0, count); - grpc_metadata *last_md = - get_md_elem(metadata, additional_metadata, total_count - 1, count); - batch->list.head = &call->send_extra_metadata[0]; - call->send_extra_metadata[call->send_extra_metadata_count - 1].next = - linked_from_md(first_md); - linked_from_md(first_md)->prev = - &call->send_extra_metadata[call->send_extra_metadata_count - 1]; - batch->list.tail = linked_from_md(last_md); - batch->list.head->prev = NULL; - batch->list.tail->next = NULL; - call->send_extra_metadata_count = 0; - break; - } - default: - GPR_UNREACHABLE_CODE(return 0); + GRPC_LOG_IF_ERROR("prepare_application_metadata", + grpc_metadata_batch_link_tail(batch, linked_from_md(md))); } + call->send_extra_metadata_count = 0; return 1; } @@ -936,6 +882,7 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, int is_trailing) { + if (b->list.count == 0) return; GPR_TIMER_BEGIN("publish_app_metadata", 0); grpc_metadata_array *dest; grpc_metadata *mdusr; diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 2bbd5ba6aa1..c41d28d9f7e 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -194,6 +194,7 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { list->head = storage; } list->tail = storage; + list->count++; assert_valid_list(list); } From 43a516929279ac20febbc0a40873c3d3c8edc4a7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:03:02 -0800 Subject: [PATCH 047/261] Declare sub_refcnt field --- include/grpc/impl/codegen/slice.h | 5 + .../chttp2/transport/hpack_encoder.c | 2 +- src/core/lib/slice/slice.c | 3 +- src/core/lib/transport/static_metadata.c | 952 ++++++++++++------ src/core/lib/transport/static_metadata.h | 13 +- tools/codegen/core/gen_static_metadata.py | 32 +- 6 files changed, 660 insertions(+), 347 deletions(-) diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index fbd18e6c65b..45902c69093 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -68,6 +68,11 @@ typedef struct grpc_slice_refcount_vtable { grpc_slice_new, or grpc_slice_new_with_len instead. */ typedef struct grpc_slice_refcount { const grpc_slice_refcount_vtable *vtable; + /* If a subset of this slice is taken, use this pointer for the refcount. + Typically points back to the refcount itself, however iterning + implementations can use this to avoid a verification step on each hash + or equality check */ + struct grpc_slice_refcount *sub_refcount; } grpc_slice_refcount; #define GRPC_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1) diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index eb19bd7c2d0..2eb0c51bdc4 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -65,7 +65,7 @@ /* don't consider adding anything bigger than this to the hpack table */ #define MAX_DECODER_SPACE_USAGE 512 -static grpc_slice_refcount terminal_slice_refcount = {NULL}; +static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; static const grpc_slice terminal_slice = {&terminal_slice_refcount, .data.refcounted = {0, 0}}; diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 2ae97b3035f..8188ba9b03d 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -81,7 +81,8 @@ static void noop_unref(grpc_exec_ctx *exec_ctx, void *unused) {} static const grpc_slice_refcount_vtable noop_refcount_vtable = { noop_ref, noop_unref, grpc_slice_default_eq_impl, grpc_slice_default_hash_impl}; -static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable}; +static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable, + &noop_refcount}; grpc_slice grpc_slice_from_static_buffer(const void *s, size_t len) { grpc_slice slice; diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 5232bd7a98c..13a0fa37e05 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -116,178 +116,313 @@ static uint8_t g_bytes[] = { static void static_ref(void *unused) {} static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} -static const grpc_slice_refcount_vtable static_vtable = { +static const grpc_slice_refcount_vtable static_sub_vtable = { + static_ref, static_unref, grpc_slice_default_eq_impl, + grpc_slice_default_hash_impl}; +const grpc_slice_refcount_vtable grpc_static_metadata_vtable = { static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash}; -typedef struct { - grpc_slice_refcount base; - const uint16_t offset; - const uint16_t length; -} static_slice_refcount; -static static_slice_refcount g_refcnts[GRPC_STATIC_MDSTR_COUNT] = { - {{&static_vtable}, 0, 5}, {{&static_vtable}, 5, 7}, - {{&static_vtable}, 12, 7}, {{&static_vtable}, 19, 10}, - {{&static_vtable}, 29, 7}, {{&static_vtable}, 36, 2}, - {{&static_vtable}, 38, 12}, {{&static_vtable}, 50, 11}, - {{&static_vtable}, 61, 16}, {{&static_vtable}, 77, 13}, - {{&static_vtable}, 90, 20}, {{&static_vtable}, 110, 12}, - {{&static_vtable}, 122, 30}, {{&static_vtable}, 152, 10}, - {{&static_vtable}, 162, 4}, {{&static_vtable}, 166, 8}, - {{&static_vtable}, 174, 11}, {{&static_vtable}, 185, 12}, - {{&static_vtable}, 197, 16}, {{&static_vtable}, 213, 14}, - {{&static_vtable}, 227, 0}, {{&static_vtable}, 227, 19}, - {{&static_vtable}, 246, 12}, {{&static_vtable}, 258, 30}, - {{&static_vtable}, 288, 31}, {{&static_vtable}, 319, 36}, - {{&static_vtable}, 355, 1}, {{&static_vtable}, 356, 1}, - {{&static_vtable}, 357, 1}, {{&static_vtable}, 358, 8}, - {{&static_vtable}, 366, 4}, {{&static_vtable}, 370, 7}, - {{&static_vtable}, 377, 8}, {{&static_vtable}, 385, 16}, - {{&static_vtable}, 401, 4}, {{&static_vtable}, 405, 3}, - {{&static_vtable}, 408, 3}, {{&static_vtable}, 411, 4}, - {{&static_vtable}, 415, 5}, {{&static_vtable}, 420, 4}, - {{&static_vtable}, 424, 3}, {{&static_vtable}, 427, 3}, - {{&static_vtable}, 430, 1}, {{&static_vtable}, 431, 11}, - {{&static_vtable}, 442, 3}, {{&static_vtable}, 445, 3}, - {{&static_vtable}, 448, 3}, {{&static_vtable}, 451, 3}, - {{&static_vtable}, 454, 3}, {{&static_vtable}, 457, 14}, - {{&static_vtable}, 471, 15}, {{&static_vtable}, 486, 13}, - {{&static_vtable}, 499, 15}, {{&static_vtable}, 514, 13}, - {{&static_vtable}, 527, 6}, {{&static_vtable}, 533, 27}, - {{&static_vtable}, 560, 3}, {{&static_vtable}, 563, 5}, - {{&static_vtable}, 568, 13}, {{&static_vtable}, 581, 13}, - {{&static_vtable}, 594, 19}, {{&static_vtable}, 613, 16}, - {{&static_vtable}, 629, 16}, {{&static_vtable}, 645, 14}, - {{&static_vtable}, 659, 16}, {{&static_vtable}, 675, 13}, - {{&static_vtable}, 688, 6}, {{&static_vtable}, 694, 4}, - {{&static_vtable}, 698, 4}, {{&static_vtable}, 702, 6}, - {{&static_vtable}, 708, 7}, {{&static_vtable}, 715, 4}, - {{&static_vtable}, 719, 8}, {{&static_vtable}, 727, 17}, - {{&static_vtable}, 744, 13}, {{&static_vtable}, 757, 8}, - {{&static_vtable}, 765, 19}, {{&static_vtable}, 784, 13}, - {{&static_vtable}, 797, 4}, {{&static_vtable}, 801, 8}, - {{&static_vtable}, 809, 12}, {{&static_vtable}, 821, 18}, - {{&static_vtable}, 839, 19}, {{&static_vtable}, 858, 5}, - {{&static_vtable}, 863, 7}, {{&static_vtable}, 870, 7}, - {{&static_vtable}, 877, 11}, {{&static_vtable}, 888, 6}, - {{&static_vtable}, 894, 10}, {{&static_vtable}, 904, 25}, - {{&static_vtable}, 929, 17}, {{&static_vtable}, 946, 4}, - {{&static_vtable}, 950, 3}, {{&static_vtable}, 953, 16}, - {{&static_vtable}, 969, 16}, {{&static_vtable}, 985, 13}, - {{&static_vtable}, 998, 12}, {{&static_vtable}, 1010, 21}, +static grpc_slice_refcount static_sub_refcnt = {&static_sub_vtable, + &static_sub_refcnt}; +grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = { + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, + {&grpc_static_metadata_vtable, &static_sub_refcnt}, }; -bool grpc_is_static_metadata_string(grpc_slice slice) { - return slice.refcount != NULL && slice.refcount->vtable == &static_vtable; -} - const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { - {.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 19, 10}}, - {.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 36, 2}}, - {.refcount = &g_refcnts[6].base, .data.refcounted = {g_bytes + 38, 12}}, - {.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &g_refcnts[8].base, .data.refcounted = {g_bytes + 61, 16}}, - {.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &g_refcnts[12].base, .data.refcounted = {g_bytes + 122, 30}}, - {.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 152, 10}}, - {.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 162, 4}}, - {.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 166, 8}}, - {.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 174, 11}}, - {.refcount = &g_refcnts[17].base, .data.refcounted = {g_bytes + 185, 12}}, - {.refcount = &g_refcnts[18].base, .data.refcounted = {g_bytes + 197, 16}}, - {.refcount = &g_refcnts[19].base, .data.refcounted = {g_bytes + 213, 14}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}, - {.refcount = &g_refcnts[21].base, .data.refcounted = {g_bytes + 227, 19}}, - {.refcount = &g_refcnts[22].base, .data.refcounted = {g_bytes + 246, 12}}, - {.refcount = &g_refcnts[23].base, .data.refcounted = {g_bytes + 258, 30}}, - {.refcount = &g_refcnts[24].base, .data.refcounted = {g_bytes + 288, 31}}, - {.refcount = &g_refcnts[25].base, .data.refcounted = {g_bytes + 319, 36}}, - {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 355, 1}}, - {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 356, 1}}, - {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 357, 1}}, - {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}, - {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}, - {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 377, 8}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 385, 16}}, - {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 401, 4}}, - {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 405, 3}}, - {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 408, 3}}, - {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 411, 4}}, - {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 415, 5}}, - {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 420, 4}}, - {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 424, 3}}, - {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 427, 3}}, - {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 430, 1}}, - {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 431, 11}}, - {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 442, 3}}, - {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 445, 3}}, - {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 448, 3}}, - {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 451, 3}}, - {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 454, 3}}, - {.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 457, 14}}, - {.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 486, 13}}, - {.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 499, 15}}, - {.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 514, 13}}, - {.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 527, 6}}, - {.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 533, 27}}, - {.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 560, 3}}, - {.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 563, 5}}, - {.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 568, 13}}, - {.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 581, 13}}, - {.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 594, 19}}, - {.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 613, 16}}, - {.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 629, 16}}, - {.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 645, 14}}, - {.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 659, 16}}, - {.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 675, 13}}, - {.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 688, 6}}, - {.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 694, 4}}, - {.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 698, 4}}, - {.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 702, 6}}, - {.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 708, 7}}, - {.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 715, 4}}, - {.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 719, 8}}, - {.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 727, 17}}, - {.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 744, 13}}, - {.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 757, 8}}, - {.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 765, 19}}, - {.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 784, 13}}, - {.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 797, 4}}, - {.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 801, 8}}, - {.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 809, 12}}, - {.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 821, 18}}, - {.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 839, 19}}, - {.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 858, 5}}, - {.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 863, 7}}, - {.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 870, 7}}, - {.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 877, 11}}, - {.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 888, 6}}, - {.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 894, 10}}, - {.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 904, 25}}, - {.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 929, 17}}, - {.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 946, 4}}, - {.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 950, 3}}, - {.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 953, 16}}, - {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 969, 16}}, - {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 985, 13}}, - {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 998, 12}}, - {.refcount = &g_refcnts[97].base, .data.refcounted = {g_bytes + 1010, 21}}, + {.refcount = &grpc_static_metadata_refcounts[0], + .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &grpc_static_metadata_refcounts[1], + .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[3], + .data.refcounted = {g_bytes + 19, 10}}, + {.refcount = &grpc_static_metadata_refcounts[4], + .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &grpc_static_metadata_refcounts[5], + .data.refcounted = {g_bytes + 36, 2}}, + {.refcount = &grpc_static_metadata_refcounts[6], + .data.refcounted = {g_bytes + 38, 12}}, + {.refcount = &grpc_static_metadata_refcounts[7], + .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &grpc_static_metadata_refcounts[8], + .data.refcounted = {g_bytes + 61, 16}}, + {.refcount = &grpc_static_metadata_refcounts[9], + .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[11], + .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &grpc_static_metadata_refcounts[12], + .data.refcounted = {g_bytes + 122, 30}}, + {.refcount = &grpc_static_metadata_refcounts[13], + .data.refcounted = {g_bytes + 152, 10}}, + {.refcount = &grpc_static_metadata_refcounts[14], + .data.refcounted = {g_bytes + 162, 4}}, + {.refcount = &grpc_static_metadata_refcounts[15], + .data.refcounted = {g_bytes + 166, 8}}, + {.refcount = &grpc_static_metadata_refcounts[16], + .data.refcounted = {g_bytes + 174, 11}}, + {.refcount = &grpc_static_metadata_refcounts[17], + .data.refcounted = {g_bytes + 185, 12}}, + {.refcount = &grpc_static_metadata_refcounts[18], + .data.refcounted = {g_bytes + 197, 16}}, + {.refcount = &grpc_static_metadata_refcounts[19], + .data.refcounted = {g_bytes + 213, 14}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}, + {.refcount = &grpc_static_metadata_refcounts[21], + .data.refcounted = {g_bytes + 227, 19}}, + {.refcount = &grpc_static_metadata_refcounts[22], + .data.refcounted = {g_bytes + 246, 12}}, + {.refcount = &grpc_static_metadata_refcounts[23], + .data.refcounted = {g_bytes + 258, 30}}, + {.refcount = &grpc_static_metadata_refcounts[24], + .data.refcounted = {g_bytes + 288, 31}}, + {.refcount = &grpc_static_metadata_refcounts[25], + .data.refcounted = {g_bytes + 319, 36}}, + {.refcount = &grpc_static_metadata_refcounts[26], + .data.refcounted = {g_bytes + 355, 1}}, + {.refcount = &grpc_static_metadata_refcounts[27], + .data.refcounted = {g_bytes + 356, 1}}, + {.refcount = &grpc_static_metadata_refcounts[28], + .data.refcounted = {g_bytes + 357, 1}}, + {.refcount = &grpc_static_metadata_refcounts[29], + .data.refcounted = {g_bytes + 358, 8}}, + {.refcount = &grpc_static_metadata_refcounts[30], + .data.refcounted = {g_bytes + 366, 4}}, + {.refcount = &grpc_static_metadata_refcounts[31], + .data.refcounted = {g_bytes + 370, 7}}, + {.refcount = &grpc_static_metadata_refcounts[32], + .data.refcounted = {g_bytes + 377, 8}}, + {.refcount = &grpc_static_metadata_refcounts[33], + .data.refcounted = {g_bytes + 385, 16}}, + {.refcount = &grpc_static_metadata_refcounts[34], + .data.refcounted = {g_bytes + 401, 4}}, + {.refcount = &grpc_static_metadata_refcounts[35], + .data.refcounted = {g_bytes + 405, 3}}, + {.refcount = &grpc_static_metadata_refcounts[36], + .data.refcounted = {g_bytes + 408, 3}}, + {.refcount = &grpc_static_metadata_refcounts[37], + .data.refcounted = {g_bytes + 411, 4}}, + {.refcount = &grpc_static_metadata_refcounts[38], + .data.refcounted = {g_bytes + 415, 5}}, + {.refcount = &grpc_static_metadata_refcounts[39], + .data.refcounted = {g_bytes + 420, 4}}, + {.refcount = &grpc_static_metadata_refcounts[40], + .data.refcounted = {g_bytes + 424, 3}}, + {.refcount = &grpc_static_metadata_refcounts[41], + .data.refcounted = {g_bytes + 427, 3}}, + {.refcount = &grpc_static_metadata_refcounts[42], + .data.refcounted = {g_bytes + 430, 1}}, + {.refcount = &grpc_static_metadata_refcounts[43], + .data.refcounted = {g_bytes + 431, 11}}, + {.refcount = &grpc_static_metadata_refcounts[44], + .data.refcounted = {g_bytes + 442, 3}}, + {.refcount = &grpc_static_metadata_refcounts[45], + .data.refcounted = {g_bytes + 445, 3}}, + {.refcount = &grpc_static_metadata_refcounts[46], + .data.refcounted = {g_bytes + 448, 3}}, + {.refcount = &grpc_static_metadata_refcounts[47], + .data.refcounted = {g_bytes + 451, 3}}, + {.refcount = &grpc_static_metadata_refcounts[48], + .data.refcounted = {g_bytes + 454, 3}}, + {.refcount = &grpc_static_metadata_refcounts[49], + .data.refcounted = {g_bytes + 457, 14}}, + {.refcount = &grpc_static_metadata_refcounts[50], + .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &grpc_static_metadata_refcounts[51], + .data.refcounted = {g_bytes + 486, 13}}, + {.refcount = &grpc_static_metadata_refcounts[52], + .data.refcounted = {g_bytes + 499, 15}}, + {.refcount = &grpc_static_metadata_refcounts[53], + .data.refcounted = {g_bytes + 514, 13}}, + {.refcount = &grpc_static_metadata_refcounts[54], + .data.refcounted = {g_bytes + 527, 6}}, + {.refcount = &grpc_static_metadata_refcounts[55], + .data.refcounted = {g_bytes + 533, 27}}, + {.refcount = &grpc_static_metadata_refcounts[56], + .data.refcounted = {g_bytes + 560, 3}}, + {.refcount = &grpc_static_metadata_refcounts[57], + .data.refcounted = {g_bytes + 563, 5}}, + {.refcount = &grpc_static_metadata_refcounts[58], + .data.refcounted = {g_bytes + 568, 13}}, + {.refcount = &grpc_static_metadata_refcounts[59], + .data.refcounted = {g_bytes + 581, 13}}, + {.refcount = &grpc_static_metadata_refcounts[60], + .data.refcounted = {g_bytes + 594, 19}}, + {.refcount = &grpc_static_metadata_refcounts[61], + .data.refcounted = {g_bytes + 613, 16}}, + {.refcount = &grpc_static_metadata_refcounts[62], + .data.refcounted = {g_bytes + 629, 16}}, + {.refcount = &grpc_static_metadata_refcounts[63], + .data.refcounted = {g_bytes + 645, 14}}, + {.refcount = &grpc_static_metadata_refcounts[64], + .data.refcounted = {g_bytes + 659, 16}}, + {.refcount = &grpc_static_metadata_refcounts[65], + .data.refcounted = {g_bytes + 675, 13}}, + {.refcount = &grpc_static_metadata_refcounts[66], + .data.refcounted = {g_bytes + 688, 6}}, + {.refcount = &grpc_static_metadata_refcounts[67], + .data.refcounted = {g_bytes + 694, 4}}, + {.refcount = &grpc_static_metadata_refcounts[68], + .data.refcounted = {g_bytes + 698, 4}}, + {.refcount = &grpc_static_metadata_refcounts[69], + .data.refcounted = {g_bytes + 702, 6}}, + {.refcount = &grpc_static_metadata_refcounts[70], + .data.refcounted = {g_bytes + 708, 7}}, + {.refcount = &grpc_static_metadata_refcounts[71], + .data.refcounted = {g_bytes + 715, 4}}, + {.refcount = &grpc_static_metadata_refcounts[72], + .data.refcounted = {g_bytes + 719, 8}}, + {.refcount = &grpc_static_metadata_refcounts[73], + .data.refcounted = {g_bytes + 727, 17}}, + {.refcount = &grpc_static_metadata_refcounts[74], + .data.refcounted = {g_bytes + 744, 13}}, + {.refcount = &grpc_static_metadata_refcounts[75], + .data.refcounted = {g_bytes + 757, 8}}, + {.refcount = &grpc_static_metadata_refcounts[76], + .data.refcounted = {g_bytes + 765, 19}}, + {.refcount = &grpc_static_metadata_refcounts[77], + .data.refcounted = {g_bytes + 784, 13}}, + {.refcount = &grpc_static_metadata_refcounts[78], + .data.refcounted = {g_bytes + 797, 4}}, + {.refcount = &grpc_static_metadata_refcounts[79], + .data.refcounted = {g_bytes + 801, 8}}, + {.refcount = &grpc_static_metadata_refcounts[80], + .data.refcounted = {g_bytes + 809, 12}}, + {.refcount = &grpc_static_metadata_refcounts[81], + .data.refcounted = {g_bytes + 821, 18}}, + {.refcount = &grpc_static_metadata_refcounts[82], + .data.refcounted = {g_bytes + 839, 19}}, + {.refcount = &grpc_static_metadata_refcounts[83], + .data.refcounted = {g_bytes + 858, 5}}, + {.refcount = &grpc_static_metadata_refcounts[84], + .data.refcounted = {g_bytes + 863, 7}}, + {.refcount = &grpc_static_metadata_refcounts[85], + .data.refcounted = {g_bytes + 870, 7}}, + {.refcount = &grpc_static_metadata_refcounts[86], + .data.refcounted = {g_bytes + 877, 11}}, + {.refcount = &grpc_static_metadata_refcounts[87], + .data.refcounted = {g_bytes + 888, 6}}, + {.refcount = &grpc_static_metadata_refcounts[88], + .data.refcounted = {g_bytes + 894, 10}}, + {.refcount = &grpc_static_metadata_refcounts[89], + .data.refcounted = {g_bytes + 904, 25}}, + {.refcount = &grpc_static_metadata_refcounts[90], + .data.refcounted = {g_bytes + 929, 17}}, + {.refcount = &grpc_static_metadata_refcounts[91], + .data.refcounted = {g_bytes + 946, 4}}, + {.refcount = &grpc_static_metadata_refcounts[92], + .data.refcounted = {g_bytes + 950, 3}}, + {.refcount = &grpc_static_metadata_refcounts[93], + .data.refcounted = {g_bytes + 953, 16}}, + {.refcount = &grpc_static_metadata_refcounts[94], + .data.refcounted = {g_bytes + 969, 16}}, + {.refcount = &grpc_static_metadata_refcounts[95], + .data.refcounted = {g_bytes + 985, 13}}, + {.refcount = &grpc_static_metadata_refcounts[96], + .data.refcounted = {g_bytes + 998, 12}}, + {.refcount = &grpc_static_metadata_refcounts[97], + .data.refcounted = {g_bytes + 1010, 21}}, }; -int grpc_static_metadata_index(grpc_slice slice) { - static_slice_refcount *r = (static_slice_refcount *)slice.refcount; - if (slice.data.refcounted.bytes == g_bytes + r->offset && - slice.data.refcounted.length == r->length) - return (int)(r - g_refcnts); - return -1; -} - uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -347,168 +482,329 @@ grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { } grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { - {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &g_refcnts[26].base, .data.refcounted = {g_bytes + 355, 1}}}, - {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &g_refcnts[27].base, .data.refcounted = {g_bytes + 356, 1}}}, - {{.refcount = &g_refcnts[7].base, .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &g_refcnts[28].base, .data.refcounted = {g_bytes + 357, 1}}}, - {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}}, - {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}}, - {{.refcount = &g_refcnts[9].base, .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}}, - {{.refcount = &g_refcnts[5].base, .data.refcounted = {g_bytes + 36, 2}}, - {.refcount = &g_refcnts[32].base, .data.refcounted = {g_bytes + 377, 8}}}, - {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &g_refcnts[33].base, .data.refcounted = {g_bytes + 385, 16}}}, - {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &g_refcnts[34].base, .data.refcounted = {g_bytes + 401, 4}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[35].base, .data.refcounted = {g_bytes + 405, 3}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[36].base, .data.refcounted = {g_bytes + 408, 3}}}, - {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &g_refcnts[37].base, .data.refcounted = {g_bytes + 411, 4}}}, - {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &g_refcnts[38].base, .data.refcounted = {g_bytes + 415, 5}}}, - {{.refcount = &g_refcnts[4].base, .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &g_refcnts[39].base, .data.refcounted = {g_bytes + 420, 4}}}, - {{.refcount = &g_refcnts[3].base, .data.refcounted = {g_bytes + 19, 10}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &g_refcnts[40].base, .data.refcounted = {g_bytes + 424, 3}}}, - {{.refcount = &g_refcnts[1].base, .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &g_refcnts[41].base, .data.refcounted = {g_bytes + 427, 3}}}, - {{.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &g_refcnts[42].base, .data.refcounted = {g_bytes + 430, 1}}}, - {{.refcount = &g_refcnts[0].base, .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &g_refcnts[43].base, .data.refcounted = {g_bytes + 431, 11}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[44].base, .data.refcounted = {g_bytes + 442, 3}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[45].base, .data.refcounted = {g_bytes + 445, 3}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[46].base, .data.refcounted = {g_bytes + 448, 3}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[47].base, .data.refcounted = {g_bytes + 451, 3}}}, - {{.refcount = &g_refcnts[2].base, .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &g_refcnts[48].base, .data.refcounted = {g_bytes + 454, 3}}}, - {{.refcount = &g_refcnts[49].base, .data.refcounted = {g_bytes + 457, 14}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[50].base, .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &g_refcnts[51].base, .data.refcounted = {g_bytes + 486, 13}}}, - {{.refcount = &g_refcnts[52].base, .data.refcounted = {g_bytes + 499, 15}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[53].base, .data.refcounted = {g_bytes + 514, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[54].base, .data.refcounted = {g_bytes + 527, 6}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[55].base, .data.refcounted = {g_bytes + 533, 27}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[56].base, .data.refcounted = {g_bytes + 560, 3}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[57].base, .data.refcounted = {g_bytes + 563, 5}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[58].base, .data.refcounted = {g_bytes + 568, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[59].base, .data.refcounted = {g_bytes + 581, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[60].base, .data.refcounted = {g_bytes + 594, 19}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[61].base, .data.refcounted = {g_bytes + 613, 16}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[62].base, .data.refcounted = {g_bytes + 629, 16}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[63].base, .data.refcounted = {g_bytes + 645, 14}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[64].base, .data.refcounted = {g_bytes + 659, 16}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[65].base, .data.refcounted = {g_bytes + 675, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[11].base, .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[66].base, .data.refcounted = {g_bytes + 688, 6}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[67].base, .data.refcounted = {g_bytes + 694, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[68].base, .data.refcounted = {g_bytes + 698, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[69].base, .data.refcounted = {g_bytes + 702, 6}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[70].base, .data.refcounted = {g_bytes + 708, 7}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[71].base, .data.refcounted = {g_bytes + 715, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[14].base, .data.refcounted = {g_bytes + 162, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[72].base, .data.refcounted = {g_bytes + 719, 8}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[73].base, .data.refcounted = {g_bytes + 727, 17}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[74].base, .data.refcounted = {g_bytes + 744, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[75].base, .data.refcounted = {g_bytes + 757, 8}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[76].base, .data.refcounted = {g_bytes + 765, 19}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[77].base, .data.refcounted = {g_bytes + 784, 13}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[15].base, .data.refcounted = {g_bytes + 166, 8}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[16].base, .data.refcounted = {g_bytes + 174, 11}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[78].base, .data.refcounted = {g_bytes + 797, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[79].base, .data.refcounted = {g_bytes + 801, 8}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[80].base, .data.refcounted = {g_bytes + 809, 12}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[81].base, .data.refcounted = {g_bytes + 821, 18}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[82].base, .data.refcounted = {g_bytes + 839, 19}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[83].base, .data.refcounted = {g_bytes + 858, 5}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[84].base, .data.refcounted = {g_bytes + 863, 7}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[85].base, .data.refcounted = {g_bytes + 870, 7}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[86].base, .data.refcounted = {g_bytes + 877, 11}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[87].base, .data.refcounted = {g_bytes + 888, 6}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[88].base, .data.refcounted = {g_bytes + 894, 10}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[89].base, .data.refcounted = {g_bytes + 904, 25}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[90].base, .data.refcounted = {g_bytes + 929, 17}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[13].base, .data.refcounted = {g_bytes + 152, 10}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[91].base, .data.refcounted = {g_bytes + 946, 4}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[92].base, .data.refcounted = {g_bytes + 950, 3}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[93].base, .data.refcounted = {g_bytes + 953, 16}}, - {.refcount = &g_refcnts[20].base, .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[29].base, .data.refcounted = {g_bytes + 358, 8}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[31].base, .data.refcounted = {g_bytes + 370, 7}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[94].base, .data.refcounted = {g_bytes + 969, 16}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[30].base, .data.refcounted = {g_bytes + 366, 4}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[95].base, .data.refcounted = {g_bytes + 985, 13}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[96].base, .data.refcounted = {g_bytes + 998, 12}}}, - {{.refcount = &g_refcnts[10].base, .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &g_refcnts[97].base, + {{.refcount = &grpc_static_metadata_refcounts[7], + .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &grpc_static_metadata_refcounts[26], + .data.refcounted = {g_bytes + 355, 1}}}, + {{.refcount = &grpc_static_metadata_refcounts[7], + .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &grpc_static_metadata_refcounts[27], + .data.refcounted = {g_bytes + 356, 1}}}, + {{.refcount = &grpc_static_metadata_refcounts[7], + .data.refcounted = {g_bytes + 50, 11}}, + {.refcount = &grpc_static_metadata_refcounts[28], + .data.refcounted = {g_bytes + 357, 1}}}, + {{.refcount = &grpc_static_metadata_refcounts[9], + .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &grpc_static_metadata_refcounts[29], + .data.refcounted = {g_bytes + 358, 8}}}, + {{.refcount = &grpc_static_metadata_refcounts[9], + .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &grpc_static_metadata_refcounts[30], + .data.refcounted = {g_bytes + 366, 4}}}, + {{.refcount = &grpc_static_metadata_refcounts[9], + .data.refcounted = {g_bytes + 77, 13}}, + {.refcount = &grpc_static_metadata_refcounts[31], + .data.refcounted = {g_bytes + 370, 7}}}, + {{.refcount = &grpc_static_metadata_refcounts[5], + .data.refcounted = {g_bytes + 36, 2}}, + {.refcount = &grpc_static_metadata_refcounts[32], + .data.refcounted = {g_bytes + 377, 8}}}, + {{.refcount = &grpc_static_metadata_refcounts[11], + .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &grpc_static_metadata_refcounts[33], + .data.refcounted = {g_bytes + 385, 16}}}, + {{.refcount = &grpc_static_metadata_refcounts[1], + .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &grpc_static_metadata_refcounts[34], + .data.refcounted = {g_bytes + 401, 4}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[35], + .data.refcounted = {g_bytes + 405, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[36], + .data.refcounted = {g_bytes + 408, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[4], + .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &grpc_static_metadata_refcounts[37], + .data.refcounted = {g_bytes + 411, 4}}}, + {{.refcount = &grpc_static_metadata_refcounts[4], + .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &grpc_static_metadata_refcounts[38], + .data.refcounted = {g_bytes + 415, 5}}}, + {{.refcount = &grpc_static_metadata_refcounts[4], + .data.refcounted = {g_bytes + 29, 7}}, + {.refcount = &grpc_static_metadata_refcounts[39], + .data.refcounted = {g_bytes + 420, 4}}}, + {{.refcount = &grpc_static_metadata_refcounts[3], + .data.refcounted = {g_bytes + 19, 10}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[1], + .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &grpc_static_metadata_refcounts[40], + .data.refcounted = {g_bytes + 424, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[1], + .data.refcounted = {g_bytes + 5, 7}}, + {.refcount = &grpc_static_metadata_refcounts[41], + .data.refcounted = {g_bytes + 427, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[0], + .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &grpc_static_metadata_refcounts[42], + .data.refcounted = {g_bytes + 430, 1}}}, + {{.refcount = &grpc_static_metadata_refcounts[0], + .data.refcounted = {g_bytes + 0, 5}}, + {.refcount = &grpc_static_metadata_refcounts[43], + .data.refcounted = {g_bytes + 431, 11}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[44], + .data.refcounted = {g_bytes + 442, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[45], + .data.refcounted = {g_bytes + 445, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[46], + .data.refcounted = {g_bytes + 448, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[47], + .data.refcounted = {g_bytes + 451, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[2], + .data.refcounted = {g_bytes + 12, 7}}, + {.refcount = &grpc_static_metadata_refcounts[48], + .data.refcounted = {g_bytes + 454, 3}}}, + {{.refcount = &grpc_static_metadata_refcounts[49], + .data.refcounted = {g_bytes + 457, 14}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[50], + .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[50], + .data.refcounted = {g_bytes + 471, 15}}, + {.refcount = &grpc_static_metadata_refcounts[51], + .data.refcounted = {g_bytes + 486, 13}}}, + {{.refcount = &grpc_static_metadata_refcounts[52], + .data.refcounted = {g_bytes + 499, 15}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[53], + .data.refcounted = {g_bytes + 514, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[54], + .data.refcounted = {g_bytes + 527, 6}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[55], + .data.refcounted = {g_bytes + 533, 27}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[56], + .data.refcounted = {g_bytes + 560, 3}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[57], + .data.refcounted = {g_bytes + 563, 5}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[58], + .data.refcounted = {g_bytes + 568, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[59], + .data.refcounted = {g_bytes + 581, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[60], + .data.refcounted = {g_bytes + 594, 19}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[61], + .data.refcounted = {g_bytes + 613, 16}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[62], + .data.refcounted = {g_bytes + 629, 16}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[63], + .data.refcounted = {g_bytes + 645, 14}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[64], + .data.refcounted = {g_bytes + 659, 16}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[65], + .data.refcounted = {g_bytes + 675, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[11], + .data.refcounted = {g_bytes + 110, 12}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[66], + .data.refcounted = {g_bytes + 688, 6}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[67], + .data.refcounted = {g_bytes + 694, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[68], + .data.refcounted = {g_bytes + 698, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[69], + .data.refcounted = {g_bytes + 702, 6}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[70], + .data.refcounted = {g_bytes + 708, 7}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[71], + .data.refcounted = {g_bytes + 715, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[14], + .data.refcounted = {g_bytes + 162, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[72], + .data.refcounted = {g_bytes + 719, 8}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[73], + .data.refcounted = {g_bytes + 727, 17}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[74], + .data.refcounted = {g_bytes + 744, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[75], + .data.refcounted = {g_bytes + 757, 8}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[76], + .data.refcounted = {g_bytes + 765, 19}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[77], + .data.refcounted = {g_bytes + 784, 13}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[15], + .data.refcounted = {g_bytes + 166, 8}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[16], + .data.refcounted = {g_bytes + 174, 11}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[78], + .data.refcounted = {g_bytes + 797, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[79], + .data.refcounted = {g_bytes + 801, 8}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[80], + .data.refcounted = {g_bytes + 809, 12}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[81], + .data.refcounted = {g_bytes + 821, 18}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[82], + .data.refcounted = {g_bytes + 839, 19}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[83], + .data.refcounted = {g_bytes + 858, 5}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[84], + .data.refcounted = {g_bytes + 863, 7}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[85], + .data.refcounted = {g_bytes + 870, 7}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[86], + .data.refcounted = {g_bytes + 877, 11}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[87], + .data.refcounted = {g_bytes + 888, 6}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[88], + .data.refcounted = {g_bytes + 894, 10}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[89], + .data.refcounted = {g_bytes + 904, 25}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[90], + .data.refcounted = {g_bytes + 929, 17}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[13], + .data.refcounted = {g_bytes + 152, 10}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[91], + .data.refcounted = {g_bytes + 946, 4}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[92], + .data.refcounted = {g_bytes + 950, 3}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[93], + .data.refcounted = {g_bytes + 953, 16}}, + {.refcount = &grpc_static_metadata_refcounts[20], + .data.refcounted = {g_bytes + 227, 0}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[29], + .data.refcounted = {g_bytes + 358, 8}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[31], + .data.refcounted = {g_bytes + 370, 7}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[94], + .data.refcounted = {g_bytes + 969, 16}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[30], + .data.refcounted = {g_bytes + 366, 4}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[95], + .data.refcounted = {g_bytes + 985, 13}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[96], + .data.refcounted = {g_bytes + 998, 12}}}, + {{.refcount = &grpc_static_metadata_refcounts[10], + .data.refcounted = {g_bytes + 90, 20}}, + {.refcount = &grpc_static_metadata_refcounts[97], .data.refcounted = {g_bytes + 1010, 21}}}, }; #define BATCH_PHASHLEN 0x10 diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 82af8926331..e03bf245ff7 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -249,7 +249,18 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; bool grpc_is_static_metadata_string(grpc_slice slice); -int grpc_static_metadata_index(grpc_slice slice); +extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable; +extern grpc_slice_refcount + grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT]; +bool grpc_is_static_metadata_string(grpc_slice slice) { + return slice.refcount != NULL && + slice.refcount->vtable == &grpc_static_metadata_vtable; +} + +inline int grpc_static_metadata_index(grpc_slice slice) { + return (int)(slice.refcount - grpc_static_metadata_refcounts); +} + #define GRPC_STATIC_MDELEM_COUNT 81 extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index a0b06edd476..027719fb980 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -331,7 +331,7 @@ for i, elem in enumerate(all_strs): id2strofs[i] = str_ofs str_ofs += len(elem); def slice_def(i): - return '{.refcount = &g_refcnts[%d].base, .data.refcounted = {g_bytes+%d, %d}}' % (i, id2strofs[i], len(all_strs[i])) + return '{.refcount = &grpc_static_metadata_refcounts[%d], .data.refcounted = {g_bytes+%d, %d}}' % (i, id2strofs[i], len(all_strs[i])) # validate configuration for elem in METADATA_BATCH_CALLOUTS: @@ -349,29 +349,29 @@ print >>C, 'static uint8_t g_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in print >>C print >>C, 'static void static_ref(void *unused) {}' print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' -print >>C, 'static const grpc_slice_refcount_vtable static_vtable = {static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash};'; -print >>C, 'typedef struct { grpc_slice_refcount base; const uint16_t offset; const uint16_t length; } static_slice_refcount;' -print >>C, 'static static_slice_refcount g_refcnts[GRPC_STATIC_MDSTR_COUNT] = {' +print >>C, 'static const grpc_slice_refcount_vtable static_sub_vtable = {static_ref, static_unref, grpc_slice_default_eq_impl, grpc_slice_default_hash_impl};'; +print >>H, 'extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable;'; +print >>C, 'const grpc_slice_refcount_vtable grpc_static_metadata_vtable = {static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash};'; +print >>C, 'static grpc_slice_refcount static_sub_refcnt = {&static_sub_vtable, &static_sub_refcnt};'; +print >>H, 'extern grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT];' +print >>C, 'grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = {' for i, elem in enumerate(all_strs): - print >>C, ' {{&static_vtable}, %d, %d},' % (id2strofs[i], len(elem)) + print >>C, ' {&grpc_static_metadata_vtable, &static_sub_refcnt},' print >>C, '};' print >>C -print >>C, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' -print >>C, ' return slice.refcount != NULL && slice.refcount->vtable == &static_vtable;' -print >>C, '}' -print >>C +print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' +print >>H, ' return slice.refcount != NULL && slice.refcount->vtable == &grpc_static_metadata_vtable;' +print >>H, '}' +print >>H print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' for i, elem in enumerate(all_strs): print >>C, slice_def(i) + ',' print >>C, '};' print >>C -print >>H, 'int grpc_static_metadata_index(grpc_slice slice);' -print >>C, 'int grpc_static_metadata_index(grpc_slice slice) {' -print >>C, ' static_slice_refcount *r = (static_slice_refcount *)slice.refcount;' -print >>C, ' if (slice.data.refcounted.bytes == g_bytes + r->offset && slice.data.refcounted.length == r->length) return (int)(r - g_refcnts);' -print >>C, ' return -1;' -print >>C, '}' -print >>C +print >>H, 'inline int grpc_static_metadata_index(grpc_slice slice) {' +print >>H, ' return (int)(slice.refcount - grpc_static_metadata_refcounts);' +print >>H, '}' +print >>H print >>D, '# hpack fuzzing dictionary' for i, elem in enumerate(all_strs): From a82d2a36cf2b03655ca1bbe158a6977888da8235 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:13:46 -0800 Subject: [PATCH 048/261] Fix compile, make slice.c respect sub_refcount --- src/core/lib/slice/slice.c | 11 +++++++---- src/core/lib/slice/slice_intern.c | 12 ++++++------ src/core/lib/transport/metadata.c | 6 +++--- src/core/lib/transport/static_metadata.c | 4 ++-- src/core/lib/transport/static_metadata.h | 14 +++++--------- tools/codegen/core/gen_static_metadata.py | 16 ++++++---------- 6 files changed, 29 insertions(+), 34 deletions(-) diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 8188ba9b03d..aecee88dbf0 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -43,7 +43,7 @@ grpc_slice grpc_empty_slice(void) { grpc_slice out; - out.refcount = 0; + out.refcount = NULL; out.data.inlined.length = 0; return out; } @@ -129,6 +129,7 @@ grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, new_slice_refcount *rc = gpr_malloc(sizeof(new_slice_refcount)); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_slice_vtable; + rc->rc.sub_refcount = &rc->rc; rc->user_destroy = destroy; rc->user_data = user_data; @@ -177,6 +178,7 @@ grpc_slice grpc_slice_new_with_len(void *p, size_t len, gpr_malloc(sizeof(new_with_len_slice_refcount)); gpr_ref_init(&rc->refs, 1); rc->rc.vtable = &new_with_len_vtable; + rc->rc.sub_refcount = &rc->rc; rc->user_destroy = destroy; rc->user_data = p; rc->user_length = len; @@ -238,6 +240,7 @@ grpc_slice grpc_slice_malloc(size_t length) { gpr_ref_init(&rc->refs, 1); rc->base.vtable = &malloc_vtable; + rc->base.sub_refcount = &rc->base; /* Build up the slice to be returned. */ /* The slices refcount points back to the allocated block. */ @@ -264,7 +267,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) { GPR_ASSERT(source.data.refcounted.length >= end); /* Build the result */ - subset.refcount = source.refcount; + subset.refcount = source.refcount->sub_refcount; /* Point into the source array */ subset.data.refcounted.bytes = source.data.refcounted.bytes + begin; subset.data.refcounted.length = end - begin; @@ -317,7 +320,7 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { tail_length); } else { /* Build the result */ - tail.refcount = source->refcount; + tail.refcount = source->refcount->sub_refcount; /* Bump the refcount */ tail.refcount->vtable->ref(tail.refcount); /* Point into the source array */ @@ -355,7 +358,7 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { GPR_ASSERT(source->data.refcounted.length >= split); /* Build the result */ - head.refcount = source->refcount; + head.refcount = source->refcount->sub_refcount; /* Bump the refcount */ head.refcount->vtable->ref(head.refcount); /* Point into the source array */ diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 3cae8a98f34..753bdccbe56 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -176,7 +176,7 @@ uint32_t grpc_slice_default_hash_impl(grpc_slice s) { } uint32_t grpc_static_slice_hash(grpc_slice s) { - int id = grpc_static_metadata_index(s); + int id = GRPC_STATIC_METADATA_INDEX(s); if (id == -1) { return grpc_slice_default_hash_impl(s); } @@ -184,8 +184,8 @@ uint32_t grpc_static_slice_hash(grpc_slice s) { } int grpc_static_slice_eq(grpc_slice a, grpc_slice b) { - int id_a = grpc_static_metadata_index(a); - int id_b = grpc_static_metadata_index(b); + int id_a = GRPC_STATIC_METADATA_INDEX(a); + int id_b = GRPC_STATIC_METADATA_INDEX(b); if (id_a == -1 || id_b == -1) { return grpc_slice_default_eq_impl(a, b); } @@ -198,7 +198,7 @@ uint32_t grpc_slice_hash(grpc_slice s) { } void grpc_slice_static_intern(grpc_slice *slice) { - if (grpc_is_static_metadata_string(*slice)) { + if (GRPC_IS_STATIC_METADATA_STRING(*slice)) { return; } @@ -217,11 +217,11 @@ void grpc_slice_static_intern(grpc_slice *slice) { bool grpc_slice_is_interned(grpc_slice slice) { return (slice.refcount && slice.refcount->vtable == &interned_slice_vtable) || - grpc_is_static_metadata_string(slice); + GRPC_IS_STATIC_METADATA_STRING(slice); } grpc_slice grpc_slice_intern(grpc_slice slice) { - if (grpc_is_static_metadata_string(slice)) { + if (GRPC_IS_STATIC_METADATA_STRING(slice)) { return slice; } diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 650f6cc088f..ce5f85b40ca 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -260,10 +260,10 @@ grpc_mdelem grpc_mdelem_create( return GRPC_MAKE_MDELEM(allocated, GRPC_MDELEM_STORAGE_ALLOCATED); } - if (grpc_is_static_metadata_string(key) && - grpc_is_static_metadata_string(value)) { + if (GRPC_IS_STATIC_METADATA_STRING(key) && + GRPC_IS_STATIC_METADATA_STRING(value)) { grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( - grpc_static_metadata_index(key), grpc_static_metadata_index(value)); + GRPC_STATIC_METADATA_INDEX(key), GRPC_STATIC_METADATA_INDEX(value)); if (!GRPC_MDISNULL(static_elem)) { return static_elem; } diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 13a0fa37e05..588c0986dd1 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -832,8 +832,8 @@ static const uint8_t batch_hash_to_idx[] = { 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) { - if (!grpc_is_static_metadata_string(slice)) return GRPC_BATCH_CALLOUTS_COUNT; - uint32_t idx = (uint32_t)grpc_static_metadata_index(slice); + if (!GRPC_IS_STATIC_METADATA_STRING(slice)) return GRPC_BATCH_CALLOUTS_COUNT; + uint32_t idx = (uint32_t)GRPC_STATIC_METADATA_INDEX(slice); uint32_t hash = batch_phash(idx); if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && batch_hash_to_idx[hash] == idx) diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index e03bf245ff7..c9cceeb9a6f 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -247,19 +247,15 @@ extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; #define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ (grpc_static_slice_table[97]) -bool grpc_is_static_metadata_string(grpc_slice slice); - extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable; extern grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT]; -bool grpc_is_static_metadata_string(grpc_slice slice) { - return slice.refcount != NULL && - slice.refcount->vtable == &grpc_static_metadata_vtable; -} +#define GRPC_IS_STATIC_METADATA_STRING(slice) \ + ((slice).refcount != NULL && \ + (slice).refcount->vtable == &grpc_static_metadata_vtable) -inline int grpc_static_metadata_index(grpc_slice slice) { - return (int)(slice.refcount - grpc_static_metadata_refcounts); -} +#define GRPC_STATIC_METADATA_INDEX(static_slice) \ + ((int)((static_slice).refcount - grpc_static_metadata_refcounts)) #define GRPC_STATIC_MDELEM_COUNT 81 extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 027719fb980..7d363a9af2e 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -343,8 +343,6 @@ for i, elem in enumerate(all_strs): print >>H, '/* "%s" */' % elem print >>H, '#define %s (grpc_static_slice_table[%d])' % (mangle(elem).upper(), i) print >>H -print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice);' -print >>H print >>C, 'static uint8_t g_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in ''.join(all_strs))) print >>C print >>C, 'static void static_ref(void *unused) {}' @@ -359,18 +357,16 @@ for i, elem in enumerate(all_strs): print >>C, ' {&grpc_static_metadata_vtable, &static_sub_refcnt},' print >>C, '};' print >>C -print >>H, 'bool grpc_is_static_metadata_string(grpc_slice slice) {' -print >>H, ' return slice.refcount != NULL && slice.refcount->vtable == &grpc_static_metadata_vtable;' -print >>H, '}' +print >>H, '#define GRPC_IS_STATIC_METADATA_STRING(slice) \\' +print >>H, ' ((slice).refcount != NULL && (slice).refcount->vtable == &grpc_static_metadata_vtable)' print >>H print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' for i, elem in enumerate(all_strs): print >>C, slice_def(i) + ',' print >>C, '};' print >>C -print >>H, 'inline int grpc_static_metadata_index(grpc_slice slice) {' -print >>H, ' return (int)(slice.refcount - grpc_static_metadata_refcounts);' -print >>H, '}' +print >>H, '#define GRPC_STATIC_METADATA_INDEX(static_slice) \\' +print >>H, ' ((int)((static_slice).refcount - grpc_static_metadata_refcounts))' print >>H print >>D, '# hpack fuzzing dictionary' @@ -511,8 +507,8 @@ for i, elem in enumerate( METADATA_BATCH_CALLOUTS): print >>C, 'static const uint8_t batch_hash_to_idx[] = {%s};' % ','.join('%d' % n for n in batch_hash_to_idx) print >>C print >>C, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) {' -print >>C, ' if (!grpc_is_static_metadata_string(slice)) return GRPC_BATCH_CALLOUTS_COUNT;' -print >>C, ' uint32_t idx = (uint32_t)grpc_static_metadata_index(slice);' +print >>C, ' if (!GRPC_IS_STATIC_METADATA_STRING(slice)) return GRPC_BATCH_CALLOUTS_COUNT;' +print >>C, ' uint32_t idx = (uint32_t)GRPC_STATIC_METADATA_INDEX(slice);' print >>C, ' uint32_t hash = batch_phash(idx);' print >>C, ' if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && batch_hash_to_idx[hash] == idx) return (grpc_metadata_batch_callouts_index)hash;' print >>C, ' return GRPC_BATCH_CALLOUTS_COUNT;' From c09d784591d75f64256232d441ae90f6525dc1f9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:16:44 -0800 Subject: [PATCH 049/261] Fix resource quota --- src/core/lib/iomgr/resource_quota.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c index 8622a3610c2..aa92283379e 100644 --- a/src/core/lib/iomgr/resource_quota.c +++ b/src/core/lib/iomgr/resource_quota.c @@ -374,6 +374,7 @@ static grpc_slice ru_slice_create(grpc_resource_user *resource_user, size_t size) { ru_slice_refcount *rc = gpr_malloc(sizeof(ru_slice_refcount) + size); rc->base.vtable = &ru_slice_vtable; + rc->base.sub_refcount = &rc->base; gpr_ref_init(&rc->refs, 1); rc->resource_user = resource_user; rc->size = size; From 1444596a6259d8be4f375b4a7fc50a6834a52ec3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:22:41 -0800 Subject: [PATCH 050/261] Start sketching interning refcount, fix static --- src/core/lib/slice/slice_intern.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 753bdccbe56..1e0e789e6ca 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -53,6 +53,7 @@ typedef struct interned_slice_refcount { grpc_slice_refcount base; + grpc_slice_refcount sub; size_t length; gpr_atm refcnt; uint32_t hash; @@ -176,20 +177,11 @@ uint32_t grpc_slice_default_hash_impl(grpc_slice s) { } uint32_t grpc_static_slice_hash(grpc_slice s) { - int id = GRPC_STATIC_METADATA_INDEX(s); - if (id == -1) { - return grpc_slice_default_hash_impl(s); - } - return static_metadata_hash_values[id]; + return static_metadata_hash_values[GRPC_STATIC_METADATA_INDEX(s)]; } int grpc_static_slice_eq(grpc_slice a, grpc_slice b) { - int id_a = GRPC_STATIC_METADATA_INDEX(a); - int id_b = GRPC_STATIC_METADATA_INDEX(b); - if (id_a == -1 || id_b == -1) { - return grpc_slice_default_eq_impl(a, b); - } - return id_a == id_b; + return GRPC_STATIC_METADATA_INDEX(a) == GRPC_STATIC_METADATA_INDEX(b); } uint32_t grpc_slice_hash(grpc_slice s) { From 42f4f52d66a9c2542caff24dd98654f675e79067 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:23:59 -0800 Subject: [PATCH 051/261] Start sketching interning refcount --- src/core/lib/slice/slice_intern.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 1e0e789e6ca..c03e5e24b0f 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -258,6 +258,9 @@ grpc_slice grpc_slice_intern(grpc_slice slice) { s->length = GRPC_SLICE_LENGTH(slice); s->hash = hash; s->base.vtable = &interned_slice_vtable; + s->base.sub_refcount = &s->sub; + s->sub.vtable = &interned_slice_sub_vtable; + s->sub.sub_refcount = &s->sub; s->bucket_next = shard->strs[idx]; shard->strs[idx] = s; memcpy(s + 1, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); From bc99a61352019170c85af4bfd00a92f899684a7b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:28:13 -0800 Subject: [PATCH 052/261] Sketch intern sub vtable --- src/core/lib/slice/slice_intern.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index c03e5e24b0f..857a1f729dd 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -111,6 +111,15 @@ static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } +static void interned_slice_sub_ref(void *p) { + interned_slice_ref(((char *)p) - offsetof(interned_slice_refcount, sub)); +} + +static void interned_slice_sub_unref(grpc_exec_ctx *exec_ctx, void *p) { + interned_slice_unref(exec_ctx, + ((char *)p) - offsetof(interned_slice_refcount, sub)); +} + static uint32_t interned_slice_hash(grpc_slice slice) { interned_slice_refcount *s = (interned_slice_refcount *)slice.refcount; if (slice.data.refcounted.bytes == (uint8_t *)(s + 1) && @@ -135,6 +144,9 @@ static int interned_slice_eq(grpc_slice a, grpc_slice b) { static const grpc_slice_refcount_vtable interned_slice_vtable = { interned_slice_ref, interned_slice_unref, interned_slice_eq, interned_slice_hash}; +static const grpc_slice_refcount_vtable interned_slice_sub_vtable = { + interned_slice_sub_ref, interned_slice_sub_unref, + grpc_slice_default_eq_impl, grpc_slice_default_hash_impl}; static void grow_shard(slice_shard *shard) { size_t capacity = shard->capacity * 2; From 7cfa5543c276c3541e0b9cf5a61686635b8100cc Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 08:29:10 -0800 Subject: [PATCH 053/261] Sketch intern vtable condensed ops --- src/core/lib/slice/slice_intern.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index 857a1f729dd..f5e9d854972 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -122,23 +122,11 @@ static void interned_slice_sub_unref(grpc_exec_ctx *exec_ctx, void *p) { static uint32_t interned_slice_hash(grpc_slice slice) { interned_slice_refcount *s = (interned_slice_refcount *)slice.refcount; - if (slice.data.refcounted.bytes == (uint8_t *)(s + 1) && - slice.data.refcounted.length == s->length) { - return s->hash; - } - return grpc_slice_default_hash_impl(slice); + return s->hash; } static int interned_slice_eq(grpc_slice a, grpc_slice b) { - interned_slice_refcount *sa = (interned_slice_refcount *)a.refcount; - interned_slice_refcount *sb = (interned_slice_refcount *)b.refcount; - if (a.data.refcounted.bytes == (uint8_t *)(sa + 1) && - b.data.refcounted.bytes == (uint8_t *)(sb + 1)) { - return a.data.refcounted.length == b.data.refcounted.length && - a.data.refcounted.bytes == b.data.refcounted.bytes; - } else { - return grpc_slice_default_eq_impl(a, b); - } + return a.refcount == b.refcount; } static const grpc_slice_refcount_vtable interned_slice_vtable = { From 6ec8aa1c0677355269c4bb0afd5fb7e38e7a8d3b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 09:35:25 -0800 Subject: [PATCH 054/261] Simplify batch callout index calculation --- src/core/lib/transport/metadata_batch.c | 16 +++++----- src/core/lib/transport/static_metadata.c | 34 -------------------- src/core/lib/transport/static_metadata.h | 38 +++++++++++++---------- tools/codegen/core/gen_static_metadata.py | 26 ++++------------ 4 files changed, 35 insertions(+), 79 deletions(-) diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index c41d28d9f7e..25cc65d5f19 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -70,7 +70,7 @@ static void assert_valid_callouts(grpc_metadata_batch *batch) { for (grpc_linked_mdelem *l = batch->list.head; l != NULL; l = l->next) { grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); grpc_metadata_batch_callouts_index callout_idx = - grpc_batch_index_of(key_interned); + GRPC_BATCH_INDEX_OF(key_interned); if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { GPR_ASSERT(batch->idx.array[callout_idx] == l); } @@ -115,22 +115,22 @@ static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { grpc_metadata_batch_callouts_index idx = - grpc_batch_index_of(GRPC_MDKEY(storage->md)); + GRPC_BATCH_INDEX_OF(GRPC_MDKEY(storage->md)); if (idx == GRPC_BATCH_CALLOUTS_COUNT) { return GRPC_ERROR_NONE; } - if (batch->idx.array[idx] != NULL) { - return grpc_attach_md_to_error( - GRPC_ERROR_CREATE("Unallowed duplicate metadata"), storage->md); + if (batch->idx.array[idx] == NULL) { + batch->idx.array[idx] = storage; + return GRPC_ERROR_NONE; } - batch->idx.array[idx] = storage; - return GRPC_ERROR_NONE; + return grpc_attach_md_to_error( + GRPC_ERROR_CREATE("Unallowed duplicate metadata"), storage->md); } static void maybe_unlink_callout(grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { grpc_metadata_batch_callouts_index idx = - grpc_batch_index_of(GRPC_MDKEY(storage->md)); + GRPC_BATCH_INDEX_OF(GRPC_MDKEY(storage->md)); if (idx == GRPC_BATCH_CALLOUTS_COUNT) { return; } diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 588c0986dd1..abd5a91eff3 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -807,39 +807,5 @@ grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { {.refcount = &grpc_static_metadata_refcounts[97], .data.refcounted = {g_bytes + 1010, 21}}}, }; -#define BATCH_PHASHLEN 0x10 -#define BATCH_PHASHNKEYS 17 -#define BATCH_PHASHRANGE 32 -#define BATCH_PHASHSALT 0x9e3779b9 - -static const uint8_t batch_tab[] = { - 0, 13, 0, 13, 0, 13, 0, 13, 0, 13, 0, 15, 0, 13, 0, 23, -}; - -static uint32_t batch_phash(uint32_t val) { - val += (uint32_t)0; - - uint32_t a, b, rsl; - - b = (val & 0xf); - a = ((val << 27) >> 28); - rsl = (a ^ batch_tab[b]); - return rsl; -} - -static const uint8_t batch_hash_to_idx[] = { - 0, 2, 4, 6, 8, 10, 12, 14, 16, 9, 11, 13, 3, 1, 7, 5, - 15, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; - -grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) { - if (!GRPC_IS_STATIC_METADATA_STRING(slice)) return GRPC_BATCH_CALLOUTS_COUNT; - uint32_t idx = (uint32_t)GRPC_STATIC_METADATA_INDEX(slice); - uint32_t hash = batch_phash(idx); - if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && - batch_hash_to_idx[hash] == idx) - return (grpc_metadata_batch_callouts_index)hash; - return GRPC_BATCH_CALLOUTS_COUNT; -} - const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 74, 75, 76, 77, 78, 79, 80}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index c9cceeb9a6f..e782a1f1c37 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -507,22 +507,22 @@ extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b); typedef enum { GRPC_BATCH_PATH, + GRPC_BATCH_METHOD, GRPC_BATCH_STATUS, + GRPC_BATCH_AUTHORITY, GRPC_BATCH_SCHEME, + GRPC_BATCH_TE, GRPC_BATCH_GRPC_MESSAGE, + GRPC_BATCH_GRPC_STATUS, GRPC_BATCH_GRPC_PAYLOAD_BIN, - GRPC_BATCH_GRPC_ACCEPT_ENCODING, - GRPC_BATCH_GRPC_INTERNAL_ENCODING_REQUEST, - GRPC_BATCH_HOST, - GRPC_BATCH_LB_COST_BIN, GRPC_BATCH_GRPC_ENCODING, + GRPC_BATCH_GRPC_ACCEPT_ENCODING, GRPC_BATCH_CONTENT_TYPE, + GRPC_BATCH_GRPC_INTERNAL_ENCODING_REQUEST, GRPC_BATCH_USER_AGENT, - GRPC_BATCH_AUTHORITY, - GRPC_BATCH_METHOD, - GRPC_BATCH_GRPC_STATUS, - GRPC_BATCH_TE, + GRPC_BATCH_HOST, GRPC_BATCH_LB_TOKEN, + GRPC_BATCH_LB_COST_BIN, GRPC_BATCH_CALLOUTS_COUNT } grpc_metadata_batch_callouts_index; @@ -530,26 +530,30 @@ typedef union { struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT]; struct { struct grpc_linked_mdelem *path; + struct grpc_linked_mdelem *method; struct grpc_linked_mdelem *status; + struct grpc_linked_mdelem *authority; struct grpc_linked_mdelem *scheme; + struct grpc_linked_mdelem *te; struct grpc_linked_mdelem *grpc_message; + struct grpc_linked_mdelem *grpc_status; struct grpc_linked_mdelem *grpc_payload_bin; - struct grpc_linked_mdelem *grpc_accept_encoding; - struct grpc_linked_mdelem *grpc_internal_encoding_request; - struct grpc_linked_mdelem *host; - struct grpc_linked_mdelem *lb_cost_bin; struct grpc_linked_mdelem *grpc_encoding; + struct grpc_linked_mdelem *grpc_accept_encoding; struct grpc_linked_mdelem *content_type; + struct grpc_linked_mdelem *grpc_internal_encoding_request; struct grpc_linked_mdelem *user_agent; - struct grpc_linked_mdelem *authority; - struct grpc_linked_mdelem *method; - struct grpc_linked_mdelem *grpc_status; - struct grpc_linked_mdelem *te; + struct grpc_linked_mdelem *host; struct grpc_linked_mdelem *lb_token; + struct grpc_linked_mdelem *lb_cost_bin; } named; } grpc_metadata_batch_callouts; -grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice); +#define GRPC_BATCH_INDEX_OF(slice) \ + (GRPC_IS_STATIC_METADATA_STRING((slice)) \ + ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, \ + GRPC_BATCH_CALLOUTS_COUNT) \ + : GRPC_BATCH_CALLOUTS_COUNT) extern const uint8_t grpc_static_accept_encoding_metadata[8]; #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 7d363a9af2e..bd05853f117 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -220,6 +220,8 @@ def put_banner(files, banner): all_strs = list() all_elems = list() static_userdata = {} +# put metadata batch callouts first, to make the check of if a static metadata +# string is a callout trivial for elem in METADATA_BATCH_CALLOUTS: if elem not in all_strs: all_strs.append(elem) @@ -482,10 +484,7 @@ for a, b in all_elems: print >>C, '};' print >>H, 'typedef enum {' -batch_keys = [str_idx(s) for s in METADATA_BATCH_CALLOUTS] -batch_hash = perfect_hash(batch_keys, 'batch') -ordered_callouts = sorted((batch_hash['pyfunc'](str_idx(elem)), elem) for elem in METADATA_BATCH_CALLOUTS) -for _, elem in ordered_callouts: +for elem in METADATA_BATCH_CALLOUTS: print >>H, ' %s,' % mangle(elem, 'batch').upper() print >>H, ' GRPC_BATCH_CALLOUTS_COUNT' print >>H, '} grpc_metadata_batch_callouts_index;' @@ -493,27 +492,14 @@ print >>H print >>H, 'typedef union {' print >>H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];' print >>H, ' struct {' -for _, elem in ordered_callouts: +for elem in METADATA_BATCH_CALLOUTS: print >>H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower() print >>H, ' } named;' print >>H, '} grpc_metadata_batch_callouts;' print >>H -print >>H, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice);' +print >>H, '#define GRPC_BATCH_INDEX_OF(slice) \\' +print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' print >>H -print >>C, batch_hash['code'] -batch_hash_to_idx = [0] * int(batch_hash['PHASHRANGE']) -for i, elem in enumerate( METADATA_BATCH_CALLOUTS): - batch_hash_to_idx[batch_hash['pyfunc'](str_idx(elem))] = str_idx(elem) -print >>C, 'static const uint8_t batch_hash_to_idx[] = {%s};' % ','.join('%d' % n for n in batch_hash_to_idx) -print >>C -print >>C, 'grpc_metadata_batch_callouts_index grpc_batch_index_of(grpc_slice slice) {' -print >>C, ' if (!GRPC_IS_STATIC_METADATA_STRING(slice)) return GRPC_BATCH_CALLOUTS_COUNT;' -print >>C, ' uint32_t idx = (uint32_t)GRPC_STATIC_METADATA_INDEX(slice);' -print >>C, ' uint32_t hash = batch_phash(idx);' -print >>C, ' if (hash < GPR_ARRAY_SIZE(batch_hash_to_idx) && batch_hash_to_idx[hash] == idx) return (grpc_metadata_batch_callouts_index)hash;' -print >>C, ' return GRPC_BATCH_CALLOUTS_COUNT;' -print >>C, '}' -print >>C print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) From 7ce0bcdf0f2a595bfa7010ae2d04a9bfebe97b6a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 09:51:53 -0800 Subject: [PATCH 055/261] Add a test of sending MANY metadata elements --- test/cpp/microbenchmarks/bm_fullstack.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/cpp/microbenchmarks/bm_fullstack.cc b/test/cpp/microbenchmarks/bm_fullstack.cc index 3528d95b5db..cd8087e65b4 100644 --- a/test/cpp/microbenchmarks/bm_fullstack.cc +++ b/test/cpp/microbenchmarks/bm_fullstack.cc @@ -432,6 +432,8 @@ BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, Server_AddInitialMetadata, 1>); BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, Server_AddInitialMetadata, 1>); +BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, + Server_AddInitialMetadata, 100>); } // namespace testing } // namespace grpc From 28d776e9d26136c818613d7d1c04c302634213f6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 10:16:53 -0800 Subject: [PATCH 056/261] Make everything compile for clang & gcc --- .../ext/transport/chttp2/transport/hpack_parser.c | 13 +++++-------- .../ext/transport/chttp2/transport/hpack_parser.h | 4 +--- src/core/lib/transport/static_metadata.h | 9 +++++---- .../transport/chttp2/hpack_parser_fuzzer_test.c | 4 ++-- test/core/transport/chttp2/hpack_parser_test.c | 5 ++--- tools/codegen/core/gen_static_metadata.py | 2 +- 6 files changed, 16 insertions(+), 21 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 23fb1d12cad..5ff768baae2 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1615,15 +1615,14 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice_refcount *refcount, - const uint8_t *beg, - const uint8_t *end) { + grpc_slice slice) { /* TODO(ctiller): limit the distance of end from beg, and perform multiple steps in the event of a large chunk of data to limit stack space usage when no tail call optimization is available */ - p->current_slice_refcount = refcount; - grpc_error *error = p->state(exec_ctx, p, beg, end); + p->current_slice_refcount = slice.refcount; + grpc_error *error = p->state(exec_ctx, p, GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_END_PTR(slice)); p->current_slice_refcount = NULL; return error; } @@ -1659,9 +1658,7 @@ grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, if (s != NULL) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error *error = grpc_chttp2_hpack_parser_parse( - exec_ctx, parser, slice.refcount, GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_END_PTR(slice)); + grpc_error *error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index 3ab0a2a34b8..a817183eb5b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -116,9 +116,7 @@ void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice_refcount *refcount, - const uint8_t *beg, - const uint8_t *end); + grpc_slice slice); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index e782a1f1c37..7649ccd5d2d 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -549,10 +549,11 @@ typedef union { } named; } grpc_metadata_batch_callouts; -#define GRPC_BATCH_INDEX_OF(slice) \ - (GRPC_IS_STATIC_METADATA_STRING((slice)) \ - ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, \ - GRPC_BATCH_CALLOUTS_COUNT) \ +#define GRPC_BATCH_INDEX_OF(slice) \ + (GRPC_IS_STATIC_METADATA_STRING((slice)) \ + ? (grpc_metadata_batch_callouts_index)GPR_CLAMP( \ + GRPC_STATIC_METADATA_INDEX((slice)), 0, \ + GRPC_BATCH_CALLOUTS_COUNT) \ : GRPC_BATCH_CALLOUTS_COUNT) extern const uint8_t grpc_static_accept_encoding_metadata[8]; diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index cfa3c5c088d..e9ac16df2de 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -57,8 +57,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); parser.on_header = onhdr; - GRPC_ERROR_UNREF( - grpc_chttp2_hpack_parser_parse(&exec_ctx, &parser, data, data + size)); + GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( + &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index b7f35a5e445..01789c4fb40 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -76,9 +76,8 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, for (i = 0; i < nslices; i++) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse( - &exec_ctx, parser, GRPC_SLICE_START_PTR(slices[i]), - GRPC_SLICE_END_PTR(slices[i])) == GRPC_ERROR_NONE); + GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == + GRPC_ERROR_NONE); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index bd05853f117..18f71646f84 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -498,7 +498,7 @@ print >>H, ' } named;' print >>H, '} grpc_metadata_batch_callouts;' print >>H print >>H, '#define GRPC_BATCH_INDEX_OF(slice) \\' -print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' +print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' print >>H print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) From c3d0948976d6740a89f32cc40ab6d6c6c276d9c1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 10:23:15 -0800 Subject: [PATCH 057/261] Fix crash --- .../ext/transport/chttp2/transport/hpack_parser.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 5ff768baae2..22737b75e19 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -936,9 +936,9 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, const uint8_t *cur, const uint8_t *end) { grpc_error *err = on_hdr( - exec_ctx, p, grpc_mdelem_from_slices( - exec_ctx, take_string(exec_ctx, p, &p->key, false), - take_string(exec_ctx, p, &p->value, false)), + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); @@ -1006,9 +1006,9 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, const uint8_t *cur, const uint8_t *end) { grpc_error *err = on_hdr( - exec_ctx, p, grpc_mdelem_from_slices( - exec_ctx, take_string(exec_ctx, p, &p->key, false), - take_string(exec_ctx, p, &p->value, false)), + exec_ctx, p, + grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), + take_string(exec_ctx, p, &p->value, false)), 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); From f269eddd57d5b9c9e4be90c08c927077a82c3a43 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 10:45:01 -0800 Subject: [PATCH 058/261] Fix metadata refcount debug --- src/core/lib/transport/metadata.c | 49 +++++++++++++++++++------------ 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index ce5f85b40ca..537b60f739e 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -48,6 +48,7 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/murmur_hash.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" @@ -160,12 +161,14 @@ static int is_mdelem_static(grpc_mdelem e) { static void ref_md_locked(mdtab_shard *shard, interned_metadata *md DEBUG_ARGS) { #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif if (0 == gpr_atm_no_barrier_fetch_add(&md->refcnt, 1)) { gpr_atm_no_barrier_fetch_add(&shard->free_estimate, -1); @@ -301,10 +304,12 @@ grpc_mdelem grpc_mdelem_create( shard->elems[idx] = md; gpr_mu_init(&md->mu_user_data); #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(GPR_DEBUG, "ELM NEW:%p:%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt), key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif shard->count++; @@ -356,12 +361,14 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif /* we can assume the ref count is >= 1 as the application is calling this function - meaning that no adjustment to mdtab_free is necessary, @@ -374,12 +381,14 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif /* we can assume the ref count is >= 1 as the application is calling this function - meaning that no adjustment to mdtab_free is necessary, @@ -400,12 +409,14 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) - 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt) - 1, key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), grpc_slice_hash(md->value)); @@ -422,12 +433,14 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) - 1, - grpc_mdstr_as_c_string((grpc_slice)md->key), - grpc_mdstr_as_c_string((grpc_slice)md->value)); + gpr_atm_no_barrier_load(&md->refcnt) - 1, key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); #endif const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); GPR_ASSERT(prev_refcount >= 1); From de7b4676e936ed9b71e99bd0edaaf025593b2c3a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 11:13:46 -0800 Subject: [PATCH 059/261] Fix metadata batch removal ref counting --- .../load_reporting/load_reporting_filter.c | 4 ++-- src/core/lib/channel/compress_filter.c | 2 +- src/core/lib/channel/http_client_filter.c | 21 +++++++++++-------- src/core/lib/channel/http_server_filter.c | 10 ++++----- src/core/lib/surface/call.c | 8 +++---- src/core/lib/transport/metadata.c | 8 +++++++ src/core/lib/transport/metadata.h | 2 +- src/core/lib/transport/metadata_batch.c | 4 +++- src/core/lib/transport/metadata_batch.h | 3 ++- 9 files changed, 38 insertions(+), 24 deletions(-) diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 6f5dacacbb2..8d316b57269 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -86,7 +86,7 @@ static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); calld->have_initial_md_string = true; grpc_metadata_batch_remove( - calld->recv_initial_metadata, + exec_ctx, calld->recv_initial_metadata, calld->recv_initial_metadata->idx.named.lb_token); } } else { @@ -197,7 +197,7 @@ static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, GRPC_MDVALUE(op->send_trailing_metadata->idx.named.lb_cost_bin->md)); calld->have_trailing_md_string = true; grpc_metadata_batch_remove( - op->send_trailing_metadata, + exec_ctx, op->send_trailing_metadata, op->send_trailing_metadata->idx.named.lb_cost_bin); } } diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 706c8df90c4..330688c29cf 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -134,7 +134,7 @@ static grpc_error *process_send_initial_metadata( calld->has_compression_algorithm = 1; grpc_metadata_batch_remove( - initial_metadata, + exec_ctx, initial_metadata, initial_metadata->idx.named.grpc_internal_encoding_request); } else { /* If no algorithm was found in the metadata and we aren't diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 4593a9cb6d0..426377ccc4a 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -99,7 +99,7 @@ static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *b) { if (b->idx.named.status != NULL) { if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { - grpc_metadata_batch_remove(b, b->idx.named.status); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); } else { char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), GPR_DUMP_ASCII); @@ -150,7 +150,7 @@ static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, gpr_free(val); } } - grpc_metadata_batch_remove(b, b->idx.named.content_type); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); } return GRPC_ERROR_NONE; @@ -201,10 +201,11 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); } -static void remove_if_present(grpc_metadata_batch *batch, +static void remove_if_present(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_metadata_batch_callouts_index idx) { if (batch->idx.array[idx] != NULL) { - grpc_metadata_batch_remove(batch, batch->idx.array[idx]); + grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); } } @@ -303,11 +304,13 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, } } - remove_if_present(op->send_initial_metadata, GRPC_BATCH_METHOD); - remove_if_present(op->send_initial_metadata, GRPC_BATCH_SCHEME); - remove_if_present(op->send_initial_metadata, GRPC_BATCH_TE); - remove_if_present(op->send_initial_metadata, GRPC_BATCH_CONTENT_TYPE); - remove_if_present(op->send_initial_metadata, GRPC_BATCH_USER_AGENT); + remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_METHOD); + remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_SCHEME); + remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_TE); + remove_if_present(exec_ctx, op->send_initial_metadata, + GRPC_BATCH_CONTENT_TYPE); + remove_if_present(exec_ctx, op->send_initial_metadata, + GRPC_BATCH_USER_AGENT); /* Send : prefixed headers, which have to be before any application layer headers. */ diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 07c67e54c1c..911589cc517 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -128,7 +128,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), b->idx.named.method->md)); } - grpc_metadata_batch_remove(b, b->idx.named.method); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.method); } else { add_error(error_name, &error, grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), @@ -141,7 +141,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), b->idx.named.te->md)); } - grpc_metadata_batch_remove(b, b->idx.named.te); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.te); } else { add_error(error_name, &error, grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), @@ -156,7 +156,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), b->idx.named.scheme->md)); } - grpc_metadata_batch_remove(b, b->idx.named.scheme); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.scheme); } else { add_error(error_name, &error, grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), @@ -189,7 +189,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, gpr_free(val); } } - grpc_metadata_batch_remove(b, b->idx.named.content_type); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); } if (b->idx.named.path == NULL) { @@ -220,7 +220,7 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, GRPC_MDVALUE(b->idx.named.grpc_payload_bin->md))); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); - grpc_metadata_batch_remove(b, b->idx.named.grpc_payload_bin); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_payload_bin); } return error; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index d5e90ccdda1..7a7c19ad8bc 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -866,7 +866,7 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, GPR_TIMER_BEGIN("status", 0); set_status_code(call, STATUS_FROM_WIRE, decode_status(b->idx.named.grpc_status->md)); - grpc_metadata_batch_remove(b, b->idx.named.grpc_status); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); GPR_TIMER_END("status", 0); } @@ -875,7 +875,7 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, set_status_details( exec_ctx, call, STATUS_FROM_WIRE, grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); - grpc_metadata_batch_remove(b, b->idx.named.grpc_message); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); GPR_TIMER_END("status-details", 0); } } @@ -910,14 +910,14 @@ static void recv_initial_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, set_incoming_compression_algorithm( call, decode_compression(b->idx.named.grpc_encoding->md)); GPR_TIMER_END("incoming_compression_algorithm", 0); - grpc_metadata_batch_remove(b, b->idx.named.grpc_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); } if (b->idx.named.grpc_accept_encoding != NULL) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); set_encodings_accepted_by_peer(exec_ctx, call, b->idx.named.grpc_accept_encoding->md); - grpc_metadata_batch_remove(b, b->idx.named.grpc_accept_encoding); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); GPR_TIMER_END("encodings_accepted_by_peer", 0); } diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 537b60f739e..9f13c7ded69 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -260,6 +260,14 @@ grpc_mdelem grpc_mdelem_create( allocated->key = grpc_slice_ref_internal(key); allocated->value = grpc_slice_ref_internal(value); gpr_atm_rel_store(&allocated->refcnt, 1); +#ifdef GRPC_METADATA_REFCOUNT_DEBUG + char *key_str = grpc_dump_slice(allocated->key, GPR_DUMP_ASCII); + char *value_str = grpc_dump_slice(allocated->value, GPR_DUMP_ASCII); + gpr_log(GPR_DEBUG, "ELM ALLOC:%p:%zu: '%s' = '%s'", (void *)allocated, + gpr_atm_no_barrier_load(&allocated->refcnt), key_str, value_str); + gpr_free(key_str); + gpr_free(value_str); +#endif return GRPC_MAKE_MDELEM(allocated, GRPC_MDELEM_STORAGE_ALLOCATED); } diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index f4ba86c854b..aad944c9737 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -148,7 +148,7 @@ void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), void *user_data); /* Reference counting */ -//#define GRPC_METADATA_REFCOUNT_DEBUG +#define GRPC_METADATA_REFCOUNT_DEBUG #ifdef GRPC_METADATA_REFCOUNT_DEBUG #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) #define GRPC_MDELEM_UNREF(exec_ctx, s) \ diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 25cc65d5f19..a83f0e0f34e 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -228,11 +228,13 @@ static void unlink_storage(grpc_mdelem_list *list, assert_valid_list(list); } -void grpc_metadata_batch_remove(grpc_metadata_batch *batch, +void grpc_metadata_batch_remove(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { assert_valid_callouts(batch); maybe_unlink_callout(batch, storage); unlink_storage(&batch->list, storage); + GRPC_MDELEM_UNREF(exec_ctx, storage->md); assert_valid_callouts(batch); } diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index a95a8887f46..d7f6485565b 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -81,7 +81,8 @@ bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch); size_t grpc_metadata_batch_size(grpc_metadata_batch *batch); /** Remove \a storage from the batch, unreffing the mdelem contained */ -void grpc_metadata_batch_remove(grpc_metadata_batch *batch, +void grpc_metadata_batch_remove(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage); /** Substitute a new mdelem for an old value */ From cf0a2024faa29bd6f89b7bedd0571be735174f18 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 11:36:21 -0800 Subject: [PATCH 060/261] Fix slice refcounting --- src/core/lib/surface/call.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 7a7c19ad8bc..96cf7067780 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -895,8 +895,9 @@ static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, } for (grpc_linked_mdelem *l = b->list.head; l != NULL; l = l->next) { mdusr = &dest->metadata[dest->count++]; - mdusr->key = grpc_slice_ref(GRPC_MDKEY(l->md)); - mdusr->value = grpc_slice_ref(GRPC_MDVALUE(l->md)); + /* we pass back borrowed slices that are valid whilst the call is valid */ + mdusr->key = GRPC_MDKEY(l->md); + mdusr->value = GRPC_MDVALUE(l->md); } GPR_TIMER_END("publish_app_metadata", 0); } From 3a6ca82a78bc9b40955a612829d71b8eff808c58 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 11:38:43 -0800 Subject: [PATCH 061/261] Fix slice refcounting --- src/core/lib/surface/channel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 6f2a88ae681..d380df4919e 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -126,7 +126,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, channel->default_authority = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern( - grpc_slice_from_copied_string(args->args[i].value.string))); + grpc_slice_from_static_string(args->args[i].value.string))); } } else if (0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { @@ -143,7 +143,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, channel->default_authority = grpc_mdelem_from_slices( exec_ctx, GRPC_MDSTR_AUTHORITY, grpc_slice_intern( - grpc_slice_from_copied_string(args->args[i].value.string))); + grpc_slice_from_static_string(args->args[i].value.string))); } } } else if (0 == strcmp(args->args[i].key, From 83d64ee574b86a9400b2009d8030a7360d8ab3fd Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 12:53:22 -0800 Subject: [PATCH 062/261] Fix uninitialized variable --- src/core/ext/transport/chttp2/transport/hpack_parser.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 22737b75e19..6c035f27888 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1587,9 +1587,11 @@ void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, p->on_header = NULL; p->on_header_user_data = NULL; p->state = parse_begin; + p->key.data.referenced = grpc_empty_slice(); p->key.data.copied.str = NULL; p->key.data.copied.capacity = 0; p->key.data.copied.length = 0; + p->value.data.referenced = grpc_empty_slice(); p->value.data.copied.str = NULL; p->value.data.copied.capacity = 0; p->value.data.copied.length = 0; From 7e1cfe14602902f1c0d3a3fbe91d268c9f4e7487 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 13:04:34 -0800 Subject: [PATCH 063/261] Fix hpack parser string identification bug --- src/core/ext/transport/chttp2/transport/hpack_parser.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 6c035f27888..9b85026b136 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1539,8 +1539,10 @@ static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, /* check if a key represents a binary header or not */ static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { - return grpc_is_binary_header(grpc_slice_from_static_buffer( - p->key.data.copied.str, p->key.data.copied.length)); + return grpc_is_binary_header( + p->key.copied ? grpc_slice_from_static_buffer(p->key.data.copied.str, + p->key.data.copied.length) + : p->key.data.referenced); } static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, From 1e5e5ea5ebea55a2fc05060a1cbcdab4d61699cb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 13:33:59 -0800 Subject: [PATCH 064/261] Fix memory leak --- src/core/lib/surface/channel.c | 4 ++-- src/core/lib/surface/server.c | 4 ++-- src/core/lib/transport/metadata.h | 2 +- test/core/transport/metadata_test.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index d380df4919e..963db614f7a 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -270,11 +270,11 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, rc->path = grpc_mdelem_from_slices( &exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_intern(grpc_slice_from_copied_string(method))); + grpc_slice_intern(grpc_slice_from_static_string(method))); rc->authority = host ? grpc_mdelem_from_slices( &exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_intern(grpc_slice_from_copied_string(host))) + grpc_slice_intern(grpc_slice_from_static_string(host))) : GRPC_MDNULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 8b30ce4f916..a4f1b90dd40 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -1166,12 +1166,12 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, bool has_host; grpc_slice method; if (rm->host != NULL) { - host = grpc_slice_intern(grpc_slice_from_copied_string(rm->host)); + host = grpc_slice_intern(grpc_slice_from_static_string(rm->host)); has_host = true; } else { has_host = false; } - method = grpc_slice_intern(grpc_slice_from_copied_string(rm->method)); + method = grpc_slice_intern(grpc_slice_from_static_string(rm->method)); hash = GRPC_MDSTR_KV_HASH(has_host ? grpc_slice_hash(host) : 0, grpc_slice_hash(method)); for (probes = 0; chand->registered_methods[(hash + probes) % slots] diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index aad944c9737..f4ba86c854b 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -148,7 +148,7 @@ void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), void *user_data); /* Reference counting */ -#define GRPC_METADATA_REFCOUNT_DEBUG +//#define GRPC_METADATA_REFCOUNT_DEBUG #ifdef GRPC_METADATA_REFCOUNT_DEBUG #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) #define GRPC_MDELEM_UNREF(exec_ctx, s) \ diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 7b9c050a8e3..fc8b187570d 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -141,14 +141,14 @@ static void test_create_many_persistant_metadata(void) { gpr_ltoa(i, buffer); created[i] = grpc_mdelem_from_slices( &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), - grpc_slice_intern(grpc_slice_from_copied_string(buffer))); + grpc_slice_intern(grpc_slice_from_static_string(buffer))); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); md = grpc_mdelem_from_slices( &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), - grpc_slice_intern(grpc_slice_from_copied_string(buffer))); + grpc_slice_intern(grpc_slice_from_static_string(buffer))); GPR_ASSERT(grpc_mdelem_eq(md, created[i])); GRPC_MDELEM_UNREF(&exec_ctx, md); } From 74fddc2d69179a07cdaba29dfe7c99a5d7a190ea Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 13:35:58 -0800 Subject: [PATCH 065/261] Fix memory leak --- src/core/lib/surface/server.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index a4f1b90dd40..927f4478159 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -753,7 +753,6 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, } else { GRPC_ERROR_REF(error); } - GRPC_ERROR_REF(error); op_deadline = calld->recv_initial_metadata->deadline; if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) { calld->deadline = op_deadline; From 70b32393189fd29ba5805906eab6115ad626f3ce Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 14:21:05 -0800 Subject: [PATCH 066/261] Fix memory leaks --- .../transport/chttp2/transport/chttp2_transport.c | 8 ++++---- .../transport/chttp2/transport/incoming_metadata.c | 12 ++++++++---- .../transport/chttp2/transport/incoming_metadata.h | 3 ++- src/core/lib/channel/http_client_filter.c | 3 +-- src/core/lib/surface/server.c | 1 + 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 586052fdd31..3e72c7cc2ca 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1306,8 +1306,8 @@ void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx, incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE); } } - grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[0], - s->recv_initial_metadata); + grpc_chttp2_incoming_metadata_buffer_publish( + exec_ctx, &s->metadata_buffer[0], s->recv_initial_metadata); null_then_run_closure(exec_ctx, &s->recv_initial_metadata_ready, GRPC_ERROR_NONE); } @@ -1350,8 +1350,8 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, } if (s->all_incoming_byte_streams_finished && s->recv_trailing_metadata_finished != NULL) { - grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[1], - s->recv_trailing_metadata); + grpc_chttp2_incoming_metadata_buffer_publish( + exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata); grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, "recv_trailing_metadata_finished"); diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index 910afea9ca0..fd1b234b8f4 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -75,15 +75,19 @@ void grpc_chttp2_incoming_metadata_buffer_set_deadline( } void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch) { + grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, + grpc_metadata_batch *batch) { GPR_ASSERT(!buffer->published); buffer->published = 1; if (buffer->count > 0) { size_t i; for (i = 0; i < buffer->count; i++) { - GRPC_LOG_IF_ERROR( - "grpc_chttp2_incoming_metadata_buffer_publish", - grpc_metadata_batch_link_tail(batch, &buffer->elems[i])); + /* TODO(ctiller): do something better here */ + if (!GRPC_LOG_IF_ERROR( + "grpc_chttp2_incoming_metadata_buffer_publish", + grpc_metadata_batch_link_tail(batch, &buffer->elems[i]))) { + GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md); + } } } else { batch->list.head = batch->list.tail = NULL; diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index e9d07724b61..cd6dacc5bf1 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -51,7 +51,8 @@ void grpc_chttp2_incoming_metadata_buffer_init( void grpc_chttp2_incoming_metadata_buffer_destroy( grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer); void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch); + grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, + grpc_metadata_batch *batch); void grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem); diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 426377ccc4a..9fd42100202 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -179,8 +179,7 @@ static void hc_on_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, } else { GRPC_ERROR_REF(error); } - grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, - GRPC_ERROR_REF(error)); + grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, error); } static void hc_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 927f4478159..6de4ff1747d 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -1181,6 +1181,7 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, crm = &chand->registered_methods[(hash + probes) % slots]; crm->server_registered_method = rm; crm->flags = rm->flags; + crm->has_host = has_host; crm->host = host; crm->method = method; } From 5059ddf58b36f1a66e4ee1cee1486362ab8cdd1f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 14:30:05 -0800 Subject: [PATCH 067/261] Fix memory leak, uninitialized memory --- src/core/lib/surface/server.c | 5 +++++ test/core/end2end/fixtures/proxy.c | 1 + 2 files changed, 6 insertions(+) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 6de4ff1747d..72ec48f4d9e 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -750,6 +750,11 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); calld->path_set = true; calld->host_set = true; + grpc_metadata_batch_remove(exec_ctx, calld->recv_initial_metadata, + calld->recv_initial_metadata->idx.named.path); + grpc_metadata_batch_remove( + exec_ctx, calld->recv_initial_metadata, + calld->recv_initial_metadata->idx.named.authority); } else { GRPC_ERROR_REF(error); } diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index d0148937424..c592f5a4711 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -308,6 +308,7 @@ static void on_p2s_status(void *arg, int success) { op.data.send_status_from_server.trailing_metadata = pc->p2s_trailing_metadata.metadata; op.data.send_status_from_server.status = pc->p2s_status; + op.data.send_status_from_server.status_details = &pc->p2s_status_details; refpc(pc, "on_c2p_sent_status"); err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_sent_status, pc), NULL); From e150fff57ef947998ce8f45da112ed45ae01bacb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 14:47:11 -0800 Subject: [PATCH 068/261] Fix some auth filtering bugs --- .../security/transport/client_auth_filter.c | 8 ++++- .../security/transport/server_auth_filter.c | 23 +++++++------- src/core/lib/transport/metadata_batch.c | 30 +++++++++++++++++++ src/core/lib/transport/metadata_batch.h | 18 +++++++++++ 4 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index 43054bcfb4b..80fdbe68eb3 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -102,7 +102,13 @@ static void bubble_up_error(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_call_next_op(exec_ctx, elem, &calld->op); } -static void add_error(grpc_error **combined, grpc_error *error) { abort(); } +static void add_error(grpc_error **combined, grpc_error *error) { + if (error == GRPC_ERROR_NONE) return; + if (*combined == GRPC_ERROR_NONE) { + *combined = GRPC_ERROR_CREATE("Client auth metadata plugin error"); + } + *combined = grpc_error_add_child(*combined, error); +} static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_credentials_md *md_elems, diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index ed9d92b74e6..34f5bbf8f47 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -83,9 +83,9 @@ static grpc_metadata_array metadata_batch_to_md_array( return result; } -#if 0 -static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, - grpc_mdelem md) { +static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; size_t i; @@ -93,11 +93,10 @@ static grpc_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, const grpc_metadata *consumed_md = &calld->consumed_md[i]; if (grpc_slice_eq(GRPC_MDKEY(md), consumed_md->key) && grpc_slice_eq(GRPC_MDVALUE(md), consumed_md->value)) - return GRPC_MDNULL; + return GRPC_FILTERED_REMOVE(); } - return md; + return GRPC_FILTERED_MDELEM(md); } -#endif static void destroy_op(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { gpr_free(arg); @@ -122,12 +121,12 @@ static void on_md_processing_done( if (status == GRPC_STATUS_OK) { calld->consumed_md = consumed_md; calld->num_consumed_md = num_consumed_md; -#if 0 - grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, - remove_consumed_md, elem); -#else - if (num_consumed_md) abort(); -#endif + /* TODO(ctiller): propagate error */ + GRPC_LOG_IF_ERROR( + "grpc_metadata_batch_filter", + grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, + remove_consumed_md, elem, + "Response metadata filtering error")); grpc_metadata_array_destroy(&calld->md); grpc_exec_ctx_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE, NULL); } else { diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index a83f0e0f34e..07b0dd37256 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -285,3 +285,33 @@ size_t grpc_metadata_batch_size(grpc_metadata_batch *batch) { } return size; } + +static void add_error(grpc_error **composite, grpc_error *error, + const char *composite_error_string) { + if (error == GRPC_ERROR_NONE) return; + if (*composite == GRPC_ERROR_NONE) { + *composite = GRPC_ERROR_CREATE(composite_error_string); + } + *composite = grpc_error_add_child(*composite, error); +} + +grpc_error *grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, + grpc_metadata_batch_filter_func func, + void *user_data, + const char *composite_error_string) { + grpc_linked_mdelem *l = batch->list.head; + grpc_error *error = GRPC_ERROR_NONE; + while (l) { + grpc_linked_mdelem *next = l->next; + grpc_filtered_mdelem new = func(exec_ctx, user_data, l->md); + add_error(&error, new.error, composite_error_string); + if (GRPC_MDISNULL(new.md)) { + grpc_metadata_batch_remove(exec_ctx, batch, l); + } else if (new.md.payload != l->md.payload) { + grpc_metadata_batch_substitute(exec_ctx, batch, l, new.md); + } + l = next; + } + return error; +} diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index d7f6485565b..894a927d3e9 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -133,6 +133,24 @@ grpc_error *grpc_metadata_batch_add_tail( grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md); +typedef struct { + grpc_error *error; + grpc_mdelem md; +} grpc_filtered_mdelem; + +#define GRPC_FILTERED_ERROR(error) \ + ((grpc_filtered_mdelem){(error), GRPC_MDNULL}) +#define GRPC_FILTERED_MDELEM(md) ((grpc_filtered_mdelem){GRPC_ERROR_NONE, (md)}) +#define GRPC_FILTERED_REMOVE() \ + ((grpc_filtered_mdelem){GRPC_ERROR_NONE, GRPC_MDNULL}) + +typedef grpc_filtered_mdelem (*grpc_metadata_batch_filter_func)( + grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem elem); +grpc_error *grpc_metadata_batch_filter( + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, + grpc_metadata_batch_filter_func func, void *user_data, + const char *composite_error_string) GRPC_MUST_USE_RESULT; + #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd); #else From b1bb50ecc133a6887009175e0c0265962d03cd96 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 15:07:43 -0800 Subject: [PATCH 069/261] Fix correctness, mem leak --- src/core/ext/load_reporting/load_reporting_filter.c | 11 +++++++++-- src/core/lib/slice/slice.c | 3 +++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 8d316b57269..e18c7afe270 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -138,8 +138,15 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, calld->service_method}; */ - grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); - grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); + if (calld->have_initial_md_string) { + grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); + } + if (calld->have_trailing_md_string) { + grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); + } + if (calld->have_service_method) { + grpc_slice_unref_internal(exec_ctx, calld->service_method); + } } /* Constructor for channel_data */ diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index aecee88dbf0..f0ad9f48814 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -327,6 +327,7 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { tail.data.refcounted.bytes = source->data.refcounted.bytes + split; tail.data.refcounted.length = tail_length; } + source->refcount = source->refcount->sub_refcount; source->data.refcounted.length = split; } @@ -352,6 +353,7 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { head.refcount = NULL; head.data.inlined.length = (uint8_t)split; memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); + source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; source->data.refcounted.length -= split; } else { @@ -364,6 +366,7 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { /* Point into the source array */ head.data.refcounted.bytes = source->data.refcounted.bytes; head.data.refcounted.length = split; + source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; source->data.refcounted.length -= split; } From ca7aeea825935b417da5ad7752ea818c0fcc98ac Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 15:11:12 -0800 Subject: [PATCH 070/261] Fix test --- test/core/slice/slice_test.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index d3d16593419..75bef28dec4 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -295,9 +295,9 @@ static void test_static_slice_copy_interning(void) { for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { grpc_slice copy = grpc_slice_dup(grpc_static_slice_table[i]); - GPR_ASSERT(!grpc_slice_is_equivalent(grpc_static_slice_table[i], copy)); - GPR_ASSERT(grpc_slice_is_equivalent(grpc_static_slice_table[i], - grpc_slice_intern(copy))); + GPR_ASSERT(grpc_static_slice_table[i].refcount != copy.refcount); + GPR_ASSERT(grpc_static_slice_table[i].refcount == + grpc_slice_intern(copy).refcount); grpc_slice_unref(copy); } From c10608f3850ab0d57f70a21f0fcf737e5d2c9875 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 15:56:17 -0800 Subject: [PATCH 071/261] Correctness, memory leak fixes --- .../security/transport/client_auth_filter.c | 24 ++++++++++++++----- .../security/transport/server_auth_filter.c | 4 ++++ test/core/end2end/fixtures/h2_oauth2.c | 6 ++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index 80fdbe68eb3..d8540b96253 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -133,12 +133,24 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, mdb = op->send_initial_metadata; grpc_error *error = GRPC_ERROR_NONE; for (i = 0; i < num_md; i++) { - add_error(&error, - grpc_metadata_batch_add_tail( - mdb, &calld->md_links[i], - grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value)))); + if (!grpc_header_key_is_legal(md_elems[i].key)) { + char *str = grpc_dump_slice(md_elems[i].key, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); + gpr_free(str); + } else if (!grpc_is_binary_header(md_elems[i].key) && + !grpc_header_nonbin_value_is_legal(md_elems[i].value)) { + char *str = + grpc_dump_slice(md_elems[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); + gpr_free(str); + } else { + add_error(&error, + grpc_metadata_batch_add_tail( + mdb, &calld->md_links[i], + grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value)))); + } } if (error == GRPC_ERROR_NONE) { grpc_call_next_op(exec_ctx, elem, op); diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 34f5bbf8f47..4433704cb97 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -127,6 +127,10 @@ static void on_md_processing_done( grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, remove_consumed_md, elem, "Response metadata filtering error")); + for (size_t i = 0; i < calld->md.count; i++) { + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); + } grpc_metadata_array_destroy(&calld->md); grpc_exec_ctx_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE, NULL); } else { diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.c index 28011be7872..33516528586 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.c @@ -74,7 +74,7 @@ static void process_oauth2_success(void *state, grpc_auth_context *ctx, grpc_process_auth_metadata_done_cb cb, void *user_data) { const grpc_metadata *oauth2 = - find_metadata(md, md_count, "Authorization", oauth2_md); + find_metadata(md, md_count, "authorization", oauth2_md); test_processor_state *s; GPR_ASSERT(state != NULL); @@ -93,7 +93,7 @@ static void process_oauth2_failure(void *state, grpc_auth_context *ctx, grpc_process_auth_metadata_done_cb cb, void *user_data) { const grpc_metadata *oauth2 = - find_metadata(md, md_count, "Authorization", oauth2_md); + find_metadata(md, md_count, "authorization", oauth2_md); test_processor_state *s; GPR_ASSERT(state != NULL); s = (test_processor_state *)state; @@ -154,7 +154,7 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); grpc_call_credentials *oauth2_creds = - grpc_md_only_test_credentials_create("Authorization", oauth2_md, 1); + grpc_md_only_test_credentials_create("authorization", oauth2_md, 1); grpc_channel_credentials *ssl_oauth2_creds = grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, From 0f97958b64a792e551aa3bde84bb8f53b04de3b4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 23 Nov 2016 15:59:05 -0800 Subject: [PATCH 072/261] Null pointer check --- src/core/lib/surface/call_log_batch.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/lib/surface/call_log_batch.c b/src/core/lib/surface/call_log_batch.c index 8f6438bc3b7..169e9673410 100644 --- a/src/core/lib/surface/call_log_batch.c +++ b/src/core/lib/surface/call_log_batch.c @@ -40,6 +40,10 @@ static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) { size_t i; + if (md == NULL) { + gpr_strvec_add(b, gpr_strdup("(nil)")); + return; + } for (i = 0; i < count; i++) { gpr_strvec_add(b, gpr_strdup("\nkey=")); gpr_strvec_add(b, grpc_dump_slice(md[i].key, GPR_DUMP_ASCII)); From a0ed373d3cb6d93b55ebe753b276c2ddf1fc7b65 Mon Sep 17 00:00:00 2001 From: Garrett Casto Date: Mon, 7 Nov 2016 20:36:31 -0800 Subject: [PATCH 073/261] Change interface --- BUILD | 2 +- build.yaml | 2 +- .../client/secure/cronet_channel_create.c | 2 +- .../cronet/transport/cronet_api_dummy.c | 29 +-- .../cronet/transport/cronet_transport.c | 116 ++++----- src/objective-c/GRPCClient/GRPCCall+Cronet.h | 6 +- src/objective-c/GRPCClient/GRPCCall+Cronet.m | 6 +- .../GRPCClient/private/GRPCChannel.m | 4 +- third_party/Cronet/bidirectional_stream_c.h | 246 ++++++++++++++++++ .../objective_c/Cronet/cronet_c_for_grpc.h | 202 -------------- tools/run_tests/sources_and_headers.json | 2 +- 11 files changed, 330 insertions(+), 287 deletions(-) create mode 100644 third_party/Cronet/bidirectional_stream_c.h delete mode 100644 third_party/objective_c/Cronet/cronet_c_for_grpc.h diff --git a/BUILD b/BUILD index f80e5f06646..955cb73af5e 100644 --- a/BUILD +++ b/BUILD @@ -687,7 +687,7 @@ cc_library( "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", "src/core/lib/transport/transport_impl.h", - "third_party/objective_c/Cronet/cronet_c_for_grpc.h", + "third_party/Cronet/bidirectional_stream_c.h", "src/core/ext/transport/chttp2/transport/bin_decoder.h", "src/core/ext/transport/chttp2/transport/bin_encoder.h", "src/core/ext/transport/chttp2/transport/chttp2_transport.h", diff --git a/build.yaml b/build.yaml index 407b50ca7b9..24f34ad77f8 100644 --- a/build.yaml +++ b/build.yaml @@ -657,7 +657,7 @@ filegroups: - include/grpc/grpc_security.h - include/grpc/grpc_security_constants.h headers: - - third_party/objective_c/Cronet/cronet_c_for_grpc.h + - third_party/Cronet/bidirectional_stream_c.h src: - src/core/ext/transport/cronet/client/secure/cronet_channel_create.c - src/core/ext/transport/cronet/transport/cronet_api_dummy.c diff --git a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.c b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.c index df1acddcc08..477cf07f45d 100644 --- a/src/core/ext/transport/cronet/client/secure/cronet_channel_create.c +++ b/src/core/ext/transport/cronet/client/secure/cronet_channel_create.c @@ -60,7 +60,7 @@ GRPCAPI grpc_channel *grpc_cronet_secure_channel_create( ct->host = gpr_malloc(strlen(target) + 1); strcpy(ct->host, target); gpr_log(GPR_DEBUG, - "grpc_create_cronet_transport: cronet_engine = %p, target=%s", engine, + "grpc_create_cronet_transport: stream_engine = %p, target=%s", engine, ct->host); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; diff --git a/src/core/ext/transport/cronet/transport/cronet_api_dummy.c b/src/core/ext/transport/cronet/transport/cronet_api_dummy.c index 687026c9fde..1c4253f43fe 100644 --- a/src/core/ext/transport/cronet/transport/cronet_api_dummy.c +++ b/src/core/ext/transport/cronet/transport/cronet_api_dummy.c @@ -38,48 +38,47 @@ library, so we can build it in all environments */ #include -#include "third_party/objective_c/Cronet/cronet_c_for_grpc.h" +#include "third_party/Cronet/bidirectional_stream_c.h" #ifdef GRPC_COMPILE_WITH_CRONET /* link with the real CRONET library in the build system */ #else /* Dummy implementation of cronet API just to test for build-ability */ -cronet_bidirectional_stream* cronet_bidirectional_stream_create( - cronet_engine* engine, void* annotation, - cronet_bidirectional_stream_callback* callback) { +bidirectional_stream* bidirectional_stream_create( + stream_engine* engine, void* annotation, + bidirectional_stream_callback* callback) { GPR_ASSERT(0); return NULL; } -int cronet_bidirectional_stream_destroy(cronet_bidirectional_stream* stream) { +int bidirectional_stream_destroy(bidirectional_stream* stream) { GPR_ASSERT(0); return 0; } -int cronet_bidirectional_stream_start( - cronet_bidirectional_stream* stream, const char* url, int priority, - const char* method, const cronet_bidirectional_stream_header_array* headers, +int bidirectional_stream_start( + bidirectional_stream* stream, const char* url, int priority, + const char* method, const bidirectional_stream_header_array* headers, bool end_of_stream) { GPR_ASSERT(0); return 0; } -int cronet_bidirectional_stream_read(cronet_bidirectional_stream* stream, - char* buffer, int capacity) { +int bidirectional_stream_read(bidirectional_stream* stream, + char* buffer, int capacity) { GPR_ASSERT(0); return 0; } -int cronet_bidirectional_stream_write(cronet_bidirectional_stream* stream, - const char* buffer, int count, - bool end_of_stream) { +int bidirectional_stream_write(bidirectional_stream* stream, + const char* buffer, int count, + bool end_of_stream) { GPR_ASSERT(0); return 0; } -int cronet_bidirectional_stream_cancel(cronet_bidirectional_stream* stream) { +void bidirectional_stream_cancel(bidirectional_stream* stream) { GPR_ASSERT(0); - return 0; } #endif /* GRPC_COMPILE_WITH_CRONET */ diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index a4c110101ec..28c4fbe9fe1 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -49,7 +49,7 @@ #include "src/core/lib/transport/metadata_batch.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/transport_impl.h" -#include "third_party/objective_c/Cronet/cronet_c_for_grpc.h" +#include "third_party/Cronet/bidirectional_stream_c.h" #define GRPC_HEADER_SIZE_IN_BYTES 5 @@ -86,19 +86,19 @@ enum e_op_id { /* Cronet callbacks. See cronet_c_for_grpc.h for documentation for each. */ -static void on_request_headers_sent(cronet_bidirectional_stream *); +static void on_request_headers_sent(bidirectional_stream *); static void on_response_headers_received( - cronet_bidirectional_stream *, - const cronet_bidirectional_stream_header_array *, const char *); -static void on_write_completed(cronet_bidirectional_stream *, const char *); -static void on_read_completed(cronet_bidirectional_stream *, char *, int); + bidirectional_stream *, + const bidirectional_stream_header_array *, const char *); +static void on_write_completed(bidirectional_stream *, const char *); +static void on_read_completed(bidirectional_stream *, char *, int); static void on_response_trailers_received( - cronet_bidirectional_stream *, - const cronet_bidirectional_stream_header_array *); -static void on_succeeded(cronet_bidirectional_stream *); -static void on_failed(cronet_bidirectional_stream *, int); -static void on_canceled(cronet_bidirectional_stream *); -static cronet_bidirectional_stream_callback cronet_callbacks = { + bidirectional_stream *, + const bidirectional_stream_header_array *); +static void on_succeeded(bidirectional_stream *); +static void on_failed(bidirectional_stream *, int); +static void on_canceled(bidirectional_stream *); +static bidirectional_stream_callback cronet_callbacks = { on_request_headers_sent, on_response_headers_received, on_read_completed, @@ -111,7 +111,7 @@ static cronet_bidirectional_stream_callback cronet_callbacks = { /* Cronet transport object */ struct grpc_cronet_transport { grpc_transport base; /* must be first element in this structure */ - cronet_engine *engine; + stream_engine *engine; char *host; }; typedef struct grpc_cronet_transport grpc_cronet_transport; @@ -173,8 +173,8 @@ struct stream_obj { grpc_transport_stream_op *curr_op; grpc_cronet_transport curr_ct; grpc_stream *curr_gs; - cronet_bidirectional_stream *cbs; - cronet_bidirectional_stream_header_array header_array; + bidirectional_stream *cbs; + bidirectional_stream_header_array header_array; /* Stream level state. Some state will be tracked both at stream and stream_op * level */ @@ -335,11 +335,11 @@ static void execute_from_storage(stream_obj *s) { /* Cronet callback */ -static void on_failed(cronet_bidirectional_stream *stream, int net_error) { +static void on_failed(bidirectional_stream *stream, int net_error) { CRONET_LOG(GPR_DEBUG, "on_failed(%p, %d)", stream, net_error); stream_obj *s = (stream_obj *)stream->annotation; gpr_mu_lock(&s->mu); - cronet_bidirectional_stream_destroy(s->cbs); + bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_FAILED] = true; s->cbs = NULL; if (s->header_array.headers) { @@ -358,11 +358,11 @@ static void on_failed(cronet_bidirectional_stream *stream, int net_error) { /* Cronet callback */ -static void on_canceled(cronet_bidirectional_stream *stream) { +static void on_canceled(bidirectional_stream *stream) { CRONET_LOG(GPR_DEBUG, "on_canceled(%p)", stream); stream_obj *s = (stream_obj *)stream->annotation; gpr_mu_lock(&s->mu); - cronet_bidirectional_stream_destroy(s->cbs); + bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_CANCELED] = true; s->cbs = NULL; if (s->header_array.headers) { @@ -381,11 +381,11 @@ static void on_canceled(cronet_bidirectional_stream *stream) { /* Cronet callback */ -static void on_succeeded(cronet_bidirectional_stream *stream) { +static void on_succeeded(bidirectional_stream *stream) { CRONET_LOG(GPR_DEBUG, "on_succeeded(%p)", stream); stream_obj *s = (stream_obj *)stream->annotation; gpr_mu_lock(&s->mu); - cronet_bidirectional_stream_destroy(s->cbs); + bidirectional_stream_destroy(s->cbs); s->state.state_callback_received[OP_SUCCEEDED] = true; s->cbs = NULL; free_read_buffer(s); @@ -396,7 +396,7 @@ static void on_succeeded(cronet_bidirectional_stream *stream) { /* Cronet callback */ -static void on_request_headers_sent(cronet_bidirectional_stream *stream) { +static void on_request_headers_sent(bidirectional_stream *stream) { CRONET_LOG(GPR_DEBUG, "W: on_request_headers_sent(%p)", stream); stream_obj *s = (stream_obj *)stream->annotation; gpr_mu_lock(&s->mu); @@ -415,8 +415,8 @@ static void on_request_headers_sent(cronet_bidirectional_stream *stream) { Cronet callback */ static void on_response_headers_received( - cronet_bidirectional_stream *stream, - const cronet_bidirectional_stream_header_array *headers, + bidirectional_stream *stream, + const bidirectional_stream_header_array *headers, const char *negotiated_protocol) { CRONET_LOG(GPR_DEBUG, "R: on_response_headers_received(%p, %p, %s)", stream, headers, negotiated_protocol); @@ -440,7 +440,7 @@ static void on_response_headers_received( /* Cronet callback */ -static void on_write_completed(cronet_bidirectional_stream *stream, +static void on_write_completed(bidirectional_stream *stream, const char *data) { stream_obj *s = (stream_obj *)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); @@ -457,7 +457,7 @@ static void on_write_completed(cronet_bidirectional_stream *stream, /* Cronet callback */ -static void on_read_completed(cronet_bidirectional_stream *stream, char *data, +static void on_read_completed(bidirectional_stream *stream, char *data, int count) { stream_obj *s = (stream_obj *)stream->annotation; CRONET_LOG(GPR_DEBUG, "R: on_read_completed(%p, %p, %d)", stream, data, @@ -468,9 +468,9 @@ static void on_read_completed(cronet_bidirectional_stream *stream, char *data, s->state.rs.received_bytes += count; s->state.rs.remaining_bytes -= count; if (s->state.rs.remaining_bytes > 0) { - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_read(%p)", s->cbs); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); s->state.state_op_done[OP_READ_REQ_MADE] = true; - cronet_bidirectional_stream_read( + bidirectional_stream_read( s->cbs, s->state.rs.read_buffer + s->state.rs.received_bytes, s->state.rs.remaining_bytes); gpr_mu_unlock(&s->mu); @@ -489,8 +489,8 @@ static void on_read_completed(cronet_bidirectional_stream *stream, char *data, Cronet callback */ static void on_response_trailers_received( - cronet_bidirectional_stream *stream, - const cronet_bidirectional_stream_header_array *trailers) { + bidirectional_stream *stream, + const bidirectional_stream_header_array *trailers) { CRONET_LOG(GPR_DEBUG, "R: on_response_trailers_received(%p,%p)", stream, trailers); stream_obj *s = (stream_obj *)stream->annotation; @@ -543,7 +543,7 @@ static void create_grpc_frame(grpc_slice_buffer *write_slice_buffer, */ static void convert_metadata_to_cronet_headers( grpc_linked_mdelem *head, const char *host, char **pp_url, - cronet_bidirectional_stream_header **pp_headers, size_t *p_num_headers, + bidirectional_stream_header **pp_headers, size_t *p_num_headers, const char **method) { grpc_linked_mdelem *curr = head; /* Walk the linked list and get number of header fields */ @@ -554,9 +554,9 @@ static void convert_metadata_to_cronet_headers( } /* Allocate enough memory. It is freed in the on_request_headers_sent callback */ - cronet_bidirectional_stream_header *headers = - (cronet_bidirectional_stream_header *)gpr_malloc( - sizeof(cronet_bidirectional_stream_header) * num_headers_available); + bidirectional_stream_header *headers = + (bidirectional_stream_header *)gpr_malloc( + sizeof(bidirectional_stream_header) * num_headers_available); *pp_headers = headers; /* Walk the linked list again, this time copying the header fields. @@ -788,9 +788,9 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, /* Start new cronet stream. It is destroyed in on_succeeded, on_canceled, * on_failed */ GPR_ASSERT(s->cbs == NULL); - s->cbs = cronet_bidirectional_stream_create(s->curr_ct.engine, s->curr_gs, - &cronet_callbacks); - CRONET_LOG(GPR_DEBUG, "%p = cronet_bidirectional_stream_create()", s->cbs); + s->cbs = bidirectional_stream_create(s->curr_ct.engine, s->curr_gs, + &cronet_callbacks); + CRONET_LOG(GPR_DEBUG, "%p = bidirectional_stream_create()", s->cbs); char *url = NULL; const char *method = "POST"; s->header_array.headers = NULL; @@ -798,10 +798,10 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, stream_op->send_initial_metadata->list.head, s->curr_ct.host, &url, &s->header_array.headers, &s->header_array.count, &method); s->header_array.capacity = s->header_array.count; - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_start(%p, %s)", s->cbs, + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); - cronet_bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, - false); + bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, + false); stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; result = ACTION_TAKEN_WITH_CALLBACK; } else if (stream_op->recv_initial_metadata && @@ -849,11 +849,11 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, size_t write_buffer_size; create_grpc_frame(&write_slice_buffer, &stream_state->ws.write_buffer, &write_buffer_size); - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_write (%p, %p)", + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", s->cbs, stream_state->ws.write_buffer); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; - cronet_bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, - (int)write_buffer_size, false); + bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, + (int)write_buffer_size, false); result = ACTION_TAKEN_WITH_CALLBACK; } else { result = NO_ACTION_POSSIBLE; @@ -893,11 +893,11 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, GPR_ASSERT(stream_state->rs.read_buffer); stream_state->rs.remaining_bytes = stream_state->rs.length_field; stream_state->rs.received_bytes = 0; - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_read(%p)", s->cbs); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); stream_state->state_op_done[OP_READ_REQ_MADE] = true; /* Indicates that at least one read request has been made */ - cronet_bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, - stream_state->rs.remaining_bytes); + bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, + stream_state->rs.remaining_bytes); result = ACTION_TAKEN_WITH_CALLBACK; } else { stream_state->rs.remaining_bytes = 0; @@ -918,11 +918,11 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, stream_state->rs.read_buffer = stream_state->rs.grpc_header_bytes; stream_state->rs.remaining_bytes = GRPC_HEADER_SIZE_IN_BYTES; stream_state->rs.received_bytes = 0; - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_read(%p)", s->cbs); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); stream_state->state_op_done[OP_READ_REQ_MADE] = true; /* Indicates that at least one read request has been made */ - cronet_bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, - stream_state->rs.remaining_bytes); + bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, + stream_state->rs.remaining_bytes); result = ACTION_TAKEN_WITH_CALLBACK; } else { result = NO_ACTION_POSSIBLE; @@ -972,10 +972,10 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, result = NO_ACTION_POSSIBLE; CRONET_LOG(GPR_DEBUG, "Stream is either cancelled or failed."); } else { - CRONET_LOG(GPR_DEBUG, "cronet_bidirectional_stream_write (%p, 0)", + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", s->cbs); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; - cronet_bidirectional_stream_write(s->cbs, "", 0, true); + bidirectional_stream_write(s->cbs, "", 0, true); result = ACTION_TAKEN_WITH_CALLBACK; } stream_state->state_op_done[OP_SEND_TRAILING_METADATA] = true; @@ -983,9 +983,9 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, op_can_be_run(stream_op, stream_state, &oas->state, OP_CANCEL_ERROR)) { CRONET_LOG(GPR_DEBUG, "running: %p OP_CANCEL_ERROR", oas); - CRONET_LOG(GPR_DEBUG, "W: cronet_bidirectional_stream_cancel(%p)", s->cbs); + CRONET_LOG(GPR_DEBUG, "W: bidirectional_stream_cancel(%p)", s->cbs); if (s->cbs) { - cronet_bidirectional_stream_cancel(s->cbs); + bidirectional_stream_cancel(s->cbs); } stream_state->state_op_done[OP_CANCEL_ERROR] = true; result = ACTION_TAKEN_WITH_CALLBACK; @@ -1064,9 +1064,9 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, header_has_authority(op->send_initial_metadata->list.head)) { /* Cronet does not support :authority header field. We cancel the call when this field is present in metadata */ - cronet_bidirectional_stream_header_array header_array; - cronet_bidirectional_stream_header *header; - cronet_bidirectional_stream cbs; + bidirectional_stream_header_array header_array; + bidirectional_stream_header *header; + bidirectional_stream cbs; CRONET_LOG(GPR_DEBUG, ":authority header is provided but not supported;" " cancel operations"); @@ -1074,8 +1074,8 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, header_array.count = 1; header_array.capacity = 1; header_array.headers = - gpr_malloc(sizeof(cronet_bidirectional_stream_header)); - header = (cronet_bidirectional_stream_header *)header_array.headers; + gpr_malloc(sizeof(bidirectional_stream_header)); + header = (bidirectional_stream_header *)header_array.headers; header->key = "grpc-status"; header->value = "1"; /* Return status GRPC_STATUS_CANCELLED */ cbs.annotation = (void *)s; diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.h b/src/objective-c/GRPCClient/GRPCCall+Cronet.h index 2d8f7ac8fb9..b9d286c929a 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.h +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.h @@ -43,13 +43,13 @@ /** * This method should be called before issuing the first RPC. It should be * called only once. Create an instance of Cronet engine in your app elsewhere - * and pass the instance pointer in the cronet_engine parameter. Once set, + * and pass the instance pointer in the stream_engine parameter. Once set, * all subsequent RPCs will use Cronet transport. The method is not thread * safe. */ -+(void)useCronetWithEngine:(cronet_engine *)engine; ++(void)useCronetWithEngine:(stream_engine *)engine; -+(cronet_engine *)cronetEngine; ++(stream_engine *)cronetEngine; +(BOOL)isUsingCronet; diff --git a/src/objective-c/GRPCClient/GRPCCall+Cronet.m b/src/objective-c/GRPCClient/GRPCCall+Cronet.m index 76ca1a2537c..0e3598fb87d 100644 --- a/src/objective-c/GRPCClient/GRPCCall+Cronet.m +++ b/src/objective-c/GRPCClient/GRPCCall+Cronet.m @@ -35,16 +35,16 @@ #ifdef GRPC_COMPILE_WITH_CRONET static BOOL useCronet = NO; -static cronet_engine *globalCronetEngine; +static stream_engine *globalCronetEngine; @implementation GRPCCall (Cronet) -+ (void)useCronetWithEngine:(cronet_engine *)engine { ++ (void)useCronetWithEngine:(stream_engine *)engine { useCronet = YES; globalCronetEngine = engine; } -+ (cronet_engine *)cronetEngine { ++ (stream_engine *)cronetEngine { return globalCronetEngine; } diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index e49aceefe18..2397c929f70 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -108,7 +108,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { #ifdef GRPC_COMPILE_WITH_CRONET - (instancetype)initWithHost:(NSString *)host - cronetEngine:(cronet_engine *)cronetEngine + cronetEngine:(stream_engine *)cronetEngine channelArgs:(NSDictionary *)channelArgs { if (!host) { [NSException raise:NSInvalidArgumentException format:@"host argument missing"]; @@ -163,7 +163,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { #ifdef GRPC_COMPILE_WITH_CRONET + (GRPCChannel *)secureCronetChannelWithHost:(NSString *)host channelArgs:(NSDictionary *)channelArgs { - cronet_engine *engine = [GRPCCall cronetEngine]; + stream_engine *engine = [GRPCCall cronetEngine]; if (!engine) { [NSException raise:NSInvalidArgumentException format:@"cronet_engine is NULL. Set it first."]; diff --git a/third_party/Cronet/bidirectional_stream_c.h b/third_party/Cronet/bidirectional_stream_c.h new file mode 100644 index 00000000000..ffb235ae874 --- /dev/null +++ b/third_party/Cronet/bidirectional_stream_c.h @@ -0,0 +1,246 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_C_H_ +#define COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_C_H_ + +#if defined(WIN32) +#define GRPC_SUPPORT_EXPORT +#else +#define GRPC_SUPPORT_EXPORT __attribute__((visibility("default"))) +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#include + +/* Engine API. */ + +/* Opaque object representing a Bidirectional stream creating engine. Created + * and configured outside of this API to facilitate sharing with other + * components */ +typedef struct stream_engine { + void* obj; + void* annotation; +} stream_engine; + +/* Bidirectional Stream API */ + +/* Opaque object representing Bidirectional Stream. */ +typedef struct bidirectional_stream { + void* obj; + void* annotation; +} bidirectional_stream; + +/* A single request or response header element. */ +typedef struct bidirectional_stream_header { + const char* key; + const char* value; +} bidirectional_stream_header; + +/* Array of request or response headers or trailers. */ +typedef struct bidirectional_stream_header_array { + size_t count; + size_t capacity; + bidirectional_stream_header* headers; +} bidirectional_stream_header_array; + +/* Set of callbacks used to receive callbacks from bidirectional stream. */ +typedef struct bidirectional_stream_callback { + /* Invoked when the stream is ready for reading and writing. + * Consumer may call bidirectional_stream_read() to start reading data. + * Consumer may call bidirectional_stream_write() to start writing + * data. + */ + void (*on_stream_ready)(bidirectional_stream* stream); + + /* Invoked when initial response headers are received. + * Consumer must call bidirectional_stream_read() to start reading. + * Consumer may call bidirectional_stream_write() to start writing or + * close the stream. Contents of |headers| is valid for duration of the call. + */ + void (*on_response_headers_received)( + bidirectional_stream* stream, + const bidirectional_stream_header_array* headers, + const char* negotiated_protocol); + + /* Invoked when data is read into the buffer passed to + * bidirectional_stream_read(). Only part of the buffer may be + * populated. To continue reading, call bidirectional_stream_read(). + * It may be invoked after on_response_trailers_received()}, if there was + * pending read data before trailers were received. + * + * If |bytes_read| is 0, it means the remote side has signaled that it will + * send no more data; future calls to bidirectional_stream_read() + * will result in the on_data_read() callback or on_succeded() callback if + * bidirectional_stream_write() was invoked with end_of_stream set to + * true. + */ + void (*on_read_completed)(bidirectional_stream* stream, + char* data, + int bytes_read); + + /** + * Invoked when all data passed to bidirectional_stream_write() is + * sent. To continue writing, call bidirectional_stream_write(). + */ + void (*on_write_completed)(bidirectional_stream* stream, const char* data); + + /* Invoked when trailers are received before closing the stream. Only invoked + * when server sends trailers, which it may not. May be invoked while there is + * read data remaining in local buffer. Contents of |trailers| is valid for + * duration of the call. + */ + void (*on_response_trailers_received)( + bidirectional_stream* stream, + const bidirectional_stream_header_array* trailers); + + /** + * Invoked when there is no data to be read or written and the stream is + * closed successfully remotely and locally. Once invoked, no further callback + * methods will be invoked. + */ + void (*on_succeded)(bidirectional_stream* stream); + + /** + * Invoked if the stream failed for any reason after + * bidirectional_stream_start(). HTTP/2 error codes are + * mapped to chrome net error codes. Once invoked, no further callback methods + * will be invoked. + */ + void (*on_failed)(bidirectional_stream* stream, int net_error); + + /** + * Invoked if the stream was canceled via + * bidirectional_stream_cancel(). Once invoked, no further callback + * methods will be invoked. + */ + void (*on_canceled)(bidirectional_stream* stream); +} bidirectional_stream_callback; + +/* Creates a new stream object that uses |engine| and |callback|. All stream + * tasks are performed asynchronously on the |engine| network thread. |callback| + * methods are invoked synchronously on the |engine| network thread, but must + * not run tasks on the current thread to prevent blocking networking operations + * and causing exceptions during shutdown. The |annotation| is stored in + * bidirectional stream for arbitrary use by application. + * + * Returned |bidirectional_stream*| is owned by the caller, and must be + * destroyed using |bidirectional_stream_destroy|. + * + * Both |calback| and |engine| must remain valid until stream is destroyed. + */ +GRPC_SUPPORT_EXPORT +bidirectional_stream* bidirectional_stream_create( + stream_engine* engine, + void* annotation, + bidirectional_stream_callback* callback); + +/* TBD: The following methods return int. Should it be a custom type? */ + +/* Destroys stream object. Destroy could be called from any thread, including + * network thread, but is posted, so |stream| is valid until calling task is + * complete. + */ +GRPC_SUPPORT_EXPORT +int bidirectional_stream_destroy(bidirectional_stream* stream); + +/** + * Disables or enables auto flush. By default, data is flushed after + * every bidirectional_stream_write(). If the auto flush is disabled, + * the client should explicitly call bidirectional_stream_flush to flush + * the data. + */ +GRPC_SUPPORT_EXPORT void bidirectional_stream_disable_auto_flush( + bidirectional_stream* stream, + bool disable_auto_flush); + +/** + * Delays sending request headers until bidirectional_stream_flush() + * is called. This flag is currently only respected when QUIC is negotiated. + * When true, QUIC will send request header frame along with data frame(s) + * as a single packet when possible. + */ +GRPC_SUPPORT_EXPORT +void bidirectional_stream_delay_request_headers_until_flush( + bidirectional_stream* stream, + bool delay_headers_until_flush); + +/* Starts the stream by sending request to |url| using |method| and |headers|. + * If |end_of_stream| is true, then no data is expected to be written. The + * |method| is HTTP verb, with PUT having a special meaning to mark idempotent + * request, which could use QUIC 0-RTT. + */ +GRPC_SUPPORT_EXPORT +int bidirectional_stream_start(bidirectional_stream* stream, + const char* url, + int priority, + const char* method, + const bidirectional_stream_header_array* headers, + bool end_of_stream); + +/* Reads response data into |buffer| of |capacity| length. Must only be called + * at most once in response to each invocation of the + * on_stream_ready()/on_response_headers_received() and on_read_completed() + * methods of the bidirectional_stream_callback. + * Each call will result in an invocation of the callback's + * on_read_completed() method if data is read, or its on_failed() method if + * there's an error. The callback's on_succeeded() method is also invoked if + * there is no more data to read and |end_of_stream| was previously sent. + */ +GRPC_SUPPORT_EXPORT +int bidirectional_stream_read(bidirectional_stream* stream, + char* buffer, + int capacity); + +/* Writes request data from |buffer| of |buffer_length| length. If auto flush is + * disabled, data will be sent only after bidirectional_stream_flush() is + * called. + * Each call will result in an invocation the callback's on_write_completed() + * method if data is sent, or its on_failed() method if there's an error. + * The callback's on_succeeded() method is also invoked if |end_of_stream| is + * set and all response data has been read. + */ +GRPC_SUPPORT_EXPORT +int bidirectional_stream_write(bidirectional_stream* stream, + const char* buffer, + int buffer_length, + bool end_of_stream); + +/** + * Flushes pending writes. This method should not be called before invocation of + * on_stream_ready() method of the bidirectional_stream_callback. + * For each previously called bidirectional_stream_write() + * a corresponding on_write_completed() callback will be invoked when the buffer + * is sent. + */ +GRPC_SUPPORT_EXPORT +void bidirectional_stream_flush(bidirectional_stream* stream); + +/* Cancels the stream. Can be called at any time after + * bidirectional_stream_start(). The on_canceled() method of + * bidirectional_stream_callback will be invoked when cancelation + * is complete and no further callback methods will be invoked. If the + * stream has completed or has not started, calling + * bidirectional_stream_cancel() has no effect and on_canceled() will not + * be invoked. At most one callback method may be invoked after + * bidirectional_stream_cancel() has completed. + */ +GRPC_SUPPORT_EXPORT +void bidirectional_stream_cancel(bidirectional_stream* stream); + +/* Returns true if the |stream| was successfully started and is now done + * (succeeded, canceled, or failed). + * Returns false if the |stream| stream is not yet started or is in progress. + */ +GRPC_SUPPORT_EXPORT +bool bidirectional_stream_is_done(bidirectional_stream* stream); + +#ifdef __cplusplus +} +#endif + +#endif // COMPONENTS_GRPC_SUPPORT_INCLUDE_BIDIRECTIONAL_STREAM_H_ diff --git a/third_party/objective_c/Cronet/cronet_c_for_grpc.h b/third_party/objective_c/Cronet/cronet_c_for_grpc.h deleted file mode 100644 index 15a511aebd0..00000000000 --- a/third_party/objective_c/Cronet/cronet_c_for_grpc.h +++ /dev/null @@ -1,202 +0,0 @@ -// Copyright 2016 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ -#define COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -/* Cronet Engine API. */ - -/* Opaque object representing Cronet Engine. Created and configured outside - * of this API to facilitate sharing with other components */ -typedef struct cronet_engine { void* obj; } cronet_engine; - -void cronet_engine_add_quic_hint(cronet_engine* engine, - const char* host, - int port, - int alternate_port); - -/* Cronet Bidirectional Stream API */ - -/* Opaque object representing Cronet Bidirectional Stream. */ -typedef struct cronet_bidirectional_stream { - void* obj; - void* annotation; -} cronet_bidirectional_stream; - -/* A single request or response header element. */ -typedef struct cronet_bidirectional_stream_header { - const char* key; - const char* value; -} cronet_bidirectional_stream_header; - -/* Array of request or response headers or trailers. */ -typedef struct cronet_bidirectional_stream_header_array { - size_t count; - size_t capacity; - cronet_bidirectional_stream_header* headers; -} cronet_bidirectional_stream_header_array; - -/* Set of callbacks used to receive callbacks from bidirectional stream. */ -typedef struct cronet_bidirectional_stream_callback { - /* Invoked when request headers are sent. Indicates that stream has initiated - * the request. Consumer may call cronet_bidirectional_stream_write() to start - * writing data. - */ - void (*on_request_headers_sent)(cronet_bidirectional_stream* stream); - - /* Invoked when initial response headers are received. - * Consumer must call cronet_bidirectional_stream_read() to start reading. - * Consumer may call cronet_bidirectional_stream_write() to start writing or - * close the stream. Contents of |headers| is valid for duration of the call. - */ - void (*on_response_headers_received)( - cronet_bidirectional_stream* stream, - const cronet_bidirectional_stream_header_array* headers, - const char* negotiated_protocol); - - /* Invoked when data is read into the buffer passed to - * cronet_bidirectional_stream_read(). Only part of the buffer may be - * populated. To continue reading, call cronet_bidirectional_stream_read(). - * It may be invoked after on_response_trailers_received()}, if there was - * pending read data before trailers were received. - * - * If count is 0, it means the remote side has signaled that it will send no - * more data; future calls to cronet_bidirectional_stream_read() will result - * in the on_data_read() callback or on_succeded() callback if - * cronet_bidirectional_stream_write() was invoked with end_of_stream set to - * true. - */ - void (*on_read_completed)(cronet_bidirectional_stream* stream, - char* data, - int count); - - /** - * Invoked when all data passed to cronet_bidirectional_stream_write() is - * sent. - * To continue writing, call cronet_bidirectional_stream_write(). - */ - void (*on_write_completed)(cronet_bidirectional_stream* stream, - const char* data); - - /* Invoked when trailers are received before closing the stream. Only invoked - * when server sends trailers, which it may not. May be invoked while there is - * read data remaining in local buffer. Contents of |trailers| is valid for - * duration of the call. - */ - void (*on_response_trailers_received)( - cronet_bidirectional_stream* stream, - const cronet_bidirectional_stream_header_array* trailers); - - /** - * Invoked when there is no data to be read or written and the stream is - * closed successfully remotely and locally. Once invoked, no further callback - * methods will be invoked. - */ - void (*on_succeded)(cronet_bidirectional_stream* stream); - - /** - * Invoked if the stream failed for any reason after - * cronet_bidirectional_stream_start(). HTTP/2 error codes are - * mapped to chrome net error codes. Once invoked, no further callback methods - * will be invoked. - */ - void (*on_failed)(cronet_bidirectional_stream* stream, int net_error); - - /** - * Invoked if the stream was canceled via - * cronet_bidirectional_stream_cancel(). Once invoked, no further callback - * methods will be invoked. - */ - void (*on_canceled)(cronet_bidirectional_stream* stream); -} cronet_bidirectional_stream_callback; - -/* Create a new stream object that uses |engine| and |callback|. All stream - * tasks are performed asynchronously on the |engine| network thread. |callback| - * methods are invoked synchronously on the |engine| network thread, but must - * not run tasks on the current thread to prevent blocking networking operations - * and causing exceptions during shutdown. The |annotation| is stored in - * bidirectional stream for arbitrary use by application. - * - * Returned |cronet_bidirectional_stream*| is owned by the caller, and must be - * destroyed using |cronet_bidirectional_stream_destroy|. - * - * Both |calback| and |engine| must remain valid until stream is destroyed. - */ -cronet_bidirectional_stream* cronet_bidirectional_stream_create( - cronet_engine* engine, - void* annotation, - cronet_bidirectional_stream_callback* callback); - -/* TBD: The following methods return int. Should it be a custom type? */ - -/* Destroy stream object. Destroy could be called from any thread, including - * network thread, but is posted, so |stream| is valid until calling task is - * complete. - */ -int cronet_bidirectional_stream_destroy(cronet_bidirectional_stream* stream); - -/* Start the stream by sending request to |url| using |method| and |headers|. If - * |end_of_stream| is true, then no data is expected to be written. - */ -int cronet_bidirectional_stream_start( - cronet_bidirectional_stream* stream, - const char* url, - int priority, - const char* method, - const cronet_bidirectional_stream_header_array* headers, - bool end_of_stream); - -/* Read response data into |buffer| of |capacity| length. Must only be called at - * most once in response to each invocation of the - * on_response_headers_received() and on_read_completed() methods of the - * cronet_bidirectional_stream_callback. - * Each call will result in an invocation of one of the callback's - * on_read_completed method if data is read, its on_succeeded() method if - * the stream is closed, or its on_failed() method if there's an error. - */ -int cronet_bidirectional_stream_read(cronet_bidirectional_stream* stream, - char* buffer, - int capacity); - -/* Read response data into |buffer| of |capacity| length. Must only be called at - * most once in response to each invocation of the - * on_response_headers_received() and on_read_completed() methods of the - * cronet_bidirectional_stream_callback. - * Each call will result in an invocation of one of the callback's - * on_read_completed method if data is read, its on_succeeded() method if - * the stream is closed, or its on_failed() method if there's an error. - */ -int cronet_bidirectional_stream_write(cronet_bidirectional_stream* stream, - const char* buffer, - int count, - bool end_of_stream); - -/* Cancels the stream. Can be called at any time after - * cronet_bidirectional_stream_start(). The on_canceled() method of - * cronet_bidirectional_stream_callback will be invoked when cancelation - * is complete and no further callback methods will be invoked. If the - * stream has completed or has not started, calling - * cronet_bidirectional_stream_cancel() has no effect and on_canceled() will not - * be invoked. At most one callback method may be invoked after - * cronet_bidirectional_stream_cancel() has completed. - */ -int cronet_bidirectional_stream_cancel(cronet_bidirectional_stream* stream); - -/* Returns true if the |stream| was successfully started and is now done - * (succeeded, canceled, or failed). - * Returns false if the |stream| stream is not yet started or is in progress. - */ -bool cronet_bidirectional_stream_is_done(cronet_bidirectional_stream* stream); - -#ifdef __cplusplus -} -#endif - -#endif // COMPONENTS_CRONET_IOS_CRONET_C_FOR_GRPC_H_ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 9be07941d75..fc609102598 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -7504,7 +7504,7 @@ "include/grpc/grpc_cronet.h", "include/grpc/grpc_security.h", "include/grpc/grpc_security_constants.h", - "third_party/objective_c/Cronet/cronet_c_for_grpc.h" + "third_party/Cronet/bidirectional_stream_c.h" ], "is_filegroup": true, "language": "c", From 0c2fb6a2a428b76c931f3795ce53e0794dbfdccd Mon Sep 17 00:00:00 2001 From: Garrett Casto Date: Tue, 22 Nov 2016 11:14:39 -0800 Subject: [PATCH 074/261] Fix CoreCronetEnd2EndTests --- .../tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m index 4a92cc8e0d3..40a18a5aa54 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m @@ -94,7 +94,7 @@ static void process_auth_failure(void *state, grpc_auth_context *ctx, static void cronet_init_client_secure_fullstack(grpc_end2end_test_fixture *f, grpc_channel_args *client_args, - cronet_engine *cronetEngine) { + stream_engine *cronetEngine) { fullstack_secure_fixture_data *ffd = f->fixture_data; f->client = grpc_cronet_secure_channel_create(cronetEngine, ffd->localaddr, client_args, NULL); @@ -124,7 +124,7 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void cronet_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { - cronet_engine *cronetEngine = [Cronet getGlobalEngine]; + stream_engine *cronetEngine = [Cronet getGlobalEngine]; grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args); cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine); From 33fdafbf18bc3f80bfddf998facefc6c9dd9f456 Mon Sep 17 00:00:00 2001 From: Garrett Casto Date: Tue, 29 Nov 2016 11:32:03 -0800 Subject: [PATCH 075/261] clang-format --- .../cronet/transport/cronet_transport.c | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 28c4fbe9fe1..084532ea836 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -88,13 +88,12 @@ enum e_op_id { static void on_request_headers_sent(bidirectional_stream *); static void on_response_headers_received( - bidirectional_stream *, - const bidirectional_stream_header_array *, const char *); + bidirectional_stream *, const bidirectional_stream_header_array *, + const char *); static void on_write_completed(bidirectional_stream *, const char *); static void on_read_completed(bidirectional_stream *, char *, int); static void on_response_trailers_received( - bidirectional_stream *, - const bidirectional_stream_header_array *); + bidirectional_stream *, const bidirectional_stream_header_array *); static void on_succeeded(bidirectional_stream *); static void on_failed(bidirectional_stream *, int); static void on_canceled(bidirectional_stream *); @@ -440,8 +439,7 @@ static void on_response_headers_received( /* Cronet callback */ -static void on_write_completed(bidirectional_stream *stream, - const char *data) { +static void on_write_completed(bidirectional_stream *stream, const char *data) { stream_obj *s = (stream_obj *)stream->annotation; CRONET_LOG(GPR_DEBUG, "W: on_write_completed(%p, %s)", stream, data); gpr_mu_lock(&s->mu); @@ -798,10 +796,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, stream_op->send_initial_metadata->list.head, s->curr_ct.host, &url, &s->header_array.headers, &s->header_array.count, &method); s->header_array.capacity = s->header_array.count; - CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, - url); - bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, - false); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); + bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, false); stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; result = ACTION_TAKEN_WITH_CALLBACK; } else if (stream_op->recv_initial_metadata && @@ -849,8 +845,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, size_t write_buffer_size; create_grpc_frame(&write_slice_buffer, &stream_state->ws.write_buffer, &write_buffer_size); - CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", - s->cbs, stream_state->ws.write_buffer); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, %p)", s->cbs, + stream_state->ws.write_buffer); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; bidirectional_stream_write(s->cbs, stream_state->ws.write_buffer, (int)write_buffer_size, false); @@ -972,8 +968,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, result = NO_ACTION_POSSIBLE; CRONET_LOG(GPR_DEBUG, "Stream is either cancelled or failed."); } else { - CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", - s->cbs); + CRONET_LOG(GPR_DEBUG, "bidirectional_stream_write (%p, 0)", s->cbs); stream_state->state_callback_received[OP_SEND_MESSAGE] = false; bidirectional_stream_write(s->cbs, "", 0, true); result = ACTION_TAKEN_WITH_CALLBACK; @@ -1073,8 +1068,7 @@ static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt, /* Notify application that operation is cancelled by forging trailers */ header_array.count = 1; header_array.capacity = 1; - header_array.headers = - gpr_malloc(sizeof(bidirectional_stream_header)); + header_array.headers = gpr_malloc(sizeof(bidirectional_stream_header)); header = (bidirectional_stream_header *)header_array.headers; header->key = "grpc-status"; header->value = "1"; /* Return status GRPC_STATUS_CANCELLED */ From 72f8e14a8068140fcda53b537253792c4907de5a Mon Sep 17 00:00:00 2001 From: Garrett Casto Date: Wed, 30 Nov 2016 13:12:39 -0800 Subject: [PATCH 076/261] More clang-format --- .../cronet/transport/cronet_api_dummy.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_api_dummy.c b/src/core/ext/transport/cronet/transport/cronet_api_dummy.c index 1c4253f43fe..74327a42142 100644 --- a/src/core/ext/transport/cronet/transport/cronet_api_dummy.c +++ b/src/core/ext/transport/cronet/transport/cronet_api_dummy.c @@ -56,23 +56,22 @@ int bidirectional_stream_destroy(bidirectional_stream* stream) { return 0; } -int bidirectional_stream_start( - bidirectional_stream* stream, const char* url, int priority, - const char* method, const bidirectional_stream_header_array* headers, - bool end_of_stream) { +int bidirectional_stream_start(bidirectional_stream* stream, const char* url, + int priority, const char* method, + const bidirectional_stream_header_array* headers, + bool end_of_stream) { GPR_ASSERT(0); return 0; } -int bidirectional_stream_read(bidirectional_stream* stream, - char* buffer, int capacity) { +int bidirectional_stream_read(bidirectional_stream* stream, char* buffer, + int capacity) { GPR_ASSERT(0); return 0; } -int bidirectional_stream_write(bidirectional_stream* stream, - const char* buffer, int count, - bool end_of_stream) { +int bidirectional_stream_write(bidirectional_stream* stream, const char* buffer, + int count, bool end_of_stream) { GPR_ASSERT(0); return 0; } From 4d01ceea2e471d46d98a02c40f4428d27f8c0ba6 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 30 Nov 2016 13:37:07 -0800 Subject: [PATCH 077/261] Change CronetFramework.podspec version number to 0.0.4 instead of 1.0.0 --- src/objective-c/CronetFramework.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objective-c/CronetFramework.podspec b/src/objective-c/CronetFramework.podspec index 538479b96bc..90c7892df14 100644 --- a/src/objective-c/CronetFramework.podspec +++ b/src/objective-c/CronetFramework.podspec @@ -30,7 +30,7 @@ Pod::Spec.new do |s| s.name = "CronetFramework" - s.version = "1.0.0" + s.version = "0.0.4" s.summary = "Cronet, precompiled and used as a framework." s.homepage = "http://chromium.org" s.license = { From ff27a7aa4a9322833dcd9c29cda7ab3f1ba84ff2 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 30 Nov 2016 15:34:10 -0800 Subject: [PATCH 078/261] Use version number in Cronet zip file name --- src/objective-c/CronetFramework.podspec | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/objective-c/CronetFramework.podspec b/src/objective-c/CronetFramework.podspec index 90c7892df14..d45b8d8143b 100644 --- a/src/objective-c/CronetFramework.podspec +++ b/src/objective-c/CronetFramework.podspec @@ -30,7 +30,8 @@ Pod::Spec.new do |s| s.name = "CronetFramework" - s.version = "0.0.4" + v = '0.0.4' + s.version = v s.summary = "Cronet, precompiled and used as a framework." s.homepage = "http://chromium.org" s.license = { @@ -69,7 +70,8 @@ Pod::Spec.new do |s| s.vendored_framework = "Cronet.framework" s.author = "The Chromium Authors" s.ios.deployment_target = "8.0" - s.source = { :http => 'https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework-1.0.0.zip' } + file = + s.source = { :http => "https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework-v#{v}.zip"} s.preserve_paths = "Cronet.framework" s.public_header_files = "Cronet.framework/Headers/**/*{.h}" s.source_files = "Cronet.framework/Headers/**/*{.h}" From ddea41e666e2c23a3f1a38e0452e541baa6dddd3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Nov 2016 17:05:54 -0800 Subject: [PATCH 079/261] Remove code, rely on a pip installable module to codegen --- src/core/lib/transport/static_metadata.c | 62 +- tools/codegen/core/gen_static_metadata.py | 76 +- tools/codegen/core/perfect/.gitignore | 7 - tools/codegen/core/perfect/build.sh | 4 - tools/codegen/core/perfect/lookupa.c | 240 ---- tools/codegen/core/perfect/lookupa.h | 24 - tools/codegen/core/perfect/perfect.c | 1367 --------------------- tools/codegen/core/perfect/perfect.h | 132 -- tools/codegen/core/perfect/perfhex.c | 1308 -------------------- tools/codegen/core/perfect/recycle.c | 87 -- tools/codegen/core/perfect/recycle.h | 65 - tools/codegen/core/perfect/run.sh | 6 - tools/codegen/core/perfect/standard.h | 57 - 13 files changed, 57 insertions(+), 3378 deletions(-) delete mode 100644 tools/codegen/core/perfect/.gitignore delete mode 100755 tools/codegen/core/perfect/build.sh delete mode 100644 tools/codegen/core/perfect/lookupa.c delete mode 100644 tools/codegen/core/perfect/lookupa.h delete mode 100644 tools/codegen/core/perfect/perfect.c delete mode 100644 tools/codegen/core/perfect/perfect.h delete mode 100644 tools/codegen/core/perfect/perfhex.c delete mode 100644 tools/codegen/core/perfect/recycle.c delete mode 100644 tools/codegen/core/perfect/recycle.h delete mode 100755 tools/codegen/core/perfect/run.sh delete mode 100644 tools/codegen/core/perfect/standard.h diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index abd5a91eff3..ee1e22b2b27 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -429,47 +429,41 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 6, 6, 8, 8}; -#define ELEMS_PHASHLEN 0x40 -#define ELEMS_PHASHNKEYS 81 -#define ELEMS_PHASHRANGE 128 -#define ELEMS_PHASHSALT 0x9e3779b9 - -static const uint8_t elems_tab[] = { - 20, 1, 0, 61, 61, 34, 10, 16, 0, 0, 0, 0, 34, 61, 0, 1, - 0, 0, 0, 61, 0, 88, 0, 4, 0, 47, 0, 47, 12, 7, 0, 16, - 51, 87, 76, 4, 79, 10, 70, 47, 76, 61, 71, 88, 0, 88, 0, 47, - 0, 16, 0, 83, 0, 57, 0, 75, 0, 42, 0, 90, 0, 42, 70, 0, -}; - -static uint32_t elems_phash(uint32_t val) { - val += (uint32_t)-11; - - uint32_t a, b, rsl; - - b = (val & 0x3f); - a = ((val << 18) >> 26); - rsl = (a ^ elems_tab[b]); - return rsl; +static const int8_t elems_r[] = { + 10, 8, -3, 0, 9, 21, -76, 22, 0, 10, -7, 20, 0, 19, 18, 17, + 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -49, -50, 16, -52, -53, -54, -54, -55, -56, -57, 0, 38, 37, 36, 35, + 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, + 18, 17, 16, 15, 14, 13, 12, 15, 14, 13, 12, 11, 10, 9, 8, 0}; +static uint32_t elems_phash(uint32_t i) { + i -= 42; + uint32_t x = i % 96; + uint32_t y = i / 96; + return x + (uint32_t)elems_r[y]; } static const uint16_t elem_keys[] = { - 138, 522, 714, 5116, 1098, 430, 5802, 232, 8840, 913, 240, 8644, - 231, 8742, 7762, 1392, 42, 5410, 4822, 5998, 139, 1490, 5900, 7664, - 6292, 8448, 6684, 7272, 7370, 8350, 8154, 7958, 7566, 912, 9036, 7860, - 6488, 8546, 1111, 9134, 712, 5214, 132, 1074, 1010, 5312, 314, 242, - 8252, 4951, 8938, 43, 7076, 6096, 6586, 6194, 1294, 1076, 5606, 1588, - 5704, 244, 911, 5508, 6390, 7174, 6880, 1077, 713, 1009, 241, 8056, - 1075, 6782, 7468, 4920, 243, 429, 431, 1011, 6978, 0, 0, 0, + 1009, 1010, 1011, 240, 241, 242, 243, 244, 138, 139, 42, 43, + 429, 430, 431, 911, 912, 913, 712, 713, 1098, 522, 714, 1294, + 1392, 1490, 1588, 4822, 4920, 4951, 5116, 5214, 5312, 1111, 5410, 5508, + 5606, 5704, 5802, 5900, 5998, 6096, 6194, 6292, 6390, 6488, 6586, 6684, + 6782, 6880, 6978, 7076, 7174, 7272, 7370, 7468, 7566, 7664, 7762, 7860, + 7958, 8056, 8154, 8252, 8350, 1074, 1075, 1076, 1077, 8448, 8546, 8644, + 8742, 8840, 8938, 9036, 9134, 314, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 132, 231, 232, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0}; + 0}; static const uint8_t elem_idxs[] = { - 15, 6, 2, 27, 41, 12, 34, 10, 69, 5, 19, 67, 9, 68, 58, 48, 17, - 30, 24, 36, 16, 55, 35, 57, 39, 65, 44, 51, 52, 64, 62, 60, 54, 4, - 72, 59, 42, 66, 7, 73, 0, 28, 8, 76, 77, 29, 14, 21, 63, 26, 71, - 18, 49, 37, 43, 38, 70, 79, 32, 56, 33, 23, 3, 31, 40, 50, 46, 80, - 1, 74, 20, 61, 78, 45, 53, 25, 22, 11, 13, 75, 47}; + 74, 77, 75, 19, 20, 21, 22, 23, 15, 16, 17, 18, 11, 12, 13, + 3, 4, 5, 0, 1, 41, 6, 2, 70, 48, 55, 56, 24, 25, 26, + 27, 28, 29, 7, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 57, 58, 59, + 60, 61, 62, 63, 64, 76, 78, 79, 80, 65, 66, 67, 68, 69, 71, + 72, 73, 14, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 8, 9, 10}; grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { if (a == -1 || b == -1) return GRPC_MDNULL; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 18f71646f84..b7c9533602e 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -36,6 +36,7 @@ import os import sys import subprocess import re +import perfection # configuration: a list of either strings or 2-tuples of strings # a single string represents a static grpc_mdstr @@ -407,59 +408,40 @@ def offset_trials(mink): yield mul * i def perfect_hash(keys, name): - ok = False - print '***********' - print keys - cmd = '%s/perfect/build.sh' % (os.path.dirname(sys.argv[0])) - subprocess.check_call(cmd, shell=True) - for offset in offset_trials(min(keys)): - tmp = open('/tmp/keys.txt', 'w') - offset_keys = [x + offset for x in keys] - print offset_keys - tmp.write(''.join('%d\n' % x for x in offset_keys)) - tmp.close() - cmd = '%s/perfect/run.sh %s -dms' % (os.path.dirname(sys.argv[0]), tmp.name) - out = subprocess.check_output(cmd, shell=True) - if 'fatal error' not in out: - ok = True - break - assert ok, "Failed to find hash of keys in /tmp/keys.txt" - - code = '' - - results = {} - with open('%s/perfect/phash.h' % os.path.dirname(sys.argv[0])) as f: - txt = f.read() - for var in ('PHASHLEN', 'PHASHNKEYS', 'PHASHRANGE', 'PHASHSALT'): - val = re.search(r'#define %s ([0-9a-zA-Z]+)' % var, txt).group(1) - code += '#define %s_%s %s\n' % (name.upper(), var, val) - results[var] = val - code += '\n' - pycode = 'def f(val):\n' - pycode += ' val += %d\n' % offset - with open('%s/perfect/phash.c' % os.path.dirname(sys.argv[0])) as f: - txt = f.read() - tabdata = re.search(r'ub1 tab\[\] = \{([^}]+)\}', txt, re.MULTILINE).group(1) - code += 'static const uint8_t %s_tab[] = {%s};\n\n' % (name, tabdata) - func_body = re.search(r'ub4 phash\(val\)\nub4 val;\n\{([^}]+)\}', txt, re.MULTILINE).group(1).replace('ub4', 'uint32_t') - code += 'static uint32_t %s_phash(uint32_t val) {\nval += (uint32_t)%d;\n%s}\n' % (name, - offset, func_body.replace('tab', '%s_tab' % name)) - pycode += ' tab=(%s)' % tabdata.replace('\n', '') - pycode += '\n'.join(' %s' % s.strip() for s in func_body.splitlines()[2:]) - g = {} - exec pycode in g - pyfunc = g['f'] - - results['code'] = code - results['pyfunc'] = pyfunc - return results + p = perfection.hash_parameters(keys) + def f(i, p=p): + i += p.offset + x = i % p.t + y = i / p.t + return x + p.r[y] + return { + 'PHASHRANGE': p.t - 1 + max(p.r), + 'PHASHNKEYS': len(p.slots), + 'pyfunc': f, + 'code': """ +static const int8_t %(name)s_r[] = {%(r)s}; +static uint32_t %(name)s_phash(uint32_t i) { + i %(offset_sign)s= %(offset)d; + uint32_t x = i %% %(t)d; + uint32_t y = i / %(t)d; + return x + (uint32_t)%(name)s_r[y]; +} + """ % { + 'name': name, + 'r': ','.join('%d' % (r if r is not None else 0) for r in p.r), + 't': p.t, + 'offset': abs(p.offset), + 'offset_sign': '+' if p.offset > 0 else '-' + } + } + elem_keys = [str_idx(elem[0]) * len(all_strs) + str_idx(elem[1]) for elem in all_elems] elem_hash = perfect_hash(elem_keys, "elems") print >>C, elem_hash['code'] keys = [0] * int(elem_hash['PHASHRANGE']) -idxs = [-1] * int(elem_hash['PHASHNKEYS']) +idxs = [255] * int(elem_hash['PHASHNKEYS']) for i, k in enumerate(elem_keys): h = elem_hash['pyfunc'](k) assert keys[h] == 0 diff --git a/tools/codegen/core/perfect/.gitignore b/tools/codegen/core/perfect/.gitignore deleted file mode 100644 index c1489f08193..00000000000 --- a/tools/codegen/core/perfect/.gitignore +++ /dev/null @@ -1,7 +0,0 @@ -perfect -*.o -phash.h -phash.c -compile.txt -hash.txt - diff --git a/tools/codegen/core/perfect/build.sh b/tools/codegen/core/perfect/build.sh deleted file mode 100755 index 139556ea483..00000000000 --- a/tools/codegen/core/perfect/build.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash -set -e -cd $(dirname $0) -gcc -o perfect perfect.c recycle.c lookupa.c perfhex.c 2> compile.txt diff --git a/tools/codegen/core/perfect/lookupa.c b/tools/codegen/core/perfect/lookupa.c deleted file mode 100644 index c122c4f107f..00000000000 --- a/tools/codegen/core/perfect/lookupa.c +++ /dev/null @@ -1,240 +0,0 @@ -/* --------------------------------------------------------------------- -lookupa.c, by Bob Jenkins, December 1996. Same as lookup2.c -Use this code however you wish. Public Domain. No warranty. -Source is http://burtleburtle.net/bob/c/lookupa.c --------------------------------------------------------------------- -*/ -#ifndef STANDARD -#include "standard.h" -#endif -#ifndef LOOKUPA -#include "lookupa.h" -#endif - -/* --------------------------------------------------------------------- -mix -- mix 3 32-bit values reversibly. -For every delta with one or two bit set, and the deltas of all three - high bits or all three low bits, whether the original value of a,b,c - is almost all zero or is uniformly distributed, -* If mix() is run forward or backward, at least 32 bits in a,b,c - have at least 1/4 probability of changing. -* If mix() is run forward, every bit of c will change between 1/3 and - 2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.) -mix() was built out of 36 single-cycle latency instructions in a - structure that could supported 2x parallelism, like so: - a -= b; - a -= c; x = (c>>13); - b -= c; a ^= x; - b -= a; x = (a<<8); - c -= a; b ^= x; - c -= b; x = (b>>13); - ... - Unfortunately, superscalar Pentiums and Sparcs can't take advantage - of that parallelism. They've also turned some of those single-cycle - latency instructions into multi-cycle latency instructions. Still, - this is the fastest good hash I could find. There were about 2^^68 - to choose from. I only looked at a billion or so. --------------------------------------------------------------------- -*/ -#define mix(a,b,c) \ -{ \ - a -= b; a -= c; a ^= (c>>13); \ - b -= c; b -= a; b ^= (a<<8); \ - c -= a; c -= b; c ^= (b>>13); \ - a -= b; a -= c; a ^= (c>>12); \ - b -= c; b -= a; b ^= (a<<16); \ - c -= a; c -= b; c ^= (b>>5); \ - a -= b; a -= c; a ^= (c>>3); \ - b -= c; b -= a; b ^= (a<<10); \ - c -= a; c -= b; c ^= (b>>15); \ -} - -/* --------------------------------------------------------------------- -lookup() -- hash a variable-length key into a 32-bit value - k : the key (the unaligned variable-length array of bytes) - len : the length of the key, counting by bytes - level : can be any 4-byte value -Returns a 32-bit value. Every bit of the key affects every bit of -the return value. Every 1-bit and 2-bit delta achieves avalanche. -About 6len+35 instructions. - -The best hash table sizes are powers of 2. There is no need to do -mod a prime (mod is sooo slow!). If you need less than 32 bits, -use a bitmask. For example, if you need only 10 bits, do - h = (h & hashmask(10)); -In which case, the hash table should have hashsize(10) elements. - -If you are hashing n strings (ub1 **)k, do it like this: - for (i=0, h=0; i= 12) - { - a += (k[0] +((ub4)k[1]<<8) +((ub4)k[2]<<16) +((ub4)k[3]<<24)); - b += (k[4] +((ub4)k[5]<<8) +((ub4)k[6]<<16) +((ub4)k[7]<<24)); - c += (k[8] +((ub4)k[9]<<8) +((ub4)k[10]<<16)+((ub4)k[11]<<24)); - mix(a,b,c); - k += 12; len -= 12; - } - - /*------------------------------------- handle the last 11 bytes */ - c += length; - switch(len) /* all the case statements fall through */ - { - case 11: c+=((ub4)k[10]<<24); - case 10: c+=((ub4)k[9]<<16); - case 9 : c+=((ub4)k[8]<<8); - /* the first byte of c is reserved for the length */ - case 8 : b+=((ub4)k[7]<<24); - case 7 : b+=((ub4)k[6]<<16); - case 6 : b+=((ub4)k[5]<<8); - case 5 : b+=k[4]; - case 4 : a+=((ub4)k[3]<<24); - case 3 : a+=((ub4)k[2]<<16); - case 2 : a+=((ub4)k[1]<<8); - case 1 : a+=k[0]; - /* case 0: nothing left to add */ - } - mix(a,b,c); - /*-------------------------------------------- report the result */ - return c; -} - - -/* --------------------------------------------------------------------- -mixc -- mixc 8 4-bit values as quickly and thoroughly as possible. -Repeating mix() three times achieves avalanche. -Repeating mix() four times eliminates all funnels and all - characteristics stronger than 2^{-11}. --------------------------------------------------------------------- -*/ -#define mixc(a,b,c,d,e,f,g,h) \ -{ \ - a^=b<<11; d+=a; b+=c; \ - b^=c>>2; e+=b; c+=d; \ - c^=d<<8; f+=c; d+=e; \ - d^=e>>16; g+=d; e+=f; \ - e^=f<<10; h+=e; f+=g; \ - f^=g>>4; a+=f; g+=h; \ - g^=h<<8; b+=g; h+=a; \ - h^=a>>9; c+=h; a+=b; \ -} - -/* --------------------------------------------------------------------- -checksum() -- hash a variable-length key into a 256-bit value - k : the key (the unaligned variable-length array of bytes) - len : the length of the key, counting by bytes - state : an array of CHECKSTATE 4-byte values (256 bits) -The state is the checksum. Every bit of the key affects every bit of -the state. There are no funnels. About 112+6.875len instructions. - -If you are hashing n strings (ub1 **)k, do it like this: - for (i=0; i<8; ++i) state[i] = 0x9e3779b9; - for (i=0, h=0; i= 32) - { - a += (k[0] +(k[1]<<8) +(k[2]<<16) +(k[3]<<24)); - b += (k[4] +(k[5]<<8) +(k[6]<<16) +(k[7]<<24)); - c += (k[8] +(k[9]<<8) +(k[10]<<16)+(k[11]<<24)); - d += (k[12]+(k[13]<<8)+(k[14]<<16)+(k[15]<<24)); - e += (k[16]+(k[17]<<8)+(k[18]<<16)+(k[19]<<24)); - f += (k[20]+(k[21]<<8)+(k[22]<<16)+(k[23]<<24)); - g += (k[24]+(k[25]<<8)+(k[26]<<16)+(k[27]<<24)); - h += (k[28]+(k[29]<<8)+(k[30]<<16)+(k[31]<<24)); - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - k += 32; len -= 32; - } - - /*------------------------------------- handle the last 31 bytes */ - h += length; - switch(len) - { - case 31: h+=(k[30]<<24); - case 30: h+=(k[29]<<16); - case 29: h+=(k[28]<<8); - case 28: g+=(k[27]<<24); - case 27: g+=(k[26]<<16); - case 26: g+=(k[25]<<8); - case 25: g+=k[24]; - case 24: f+=(k[23]<<24); - case 23: f+=(k[22]<<16); - case 22: f+=(k[21]<<8); - case 21: f+=k[20]; - case 20: e+=(k[19]<<24); - case 19: e+=(k[18]<<16); - case 18: e+=(k[17]<<8); - case 17: e+=k[16]; - case 16: d+=(k[15]<<24); - case 15: d+=(k[14]<<16); - case 14: d+=(k[13]<<8); - case 13: d+=k[12]; - case 12: c+=(k[11]<<24); - case 11: c+=(k[10]<<16); - case 10: c+=(k[9]<<8); - case 9 : c+=k[8]; - case 8 : b+=(k[7]<<24); - case 7 : b+=(k[6]<<16); - case 6 : b+=(k[5]<<8); - case 5 : b+=k[4]; - case 4 : a+=(k[3]<<24); - case 3 : a+=(k[2]<<16); - case 2 : a+=(k[1]<<8); - case 1 : a+=k[0]; - } - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - mixc(a,b,c,d,e,f,g,h); - - /*-------------------------------------------- report the result */ - state[0]=a; state[1]=b; state[2]=c; state[3]=d; - state[4]=e; state[5]=f; state[6]=g; state[7]=h; -} diff --git a/tools/codegen/core/perfect/lookupa.h b/tools/codegen/core/perfect/lookupa.h deleted file mode 100644 index 0b27db680dc..00000000000 --- a/tools/codegen/core/perfect/lookupa.h +++ /dev/null @@ -1,24 +0,0 @@ -/* ------------------------------------------------------------------------------- -By Bob Jenkins, September 1996. -lookupa.h, a hash function for table lookup, same function as lookup.c. -Use this code in any way you wish. Public Domain. It has no warranty. -Source is http://burtleburtle.net/bob/c/lookupa.h ------------------------------------------------------------------------------- -*/ - -#ifndef STANDARD -#include "standard.h" -#endif - -#ifndef LOOKUPA -#define LOOKUPA - -#define CHECKSTATE 8 -#define hashsize(n) ((ub4)1<<(n)) -#define hashmask(n) (hashsize(n)-1) - -ub4 lookup(/*_ ub1 *k, ub4 length, ub4 level _*/); -void checksum(/*_ ub1 *k, ub4 length, ub4 *state _*/); - -#endif /* LOOKUPA */ diff --git a/tools/codegen/core/perfect/perfect.c b/tools/codegen/core/perfect/perfect.c deleted file mode 100644 index 67fd2fd262e..00000000000 --- a/tools/codegen/core/perfect/perfect.c +++ /dev/null @@ -1,1367 +0,0 @@ -/* ------------------------------------------------------------------------------- -perfect.c: code to generate code for a hash for perfect hashing. -(c) Bob Jenkins, September 1996, December 1999 -You may use this code in any way you wish, and it is free. No warranty. -I hereby place this in the public domain. -Source is http://burtleburtle.net/bob/c/perfect.c - -This generates a minimal perfect hash function. That means, given a -set of n keys, this determines a hash function that maps each of -those keys into a value in 0..n-1 with no collisions. - -The perfect hash function first uses a normal hash function on the key -to determine (a,b) such that the pair (a,b) is distinct for all -keys, then it computes a^scramble[tab[b]] to get the final perfect hash. -tab[] is an array of 1-byte values and scramble[] is a 256-term array of -2-byte or 4-byte values. If there are n keys, the length of tab[] is a -power of two between n/3 and n. - -I found the idea of computing distinct (a,b) values in "Practical minimal -perfect hash functions for large databases", Fox, Heath, Chen, and Daoud, -Communications of the ACM, January 1992. They found the idea in Chichelli -(CACM Jan 1980). Beyond that, our methods differ. - -The key is hashed to a pair (a,b) where a in 0..*alen*-1 and b in -0..*blen*-1. A fast hash function determines both a and b -simultaneously. Any decent hash function is likely to produce -hashes so that (a,b) is distinct for all pairs. I try the hash -using different values of *salt* until all pairs are distinct. - -The final hash is (a XOR scramble[tab[b]]). *scramble* is a -predetermined mapping of 0..255 into 0..smax-1. *tab* is an -array that we fill in in such a way as to make the hash perfect. - -First we fill in all values of *tab* that are used by more than one -key. We try all possible values for each position until one works. - -This leaves m unmapped keys and m values that something could hash to. -If you treat unmapped keys as lefthand nodes and unused hash values -as righthand nodes, and draw a line connecting each key to each hash -value it could map to, you get a bipartite graph. We attempt to -find a perfect matching in this graph. If we succeed, we have -determined a perfect hash for the whole set of keys. - -*scramble* is used because (a^tab[i]) clusters keys around *a*. ------------------------------------------------------------------------------- -*/ - -#ifndef STANDARD -#include "standard.h" -#endif -#ifndef LOOKUPA -#include "lookupa.h" -#endif -#ifndef RECYCLE -#include "recycle.h" -#endif -#ifndef PERFECT -#include "perfect.h" -#endif - -/* ------------------------------------------------------------------------------- -Find the mapping that will produce a perfect hash ------------------------------------------------------------------------------- -*/ - -/* return the ceiling of the log (base 2) of val */ -ub4 mylog2(val) -ub4 val; -{ - ub4 i; - for (i=0; ((ub4)1<>const3)); - x = (x+(x<>const5)); - } - return x; -} - -/* initialize scramble[] with distinct random values in 0..smax-1 */ -static void scrambleinit(scramble, smax) -ub4 *scramble; /* hash is a^scramble[tab[b]] */ -ub4 smax; /* scramble values should be in 0..smax-1 */ -{ - ub4 i; - - /* fill scramble[] with distinct random integers in 0..smax-1 */ - for (i=0; ihashtype) - { - case STRING_HT: - if ((key1->len_k == key2->len_k) && - !memcmp(key1->name_k, key2->name_k, (size_t)key1->len_k)) - { - fprintf(stderr, "perfect.c: Duplicates keys! %.*s\n", - key1->len_k, key1->name_k); - exit(SUCCESS); - } - break; - case INT_HT: - if (key1->hash_k == key2->hash_k) - { - fprintf(stderr, "perfect.c: Duplicate keys! %.8lx\n", key1->hash_k); - exit(SUCCESS); - } - break; - case AB_HT: - fprintf(stderr, "perfect.c: Duplicate keys! %.8lx %.8lx\n", - key1->a_k, key1->b_k); - exit(SUCCESS); - break; - default: - fprintf(stderr, "perfect.c: Illegal hash type %ld\n", (ub4)form->hashtype); - exit(SUCCESS); - break; - } -} - - -/* - * put keys in tabb according to key->b_k - * check if the initial hash might work - */ -static int inittab(tabb, blen, keys, form, complete) -bstuff *tabb; /* output, list of keys with b for (a,b) */ -ub4 blen; /* length of tabb */ -key *keys; /* list of keys already hashed */ -hashform *form; /* user directives */ -int complete; /* TRUE means to complete init despite collisions */ -{ - int nocollision = TRUE; - key *mykey; - - memset((void *)tabb, 0, (size_t)(sizeof(bstuff)*blen)); - - /* Two keys with the same (a,b) guarantees a collision */ - for (mykey=keys; mykey; mykey=mykey->next_k) - { - key *otherkey; - - for (otherkey=tabb[mykey->b_k].list_b; - otherkey; - otherkey=otherkey->nextb_k) - { - if (mykey->a_k == otherkey->a_k) - { - nocollision = FALSE; - checkdup(mykey, otherkey, form); - if (!complete) - return FALSE; - } - } - ++tabb[mykey->b_k].listlen_b; - mykey->nextb_k = tabb[mykey->b_k].list_b; - tabb[mykey->b_k].list_b = mykey; - } - - /* no two keys have the same (a,b) pair */ - return nocollision; -} - - -/* Do the initial hash for normal mode (use lookup and checksum) */ -static void initnorm(keys, alen, blen, smax, salt, final) -key *keys; /* list of all keys */ -ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ -ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ -ub4 smax; /* maximum range of computable hash values */ -ub4 salt; /* used to initialize the hash function */ -gencode *final; /* output, code for the final hash */ -{ - key *mykey; - if (mylog2(alen)+mylog2(blen) > UB4BITS) - { - ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ - - for (mykey=keys; mykey; mykey=mykey->next_k) - { - ub4 i, state[CHECKSTATE]; - for (i=0; iname_k, mykey->len_k, state); - mykey->a_k = state[0]&(alen-1); - mykey->b_k = state[1]&(blen-1); - } - final->used = 4; - sprintf(final->line[0], - " ub4 i,state[CHECKSTATE],rsl;\n"); - sprintf(final->line[1], - " for (i=0; iline[2], - " checksum(key, len, state);\n"); - sprintf(final->line[3], - " rsl = ((state[0]&0x%x)^scramble[tab[state[1]&0x%x]]);\n", - alen-1, blen-1); - } - else - { - ub4 loga = mylog2(alen); /* log based 2 of blen */ - ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ - - for (mykey=keys; mykey; mykey=mykey->next_k) - { - ub4 hash = lookup(mykey->name_k, mykey->len_k, initlev); - mykey->a_k = (loga > 0) ? hash>>(UB4BITS-loga) : 0; - mykey->b_k = (blen > 1) ? hash&(blen-1) : 0; - } - final->used = 2; - sprintf(final->line[0], - " ub4 rsl, val = lookup(key, len, 0x%lx);\n", initlev); - if (smax <= 1) - { - sprintf(final->line[1], " rsl = 0;\n"); - } - else if (mylog2(alen) == 0) - { - sprintf(final->line[1], " rsl = tab[val&0x%x];\n", blen-1); - } - else if (blen < USE_SCRAMBLE) - { - sprintf(final->line[1], " rsl = ((val>>%ld)^tab[val&0x%x]);\n", - UB4BITS-mylog2(alen), blen-1); - } - else - { - sprintf(final->line[1], " rsl = ((val>>%ld)^scramble[tab[val&0x%x]]);\n", - UB4BITS-mylog2(alen), blen-1); - } - } -} - - - -/* Do initial hash for inline mode */ -static void initinl(keys, alen, blen, smax, salt, final) -key *keys; /* list of all keys */ -ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ -ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ -ub4 smax; /* range of computable hash values */ -ub4 salt; /* used to initialize the hash function */ -gencode *final; /* generated code for final hash */ -{ - key *mykey; - ub4 amask = alen-1; - ub4 blog = mylog2(blen); - ub4 initval = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */ - - /* It's more important to have b uniform than a, so b is the low bits */ - for (mykey = keys; mykey != (key *)0; mykey = mykey->next_k) - { - ub4 hash = initval; - ub4 i; - for (i=0; ilen_k; ++i) - { - hash = (mykey->name_k[i] ^ hash) + ((hash<<(UB4BITS-6))+(hash>>6)); - } - mykey->hash_k = hash; - mykey->a_k = (alen > 1) ? (hash & amask) : 0; - mykey->b_k = (blen > 1) ? (hash >> (UB4BITS-blog)) : 0; - } - final->used = 1; - if (smax <= 1) - { - sprintf(final->line[0], " ub4 rsl = 0;\n"); - } - else if (blen < USE_SCRAMBLE) - { - sprintf(final->line[0], " ub4 rsl = ((val & 0x%lx) ^ tab[val >> %ld]);\n", - amask, UB4BITS-blog); - } - else - { - sprintf(final->line[0], " ub4 rsl = ((val & 0x%lx) ^ scramble[tab[val >> %ld]]);\n", - amask, UB4BITS-blog); - } -} - - -/* - * Run a hash function on the key to get a and b - * Returns: - * 0: didn't find distinct (a,b) for all keys - * 1: found distinct (a,b) for all keys, put keys in tabb[] - * 2: found a perfect hash, no need to do any more work - */ -static ub4 initkey(keys, nkeys, tabb, alen, blen, smax, salt, form, final) -key *keys; /* list of all keys */ -ub4 nkeys; /* total number of keys */ -bstuff *tabb; /* stuff indexed by b */ -ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ -ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ -ub4 smax; /* range of computable hash values */ -ub4 salt; /* used to initialize the hash function */ -hashform *form; /* user directives */ -gencode *final; /* code for final hash */ -{ - ub4 finished; - - /* Do the initial hash of the keys */ - switch(form->mode) - { - case NORMAL_HM: - initnorm(keys, alen, blen, smax, salt, final); - break; - case INLINE_HM: - initinl(keys, alen, blen, smax, salt, final); - break; - case HEX_HM: - case DECIMAL_HM: - finished = inithex(keys, nkeys, alen, blen, smax, salt, final, form); - if (finished) return 2; - break; - default: - fprintf(stderr, "fatal error: illegal mode\n"); - exit(1); - } - - if (nkeys <= 1) - { - final->used = 1; - sprintf(final->line[0], " ub4 rsl = 0;\n"); - return 2; - } - - return inittab(tabb, blen, keys, form, FALSE); -} - -/* Print an error message and exit if there are duplicates */ -static void duplicates(tabb, blen, keys, form) -bstuff *tabb; /* array of lists of keys with the same b */ -ub4 blen; /* length of tabb, a power of 2 */ -key *keys; -hashform *form; /* user directives */ -{ - ub4 i; - key *key1; - key *key2; - - (void)inittab(tabb, blen, keys, form, TRUE); - - /* for each b, do nested loops through key list looking for duplicates */ - for (i=0; inextb_k) - for (key2=key1->nextb_k; key2; key2=key2->nextb_k) - checkdup(key1, key2, form); -} - - -/* Try to apply an augmenting list */ -static int apply(tabb, tabh, tabq, blen, scramble, tail, rollback) -bstuff *tabb; -hstuff *tabh; -qstuff *tabq; -ub4 blen; -ub4 *scramble; -ub4 tail; -int rollback; /* FALSE applies augmenting path, TRUE rolls back */ -{ - ub4 hash; - key *mykey; - bstuff *pb; - ub4 child; - ub4 parent; - ub4 stabb; /* scramble[tab[b]] */ - - /* walk from child to parent */ - for (child=tail-1; child; child=parent) - { - parent = tabq[child].parent_q; /* find child's parent */ - pb = tabq[parent].b_q; /* find parent's list of siblings */ - - /* erase old hash values */ - stabb = scramble[pb->val_b]; - for (mykey=pb->list_b; mykey; mykey=mykey->nextb_k) - { - hash = mykey->a_k^stabb; - if (mykey == tabh[hash].key_h) - { /* erase hash for all of child's siblings */ - tabh[hash].key_h = (key *)0; - } - } - - /* change pb->val_b, which will change the hashes of all parent siblings */ - pb->val_b = (rollback ? tabq[child].oldval_q : tabq[child].newval_q); - - /* set new hash values */ - stabb = scramble[pb->val_b]; - for (mykey=pb->list_b; mykey; mykey=mykey->nextb_k) - { - hash = mykey->a_k^stabb; - if (rollback) - { - if (parent == 0) continue; /* root never had a hash */ - } - else if (tabh[hash].key_h) - { - /* very rare: roll back any changes */ - (void *)apply(tabb, tabh, tabq, blen, scramble, tail, TRUE); - return FALSE; /* failure, collision */ - } - tabh[hash].key_h = mykey; - } - } - return TRUE; -} - - -/* -------------------------------------------------------------------------------- -augment(): Add item to the mapping. - -Construct a spanning tree of *b*s with *item* as root, where each -parent can have all its hashes changed (by some new val_b) with -at most one collision, and each child is the b of that collision. - -I got this from Tarjan's "Data Structures and Network Algorithms". The -path from *item* to a *b* that can be remapped with no collision is -an "augmenting path". Change values of tab[b] along the path so that -the unmapped key gets mapped and the unused hash value gets used. - -Assuming 1 key per b, if m out of n hash values are still unused, -you should expect the transitive closure to cover n/m nodes before -an unused node is found. Sum(i=1..n)(n/i) is about nlogn, so expect -this approach to take about nlogn time to map all single-key b's. -------------------------------------------------------------------------------- -*/ -static int augment(tabb, tabh, tabq, blen, scramble, smax, item, nkeys, - highwater, form) -bstuff *tabb; /* stuff indexed by b */ -hstuff *tabh; /* which key is associated with which hash, indexed by hash */ -qstuff *tabq; /* queue of *b* values, this is the spanning tree */ -ub4 blen; /* length of tabb */ -ub4 *scramble; /* final hash is a^scramble[tab[b]] */ -ub4 smax; /* highest value in scramble */ -bstuff *item; /* &tabb[b] for the b to be mapped */ -ub4 nkeys; /* final hash must be in 0..nkeys-1 */ -ub4 highwater; /* a value higher than any now in tabb[].water_b */ -hashform *form; /* TRUE if we should do a minimal perfect hash */ -{ - ub4 q; /* current position walking through the queue */ - ub4 tail; /* tail of the queue. 0 is the head of the queue. */ - ub4 limit=((blen < USE_SCRAMBLE) ? smax : UB1MAXVAL+1); - ub4 highhash = ((form->perfect == MINIMAL_HP) ? nkeys : smax); - int trans = (form->speed == SLOW_HS || form->perfect == MINIMAL_HP); - - /* initialize the root of the spanning tree */ - tabq[0].b_q = item; - tail = 1; - - /* construct the spanning tree by walking the queue, add children to tail */ - for (q=0; qval_b */ - - if (!trans && (q == 1)) - break; /* don't do transitive closure */ - - for (i=0; ilist_b; mykey; mykey=mykey->nextb_k) - { - key *childkey; - ub4 hash = mykey->a_k^scramble[i]; - - if (hash >= highhash) break; /* out of bounds */ - childkey = tabh[hash].key_h; - - if (childkey) - { - bstuff *hitb = &tabb[childkey->b_k]; - - if (childb) - { - if (childb != hitb) break; /* hit at most one child b */ - } - else - { - childb = hitb; /* remember this as childb */ - if (childb->water_b == highwater) break; /* already explored */ - } - } - } - if (mykey) continue; /* myb with i has multiple collisions */ - - /* add childb to the queue of reachable things */ - if (childb) childb->water_b = highwater; - tabq[tail].b_q = childb; - tabq[tail].newval_q = i; /* how to make parent (myb) use this hash */ - tabq[tail].oldval_q = myb->val_b; /* need this for rollback */ - tabq[tail].parent_q = q; - ++tail; - - if (!childb) - { /* found an *i* with no collisions? */ - /* try to apply the augmenting path */ - if (apply(tabb, tabh, tabq, blen, scramble, tail, FALSE)) - return TRUE; /* success, item was added to the perfect hash */ - - --tail; /* don't know how to handle such a child! */ - } - } - } - return FALSE; -} - - -/* find a mapping that makes this a perfect hash */ -static int perfect(tabb, tabh, tabq, blen, smax, scramble, nkeys, form) -bstuff *tabb; -hstuff *tabh; -qstuff *tabq; -ub4 blen; -ub4 smax; -ub4 *scramble; -ub4 nkeys; -hashform *form; -{ - ub4 maxkeys; /* maximum number of keys for any b */ - ub4 i, j; - - /* clear any state from previous attempts */ - memset((void *)tabh, 0, - (size_t)(sizeof(hstuff)* - ((form->perfect == MINIMAL_HP) ? nkeys : smax))); - memset((void *)tabq, 0, (size_t)(sizeof(qstuff)*(blen+1))); - - for (maxkeys=0,i=0; i maxkeys) - maxkeys = tabb[i].listlen_b; - - /* In descending order by number of keys, map all *b*s */ - for (j=maxkeys; j>0; --j) - for (i=0; ia_k, key->b_k), and final->form == AB_HK. - */ -static void hash_ab(tabb, alen, blen, salt, final, - scramble, smax, keys, nkeys, form) -bstuff **tabb; /* output, tab[] of the perfect hash, length *blen */ -ub4 *alen; /* output, 0..alen-1 is range for a of (a,b) */ -ub4 *blen; /* output, 0..blen-1 is range for b of (a,b) */ -ub4 *salt; /* output, initializes initial hash */ -gencode *final; /* code for final hash */ -ub4 *scramble; /* input, hash = a^scramble[tab[b]] */ -ub4 *smax; /* input, scramble[i] in 0..smax-1 */ -key *keys; /* input, keys to hash */ -ub4 nkeys; /* input, number of keys being hashed */ -hashform *form; /* user directives */ -{ - hstuff *tabh; - qstuff *tabq; - key *mykey; - ub4 i; - int used_tab; - - /* initially make smax the first power of two bigger than nkeys */ - *smax = ((ub4)1<next_k) - { - while (*alen <= mykey->a_k) *alen *= 2; - while (*blen <= mykey->b_k) *blen *= 2; - } - if (*alen > 2**smax) - { - fprintf(stderr, - "perfect.c: Can't deal with (A,B) having A bigger than twice \n"); - fprintf(stderr, - " the smallest power of two greater or equal to any legal hash.\n"); - exit(SUCCESS); - } - - /* allocate working memory */ - *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); - tabq = (qstuff *)remalloc(sizeof(qstuff)*(*blen+1), "perfect.c, tabq"); - tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? - nkeys : *smax), - "perfect.c, tabh"); - - /* check that (a,b) are distinct and put them in tabb indexed by b */ - (void)inittab(*tabb, *blen, keys, form, FALSE); - - /* try with smax */ - if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) - { - if (form->perfect == MINIMAL_HP) - { - printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n"); - exit(SUCCESS); - } - else - { - /* try with 2*smax */ - free((void *)tabh); - *smax = *smax * 2; - scrambleinit(scramble, *smax); - tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? - nkeys : *smax), - "perfect.c, tabh"); - if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) - { - printf("fatal error: Cannot find perfect hash for user (A,B) pairs\n"); - exit(SUCCESS); - } - } - } - - /* check if tab[] was really needed */ - for (i=0; i<*blen; ++i) - { - if ((*tabb)[i].val_b != 0) break; /* assumes permute(0) == 0 */ - } - used_tab = (i < *blen); - - /* write the code for the perfect hash */ - *salt = 1; - final->used = 1; - if (!used_tab) - { - sprintf(final->line[0], " ub4 rsl = a;\n"); - } - else if (*blen < USE_SCRAMBLE) - { - sprintf(final->line[0], " ub4 rsl = (a ^ tab[b]);\n"); - } - else - { - sprintf(final->line[0], " ub4 rsl = (a ^ scramble[tab[b]]);\n"); - } - - printf("success, found a perfect hash\n"); - - free((void *)tabq); - free((void *)tabh); -} - - -/* guess initial values for alen and blen */ -static void initalen(alen, blen, smax, nkeys, form) -ub4 *alen; /* output, initial alen */ -ub4 *blen; /* output, initial blen */ -ub4 *smax; /* input, power of two greater or equal to max hash value */ -ub4 nkeys; /* number of keys being hashed */ -hashform *form; /* user directives */ -{ - /* - * Find initial *alen, *blen - * Initial alen and blen values were found empirically. Some factors: - * - * If smax<256 there is no scramble, so tab[b] needs to cover 0..smax-1. - * - * alen and blen must be powers of 2 because the values in 0..alen-1 and - * 0..blen-1 are produced by applying a bitmask to the initial hash function. - * - * alen must be less than smax, in fact less than nkeys, because otherwise - * there would often be no i such that a^scramble[i] is in 0..nkeys-1 for - * all the *a*s associated with a given *b*, so there would be no legal - * value to assign to tab[b]. This only matters when we're doing a minimal - * perfect hash. - * - * It takes around 800 trials to find distinct (a,b) with nkey=smax*(5/8) - * and alen*blen = smax*smax/32. - * - * Values of blen less than smax/4 never work, and smax/2 always works. - * - * We want blen as small as possible because it is the number of bytes in - * the huge array we must create for the perfect hash. - * - * When nkey <= smax*(5/8), blen=smax/4 works much more often with - * alen=smax/8 than with alen=smax/4. Above smax*(5/8), blen=smax/4 - * doesn't seem to care whether alen=smax/8 or alen=smax/4. I think it - * has something to do with 5/8 = 1/8 * 5. For example examine 80000, - * 85000, and 90000 keys with different values of alen. This only matters - * if we're doing a minimal perfect hash. - * - * When alen*blen <= 1<perfect == NORMAL_HP) - { - if ((form->speed == FAST_HS) && (nkeys > *smax*0.8)) - { - *smax = *smax * 2; - } - - *alen = ((form->hashtype==INT_HT) && *smax>131072) ? - ((ub4)1<<(UB4BITS-mylog2(*blen))) : /* distinct keys => distinct (A,B) */ - *smax; /* no reason to restrict alen to smax/2 */ - if ((form->hashtype == INT_HT) && *smax < 32) - *blen = *smax; /* go for function speed not space */ - else if (*smax/4 <= (1<<14)) - *blen = ((nkeys <= *smax*0.56) ? *smax/32 : - (nkeys <= *smax*0.74) ? *smax/16 : *smax/8); - else - *blen = ((nkeys <= *smax*0.6) ? *smax/16 : - (nkeys <= *smax*0.8) ? *smax/8 : *smax/4); - - if ((form->speed == FAST_HS) && (*blen < *smax/8)) - *blen = *smax/8; - - if (*alen < 1) *alen = 1; - if (*blen < 1) *blen = 1; - } - else - { - switch(mylog2(*smax)) - { - case 0: - *alen = 1; - *blen = 1; - case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: - *alen = (form->perfect == NORMAL_HP) ? *smax : *smax/2; - *blen = *smax/2; - break; - case 9: - case 10: - case 11: - case 12: - case 13: - case 14: - case 15: - case 16: - case 17: - if (form->speed == FAST_HS) - { - *alen = *smax/2; - *blen = *smax/4; - } - else if (*smax/4 < USE_SCRAMBLE) - { - *alen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4); - *blen = ((nkeys <= *smax*0.52) ? *smax/8 : *smax/4); - } - else - { - *alen = ((nkeys <= *smax*(5.0/8.0)) ? *smax/8 : - (nkeys <= *smax*(3.0/4.0)) ? *smax/4 : *smax/2); - *blen = *smax/4; /* always give the small size a shot */ - } - break; - case 18: - if (form->speed == FAST_HS) - { - *alen = *smax/2; - *blen = *smax/2; - } - else - { - *alen = *smax/8; /* never require the multiword hash */ - *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2; - } - break; - case 19: - case 20: - *alen = (nkeys <= *smax*(5.0/8.0)) ? *smax/8 : *smax/2; - *blen = (nkeys <= *smax*(5.0/8.0)) ? *smax/4 : *smax/2; - break; - default: - *alen = *smax/2; /* just find a hash as quick as possible */ - *blen = *smax/2; /* we'll be thrashing virtual memory at this size */ - break; - } - } -} - -/* -** Try to find a perfect hash function. -** Return the successful initializer for the initial hash. -** Return 0 if no perfect hash could be found. -*/ -void findhash(tabb, alen, blen, salt, final, - scramble, smax, keys, nkeys, form) -bstuff **tabb; /* output, tab[] of the perfect hash, length *blen */ -ub4 *alen; /* output, 0..alen-1 is range for a of (a,b) */ -ub4 *blen; /* output, 0..blen-1 is range for b of (a,b) */ -ub4 *salt; /* output, initializes initial hash */ -gencode *final; /* code for final hash */ -ub4 *scramble; /* input, hash = a^scramble[tab[b]] */ -ub4 *smax; /* input, scramble[i] in 0..smax-1 */ -key *keys; /* input, keys to hash */ -ub4 nkeys; /* input, number of keys being hashed */ -hashform *form; /* user directives */ -{ - ub4 bad_initkey; /* how many times did initkey fail? */ - ub4 bad_perfect; /* how many times did perfect fail? */ - ub4 trysalt; /* trial initializer for initial hash */ - ub4 maxalen; - hstuff *tabh; /* table of keys indexed by hash value */ - qstuff *tabq; /* table of stuff indexed by queue value, used by augment */ - - /* The case of (A,B) supplied by the user is a special case */ - if (form->hashtype == AB_HT) - { - hash_ab(tabb, alen, blen, salt, final, - scramble, smax, keys, nkeys, form); - return; - } - - /* guess initial values for smax, alen and blen */ - *smax = ((ub4)1<perfect == MINIMAL_HP) ? *smax/2 : *smax; - - /* allocate working memory */ - *tabb = (bstuff *)remalloc((size_t)(sizeof(bstuff)*(*blen)), - "perfect.c, tabb"); - tabq = (qstuff *)remalloc(sizeof(qstuff)*(*blen+1), "perfect.c, tabq"); - tabh = (hstuff *)remalloc(sizeof(hstuff)*(form->perfect == MINIMAL_HP ? - nkeys : *smax), - "perfect.c, tabh"); - - /* Actually find the perfect hash */ - *salt = 0; - bad_initkey = 0; - bad_perfect = 0; - for (trysalt=1; ; ++trysalt) - { - ub4 rslinit; - /* Try to find distinct (A,B) for all keys */ - - rslinit = initkey(keys, nkeys, *tabb, *alen, *blen, *smax, trysalt, - form, final); - - if (rslinit == 2) - { /* initkey actually found a perfect hash, not just distinct (a,b) */ - *salt = 1; - *blen = 0; - break; - } - else if (rslinit == 0) - { - /* didn't find distinct (a,b) */ - if (++bad_initkey >= RETRY_INITKEY) - { - /* Try to put more bits in (A,B) to make distinct (A,B) more likely */ - if (*alen < maxalen) - { - *alen *= 2; - } - else if (*blen < *smax) - { - *blen *= 2; - free(tabq); - free(*tabb); - *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); - tabq = (qstuff *)malloc((size_t)(sizeof(qstuff)*(*blen+1))); - } - else - { - duplicates(*tabb, *blen, keys, form); /* check for duplicates */ - printf("fatal error: Cannot perfect hash: cannot find distinct (A,B)\n"); - exit(SUCCESS); - } - bad_initkey = 0; - bad_perfect = 0; - } - continue; /* two keys have same (a,b) pair */ - } - - printf("found distinct (A,B) on attempt %ld\n", trysalt); - - /* Given distinct (A,B) for all keys, build a perfect hash */ - if (!perfect(*tabb, tabh, tabq, *blen, *smax, scramble, nkeys, form)) - { - if ((form->hashtype != INT_HT && ++bad_perfect >= RETRY_PERFECT) || - (form->hashtype == INT_HT && ++bad_perfect >= RETRY_HEX)) - { - if (*blen < *smax) - { - *blen *= 2; - free(*tabb); - free(tabq); - *tabb = (bstuff *)malloc((size_t)(sizeof(bstuff)*(*blen))); - tabq = (qstuff *)malloc((size_t)(sizeof(qstuff)*(*blen+1))); - --trysalt; /* we know this salt got distinct (A,B) */ - } - else - { - printf("fatal error: Cannot perfect hash: cannot build tab[]\n"); - exit(SUCCESS); - } - bad_perfect = 0; - } - continue; - } - - *salt = trysalt; - break; - } - - printf("built perfect hash table of size %ld\n", *blen); - - /* free working memory */ - free((void *)tabh); - free((void *)tabq); -} - -/* ------------------------------------------------------------------------------- -Input/output type routines ------------------------------------------------------------------------------- -*/ - -/* get the list of keys */ -static void getkeys(keys, nkeys, textroot, keyroot, form) -key **keys; /* list of all keys */ -ub4 *nkeys; /* number of keys */ -reroot *textroot; /* get space to store key text */ -reroot *keyroot; /* get space for keys */ -hashform *form; /* user directives */ -{ - key *mykey; - char *mytext; - mytext = (char *)renew(textroot); - *keys = 0; - *nkeys = 0; - while (fgets(mytext, MAXKEYLEN, stdin)) - { - mykey = (key *)renew(keyroot); - if (form->mode == AB_HM) - { - sscanf(mytext, "%lx %lx ", &mykey->a_k, &mykey->b_k); - } - else if (form->mode == ABDEC_HM) - { - sscanf(mytext, "%ld %ld ", &mykey->a_k, &mykey->b_k); - } - else if (form->mode == HEX_HM) - { - sscanf(mytext, "%lx ", &mykey->hash_k); - } - else if (form->mode == DECIMAL_HM) - { - sscanf(mytext, "%ld ", &mykey->hash_k); - } - else - { - mykey->name_k = (ub1 *)mytext; - mytext = (char *)renew(textroot); - mykey->len_k = (ub4)(strlen((char *)mykey->name_k)-1); - } - mykey->next_k = *keys; - *keys = mykey; - ++*nkeys; - } - redel(textroot, mytext); -} - -/* make the .h file */ -static void make_h(blen, smax, nkeys, salt) -ub4 blen; -ub4 smax; -ub4 nkeys; -ub4 salt; -{ - FILE *f; - f = fopen("phash.h", "w"); - fprintf(f, "/* Perfect hash definitions */\n"); - fprintf(f, "#ifndef STANDARD\n"); - fprintf(f, "#include \"standard.h\"\n"); - fprintf(f, "#endif /* STANDARD */\n"); - fprintf(f, "#ifndef PHASH\n"); - fprintf(f, "#define PHASH\n"); - fprintf(f, "\n"); - if (blen > 0) - { - if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE) - fprintf(f, "extern ub1 tab[];\n"); - else - { - fprintf(f, "extern ub2 tab[];\n"); - if (blen >= USE_SCRAMBLE) - { - if (smax <= UB2MAXVAL+1) - fprintf(f, "extern ub2 scramble[];\n"); - else - fprintf(f, "extern ub4 scramble[];\n"); - } - } - fprintf(f, "#define PHASHLEN 0x%lx /* length of hash mapping table */\n", - blen); - } - fprintf(f, "#define PHASHNKEYS %ld /* How many keys were hashed */\n", - nkeys); - fprintf(f, "#define PHASHRANGE %ld /* Range any input might map to */\n", - smax); - fprintf(f, "#define PHASHSALT 0x%.8lx /* internal, initialize normal hash */\n", - salt*0x9e3779b9); - fprintf(f, "\n"); - fprintf(f, "ub4 phash();\n"); - fprintf(f, "\n"); - fprintf(f, "#endif /* PHASH */\n"); - fprintf(f, "\n"); - fclose(f); -} - -/* make the .c file */ -static void make_c(tab, smax, blen, scramble, final, form) -bstuff *tab; /* table indexed by b */ -ub4 smax; /* range of scramble[] */ -ub4 blen; /* b in 0..blen-1, power of 2 */ -ub4 *scramble; /* used in final hash */ -gencode *final; /* code for the final hash */ -hashform *form; /* user directives */ -{ - ub4 i; - FILE *f; - f = fopen("phash.c", "w"); - fprintf(f, "/* table for the mapping for the perfect hash */\n"); - fprintf(f, "#ifndef STANDARD\n"); - fprintf(f, "#include \"standard.h\"\n"); - fprintf(f, "#endif /* STANDARD */\n"); - fprintf(f, "#ifndef PHASH\n"); - fprintf(f, "#include \"phash.h\"\n"); - fprintf(f, "#endif /* PHASH */\n"); - fprintf(f, "#ifndef LOOKUPA\n"); - fprintf(f, "#include \"lookupa.h\"\n"); - fprintf(f, "#endif /* LOOKUPA */\n"); - fprintf(f, "\n"); - if (blen >= USE_SCRAMBLE) - { - fprintf(f, "/* A way to make the 1-byte values in tab bigger */\n"); - if (smax > UB2MAXVAL+1) - { - fprintf(f, "ub4 scramble[] = {\n"); - for (i=0; i<=UB1MAXVAL; i+=4) - fprintf(f, "0x%.8lx, 0x%.8lx, 0x%.8lx, 0x%.8lx,\n", - scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3]); - } - else - { - fprintf(f, "ub2 scramble[] = {\n"); - for (i=0; i<=UB1MAXVAL; i+=8) - fprintf(f, -"0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx, 0x%.4lx,\n", - scramble[i+0], scramble[i+1], scramble[i+2], scramble[i+3], - scramble[i+4], scramble[i+5], scramble[i+6], scramble[i+7]); - } - fprintf(f, "};\n"); - fprintf(f, "\n"); - } - if (blen > 0) - { - fprintf(f, "/* small adjustments to _a_ to make values distinct */\n"); - - if (smax <= UB1MAXVAL+1 || blen >= USE_SCRAMBLE) - fprintf(f, "ub1 tab[] = {\n"); - else - fprintf(f, "ub2 tab[] = {\n"); - - if (blen < 16) - { - for (i=0; imode) - { - case NORMAL_HM: - fprintf(f, "ub4 phash(key, len)\n"); - fprintf(f, "char *key;\n"); - fprintf(f, "int len;\n"); - break; - case INLINE_HM: - case HEX_HM: - case DECIMAL_HM: - fprintf(f, "ub4 phash(val)\n"); - fprintf(f, "ub4 val;\n"); - break; - case AB_HM: - case ABDEC_HM: - fprintf(f, "ub4 phash(a,b)\n"); - fprintf(f, "ub4 a;\n"); - fprintf(f, "ub4 b;\n"); - break; - } - fprintf(f, "{\n"); - for (i=0; iused; ++i) - fprintf(f, final->line[i]); - fprintf(f, " return rsl;\n"); - fprintf(f, "}\n"); - fprintf(f, "\n"); - fclose(f); -} - -/* ------------------------------------------------------------------------------- -Read in the keys, find the hash, and write the .c and .h files ------------------------------------------------------------------------------- -*/ -static void driver(form) -hashform *form; /* user directives */ -{ - ub4 nkeys; /* number of keys */ - key *keys; /* head of list of keys */ - bstuff *tab; /* table indexed by b */ - ub4 smax; /* scramble[] values in 0..smax-1, a power of 2 */ - ub4 alen; /* a in 0..alen-1, a power of 2 */ - ub4 blen; /* b in 0..blen-1, a power of 2 */ - ub4 salt; /* a parameter to the hash function */ - reroot *textroot; /* MAXKEYLEN-character text lines */ - reroot *keyroot; /* source of keys */ - gencode final; /* code for final hash */ - ub4 i; - ub4 scramble[SCRAMBLE_LEN]; /* used in final hash function */ - char buf[10][80]; /* buffer for generated code */ - char *buf2[10]; /* also for generated code */ - - /* set up memory sources */ - textroot = remkroot((size_t)MAXKEYLEN); - keyroot = remkroot(sizeof(key)); - - /* set up code for final hash */ - final.line = buf2; - final.used = 0; - final.len = 10; - for (i=0; i<10; ++i) final.line[i] = buf[i]; - - /* read in the list of keywords */ - getkeys(&keys, &nkeys, textroot, keyroot, form); - printf("Read in %ld keys\n",nkeys); - - /* find the hash */ - findhash(&tab, &alen, &blen, &salt, &final, - scramble, &smax, keys, nkeys, form); - - /* generate the phash.h file */ - make_h(blen, smax, nkeys, salt); - printf("Wrote phash.h\n"); - - /* generate the phash.c file */ - make_c(tab, smax, blen, scramble, &final, form); - printf("Wrote phash.c\n"); - - /* clean up memory sources */ - refree(textroot); - refree(keyroot); - free((void *)tab); - printf("Cleaned up\n"); -} - - -/* Describe how to use this utility */ -static void usage_error() -{ - printf("Usage: perfect [-{NnIiHhDdAaBb}{MmPp}{FfSs}] < key.txt \n"); - printf("The input is a list of keys, one key per line.\n"); - printf("Only one of NnIiHhDdAa and one of MmPp may be specified.\n"); - printf(" N,n: normal mode, key is any string string (default).\n"); - printf(" I,i: initial hash for ASCII char strings.\n"); - printf("The initial hash must be\n"); - printf(" hash = PHASHSALT;\n"); - printf(" for (i=0; i>6));\n"); - printf(" }\n"); - printf("Note that this can be inlined in any user loop that walks\n"); - printf("through the key anyways, eliminating the loop overhead.\n"); - printf(" H,h: Keys are 4-byte integers in hex in this format:\n"); - printf("ffffffff\n"); - printf("This is good for optimizing switch statement compilation.\n"); - printf(" D,d: Same as H,h, except in decimal not hexidecimal\n"); - printf(" A,a: An (A,B) pair is supplied in hex in this format:\n"); - printf("aaa bbb\n"); - printf(" B,b: Same as A,a, except in decimal not hexidecimal\n"); - printf("This mode does nothing but find the values of tab[].\n"); - printf("*A* must be less than the total number of keys.\n"); - printf(" M,m: Minimal perfect hash. Hash will be in 0..nkeys-1 (default)\n"); - printf(" P,p: Perfect hash. Hash will be in 0..n-1, where n >= nkeys\n"); - printf("and n is a power of 2. Will probably use a smaller tab[]."); - printf(" F,f: Fast mode. Generate the perfect hash fast.\n"); - printf(" S,s: Slow mode. Spend time finding a good perfect hash.\n"); - - exit(SUCCESS); -} - - -/* Interpret arguments and call the driver */ -/* See usage_error for the expected arguments */ -int main(argc, argv) -int argc; -char **argv; -{ - int mode_given = FALSE; - int minimal_given = FALSE; - int speed_given = FALSE; - hashform form; - char *c; - - /* default behavior */ - form.mode = NORMAL_HM; - form.hashtype = STRING_HT; - form.perfect = MINIMAL_HP; - form.speed = SLOW_HS; - - /* let the user override the default behavior */ - switch (argc) - { - case 1: - break; - case 2: - if (argv[1][0] != '-') - { - usage_error(); - break; - } - for (c = &argv[1][1]; *c != '\0'; ++c) switch(*c) - { - case 'n': case 'N': - case 'i': case 'I': - case 'h': case 'H': - case 'd': case 'D': - case 'a': case 'A': - case 'b': case 'B': - if (mode_given == TRUE) - usage_error(); - switch(*c) - { - case 'n': case 'N': - form.mode = NORMAL_HM; form.hashtype = STRING_HT; break; - case 'i': case 'I': - form.mode = INLINE_HM; form.hashtype = STRING_HT; break; - case 'h': case 'H': - form.mode = HEX_HM; form.hashtype = INT_HT; break; - case 'd': case 'D': - form.mode = DECIMAL_HM; form.hashtype = INT_HT; break; - case 'a': case 'A': - form.mode = AB_HM; form.hashtype = AB_HT; break; - case 'b': case 'B': - form.mode = ABDEC_HM; form.hashtype = AB_HT; break; - } - mode_given = TRUE; - break; - case 'm': case 'M': - case 'p': case 'P': - if (minimal_given == TRUE) - usage_error(); - switch(*c) - { - case 'p': case 'P': - form.perfect = NORMAL_HP; break; - case 'm': case 'M': - form.perfect = MINIMAL_HP; break; - } - minimal_given = TRUE; - break; - case 'f': case 'F': - case 's': case 'S': - if (speed_given == TRUE) - usage_error(); - switch(*c) - { - case 'f': case 'F': - form.speed = FAST_HS; break; - case 's': case 'S': - form.speed = SLOW_HS; break; - } - speed_given = TRUE; - break; - default: - usage_error(); - } - break; - default: - usage_error(); - } - - /* Generate the [minimal] perfect hash */ - driver(&form); - - return SUCCESS; -} diff --git a/tools/codegen/core/perfect/perfect.h b/tools/codegen/core/perfect/perfect.h deleted file mode 100644 index fed5296bb75..00000000000 --- a/tools/codegen/core/perfect/perfect.h +++ /dev/null @@ -1,132 +0,0 @@ -/* ------------------------------------------------------------------------------- -perfect.h: code to generate code for a hash for perfect hashing. -(c) Bob Jenkins, September 1996 -You may use this code in any way you wish, and it is free. No warranty. -I hereby place this in the public domain. -Source is http://burtleburtle.net/bob/c/perfect.h ------------------------------------------------------------------------------- -*/ - -#ifndef STANDARD -#include "standard.h" -#endif - -#ifndef PERFECT -#define PERFECT - -#define MAXKEYLEN 30 /* maximum length of a key */ -#define USE_SCRAMBLE 4096 /* use scramble if blen >= USE_SCRAMBLE */ -#define SCRAMBLE_LEN ((ub4)1<<16) /* length of *scramble* */ -#define RETRY_INITKEY 2048 /* number of times to try to find distinct (a,b) */ -#define RETRY_PERFECT 1 /* number of times to try to make a perfect hash */ -#define RETRY_HEX 200 /* RETRY_PERFECT when hex keys given */ - -/* the generated code for the final hash, assumes initial hash is done */ -struct gencode -{ - char **line; /* array of text lines, 80 bytes apiece */ - /* - * The code placed here must declare "ub4 rsl" - * and assign it the value of the perfect hash using the function inputs. - * Later code will be tacked on which returns rsl or manipulates it according - * to the user directives. - * - * This code is at the top of the routine; it may and must declare any - * local variables it needs. - * - * Each way of filling in **line should be given a comment that is a unique - * tag. A testcase named with that tag should also be found which tests - * the generated code. - */ - ub4 len; /* number of lines available for final hash */ - ub4 used; /* number of lines used by final hash */ - - ub4 lowbit; /* for HEX, lowest interesting bit */ - ub4 highbit; /* for HEX, highest interesting bit */ - ub4 diffbits; /* bits which differ for some key */ - ub4 i,j,k,l,m,n,o; /* state machine used in hexn() */ -}; -typedef struct gencode gencode; - -/* user directives: perfect hash? minimal perfect hash? input is an int? */ -struct hashform -{ - enum { - NORMAL_HM, /* key is a string */ - INLINE_HM, /* user will do initial hash, we must choose salt for them */ - HEX_HM, /* key to be hashed is a hexidecimal 4-byte integer */ - DECIMAL_HM, /* key to be hashed is a decimal 4-byte integer */ - AB_HM, /* key to be hashed is "A B", where A and B are (A,B) in hex */ - ABDEC_HM /* like AB_HM, but in decimal */ - } mode; - enum { - STRING_HT, /* key is a string */ - INT_HT, /* key is an integer */ - AB_HT /* dunno what key is, but input is distinct (A,B) pair */ - } hashtype; - enum { - NORMAL_HP, /* just find a perfect hash */ - MINIMAL_HP /* find a minimal perfect hash */ - } perfect; - enum { - FAST_HS, /* fast mode */ - SLOW_HS /* slow mode */ - } speed; -}; -typedef struct hashform hashform; - -/* representation of a key */ -struct key -{ - ub1 *name_k; /* the actual key */ - ub4 len_k; /* the length of the actual key */ - ub4 hash_k; /* the initial hash value for this key */ - struct key *next_k; /* next key */ -/* beyond this point is mapping-dependent */ - ub4 a_k; /* a, of the key maps to (a,b) */ - ub4 b_k; /* b, of the key maps to (a,b) */ - struct key *nextb_k; /* next key with this b */ -}; -typedef struct key key; - -/* things indexed by b of original (a,b) pair */ -struct bstuff -{ - ub2 val_b; /* hash=a^tabb[b].val_b */ - key *list_b; /* tabb[i].list_b is list of keys with b==i */ - ub4 listlen_b; /* length of list_b */ - ub4 water_b; /* high watermark of who has visited this map node */ -}; -typedef struct bstuff bstuff; - -/* things indexed by final hash value */ -struct hstuff -{ - key *key_h; /* tabh[i].key_h is the key with a hash of i */ -}; -typedef struct hstuff hstuff; - -/* things indexed by queue position */ -struct qstuff -{ - bstuff *b_q; /* b that currently occupies this hash */ - ub4 parent_q; /* queue position of parent that could use this hash */ - ub2 newval_q; /* what to change parent tab[b] to to use this hash */ - ub2 oldval_q; /* original value of tab[b] */ -}; -typedef struct qstuff qstuff; - -/* return ceiling(log based 2 of x) */ -ub4 mylog2(/*_ ub4 x _*/); - -/* Given the keys, scramble[], and hash mode, find the perfect hash */ -void findhash(/*_ bstuff **tabb, ub4 *alen, ub4 *blen, ub4 *salt, - gencode *final, ub4 *scramble, ub4 smax, key *keys, ub4 nkeys, - hashform *form _*/); - -/* private, but in a different file because it's excessively verbose */ -int inithex(/*_ key *keys, ub4 *alen, ub4 *blen, ub4 smax, ub4 nkeys, - ub4 salt, gencode *final, gencode *form _*/); - -#endif /* PERFECT */ diff --git a/tools/codegen/core/perfect/perfhex.c b/tools/codegen/core/perfect/perfhex.c deleted file mode 100644 index 9c28dc734b3..00000000000 --- a/tools/codegen/core/perfect/perfhex.c +++ /dev/null @@ -1,1308 +0,0 @@ -/* ------------------------------------------------------------------------------- -perfhex.c: code to generate code for a hash for perfect hashing. -(c) Bob Jenkins, December 31 1999 -You may use this code in any way you wish, and it is free. No warranty. -I hereby place this in the public domain. -Source is http://burtleburtle.net/bob/c/perfhex.c - -The task of this file is to do the minimal amount of mixing needed to -find distinct (a,b) for each key when each key is a distinct ub4. That -means trying all possible ways to mix starting with the fastest. The -output is those (a,b) pairs and code in the *final* structure for producing -those pairs. ------------------------------------------------------------------------------- -*/ - -#ifndef STANDARD -#include "standard.h" -#endif -#ifndef LOOKUPA -#include "lookupa.h" -#endif -#ifndef RECYCLE -#include "recycle.h" -#endif -#ifndef PERFECT -#include "perfect.h" -#endif - -/* - * Find a perfect hash when there is only one key. Zero instructions. - * Hint: the one key always hashes to 0 - */ -static void hexone(keys, final) -key *keys; -gencode *final; -{ - /* 1 key: the hash is always 0 */ - keys->a_k = 0; - keys->b_k = 0; - final->used = 1; - sprintf(final->line[0], " ub4 rsl = 0;\n"); /* h1a: 37 */ -} - - - -/* - * Find a perfect hash when there are only two keys. Max 2 instructions. - * There exists a bit that is different for the two keys. Test it. - * Note that a perfect hash of 2 keys is automatically minimal. - */ -static void hextwo(keys, final) -key *keys; -gencode *final; -{ - ub4 a = keys->hash_k; - ub4 b = keys->next_k->hash_k; - ub4 i; - - if (a == b) - { - printf("fatal error: duplicate keys\n"); - exit(SUCCESS); - } - - final->used = 1; - - /* one instruction */ - if ((a&1) != (b&1)) - { - sprintf(final->line[0], " ub4 rsl = (val & 1);\n"); /* h2a: 3,4 */ - return; - } - - /* two instructions */ - for (i=0; iline[0], " ub4 rsl = ((val << %ld) & 1);\n", i); -} - - - -/* - * find the value to xor to a and b and c to make none of them 3 - * assert, (a,b,c) are three distinct values in (0,1,2,3). - */ -static ub4 find_adder(a,b,c) -ub4 a; -ub4 b; -ub4 c; -{ - return (a^b^c^3); -} - - - -/* - * Find a perfect hash when there are only three keys. Max 6 instructions. - * - * keys a,b,c. - * There exists bit i such that a[i] != b[i]. - * Either c[i] != a[i] or c[i] != b[i], assume c[i] != a[i]. - * There exists bit j such that b[j] != c[j]. Note i != j. - * Final hash should be no longer than val[i]^val[j]. - * - * A minimal perfect hash needs to xor one of 0,1,2,3 afterwards to cause - * the hole to land on 3. find_adder() finds that constant - */ -static void hexthree(keys, final, form) -key *keys; -gencode *final; -hashform *form; -{ - ub4 a = keys->hash_k; - ub4 b = keys->next_k->hash_k; - ub4 c = keys->next_k->next_k->hash_k; - ub4 i,j,x,y,z; - - final->used = 1; - - if (a == b || a == c || b == c) - { - printf("fatal error: duplicate keys\n"); - exit(SUCCESS); - } - - /* one instruction */ - x = a&3; - y = b&3; - z = c&3; - if (x != y && x != z && y != z) - { - if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) - { - /* h3a: 0,1,2 */ - sprintf(final->line[0], " ub4 rsl = (val & 3);\n"); - } - else - { - /* h3b: 0,3,2 */ - sprintf(final->line[0], " ub4 rsl = ((val & 3) ^ %d);\n", - find_adder(x,y,z)); - } - return; - } - - x = a>>(UB4BITS-2); - y = b>>(UB4BITS-2); - z = c>>(UB4BITS-2); - if (x != y && x != z && y != z) - { - if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) - { - /* h3c: 3fffffff, 7fffffff, bfffffff */ - sprintf(final->line[0], " ub4 rsl = (val >> %ld);\n", (ub4)(UB4BITS-2)); - } - else - { - /* h3d: 7fffffff, bfffffff, ffffffff */ - sprintf(final->line[0], " ub4 rsl = ((val >> %ld) ^ %ld);\n", - (ub4)(UB4BITS-2), find_adder(x,y,z)); - } - return; - } - - /* two instructions */ - for (i=0; ihighbit; ++i) - { - x = (a>>i)&3; - y = (b>>i)&3; - z = (c>>i)&3; - if (x != y && x != z && y != z) - { - if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) - { - /* h3e: ffff3fff, ffff7fff, ffffbfff */ - sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 3);\n", i); - } - else - { - /* h3f: ffff7fff, ffffbfff, ffffffff */ - sprintf(final->line[0], " ub4 rsl = (((val >> %ld) & 3) ^ %ld);\n", i, - find_adder(x,y,z)); - } - return; - } - } - - /* three instructions */ - for (i=0; i<=final->highbit; ++i) - { - x = (a+(a>>i))&3; - y = (b+(b>>i))&3; - z = (c+(c>>i))&3; - if (x != y && x != z && y != z) - { - if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) - { - /* h3g: 0x000, 0x001, 0x100 */ - sprintf(final->line[0], " ub4 rsl = ((val+(val>>%ld))&3);\n", i); - } - else - { - /* h3h: 0x001, 0x100, 0x101 */ - sprintf(final->line[0], " ub4 rsl = (((val+(val>>%ld))&3)^%ld);\n", i, - find_adder(x,y,z)); - } - return; - } - } - - /* - * Four instructions: I can prove this will always work. - * - * If the three values are distinct, there are two bits which - * distinguish them. Choose the two such bits that are closest together. - * If those bits are values 001 and 100 for those three values, - * then there either aren't any bits in between - * or the in-between bits aren't valued 001, 110, 100, 011, 010, or 101, - * because that would violate the closest-together assumption. - * So any in-between bits must be 000 or 111, and of 000 and 111 with - * the distinguishing bits won't cause them to stop being distinguishing. - */ - for (i=final->lowbit; i<=final->highbit; ++i) - { - for (j=i; j<=final->highbit; ++j) - { - x = ((a>>i)^(a>>j))&3; - y = ((b>>i)^(b>>j))&3; - z = ((c>>i)^(c>>j))&3; - if (x != y && x != z && y != z) - { - if (form->perfect == NORMAL_HP || (x != 3 && y != 3 && z != 3)) - { - /* h3i: 0x00, 0x04, 0x10 */ - sprintf(final->line[0], - " ub4 rsl = (((val>>%ld) ^ (val>>%ld)) & 3);\n", i, j); - } - else - { - /* h3j: 0x04, 0x10, 0x14 */ - sprintf(final->line[0], - " ub4 rsl = ((((val>>%ld) ^ (val>>%ld)) & 3) ^ %ld);\n", - i, j, find_adder(x,y,z)); - } - return; - } - } - } - - printf("fatal error: hexthree\n"); - exit(SUCCESS); -} - - - -/* - * Check that a,b,c,d are some permutation of 0,1,2,3 - * Assume that a,b,c,d are all have values less than 32. - */ -static int testfour(a,b,c,d) -ub4 a; -ub4 b; -ub4 c; -ub4 d; -{ - ub4 mask = (1<hash_k; - ub4 b = keys->next_k->hash_k; - ub4 c = keys->next_k->next_k->hash_k; - ub4 d = keys->next_k->next_k->next_k->hash_k; - ub4 w,x,y,z; - ub4 i,j,k; - - if (a==b || a==c || a==d || b==c || b==d || c==d) - { - printf("fatal error: Duplicate keys\n"); - exit(SUCCESS); - } - - final->used = 1; - - /* one instruction */ - if ((final->diffbits & 3) == 3) - { - w = a&3; - x = b&3; - y = c&3; - z = d&3; - if (testfour(w,x,y,z)) - { - sprintf(final->line[0], " ub4 rsl = (val & 3);\n"); /* h4a: 0,1,2,3 */ - return; - } - } - - if (((final->diffbits >> (UB4BITS-2)) & 3) == 3) - { - w = a>>(UB4BITS-2); - x = b>>(UB4BITS-2); - y = c>>(UB4BITS-2); - z = d>>(UB4BITS-2); - if (testfour(w,x,y,z)) - { /* h4b: 0fffffff, 4fffffff, 8fffffff, cfffffff */ - sprintf(final->line[0], " ub4 rsl = (val >> %ld);\n", (ub4)(UB4BITS-2)); - return; - } - } - - /* two instructions */ - for (i=final->lowbit; ihighbit; ++i) - { - if (((final->diffbits >> i) & 3) == 3) - { - w = (a>>i)&3; - x = (b>>i)&3; - y = (c>>i)&3; - z = (d>>i)&3; - if (testfour(w,x,y,z)) - { /* h4c: 0,2,4,6 */ - sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 3);\n", i); - return; - } - } - } - - /* three instructions (linear with the number of diffbits) */ - if ((final->diffbits & 3) != 0) - { - for (i=final->lowbit; i<=final->highbit; ++i) - { - if (((final->diffbits >> i) & 3) != 0) - { - w = (a+(a>>i))&3; - x = (b+(b>>i))&3; - y = (c+(c>>i))&3; - z = (d+(d>>i))&3; - if (testfour(w,x,y,z)) - { /* h4d: 0,1,2,4 */ - sprintf(final->line[0], - " ub4 rsl = ((val + (val >> %ld)) & 3);\n", i); - return; - } - - w = (a-(a>>i))&3; - x = (b-(b>>i))&3; - y = (c-(c>>i))&3; - z = (d-(d>>i))&3; - if (testfour(w,x,y,z)) - { /* h4e: 0,1,3,5 */ - sprintf(final->line[0], - " ub4 rsl = ((val - (val >> %ld)) & 3);\n", i); - return; - } - - /* h4f: ((val>>k)-val)&3: redundant with h4e */ - - w = (a^(a>>i))&3; - x = (b^(b>>i))&3; - y = (c^(c>>i))&3; - z = (d^(d>>i))&3; - if (testfour(w,x,y,z)) - { /* h4g: 3,4,5,8 */ - sprintf(final->line[0], - " ub4 rsl = ((val ^ (val >> %ld)) & 3);\n", i); - return; - } - } - } - } - - /* four instructions (linear with the number of diffbits) */ - if ((final->diffbits & 3) != 0) - { - for (i=final->lowbit; i<=final->highbit; ++i) - { - if ((((final->diffbits >> i) & 1) != 0) && - ((final->diffbits & 2) != 0)) - { - w = (a&3)^((a>>i)&1); - x = (b&3)^((b>>i)&1); - y = (c&3)^((c>>i)&1); - z = (d&3)^((d>>i)&1); - if (testfour(w,x,y,z)) - { /* h4h: 1,2,6,8 */ - sprintf(final->line[0], - " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 1));\n", i); - return; - } - - w = (a&2)^((a>>i)&1); - x = (b&2)^((b>>i)&1); - y = (c&2)^((c>>i)&1); - z = (d&2)^((d>>i)&1); - if (testfour(w,x,y,z)) - { /* h4i: 1,2,8,a */ - sprintf(final->line[0], - " ub4 rsl = ((val & 2) ^ ((val >> %ld) & 1));\n", i); - return; - } - } - - if ((((final->diffbits >> i) & 2) != 0) && - ((final->diffbits & 1) != 0)) - { - w = (a&3)^((a>>i)&2); - x = (b&3)^((b>>i)&2); - y = (c&3)^((c>>i)&2); - z = (d&3)^((d>>i)&2); - if (testfour(w,x,y,z)) - { /* h4j: 0,1,3,4 */ - sprintf(final->line[0], - " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 2));\n", i); - return; - } - - w = (a&1)^((a>>i)&2); - x = (b&1)^((b>>i)&2); - y = (c&1)^((c>>i)&2); - z = (d&1)^((d>>i)&2); - if (testfour(w,x,y,z)) - { /* h4k: 1,4,7,8 */ - sprintf(final->line[0], - " ub4 rsl = ((val & 1) ^ ((val >> %ld) & 2));\n", i); - return; - } - } - } - } - - /* four instructions (quadratic in the number of diffbits) */ - for (i=final->lowbit; i<=final->highbit; ++i) - { - if (((final->diffbits >> i) & 1) == 1) - { - for (j=final->lowbit; j<=final->highbit; ++j) - { - if (((final->diffbits >> j) & 3) != 0) - { - /* test + */ - w = ((a>>i)+(a>>j))&3; - x = ((b>>i)+(a>>j))&3; - y = ((c>>i)+(a>>j))&3; - z = ((d>>i)+(a>>j))&3; - if (testfour(w,x,y,z)) - { /* h4l: testcase? */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) + (val >> %ld)) & 3);\n", - i, j); - return; - } - - /* test - */ - w = ((a>>i)-(a>>j))&3; - x = ((b>>i)-(a>>j))&3; - y = ((c>>i)-(a>>j))&3; - z = ((d>>i)-(a>>j))&3; - if (testfour(w,x,y,z)) - { /* h4m: testcase? */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) - (val >> %ld)) & 3);\n", - i, j); - return; - } - - /* test ^ */ - w = ((a>>i)^(a>>j))&3; - x = ((b>>i)^(a>>j))&3; - y = ((c>>i)^(a>>j))&3; - z = ((d>>i)^(a>>j))&3; - if (testfour(w,x,y,z)) - { /* h4n: testcase? */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) ^ (val >> %ld)) & 3);\n", - i, j); - return; - } - } - } - } - } - - /* five instructions (quadratic in the number of diffbits) */ - for (i=final->lowbit; i<=final->highbit; ++i) - { - if (((final->diffbits >> i) & 1) != 0) - { - for (j=final->lowbit; j<=final->highbit; ++j) - { - if (((final->diffbits >> j) & 3) != 0) - { - w = ((a>>j)&3)^((a>>i)&1); - x = ((b>>j)&3)^((b>>i)&1); - y = ((c>>j)&3)^((c>>i)&1); - z = ((d>>j)&3)^((d>>i)&1); - if (testfour(w,x,y,z)) - { /* h4o: 0,4,8,a */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 1));\n", - j, i); - return; - } - - w = ((a>>j)&2)^((a>>i)&1); - x = ((b>>j)&2)^((b>>i)&1); - y = ((c>>j)&2)^((c>>i)&1); - z = ((d>>j)&2)^((d>>i)&1); - if (testfour(w,x,y,z)) - { /* h4p: 0x04, 0x08, 0x10, 0x14 */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) & 2) ^ ((val >> %ld) & 1));\n", - j, i); - return; - } - } - - if (i==0) - { - w = ((a>>j)^(a<<1))&3; - x = ((b>>j)^(b<<1))&3; - y = ((c>>j)^(c<<1))&3; - z = ((d>>j)^(d<<1))&3; - } - else - { - w = ((a>>j)&3)^((a>>(i-1))&2); - x = ((b>>j)&3)^((b>>(i-1))&2); - y = ((c>>j)&3)^((c>>(i-1))&2); - z = ((d>>j)&3)^((d>>(i-1))&2); - } - if (testfour(w,x,y,z)) - { - if (i==0) /* h4q: 0,4,5,8 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) ^ (val << 1)) & 3);\n", - j); - } - else if (i==1) /* h4r: 0x01,0x09,0x0b,0x10 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) & 3) ^ (val & 2));\n", - j); - } - else /* h4s: 0,2,6,8 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 2));\n", - j, (i-1)); - } - return; - } - - w = ((a>>j)&1)^((a>>i)&2); - x = ((b>>j)&1)^((b>>i)&2); - y = ((c>>j)&1)^((c>>i)&2); - z = ((d>>j)&1)^((d>>i)&2); - if (testfour(w,x,y,z)) /* h4t: 0x20,0x14,0x10,0x06 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) & 1) ^ ((val >> %ld) & 2));\n", - j, i); - return; - } - } - } - } - - /* - * OK, bring out the big guns. - * There exist three bits i,j,k which distinguish a,b,c,d. - * i^(j<<1)^(k*q) is guaranteed to work for some q in {0,1,2,3}, - * proven by exhaustive search of all (8 choose 4) cases. - * Find three such bits and try the 4 cases. - * Linear with the number of diffbits. - * Some cases below may duplicate some cases above. I did it that way - * so that what is below is guaranteed to work, no matter what was - * attempted above. - * The generated hash is at most 10 instructions. - */ - for (i=final->lowbit; i>i)&1; - z = (d>>i)&1; - if (y != z) - break; - } - - for (j=final->lowbit; j>i)&1)^(((b>>j)&1)<<1); - y = ((c>>i)&1)^(((c>>j)&1)<<1); - z = ((d>>i)&1)^(((d>>j)&1)<<1); - if (x != y && x != z && y != z) - break; - } - - for (k=final->lowbit; k>i)&1)^(((a>>j)&1)<<1)^(((a>>k)&1)<<2); - x = ((b>>i)&1)^(((b>>j)&1)<<1)^(((b>>k)&1)<<2); - y = ((c>>i)&1)^(((c>>j)&1)<<1)^(((c>>k)&1)<<2); - z = ((d>>i)&1)^(((d>>j)&1)<<1)^(((d>>k)&1)<<2); - if (w != x && w != y && w != z && x != y && x != z && y != z) - break; - } - - /* Assert: bits i,j,k were found which distinguish a,b,c,d */ - if (i==UB4BITS || j==UB4BITS || k==UB4BITS) - { - printf("Fatal error: hexfour(), i %ld j %ld k %ld\n", i,j,k); - exit(SUCCESS); - } - - /* now try the four cases */ - { - ub4 m,n,o,p; - - /* if any bit has two 1s and two 0s, make that bit o */ - if (((a>>i)&1)+((b>>i)&1)+((c>>i)&1)+((d>>i)&1) != 2) - { m=j; n=k; o=i; } - else if (((a>>j)&1)+((b>>j)&1)+((c>>j)&1)+((d>>j)&1) != 2) - { m=i; n=k; o=j; } - else - { m=i; n=j; o=k; } - if (m > n) {p=m; m=n; n=p; } /* guarantee m < n */ - - /* printf("m %ld n %ld o %ld %ld %ld %ld %ld\n", m, n, o, w,x,y,z); */ - - /* seven instructions, multiply bit o by 1 */ - w = (((a>>m)^(a>>o))&1)^((a>>(n-1))&2); - x = (((b>>m)^(b>>o))&1)^((b>>(n-1))&2); - y = (((c>>m)^(c>>o))&1)^((c>>(n-1))&2); - z = (((d>>m)^(d>>o))&1)^((d>>(n-1))&2); - if (testfour(w,x,y,z)) - { - if (m>o) {p=m; m=o; o=p;} /* make sure m < o and m < n */ - - if (m==0) /* 0,2,8,9 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val^(val>>%ld))&1)^((val>>%ld)&2));\n", o, n-1); - } - else /* 0x00,0x04,0x10,0x12 */ - { - sprintf(final->line[0], - " ub4 rsl = ((((val>>%ld) ^ (val>>%ld)) & 1) ^ ((val>>%ld) & 2));\n", - m, o, n-1); - } - return; - } - - /* six to seven instructions, multiply bit o by 2 */ - w = ((a>>m)&1)^((((a>>n)^(a>>o))&1)<<1); - x = ((b>>m)&1)^((((b>>n)^(b>>o))&1)<<1); - y = ((c>>m)&1)^((((c>>n)^(c>>o))&1)<<1); - z = ((d>>m)&1)^((((d>>n)^(d>>o))&1)<<1); - if (testfour(w,x,y,z)) - { - if (m==o-1) {p=n; n=o; o=p;} /* make m==n-1 if possible */ - - if (m==0) /* 0,1,5,8 */ - { - sprintf(final->line[0], - " ub4 rsl = ((val & 1) ^ (((val>>%ld) ^ (val>>%ld)) & 2));\n", - n-1, o-1); - } - else if (o==0) /* 0x00,0x04,0x05,0x10 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val>>%ld) & 2) ^ (((val>>%ld) ^ val) & 1));\n", - m-1, n); - } - else /* 0x00,0x02,0x0a,0x10 */ - { - sprintf(final->line[0], - " ub4 rsl = (((val>>%ld) & 1) ^ (((val>>%ld) ^ (val>>%ld)) & 2));\n", - m, n-1, o-1); - } - return; - } - - /* multiplying by 3 is a pain: seven or eight instructions */ - w = (((a>>m)&1)^((a>>(n-1))&2))^((a>>o)&1)^(((a>>o)&1)<<1); - x = (((b>>m)&1)^((b>>(n-1))&2))^((b>>o)&1)^(((b>>o)&1)<<1); - y = (((c>>m)&1)^((c>>(n-1))&2))^((c>>o)&1)^(((c>>o)&1)<<1); - z = (((d>>m)&1)^((d>>(n-1))&2))^((d>>o)&1)^(((d>>o)&1)<<1); - if (testfour(w,x,y,z)) - { - final->used = 2; - sprintf(final->line[0], " ub4 b = (val >> %ld) & 1;\n", o); - if (m==o-1 && m==0) /* 0x02,0x10,0x11,0x18 */ - { - sprintf(final->line[1], - " ub4 rsl = ((val & 3) ^ ((val >> %ld) & 2) ^ b);\n", n-1); - } - else if (m==o-1) /* 0,4,6,c */ - { - sprintf(final->line[1], - " ub4 rsl = (((val >> %ld) & 3) ^ ((val >> %ld) & 2) ^ b);\n", - m, n-1); - } - else if (m==n-1 && m==0) /* 02,0a,0b,18 */ - { - sprintf(final->line[1], - " ub4 rsl = ((val & 3) ^ b ^ (b << 1));\n"); - } - else if (m==n-1) /* 0,2,4,8 */ - { - sprintf(final->line[1], - " ub4 rsl = (((val >> %ld) & 3) ^ b ^ (b << 1));\n", m); - } - else if (o==n-1 && m==0) /* h4am: not reached */ - { - sprintf(final->line[1], - " ub4 rsl = ((val & 1) ^ ((val >> %ld) & 3) ^ (b <<1 ));\n", - o); - } - else if (o==n-1) /* 0x00,0x02,0x08,0x10 */ - { - sprintf(final->line[1], - " ub4 rsl = (((val >> %ld) & 1) ^ ((val >> %ld) & 3) ^ (b << 1));\n", - m, o); - } - else if ((m != o-1) && (m != n-1) && (o != m-1) && (o != n-1)) - { - final->used = 3; - sprintf(final->line[0], " ub4 newval = val & 0x%lx;\n", - (((ub4)1<line[1], " ub4 b = -newval;\n"); - } - else /* 0x00,0x04,0x09,0x10 */ - { - sprintf(final->line[1], " ub4 b = -(newval >> %ld);\n", o); - } - if (m==0) /* 0x00,0x04,0x09,0x10 */ - { - sprintf(final->line[2], - " ub4 rsl = ((newval ^ (newval>>%ld) ^ b) & 3);\n", n-1); - } - else /* 0x00,0x03,0x04,0x10 */ - { - sprintf(final->line[2], - " ub4 rsl = (((newval>>%ld) ^ (newval>>%ld) ^ b) & 3);\n", - m, n-1); - } - } - else if (o == m-1) - { - if (o==0) /* 0x02,0x03,0x0a,0x10 */ - { - sprintf(final->line[0], " ub4 b = (val<<1) & 2;\n"); - } - else if (o==1) /* 0x00,0x02,0x04,0x10 */ - { - sprintf(final->line[0], " ub4 b = val & 2;\n"); - } - else /* 0x00,0x04,0x08,0x20 */ - { - sprintf(final->line[0], " ub4 b = (val>>%ld) & 2;\n", o-1); - } - - if (o==0) /* 0x02,0x03,0x0a,0x10 */ - { - sprintf(final->line[1], - " ub4 rsl = ((val & 3) ^ ((val>>%ld) & 1) ^ b);\n", - n); - } - else /* 0x00,0x02,0x04,0x10 */ - { - sprintf(final->line[1], - " ub4 rsl = (((val>>%ld) & 3) ^ ((val>>%ld) & 1) ^ b);\n", - o, n); - } - } - else /* h4ax: 10 instructions, but not reached */ - { - sprintf(final->line[1], - " ub4 rsl = (((val>>%ld) & 1) ^ ((val>>%ld) & 2) ^ b ^ (b<<1));\n", - m, n-1); - } - - return; - } - - /* five instructions, multiply bit o by 0, covered before the big guns */ - w = ((a>>m)&1)^(a>>(n-1)&2); - x = ((b>>m)&1)^(b>>(n-1)&2); - y = ((c>>m)&1)^(c>>(n-1)&2); - z = ((d>>m)&1)^(d>>(n-1)&2); - if (testfour(w,x,y,z)) - { /* h4v, not reached */ - sprintf(final->line[0], - " ub4 rsl = (((val>>%ld) & 1) ^ ((val>>%ld) & 2));\n", m, n-1); - return; - } - } - - printf("fatal error: bug in hexfour!\n"); - exit(SUCCESS); - return; -} - - -/* test if a_k is distinct and in range for all keys */ -static int testeight(keys, badmask) -key *keys; /* keys being hashed */ -ub1 badmask; /* used for minimal perfect hashing */ -{ - ub1 mask = badmask; - key *mykey; - - for (mykey=keys; mykey; mykey=mykey->next_k) - { - if (bit(mask, 1<a_k)) return FALSE; - bis(mask, 1<a_k); - } - return TRUE; -} - - - -/* - * Try to find a perfect hash when there are five to eight keys. - * - * We can't deterministically find a perfect hash, but there's a reasonable - * chance we'll get lucky. Give it a shot. Return TRUE if we succeed. - */ -static int hexeight(keys, nkeys, final, form) -key *keys; -ub4 nkeys; -gencode *final; -hashform *form; -{ - key *mykey; /* walk through the keys */ - ub4 i,j,k; - ub1 badmask; - - printf("hexeight\n"); - - /* what hash values should never be used? */ - badmask = 0; - if (form->perfect == MINIMAL_HP) - { - for (i=nkeys; i<8; ++i) - bis(badmask,(1<next_k) - mykey->a_k = mykey->hash_k & 7; - if (testeight(keys, badmask)) - { /* h8a */ - final->used = 1; - sprintf(final->line[0], " ub4 rsl = (val & 7);\n"); - return TRUE; - } - - /* two instructions */ - for (i=final->lowbit; i<=final->highbit-2; ++i) - { - for (mykey=keys; mykey; mykey=mykey->next_k) - mykey->a_k = (mykey->hash_k >> i) & 7; - if (testeight(keys, badmask)) - { /* h8b */ - final->used = 1; - sprintf(final->line[0], " ub4 rsl = ((val >> %ld) & 7);\n", i); - return TRUE; - } - } - - /* four instructions */ - for (i=final->lowbit; i<=final->highbit; ++i) - { - for (j=i+1; j<=final->highbit; ++j) - { - for (mykey=keys; mykey; mykey=mykey->next_k) - mykey->a_k = ((mykey->hash_k >> i)+(mykey->hash_k >> j)) & 7; - if (testeight(keys, badmask)) - { - final->used = 1; - if (i == 0) /* h8c */ - sprintf(final->line[0], - " ub4 rsl = ((val + (val >> %ld)) & 7);\n", j); - else /* h8d */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) + (val >> %ld)) & 7);\n", i, j); - return TRUE; - } - - for (mykey=keys; mykey; mykey=mykey->next_k) - mykey->a_k = ((mykey->hash_k >> i)^(mykey->hash_k >> j)) & 7; - if (testeight(keys, badmask)) - { - final->used = 1; - if (i == 0) /* h8e */ - sprintf(final->line[0], - " ub4 rsl = ((val ^ (val >> %ld)) & 7);\n", j); - else /* h8f */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) ^ (val >> %ld)) & 7);\n", i, j); - - return TRUE; - } - - for (mykey=keys; mykey; mykey=mykey->next_k) - mykey->a_k = ((mykey->hash_k >> i)-(mykey->hash_k >> j)) & 7; - if (testeight(keys, badmask)) - { - final->used = 1; - if (i == 0) /* h8g */ - sprintf(final->line[0], - " ub4 rsl = ((val - (val >> %ld)) & 7);\n", j); - else /* h8h */ - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) - (val >> %ld)) & 7);\n", i, j); - - return TRUE; - } - } - } - - - /* six instructions */ - for (i=final->lowbit; i<=final->highbit; ++i) - { - for (j=i+1; j<=final->highbit; ++j) - { - for (k=j+1; k<=final->highbit; ++k) - { - for (mykey=keys; mykey; mykey=mykey->next_k) - mykey->a_k = ((mykey->hash_k >> i) + - (mykey->hash_k >> j) + - (mykey->hash_k >> k)) & 7; - if (testeight(keys, badmask)) - { /* h8i */ - final->used = 1; - sprintf(final->line[0], - " ub4 rsl = (((val >> %ld) + (val >> %ld) + (val >> %ld)) & 7);\n", - i, j, k); - return TRUE; - } - } - } - } - - - return FALSE; -} - - - -/* - * Guns aren't enough. Bring out the Bomb. Use tab[]. - * This finds the initial (a,b) when we need to use tab[]. - * - * We need to produce a different (a,b) every time this is called. Try all - * reasonable cases, fastest first. - * - * The initial mix (which this determines) can be filled into final starting - * at line[1]. val is set and a,b are declared. The final hash (at line[7]) - * is a^tab[b] or a^scramble[tab[b]]. - * - * The code will probably look like this, minus some stuff: - * val += CONSTANT; - * val ^= (val<<16); - * val += (val>>8); - * val ^= (val<<4); - * b = (val >> l) & 7; - * a = (val + (val<> 29; - * return a^scramble[tab[b]]; - * Note that *a* and tab[b] will be computed in parallel by most modern chips. - * - * final->i is the current state of the state machine. - * final->j and final->k are counters in the loops the states simulate. - */ -static void hexn(keys, salt, alen, blen, final) -key *keys; -ub4 salt; -ub4 alen; -ub4 blen; -gencode *final; -{ - key *mykey; - ub4 highbit = final->highbit; - ub4 lowbit = final->lowbit; - ub4 alog = mylog2(alen); - ub4 blog = mylog2(blen); - - for (;;) - { - switch(final->i) - { - case 1: - /* a = val>>30; b=val&3 */ - for (mykey=keys; mykey; mykey=mykey->next_k) - { - mykey->a_k = (mykey->hash_k << (UB4BITS-(highbit+1)))>>(UB4BITS-alog); - mykey->b_k = (mykey->hash_k >> lowbit) & (blen-1); - } - if (lowbit == 0) /* hna */ - sprintf(final->line[5], " b = (val & 0x%lx);\n", - blen-1); - else /* hnb */ - sprintf(final->line[5], " b = ((val >> %ld) & 0x%lx);\n", - lowbit, blen-1); - if (highbit+1 == UB4BITS) /* hnc */ - sprintf(final->line[6], " a = (val >> %ld);\n", - UB4BITS-alog); - else /* hnd */ - sprintf(final->line[6], " a = ((val << %ld ) >> %ld);\n", - UB4BITS-(highbit+1), UB4BITS-alog); - - ++final->i; - return; - - case 2: - /* a = val&3; b=val>>30 */ - for (mykey=keys; mykey; mykey=mykey->next_k) - { - mykey->a_k = (mykey->hash_k >> lowbit) & (alen-1); - mykey->b_k = (mykey->hash_k << (UB4BITS-(highbit+1)))>>(UB4BITS-blog); - } - if (highbit+1 == UB4BITS) /* hne */ - sprintf(final->line[5], " b = (val >> %ld);\n", - UB4BITS-blog); - else /* hnf */ - sprintf(final->line[5], " b = ((val << %ld ) >> %ld);\n", - UB4BITS-(highbit+1), UB4BITS-blog); - if (lowbit == 0) /* hng */ - sprintf(final->line[6], " a = (val & 0x%lx);\n", - alen-1); - else /* hnh */ - sprintf(final->line[6], " a = ((val >> %ld) & 0x%lx);\n", - lowbit, alen-1); - - ++final->i; - return; - - case 3: - /* - * cases 3,4,5: - * for (k=lowbit; k<=highbit; ++k) - * for (j=lowbit; j<=highbit; ++j) - * b = (val>>j)&3; - * a = (val<>30; - */ - final->k = lowbit; - final->j = lowbit; - ++final->i; - break; - - case 4: - if (!(final->j < highbit)) - { - ++final->i; - break; - } - for (mykey=keys; mykey; mykey=mykey->next_k) - { - mykey->b_k = (mykey->hash_k >> (final->j)) & (blen-1); - mykey->a_k = (mykey->hash_k << (UB4BITS-final->k-1)) >> (UB4BITS-alog); - } - if (final->j == 0) /* hni */ - sprintf(final->line[5], " b = val & 0x%lx;\n", - blen-1); - else if (blog+final->j == UB4BITS) /* hnja */ - sprintf(final->line[5], " b = val >> %ld;\n", - final->j); - else - sprintf(final->line[5], " b = (val >> %ld) & 0x%lx;\n", /* hnj */ - final->j, blen-1); - if (UB4BITS-final->k-1 == 0) /* hnk */ - sprintf(final->line[6], " a = (val >> %ld);\n", - UB4BITS-alog); - else /* hnl */ - sprintf(final->line[6], " a = ((val << %ld) >> %ld);\n", - UB4BITS-final->k-1, UB4BITS-alog); - while (++final->j < highbit) - { - if (((final->diffbits>>(final->j)) & (blen-1)) > 2) - break; - } - return; - - case 5: - while (++final->k < highbit) - { - if ((((final->diffbits<<(UB4BITS-final->k-1))>>alog) & (alen-1)) > 0) - break; - } - if (!(final->k < highbit)) - { - ++final->i; - break; - } - final->j = lowbit; - final->i = 4; - break; - - - case 6: - /* - * cases 6,7,8: - * for (k=0; k> 16); - * val += (val << 8); - * val ^= (val >> 4); - * b = (val >> j) & 3; - * a = (val + (val << k)) >> 30; - */ - final->k = 0; - final->j = 0; - ++final->i; - break; - - case 7: - /* Just do something that will surely work */ - { - ub4 addk = 0x9e3779b9*salt; - - if (!(final->j <= UB4BITS-blog)) - { - ++final->i; - break; - } - for (mykey=keys; mykey; mykey=mykey->next_k) - { - ub4 val = mykey->hash_k + addk; - if (final->highbit+1 - final->lowbit > 16) - val ^= (val >> 16); - if (final->highbit+1 - final->lowbit > 8) - val += (val << 8); - val ^= (val >> 4); - mykey->b_k = (val >> final->j) & (blen-1); - if (final->k == 0) - mykey->a_k = val >> (UB4BITS-alog); - else - mykey->a_k = (val + (val << final->k)) >> (UB4BITS-alog); - } - sprintf(final->line[1], " val += 0x%lx;\n", addk); - if (final->highbit+1 - final->lowbit > 16) /* hnm */ - sprintf(final->line[2], " val ^= (val >> 16);\n"); - if (final->highbit+1 - final->lowbit > 8) /* hnn */ - sprintf(final->line[3], " val += (val << 8);\n"); - sprintf(final->line[4], " val ^= (val >> 4);\n"); - if (final->j == 0) /* hno: don't know how to reach this */ - sprintf(final->line[5], " b = val & 0x%lx;\n", blen-1); - else /* hnp */ - sprintf(final->line[5], " b = (val >> %ld) & 0x%lx;\n", - final->j, blen-1); - if (final->k == 0) /* hnq */ - sprintf(final->line[6], " a = val >> %ld;\n", UB4BITS-alog); - else /* hnr */ - sprintf(final->line[6], " a = (val + (val << %ld)) >> %ld;\n", - final->k, UB4BITS-alog); - - ++final->j; - return; - } - - case 8: - ++final->k; - if (!(final->k <= UB4BITS-alog)) - { - ++final->i; - break; - } - final->j = 0; - final->i = 7; - break; - - case 9: - final->i = 6; - break; - } - } -} - - - -/* find the highest and lowest bit where any key differs */ -static void setlow(keys, final) -key *keys; -gencode *final; -{ - ub4 lowbit; - ub4 highbit; - ub4 i; - key *mykey; - ub4 firstkey; - - /* mark the interesting bits in final->mask */ - final->diffbits = (ub4)0; - if (keys) firstkey = keys->hash_k; - for (mykey=keys; mykey!=(key *)0; mykey=mykey->next_k) - final->diffbits |= (firstkey ^ mykey->hash_k); - - /* find the lowest interesting bit */ - for (i=0; idiffbits & (((ub4)1)<lowbit = i; - - /* find the highest interesting bit */ - for (i=UB4BITS; --i; ) - if (final->diffbits & (((ub4)1)<highbit = i; -} - -/* - * Initialize (a,b) when keys are integers. - * - * Normally there's an initial hash which produces a number. That hash takes - * an initializer. Changing the initializer causes the initial hash to - * produce a different (uniformly distributed) number without any extra work. - * - * Well, here we start with a number. There's no initial hash. Any mixing - * costs extra work. So we go through a lot of special cases to minimize the - * mixing needed to get distinct (a,b). For small sets of keys, it's often - * fastest to skip the final hash and produce the perfect hash from the number - * directly. - * - * The target user for this is switch statement optimization. The common case - * is 3 to 16 keys, and instruction counts matter. The competition is a - * binary tree of branches. - * - * Return TRUE if we found a perfect hash and no more work is needed. - * Return FALSE if we just did an initial hash and more work is needed. - */ -int inithex(keys, nkeys, alen, blen, smax, salt, final, form) -key *keys; /* list of all keys */ -ub4 nkeys; /* number of keys to hash */ -ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */ -ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */ -ub4 smax; /* maximum range of computable hash values */ -ub4 salt; /* used to initialize the hash function */ -gencode *final; /* output, code for the final hash */ -hashform *form; /* user directives */ -{ - setlow(keys, final); - - switch (nkeys) - { - case 1: - hexone(keys, final); - return TRUE; - case 2: - hextwo(keys, final); - return TRUE; - case 3: - hexthree(keys, final, form); - return TRUE; - case 4: - hexfour(keys, final); - return TRUE; - case 5: case 6: case 7: case 8: - if (salt == 1 && /* first time through */ - hexeight(keys, nkeys, final, form)) /* get lucky, don't need tab[] ? */ - return TRUE; - /* fall through */ - default: - if (salt == 1) - { - final->used = 8; - final->i = 1; - final->j = final->k = final->l = final->m = final->n = final->o = 0; - sprintf(final->line[0], " ub4 a, b, rsl;\n"); - sprintf(final->line[1], "\n"); - sprintf(final->line[2], "\n"); - sprintf(final->line[3], "\n"); - sprintf(final->line[4], "\n"); - sprintf(final->line[5], "\n"); - sprintf(final->line[6], "\n"); - if (blen < USE_SCRAMBLE) - { /* hns */ - sprintf(final->line[7], " rsl = (a^tab[b]);\n"); - } - else - { /* hnt */ - sprintf(final->line[7], " rsl = (a^scramble[tab[b]]);\n"); - } - } - hexn(keys, salt, alen, blen, final); - return FALSE; - } -} diff --git a/tools/codegen/core/perfect/recycle.c b/tools/codegen/core/perfect/recycle.c deleted file mode 100644 index 3f857cba7d2..00000000000 --- a/tools/codegen/core/perfect/recycle.c +++ /dev/null @@ -1,87 +0,0 @@ -/* --------------------------------------------------------------------- -By Bob Jenkins, September 1996. recycle.c -You may use this code in any way you wish, and it is free. No warranty. - -This manages memory for commonly-allocated structures. -It allocates RESTART to REMAX items at a time. -Timings have shown that, if malloc is used for every new structure, - malloc will consume about 90% of the time in a program. This - module cuts down the number of mallocs by an order of magnitude. -This also decreases memory fragmentation, and freeing structures - only requires freeing the root. --------------------------------------------------------------------- -*/ - -#ifndef STANDARD -# include "standard.h" -#endif -#ifndef RECYCLE -# include "recycle.h" -#endif - -reroot *remkroot(size) -size_t size; -{ - reroot *r = (reroot *)remalloc(sizeof(reroot), "recycle.c, root"); - r->list = (recycle *)0; - r->trash = (recycle *)0; - r->size = align(size); - r->logsize = RESTART; - r->numleft = 0; - return r; -} - -void refree(r) -struct reroot *r; -{ - recycle *temp; - if (temp = r->list) while (r->list) - { - temp = r->list->next; - free((char *)r->list); - r->list = temp; - } - free((char *)r); - return; -} - -/* to be called from the macro renew only */ -char *renewx(r) -struct reroot *r; -{ - recycle *temp; - if (r->trash) - { /* pull a node off the trash heap */ - temp = r->trash; - r->trash = temp->next; - (void)memset((void *)temp, 0, r->size); - } - else - { /* allocate a new block of nodes */ - r->numleft = r->size*((ub4)1<logsize); - if (r->numleft < REMAX) ++r->logsize; - temp = (recycle *)remalloc(sizeof(recycle) + r->numleft, - "recycle.c, data"); - temp->next = r->list; - r->list = temp; - r->numleft-=r->size; - temp = (recycle *)((char *)(r->list+1)+r->numleft); - } - return (char *)temp; -} - -char *remalloc(len, purpose) -size_t len; -char *purpose; -{ - char *x = (char *)malloc(len); - if (!x) - { - fprintf(stderr, "malloc of %d failed for %s\n", - len, purpose); - exit(SUCCESS); - } - return x; -} - diff --git a/tools/codegen/core/perfect/recycle.h b/tools/codegen/core/perfect/recycle.h deleted file mode 100644 index 7472495e848..00000000000 --- a/tools/codegen/core/perfect/recycle.h +++ /dev/null @@ -1,65 +0,0 @@ -/* --------------------------------------------------------------------- -By Bob Jenkins, September 1996. recycle.h -You may use this code in any way you wish, and it is free. No warranty. - -This manages memory for commonly-allocated structures. -It allocates RESTART to REMAX items at a time. -Timings have shown that, if malloc is used for every new structure, - malloc will consume about 90% of the time in a program. This - module cuts down the number of mallocs by an order of magnitude. -This also decreases memory fragmentation, and freeing all structures - only requires freeing the root. --------------------------------------------------------------------- -*/ - -#ifndef STANDARD -#include "standard.h" -#endif - -#ifndef RECYCLE -#define RECYCLE - -#define RESTART 0 -#define REMAX 32000 - -struct recycle -{ - struct recycle *next; -}; -typedef struct recycle recycle; - -struct reroot -{ - struct recycle *list; /* list of malloced blocks */ - struct recycle *trash; /* list of deleted items */ - size_t size; /* size of an item */ - size_t logsize; /* log_2 of number of items in a block */ - word numleft; /* number of bytes left in this block */ -}; -typedef struct reroot reroot; - -/* make a new recycling root */ -reroot *remkroot(/*_ size_t mysize _*/); - -/* free a recycling root and all the items it has made */ -void refree(/*_ struct reroot *r _*/); - -/* get a new (cleared) item from the root */ -#define renew(r) ((r)->numleft ? \ - (((char *)((r)->list+1))+((r)->numleft-=(r)->size)) : renewx(r)) - -char *renewx(/*_ struct reroot *r _*/); - -/* delete an item; let the root recycle it */ -/* void redel(/o_ struct reroot *r, struct recycle *item _o/); */ -#define redel(root,item) { \ - ((recycle *)item)->next=(root)->trash; \ - (root)->trash=(recycle *)(item); \ -} - -/* malloc, but complain to stderr and exit program if no joy */ -/* use plain free() to free memory allocated by remalloc() */ -char *remalloc(/*_ size_t len, char *purpose _*/); - -#endif /* RECYCLE */ diff --git a/tools/codegen/core/perfect/run.sh b/tools/codegen/core/perfect/run.sh deleted file mode 100755 index c0d1fc3b812..00000000000 --- a/tools/codegen/core/perfect/run.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash -set -e -cd $(dirname $0) -fn=$1 -shift -./perfect $* < $fn diff --git a/tools/codegen/core/perfect/standard.h b/tools/codegen/core/perfect/standard.h deleted file mode 100644 index 202a5d658c5..00000000000 --- a/tools/codegen/core/perfect/standard.h +++ /dev/null @@ -1,57 +0,0 @@ -/* ------------------------------------------------------------------------------- -Standard definitions and types, Bob Jenkins ------------------------------------------------------------------------------- -*/ -#ifndef STANDARD -# define STANDARD -# ifndef STDIO -# include -# define STDIO -# endif -# ifndef STDDEF -# include -# define STDDEF -# endif -typedef unsigned long long ub8; -#define UB8MAXVAL 0xffffffffffffffffLL -#define UB8BITS 64 -typedef signed long long sb8; -#define SB8MAXVAL 0x7fffffffffffffffLL -typedef unsigned long int ub4; /* unsigned 4-byte quantities */ -#define UB4MAXVAL 0xffffffff -typedef signed long int sb4; -#define UB4BITS 32 -#define SB4MAXVAL 0x7fffffff -typedef unsigned short int ub2; -#define UB2MAXVAL 0xffff -#define UB2BITS 16 -typedef signed short int sb2; -#define SB2MAXVAL 0x7fff -typedef unsigned char ub1; -#define UB1MAXVAL 0xff -#define UB1BITS 8 -typedef signed char sb1; /* signed 1-byte quantities */ -#define SB1MAXVAL 0x7f -typedef int word; /* fastest type available */ - -#define bis(target,mask) ((target) |= (mask)) -#define bic(target,mask) ((target) &= ~(mask)) -#define bit(target,mask) ((target) & (mask)) -#ifndef min -# define min(a,b) (((a)<(b)) ? (a) : (b)) -#endif /* min */ -#ifndef max -# define max(a,b) (((a)<(b)) ? (b) : (a)) -#endif /* max */ -#ifndef align -# define align(a) (((ub4)a+(sizeof(void *)-1))&(~(sizeof(void *)-1))) -#endif /* align */ -#ifndef abs -# define abs(a) (((a)>0) ? (a) : -(a)) -#endif -#define TRUE 1 -#define FALSE 0 -#define SUCCESS 0 /* 1 on VAX */ - -#endif /* STANDARD */ From b9ad635602ad22b72ad2824284e71201b226a5e5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 30 Nov 2016 17:32:27 -0800 Subject: [PATCH 080/261] Fix leak --- test/core/transport/metadata_test.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index fc8b187570d..92e58f23751 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -389,6 +389,8 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { } else { GPR_ASSERT(p.payload == q.payload); } + GRPC_MDELEM_UNREF(&exec_ctx, p); + GRPC_MDELEM_UNREF(&exec_ctx, q); } grpc_exec_ctx_finish(&exec_ctx); From f0f787d117a20156eeda8dbd6e96398fe4d443a7 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 5 Dec 2016 09:41:18 -0800 Subject: [PATCH 081/261] Fix Ruby compilation problems on MinGW --- Makefile | 72 +++++++------- Rakefile | 2 +- src/core/ext/census/tracing.c | 19 ++-- src/core/lib/iomgr/tcp_server_windows.c | 6 +- templates/Makefile.template | 8 +- templates/Rakefile.template | 126 ++++++++++++++++++++++++ 6 files changed, 183 insertions(+), 50 deletions(-) create mode 100644 templates/Rakefile.template diff --git a/Makefile b/Makefile index 87b152514b9..248770673a6 100644 --- a/Makefile +++ b/Makefile @@ -2327,7 +2327,7 @@ install-static_cxx: static_cxx strip-static_cxx install-pkg-config_cxx install-shared_c: shared_c strip-shared_c install-pkg-config_c $(E) "[INSTALL] Installing $(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)gpr$(SHARED_VERSION).$(SHARED_EXT_CORE) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgpr-imp.a $(prefix)/lib/libgpr-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2336,7 +2336,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc$(SHARED_VERSION).$(SHARED_EXT_CORE) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc-imp.a $(prefix)/lib/libgrpc-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2345,7 +2345,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION).$(SHARED_EXT_CORE) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_cronet-imp.a $(prefix)/lib/libgrpc_cronet-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2354,7 +2354,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION).$(SHARED_EXT_CORE) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(prefix)/lib/$(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure-imp.a $(prefix)/lib/libgrpc_unsecure-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2371,7 +2371,7 @@ endif install-shared_cxx: shared_cxx strip-shared_cxx install-shared_c install-pkg-config_cxx $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++$(SHARED_VERSION).$(SHARED_EXT_CPP) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++-imp.a $(prefix)/lib/libgrpc++-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2380,7 +2380,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION).$(SHARED_EXT_CPP) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet-imp.a $(prefix)/lib/libgrpc++_cronet-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2389,7 +2389,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION).$(SHARED_EXT_CPP) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection-imp.a $(prefix)/lib/libgrpc++_reflection-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2398,7 +2398,7 @@ else ifneq ($(SYSTEM),Darwin) endif $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION).$(SHARED_EXT_CPP) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(prefix)/lib/$(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure-imp.a $(prefix)/lib/libgrpc++_unsecure-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2415,7 +2415,7 @@ endif install-shared_csharp: shared_csharp strip-shared_csharp $(E) "[INSTALL] Installing $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP)" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(prefix)/lib/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION).$(SHARED_EXT_CSHARP) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(prefix)/lib/$(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a $(prefix)/lib/libgrpc_csharp_ext-imp.a else ifneq ($(SYSTEM),Darwin) @@ -2584,11 +2584,11 @@ $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE): $(LIBGPR_OB $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)gpr$(SHARED_VERSION).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGPR_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGPR_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) else $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgpr.so.2 -o $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGPR_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) - $(Q) ln -sf $(SHARED_PREFIX)gpr$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).so.2 - $(Q) ln -sf $(SHARED_PREFIX)gpr$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).so + $(Q) ln -sf $(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).so.2 + $(Q) ln -sf $(SHARED_PREFIX)gpr$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgpr$(SHARED_VERSION_CORE).so endif endif @@ -2902,11 +2902,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE): $(LIBGRPC_ $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc$(SHARED_VERSION).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) else $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) - $(Q) ln -sf $(SHARED_PREFIX)grpc$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).so.2 - $(Q) ln -sf $(SHARED_PREFIX)grpc$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).so + $(Q) ln -sf $(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).so.2 + $(Q) ln -sf $(SHARED_PREFIX)grpc$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc$(SHARED_VERSION_CORE).so endif endif @@ -3171,11 +3171,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE): $(L $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_CRONET_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_CRONET_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) else $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_cronet.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_CRONET_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) - $(Q) ln -sf $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).so.2 - $(Q) ln -sf $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).so + $(Q) ln -sf $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).so.2 + $(Q) ln -sf $(SHARED_PREFIX)grpc_cronet$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_cronet$(SHARED_VERSION_CORE).so endif endif @@ -3663,11 +3663,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE): $ $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_UNSECURE_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_UNSECURE_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) else $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_unsecure.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBGRPC_UNSECURE_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) - $(Q) ln -sf $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).so.2 - $(Q) ln -sf $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).so + $(Q) ln -sf $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).so.2 + $(Q) ln -sf $(SHARED_PREFIX)grpc_unsecure$(SHARED_VERSION_CORE).$(SHARED_EXT_CORE) $(LIBDIR)/$(CONFIG)/libgrpc_unsecure$(SHARED_VERSION_CORE).so endif endif @@ -3926,11 +3926,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(LIBGRPC+ $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++$(SHARED_VERSION).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc else $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc - $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so + $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++$(SHARED_VERSION_CPP).so endif endif @@ -4296,11 +4296,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(L $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_cronet + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_cronet else $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_cronet.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_CRONET_OBJS) $(LDLIBS) $(OPENSSL_MERGE_LIBS) $(LDLIBS_SECURE) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_cronet - $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so + $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++_cronet$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_cronet$(SHARED_VERSION_CPP).so endif endif @@ -4419,11 +4419,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc++ + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc++ else $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_reflection.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_REFLECTION_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgrpc++ - $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so + $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++_reflection$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_reflection$(SHARED_VERSION_CPP).so endif endif @@ -4809,11 +4809,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP): $ $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_unsecure + $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_unsecure else $(Q) $(LDXX) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc++_unsecure.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBGRPC++_UNSECURE_OBJS) $(LDLIBS) $(ZLIB_MERGE_LIBS) $(LDLIBSXX) $(LDLIBS_PROTOBUF) -lgpr -lgrpc_unsecure - $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so + $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc++_unsecure$(SHARED_VERSION_CPP).$(SHARED_EXT_CPP) $(LIBDIR)/$(CONFIG)/libgrpc++_unsecure$(SHARED_VERSION_CPP).so endif endif @@ -5299,11 +5299,11 @@ $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHA $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION).$(SHARED_EXT_CSHARP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) else $(Q) $(LD) $(LDFLAGS) $(if $(subst Linux,,$(SYSTEM)),,-Wl$(comma)-wrap$(comma)memcpy) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.2 -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) - $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so.1 - $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so + $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so.1 + $(Q) ln -sf $(SHARED_PREFIX)grpc_csharp_ext$(SHARED_VERSION_CSHARP).$(SHARED_EXT_CSHARP) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext$(SHARED_VERSION_CSHARP).so endif endif diff --git a/Rakefile b/Rakefile index cfd4181d7e0..8a88b4401f5 100755 --- a/Rakefile +++ b/Rakefile @@ -83,7 +83,7 @@ task 'dlls' do env += 'EMBED_ZLIB=true ' env += 'BUILDDIR=/tmp ' env += "V=#{verbose} " - out = '/tmp/libs/opt/grpc-1.dll' + out = '/tmp/libs/opt/grpc-2.dll' w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } diff --git a/src/core/ext/census/tracing.c b/src/core/ext/census/tracing.c index 8f0e12296dd..536ba98f64f 100644 --- a/src/core/ext/census/tracing.c +++ b/src/core/ext/census/tracing.c @@ -33,17 +33,24 @@ //#include "src/core/ext/census/tracing.h" +#include + #include /* TODO(aveitch): These are all placeholder implementations. */ -// int census_trace_mask(const census_context *context) { -// return CENSUS_TRACE_MASK_NONE; -// } +int census_trace_mask(const census_context *context) { + abort(); + return CENSUS_TRACE_MASK_NONE; +} -// void census_set_trace_mask(int trace_mask) {} +void census_set_trace_mask(int trace_mask) { + abort(); +} -// void census_trace_print(census_context *context, uint32_t type, -// const char *buffer, size_t n) {} +void census_trace_print(census_context *context, uint32_t type, + const char *buffer, size_t n) { + abort(); +} // void SetTracerParams(const Params& params); diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index b8a391c0590..40d1746730b 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -239,7 +239,7 @@ static grpc_error *prepare_socket(SOCKET sock, error = GRPC_WSA_ERROR(WSAGetLastError(), "getsockname"); goto failure; } - sockname_temp.len = sockname_temp_len; + sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); return GRPC_ERROR_NONE; @@ -375,7 +375,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { int peer_name_len = (int)peer_name.len; err = getpeername(sock, (struct sockaddr *)peer_name.addr, &peer_name_len); - peer_name.len = peer_name_len; + peer_name.len = (size_t)peer_name_len; if (!err) { peer_name_string = grpc_sockaddr_to_uri(&peer_name); } else { @@ -493,7 +493,7 @@ grpc_error *grpc_tcp_server_add_port(grpc_tcp_server *s, if (0 == getsockname(sp->socket->socket, (struct sockaddr *)sockname_temp.addr, &sockname_temp_len)) { - sockname_temp.len = sockname_temp_len; + sockname_temp.len = (size_t)sockname_temp_len; *port = grpc_sockaddr_get_port(&sockname_temp); if (*port > 0) { allocated_addr = gpr_malloc(sizeof(grpc_resolved_address)); diff --git a/templates/Makefile.template b/templates/Makefile.template index 109de33c31e..d58d4fce41e 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -1293,7 +1293,7 @@ % if not lib.get('external_deps', None): $(E) "[INSTALL] Installing $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]})" $(Q) $(INSTALL) -d $(prefix)/lib - $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT_${lang_to_var[lib.language]}) + $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) $(prefix)/lib/$(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ifeq ($(SYSTEM),MINGW32) $(Q) $(INSTALL) $(LIBDIR)/$(CONFIG)/lib${lib.name}-imp.a $(prefix)/lib/lib${lib.name}-imp.a else ifneq ($(SYSTEM),Darwin) @@ -1552,11 +1552,11 @@ $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs} + $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) -dynamiclib -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs} else $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.core_version.major} -o ${out_libbase}.$(SHARED_EXT_${lang_to_var[lib.language]}) ${common}${link_libs} - $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} - $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so + $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so.${settings.get(lang_to_var[lib.language].lower() + '_version').major} + $(Q) ln -sf $(SHARED_PREFIX)${lib.name}$(SHARED_VERSION_${lang_to_var[lib.language]}).$(SHARED_EXT_${lang_to_var[lib.language]}) ${out_libbase}.so endif endif % endif diff --git a/templates/Rakefile.template b/templates/Rakefile.template new file mode 100644 index 00000000000..2ab505b7c10 --- /dev/null +++ b/templates/Rakefile.template @@ -0,0 +1,126 @@ +%YAML 1.2 +--- | + # -*- ruby -*- + require 'rake/extensiontask' + require 'rspec/core/rake_task' + require 'rubocop/rake_task' + require 'bundler/gem_tasks' + require 'fileutils' + + load 'tools/distrib/docker_for_windows.rb' + + # Add rubocop style checking tasks + RuboCop::RakeTask.new(:rubocop) do |task| + task.options = ['-c', 'src/ruby/.rubocop.yml'] + task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] + end + + spec = Gem::Specification.load('grpc.gemspec') + + Gem::PackageTask.new(spec) do |pkg| + end + + # Add the extension compiler task + Rake::ExtensionTask.new('grpc_c', spec) do |ext| + ext.source_pattern = '**/*.{c,h}' + ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc') + ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc') + ext.cross_compile = true + ext.cross_platform = [ + 'x86-mingw32', 'x64-mingw32', + 'x86_64-linux', 'x86-linux', + 'universal-darwin' + ] + ext.cross_compiling do |spec| + spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) + spec.files += Dir.glob('src/ruby/bin/**/*') + spec.files += Dir.glob('src/ruby/ext/**/*') + spec.files += Dir.glob('src/ruby/lib/**/*') + spec.files += Dir.glob('src/ruby/pb/**/*') + end + end + + # Define the test suites + SPEC_SUITES = [ + { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, + { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), + tags: ['~bidi', '~server'] }, + { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), + tag: 'bidi' }, + { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), + tag: 'server' }, + { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } + ] + namespace :suite do + SPEC_SUITES.each do |suite| + desc "Run all specs in the #{suite[:title]} spec suite" + RSpec::Core::RakeTask.new(suite[:id]) do |t| + ENV['COVERAGE_NAME'] = suite[:id].to_s + spec_files = [] + suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] + + if suite[:dir] + suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } + end + helper = 'src/ruby/spec/spec_helper.rb' + spec_files << helper unless spec_files.include?(helper) + + t.pattern = spec_files + t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] + if suite[:tags] + t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') + end + end + end + end + + desc 'Build the Windows gRPC DLLs for Ruby' + task 'dlls' do + grpc_config = ENV['GRPC_CONFIG'] || 'opt' + verbose = ENV['V'] || '0' + + env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE -Wno-unused-variable -Wno-unused-result" ' + env += 'LDFLAGS=-static ' + env += 'SYSTEM=MINGW32 ' + env += 'EMBED_ZLIB=true ' + env += 'BUILDDIR=/tmp ' + env += "V=#{verbose} " + out = '/tmp/libs/opt/grpc-${settings.core_version.major}.dll' + + w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } + w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } + + [ w64, w32 ].each do |opt| + env_comp = "CC=#{opt[:cross]}-gcc " + env_comp += "LD=#{opt[:cross]}-gcc " + docker_for_windows "#{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}" + end + + end + + desc 'Build the native gem file under rake_compiler_dock' + task 'gem:native' do + verbose = ENV['V'] || '0' + + grpc_config = ENV['GRPC_CONFIG'] || 'opt' + + if RUBY_PLATFORM =~ /darwin/ + FileUtils.touch 'grpc_c.32.ruby' + FileUtils.touch 'grpc_c.64.ruby' + system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}" + else + Rake::Task['dlls'].execute + docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}" + end + end + + # Define dependencies between the suites. + task 'suite:wrapper' => [:compile, :rubocop] + task 'suite:idiomatic' => 'suite:wrapper' + task 'suite:bidi' => 'suite:wrapper' + task 'suite:server' => 'suite:wrapper' + task 'suite:pb' => 'suite:server' + + desc 'Compiles the gRPC extension then runs all the tests' + task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] + task default: :all From 116901598f05690168e18e6cd73c6422089006b8 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 5 Dec 2016 09:42:15 -0800 Subject: [PATCH 082/261] Clang format --- src/core/ext/census/tracing.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/ext/census/tracing.c b/src/core/ext/census/tracing.c index 536ba98f64f..51508b00efe 100644 --- a/src/core/ext/census/tracing.c +++ b/src/core/ext/census/tracing.c @@ -44,9 +44,7 @@ int census_trace_mask(const census_context *context) { return CENSUS_TRACE_MASK_NONE; } -void census_set_trace_mask(int trace_mask) { - abort(); -} +void census_set_trace_mask(int trace_mask) { abort(); } void census_trace_print(census_context *context, uint32_t type, const char *buffer, size_t n) { From c6bbc4708c1b2a8fa41e593e2aca5863a144daca Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 6 Dec 2016 11:00:39 -0800 Subject: [PATCH 083/261] Replace usages of std::list with std::queue in Node extension --- src/node/ext/call_credentials.cc | 12 ++++++------ src/node/ext/call_credentials.h | 4 ++-- src/node/ext/node_grpc.cc | 14 +++++++------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 81fc552fd10..41f6c29f7d3 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -35,7 +35,7 @@ #include #include -#include +#include #include "grpc/grpc.h" #include "grpc/grpc_security.h" @@ -170,7 +170,7 @@ NAN_METHOD(CallCredentials::CreateFromPlugin) { grpc_metadata_credentials_plugin plugin; plugin_state *state = new plugin_state; state->callback = new Nan::Callback(info[0].As()); - state->pending_callbacks = new std::list(); + state->pending_callbacks = new std::queue(); uv_mutex_init(&state->plugin_mutex); uv_async_init(uv_default_loop(), &state->plugin_async, @@ -232,13 +232,13 @@ NAN_METHOD(PluginCallback) { NAUV_WORK_CB(SendPluginCallback) { Nan::HandleScope scope; plugin_state *state = reinterpret_cast(async->data); - std::list callbacks; + std::queue callbacks; uv_mutex_lock(&state->plugin_mutex); - callbacks.splice(callbacks.begin(), *state->pending_callbacks); + state->pending_callbacks->swap(callbacks); uv_mutex_unlock(&state->plugin_mutex); while (!callbacks.empty()) { plugin_callback_data *data = callbacks.front(); - callbacks.pop_front(); + callbacks.pop(); Local callback_data = Nan::New(); Nan::Set(callback_data, Nan::New("cb").ToLocalChecked(), Nan::New(reinterpret_cast(data->cb))); @@ -267,7 +267,7 @@ void plugin_get_metadata(void *state, grpc_auth_metadata_context context, data->user_data = user_data; uv_mutex_lock(&p_state->plugin_mutex); - p_state->pending_callbacks->push_back(data); + p_state->pending_callbacks->push(data); uv_mutex_unlock(&p_state->plugin_mutex); uv_async_send(&p_state->plugin_async); diff --git a/src/node/ext/call_credentials.h b/src/node/ext/call_credentials.h index 04c852bea1e..21a4b8923e2 100644 --- a/src/node/ext/call_credentials.h +++ b/src/node/ext/call_credentials.h @@ -34,7 +34,7 @@ #ifndef GRPC_NODE_CALL_CREDENTIALS_H_ #define GRPC_NODE_CALL_CREDENTIALS_H_ -#include +#include #include #include @@ -84,7 +84,7 @@ typedef struct plugin_callback_data { typedef struct plugin_state { Nan::Callback *callback; - std::list *pending_callbacks; + std::queue *pending_callbacks; uv_mutex_t plugin_mutex; // async.data == this uv_async_t plugin_async; diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 848c601587f..620b086915c 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -31,7 +31,7 @@ * */ -#include +#include #include #include @@ -66,7 +66,7 @@ typedef struct log_args { typedef struct logger_state { Nan::Callback *callback; - std::list *pending_args; + std::queue *pending_args; uv_mutex_t mutex; uv_async_t async; // Indicates that a logger has been set @@ -334,14 +334,14 @@ NAN_METHOD(SetDefaultRootsPem) { NAUV_WORK_CB(LogMessagesCallback) { Nan::HandleScope scope; - std::list args; + std::queue args; uv_mutex_lock(&grpc_logger_state.mutex); - args.splice(args.begin(), *grpc_logger_state.pending_args); + grpc_logger_state.pending_args->swap(args); uv_mutex_unlock(&grpc_logger_state.mutex); /* Call the callback with each log message */ while (!args.empty()) { log_args *arg = args.front(); - args.pop_front(); + args.pop(); Local file = Nan::New(arg->core_args.file).ToLocalChecked(); Local line = Nan::New(arg->core_args.line); Local severity = Nan::New( @@ -368,7 +368,7 @@ void node_log_func(gpr_log_func_args *args) { args_copy->timestamp = gpr_now(GPR_CLOCK_REALTIME); uv_mutex_lock(&grpc_logger_state.mutex); - grpc_logger_state.pending_args->push_back(args_copy); + grpc_logger_state.pending_args->push(args_copy); uv_mutex_unlock(&grpc_logger_state.mutex); uv_async_send(&grpc_logger_state.async); @@ -376,7 +376,7 @@ void node_log_func(gpr_log_func_args *args) { void init_logger() { memset(&grpc_logger_state, 0, sizeof(logger_state)); - grpc_logger_state.pending_args = new std::list(); + grpc_logger_state.pending_args = new std::queue(); uv_mutex_init(&grpc_logger_state.mutex); uv_async_init(uv_default_loop(), &grpc_logger_state.async, From 123d0dbd614f6d6626295dec93764549e0e650ff Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 7 Dec 2016 09:37:24 -0800 Subject: [PATCH 084/261] bug fix --- src/objective-c/CronetFramework.podspec | 1 - 1 file changed, 1 deletion(-) diff --git a/src/objective-c/CronetFramework.podspec b/src/objective-c/CronetFramework.podspec index d45b8d8143b..509358dada2 100644 --- a/src/objective-c/CronetFramework.podspec +++ b/src/objective-c/CronetFramework.podspec @@ -70,7 +70,6 @@ Pod::Spec.new do |s| s.vendored_framework = "Cronet.framework" s.author = "The Chromium Authors" s.ios.deployment_target = "8.0" - file = s.source = { :http => "https://storage.googleapis.com/grpc-precompiled-binaries/cronet/Cronet.framework-v#{v}.zip"} s.preserve_paths = "Cronet.framework" s.public_header_files = "Cronet.framework/Headers/**/*{.h}" From 18348a3bfbf5611b3ae68d5bda4c360c44f54cd1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 09:58:31 -0800 Subject: [PATCH 085/261] Fix C++ test compilation --- test/cpp/grpclb/grpclb_test.cc | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index fcdcaba6a23..87b02e5c88f 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -288,7 +288,8 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -345,8 +346,9 @@ static void start_backend_server(server_fixture *sf) { } GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); const string expected_token = - strlen(sf->lb_token_prefix) == 0 ? "" : sf->lb_token_prefix + - std::to_string(sf->port); + strlen(sf->lb_token_prefix) == 0 + ? "" + : sf->lb_token_prefix + std::to_string(sf->port); GPR_ASSERT(contains_metadata(&request_metadata_recv, "lb-token", expected_token.c_str())); @@ -433,7 +435,9 @@ static void start_backend_server(server_fixture *sf) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "Backend server out a-ok"; + grpc_slice status_details = + grpc_slice_from_static_string("Backend server out a-ok"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -462,8 +466,7 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details; grpc_byte_buffer *request_payload; grpc_byte_buffer *response_payload_recv; int i; @@ -472,9 +475,11 @@ static void perform_request(client_fixture *cf) { grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); + grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(cf->client, NULL, GRPC_PROPAGATE_DEFAULTS, - cf->cq, "/foo", "foo.test.google.fr:1234", - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL); + cf->cq, grpc_slice_from_static_string("/foo"), + &host, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), + NULL); gpr_log(GPR_INFO, "Call 0x%" PRIxPTR " created", (intptr_t)c); GPR_ASSERT(c); char *peer; @@ -497,7 +502,6 @@ static void perform_request(client_fixture *cf) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -553,7 +557,7 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - gpr_free(details); + grpc_slice_unref(details); gpr_log(GPR_INFO, "Client call (peer %s) DESTROYED.", peer); gpr_free(peer); } From ebc77551e90793e1cd5403cb740c70b13403ecfd Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 11:25:11 -0800 Subject: [PATCH 086/261] Fix memory overrun --- src/core/lib/transport/static_metadata.c | 2 +- tools/codegen/core/gen_static_metadata.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index ee1e22b2b27..807adfef549 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -440,7 +440,7 @@ static uint32_t elems_phash(uint32_t i) { i -= 42; uint32_t x = i % 96; uint32_t y = i / 96; - return x + (uint32_t)elems_r[y]; + return y < GPR_ARRAY_SIZE(elems_r) ? x + (uint32_t)elems_r[y] : 0; } static const uint16_t elem_keys[] = { diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index b7c9533602e..1a2911cd04c 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -424,7 +424,7 @@ static uint32_t %(name)s_phash(uint32_t i) { i %(offset_sign)s= %(offset)d; uint32_t x = i %% %(t)d; uint32_t y = i / %(t)d; - return x + (uint32_t)%(name)s_r[y]; + return y < GPR_ARRAY_SIZE(%(name)s_r) ? x + (uint32_t)%(name)s_r[y] : 0; } """ % { 'name': name, From 75731e65a8454d2632acd84a9255facaacc3d424 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 15:23:21 -0800 Subject: [PATCH 087/261] Fix some leaks/use-after-frees --- src/core/lib/surface/lame_client.c | 7 +++++++ test/core/end2end/fixtures/proxy.c | 4 ++++ test/core/end2end/invalid_call_argument_test.c | 1 + test/core/end2end/tests/max_concurrent_streams.c | 2 ++ test/core/transport/chttp2/hpack_encoder_test.c | 14 ++++++++------ 5 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/core/lib/surface/lame_client.c b/src/core/lib/surface/lame_client.c index a43969be570..e713893fef5 100644 --- a/src/core/lib/surface/lame_client.c +++ b/src/core/lib/surface/lame_client.c @@ -49,6 +49,7 @@ typedef struct { grpc_linked_mdelem status; grpc_linked_mdelem details; + gpr_atm filled_metadata; } call_data; typedef struct { @@ -59,6 +60,9 @@ typedef struct { static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_metadata_batch *mdb) { call_data *calld = elem->call_data; + if (!gpr_atm_no_barrier_cas(&calld->filled_metadata, 0, 1)) { + return; + } channel_data *chand = elem->channel_data; char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); @@ -72,6 +76,7 @@ static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, calld->details.prev = &calld->status; mdb->list.head = &calld->status; mdb->list.tail = &calld->details; + mdb->list.count = 2; mdb->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } @@ -118,6 +123,8 @@ static void lame_start_transport_op(grpc_exec_ctx *exec_ctx, static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_call_element_args *args) { + call_data *calld = elem->call_data; + gpr_atm_no_barrier_store(&calld->filled_metadata, 0); return GRPC_ERROR_NONE; } diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index c592f5a4711..30bb9ff1b34 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -111,6 +111,7 @@ grpc_end2end_proxy *grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, grpc_server_register_completion_queue(proxy->server, proxy->cq, NULL); grpc_server_start(proxy->server); + grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); @@ -398,6 +399,9 @@ static void on_new_call(void *arg, int success) { request_call(proxy); + grpc_call_details_destroy(&proxy->new_call_details); + grpc_call_details_init(&proxy->new_call_details); + unrefpc(pc, "init"); } else { GPR_ASSERT(proxy->new_call == NULL); diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index 3b26ddb6d08..3a68e55ba37 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -75,6 +75,7 @@ static void prepare_test(int is_client) { g_state.deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2); g_state.cq = grpc_completion_queue_create(NULL); g_state.cqv = cq_verifier_create(g_state.cq); + g_state.details = grpc_empty_slice(); memset(g_state.ops, 0, sizeof(g_state.ops)); if (is_client) { diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index 56243179b01..b34ea40f1b3 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -391,6 +391,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { CQ_EXPECT_COMPLETION(cqv, tag(live_call + 1), 1); cq_verify(cqv); + grpc_call_details_destroy(&call_details); + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( f.server, &s2, &call_details, &request_metadata_recv, f.cq, f.cq, tag(201))); diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index 9e418bad5d0..d572d79a7ff 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -81,9 +81,9 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, e[i - 1].next = &e[i]; e[i].prev = &e[i - 1]; } - e[i].md = - grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + e[i].md = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(value))); } e[0].prev = NULL; e[nheaders - 1].next = NULL; @@ -91,6 +91,7 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, b.list.head = &e[0]; b.list.tail = &e[nheaders - 1]; + b.list.count = nheaders; if (cap_to_delete == num_to_delete) { cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000); @@ -195,9 +196,9 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value) { grpc_slice_buffer output; - grpc_mdelem elem = - grpc_mdelem_from_slices(exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem elem = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), + grpc_slice_intern(grpc_slice_from_static_string(value))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t initial_table_size = g_compressor.table_size; grpc_linked_mdelem *e = gpr_malloc(sizeof(*e)); @@ -208,6 +209,7 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, e[0].next = NULL; b.list.head = &e[0]; b.list.tail = &e[0]; + b.list.count = 1; grpc_slice_buffer_init(&output); grpc_transport_one_way_stats stats; From 3153e5af0cda0755d927f281f6561eb52279ced1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 16:25:26 -0800 Subject: [PATCH 088/261] Fix memory leak --- src/core/lib/security/transport/server_auth_filter.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 4433704cb97..cddc5d90863 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -137,6 +137,10 @@ static void on_md_processing_done( grpc_slice message; grpc_transport_stream_op *close_op = gpr_malloc(sizeof(*close_op)); memset(close_op, 0, sizeof(*close_op)); + for (size_t i = 0; i < calld->md.count; i++) { + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); + grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); + } grpc_metadata_array_destroy(&calld->md); error_details = error_details != NULL ? error_details From 5efdf3ca26303df055a17de5bd0265378d663ddc Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 17:30:21 -0800 Subject: [PATCH 089/261] Fix casting error --- src/core/lib/transport/static_metadata.c | 7 ++++++- tools/codegen/core/gen_static_metadata.py | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 807adfef549..5adc3216c98 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -440,7 +440,12 @@ static uint32_t elems_phash(uint32_t i) { i -= 42; uint32_t x = i % 96; uint32_t y = i / 96; - return y < GPR_ARRAY_SIZE(elems_r) ? x + (uint32_t)elems_r[y] : 0; + uint32_t h = x; + if (y < GPR_ARRAY_SIZE(elems_r)) { + uint32_t delta = (uint32_t)elems_r[y]; + h += delta; + } + return h; } static const uint16_t elem_keys[] = { diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 1a2911cd04c..0374cf75a1a 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -424,7 +424,12 @@ static uint32_t %(name)s_phash(uint32_t i) { i %(offset_sign)s= %(offset)d; uint32_t x = i %% %(t)d; uint32_t y = i / %(t)d; - return y < GPR_ARRAY_SIZE(%(name)s_r) ? x + (uint32_t)%(name)s_r[y] : 0; + uint32_t h = x; + if (y < GPR_ARRAY_SIZE(%(name)s_r)) { + uint32_t delta = (uint32_t)%(name)s_r[y]; + h += delta; + } + return h; } """ % { 'name': name, From 35e34915423bde8a4273f1837700442e2b698c67 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 7 Dec 2016 17:52:07 -0800 Subject: [PATCH 090/261] Fix cronet for new metadata interfaces --- .../cronet/transport/cronet_transport.c | 47 ++++++++++++------- 1 file changed, 31 insertions(+), 16 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index a5996b448fb..02e3099f0f5 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -44,6 +44,8 @@ #include "src/core/ext/transport/chttp2/transport/incoming_metadata.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/metadata_batch.h" @@ -429,9 +431,11 @@ static void on_response_headers_received( for (size_t i = 0; i < headers->count; i++) { grpc_chttp2_incoming_metadata_buffer_add( &s->state.rs.initial_metadata, - grpc_mdelem_from_metadata_strings( - &exec_ctx, grpc_mdstr_from_string(headers->headers[i].key), - grpc_mdstr_from_string(headers->headers[i].value))); + grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( + headers->headers[i].key)), + grpc_slice_intern( + grpc_slice_from_static_string(headers->headers[i].value)))); } s->state.state_callback_received[OP_RECV_INITIAL_METADATA] = true; gpr_mu_unlock(&s->mu); @@ -507,9 +511,11 @@ static void on_response_trailers_received( trailers->headers[i].value); grpc_chttp2_incoming_metadata_buffer_add( &s->state.rs.trailing_metadata, - grpc_mdelem_from_metadata_strings( - &exec_ctx, grpc_mdstr_from_string(trailers->headers[i].key), - grpc_mdstr_from_string(trailers->headers[i].value))); + grpc_mdelem_from_slices( + &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( + trailers->headers[i].key)), + grpc_slice_intern( + grpc_slice_from_static_string(trailers->headers[i].value)))); s->state.rs.trailing_metadata_valid = true; } s->state.state_callback_received[OP_RECV_TRAILING_METADATA] = true; @@ -573,31 +579,39 @@ static void convert_metadata_to_cronet_headers( while (num_headers < num_headers_available) { grpc_mdelem mdelem = curr->md; curr = curr->next; - const char *key = grpc_mdstr_as_c_string(mdelem->key); - const char *value = grpc_mdstr_as_c_string(mdelem->value); - if (mdelem->key == GRPC_MDSTR_SCHEME || - mdelem->key == GRPC_MDSTR_AUTHORITY) { + char *key = grpc_dump_slice(GRPC_MDKEY(mdelem), GPR_DUMP_ASCII); + char *value = grpc_dump_slice(GRPC_MDVALUE(mdelem), GPR_DUMP_ASCII); + if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_SCHEME) || + grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_AUTHORITY)) { /* Cronet populates these fields on its own */ + gpr_free(key); + gpr_free(value); continue; } - if (mdelem->key == GRPC_MDSTR_METHOD) { - if (mdelem->value == GRPC_MDSTR_PUT) { + if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_METHOD)) { + if (grpc_slice_eq(GRPC_MDVALUE(mdelem), GRPC_MDSTR_PUT)) { *method = "PUT"; } else { /* POST method in default*/ *method = "POST"; } + gpr_free(key); + gpr_free(value); continue; } - if (mdelem->key == GRPC_MDSTR_PATH) { + if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_PATH)) { /* Create URL by appending :path value to the hostname */ gpr_asprintf(pp_url, "https://%s%s", host, value); + gpr_free(key); + gpr_free(value); continue; } CRONET_LOG(GPR_DEBUG, "header %s = %s", key, value); headers[num_headers].key = key; headers[num_headers].value = value; num_headers++; + gpr_free(key); + gpr_free(value); if (curr == NULL) { break; } @@ -617,7 +631,7 @@ static int parse_grpc_header(const uint8_t *data) { static bool header_has_authority(grpc_linked_mdelem *head) { while (head != NULL) { - if (head->md->key == GRPC_MDSTR_AUTHORITY) { + if (grpc_slice_eq(GRPC_MDKEY(head->md), GRPC_MDSTR_AUTHORITY)) { return true; } head = head->next; @@ -818,7 +832,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, GRPC_ERROR_CANCELLED, NULL); } else { grpc_chttp2_incoming_metadata_buffer_publish( - &oas->s->state.rs.initial_metadata, stream_op->recv_initial_metadata); + exec_ctx, &oas->s->state.rs.initial_metadata, + stream_op->recv_initial_metadata); grpc_exec_ctx_sched(exec_ctx, stream_op->recv_initial_metadata_ready, GRPC_ERROR_NONE, NULL); } @@ -962,7 +977,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", oas); if (oas->s->state.rs.trailing_metadata_valid) { grpc_chttp2_incoming_metadata_buffer_publish( - &oas->s->state.rs.trailing_metadata, + exec_ctx, &oas->s->state.rs.trailing_metadata, stream_op->recv_trailing_metadata); stream_state->rs.trailing_metadata_valid = false; } From 990983110f0c2e948ab23289f994876f1e0f565f Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 7 Dec 2016 19:37:01 -0800 Subject: [PATCH 091/261] Begin patching Cython --- .../grpc/_cython/_cygrpc/channel.pyx.pxi | 14 ++- .../grpcio/grpc/_cython/_cygrpc/grpc.pxi | 35 +++---- .../grpc/_cython/_cygrpc/records.pxd.pxi | 15 ++- .../grpc/_cython/_cygrpc/records.pyx.pxi | 94 +++++++++++-------- 4 files changed, 95 insertions(+), 63 deletions(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index 73d1ff7b97d..e4c24a83abd 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -60,19 +60,23 @@ cdef class Channel: method, host, Timespec deadline not None): if queue.is_shutting_down: raise ValueError("queue must not be shutting down or shutdown") - cdef char *method_c_string = method - cdef char *host_c_string = NULL + cdef Slice method_slice = Slice.from_bytes(method) + cdef Slice host_slice + cdef grpc_slice *host_c_slice = NULL if host is not None: - host_c_string = host + host_slice = Slice.from_bytes(host) + host_c_slice = &host_slice.c_slice + else: + host_slice = Slice() cdef Call operation_call = Call() - operation_call.references = [self, method, host, queue] + operation_call.references = [self, method_slice, host_slice, queue] cdef grpc_call *parent_call = NULL if parent is not None: parent_call = parent.c_call with nogil: operation_call.c_call = grpc_channel_create_call( self.c_channel, parent_call, flags, - queue.c_completion_queue, method_c_string, host_c_string, + queue.c_completion_queue, method_slice.c_slice, host_c_slice, deadline.c_time, NULL) return operation_call diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index ad766186bd1..141580b82ad 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -51,6 +51,13 @@ cdef extern from "grpc/byte_buffer_reader.h": pass +cdef extern from "grpc/impl/codegen/exec_ctx_fwd.h": + + struct grpc_exec_ctx: + # We don't care about the internals + pass + + cdef extern from "grpc/grpc.h": ctypedef struct grpc_slice: @@ -60,6 +67,7 @@ cdef extern from "grpc/grpc.h": grpc_slice grpc_slice_ref(grpc_slice s) nogil void grpc_slice_unref(grpc_slice s) nogil + grpc_slice grpc_empty_slice() nogil grpc_slice grpc_slice_new(void *p, size_t len, void (*destroy)(void *)) nogil grpc_slice grpc_slice_new_with_len( void *p, size_t len, void (*destroy)(void *, size_t)) nogil @@ -175,7 +183,7 @@ cdef extern from "grpc/grpc.h": ctypedef struct grpc_arg_pointer_vtable: void *(*copy)(void *) - void (*destroy)(void *) + void (*destroy)(grpc_exec_ctx *, void *) int (*cmp)(void *, void *) ctypedef struct grpc_arg_value_pointer: @@ -217,9 +225,8 @@ cdef extern from "grpc/grpc.h": GRPC_CHANNEL_SHUTDOWN ctypedef struct grpc_metadata: - const char *key - const char *value - size_t value_length + grpc_slice key + grpc_slice value # ignore the 'internal_data.obfuscated' fields. ctypedef enum grpc_completion_type: @@ -241,10 +248,8 @@ cdef extern from "grpc/grpc.h": void grpc_metadata_array_destroy(grpc_metadata_array *array) nogil ctypedef struct grpc_call_details: - char *method - size_t method_capacity - char *host - size_t host_capacity + grpc_slice method + grpc_slice host gpr_timespec deadline void grpc_call_details_init(grpc_call_details *details) nogil @@ -268,13 +273,12 @@ cdef extern from "grpc/grpc.h": size_t trailing_metadata_count grpc_metadata *trailing_metadata grpc_status_code status - const char *status_details + grpc_slice *status_details ctypedef struct grpc_op_data_recv_status_on_client: grpc_metadata_array *trailing_metadata grpc_status_code *status - char **status_details - size_t *status_details_capacity + grpc_slice *status_details ctypedef struct grpc_op_data_recv_close_on_server: int *cancelled @@ -321,9 +325,9 @@ cdef extern from "grpc/grpc.h": const grpc_channel_args *args, void *reserved) nogil grpc_call *grpc_channel_create_call( - grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_completion_queue *completion_queue, const char *method, - const char *host, gpr_timespec deadline, void *reserved) nogil + grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, + grpc_completion_queue *completion_queue, grpc_slice method, + const grpc_slice *host, gpr_timespec deadline, void *reserved) nogil grpc_connectivity_state grpc_channel_check_connectivity_state( grpc_channel *channel, int try_to_connect) nogil void grpc_channel_watch_connectivity_state( @@ -473,8 +477,7 @@ cdef extern from "grpc/compression.h": grpc_compression_algorithm default_compression_algorithm int grpc_compression_algorithm_parse( - const char *name, size_t name_length, - grpc_compression_algorithm *algorithm) nogil + grpc_slice value, grpc_compression_algorithm *algorithm) nogil int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, char **name) nogil grpc_compression_algorithm grpc_compression_algorithm_for_level( diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index 00ec91b131e..870da51fa8b 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -70,6 +70,15 @@ cdef class Event: cdef readonly Operations batch_operations +cdef class Slice: + + cdef grpc_slice c_slice + + cdef void _assign_slice(self, grpc_slice new_slice) nogil + @staticmethod + cdef Slice from_slice(grpc_slice slice) + + cdef class ByteBuffer: cdef grpc_byte_buffer *c_byte_buffer @@ -97,7 +106,8 @@ cdef class ChannelArgs: cdef class Metadatum: cdef grpc_metadata c_metadata - cdef object _key, _value + cdef Slice _key, + cdef Slice _value cdef class Metadata: @@ -112,8 +122,7 @@ cdef class Operation: cdef ByteBuffer _received_message cdef Metadata _received_metadata cdef grpc_status_code _received_status_code - cdef char *_received_status_details - cdef size_t _received_status_details_capacity + cdef Slice _received_status_details cdef int _received_cancelled cdef readonly bint is_valid cdef object references diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index cadfce6ee6b..b7a75cd97a0 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -189,17 +189,11 @@ cdef class CallDetails: @property def method(self): - if self.c_details.method != NULL: - return self.c_details.method - else: - return None + return Slice.from_slice(self.c_details.method).bytes() @property def host(self): - if self.c_details.host != NULL: - return self.c_details.host - else: - return None + return Slice.from_slice(self.c_details.host).bytes() @property def deadline(self): @@ -233,6 +227,42 @@ cdef class Event: self.is_new_request = is_new_request +cdef class Slice: + + def __cinit__(self): + with nogil: + grpc_init() + self.c_slice = grpc_empty_slice() + + cdef void _assign_slice(self, grpc_slice new_slice) nogil: + grpc_slice_unref(self.c_slice) + self.c_slice = new_slice + + @staticmethod + def from_bytes(bytes data): + cdef Slice self = Slice() + self._assign_slice(grpc_slice_from_copied_buffer(data, len(data))) + return self + + @staticmethod + cdef Slice from_slice(grpc_slice slice): + cdef Slice self = Slice() + grpc_slice_ref(slice) + self._assign_slice(slice) + return self + + def bytes(self): + with nogil: + pointer = grpc_slice_start_ptr(self.c_slice) + length = grpc_slice_length(self.c_slice) + return (pointer)[:length] + + def __dealloc__(self): + with nogil: + grpc_slice_unref(self.c_slice) + grpc_shutdown() + + cdef class ByteBuffer: def __cinit__(self, bytes data): @@ -310,7 +340,7 @@ cdef void* copy_ptr(void* ptr): return ptr -cdef void destroy_ptr(void* ptr): +cdef void destroy_ptr(grpc_exec_ctx* ctx, void* ptr): pass @@ -382,20 +412,20 @@ cdef class ChannelArgs: cdef class Metadatum: + # TODO(atash) this should just accept Slice objects. def __cinit__(self, bytes key, bytes value): - self._key = key - self._value = value - self.c_metadata.key = self._key - self.c_metadata.value = self._value - self.c_metadata.value_length = len(self._value) + self._key = Slice.from_bytes(key) + self._value = Slice.from_bytes(value) + self.c_metadata.key = self._key.c_slice + self.c_metadata.value = self._value.c_slice @property def key(self): - return self.c_metadata.key + return self._key.bytes() @property def value(self): - return self.c_metadata.value[:self.c_metadata.value_length] + return self._value.bytes() def __len__(self): return 2 @@ -465,9 +495,8 @@ cdef class Metadata: def __getitem__(self, size_t i): return Metadatum( - key=self.c_metadata_array.metadata[i].key, - value=self.c_metadata_array.metadata[i].value[ - :self.c_metadata_array.metadata[i].value_length]) + key=Slice.from_slice(self.c_metadata_array.metadata[i].key).bytes(), + value=Slice.from_slice(self.c_metadata_array.metadata[i].value).bytes()) def __iter__(self): return _MetadataIterator(self) @@ -478,8 +507,7 @@ cdef class Operation: def __cinit__(self): grpc_init() self.references = [] - self._received_status_details = NULL - self._received_status_details_capacity = 0 + self._received_status_details = Slice() self.is_valid = False @property @@ -536,19 +564,13 @@ cdef class Operation: def received_status_details(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: raise TypeError("self must be an operation receiving status details") - if self._received_status_details: - return self._received_status_details - else: - return None + return self._received_status_details.bytes() @property def received_status_details_or_none(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: return None - if self._received_status_details: - return self._received_status_details - else: - return None + return self._received_status_details.bytes() @property def received_cancelled(self): @@ -564,11 +586,6 @@ cdef class Operation: return False if self._received_cancelled == 0 else True def __dealloc__(self): - # We *almost* don't need to do anything; most of the objects are handled by - # Python. The remaining one(s) are primitive fields filled in by GRPC core. - # This means that we need to clean up after receive_status_on_client. - if self.c_op.type == GRPC_OP_RECV_STATUS_ON_CLIENT: - gpr_free(self._received_status_details) grpc_shutdown() def operation_send_initial_metadata(Metadata metadata, int flags): @@ -609,9 +626,10 @@ def operation_send_status_from_server( op.c_op.data.send_status_from_server.trailing_metadata = ( metadata.c_metadata_array.metadata) op.c_op.data.send_status_from_server.status = code - op.c_op.data.send_status_from_server.status_details = details + cdef Slice details_slice = Slice.from_bytes(details) + op.c_op.data.send_status_from_server.status_details = &details_slice.c_slice op.references.append(metadata) - op.references.append(details) + op.references.append(details_slice) op.is_valid = True return op @@ -647,9 +665,7 @@ def operation_receive_status_on_client(int flags): op.c_op.data.receive_status_on_client.status = ( &op._received_status_code) op.c_op.data.receive_status_on_client.status_details = ( - &op._received_status_details) - op.c_op.data.receive_status_on_client.status_details_capacity = ( - &op._received_status_details_capacity) + &op._received_status_details.c_slice) op.is_valid = True return op From f658bf0e1ba017038267246a42bd980ce0f9033d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 8 Dec 2016 14:11:47 -0800 Subject: [PATCH 092/261] Start resolving memory issues in C++ metadata --- include/grpc++/impl/codegen/call.h | 43 ++++------- include/grpc++/impl/codegen/client_context.h | 10 +-- include/grpc++/impl/codegen/metadata_map.h | 71 +++++++++++++++++++ include/grpc++/impl/codegen/server_context.h | 5 +- include/grpc++/impl/codegen/slice.h | 9 +-- src/core/ext/census/gen/census.pb.h | 2 +- src/core/ext/census/gen/trace_context.pb.h | 2 +- .../transport/chttp2/transport/hpack_table.h | 2 +- src/core/lib/compression/compression.c | 3 +- src/core/lib/slice/slice_hash_table.c | 2 +- src/core/lib/slice/slice_hash_table.h | 6 +- src/core/lib/slice/slice_intern.c | 18 ++--- src/core/lib/slice/slice_internal.h | 9 ++- src/core/lib/slice/slice_traits.h | 6 +- src/core/lib/surface/channel.h | 4 +- src/core/lib/transport/metadata.c | 9 ++- src/cpp/server/secure_server_credentials.cc | 4 +- src/cpp/server/server_cc.cc | 12 +--- src/cpp/server/server_context.cc | 7 +- src/cpp/test/server_context_test_spouse.cc | 7 +- test/core/end2end/cq_verifier.c | 3 +- test/core/end2end/fixtures/h2_ssl_cert.c | 4 +- test/core/end2end/fuzzers/api_fuzzer.c | 2 +- test/core/slice/percent_encoding_test.c | 4 +- test/cpp/end2end/async_end2end_test.cc | 21 ++++-- test/cpp/end2end/end2end_test.cc | 20 ++++-- test/cpp/grpclb/grpclb_test.cc | 5 +- 27 files changed, 184 insertions(+), 106 deletions(-) create mode 100644 include/grpc++/impl/codegen/metadata_map.h diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 1d511792570..9165f4fd6c5 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -63,19 +63,6 @@ class CallHook; class CompletionQueue; extern CoreCodegenInterface* g_core_codegen_interface; -inline void FillMetadataMap( - grpc_metadata_array* arr, - std::multimap* metadata) { - for (size_t i = 0; i < arr->count; i++) { - // TODO(yangg) handle duplicates? - metadata->insert(std::pair( - StringRefFromSlice(arr->metadata[i].key), - StringRefFromSlice(arr->metadata[i].value))); - } - g_core_codegen_interface->grpc_metadata_array_destroy(arr); - g_core_codegen_interface->grpc_metadata_array_init(arr); -} - // TODO(yangg) if the map is changed before we send, the pointers will be a // mess. Make sure it does not happen. inline grpc_metadata* FillMetadataArray( @@ -474,32 +461,30 @@ class CallOpServerSendStatus { class CallOpRecvInitialMetadata { public: - CallOpRecvInitialMetadata() : recv_initial_metadata_(nullptr) {} + CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} void RecvInitialMetadata(ClientContext* context) { context->initial_metadata_received_ = true; - recv_initial_metadata_ = &context->recv_initial_metadata_; + metadata_map_ = &context->recv_initial_metadata_; } protected: void AddOp(grpc_op* ops, size_t* nops) { - if (!recv_initial_metadata_) return; - memset(&recv_initial_metadata_arr_, 0, sizeof(recv_initial_metadata_arr_)); + if (metadata_map_ == nullptr) return; grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata = &recv_initial_metadata_arr_; + op->data.recv_initial_metadata = metadata_map_->arr(); op->flags = 0; op->reserved = NULL; } void FinishOp(bool* status, int max_receive_message_size) { - if (recv_initial_metadata_ == nullptr) return; - FillMetadataMap(&recv_initial_metadata_arr_, recv_initial_metadata_); - recv_initial_metadata_ = nullptr; + if (metadata_map_ == nullptr) return; + metadata_map_->FillMap(); + metadata_map_ = nullptr; } private: - std::multimap* recv_initial_metadata_; - grpc_metadata_array recv_initial_metadata_arr_; + MetadataMap* metadata_map_; }; class CallOpClientRecvStatus { @@ -507,19 +492,16 @@ class CallOpClientRecvStatus { CallOpClientRecvStatus() : recv_status_(nullptr) {} void ClientRecvStatus(ClientContext* context, Status* status) { - recv_trailing_metadata_ = &context->trailing_metadata_; + metadata_map_ = &context->trailing_metadata_; recv_status_ = status; } protected: void AddOp(grpc_op* ops, size_t* nops) { if (recv_status_ == nullptr) return; - memset(&recv_trailing_metadata_arr_, 0, - sizeof(recv_trailing_metadata_arr_)); grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = - &recv_trailing_metadata_arr_; + op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); op->data.recv_status_on_client.status = &status_code_; op->data.recv_status_on_client.status_details = &status_details_; op->flags = 0; @@ -528,7 +510,7 @@ class CallOpClientRecvStatus { void FinishOp(bool* status, int max_receive_message_size) { if (recv_status_ == nullptr) return; - FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_); + metadata_map_->FillMap(); *recv_status_ = Status(static_cast(status_code_), grpc::string(GRPC_SLICE_START_PTR(status_details_), GRPC_SLICE_END_PTR(status_details_))); @@ -537,9 +519,8 @@ class CallOpClientRecvStatus { } private: - std::multimap* recv_trailing_metadata_; + MetadataMap* metadata_map_; Status* recv_status_; - grpc_metadata_array recv_trailing_metadata_arr_; grpc_status_code status_code_; grpc_slice status_details_; }; diff --git a/include/grpc++/impl/codegen/client_context.h b/include/grpc++/impl/codegen/client_context.h index 777b2f8847f..b91c7f65d43 100644 --- a/include/grpc++/impl/codegen/client_context.h +++ b/include/grpc++/impl/codegen/client_context.h @@ -57,7 +57,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -193,7 +195,7 @@ class ClientContext { const std::multimap& GetServerInitialMetadata() const { GPR_CODEGEN_ASSERT(initial_metadata_received_); - return recv_initial_metadata_; + return *recv_initial_metadata_.map(); } /// Return a collection of trailing metadata key-value pairs. Note that keys @@ -205,7 +207,7 @@ class ClientContext { const std::multimap& GetServerTrailingMetadata() const { // TODO(yangg) check finished - return trailing_metadata_; + return *trailing_metadata_.map(); } /// Set the deadline for the client call. @@ -375,8 +377,8 @@ class ClientContext { mutable std::shared_ptr auth_context_; struct census_context* census_context_; std::multimap send_initial_metadata_; - std::multimap recv_initial_metadata_; - std::multimap trailing_metadata_; + MetadataMap recv_initial_metadata_; + MetadataMap trailing_metadata_; grpc_call* propagate_from_call_; PropagationOptions propagation_options_; diff --git a/include/grpc++/impl/codegen/metadata_map.h b/include/grpc++/impl/codegen/metadata_map.h new file mode 100644 index 00000000000..fc2ed7d9e1a --- /dev/null +++ b/include/grpc++/impl/codegen/metadata_map.h @@ -0,0 +1,71 @@ +/* +* +* 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. +* +*/ + +#ifndef META_H +#define META_H + +#include + +namespace grpc { + +class MetadataMap { + public: + MetadataMap() { memset(&arr_, 0, sizeof(arr_)); } + + ~MetadataMap() { + g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); + } + + void FillMap() { + for (size_t i = 0; i < arr_.count; i++) { + // TODO(yangg) handle duplicates? + map_.insert(std::pair( + StringRefFromSlice(&arr_.metadata[i].key), + StringRefFromSlice(&arr_.metadata[i].value))); + } + } + + std::multimap *map() { return &map_; } + const std::multimap *map() const { + return &map_; + } + grpc_metadata_array *arr() { return &arr_; } + + private: + grpc_metadata_array arr_; + std::multimap map_; +}; + +} // namespace grpc + +#endif diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h index dd305763796..8c7fe0809ea 100644 --- a/include/grpc++/impl/codegen/server_context.h +++ b/include/grpc++/impl/codegen/server_context.h @@ -39,6 +39,7 @@ #include #include +#include #include #include #include @@ -123,7 +124,7 @@ class ServerContext { const std::multimap& client_metadata() const { - return client_metadata_; + return *client_metadata_.map(); } grpc_compression_level compression_level() const { @@ -223,7 +224,7 @@ class ServerContext { CompletionQueue* cq_; bool sent_initial_metadata_; mutable std::shared_ptr auth_context_; - std::multimap client_metadata_; + MetadataMap client_metadata_; std::multimap initial_metadata_; std::multimap trailing_metadata_; diff --git a/include/grpc++/impl/codegen/slice.h b/include/grpc++/impl/codegen/slice.h index e79754f943e..04b2f9af016 100644 --- a/include/grpc++/impl/codegen/slice.h +++ b/include/grpc++/impl/codegen/slice.h @@ -39,9 +39,10 @@ namespace grpc { -inline grpc::string_ref StringRefFromSlice(grpc_slice slice) { - return grpc::string_ref(reinterpret_cast(GRPC_SLICE_START_PTR(slice)), - GRPC_SLICE_LENGTH(slice)); +inline grpc::string_ref StringRefFromSlice(const grpc_slice* slice) { + return grpc::string_ref( + reinterpret_cast(GRPC_SLICE_START_PTR(*slice)), + GRPC_SLICE_LENGTH(*slice)); } inline grpc::string StringFromCopiedSlice(grpc_slice slice) { @@ -61,4 +62,4 @@ inline grpc_slice SliceFromCopiedString(const grpc::string& str) { } // namespace grpc -#endif +#endif // GRPCXX_IMPL_CODEGEN_SLICE_H diff --git a/src/core/ext/census/gen/census.pb.h b/src/core/ext/census/gen/census.pb.h index dae583f33d3..c8546eac2e3 100644 --- a/src/core/ext/census/gen/census.pb.h +++ b/src/core/ext/census/gen/census.pb.h @@ -292,4 +292,4 @@ extern const pb_field_t google_census_Metric_fields[5]; } /* extern "C" */ #endif -#endif +#endif /* GRPC_CORE_EXT_CENSUS_GEN_CENSUS_PB_H */ diff --git a/src/core/ext/census/gen/trace_context.pb.h b/src/core/ext/census/gen/trace_context.pb.h index 263c4c58cbf..cfb2f04ccd2 100644 --- a/src/core/ext/census/gen/trace_context.pb.h +++ b/src/core/ext/census/gen/trace_context.pb.h @@ -96,4 +96,4 @@ extern const pb_field_t google_trace_TraceContext_fields[4]; } /* extern "C" */ #endif -#endif +#endif /* GRPC_CORE_EXT_CENSUS_GEN_TRACE_CONTEXT_PB_H */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index 0e6655289fc..32a0380e009 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -95,7 +95,7 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, /* lookup a table entry based on its hpack index */ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, - uint32_t index); + uint32_t index); /* add a table entry to the index */ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl, diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index 80c1aaed5ba..ce4f597af56 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -84,8 +84,7 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, grpc_compression_algorithm grpc_compression_algorithm_from_slice( grpc_slice str) { if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE; - if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) - return GRPC_COMPRESS_DEFLATE; + if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) return GRPC_COMPRESS_DEFLATE; if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_COMPRESS_GZIP; return GRPC_COMPRESS_ALGORITHMS_COUNT; } diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 017bf03da90..1f3ca72ce6b 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -46,7 +46,7 @@ struct grpc_slice_hash_table { grpc_slice_hash_table_entry* entries; }; -static bool is_empty(grpc_slice_hash_table_entry *entry) { +static bool is_empty(grpc_slice_hash_table_entry* entry) { return entry->vtable == NULL; } diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index f760836a489..d16a95bd1d2 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -29,8 +29,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H -#define GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H +#ifndef GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H +#define GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H #include "src/core/lib/transport/metadata.h" @@ -75,4 +75,4 @@ void grpc_slice_hash_table_unref(grpc_exec_ctx *exec_ctx, void *grpc_slice_hash_table_get(const grpc_slice_hash_table *table, const grpc_slice key); -#endif /* GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H */ +#endif /* GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H */ diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c index f5e9d854972..7cbd17bffd8 100644 --- a/src/core/lib/slice/slice_intern.c +++ b/src/core/lib/slice/slice_intern.c @@ -189,22 +189,24 @@ uint32_t grpc_slice_hash(grpc_slice s) { : s.refcount->vtable->hash(s); } -void grpc_slice_static_intern(grpc_slice *slice) { - if (GRPC_IS_STATIC_METADATA_STRING(*slice)) { - return; +grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, + bool *returned_slice_is_different) { + if (GRPC_IS_STATIC_METADATA_STRING(slice)) { + return slice; } - uint32_t hash = grpc_slice_hash(*slice); + uint32_t hash = grpc_slice_hash(slice); for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { static_metadata_hash_ent ent = static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - grpc_slice_eq(grpc_static_slice_table[ent.idx], *slice)) { - grpc_slice_unref(*slice); - *slice = grpc_static_slice_table[ent.idx]; - return; + grpc_slice_eq(grpc_static_slice_table[ent.idx], slice)) { + *returned_slice_is_different = true; + return grpc_static_slice_table[ent.idx]; } } + + return slice; } bool grpc_slice_is_interned(grpc_slice slice) { diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index cb85d572132..6467b0a8d63 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -52,9 +52,12 @@ bool grpc_slice_is_interned(grpc_slice slice); void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); void grpc_test_only_set_slice_hash_seed(uint32_t key); -// if slice matches a static slice, consume it and replace it with the static -// slice, otherwise do nothing: this is a fast interning for well known strings -void grpc_slice_static_intern(grpc_slice *slice); +// if slice matches a static slice, returns the static slice +// otherwise returns the passed in slice (without reffing it) +// used for surface boundaries where we might receive an un-interned static +// string +grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, + bool *returned_slice_is_different); uint32_t grpc_static_slice_hash(grpc_slice s); int grpc_static_slice_eq(grpc_slice a, grpc_slice b); diff --git a/src/core/lib/slice/slice_traits.h b/src/core/lib/slice/slice_traits.h index facbd0dd812..8a283dc65c4 100644 --- a/src/core/lib/slice/slice_traits.h +++ b/src/core/lib/slice/slice_traits.h @@ -31,8 +31,8 @@ * */ -#ifndef SLICE_TRAITS_H -#define SLICE_TRAITS_H +#ifndef GRPC_CORE_LIB_SLICE_SLICE_TRAITS_H +#define GRPC_CORE_LIB_SLICE_SLICE_TRAITS_H #include #include @@ -41,4 +41,4 @@ bool grpc_slice_is_legal_header(grpc_slice s); bool grpc_slice_is_legal_nonbin_header(grpc_slice s); bool grpc_slice_is_bin_suffixed(grpc_slice s); -#endif +#endif /* GRPC_CORE_LIB_SLICE_SLICE_TRAITS_H */ diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index 0ac04b6b588..3a441d7adde 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -63,8 +63,8 @@ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); The returned elem is owned by the caller. */ grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, - grpc_channel *channel, - int status_code); + grpc_channel *channel, + int status_code); #ifdef GRPC_STREAM_REFCOUNT_DEBUG void grpc_channel_internal_ref(grpc_channel *channel, const char *reason); diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 9f13c7ded69..06e703c9d96 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -342,8 +342,13 @@ grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx *exec_ctx, grpc_metadata *metadata) { - return grpc_mdelem_create(exec_ctx, metadata->key, metadata->value, - (grpc_mdelem_data *)metadata); + bool changed = false; + grpc_slice key_slice = + grpc_slice_maybe_static_intern(metadata->key, &changed); + grpc_slice value_slice = + grpc_slice_maybe_static_intern(metadata->value, &changed); + return grpc_mdelem_create(exec_ctx, key_slice, value_slice, + changed ? NULL : (grpc_mdelem_data *)metadata); } static size_t get_base64_encoded_size(size_t raw_length) { diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 3c90986cd05..10f662c77df 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -72,8 +72,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( grpc_process_auth_metadata_done_cb cb, void* user_data) { AuthMetadataProcessor::InputMetadata metadata; for (size_t i = 0; i < num_md; i++) { - metadata.insert(std::make_pair(StringRefFromSlice(md[i].key), - StringRefFromSlice(md[i].value))); + metadata.insert(std::make_pair(StringRefFromSlice(&md[i].key), + StringRefFromSlice(&md[i].value))); } SecureAuthContext context(ctx, false); AuthMetadataProcessor::OutputMetadata consumed_metadata; diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 1f8782ca723..06fa4a85387 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -586,14 +586,8 @@ ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) { if (*status) { - for (size_t i = 0; i < initial_metadata_array_.count; i++) { - context_->client_metadata_.insert( - std::pair( - StringRefFromSlice(initial_metadata_array_.metadata[i].key), - StringRefFromSlice(initial_metadata_array_.metadata[i].value))); - } + context_->client_metadata_.FillMap(); } - grpc_metadata_array_destroy(&initial_metadata_array_); context_->set_call(call_); context_->cq_ = call_cq_; Call call(call_, server_, call_cq_, server_->max_receive_message_size()); @@ -619,8 +613,8 @@ void ServerInterface::RegisteredAsyncRequest::IssueRequest( ServerCompletionQueue* notification_cq) { grpc_server_request_registered_call( server_->server(), registered_method, &call_, &context_->deadline_, - &initial_metadata_array_, payload, call_cq_->cq(), notification_cq->cq(), - this); + context_->client_metadata_.arr(), payload, call_cq_->cq(), + notification_cq->cq(), this); } ServerInterface::GenericAsyncRequest::GenericAsyncRequest( diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index 9fc8d752eb3..a7aaa255724 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -144,9 +144,10 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, sent_initial_metadata_(false), compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { - client_metadata_.insert(std::pair( - StringRefFromSlice(metadata[i].key), - StringRefFromSlice(metadata[i].value))); + client_metadata_.map()->insert( + std::pair( + StringRefFromSlice(&metadata[i].key), + StringRefFromSlice(&metadata[i].value))); } } diff --git a/src/cpp/test/server_context_test_spouse.cc b/src/cpp/test/server_context_test_spouse.cc index b93152eea0e..b812d169a52 100644 --- a/src/cpp/test/server_context_test_spouse.cc +++ b/src/cpp/test/server_context_test_spouse.cc @@ -40,11 +40,12 @@ void ServerContextTestSpouse::AddClientMetadata(const grpc::string& key, const grpc::string& value) { client_metadata_storage_.insert( std::pair(key, value)); - ctx_->client_metadata_.clear(); + ctx_->client_metadata_.map()->clear(); for (auto iter = client_metadata_storage_.begin(); iter != client_metadata_storage_.end(); ++iter) { - ctx_->client_metadata_.insert(std::pair( - iter->first.c_str(), iter->second.c_str())); + ctx_->client_metadata_.map()->insert( + std::pair(iter->first.c_str(), + iter->second.c_str())); } } diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index 3b463a69337..bc2d5888f0d 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -109,8 +109,7 @@ static int has_metadata_slices(const grpc_metadata *md, size_t count, grpc_slice key, grpc_slice value) { size_t i; for (i = 0; i < count; i++) { - if (grpc_slice_eq(md[i].key, key) && - grpc_slice_eq(md[i].value, value)) { + if (grpc_slice_eq(md[i].key, key) && grpc_slice_eq(md[i].value, value)) { return 1; } } diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/fixtures/h2_ssl_cert.c index 92fac10d49a..844e93396df 100644 --- a/test/core/end2end/fixtures/h2_ssl_cert.c +++ b/test/core/end2end/fixtures/h2_ssl_cert.c @@ -323,8 +323,8 @@ static void simple_request_body(grpc_end2end_test_fixture f, grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), &host, deadline, - NULL); + grpc_slice_from_static_string("/foo"), &host, + deadline, NULL); GPR_ASSERT(c); memset(ops, 0, sizeof(ops)); diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index c9d5c247984..070a6039c45 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -108,7 +108,7 @@ static char *read_string(input_stream *inp, bool *special) { *special = (c == 1); } if (c == 1) { - str[sz-1] = 0; + str[sz - 1] = 0; } return str; } diff --git a/test/core/slice/percent_encoding_test.c b/test/core/slice/percent_encoding_test.c index 0bff4903e6c..222e695fd42 100644 --- a/test/core/slice/percent_encoding_test.c +++ b/test/core/slice/percent_encoding_test.c @@ -123,8 +123,8 @@ static void test_nonconformant_vector(const char *encoded, encoded2raw_permissive_msg); gpr_free(encoded2raw_permissive_msg); - GPR_ASSERT(grpc_slice_eq(permissive_unencoded_slice, - encoded2raw_permissive_slice)); + GPR_ASSERT( + grpc_slice_eq(permissive_unencoded_slice, encoded2raw_permissive_slice)); grpc_slice_unref(permissive_unencoded_slice); grpc_slice_unref(encoded2raw_permissive_slice); diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index 8e385d100c1..70be857b496 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -228,12 +228,7 @@ class TestScenario { : disable_blocking(non_block), credentials_type(creds_type), message_content(content) {} - void Log() const { - gpr_log( - GPR_INFO, - "Scenario: disable_blocking %d, credentials %s, message size %" PRIuPTR, - disable_blocking, credentials_type.c_str(), message_content.size()); - } + void Log() const; bool disable_blocking; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -242,6 +237,20 @@ class TestScenario { grpc::string message_content; }; +static std::ostream& operator<<(std::ostream& out, + const TestScenario& scenario) { + return out << "TestScenario{disable_blocking=" + << (scenario.disable_blocking ? "true" : "false") + << ", credentials='" << scenario.credentials_type + << "', message_size=" << scenario.message_content.size() << "}"; +} + +void TestScenario::Log() const { + std::ostringstream out; + out << *this; + gpr_log(GPR_DEBUG, "%s", out.str().c_str()); +} + class AsyncEnd2endTest : public ::testing::TestWithParam { protected: AsyncEnd2endTest() { GetParam().Log(); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 9bb892c694b..620b3ae7bcb 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -209,10 +209,7 @@ class TestScenario { public: TestScenario(bool proxy, const grpc::string& creds_type) : use_proxy(proxy), credentials_type(creds_type) {} - void Log() const { - gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy, - credentials_type.c_str()); - } + void Log() const; bool use_proxy; // Although the below grpc::string is logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -220,6 +217,19 @@ class TestScenario { grpc::string credentials_type; }; +static std::ostream& operator<<(std::ostream& out, + const TestScenario& scenario) { + return out << "TestScenario{use_proxy=" + << (scenario.use_proxy ? "true" : "false") << ", credentials='" + << scenario.credentials_type << "'}"; +} + +void TestScenario::Log() const { + std::ostringstream out; + out << *this; + gpr_log(GPR_DEBUG, "%s", out.str().c_str()); +} + class End2endTest : public ::testing::TestWithParam { protected: End2endTest() @@ -635,7 +645,7 @@ TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { TestBidiStreamServerCancel(CANCEL_AFTER_PROCESSING, 5); } -TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) { +TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { user_agent_prefix_ = "custom_prefix"; ResetStub(); EchoRequest request; diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 87b02e5c88f..c93dfacbe08 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -346,9 +346,8 @@ static void start_backend_server(server_fixture *sf) { } GPR_ASSERT(ev.type == GRPC_OP_COMPLETE); const string expected_token = - strlen(sf->lb_token_prefix) == 0 - ? "" - : sf->lb_token_prefix + std::to_string(sf->port); + strlen(sf->lb_token_prefix) == 0 ? "" : sf->lb_token_prefix + + std::to_string(sf->port); GPR_ASSERT(contains_metadata(&request_metadata_recv, "lb-token", expected_token.c_str())); From cadabdf1f3985f5776d7aa3e588acea19c37ddcb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 8 Dec 2016 14:12:28 -0800 Subject: [PATCH 093/261] Fix include guards --- include/grpc++/impl/codegen/metadata_map.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/grpc++/impl/codegen/metadata_map.h b/include/grpc++/impl/codegen/metadata_map.h index fc2ed7d9e1a..53b9d62f9f9 100644 --- a/include/grpc++/impl/codegen/metadata_map.h +++ b/include/grpc++/impl/codegen/metadata_map.h @@ -31,8 +31,8 @@ * */ -#ifndef META_H -#define META_H +#ifndef GRPCXX_IMPL_CODEGEN_METADATA_MAP_H +#define GRPCXX_IMPL_CODEGEN_METADATA_MAP_H #include @@ -68,4 +68,4 @@ class MetadataMap { } // namespace grpc -#endif +#endif // GRPCXX_IMPL_CODEGEN_METADATA_MAP_H From 78bc54e7d9345a9af6db88a2264533d43ff57ea0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 8 Dec 2016 15:19:41 -0800 Subject: [PATCH 094/261] Fix stack corruption --- include/grpc++/impl/codegen/call.h | 5 +++-- include/grpc++/impl/codegen/server_interface.h | 1 - src/cpp/server/server_cc.cc | 3 +-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index 9165f4fd6c5..dd6c83a14ae 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -438,9 +438,9 @@ class CallOpServerSendStatus { trailing_metadata_count_; op->data.send_status_from_server.trailing_metadata = trailing_metadata_; op->data.send_status_from_server.status = send_status_code_; - grpc_slice status_details = SliceReferencingString(send_status_details_); + status_details_slice_ = SliceReferencingString(send_status_details_); op->data.send_status_from_server.status_details = - send_status_details_.empty() ? nullptr : &status_details; + send_status_details_.empty() ? nullptr : &status_details_slice_; op->flags = 0; op->reserved = NULL; } @@ -457,6 +457,7 @@ class CallOpServerSendStatus { grpc::string send_status_details_; size_t trailing_metadata_count_; grpc_metadata* trailing_metadata_; + grpc_slice status_details_slice_; }; class CallOpRecvInitialMetadata { diff --git a/include/grpc++/impl/codegen/server_interface.h b/include/grpc++/impl/codegen/server_interface.h index 666b9ff66eb..af1bf6fa6f7 100644 --- a/include/grpc++/impl/codegen/server_interface.h +++ b/include/grpc++/impl/codegen/server_interface.h @@ -152,7 +152,6 @@ class ServerInterface : public CallHook { void* const tag_; const bool delete_on_finalize_; grpc_call* call_; - grpc_metadata_array initial_metadata_array_; }; class RegisteredAsyncRequest : public BaseAsyncRequest { diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index 06fa4a85387..dcc56eecbce 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -576,7 +576,6 @@ ServerInterface::BaseAsyncRequest::BaseAsyncRequest( delete_on_finalize_(delete_on_finalize), call_(nullptr) { call_cq_->RegisterAvalanching(); // This op will trigger more ops - memset(&initial_metadata_array_, 0, sizeof(initial_metadata_array_)); } ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { @@ -627,7 +626,7 @@ ServerInterface::GenericAsyncRequest::GenericAsyncRequest( GPR_ASSERT(notification_cq); GPR_ASSERT(call_cq); grpc_server_request_call(server->server(), &call_, &call_details_, - &initial_metadata_array_, call_cq->cq(), + context->client_metadata_.arr(), call_cq->cq(), notification_cq->cq(), this); } From 3ba16e4f0562e32cfffb786c1d74e8e49bb5e6de Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 8 Dec 2016 16:46:18 -0800 Subject: [PATCH 095/261] Fix bug whereby errors on a call do not lead to cancellation --- src/core/lib/channel/http_client_filter.c | 13 +++-- src/core/lib/slice/slice.c | 2 + src/core/lib/surface/call.c | 59 ++++++++++++++--------- 3 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 31e9bde9d3a..33834adc1d1 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -103,11 +103,18 @@ static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } else { char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), GPR_DUMP_ASCII); + char *msg; + gpr_asprintf(&msg, "Received http2 header with status: %s", val); grpc_error *e = grpc_error_set_str( - GRPC_ERROR_CREATE( - "Received http2 :status header with non-200 OK status"), - GRPC_ERROR_STR_VALUE, val); + grpc_error_set_int( + grpc_error_set_str( + GRPC_ERROR_CREATE( + "Received http2 :status header with non-200 OK status"), + GRPC_ERROR_STR_VALUE, val), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_CANCELLED), + GRPC_ERROR_STR_GRPC_MESSAGE, msg); gpr_free(val); + gpr_free(msg); return e; } } diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index f0ad9f48814..e77be6fc145 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -436,6 +436,8 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { if (haystack_len == 0 || needle_len == 0) return -1; if (haystack_len < needle_len) return -1; + if (haystack_len == needle_len) + return grpc_slice_eq(haystack, needle) ? 0 : -1; if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes); const uint8_t *last = haystack_bytes + haystack_len - needle_len; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index acfa03384a8..439d17b3dba 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -219,6 +219,8 @@ static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); +static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_error *error); static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); @@ -698,11 +700,13 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *c, return r; } +typedef enum { TC_CANCEL, TC_CLOSE } termination_closure_type; + typedef struct termination_closure { grpc_closure closure; grpc_call *call; grpc_error *error; - enum { TC_CANCEL, TC_CLOSE } type; + termination_closure_type type; grpc_transport_stream_op op; } termination_closure; @@ -757,36 +761,43 @@ static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, return GRPC_CALL_OK; } -static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description) { - GPR_ASSERT(status != GRPC_STATUS_OK); +static grpc_call_error terminate_with_error(grpc_exec_ctx *exec_ctx, + grpc_call *c, + termination_closure_type tc_type, + grpc_error *error) { termination_closure *tc = gpr_malloc(sizeof(*tc)); - memset(tc, 0, sizeof(termination_closure)); - tc->type = TC_CANCEL; + memset(tc, 0, sizeof(*tc)); + tc->type = tc_type; tc->call = c; - tc->error = grpc_error_set_int( + tc->error = error; + return terminate_with_status(exec_ctx, tc); +} + +static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_error *error) { + terminate_with_error(exec_ctx, c, TC_CANCEL, error); +} + +static grpc_error *error_from_status(grpc_status_code status, + const char *description) { + return grpc_error_set_int( grpc_error_set_str(GRPC_ERROR_CREATE(description), GRPC_ERROR_STR_GRPC_MESSAGE, description), GRPC_ERROR_INT_GRPC_STATUS, status); +} - return terminate_with_status(exec_ctx, tc); +static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description) { + return terminate_with_error(exec_ctx, c, TC_CANCEL, + error_from_status(status, description)); } static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description) { - GPR_ASSERT(status != GRPC_STATUS_OK); - termination_closure *tc = gpr_malloc(sizeof(*tc)); - memset(tc, 0, sizeof(termination_closure)); - tc->type = TC_CLOSE; - tc->call = c; - tc->error = grpc_error_set_int( - grpc_error_set_str(GRPC_ERROR_CREATE(description), - GRPC_ERROR_STR_GRPC_MESSAGE, description), - GRPC_ERROR_INT_GRPC_STATUS, status); - - return terminate_with_status(exec_ctx, tc); + return terminate_with_error(exec_ctx, c, TC_CLOSE, + error_from_status(status, description)); } static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, @@ -1155,8 +1166,10 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, } } -static void add_batch_error(batch_control *bctl, grpc_error *error) { +static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, + grpc_error *error) { if (error == GRPC_ERROR_NONE) return; + cancel_with_error(exec_ctx, bctl->call, GRPC_ERROR_REF(error)); if (bctl->error == GRPC_ERROR_NONE) { bctl->error = GRPC_ERROR_CREATE("Call batch operation failed"); } @@ -1170,7 +1183,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&call->mu); - add_batch_error(bctl, GRPC_ERROR_REF(error)); + add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); if (error == GRPC_ERROR_NONE) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; @@ -1270,7 +1283,7 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, GRPC_ERROR_UNREF(error); error = GRPC_ERROR_NONE; } - add_batch_error(bctl, GRPC_ERROR_REF(error)); + add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); gpr_mu_unlock(&call->mu); if (gpr_unref(&bctl->steps_to_complete)) { post_batch_completion(exec_ctx, bctl); From 9e78d69fafd66334909f13cac1f3743a21c7ff55 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 8 Dec 2016 17:05:02 -0800 Subject: [PATCH 096/261] Start converting php --- src/php/ext/grpc/call.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 3a49ea87081..85fb994afda 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -100,11 +100,11 @@ zval *grpc_parse_metadata_array(grpc_metadata_array grpc_metadata *elem; for (i = 0; i < count; i++) { elem = &elements[i]; - key_len = strlen(elem->key); + key_len = GRPC_SLICE_LENGTH(elem->key); str_key = ecalloc(key_len + 1, sizeof(char)); - memcpy(str_key, elem->key, key_len); - str_val = ecalloc(elem->value_length + 1, sizeof(char)); - memcpy(str_val, elem->value, elem->value_length); + memcpy(str_key, GRPC_SLICE_START_PTR(elem->key), key_len); + str_val = ecalloc(GRPC_SLICE_LENGTH(elem->value) + 1, sizeof(char)); + memcpy(str_val, GRPC_SLICE_START_PTR(elem->value), GRPC_SLICE_LENGTH(elem->value)); if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data) == SUCCESS) { if (Z_TYPE_P(data) != IS_ARRAY) { @@ -115,13 +115,13 @@ zval *grpc_parse_metadata_array(grpc_metadata_array efree(str_val); return NULL; } - php_grpc_add_next_index_stringl(data, str_val, elem->value_length, + php_grpc_add_next_index_stringl(data, str_val, GRPC_SLICE_LENGTH(elem->value), false); } else { PHP_GRPC_MAKE_STD_ZVAL(inner_array); array_init(inner_array); php_grpc_add_next_index_stringl(inner_array, str_val, - elem->value_length, false); + GRPC_SLICE_LENGTH(elem->value), false); add_assoc_zval(array, str_key, inner_array); } } From 3bfb00486aee85081b34fe1391704fdf5207f384 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:29:19 -0800 Subject: [PATCH 097/261] Convert more of PHP --- src/php/ext/grpc/call.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 85fb994afda..1b963f2dbe6 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -164,7 +164,7 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { if (key_type1 != HASH_KEY_IS_STRING) { return false; } - if (!grpc_header_key_is_legal(key1, strlen(key1))) { + if (!grpc_header_key_is_legal(grpc_slice_from_static_string(key1))) { return false; } inner_array_hash = Z_ARRVAL_P(inner_array); @@ -172,9 +172,8 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { if (Z_TYPE_P(value) != IS_STRING) { return false; } - metadata->metadata[metadata->count].key = key1; - metadata->metadata[metadata->count].value = Z_STRVAL_P(value); - metadata->metadata[metadata->count].value_length = Z_STRLEN_P(value); + metadata->metadata[metadata->count].key = grpc_slice_from_copied_string(key1); + metadata->metadata[metadata->count].value = grpc_slice_from_copied_buffer(Z_STRVAL_P(value), Z_STRLEN_P(value)); metadata->count += 1; PHP_GRPC_HASH_FOREACH_END() PHP_GRPC_HASH_FOREACH_END() @@ -229,10 +228,15 @@ PHP_METHOD(Call, __construct) { } add_property_zval(getThis(), "channel", channel_obj); wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj); + grpc_slice method_slice = grpc_slice_from_copied_string(method); + grpc_slice host_slice = host_override != NULL ? + grpc_slice_from_copied_string(host_override) : grpc_empty_slice(); call->wrapped = grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS, - completion_queue, method, host_override, + completion_queue, method_slice, host_override != NULL ? &host_slice : NULL, deadline->wrapped, NULL); + grpc_slice_unref(method_slice); + grpc_slice_unref(host_slice); call->owned = true; } From a25cbbc885ac77c2a2923c678a1cd0b87b90ef0e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:32:10 -0800 Subject: [PATCH 098/261] Convert more of PHP --- src/php/ext/grpc/call.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 1b963f2dbe6..736738c8e05 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -271,8 +271,7 @@ PHP_METHOD(Call, startBatch) { grpc_metadata_array recv_metadata; grpc_metadata_array recv_trailing_metadata; grpc_status_code status; - char *status_details = NULL; - size_t status_details_capacity = 0; + grpc_slice status_details; grpc_byte_buffer *message; int cancelled; grpc_call_error error; @@ -384,8 +383,8 @@ PHP_METHOD(Call, startBatch) { 1 TSRMLS_CC); goto cleanup; } - ops[op_num].data.send_status_from_server.status_details = - Z_STRVAL_P(inner_value); + grpc_slice send_status_details = grpc_slice_from_copied_string(Z_STRVAL_P(inner_value)); + ops[op_num].data.send_status_from_server.status_details = &send_status_details; } else { zend_throw_exception(spl_ce_InvalidArgumentException, "String status details is required", @@ -405,8 +404,6 @@ PHP_METHOD(Call, startBatch) { ops[op_num].data.recv_status_on_client.status = &status; ops[op_num].data.recv_status_on_client.status_details = &status_details; - ops[op_num].data.recv_status_on_client.status_details_capacity = - &status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: ops[op_num].data.recv_close_on_server.cancelled = &cancelled; From 75f8013ba65f5008660c8483800f325d0c1b80a9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:34:28 -0800 Subject: [PATCH 099/261] Continue updating PHP --- src/php/ext/grpc/call.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 736738c8e05..d679ae15453 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -475,8 +475,10 @@ PHP_METHOD(Call, startBatch) { #endif PHP_GRPC_DELREF(array); add_property_long(recv_status, "code", status); - php_grpc_add_property_string(recv_status, "details", status_details, + char *status_details_text = grpc_dump_slice(status_details, GPR_DUMP_ASCII); + php_grpc_add_property_string(recv_status, "details", status_details_text, true); + gpr_free(status_details_text); add_property_zval(result, "status", recv_status); PHP_GRPC_DELREF(recv_status); break; From b4aa70ea94687f41c731e57f9782c51c5dacf779 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:40:11 -0800 Subject: [PATCH 100/261] Offer grpc_slice_to_c_string to simplify some code --- include/grpc/slice.h | 4 +++ src/core/ext/lb_policy/grpclb/grpclb.c | 2 +- .../ext/resolver/sockaddr/sockaddr_resolver.c | 2 +- .../transport/chttp2/transport/bin_decoder.c | 4 +-- .../chttp2/transport/chttp2_transport.c | 4 +-- .../chttp2/transport/hpack_encoder.c | 4 +-- .../transport/chttp2/transport/hpack_parser.c | 4 +-- .../ext/transport/chttp2/transport/parsing.c | 6 ++-- .../cronet/transport/cronet_transport.c | 4 +-- src/core/lib/channel/compress_filter.c | 4 +-- .../credentials/plugin/plugin_credentials.c | 2 +- .../security/transport/client_auth_filter.c | 10 +++---- src/core/lib/slice/slice.c | 7 +++++ src/core/lib/surface/call.c | 6 ++-- src/core/lib/surface/call_log_batch.c | 2 +- src/core/lib/transport/metadata.c | 28 +++++++++---------- src/core/lib/transport/metadata_batch.c | 4 +-- src/core/lib/transport/service_config.c | 2 +- src/core/lib/transport/transport.c | 4 +-- src/php/ext/grpc/call.c | 2 +- .../set_initial_connect_string_test.c | 2 +- test/core/end2end/dualstack_socket_test.c | 2 +- test/core/end2end/fake_resolver.c | 2 +- .../print_google_default_creds_token.c | 2 +- test/core/security/security_connector_test.c | 6 ++-- 25 files changed, 65 insertions(+), 54 deletions(-) diff --git a/include/grpc/slice.h b/include/grpc/slice.h index 73d1fa43ec0..ea66e094e98 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -157,6 +157,10 @@ GPRAPI int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b); * as \a s */ GPRAPI grpc_slice grpc_slice_dup(grpc_slice a); +/* Return a copy of slice as a C string. Offers no protection against embedded + NULL's. Returned string must be freed with gpr_free. */ +GPRAPI char *grpc_slice_to_c_string(grpc_slice s); + #ifdef __cplusplus } #endif diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 9e35dde07ca..033f6726e75 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -1323,7 +1323,7 @@ static void lb_on_server_status_received(grpc_exec_ctx *exec_ctx, void *arg, if (grpc_lb_glb_trace) { char *status_details = - grpc_dump_slice(glb_policy->lb_call_status_details, GPR_DUMP_ASCII); + grpc_slice_to_c_string(glb_policy->lb_call_status_details); gpr_log(GPR_DEBUG, "Status from LB server received. Status = %d, Details = '%s', " "(call: %p)", diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index 55f8c071f2f..63180ab3c37 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -182,7 +182,7 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; - char *part_str = grpc_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII); + char *part_str = grpc_slice_to_c_string(path_parts.slices[i]); ith_uri.path = part_str; if (!parse(&ith_uri, &addresses->addresses[i].address)) { errors_found = true; /* GPR_TRUE */ diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.c b/src/core/ext/transport/chttp2/transport/bin_decoder.c index 1a3637a1e3e..8c87de112eb 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.c +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.c @@ -178,7 +178,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, ctx.contains_tail = false; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); + char *s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); @@ -224,7 +224,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, ctx.contains_tail = true; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); + char *s = grpc_slice_to_c_string(input); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index e35c275f1ef..6563b42a60f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -983,8 +983,8 @@ static void log_metadata(const grpc_metadata_batch *md_batch, uint32_t id, bool is_client, bool is_initial) { for (grpc_linked_mdelem *md = md_batch->list.head; md != md_batch->list.tail; md = md->next) { - char *key = grpc_dump_slice(GRPC_MDKEY(md->md), GPR_DUMP_ASCII); - char *value = grpc_dump_slice(GRPC_MDVALUE(md->md), GPR_DUMP_ASCII); + char *key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); + char *value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); gpr_log(GPR_INFO, "HTTP:%d:%s:%s: %s: %s", id, is_initial ? "HDR" : "TRL", is_client ? "CLI" : "SVR", key, value); gpr_free(key); diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 2eb0c51bdc4..ae2055bc3e9 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -397,8 +397,8 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, } if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(elem)) { - char *k = grpc_dump_slice(GRPC_MDKEY(elem), GPR_DUMP_ASCII); - char *v = grpc_dump_slice(GRPC_MDVALUE(elem), GPR_DUMP_ASCII); + char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); + char *v = grpc_slice_to_c_string(GRPC_MDVALUE(elem)); gpr_log( GPR_DEBUG, "Encode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 9b85026b136..3c7d5e83104 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -674,8 +674,8 @@ static const uint8_t inverse_base64[256] = { static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, grpc_mdelem md, int add_to_table) { if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(md)) { - char *k = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); - char *v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); + char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log( GPR_DEBUG, "Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index b002710be33..c5a99e54241 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -453,7 +453,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); if (grpc_http_trace) { - char *key = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); + char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, @@ -475,7 +475,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, /* not already parsed: parse it now, and store the result away */ cached_timeout = gpr_malloc(sizeof(gpr_timespec)); if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), cached_timeout)) { - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); gpr_free(val); *cached_timeout = gpr_inf_future(GPR_TIMESPAN); @@ -525,7 +525,7 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); if (grpc_http_trace) { - char *key = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); + char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); char *value = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 301bdc5c624..c45c653247f 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -626,8 +626,8 @@ static void convert_metadata_to_cronet_headers( while (num_headers < num_headers_available) { grpc_mdelem mdelem = curr->md; curr = curr->next; - char *key = grpc_dump_slice(GRPC_MDKEY(mdelem), GPR_DUMP_ASCII); - char *value = grpc_dump_slice(GRPC_MDVALUE(mdelem), GPR_DUMP_ASCII); + char *key = grpc_slice_to_c_string(GRPC_MDKEY(mdelem)); + char *value = grpc_slice_to_c_string(GRPC_MDVALUE(mdelem)); if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_SCHEME) || grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_AUTHORITY)) { /* Cronet populates these fields on its own */ diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 330688c29cf..3347b5facb8 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -115,7 +115,7 @@ static grpc_error *process_send_initial_metadata( initial_metadata->idx.named.grpc_internal_encoding_request->md; if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), &calld->compression_algorithm)) { - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); gpr_free(val); @@ -123,7 +123,7 @@ static grpc_error *process_send_initial_metadata( } if (!GPR_BITGET(channeld->enabled_algorithms_bitset, calld->compression_algorithm)) { - char *val = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s' (previously disabled). " "Ignoring.", diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index 66e501cffc3..f98c9cd8ef2 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -79,7 +79,7 @@ static void plugin_md_request_metadata_ready(void *request, grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { if (!grpc_header_key_is_legal(md[i].key)) { - char *key = grpc_dump_slice(md[i].key, GPR_DUMP_ASCII); + char *key = grpc_slice_to_c_string(md[i].key); gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", key); gpr_free(key); seen_illegal_header = true; diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index d8540b96253..8852412d61d 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -134,7 +134,7 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error = GRPC_ERROR_NONE; for (i = 0; i < num_md; i++) { if (!grpc_header_key_is_legal(md_elems[i].key)) { - char *str = grpc_dump_slice(md_elems[i].key, GPR_DUMP_ASCII); + char *str = grpc_slice_to_c_string(md_elems[i].key); gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); } else if (!grpc_is_binary_header(md_elems[i].key) && @@ -162,7 +162,7 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, void build_auth_metadata_context(grpc_security_connector *sc, grpc_auth_context *auth_context, call_data *calld) { - char *service = grpc_dump_slice(calld->method, GPR_DUMP_ASCII); + char *service = grpc_slice_to_c_string(calld->method); char *last_slash = strrchr(service, '/'); char *method_name = NULL; char *service_url = NULL; @@ -178,7 +178,7 @@ void build_auth_metadata_context(grpc_security_connector *sc, method_name = gpr_strdup(last_slash + 1); } if (method_name == NULL) method_name = gpr_strdup(""); - char *host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); + char *host = grpc_slice_to_c_string(calld->host); gpr_asprintf(&service_url, "%s://%s%s", sc->url_scheme == NULL ? "" : sc->url_scheme, host, service); calld->auth_md_context.service_url = service_url; @@ -237,7 +237,7 @@ static void on_host_checked(grpc_exec_ctx *exec_ctx, void *user_data, send_security_metadata(exec_ctx, elem, &calld->op); } else { char *error_msg; - char *host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); + char *host = grpc_slice_to_c_string(calld->host); gpr_asprintf(&error_msg, "Invalid host %s set in :authority metadata.", host); gpr_free(host); @@ -297,7 +297,7 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx, } } if (calld->have_host) { - char *call_host = grpc_dump_slice(calld->host, GPR_DUMP_ASCII); + char *call_host = grpc_slice_to_c_string(calld->host); calld->op = *op; /* Copy op (originates from the caller's stack). */ grpc_channel_security_connector_check_call_host( exec_ctx, chand->security_connector, call_host, chand->auth_context, diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index e77be6fc145..1cddf062cd4 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -41,6 +41,13 @@ #include "src/core/lib/iomgr/exec_ctx.h" +char *grpc_slice_to_c_string(grpc_slice slice) { + char *out = gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1); + memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); + out[GRPC_SLICE_LENGTH(slice)] = 0; + return out; +} + grpc_slice grpc_empty_slice(void) { grpc_slice out; out.refcount = NULL; diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 439d17b3dba..366dd98279b 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -532,7 +532,7 @@ static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, GPR_BITSET(&call->encodings_accepted_by_peer, algorithm); } else { char *accept_encoding_entry_str = - grpc_dump_slice(accept_encoding_entry_slice, GPR_DUMP_ASCII); + grpc_slice_to_c_string(accept_encoding_entry_slice); gpr_log(GPR_ERROR, "Invalid entry in accept encoding metadata: '%s'. Ignoring.", accept_encoding_entry_str); @@ -599,7 +599,7 @@ static int prepare_application_metadata( grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); if (!grpc_header_key_is_legal(md->key)) { - char *str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); + char *str = grpc_slice_to_c_string(md->key); gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); gpr_free(str); break; @@ -860,7 +860,7 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem md) { grpc_compression_algorithm algorithm = grpc_compression_algorithm_from_slice(GRPC_MDVALUE(md)); if (algorithm == GRPC_COMPRESS_ALGORITHMS_COUNT) { - char *md_c_str = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *md_c_str = grpc_slice_to_c_string(GRPC_MDVALUE(md)); gpr_log(GPR_ERROR, "Invalid incoming compression algorithm: '%s'. Interpreting " "incoming data as uncompressed.", diff --git a/src/core/lib/surface/call_log_batch.c b/src/core/lib/surface/call_log_batch.c index 169e9673410..7fc58e19c29 100644 --- a/src/core/lib/surface/call_log_batch.c +++ b/src/core/lib/surface/call_log_batch.c @@ -46,7 +46,7 @@ static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) { } for (i = 0; i < count; i++) { gpr_strvec_add(b, gpr_strdup("\nkey=")); - gpr_strvec_add(b, grpc_dump_slice(md[i].key, GPR_DUMP_ASCII)); + gpr_strvec_add(b, grpc_slice_to_c_string(md[i].key)); gpr_strvec_add(b, gpr_strdup(" value=")); gpr_strvec_add(b, diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 06e703c9d96..489c20cbc82 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -161,8 +161,8 @@ static int is_mdelem_static(grpc_mdelem e) { static void ref_md_locked(mdtab_shard *shard, interned_metadata *md DEBUG_ARGS) { #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), @@ -261,8 +261,8 @@ grpc_mdelem grpc_mdelem_create( allocated->value = grpc_slice_ref_internal(value); gpr_atm_rel_store(&allocated->refcnt, 1); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(allocated->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(allocated->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(allocated->key); + char *value_str = grpc_slice_to_c_string(allocated->value); gpr_log(GPR_DEBUG, "ELM ALLOC:%p:%zu: '%s' = '%s'", (void *)allocated, gpr_atm_no_barrier_load(&allocated->refcnt), key_str, value_str); gpr_free(key_str); @@ -312,8 +312,8 @@ grpc_mdelem grpc_mdelem_create( shard->elems[idx] = md; gpr_mu_init(&md->mu_user_data); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(GPR_DEBUG, "ELM NEW:%p:%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), key_str, value_str); gpr_free(key_str); @@ -374,8 +374,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), @@ -394,8 +394,8 @@ grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), @@ -422,8 +422,8 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_INTERNED: { interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), @@ -446,8 +446,8 @@ void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { case GRPC_MDELEM_STORAGE_ALLOCATED: { allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_dump_slice(md->key, GPR_DUMP_ASCII); - char *value_str = grpc_dump_slice(md->value, GPR_DUMP_ASCII); + char *key_str = grpc_slice_to_c_string(md->key); + char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 07b0dd37256..18b0f161ab5 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -99,8 +99,8 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, } grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md) { - char *k = grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_ASCII); - char *v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_ASCII); + char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); + char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); grpc_error *out = grpc_error_set_str( grpc_error_set_str(src, GRPC_ERROR_STR_KEY, k), GRPC_ERROR_STR_VALUE, v); gpr_free(k); diff --git a/src/core/lib/transport/service_config.c b/src/core/lib/transport/service_config.c index 8073a46105f..12da2a88feb 100644 --- a/src/core/lib/transport/service_config.c +++ b/src/core/lib/transport/service_config.c @@ -237,7 +237,7 @@ void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, // 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) { - char* path_str = grpc_dump_slice(path, GPR_DUMP_ASCII); + char* path_str = grpc_slice_to_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 diff --git a/src/core/lib/transport/transport.c b/src/core/lib/transport/transport.c index 9bc278c1334..9ccd7daf454 100644 --- a/src/core/lib/transport/transport.c +++ b/src/core/lib/transport/transport.c @@ -224,7 +224,7 @@ void grpc_transport_stream_op_add_cancellation_with_message( } grpc_error *error; if (optional_message != NULL) { - char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII); + char *msg = grpc_slice_to_c_string(*optional_message); error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), GRPC_ERROR_STR_GRPC_MESSAGE, msg); gpr_free(msg); @@ -250,7 +250,7 @@ void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx, } grpc_error *error; if (optional_message != NULL) { - char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII); + char *msg = grpc_slice_to_c_string(*optional_message); error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), GRPC_ERROR_STR_GRPC_MESSAGE, msg); gpr_free(msg); diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index d679ae15453..aaf34bd99b8 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -475,7 +475,7 @@ PHP_METHOD(Call, startBatch) { #endif PHP_GRPC_DELREF(array); add_property_long(recv_status, "code", status); - char *status_details_text = grpc_dump_slice(status_details, GPR_DUMP_ASCII); + char *status_details_text = grpc_slice_to_c_string(status_details); php_grpc_add_property_string(recv_status, "details", status_details_text, true); gpr_free(status_details_text); diff --git a/test/core/client_channel/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c index e816347123d..dc470ec6627 100644 --- a/test/core/client_channel/set_initial_connect_string_test.c +++ b/test/core/client_channel/set_initial_connect_string_test.c @@ -209,7 +209,7 @@ static void match_initial_magic_string(grpc_slice_buffer *buffer) { GPR_ASSERT(buffer->length >= magic_length); for (i = 0, j = 0; i < state.incoming_buffer.count && j < magic_length; i++) { char *dump = - grpc_dump_slice(state.incoming_buffer.slices[i], GPR_DUMP_ASCII); + grpc_slice_to_c_string(state.incoming_buffer.slices[i]); cmp_length = GPR_MIN(strlen(dump), magic_length - j); GPR_ASSERT(strncmp(dump, magic_connect_string + j, cmp_length) == 0); j += cmp_length; diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index 76d2747c9cf..9cd07071746 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -134,7 +134,7 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_slice_split(uri_slice, ",", &uri_parts); hosts_with_port = gpr_malloc(sizeof(char *) * uri_parts.count); for (i = 0; i < uri_parts.count; i++) { - char *uri_part_str = grpc_dump_slice(uri_parts.slices[i], GPR_DUMP_ASCII); + char *uri_part_str = grpc_slice_to_c_string(uri_parts.slices[i]); gpr_asprintf(&hosts_with_port[i], "%s:%d", uri_part_str, port); gpr_free(uri_part_str); } diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 55a42b8fa38..185c915e4b0 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -165,7 +165,7 @@ static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx, bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; - char* part_str = grpc_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII); + char* part_str = grpc_slice_to_c_string(path_parts.slices[i]); ith_uri.path = part_str; if (!parse_ipv4(&ith_uri, &addresses->addresses[i].address)) { errors_found = true; diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index 2b74690bc3f..ea136fbdcf6 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -63,7 +63,7 @@ static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *user_data, } else { char *token; GPR_ASSERT(num_md == 1); - token = grpc_dump_slice(md_elems[0].value, GPR_DUMP_ASCII); + token = grpc_slice_to_c_string(md_elems[0].value); printf("\nGot token: %s\n\n", token); gpr_free(token); } diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c index 8872cbe278f..4219b134f25 100644 --- a/test/core/security/security_connector_test.c +++ b/test/core/security/security_connector_test.c @@ -370,7 +370,7 @@ static void test_default_ssl_roots(void) { gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); grpc_set_ssl_roots_override_callback(override_roots_success); grpc_slice roots = grpc_get_default_ssl_roots_for_testing(); - char *roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); + char *roots_contents = grpc_slice_to_c_string(roots); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); gpr_free(roots_contents); @@ -379,7 +379,7 @@ static void test_default_ssl_roots(void) { instead. */ gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_env_var_file_path); roots = grpc_get_default_ssl_roots_for_testing(); - roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); + roots_contents = grpc_slice_to_c_string(roots); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_env_var) == 0); gpr_free(roots_contents); @@ -388,7 +388,7 @@ static void test_default_ssl_roots(void) { the api. */ gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); roots = grpc_get_default_ssl_roots_for_testing(); - roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); + roots_contents = grpc_slice_to_c_string(roots); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); gpr_free(roots_contents); From d2b00144306610654c0ea4d0ef8ed163e0dfb150 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:42:38 -0800 Subject: [PATCH 101/261] Continue updating PHP --- src/php/ext/grpc/call.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index aaf34bd99b8..95ca6a6f3dd 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -271,7 +271,8 @@ PHP_METHOD(Call, startBatch) { grpc_metadata_array recv_metadata; grpc_metadata_array recv_trailing_metadata; grpc_status_code status; - grpc_slice status_details; + grpc_slice recv_status_details = grpc_empty_slice(); + grpc_slice send_status_details = grpc_empty_slice(); grpc_byte_buffer *message; int cancelled; grpc_call_error error; @@ -383,7 +384,7 @@ PHP_METHOD(Call, startBatch) { 1 TSRMLS_CC); goto cleanup; } - grpc_slice send_status_details = grpc_slice_from_copied_string(Z_STRVAL_P(inner_value)); + send_status_details = grpc_slice_from_copied_string(Z_STRVAL_P(inner_value)); ops[op_num].data.send_status_from_server.status_details = &send_status_details; } else { zend_throw_exception(spl_ce_InvalidArgumentException, @@ -403,7 +404,7 @@ PHP_METHOD(Call, startBatch) { &recv_trailing_metadata; ops[op_num].data.recv_status_on_client.status = &status; ops[op_num].data.recv_status_on_client.status_details = - &status_details; + &recv_status_details; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: ops[op_num].data.recv_close_on_server.cancelled = &cancelled; @@ -475,7 +476,7 @@ PHP_METHOD(Call, startBatch) { #endif PHP_GRPC_DELREF(array); add_property_long(recv_status, "code", status); - char *status_details_text = grpc_slice_to_c_string(status_details); + char *status_details_text = grpc_slice_to_c_string(recv_status_details); php_grpc_add_property_string(recv_status, "details", status_details_text, true); gpr_free(status_details_text); @@ -495,9 +496,8 @@ cleanup: grpc_metadata_array_destroy(&trailing_metadata); grpc_metadata_array_destroy(&recv_metadata); grpc_metadata_array_destroy(&recv_trailing_metadata); - if (status_details != NULL) { - gpr_free(status_details); - } + grpc_slice_unref(recv_status_details); + grpc_slice_unref(send_status_details); for (int i = 0; i < op_num; i++) { if (ops[i].op == GRPC_OP_SEND_MESSAGE) { grpc_byte_buffer_destroy(ops[i].data.send_message); From cdfd15cc1ae1f016269a41bc509b38e9f560b434 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:44:30 -0800 Subject: [PATCH 102/261] Continue updating PHP --- src/php/ext/grpc/server.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 2217a4f9a81..adcc982e593 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -149,8 +149,12 @@ PHP_METHOD(Server, requestCall) { 1 TSRMLS_CC); goto cleanup; } - php_grpc_add_property_string(result, "method", details.method, true); - php_grpc_add_property_string(result, "host", details.host, true); + char *method_text = grpc_slice_as_c_string(details.method); + char *host_text = grpc_slice_as_c_string(details.host); + php_grpc_add_property_string(result, "method", method_text, true); + php_grpc_add_property_string(result, "host", host_text, true); + gpr_free(method_text); + gpr_free(host_text); #if PHP_MAJOR_VERSION < 7 add_property_zval(result, "call", grpc_php_wrap_call(call, true TSRMLS_CC)); add_property_zval(result, "absolute_deadline", From 7a454c24d90beb5f2b39522a78289909032b834c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:45:23 -0800 Subject: [PATCH 103/261] Continue updating PHP --- src/php/ext/grpc/server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index adcc982e593..6f8e1e4cd80 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -49,6 +49,7 @@ #include #include +#include #include "completion_queue.h" #include "server.h" From 9e11a98eb497de93e124714a354cf0995f1fbd87 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:46:08 -0800 Subject: [PATCH 104/261] Continue updating PHP --- src/php/ext/grpc/server.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 6f8e1e4cd80..55a61e2b448 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -150,8 +150,8 @@ PHP_METHOD(Server, requestCall) { 1 TSRMLS_CC); goto cleanup; } - char *method_text = grpc_slice_as_c_string(details.method); - char *host_text = grpc_slice_as_c_string(details.host); + char *method_text = grpc_slice_to_c_string(details.method); + char *host_text = grpc_slice_to_c_string(details.host); php_grpc_add_property_string(result, "method", method_text, true); php_grpc_add_property_string(result, "host", host_text, true); gpr_free(method_text); From e2e4670e09f0f7f7aff60eac0c6aabfea23a34bd Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:46:51 -0800 Subject: [PATCH 105/261] Continue updating PHP --- src/php/ext/grpc/server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 55a61e2b448..9ac5d2a3c39 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -50,6 +50,7 @@ #include #include #include +#include #include "completion_queue.h" #include "server.h" From 1bcdf17c11721bce69fb383940dc623eef81fc7b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:50:49 -0800 Subject: [PATCH 106/261] Continue updating C# --- src/csharp/ext/grpc_csharp_ext.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 946f5872c0e..ee1fe0b494f 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -122,8 +122,8 @@ void grpcsharp_metadata_array_destroy_metadata_including_entries( size_t i; if (array->metadata) { for (i = 0; i < array->count; i++) { - gpr_free((void *)array->metadata[i].key); - gpr_free((void *)array->metadata[i].value); + grpc_slice_unref(array->metadata[i].key); + grpc_slice_unref(array->metadata[i].value); } } gpr_free(array->metadata); @@ -167,10 +167,8 @@ grpcsharp_metadata_array_add(grpc_metadata_array *array, const char *key, const char *value, size_t value_length) { size_t i = array->count; GPR_ASSERT(array->count < array->capacity); - array->metadata[i].key = gpr_strdup(key); - array->metadata[i].value = (char *)gpr_malloc(value_length); - memcpy((void *)array->metadata[i].value, value, value_length); - array->metadata[i].value_length = value_length; + array->metadata[i].key = grpc_slice_from_copied_string(key); + array->metadata[i].value = grpc_slice_from_copied_buffer(value, value_length); array->count++; } From b9a5e073731d819091da4a783191a6a220db3a67 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 09:53:49 -0800 Subject: [PATCH 107/261] Continue updating C# --- src/csharp/ext/grpc_csharp_ext.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index ee1fe0b494f..618522a3b50 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -402,8 +402,10 @@ grpcsharp_channel_create_call(grpc_channel *channel, grpc_call *parent_call, grpc_completion_queue *cq, const char *method, const char *host, gpr_timespec deadline) { - return grpc_channel_create_call(channel, parent_call, propagation_mask, cq, - method, host, deadline, NULL); + grpc_slice method_slice = grpc_slice_from_copied_string(method); + grpc_slice host_slice = host == NULL ? grpc_empty_string() : grpc_slice_from_copied_string(host); + grpc_call *grpc_channel_create_call(channel, parent_call, propagation_mask, cq, + method_slice, host_slice, deadline, NULL); } GPR_EXPORT grpc_connectivity_state GPR_CALLTYPE From 9e90d22ab7e429f23f740ae56445910678642e75 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 12:36:39 -0800 Subject: [PATCH 108/261] Fixes --- test/core/client_channel/set_initial_connect_string_test.c | 3 +-- test/cpp/test/server_context_test_spouse_test.cc | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/test/core/client_channel/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c index dc470ec6627..5c56d19eb0d 100644 --- a/test/core/client_channel/set_initial_connect_string_test.c +++ b/test/core/client_channel/set_initial_connect_string_test.c @@ -208,8 +208,7 @@ static void match_initial_magic_string(grpc_slice_buffer *buffer) { size_t magic_length = strlen(magic_connect_string); GPR_ASSERT(buffer->length >= magic_length); for (i = 0, j = 0; i < state.incoming_buffer.count && j < magic_length; i++) { - char *dump = - grpc_slice_to_c_string(state.incoming_buffer.slices[i]); + char *dump = grpc_slice_to_c_string(state.incoming_buffer.slices[i]); cmp_length = GPR_MIN(strlen(dump), magic_length - j); GPR_ASSERT(strncmp(dump, magic_connect_string + j, cmp_length) == 0); j += cmp_length; diff --git a/test/cpp/test/server_context_test_spouse_test.cc b/test/cpp/test/server_context_test_spouse_test.cc index e0d6a2ff67a..eb279e2401b 100644 --- a/test/cpp/test/server_context_test_spouse_test.cc +++ b/test/cpp/test/server_context_test_spouse_test.cc @@ -36,11 +36,14 @@ #include #include +#include #include namespace grpc { namespace testing { +static internal::GrpcLibraryInitializer g_initializer; + const char key1[] = "metadata-key1"; const char key2[] = "metadata-key2"; const char val1[] = "metadata-val1"; From 69153e020d1975b93d78df6fc4d1c47e2ed7eb5e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 15:56:50 -0800 Subject: [PATCH 109/261] Fix memory leak --- src/core/lib/surface/server.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 72ec48f4d9e..ddcd8265cdd 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -765,12 +765,14 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, if (calld->host_set && calld->path_set) { /* do nothing */ } else { - GRPC_ERROR_UNREF(error); + grpc_error *src_error = error; error = GRPC_ERROR_CREATE_REFERENCING("Missing :authority or :path", &error, 1); + GRPC_ERROR_UNREF(src_error); } grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error); + GRPC_ERROR_UNREF(error); } static void server_mutate_op(grpc_call_element *elem, From 58a81ac72314940d04ddb1e49c9b18e75d306f83 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 9 Dec 2016 16:10:08 -0800 Subject: [PATCH 110/261] Undo bogus commit --- src/core/lib/surface/server.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index ddcd8265cdd..6af5947f935 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -772,7 +772,6 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, } grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error); - GRPC_ERROR_UNREF(error); } static void server_mutate_op(grpc_call_element *elem, From 4d2ea021296697ade62457386ab36bafa8e7c5c4 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 12 Dec 2016 07:12:27 -0800 Subject: [PATCH 111/261] Revert "Revert "Revert "Revert "Remove redundant includes from string.h and tmpfile.h"""" --- BUILD | 9 ++ CMakeLists.txt | 7 ++ Makefile | 9 ++ build.yaml | 1 + gRPC-Core.podspec | 2 + grpc.gemspec | 2 + include/grpc/impl/codegen/gpr_slice.h | 84 +++++++++++++++++++ include/grpc/impl/codegen/slice.h | 20 +++++ package.xml | 2 + src/core/lib/support/string.h | 2 - src/core/lib/support/tmpfile.h | 2 - .../core/surface/public_headers_must_be_c89.c | 1 + tools/doxygen/Doxyfile.c++ | 1 + tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core | 2 + tools/doxygen/Doxyfile.core.internal | 2 + tools/run_tests/sources_and_headers.json | 2 + vsprojects/vcxproj/gpr/gpr.vcxproj | 1 + vsprojects/vcxproj/gpr/gpr.vcxproj.filters | 3 + vsprojects/vcxproj/grpc++/grpc++.vcxproj | 1 + .../vcxproj/grpc++/grpc++.vcxproj.filters | 3 + .../grpc++_test_util/grpc++_test_util.vcxproj | 1 + .../grpc++_test_util.vcxproj.filters | 3 + .../grpc++_unsecure/grpc++_unsecure.vcxproj | 1 + .../grpc++_unsecure.vcxproj.filters | 3 + vsprojects/vcxproj/grpc/grpc.vcxproj | 1 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 3 + .../grpc_test_util/grpc_test_util.vcxproj | 1 + .../grpc_test_util.vcxproj.filters | 3 + .../grpc_unsecure/grpc_unsecure.vcxproj | 1 + .../grpc_unsecure.vcxproj.filters | 3 + .../codegen_test_full.vcxproj | 1 + .../codegen_test_full.vcxproj.filters | 3 + .../codegen_test_minimal.vcxproj | 1 + .../codegen_test_minimal.vcxproj.filters | 3 + .../grpc_tool_test/grpc_tool_test.vcxproj | 1 + .../grpc_tool_test.vcxproj.filters | 3 + 37 files changed, 185 insertions(+), 4 deletions(-) create mode 100644 include/grpc/impl/codegen/gpr_slice.h diff --git a/BUILD b/BUILD index ab0fc237b78..fb81cf65fc2 100644 --- a/BUILD +++ b/BUILD @@ -135,6 +135,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -564,6 +565,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -960,6 +962,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -1341,6 +1344,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -1496,6 +1500,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -1958,6 +1963,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -2134,6 +2140,7 @@ cc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -2296,6 +2303,7 @@ objc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -2562,6 +2570,7 @@ objc_library( "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", diff --git a/CMakeLists.txt b/CMakeLists.txt index ff0927504aa..16e5d62de2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -258,6 +258,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -537,6 +538,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -788,6 +790,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -1039,6 +1042,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -1202,6 +1206,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -1535,6 +1540,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h @@ -1741,6 +1747,7 @@ foreach(_hdr include/grpc/impl/codegen/atm_gcc_atomic.h include/grpc/impl/codegen/atm_gcc_sync.h include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h include/grpc/impl/codegen/gpr_types.h include/grpc/impl/codegen/port_platform.h include/grpc/impl/codegen/slice.h diff --git a/Makefile b/Makefile index 8f7328ae285..eae4f46e701 100644 --- a/Makefile +++ b/Makefile @@ -2552,6 +2552,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -2859,6 +2860,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -3129,6 +3131,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -3345,6 +3348,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -3635,6 +3639,7 @@ PUBLIC_HEADERS_C += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -3879,6 +3884,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -4241,6 +4247,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -4596,6 +4603,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -4774,6 +4782,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ + include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ diff --git a/build.yaml b/build.yaml index de9d253ef1c..2555abce0c6 100644 --- a/build.yaml +++ b/build.yaml @@ -144,6 +144,7 @@ filegroups: - include/grpc/impl/codegen/atm_gcc_atomic.h - include/grpc/impl/codegen/atm_gcc_sync.h - include/grpc/impl/codegen/atm_windows.h + - include/grpc/impl/codegen/gpr_slice.h - include/grpc/impl/codegen/gpr_types.h - include/grpc/impl/codegen/port_platform.h - include/grpc/impl/codegen/slice.h diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 04f7211d210..f9e0164bdca 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -146,6 +146,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/codegen/atm_gcc_atomic.h', 'include/grpc/impl/codegen/atm_gcc_sync.h', 'include/grpc/impl/codegen/atm_windows.h', + 'include/grpc/impl/codegen/gpr_slice.h', 'include/grpc/impl/codegen/gpr_types.h', 'include/grpc/impl/codegen/port_platform.h', 'include/grpc/impl/codegen/slice.h', @@ -172,6 +173,7 @@ Pod::Spec.new do |s| 'include/grpc/impl/codegen/atm_gcc_atomic.h', 'include/grpc/impl/codegen/atm_gcc_sync.h', 'include/grpc/impl/codegen/atm_windows.h', + 'include/grpc/impl/codegen/gpr_slice.h', 'include/grpc/impl/codegen/gpr_types.h', 'include/grpc/impl/codegen/port_platform.h', 'include/grpc/impl/codegen/slice.h', diff --git a/grpc.gemspec b/grpc.gemspec index 6019b97f672..9c9568ce64d 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -73,6 +73,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/codegen/atm_gcc_atomic.h ) s.files += %w( include/grpc/impl/codegen/atm_gcc_sync.h ) s.files += %w( include/grpc/impl/codegen/atm_windows.h ) + s.files += %w( include/grpc/impl/codegen/gpr_slice.h ) s.files += %w( include/grpc/impl/codegen/gpr_types.h ) s.files += %w( include/grpc/impl/codegen/port_platform.h ) s.files += %w( include/grpc/impl/codegen/slice.h ) @@ -155,6 +156,7 @@ Gem::Specification.new do |s| s.files += %w( include/grpc/impl/codegen/atm_gcc_atomic.h ) s.files += %w( include/grpc/impl/codegen/atm_gcc_sync.h ) s.files += %w( include/grpc/impl/codegen/atm_windows.h ) + s.files += %w( include/grpc/impl/codegen/gpr_slice.h ) s.files += %w( include/grpc/impl/codegen/gpr_types.h ) s.files += %w( include/grpc/impl/codegen/port_platform.h ) s.files += %w( include/grpc/impl/codegen/slice.h ) diff --git a/include/grpc/impl/codegen/gpr_slice.h b/include/grpc/impl/codegen/gpr_slice.h new file mode 100644 index 00000000000..c62e976b8f4 --- /dev/null +++ b/include/grpc/impl/codegen/gpr_slice.h @@ -0,0 +1,84 @@ +/* + * + * 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_IMPL_CODEGEN_GPR_SLICE_H +#define GRPC_IMPL_CODEGEN_GPR_SLICE_H + +/* WARNING: Please do not use this header. This was added as a temporary measure + * to not break some of the external projects that depend on gpr_slice_* + * functions. We are actively working on moving all the gpr_slice_* references + * to grpc_slice_* and this file will be removed + * */ + +/* TODO (sreek) - Allowed by default but will be very soon turned off */ +#define GRPC_ALLOW_GPR_SLICE_FUNCTIONS 1 + +#ifdef GRPC_ALLOW_GPR_SLICE_FUNCTIONS + +#define gpr_slice_refcount grpc_slice_refcount +#define gpr_slice grpc_slice +#define gpr_slice_buffer grpc_slice_buffer + +#define gpr_slice_ref grpc_slice_ref +#define gpr_slice_unref grpc_slice_unref +#define gpr_slice_new grpc_slice_new +#define gpr_slice_new_with_user_data grpc_slice_new_with_user_data +#define gpr_slice_new_with_len grpc_slice_new_with_len +#define gpr_slice_malloc grpc_slice_malloc +#define gpr_slice_from_copied_string grpc_slice_from_copied_string +#define gpr_slice_from_copied_buffer grpc_slice_from_copied_buffer +#define gpr_slice_from_static_string grpc_slice_from_static_string +#define gpr_slice_sub grpc_slice_sub +#define gpr_slice_sub_no_ref grpc_slice_sub_no_ref +#define gpr_slice_split_tail grpc_slice_split_tail +#define gpr_slice_split_head grpc_slice_split_head +#define gpr_slice_cmp grpc_slice_cmp +#define gpr_slice_str_cmp grpc_slice_str_cmp + +#define gpr_slice_buffer grpc_slice_buffer +#define gpr_slice_buffer_init grpc_slice_buffer_init +#define gpr_slice_buffer_destroy grpc_slice_buffer_destroy +#define gpr_slice_buffer_add grpc_slice_buffer_add +#define gpr_slice_buffer_add_indexed grpc_slice_buffer_add_indexed +#define gpr_slice_buffer_addn grpc_slice_buffer_addn +#define gpr_slice_buffer_tiny_add grpc_slice_buffer_tiny_add +#define gpr_slice_buffer_pop grpc_slice_buffer_pop +#define gpr_slice_buffer_reset_and_unref grpc_slice_buffer_reset_and_unref +#define gpr_slice_buffer_swap grpc_slice_buffer_swap +#define gpr_slice_buffer_move_into grpc_slice_buffer_move_into +#define gpr_slice_buffer_trim_end grpc_slice_buffer_trim_end +#define gpr_slice_buffer_move_first grpc_slice_buffer_move_first +#define gpr_slice_buffer_take_first grpc_slice_buffer_take_first + +#endif /* GRPC_ALLOW_GPR_SLICE_FUNCTIONS */ + +#endif /* GRPC_IMPL_CODEGEN_GPR_SLICE_H */ diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 774ba0e95d4..50b5426e1a1 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -37,6 +37,8 @@ #include #include +#include + /* Slice API A slice represents a contiguous reference counted array of bytes. @@ -115,4 +117,22 @@ typedef struct { GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice) #define GRPC_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0) +#ifdef GRPC_ALLOW_GPR_SLICE_FUNCTIONS + +/* Duplicate GPR_* definitions */ +#define GPR_SLICE_START_PTR(slice) \ + ((slice).refcount ? (slice).data.refcounted.bytes \ + : (slice).data.inlined.bytes) +#define GPR_SLICE_LENGTH(slice) \ + ((slice).refcount ? (slice).data.refcounted.length \ + : (slice).data.inlined.length) +#define GPR_SLICE_SET_LENGTH(slice, newlen) \ + ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \ + : ((slice).data.inlined.length = (uint8_t)(newlen))) +#define GPR_SLICE_END_PTR(slice) \ + GRPC_SLICE_START_PTR(slice) + GRPC_SLICE_LENGTH(slice) +#define GPR_SLICE_IS_EMPTY(slice) (GRPC_SLICE_LENGTH(slice) == 0) + +#endif /* GRPC_ALLOW_GPR_SLICE_FUNCTIONS */ + #endif /* GRPC_IMPL_CODEGEN_SLICE_H */ diff --git a/package.xml b/package.xml index 61668815a68..2106b8f666b 100644 --- a/package.xml +++ b/package.xml @@ -81,6 +81,7 @@ + @@ -163,6 +164,7 @@ + diff --git a/src/core/lib/support/string.h b/src/core/lib/support/string.h index e933e2eb468..db59308425d 100644 --- a/src/core/lib/support/string.h +++ b/src/core/lib/support/string.h @@ -36,8 +36,6 @@ #include -#include -#include #include #ifdef __cplusplus diff --git a/src/core/lib/support/tmpfile.h b/src/core/lib/support/tmpfile.h index 8952e5ec3da..f613cf9bc8d 100644 --- a/src/core/lib/support/tmpfile.h +++ b/src/core/lib/support/tmpfile.h @@ -36,8 +36,6 @@ #include -#include - #ifdef __cplusplus extern "C" { #endif diff --git a/test/core/surface/public_headers_must_be_c89.c b/test/core/surface/public_headers_must_be_c89.c index d4cfa25d44b..df6b7334932 100644 --- a/test/core/surface/public_headers_must_be_c89.c +++ b/test/core/surface/public_headers_must_be_c89.c @@ -42,6 +42,7 @@ #include #include #include +#include #include #include #include diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index ff3a0e381da..9e3fc62ebc6 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -840,6 +840,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 04e8f4e7f20..074ba504fa6 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -840,6 +840,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 1e748ba4a89..b83e710a2b7 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -779,6 +779,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -818,6 +819,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 6572bd4ddf9..533999b7655 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -779,6 +779,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ @@ -1212,6 +1213,7 @@ include/grpc/impl/codegen/atm.h \ include/grpc/impl/codegen/atm_gcc_atomic.h \ include/grpc/impl/codegen/atm_gcc_sync.h \ include/grpc/impl/codegen/atm_windows.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/port_platform.h \ include/grpc/impl/codegen/slice.h \ diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index 6ae269cc20d..449cc126e38 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -6631,6 +6631,7 @@ "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", @@ -6647,6 +6648,7 @@ "include/grpc/impl/codegen/atm_gcc_atomic.h", "include/grpc/impl/codegen/atm_gcc_sync.h", "include/grpc/impl/codegen/atm_windows.h", + "include/grpc/impl/codegen/gpr_slice.h", "include/grpc/impl/codegen/gpr_types.h", "include/grpc/impl/codegen/port_platform.h", "include/grpc/impl/codegen/slice.h", diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj b/vsprojects/vcxproj/gpr/gpr.vcxproj index ce593473c07..c4f9c55308e 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj @@ -177,6 +177,7 @@ + diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters index a50a9f42001..77a1ba64d64 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters @@ -225,6 +225,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index f281db72b66..14b3453b74e 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -338,6 +338,7 @@ + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index f359e4ef31a..53608196494 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -354,6 +354,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index d2305b2e255..6a928e173f6 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -185,6 +185,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 d1aaba70926..bf8fab03bb3 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters @@ -147,6 +147,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index 1511a2cfe4c..39b01e6a4e1 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -338,6 +338,7 @@ + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index bed77b25a44..9cafa1670ab 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -339,6 +339,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 558b5b0c66a..40f0f141b58 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -286,6 +286,7 @@ + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index a40a1b5f1c8..c0de28563e1 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -705,6 +705,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 2acdd32cf3e..01b73ce1a2a 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -166,6 +166,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 6c918f12546..40ff67671f3 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -456,6 +456,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 661192101c8..49c2d2db306 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -277,6 +277,7 @@ + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 466116e6043..5bca4fb9a5b 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -621,6 +621,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj index a2b2a1dfa0f..377d86fa5a9 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj @@ -198,6 +198,7 @@ + diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters index 94b6c2530ef..e9ba002e9b1 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters @@ -135,6 +135,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj index 1a3c1579837..3254ad8d459 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj @@ -198,6 +198,7 @@ + diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters index 1f4b60ca4d9..6f32f65524b 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters @@ -138,6 +138,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj index 1e3cc3ca043..7fad9222333 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj @@ -199,6 +199,7 @@ + diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters index 1c308c58817..19cb1133412 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters @@ -129,6 +129,9 @@ include\grpc\impl\codegen + + include\grpc\impl\codegen + include\grpc\impl\codegen From e272af07c77af238209fce05af4cc9fee372a948 Mon Sep 17 00:00:00 2001 From: David Garcia Quintas Date: Mon, 12 Dec 2016 14:51:31 -0800 Subject: [PATCH 112/261] poll_posix double shutdown fix --- src/core/lib/iomgr/ev_poll_posix.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/core/lib/iomgr/ev_poll_posix.c b/src/core/lib/iomgr/ev_poll_posix.c index 21b28e5554e..486181df0df 100644 --- a/src/core/lib/iomgr/ev_poll_posix.c +++ b/src/core/lib/iomgr/ev_poll_posix.c @@ -413,9 +413,7 @@ static void fd_orphan(grpc_exec_ctx *exec_ctx, grpc_fd *fd, const char *reason) { fd->on_done_closure = on_done; fd->released = release_fd != NULL; - if (!fd->released) { - shutdown(fd->fd, SHUT_RDWR); - } else { + if (fd->released) { *release_fd = fd->fd; } gpr_mu_lock(&fd->mu); From a053f23b1da74ebb238ee97ea86ba0f9b0ecc0b1 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Mon, 12 Dec 2016 17:40:22 -0800 Subject: [PATCH 113/261] Make Node extension work with slice changes --- binding.gyp | 1 + build.yaml | 2 + grpc.def | 1 + src/core/lib/iomgr/tcp_uv.c | 1 + src/node/ext/byte_buffer.cc | 6 +- src/node/ext/call.cc | 130 +++++++----------- src/node/ext/call.h | 17 +-- src/node/ext/call_credentials.cc | 3 +- src/node/ext/channel.cc | 3 +- src/node/ext/node_grpc.cc | 16 +-- src/node/ext/server.cc | 19 ++- src/node/ext/slice.cc | 102 ++++++++++++++ src/node/ext/slice.h | 52 +++++++ src/ruby/ext/grpc/rb_grpc_imports.generated.c | 2 + src/ruby/ext/grpc/rb_grpc_imports.generated.h | 3 + 15 files changed, 235 insertions(+), 123 deletions(-) create mode 100644 src/node/ext/slice.cc create mode 100644 src/node/ext/slice.h diff --git a/binding.gyp b/binding.gyp index 356d4acaac7..3c7eb98df20 100644 --- a/binding.gyp +++ b/binding.gyp @@ -839,6 +839,7 @@ "src/node/ext/node_grpc.cc", "src/node/ext/server.cc", "src/node/ext/server_credentials.cc", + "src/node/ext/slice.cc", "src/node/ext/timeval.cc", ], "dependencies": [ diff --git a/build.yaml b/build.yaml index 9e6660d513b..25fe4a7f175 100644 --- a/build.yaml +++ b/build.yaml @@ -3818,6 +3818,7 @@ node_modules: - src/node/ext/completion_queue_async_worker.h - src/node/ext/server.h - src/node/ext/server_credentials.h + - src/node/ext/slice.h - src/node/ext/timeval.h js: - src/node/index.js @@ -3839,6 +3840,7 @@ node_modules: - src/node/ext/node_grpc.cc - src/node/ext/server.cc - src/node/ext/server_credentials.cc + - src/node/ext/slice.cc - src/node/ext/timeval.cc openssl_fallback: base_uri: https://openssl.org/source/old/1.0.2/ diff --git a/grpc.def b/grpc.def index 523fa550f2a..5b2b679708a 100644 --- a/grpc.def +++ b/grpc.def @@ -164,6 +164,7 @@ EXPORTS grpc_slice_hash grpc_slice_is_equivalent grpc_slice_dup + grpc_slice_to_c_string grpc_slice_buffer_init grpc_slice_buffer_destroy grpc_slice_buffer_add diff --git a/src/core/lib/iomgr/tcp_uv.c b/src/core/lib/iomgr/tcp_uv.c index f3510bc7803..15c8b3cbee6 100644 --- a/src/core/lib/iomgr/tcp_uv.c +++ b/src/core/lib/iomgr/tcp_uv.c @@ -48,6 +48,7 @@ #include "src/core/lib/iomgr/network_status_tracker.h" #include "src/core/lib/iomgr/resource_quota.h" #include "src/core/lib/iomgr/tcp_uv.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index fc339fc4629..7d6fb198603 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -40,6 +40,7 @@ #include "grpc/slice.h" #include "byte_buffer.h" +#include "slice.h" namespace grpc { namespace node { @@ -54,10 +55,7 @@ using v8::Value; grpc_byte_buffer *BufferToByteBuffer(Local buffer) { Nan::HandleScope scope; - int length = ::node::Buffer::Length(buffer); - char *data = ::node::Buffer::Data(buffer); - grpc_slice slice = grpc_slice_malloc(length); - memcpy(GRPC_SLICE_START_PTR(slice), data, length); + grpc_slice slice = CreateSliceFromBuffer(buffer); grpc_byte_buffer *byte_buffer(grpc_raw_byte_buffer_create(&slice, 1)); grpc_slice_unref(slice); return byte_buffer; diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 191e763e0e7..9213d5e87d3 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -48,6 +48,7 @@ #include "completion_queue.h" #include "completion_queue_async_worker.h" #include "call_credentials.h" +#include "slice.h" #include "timeval.h" using std::unique_ptr; @@ -96,8 +97,7 @@ Local nanErrorWithCode(const char *msg, grpc_call_error code) { return scope.Escape(err); } -bool CreateMetadataArray(Local metadata, grpc_metadata_array *array, - shared_ptr resources) { +bool CreateMetadataArray(Local metadata, grpc_metadata_array *array) { HandleScope scope; grpc_metadata_array_init(array); Local keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked(); @@ -113,32 +113,25 @@ bool CreateMetadataArray(Local metadata, grpc_metadata_array *array, array->metadata = reinterpret_cast( gpr_malloc(array->capacity * sizeof(grpc_metadata))); for (unsigned int i = 0; i < keys->Length(); i++) { - Local current_key(keys->Get(i)->ToString()); - Utf8String *utf8_key = new Utf8String(current_key); - resources->strings.push_back(unique_ptr(utf8_key)); + Local current_key(Nan::To(keys->Get(i)).ToLocalChecked()); Local values = Local::Cast( Nan::Get(metadata, current_key).ToLocalChecked()); + grpc_slice key_slice = grpc_slice_intern(CreateSliceFromString(current_key)); for (unsigned int j = 0; j < values->Length(); j++) { Local value = Nan::Get(values, j).ToLocalChecked(); grpc_metadata *current = &array->metadata[array->count]; - current->key = **utf8_key; + current->key = key_slice; // Only allow binary headers for "-bin" keys - if (grpc_is_binary_header(current->key, strlen(current->key))) { + if (grpc_is_binary_header(key_slice)) { if (::node::Buffer::HasInstance(value)) { - current->value = ::node::Buffer::Data(value); - current->value_length = ::node::Buffer::Length(value); - PersistentValue *handle = new PersistentValue(value); - resources->handles.push_back(unique_ptr(handle)); + current->value = CreateSliceFromBuffer(value); } else { return false; } } else { if (value->IsString()) { Local string_value = Nan::To(value).ToLocalChecked(); - Utf8String *utf8_value = new Utf8String(string_value); - resources->strings.push_back(unique_ptr(utf8_value)); - current->value = **utf8_value; - current->value_length = string_value->Length(); + current->value = CreateSliceFromString(string_value); } else { return false; } @@ -153,40 +146,25 @@ Local ParseMetadata(const grpc_metadata_array *metadata_array) { EscapableHandleScope scope; grpc_metadata *metadata_elements = metadata_array->metadata; size_t length = metadata_array->count; - std::map size_map; - std::map index_map; - - for (unsigned int i = 0; i < length; i++) { - const char *key = metadata_elements[i].key; - if (size_map.count(key)) { - size_map[key] += 1; - } else { - size_map[key] = 1; - } - index_map[key] = 0; - } Local metadata_object = Nan::New(); for (unsigned int i = 0; i < length; i++) { grpc_metadata* elem = &metadata_elements[i]; - Local key_string = Nan::New(elem->key).ToLocalChecked(); + // TODO(murgatroid99): Use zero-copy string construction instead + Local key_string = CopyStringFromSlice(elem->key); Local array; MaybeLocal maybe_array = Nan::Get(metadata_object, key_string); if (maybe_array.IsEmpty() || !maybe_array.ToLocalChecked()->IsArray()) { - array = Nan::New(size_map[elem->key]); + array = Nan::New(0); Nan::Set(metadata_object, key_string, array); } else { array = Local::Cast(maybe_array.ToLocalChecked()); } - if (grpc_is_binary_header(elem->key, strlen(elem->key))) { - Nan::Set(array, index_map[elem->key], - MakeFastBuffer( - Nan::CopyBuffer(elem->value, - elem->value_length).ToLocalChecked())); + if (grpc_is_binary_header(elem->key)) { + Nan::Set(array, array->Length(), CreateBufferFromSlice(elem->value)); } else { - Nan::Set(array, index_map[elem->key], - Nan::New(elem->value).ToLocalChecked()); + // TODO(murgatroid99): Use zero-copy string construction instead + Nan::Set(array, array->Length(), CopyStringFromSlice(elem->value)); } - index_map[elem->key] += 1; } return scope.Escape(metadata_object); } @@ -205,8 +183,7 @@ class SendMetadataOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { if (!value->IsObject()) { return false; } @@ -216,7 +193,7 @@ class SendMetadataOp : public Op { return false; } if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(), - &array, resources)) { + &array)) { return false; } out->data.send_initial_metadata.count = array.count; @@ -246,8 +223,7 @@ class SendMessageOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { if (!::node::Buffer::HasInstance(value)) { return false; } @@ -263,8 +239,6 @@ class SendMessageOp : public Op { } send_message = BufferToByteBuffer(value); out->data.send_message = send_message; - PersistentValue *handle = new PersistentValue(value); - resources->handles.push_back(unique_ptr(handle)); return true; } bool IsFinalOp() { @@ -284,8 +258,7 @@ class SendClientCloseOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { return true; } bool IsFinalOp() { @@ -299,12 +272,14 @@ class SendClientCloseOp : public Op { class SendServerStatusOp : public Op { public: + ~SendServerStatusOp() { + grpc_slice_unref(details); + } Local GetNodeValue() const { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { if (!value->IsObject()) { return false; } @@ -339,16 +314,15 @@ class SendServerStatusOp : public Op { Local details = Nan::To( maybe_details.ToLocalChecked()).ToLocalChecked(); grpc_metadata_array array; - if (!CreateMetadataArray(metadata, &array, resources)) { + if (!CreateMetadataArray(metadata, &array)) { return false; } out->data.send_status_from_server.trailing_metadata_count = array.count; out->data.send_status_from_server.trailing_metadata = array.metadata; out->data.send_status_from_server.status = static_cast(code); - Utf8String *str = new Utf8String(details); - resources->strings.push_back(unique_ptr(str)); - out->data.send_status_from_server.status_details = **str; + this->details = CreateSliceFromString(details); + out->data.send_status_from_server.status_details = &this->details; return true; } bool IsFinalOp() { @@ -358,6 +332,9 @@ class SendServerStatusOp : public Op { std::string GetTypeString() const { return "send_status"; } + + private: + grpc_slice details; }; class GetMetadataOp : public Op { @@ -375,8 +352,7 @@ class GetMetadataOp : public Op { return scope.Escape(ParseMetadata(&recv_metadata)); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { out->data.recv_initial_metadata = &recv_metadata; return true; } @@ -408,8 +384,7 @@ class ReadMessageOp : public Op { return scope.Escape(ByteBufferToBuffer(recv_message)); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { out->data.recv_message = &recv_message; return true; } @@ -430,21 +405,16 @@ class ClientStatusOp : public Op { public: ClientStatusOp() { grpc_metadata_array_init(&metadata_array); - status_details = NULL; - details_capacity = 0; } ~ClientStatusOp() { grpc_metadata_array_destroy(&metadata_array); - gpr_free(status_details); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { out->data.recv_status_on_client.trailing_metadata = &metadata_array; out->data.recv_status_on_client.status = &status; out->data.recv_status_on_client.status_details = &status_details; - out->data.recv_status_on_client.status_details_capacity = &details_capacity; return true; } @@ -453,10 +423,8 @@ class ClientStatusOp : public Op { Local status_obj = Nan::New(); Nan::Set(status_obj, Nan::New("code").ToLocalChecked(), Nan::New(status)); - if (status_details != NULL) { - Nan::Set(status_obj, Nan::New("details").ToLocalChecked(), - Nan::New(status_details).ToLocalChecked()); - } + Nan::Set(status_obj, Nan::New("details").ToLocalChecked(), + CopyStringFromSlice(status_details)); Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(), ParseMetadata(&metadata_array)); return scope.Escape(status_obj); @@ -471,8 +439,7 @@ class ClientStatusOp : public Op { private: grpc_metadata_array metadata_array; grpc_status_code status; - char *status_details; - size_t details_capacity; + grpc_slice status_details; }; class ServerCloseResponseOp : public Op { @@ -482,8 +449,7 @@ class ServerCloseResponseOp : public Op { return scope.Escape(Nan::New(cancelled)); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { out->data.recv_close_on_server.cancelled = &cancelled; return true; } @@ -500,9 +466,8 @@ class ServerCloseResponseOp : public Op { int cancelled; }; -tag::tag(Callback *callback, OpVec *ops, - shared_ptr resources, Call *call) : - callback(callback), ops(ops), resources(resources), call(call){ +tag::tag(Callback *callback, OpVec *ops, Call *call) : + callback(callback), ops(ops), call(call){ } tag::~tag() { @@ -650,20 +615,24 @@ NAN_METHOD(Call::New) { if (channel->GetWrappedChannel() == NULL) { return Nan::ThrowError("Call cannot be created from a closed channel"); } - Utf8String method(info[1]); double deadline = Nan::To(info[2]).FromJust(); grpc_channel *wrapped_channel = channel->GetWrappedChannel(); grpc_call *wrapped_call; if (info[3]->IsString()) { - Utf8String host_override(info[3]); + grpc_slice *host = new grpc_slice; + *host = CreateSliceFromString( + Nan::To(info[3]).ToLocalChecked()); wrapped_call = grpc_channel_create_call( wrapped_channel, parent_call, propagate_flags, - GetCompletionQueue(), *method, - *host_override, MillisecondsToTimespec(deadline), NULL); + GetCompletionQueue(), CreateSliceFromString( + Nan::To(info[1]).ToLocalChecked()), + host, MillisecondsToTimespec(deadline), NULL); + delete host; } else if (info[3]->IsUndefined() || info[3]->IsNull()) { wrapped_call = grpc_channel_create_call( wrapped_channel, parent_call, propagate_flags, - GetCompletionQueue(), *method, + GetCompletionQueue(), CreateSliceFromString( + Nan::To(info[1]).ToLocalChecked()), NULL, MillisecondsToTimespec(deadline), NULL); } else { return Nan::ThrowTypeError("Call's fourth argument must be a string"); @@ -700,7 +669,6 @@ NAN_METHOD(Call::StartBatch) { } Local callback_func = info[1].As(); Call *call = ObjectWrap::Unwrap(info.This()); - shared_ptr resources(new Resources); Local obj = Nan::To(info[0]).ToLocalChecked(); Local keys = Nan::GetOwnPropertyNames(obj).ToLocalChecked(); size_t nops = keys->Length(); @@ -745,7 +713,7 @@ NAN_METHOD(Call::StartBatch) { default: return Nan::ThrowError("Argument object had an unrecognized key"); } - if (!op->ParseOp(obj->Get(type), &ops[i], resources)) { + if (!op->ParseOp(obj->Get(type), &ops[i])) { return Nan::ThrowTypeError("Incorrectly typed arguments to startBatch"); } op_vector->push_back(std::move(op)); @@ -753,7 +721,7 @@ NAN_METHOD(Call::StartBatch) { Callback *callback = new Callback(callback_func); grpc_call_error error = grpc_call_start_batch( call->wrapped_call, &ops[0], nops, new struct tag( - callback, op_vector.release(), resources, call), NULL); + callback, op_vector.release(), call), NULL); if (error != GRPC_CALL_OK) { return Nan::ThrowError(nanErrorWithCode("startBatch failed", error)); } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index 31c6566d145..cffff00fce4 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -51,20 +51,12 @@ namespace node { using std::unique_ptr; using std::shared_ptr; -typedef Nan::Persistent> PersistentValue; - v8::Local nanErrorWithCode(const char *msg, grpc_call_error code); v8::Local ParseMetadata(const grpc_metadata_array *metadata_array); -struct Resources { - std::vector > strings; - std::vector > handles; -}; - bool CreateMetadataArray(v8::Local metadata, - grpc_metadata_array *array, - shared_ptr resources); + grpc_metadata_array *array); /* Wrapper class for grpc_call structs. */ class Call : public Nan::ObjectWrap { @@ -106,8 +98,7 @@ class Call : public Nan::ObjectWrap { class Op { public: virtual v8::Local GetNodeValue() const = 0; - virtual bool ParseOp(v8::Local value, grpc_op *out, - shared_ptr resources) = 0; + virtual bool ParseOp(v8::Local value, grpc_op *out) = 0; virtual ~Op(); v8::Local GetOpType() const; virtual bool IsFinalOp() = 0; @@ -118,12 +109,10 @@ class Op { typedef std::vector> OpVec; struct tag { - tag(Nan::Callback *callback, OpVec *ops, - shared_ptr resources, Call *call); + tag(Nan::Callback *callback, OpVec *ops, Call *call); ~tag(); Nan::Callback *callback; OpVec *ops; - shared_ptr resources; Call *call; }; diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 81fc552fd10..4d172d4ddfd 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -206,7 +206,6 @@ NAN_METHOD(PluginCallback) { return Nan::ThrowTypeError( "The callback's fourth argument must be an object"); } - shared_ptr resources(new Resources); grpc_status_code code = static_cast( Nan::To(info[0]).FromJust()); Utf8String details_utf8_str(info[1]); @@ -214,7 +213,7 @@ NAN_METHOD(PluginCallback) { grpc_metadata_array array; Local callback_data = Nan::To(info[3]).ToLocalChecked(); if (!CreateMetadataArray(Nan::To(info[2]).ToLocalChecked(), - &array, resources)){ + &array)){ return Nan::ThrowError("Failed to parse metadata"); } grpc_credentials_plugin_metadata_cb cb = diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc index 5bc58b9b324..c795ff7f42f 100644 --- a/src/node/ext/channel.cc +++ b/src/node/ext/channel.cc @@ -280,8 +280,7 @@ NAN_METHOD(Channel::WatchConnectivityState) { channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline), GetCompletionQueue(), new struct tag(callback, - ops.release(), - shared_ptr(nullptr), NULL)); + ops.release(), NULL)); CompletionQueueNext(); } diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 9b9eee85b79..682af0e5add 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -56,9 +56,12 @@ extern "C" { #include "server.h" #include "completion_queue_async_worker.h" #include "server_credentials.h" +#include "slice.h" #include "timeval.h" #include "completion_queue.h" +using grpc::node::CreateSliceFromString; + using v8::FunctionTemplate; using v8::Local; using v8::Value; @@ -283,10 +286,8 @@ NAN_METHOD(MetadataKeyIsLegal) { "headerKeyIsLegal's argument must be a string"); } Local key = Nan::To(info[0]).ToLocalChecked(); - Nan::Utf8String key_utf8_str(key); - char *key_str = *key_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_header_key_is_legal(key_str, static_cast(key->Length())))); + grpc_header_key_is_legal(CreateSliceFromString(key)))); } NAN_METHOD(MetadataNonbinValueIsLegal) { @@ -295,11 +296,8 @@ NAN_METHOD(MetadataNonbinValueIsLegal) { "metadataNonbinValueIsLegal's argument must be a string"); } Local value = Nan::To(info[0]).ToLocalChecked(); - Nan::Utf8String value_utf8_str(value); - char *value_str = *value_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_header_nonbin_value_is_legal( - value_str, static_cast(value->Length())))); + grpc_header_nonbin_value_is_legal(CreateSliceFromString(value)))); } NAN_METHOD(MetadataKeyIsBinary) { @@ -308,10 +306,8 @@ NAN_METHOD(MetadataKeyIsBinary) { "metadataKeyIsLegal's argument must be a string"); } Local key = Nan::To(info[0]).ToLocalChecked(); - Nan::Utf8String key_utf8_str(key); - char *key_str = *key_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_is_binary_header(key_str, static_cast(key->Length())))); + grpc_is_binary_header(CreateSliceFromString(key)))); } static grpc_ssl_roots_override_result get_ssl_roots_override( diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc index 70d5b96f397..4761b2867db 100644 --- a/src/node/ext/server.cc +++ b/src/node/ext/server.cc @@ -46,6 +46,7 @@ #include "grpc/grpc_security.h" #include "grpc/support/log.h" #include "server_credentials.h" +#include "slice.h" #include "timeval.h" namespace grpc { @@ -99,10 +100,11 @@ class NewCallOp : public Op { } Local obj = Nan::New(); Nan::Set(obj, Nan::New("call").ToLocalChecked(), Call::WrapStruct(call)); + // TODO(murgatroid99): Use zero-copy string construction instead Nan::Set(obj, Nan::New("method").ToLocalChecked(), - Nan::New(details.method).ToLocalChecked()); + CopyStringFromSlice(details.method)); Nan::Set(obj, Nan::New("host").ToLocalChecked(), - Nan::New(details.host).ToLocalChecked()); + CopyStringFromSlice(details.host)); Nan::Set(obj, Nan::New("deadline").ToLocalChecked(), Nan::New(TimespecToMilliseconds(details.deadline)) .ToLocalChecked()); @@ -111,8 +113,7 @@ class NewCallOp : public Op { return scope.Escape(obj); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { return true; } bool IsFinalOp() { @@ -139,8 +140,7 @@ class ServerShutdownOp : public Op { return Nan::New(reinterpret_cast(server)); } - bool ParseOp(Local value, grpc_op *out, - shared_ptr resources) { + bool ParseOp(Local value, grpc_op *out) { return true; } bool IsFinalOp() { @@ -207,8 +207,7 @@ void Server::ShutdownServer() { grpc_server_shutdown_and_notify( this->wrapped_server, GetCompletionQueue(), - new struct tag(new Callback(**shutdown_callback), ops.release(), - shared_ptr(nullptr), NULL)); + new struct tag(new Callback(**shutdown_callback), ops.release(), NULL)); grpc_server_cancel_all_calls(this->wrapped_server); CompletionQueueNext(); this->wrapped_server = NULL; @@ -261,7 +260,7 @@ NAN_METHOD(Server::RequestCall) { GetCompletionQueue(), GetCompletionQueue(), new struct tag(new Callback(info[0].As()), ops.release(), - shared_ptr(nullptr), NULL)); + NULL)); if (error != GRPC_CALL_OK) { return Nan::ThrowError(nanErrorWithCode("requestCall failed", error)); } @@ -314,7 +313,7 @@ NAN_METHOD(Server::TryShutdown) { grpc_server_shutdown_and_notify( server->wrapped_server, GetCompletionQueue(), new struct tag(new Nan::Callback(info[0].As()), ops.release(), - shared_ptr(nullptr), NULL)); + NULL)); CompletionQueueNext(); } diff --git a/src/node/ext/slice.cc b/src/node/ext/slice.cc new file mode 100644 index 00000000000..98a80b3d2f9 --- /dev/null +++ b/src/node/ext/slice.cc @@ -0,0 +1,102 @@ +/* + * + * 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. + * + */ + +#include +#include +#include +#include + +#include "slice.h" +#include "byte_buffer.h" + +namespace grpc { +namespace node { + +using Nan::Persistent; + +using v8::Local; +using v8::String; +using v8::Value; + +namespace { +void SliceFreeCallback(char *data, void *hint) { + grpc_slice *slice = reinterpret_cast(hint); + grpc_slice_unref(*slice); + delete slice; +} + +void string_destroy_func(void *user_data) { + delete reinterpret_cast(user_data); +} + +void buffer_destroy_func(void *user_data) { + delete reinterpret_cast(user_data); +} +} // namespace + +grpc_slice CreateSliceFromString(const Local source) { + Nan::HandleScope scope; + Nan::Utf8String *utf8_value = new Nan::Utf8String(source); + return grpc_slice_new_with_user_data(**utf8_value, source->Length(), + string_destroy_func, utf8_value); +} + +grpc_slice CreateSliceFromBuffer(const Local source) { + // Prerequisite: ::node::Buffer::HasInstance(source) + Nan::HandleScope scope; + return grpc_slice_new_with_user_data(::node::Buffer::Data(source), + ::node::Buffer::Length(source), + buffer_destroy_func, + new PersistentValue(source)); +} +Local CopyStringFromSlice(const grpc_slice slice) { + Nan::EscapableHandleScope scope; + if (GRPC_SLICE_LENGTH(slice) == 0) { + return scope.Escape(Nan::EmptyString()); + } + return scope.Escape(Nan::New( + const_cast(reinterpret_cast(GRPC_SLICE_START_PTR(slice))), + GRPC_SLICE_LENGTH(slice)).ToLocalChecked()); +} + +Local CreateBufferFromSlice(const grpc_slice slice) { + Nan::EscapableHandleScope scope; + grpc_slice *slice_ptr = new grpc_slice; + *slice_ptr = grpc_slice_ref(slice); + return scope.Escape(MakeFastBuffer(Nan::NewBuffer( + const_cast(reinterpret_cast(GRPC_SLICE_START_PTR(*slice_ptr))), + GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked())); +} + +} // namespace node +} // namespace grpc diff --git a/src/node/ext/slice.h b/src/node/ext/slice.h new file mode 100644 index 00000000000..7dcb1bd45a8 --- /dev/null +++ b/src/node/ext/slice.h @@ -0,0 +1,52 @@ +/* + * + * 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. + * + */ + +#include +#include +#include + +namespace grpc { +namespace node { + +typedef Nan::Persistent> PersistentValue; + +grpc_slice CreateSliceFromString(const v8::Local source); + +grpc_slice CreateSliceFromBuffer(const v8::Local source); + +v8::Local CopyStringFromSlice(const grpc_slice slice); + +v8::Local CreateBufferFromSlice(const grpc_slice slice); + +} // namespace node +} // namespace grpc diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 4759d26da53..230682e72d9 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -202,6 +202,7 @@ grpc_slice_slice_type grpc_slice_slice_import; grpc_slice_hash_type grpc_slice_hash_import; grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; grpc_slice_dup_type grpc_slice_dup_import; +grpc_slice_to_c_string_type grpc_slice_to_c_string_import; grpc_slice_buffer_init_type grpc_slice_buffer_init_import; grpc_slice_buffer_destroy_type grpc_slice_buffer_destroy_import; grpc_slice_buffer_add_type grpc_slice_buffer_add_import; @@ -490,6 +491,7 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_hash_import = (grpc_slice_hash_type) GetProcAddress(library, "grpc_slice_hash"); grpc_slice_is_equivalent_import = (grpc_slice_is_equivalent_type) GetProcAddress(library, "grpc_slice_is_equivalent"); grpc_slice_dup_import = (grpc_slice_dup_type) GetProcAddress(library, "grpc_slice_dup"); + grpc_slice_to_c_string_import = (grpc_slice_to_c_string_type) GetProcAddress(library, "grpc_slice_to_c_string"); grpc_slice_buffer_init_import = (grpc_slice_buffer_init_type) GetProcAddress(library, "grpc_slice_buffer_init"); grpc_slice_buffer_destroy_import = (grpc_slice_buffer_destroy_type) GetProcAddress(library, "grpc_slice_buffer_destroy"); grpc_slice_buffer_add_import = (grpc_slice_buffer_add_type) GetProcAddress(library, "grpc_slice_buffer_add"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 32386e81315..4c4f655b861 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -557,6 +557,9 @@ extern grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; typedef grpc_slice(*grpc_slice_dup_type)(grpc_slice a); extern grpc_slice_dup_type grpc_slice_dup_import; #define grpc_slice_dup grpc_slice_dup_import +typedef char *(*grpc_slice_to_c_string_type)(grpc_slice s); +extern grpc_slice_to_c_string_type grpc_slice_to_c_string_import; +#define grpc_slice_to_c_string grpc_slice_to_c_string_import typedef void(*grpc_slice_buffer_init_type)(grpc_slice_buffer *sb); extern grpc_slice_buffer_init_type grpc_slice_buffer_init_import; #define grpc_slice_buffer_init grpc_slice_buffer_init_import From 70f4d26e0f164c2ccf5d9530681d25913a2c4509 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 9 Dec 2016 17:39:33 -0800 Subject: [PATCH 114/261] convert char* to grpc_slice in ruby --- src/ruby/ext/grpc/rb_byte_buffer.c | 7 ++ src/ruby/ext/grpc/rb_byte_buffer.h | 3 + src/ruby/ext/grpc/rb_call.c | 93 +++++++++++----------- src/ruby/ext/grpc/rb_channel.c | 27 +++++-- src/ruby/ext/grpc/rb_compression_options.c | 15 ++-- src/ruby/ext/grpc/rb_server.c | 10 ++- 6 files changed, 93 insertions(+), 62 deletions(-) diff --git a/src/ruby/ext/grpc/rb_byte_buffer.c b/src/ruby/ext/grpc/rb_byte_buffer.c index f97890e4a2e..0f15f70a28d 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.c +++ b/src/ruby/ext/grpc/rb_byte_buffer.c @@ -67,3 +67,10 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) { } return rb_string; } + +VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice) { + if (GRPC_SLICE_START_PTR(slice) == NULL) { + rb_raise(rb_eRuntimeError, "attempt to convert uninitialized grpc_slice to ruby string"); + } + return rb_str_new((char*)GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); +} diff --git a/src/ruby/ext/grpc/rb_byte_buffer.h b/src/ruby/ext/grpc/rb_byte_buffer.h index c7ddd764890..fac68fe6a00 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.h +++ b/src/ruby/ext/grpc/rb_byte_buffer.h @@ -44,4 +44,7 @@ grpc_byte_buffer *grpc_rb_s_to_byte_buffer(char *string, size_t length); /* Converts a grpc_byte_buffer to a ruby string */ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer); +/* Converts a grpc_slice to a ruby string */ +VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice); + #endif /* GRPC_RB_BYTE_BUFFER_H_ */ diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index 67a42af619b..0179bd9e9b2 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -121,8 +121,8 @@ static size_t md_ary_datasize(const void *p) { size_t i, datasize = sizeof(grpc_metadata_array); for (i = 0; i < ary->count; ++i) { const grpc_metadata *const md = &ary->metadata[i]; - datasize += strlen(md->key); - datasize += md->value_length; + datasize += GRPC_SLICE_LENGTH(md->key); + datasize += GRPC_SLICE_LENGTH(md->value); } datasize += ary->capacity * sizeof(grpc_metadata); return datasize; @@ -386,23 +386,23 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { grpc_metadata_array *md_ary = NULL; long array_length; long i; - char *key_str; - size_t key_len; - char *value_str; - size_t value_len; + grpc_slice key_slice; + grpc_slice value_slice; + char* tmp_str; if (TYPE(key) == T_SYMBOL) { - key_str = (char *)rb_id2name(SYM2ID(key)); - key_len = strlen(key_str); - } else { /* StringValueCStr does all other type exclusions for us */ - key_str = StringValueCStr(key); - key_len = RSTRING_LEN(key); + key_slice = grpc_slice_from_static_string(rb_id2name(SYM2ID(key))); + } else if (TYPE(key) == T_STRING) { + key_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(key), RSTRING_LEN(key)); + } else { + rb_raise(rb_eTypeError, "grpc_rb_md_ary_fill_hash_cb: bad type for key parameter"); } - if (!grpc_header_key_is_legal(key_str, key_len)) { + if (!grpc_header_key_is_legal(key_slice)) { + tmp_str = grpc_slice_to_c_string(key_slice); rb_raise(rb_eArgError, "'%s' is an invalid header key, must match [a-z0-9-_.]+", - key_str); + tmp_str); return ST_STOP; } @@ -414,33 +414,31 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { array_length = RARRAY_LEN(val); /* If the value is an array, add capacity for each value in the array */ for (i = 0; i < array_length; i++) { - value_str = RSTRING_PTR(rb_ary_entry(val, i)); - value_len = RSTRING_LEN(rb_ary_entry(val, i)); - if (!grpc_is_binary_header(key_str, key_len) && - !grpc_header_nonbin_value_is_legal(value_str, value_len)) { + value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(rb_ary_entry(val, i)), RSTRING_LEN(rb_ary_entry(val, i))); + if (!grpc_is_binary_header(key_slice) && + !grpc_header_nonbin_value_is_legal(value_slice)) { // The value has invalid characters + tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", value_str); + "Header value '%s' has invalid characters", tmp_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_str; - md_ary->metadata[md_ary->count].value = value_str; - md_ary->metadata[md_ary->count].value_length = value_len; + md_ary->metadata[md_ary->count].key = key_slice; + md_ary->metadata[md_ary->count].value = value_slice; md_ary->count += 1; } } else if (TYPE(val) == T_STRING) { - value_str = RSTRING_PTR(val); - value_len = RSTRING_LEN(val); - if (!grpc_is_binary_header(key_str, key_len) && - !grpc_header_nonbin_value_is_legal(value_str, value_len)) { + value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(val), RSTRING_LEN(val)); + if (!grpc_is_binary_header(key_slice) && + !grpc_header_nonbin_value_is_legal(value_slice)) { // The value has invalid characters + tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", value_str); + "Header value '%s' has invalid characters", tmp_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_str; - md_ary->metadata[md_ary->count].value = value_str; - md_ary->metadata[md_ary->count].value_length = value_len; + md_ary->metadata[md_ary->count].key = key_slice; + md_ary->metadata[md_ary->count].value = value_slice; md_ary->count += 1; } else { rb_raise(rb_eArgError, @@ -506,22 +504,19 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary) { size_t i; for (i = 0; i < md_ary->count; i++) { - key = rb_str_new2(md_ary->metadata[i].key); + key = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].key); value = rb_hash_aref(result, key); if (value == Qnil) { - value = rb_str_new(md_ary->metadata[i].value, - md_ary->metadata[i].value_length); + value = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value); rb_hash_aset(result, key, value); } else if (TYPE(value) == T_ARRAY) { /* Add the string to the returned array */ - rb_ary_push(value, rb_str_new(md_ary->metadata[i].value, - md_ary->metadata[i].value_length)); + rb_ary_push(value, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); } else { /* Add the current value with this key and the new one to an array */ new_ary = rb_ary_new(); rb_ary_push(new_ary, value); - rb_ary_push(new_ary, rb_str_new(md_ary->metadata[i].value, - md_ary->metadata[i].value_length)); + rb_ary_push(new_ary, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); rb_hash_aset(result, key, new_ary); } } @@ -563,6 +558,7 @@ static int grpc_rb_call_check_op_keys_hash_cb(VALUE key, VALUE val, */ static void grpc_rb_op_update_status_from_server(grpc_op *op, grpc_metadata_array *md_ary, + grpc_slice *send_status_details, VALUE status) { VALUE code = rb_struct_aref(status, sym_code); VALUE details = rb_struct_aref(status, sym_details); @@ -579,8 +575,11 @@ static void grpc_rb_op_update_status_from_server(grpc_op *op, rb_obj_classname(code)); return; } + + *send_status_details = grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details)); + op->data.send_status_from_server.status = NUM2INT(code); - op->data.send_status_from_server.status_details = StringValueCStr(details); + op->data.send_status_from_server.status_details = send_status_details; grpc_rb_md_ary_convert(metadata_hash, md_ary); op->data.send_status_from_server.trailing_metadata_count = md_ary->count; op->data.send_status_from_server.trailing_metadata = md_ary->metadata; @@ -603,9 +602,9 @@ typedef struct run_batch_stack { grpc_metadata_array recv_trailing_metadata; int recv_cancelled; grpc_status_code recv_status; - char *recv_status_details; - size_t recv_status_details_capacity; + grpc_slice recv_status_details; unsigned write_flag; + grpc_slice send_status_details; } run_batch_stack; /* grpc_run_batch_stack_init ensures the run_batch_stack is properly @@ -631,8 +630,12 @@ static void grpc_run_batch_stack_cleanup(run_batch_stack *st) { grpc_metadata_array_destroy(&st->recv_metadata); grpc_metadata_array_destroy(&st->recv_trailing_metadata); - if (st->recv_status_details != NULL) { - gpr_free(st->recv_status_details); + if (GRPC_SLICE_START_PTR(st->send_status_details) != NULL) { + grpc_slice_unref(st->send_status_details); + } + + if (GRPC_SLICE_START_PTR(st->recv_status_details) != NULL) { + grpc_slice_unref(st->recv_status_details); } if (st->recv_message != NULL) { @@ -683,7 +686,7 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { /* N.B. later there is no need to explicitly delete the metadata keys * and values, they are references to data in ruby objects. */ grpc_rb_op_update_status_from_server( - &st->ops[st->op_num], &st->send_trailing_metadata, this_value); + &st->ops[st->op_num], &st->send_trailing_metadata, &st->send_status_details, this_value); break; case GRPC_OP_RECV_INITIAL_METADATA: st->ops[st->op_num].data.recv_initial_metadata = &st->recv_metadata; @@ -698,8 +701,6 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { &st->recv_status; st->ops[st->op_num].data.recv_status_on_client.status_details = &st->recv_status_details; - st->ops[st->op_num].data.recv_status_on_client.status_details_capacity = - &st->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: st->ops[st->op_num].data.recv_close_on_server.cancelled = @@ -747,9 +748,9 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) { rb_struct_aset( result, sym_status, rb_struct_new(grpc_rb_sStatus, UINT2NUM(st->recv_status), - (st->recv_status_details == NULL + (GRPC_SLICE_START_PTR(st->recv_status_details) == NULL ? Qnil - : rb_str_new2(st->recv_status_details)), + : grpc_rb_slice_to_ruby_string(st->recv_status_details)), grpc_rb_md_ary_to_h(&st->recv_trailing_metadata), NULL)); break; diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 3b2b88eb774..84e43d3f7bf 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -35,6 +35,7 @@ #include "rb_grpc_imports.generated.h" #include "rb_channel.h" +#include "rb_byte_buffer.h" #include #include @@ -252,10 +253,14 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, grpc_channel *ch = NULL; grpc_completion_queue *cq = NULL; int flags = GRPC_PROPAGATE_DEFAULTS; - char *method_chars = StringValueCStr(method); - char *host_chars = NULL; + grpc_slice method_slice; + grpc_slice host_slice; + grpc_slice *host_slice_ptr = NULL; + char* tmp_str = NULL; + if (host != Qnil) { - host_chars = StringValueCStr(host); + host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); + host_slice_ptr = &host_slice; } if (mask != Qnil) { flags = NUM2UINT(mask); @@ -272,15 +277,25 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, return Qnil; } - call = grpc_channel_create_call(ch, parent_call, flags, cq, method_chars, - host_chars, grpc_rb_time_timeval( + method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); + + call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice, + host_slice_ptr, grpc_rb_time_timeval( deadline, /* absolute time */ 0), NULL); + if (call == NULL) { + tmp_str = grpc_slice_to_c_string(method_slice); rb_raise(rb_eRuntimeError, "cannot create call with method %s", - method_chars); + tmp_str); return Qnil; } + + grpc_slice_unref(method_slice); + if (host_slice_ptr != NULL) { + grpc_slice_unref(host_slice); + } + res = grpc_rb_wrap_call(call, cq); /* Make this channel an instance attribute of the call so that it is not GCed diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index 6200dbafeb8..6b2467ee461 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -34,6 +34,7 @@ #include #include "rb_compression_options.h" +#include "rb_byte_buffer.h" #include "rb_grpc_imports.generated.h" #include @@ -168,9 +169,9 @@ void grpc_rb_compression_options_set_default_level( * Raises an error if the name of the algorithm passed in is invalid. */ void grpc_rb_compression_options_algorithm_name_to_value_internal( grpc_compression_algorithm *algorithm_value, VALUE algorithm_name) { - char *name_str = NULL; - long name_len = 0; + grpc_slice name_slice; VALUE algorithm_name_as_string = Qnil; + char *tmp_str = NULL; Check_Type(algorithm_name, T_SYMBOL); @@ -178,16 +179,18 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( * correct C string out of it. */ algorithm_name_as_string = rb_funcall(algorithm_name, rb_intern("to_s"), 0); - name_str = RSTRING_PTR(algorithm_name_as_string); - name_len = RSTRING_LEN(algorithm_name_as_string); + name_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(algorithm_name_as_string), RSTRING_LEN(algorithm_name_as_string)); /* Raise an error if the name isn't recognized as a compression algorithm by * the algorithm parse function * in GRPC core. */ - if (!grpc_compression_algorithm_parse(name_str, name_len, algorithm_value)) { + if(!grpc_compression_algorithm_parse(name_slice, algorithm_value)) { + tmp_str = grpc_slice_to_c_string(name_slice); rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", - StringValueCStr(algorithm_name_as_string)); + tmp_str); } + + grpc_slice_unref(name_slice); } /* Indicates whether a given algorithm is enabled on this instance, given the diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 2a6a246e677..7caafe7b8de 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -43,6 +43,7 @@ #include "rb_channel_args.h" #include "rb_completion_queue.h" #include "rb_server_credentials.h" +#include "rb_byte_buffer.h" #include "rb_grpc.h" /* grpc_rb_cServer is the ruby class that proxies grpc_server. */ @@ -160,8 +161,6 @@ static void grpc_request_call_stack_init(request_call_stack* st) { MEMZERO(st, request_call_stack, 1); grpc_metadata_array_init(&st->md_ary); grpc_call_details_init(&st->details); - st->details.method = NULL; - st->details.host = NULL; } /* grpc_request_call_stack_cleanup ensures the request_call_stack is properly @@ -185,6 +184,7 @@ static VALUE grpc_rb_server_request_call(VALUE self) { void *tag = (void*)&st; grpc_completion_queue *call_queue = grpc_completion_queue_create(NULL); gpr_timespec deadline; + TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); if (s->wrapped == NULL) { rb_raise(rb_eRuntimeError, "destroyed!"); @@ -212,11 +212,13 @@ static VALUE grpc_rb_server_request_call(VALUE self) { return Qnil; } + + /* build the NewServerRpc struct result */ deadline = gpr_convert_clock_type(st.details.deadline, GPR_CLOCK_REALTIME); result = rb_struct_new( - grpc_rb_sNewServerRpc, rb_str_new2(st.details.method), - rb_str_new2(st.details.host), + grpc_rb_sNewServerRpc, grpc_rb_slice_to_ruby_string(st.details.method), + grpc_rb_slice_to_ruby_string(st.details.host), rb_funcall(rb_cTime, id_at, 2, INT2NUM(deadline.tv_sec), INT2NUM(deadline.tv_nsec / 1000)), grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call, call_queue), From 4038cbff1a3a98ae8c7ea422e22a9da55e46f313 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 12 Dec 2016 20:36:48 +0100 Subject: [PATCH 115/261] make grpc_csharp_ext compile --- .../Internal/BatchContextSafeHandle.cs | 4 +- .../Internal/MetadataArraySafeHandle.cs | 10 ++- .../Grpc.Core/Internal/NativeMethods.cs | 13 ++-- .../Internal/RequestCallContextSafeHandle.cs | 10 ++- src/csharp/ext/grpc_csharp_ext.c | 65 ++++++++----------- 5 files changed, 50 insertions(+), 52 deletions(-) diff --git a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs index 26449ee5393..0e4a77be81a 100644 --- a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs @@ -71,7 +71,9 @@ namespace Grpc.Core.Internal // Gets data of recv_status_on_client completion. public ClientSideStatus GetReceivedStatusOnClient() { - string details = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_context_recv_status_on_client_details(this)); + UIntPtr detailsLength; + IntPtr detailsPtr = Native.grpcsharp_batch_context_recv_status_on_client_details(this, out detailsLength); + string details = Marshal.PtrToStringAnsi(detailsPtr, (int) detailsLength.ToUInt32()); var status = new Status(Native.grpcsharp_batch_context_recv_status_on_client_status(this), details); IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_recv_status_on_client_trailing_metadata(this); diff --git a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs index 05dda5b1486..d5b87a6c945 100644 --- a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs @@ -79,9 +79,13 @@ namespace Grpc.Core.Internal for (ulong i = 0; i < count; i++) { var index = new UIntPtr(i); - string key = Marshal.PtrToStringAnsi(Native.grpcsharp_metadata_array_get_key(metadataArray, index)); - var bytes = new byte[Native.grpcsharp_metadata_array_get_value_length(metadataArray, index).ToUInt64()]; - Marshal.Copy(Native.grpcsharp_metadata_array_get_value(metadataArray, index), bytes, 0, bytes.Length); + UIntPtr keyLen; + IntPtr keyPtr = Native.grpcsharp_metadata_array_get_key(metadataArray, index, out keyLen); + string key = Marshal.PtrToStringAnsi(keyPtr, (int)keyLen.ToUInt32()); + UIntPtr valueLen; + IntPtr valuePtr = Native.grpcsharp_metadata_array_get_value(metadataArray, index, out valueLen); + var bytes = new byte[valueLen.ToUInt64()]; + Marshal.Copy(valuePtr, bytes, 0, bytes.Length); metadata.Add(Metadata.Entry.CreateUnsafe(key, bytes)); } return metadata; diff --git a/src/csharp/Grpc.Core/Internal/NativeMethods.cs b/src/csharp/Grpc.Core/Internal/NativeMethods.cs index ce38e370936..2f377071f79 100644 --- a/src/csharp/Grpc.Core/Internal/NativeMethods.cs +++ b/src/csharp/Grpc.Core/Internal/NativeMethods.cs @@ -128,7 +128,6 @@ namespace Grpc.Core.Internal public readonly Delegates.grpcsharp_metadata_array_count_delegate grpcsharp_metadata_array_count; public readonly Delegates.grpcsharp_metadata_array_get_key_delegate grpcsharp_metadata_array_get_key; public readonly Delegates.grpcsharp_metadata_array_get_value_delegate grpcsharp_metadata_array_get_value; - public readonly Delegates.grpcsharp_metadata_array_get_value_length_delegate grpcsharp_metadata_array_get_value_length; public readonly Delegates.grpcsharp_metadata_array_destroy_full_delegate grpcsharp_metadata_array_destroy_full; public readonly Delegates.grpcsharp_redirect_log_delegate grpcsharp_redirect_log; @@ -237,7 +236,6 @@ namespace Grpc.Core.Internal this.grpcsharp_metadata_array_count = GetMethodDelegate(library); this.grpcsharp_metadata_array_get_key = GetMethodDelegate(library); this.grpcsharp_metadata_array_get_value = GetMethodDelegate(library); - this.grpcsharp_metadata_array_get_value_length = GetMethodDelegate(library); this.grpcsharp_metadata_array_destroy_full = GetMethodDelegate(library); this.grpcsharp_redirect_log = GetMethodDelegate(library); @@ -306,15 +304,15 @@ namespace Grpc.Core.Internal public delegate IntPtr grpcsharp_batch_context_recv_message_length_delegate(BatchContextSafeHandle ctx); public delegate void grpcsharp_batch_context_recv_message_to_buffer_delegate(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen); public delegate StatusCode grpcsharp_batch_context_recv_status_on_client_status_delegate(BatchContextSafeHandle ctx); - public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate(BatchContextSafeHandle ctx); // returns const char* + public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate(BatchContextSafeHandle ctx, out UIntPtr detailsLength); public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate(BatchContextSafeHandle ctx); public delegate int grpcsharp_batch_context_recv_close_on_server_cancelled_delegate(BatchContextSafeHandle ctx); public delegate void grpcsharp_batch_context_destroy_delegate(IntPtr ctx); public delegate RequestCallContextSafeHandle grpcsharp_request_call_context_create_delegate(); public delegate CallSafeHandle grpcsharp_request_call_context_call_delegate(RequestCallContextSafeHandle ctx); - public delegate IntPtr grpcsharp_request_call_context_method_delegate(RequestCallContextSafeHandle ctx); // returns const char* - public delegate IntPtr grpcsharp_request_call_context_host_delegate(RequestCallContextSafeHandle ctx); // returns const char* + public delegate IntPtr grpcsharp_request_call_context_method_delegate(RequestCallContextSafeHandle ctx, out UIntPtr methodLength); + public delegate IntPtr grpcsharp_request_call_context_host_delegate(RequestCallContextSafeHandle ctx, out UIntPtr hostLength); public delegate Timespec grpcsharp_request_call_context_deadline_delegate(RequestCallContextSafeHandle ctx); public delegate IntPtr grpcsharp_request_call_context_request_metadata_delegate(RequestCallContextSafeHandle ctx); public delegate void grpcsharp_request_call_context_destroy_delegate(IntPtr ctx); @@ -384,9 +382,8 @@ namespace Grpc.Core.Internal public delegate MetadataArraySafeHandle grpcsharp_metadata_array_create_delegate(UIntPtr capacity); public delegate void grpcsharp_metadata_array_add_delegate(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength); public delegate UIntPtr grpcsharp_metadata_array_count_delegate(IntPtr metadataArray); - public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(IntPtr metadataArray, UIntPtr index); - public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(IntPtr metadataArray, UIntPtr index); - public delegate UIntPtr grpcsharp_metadata_array_get_value_length_delegate(IntPtr metadataArray, UIntPtr index); + public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(IntPtr metadataArray, UIntPtr index, out UIntPtr keyLength); + public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(IntPtr metadataArray, UIntPtr index, out UIntPtr valueLength); public delegate void grpcsharp_metadata_array_destroy_full_delegate(IntPtr array); public delegate void grpcsharp_redirect_log_delegate(GprLogDelegate callback); diff --git a/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs b/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs index ea7819d7b1f..c1560bc8bf4 100644 --- a/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs @@ -66,8 +66,14 @@ namespace Grpc.Core.Internal { var call = Native.grpcsharp_request_call_context_call(this); - var method = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_method(this)); - var host = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_host(this)); + UIntPtr methodLen; + IntPtr methodPtr = Native.grpcsharp_request_call_context_method(this, out methodLen); + var method = Marshal.PtrToStringAnsi(methodPtr, (int) methodLen.ToUInt32()); + + UIntPtr hostLen; + IntPtr hostPtr = Native.grpcsharp_request_call_context_host(this, out hostLen); + var host = Marshal.PtrToStringAnsi(hostPtr, (int) hostLen.ToUInt32()); + var deadline = Native.grpcsharp_request_call_context_deadline(this); IntPtr metadataArrayPtr = Native.grpcsharp_request_call_context_request_metadata(this); diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 618522a3b50..12c747b8008 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -73,15 +73,13 @@ typedef struct grpcsharp_batch_context { grpc_byte_buffer *send_message; struct { grpc_metadata_array trailing_metadata; - char *status_details; } send_status_from_server; grpc_metadata_array recv_initial_metadata; grpc_byte_buffer *recv_message; struct { grpc_metadata_array trailing_metadata; grpc_status_code status; - char *status_details; - size_t status_details_capacity; + grpc_slice status_details; } recv_status_on_client; int recv_close_on_server_cancelled; } grpcsharp_batch_context; @@ -178,21 +176,17 @@ grpcsharp_metadata_array_count(grpc_metadata_array *array) { } GPR_EXPORT const char *GPR_CALLTYPE -grpcsharp_metadata_array_get_key(grpc_metadata_array *array, size_t index) { +grpcsharp_metadata_array_get_key(grpc_metadata_array *array, size_t index, size_t *key_length) { GPR_ASSERT(index < array->count); - return array->metadata[index].key; + *key_length = GRPC_SLICE_LENGTH(array->metadata[index].key); + return (char *)GRPC_SLICE_START_PTR(array->metadata[index].key); } GPR_EXPORT const char *GPR_CALLTYPE -grpcsharp_metadata_array_get_value(grpc_metadata_array *array, size_t index) { +grpcsharp_metadata_array_get_value(grpc_metadata_array *array, size_t index, size_t *value_length) { GPR_ASSERT(index < array->count); - return array->metadata[index].value; -} - -GPR_EXPORT intptr_t GPR_CALLTYPE grpcsharp_metadata_array_get_value_length( - grpc_metadata_array *array, size_t index) { - GPR_ASSERT(index < array->count); - return (intptr_t)array->metadata[index].value_length; + *value_length = GRPC_SLICE_LENGTH(array->metadata[index].value); + return (char *)GRPC_SLICE_START_PTR(array->metadata[index].value); } /* Move contents of metadata array */ @@ -225,7 +219,6 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_batch_context_destroy(grpcsharp_batch_con grpcsharp_metadata_array_destroy_metadata_including_entries( &(ctx->send_status_from_server.trailing_metadata)); - gpr_free(ctx->send_status_from_server.status_details); grpcsharp_metadata_array_destroy_metadata_only(&(ctx->recv_initial_metadata)); @@ -233,7 +226,7 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_batch_context_destroy(grpcsharp_batch_con grpcsharp_metadata_array_destroy_metadata_only( &(ctx->recv_status_on_client.trailing_metadata)); - gpr_free((void *)ctx->recv_status_on_client.status_details); + grpc_slice_unref(ctx->recv_status_on_client.status_details); gpr_free(ctx); } @@ -305,8 +298,9 @@ grpcsharp_batch_context_recv_status_on_client_status( GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_batch_context_recv_status_on_client_details( - const grpcsharp_batch_context *ctx) { - return ctx->recv_status_on_client.status_details; + const grpcsharp_batch_context *ctx, size_t *details_length) { + *details_length = GRPC_SLICE_LENGTH(ctx->recv_status_on_client.status_details); + return (char *)GRPC_SLICE_START_PTR(ctx->recv_status_on_client.status_details); } GPR_EXPORT const grpc_metadata_array *GPR_CALLTYPE @@ -322,13 +316,15 @@ GPR_EXPORT grpc_call *GPR_CALLTYPE grpcsharp_request_call_context_call( GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_request_call_context_method( - const grpcsharp_request_call_context *ctx) { - return ctx->call_details.method; + const grpcsharp_request_call_context *ctx, size_t *method_length) { + *method_length = GRPC_SLICE_LENGTH(ctx->call_details.method); + return (char *)GRPC_SLICE_START_PTR(ctx->call_details.method); } GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_request_call_context_host( - const grpcsharp_request_call_context *ctx) { - return ctx->call_details.host; + const grpcsharp_request_call_context *ctx, size_t *host_length) { + *host_length = GRPC_SLICE_LENGTH(ctx->call_details.host); + return (char *)GRPC_SLICE_START_PTR(ctx->call_details.host); } GPR_EXPORT gpr_timespec GPR_CALLTYPE @@ -403,9 +399,14 @@ grpcsharp_channel_create_call(grpc_channel *channel, grpc_call *parent_call, const char *method, const char *host, gpr_timespec deadline) { grpc_slice method_slice = grpc_slice_from_copied_string(method); - grpc_slice host_slice = host == NULL ? grpc_empty_string() : grpc_slice_from_copied_string(host); - grpc_call *grpc_channel_create_call(channel, parent_call, propagation_mask, cq, - method_slice, host_slice, deadline, NULL); + grpc_slice *host_slice_ptr = NULL; + grpc_slice host_slice; + if (host != NULL) { + host_slice = grpc_slice_from_copied_string(host); + host_slice_ptr = &host_slice; + } + return grpc_channel_create_call(channel, parent_call, propagation_mask, cq, + method_slice, host_slice_ptr, deadline, NULL); } GPR_EXPORT grpc_connectivity_state GPR_CALLTYPE @@ -560,11 +561,8 @@ grpcsharp_call_start_unary(grpc_call *call, grpcsharp_batch_context *ctx, &(ctx->recv_status_on_client.trailing_metadata); ops[5].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); - /* not using preallocation for status_details */ ops[5].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); - ops[5].data.recv_status_on_client.status_details_capacity = - &(ctx->recv_status_on_client.status_details_capacity); ops[5].flags = 0; ops[5].reserved = NULL; @@ -604,11 +602,8 @@ grpcsharp_call_start_client_streaming(grpc_call *call, &(ctx->recv_status_on_client.trailing_metadata); ops[3].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); - /* not using preallocation for status_details */ ops[3].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); - ops[3].data.recv_status_on_client.status_details_capacity = - &(ctx->recv_status_on_client.status_details_capacity); ops[3].flags = 0; ops[3].reserved = NULL; @@ -647,11 +642,8 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_start_server_streaming( &(ctx->recv_status_on_client.trailing_metadata); ops[3].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); - /* not using preallocation for status_details */ ops[3].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); - ops[3].data.recv_status_on_client.status_details_capacity = - &(ctx->recv_status_on_client.status_details_capacity); ops[3].flags = 0; ops[3].reserved = NULL; @@ -681,11 +673,8 @@ grpcsharp_call_start_duplex_streaming(grpc_call *call, &(ctx->recv_status_on_client.trailing_metadata); ops[1].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); - /* not using preallocation for status_details */ ops[1].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); - ops[1].data.recv_status_on_client.status_details_capacity = - &(ctx->recv_status_on_client.status_details_capacity); ops[1].flags = 0; ops[1].reserved = NULL; @@ -749,10 +738,10 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_send_status_from_server( grpc_op ops[3]; memset(ops, 0, sizeof(ops)); size_t nops = 1; + grpc_slice status_details_slice = grpc_slice_from_copied_string(status_details); ops[0].op = GRPC_OP_SEND_STATUS_FROM_SERVER; ops[0].data.send_status_from_server.status = status_code; - ops[0].data.send_status_from_server.status_details = - gpr_strdup(status_details); + ops[0].data.send_status_from_server.status_details = &status_details_slice; grpcsharp_metadata_array_move( &(ctx->send_status_from_server.trailing_metadata), trailing_metadata); ops[0].data.send_status_from_server.trailing_metadata_count = From 5b7c5f52163a23b06bb0d329b2544e6c5fb1d521 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 13 Dec 2016 10:48:21 +0100 Subject: [PATCH 116/261] fix compiler warning in hpack_parser.c --- src/core/ext/transport/chttp2/transport/hpack_parser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 3c7d5e83104..5dabe272d39 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1511,7 +1511,7 @@ static grpc_error *begin_parse_string(grpc_exec_ctx *exec_ctx, const uint8_t *cur, const uint8_t *end, uint8_t binary, grpc_chttp2_hpack_parser_string *str) { - if (!p->huff && binary == NOT_BINARY && (end - cur) >= p->strlen && + if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && p->current_slice_refcount != NULL) { str->copied = false; str->data.referenced.refcount = p->current_slice_refcount; From 0e3f1f1e5312b9d20b97642f5c81104ad05a370d Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Tue, 22 Nov 2016 12:28:14 -0800 Subject: [PATCH 117/261] Support compat with old generated PB files --- include/grpc++/impl/codegen/config.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/grpc++/impl/codegen/config.h b/include/grpc++/impl/codegen/config.h index af3ee5a4cf8..a43bf65f913 100644 --- a/include/grpc++/impl/codegen/config.h +++ b/include/grpc++/impl/codegen/config.h @@ -39,6 +39,12 @@ #define GRPC_CUSTOM_STRING std::string #endif +// The following macros are deprecated and appear only for users +// with PB files generated using gRPC 1.0.x plugins. They should +// not be used in new code +#define GRPC_OVERRIDE override // deprecated +#define GRPC_FINAL final // deprecated + namespace grpc { typedef GRPC_CUSTOM_STRING string; From 3cadfb152fee3160be689ee4545e15dfcf8ebd37 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 14 Dec 2016 07:52:47 -0800 Subject: [PATCH 118/261] Started updating docs. --- doc/images/load-balancing.svg | 4 + doc/images/load_balancing_design.png | Bin 40354 -> 0 bytes doc/load-balancing.md | 128 +++++++++-------- doc/naming.md | 49 +++++-- doc/service_config.md | 201 +++++++++++++++++++++++++++ 5 files changed, 317 insertions(+), 65 deletions(-) create mode 100644 doc/images/load-balancing.svg delete mode 100644 doc/images/load_balancing_design.png create mode 100644 doc/service_config.md diff --git a/doc/images/load-balancing.svg b/doc/images/load-balancing.svg new file mode 100644 index 00000000000..425a9d33aa7 --- /dev/null +++ b/doc/images/load-balancing.svg @@ -0,0 +1,4 @@ + + + + diff --git a/doc/images/load_balancing_design.png b/doc/images/load_balancing_design.png deleted file mode 100644 index 86183966fb88e24a5a86dbd4b62ae2a308d0a542..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 40354 zcmbrmgL_=j_CK69ZW^nx8mqC@*bN#x6Wg|JvvC^RYHZuK?cd40-~0Xp@6+a)$?43V zGkfj5*7{&K zZG~~b6+IMk1yPhhF(-++tI_TtjQ&>PT*2za#KZ#vLmV1!`eLIR4;OD7pF zD)GBd{d`Q_jGZtrIp$xAU_w#y$Wkc`>57^_mWNfd3Xave9Y?k4oJvadnKab0swtTx zw4-=7up090rqQ7|p}{aPzTV(pmq*T{oD6l6KgkKGW{x|I=C?j`U(>DMd!FsP`SBAX z!9aZW`TzZ3j6QJGw1P(Xi#cfn!3JA}Bvs&JCGSc$N+ zbAr`Bs7NRb7CYfJ#1!GX23w}nf9|3d6a&fc92}~gb%8`nW~`BDfGw2xpSv5yZZiJA z8}$wBmtY2l%0u##f@tvj#%ya;-rdGu8gPi*sZ*s@qAnXua!k~g2xT%To3&dN}t3iPrA_%sA#BV~08+Qv_ zq=bYvz8zj-$%XsUW#9G=2S>|E=FHxXVPi-?W?JAi_?3c~Sgvq7Ah-Yt=D!zx_^qLX zhX-`}1K`@l#ILH@)U;IC|1T^vq96mqD}DJ`dWWc=XvC8LjaN1U^8cRl1K;&yg0K^U zy?XirdkjFqiT@i|0G!czG=+)CCM6|@6yoD+{&xod_pyXRO5NF%)3J%aMJxq`%ZAYs z#DE{;wBOrU?P>Y4A~G&k!wuF}$G;8i`GafiTcxJYQYo zI19KV0&kAziziIeELs9xoG+Yz{i2euI%uJX0bNX z`MV@_hM|oBvmbaiKt*NRPCPsv*8ufZEFWJa&l(zUoym5{#lnVDyJK&9OJz=Hdd3|e!L`X>x(>?FEo{3`JzFqk5 z0%w#=Ia;sTUy09~HmgZZ;jhVQ_aYK%Y_1(mC=2DdHhy;!uorr@gNRdD&x-3;6kLh! zO5a?=QI)f^^KJWu5)*#*4Haqh39~chbSQ+G_GoFII@{-!EZ!_e)$TV1V5(vz3>UOL zj^LhBjWxFPvu{9LkXcJG2N@W?*p&{hqZ=foKfKbkcs^yI)CE$~M=++G6CC+@6;%w@ zGKtDBw1N;H7XzeH*{0ZE@1?yepSCR?pj<8&I{LPE_QX`hv25hLs^6}SfyiOKH$WeA zw^L(QT=k~E=akJbZe3ctyEz};yZ9{BUFMN#?)6$_cFN?}Hnw{eA=2ST*uAUXFCxhF zWmO~%aH4zRD8|7_vo{<<#l%2bfO#5mST!e68n&qD(2)8JAlov|4N8r7uH z71^mHyxFE$<*_?($n>_NKSe^4M)c}|h}L;QSs6Adg8ef)8YMa>I!3H7juF6b6c#&D z_B|CDEDW89Qv|1 z9UXVUIUZQ3l?s%DQiF!49l0MXR~3#tO{mcq>Y+xjOXRMUQ%Fq6$=$Ejl&2jXj`brh z_s9JQ8`EP#+>ekhmswt=WJf_B+%NyE!;U*DoegvAR!8k$GdOI0&R&~qdlUu;D|w;% zz}G*C{vFNA@ml17rx87paaX0ENd4kg2m$dOND{SwKTihLR4*iD$`q(cdxybwyL((Z z*faAvU0;1%G}R?iV#Lx+&j`7>?jBuR12z4tW@IHJx7%A{;l{=Nwq93)q#7a4Mxefy zyxWDNty!+zu(<~;TeWDaRele1O4`{f_v7Cf?nzy-^B&<_8y(BGAsq4psTnT7%y}24 zv0!oRy0_7#p~G?3INzd2l45S>$w$X1jA52kAhj?@TV~`z_bxKSZ|{-D#VE)Ct3X21 z;o}WjZ;qw!jnsG=rB>%X(y>pOcqb+JR7TUxQtpSiCaMMwXLgHwC9OA$q_`(LHwWhZ zXAeJlwPJc3ftArZz1Y~6-?4Xbgn6h!33_;5sCMweBB&V98?wf1_Z;od8Q_S{-V2*m zzBn)X&OC9m-&1T*vyv|FwE$3Z6doTa}LIDDF9is z-Z2orNmsg`lswC;@NYtW)|DA~x#|(%1i4RR8M9r@`+h2DYdd3U~ z51fYs%PTYXI8`lIr~sKn8z_9Sah?$}KKLig)({r?i9y=mEaw7Xe%z%%)5x$jH4(J& zFC9vear2D`>HNkt^CP>fV;}F7J+~rb=l0&X0NbwRyZdg#{=}Y7YQWCE%%me#6avOs z|Nd2Z$`%%XA>sfXdSINcXKpMonDQ0o;1s&EJONsq!!ac1MbFdKi|MuBe~PqGzpUSe z@r_%-ObAka!EP5KTi^&qLz`CZmiZ$0?cGLfH8ko|7VDqwsQ)XdbzfqB|CznIT5Eer zO%KnFfM2s%s@#2X;eAULcu+vM!he)4(36u?^ zCm6fDb%)vCRqvkkY2iM!a|L-Fb^Y00t&$&jI4Pti8#daBwPS=rwke-Rg_->o<=z)pJJ zS3dmu^><7)X)>O+dud@Pb_)kESrvEZ@aK#f8mYE9`RVBpI_GVO@~^&BVt!^rODMI7bxdF z3knOx@$3y1>(Y$-)%IFg&3nMY+d4hhGP_TPhT# z|El`&%fqRcEl1N)>cYdUWnxDSato`3FEr%mi`y{1>*oT#@L>&^_J4n9Vcnlb7)vcm z4{%pP(ue0Cp58slSj4f#whp$u%QE0?18|j{jLc6>y*P%Y1`8-UlFR?_(%#mVOo$e* zL3j#ai^EKy9{9ya?|6RK z9zPvf!`>hK*){dbew~cs{5wrY_R&d?2ug#VAv-OWYKws~q`)V?D#?*Rec;lFf5dTh~Wi?uXaH6^St zts@Z1D3)s$Nt8(QMR!3-o(3Juu~zBe{BiZ8t7d(#OWVt-%1d?BGNeo@zDc8cF>QyQ|f}=ba zmBo(xYbqia0>;H{vw0kDi_ag6WG3NI%hjS)h=}pAU1$ng%59*n#(Z zQ7!x?nVWW)O6+Z$_{di;)A?Dq##kXlO;D>~Mo>|;nDkuYlM#aUhV_k&Z#Q_j_<=H= z7AZ*Vei7xxFAT^33Q9e7h(YnJKzj#^-&bvhWt6^ir@9e;j_A*d%j`$B z;u~ob%x`!SKz+X0^B;fImqlq8(7Fk04chS!Ln~onllsed+kplY%gVYM6O%%9*$wm! z`q=_a$gi(LvY&8#U}yJQz>}iQ337VT-S%@;sAFSctZg<=pU>H3oaCq;^$vdhQ!djx ztkU;)ag_&Bn946C*_)$)gw`Y8A64pXTHz6-b-%DF-O1>q^f@@V7fUb!MAEmLi3o4t zCLvLSsRs1-FUj#cVa(Yi_2MBk-QBMutAQCS7Aoxh%M^|BQ<6>g`QhE-!s$|!RR@LW zCss?lyIbY~Mj>?}VoWfw(kTcn0mQ6rxM<}sOrzg3+H!G!(pBFx;!Jlel^i2Hbo#u zpB!EvD^;JCAR@_;#c9_{8eL?L5PysJIgBYEdHo*ICR)LC!z&6jSFF8z*E)Qn+jk#t zS{$CsX$vfgLx(MthCFZkbhkA&>(6fUBjrq2Q;PW4+S^&3qX8B~Tyu8MLL0lWp7t4m zQ$;U@;>eP--dtZAp9S;-)2_kv*^hu66JeI9Q$BG1cZPztpZCI0s5PvacCeVRAw?*G zZGRmYIGc;CEziZOp7u^vW%@F5-BiLxWW}NT2uW+aaxs;oz|V>L=L)!EXsHO z=?DsXteF}v5f-Ykq-wNhbL4!Exib$PWs7936}tKJdF|n-n&AkPAB~J{95p2(^J&jh zJ&mXD}khi)&aiOY`6CU}%+JhIEcSSXSA{ zUkA6vrYT11_2Ut8>S~o5rYI}6or}{z+;~=7G6aj^emkx$9r8kc%@DtgT>%IvpOhpk z4kD+kADCLN#2GAH*WZBr;P&RU`b`+37^fa6R6y?ov=k~8tZfPFn=&1(pNh+NKaY!# z=bm3^8BS|*r$_ky<(x(Bo|ZAH-s#QyXd|EtR2|z7*pBeyKrT%`BaMvMYFcU8tT1h- zt}TySzU4>&$l&&@zBKF~Hw)PNedo_%3#Y}K-hWGbcUDP2zmSL9($k}ca-GKU$p5|a z>jS@6nMV$$hTyHQX105jdc z6zQr*_q&|LtXx|ghiW}%uftDsYr<+)QjJVN+*V@O>R;7{AuY{}^iK>+9xFSLGd}Yq zKUQ42ziy3}IvbIU)2HfsMmBS8Ye%gRuM^Uv=*!6E)Tgs+YbkZ9N6{3#3;qdDLD#jx zdHchAqUsQA7lL`HFTnoU{e6!fK+M-$Y_e-VV%7*(wBF7r!>&)3C~#ix*^{i1xe}_o znz_>mZM^e6H+lFg)aDkI!XBE{g^ts^vyy;yHo0Gcf(Ap zlvIu=2>~uaK;Ir*!w>JQJXTfee+&}3hMX_sue)4pf-TPQ| z{3fcKiS3lN)V9-nd)YlH+&h+qpjIn6AT_wR(9Xo(!Z9bQ<8WaT)SR7sRsBT+*g9EL zv5X%>saxLEeKfkO-Oa(MH6~2|V{B;O!k`)(bxMAHi(4*syvDr6bs9r>mOzW(yOeDjEJKbN8){B_3QgWQ`0zY9my6c+_77+YNh;{0vgy z)le@sp_jJu(TeszEPeT6y(FKMkr+oO@OLX9rR(%PAWkRuL3&JKkn7 z;ry}2m7D}+_Dqd`03vaSyukUk6ex4XN~4nMQy?`wGFiX@^2#^>cqhnrm3YhgS0GnK z$7n`oA2M!LSu-kBt6mQ}&Or9=7-3#*zrgpES3mu@TZ9I3wK4OzHgtfeJK)N}{GcG< zwNFYDpMOi;T!EXvvO)nQp1xiaDbV*NUtLiE13j9a$)@v>!3qONM*n&IVs|A$Wm$y* z80^SF>Xq29s;)+NHb^~UvK=5ZviMepx@ci*ZGNxLI4M%>#B0n)$7L#;QDMT5X5|9txl&axE>;<)6e0)GVr3 zUe>+X7PXC^?;u*5s)#8Eg^YzY8#~t|lhiby)mKl!RjyJIb)zzv#SOh|HMrVWqeok1 z>8iGMK2dQ&2E~Q`N>W6bEQGHTEeD{)OFd7iMn@j8tN1cHOhJutX*}B z=XZ+dZ|tU=(P$)!U+jGU=Zi=2OBuzfG#G(yt`E0zuv_CJh5#a-pgx3n_4}PJ5kssC zF1Y*+8fm8YMobxlZa6QgBZHyYXd|TRl-*ux^r}pG5nWrS`t_}=pvl;`AP69C6twY2 z3rOAAD=#SsN%Nh)l)j%E7RobT25h>&_tBR=g1E-rnQs##4f>Ats}v{~Tiz;FtKA2p z&qka*PT)y?b!~p)zP#%$eRn4h%Y2>$Wu`U2)nLe!Pm`B$M$%Dby51uzwbsOVNk62s zmQ#gZg~d?sjHt0M=5fn<#sN=R9xn{NwV5} zDJ}$20WchoFYaq$VcSVHMu&6tw4&A312j}y6cQ5*!?hIR}5qK$xl-KA2pLY>IN+C^O=g z&QW1}Wi{LLb+}X7I>_FrVmQ6HWq!rCZ3?$RwrB##%@}|?VIv@=mpbnB-EWnuuc(cg zU&OfGB-ZMdmhNAsZSw?im>u zUuuAK`GUaZwP9y`4>I?zZIgaI%R9pfP&iwX~aW z??|10fgwsAk2e|-WLrQ_$8vZItU=sd3htU$U}m(F^`GpW{(R{6IQX{VqaBUu5qJxl zdXLES=>Kaesq91!K+)7X=~0W8=VoN=$&Bo`H~XeSRD{R^dYXLU{Ez2&Ei7YUgH8Tn zf#sV|T3jC9s@`nYt&n{CmWP~QuW!uPI8+(2{+urBKj5?Qz4GuJZk>cj{Oo!t*E~Eq zkunj6RF;%DI6fQ0d40yoRRQCTjJ&zO$&)W65iIKyE(RG!;kV*r1ZKsdmODD$7|$c9 z2YklNj}>ip=FTv%rE>I8#wb=h1kfd9Y}11fex1{N8q$#K^lx8H<*6HuQ$ zcB)tKY!c;Q_=@ZU#REtWuooB?j(Gn}iGRTV@P|B7d$VNF_R;_g5$g*#i`FPN(`+Y# z`{o5S8XDujnSjj{F%1yBE=EVnU(;;7a?vC(R`7B>7y9oA?&ch5DPlw(Bj&>*@1!4= zOiGV0WOXz>%DbD|+?X1itZejPM-Rc3abb+cWp;Cig(R!K-}DI2lO&=)Ux;hqR-A34uDnHJ*cg8oh3wLmgJ7f zVbG6mhA;`7mkDb|fc(%%O!M?wVUUB}NL|Gk7)kTz|r&W^3TJEGH6=iEyqT;=cdq5l91 zARrl6DT1Zl5Rl4i4U&lU8sM3_{9^9iSq;WnnLzKfZR-pbJ~~2%u?&ivEf4Tf+y&j1 z3WC~J|1I}SIV8iqm?9}Xxkd8-A_v%qlSb<I>+Ba5v+df&| zIfgfQ<;24K_z>LQi%-xStZkj2*{MBE1;FjVoKcJOA_y+HFK{N*H2tstY6hK&VPLrV zccRRw|4+R7(a1a8&?u%PoF56_p{al15!uMO+En2LaAQ-98H@JHH6Nk*6I9mB0fE5$z^9D@=JRGMxh|w~}Aw z-^YRzgcoJ6T()QgP;LD2FU?<4sy0|k^-Ao`MM%uB@;((e1PO0TSh;+%>Wp=oK~4$j zTY6zE;LB7A>??*uyMTUG)llCjyvPXMfR>mbr=k{`*48#@RZ`TNZiWpXSzq7h8Yb<7 zL0-+P8q+%m{s<@owxajXJIlp=oPI2a0Ez(0Awb3I=&iYYFAkpclI;UH|HfS&Yx$J4 z8mvUst7gQg$WlfzjTY)Cpe~y$85RM617KRxCc#Ujuo75pMYz2J7xI1BXe3s{A(a(& zsNtpqiG?>;%%s*Qlc52L1l^G3tAMSY)2;PKtN+!t(Uefl_MdQja?L+;mxMT;)7E81 zkS$*rsdeND_gLm{n>=#mglT}dkE|N!<+pa`&*(S4aB+28#nmun5H34y0XR74XD6MW z?M;ZAcDvh-?cBGW!h2SnsKpCB3LGwJJ|H7ZOgEf zu_b7kz*v3j8mZ0HyyWS)4N8+vC(sv%F|qb>fQ7oZNHicN}aH*u{p-Jd@L{OzNT zD%l5@rf&6`X%-%3JiO2~#-`i_umlEq5W|8Ci!Ugx}31So@t_U zBy+Wadl;pImVG|QQ6z0dZbYKBVXF-l<%ZJWxZyngMkRxKih|vIO<6~(VO`Sz z!GHOoZnO~osg-G$+VRzXf+F>8Ax;S3Spr8J*Gu{BfEmo9Ci-iqFCajuuhRSqsKX$zAV2H-Ydp z;!=RT9b8(_1+Wh4_xm*u=+|jxK)yH-4CujA$fYa(zObGdL||-I{rly}jbP#FbwG;#6P5pGo;jY8v6|Egqj%45iRqhA`|&p(WGos_P#INl*c(#%xyr zC}uX+^+pFXZ{Nwa0C85iVju>fk;~6y02;A;{>}W<9OmG-fAiq4trLUUwvD|UgQ1fD z;+1VcdR0x3t@%3EQ0Q>>C!s{r6Ge%YR!s`}60Y67i8+WFNK&8(k+?p3O3Yw?$ijMi z{54xsgRq#34VyoNAA13~g3L`3{igrZlosS+{*D!S%GVt}-;Z60zE}Kc@f+8qFu$B= zozN<9^qY5v#9%wTD1bW+ha_{Q>fVgcqmvxd=q3z_oXTQ4IlsO;S4Nw)8Xyq^X~9T zn|(-5=$Aw1*B9%Wie|(-3=CUl>M-5*c5^A2J$FxDV2IHc$GpwAd3l+ktlYfjEEY&1 z03GVTWsU%X2|$Rjpp2niPZ=d0aBY7FV3CynLY$Sh&Pgi>P+M&e8dFoO3VvK`Q;vAP z6E7p|tj}F?EDT~{ZiWMJ(?@7}r3^ryt*@n+0F^%S%zPTS{N=8JoTM;aRtfZnayoVN zUALWJnfIP8jn~$j1hy~?&}@;Ns zR_O}2#^YjQr7yBOIg_}&PEelb2n+|q__l#gw2k0I+)x660O6CW8&zG(J>Gw*r zb83Az1bl$ZQ**a2N8@HDShn1r?j8WhA=vL@!z26M{YkM%ZW7wRmXie4Q65g3cH@(N zXWLe9clPBPcFexPi;BrKQa~tClhzak1I5pGb>(lSoEoj&-HGnMz6cr~$8aVWmydWP zcszfrvc%))?X9zwUPb9 zY>{}q|G0aiy7zX6!&GmP`%~TFnKM1XU}bN!l*X~3fYEGU#?XA-QtE)7ihjSUh@!x1 zxvye>%;xIoHvqi!50>h1$Nmm2bEhWshE-LyHd_(AKfO97l9N{LjPnV9FQG*CsPxA7 zbTpL9cF8KRVJ{x|Zu0`@9)ND9ztyM3>jt z<$1s9z1+6nL~q#8{Q!!jih(r?Amq%~(zJ~lHi4J2rz`gO0wU}E5KZ8X4M?Xbv@(@l`XZ&v?MUnroa>bA=Wz`CSN!HKx2LIQt#L|=h`v*u>v zny)~4r_E>Jn8&8tr#!}CDD!wrP*aR3Fj>1>#X-C+0lMiAE`XIWZ#eV=cfs1F#5Ur(gFbo* z!yx|)Pj_xNdd;mYUEMzYVHzsEzIqGpI(=w2GFjFT<6Z+$rQQt1(&8e^;yU$6w_m@X zue_I(#L}{G_9;gu0Uf!m^dPnMHCnKPU(}oliG-Yhkxp=gjI_>cuQy3SQEWck=di3*}KBXLO!~q10>D9&U#yj91wkj^$b`#p$aKQV2s~GPBip zpit%c4aOI-01Hb&gQd*-ert5Wu+8AK1gCR`nFP)8}e{%ZLRa>{b^*SeO2lkFQ9k%wYH_* zoTKj@iYEt&9z}_ZSCxr?434j(T34i=^H9gpj(a1*vz&HP%j2la;;fsKkzX^!nly$0 z>e28YNa#HfaejU!=#yZ>CZL+=treP-Iv3iNEgx*?jsD|UqeT7;6~l9;E)qRT(0bA)N=Vlr&8Of4m`Odcwo<1)+IAIjBGcJ>S`ok`R? z3v~=piuE?XFaK?&^mV*1#PwV`vBo-b`u$Ppra9AJ2!B3Ys|XAEcDS)^N__P7SsoK@ zy$b3S_zgvuF?hhh%0lOLe-h&M+!T!=@#5sfP|i6aF+L_sQ%vTG<<)bfWXjpzF_)sl zbG=TetZR0an@aO_0cfkbeIi6T0A&oYU2HYHivw+)1Aa&L?#1rJAF`M<#Q z2uL3p-Mt@9y#DdJoC-z5jVpD|&~KZ^nexglrSP?M$F|+`LO@^fZ*4V-dVue(k+er5 z{Avj7;v(5}iBnWPnwtN>&}fp7ptKo;VEYu{IRi?yn$jbw8sKB93(W#3MtH|`Bl<*% z80M^{mLpR~oMv_^%f?l}U~_ZTpg#w}#t3-xZnE}2(m9Z@Q?Q~r7Y3WsHObD*oeBW{X|!ipVXOATzn!WU1rAx zWxhjO0V5rTq*^|v{7$bqj*p#MyC> z?4Pol;rS5N0b7tNGi8L9jW)g zW&@Q1%{I(pK`N76-J8J2I&aBRPONtvUUrdPC-v?9)Vt%;arDp|Gy0tjER5LK>kF8s zH0a6s)eKU8Q=gj^XFlFcf=Gh>KXjVO8|ShO^%j?w(;v=OtVYw{Wy^zR3 zNs<7|&o|UF^GVk~oU@`hZ`ah*_8DiM5`bpz89Btlr37x0GNm3lB%_P5*b=L}mOaTK zkRkQS@E~A@d1TmS#gQ`mPt@K1!P$2}Z2D;;j+H{WSnBR|EiLSY?_uy2Ncvf8>+XWj zeoKvBD{aotE!Wr3>W>x<=~c%+=$W#Bf0WW2p@fn?2@~DFV_Q)=8XN{ptjy1feDx>} z#fvYR)QHu`h3kO#lqg$vb?qmhiJ3p>k*j&cA4c(rr-$>6XNP#?H@xtA+FzLT_fJE z5eYV@1$P+w|9O5Ed|j{N$M~hmV0zdd?z>$P`A~Qj* z>BBA@c|c7y3Gfh8Mct~XdAu7gOq@Re{^BFJ|JB|1t>ux=>DroXZCP5j=!}x80D*Je za-geA#&R-v1|`t4J2l^x(`}KFY$c`a`8wt5$Yt%RBx$lkQlY@$wA{?SmKar*%`9+! zfLwCUN%^i#;Jfq$;RErkBzUqUi9-zklb>^5_@m8UqD0CASlm_g`%#*V$9sR_ zqsC6LShqcMlFp6pWuZr@|gtd!wHM;Q*42>&@}M5Wm42oLTcx zsq2{LH~y<2H>vmY^E#UIuiW`jmc{DF5yUlt6O?78AS+i+$tb)J`ub9{1v^(10H}Rp z$YQG&=l%WjO&)?tTGC-bW&7he*G-m*17jI3fGjO68fo28SSSZ$$>Ws?;F^)sRU9@q zHxY-kk-K=bxh$UH9?RA6b*ru}zY}pu{YKvYQV!&#n65}TO!pY#x~j6DpikTj<1rQU z1`65b%nVqs06+w+piGYm*EjIC(MJ&Y)LRl-O^UH1^uNdu?KYilVYN#WMNT-1(KH6B zjQ~3*;H4|Mw+VNDEA2hZXfuBV2FPeT${N-^U}fG3$9lMf*T#R{cX8~;tmbM*B2V}X z=s)41y)7=GJ_Xj(rOt&{R z)?+JivH+G75ZhYD+!u>8w1szvu9xCW2;~cRG!iI9lvUf+l;2E4Od@%_rgFvU*-npSfTKy5;^E24=O98;4cMM z>Y&F3)v=(efN|Yu=`|c_&=;{?`~3KB7N{E0lzVUF=?Cag(^^>iBZU&2$ut>!vm?S* zXf9RtRgB`+4WO7`+5q2VX#z?Q3$kk)kvPT?Zbk++YWAl$HjRR(0}080)y>Ier(8gW zHnPdfVQ`g`@0(l|?>ieZl!4qRj8Z&>#sI6p%9I2210O}xBTSuOPpxBQ<<(~7JzYz% z6CI0)id+)#*4FS<8!I_J|8?HtrXOBw~1>!5{;r`(GU`=Ju*<5E4_LB_$>C5$n4sdXXeJK?R9M{4E zcxS`lCBpSBsq57Dk4-#SqHN=2z0ob;m%LDxHfc9Jx|TVLN><6hkqU{r;f04T&-MuWy8h_;30=+tOHd}!=iH~z2f0idgw;H583@hkQ2p(d z!JZO3S-o3wSh#qnmp4(`wS*pL@6eZtk2SsV$g9G~^Y^?AWVM61 zVH!k6cZE^)@deUCf4fa8ZD0gL^=>OXn?EzKyvaZ)vHm${_>U0>pDF=K^)pem>DA>* zB#o9wz>06E+VGUhKS0{~pabp?9DrN;C0CrA78SesibuQ0#zHPX#X{qmj|y<`!A$L! z&QO#-Yy=N*dyep*1XR$y7#|79%?Ecm< zpfLun?JsPJti#&O9zcA~I(UCC4S){epHM3To10;zmwQKsQG+Ko5hQHniC0`?c~R*H z7x~YLyYwH3i1>(KBp~m;0LQ$TdEsKNB*s433E6#|K7+$h&CG0N(c!1My%<0Nj*vC- zh!8e4;hbR4AM$_0G!I(D0t-hfns9(gqp(v;fo=BB8rS0!kIxQ#2oN(JZ)nPyQ@UTDX5I@F4tQ~7RqG& zdU{R*EiCQTF1ET@+dX(X8S`ipX7du4@UkfFfm^lR`S;VNxqpGU-TnUrai>aVX&zNy z5UcCwgD}OD`adpEl=CGl+Xy#cuAc+-(n7@i;4PpNKbPHl!r02{iZznF9SX+DZ;@2@S*k#|am$XQN(in$eX#Pdm$gtMw^z`20 zkH&(`9A2pg_8lBnOzE4Z&lUD?TLorapu~`ePm~!=?yS}Ms_F7`A!HXBQmv`Eg+;Cd zr>2KC$~#fqApS&H4MWbYWu~iW^&RaS60>KkJ)ZA= zq)6Sxi{z$+GCM=3NGSnwySbUFFtp;(?v*NMhNXr>TlOys5in}u64ufI#+~5CusxI& z0iRhk+qi$xC>H|NW=K}n@WUo~bZxRXYPHZowtw;h7fo~cB7EF$#TN+iN{rt(nX zqT#iuwR$w)n+U+#YwGG&3nq=}h|n7=T)AQf?Kv}KpxhbtdV*2q?JdiDmhAxiPG{tx-QBLbGaePVbe zcK`TcQlwgyoZMV+r;`PSu_^9+`6l^dMaS^)aQCw2&ZT+_^(;4c_LxJ0P@eBDq*JYMLKe!!bE>1~Ok{=Y|=ID(_&%D_R}{<5PuFn)atwjnjsr z6t0|!ce8J&H}E>nzfJ_Pa37SYRl zAK6n9a0foeG{4WdGH@Y2l&1cAf~6$F|87;iRODHc1)29*!P`AA&$XKuUo_P87HyQ? zSUen;;|dq4WY$!ciT4w)4C<( z#QHzehxo{}+Fn93iTu9;65e!Ipeg^jrW(gWkwOFu9DU}7mg;0SqWZP|wt9=``{Q-p zVKRftPbfi4@pmD4ETpLHYwLySXBk4{EA!?0QBATqo`PQ#th3e{9i)1Cdhw*Bq^BYg z*a=$t&8EPln|cEifvkex1m_KT?<9bShz=YiuHvV!lrOISio}e&e`AsM<)zn`kQ3ft zo`v`##nrr~8Lo~rt`3#oONU_!#v}%Y-uSAgr$;3rF)?z^v`%&yR2}1;pj2WZ`kU>E zmI*X~1ds7$83zKxTc!|)K5iD@uWI9s4hbkcMR9+`Tm;a?kW1Yszr#mj4}PnqqYj_J z&N(hK^%6bct5Qs85i8sG%$is~7xK)=9z?;z!z-FK&6+Z1W&(3+n<(a|!mQgitgo|J zuIE)!Qc6W85m~tj3y>m{EOk6xJ#rxDx5xYfLAVI^oiIYo4cu9lSv(HZ{?_-7Azk6z z$Zsuqkg-rmvWtLCMVLK(C^N8oMKC-(oU~p#{1l1D^;SN8$UAvxUwC?Q@}wLkze)q_ zz`kQTMn-uJC$^Aazz0;RNMDHnMi9DZj6_DP`lBfA!KN9Uo_NvTxM!TKQ9%gE>R?fa z84C$uj43qQC9~yFiBZ@rRA(5F%kmjAZ0P)SN#_{*bwGLTTHUb{8{2qR`Uyex;XB5~4W%pBKQR8#)H%QlVFt!kDJsYW)meDrpcTtFP9|tyDPeQK(2Y ze{5G^nF`EEfH8Bb!_(U%sC6=#^lJnbYrcxS)2wfX(0 zu$N~Gh3ZlGoP%BVIk|=NhicRbVhgi}?CB;%!`uin(%>PQ&+wIMi3qVk!bf%aopS-X zVBc|g`dc$Vx}DD)+P}+DC0tvwU@O77#n@Kgg=WbTBF!ZAim_bD5Uq4tC3$_`eYy+( zdDUh5b?^9|p(CdL{oZta`-eP8hOiN9GB-Rl)Rhc4(=DKXPR+^LynlDP93?6&e3+Ay zQ*O21?h*O`nTr4KQgZ?uD`IEQveN8V7+I5n2-x}2`#Xlb++JUGhw%y9(Rd7ZoqS9) zVoPwAvNcnDe0(i zhO;Kt#CGc4^aNe9ai$n1#w*0}l zpo(o+!xJc(y#o&7QK5yJG;HnAHC_jcC1%%6Ko>7mqW_3ZoUU^yyb!_mVT+nmf473D zL?67{mhL&|#u%;WcsnXpq$(s_Y`J0JWhM>tKOY(%o?j_NeLh7&N54&8la%y;zQ^*J z@n~mbWMouI$6^Zt_J$fbl}^H&yY_d8IcX-e!OSkahp)wNI%YjO_>WXSkW420FOIA~JdNY%!ax0lS)DnyczrDXmWZyr;eRPuzkP z;f=f1e0J?8WM0(=g)=0aWin}^7q+Y8BdydIU`OrVWq`r!Ip)X zYKTY6+rXu*oaf4vD*gV*kC3>$TA9Fb=8<5b(RbkdH0qDU%R01gF5IUlq6*qg^6&i1=F?g61!v&mE5&K#*SPfG z1jU}t7)ETFRJ1Wa%;Eje(0wdNFun<&MamWO>MAMya`+vDcqhA_k|4F6v9Yl+2BtKV z#)k|%D?>%oPlb3JBT{`Qp9)iKl8$p~&cqppAp&4U6KI(7@bK^jDy`3UoanFLj`f$I z=%n@Q7hL+hG^(ww4IdYpuSnj;_M_Em`!X*N50Ap5)PGOUKs3v<5vHRQ z{HgJm(wW@mJTfr1#Utlyc;BmX!+T}m=Z}C5>SUsB7?u!V0+M=^@`7%-D7z(ujvjTHM6zMqaYp{;04-u*K&#~N z81h3BKkF6oKwB2F;g6_1(FoO$4*<}!`WVOoj#>u336&?o`!V$}RI6NVqV{Ls@AuL` zU_caoL|37>;|?RcN>YTBz9fezk>N<^85yYDCCKZ7t|X`G6DM`n)yFDaJ*qYtN^+T* znNfD)S>9A}G!hTTuP`t9)8_r)VjC%De5z48zVBokfzK`#YWv^136aL7^GcX7D~ZNy z4>0&r#`v*mvC3rxbH1Vs!qXj(Ug6}2tN6-) zPR-Mx;2sM2@R?|7OFX87oD3F<6n~Z^jW=QL&fDUBg#6J+0Rm~R>8@_s0ad32>F zYwgBQ|4N!bn|%A!sY7|=))mc=C=&g`F|SI<$dOyEw(qPdifEgIbB6X zmLs`YzIU&WBUwU4_D9d#o3{E(h@Bexr5+&;`kB6GuZvfdhZ*KpgQ;pEjJjAkg+^LR zs&8L0*_3PO#{)egDCn6|Vo*j-LO! z)VIHLlRO3NM3|}sutx0v6hrJlrlSvZ*S*Sa-=w6ZcFOnxloc1a_tz&B6cp*QEz^6% z!%(IoVq)R=$^TVbxJzd=uqnAXZ=r_1`aOqsLAVl-RsH)!9k01RG)M^9KKYf+GA$hQ zK^8$Y{>MLn-Aq5lqen41Dqg+p=S*da7_q0kf2&KDE0n68-|yWU;>+&!pVBvMhJUh- zO6Y!BkqGOXK8SrHQpUM;>?D37Fq1C$fLP|z>10zuC<`-TcizUJP!_Z|)~)t7EHXU& zyiUcd>Bo-^Is$_9tC4Ev^CSlC1x-!OCmiz_Xtw2JA=lxjGmN(dBVhPxf7--+-`a}& zQg*{a_~W#9FOs*EkR_q()$n`uinFG)6O$b#h{;ZZseP0zl7}yVEr|H3U0xkib<>|I zmYjct|E&&eYrxjfR07GI^wsYTQxP@ktAjJRAD11od5d0WUnl<4zH)`%|N71zv+o{Y z{!TYhY81}J)jG;z+qA(+s|duoy4m?h?y4s(aB@ujN{=xjq|>d);is-@6xW;ib>t@lq!Fu-2UU&AuqpjlL&VxUD z>`%=J)(JuA1ggc@c0}&R=zZbNeFa^hK?pwD`bwX@NDf=B!`R9STSU!s(P3p~-)?Iv zy2|y!5DgK%ya~kdz1TKUjo~RLGc|mm_mv1V6qEz;A+JoZ2eX5<`8*4s`r;yx8q6U9A40%Rm5ymT65wVLK;sAZzy1_*}YLf76E%O|Wdh?MQ|D{r_eC=sF_fIp* zcEyu&@OJ{#pD)%h*g1n|LF=N&pFfASnYp-Jf0CU{Q!CRr(>(tRJ;a1Pv?w7Zg>+u; z_o#!pj^9b10KaCl=`-K87buKKaV(r$`!!Ol7r%F#>piAawR`p1OJN^MyYkzP8qAW> ztZrt?a0g{K$Ze&Fp;Hei-JpTV)g$_8CR8*z9Ewp3=l%(cE0w zFqU3;9)6j#X-F?qv&@^e&^7;f^3S{>T&g(;s-c$DbD6RD$ygCpwv-#BWHz;yk12N~K0H}LU~@csUuB9mih9exUiKMYt_d}ZO} zBd4V-L#2nJVl%V}2i92bfiL`LdNmnCETmmxo*_SjlzRIe-v9C5W5Ja=)J37XK3x*a z&F#rrdn0u?`+eSuc*l+_39xd$+xoirkGOd1?FF^Zefs;kl9&io60F?@_{d(4y@vyk zgd7oBbfTYcpg5L{8yr~S5@p?>8beA8-J)65WIQ18n(BAIc0C&5dcLsM!{Y}V@|=Rl z{tyUr(K2q08u|38JOARt{@y!*v3Ib$i(`xMZ3owX$e(H@uZM9QC9w= zrOQu<@itw$Jmkxb>oQ%A>>k6nY6ce4Dj1&$@Hl4KMuq(h^V^^d>$H+{b^dZ&!DFY4 z>|nip`&OXs-mqbj&dk&l4om^jWwr7_Sojdq$764b7%oYcUqKF%Q97RyXp!xmxUEC# zi`=TYM8*nQF(cykimWcb*%aYcOnm$W_fyS1`Tp*X0mKfE)qHFY;EPpIup_a#f|pjU zY;JJ&ja2R>kltPKcb&{tF3?O#lN_My@`Kl&jEa9>IR*?RBBnvMD1=eZMvRzR8r006 zkCd^ek4O)jI=1cY?fu>E?fj)x?)~)mSP${$@$oSOHRNZo6YsiKY$AP^@_tx}(F+dk z@~r_k?+d9)m9J+4@)i41pz61CSrZlWAB5^FIx51F)jES8K74RBGc$XE$lypHsq<#1 zsG^xWx*kLg+2m&o;iG3xAL%A1Cl?WvLI)-IL0G}&_h6Am`M2%E$MheUvG_Sg)Eo9p zb_@vIC}O>QX^M31(MrRO!ll#AZ*GBqjpDF?PvTWlQc5#5F=1e3Yk!8yij0cVBVU$& zJs!JE(P1*P%C%CogUfSupZjjlQqQ_xe;prY)EAr`aaIE=i@FAAb;@W^sNO&eZ6jM8 zP(@B#9DS!n*VmlAI(dA0@&wH6^PXYTf&^5^;crXN9K?Y4XC;OP`5T!gHWkTFeJ8zr zci&4lKBD~$sCpkByWMA#AibPnY%qW1qHJnvnpbh~hFr=HjJ&ZTA9su3Q3 zC!#4Fiw-rO)D_Rw=nGszF35+{^v0MIk%Bw z^92jt*=m<{JBj~$4i~W%mBT%o;|oCZf$oGc;M8|4mJ`dEPK4B`ImpCmjb1dz-8ofS{;hZcZas>;pu% zC=FaQu4X_oD+v{PGZqz+7ICNu)WSDQPHZiUG>*=7yB-2K=pwB0?dA%mh_JAEM6W0e zrYBx0vkE>lv@|B2MrP&7TC%=^ZPOa}m_~S5mR~UXX3XPw+r)>usKhXdic}`eP-9Sz zdB_N&WZc}`bE~Tzg%tFiEPiK|M1?97d)V(J_&9(KBXnwQiqH9&p=H$`j;M;l zy$g9$9i44!{?-OpW4+xYz@??_*R%zZLA6F-;sj$KL~=xSlE6}wDIOzL;Ize?2CZ^T zls5X@6p16@+_F&7-Y_mjQ5$dWTPLpM{0~{8y_u3#)@Spfv<$U>)#b;F;u}6q)+Wct z#RW(i;@CpH6%$-K{wXGu*S&sA_DVM>sTgG9?+*;kk-(Inkm6F+BQj%C73>WSL(V{2 z$B??_qN9jj7k9?wLWY_RWP?!mo*P}tk&ULDufwoN!yl~DL z%tY8G1m(xU%j-$XOhrv?>M0OB^WDTP)U>sA(C>d}Uf=ijT zH-|Z~2m_$=T+SpxEgCTemhxflt`}-3^1=%mmpZw%2T>e$)#i6#;A**=rKQ2^h@=>) zTy$rXp`_0p-+Cal`IGo3EBcR?M_Ln`^#H8{&r28;%`S^vzj#zGQm6Ym%9CM{^2bI&u?vhV7{5?qb*Rm@a@6kPhQM6p9G!)OFtww56jWw1z2P zL`IR!K*P2}GKm$3b|ENK|Filk5cqY&U5Z^SILcfj4LJz@7^$mmRNdJ{%e0x5 z6s|I{X|yHuw{O>vt~li({&toYedNHnQ_UV0<(H;DVj* z(}A&yWc2iH5{JBZcjrPBZ8KfXzJmmiXN11KFDHz;%?abVpF<`ETs-6w4m^=eQu+;h z8X1PzbN8``h}wiavR^NI1uqaOiysQ*yxLLQU#m@`FOan==%CxEdTN^ONL6++00dnd z6<*6UY=;MDpL`PyAEJd!c+&jJn=5WY!@{`9`IS$xMb30-7_@#uC1e&&olXk4MP-Nk zZ!ZFPe1`2gXkKwYTBu{s6J4U-!&E4pq8eSOv$WJGS1T)EMW`Z!sY2%;^O1G zWvC|^8NXwTi;9bP(448i&Q8uP1lDOgrd#jOmxDMzQzkesvj9JZC-UNLNNIwCPf;^3i!6)ies0idY2=sTanRV z{a+qbxdIldSPo2ZxBv5}`#P`OX$$MpgL`@i*-2Aa7?_BpX}Ye(zj=s37Eq=-M|SenAH4MFv?ZVlY|k9pwHb(fs6QP z`s-#b6E^No?nJK;Vv#`P7c>tdK&lz3sd(VBJ|!5r+fZG@c4CB8)7FK}KzK=`$)or5 zV+>~0cY1V_ng?R+U5epDXe(^nC-s|L3D9E?amh}Kx*adV@e zXRdVuva6FkQ5gMfcZAMCNxKDRN!UnqYE69~c-IIdt*drsI%@xEvoJcg_382UwV(`%xZ)*U5fIv-AH0#l=WhgGJN0nZrv7S zni!bT_sR}DX}O*Q)b4kT7FQtfM{pQ*Qh;7VH=cB; zndbu!#r=^ZIp_Mx(VV+$_AQH2E*D%AR(_5(^pCc^#zH(+)4$TR5AgQyfA+|>=rHB~ zYi@_oz`(>*)_@Y_QvW-EVZ+CfUJhBM1S+Wr>-a5*%ztUoBLLXyH9%p;;_|0Wr-1ve zK>3PDY_bQy@61ZiUXdEtKuf@2Oa0ZXteH@V^zzXQ@e%V$LarW2>~vhx~4J(p{jC2~q!qH#RmpnUkIL0MGl8m9=ocS>X4a z6Z?&UqIvM(BdltXH)ULo(u^?|p)sr`wMehH(XXIVMZEkeD`9hK_Y(hUSU0>-h^_Ub z4>eq}ixmeRyt0!?7HRbg7SneTVq~!V>D5v|bwGSSa`DWP)D{s5`iw%qN(#DEX7*~jxdPrit$tzMj*STx znl5CSCh>OqQ_PuX0X@p=lC%pW&{9Knhu;0|j;f@pf=;w|f!e0dph!OI!@$G4%PcT& z@sHf!-_I{!A&OG+MoUiWIP2-_JDzg(t|&04c;!5sPcphZgQ{G=Q$&^-)P>Mt^nv+w znpKp(&gz3$i?jD~nF>!*kou3HM@$K9sx=0i5pH2N)8u1Hm5vdh^VCf63=*dP0-lR# zvGhto681r>Nuq%q6C!r=+80~RL~RY-ZDMI71{?>vh+FFL=nd8NV5o3|0!L_Q72xJI z%%GoBOPNJn^zy?~+TSMr#mUsgW!D8mKog>h3nu&)^aEjnb6UYbU$Fmb0ch(d zCxT)?vCq%XCn{D)Wj#J>1=FgnBL6+X1h~zYaaT0`{iu@?Z9jViU0tZyfTkL)e|R`z zmW`nSmjcdTZ;LZsmjA1#fiL&Cp%c!T$T*BW9-Uhylw6SxBvGGLizO0E84}ok z#i_Q3ZT(7fK-=t7Q5)t&DeF*>e(LV&q!qwn(nArNPVyWPSEC8S=&`7)=SY=l@uTUc z2@4Mk(_H^txF!9}k>p-a7$P0M+dvxuBO^jK3gM?LBMA1qM-g_aDKk&1)E zrJ*)l0asE|QV7IwI(Y{kX2z2$HS>>BA|fL0tiLG~MYkS)s+|S>;G-#0RwVO}qUaPsvgoai#2?H-oDqc|-Z}p!h&}{9-H5{0A%8Ofj1FuCW9KK` zS?yhqeQ=pL2hHty8SG(}Vv#VNIK9jy6$kfDn*tr6wQK;y7jM^cXB1&Q5T?TO(#mYe z?tc(AC#Tcg{ys?aCbdOz-jmY2>}6D7j-!hmVv%C9D@-y|J^EqJqc3&+4W6GtJdCvvKz47%X}m zpi`7UR?uA0u*crj@qh0Hn04kiO=80laVi|#uwo3InK8;}~S1Q9!ZgT9^_7s~ndlf1864l`q zwhs#r=lKePxqr>aZ0REu-Z?sQ=8iC-5cr|7s(T{LgaeH4KzUx``=Y?)O34m4`9B<6 z;c8&qC_n&!I=Ov#I2j!rlnRZEOeAQt(-jdHM~hRV!It}^_8ocGknxXjcq|nd5UjC+ zrlz>UJu_!qY>{fsw*+NFneV+y>XWsIpSD3e6RWoq6A-k-|H28tf+0JpsYb@&MN(o_ zK}X7?vO^qKtl(XTt8qD6z*j51ikr4*1KalRC>b1dWti{JgU*)_UW0{RqdU@9*Y6aj zwE5;|W%-sva3$$Gf)AyeEikzOJhC*pWp6kQe7Enq%>HvS!Msj;c3QJnK4}F{42+Dx zrR5J7RpJ1Z)hCg3tI;e{Tume)K45Sty#D~CYNLkfaF2^ZvyCApGv;kEAHLRWnx|bp zV-CjDIBgM`VDo+nBCs6<9J;nE8+wIJB}&wG)kj zibMP5iY)4x{#)m#F^&L&6vOWrbOR+PO#$tP#kG;%qM90Gr2af>AjJK$qzx++QRcw+ zKx?gfWjAG^$xK@$fJ%b4R=bC^bXJPSTG>8fpEu+u><`$L>E0S^0n zehZ-AVbhDBKdw($Fz0d;YMM)b#5+HsnRL0jO*2<1`4>u?lUyj;d_?(tfaN8V)%8E< zF$Q)U-XaY<(K3S&@;_yhQ2TA-(D(mnz#53u)Ku@L>U$UAXTm%$?0TF`dO#ovBHc9I zYx|Ld5g*>nmPL9nyQLaQQutt&A9E*jQ0Y(G-uePwD}r}Y^K zGAY?fhe3tN(D3lI_sJ`pERLH}iLVxxGX=lXXw#!Tf|gcC%L{3WPL!fT2G})(qTGXf zSKud+|Bo++S1d`!b1pWnndgE0?yQRjr39{^1<$B1z)TsZ3c8ZaSrbs4SKM9Sr&Xj@ zcj)WgD>yX}G220!SnYfDJ(^BDeD1qUjk! ziR)a@mSfECs4`=skerx4xT-PRkqA%^!~h4(#>>l#s48APomeR@E?)SR%De8n$K=NsTjCOj$=?6 zHK*zDD71h2hJ=M`k){S+L}y|X^b63B7!a95VA;UMX@~i5*U__3TMOcg%`he$2EJ;7 z{1pG_$W>%NRjSLj&;EdT1q(ckH}mrH*yzb*b>fFjbC)sLccPxJImo%ec&P`BO##V=)Y^@~PS2uk8$Zp? zudNbUWdC#KuJHFJAc_V4|Ed2yIy<=eNPJ&FSks^pKG{%3a@_f8J0&HBGvCB3xI@8^ zfIv|%_{{_*SlbnG`qMH)h^w{xKzf3l!A&;Sc1zN#-`e=y=tDz_Mx4-J(~?F_R9%E< z98nAxb&IA;DLzGmLzPc_6d2%3a25I(-`kJT8eyPda&yrX1k?t*3YxLLy^`N2+xI<#}9oSAJb+?o5*0zq-|bua1RmE{db6&S*V!qJ=AwV{K|Qj2rGWL z8rxa*eL>7bSTFa*Y+)d3F+&e7!9pm>8woqNn@}rt)&wE8*XT=H!4Vv`PP3Eww?=Ik z`Cg;y2;k;l*uZ4-n!h2#S#HT;evM)5150s zB_ky@$n9SLT4}!EWRHdfdy0BWMO(^?LZ!Db6n{JvprE&hy4T5_@Y~ZKQK-0K*GpVq zo~P+mij+>506f;;QbJZIBTO-P#D>u)MX18R*&X9Qg8*qKK>1w{7DhM@%O`yeIYEl?0Z`w zt4H>yC=Ee|_B$rx z`QVFy1?*Q|QAeQ^1$??9pv6 z84NT-BP6Wk?Em#Ds3=p;{I2yIat8iDa=pdDNoGt|I)w!pj0u=Xl2G_@XK$O{aIBE9 z=R~_eE=ZA|Mo#)-y>sKd>G`p-e&GzRYf==p9v5tMQLwauRrdOe79x>7ZpdZ|PTqDdFXcuVz zBQCif|K`z!=BT>^57QwV-?crMT6T@4?-(^9YFf!SNeS0jVW^LK3gf&E?hg(D*p>x5 zM0#lj3ZhM_P0VfXZuK+_? z|21u9DrJw403_BTT4Lxymc8<6IWonN^c>GVceHTWG&t)vDlwi8=7ceCwd+6`RXex` zor~z`=rk9YFFNbKjE;>}CgN%YB>%<6k|IY4=+aV2MduZj7jCTh0{faTYn8_W*fNol z8eDcjgz2*OO39arTKlH5MwGBgOIWU&dUt>8ET`$oVS0JfNo$q{x4eNZmsk zcsMy-er9F?trrRh)-CY{{GWWhrB=-=cr$3-YEy z4-Q`^f^FUWuqg*p*xCgySL#r_M6$1NJ5cIL+qkGQoX^iBv~Z;wU?UY8_|i>w*&$61 z7u=c*s*eP32U&wr1}4BB1__8$93_v@y+Tz~pr+XjUGpkC*NRdA`HM` zIS%(!xy9-bDu-gCA5DI}J4898yP8OY9xiDukjozk@WS3ARfZb2@3@-nQhX&UqsyIy z-D?gxFd~i-SuKjvt=z?%ZT&636PeUX>&nkEj{sD??pcjmR)hN|FziDR^ki_8+1DF? z&keHF>d_r1!HWTtE&WiHHE#Zj0o;oPj4a++Ys|x+?Y;jnPt+%Bj|0(+Wn4X6-w0@6zOy` z6)Jl8z#edOC&<8u0Wm#Qdhzq{ctBSPrD>fi77$>@JkosS&a@n+!vb+JPYD0g*GCthV?1?{AV55dmvr=*g^0*=+UueU1mvUm(RI=$Y0G zRXPm~ryzwLh*9s_y6hlP&n_-3iE(h=w>#vvu8ZX7?)GJS>3jnPThYB<1#JvjSYZD1 zH9-5agdj|u1*g~KAb_SLyw8Q2OpQS?G#SS9+p}cF{twXr5E{0?jq9VBEb{>i$Mkw5 zg<_ftO(8wZ$BMa~9okyZnm|VgBi<21l7mC8Bo$x=c_G4O4VgX2_ML=rBSZYYB9jit zpRIsxMxs+G>imqx-}5tCKA{g zS51Ogdp7iNDy&(Iy)6KS>!mAroMyN=TDCA+OkV5=&Fw%h-fc zLD-b5iHC4NCsB!boE{rieR$&&6R*$`7{g+c zC*S?lGe$h8sQL}P_>;F}E6(6_20Ud@wNkH*3>f=)?FO6W+v`PJU+1%p-mdLNNxr%h z58iF}Ln0W{oE|BHY(DpMJ-?B3&JgJankIWr7NRm(&L+W~LDiE8j$Rx8IqlRuScWhxUqGMv6{$l5U6@Ux|8fGsKwl#?6ZHlrnIF)Q;ceZKa{Z>349B zX6*<{(A*>;K0AZAK+g9djVMa|MTMi`;-5_w+tdu%X7y}eTL_HdKmE1zu-)5tnv9A zP@?L(=yQCSefZ)d-=1Ck4p&0rNlXO^h2AcEm-XZANiqR+aW^ z<%Ha>Q53tQih?wuX^FJ%JuI1RZn55l^2!ZTSpU?D$te_G2TM^}t9kj1GE*i)bIFfZ z7il!H=%_0;{(N%7T;$m$YD5Q<;@&E*FBX{{-m!mPY|5SK#rDFFJ>s73X!bIEkt#Iy z^xeN(%=4*Nme0;lbJeSRaedv%d~Tc~%6xTyvZqq}Pw2yO{CyPI+5@}4oN>jD*vf5v z>42%b*DN;CYj2mXt8@`I_M7P^4j+%XmX>=kR!WsK1?3Wt5spr_n zVbepZG((9oQ}QM->jB5NrI7pincC%Ksjo%(J+s-u7e-SaH`6J)iO>H{`so{rgRC8f zBITQFzQsjR*B_goea+fT*!RsQmUKL>gpYrGp3QO>z?{!Tu14b^v)_jbj`B!Ff;63> zrjGeV9UHPB#$x>Zu>q?Bp4djbrb^Ap^OD5t_8Eoe&&|k<#{U+U?|1)#!QH#XG?9rH ziJ$g+ZG2~2laDt;kq~$I;&1x33!l#CG4{##Q7C7iC(!v| zqD_$k%C>pn$h+8V?AO0e$m>i2+2Bb@_L|iChE=&jxHrsqx}*7are+t}Bt8a{>)l+= znIQ+$KmRf`^cP`*argAoA{Ml=1@z=2BNng5jC*QV32=vP$tNj)V2;tMv!(kL>nuPK zc%*%Jn=Ug|;;kKflkGz-izlB5#qIt`^U$%{&3{v$<1wNI>r>$9MFJ+|gF4ZA_es0) zxw^h$jS`jCOvOksGEU0lv^wSC;-B;DBVGRs{l{wpdGBkyhLn+71k{2FSn^jAg!4m^Z;9&mmu$%Sjy<&wy&GcOD4K;qK zIps|4ci_Q$a4AzXl~}^5@4U+0bp(HN zLQ$ql0NTlHx1Irl?dz0Ag%_jC(=%^;$9*_Nq}AV{YnYf8#gNZO_Kzt<`T|w482_+||pF$rkE9 zZ@u2`yRy*?ejiOj1x63r09~b=$Cz5)^`&BMacgjw+;CL@qCns>Cf)Khx7m4Lp+i7Y z@JZy~e9aUp%9r7%8|6A-*kpfLbnpbDgGC!-P(Qw0gs;Q2L?im)VvsY`300(7j6w1H zH||+4&cxpT`f|3roqyHA>?zn?EvsaL2e9m**~1y_{Qom?QUL)v zo~kyegRY*(hrfOKa7Urh>hk4x>-pxdSTJU+sq=jF+6v*j7g_d?n$-D|cq7M%<(`_x zZ!*XF4Q@uQ*^n(&i&Ba!?fTYpCa}7WDo~AJewmq?K%Tl=&@x#s4;EkSLKYF>_Vcq_ zPBeNr*Aw$2t$8rqSg51c4GDQ7fti6yaL~+@@=v@ghX~x+I{PVl9|dN>{dxOC1~|uM z%*q$;%vmo!(AJJ)Z47fYmhk3#|TQ2^ttT#4Gi8%{SiRS4q==dWY7=Y!@p+p%J0n-|WGE45d`o&S!rtXA9J{=1wef&ZJTY?0EHDSpU`^lX-V z^FRUpy#ckp^&{Wvm`bJQ_oQ-)(6ER1SWv_6daEx_#LpM&53hp+RQ^-RfHV?61Y`E6 zZEQ_sO@^GB*QKqMCC2>AlOBNZDW64=anJE8@(^qUVNJz3-18ewd$Yjc+Q?%OjZ%(^ zBQV1sujilddXLjLvq8RPi>jYy$XXS!{ZHl36b?DnTO(W44#lP#j zl}W(Ss}j~_qP-%NEuyj>TrhnV2OdZuxsyfG$)ocIRMV9Z>=>JuS>Ey7rVO0 z>ee{6RD@PgSo1Uoo-YHD^>rx)!q>OY_l_!LViGdn{;KPE*^0+21@-DcnU^_6d-$J! z(`FCitSfI#O=_DZ_+XP4qQ*ltF90T>VvG)VMk=POp3Fv>y?5pCoQeBJt+kQLAe$W* zv3F$BWoE@sT+?y$iI>K}_iwk?Aft$$r;q+*{fd%&!5@ry&*Q){>CNuAGR(O*ziwz{ zsrDBz5FGyv6FINTcEeOQ-pgYQd8JykPc!EvbrjjrO*|j|VrtZ~$3&4NO+94ta zfuM8}GMyV6xAETKgbl>LZ(g<686TW;G#ShK=h^GwVVPG-0}!%<=laSIKW@y>Z~DEh z?#O$+^+Qn6aqLOJvDb}EsiSZ9q+iUk3gwo0C3Ko&Y@%1jDu@;2L^|6&GirWlEGXiqvy8r@1t;=5DSX^~s*-zt!tO(yp zU6tFlXK%jwZI(Vk!IZ02!eLh`S#-WI#m&MUyw4Dx9m`!YSwtxu_9!fwEiJw94d3@O zYzZ9(7gQq%1Y#tAhQys;MFZ~7;C*=iIcu+fU-^CN`6!gpM)NL9h8SwZZm-!x&G|(o za-u{U$CY@c;(l1%Ni59Yn%PDginI&%buU;InxzTW-gz4mGe6nx?O+}(Gh zz_i7P-6q(5WaJWcQhHft^Fd>vZ7j!ds>r?cK+Fg9xl9&Ia<}6^q@U?kD5B#fGr>65ORW z@_ctPSr_KxMJ)FG_h)}wUFR;2qWI7%FImkAmpaC_f6$llU;DHK{%e?NE+|0*uy;Px z1+7x-!TJWDozYGZsQriQ!;P5*XRn=h3L4bH=iz}(@unJ~ZsFcaOaj(KX2(SXV{EF~pLNo|#HFz8@|>J&*wxlcuj?!i+*+b^ z)Gyj$(E8gdT3WhtS{X4T^B&~QGw+<00wwW?y`MM*4R{3%s(IiUD%gxxau@vfn z5?n^V%~R!@1V-bFv1)7Q&pAh{YHKEz?BXiLwo5 zJy;kScXOBnhEmVeXBaTs^T~L8-;n%CX5@K<8>+ z^~68G6;~b5(U+43UY$*9Kyo41C!0WnQ2JhZ7mOgkfq)=Idp>rA%B_LcO4SFB8LMagtRqWI zOt;-gL>usF&_+D0&*k%s6kh>Zr0`xiujpp<_xqm#k;7(zF~|guHr^^qxASZ!OZ=Js zx~rh4&)Kzn&-?MjHTC6KyW%0UV?gAO4L=_Hv+OL(_MsV=bD8_u8u0eo@B72GO(e-$ zzBJP*WjxNduk$2PswQ5l1=SvHo*fAAO+}7Su>jTmv5mdAPON8M~R3$F|nJkz?lGjo4T-lgy zb-Jmy%@D>VF|A(~$5%Agj_)w!ZF+D6I6yhV{FD3ifP2%&TQ>hFNZrAY<2l$&-pjYW zQ!0B=fIFp4$Q0<8#Nzw4gYbf0V!kNewUf0dhE8-1b2JoP-oiN0#{nY*Ix0`4$^_=H=o6$ z%|-@c^t|fzvm8^w|7~nMOqiY8f#Wbt3n-S*X|mWa&o`Li3?&a!+{JI(;9M??(p^lq zV!*85r}Az(12fUP6jWD{evsF&>i{B*J2maOm!~W~&0vsRNbuKY197^v$`kNB7BPI$ z1TA>z{P1%7cNP4Mo*JWWXve^o)(1I3M|{6@+hUjHT{Y0tJC#+ZJGY9j$3ZD~Bhs3E?*> zUqpEZa&HT?)ur!_JA@h)JtZi~hQ?$dAz3&L8D8i3q?N@#$T@xKx@PG4 zp6kl2A#nrzl;TNL%iiQ&td}6G_xT*3O*x^uF)*C0*2jO`)m-GW@0UlsUuK(X2zk$6 z!8iu2>)8|BtDic2(L=OdC06PX8MQs!+J8lMMC8@?hUdCix}s zN}01#*Z16sFLnLMsMXrA`^N*pig3gBlBS`W)`DH-|@1(Z%UG1qGNR}?4 zy#TNWg>|O+BtJNws>Bj6`55e7s1Xfm$R+&S7 zQs8|6>ncKeuFEa*X>UGLn8D_lq$9)uYP?TnOKz!E+*Dwx@`|YB@QLaeNGL>GaM2SZ|zC-ngu+`;7?o57#)_{PBIoKx1Z^}8W{b%5Rd{jU*mTcohj>jw^E*Qrn=c2 zQo^A=;4E^Kn?0!U0-QDmusrv0go=SZY&a^OJr1Vy;pT`87z`d4Pl4#zIgVz`SLOOT zt=7)l7Jwp9)NT3`5g92gUv4}>c@qam5uf3I6iNO)ITn#(6uSfTOblo|44UlZa z)NE$kW(hQNj7Xl(3>qUofeq&^`tn_zOFW0!m!TV0byFN*cT;!oU5y`RB7tBo?evb! zx}|>e;u5`BkKZseSRX6)3-fZ2CgY?`p47jSidg zho*%8YP@#V#U4L36*{5mI3^w0&Hl^A5^;O@KBC%lfqk9s>x655OSN1Zuh$R=Ub|Si zvd`3GBa_V?1q*C<#of$rKM6E%j(PkjO)Mk%(${z1Y*P;Lak?nA zufu=~mLU=h2U73ii_l%V4Bx38FW_^LLulEm!ZJtxJiw#Wt?VtGPb>2|xr;Yj4Z`Tt z)pT_K%bVI)n*XwUwmS&l0a1mt6kVos$B_s{7ym52!0x*O8g?qE_!SC(ib&;Y=K)br z;;ccbyJc*ju0q|vpefsaKogBA`!vkCuc(CLd!7xJwx;t7v-AWK(2!IYZ~ArpUrZVsB)bJsPPQlMoyJ*U1skZVBf-;G{H>CBJEi>Ss;bczDCeY}e6< z1Os+^0~AOj(`Z~DyPh7-TU|_0R1HBCma^L?XZnwhiP>;!lCo^sY2-NMfy65%$6^}L z(-)8|T(E^S>9{i_dw}R$=ACu22++I1 z7}F~rF7mnWHIq8ORpg`~9oqi_x+Z*T>{FQS$wGA`$S%V|t@LwR+G#|b4+jCL#iyJa z`om5A+a{@gdEn2Wqiou?`!`mmnfmDh8*QAsUEW`eh^F^GL-oQB!jV}035fa@SDQkg z?hf6n+k>gL%qlf&34kbIH^B~^Q*0-#e+$>Ai!1f>K54O*+y=#n77+0Rt$#iS*t}0)#vH z{(NiQA2&a9lF6*h%--*Q-ZOJN0OyLSrGu*}w_k&}FhyPnpTraag1*=x`QsMB_Uy_1 zZB$*PP7=<1S(NojBt#gmKk%fZF{BQ`Glrj&z82TO8^aZ2q4HjyQr;U#pd~d}g!}nw z@2^-K&t}|$Ea?z@;HMC9S>Ev5)&e=-$}UGD^H*7X4N%|qpy(8Z-8%Iz%S!#e?X0wN zbw2(b2nTyDb6#gApegdL0}1reWwECwE7!`MkmoZ~@yjhKRi6VaV2|M~I10!UQ|9dA z9J<$B#0Uj2RRK_vjHg1B5XMo?<;a0Ih#ag5DseIalh!E+r1Nn|3yJ!$JIyMqI~|ZS zIv@prxSYL$$^nm|CEp&pGZ!;+9`$youZF!v5PS!3_e7bL&0Fvp<8vdg83L~L=pT}` z-`X{vBJity(@upo=e@w5{xQ>^za_yE{C7rSv-o|C2NddEYlic`HJbt7 zZ+-`sAv=KXMVr;dRo-9{dVrYbn&RJUC9nxPxB-xE@$)RH;j~cgTeH^aI%)cSMP;C8 zKB|qd0SqPhtRpq!{Me*k#$WbeF6gbdU{<9h>@=Dy#{zs-#V|<)1cIoj7g|~MKCVE| zjE{2QwHlZkBcUiaqdQ%MWHDOXU|W+H1_A(|&2bGbd&cW% z1pRCr&`cb>nF=7w75y^gJwdQ?frh~nx551LW1haeil4+FZF=vVei|3_b+VG$136jD zrFsu{sLvp3u`a4rZ_{tqRU7orx6(|%-RP?uY6oAXSJh1db1Ah-#nl!4Zicxa}kjiup zf0l}#X>b9vArp|xT*oQ`XV^GM*)ahNx4S5|lyfxW2R;5i#*cm0)VFGz=T|_-7gZH^ z{nqzWJ?h)867S=y!yW1l%k`ctF_bLimjs$E!r z`)uZ>PXy}LJeGre?aZ!rzC|{h(KY)_diO*eWl8($IIiztw%w8)C;;o#)jf{j#!%!A z+8h{Oq@VP{L4ClLoBG@l5YtWtr+fgXZce4^R=y}pz~1n4Up+wb2pEGhf(XXT5qL@f zSkerkk^*Syuv7dX5Dhqm!LF&*Xt~MyPq7zZtpS^>VI~xy{ffbFQJaI25s@BtgC%aw zpT=rs)huVr#qqHQv_fFV><{1J*YxbOt2fFZo9zSjwLSABGx+WCC!@olNKY=uy_~;j zKrxUY85H16GH=c5yYU85Wm9&6C1)W4-O~!Cnz&NGw|bz+Y~l6Y;S;N>L-l5N%CMkY zE%M)r_^pHR!YJ1KI{xy4A0%V9iud|JYii$aSjJ=nbE`YA6YYC4K-wtmbp=2LfHO2e z73b&N&!Hdi6opxqpOSz6h{8I^oyraKorhi8b3WN&1h4IF8pYyxi<7{3tVx=4qhtJk zc)@!n;#;6gnJdDs`>3S$d?{ z##_?iGy8T!JoIEnzZ~5KEJNV!j!)*3cvW#ndLY=t#rl$mc9V^(J;9dm;KgZ4Be?PM zZ5+IYvK)A*nwDb@Bn;+&VeG;2 z=S)p-*G`{q(F?ckXQc)bk`pu-B0s(B1`_F3?6wgM1?( zL22Q2`7eKP_1t#;EJBvHFO2mVM272l7I0+jh%dVU;q#L^ChjW+)F&QPL7s*K0Jquz zwui6(Kv@V9+)M;s_^L94zT? ziUJ9}cp%&HdoPWwrXJl#2xT~XH?kV=87xI`9A>8(x!S}xefS*=@2u|<(fXf;tTuKt z4xlxrqvSxuEs)Fa5}|PV)pj8(;BJmcyxkz=b$mA^Q50zO&FNsnM_2&A$ZsF1rI{1} zD+_P9pEm4x3+vTa7#k_CBkpwzCV$PXGCPV+^2S zjkkZzKk1dUg1^7!{9IUCGt*pcWAx{^WN;?lOAnL9;T_!RC$;y0i`RIvRfqS}m~a@a zD>2XYH{dM-FFJ^M(lqdhdIdZ!Yb#4y71;0vzp_e!QwfvV1jAn8(hxft7G@BPi3Fo% z?(Zv+#U$biPS82@9A(kL@*_*jxJ`<7{>}qd^BAA?fM8^U_4NXl34|(>m03_jXAG0v zO@6#p?qS>bOTB|+e=uDUFF`v>Ujyt}WSM|PaK>^djUF9~+cY!Ru(y$&miM?V`GhwK05+DdOR-NK=a`LIAs}qZ_=ruGJ zyfKi@A@`9J`H?11m~f4`O`9|!(I?H9q39w!jf=&WZCazSImcs}In{4@cBNmKE@U4Y2!EExwsDZ}S5lYRy^~{fHP^P3W2%}&wKx8a7*wkGvPh#v-IL62 zC$D<>`fpvsNsY60SP9|*0VLU_1!)x^?T*fri%|-f)ktMyK5;f=h@mAjO_$Q82B$V) z9m^%%2}yWhH3+H6!k~lrRh^O?oo_7}8+wTlJ` z?>REZ4wU090}L6C^`Dx{8PGFMPSxPt)@w&S}RKyWkXTLNB-pl z=nhq2c+3V((JJFN=G& z3C&x4n*lBj+&$^OXSd~p-<9dw3Re6HVqyQF@hbV3rbV=7)rjR*f$Dczgo$USuy1Mo zs?3`8iO-zH2h;e6E-pht*_J&wJMBbD>>T8sj5D~$4OwpU5gI@Qd=^z+z+oMzQ9a1R z(Y4=p8|&>!3tglHv=H8FWF4hN_Y_M;stqb6?8K~oMM2vorOtwks+3>0g+92KWCu6a zQH*e9X+nP>w%M=R#%g1{qE`1Yr=@#6qDDu#W-19phvg$(1M1XjkKZ$>@6MegtR=UJ z!P))HYiE=l>K`AX_Q-myg#f{ta57%Lo>a2@yJEhwPw9Y8CdSI|b;3cfa#TjjHAiD6 zis#4gn_T&0-!rv5OmLQ%_4CM|x(ox2DxxEm6-|%Gh65HF2Aq{ge!P`99uOaYY!F2l zPB5{zx0}=l%^zY@$`AYDfLx0tD{*i_BA?v4?&tu4+)jBa?(@#im(A@D_xPqaJs<5; zG4YP+>6m@2Kl4Rb5JjzknOoY;OC}d;K;hhA|4yO#c`gyw-t1VB%YQGtLv!ML9%z5{u_4Vqe9i97xMACav z(b1C$v_Obk0$W4ZlLnn=!jC*O^13{K3@gT;n#5et&=`pLi}32fMweF>awo`hZHu`2 z$LRbkXt|geu}&um6ER@Dfx(18vUH-kLqcM9_riuO-I!93imO5^#aG;ON~PIHh78ju>HOn;J%-r2F-a-uAo$(Ks4H|6&u=WzA5GUW$s&9 z*{@@a(axmhqZ>y(=jP&9u7pP}QGE@8APRI8yEIypvtG&hd{mO&ZgzAfgrQlbUxnKU z>%}p>MzJej&zLSVGEOu#owbz)U9CoNk$}ZLn<;oT5r=Ennf}y>sFNF|bZee_W`hMo zbNX{>*NfLfM$DU+HlCp)5p2Mb4bX2a*F0TS;nr11M7gA>zX_OU^;fhQ+P7hZ#x}{%(QDS>2!aQB21i?#p_8 z(_>6rVdKN@P4n$E;lcYK3?!X1SNYrF8|zr76+17{7v9o3d3gf&xmCW5tqm{LhrJ

5Qw8bKh&lU^tkaeKh0(DtnAPYRj#ErXG4^q6m@+Ko+ z_uJruis%1$=|x0z@ok5EIBsn8&C8D|*U2uc40$2n zSC%uNC6E6e{j+>8eQZ0i>3yDGKq%_uWFX-{eZJ`4`8smm*NIPzhOWb=?&_-QmvsMA z0k!pY*Nk*jTvXKR$^zHKDem#l>z(-+N5)9hAc~m)KQ-fq#;3^1m%%?>|u_ zRgM0?)nn1SfM%1i7mN!^4)<7A1N%KX)aSR}3H-UgH&3mR;{|u842&3Ew((Ud);M@{o{_c%kh_{2``3MSlJ>q3``dhgC|J zTLnzG{4>%j*NU5rv+{GyUX4xFf3ju`=jj+utKLlI4JK5fX!server) in bytes. The size which is measured is + # the serialized, uncompressed payload in bytes. This applies both + # to streaming and non-streaming requests. + # + # The actual value used is the minimum of the value specified here and + # the value set by the application via the gRPC client API. + # If either one is not set, then the other will be used. + # If neither is set, then the built-in default is used. + # + # If a client attempts to send an object larger than this value, it + # will not be sent and the client will see an error. + # Note that 0 is a valid value, meaning that the request message must + # be empty. + # + # The format of the value is that of the 'uint64' type defined here: + # https://developers.google.com/protocol-buffers/docs/proto3#json + 'maxRequestMessageBytes': string, + + # The maximum allowed payload size for an individual response or object + # in a stream (server->client) in bytes. The size which is measured is + # the serialized, uncompressed payload in bytes. This applies both + # to streaming and non-streaming requests. + # + # The actual value used is the minimum of the value specified here and + # the value set by the application via the gRPC client API. + # If either one is not set, then the other will be used. + # If neither is set, then the built-in default is used. + # + # If a server attempts to send an object larger than this value, it + # will not be sent, and the client will see an error. + # Note that 0 is a valid value, meaning that the response message must + # be empty. + # + # The format of the value is that of the 'uint64' type defined here: + # https://developers.google.com/protocol-buffers/docs/proto3#json + 'maxResponseMessageBytes': string + } + ] +} +``` + +# Architecture + +A service config is associated with a server name. The [name +resolver](naming.md) plugin, when asked to resolve a particular server +name, will return both the resolved addresses and the service config. + +TODO(roth): Design how the service config will be encoded in DNS. + + + + +The gRPC load balancing implements the external load balancing server approach: +an external load balancer provides simple clients with an up-to-date list of +servers. + +![image](images/load_balancing_design.png) + +1. On startup, the gRPC client issues a name resolution request for the service. + The name will resolve to one or more IP addresses to gRPC servers, a hint on + whether the IP address(es) point to a load balancer or not, and also return a + client config. +2. The gRPC client connects to a gRPC Server. + 1. If the name resolution has hinted that the endpoint is a load balancer, + the client's gRPC LB policy will attempt to open a stream to the load + balancer service. The server may respond in only one of the following + ways. + 1. `status::UNIMPLEMENTED`. There is no loadbalancing in use. The client + call will fail. + 2. "I am a Load Balancer and here is the server list." (Goto Step 4.) + 3. "Please contact Load Balancer X" (See Step 3.) The client will close + this connection and cancel the stream. + 4. If the server fails to respond, the client will wait for some timeout + and then re-resolve the name (process to Step 1 above). + 2. If the name resolution has not hinted that the endpoint is a load + balancer, the client connects directly to the service it wants to talk to. +3. The gRPC client's gRPC LB policy opens a separate connection to the Load + Balancer. If this fails, it will go back to step 1 and try another address. + 1. During channel initialization to the Load Balancer, the client will + attempt to open a stream to the Load Balancer service. + 2. The Load Balancer will return a server list to the gRPC client. If the + server list is empty, the call will wait until a non-empty one is + received. Optional: The Load Balancer will also open channels to the gRPC + servers if load reporting is needed. +4. The gRPC client will send RPCs to the gRPC servers contained in the server + list from the Load Balancer. +5. Optional: The gRPC servers may periodically report load to the Load Balancer. + +## Client + +When establishing a gRPC _stream_ to the balancer, the client will send an initial +request to the load balancer (via a regular gRPC message). The load balancer +will respond with client config (including, for example, settings for flow +control, RPC deadlines, etc.) or a redirect to another load balancer. If the +balancer did not redirect the client, it will then send a list of servers to the +client. The client will contain simple load balancing logic for choosing the +next server when it needs to send a request. + +## Load Balancer + +The Load Balancer is responsible for providing the client with a list of servers +and client RPC parameters. The balancer chooses when to update the list of +servers and can decide whether to provide a complete list, a subset, or a +specific list of “picked” servers in a particular order. The balancer can +optionally provide an expiration interval after which the server list should no +longer be trusted and should be updated by the balancer. + +The load balancer may open reporting streams to each server contained in the +server list. These streams are primarily used for load reporting. For example, +Weighted Round Robin requires that the servers report utilization to the load +balancer in order to compute the next list of servers. + +## Server + +The gRPC Server is responsible for answering RPC requests and providing +responses to the client. The server will also report load to the load balancer +if a reporting stream was opened for this purpose. From 8fda5511cb8dea5cb7fcd163253893f3d89357a1 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 14 Dec 2016 08:05:55 -0800 Subject: [PATCH 119/261] Finish docs. --- doc/load-balancing.md | 44 ++++-------------------- doc/service_config.md | 78 +++++++------------------------------------ 2 files changed, 19 insertions(+), 103 deletions(-) diff --git a/doc/load-balancing.md b/doc/load-balancing.md index 03c9bd2cbad..4ed938c9903 100644 --- a/doc/load-balancing.md +++ b/doc/load-balancing.md @@ -11,7 +11,7 @@ instruct the client how to send load to multiple backend servers. Prior to any gRPC specifics, we explore some usual ways to approach load balancing. -### Proxy Model +## Proxy Model Using a proxy provides a solid trustable client that can report load to the load balancing system. Proxies typically require more resources to operate since they @@ -21,7 +21,7 @@ latency to the RPCs. The proxy model was deemed inefficient when considering request heavy services like storage. -### Balancing-aware Client +## Balancing-aware Client This thicker client places more of the load balancing logic in the client. For example, the client could contain many load balancing policies (Round Robin, @@ -41,7 +41,7 @@ It would also significantly complicate the client's code: the new design hides the load balancing complexity of multiple layers and presents it as a simple list of servers to the client. -### External Load Balancing Service +## External Load Balancing Service The client load balancing code is kept simple and portable, implementing well-known algorithms (e.g., Round Robin) for server selection. @@ -56,7 +56,7 @@ servers to collect load and health information. # Requirements -### Simple API and client +## Simple API and client The gRPC client load balancing code must be simple and portable. The client should only contain simple algorithms (e.g., Round Robin) for @@ -68,7 +68,7 @@ unavailability or health issues. The load balancer will make any necessary complex decisions and inform the client. The load balancer may communicate with the backend servers to collect load and health information. -### Security +## Security The load balancer may be separate from the actual server backends and a compromise of the load balancer should only lead to a compromise of the @@ -90,13 +90,13 @@ However, there are only a small number of these (one of which is the are discouraged from trying to extend gRPC by adding more. Instead, new load balancing policies should be implemented in external load balancers. -## Load Balancing Policies +## Workflow Load-balancing policies fit into the gRPC client workflow in between name resolution and the connection to the server. Here's how it all works: -![image](images/load_balancing_design.png) +![image](images/load-balancing.svg) 1. On startup, the gRPC client issues a [name resolution](naming.md) request for the server name. The name will resolve to one or more IP addresses, @@ -130,33 +130,3 @@ works: received. 6. The gRPC client will send RPCs to the gRPC servers contained in the server list from the Load Balancer. - -## Client - -When establishing a gRPC _stream_ to the balancer, the client will send an initial -request to the load balancer (via a regular gRPC message). The load balancer -will respond with client config (including, for example, settings for flow -control, RPC deadlines, etc.) or a redirect to another load balancer. If the -balancer did not redirect the client, it will then send a list of servers to the -client. The client will contain simple load balancing logic for choosing the -next server when it needs to send a request. - -## Load Balancer - -The Load Balancer is responsible for providing the client with a list of servers -and client RPC parameters. The balancer chooses when to update the list of -servers and can decide whether to provide a complete list, a subset, or a -specific list of “picked” servers in a particular order. The balancer can -optionally provide an expiration interval after which the server list should no -longer be trusted and should be updated by the balancer. - -The load balancer may open reporting streams to each server contained in the -server list. These streams are primarily used for load reporting. For example, -Weighted Round Robin requires that the servers report utilization to the load -balancer in order to compute the next list of servers. - -## Server - -The gRPC Server is responsible for answering RPC requests and providing -responses to the client. The server will also report load to the load balancer -if a reporting stream was opened for this purpose. diff --git a/doc/service_config.md b/doc/service_config.md index 6093fc34453..7318b69f214 100644 --- a/doc/service_config.md +++ b/doc/service_config.md @@ -123,6 +123,9 @@ The service config is a JSON string of the following form: } ``` +Note that new per-method parameters may be added in the future as new +functionality is introduced. + # Architecture A service config is associated with a server name. The [name @@ -131,71 +134,14 @@ name, will return both the resolved addresses and the service config. TODO(roth): Design how the service config will be encoded in DNS. +# APIs +The service config is used in the following APIs: - -The gRPC load balancing implements the external load balancing server approach: -an external load balancer provides simple clients with an up-to-date list of -servers. - -![image](images/load_balancing_design.png) - -1. On startup, the gRPC client issues a name resolution request for the service. - The name will resolve to one or more IP addresses to gRPC servers, a hint on - whether the IP address(es) point to a load balancer or not, and also return a - client config. -2. The gRPC client connects to a gRPC Server. - 1. If the name resolution has hinted that the endpoint is a load balancer, - the client's gRPC LB policy will attempt to open a stream to the load - balancer service. The server may respond in only one of the following - ways. - 1. `status::UNIMPLEMENTED`. There is no loadbalancing in use. The client - call will fail. - 2. "I am a Load Balancer and here is the server list." (Goto Step 4.) - 3. "Please contact Load Balancer X" (See Step 3.) The client will close - this connection and cancel the stream. - 4. If the server fails to respond, the client will wait for some timeout - and then re-resolve the name (process to Step 1 above). - 2. If the name resolution has not hinted that the endpoint is a load - balancer, the client connects directly to the service it wants to talk to. -3. The gRPC client's gRPC LB policy opens a separate connection to the Load - Balancer. If this fails, it will go back to step 1 and try another address. - 1. During channel initialization to the Load Balancer, the client will - attempt to open a stream to the Load Balancer service. - 2. The Load Balancer will return a server list to the gRPC client. If the - server list is empty, the call will wait until a non-empty one is - received. Optional: The Load Balancer will also open channels to the gRPC - servers if load reporting is needed. -4. The gRPC client will send RPCs to the gRPC servers contained in the server - list from the Load Balancer. -5. Optional: The gRPC servers may periodically report load to the Load Balancer. - -## Client - -When establishing a gRPC _stream_ to the balancer, the client will send an initial -request to the load balancer (via a regular gRPC message). The load balancer -will respond with client config (including, for example, settings for flow -control, RPC deadlines, etc.) or a redirect to another load balancer. If the -balancer did not redirect the client, it will then send a list of servers to the -client. The client will contain simple load balancing logic for choosing the -next server when it needs to send a request. - -## Load Balancer - -The Load Balancer is responsible for providing the client with a list of servers -and client RPC parameters. The balancer chooses when to update the list of -servers and can decide whether to provide a complete list, a subset, or a -specific list of “picked” servers in a particular order. The balancer can -optionally provide an expiration interval after which the server list should no -longer be trusted and should be updated by the balancer. - -The load balancer may open reporting streams to each server contained in the -server list. These streams are primarily used for load reporting. For example, -Weighted Round Robin requires that the servers report utilization to the load -balancer in order to compute the next list of servers. - -## Server - -The gRPC Server is responsible for answering RPC requests and providing -responses to the client. The server will also report load to the load balancer -if a reporting stream was opened for this purpose. +- In the resolver API, used by resolver plugins to return the service + config to the gRPC client. +- In the gRPC client API, where users can query the channel to obtain + the service config associated with the channel (for debugging + purposes). +- In the gRPC client API, where users can set the service config + explicitly. This is intended for use in unit tests. From b3f811c7397e06d5c80317bdbda900aed914cf4a Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 14 Dec 2016 08:10:11 -0800 Subject: [PATCH 120/261] Add image in PNG format. --- doc/images/load-balancing.png | Bin 0 -> 27733 bytes doc/load-balancing.md | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) create mode 100644 doc/images/load-balancing.png diff --git a/doc/images/load-balancing.png b/doc/images/load-balancing.png new file mode 100644 index 0000000000000000000000000000000000000000..18b68bfdad83d15b33f37eeeb98f582feb8ee0c0 GIT binary patch literal 27733 zcmeFZg;!M3_cwfJXb@>pDFFecrBjd)gOu))?qzK{e9Q_yzlc5ylXvox$tuCxhM8MXYYMJ`*VpSU3!CB*Am+_s3`Lm094P0pkTrK=5C6~4pEZi(E<|_PW{9#=c+`a$v&+x02TAkY;hvgR(Ub+AvA!n+UQXI$(4h8`D*&Njz-&%uR%J{R&WnhbP-`|Sh$-4yr zQ&Ib>M~a~{U>SJH(h3R|u3YeD-pBs-498LsfQ#Hgp$PwuP5rhO>6wCpwk-g!;ZI}7 zR=G!$l7?*$ygY?HvZt;w2-*?@@UgPH*?Tl#p{)LJ)srGyd;tC+A?LG~YQ2}W z2yC0x**Ms6%3Gw{c_>iilQ>FgdZtB?b^ih|lOk~sVuApfL@^4&F2n#*0e6pr1HZDS zH!w&5O=k)9ZN$vi2BwoA;USuu{AX?aDGjMcn`*eyzK>zTv%8wwqGlhYdAGw9EpQ?b z9&6c7PMqXOj~RCdum^(KdhB#%Nrvylod!e9vY~ZPz94*hui@dknhr=D)n_D^_czx* zuu0>XT{~R;@iG75F7DnEa!oLG?_C=5I?;lv8!qG;*u;>ZMKb6=u8C1_4z3$rbIalFhi(SPQ95 z4Ql#M5*wgUO%TuV-*%~NDAQNlj8+s}bD(-5La-NPjaG>w%y1=v*W)I9_HFeW^f4m! zs;p4o+UXiTEw4-B>N#35(G@PfgPPj;W|VF=JML}ZW-SERlP3n86y{9BuHLNTGYwF@ zKID8p&4K{gAWX` z6C!Yc9GM<6QIlj=+zZYj%2%t043X{HpQCagNoCW#+Uitoe#_*iLy+6})~=sUwCd;_|pre9Sf3mgmkD&Kf-?9#ITcomX}d^m}8 z7fc~X#y&ojUW~OKXf~Nm(wg*suM{gfTko z$>66@K!>@+QgvqFhrV@-`$D`RT9bF_j*foPlo_ZfMJz4@ zuKlYV|hGuH$AAJ?h;^Tfv<@lbAM$*LP0vmv(@5 zv#D*ebC?~AY3A=Ma4PV5b(>F5Zgkq$d>XT;omuLG@sZF^f0#RZoGmCV?7geMYIS5j zt*N+e>?{rT@VASoN$N29ZEjKThbp)Lzm+;2SPp8AM`7_B@%$l)>ixkZ1+CWa)S!`d z#sL<>sR7OqxsZgx!gIY9fGN7mUE|Ls^uNy-sHxJM8_xMU1@x7sI~`oS-_xW6)!P7j}uue8JwS-#Ej*fGzlY{XeUN zPZ^GeK)ryQ3%t6V002q$*M}^N0Dr{-4%dwikR9Zo=yEE3vaNA#D-Mw<2~HE+Ozvx% zU8UO{5_WIF*RhkA?T%OCH3=9&FU2-3hus|08Sz@h$BX@W2sV!0IIwqBn!xka^KE}o zOFcuC@mttduq&BgTjmR)*)_<_t?$*{-_!E=ESg8g&o=C_BLho|pr4HV-_5|zSRR{# zedF@K0d|Rg26^|Z@I|8h_Ox$~ecWh>c*0<7XKLg*Y4wM|z?}~M_xI_)Dxkprw+gaeHy;6( zgl5>e;Q##rtmEB#9mWi&z>a|&sV9ucLgYIwJDL_GcfPPca_ToN&TE* z>-1;qQ9mugmTn*gDW~bGOU>y2zOR&h>}!!iIsJa(NB%i1meA}SiykPdg&!nllVj1k zUSEOBg`UZRvV$Eb8D!@SD z5b8TMdBxsx(r(u_v`|R0AagP!TyNg3YaHa<(06s#MM}6(K!cQz;PIJO#I|rGC|&+4 z{|3zbJ8Ki&Kj{Gg!mO+hdXj}PiK8P<0c7p)t0}Yb$ zWt5Ab2|u;OT{v6SL3&eH?W`DUP@Ce~m(s&=Q&kkA4xN2c@qFN^hx5hCUB<)o8s-s< zs1bU`?OV;=!j-i2%hbvx!xEWb&%lUg9YV7mwce9E!uhd_{drsNj#{NVnq_WA$EZtKf=(CwbXLi$Z*WI z#5~&BjPj-`p={aBWo*5q5d@bmxLdfj0-Q}Prio}<6XWZIVsjHmYN}HCgrWvi z7)KmwY$N1XE;rHRGk$GiY6UwZO~0n{7%H2JR)hnu#nJPT@%?)?({j^E@Udgt9qVpB4TRICloK6x zla7r*eN8OFa|~{`3t@NbV{jW*MS7EN8nVL=4WN8Ip>j4!@v;dg{i`I;4-^M9H%ZKh z)lx;y1)rcI+K4&$|hosS_&Xzkz zcvZN$1G>|~eD2FUey+MHPfEWRPa%}&562>}Mq!zC#Aw|21T(T7O%rn`wRTOY_MCfj;vH>_jmL*W zgN$AWI*Er7c4?L-6x>9HI~`3w#vZQj2*($xuWpwo6HHD`ggT7nyaPpKDQ%4VT)dUo zfA`pt0&64k4g@{%fOQH;DrwjNFDojSSXY0pM7h_n#Gwe+RcoPHn5$4ZEeWT1d_UD1 zouKkjq(P0yHbRZa9;3`?K=YY6O>OKK@2UnEVPEYPBqI}QC)?Ai`KT^xRO9uhQ(V)Y zEEZiSG1JZpq{ND4TD6r5sXrZsHFjVut_c+bSDSH{LY%wJO4vb|8y8*~ZegTWwdL)* z=(wH_+u=6PA^b<)c($2(pR`R!lcATnb}s>vfD*@td1hsfBJ zOC4z7)DO{6A-^(uvck)GOQ6ODEpPvIM!1kjY$ii(V4@Oyi-c-G=icSA&04h<@Z79d zlP)<&*StTd9AS-D7Gs>%tC1U*pzVFVIy|(vkk7#wW>b0E5u{hqLI$(+AclkkfhJ6IwEvy-_J(2 zlpg~rpFTc02+O6(B<|Or=@WXA{Nj7AUPZPpj(7g0;3gd#D#qqOl@hb%vr){J?1ppMTUMJlVuv=65OHk2jSDq9du~u96cVm(Uu!?=rKPV zw|kY)>+-a={A4$&8+CG$^7Hs&Wh}OdOPYO0vy^FSUv_%>T=Z(472LCXA5%hK9yJ~K z4O=B8tlpdtaN;Sv&n41&b~dhwO9B85@_-Fm+36NlCb32$@&myOsES43YPM4tAVQW; zBuiw%6~xBp`CV{kTMEg(er{P+@TN+Q$b{-E7Usf+S)meY}OFf0HY*w~mD_}8&eOn-N~JVRaDpSKs;YbI@!)|i*B z83{@Tou@F-*UB_s{n2dV9tWTaOfMSvTR6`n$i%-BGw#i9&*lUT6|xEG365z-gJYPnMJ24kGGTUW*TBi;usM`<)&elmt>`t?=GYPu#W zM9yJ2(?@jTwb^p|Q!#QWmA&^<4aJ-He?6NiB&}E+pse4=<@%)uH3;^)oE&m()}eb6 zw?$tyyDh%ywLXJD9DYW*4W@_0$UEii6d`_DXE{+Y#HYu+%WCD9Ds;T095)Vtw9 zH0=kSP$+w7xVM=UvwQVkoc3!XEekga(FD3(b2)LYpvv|kxtdC-UiT&gGr1iI4I5 zr0L~~5UtO8b*akyv2@zL`)(a(*Rx)2#!cxw$ES()vd7rxYp#)AGsmlwMMLL^tCJSY zYs^m!-3^{+Nh5zS=_4$V;+g5g)`RDN0@15qF?M(P^e{i&rrjR;c90fajBT0F8kxYF zGJ;mPmfN;U)l{6~`*-?@%@|sb;-wkWq6Rd(F_$SWjN^&+(|p&i;l@77`Za|;Z-Sw* z9u2Om?H;490)RQ{NQL-zs?FI5gabkKToHaC>L9G@8_VBVt$)q6eO z)a-|#H*F4DF1`MnG4Du&FIXqtbiRYGhtF9A*YC#y*H4l7W4)|NffZ?+=4E?9lJP`4 zakOg@!v)GXYgzLy95GK{@}za+rKyzqFIq!pI9ot9f+QWCdeRWZ7c(f0**-~}tXzIR zAjwDL-$LHJRamry9u&7ZIJvujSJl*gSn7fS7WyLji=7Pg{*Tc~b2~lG|JHJ#vmxUfK%`BJR z%kkPKwxGq+>g+g!$CzJN9_hzT2bI?DaGAqM-7jl=BM*j^dGYIk95mWV>^$ zXibB}|06*=JlE#7Mi>7X39E8xQu<060QCuIai1g6e3Uz*-<)`?B_{xeb^CX31da$$ zrcp)&Jtzh>%A(t{P(4npnZ6EtGGR~088EsoafrLOU;W%ZVemsM<&FSD<(xmtW=^EU z$@7x3$>6bt@lIiYb+1QyJNY{2amvqwZ$F65U~(!G$$6SAzZ5KVfZn^G*k<~oINKav zzev|<=5WbZD96o&J!T`Xo+&D+v#9E+OdNNJ7?BA;r+9#&TDlfh@qWXzd(TqOSVYu- z=dKt=Jy`x>%VqMK?vifrshp09Wpmz9*#(GgNr+HQ?;A`Xp|*=gNr&C^48IG~pFR8y z!$wV>WT0^_j>6q5$Hzy^z6_ovf;gJj7d<>(bwd@s@OT2OeU?i~=-6`U0C#e7fqEh= z#dI%QKWDL%eIl|@UNqTqS~+Eu3c0^N(0Y-)ARm&%9q^~FrrzoY>2hLxl334gTD4ce zZgtQ|O^cX5gj+2KH(h2YZrdk`mz3BnqH|jW6!1v}Gm{FY~nIz*&BbdU2zzy^IJHdRZb{jc|GJ_6xGTc@B}(30Vs! zR4C|U@|bQoCVZ5K>amQun^%{}<+9;dZegH$+Mfb7=Srnof_M=yIEN;@M+&+BqE-%= zKJx6FEJ*zr%Z+l@@b%3{j!_euwa%w@;>@_3N~P~afoFpok@RQEbJN8@BAf&qB3t;r zUB4h0O=b76zrcOo&fi!Z>hV45HYIYtX)S%mLWgpf-QYsqMi4=V*PaBL&M+xa&KLcH zh;VXy4_L!<9o(V}@KE^oycv#9J3>d^q5T7LN#K$x&C?jrh*w7R)zO@T%Hhx*zEZC3 zT#V{>x{E8}kjR?Sk2qAxnoRB$)e7xVem!&C_a@ToX&o1;J{_nLsXOc9>VlOA7QulM zzrTCignY^K`KK3vwQ6r{=uPO?+jM#c3n5KU$dT3H43>%ZgRhY4e)nGYt8uYw&;~+0wvE{@2i-m76UpE&ahdLWE`v> zU`3PkW<=%@_FUHz4nv=rtr9K7x$3N}=eNFrh{un(w8yEC$>~qG@?Ddfy6m|kmK?urJ;p7YQrx<4)b#n;C<8fi2m;yGwH7fi zl$yYH1A?J)u>PE)`w4g7A;c23#l}R6vnwu>Idtl46ty#*3hzpGSr^JWh?~Y)7s+n< zR!hU2FQm+1F*||iIS}C<%cVTOl!u@Nw%Xt*HeEV94D+xu1&A)FS3O-Vh7QGuS3Q3ofb z(iG_%M0yP2omI;1y3-}11Z6H;N^=Rst`RCu@=%>M8;f7cYXz27EG81I+YcNJ`GWfo zbGmcXw;jLx<~vnP*X(RP3Yl|R4IoF3(jqTsngmh^#ue?S%lF#V9r`U!{A;~A?4lHpRP zJEBQ3u=?me97j}vv{(9(?4z{|>Blt9&zP>Mx$l}{Avb8<$0N~sKYdQ2m7Ubc3#9?f z?X&HnahJEH4d*kSw<1Q1>k@36K^W-|7Buq0D;v=4?Hys*Uk`HcU)k8#FE0wmv1dZW z0=veLV*W+{x#KB8cWa*C6OoGMqXM|D;-I}#BQl36upRxT=qEPW>CJ`q5StMhILUk9 z7HwAc)1CD!V_Rx{Bs6|--hQqxhkZ{6>*mv%CJEiSq9A|B9rQrn)w=Et_nlPc~o zm3zc7%&F=B@;Jxx&$MxO;rJxfz+Q==w6khp0FMH!0&O z12Zo65(>f(nvYGAS3BQy=16@t9BaL2tU5O(bLzvVQkzFVJ>*SCgA^b#Iv478L`E3pV48tqua6mYR#LT86i5LlO;{s) zOQ0LqpQ0D#cCz}0Aaa($!hBZqxBQ-R=2s?U(p;vl-5PM#mLUoqD!Y?-r*zz~&5jg0SLP$+3wt(_hRhej@y* zaFC5RuyXM34K_k_XoY*YAsd`0bxNv?*)0XcW~h)sa}_Zv^RaSB6~f-8+Zx6jge4!&la{1^DvA^r=fFO2!YdDd#?nvkmy9cR}@DI{fOJc&jL z?c8=ah^%RRsxhI}{wjj<_HOk3AA}r4zd>}|$PMCHkI;uWSa4ELamN?jkH4$TLomS? znLslPMnqFJiSd~w9PkTuTbTQW)&A-!7?=$8xC{^n)0{*?6LSCIlh?qQbon1J0zjmg zHB}KY4cnqb4n2?*^`gYH7~;o$QthoFUfHtA+XP=vbee^UcFgg3B; z>oru5J)UkK*@NMt;QpYiJ;JaN9PzxL!m+pDc2)Zauad+Nu6W0#Y6^(aOUen#QbmvR z)fFb2q*D-8`szVEZ9~~9;E(XQ78bY_7!kAz0kJniGui(jt*&8sWlbp}2#q5_n8gZ@ zwpe9o{s7xYc`j73RLxYPTtf9bq6$9~O`arSCnfVq7*v<}hXF6wyFmY?Eb%t0-}O4X z`ysv7Us;TE≶ruakHo_!h6)5-R^II&4xz9ft3(4?Hh^ws2p`n`P_S6VNizeB`7o z(B>!dt5(za!~Ne$V^b#lH}l~@;*Z{vk1z6B9hH1+J4=;)spN>j63 z4h8bvyC`S*r*JHy2XYo5Gw}N;ZI+_~GLzwh24ba}Y)#6Jo~vl1#li}Im95XAP42-( z3*WFH$p2(u09n>|2Ms{teO+BxC6&G|R71Q`LO1NiI9Gu7*F77Wfx`Cxy%RIe;3r&c z@N#=PY&Hm+e$k61{Lgy-o5uN1>gDkD|3sW%ckBO62mMd3=WoWQK@mV@HA4O;A@nHx zZ*#RI3%4TDzWkrcTRLO@zp1EcyuF#u>my)_ioN@NXD)Vbu3iMQ<1+`@T770V23IM; z_ZfY+oT?O&p0ju0hSRjP#@_mz-u!){#2haK{DcjqQw>`ojUzEpn`Q(;*0p)bcL`i4O@Hp{g>V!eVZIJ7sw;rVa7m+UP0ui6b z)v0wu0H(Hi%c6y zyc-7qKguvh9;ZJdKf>F;TZMX;mC7ERF%Q(*%#FCD5?@{z4@g|r9Pxk0wM`)$*s3-C z@)>04Xg(2gbQ$sf5rTb1hwRH$s|1U;wif#LS;mg%7GD9HTyf5#NgddsX}e0^@X4dX ze8%u(Jk`Ye{D=wwDHyYkTJJ2bgX|p|Gvilq>6@cXwHPRlBPJTtoa%KYUO1`ccYb#;^|`lNYltIkBq-ah;Ci$uDd#H{l{4k3F;edca(H6Xd3nFy0y0DIT{+#oEo0o%F?>S4hUYxV z0Quvt1YfI@9OV7XGW%EaOGe z>&LLy!tU9JOgZQDi)nM-YXtZUAxhzURK^a~3;7|tHv@Pt$c2kZW8NYB3E&~v#unZmFL%}i<_Q(mSa zoH9jG6F^e4zVbto2B4c11Lv;fH7-uGnVei(rzxjt9&qpja&_qZ+%~{e6p&q;_&725 z7PbbMZQ8Axr^;NNq}y_L`(%4O{y=aIP7ZRM7|koG+I(L_G9#sK3-A8H148$-Mrap( zK?a!nZz3JB11zm;s&D@W+2s@)+@{fq@-``)+?ggSdrHfx_mmR?ZJ5Qj*eI% z%-#YY0oHuVn3LSUSk!I4HY2mp%pZj%5;N&Ip z!3y8(K^j~(le2Wa)_RN_t&fDcve+Gfy8P~Kl(^IJoyyk!wVZm1*m|`2oGK7nwt2fR z+WtCJdV55^B}7OXkoC!OMbc(63XJg@o?^hV#_moHNN`Nyh)z#aLVLIX+|Jc+yU9YwPbxP z!m^4b+)MZKMdRk$?%W2L!My?iv)|5a&wt5Q=B|sKrQ(=mxOL1PKe* zb2#&+n_n$;+1jrWqB^CJ(La+WAU;yW5hndB(En7j7vL+GpF_IZ5yccJL-lN(hnQV} z=Ja0t|MW6SjpWElPV#Vm8dKm1ozPokyrItUKSQ9g($FFa;U%%6LH?)Hzw`$=FdhL} z9vxDkg;j4WU z#6zbWrp#ai2Le4ivzw%=BH9a|FgfmhI5Wz0F6b%W=R(yZPav{hVP&}nlDk2*WDWC) zc6iRGq7y|hrYQjVobxO*(3w$ZcmLA+Mr zuIR3?EzV3>#nEBz*x0QMs^yU%VJiT}9v%DGC=6qVzAl$o2YHV#R|rV7hIWhn#`lk! z$#jx{`clJ!d>TEpTIT$C?ZAe@gZMDnQwNXrYY66g4Z(O2$o#2{?lj-V*R~3ra+!;2 zj$nwipNn|B#WoT18xA!Mg(8g)n}Q&H~e1ftKR)Q?kfKyR=2x$!XL3A zb#w**!I5jrz~D<>*oz|zo!5R%4i5G}~yB)tMZ(xj(>#ytrQW^E?&6{0=)Lc*&!= zmJ#PNL1how_Q+1v28SgxtpRb6?D}`J5AomrzWuH%S1kL4>ZH$ONz~iIH;x@5OL&}5 zZn6l*Fmg4oGeGL;K5Oipxr=ONDEljbIGFJde(PCAsyz_u%15+FGY7NOOJ{x!0iN~! zwB>F(l(h&HdipF_fo5F_e^$7X1Oj@2-3QF6s_{OjO_EE7Nf)=@L<<_zQfS_T0w2@s zRr|iDh^DRHl=;5Mt|PXWrYH!=#u6~_aC`o6b}S9*PUycZ zJcx7+iB+<;uY;y~mg_%-nR4ng#E==)k7P~Vq~1xx^q|e>rEbTPB)}jVqSfrvh|w^S z_qYR}_DwqtnN^`stN=0_L;piH`be+h=J}n@ll$vaa-@^Bu~y1+gPmGYmTr2WL5c8h z%nQgy=rcxx)%Xjw1MqQOIrLH|G{)a_v$mrknUeo)h&(Lq;RY#h&Ex7lE!)(~w;{v7zKg%d*tqajboKq1njw0g zJeh1_&&J_%BqqE3wUdJ#C2+4E?3xvf*s+Eqy)t?ZF!K*3sB;RTceY@tPZ#wcN5|yf z_IL%Abs;v#o=8Bc4?X(GRWAwhL?2XNgVq`9t>Ty4qdOw{K|`1sDp$9LyC?Y&-QgQ_ zHNCvnx|i&kHmS?^&eZFQ>Q6Es6J700W9#1XNup@Ly_PDMw)G>v3?HSYg9}q}%M_Or zWbj+Q#?>*;TRc|{$Jek(@4~f@tgv4fWsFgT{fdAOQ(y#x>-ec-G7j+UUa0>wVE*bP zqifCB*Dl~le64G|b^r39iOpyf--EWr+_U~TXv0PG)i$5cGE#DRZJ_R+vCix9#K1!w zwXZ1SfYaxiZQO2%!zv~$Aa+vhDpQCdCm>wlee9vPe1QkAAYM$TMD8!7dyQ39$yHvp zC=^Y#6^f+f_v^T|_;i#U1oD)Qqi&tq1?<9TbC-0lrrmvlPqvQIutzU5dSa@y$AVaL zV}#C5NO?5&z$6RElS-fH%Ypld4s>QWv_6hr!`=IHqSAU4T{UZRI@TSM(HoUA`({kP zX=&N+q!I+0np*&oSN8^8z5PX7ok_uye`Yvy=Pk&!<;mYIvGMsWpp7$Qk@LNKyXdhD zDa42hiGwdIp;Z)3?1KO-u2!c7{#oCDm<%+6&K2%r1g= z5XbK#ty(3j_5(nI*XFQB?!Cm%kv3Ri`H{@ReH1N0m!I_%7`WNQ=pCqF;ftpN1$Zdi zgIAj`!!V5vNnjEJM$;a!_?7RWWe+Qt0f_lj@enNyc`C*0J}^i(H6_Q?w+p5RV~LWP z-OgP~GqJ0GI`M5O;dgrar&md}Y89y8;J|;7ECwG2>GmD)`#r4%lU#;rO5YuKO;*sG z0i_M6C7ut>s9KXNo@5Phe*AiTX5wwrkP2?0KwCPI>Ud(KNz5wGSkT>yYGWr;#cC{7 zrumheq*^^w-$g_}IQq?sDNXS+>Di~BUsDg1zz9-6K@dhG93R$3`?k7V8uP;TXbUSjBhP{z@NW9dy785QV|@ij8CK^WL0KBb|s zkP!9uGIriw#h+B>FyrjsP_Y?7XB(3gie(_20mzbv897IE5!<{|pazxGp_K{Q+O_4r zn=BsEn1QF^)rs<6GQe98E1TkG)`XCg#W(^X2u!bK81fAlPmj=c3s z%>sSy56&Jdig!$|C@W+%@aBbd+|=(gOPT)R(e+2mLE}CYNE-8(FJD@-sMFr9k)o*G z`q0WH-@9=E7t3jcvT3t~t*NRPUL!>a9VSg4}&cEf)9#5p74ET_Jqcu5OIzao2 zZp(p=5PQZNkPX@SEF}MR_&CoVgPwK3btQ0RoHXWT68-qxU#u!!E`3E`+sj&4uV+s8 z$-V_mRgb<)1683CrCWn>R-b_hN=@Np^V5gGi<;0z^fOF%3y+Q9R|;g(U?c0vWCd9u z&&7GyD<3RO2X+Q5>n-7P-OlIB6zA+c>KucWQXr`mmb6aG_uDy{L@8c(z%10wzug-4 z)iVEX(7m$H%QuyTUVldD@<;x&l|)R_a>@eisZ_>ZDC%vf%c`$;{owJ9x0^pn7BEa# zBbh*=(g|DbES=0%*mx&4HaMhiJ&3`)K)J;OL8zolk)Rbrrr5tOSNe0);3WSRUa4_f zvedBdY{2;XLr?n2rr*M*4-=iyKU?rN+-XfOf1a%PAfo354@TU2d9J>rx&!$dJv>{- z=ls+fE{1~G&b^$c#(o|L<6$EOd{0Z=I)-#s_~y^GvvPdyLVD%l2K#Ij>aC4VxVgBB zCQ}k?<2=<{n+eNUX%QZ!PF{xFx0C1dX~zsvW+wMMSW?4(8#^Du8um5?LrWK%kl}%) zo};*Bp)2Q?wRst>8{;hx&Ms$}F8u<=^haJi;>;>o&S=~t-EarJfIg=?8h4LoyqPml zZAo)$_Pjy3;O3}*3*p$G^$U*yX_=s5($>^nrEL9PJG#pU_WI3yZbeSdK23{nc<_ks z#SG@6Ha@w)I>LYM*kL5dB8-DuDO=Xkear*q!jf`>vFbx8h5%d@EQZfN09v<6XTqBv z^0A;}8njU0*4t}Yv{IR_N7cJu z^#&9|rOESyvn@MG&YBexL#pci?X%uwcu==ZkeKR(^|U%v7xlcUWa>P}6SGf_F)_d3 zd&E8LEH`=N(4Bw0BM90nm6a8lUy zayg1=QTKM{!=k`^@@vhdiTT9O3i+M+eDLaEG`o#r){eZ1DT6=A53#5D^WsU3RIh>3 zh=kQ~qwlxwZl^)qGNvAt>!3Mx(4!ue+dSy-<}QTMX8Lc$=0j(rz;li6MF2s+hQ5%O z%1U$V{^LT6ihZ{aSE9C?cUJNm>Rr}GDUkamyEml5tW~Z z{A8{umc=hZ1i1nsHJaq_n;K&{eC*P1IXK@n72gMkc;fDY3;D?*Fh!&kCKz1cb8 z33NuDL7W3$y{h;wm;`#!Skqk6<)Y2OHJz55zmPR1gh(cCT5;48s36%mm+X;rD}SL z687Ff!-`+(5KXx|RYE6-^{hPLPK95=j?fY|-w^K62&br3fy6a~H5>7M?4bx`vQ!Z$ z2H(T8c&>2w$)NdZ9r3A(V@@an{hl#NUF+L2eO9g&S#L;TfRVP8>X>0}L5KtmCpTXe z)w?1uDHw}MR^NbR^COxs91?5J1WZ!OiV`pEaLYP#V>(15jA(NAzvXlmsl0lb@M(pn zrm(kV0i*$7V2>G|_=tzU*g zm2;ZTt~JC$phC=+aAv}UaPGjF;lzvjJn##RSe;wD*1w-}f2vsB6{H=BC-=bc&G$K3;HR^I`PF3I~GFS9lx`+i>}EF{zk4;DG~j(y0} zF1@JtVf(^nQk_n$_IV+JR=?N4xva*VanA*n(u(6YtW`QkH8Q~I{nL%ir)~NV6w{nHmHcg*STU6D?w#PY$D<8ufQ{X z*2AsrKO;HJuO+!XwLkq>nQ-=)n_NCDywPZ+2MeqfL?=!_T@eog>og+5L@ZoJeqn>+)1?9QYk3`|$3;%_G0^IGzZ4pmNg~#1%Ek?_{5kIg`w%o6$*6g|*ZE z6b)4GGm z%#r#A3*&vG-9aj+vzZlcJ|;#+>$wwv_;jq}Jug+uKWTntblmlkkK&sthPODHMU5V!Vzjo+KDjjT-joDn^KQNEYA20VP{Vd|9Axh3k z-egA40*rz?D^_)Px|TF~$dMhNy`^^LKC?v8q3Sbk*{y1eKU6b! z`cs1Sc5G-){zBL8b?~Tlm4GJYg$&uC zSbNTM^nH%#-dST*Q*AenQ$vW3ee>Q<`;rdmB0%xu@>9QkeT%nKFTK;tmqyo zUy4J06G^O0BKRGq<=>cx@&N$ym-(m`87r7gqmg@#t}Wzr7Z{rVNLaAL%cQIQ!6$r7 z!~A}4x7S=(e+g%0Q#_iT-z$!oH(J3GPwR0uV@iVxqu1Kg`FPE}Ev-2mB5;auXGKlk z?dY!65u;}x09gvk9N0*;7_;H;AJRjM9SO(BUog=lE&e^ri9ce;aNZi1JehbQ_j&qk z&%DO}t)K#UNC!TKUv|bQTB2=vzdQy1RDiR9ujzu^hjF_*d?+UirPNOnlm>$(Q-*=t$E8<~F>MdmBjDWp{s`4Y&%H@HMMxIgu!73V> z_fs^{{ShWNDR=gL4y744-*Zl?a|iqYQ^df%2M*cg_hYE1lwQ$+jX>6ZFu0ArkHu3M zYM}q~adqE5#yH|-JLhwsv=~*2TKAP6LphQH${LQC-)-|-g^qk2AL|>$TpqU5g6SR> z+p~A^wvLfG{S=z?5NMs}cP{W?3`3f>At z`Og;&2CNDmHRI>qdhzIiG&28xwey`(O*dP=K{O~5K|rNQ02M(|KxtA!M^wbbhbA4A zDov?EAb^N8X`-kg{hdvie9Nr= z?Ad$Io;@>r@A>VNBc%5EK9ZsK!U4d=|6Z(HAIs-PJhzUxBc~cj{`E#1*=x5dkFWTr z_}cUwL7)$|!LH{I^5%Xin^f}Q!e6`=C3@F3h(kFyF)p4VDauuASyMN$rs2$9cD?H$o6yz9TK6%u`45So+E zGu5euwI(08%SCI1{n>Pb&mP7xf=eSu6gZ_>WsOwOb>4o$?VLB#e!*tHnfg{SQTUXr z$742T1l#;}o?obT8>+OHPrh(hyL71U_xm&T+24y_OdeJ&fb?TE;NzP&^E_LA_I_3; zznLlfJ~QnjNpnl2ys%u5K1X)@-nOl~dWll(@?5NJwzSjd((PjuR#vNTqW}+In!mJE z_OT&E%)Q6MIK?Ecc|V$JV>RwJo9Jov?q_pKg{-gNfV=fXeAoMoY{ND)s#&6VBYukH%gx4aK)a{Vpa@_$`+A1VW772^j^ZWg5}u2dP@f$ zkKa3WoL5X(;>e`hgQJa+EtT&lrGQLF2R)C|tV`aw+xf(y+eW}-@FRji!bj##Vxs}% za(dwQu!!4Ix~K)Jc-;j)7ilOO3`gy6q#v}ms%(GNj8k53Gp?wwY|be6O~4uv)E1>*^ftvz7G<$-wPDWJ>`^d%e|(Rxv1B||#2ZPD-jGu&!_ z#%v_l2?46R(>&AbZ7XBo$anhcxsHIAXi!^9vZH#~1&|D-CO0GHJ9gY;@4Qv6EZ|o1 zRXADmQXPNsK6E)|8ho_C!_ngV7(_zH4WoA^QPg&PQ-iaqwj$QU&*A~)8yF{fd~%|0 z!e{o?&Gdl^EpE_#qaFXSo+12AfTKbCGOotsU`JNNj;@r6=E!knIGXi4Tlr!MP@{O| znS)5B!OKhY8v^7J#f-(mwY4e`PT=DS5fLgM;%aX*f3xMN z>Yts?Wp19?D#iPA3O{%w#_gThIWMr#IG}!fGAcXX*0>Al>M`!3w_E~KPAGvC>u*Zs z>Y$q6Uwm`Rxz`# zvTwR5?nl%)bcVv^xD*x0pJ{wPBeIaq>(6Cu;+NCeI=>B8@oSon7en z*9WC0b0c^DBULS8aiiMYN3$P{$@0~Th1wXmBh@W?W$rw*8ao?f7&-A9MX`DL36s3V+b4e~p-n&0PHEQ$=JzWLOLj0ge1acqc$@-_&_uB)O<19e)|K-cb`UHqEPE zt5j~ezF*f;d1v8^P<*cc!$EUX?vXI9!j{4obY~}Q!K%;?Dx>VI-|dks#ON9eUIm=R z0%}|PiSRRBr`Yb_-`;(wDhPVnUwKRY`RyDtQ3;v6D{1^<(ZRR)SnYh+-DV6gmL9zq zt;?%^xO;jjaN<}l%!Roqv6}e+p;ov0zJA`!XEN@vc_yfVira*Y7HCDwas)ViqqMna zW?$8sds>W|iClh1)E!XI=?%&Td2>QnGi>N}EzButT7W&H(;bt7JG2WBgS^0+kvAcMB}K^sOo;ANk z#*gND`%veb&~**B4X{K?mP8MAFhl2?fkKqqz3AfP4LNvQ&F(Wjwzlbt(XgQ0i5s(2 z4_@yxq|cM@SDrH-$5GQoQ}iVv7>wMZYf+79(jBkKRz5+`gd zAG3^G&)Pojtl71dZEWvseeVPvJ0Fr!?J@t5Bgf$vUkr?+qpZvD*6FZIwc#*lLlI?% zPoL2EZ`wB%{Oa3w7CY8G97Cy)!$F~^6k|h!sKR;@;&vHo1*?tL|@JuF21@Z zXgnb5kL$=hBCNFBg4S9^b+#HxWaqls;MpySVw?^4xE92xLuwVWjcX8dj8BNU z{+R`hcCzj|Cl>bdhoAp^?+h^IxF#9-Hhg1XEwvtpy?*hHZd@)$$Hs3(GvHOQLqgn1 zh)}|dQZbYC~|W`YRq2Xz%sCt8wSx66L`No=wRy zqIRkZkG8U-sqnd#64~l*y2sIy^I$$Caj9I9-g-3}SX4BU?=6gz);_ewMQ# z-q0`CyQPu8W`$0L5A_RKrdfU{tm^U$X0bS(HXINp6*d#5E{TyAA|@H@)$x87m8T;X zGQ?*p6?>T35FRL42mJaY!rwa#aY_ijXOLoU!E$&RQp2nPiGVIY`Y3U~0fXBf!3#B~ z)fBE8Hm4c*Jr55LpXWY4ob`FkH9#DpUTTBa$vQ9jUaP>6r|0CjZ=k1XpViq*oyEN% z3(JYmD-d9!A?-Jr?^hhN2!=j|igPp`xDTj3uP)lza>3Bf{y9p9m#ktWQESmovxJb4 z5P$t@m!62R#r66xk774|0I?sF6h%jO#|Hm(@)yZM){V3C$1J~4+pAx)CKiKna$YO7 z9CoV8yKy)b*?ySN$nsob_v@SPd7m;_R--M?3{&Kv#nID`IZ2B<0oXjjP|o_{rmc?m z;;j&gZbeejPM@x145nu3%R%;6q(SE~=$4~Gk3rfw<3T&$-Vwa!jtyQlx^B^QtT{_h zt_yMDC7eF>F)0sS9;{}iIHU2IP=3LjFXKYsUG{g}hHG)&TC3}k5mpYZ5lMh4F9=Vi zu+<$53bFNh-tfcBkYt?PmKYt0*hiMHGZ)gnyM<=-R&B zCz*69@b{hk9=m9R0!mfe@vS@&wr-{$kyD5?22uM{bqGIq!&fT~;2;I^zq6AZxE5`- zr#%@68T0Lr0zooEYOdx{O%lX0l8icQ4wd`;O!ptLxwnr|P7R*M9lRT337Y(pi^(tn ziXu7|Zf}bjm32zgF1Lq6{Tcp* zm`H&t;DYXhnmTE9YtXTQzU-h%FOzUTM}r1p1OoMramkAG6|}te?m;dUb$fYu%@sR-mi^SJAL)BDqNGzTn1+3t zn>!cy=w@wYvd288>UY#mtP(kbOZa@yX0~7q*NyY@S{85i)7d5#k!r-042x$?$DFK? zJ5%A)*t*&4YsJ`!k&}T@C>9WYdcnz|Zne_5g|a)T^YuKEQUh6Q=2tnby4?n ze*=5kbLMp&IhEe`^TniZ5HK{S5Kqbdrm~aJ`Wq4#cy)h<3;sPt6)OVupW~%L@l;b= zXO%rtIWyxFusB(mX;Z4J@}gfayAU%E1Sk{K<`=DK)hORUYERAjd2b6To($sq_Wj>^ zs?iMxs{5DsC5Z=}JN(26u7i2iJ&8c}1tbqZ3BW&HaMH0bNYsRUT(31y-Q{NF@D|9%6& z2Tvd%?jh0OCeS~n4gU8V00rG{U<~Ts)9vSLF;kz!PNy#^CPb zryD#bz1KD*s-(tW?@!e146bp(50GGH1Px_85N@kGu`{>B)v$YikBIVkJm&AO>Ygf3 zY`D5|&W}E}H;c&)9HIUE87=XEPBN}v(}4(5(;D`i_8ONeo)ZTNBU>M~t#Elg3rNIv zJwVP2?$?S`L6f?6d}T zj8Tf%3wmtn;}Cfwr|SF|fRt5(W^9$$(VkQiO|0HKfhd@47TqOx+VU~UI^`8fMO9Zb zdhfOj561T=alh%{jb#1Iu|*%Zn%PP(rBaexokAcyozaxOA5qVeLq;x%*N`=-%C+?( zH@D(DhI*UDYB6^7)N$VdY$+Afs!E;hRmly9FQrg%fm``JMygL|nlNOiq1H>2D`^f5 zTs5M7e+)`3@krG|L0M$~@+6G%3rcGf?d$Pw#!@f6md(dQlxLpzad{PIHwD4i-?`D& z746ciNEMJDK_t>aSQF@-C1`#{huH}!HKQ6(s_yHUDuCQq7I@_>a4?lvXX+1UrWEOz zyd2c>hQU{1?gIC*Tv4U*!KY66(4g-gg66j}>*ya&STnjLFe*9qIX#0qdn#yD4l<8s z?;`-)8&u>h*KRGWcVRCmdu+m1y5OxR7(2_KyH=4skDOMa*XGsnOn}qpZlq7!#AUQo`76JGj&q-_kBeN z=0+;FGXn=ls7Gm^)(#9Y^V^_tl0C`zo~g&8^-q`h`k?x4zX>+{Y0ChjJ+ViSc-^=KkQpajCwPGVu4BHSvHiK%UaQFzM_0hTCAu z713YUrE@CD6kk%nd>Ue zBR_obsG_A#rEK-##!*{pqO0ghY~mg4>^tTz>kJy>0ihOsvC}=y+#uBN{r!)!ec>*X zBrASEJC(7n#;t!*ni3-?{h4i3b$Wv>C-RF{4T37v>pxl2r*ceNV}~^mgYM;@vuBCtYiSyVU!E!ESK2Ji@QX)uelh~PcmZh)Gq|;=4wAWy)CEBmacg*@D3q#Xt08i zfBgLwWmD3wrP+Ai60D>hdB=WxK)NB(t+T=1;X9TVe}KP3S+txvIJFp1O69FRXA)7t zu-v6q#Qz$)F-#fnlOLCNQ+*m*#DjevUN>H8{?P2u{CU`9U>x`^{I?kI>^>pHZ)5o@ zCelZKDc|F}FSms2+rJL)rAjTn9_uJ^g}m@)Q%uXs>puH5m%jo$!T0Rr&ZZ^+W%X44 z(@^i)(@{Q`&W-m1Vxuv{mdZ%TnTt1j&^S>hvS33!Kd?mD1vJYh?7_^l=UTdpWqmg3+Ci$v+sjHuHOD0)J2R@&DzJnXBmT3Mb{qwU@G!%iXpAc2wi<-=3Ieln-_clcZZ?-*s{Sa6NynN3)Gz~93LDyD{DueC|UHJ9vP!$Z)aCt zr>$fVnSe)ujX|g z)FwCT=Gpa9r;O~BuiJ~!HsiJxpTTv0E4G#w_=RlK14cDL#OT~7_{j+m=t^YJ!WG>1 z%1Jxtjdp_~dnrUcDv#6#Ew^oE?vj3grV)Uky=>~;Wy^w>i{GTDYNex*y3%->oLa@K z+57N3=OG&Q)6rrrO}V0nffr|P47o?b#MS})u0g>8Gr`Vn3ofytq$TRo!7x)r#aCEB zDIqfi7Kj-MgbVLyIyXYS>;WW^<4MZtXL&PJX3mwDB7wv>6$W$c-LfN@)Yn^F?DALG zxZj$^eXN0KLPVr*(qkf@ldLj*IwqojW~Zz?L8TjwF2Mrl^7wbzeHnPS7{O&r7j0Tp zU&;co2T2t)1%vZzn8MO70Wb!f^>SS=!AvzF4!ArY~YSz$~7+) zFUX^W&%n!8sFj5?pJTX241=U>%Ne@gh#Nfe3tXj$63C7nt#eUy3u?p=6O_Ler~vO? zk3AF9Xn}eS2V2mGb{!iozs-KRXGcu5bA^6kS0fhs5c_3$Iy|xAe`z22g{eW)(@}Y4 z6NYq1kF-T%4Z#+ZV06OT>eZ6X2jzTJ71l~f_oYn7m7`AVO=lvfh|#5|FPycTiZ+9d z4Iz{2ts9&&Io!;KSV<-oE{DFZ+*Qh2zNPMn(3VDq$j?2FFLg&$OxR1#G_{?Ay6hT- zshtZmA9t=(v}q0DD6!_v;l^d}+a8)K8kz#jw`@nr^q>en4eJ!flUW+5C#8vh>b=N2c`U zO1>*Eb2y&BVtQUbv1?9>fRZ(>b$U9Pm4a$pj;w^7kNToZdhKR2xZli_a^ZHX zvAgQ=N%FGqSvTJGvBQna4?SpA`mJI(iu4Q}sb8~@31M>1M85{nZKc0e+`o%5ejCX-Yd$=v zWc;Z&UkPP`t8@XquJ{Q7-wW#V4%! zt9GWGP{QP0nZ(Y9e zxWDY9PKV&5g}qJG_Re*KpGT#SR4LI@{T`PRlEI(5j6y2!kxenc5W;07IP>&!MFHax z`FX;*dn6|X0r-N=TksD#1lF@WKcYy!D{Avmw>^x>g`Mp3RJK#Ri2AGxC4OJ(VsI^% zGAyHlDrT`L^I4IXhP)kT*`v>B0S_Qa;bcQp#iGCEY0sW+!3J2Gg5!)|qFRRC)^s*uG z9;V$LW|VBIoUuOzCMYnRx)#tawCG2pj{vzSscJHDD`M+fYd-t0SZ$Jt$cM{~(vd-C z5<6ACquBLf=S@>j!6|35m4q*7Ea$ZQ?-7s;*3hZMC1d6zVf69-Fv zws9C+Oe#Op*>zrK+{|Z4C5!AW>r>6FCcWAY)4?WADtN!37+lWbopi1yZ8G-Vb?#sr z(zE}rv>2Y=A13|$99x3UfqO5Qjd9XB|lx2o&%QC0hk6n2nJ5wg%fNWv~I;&Kh zVJ5~35@*qSdS~O%=4jiv(K3SRxCxS2Gf*n8`!H?xji`t(NV)1XC0}3XWy((F<-8vO zL#MBHf#TXNbW%+n2#SQEC@i@c95A$hb$I&5urrIk^NJZ}WCojx8x@ZiuV$VMOJU04 zRU^M!Zclrw1Zd=*bnw`f;Y1if*%AECUX48SpgnE*%At4}GRz)%w(xCRc)I{78R!#)%vBP$a`eapAW}|yZ`0G z!y$n2-;FV4@FJ3#fG@-Ul{5BXeGe9ZwiEad&wm8!3T}e`^Z%9VL?uvHa39-0$N(~6 z@N9cKyQJx8tAdIViGNB5P+z?|aex{Y_cowpUHCKP;kSJpdqzu%eaG8U-@* Date: Wed, 14 Dec 2016 08:12:39 -0800 Subject: [PATCH 121/261] Fix link. --- doc/naming.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/naming.md b/doc/naming.md index 5d603061f8a..588f611f163 100644 --- a/doc/naming.md +++ b/doc/naming.md @@ -53,7 +53,7 @@ include: is in use). - The name of the balancer, if the address is a balancer address. This will be used to perform peer authorization. -- A [service config](service-config.md). +- A [service config](service_config.md). The plugin API allows the resolvers to continuously watch an endpoint and return updated resolutions as needed. From e9fee3c48fb9fcda819a2fab648ebbbf3a6b5b7d Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 14 Dec 2016 17:36:50 -0800 Subject: [PATCH 122/261] Force use of local distributions in Python-building Pip refuses to recognize the presence of existent installations for some reason and decides to download from PyPI instead of using what's already installed as dependencies for our distributions-under-test. This forces pip to respect our wishes at the cost of some verbosity. --- tools/run_tests/build_python.sh | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/run_tests/build_python.sh b/tools/run_tests/build_python.sh index 0a73353ce5e..c3783b6faa9 100755 --- a/tools/run_tests/build_python.sh +++ b/tools/run_tests/build_python.sh @@ -162,25 +162,24 @@ pip_install_dir() { PWD=`pwd` cd $1 ($VENV_PYTHON setup.py build_ext -c $TOOLCHAIN || true) - # install the dependencies - $VENV_PYTHON -m pip install --upgrade . - # ensure that we've reinstalled the test packages - $VENV_PYTHON -m pip install --upgrade --force-reinstall --no-deps . + $VENV_PYTHON -m pip install --no-deps . cd $PWD } $VENV_PYTHON -m pip install --upgrade pip $VENV_PYTHON -m pip install setuptools $VENV_PYTHON -m pip install cython +$VENV_PYTHON -m pip install six enum34 protobuf futures pip_install_dir $ROOT + $VENV_PYTHON $ROOT/tools/distrib/python/make_grpcio_tools.py pip_install_dir $ROOT/tools/distrib/python/grpcio_tools -# TODO(atash) figure out namespace packages and grpcio-tools and auditwheel -# etc... -pip_install_dir $ROOT + $VENV_PYTHON $ROOT/src/python/grpcio_health_checking/setup.py preprocess $VENV_PYTHON $ROOT/src/python/grpcio_health_checking/setup.py build_package_protos pip_install_dir $ROOT/src/python/grpcio_health_checking + +$VENV_PYTHON -m pip install coverage oauth2client $VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py preprocess $VENV_PYTHON $ROOT/src/python/grpcio_tests/setup.py build_package_protos pip_install_dir $ROOT/src/python/grpcio_tests From e955c1f2367288f5e7047e33c48ad55ad58a9c80 Mon Sep 17 00:00:00 2001 From: Dan Born Date: Tue, 20 Dec 2016 13:48:11 -0800 Subject: [PATCH 123/261] Method to expose the resource quota of a resource user --- src/core/lib/iomgr/resource_quota.c | 5 +++++ src/core/lib/iomgr/resource_quota.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c index 213d29600c9..74c6c3e0fbf 100644 --- a/src/core/lib/iomgr/resource_quota.c +++ b/src/core/lib/iomgr/resource_quota.c @@ -695,6 +695,11 @@ grpc_resource_user *grpc_resource_user_create( return resource_user; } +grpc_resource_quota *grpc_resource_user_quota( + grpc_resource_user *resource_user) { + return resource_user->resource_quota; +} + static void ru_ref_by(grpc_resource_user *resource_user, gpr_atm amount) { GPR_ASSERT(amount > 0); GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&resource_user->refs, amount) != 0); diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 0181fd978b4..14475c864e1 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -88,6 +88,8 @@ typedef struct grpc_resource_user grpc_resource_user; grpc_resource_user *grpc_resource_user_create( grpc_resource_quota *resource_quota, const char *name); +grpc_resource_quota *grpc_resource_user_quota( + grpc_resource_user *resource_user); void grpc_resource_user_ref(grpc_resource_user *resource_user); void grpc_resource_user_unref(grpc_exec_ctx *exec_ctx, grpc_resource_user *resource_user); From 00a2d18234269e901deb7da22063c7fda210d7ee Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 27 Dec 2016 15:29:54 -0800 Subject: [PATCH 124/261] Fix flipped conditional --- src/core/lib/surface/channel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 6744570b440..f2708fdf430 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -136,7 +136,7 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - if (GRPC_MDISNULL(channel->default_authority)) { + if (!GRPC_MDISNULL(channel->default_authority)) { /* other ways of setting this (notably ssl) take precedence */ gpr_log(GPR_ERROR, "%s ignored: default host already set some other way", From 4e6247a23cf94bc363abb2e8eb0d2b03195b9c5d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 5 Jan 2017 10:17:01 -0800 Subject: [PATCH 125/261] Fix sequential write buffering --- Makefile | 2 + include/grpc/impl/codegen/grpc_types.h | 3 + .../chttp2/transport/chttp2_transport.c | 31 +- .../ext/transport/chttp2/transport/internal.h | 6 + test/core/end2end/end2end_nosec_tests.c | 8 + test/core/end2end/end2end_tests.c | 8 + test/core/end2end/gen_build_yaml.py | 1 + test/core/end2end/generate_tests.bzl | 1 + test/core/end2end/tests/write_buffering.c | 291 +++++++ .../generated/sources_and_headers.json | 6 +- tools/run_tests/generated/tests.json | 738 +++++++++++++++++- .../end2end_nosec_tests.vcxproj | 2 + .../end2end_nosec_tests.vcxproj.filters | 3 + .../tests/end2end_tests/end2end_tests.vcxproj | 2 + .../end2end_tests.vcxproj.filters | 3 + 15 files changed, 1085 insertions(+), 20 deletions(-) create mode 100644 test/core/end2end/tests/write_buffering.c diff --git a/Makefile b/Makefile index 8f7328ae285..edcf50ec71c 100644 --- a/Makefile +++ b/Makefile @@ -7215,6 +7215,7 @@ LIBEND2END_TESTS_SRC = \ test/core/end2end/tests/simple_request.c \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ + test/core/end2end/tests/write_buffering.c \ PUBLIC_HEADERS_C += \ @@ -7301,6 +7302,7 @@ LIBEND2END_NOSEC_TESTS_SRC = \ test/core/end2end/tests/simple_request.c \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ + test/core/end2end/tests/write_buffering.c \ PUBLIC_HEADERS_C += \ diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 4471ccf7456..4dfd8794992 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -179,6 +179,9 @@ typedef struct { Larger values give lower CPU usage for large messages, but more head of line blocking for small messages. */ #define GRPC_ARG_HTTP2_MAX_FRAME_SIZE "grpc.http2.max_frame_size" +/** How much data are we willing to queue up per stream if + GRPC_WRITE_BUFFER_HINT is set? This is an upper bound */ +#define GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE "grpc.http2.write_buffer_size" /** Default authority to pass if none specified on call construction. A string. * */ #define GRPC_ARG_DEFAULT_AUTHORITY "grpc.default_authority" diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 488c3b93ccd..30c66d89529 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -269,6 +269,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, window -- this should by rights be 0 */ t->force_send_settings = 1 << GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE; t->sent_local_settings = 0; + t->write_buffer_size = DEFAULT_WINDOW; if (is_client) { grpc_slice_buffer_add(&t->outbuf, grpc_slice_from_copied_string( @@ -319,6 +320,11 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_hpack_compressor_set_max_usable_size(&t->hpack_compressor, (uint32_t)value); } + } else if (0 == strcmp(channel_args->args[i].key, + GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { + t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer( + &channel_args->args[i], + (grpc_integer_options){0, 0, 64 * 1024 * 1024}); } else { static const struct { const char *channel_arg_name; @@ -895,15 +901,22 @@ static bool contains_non_ok_status(grpc_metadata_batch *batch) { return false; } +static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx *exec_ctx, + grpc_chttp2_transport *t, + grpc_chttp2_stream *s) { + if (s->id != 0 && (!s->write_buffering || + s->flow_controlled_buffer.length > t->write_buffer_size)) { + grpc_chttp2_become_writable(exec_ctx, t, s, true, "op.send_message"); + } +} + static void add_fetched_slice_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s) { s->fetched_send_message_length += (uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice); grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice); - if (s->id != 0) { - grpc_chttp2_become_writable(exec_ctx, t, s, true, "op.send_message"); - } + maybe_become_writable_due_to_send_msg(exec_ctx, t, s); } static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx, @@ -1096,14 +1109,13 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, (int64_t)len; s->complete_fetch_covered_by_poller = op->covered_by_poller; if (flags & GRPC_WRITE_BUFFER_HINT) { - /* allow up to 64kb to be buffered */ - /* TODO(ctiller): make this configurable */ - s->next_message_end_offset -= 65536; + s->next_message_end_offset -= t->write_buffer_size; + s->write_buffering = true; + } else { + s->write_buffering = false; } continue_fetching_send_locked(exec_ctx, t, s); - if (s->id != 0) { - grpc_chttp2_become_writable(exec_ctx, t, s, true, "op.send_message"); - } + maybe_become_writable_due_to_send_msg(exec_ctx, t, s); } } @@ -1112,6 +1124,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->send_trailing_metadata_finished = add_closure_barrier(on_complete); s->send_trailing_metadata = op->send_trailing_metadata; + s->write_buffering = false; const size_t metadata_size = grpc_metadata_batch_size(op->send_trailing_metadata); const size_t metadata_peer_limit = diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index a52acbacdb3..ea7beb4c2b6 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -249,6 +249,9 @@ struct grpc_chttp2_transport { int64_t announce_incoming_window; /** how much window would we like to have for incoming_window */ uint32_t connection_window_target; + /** how much data are we willing to buffer when the WRITE_BUFFER_HINT is set? + */ + uint32_t write_buffer_size; /** have we seen a goaway */ uint8_t seen_goaway; @@ -403,6 +406,9 @@ struct grpc_chttp2_stream { /** Has this stream seen an error. If true, then pending incoming frames can be thrown away. */ bool seen_error; + /** Are we buffering writes on this stream? If yes, we won't become writable + until there's enough queued up in the flow_controlled_buffer */ + bool write_buffering; /** the error that resulted in this stream being read-closed */ grpc_error *read_closed_error; diff --git a/test/core/end2end/end2end_nosec_tests.c b/test/core/end2end/end2end_nosec_tests.c index 663489082f9..03e98ee850d 100644 --- a/test/core/end2end/end2end_nosec_tests.c +++ b/test/core/end2end/end2end_nosec_tests.c @@ -135,6 +135,8 @@ extern void streaming_error_response(grpc_end2end_test_config config); extern void streaming_error_response_pre_init(void); extern void trailing_metadata(grpc_end2end_test_config config); extern void trailing_metadata_pre_init(void); +extern void write_buffering(grpc_end2end_test_config config); +extern void write_buffering_pre_init(void); void grpc_end2end_tests_pre_init(void) { GPR_ASSERT(!g_pre_init_called); @@ -185,6 +187,7 @@ void grpc_end2end_tests_pre_init(void) { simple_request_pre_init(); streaming_error_response_pre_init(); trailing_metadata_pre_init(); + write_buffering_pre_init(); } void grpc_end2end_tests(int argc, char **argv, @@ -240,6 +243,7 @@ void grpc_end2end_tests(int argc, char **argv, simple_request(config); streaming_error_response(config); trailing_metadata(config); + write_buffering(config); return; } @@ -428,6 +432,10 @@ void grpc_end2end_tests(int argc, char **argv, trailing_metadata(config); continue; } + if (0 == strcmp("write_buffering", argv[i])) { + write_buffering(config); + continue; + } gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]); abort(); } diff --git a/test/core/end2end/end2end_tests.c b/test/core/end2end/end2end_tests.c index 25c7c62fde5..f116dc0c70b 100644 --- a/test/core/end2end/end2end_tests.c +++ b/test/core/end2end/end2end_tests.c @@ -137,6 +137,8 @@ extern void streaming_error_response(grpc_end2end_test_config config); extern void streaming_error_response_pre_init(void); extern void trailing_metadata(grpc_end2end_test_config config); extern void trailing_metadata_pre_init(void); +extern void write_buffering(grpc_end2end_test_config config); +extern void write_buffering_pre_init(void); void grpc_end2end_tests_pre_init(void) { GPR_ASSERT(!g_pre_init_called); @@ -188,6 +190,7 @@ void grpc_end2end_tests_pre_init(void) { simple_request_pre_init(); streaming_error_response_pre_init(); trailing_metadata_pre_init(); + write_buffering_pre_init(); } void grpc_end2end_tests(int argc, char **argv, @@ -244,6 +247,7 @@ void grpc_end2end_tests(int argc, char **argv, simple_request(config); streaming_error_response(config); trailing_metadata(config); + write_buffering(config); return; } @@ -436,6 +440,10 @@ void grpc_end2end_tests(int argc, char **argv, trailing_metadata(config); continue; } + if (0 == strcmp("write_buffering", argv[i])) { + write_buffering(config); + continue; + } gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]); abort(); } diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 201a92a1fdc..52142c26407 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -143,6 +143,7 @@ END2END_TESTS = { 'streaming_error_response': default_test_options, 'trailing_metadata': default_test_options, 'authority_not_supported': default_test_options, + 'write_buffering': default_test_options, } diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index ed1ba3eea99..8195abab694 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -131,6 +131,7 @@ END2END_TESTS = { 'trailing_metadata': test_options(), 'authority_not_supported': test_options(), 'filter_latency': test_options(), + 'write_buffering': test_options(), } diff --git a/test/core/end2end/tests/write_buffering.c b/test/core/end2end/tests/write_buffering.c new file mode 100644 index 00000000000..856e9f0306f --- /dev/null +++ b/test/core/end2end/tests/write_buffering.c @@ -0,0 +1,291 @@ +/* + * + * Copyright 2017, 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 "test/core/end2end/end2end_tests.h" + +#include +#include + +#include +#include +#include +#include +#include +#include "test/core/end2end/cq_verifier.h" + +static void *tag(intptr_t t) { return (void *)t; } + +static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, + const char *test_name, + grpc_channel_args *client_args, + grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_server(&f, server_args); + config.init_client(&f, client_args); + return f; +} + +static gpr_timespec n_seconds_time(int n) { + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +} + +static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void shutdown_server(grpc_end2end_test_fixture *f) { + if (!f->server) return; + grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck( + f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = NULL; +} + +static void shutdown_client(grpc_end2end_test_fixture *f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = NULL; +} + +static void end_test(grpc_end2end_test_fixture *f) { + shutdown_server(f); + shutdown_client(f); + + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); +} + +/* Client sends a request with payload, server reads then returns status. */ +static void test_invoke_request_with_payload(grpc_end2end_test_config config) { + grpc_call *c; + grpc_call *s; + grpc_slice request_payload_slice1 = + grpc_slice_from_copied_string("hello world"); + grpc_byte_buffer *request_payload1 = + grpc_raw_byte_buffer_create(&request_payload_slice1, 1); + grpc_slice request_payload_slice2 = grpc_slice_from_copied_string("abc123"); + grpc_byte_buffer *request_payload2 = + grpc_raw_byte_buffer_create(&request_payload_slice2, 1); + gpr_timespec deadline = five_seconds_time(); + grpc_end2end_test_fixture f = + begin_test(config, "test_invoke_request_with_payload", NULL, NULL); + cq_verifier *cqv = cq_verifier_create(f.cq); + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_byte_buffer *request_payload_recv1 = NULL; + grpc_byte_buffer *request_payload_recv2 = NULL; + grpc_call_details call_details; + grpc_status_code status; + grpc_call_error error; + char *details = NULL; + size_t details_capacity = 0; + int was_cancelled = 2; + + c = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, + NULL); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( + f.server, &s, &call_details, + &request_metadata_recv, f.cq, f.cq, tag(101))); + CQ_EXPECT_COMPLETION(cqv, tag(1), true); /* send message is buffered */ + CQ_EXPECT_COMPLETION(cqv, tag(101), true); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message = request_payload1; + op->flags = GRPC_WRITE_BUFFER_HINT; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + /* recv message should not succeed yet - it's buffered at the client still */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &request_payload_recv1; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(2), true); + CQ_EXPECT_COMPLETION(cqv, tag(3), true); + CQ_EXPECT_COMPLETION(cqv, tag(102), true); + cq_verify(cqv); + + /* send another message, this time not buffered */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message = request_payload2; + op->flags = 0; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + /* now the first send should match up with the first recv */ + CQ_EXPECT_COMPLETION(cqv, tag(103), true); + CQ_EXPECT_COMPLETION(cqv, tag(4), true); + cq_verify(cqv); + + /* and the next recv should be ready immediately also */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &request_payload_recv2; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(104), true); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_OK; + op->data.send_status_from_server.status_details = "xyz"; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(105), 1); + CQ_EXPECT_COMPLETION(cqv, tag(4), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + validate_host_override_string("foo.test.google.fr:1234", call_details.host, + config); + GPR_ASSERT(was_cancelled == 0); + GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); + GPR_ASSERT(byte_buffer_eq_string(request_payload_recv2, "abc123")); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + + grpc_call_destroy(c); + grpc_call_destroy(s); + + cq_verifier_destroy(cqv); + + grpc_byte_buffer_destroy(request_payload1); + grpc_byte_buffer_destroy(request_payload_recv1); + grpc_byte_buffer_destroy(request_payload2); + grpc_byte_buffer_destroy(request_payload_recv2); + + end_test(&f); + config.tear_down_data(&f); +} + +void write_buffering(grpc_end2end_test_config config) { + test_invoke_request_with_payload(config); +} + +void write_buffering_pre_init(void) {} diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 6ae269cc20d..3755f242e0a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6362,7 +6362,8 @@ "test/core/end2end/tests/simple_metadata.c", "test/core/end2end/tests/simple_request.c", "test/core/end2end/tests/streaming_error_response.c", - "test/core/end2end/tests/trailing_metadata.c" + "test/core/end2end/tests/trailing_metadata.c", + "test/core/end2end/tests/write_buffering.c" ], "third_party": false, "type": "lib" @@ -6431,7 +6432,8 @@ "test/core/end2end/tests/simple_metadata.c", "test/core/end2end/tests/simple_request.c", "test/core/end2end/tests/streaming_error_response.c", - "test/core/end2end/tests/trailing_metadata.c" + "test/core/end2end/tests/trailing_metadata.c", + "test/core/end2end/tests/write_buffering.c" ], "third_party": false, "type": "lib" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b76263b8b98..50992aa436c 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -6080,6 +6080,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -7163,6 +7186,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_compress_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -8199,6 +8245,28 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_fakesec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -9165,6 +9233,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -10248,6 +10339,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -11141,6 +11255,25 @@ "linux" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_test", + "platforms": [ + "linux" + ] + }, { "args": [ "authority_not_supported" @@ -12178,6 +12311,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -13306,6 +13462,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -14389,6 +14569,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -15517,6 +15720,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_oauth2_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -16477,6 +16704,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -17487,7 +17738,7 @@ }, { "args": [ - "authority_not_supported" + "write_buffering" ], "ci_platforms": [ "windows", @@ -17501,7 +17752,7 @@ ], "flaky": false, "language": "c", - "name": "h2_sockpair+trace_test", + "name": "h2_sockpair_test", "platforms": [ "windows", "linux", @@ -17511,7 +17762,7 @@ }, { "args": [ - "bad_hostname" + "authority_not_supported" ], "ci_platforms": [ "windows", @@ -17535,7 +17786,7 @@ }, { "args": [ - "binary_metadata" + "bad_hostname" ], "ci_platforms": [ "windows", @@ -17559,7 +17810,7 @@ }, { "args": [ - "call_creds" + "binary_metadata" ], "ci_platforms": [ "windows", @@ -17583,14 +17834,14 @@ }, { "args": [ - "cancel_after_accept" + "call_creds" ], "ci_platforms": [ "windows", "linux", "posix" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [ "uv" @@ -17607,14 +17858,38 @@ }, { "args": [ - "cancel_after_client_done" + "cancel_after_accept" ], "ci_platforms": [ "windows", "linux", "posix" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, + { + "args": [ + "cancel_after_client_done" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [ "uv" @@ -18421,6 +18696,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -19487,6 +19786,32 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -20570,6 +20895,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -21653,6 +22001,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_cert_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -22613,6 +22984,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_ssl_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -23671,6 +24066,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -24731,6 +25149,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -25791,6 +26232,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_compress_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -26734,6 +27198,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_nosec_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -27794,6 +28281,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -28668,6 +29178,25 @@ "linux" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_nosec_test", + "platforms": [ + "linux" + ] + }, { "args": [ "authority_not_supported" @@ -29682,6 +30211,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -30786,6 +31338,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -31846,6 +32422,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -32782,6 +33381,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -33766,6 +34389,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -34678,6 +35325,30 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -35718,6 +36389,32 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -36753,6 +37450,29 @@ "posix" ] }, + { + "args": [ + "write_buffering" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_nosec_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "--scenarios_json", diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj index 4fb8f8f4a15..5f1ea5ed274 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj @@ -247,6 +247,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters index ff82a4dd43c..5f38c36f78d 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters @@ -145,6 +145,9 @@ test\core\end2end\tests + + test\core\end2end\tests + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj index 0b7d7c2e752..83e57eff7d0 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj @@ -249,6 +249,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters index e641930e64a..00587c05b82 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters @@ -148,6 +148,9 @@ test\core\end2end\tests + + test\core\end2end\tests + From 2ef5a647bfb2bc9390a14be843647c2fb7841b36 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 5 Jan 2017 10:33:47 -0800 Subject: [PATCH 126/261] Add a test of finishing buffering with EOS --- Makefile | 2 + test/core/end2end/end2end_nosec_tests.c | 8 + test/core/end2end/end2end_tests.c | 8 + test/core/end2end/gen_build_yaml.py | 1 + test/core/end2end/generate_tests.bzl | 1 + .../end2end/tests/write_buffering_at_end.c | 280 +++++++ .../generated/sources_and_headers.json | 6 +- tools/run_tests/generated/tests.json | 738 +++++++++++++++++- .../end2end_nosec_tests.vcxproj | 2 + .../end2end_nosec_tests.vcxproj.filters | 3 + .../tests/end2end_tests/end2end_tests.vcxproj | 2 + .../end2end_tests.vcxproj.filters | 3 + 12 files changed, 1043 insertions(+), 11 deletions(-) create mode 100644 test/core/end2end/tests/write_buffering_at_end.c diff --git a/Makefile b/Makefile index edcf50ec71c..da06d17547c 100644 --- a/Makefile +++ b/Makefile @@ -7216,6 +7216,7 @@ LIBEND2END_TESTS_SRC = \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ test/core/end2end/tests/write_buffering.c \ + test/core/end2end/tests/write_buffering_at_end.c \ PUBLIC_HEADERS_C += \ @@ -7303,6 +7304,7 @@ LIBEND2END_NOSEC_TESTS_SRC = \ test/core/end2end/tests/streaming_error_response.c \ test/core/end2end/tests/trailing_metadata.c \ test/core/end2end/tests/write_buffering.c \ + test/core/end2end/tests/write_buffering_at_end.c \ PUBLIC_HEADERS_C += \ diff --git a/test/core/end2end/end2end_nosec_tests.c b/test/core/end2end/end2end_nosec_tests.c index 03e98ee850d..b162bf2f40f 100644 --- a/test/core/end2end/end2end_nosec_tests.c +++ b/test/core/end2end/end2end_nosec_tests.c @@ -137,6 +137,8 @@ extern void trailing_metadata(grpc_end2end_test_config config); extern void trailing_metadata_pre_init(void); extern void write_buffering(grpc_end2end_test_config config); extern void write_buffering_pre_init(void); +extern void write_buffering_at_end(grpc_end2end_test_config config); +extern void write_buffering_at_end_pre_init(void); void grpc_end2end_tests_pre_init(void) { GPR_ASSERT(!g_pre_init_called); @@ -188,6 +190,7 @@ void grpc_end2end_tests_pre_init(void) { streaming_error_response_pre_init(); trailing_metadata_pre_init(); write_buffering_pre_init(); + write_buffering_at_end_pre_init(); } void grpc_end2end_tests(int argc, char **argv, @@ -244,6 +247,7 @@ void grpc_end2end_tests(int argc, char **argv, streaming_error_response(config); trailing_metadata(config); write_buffering(config); + write_buffering_at_end(config); return; } @@ -436,6 +440,10 @@ void grpc_end2end_tests(int argc, char **argv, write_buffering(config); continue; } + if (0 == strcmp("write_buffering_at_end", argv[i])) { + write_buffering_at_end(config); + continue; + } gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]); abort(); } diff --git a/test/core/end2end/end2end_tests.c b/test/core/end2end/end2end_tests.c index f116dc0c70b..9bca0c81f67 100644 --- a/test/core/end2end/end2end_tests.c +++ b/test/core/end2end/end2end_tests.c @@ -139,6 +139,8 @@ extern void trailing_metadata(grpc_end2end_test_config config); extern void trailing_metadata_pre_init(void); extern void write_buffering(grpc_end2end_test_config config); extern void write_buffering_pre_init(void); +extern void write_buffering_at_end(grpc_end2end_test_config config); +extern void write_buffering_at_end_pre_init(void); void grpc_end2end_tests_pre_init(void) { GPR_ASSERT(!g_pre_init_called); @@ -191,6 +193,7 @@ void grpc_end2end_tests_pre_init(void) { streaming_error_response_pre_init(); trailing_metadata_pre_init(); write_buffering_pre_init(); + write_buffering_at_end_pre_init(); } void grpc_end2end_tests(int argc, char **argv, @@ -248,6 +251,7 @@ void grpc_end2end_tests(int argc, char **argv, streaming_error_response(config); trailing_metadata(config); write_buffering(config); + write_buffering_at_end(config); return; } @@ -444,6 +448,10 @@ void grpc_end2end_tests(int argc, char **argv, write_buffering(config); continue; } + if (0 == strcmp("write_buffering_at_end", argv[i])) { + write_buffering_at_end(config); + continue; + } gpr_log(GPR_DEBUG, "not a test: '%s'", argv[i]); abort(); } diff --git a/test/core/end2end/gen_build_yaml.py b/test/core/end2end/gen_build_yaml.py index 52142c26407..bcb7136eaa2 100755 --- a/test/core/end2end/gen_build_yaml.py +++ b/test/core/end2end/gen_build_yaml.py @@ -144,6 +144,7 @@ END2END_TESTS = { 'trailing_metadata': default_test_options, 'authority_not_supported': default_test_options, 'write_buffering': default_test_options, + 'write_buffering_at_end': default_test_options, } diff --git a/test/core/end2end/generate_tests.bzl b/test/core/end2end/generate_tests.bzl index 8195abab694..95c06de73f9 100755 --- a/test/core/end2end/generate_tests.bzl +++ b/test/core/end2end/generate_tests.bzl @@ -132,6 +132,7 @@ END2END_TESTS = { 'authority_not_supported': test_options(), 'filter_latency': test_options(), 'write_buffering': test_options(), + 'write_buffering_at_end': test_options(), } diff --git a/test/core/end2end/tests/write_buffering_at_end.c b/test/core/end2end/tests/write_buffering_at_end.c new file mode 100644 index 00000000000..43aefcbdbcc --- /dev/null +++ b/test/core/end2end/tests/write_buffering_at_end.c @@ -0,0 +1,280 @@ +/* + * + * Copyright 2017, 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 "test/core/end2end/end2end_tests.h" + +#include +#include + +#include +#include +#include +#include +#include +#include "test/core/end2end/cq_verifier.h" + +static void *tag(intptr_t t) { return (void *)t; } + +static grpc_end2end_test_fixture begin_test(grpc_end2end_test_config config, + const char *test_name, + grpc_channel_args *client_args, + grpc_channel_args *server_args) { + grpc_end2end_test_fixture f; + gpr_log(GPR_INFO, "%s/%s", test_name, config.name); + f = config.create_fixture(client_args, server_args); + config.init_server(&f, server_args); + config.init_client(&f, client_args); + return f; +} + +static gpr_timespec n_seconds_time(int n) { + return GRPC_TIMEOUT_SECONDS_TO_DEADLINE(n); +} + +static gpr_timespec five_seconds_time(void) { return n_seconds_time(5); } + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, five_seconds_time(), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + +static void shutdown_server(grpc_end2end_test_fixture *f) { + if (!f->server) return; + grpc_server_shutdown_and_notify(f->server, f->cq, tag(1000)); + GPR_ASSERT(grpc_completion_queue_pluck( + f->cq, tag(1000), GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL) + .type == GRPC_OP_COMPLETE); + grpc_server_destroy(f->server); + f->server = NULL; +} + +static void shutdown_client(grpc_end2end_test_fixture *f) { + if (!f->client) return; + grpc_channel_destroy(f->client); + f->client = NULL; +} + +static void end_test(grpc_end2end_test_fixture *f) { + shutdown_server(f); + shutdown_client(f); + + grpc_completion_queue_shutdown(f->cq); + drain_cq(f->cq); + grpc_completion_queue_destroy(f->cq); +} + +/* Client sends a request with payload, server reads then returns status. */ +static void test_invoke_request_with_payload(grpc_end2end_test_config config) { + grpc_call *c; + grpc_call *s; + grpc_slice request_payload_slice = + grpc_slice_from_copied_string("hello world"); + grpc_byte_buffer *request_payload = + grpc_raw_byte_buffer_create(&request_payload_slice, 1); + gpr_timespec deadline = five_seconds_time(); + grpc_end2end_test_fixture f = + begin_test(config, "test_invoke_request_with_payload", NULL, NULL); + cq_verifier *cqv = cq_verifier_create(f.cq); + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_byte_buffer *request_payload_recv1 = NULL; + grpc_byte_buffer *request_payload_recv2 = NULL; + grpc_call_details call_details; + grpc_status_code status; + grpc_call_error error; + char *details = NULL; + size_t details_capacity = 0; + int was_cancelled = 2; + + c = grpc_channel_create_call( + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, + NULL); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(2), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( + f.server, &s, &call_details, + &request_metadata_recv, f.cq, f.cq, tag(101))); + CQ_EXPECT_COMPLETION(cqv, tag(1), true); /* send message is buffered */ + CQ_EXPECT_COMPLETION(cqv, tag(101), true); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message = request_payload; + op->flags = GRPC_WRITE_BUFFER_HINT; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 0; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(102), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + /* recv message should not succeed yet - it's buffered at the client still */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &request_payload_recv1; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(103), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(2), true); + CQ_EXPECT_COMPLETION(cqv, tag(3), true); + CQ_EXPECT_COMPLETION(cqv, tag(102), true); + cq_verify(cqv); + + /* send end of stream: should release the buffering */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + /* now the first send should match up with the first recv */ + CQ_EXPECT_COMPLETION(cqv, tag(103), true); + CQ_EXPECT_COMPLETION(cqv, tag(4), true); + cq_verify(cqv); + + /* and the next recv should be ready immediately also (and empty) */ + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &request_payload_recv2; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(104), true); + cq_verify(cqv); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(4), NULL); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; + op->data.recv_close_on_server.cancelled = &was_cancelled; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; + op->data.send_status_from_server.trailing_metadata_count = 0; + op->data.send_status_from_server.status = GRPC_STATUS_OK; + op->data.send_status_from_server.status_details = "xyz"; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(105), NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + CQ_EXPECT_COMPLETION(cqv, tag(105), 1); + CQ_EXPECT_COMPLETION(cqv, tag(4), 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_OK); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + validate_host_override_string("foo.test.google.fr:1234", call_details.host, + config); + GPR_ASSERT(was_cancelled == 0); + GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); + GPR_ASSERT(request_payload_recv2 == NULL); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + + grpc_call_destroy(c); + grpc_call_destroy(s); + + cq_verifier_destroy(cqv); + + grpc_byte_buffer_destroy(request_payload); + grpc_byte_buffer_destroy(request_payload_recv1); + + end_test(&f); + config.tear_down_data(&f); +} + +void write_buffering_at_end(grpc_end2end_test_config config) { + test_invoke_request_with_payload(config); +} + +void write_buffering_at_end_pre_init(void) {} diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 3755f242e0a..9287c839745 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6363,7 +6363,8 @@ "test/core/end2end/tests/simple_request.c", "test/core/end2end/tests/streaming_error_response.c", "test/core/end2end/tests/trailing_metadata.c", - "test/core/end2end/tests/write_buffering.c" + "test/core/end2end/tests/write_buffering.c", + "test/core/end2end/tests/write_buffering_at_end.c" ], "third_party": false, "type": "lib" @@ -6433,7 +6434,8 @@ "test/core/end2end/tests/simple_request.c", "test/core/end2end/tests/streaming_error_response.c", "test/core/end2end/tests/trailing_metadata.c", - "test/core/end2end/tests/write_buffering.c" + "test/core/end2end/tests/write_buffering.c", + "test/core/end2end/tests/write_buffering_at_end.c" ], "third_party": false, "type": "lib" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 50992aa436c..9ac477c5cd4 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -6103,6 +6103,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -7209,6 +7232,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_compress_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -8267,6 +8313,28 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_fakesec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -9256,6 +9324,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -10362,6 +10453,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -11274,6 +11388,25 @@ "linux" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_test", + "platforms": [ + "linux" + ] + }, { "args": [ "authority_not_supported" @@ -12334,6 +12467,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -13486,6 +13642,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -14592,6 +14772,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -15744,6 +15947,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_oauth2_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -16728,6 +16955,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -17762,7 +18013,7 @@ }, { "args": [ - "authority_not_supported" + "write_buffering_at_end" ], "ci_platforms": [ "windows", @@ -17776,7 +18027,7 @@ ], "flaky": false, "language": "c", - "name": "h2_sockpair+trace_test", + "name": "h2_sockpair_test", "platforms": [ "windows", "linux", @@ -17786,7 +18037,7 @@ }, { "args": [ - "bad_hostname" + "authority_not_supported" ], "ci_platforms": [ "windows", @@ -17810,7 +18061,7 @@ }, { "args": [ - "binary_metadata" + "bad_hostname" ], "ci_platforms": [ "windows", @@ -17834,7 +18085,7 @@ }, { "args": [ - "call_creds" + "binary_metadata" ], "ci_platforms": [ "windows", @@ -17858,14 +18109,14 @@ }, { "args": [ - "cancel_after_accept" + "call_creds" ], "ci_platforms": [ "windows", "linux", "posix" ], - "cpu_cost": 0.1, + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [ "uv" @@ -17882,14 +18133,38 @@ }, { "args": [ - "cancel_after_client_done" + "cancel_after_accept" ], "ci_platforms": [ "windows", "linux", "posix" ], - "cpu_cost": 1.0, + "cpu_cost": 0.1, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, + { + "args": [ + "cancel_after_client_done" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, "exclude_configs": [], "exclude_iomgrs": [ "uv" @@ -18720,6 +18995,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -19812,6 +20111,32 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -20918,6 +21243,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -22024,6 +22372,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_ssl_cert_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -23008,6 +23379,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_ssl_proxy_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -24089,6 +24484,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -25172,6 +25590,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_census_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -26255,6 +26696,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_compress_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -27221,6 +27685,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_fd_nosec_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -28304,6 +28791,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -29197,6 +29707,25 @@ "linux" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_full+pipe_nosec_test", + "platforms": [ + "linux" + ] + }, { "args": [ "authority_not_supported" @@ -30234,6 +30763,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_full+trace_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -31362,6 +31914,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_http_proxy_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -32445,6 +33021,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "language": "c", + "name": "h2_load_reporting_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -33405,6 +34004,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_proxy_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -34413,6 +35036,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -35349,6 +35996,30 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair+trace_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -36415,6 +37086,32 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "windows", + "linux", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [ + "msan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_sockpair_1byte_nosec_test", + "platforms": [ + "windows", + "linux", + "mac", + "posix" + ] + }, { "args": [ "authority_not_supported" @@ -37473,6 +38170,29 @@ "posix" ] }, + { + "args": [ + "write_buffering_at_end" + ], + "ci_platforms": [ + "linux", + "mac", + "posix" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "h2_uds_nosec_test", + "platforms": [ + "linux", + "mac", + "posix" + ] + }, { "args": [ "--scenarios_json", diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj index 5f1ea5ed274..6506f24d1bb 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj @@ -249,6 +249,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters index 5f38c36f78d..77e5ebf8b19 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_nosec_tests/end2end_nosec_tests.vcxproj.filters @@ -148,6 +148,9 @@ test\core\end2end\tests + + test\core\end2end\tests + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj index 83e57eff7d0..176e8f71976 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj @@ -251,6 +251,8 @@ + + diff --git a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters index 00587c05b82..fa702679338 100644 --- a/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters +++ b/vsprojects/vcxproj/test/end2end/tests/end2end_tests/end2end_tests.vcxproj.filters @@ -151,6 +151,9 @@ test\core\end2end\tests + + test\core\end2end\tests + From 4f8a11e5c72d8ac9d3a73b3da1baebc82d90dfd8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 5 Jan 2017 13:24:52 -0800 Subject: [PATCH 127/261] Get ASAN building again --- src/core/lib/transport/timeout_encoding.h | 2 ++ test/core/end2end/invalid_call_argument_test.c | 5 ++--- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/lib/transport/timeout_encoding.h b/src/core/lib/transport/timeout_encoding.h index 9b34cec3736..4c8025d800f 100644 --- a/src/core/lib/transport/timeout_encoding.h +++ b/src/core/lib/transport/timeout_encoding.h @@ -34,7 +34,9 @@ #ifndef GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H #define GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H +#include #include + #include "src/core/lib/support/string.h" #define GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1) diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index 839facf4886..9067b24168c 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -576,9 +576,8 @@ static void test_invalid_initial_metadata_reserved_key() { gpr_log(GPR_INFO, "test_invalid_initial_metadata_reserved_key"); grpc_metadata metadata; - metadata.key = ":start_with_colon"; - metadata.value = "value"; - metadata.value_length = 6; + metadata.key = grpc_slice_from_static_string(":start_with_colon"); + metadata.value = grpc_slice_from_static_string("value"); grpc_op *op; prepare_test(1); From 38842566f72ca51762df4dac4677bfdbd15d16d7 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 5 Jan 2017 13:49:43 -0800 Subject: [PATCH 128/261] Fix windows compilation --- src/core/lib/transport/service_config.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h index ab964b3bae3..cd739a593c2 100644 --- a/src/core/lib/transport/service_config.h +++ b/src/core/lib/transport/service_config.h @@ -66,6 +66,6 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( /// Caller does NOT own a reference to the result. void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, const grpc_slice_hash_table* table, - const grpc_slice path); + grpc_slice path); #endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ From 9490389f868f6addf0e27f8c299f1e63c76dde1e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Oct 2016 15:43:35 -0700 Subject: [PATCH 129/261] Refine error handling in call --- src/core/lib/iomgr/error.c | 1 + src/core/lib/surface/call.c | 145 ++++++++++++++++++------------------ 2 files changed, 72 insertions(+), 74 deletions(-) diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index 82edcfd16c6..f6eb8e02c97 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -349,6 +349,7 @@ static grpc_error *recursively_find_error_with_status(grpc_error *error, if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) { return error; } + if (is_special(error)) return NULL; // Otherwise, search through its children. intptr_t key = 0; while (true) { diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index ed186271e7c..04979ff4601 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -62,7 +62,7 @@ /** The maximum number of concurrent batches possible. Based upon the maximum number of individually queueable ops in the batch - api: + api: - initial metadata send - message send - status/close send (depending on client/server) @@ -98,13 +98,17 @@ typedef struct { grpc_slice details; } received_status; +#define MAX_ERRORS_PER_BATCH 3 + typedef struct batch_control { grpc_call *call; grpc_cq_completion cq_completion; grpc_closure finish_batch; void *notify_tag; gpr_refcount steps_to_complete; - grpc_error *error; + + grpc_error *errors[MAX_ERRORS_PER_BATCH]; + gpr_atm num_errors; uint8_t send_initial_metadata; uint8_t send_message; @@ -186,6 +190,7 @@ struct grpc_call { grpc_call *sibling_prev; grpc_slice_buffer_stream sending_stream; + grpc_byte_stream *receiving_stream; grpc_byte_buffer **receiving_buffer; grpc_slice receiving_slice; @@ -1000,14 +1005,74 @@ static void finish_batch_completion(grpc_exec_ctx *exec_ctx, void *user_data, GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } +static grpc_error *consolidate_batch_errors(batch_control *bctl) { + size_t n = (size_t)gpr_atm_no_barrier_load(&bctl->num_errors); + if (n == 0) { + return GRPC_ERROR_NONE; + } else if (n == 1) { + return GRPC_ERROR_REF(bctl->errors[0]); + } else { + return GRPC_ERROR_CREATE_REFERENCING("Call batch failed", bctl->errors, n); + } +} + static void post_batch_completion(grpc_exec_ctx *exec_ctx, batch_control *bctl) { + grpc_call *child_call; + grpc_call *next_child_call; grpc_call *call = bctl->call; - grpc_error *error = bctl->error; + grpc_error *error = consolidate_batch_errors(bctl); + + gpr_mu_lock(&call->mu); + + if (error != GRPC_ERROR_NONE) { + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); + } + + if (bctl->send_initial_metadata) { + grpc_metadata_batch_destroy( + exec_ctx, + &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); + } + if (bctl->send_final_op) { + grpc_metadata_batch_destroy( + exec_ctx, + &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); + } if (bctl->recv_final_op) { + grpc_metadata_batch *md = + &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; + recv_trailing_filter(exec_ctx, call, md); + + call->received_final_op = true; + /* propagate cancellation to any interested children */ + child_call = call->first_child; + if (child_call != NULL) { + do { + next_child_call = child_call->sibling_next; + if (child_call->cancellation_is_inherited) { + GRPC_CALL_INTERNAL_REF(child_call, "propagate_cancel"); + grpc_call_cancel(child_call, NULL); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, child_call, "propagate_cancel"); + } + child_call = next_child_call; + } while (child_call != call->first_child); + } + + if (call->is_client) { + get_final_status(call, set_status_value_directly, + call->final_op.client.status); + get_final_details(call, call->final_op.client.status_details); + } else { + get_final_status(call, set_cancelled_value, + call->final_op.server.cancelled); + } + GRPC_ERROR_UNREF(error); error = GRPC_ERROR_NONE; } + gpr_mu_unlock(&call->mu); + if (bctl->is_notify_tag_closure) { /* unrefs bctl->error */ grpc_closure_run(exec_ctx, bctl->notify_tag, error); @@ -1171,11 +1236,8 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, grpc_error *error) { if (error == GRPC_ERROR_NONE) return; - cancel_with_error(exec_ctx, bctl->call, GRPC_ERROR_REF(error)); - if (bctl->error == GRPC_ERROR_NONE) { - bctl->error = GRPC_ERROR_CREATE("Call batch operation failed"); - } - bctl->error = grpc_error_add_child(bctl->error, error); + int idx = (int)gpr_atm_no_barrier_fetch_add(&bctl->num_errors, 1); + bctl->errors[idx] = error; } static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, @@ -1223,76 +1285,12 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error) { batch_control *bctl = bctlp; - grpc_call *call = bctl->call; - grpc_call *child_call; - grpc_call *next_child_call; - - GRPC_ERROR_REF(error); - - gpr_mu_lock(&call->mu); - - // If the error has an associated status code, set the call's status. - intptr_t status; - if (error != GRPC_ERROR_NONE && - grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &status)) { - set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); - } - - if (bctl->send_initial_metadata) { - if (error != GRPC_ERROR_NONE) { - set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); - } - grpc_metadata_batch_destroy( - exec_ctx, - &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); - } - if (bctl->send_message) { - call->sending_message = 0; - } - if (bctl->send_final_op) { - grpc_metadata_batch_destroy( - exec_ctx, - &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); - } - if (bctl->recv_final_op) { - grpc_metadata_batch *md = - &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - recv_trailing_filter(exec_ctx, call, md); - - call->received_final_op = true; - /* propagate cancellation to any interested children */ - child_call = call->first_child; - if (child_call != NULL) { - do { - next_child_call = child_call->sibling_next; - if (child_call->cancellation_is_inherited) { - GRPC_CALL_INTERNAL_REF(child_call, "propagate_cancel"); - grpc_call_cancel(child_call, NULL); - GRPC_CALL_INTERNAL_UNREF(exec_ctx, child_call, "propagate_cancel"); - } - child_call = next_child_call; - } while (child_call != call->first_child); - } - if (call->is_client) { - get_final_status(call, set_status_value_directly, - call->final_op.client.status); - get_final_details(call, call->final_op.client.status_details); - } else { - get_final_status(call, set_cancelled_value, - call->final_op.server.cancelled); - } - - GRPC_ERROR_UNREF(error); - error = GRPC_ERROR_NONE; - } add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); - gpr_mu_unlock(&call->mu); + if (gpr_unref(&bctl->steps_to_complete)) { post_batch_completion(exec_ctx, bctl); } - - GRPC_ERROR_UNREF(error); } static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, @@ -1326,7 +1324,6 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, if (nops == 0) { GRPC_CALL_INTERNAL_REF(call, "completion"); - bctl->error = GRPC_ERROR_NONE; if (!is_notify_tag_closure) { grpc_cq_begin_op(call->cq, notify_tag); } From 841a99d7522af5cb1c9acdb2bd8bb431a8bfa758 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 12 Dec 2016 16:58:57 -0800 Subject: [PATCH 130/261] Cleaning up error handling --- src/core/lib/channel/channel_stack.c | 39 -- src/core/lib/channel/channel_stack.h | 15 +- src/core/lib/channel/deadline_filter.c | 9 +- src/core/lib/channel/message_size_filter.c | 7 +- src/core/lib/iomgr/error.c | 4 +- src/core/lib/surface/call.c | 550 +++++++++--------- src/core/lib/transport/transport.c | 87 --- src/core/lib/transport/transport.h | 12 - test/core/end2end/tests/filter_causes_close.c | 9 - 9 files changed, 279 insertions(+), 453 deletions(-) diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index fe2e50e71aa..22bdb2952ae 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -287,42 +287,3 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) { return (grpc_call_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( sizeof(grpc_call_stack))); } - -static void destroy_op(grpc_exec_ctx *exec_ctx, void *op, grpc_error *error) { - gpr_free(op); -} - -void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem) { - grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); - memset(op, 0, sizeof(*op)); - op->cancel_error = GRPC_ERROR_CANCELLED; - op->on_complete = - grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); - elem->filter->start_transport_stream_op(exec_ctx, elem, op); -} - -void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_status_code status, - grpc_slice *optional_message) { - grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); - memset(op, 0, sizeof(*op)); - op->on_complete = - grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); - grpc_transport_stream_op_add_cancellation_with_message(exec_ctx, op, status, - optional_message); - elem->filter->start_transport_stream_op(exec_ctx, elem, op); -} - -void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_status_code status, - grpc_slice *optional_message) { - grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); - memset(op, 0, sizeof(*op)); - op->on_complete = - grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); - grpc_transport_stream_op_add_close(exec_ctx, op, status, optional_message); - elem->filter->start_transport_stream_op(exec_ctx, elem, op); -} diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index f420583a8d4..1cf07d43c24 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -299,18 +299,9 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem); void grpc_call_log_op(char *file, int line, gpr_log_severity severity, grpc_call_element *elem, grpc_transport_stream_op *op); -void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, - grpc_call_element *cur_elem); - -void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *cur_elem, - grpc_status_code status, - grpc_slice *optional_message); - -void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx, - grpc_call_element *cur_elem, - grpc_status_code status, - grpc_slice *optional_message); +void grpc_call_element_signal_error(grpc_exec_ctx *exec_ctx, + grpc_call_element *cur_elem, + grpc_error *error); extern int grpc_trace_channel; diff --git a/src/core/lib/channel/deadline_filter.c b/src/core/lib/channel/deadline_filter.c index a45a4d4b820..4e140c10f19 100644 --- a/src/core/lib/channel/deadline_filter.c +++ b/src/core/lib/channel/deadline_filter.c @@ -56,10 +56,11 @@ static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg, deadline_state->timer_pending = false; gpr_mu_unlock(&deadline_state->timer_mu); if (error != GRPC_ERROR_CANCELLED) { - grpc_slice msg = grpc_slice_from_static_string("Deadline Exceeded"); - grpc_call_element_send_cancel_with_message( - exec_ctx, elem, GRPC_STATUS_DEADLINE_EXCEEDED, &msg); - grpc_slice_unref_internal(exec_ctx, msg); + grpc_call_element_signal_error( + exec_ctx, elem, + grpc_error_set_int(GRPC_ERROR_CREATE("Deadline Exceeded"), + GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_DEADLINE_EXCEEDED)); } GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); } diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index f8cdf625408..3578f208275 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -142,10 +142,11 @@ static void start_transport_stream_op(grpc_exec_ctx* exec_ctx, char* message_string; gpr_asprintf(&message_string, "Sent message larger than max (%u vs. %d)", op->send_message->length, calld->max_send_size); - grpc_slice message = grpc_slice_from_copied_string(message_string); + grpc_transport_stream_op_finish_with_failure( + exec_ctx, op, grpc_error_set_int(GRPC_ERROR_CREATE(message_string), + GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_INVALID_ARGUMENT)); gpr_free(message_string); - grpc_call_element_send_close_with_message( - exec_ctx, elem, GRPC_STATUS_INVALID_ARGUMENT, &message); } // Inject callback for receiving a message. if (op->recv_message_ready != NULL) { diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index f6eb8e02c97..e4bfa322145 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -385,9 +385,9 @@ void grpc_error_get_status(grpc_error *error, grpc_status_code *code, // If the error has a status message, use it. Otherwise, fall back to // the error description. *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); - if (*msg == NULL) { + if (*msg == NULL && status != GRPC_STATUS_OK) { *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); - if (*msg == NULL) *msg = "uknown error"; // Just in case. + if (*msg == NULL) *msg = "unknown error"; // Just in case. } } diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 04979ff4601..1c32515c933 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -92,10 +92,8 @@ typedef enum { } status_source; typedef struct { - bool is_code_set; - bool is_details_set; - grpc_status_code code; - grpc_slice details; + bool is_set; + grpc_error *error; } received_status; #define MAX_ERRORS_PER_BATCH 3 @@ -224,8 +222,6 @@ static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); -static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_error *error); static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); @@ -233,6 +229,17 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call_stack, grpc_error *error); static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error); +static void get_final_status(grpc_call *call, + void (*set_value)(grpc_status_code code, + void *user_data), + void *set_value_user_data, grpc_slice *details); +static void set_status_value_directly(grpc_status_code status, void *dest); +static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, + status_source source, grpc_error *error); +static void process_data_after_md(grpc_exec_ctx *exec_ctx, batch_control *bctl); +static void post_batch_completion(grpc_exec_ctx *exec_ctx, batch_control *bctl); +static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, + grpc_error *error); grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, const grpc_call_create_args *args, @@ -386,24 +393,6 @@ void grpc_call_internal_unref(grpc_exec_ctx *exec_ctx, grpc_call *c REF_ARG) { GRPC_CALL_STACK_UNREF(exec_ctx, CALL_STACK_FROM_CALL(c), REF_REASON); } -static void get_final_status(grpc_call *call, - void (*set_value)(grpc_status_code code, - void *user_data), - void *set_value_user_data) { - int i; - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_code_set) { - set_value(call->status[i].code, set_value_user_data); - return; - } - } - if (call->is_client) { - set_value(GRPC_STATUS_UNKNOWN, set_value_user_data); - } else { - set_value(GRPC_STATUS_OK, set_value_user_data); - } -} - static void set_status_value_directly(grpc_status_code status, void *dest); static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, grpc_error *error) { @@ -419,11 +408,6 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } gpr_mu_destroy(&c->mu); - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (c->status[i].is_details_set) { - grpc_slice_unref_internal(exec_ctx, c->status[i].details); - } - } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { GRPC_MDELEM_UNREF(exec_ctx, c->send_extra_metadata[ii].md); } @@ -437,44 +421,241 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, } grpc_channel *channel = c->channel; - get_final_status(call, set_status_value_directly, - &c->final_info.final_status); + get_final_status(call, set_status_value_directly, &c->final_info.final_status, + NULL); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + GRPC_ERROR_UNREF(c->status[i].error); + } + grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), &c->final_info, c); GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "call"); GPR_TIMER_END("destroy_call", 0); } -static void set_status_code(grpc_call *call, status_source source, - uint32_t status) { - if (call->status[source].is_code_set) return; +void grpc_call_destroy(grpc_call *c) { + int cancel; + grpc_call *parent = c->parent; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + GPR_TIMER_BEGIN("grpc_call_destroy", 0); + GRPC_API_TRACE("grpc_call_destroy(c=%p)", 1, (c)); + + if (parent) { + gpr_mu_lock(&parent->mu); + if (c == parent->first_child) { + parent->first_child = c->sibling_next; + if (c == parent->first_child) { + parent->first_child = NULL; + } + c->sibling_prev->sibling_next = c->sibling_next; + c->sibling_next->sibling_prev = c->sibling_prev; + } + gpr_mu_unlock(&parent->mu); + GRPC_CALL_INTERNAL_UNREF(&exec_ctx, parent, "child"); + } + + gpr_mu_lock(&c->mu); + GPR_ASSERT(!c->destroy_called); + c->destroy_called = 1; + cancel = !c->received_final_op; + gpr_mu_unlock(&c->mu); + if (cancel) grpc_call_cancel(c, NULL); + GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); + grpc_exec_ctx_finish(&exec_ctx); + GPR_TIMER_END("grpc_call_destroy", 0); +} + +grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) { + GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); + GPR_ASSERT(!reserved); + return grpc_call_cancel_with_status(call, GRPC_STATUS_CANCELLED, "Cancelled", + NULL); +} + +static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_transport_stream_op *op) { + grpc_call_element *elem; + + GPR_TIMER_BEGIN("execute_op", 0); + elem = CALL_ELEM_FROM_CALL(call, 0); + op->context = call->context; + elem->filter->start_transport_stream_op(exec_ctx, elem, op); + GPR_TIMER_END("execute_op", 0); +} + +char *grpc_call_get_peer(grpc_call *call) { + grpc_call_element *elem = CALL_ELEM_FROM_CALL(call, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + char *result; + GRPC_API_TRACE("grpc_call_get_peer(%p)", 1, (call)); + result = elem->filter->get_peer(&exec_ctx, elem); + if (result == NULL) { + result = grpc_channel_get_target(call->channel); + } + if (result == NULL) { + result = gpr_strdup("unknown"); + } + grpc_exec_ctx_finish(&exec_ctx); + return result; +} + +grpc_call *grpc_call_from_top_element(grpc_call_element *elem) { + return CALL_FROM_TOP_ELEM(elem); +} + +/******************************************************************************* + * CANCELLATION + */ + +grpc_call_error grpc_call_cancel_with_status(grpc_call *c, + grpc_status_code status, + const char *description, + void *reserved) { + grpc_call_error r; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + GRPC_API_TRACE( + "grpc_call_cancel_with_status(" + "c=%p, status=%d, description=%s, reserved=%p)", + 4, (c, (int)status, description, reserved)); + GPR_ASSERT(reserved == NULL); + gpr_mu_lock(&c->mu); + r = cancel_with_status(&exec_ctx, c, status, description); + gpr_mu_unlock(&c->mu); + grpc_exec_ctx_finish(&exec_ctx); + return r; +} + +typedef enum { TC_CANCEL, TC_CLOSE } termination_closure_type; + +typedef struct termination_closure { + grpc_closure closure; + grpc_call *call; + grpc_error *error; + termination_closure_type type; + grpc_transport_stream_op op; +} termination_closure; + +static void done_termination(grpc_exec_ctx *exec_ctx, void *tcp, + grpc_error *error) { + termination_closure *tc = tcp; + GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "termination"); + GRPC_ERROR_UNREF(tc->error); + gpr_free(tc); +} + +static void send_termination(grpc_exec_ctx *exec_ctx, void *tcp, + grpc_error *error) { + termination_closure *tc = tcp; + memset(&tc->op, 0, sizeof(tc->op)); + switch (tc->type) { + case TC_CANCEL: + tc->op.cancel_error = tc->error; + break; + case TC_CLOSE: + tc->op.close_error = tc->error; + break; + } + /* reuse closure to catch completion */ + grpc_closure_init(&tc->closure, done_termination, tc, + grpc_schedule_on_exec_ctx); + tc->op.on_complete = &tc->closure; + execute_op(exec_ctx, tc->call, &tc->op); +} + +static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, + termination_closure *tc) { + set_status_from_error(exec_ctx, tc->call, STATUS_FROM_API_OVERRIDE, + GRPC_ERROR_REF(tc->error)); + grpc_closure_init(&tc->closure, send_termination, tc, + grpc_schedule_on_exec_ctx); + GRPC_CALL_INTERNAL_REF(tc->call, "termination"); + grpc_closure_sched(exec_ctx, &tc->closure, GRPC_ERROR_NONE); + return GRPC_CALL_OK; +} + +static grpc_call_error terminate_with_error(grpc_exec_ctx *exec_ctx, + grpc_call *c, + termination_closure_type tc_type, + grpc_error *error) { + termination_closure *tc = gpr_malloc(sizeof(*tc)); + memset(tc, 0, sizeof(*tc)); + tc->type = tc_type; + tc->call = c; + tc->error = error; + return terminate_with_status(exec_ctx, tc); +} + +static grpc_error *error_from_status(grpc_status_code status, + const char *description) { + return grpc_error_set_int( + grpc_error_set_str(GRPC_ERROR_CREATE(description), + GRPC_ERROR_STR_GRPC_MESSAGE, description), + GRPC_ERROR_INT_GRPC_STATUS, status); +} + +static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description) { + return terminate_with_error(exec_ctx, c, TC_CANCEL, + error_from_status(status, description)); +} - call->status[source].is_code_set = true; - call->status[source].code = (grpc_status_code)status; +static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description) { + return terminate_with_error(exec_ctx, c, TC_CLOSE, + error_from_status(status, description)); } -static void set_status_details(grpc_exec_ctx *exec_ctx, grpc_call *call, - status_source source, grpc_slice status) { - if (call->status[source].is_details_set) { - grpc_slice_unref_internal(exec_ctx, status); +/******************************************************************************* + * FINAL STATUS CODE MANIPULATION + */ + +static void get_final_status(grpc_call *call, + void (*set_value)(grpc_status_code code, + void *user_data), + void *set_value_user_data, grpc_slice *details) { + int i; + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + if (call->status[i].is_set) { + const char *text = grpc_error_string(call->status[i].error); + gpr_log(GPR_DEBUG, "%s", text); + grpc_error_free_string(text); + + grpc_status_code code; + const char *msg = NULL; + grpc_error_get_status(call->status[i].error, &code, &msg); + set_value(code, set_value_user_data); + if (details != NULL) { + *details = grpc_slice_from_copied_string(msg); + } + return; + } + } + if (call->is_client) { + set_value(GRPC_STATUS_UNKNOWN, set_value_user_data); } else { - call->status[source].details = status; - call->status[source].is_details_set = true; + set_value(GRPC_STATUS_OK, set_value_user_data); } } static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, status_source source, grpc_error *error) { - grpc_status_code status; - const char *msg; - grpc_error_get_status(error, &status, &msg); - set_status_code(call, source, (uint32_t)status); - set_status_details(exec_ctx, call, source, - grpc_slice_from_copied_string(msg)); + if (call->status[source].is_set) { + GRPC_ERROR_UNREF(error); + return; + } + call->status[source].is_set = true; + call->status[source].error = error; } +/******************************************************************************* + * COMPRESSION + */ + static void set_incoming_compression_algorithm( grpc_call *call, grpc_compression_algorithm algo) { GPR_ASSERT(algo < GRPC_COMPRESS_ALGORITHMS_COUNT); @@ -560,23 +741,6 @@ uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { return encodings_accepted_by_peer; } -static void get_final_details(grpc_call *call, grpc_slice *out_details) { - int i; - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_code_set) { - if (call->status[i].is_details_set) { - *out_details = grpc_slice_ref(call->status[i].details); - } else { - goto no_details; - } - return; - } - } - -no_details: - *out_details = grpc_empty_slice(); -} - static grpc_linked_mdelem *linked_from_md(grpc_metadata *md) { return (grpc_linked_mdelem *)&md->internal_data; } @@ -647,197 +811,6 @@ static int prepare_application_metadata( return 1; } -void grpc_call_destroy(grpc_call *c) { - int cancel; - grpc_call *parent = c->parent; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - GPR_TIMER_BEGIN("grpc_call_destroy", 0); - GRPC_API_TRACE("grpc_call_destroy(c=%p)", 1, (c)); - - if (parent) { - gpr_mu_lock(&parent->mu); - if (c == parent->first_child) { - parent->first_child = c->sibling_next; - if (c == parent->first_child) { - parent->first_child = NULL; - } - c->sibling_prev->sibling_next = c->sibling_next; - c->sibling_next->sibling_prev = c->sibling_prev; - } - gpr_mu_unlock(&parent->mu); - GRPC_CALL_INTERNAL_UNREF(&exec_ctx, parent, "child"); - } - - gpr_mu_lock(&c->mu); - GPR_ASSERT(!c->destroy_called); - c->destroy_called = 1; - cancel = !c->received_final_op; - gpr_mu_unlock(&c->mu); - if (cancel) grpc_call_cancel(c, NULL); - GRPC_CALL_INTERNAL_UNREF(&exec_ctx, c, "destroy"); - grpc_exec_ctx_finish(&exec_ctx); - GPR_TIMER_END("grpc_call_destroy", 0); -} - -grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) { - GRPC_API_TRACE("grpc_call_cancel(call=%p, reserved=%p)", 2, (call, reserved)); - GPR_ASSERT(!reserved); - return grpc_call_cancel_with_status(call, GRPC_STATUS_CANCELLED, "Cancelled", - NULL); -} - -grpc_call_error grpc_call_cancel_with_status(grpc_call *c, - grpc_status_code status, - const char *description, - void *reserved) { - grpc_call_error r; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GRPC_API_TRACE( - "grpc_call_cancel_with_status(" - "c=%p, status=%d, description=%s, reserved=%p)", - 4, (c, (int)status, description, reserved)); - GPR_ASSERT(reserved == NULL); - gpr_mu_lock(&c->mu); - r = cancel_with_status(&exec_ctx, c, status, description); - gpr_mu_unlock(&c->mu); - grpc_exec_ctx_finish(&exec_ctx); - return r; -} - -typedef enum { TC_CANCEL, TC_CLOSE } termination_closure_type; - -typedef struct termination_closure { - grpc_closure closure; - grpc_call *call; - grpc_error *error; - termination_closure_type type; - grpc_transport_stream_op op; -} termination_closure; - -static void done_termination(grpc_exec_ctx *exec_ctx, void *tcp, - grpc_error *error) { - termination_closure *tc = tcp; - switch (tc->type) { - case TC_CANCEL: - GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "cancel"); - break; - case TC_CLOSE: - GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "close"); - break; - } - GRPC_ERROR_UNREF(tc->error); - gpr_free(tc); -} - -static void send_cancel(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { - termination_closure *tc = tcp; - memset(&tc->op, 0, sizeof(tc->op)); - tc->op.cancel_error = tc->error; - /* reuse closure to catch completion */ - grpc_closure_init(&tc->closure, done_termination, tc, - grpc_schedule_on_exec_ctx); - tc->op.on_complete = &tc->closure; - execute_op(exec_ctx, tc->call, &tc->op); -} - -static void send_close(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { - termination_closure *tc = tcp; - memset(&tc->op, 0, sizeof(tc->op)); - tc->op.close_error = tc->error; - /* reuse closure to catch completion */ - grpc_closure_init(&tc->closure, done_termination, tc, - grpc_schedule_on_exec_ctx); - tc->op.on_complete = &tc->closure; - execute_op(exec_ctx, tc->call, &tc->op); -} - -static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, - termination_closure *tc) { - set_status_from_error(exec_ctx, tc->call, STATUS_FROM_API_OVERRIDE, - tc->error); - - if (tc->type == TC_CANCEL) { - grpc_closure_init(&tc->closure, send_cancel, tc, grpc_schedule_on_exec_ctx); - GRPC_CALL_INTERNAL_REF(tc->call, "cancel"); - } else if (tc->type == TC_CLOSE) { - grpc_closure_init(&tc->closure, send_close, tc, grpc_schedule_on_exec_ctx); - GRPC_CALL_INTERNAL_REF(tc->call, "close"); - } - grpc_closure_sched(exec_ctx, &tc->closure, GRPC_ERROR_NONE); - return GRPC_CALL_OK; -} - -static grpc_call_error terminate_with_error(grpc_exec_ctx *exec_ctx, - grpc_call *c, - termination_closure_type tc_type, - grpc_error *error) { - termination_closure *tc = gpr_malloc(sizeof(*tc)); - memset(tc, 0, sizeof(*tc)); - tc->type = tc_type; - tc->call = c; - tc->error = error; - return terminate_with_status(exec_ctx, tc); -} - -static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_error *error) { - terminate_with_error(exec_ctx, c, TC_CANCEL, error); -} - -static grpc_error *error_from_status(grpc_status_code status, - const char *description) { - return grpc_error_set_int( - grpc_error_set_str(GRPC_ERROR_CREATE(description), - GRPC_ERROR_STR_GRPC_MESSAGE, description), - GRPC_ERROR_INT_GRPC_STATUS, status); -} - -static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description) { - return terminate_with_error(exec_ctx, c, TC_CANCEL, - error_from_status(status, description)); -} - -static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description) { - return terminate_with_error(exec_ctx, c, TC_CLOSE, - error_from_status(status, description)); -} - -static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_transport_stream_op *op) { - grpc_call_element *elem; - - GPR_TIMER_BEGIN("execute_op", 0); - elem = CALL_ELEM_FROM_CALL(call, 0); - op->context = call->context; - elem->filter->start_transport_stream_op(exec_ctx, elem, op); - GPR_TIMER_END("execute_op", 0); -} - -char *grpc_call_get_peer(grpc_call *call) { - grpc_call_element *elem = CALL_ELEM_FROM_CALL(call, 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - char *result; - GRPC_API_TRACE("grpc_call_get_peer(%p)", 1, (call)); - result = elem->filter->get_peer(&exec_ctx, elem); - if (result == NULL) { - result = grpc_channel_get_target(call->channel); - } - if (result == NULL) { - result = gpr_strdup("unknown"); - } - grpc_exec_ctx_finish(&exec_ctx); - return result; -} - -grpc_call *grpc_call_from_top_element(grpc_call_element *elem) { - return CALL_FROM_TOP_ELEM(elem); -} - /* we offset status by a small amount when storing it into transport metadata as metadata cannot store a 0 value (which is used as OK for grpc_status_codes */ @@ -880,22 +853,22 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem md) { static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, grpc_metadata_batch *b) { - if (b->idx.named.grpc_status != NULL) { - GPR_TIMER_BEGIN("status", 0); - set_status_code(call, STATUS_FROM_WIRE, - decode_status(b->idx.named.grpc_status->md)); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); - GPR_TIMER_END("status", 0); - } + uint32_t status_code = decode_status(b->idx.named.grpc_status->md); + grpc_error *error = + status_code == GRPC_STATUS_OK + ? GRPC_ERROR_NONE + : grpc_error_set_int(GRPC_ERROR_CREATE("Error received from peer"), + GRPC_ERROR_INT_GRPC_STATUS, status_code); if (b->idx.named.grpc_message != NULL) { - GPR_TIMER_BEGIN("status-details", 0); - set_status_details( - exec_ctx, call, STATUS_FROM_WIRE, - grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.grpc_message->md))); + char *msg = + grpc_slice_to_c_string(GRPC_MDVALUE(b->idx.named.grpc_message->md)); + error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); + gpr_free(msg); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); - GPR_TIMER_END("status-details", 0); } + + set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); } static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, @@ -1026,7 +999,8 @@ static void post_batch_completion(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&call->mu); if (error != GRPC_ERROR_NONE) { - set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, + GRPC_ERROR_REF(error)); } if (bctl->send_initial_metadata) { @@ -1061,11 +1035,11 @@ static void post_batch_completion(grpc_exec_ctx *exec_ctx, if (call->is_client) { get_final_status(call, set_status_value_directly, - call->final_op.client.status); - get_final_details(call, call->final_op.client.status_details); + call->final_op.client.status, + call->final_op.client.status_details); } else { get_final_status(call, set_cancelled_value, - call->final_op.server.cancelled); + call->final_op.server.cancelled, NULL); } GRPC_ERROR_UNREF(error); @@ -1468,19 +1442,25 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->send_extra_metadata_count = 1; call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( exec_ctx, call->channel, op->data.send_status_from_server.status); - if (op->data.send_status_from_server.status_details != NULL) { - call->send_extra_metadata[1].md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_slice_ref_internal( - *op->data.send_status_from_server.status_details)); - call->send_extra_metadata_count++; - set_status_details(exec_ctx, call, STATUS_FROM_API_OVERRIDE, - grpc_slice_ref_internal(GRPC_MDVALUE( - call->send_extra_metadata[1].md))); - } - if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { - set_status_code(call, STATUS_FROM_API_OVERRIDE, - (uint32_t)op->data.send_status_from_server.status); + { + grpc_error *override_error = GRPC_ERROR_NONE; + if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { + override_error = GRPC_ERROR_CREATE("Error from server send status"); + } + if (op->data.send_status_from_server.status_details != NULL) { + call->send_extra_metadata[1].md = grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_slice_ref_internal( + *op->data.send_status_from_server.status_details)); + call->send_extra_metadata_count++; + char *msg = grpc_slice_to_c_string( + GRPC_MDVALUE(call->send_extra_metadata[1].md)); + override_error = grpc_error_set_str( + override_error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); + gpr_free(msg); + } + set_status_from_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, + override_error); } if (!prepare_application_metadata( exec_ctx, call, diff --git a/src/core/lib/transport/transport.c b/src/core/lib/transport/transport.c index 8f9e6ca4ed4..4841dc3143b 100644 --- a/src/core/lib/transport/transport.c +++ b/src/core/lib/transport/transport.c @@ -175,93 +175,6 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, grpc_closure_sched(exec_ctx, op->on_complete, error); } -typedef struct { - grpc_error *error; - grpc_closure *then_call; - grpc_closure closure; -} close_message_data; - -static void free_message(grpc_exec_ctx *exec_ctx, void *p, grpc_error *error) { - close_message_data *cmd = p; - GRPC_ERROR_UNREF(cmd->error); - if (cmd->then_call != NULL) { - cmd->then_call->cb(exec_ctx, cmd->then_call->cb_arg, error); - } - gpr_free(cmd); -} - -static void add_error(grpc_transport_stream_op *op, grpc_error **which, - grpc_error *error) { - close_message_data *cmd; - cmd = gpr_malloc(sizeof(*cmd)); - cmd->error = error; - cmd->then_call = op->on_complete; - grpc_closure_init(&cmd->closure, free_message, cmd, - grpc_schedule_on_exec_ctx); - op->on_complete = &cmd->closure; - *which = error; -} - -void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, - grpc_status_code status) { - GPR_ASSERT(status != GRPC_STATUS_OK); - if (op->cancel_error == GRPC_ERROR_NONE) { - op->cancel_error = grpc_error_set_int(GRPC_ERROR_CANCELLED, - GRPC_ERROR_INT_GRPC_STATUS, status); - op->close_error = GRPC_ERROR_NONE; - } -} - -void grpc_transport_stream_op_add_cancellation_with_message( - grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, - grpc_status_code status, grpc_slice *optional_message) { - GPR_ASSERT(status != GRPC_STATUS_OK); - if (op->cancel_error != GRPC_ERROR_NONE) { - if (optional_message) { - grpc_slice_unref_internal(exec_ctx, *optional_message); - } - return; - } - grpc_error *error; - if (optional_message != NULL) { - char *msg = grpc_slice_to_c_string(*optional_message); - error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), - GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(msg); - grpc_slice_unref_internal(exec_ctx, *optional_message); - } else { - error = GRPC_ERROR_CREATE("Call cancelled"); - } - error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status); - add_error(op, &op->cancel_error, error); -} - -void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx, - grpc_transport_stream_op *op, - grpc_status_code status, - grpc_slice *optional_message) { - GPR_ASSERT(status != GRPC_STATUS_OK); - if (op->cancel_error != GRPC_ERROR_NONE || - op->close_error != GRPC_ERROR_NONE) { - if (optional_message) { - grpc_slice_unref_internal(exec_ctx, *optional_message); - } - return; - } - grpc_error *error; - if (optional_message != NULL) { - char *msg = grpc_slice_to_c_string(*optional_message); - error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), - GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(msg); - grpc_slice_unref_internal(exec_ctx, *optional_message); - } else { - error = GRPC_ERROR_CREATE("Call force closed"); - } - error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status); - add_error(op, &op->close_error, error); -} - typedef struct { grpc_closure outer_on_complete; grpc_closure *inner_on_complete; diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index d1281830aa0..5a92226942d 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -245,18 +245,6 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, grpc_error *error); -void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, - grpc_status_code status); - -void grpc_transport_stream_op_add_cancellation_with_message( - grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, - grpc_status_code status, grpc_slice *optional_message); - -void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx, - grpc_transport_stream_op *op, - grpc_status_code status, - grpc_slice *optional_message); - char *grpc_transport_stream_op_string(grpc_transport_stream_op *op); char *grpc_transport_op_string(grpc_transport_op *op); diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c index d5f96bd4f2e..8afd6815050 100644 --- a/test/core/end2end/tests/filter_causes_close.c +++ b/test/core/end2end/tests/filter_causes_close.c @@ -208,15 +208,6 @@ static void recv_im_ready(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { grpc_call_element *elem = arg; call_data *calld = elem->call_data; - if (error == GRPC_ERROR_NONE) { - // close the stream with an error. - grpc_slice message = - grpc_slice_from_copied_string("Failure that's not preventable."); - grpc_transport_stream_op *op = grpc_make_transport_stream_op(NULL); - grpc_transport_stream_op_add_close(exec_ctx, op, - GRPC_STATUS_PERMISSION_DENIED, &message); - grpc_call_next_op(exec_ctx, elem, op); - } grpc_closure_sched( exec_ctx, calld->recv_im_ready, GRPC_ERROR_CREATE_REFERENCING("Forced call to close", &error, 1)); From e9d67009e9dfa35c499cdeb0ea103bd5c379c0bb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 12 Dec 2016 17:12:45 -0800 Subject: [PATCH 131/261] Update to new error handling discipline --- src/core/lib/channel/channel_stack.c | 8 ++ .../security/transport/client_auth_filter.c | 80 +++++++++---------- .../security/transport/server_auth_filter.c | 10 --- 3 files changed, 47 insertions(+), 51 deletions(-) diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index 22bdb2952ae..ec973d4e7f8 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -287,3 +287,11 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) { return (grpc_call_stack *)((char *)(elem)-ROUND_UP_TO_ALIGNMENT_SIZE( sizeof(grpc_call_stack))); } + +void grpc_call_element_signal_error(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_error *error) { + grpc_transport_stream_op *op = grpc_make_transport_stream_op(NULL); + op->cancel_error = error; + elem->filter->start_transport_stream_op(exec_ctx, elem, op); +} diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index eb137ba3119..b20e88851ab 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -92,16 +92,6 @@ static void reset_auth_metadata_context( auth_md_context->channel_auth_context = NULL; } -static void bubble_up_error(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_status_code status, const char *error_msg) { - call_data *calld = elem->call_data; - gpr_log(GPR_ERROR, "Client side authentication failure: %s", error_msg); - grpc_slice error_slice = grpc_slice_from_copied_string(error_msg); - grpc_transport_stream_op_add_close(exec_ctx, &calld->op, status, - &error_slice); - grpc_call_next_op(exec_ctx, elem, &calld->op); -} - static void add_error(grpc_error **combined, grpc_error *error) { if (error == GRPC_ERROR_NONE) return; if (*combined == GRPC_ERROR_NONE) { @@ -121,35 +111,36 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_metadata_batch *mdb; size_t i; reset_auth_metadata_context(&calld->auth_md_context); - if (status != GRPC_CREDENTIALS_OK) { - bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, - (error_details != NULL && strlen(error_details) > 0) - ? error_details - : "Credentials failed to get metadata."); - return; - } - GPR_ASSERT(num_md <= MAX_CREDENTIALS_METADATA_COUNT); - GPR_ASSERT(op->send_initial_metadata != NULL); - mdb = op->send_initial_metadata; grpc_error *error = GRPC_ERROR_NONE; - for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md_elems[i].key)) { - char *str = grpc_slice_to_c_string(md_elems[i].key); - gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); - gpr_free(str); - } else if (!grpc_is_binary_header(md_elems[i].key) && - !grpc_header_nonbin_value_is_legal(md_elems[i].value)) { - char *str = - grpc_dump_slice(md_elems[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); - gpr_free(str); - } else { - add_error(&error, - grpc_metadata_batch_add_tail( - mdb, &calld->md_links[i], - grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value)))); + if (status != GRPC_CREDENTIALS_OK) { + error = grpc_error_set_int( + GRPC_ERROR_CREATE(error_details != NULL && strlen(error_details) > 0 + ? error_details + : "Credentials failed to get metadata."), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED); + } else { + GPR_ASSERT(num_md <= MAX_CREDENTIALS_METADATA_COUNT); + GPR_ASSERT(op->send_initial_metadata != NULL); + mdb = op->send_initial_metadata; + for (i = 0; i < num_md; i++) { + if (!grpc_header_key_is_legal(md_elems[i].key)) { + char *str = grpc_slice_to_c_string(md_elems[i].key); + gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); + gpr_free(str); + } else if (!grpc_is_binary_header(md_elems[i].key) && + !grpc_header_nonbin_value_is_legal(md_elems[i].value)) { + char *str = + grpc_dump_slice(md_elems[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); + gpr_free(str); + } else { + add_error(&error, + grpc_metadata_batch_add_tail( + mdb, &calld->md_links[i], + grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value)))); + } } } if (error == GRPC_ERROR_NONE) { @@ -210,8 +201,12 @@ static void send_security_metadata(grpc_exec_ctx *exec_ctx, calld->creds = grpc_composite_call_credentials_create(channel_call_creds, ctx->creds, NULL); if (calld->creds == NULL) { - bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, - "Incompatible credentials set on channel and call."); + grpc_transport_stream_op_finish_with_failure( + exec_ctx, op, + grpc_error_set_int( + GRPC_ERROR_CREATE( + "Incompatible credentials set on channel and call."), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED)); return; } } else { @@ -241,7 +236,10 @@ static void on_host_checked(grpc_exec_ctx *exec_ctx, void *user_data, gpr_asprintf(&error_msg, "Invalid host %s set in :authority metadata.", host); gpr_free(host); - bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, error_msg); + grpc_call_element_signal_error( + exec_ctx, elem, grpc_error_set_int(GRPC_ERROR_CREATE(error_msg), + GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_UNAUTHENTICATED)); gpr_free(error_msg); } } diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 8eb84ed3e4d..6b04ad23858 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -98,10 +98,6 @@ static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, return GRPC_FILTERED_MDELEM(md); } -static void destroy_op(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { - gpr_free(arg); -} - /* called from application code */ static void on_md_processing_done( void *user_data, const grpc_metadata *consumed_md, size_t num_consumed_md, @@ -135,8 +131,6 @@ static void on_md_processing_done( grpc_closure_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE); } else { grpc_slice message; - grpc_transport_stream_op *close_op = gpr_malloc(sizeof(*close_op)); - memset(close_op, 0, sizeof(*close_op)); for (size_t i = 0; i < calld->md.count; i++) { grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); @@ -152,10 +146,6 @@ static void on_md_processing_done( calld->transport_op->send_message = NULL; } calld->transport_op->send_trailing_metadata = NULL; - close_op->on_complete = - grpc_closure_create(destroy_op, close_op, grpc_schedule_on_exec_ctx); - grpc_transport_stream_op_add_close(&exec_ctx, close_op, status, &message); - grpc_call_next_op(&exec_ctx, elem, close_op); grpc_closure_sched(&exec_ctx, calld->on_done_recv, grpc_error_set_int(GRPC_ERROR_CREATE(error_details), GRPC_ERROR_INT_GRPC_STATUS, status)); From 255edaa32e236c8e30d378517e64b507e5b765a9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 13 Dec 2016 09:04:55 -0800 Subject: [PATCH 132/261] Fixes --- .../chttp2/transport/chttp2_transport.c | 10 ++-- src/core/lib/channel/deadline_filter.c | 6 +-- src/core/lib/iomgr/error.c | 3 +- src/core/lib/surface/call.c | 49 ++++++------------- src/core/lib/transport/transport.h | 15 ++++-- src/core/lib/transport/transport_op_string.c | 8 --- test/core/end2end/tests/filter_causes_close.c | 4 +- 7 files changed, 38 insertions(+), 57 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 1bf6dd4c285..858cb41ec88 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1018,10 +1018,6 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, grpc_chttp2_cancel_stream(exec_ctx, t, s, GRPC_ERROR_REF(op->cancel_error)); } - if (op->close_error != GRPC_ERROR_NONE) { - close_from_api(exec_ctx, t, s, GRPC_ERROR_REF(op->close_error)); - } - if (op->send_initial_metadata != NULL) { GPR_ASSERT(s->send_initial_metadata_finished == NULL); on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; @@ -1461,6 +1457,12 @@ static void status_codes_from_error(grpc_error *error, gpr_timespec deadline, void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *due_to_error) { + if (!t->is_client && !s->sent_trailing_metadata && + grpc_error_get_int(due_to_error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { + close_from_api(exec_ctx, t, s, due_to_error); + return; + } + if (!s->read_closed || !s->write_closed) { grpc_status_code grpc_status; grpc_chttp2_error_code http_error; diff --git a/src/core/lib/channel/deadline_filter.c b/src/core/lib/channel/deadline_filter.c index 4e140c10f19..bc9a2effc28 100644 --- a/src/core/lib/channel/deadline_filter.c +++ b/src/core/lib/channel/deadline_filter.c @@ -197,8 +197,7 @@ void grpc_deadline_state_client_start_transport_stream_op( grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op* op) { grpc_deadline_state* deadline_state = elem->call_data; - if (op->cancel_error != GRPC_ERROR_NONE || - op->close_error != GRPC_ERROR_NONE) { + if (op->cancel_error != GRPC_ERROR_NONE) { cancel_timer_if_needed(exec_ctx, deadline_state); } else { // Make sure we know when the call is complete, so that we can cancel @@ -286,8 +285,7 @@ static void server_start_transport_stream_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op* op) { server_call_data* calld = elem->call_data; - if (op->cancel_error != GRPC_ERROR_NONE || - op->close_error != GRPC_ERROR_NONE) { + if (op->cancel_error != GRPC_ERROR_NONE) { cancel_timer_if_needed(exec_ctx, &calld->base.deadline_state); } else { // If we're receiving initial metadata, we need to get the deadline diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index e4bfa322145..227c94020fe 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -261,7 +261,8 @@ static grpc_error *copy_error_and_unref(grpc_error *in) { grpc_error *out; if (is_special(in)) { if (in == GRPC_ERROR_NONE) - out = GRPC_ERROR_CREATE("no error"); + out = grpc_error_set_int(GRPC_ERROR_CREATE("no error"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK); else if (in == GRPC_ERROR_OOM) out = GRPC_ERROR_CREATE("oom"); else if (in == GRPC_ERROR_CANCELLED) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 1c32515c933..57603ca386c 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -222,9 +222,8 @@ static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); -static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description); +static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_error *error); static void destroy_call(grpc_exec_ctx *exec_ctx, void *call_stack, grpc_error *error); static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, @@ -339,7 +338,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, grpc_status_code status; const char *error_str; grpc_error_get_status(error, &status, &error_str); - close_with_status(exec_ctx, call, status, error_str); + cancel_with_status(exec_ctx, call, status, error_str); } if (args->cq != NULL) { GPR_ASSERT( @@ -528,13 +527,10 @@ grpc_call_error grpc_call_cancel_with_status(grpc_call *c, return r; } -typedef enum { TC_CANCEL, TC_CLOSE } termination_closure_type; - typedef struct termination_closure { grpc_closure closure; grpc_call *call; grpc_error *error; - termination_closure_type type; grpc_transport_stream_op op; } termination_closure; @@ -550,14 +546,7 @@ static void send_termination(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { termination_closure *tc = tcp; memset(&tc->op, 0, sizeof(tc->op)); - switch (tc->type) { - case TC_CANCEL: - tc->op.cancel_error = tc->error; - break; - case TC_CLOSE: - tc->op.close_error = tc->error; - break; - } + tc->op.cancel_error = tc->error; /* reuse closure to catch completion */ grpc_closure_init(&tc->closure, done_termination, tc, grpc_schedule_on_exec_ctx); @@ -577,17 +566,19 @@ static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, } static grpc_call_error terminate_with_error(grpc_exec_ctx *exec_ctx, - grpc_call *c, - termination_closure_type tc_type, - grpc_error *error) { + grpc_call *c, grpc_error *error) { termination_closure *tc = gpr_malloc(sizeof(*tc)); memset(tc, 0, sizeof(*tc)); - tc->type = tc_type; tc->call = c; tc->error = error; return terminate_with_status(exec_ctx, tc); } +static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_error *error) { + terminate_with_error(exec_ctx, c, error); +} + static grpc_error *error_from_status(grpc_status_code status, const char *description) { return grpc_error_set_int( @@ -599,14 +590,7 @@ static grpc_error *error_from_status(grpc_status_code status, static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description) { - return terminate_with_error(exec_ctx, c, TC_CANCEL, - error_from_status(status, description)); -} - -static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description) { - return terminate_with_error(exec_ctx, c, TC_CLOSE, + return terminate_with_error(exec_ctx, c, error_from_status(status, description)); } @@ -927,7 +911,7 @@ grpc_call_stack *grpc_call_get_call_stack(grpc_call *call) { return CALL_STACK_FROM_CALL(call); } -/* +/******************************************************************************* * BATCH API IMPLEMENTATION */ @@ -1141,10 +1125,7 @@ static void receiving_stream_ready(grpc_exec_ctx *exec_ctx, void *bctlp, batch_control *bctl = bctlp; grpc_call *call = bctl->call; if (error != GRPC_ERROR_NONE) { - grpc_status_code status; - const char *msg; - grpc_error_get_status(error, &status, &msg); - close_with_status(exec_ctx, call, status, msg); + cancel_with_error(exec_ctx, call, GRPC_ERROR_REF(error)); } gpr_mu_lock(&bctl->call->mu); if (bctl->call->has_initial_md_been_received || error != GRPC_ERROR_NONE || @@ -1172,7 +1153,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, gpr_asprintf(&error_msg, "Invalid compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - close_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1181,7 +1162,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - close_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); + cancel_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); } else { call->incoming_compression_algorithm = algo; } diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 5a92226942d..2dbb842a53e 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -150,13 +150,18 @@ typedef struct grpc_transport_stream_op { /** Collect any stats into provided buffer, zero internal stat counters */ grpc_transport_stream_stats *collect_stats; - /** If != GRPC_ERROR_NONE, cancel this stream */ + /** If != GRPC_ERROR_NONE, forcefully close this stream. + The HTTP2 semantics should be: + - server side: if cancel_error has GRPC_ERROR_INT_GRPC_STATUS, and + trailing metadata has not been sent, send trailing metadata with status + and message from cancel_error (use grpc_error_get_status) followed by + a RST_STREAM with error=GRPC_CHTTP2_NO_ERROR to force a full close + - at all other times: use grpc_error_get_status to get a status code, and + convert to a HTTP2 error code using + grpc_chttp2_grpc_status_to_http2_error. Send a RST_STREAM with this + error. */ grpc_error *cancel_error; - /** If != GRPC_ERROR_NONE, send grpc-status, grpc-message, and close this - stream for both reading and writing */ - grpc_error *close_error; - /* Indexes correspond to grpc_context_index enum values */ grpc_call_context_element *context; diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index b36e4f22d0f..33bd35bd456 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -125,14 +125,6 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) { gpr_strvec_add(&b, tmp); } - if (op->close_error != GRPC_ERROR_NONE) { - gpr_strvec_add(&b, gpr_strdup(" ")); - const char *msg = grpc_error_string(op->close_error); - gpr_asprintf(&tmp, "CLOSE:%s", msg); - grpc_error_free_string(msg); - gpr_strvec_add(&b, tmp); - } - out = gpr_strvec_flatten(&b, NULL); gpr_strvec_destroy(&b); diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c index 8afd6815050..114fd71d058 100644 --- a/test/core/end2end/tests/filter_causes_close.c +++ b/test/core/end2end/tests/filter_causes_close.c @@ -210,7 +210,9 @@ static void recv_im_ready(grpc_exec_ctx *exec_ctx, void *arg, call_data *calld = elem->call_data; grpc_closure_sched( exec_ctx, calld->recv_im_ready, - GRPC_ERROR_CREATE_REFERENCING("Forced call to close", &error, 1)); + grpc_error_set_int( + GRPC_ERROR_CREATE_REFERENCING("Forced call to close", &error, 1), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED)); } static void start_transport_stream_op(grpc_exec_ctx *exec_ctx, From 732351f8267e51711abd3a390d940c8177871c97 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 13 Dec 2016 16:40:38 -0800 Subject: [PATCH 133/261] Start fixing http error --> grpc status conversion --- BUILD | 9 +- CMakeLists.txt | 12 +- Makefile | 14 +- binding.gyp | 3 +- build.yaml | 9 +- config.m4 | 3 +- gRPC-Core.podspec | 15 +- grpc.gemspec | 9 +- package.xml | 9 +- .../chttp2/transport/chttp2_transport.c | 184 ++++++++---------- .../chttp2/transport/frame_settings.c | 2 +- .../transport/chttp2/transport/hpack_parser.c | 2 +- src/core/lib/iomgr/error.c | 116 ++++------- src/core/lib/iomgr/error.h | 6 - src/core/lib/iomgr/error_internal.h | 53 +++++ .../security/transport/server_auth_filter.c | 2 - src/core/lib/surface/call.c | 1 + src/core/lib/transport/error_utils.c | 90 +++++++++ src/core/lib/transport/error_utils.h | 50 +++++ .../chttp2 => lib}/transport/http2_errors.h | 0 .../transport/status_conversion.c | 2 +- .../transport/status_conversion.h | 2 +- src/python/grpcio/grpc_core_dependencies.py | 3 +- test/core/end2end/tests/filter_causes_close.c | 7 +- tools/doxygen/Doxyfile.core.internal | 9 +- .../generated/sources_and_headers.json | 15 +- vsprojects/vcxproj/grpc/grpc.vcxproj | 12 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 27 ++- .../grpc_test_util/grpc_test_util.vcxproj | 8 + .../grpc_test_util.vcxproj.filters | 18 ++ .../grpc_unsecure/grpc_unsecure.vcxproj | 12 +- .../grpc_unsecure.vcxproj.filters | 27 ++- 32 files changed, 474 insertions(+), 257 deletions(-) create mode 100644 src/core/lib/iomgr/error_internal.h create mode 100644 src/core/lib/transport/error_utils.c create mode 100644 src/core/lib/transport/error_utils.h rename src/core/{ext/transport/chttp2 => lib}/transport/http2_errors.h (100%) rename src/core/{ext/transport/chttp2 => lib}/transport/status_conversion.c (98%) rename src/core/{ext/transport/chttp2 => lib}/transport/status_conversion.h (97%) diff --git a/BUILD b/BUILD index 9f88fea626a..a756f5ac621 100644 --- a/BUILD +++ b/BUILD @@ -519,11 +519,13 @@ grpc_cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", + "src/core/lib/transport/error_utils.c", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata_batch.c", "src/core/lib/transport/pid_controller.c", "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", + "src/core/lib/transport/status_conversion.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", "src/core/lib/transport/transport_op_string.c", @@ -551,6 +553,7 @@ grpc_cc_library( "src/core/lib/iomgr/endpoint.h", "src/core/lib/iomgr/endpoint_pair.h", "src/core/lib/iomgr/error.h", + "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.h", "src/core/lib/iomgr/ev_posix.h", @@ -619,11 +622,14 @@ grpc_cc_library( "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/error_utils.h", + "src/core/lib/transport/http2_errors.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/pid_controller.h", "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", + "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", "src/core/lib/transport/transport_impl.h", @@ -876,7 +882,6 @@ grpc_cc_library( "src/core/ext/transport/chttp2/transport/huffsyms.c", "src/core/ext/transport/chttp2/transport/incoming_metadata.c", "src/core/ext/transport/chttp2/transport/parsing.c", - "src/core/ext/transport/chttp2/transport/status_conversion.c", "src/core/ext/transport/chttp2/transport/stream_lists.c", "src/core/ext/transport/chttp2/transport/stream_map.c", "src/core/ext/transport/chttp2/transport/varint.c", @@ -896,11 +901,9 @@ grpc_cc_library( "src/core/ext/transport/chttp2/transport/hpack_encoder.h", "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.h", - "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", - "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h", ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 0bd7a5aa80a..f406e11f347 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -390,11 +390,13 @@ add_library(grpc src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/error_utils.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c + src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -415,7 +417,6 @@ add_library(grpc src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c - src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -673,11 +674,13 @@ add_library(grpc_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/error_utils.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c + src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -701,7 +704,6 @@ add_library(grpc_cronet src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c - src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -927,11 +929,13 @@ add_library(grpc_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/error_utils.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c + src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -953,7 +957,6 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c - src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -1287,7 +1290,6 @@ add_library(grpc++_cronet src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c - src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -1397,11 +1399,13 @@ add_library(grpc++_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c + src/core/lib/transport/error_utils.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c + src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c diff --git a/Makefile b/Makefile index db8f5d31d5f..c5d63eace8b 100644 --- a/Makefile +++ b/Makefile @@ -2729,11 +2729,13 @@ LIBGRPC_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -2754,7 +2756,6 @@ LIBGRPC_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ - src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -3030,11 +3031,13 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3058,7 +3061,6 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ - src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -3321,11 +3323,13 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3540,11 +3544,13 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3566,7 +3572,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ - src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -4012,7 +4017,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ - src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -4122,11 +4126,13 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ diff --git a/binding.gyp b/binding.gyp index 3c7eb98df20..296fb4e43ad 100644 --- a/binding.gyp +++ b/binding.gyp @@ -670,11 +670,13 @@ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/error_utils.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', + 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -695,7 +697,6 @@ 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', - 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', diff --git a/build.yaml b/build.yaml index fd9b69bb8c5..cce12284bef 100644 --- a/build.yaml +++ b/build.yaml @@ -185,6 +185,7 @@ filegroups: - src/core/lib/iomgr/endpoint.h - src/core/lib/iomgr/endpoint_pair.h - src/core/lib/iomgr/error.h + - src/core/lib/iomgr/error_internal.h - src/core/lib/iomgr/ev_epoll_linux.h - src/core/lib/iomgr/ev_poll_posix.h - src/core/lib/iomgr/ev_posix.h @@ -253,11 +254,14 @@ filegroups: - src/core/lib/surface/server.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h + - src/core/lib/transport/error_utils.h + - src/core/lib/transport/http2_errors.h - src/core/lib/transport/metadata.h - src/core/lib/transport/metadata_batch.h - src/core/lib/transport/pid_controller.h - src/core/lib/transport/service_config.h - src/core/lib/transport/static_metadata.h + - src/core/lib/transport/status_conversion.h - src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/transport.h - src/core/lib/transport/transport_impl.h @@ -367,11 +371,13 @@ filegroups: - src/core/lib/surface/version.c - src/core/lib/transport/byte_stream.c - src/core/lib/transport/connectivity_state.c + - src/core/lib/transport/error_utils.c - src/core/lib/transport/metadata.c - src/core/lib/transport/metadata_batch.c - src/core/lib/transport/pid_controller.c - src/core/lib/transport/service_config.c - src/core/lib/transport/static_metadata.c + - src/core/lib/transport/status_conversion.c - src/core/lib/transport/timeout_encoding.c - src/core/lib/transport/transport.c - src/core/lib/transport/transport_op_string.c @@ -584,11 +590,9 @@ filegroups: - src/core/ext/transport/chttp2/transport/hpack_encoder.h - src/core/ext/transport/chttp2/transport/hpack_parser.h - src/core/ext/transport/chttp2/transport/hpack_table.h - - src/core/ext/transport/chttp2/transport/http2_errors.h - src/core/ext/transport/chttp2/transport/huffsyms.h - src/core/ext/transport/chttp2/transport/incoming_metadata.h - src/core/ext/transport/chttp2/transport/internal.h - - src/core/ext/transport/chttp2/transport/status_conversion.h - src/core/ext/transport/chttp2/transport/stream_map.h - src/core/ext/transport/chttp2/transport/varint.h src: @@ -608,7 +612,6 @@ filegroups: - src/core/ext/transport/chttp2/transport/huffsyms.c - src/core/ext/transport/chttp2/transport/incoming_metadata.c - src/core/ext/transport/chttp2/transport/parsing.c - - src/core/ext/transport/chttp2/transport/status_conversion.c - src/core/ext/transport/chttp2/transport/stream_lists.c - src/core/ext/transport/chttp2/transport/stream_map.c - src/core/ext/transport/chttp2/transport/varint.c diff --git a/config.m4 b/config.m4 index d265d0be5af..4c30d11c267 100644 --- a/config.m4 +++ b/config.m4 @@ -186,11 +186,13 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ + src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ + src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -211,7 +213,6 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ - src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 86d4d3cc395..66061856685 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -270,6 +270,7 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/endpoint.h', 'src/core/lib/iomgr/endpoint_pair.h', 'src/core/lib/iomgr/error.h', + 'src/core/lib/iomgr/error_internal.h', 'src/core/lib/iomgr/ev_epoll_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', @@ -338,11 +339,14 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/error_utils.h', + 'src/core/lib/transport/http2_errors.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', + 'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', @@ -359,11 +363,9 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/hpack_encoder.h', 'src/core/ext/transport/chttp2/transport/hpack_parser.h', 'src/core/ext/transport/chttp2/transport/hpack_table.h', - 'src/core/ext/transport/chttp2/transport/http2_errors.h', 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/incoming_metadata.h', 'src/core/ext/transport/chttp2/transport/internal.h', - 'src/core/ext/transport/chttp2/transport/status_conversion.h', 'src/core/ext/transport/chttp2/transport/stream_map.h', 'src/core/ext/transport/chttp2/transport/varint.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', @@ -534,11 +536,13 @@ Pod::Spec.new do |s| 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/error_utils.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', + 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -559,7 +563,6 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', - 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', @@ -679,6 +682,7 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/endpoint.h', 'src/core/lib/iomgr/endpoint_pair.h', 'src/core/lib/iomgr/error.h', + 'src/core/lib/iomgr/error_internal.h', 'src/core/lib/iomgr/ev_epoll_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', @@ -747,11 +751,14 @@ Pod::Spec.new do |s| 'src/core/lib/surface/server.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', + 'src/core/lib/transport/error_utils.h', + 'src/core/lib/transport/http2_errors.h', 'src/core/lib/transport/metadata.h', 'src/core/lib/transport/metadata_batch.h', 'src/core/lib/transport/pid_controller.h', 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', + 'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', @@ -768,11 +775,9 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/hpack_encoder.h', 'src/core/ext/transport/chttp2/transport/hpack_parser.h', 'src/core/ext/transport/chttp2/transport/hpack_table.h', - 'src/core/ext/transport/chttp2/transport/http2_errors.h', 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/incoming_metadata.h', 'src/core/ext/transport/chttp2/transport/internal.h', - 'src/core/ext/transport/chttp2/transport/status_conversion.h', 'src/core/ext/transport/chttp2/transport/stream_map.h', 'src/core/ext/transport/chttp2/transport/varint.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', diff --git a/grpc.gemspec b/grpc.gemspec index 4312444ef52..ab57b444ed7 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -187,6 +187,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/endpoint.h ) s.files += %w( src/core/lib/iomgr/endpoint_pair.h ) s.files += %w( src/core/lib/iomgr/error.h ) + s.files += %w( src/core/lib/iomgr/error_internal.h ) s.files += %w( src/core/lib/iomgr/ev_epoll_linux.h ) s.files += %w( src/core/lib/iomgr/ev_poll_posix.h ) s.files += %w( src/core/lib/iomgr/ev_posix.h ) @@ -255,11 +256,14 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/server.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) + s.files += %w( src/core/lib/transport/error_utils.h ) + s.files += %w( src/core/lib/transport/http2_errors.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/pid_controller.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/status_conversion.h ) s.files += %w( src/core/lib/transport/timeout_encoding.h ) s.files += %w( src/core/lib/transport/transport.h ) s.files += %w( src/core/lib/transport/transport_impl.h ) @@ -276,11 +280,9 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/transport/hpack_encoder.h ) s.files += %w( src/core/ext/transport/chttp2/transport/hpack_parser.h ) s.files += %w( src/core/ext/transport/chttp2/transport/hpack_table.h ) - s.files += %w( src/core/ext/transport/chttp2/transport/http2_errors.h ) s.files += %w( src/core/ext/transport/chttp2/transport/huffsyms.h ) s.files += %w( src/core/ext/transport/chttp2/transport/incoming_metadata.h ) s.files += %w( src/core/ext/transport/chttp2/transport/internal.h ) - s.files += %w( src/core/ext/transport/chttp2/transport/status_conversion.h ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_map.h ) s.files += %w( src/core/ext/transport/chttp2/transport/varint.h ) s.files += %w( src/core/ext/transport/chttp2/alpn/alpn.h ) @@ -451,11 +453,13 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/version.c ) s.files += %w( src/core/lib/transport/byte_stream.c ) s.files += %w( src/core/lib/transport/connectivity_state.c ) + s.files += %w( src/core/lib/transport/error_utils.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/pid_controller.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/status_conversion.c ) s.files += %w( src/core/lib/transport/timeout_encoding.c ) s.files += %w( src/core/lib/transport/transport.c ) s.files += %w( src/core/lib/transport/transport_op_string.c ) @@ -476,7 +480,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/transport/huffsyms.c ) s.files += %w( src/core/ext/transport/chttp2/transport/incoming_metadata.c ) s.files += %w( src/core/ext/transport/chttp2/transport/parsing.c ) - s.files += %w( src/core/ext/transport/chttp2/transport/status_conversion.c ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_lists.c ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_map.c ) s.files += %w( src/core/ext/transport/chttp2/transport/varint.c ) diff --git a/package.xml b/package.xml index 3dbf6d3d23a..3313ead9e2f 100644 --- a/package.xml +++ b/package.xml @@ -195,6 +195,7 @@ + @@ -263,11 +264,14 @@ + + + @@ -284,11 +288,9 @@ - - @@ -459,11 +461,13 @@ + + @@ -484,7 +488,6 @@ - diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 858cb41ec88..3711e0cba13 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -44,9 +44,7 @@ #include #include -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/ext/transport/chttp2/transport/internal.h" -#include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/http/parser.h" @@ -55,7 +53,10 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" +#include "src/core/lib/transport/error_utils.h" +#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/static_metadata.h" +#include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" #include "src/core/lib/transport/transport_impl.h" @@ -1458,7 +1459,7 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *due_to_error) { if (!t->is_client && !s->sent_trailing_metadata && - grpc_error_get_int(due_to_error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { + grpc_error_has_clear_grpc_status(due_to_error)) { close_from_api(exec_ctx, t, s, due_to_error); return; } @@ -1634,112 +1635,97 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, uint8_t *p; uint32_t len = 0; grpc_status_code grpc_status; - grpc_chttp2_error_code http_error; - status_codes_from_error(error, s->deadline, &http_error, &grpc_status); + const char *msg; + grpc_error_get_status(error, &grpc_status, &msg); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); - if (s->id != 0 && !t->is_client) { - /* Hand roll a header block. - This is unnecessarily ugly - at some point we should find a more - elegant - solution. - It's complicated by the fact that our send machinery would be dead by - the - time we got around to sending this, so instead we ignore HPACK - compression - and just write the uncompressed bytes onto the wire. */ - status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); - p = GRPC_SLICE_START_PTR(status_hdr); - *p++ = 0x40; /* literal header */ - *p++ = 11; /* len(grpc-status) */ + /* Hand roll a header block. + This is unnecessarily ugly - at some point we should find a more + elegant solution. + It's complicated by the fact that our send machinery would be dead by + the time we got around to sending this, so instead we ignore HPACK + compression and just write the uncompressed bytes onto the wire. */ + status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); + p = GRPC_SLICE_START_PTR(status_hdr); + *p++ = 0x40; /* literal header */ + *p++ = 11; /* len(grpc-status) */ + *p++ = 'g'; + *p++ = 'r'; + *p++ = 'p'; + *p++ = 'c'; + *p++ = '-'; + *p++ = 's'; + *p++ = 't'; + *p++ = 'a'; + *p++ = 't'; + *p++ = 'u'; + *p++ = 's'; + if (grpc_status < 10) { + *p++ = 1; + *p++ = (uint8_t)('0' + grpc_status); + } else { + *p++ = 2; + *p++ = (uint8_t)('0' + (grpc_status / 10)); + *p++ = (uint8_t)('0' + (grpc_status % 10)); + } + GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); + len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); + + if (msg != NULL) { + size_t msg_len = strlen(msg); + GPR_ASSERT(msg_len <= UINT32_MAX); + uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0); + message_pfx = grpc_slice_malloc(14 + msg_len_len); + p = GRPC_SLICE_START_PTR(message_pfx); + *p++ = 0x40; + *p++ = 12; /* len(grpc-message) */ *p++ = 'g'; *p++ = 'r'; *p++ = 'p'; *p++ = 'c'; *p++ = '-'; + *p++ = 'm'; + *p++ = 'e'; *p++ = 's'; - *p++ = 't'; - *p++ = 'a'; - *p++ = 't'; - *p++ = 'u'; *p++ = 's'; - if (grpc_status < 10) { - *p++ = 1; - *p++ = (uint8_t)('0' + grpc_status); - } else { - *p++ = 2; - *p++ = (uint8_t)('0' + (grpc_status / 10)); - *p++ = (uint8_t)('0' + (grpc_status % 10)); - } - GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); - - const char *optional_message = - grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE); - - if (optional_message != NULL) { - size_t msg_len = strlen(optional_message); - GPR_ASSERT(msg_len <= UINT32_MAX); - uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0); - message_pfx = grpc_slice_malloc(14 + msg_len_len); - p = GRPC_SLICE_START_PTR(message_pfx); - *p++ = 0x40; - *p++ = 12; /* len(grpc-message) */ - *p++ = 'g'; - *p++ = 'r'; - *p++ = 'p'; - *p++ = 'c'; - *p++ = '-'; - *p++ = 'm'; - *p++ = 'e'; - *p++ = 's'; - *p++ = 's'; - *p++ = 'a'; - *p++ = 'g'; - *p++ = 'e'; - GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 0, 0, p, - (uint32_t)msg_len_len); - p += msg_len_len; - GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); - len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); - len += (uint32_t)msg_len; - } - - hdr = grpc_slice_malloc(9); - p = GRPC_SLICE_START_PTR(hdr); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); - *p++ = GRPC_CHTTP2_FRAME_HEADER; - *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = (uint8_t)(s->id >> 24); - *p++ = (uint8_t)(s->id >> 16); - *p++ = (uint8_t)(s->id >> 8); - *p++ = (uint8_t)(s->id); - GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); - - grpc_slice_buffer_add(&t->qbuf, hdr); - grpc_slice_buffer_add(&t->qbuf, status_hdr); - if (optional_message) { - grpc_slice_buffer_add(&t->qbuf, message_pfx); - grpc_slice_buffer_add(&t->qbuf, - grpc_slice_from_copied_string(optional_message)); - } - grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, - &s->stats.outgoing)); - } - - const char *msg = grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE); - bool free_msg = false; - if (msg == NULL) { - free_msg = true; - msg = grpc_error_string(error); - } - grpc_slice msg_slice = grpc_slice_from_copied_string(msg); - grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, &msg_slice); - if (free_msg) grpc_error_free_string(msg); + *p++ = 'a'; + *p++ = 'g'; + *p++ = 'e'; + GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 0, 0, p, (uint32_t)msg_len_len); + p += msg_len_len; + GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); + len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); + len += (uint32_t)msg_len; + } + + hdr = grpc_slice_malloc(9); + p = GRPC_SLICE_START_PTR(hdr); + *p++ = (uint8_t)(len >> 16); + *p++ = (uint8_t)(len >> 8); + *p++ = (uint8_t)(len); + *p++ = GRPC_CHTTP2_FRAME_HEADER; + *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; + *p++ = (uint8_t)(s->id >> 24); + *p++ = (uint8_t)(s->id >> 16); + *p++ = (uint8_t)(s->id >> 8); + *p++ = (uint8_t)(s->id); + GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); + + grpc_slice_buffer_add(&t->qbuf, hdr); + grpc_slice_buffer_add(&t->qbuf, status_hdr); + if (msg != NULL) { + grpc_slice_buffer_add(&t->qbuf, message_pfx); + grpc_slice_buffer_add(&t->qbuf, grpc_slice_from_copied_string(msg)); + } + grpc_slice_buffer_add( + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, + &s->stats.outgoing)); + + grpc_slice msg_slice = + msg == NULL ? grpc_empty_slice() : grpc_slice_from_copied_string(msg); + grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, + msg == NULL ? NULL : &msg_slice); grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error); grpc_chttp2_initiate_write(exec_ctx, t, false, "close_from_api"); diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.c b/src/core/ext/transport/chttp2/transport/frame_settings.c index 98facae87fe..bfed41fadbd 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.c +++ b/src/core/ext/transport/chttp2/transport/frame_settings.c @@ -43,8 +43,8 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/frame.h" -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/transport/http2_errors.h" #define MAX_MAX_HEADER_LIST_SIZE (1024 * 1024 * 1024) diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 2a14167f670..6d6d0de742b 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -50,10 +50,10 @@ #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" +#include "src/core/lib/transport/http2_errors.h" /* TODO(ctiller): remove before submission */ #include "src/core/lib/slice/slice_string_helpers.h" diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index 227c94020fe..3cf644f4211 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -33,13 +33,10 @@ #include "src/core/lib/iomgr/error.h" -#include -#include #include #include #include -#include #include #include #include @@ -48,6 +45,7 @@ #include #endif +#include "src/core/lib/iomgr/error_internal.h" #include "src/core/lib/profiling/timers.h" static void destroy_integer(void *key) {} @@ -164,16 +162,7 @@ static const char *error_time_name(grpc_error_times key) { GPR_UNREACHABLE_CODE(return "unknown"); } -struct grpc_error { - gpr_refcount refs; - gpr_avl ints; - gpr_avl strs; - gpr_avl times; - gpr_avl errs; - uintptr_t next_err; -}; - -static bool is_special(grpc_error *err) { +bool grpc_error_is_special(grpc_error *err) { return err == GRPC_ERROR_NONE || err == GRPC_ERROR_OOM || err == GRPC_ERROR_CANCELLED; } @@ -189,14 +178,14 @@ grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, } #else grpc_error *grpc_error_ref(grpc_error *err) { - if (is_special(err)) return err; + if (grpc_error_is_special(err)) return err; gpr_ref(&err->refs); return err; } #endif static void error_destroy(grpc_error *err) { - GPR_ASSERT(!is_special(err)); + GPR_ASSERT(!grpc_error_is_special(err)); gpr_avl_unref(err->ints); gpr_avl_unref(err->strs); gpr_avl_unref(err->errs); @@ -216,7 +205,7 @@ void grpc_error_unref(grpc_error *err, const char *file, int line, } #else void grpc_error_unref(grpc_error *err) { - if (is_special(err)) return; + if (grpc_error_is_special(err)) return; if (gpr_unref(&err->refs)) { error_destroy(err); } @@ -259,7 +248,7 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, static grpc_error *copy_error_and_unref(grpc_error *in) { GPR_TIMER_BEGIN("copy_error_and_unref", 0); grpc_error *out; - if (is_special(in)) { + if (grpc_error_is_special(in)) { if (in == GRPC_ERROR_NONE) out = grpc_error_set_int(GRPC_ERROR_CREATE("no error"), GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK); @@ -297,14 +286,29 @@ grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, return new; } +typedef struct { + grpc_error *error; + grpc_status_code code; + const char *msg; +} special_error_status_map; +static special_error_status_map error_status_map[] = { + {GRPC_ERROR_NONE, GRPC_STATUS_OK, NULL}, + {GRPC_ERROR_CANCELLED, GRPC_STATUS_CANCELLED, "Cancelled"}, + {GRPC_ERROR_OOM, GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory"}, +}; + bool grpc_error_get_int(grpc_error *err, grpc_error_ints which, intptr_t *p) { GPR_TIMER_BEGIN("grpc_error_get_int", 0); void *pp; - if (is_special(err)) { - if (err == GRPC_ERROR_CANCELLED && which == GRPC_ERROR_INT_GRPC_STATUS) { - *p = GRPC_STATUS_CANCELLED; - GPR_TIMER_END("grpc_error_get_int", 0); - return true; + if (grpc_error_is_special(err)) { + if (which == GRPC_ERROR_INT_GRPC_STATUS) { + for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) { + if (error_status_map[i].error == err) { + if (p != NULL) *p = error_status_map[i].code; + GPR_TIMER_END("grpc_error_get_int", 0); + return true; + } + } } GPR_TIMER_END("grpc_error_get_int", 0); return false; @@ -329,67 +333,17 @@ grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, } const char *grpc_error_get_str(grpc_error *err, grpc_error_strs which) { - if (is_special(err)) return NULL; - return gpr_avl_get(err->strs, (void *)(uintptr_t)which); -} - -typedef struct { - grpc_error *error; - grpc_status_code code; - const char *msg; -} special_error_status_map; -static special_error_status_map error_status_map[] = { - {GRPC_ERROR_NONE, GRPC_STATUS_OK, ""}, - {GRPC_ERROR_CANCELLED, GRPC_STATUS_CANCELLED, "RPC cancelled"}, - {GRPC_ERROR_OOM, GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory"}, -}; - -static grpc_error *recursively_find_error_with_status(grpc_error *error, - intptr_t *status) { - // If the error itself has a status code, return it. - if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) { - return error; - } - if (is_special(error)) return NULL; - // Otherwise, search through its children. - intptr_t key = 0; - while (true) { - grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); - if (child_error == NULL) break; - grpc_error *result = - recursively_find_error_with_status(child_error, status); - if (result != NULL) return result; - } - return NULL; -} - -void grpc_error_get_status(grpc_error *error, grpc_status_code *code, - const char **msg) { - // Handle special errors via the static map. - for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); ++i) { - if (error == error_status_map[i].error) { - *code = error_status_map[i].code; - *msg = error_status_map[i].msg; - return; + if (grpc_error_is_special(err)) { + if (which == GRPC_ERROR_STR_GRPC_MESSAGE) { + for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) { + if (error_status_map[i].error == err) { + return error_status_map[i].msg; + } + } } + return NULL; } - // Populate code. - // Start with the parent error and recurse through the tree of children - // until we find the first one that has a status code. - intptr_t status = GRPC_STATUS_UNKNOWN; // Default in case we don't find one. - grpc_error *found_error = recursively_find_error_with_status(error, &status); - *code = (grpc_status_code)status; - // Now populate msg. - // If we found an error with a status code above, use that; otherwise, - // fall back to using the parent error. - if (found_error == NULL) found_error = error; - // If the error has a status message, use it. Otherwise, fall back to - // the error description. - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); - if (*msg == NULL && status != GRPC_STATUS_OK) { - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); - if (*msg == NULL) *msg = "unknown error"; // Just in case. - } + return gpr_avl_get(err->strs, (void *)(uintptr_t)which); } grpc_error *grpc_error_add_child(grpc_error *src, grpc_error *child) { diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index a2ba84deed6..75ca9c4bf97 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -193,12 +193,6 @@ grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, /// Caller does NOT own return value. const char *grpc_error_get_str(grpc_error *error, grpc_error_strs which); -/// A utility function to get the status code and message to be returned -/// to the application. If not set in the top-level message, looks -/// through child errors until it finds the first one with these attributes. -void grpc_error_get_status(grpc_error *error, grpc_status_code *code, - const char **msg); - /// Add a child error: an error that is believed to have contributed to this /// error occurring. Allows root causing high level errors from lower level /// errors that contributed to them. diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h new file mode 100644 index 00000000000..5afe9edc7fb --- /dev/null +++ b/src/core/lib/iomgr/error_internal.h @@ -0,0 +1,53 @@ +/* + * + * 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_ERROR_INTERNAL_H +#define GRPC_ERROR_INTERNAL_H + +#include +#include + +#include + +struct grpc_error { + gpr_refcount refs; + gpr_avl ints; + gpr_avl strs; + gpr_avl times; + gpr_avl errs; + uintptr_t next_err; +}; + +bool grpc_error_is_special(grpc_error *err); + +#endif diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 6b04ad23858..36e81d6501c 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -130,7 +130,6 @@ static void on_md_processing_done( grpc_metadata_array_destroy(&calld->md); grpc_closure_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE); } else { - grpc_slice message; for (size_t i = 0; i < calld->md.count; i++) { grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); @@ -139,7 +138,6 @@ static void on_md_processing_done( error_details = error_details != NULL ? error_details : "Authentication metadata processing failed."; - message = grpc_slice_from_copied_string(error_details); calld->transport_op->send_initial_metadata = NULL; if (calld->transport_op->send_message != NULL) { grpc_byte_stream_destroy(&exec_ctx, calld->transport_op->send_message); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 57603ca386c..4abf9819979 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -56,6 +56,7 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/completion_queue.h" +#include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/transport.h" diff --git a/src/core/lib/transport/error_utils.c b/src/core/lib/transport/error_utils.c new file mode 100644 index 00000000000..6403cf80d8c --- /dev/null +++ b/src/core/lib/transport/error_utils.c @@ -0,0 +1,90 @@ +/* + * + * 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. + * + */ + +#include "src/core/lib/transport/error_utils.h" +#include "src/core/lib/iomgr/error_internal.h" + +static grpc_error *recursively_find_error_with_status(grpc_error *error, + intptr_t *status) { + // If the error itself has a status code, return it. + if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) { + return error; + } + if (grpc_error_is_special(error)) return NULL; + // Otherwise, search through its children. + intptr_t key = 0; + while (true) { + grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); + if (child_error == NULL) break; + grpc_error *result = + recursively_find_error_with_status(child_error, status); + if (result != NULL) return result; + } + return NULL; +} + +void grpc_error_get_status(grpc_error *error, grpc_status_code *code, + const char **msg) { + // Populate code. + // Start with the parent error and recurse through the tree of children + // until we find the first one that has a status code. + intptr_t status = GRPC_STATUS_UNKNOWN; // Default in case we don't find one. + grpc_error *found_error = recursively_find_error_with_status(error, &status); + *code = (grpc_status_code)status; + // Now populate msg. + // If we found an error with a status code above, use that; otherwise, + // fall back to using the parent error. + if (found_error == NULL) found_error = error; + // If the error has a status message, use it. Otherwise, fall back to + // the error description. + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); + if (*msg == NULL && status != GRPC_STATUS_OK) { + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); + if (*msg == NULL) *msg = "unknown error"; // Just in case. + } +} + +bool grpc_error_has_clear_grpc_status(grpc_error *error) { + if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { + return true; + } + intptr_t key = 0; + while (true) { + grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); + if (child_error == NULL) break; + if (grpc_error_has_clear_grpc_status(child_error)) { + return true; + } + } + return false; +} diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h new file mode 100644 index 00000000000..541dba852f9 --- /dev/null +++ b/src/core/lib/transport/error_utils.h @@ -0,0 +1,50 @@ +/* + * + * 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_ERROR_UTILS_H +#define GRPC_ERROR_UTILS_H + +#include "src/core/lib/iomgr/error.h" + +/// A utility function to get the status code and message to be returned +/// to the application. If not set in the top-level message, looks +/// through child errors until it finds the first one with these attributes. +void grpc_error_get_status(grpc_error *error, grpc_status_code *code, + const char **msg); +/// A utility function to check whether there is a clear status code that +/// doesn't need to be guessed in \a error. This means that \a error or some +/// child has GRPC_ERROR_INT_GRPC_STATUS set, or that it is GRPC_ERROR_NONE or +/// GRPC_ERROR_CANCELLED +bool grpc_error_has_clear_grpc_status(grpc_error *error); + +#endif diff --git a/src/core/ext/transport/chttp2/transport/http2_errors.h b/src/core/lib/transport/http2_errors.h similarity index 100% rename from src/core/ext/transport/chttp2/transport/http2_errors.h rename to src/core/lib/transport/http2_errors.h diff --git a/src/core/ext/transport/chttp2/transport/status_conversion.c b/src/core/lib/transport/status_conversion.c similarity index 98% rename from src/core/ext/transport/chttp2/transport/status_conversion.c rename to src/core/lib/transport/status_conversion.c index 5dce2f2d0cc..eb1d53c8d1c 100644 --- a/src/core/ext/transport/chttp2/transport/status_conversion.c +++ b/src/core/lib/transport/status_conversion.c @@ -31,7 +31,7 @@ * */ -#include "src/core/ext/transport/chttp2/transport/status_conversion.h" +#include "src/core/lib/transport/status_conversion.h" int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) { switch (status) { diff --git a/src/core/ext/transport/chttp2/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h similarity index 97% rename from src/core/ext/transport/chttp2/transport/status_conversion.h rename to src/core/lib/transport/status_conversion.h index 953bc9f1e1f..592411529d6 100644 --- a/src/core/ext/transport/chttp2/transport/status_conversion.h +++ b/src/core/lib/transport/status_conversion.h @@ -35,7 +35,7 @@ #define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H #include -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" +#include "src/core/lib/transport/http2_errors.h" /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error( diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 8397224a02e..dfb64f87442 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -180,11 +180,13 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', + 'src/core/lib/transport/error_utils.c', 'src/core/lib/transport/metadata.c', 'src/core/lib/transport/metadata_batch.c', 'src/core/lib/transport/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', + 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -205,7 +207,6 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', - 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c index 114fd71d058..a1f7d1b6a79 100644 --- a/test/core/end2end/tests/filter_causes_close.c +++ b/test/core/end2end/tests/filter_causes_close.c @@ -210,9 +210,10 @@ static void recv_im_ready(grpc_exec_ctx *exec_ctx, void *arg, call_data *calld = elem->call_data; grpc_closure_sched( exec_ctx, calld->recv_im_ready, - grpc_error_set_int( - GRPC_ERROR_CREATE_REFERENCING("Forced call to close", &error, 1), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_PERMISSION_DENIED)); + grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING( + "Failure that's not preventable.", &error, 1), + GRPC_ERROR_INT_GRPC_STATUS, + GRPC_STATUS_PERMISSION_DENIED)); } static void start_transport_stream_op(grpc_exec_ctx *exec_ctx, diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 34361a8eb3a..f9343a2b73f 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -811,6 +811,7 @@ src/core/lib/iomgr/combiner.h \ src/core/lib/iomgr/endpoint.h \ src/core/lib/iomgr/endpoint_pair.h \ src/core/lib/iomgr/error.h \ +src/core/lib/iomgr/error_internal.h \ src/core/lib/iomgr/ev_epoll_linux.h \ src/core/lib/iomgr/ev_poll_posix.h \ src/core/lib/iomgr/ev_posix.h \ @@ -879,11 +880,14 @@ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.h \ +src/core/lib/transport/error_utils.h \ +src/core/lib/transport/http2_errors.h \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.h \ src/core/lib/transport/pid_controller.h \ src/core/lib/transport/service_config.h \ src/core/lib/transport/static_metadata.h \ +src/core/lib/transport/status_conversion.h \ src/core/lib/transport/timeout_encoding.h \ src/core/lib/transport/transport.h \ src/core/lib/transport/transport_impl.h \ @@ -900,11 +904,9 @@ src/core/ext/transport/chttp2/transport/frame_window_update.h \ src/core/ext/transport/chttp2/transport/hpack_encoder.h \ src/core/ext/transport/chttp2/transport/hpack_parser.h \ src/core/ext/transport/chttp2/transport/hpack_table.h \ -src/core/ext/transport/chttp2/transport/http2_errors.h \ src/core/ext/transport/chttp2/transport/huffsyms.h \ src/core/ext/transport/chttp2/transport/incoming_metadata.h \ src/core/ext/transport/chttp2/transport/internal.h \ -src/core/ext/transport/chttp2/transport/status_conversion.h \ src/core/ext/transport/chttp2/transport/stream_map.h \ src/core/ext/transport/chttp2/transport/varint.h \ src/core/ext/transport/chttp2/alpn/alpn.h \ @@ -1075,11 +1077,13 @@ src/core/lib/surface/validate_metadata.c \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ +src/core/lib/transport/error_utils.c \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata_batch.c \ src/core/lib/transport/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ +src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -1100,7 +1104,6 @@ src/core/ext/transport/chttp2/transport/hpack_table.c \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ -src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index cadb639fe47..40a06df4551 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6695,6 +6695,7 @@ "src/core/lib/iomgr/endpoint.h", "src/core/lib/iomgr/endpoint_pair.h", "src/core/lib/iomgr/error.h", + "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.h", "src/core/lib/iomgr/ev_posix.h", @@ -6763,11 +6764,14 @@ "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/error_utils.h", + "src/core/lib/transport/http2_errors.h", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.h", "src/core/lib/transport/pid_controller.h", "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", + "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", "src/core/lib/transport/transport_impl.h" @@ -6830,6 +6834,7 @@ "src/core/lib/iomgr/endpoint_pair_windows.c", "src/core/lib/iomgr/error.c", "src/core/lib/iomgr/error.h", + "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.c", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.c", @@ -6980,6 +6985,9 @@ "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.c", "src/core/lib/transport/connectivity_state.h", + "src/core/lib/transport/error_utils.c", + "src/core/lib/transport/error_utils.h", + "src/core/lib/transport/http2_errors.h", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", @@ -6990,6 +6998,8 @@ "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/status_conversion.c", + "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.c", @@ -7359,11 +7369,9 @@ "src/core/ext/transport/chttp2/transport/hpack_encoder.h", "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.h", - "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", - "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h" ], @@ -7397,15 +7405,12 @@ "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.c", "src/core/ext/transport/chttp2/transport/hpack_table.h", - "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.c", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.c", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", "src/core/ext/transport/chttp2/transport/parsing.c", - "src/core/ext/transport/chttp2/transport/status_conversion.c", - "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_lists.c", "src/core/ext/transport/chttp2/transport/stream_map.c", "src/core/ext/transport/chttp2/transport/stream_map.h", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index f1adc1a4bc5..b408a0c6344 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -320,6 +320,7 @@ + @@ -388,11 +389,14 @@ + + + @@ -409,11 +413,9 @@ - - @@ -692,6 +694,8 @@ + + @@ -702,6 +706,8 @@ + + @@ -742,8 +748,6 @@ - - diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 1e6665dd5ab..f64d4aaa540 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -319,6 +319,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -334,6 +337,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -394,9 +400,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport @@ -806,6 +809,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -1010,6 +1016,12 @@ src\core\lib\transport + + src\core\lib\transport + + + src\core\lib\transport + src\core\lib\transport @@ -1025,6 +1037,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -1073,9 +1088,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport @@ -1085,9 +1097,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index ac961489340..6c7af6ca016 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -213,6 +213,7 @@ + @@ -281,11 +282,14 @@ + + + @@ -541,6 +545,8 @@ + + @@ -551,6 +557,8 @@ + + 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 2c1fc5956de..eea0fe80092 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -376,6 +376,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -391,6 +394,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -596,6 +602,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -800,6 +809,12 @@ src\core\lib\transport + + src\core\lib\transport + + + src\core\lib\transport + src\core\lib\transport @@ -815,6 +830,9 @@ src\core\lib\transport + + 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 1ef1d3f51f3..ea491dc69a8 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -310,6 +310,7 @@ + @@ -378,11 +379,14 @@ + + + @@ -399,11 +403,9 @@ - - @@ -660,6 +662,8 @@ + + @@ -670,6 +674,8 @@ + + @@ -712,8 +718,6 @@ - - diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index ffcf584358e..1bff26e9b81 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -322,6 +322,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -337,6 +340,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -400,9 +406,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport @@ -719,6 +722,9 @@ src\core\lib\iomgr + + src\core\lib\iomgr + src\core\lib\iomgr @@ -923,6 +929,12 @@ src\core\lib\transport + + src\core\lib\transport + + + src\core\lib\transport + src\core\lib\transport @@ -938,6 +950,9 @@ src\core\lib\transport + + src\core\lib\transport + src\core\lib\transport @@ -986,9 +1001,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport @@ -998,9 +1010,6 @@ src\core\ext\transport\chttp2\transport - - src\core\ext\transport\chttp2\transport - src\core\ext\transport\chttp2\transport From dc21a4efb281459b4d3d046cc17ea89e5b56f878 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 13 Dec 2016 17:33:51 -0800 Subject: [PATCH 134/261] Error handling cleanup --- .../chttp2/transport/chttp2_transport.c | 96 ++++++------------- .../chttp2/transport/frame_rst_stream.c | 13 +-- .../chttp2/transport/frame_settings.c | 14 +-- .../transport/chttp2/transport/hpack_parser.c | 2 +- .../ext/transport/chttp2/transport/internal.h | 3 +- .../ext/transport/chttp2/transport/parsing.c | 8 +- .../ext/transport/chttp2/transport/writing.c | 6 +- src/core/lib/surface/call.c | 8 +- src/core/lib/surface/server.c | 10 +- src/core/lib/transport/error_utils.c | 66 +++++++++---- src/core/lib/transport/error_utils.h | 10 +- src/core/lib/transport/http2_errors.h | 30 +++--- src/core/lib/transport/status_conversion.c | 36 ++++--- src/core/lib/transport/status_conversion.h | 11 +-- src/core/lib/transport/transport.h | 7 +- src/core/lib/transport/transport_op_string.c | 11 +-- 16 files changed, 156 insertions(+), 175 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 3711e0cba13..6a2a54a660e 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1252,11 +1252,16 @@ void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_error_code error, grpc_slice data) { + grpc_error *error) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; - grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)error, data, - &t->qbuf); + grpc_http2_error_code http_error; + const char *msg; + grpc_error_get_status(error, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL, &msg, + &http_error); + grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, + grpc_slice_from_copied_string(msg), &t->qbuf); grpc_chttp2_initiate_write(exec_ctx, t, false, "goaway_sent"); + GRPC_ERROR_UNREF(error); } static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, @@ -1272,10 +1277,8 @@ static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, op->on_connectivity_state_change); } - if (op->send_goaway) { - send_goaway(exec_ctx, t, - grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), - grpc_slice_ref_internal(*op->goaway_message)); + if (op->goaway_error) { + send_goaway(exec_ctx, t, op->goaway_error); } if (op->set_accept_stream) { @@ -1428,33 +1431,6 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, maybe_start_some_streams(exec_ctx, t); } -static void status_codes_from_error(grpc_error *error, gpr_timespec deadline, - grpc_chttp2_error_code *http2_error, - grpc_status_code *grpc_status) { - intptr_t ip_http; - intptr_t ip_grpc; - bool have_http = - grpc_error_get_int(error, GRPC_ERROR_INT_HTTP2_ERROR, &ip_http); - bool have_grpc = - grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &ip_grpc); - if (have_http) { - *http2_error = (grpc_chttp2_error_code)ip_http; - } else if (have_grpc) { - *http2_error = - grpc_chttp2_grpc_status_to_http2_error((grpc_status_code)ip_grpc); - } else { - *http2_error = GRPC_CHTTP2_INTERNAL_ERROR; - } - if (have_grpc) { - *grpc_status = (grpc_status_code)ip_grpc; - } else if (have_http) { - *grpc_status = grpc_chttp2_http2_error_to_grpc_status( - (grpc_chttp2_error_code)ip_http, deadline); - } else { - *grpc_status = GRPC_STATUS_INTERNAL; - } -} - void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *due_to_error) { @@ -1465,28 +1441,14 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, } if (!s->read_closed || !s->write_closed) { - grpc_status_code grpc_status; - grpc_chttp2_error_code http_error; - status_codes_from_error(due_to_error, s->deadline, &http_error, - &grpc_status); - if (s->id != 0) { + grpc_http2_error_code http_error; + grpc_error_get_status(due_to_error, s->deadline, NULL, NULL, &http_error); grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, &s->stats.outgoing)); grpc_chttp2_initiate_write(exec_ctx, t, false, "rst_stream"); } - - const char *msg = - grpc_error_get_str(due_to_error, GRPC_ERROR_STR_GRPC_MESSAGE); - bool free_msg = false; - if (msg == NULL) { - free_msg = true; - msg = grpc_error_string(due_to_error); - } - grpc_slice msg_slice = grpc_slice_from_copied_string(msg); - grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, &msg_slice); - if (free_msg) grpc_error_free_string(msg); } if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) { s->seen_error = true; @@ -1496,8 +1458,11 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, } void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_status_code status, - grpc_slice *slice) { + grpc_chttp2_stream *s, grpc_error *error) { + grpc_status_code status; + const char *msg; + grpc_error_get_status(error, s->deadline, &status, &msg, NULL); + if (status != GRPC_STATUS_OK) { s->seen_error = true; } @@ -1515,18 +1480,17 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, &s->metadata_buffer[1], grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(status_string))); - if (slice) { + if (msg != NULL) { grpc_chttp2_incoming_metadata_buffer_add( &s->metadata_buffer[1], grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_slice_ref_internal(*slice))); + grpc_slice_from_copied_string(msg))); } s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } - if (slice) { - grpc_slice_unref_internal(exec_ctx, *slice); - } + + GRPC_ERROR_UNREF(error); } static void add_error(grpc_error *error, grpc_error **refs, size_t *nrefs) { @@ -1596,6 +1560,7 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, return; } if (close_reads && !s->read_closed) { + grpc_chttp2_fake_status(exec_ctx, t, s, GRPC_ERROR_REF(error)); s->read_closed_error = GRPC_ERROR_REF(error); s->read_closed = true; for (int i = 0; i < 2; i++) { @@ -1636,7 +1601,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, uint32_t len = 0; grpc_status_code grpc_status; const char *msg; - grpc_error_get_status(error, &grpc_status, &msg); + grpc_error_get_status(error, s->deadline, &grpc_status, &msg, NULL); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); @@ -1719,14 +1684,9 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_slice_buffer_add(&t->qbuf, grpc_slice_from_copied_string(msg)); } grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); - grpc_slice msg_slice = - msg == NULL ? grpc_empty_slice() : grpc_slice_from_copied_string(msg); - grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, - msg == NULL ? NULL : &msg_slice); - grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error); grpc_chttp2_initiate_write(exec_ctx, t, false, "close_from_api"); } @@ -2173,8 +2133,10 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory", t->peer_string); } - send_goaway(exec_ctx, t, GRPC_CHTTP2_ENHANCE_YOUR_CALM, - grpc_slice_from_static_string("Buffers full")); + send_goaway(exec_ctx, t, + grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), + GRPC_ERROR_INT_HTTP2_ERROR, + GRPC_HTTP2_ENHANCE_YOUR_CALM)); } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace) { gpr_log(GPR_DEBUG, "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR @@ -2203,7 +2165,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_chttp2_cancel_stream( exec_ctx, t, s, grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, - GRPC_CHTTP2_ENHANCE_YOUR_CALM)); + GRPC_HTTP2_ENHANCE_YOUR_CALM)); if (n > 1) { /* Since we cancel one stream per destructive reclamation, if there are more streams left, we can immediately post a new diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c index b4c5ed769b9..583ac9e98e1 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c @@ -39,8 +39,7 @@ #include #include "src/core/ext/transport/chttp2/transport/frame.h" -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" -#include "src/core/ext/transport/chttp2/transport/status_conversion.h" +#include "src/core/lib/transport/http2_errors.h" grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, grpc_transport_one_way_stats *stats) { @@ -109,17 +108,9 @@ grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, (((uint32_t)p->reason_bytes[2]) << 8) | (((uint32_t)p->reason_bytes[3])); grpc_error *error = GRPC_ERROR_NONE; - if (reason != GRPC_CHTTP2_NO_ERROR) { + if (reason != GRPC_HTTP2_NO_ERROR) { error = grpc_error_set_int(GRPC_ERROR_CREATE("RST_STREAM"), GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); - grpc_status_code status_code = grpc_chttp2_http2_error_to_grpc_status( - (grpc_chttp2_error_code)reason, s->deadline); - char *status_details; - gpr_asprintf(&status_details, "Received RST_STREAM with error code %d", - reason); - grpc_slice slice_details = grpc_slice_from_copied_string(status_details); - gpr_free(status_details); - grpc_chttp2_fake_status(exec_ctx, t, s, status_code, &slice_details); } grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, error); } diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.c b/src/core/ext/transport/chttp2/transport/frame_settings.c index bfed41fadbd..be9b663ac14 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.c +++ b/src/core/ext/transport/chttp2/transport/frame_settings.c @@ -52,21 +52,21 @@ const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = { {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_HTTP2_PROTOCOL_ERROR}, {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff, - GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_HTTP2_PROTOCOL_ERROR}, {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, {"INITIAL_WINDOW_SIZE", 65535, 0, 0x7fffffffu, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_CHTTP2_FLOW_CONTROL_ERROR}, + GRPC_HTTP2_FLOW_CONTROL_ERROR}, {"MAX_FRAME_SIZE", 16384, 16384, 16777215, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, {"MAX_HEADER_LIST_SIZE", MAX_MAX_HEADER_LIST_SIZE, 0, MAX_MAX_HEADER_LIST_SIZE, GRPC_CHTTP2_CLAMP_INVALID_VALUE, - GRPC_CHTTP2_PROTOCOL_ERROR}, + GRPC_HTTP2_PROTOCOL_ERROR}, }; static uint8_t *fill_header(uint8_t *out, uint32_t length, uint8_t flags) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 6d6d0de742b..40f5120308c 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -1644,7 +1644,7 @@ static void force_client_rst_stream(grpc_exec_ctx *exec_ctx, void *sp, grpc_chttp2_transport *t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); grpc_chttp2_initiate_write(exec_ctx, t, false, "force_rst_stream"); grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, GRPC_ERROR_NONE); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index a52acbacdb3..43fd10f0fd2 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -612,8 +612,7 @@ void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase, uint32_t stream_id, int64_t val1, int64_t val2); void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *stream, - grpc_status_code status, grpc_slice *details); + grpc_chttp2_stream *stream, grpc_error *error); void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, int close_reads, diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index c5a99e54241..11e4655f117 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -39,11 +39,11 @@ #include #include -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" -#include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_string_helpers.h" +#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/static_metadata.h" +#include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx, @@ -433,7 +433,7 @@ error_handler: } grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, - GRPC_CHTTP2_PROTOCOL_ERROR, + GRPC_HTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); return init_skip_frame_parser(exec_ctx, t, 0); } else { @@ -758,7 +758,7 @@ static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, s->forced_close_error = err; grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, - GRPC_CHTTP2_PROTOCOL_ERROR, + GRPC_HTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); } else { GRPC_ERROR_UNREF(err); diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index ef2010af7b9..182aff1e3ff 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -37,9 +37,9 @@ #include -#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" +#include "src/core/lib/transport/http2_errors.h" static void add_to_write_list(grpc_chttp2_write_cb **list, grpc_chttp2_write_cb *cb) { @@ -164,7 +164,7 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, s->sent_trailing_metadata = true; if (!t->is_client && !s->read_closed) { grpc_slice_buffer_add(&t->outbuf, grpc_chttp2_rst_stream_create( - s->id, GRPC_CHTTP2_NO_ERROR, + s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); } } @@ -197,7 +197,7 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, if (!t->is_client && !s->read_closed) { grpc_slice_buffer_add( &t->outbuf, grpc_chttp2_rst_stream_create( - s->id, GRPC_CHTTP2_NO_ERROR, &s->stats.outgoing)); + s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); } now_writing = true; } diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 4abf9819979..17fda435aaf 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -336,10 +336,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, args->server_transport_data, path, call->start_time, send_deadline, CALL_STACK_FROM_CALL(call)); if (error != GRPC_ERROR_NONE) { - grpc_status_code status; - const char *error_str; - grpc_error_get_status(error, &status, &error_str); - cancel_with_status(exec_ctx, call, status, error_str); + cancel_with_error(exec_ctx, call, GRPC_ERROR_REF(error)); } if (args->cq != NULL) { GPR_ASSERT( @@ -612,7 +609,8 @@ static void get_final_status(grpc_call *call, grpc_status_code code; const char *msg = NULL; - grpc_error_get_status(call->status[i].error, &code, &msg); + grpc_error_get_status(call->status[i].error, call->send_deadline, &code, + &msg, NULL); set_value(code, set_value_user_data); if (details != NULL) { *details = grpc_slice_from_copied_string(msg); diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 7af951f2a0e..b5f905bf040 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -280,18 +280,20 @@ static void shutdown_cleanup(grpc_exec_ctx *exec_ctx, void *arg, } static void send_shutdown(grpc_exec_ctx *exec_ctx, grpc_channel *channel, - int send_goaway, grpc_error *send_disconnect) { + bool send_goaway, grpc_error *send_disconnect) { struct shutdown_cleanup_args *sc = gpr_malloc(sizeof(*sc)); grpc_closure_init(&sc->closure, shutdown_cleanup, sc, grpc_schedule_on_exec_ctx); grpc_transport_op *op = grpc_make_transport_op(&sc->closure); grpc_channel_element *elem; - op->send_goaway = send_goaway; + op->goaway_error = + send_goaway + ? grpc_error_set_int(GRPC_ERROR_CREATE("Server shutdown"), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK) + : GRPC_ERROR_NONE; op->set_accept_stream = true; sc->slice = grpc_slice_from_copied_string("Server shutdown"); - op->goaway_message = &sc->slice; - op->goaway_status = GRPC_STATUS_OK; op->disconnect_with_error = send_disconnect; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); diff --git a/src/core/lib/transport/error_utils.c b/src/core/lib/transport/error_utils.c index 6403cf80d8c..da77828d9c1 100644 --- a/src/core/lib/transport/error_utils.c +++ b/src/core/lib/transport/error_utils.c @@ -32,12 +32,14 @@ */ #include "src/core/lib/transport/error_utils.h" + #include "src/core/lib/iomgr/error_internal.h" +#include "src/core/lib/transport/status_conversion.h" -static grpc_error *recursively_find_error_with_status(grpc_error *error, - intptr_t *status) { +static grpc_error *recursively_find_error_with_field(grpc_error *error, + grpc_error_ints which) { // If the error itself has a status code, return it. - if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) { + if (grpc_error_get_int(error, which, NULL)) { return error; } if (grpc_error_is_special(error)) return NULL; @@ -46,32 +48,64 @@ static grpc_error *recursively_find_error_with_status(grpc_error *error, while (true) { grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); if (child_error == NULL) break; - grpc_error *result = - recursively_find_error_with_status(child_error, status); + grpc_error *result = recursively_find_error_with_field(child_error, which); if (result != NULL) return result; } return NULL; } -void grpc_error_get_status(grpc_error *error, grpc_status_code *code, - const char **msg) { - // Populate code. +void grpc_error_get_status(grpc_error *error, gpr_timespec deadline, + grpc_status_code *code, const char **msg, + grpc_http2_error_code *http_error) { // Start with the parent error and recurse through the tree of children // until we find the first one that has a status code. - intptr_t status = GRPC_STATUS_UNKNOWN; // Default in case we don't find one. - grpc_error *found_error = recursively_find_error_with_status(error, &status); - *code = (grpc_status_code)status; - // Now populate msg. + grpc_error *found_error = + recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS); + if (found_error == NULL) { + /// If no grpc-status exists, retry through the tree to find a http2 error + /// code + found_error = + recursively_find_error_with_field(error, GRPC_ERROR_INT_HTTP2_ERROR); + } + // If we found an error with a status code above, use that; otherwise, // fall back to using the parent error. if (found_error == NULL) found_error = error; + + grpc_status_code status = GRPC_STATUS_UNKNOWN; + intptr_t integer; + if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) { + status = (grpc_status_code)integer; + } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, + &integer)) { + status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer, + deadline); + } + if (code != NULL) *code = status; + + if (http_error != NULL) { + if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { + *http_error = (grpc_http2_error_code)integer; + } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, + &integer)) { + *http_error = grpc_status_to_http2_error((grpc_status_code)integer); + } else { + *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR + : GRPC_HTTP2_INTERNAL_ERROR; + } + } + // If the error has a status message, use it. Otherwise, fall back to // the error description. - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); - if (*msg == NULL && status != GRPC_STATUS_OK) { - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); - if (*msg == NULL) *msg = "unknown error"; // Just in case. + if (msg != NULL) { + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); + if (*msg == NULL && error != GRPC_ERROR_NONE) { + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); + if (*msg == NULL) *msg = "unknown error"; // Just in case. + } } + + if (found_error == NULL) found_error = error; } bool grpc_error_has_clear_grpc_status(grpc_error *error) { diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h index 541dba852f9..f72c3dca0ed 100644 --- a/src/core/lib/transport/error_utils.h +++ b/src/core/lib/transport/error_utils.h @@ -35,12 +35,18 @@ #define GRPC_ERROR_UTILS_H #include "src/core/lib/iomgr/error.h" +#include "src/core/lib/transport/http2_errors.h" /// A utility function to get the status code and message to be returned /// to the application. If not set in the top-level message, looks /// through child errors until it finds the first one with these attributes. -void grpc_error_get_status(grpc_error *error, grpc_status_code *code, - const char **msg); +/// All attributes are pulled from the same child error. If any of the +/// attributes (code, msg, http_status) are unneeded, they can be passed as +/// NULL. +void grpc_error_get_status(grpc_error *error, gpr_timespec deadline, + grpc_status_code *code, const char **msg, + grpc_http2_error_code *http_status); + /// A utility function to check whether there is a clear status code that /// doesn't need to be guessed in \a error. This means that \a error or some /// child has GRPC_ERROR_INT_GRPC_STATUS set, or that it is GRPC_ERROR_NONE or diff --git a/src/core/lib/transport/http2_errors.h b/src/core/lib/transport/http2_errors.h index deab2b7e3e8..bf24438dde3 100644 --- a/src/core/lib/transport/http2_errors.h +++ b/src/core/lib/transport/http2_errors.h @@ -36,21 +36,21 @@ /* error codes for RST_STREAM from http2 draft 14 section 7 */ typedef enum { - GRPC_CHTTP2_NO_ERROR = 0x0, - GRPC_CHTTP2_PROTOCOL_ERROR = 0x1, - GRPC_CHTTP2_INTERNAL_ERROR = 0x2, - GRPC_CHTTP2_FLOW_CONTROL_ERROR = 0x3, - GRPC_CHTTP2_SETTINGS_TIMEOUT = 0x4, - GRPC_CHTTP2_STREAM_CLOSED = 0x5, - GRPC_CHTTP2_FRAME_SIZE_ERROR = 0x6, - GRPC_CHTTP2_REFUSED_STREAM = 0x7, - GRPC_CHTTP2_CANCEL = 0x8, - GRPC_CHTTP2_COMPRESSION_ERROR = 0x9, - GRPC_CHTTP2_CONNECT_ERROR = 0xa, - GRPC_CHTTP2_ENHANCE_YOUR_CALM = 0xb, - GRPC_CHTTP2_INADEQUATE_SECURITY = 0xc, + GRPC_HTTP2_NO_ERROR = 0x0, + GRPC_HTTP2_PROTOCOL_ERROR = 0x1, + GRPC_HTTP2_INTERNAL_ERROR = 0x2, + GRPC_HTTP2_FLOW_CONTROL_ERROR = 0x3, + GRPC_HTTP2_SETTINGS_TIMEOUT = 0x4, + GRPC_HTTP2_STREAM_CLOSED = 0x5, + GRPC_HTTP2_FRAME_SIZE_ERROR = 0x6, + GRPC_HTTP2_REFUSED_STREAM = 0x7, + GRPC_HTTP2_CANCEL = 0x8, + GRPC_HTTP2_COMPRESSION_ERROR = 0x9, + GRPC_HTTP2_CONNECT_ERROR = 0xa, + GRPC_HTTP2_ENHANCE_YOUR_CALM = 0xb, + GRPC_HTTP2_INADEQUATE_SECURITY = 0xc, /* force use of a default clause */ - GRPC_CHTTP2__ERROR_DO_NOT_USE = -1 -} grpc_chttp2_error_code; + GRPC_HTTP2__ERROR_DO_NOT_USE = -1 +} grpc_http2_error_code; #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H */ diff --git a/src/core/lib/transport/status_conversion.c b/src/core/lib/transport/status_conversion.c index eb1d53c8d1c..af0ac89db75 100644 --- a/src/core/lib/transport/status_conversion.c +++ b/src/core/lib/transport/status_conversion.c @@ -33,49 +33,49 @@ #include "src/core/lib/transport/status_conversion.h" -int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) { +int grpc_status_to_http2_error(grpc_status_code status) { switch (status) { case GRPC_STATUS_OK: - return GRPC_CHTTP2_NO_ERROR; + return GRPC_HTTP2_NO_ERROR; case GRPC_STATUS_CANCELLED: - return GRPC_CHTTP2_CANCEL; + return GRPC_HTTP2_CANCEL; case GRPC_STATUS_DEADLINE_EXCEEDED: - return GRPC_CHTTP2_CANCEL; + return GRPC_HTTP2_CANCEL; case GRPC_STATUS_RESOURCE_EXHAUSTED: - return GRPC_CHTTP2_ENHANCE_YOUR_CALM; + return GRPC_HTTP2_ENHANCE_YOUR_CALM; case GRPC_STATUS_PERMISSION_DENIED: - return GRPC_CHTTP2_INADEQUATE_SECURITY; + return GRPC_HTTP2_INADEQUATE_SECURITY; case GRPC_STATUS_UNAVAILABLE: - return GRPC_CHTTP2_REFUSED_STREAM; + return GRPC_HTTP2_REFUSED_STREAM; default: - return GRPC_CHTTP2_INTERNAL_ERROR; + return GRPC_HTTP2_INTERNAL_ERROR; } } -grpc_status_code grpc_chttp2_http2_error_to_grpc_status( - grpc_chttp2_error_code error, gpr_timespec deadline) { +grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, + gpr_timespec deadline) { switch (error) { - case GRPC_CHTTP2_NO_ERROR: + case GRPC_HTTP2_NO_ERROR: /* should never be received */ return GRPC_STATUS_INTERNAL; - case GRPC_CHTTP2_CANCEL: + case GRPC_HTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ return gpr_time_cmp(gpr_now(deadline.clock_type), deadline) >= 0 ? GRPC_STATUS_DEADLINE_EXCEEDED : GRPC_STATUS_CANCELLED; - case GRPC_CHTTP2_ENHANCE_YOUR_CALM: + case GRPC_HTTP2_ENHANCE_YOUR_CALM: return GRPC_STATUS_RESOURCE_EXHAUSTED; - case GRPC_CHTTP2_INADEQUATE_SECURITY: + case GRPC_HTTP2_INADEQUATE_SECURITY: return GRPC_STATUS_PERMISSION_DENIED; - case GRPC_CHTTP2_REFUSED_STREAM: + case GRPC_HTTP2_REFUSED_STREAM: return GRPC_STATUS_UNAVAILABLE; default: return GRPC_STATUS_INTERNAL; } } -grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) { +grpc_status_code grpc_http2_status_to_grpc_status(int status) { switch (status) { /* these HTTP2 status codes are called out explicitly in status.proto */ case 200: @@ -110,6 +110,4 @@ grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) { } } -int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) { - return 200; -} +int grpc_status_to_http2_status(grpc_status_code status) { return 200; } diff --git a/src/core/lib/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h index 592411529d6..3885ac90a53 100644 --- a/src/core/lib/transport/status_conversion.h +++ b/src/core/lib/transport/status_conversion.h @@ -38,13 +38,12 @@ #include "src/core/lib/transport/http2_errors.h" /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ -grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error( - grpc_status_code status); -grpc_status_code grpc_chttp2_http2_error_to_grpc_status( - grpc_chttp2_error_code error, gpr_timespec deadline); +grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status); +grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, + gpr_timespec deadline); /* Conversion of HTTP status codes (:status) to grpc status codes */ -grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status); -int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status); +grpc_status_code grpc_http2_status_to_grpc_status(int status); +int grpc_status_to_http2_status(grpc_status_code status); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H */ diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 2dbb842a53e..9a0abe1ca46 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -181,13 +181,8 @@ typedef struct grpc_transport_op { grpc_connectivity_state *connectivity_state; /** should the transport be disconnected */ grpc_error *disconnect_with_error; - /** should we send a goaway? - after a goaway is sent, once there are no more active calls on - the transport, the transport should disconnect */ - bool send_goaway; /** what should the goaway contain? */ - grpc_status_code goaway_status; - grpc_slice *goaway_message; + grpc_error *goaway_error; /** set the callback for accepting new streams; this is a permanent callback, unlike the other one-shot closures. If true, the callback is set to set_accept_stream_fn, with its diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index 33bd35bd456..8810a6bbda1 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -163,15 +163,12 @@ char *grpc_transport_op_string(grpc_transport_op *op) { grpc_error_free_string(err); } - if (op->send_goaway) { + if (op->goaway_error) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; - char *msg = op->goaway_message == NULL - ? "null" - : grpc_dump_slice(*op->goaway_message, - GPR_DUMP_ASCII | GPR_DUMP_HEX); - gpr_asprintf(&tmp, "SEND_GOAWAY:status=%d:msg=%s", op->goaway_status, msg); - if (op->goaway_message != NULL) gpr_free(msg); + const char *msg = grpc_error_string(op->goaway_error); + gpr_asprintf(&tmp, "SEND_GOAWAY:%s", msg); + grpc_error_free_string(msg); gpr_strvec_add(&b, tmp); } From d7ee291d5f915e2663af4327961d587c45bffc5d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Dec 2016 06:45:00 -0800 Subject: [PATCH 135/261] Fix tests --- Makefile | 72 +++++++------- build.yaml | 20 ++-- .../{chttp2 => }/status_conversion_test.c | 98 +++++++++---------- .../generated/sources_and_headers.json | 34 +++---- tools/run_tests/generated/tests.json | 44 ++++----- vsprojects/buildtests_c.sln | 54 +++++----- ...tp2_status_conversion_test.vcxproj.filters | 24 ----- .../status_conversion_test.vcxproj} | 8 +- .../status_conversion_test.vcxproj.filters | 21 ++++ 9 files changed, 186 insertions(+), 189 deletions(-) rename test/core/transport/{chttp2 => }/status_conversion_test.c (65%) delete mode 100644 vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters rename vsprojects/vcxproj/test/{chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj => status_conversion_test/status_conversion_test.vcxproj} (97%) create mode 100644 vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters diff --git a/Makefile b/Makefile index c5d63eace8b..0b2bc0c692f 100644 --- a/Makefile +++ b/Makefile @@ -934,7 +934,6 @@ census_resource_test: $(BINDIR)/$(CONFIG)/census_resource_test census_trace_context_test: $(BINDIR)/$(CONFIG)/census_trace_context_test channel_create_test: $(BINDIR)/$(CONFIG)/channel_create_test chttp2_hpack_encoder_test: $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test -chttp2_status_conversion_test: $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test chttp2_stream_map_test: $(BINDIR)/$(CONFIG)/chttp2_stream_map_test chttp2_varint_test: $(BINDIR)/$(CONFIG)/chttp2_varint_test client_fuzzer: $(BINDIR)/$(CONFIG)/client_fuzzer @@ -1039,6 +1038,7 @@ sockaddr_resolver_test: $(BINDIR)/$(CONFIG)/sockaddr_resolver_test sockaddr_utils_test: $(BINDIR)/$(CONFIG)/sockaddr_utils_test socket_utils_test: $(BINDIR)/$(CONFIG)/socket_utils_test ssl_server_fuzzer: $(BINDIR)/$(CONFIG)/ssl_server_fuzzer +status_conversion_test: $(BINDIR)/$(CONFIG)/status_conversion_test tcp_client_posix_test: $(BINDIR)/$(CONFIG)/tcp_client_posix_test tcp_posix_test: $(BINDIR)/$(CONFIG)/tcp_posix_test tcp_server_posix_test: $(BINDIR)/$(CONFIG)/tcp_server_posix_test @@ -1281,7 +1281,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/census_trace_context_test \ $(BINDIR)/$(CONFIG)/channel_create_test \ $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test \ - $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test \ $(BINDIR)/$(CONFIG)/chttp2_stream_map_test \ $(BINDIR)/$(CONFIG)/chttp2_varint_test \ $(BINDIR)/$(CONFIG)/combiner_test \ @@ -1368,6 +1367,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/sockaddr_resolver_test \ $(BINDIR)/$(CONFIG)/sockaddr_utils_test \ $(BINDIR)/$(CONFIG)/socket_utils_test \ + $(BINDIR)/$(CONFIG)/status_conversion_test \ $(BINDIR)/$(CONFIG)/tcp_client_posix_test \ $(BINDIR)/$(CONFIG)/tcp_posix_test \ $(BINDIR)/$(CONFIG)/tcp_server_posix_test \ @@ -1621,8 +1621,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/channel_create_test || ( echo test channel_create_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_hpack_encoder_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test || ( echo test chttp2_hpack_encoder_test failed ; exit 1 ) - $(E) "[RUN] Testing chttp2_status_conversion_test" - $(Q) $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test || ( echo test chttp2_status_conversion_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_stream_map_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_stream_map_test || ( echo test chttp2_stream_map_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_varint_test" @@ -1777,6 +1775,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/sockaddr_utils_test || ( echo test sockaddr_utils_test failed ; exit 1 ) $(E) "[RUN] Testing socket_utils_test" $(Q) $(BINDIR)/$(CONFIG)/socket_utils_test || ( echo test socket_utils_test failed ; exit 1 ) + $(E) "[RUN] Testing status_conversion_test" + $(Q) $(BINDIR)/$(CONFIG)/status_conversion_test || ( echo test status_conversion_test failed ; exit 1 ) $(E) "[RUN] Testing tcp_client_posix_test" $(Q) $(BINDIR)/$(CONFIG)/tcp_client_posix_test || ( echo test tcp_client_posix_test failed ; exit 1 ) $(E) "[RUN] Testing tcp_posix_test" @@ -7763,38 +7763,6 @@ endif endif -CHTTP2_STATUS_CONVERSION_TEST_SRC = \ - test/core/transport/chttp2/status_conversion_test.c \ - -CHTTP2_STATUS_CONVERSION_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHTTP2_STATUS_CONVERSION_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/chttp2_status_conversion_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/chttp2_status_conversion_test: $(CHTTP2_STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(CHTTP2_STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/transport/chttp2/status_conversion_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_chttp2_status_conversion_test: $(CHTTP2_STATUS_CONVERSION_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(CHTTP2_STATUS_CONVERSION_TEST_OBJS:.o=.dep) -endif -endif - - CHTTP2_STREAM_MAP_TEST_SRC = \ test/core/transport/chttp2/stream_map_test.c \ @@ -11123,6 +11091,38 @@ endif endif +STATUS_CONVERSION_TEST_SRC = \ + test/core/transport/status_conversion_test.c \ + +STATUS_CONVERSION_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATUS_CONVERSION_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/status_conversion_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/status_conversion_test: $(STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/status_conversion_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/transport/status_conversion_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_status_conversion_test: $(STATUS_CONVERSION_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(STATUS_CONVERSION_TEST_OBJS:.o=.dep) +endif +endif + + TCP_CLIENT_POSIX_TEST_SRC = \ test/core/iomgr/tcp_client_posix_test.c \ diff --git a/build.yaml b/build.yaml index cce12284bef..ab23c8080fe 100644 --- a/build.yaml +++ b/build.yaml @@ -1477,16 +1477,6 @@ targets: - grpc - gpr_test_util - gpr -- name: chttp2_status_conversion_test - build: test - language: c - src: - - test/core/transport/chttp2/status_conversion_test.c - deps: - - grpc_test_util - - grpc - - gpr_test_util - - gpr - name: chttp2_stream_map_test build: test language: c @@ -2618,6 +2608,16 @@ targets: corpus_dirs: - test/core/security/corpus/ssl_server_corpus maxlen: 2048 +- name: status_conversion_test + build: test + language: c + src: + - test/core/transport/status_conversion_test.c + deps: + - grpc_test_util + - grpc + - gpr_test_util + - gpr - name: tcp_client_posix_test cpu_cost: 0.5 build: test diff --git a/test/core/transport/chttp2/status_conversion_test.c b/test/core/transport/status_conversion_test.c similarity index 65% rename from test/core/transport/chttp2/status_conversion_test.c rename to test/core/transport/status_conversion_test.c index f5a5cd1395b..65f840b1e26 100644 --- a/test/core/transport/chttp2/status_conversion_test.c +++ b/test/core/transport/status_conversion_test.c @@ -31,50 +31,50 @@ * */ -#include "src/core/ext/transport/chttp2/transport/status_conversion.h" +#include "src/core/lib/transport/status_conversion.h" #include #include "test/core/util/test_config.h" #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \ - GPR_ASSERT(grpc_chttp2_grpc_status_to_http2_error(a) == (b)) + GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) #define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ - GPR_ASSERT(grpc_chttp2_http2_error_to_grpc_status(a, deadline) == (b)) + GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ - GPR_ASSERT(grpc_chttp2_grpc_status_to_http2_status(a) == (b)) + GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) #define HTTP2_STATUS_TO_GRPC_STATUS(a, b) \ - GPR_ASSERT(grpc_chttp2_http2_status_to_grpc_status(a) == (b)) + GPR_ASSERT(grpc_http2_status_to_grpc_status(a) == (b)) int main(int argc, char **argv) { int i; grpc_test_init(argc, argv); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OK, GRPC_CHTTP2_NO_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_CANCELLED, GRPC_CHTTP2_CANCEL); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNKNOWN, GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OK, GRPC_HTTP2_NO_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_CANCELLED, GRPC_HTTP2_CANCEL); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNKNOWN, GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INVALID_ARGUMENT, - GRPC_CHTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DEADLINE_EXCEEDED, GRPC_CHTTP2_CANCEL); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_NOT_FOUND, GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DEADLINE_EXCEEDED, GRPC_HTTP2_CANCEL); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_NOT_FOUND, GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ALREADY_EXISTS, - GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_PERMISSION_DENIED, - GRPC_CHTTP2_INADEQUATE_SECURITY); + GRPC_HTTP2_INADEQUATE_SECURITY); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNAUTHENTICATED, - GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_RESOURCE_EXHAUSTED, - GRPC_CHTTP2_ENHANCE_YOUR_CALM); + GRPC_HTTP2_ENHANCE_YOUR_CALM); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_FAILED_PRECONDITION, - GRPC_CHTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ABORTED, GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ABORTED, GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OUT_OF_RANGE, - GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNIMPLEMENTED, - GRPC_CHTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INTERNAL, GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INTERNAL, GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNAVAILABLE, - GRPC_CHTTP2_REFUSED_STREAM); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DATA_LOSS, GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_HTTP2_REFUSED_STREAM); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DATA_LOSS, GRPC_HTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_OK, 200); GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_CANCELLED, 200); @@ -95,59 +95,59 @@ int main(int argc, char **argv) { GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_DATA_LOSS, 200); const gpr_timespec before_deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_NO_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_PROTOCOL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INTERNAL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INTERNAL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FLOW_CONTROL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FLOW_CONTROL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_SETTINGS_TIMEOUT, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_SETTINGS_TIMEOUT, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_STREAM_CLOSED, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_STREAM_CLOSED, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FRAME_SIZE_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FRAME_SIZE_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_REFUSED_STREAM, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_REFUSED_STREAM, before_deadline, GRPC_STATUS_UNAVAILABLE); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CANCEL, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CANCEL, before_deadline, GRPC_STATUS_CANCELLED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_COMPRESSION_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_COMPRESSION_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CONNECT_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CONNECT_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_ENHANCE_YOUR_CALM, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_ENHANCE_YOUR_CALM, before_deadline, GRPC_STATUS_RESOURCE_EXHAUSTED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INADEQUATE_SECURITY, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, before_deadline, GRPC_STATUS_PERMISSION_DENIED); const gpr_timespec after_deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_NO_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_PROTOCOL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INTERNAL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INTERNAL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FLOW_CONTROL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FLOW_CONTROL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_SETTINGS_TIMEOUT, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_SETTINGS_TIMEOUT, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_STREAM_CLOSED, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_STREAM_CLOSED, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FRAME_SIZE_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FRAME_SIZE_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_REFUSED_STREAM, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_REFUSED_STREAM, after_deadline, GRPC_STATUS_UNAVAILABLE); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CANCEL, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CANCEL, after_deadline, GRPC_STATUS_DEADLINE_EXCEEDED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_COMPRESSION_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_COMPRESSION_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CONNECT_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CONNECT_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_ENHANCE_YOUR_CALM, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_ENHANCE_YOUR_CALM, after_deadline, GRPC_STATUS_RESOURCE_EXHAUSTED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INADEQUATE_SECURITY, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, after_deadline, GRPC_STATUS_PERMISSION_DENIED); HTTP2_STATUS_TO_GRPC_STATUS(200, GRPC_STATUS_OK); @@ -165,7 +165,7 @@ int main(int argc, char **argv) { /* check all status values can be converted */ for (i = 0; i <= 999; i++) { - grpc_chttp2_http2_status_to_grpc_status(i); + grpc_http2_status_to_grpc_status(i); } return 0; diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 40a06df4551..05509021844 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -217,23 +217,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c", - "name": "chttp2_status_conversion_test", - "src": [ - "test/core/transport/chttp2/status_conversion_test.c" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -1949,6 +1932,23 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "status_conversion_test", + "src": [ + "test/core/transport/status_conversion_test.c" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b76263b8b98..3eeed5a24b0 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -267,28 +267,6 @@ "windows" ] }, - { - "args": [], - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "chttp2_status_conversion_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ] - }, { "args": [], "ci_platforms": [ @@ -2013,6 +1991,28 @@ "posix" ] }, + { + "args": [], + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c", + "name": "status_conversion_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [], "ci_platforms": [ diff --git a/vsprojects/buildtests_c.sln b/vsprojects/buildtests_c.sln index d08a47aa86e..11397831ff5 100644 --- a/vsprojects/buildtests_c.sln +++ b/vsprojects/buildtests_c.sln @@ -153,17 +153,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_hpack_encoder_test", {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_status_conversion_test", "vcxproj\test\chttp2_status_conversion_test\chttp2_status_conversion_test.vcxproj", "{ABAD3D2C-078C-7850-B413-3352A07C6176}" - ProjectSection(myProperties) = preProject - lib = "False" - EndProjectSection - ProjectSection(ProjectDependencies) = postProject - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} - {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} - {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_stream_map_test", "vcxproj\test\chttp2_stream_map_test\chttp2_stream_map_test.vcxproj", "{12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}" ProjectSection(myProperties) = preProject lib = "False" @@ -1434,6 +1423,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockaddr_utils_test", "vcxp {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "status_conversion_test", "vcxproj\test\status_conversion_test\status_conversion_test.vcxproj", "{21E2A241-9D48-02CD-92E4-4EEC98424CF5}" + ProjectSection(myProperties) = preProject + lib = "False" + EndProjectSection + ProjectSection(ProjectDependencies) = postProject + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_tcp_server", "vcxproj\.\test_tcp_server\test_tcp_server.vcxproj", "{E3110C46-A148-FF65-08FD-3324829BE7FE}" ProjectSection(myProperties) = preProject lib = "True" @@ -1793,22 +1793,6 @@ Global {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|Win32.Build.0 = Release|Win32 {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|x64.ActiveCfg = Release|x64 {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|x64.Build.0 = Release|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|Win32.ActiveCfg = Debug|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|x64.ActiveCfg = Debug|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|Win32.ActiveCfg = Release|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|x64.ActiveCfg = Release|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|Win32.Build.0 = Debug|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|x64.Build.0 = Debug|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|Win32.Build.0 = Release|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|x64.Build.0 = Release|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|Win32.Build.0 = Debug|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|x64.ActiveCfg = Debug|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|x64.Build.0 = Debug|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|Win32.ActiveCfg = Release|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|Win32.Build.0 = Release|Win32 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|x64.ActiveCfg = Release|x64 - {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|x64.Build.0 = Release|x64 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Debug|Win32.ActiveCfg = Debug|Win32 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Debug|x64.ActiveCfg = Debug|x64 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Release|Win32.ActiveCfg = Release|Win32 @@ -3713,6 +3697,22 @@ Global {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|Win32.Build.0 = Release|Win32 {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|x64.ActiveCfg = Release|x64 {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|x64.Build.0 = Release|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|Win32.ActiveCfg = Debug|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|x64.ActiveCfg = Debug|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|Win32.ActiveCfg = Release|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|x64.ActiveCfg = Release|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|Win32.Build.0 = Debug|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|x64.Build.0 = Debug|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|Win32.Build.0 = Release|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|x64.Build.0 = Release|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|Win32.Build.0 = Debug|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|x64.ActiveCfg = Debug|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|x64.Build.0 = Debug|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|Win32.ActiveCfg = Release|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|Win32.Build.0 = Release|Win32 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|x64.ActiveCfg = Release|x64 + {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|x64.Build.0 = Release|x64 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Debug|Win32.ActiveCfg = Debug|Win32 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Debug|x64.ActiveCfg = Debug|x64 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters b/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters deleted file mode 100644 index d94af50254a..00000000000 --- a/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters +++ /dev/null @@ -1,24 +0,0 @@ - - - - - test\core\transport\chttp2 - - - - - - {29690dfb-a808-84b3-d82e-deadb5d04103} - - - {d17e51ca-73ac-6f31-d02c-631ac849c194} - - - {3f03cd74-998e-23ed-a372-a1b706d35bf4} - - - {b65a9b0c-fa3d-1919-b70f-9d2d5cc28077} - - - - diff --git a/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj b/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj similarity index 97% rename from vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj rename to vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj index f5b8838cdf9..ab1e3a7a9fb 100644 --- a/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj +++ b/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj @@ -20,7 +20,7 @@ - {ABAD3D2C-078C-7850-B413-3352A07C6176} + {21E2A241-9D48-02CD-92E4-4EEC98424CF5} true $(SolutionDir)IntDir\$(MSBuildProjectName)\ @@ -60,14 +60,14 @@ - chttp2_status_conversion_test + status_conversion_test static Debug static Debug - chttp2_status_conversion_test + status_conversion_test static Release static @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters b/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters new file mode 100644 index 00000000000..72ebef552d2 --- /dev/null +++ b/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters @@ -0,0 +1,21 @@ + + + + + test\core\transport + + + + + + {4702a9eb-d239-c799-0712-b7af210665bd} + + + {2f2eed07-7d0f-4b4a-67c0-96e860bb6b16} + + + {269c6750-9126-9b6a-4196-b7cbe492ee9f} + + + + From 60e63d41e18ccd57482fc9df1455513e080f7220 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Dec 2016 07:23:42 -0800 Subject: [PATCH 136/261] Fixes --- .../ext/transport/chttp2/transport/chttp2_transport.c | 10 +++++----- src/core/lib/surface/call.c | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 6a2a54a660e..8bfacfac67f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1560,7 +1560,6 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, return; } if (close_reads && !s->read_closed) { - grpc_chttp2_fake_status(exec_ctx, t, s, GRPC_ERROR_REF(error)); s->read_closed_error = GRPC_ERROR_REF(error); s->read_closed = true; for (int i = 0; i < 2; i++) { @@ -1571,22 +1570,23 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, decrement_active_streams_locked(exec_ctx, t, s); grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } if (close_writes && !s->write_closed) { s->write_closed_error = GRPC_ERROR_REF(error); s->write_closed = true; grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error)); - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } if (s->read_closed && s->write_closed) { + grpc_error *overall_error = + removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { - remove_stream(exec_ctx, t, s->id, - removal_error(GRPC_ERROR_REF(error), s, "Stream removed")); + remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error)); } else { /* Purge streams waiting on concurrency still waiting for id assignment */ grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } + grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2"); } GRPC_ERROR_UNREF(error); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 17fda435aaf..38b6225abdd 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -627,6 +627,11 @@ static void get_final_status(grpc_call *call, static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, status_source source, grpc_error *error) { + const char *es = grpc_error_string(error); + gpr_log(GPR_DEBUG, "%p[%d]: set %d[is_set=%d] to %s", call, call->is_client, + source, call->status[source].is_set, es); + grpc_error_free_string(es); + if (call->status[source].is_set) { GRPC_ERROR_UNREF(error); return; From bedb18959b9320929d25b230b592b76b96355e03 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Dec 2016 08:06:36 -0800 Subject: [PATCH 137/261] Fixes, remove grpc_error_free_string --- src/core/ext/client_channel/subchannel.c | 4 +-- .../ext/resolver/dns/native/dns_resolver.c | 2 +- .../transport/chttp2/server/chttp2_server.c | 4 +-- .../chttp2/server/insecure/server_chttp2.c | 2 +- .../server/secure/server_secure_chttp2.c | 2 +- .../chttp2/transport/chttp2_transport.c | 16 +++++++---- .../ext/transport/chttp2/transport/parsing.c | 2 +- .../lib/http/httpcli_security_connector.c | 2 +- src/core/lib/iomgr/error.c | 28 +++++++++++-------- src/core/lib/iomgr/error.h | 1 - src/core/lib/iomgr/error_internal.h | 1 + src/core/lib/iomgr/tcp_client_posix.c | 4 +-- src/core/lib/iomgr/tcp_posix.c | 6 ++-- src/core/lib/iomgr/tcp_server_windows.c | 2 +- src/core/lib/iomgr/tcp_uv.c | 2 +- .../security/transport/security_handshaker.c | 2 +- src/core/lib/surface/call.c | 9 +++--- src/core/lib/surface/completion_queue.c | 8 +++--- src/core/lib/surface/server.c | 2 +- src/core/lib/transport/connectivity_state.c | 2 +- src/core/lib/transport/transport_op_string.c | 6 ++-- test/core/end2end/fixtures/http_proxy.c | 2 +- test/core/util/port_server_client.c | 2 +- 23 files changed, 61 insertions(+), 50 deletions(-) diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 54764ea7f87..73ae1b859d5 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -687,7 +687,7 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, const char *errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); - grpc_error_free_string(errmsg); + maybe_start_connecting_locked(exec_ctx, c); GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); @@ -758,7 +758,7 @@ grpc_error *grpc_connected_subchannel_create_call( if (error != GRPC_ERROR_NONE) { const char *error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); - grpc_error_free_string(error_string); + gpr_free(*call); return error; } diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index bb2b0125072..297700143e2 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -190,7 +190,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, gpr_timespec timeout = gpr_time_sub(next_try, now); const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); - grpc_error_free_string(msg); + GPR_ASSERT(!r->have_retry_timer); r->have_retry_timer = true; GRPC_RESOLVER_REF(&r->base, "retry-timer"); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.c b/src/core/ext/transport/chttp2/server/chttp2_server.c index 86f5a198c26..fb029601600 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.c +++ b/src/core/ext/transport/chttp2/server/chttp2_server.c @@ -139,7 +139,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE || connection_state->server_state->shutdown) { const char *error_str = grpc_error_string(error); gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str); - grpc_error_free_string(error_str); + if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { // We were shut down after handshaking completed successfully, so // destroy the endpoint here. @@ -328,7 +328,7 @@ grpc_error *grpc_chttp2_server_add_port( const char *warning_message = grpc_error_string(err); gpr_log(GPR_INFO, "WARNING: %s", warning_message); - grpc_error_free_string(warning_message); + /* we managed to bind some addresses: continue */ } grpc_resolved_addresses_destroy(resolved); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c index 7e286d4e46d..996681842bb 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c @@ -52,7 +52,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) { if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - grpc_error_free_string(msg); + GRPC_ERROR_UNREF(err); } grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c index b5e4996b16e..2469b9531f1 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c @@ -123,7 +123,7 @@ done: if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - grpc_error_free_string(msg); + GRPC_ERROR_UNREF(err); } return port_num; diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 8bfacfac67f..6ca00032d1f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -861,7 +861,6 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, (int)(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), (int)(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, errstr); - grpc_error_free_string(errstr); } if (error != GRPC_ERROR_NONE) { if (closure->error_data.error == GRPC_ERROR_NONE) { @@ -1452,7 +1451,6 @@ void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, } if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) { s->seen_error = true; - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error); } @@ -1559,6 +1557,8 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, GRPC_ERROR_UNREF(error); return; } + bool closed_read = false; + bool became_closed = false; if (close_reads && !s->read_closed) { s->read_closed_error = GRPC_ERROR_REF(error); s->read_closed = true; @@ -1567,9 +1567,7 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; } } - decrement_active_streams_locked(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + closed_read = true; } if (close_writes && !s->write_closed) { s->write_closed_error = GRPC_ERROR_REF(error); @@ -1577,6 +1575,7 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error)); } if (s->read_closed && s->write_closed) { + became_closed = true; grpc_error *overall_error = removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { @@ -1586,6 +1585,13 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); + } + if (closed_read) { + decrement_active_streams_locked(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + } + if (became_closed) { grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2"); } diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 11e4655f117..2b8563b9d05 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -751,7 +751,7 @@ static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, if (grpc_http_trace) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - grpc_error_free_string(msg); + } grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); if (s) { diff --git a/src/core/lib/http/httpcli_security_connector.c b/src/core/lib/http/httpcli_security_connector.c index 440817c5a6b..fd6fda03c3f 100644 --- a/src/core/lib/http/httpcli_security_connector.c +++ b/src/core/lib/http/httpcli_security_connector.c @@ -156,7 +156,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - grpc_error_free_string(msg); + c->func(exec_ctx, c->arg, NULL); } else { grpc_channel_args_destroy(exec_ctx, args->args); diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index 3cf644f4211..ceff429fcc1 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -190,6 +190,7 @@ static void error_destroy(grpc_error *err) { gpr_avl_unref(err->strs); gpr_avl_unref(err->errs); gpr_avl_unref(err->times); + gpr_free((void *)gpr_atm_acq_load(&err->error_string)); gpr_free(err); } @@ -240,6 +241,7 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, err->times = gpr_avl_add(gpr_avl_create(&avl_vtable_times), (void *)(uintptr_t)GRPC_ERROR_TIME_CREATED, box_time(gpr_now(GPR_CLOCK_REALTIME))); + gpr_atm_no_barrier_store(&err->error_string, 0); gpr_ref_init(&err->refs, 1); GPR_TIMER_END("grpc_error_create", 0); return err; @@ -269,6 +271,7 @@ static grpc_error *copy_error_and_unref(grpc_error *in) { out->strs = gpr_avl_ref(in->strs); out->errs = gpr_avl_ref(in->errs); out->times = gpr_avl_ref(in->times); + gpr_atm_no_barrier_store(&out->error_string, 0); out->next_err = in->next_err; gpr_ref_init(&out->refs, 1); GRPC_ERROR_UNREF(in); @@ -495,7 +498,6 @@ static void add_errs(gpr_avl_node *n, char **s, size_t *sz, size_t *cap, *first = false; const char *e = grpc_error_string(n->value); append_str(e, s, sz, cap); - grpc_error_free_string(e); add_errs(n->right, s, sz, cap, first); } @@ -517,7 +519,7 @@ static int cmp_kvs(const void *a, const void *b) { return strcmp(ka->key, kb->key); } -static const char *finish_kvs(kv_pairs *kvs) { +static char *finish_kvs(kv_pairs *kvs) { char *s = NULL; size_t sz = 0; size_t cap = 0; @@ -538,19 +540,18 @@ static const char *finish_kvs(kv_pairs *kvs) { return s; } -void grpc_error_free_string(const char *str) { - if (str == no_error_string) return; - if (str == oom_error_string) return; - if (str == cancelled_error_string) return; - gpr_free((char *)str); -} - const char *grpc_error_string(grpc_error *err) { GPR_TIMER_BEGIN("grpc_error_string", 0); if (err == GRPC_ERROR_NONE) return no_error_string; if (err == GRPC_ERROR_OOM) return oom_error_string; if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string; + void *p = (void *)gpr_atm_acq_load(&err->error_string); + if (p != NULL) { + GPR_TIMER_END("grpc_error_string", 0); + return p; + } + kv_pairs kvs; memset(&kvs, 0, sizeof(kvs)); @@ -563,7 +564,13 @@ const char *grpc_error_string(grpc_error *err) { qsort(kvs.kvs, kvs.num_kvs, sizeof(kv_pair), cmp_kvs); - const char *out = finish_kvs(&kvs); + char *out = finish_kvs(&kvs); + + if (!gpr_atm_rel_cas(&err->error_string, 0, (gpr_atm)out)) { + gpr_free(out); + out = (char *)gpr_atm_no_barrier_load(&err->error_string); + } + GPR_TIMER_END("grpc_error_string", 0); return out; } @@ -598,7 +605,6 @@ bool grpc_log_if_error(const char *what, grpc_error *error, const char *file, if (error == GRPC_ERROR_NONE) return true; const char *msg = grpc_error_string(error); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "%s: %s", what, msg); - grpc_error_free_string(msg); GRPC_ERROR_UNREF(error); return false; } diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 75ca9c4bf97..ffacdac3934 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -145,7 +145,6 @@ typedef enum { #define GRPC_ERROR_CANCELLED ((grpc_error *)4) const char *grpc_error_string(grpc_error *error); -void grpc_error_free_string(const char *str); /// Create an error - but use GRPC_ERROR_CREATE instead grpc_error *grpc_error_create(const char *file, int line, const char *desc, diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h index 5afe9edc7fb..8f49ba39922 100644 --- a/src/core/lib/iomgr/error_internal.h +++ b/src/core/lib/iomgr/error_internal.h @@ -46,6 +46,7 @@ struct grpc_error { gpr_avl times; gpr_avl errs; uintptr_t next_err; + gpr_atm error_string; }; bool grpc_error_is_special(grpc_error *err); diff --git a/src/core/lib/iomgr/tcp_client_posix.c b/src/core/lib/iomgr/tcp_client_posix.c index 9a77c92016b..a55e7bfc72c 100644 --- a/src/core/lib/iomgr/tcp_client_posix.c +++ b/src/core/lib/iomgr/tcp_client_posix.c @@ -118,7 +118,7 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, str); - grpc_error_free_string(str); + } gpr_mu_lock(&ac->mu); if (ac->fd != NULL) { @@ -178,7 +178,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s", ac->addr_str, str); - grpc_error_free_string(str); + } gpr_mu_lock(&ac->mu); diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index ece44978b0f..402501be5e4 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -181,7 +181,7 @@ static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - grpc_error_free_string(str); + for (i = 0; i < tcp->incoming_buffer->count; i++) { char *dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -435,7 +435,7 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); - grpc_error_free_string(str); + } grpc_closure_run(exec_ctx, cb, error); @@ -485,7 +485,7 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); - grpc_error_free_string(str); + } grpc_closure_sched(exec_ctx, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index 97d78274614..b25783f986e 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -345,7 +345,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Skipping on_accept due to error: %s", msg); - grpc_error_free_string(msg); + gpr_mu_unlock(&sp->server->mu); return; } diff --git a/src/core/lib/iomgr/tcp_uv.c b/src/core/lib/iomgr/tcp_uv.c index a1ee597d094..4bf2e086849 100644 --- a/src/core/lib/iomgr/tcp_uv.c +++ b/src/core/lib/iomgr/tcp_uv.c @@ -157,7 +157,7 @@ static void read_callback(uv_stream_t *stream, ssize_t nread, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - grpc_error_free_string(str); + for (i = 0; i < tcp->read_slices->count; i++) { char *dump = grpc_dump_slice(tcp->read_slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); diff --git a/src/core/lib/security/transport/security_handshaker.c b/src/core/lib/security/transport/security_handshaker.c index e886cc59a02..a14fab71fd8 100644 --- a/src/core/lib/security/transport/security_handshaker.c +++ b/src/core/lib/security/transport/security_handshaker.c @@ -123,7 +123,7 @@ static void security_handshake_failed_locked(grpc_exec_ctx *exec_ctx, } const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "Security handshake failed: %s", msg); - grpc_error_free_string(msg); + if (!h->shutdown) { // TODO(ctiller): It is currently necessary to shutdown endpoints // before destroying them, even if we know that there are no diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 38b6225abdd..f7e7dff097c 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -603,14 +603,14 @@ static void get_final_status(grpc_call *call, int i; for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (call->status[i].is_set) { - const char *text = grpc_error_string(call->status[i].error); - gpr_log(GPR_DEBUG, "%s", text); - grpc_error_free_string(text); - grpc_status_code code; const char *msg = NULL; grpc_error_get_status(call->status[i].error, call->send_deadline, &code, &msg, NULL); + + gpr_log(GPR_DEBUG, "%s --> %d %s", + grpc_error_string(call->status[i].error), code, msg); + set_value(code, set_value_user_data); if (details != NULL) { *details = grpc_slice_from_copied_string(msg); @@ -630,7 +630,6 @@ static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, const char *es = grpc_error_string(error); gpr_log(GPR_DEBUG, "%p[%d]: set %d[is_set=%d] to %s", call, call->is_client, source, call->status[source].is_set, es); - grpc_error_free_string(es); if (call->status[source].is_set) { GRPC_ERROR_UNREF(error); diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index 4613c9021ee..d1f1cd046e9 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -253,7 +253,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (grpc_trace_operation_failures && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } - grpc_error_free_string(errmsg); + } storage->tag = tag; @@ -294,7 +294,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (kick_error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(kick_error); gpr_log(GPR_ERROR, "Kick failed: %s", msg); - grpc_error_free_string(msg); + GRPC_ERROR_UNREF(kick_error); } } else { @@ -461,7 +461,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - grpc_error_free_string(msg); + GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; @@ -647,7 +647,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - grpc_error_free_string(msg); + GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index b5f905bf040..c70aaa174b4 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -453,7 +453,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Disconnected client: %s", msg); - grpc_error_free_string(msg); + } GRPC_ERROR_UNREF(error); diff --git a/src/core/lib/transport/connectivity_state.c b/src/core/lib/transport/connectivity_state.c index c656d93740e..2f55ffd96ca 100644 --- a/src/core/lib/transport/connectivity_state.c +++ b/src/core/lib/transport/connectivity_state.c @@ -163,7 +163,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx, gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker, tracker->name, grpc_connectivity_state_name(tracker->current_state), grpc_connectivity_state_name(state), reason, error, error_string); - grpc_error_free_string(error_string); + } switch (state) { case GRPC_CHANNEL_INIT: diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index 8810a6bbda1..9d5f9c2d6e7 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -121,7 +121,7 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) { gpr_strvec_add(&b, gpr_strdup(" ")); const char *msg = grpc_error_string(op->cancel_error); gpr_asprintf(&tmp, "CANCEL:%s", msg); - grpc_error_free_string(msg); + gpr_strvec_add(&b, tmp); } @@ -160,7 +160,7 @@ char *grpc_transport_op_string(grpc_transport_op *op) { const char *err = grpc_error_string(op->disconnect_with_error); gpr_asprintf(&tmp, "DISCONNECT:%s", err); gpr_strvec_add(&b, tmp); - grpc_error_free_string(err); + } if (op->goaway_error) { @@ -168,7 +168,7 @@ char *grpc_transport_op_string(grpc_transport_op *op) { first = false; const char *msg = grpc_error_string(op->goaway_error); gpr_asprintf(&tmp, "SEND_GOAWAY:%s", msg); - grpc_error_free_string(msg); + gpr_strvec_add(&b, tmp); } diff --git a/test/core/end2end/fixtures/http_proxy.c b/test/core/end2end/fixtures/http_proxy.c index b62082c6fb1..5da6f03e18a 100644 --- a/test/core/end2end/fixtures/http_proxy.c +++ b/test/core/end2end/fixtures/http_proxy.c @@ -132,7 +132,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, const char* prefix, grpc_error* error) { const char* msg = grpc_error_string(error); gpr_log(GPR_INFO, "%s: %s", prefix, msg); - grpc_error_free_string(msg); + grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint); if (conn->server_endpoint != NULL) grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint); diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c index 4baf63dcd7c..74a4d14ff8e 100644 --- a/test/core/util/port_server_client.c +++ b/test/core/util/port_server_client.c @@ -152,7 +152,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, failed = 1; const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "failed port pick from server: retrying [%s]", msg); - grpc_error_free_string(msg); + } else if (response->status != 200) { failed = 1; gpr_log(GPR_DEBUG, "failed port pick from server: status=%d", From 76dca1995352461a97825a28a816c97f0eac2cfb Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 14:54:18 -0800 Subject: [PATCH 138/261] clang-format --- src/core/ext/client_channel/subchannel.c | 3 +-- src/core/ext/resolver/dns/native/dns_resolver.c | 2 +- src/core/ext/transport/chttp2/server/chttp2_server.c | 4 ++-- .../ext/transport/chttp2/server/insecure/server_chttp2.c | 2 +- .../transport/chttp2/server/secure/server_secure_chttp2.c | 2 +- src/core/ext/transport/chttp2/transport/parsing.c | 1 - src/core/lib/http/httpcli_security_connector.c | 2 +- src/core/lib/iomgr/tcp_client_posix.c | 2 -- src/core/lib/iomgr/tcp_posix.c | 4 +--- src/core/lib/iomgr/tcp_server_windows.c | 2 +- src/core/lib/iomgr/tcp_uv.c | 2 +- src/core/lib/security/transport/security_handshaker.c | 2 +- src/core/lib/surface/completion_queue.c | 7 +++---- src/core/lib/surface/server.c | 1 - src/core/lib/transport/connectivity_state.c | 1 - src/core/lib/transport/transport_op_string.c | 5 ++--- test/core/end2end/fixtures/http_proxy.c | 2 +- test/core/util/port_server_client.c | 2 +- 18 files changed, 18 insertions(+), 28 deletions(-) diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 73ae1b859d5..86a19d99ba7 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -687,7 +687,6 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, const char *errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); - maybe_start_connecting_locked(exec_ctx, c); GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); @@ -758,7 +757,7 @@ grpc_error *grpc_connected_subchannel_create_call( if (error != GRPC_ERROR_NONE) { const char *error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); - + gpr_free(*call); return error; } diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 297700143e2..9bb1c0c2273 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -190,7 +190,7 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, gpr_timespec timeout = gpr_time_sub(next_try, now); const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg); - + GPR_ASSERT(!r->have_retry_timer); r->have_retry_timer = true; GRPC_RESOLVER_REF(&r->base, "retry-timer"); diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.c b/src/core/ext/transport/chttp2/server/chttp2_server.c index fb029601600..86fe8d1ccd8 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.c +++ b/src/core/ext/transport/chttp2/server/chttp2_server.c @@ -139,7 +139,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE || connection_state->server_state->shutdown) { const char *error_str = grpc_error_string(error); gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str); - + if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { // We were shut down after handshaking completed successfully, so // destroy the endpoint here. @@ -328,7 +328,7 @@ grpc_error *grpc_chttp2_server_add_port( const char *warning_message = grpc_error_string(err); gpr_log(GPR_INFO, "WARNING: %s", warning_message); - + /* we managed to bind some addresses: continue */ } grpc_resolved_addresses_destroy(resolved); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c index 996681842bb..77ed26a54a5 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c @@ -52,7 +52,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) { if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - + GRPC_ERROR_UNREF(err); } grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c index 2469b9531f1..f909a760d0f 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c @@ -123,7 +123,7 @@ done: if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - + GRPC_ERROR_UNREF(err); } return port_num; diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index 2b8563b9d05..f58cd696f9b 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -751,7 +751,6 @@ static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, if (grpc_http_trace) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - } grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); if (s) { diff --git a/src/core/lib/http/httpcli_security_connector.c b/src/core/lib/http/httpcli_security_connector.c index fd6fda03c3f..f4f6f3c27aa 100644 --- a/src/core/lib/http/httpcli_security_connector.c +++ b/src/core/lib/http/httpcli_security_connector.c @@ -156,7 +156,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - + c->func(exec_ctx, c->arg, NULL); } else { grpc_channel_args_destroy(exec_ctx, args->args); diff --git a/src/core/lib/iomgr/tcp_client_posix.c b/src/core/lib/iomgr/tcp_client_posix.c index a55e7bfc72c..16b0f4e73c1 100644 --- a/src/core/lib/iomgr/tcp_client_posix.c +++ b/src/core/lib/iomgr/tcp_client_posix.c @@ -118,7 +118,6 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, str); - } gpr_mu_lock(&ac->mu); if (ac->fd != NULL) { @@ -178,7 +177,6 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s", ac->addr_str, str); - } gpr_mu_lock(&ac->mu); diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index 402501be5e4..a33e63e845c 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -181,7 +181,7 @@ static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - + for (i = 0; i < tcp->incoming_buffer->count; i++) { char *dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -435,7 +435,6 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); - } grpc_closure_run(exec_ctx, cb, error); @@ -485,7 +484,6 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); - } grpc_closure_sched(exec_ctx, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index b25783f986e..7041f8fb7ec 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -345,7 +345,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Skipping on_accept due to error: %s", msg); - + gpr_mu_unlock(&sp->server->mu); return; } diff --git a/src/core/lib/iomgr/tcp_uv.c b/src/core/lib/iomgr/tcp_uv.c index 4bf2e086849..7f4ea49a1ce 100644 --- a/src/core/lib/iomgr/tcp_uv.c +++ b/src/core/lib/iomgr/tcp_uv.c @@ -157,7 +157,7 @@ static void read_callback(uv_stream_t *stream, ssize_t nread, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - + for (i = 0; i < tcp->read_slices->count; i++) { char *dump = grpc_dump_slice(tcp->read_slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); diff --git a/src/core/lib/security/transport/security_handshaker.c b/src/core/lib/security/transport/security_handshaker.c index a14fab71fd8..6891debfd35 100644 --- a/src/core/lib/security/transport/security_handshaker.c +++ b/src/core/lib/security/transport/security_handshaker.c @@ -123,7 +123,7 @@ static void security_handshake_failed_locked(grpc_exec_ctx *exec_ctx, } const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "Security handshake failed: %s", msg); - + if (!h->shutdown) { // TODO(ctiller): It is currently necessary to shutdown endpoints // before destroying them, even if we know that there are no diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index d1f1cd046e9..20c22ea2bc4 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -253,7 +253,6 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (grpc_trace_operation_failures && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } - } storage->tag = tag; @@ -294,7 +293,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (kick_error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(kick_error); gpr_log(GPR_ERROR, "Kick failed: %s", msg); - + GRPC_ERROR_UNREF(kick_error); } } else { @@ -461,7 +460,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - + GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; @@ -647,7 +646,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - + GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index c70aaa174b4..7d0b30e97a6 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -453,7 +453,6 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Disconnected client: %s", msg); - } GRPC_ERROR_UNREF(error); diff --git a/src/core/lib/transport/connectivity_state.c b/src/core/lib/transport/connectivity_state.c index 2f55ffd96ca..8fc5bf3e9a6 100644 --- a/src/core/lib/transport/connectivity_state.c +++ b/src/core/lib/transport/connectivity_state.c @@ -163,7 +163,6 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx, gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker, tracker->name, grpc_connectivity_state_name(tracker->current_state), grpc_connectivity_state_name(state), reason, error, error_string); - } switch (state) { case GRPC_CHANNEL_INIT: diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index 9d5f9c2d6e7..28360e37840 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -121,7 +121,7 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) { gpr_strvec_add(&b, gpr_strdup(" ")); const char *msg = grpc_error_string(op->cancel_error); gpr_asprintf(&tmp, "CANCEL:%s", msg); - + gpr_strvec_add(&b, tmp); } @@ -160,7 +160,6 @@ char *grpc_transport_op_string(grpc_transport_op *op) { const char *err = grpc_error_string(op->disconnect_with_error); gpr_asprintf(&tmp, "DISCONNECT:%s", err); gpr_strvec_add(&b, tmp); - } if (op->goaway_error) { @@ -168,7 +167,7 @@ char *grpc_transport_op_string(grpc_transport_op *op) { first = false; const char *msg = grpc_error_string(op->goaway_error); gpr_asprintf(&tmp, "SEND_GOAWAY:%s", msg); - + gpr_strvec_add(&b, tmp); } diff --git a/test/core/end2end/fixtures/http_proxy.c b/test/core/end2end/fixtures/http_proxy.c index 5da6f03e18a..dac9baf3cec 100644 --- a/test/core/end2end/fixtures/http_proxy.c +++ b/test/core/end2end/fixtures/http_proxy.c @@ -132,7 +132,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, const char* prefix, grpc_error* error) { const char* msg = grpc_error_string(error); gpr_log(GPR_INFO, "%s: %s", prefix, msg); - + grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint); if (conn->server_endpoint != NULL) grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint); diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c index 74a4d14ff8e..118708d419c 100644 --- a/test/core/util/port_server_client.c +++ b/test/core/util/port_server_client.c @@ -152,7 +152,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, failed = 1; const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "failed port pick from server: retrying [%s]", msg); - + } else if (response->status != 200) { failed = 1; gpr_log(GPR_DEBUG, "failed port pick from server: status=%d", From 6538504ed55590e8b4ab6b51339dc00bdf38ac9b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 14 Dec 2016 08:34:32 -0800 Subject: [PATCH 139/261] Fixes --- .../transport/chttp2/transport/chttp2_transport.c | 12 +++++++----- .../transport/chttp2/transport/incoming_metadata.c | 13 +++++++++++++ .../transport/chttp2/transport/incoming_metadata.h | 3 +++ src/core/lib/surface/call.c | 7 ------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 6ca00032d1f..51191f338e3 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1474,13 +1474,13 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, s->recv_trailing_metadata_finished != NULL) { char status_string[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(status, status_string); - grpc_chttp2_incoming_metadata_buffer_add( - &s->metadata_buffer[1], + grpc_chttp2_incoming_metadata_buffer_replace_or_add( + exec_ctx, &s->metadata_buffer[1], grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(status_string))); if (msg != NULL) { - grpc_chttp2_incoming_metadata_buffer_add( - &s->metadata_buffer[1], + grpc_chttp2_incoming_metadata_buffer_replace_or_add( + exec_ctx, &s->metadata_buffer[1], grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, grpc_slice_from_copied_string(msg))); } @@ -1584,7 +1584,9 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, /* Purge streams waiting on concurrency still waiting for id assignment */ grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } - grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); + if (overall_error != GRPC_ERROR_NONE) { + grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); + } } if (closed_read) { decrement_active_streams_locked(exec_ctx, t, s); diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index fd1b234b8f4..4e4e41734a2 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -68,6 +68,19 @@ void grpc_chttp2_incoming_metadata_buffer_add( buffer->size += GRPC_MDELEM_LENGTH(elem); } +void grpc_chttp2_incoming_metadata_buffer_replace_or_add( + grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, + grpc_mdelem elem) { + for (size_t i = 0; i < buffer->count; i++) { + if (grpc_slice_eq(GRPC_MDKEY(buffer->elems[i].md), GRPC_MDKEY(elem))) { + GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md); + buffer->elems[i].md = elem; + return; + } + } + grpc_chttp2_incoming_metadata_buffer_add(buffer, elem); +} + void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) { GPR_ASSERT(!buffer->published); diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index cd6dacc5bf1..1eac6fc1504 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -56,6 +56,9 @@ void grpc_chttp2_incoming_metadata_buffer_publish( void grpc_chttp2_incoming_metadata_buffer_add( grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem); +void grpc_chttp2_incoming_metadata_buffer_replace_or_add( + grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, + grpc_mdelem elem); void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index f7e7dff097c..4f53b694552 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -608,9 +608,6 @@ static void get_final_status(grpc_call *call, grpc_error_get_status(call->status[i].error, call->send_deadline, &code, &msg, NULL); - gpr_log(GPR_DEBUG, "%s --> %d %s", - grpc_error_string(call->status[i].error), code, msg); - set_value(code, set_value_user_data); if (details != NULL) { *details = grpc_slice_from_copied_string(msg); @@ -627,10 +624,6 @@ static void get_final_status(grpc_call *call, static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, status_source source, grpc_error *error) { - const char *es = grpc_error_string(error); - gpr_log(GPR_DEBUG, "%p[%d]: set %d[is_set=%d] to %s", call, call->is_client, - source, call->status[source].is_set, es); - if (call->status[source].is_set) { GRPC_ERROR_UNREF(error); return; From 81a7937b4b5d1a0d3dd0114d9ff0442fdaf48210 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 14:56:25 -0800 Subject: [PATCH 140/261] Fixes --- src/core/ext/client_channel/subchannel.c | 5 ++--- src/core/lib/surface/channel.c | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 86a19d99ba7..f55fa60f913 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -620,9 +620,8 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx, grpc_error *error = grpc_channel_stack_builder_finish( exec_ctx, builder, 0, 1, connection_destroy, NULL, (void **)&con); if (error != GRPC_ERROR_NONE) { - const char *msg = grpc_error_string(error); - gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", msg); - grpc_error_free_string(msg); + gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", + grpc_error_string(error)); GRPC_ERROR_UNREF(error); abort(); /* TODO(ctiller): what to do here? */ } diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index f2708fdf430..1ef023ed628 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -102,9 +102,8 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, NULL, (void **)&channel); if (error != GRPC_ERROR_NONE) { - const char *msg = grpc_error_string(error); - gpr_log(GPR_ERROR, "channel stack builder failed: %s", msg); - grpc_error_free_string(msg); + gpr_log(GPR_ERROR, "channel stack builder failed: %s", + grpc_error_string(error)); GRPC_ERROR_UNREF(error); goto done; } From de2508b1da57a74f6304db5b40de8b6e79c5fc74 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 15:23:23 -0800 Subject: [PATCH 141/261] Fix merge errors --- src/core/lib/surface/call.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 4f53b694552..f5bac0779c8 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -833,22 +833,25 @@ static grpc_compression_algorithm decode_compression(grpc_mdelem md) { static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, grpc_metadata_batch *b) { - uint32_t status_code = decode_status(b->idx.named.grpc_status->md); - grpc_error *error = - status_code == GRPC_STATUS_OK - ? GRPC_ERROR_NONE - : grpc_error_set_int(GRPC_ERROR_CREATE("Error received from peer"), - GRPC_ERROR_INT_GRPC_STATUS, status_code); - - if (b->idx.named.grpc_message != NULL) { - char *msg = - grpc_slice_to_c_string(GRPC_MDVALUE(b->idx.named.grpc_message->md)); - error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(msg); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); - } - - set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); + if (b->idx.named.grpc_status != NULL) { + uint32_t status_code = decode_status(b->idx.named.grpc_status->md); + grpc_error *error = + status_code == GRPC_STATUS_OK + ? GRPC_ERROR_NONE + : grpc_error_set_int(GRPC_ERROR_CREATE("Error received from peer"), + GRPC_ERROR_INT_GRPC_STATUS, status_code); + + if (b->idx.named.grpc_message != NULL) { + char *msg = + grpc_slice_to_c_string(GRPC_MDVALUE(b->idx.named.grpc_message->md)); + error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); + gpr_free(msg); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); + } + + set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); + grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); + } } static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, @@ -1187,6 +1190,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, grpc_error *error) { if (error == GRPC_ERROR_NONE) return; + cancel_with_error(exec_ctx, bctl->call, GRPC_ERROR_REF(error)); int idx = (int)gpr_atm_no_barrier_fetch_add(&bctl->num_errors, 1); bctl->errors[idx] = error; } From f927ad152b23bc6b469140e92bb2f9cb56d5541f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 15:27:31 -0800 Subject: [PATCH 142/261] Fix merge errors --- src/core/lib/surface/call.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index f5bac0779c8..f53e940fde0 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -991,6 +991,9 @@ static void post_batch_completion(grpc_exec_ctx *exec_ctx, exec_ctx, &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); } + if (bctl->send_message) { + call->sending_message = false; + } if (bctl->send_final_op) { grpc_metadata_batch_destroy( exec_ctx, From fd9f53a20fc87d1ff70f38c850eb7f03296cfb60 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 6 Jan 2017 15:33:04 -0800 Subject: [PATCH 143/261] clang-format --- include/grpc/impl/codegen/slice.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 9c226f78c47..00781bb76bd 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -37,8 +37,8 @@ #include #include -#include #include +#include /* Slice API From 1c4775c3eec28484ce5e0bf86dcfb562d4276d78 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 16:07:45 -0800 Subject: [PATCH 144/261] Fix refcounting bug --- .../chttp2/transport/chttp2_transport.c | 17 +++++++++-------- src/core/lib/iomgr/error.c | 4 ++-- src/core/lib/iomgr/error.h | 2 +- src/core/lib/surface/call.c | 10 +++++++--- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 51191f338e3..84357b80753 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1015,7 +1015,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->cancel_error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(exec_ctx, t, s, GRPC_ERROR_REF(op->cancel_error)); + grpc_chttp2_cancel_stream(exec_ctx, t, s, op->cancel_error); } if (op->send_initial_metadata != NULL) { @@ -1066,8 +1066,9 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, s->send_initial_metadata = NULL; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_initial_metadata_finished, - GRPC_ERROR_CREATE( - "Attempt to send initial metadata after stream was closed"), + GRPC_ERROR_CREATE_REFERENCING( + "Attempt to send initial metadata after stream was closed", + &s->write_closed_error, 1), "send_initial_metadata_finished"); } } @@ -1562,11 +1563,6 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, if (close_reads && !s->read_closed) { s->read_closed_error = GRPC_ERROR_REF(error); s->read_closed = true; - for (int i = 0; i < 2; i++) { - if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) { - s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; - } - } closed_read = true; } if (close_writes && !s->write_closed) { @@ -1589,6 +1585,11 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, } } if (closed_read) { + for (int i = 0; i < 2; i++) { + if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) { + s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; + } + } decrement_active_streams_locked(exec_ctx, t, s); grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index ceff429fcc1..dbe5b139f91 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -170,7 +170,7 @@ bool grpc_error_is_special(grpc_error *err) { #ifdef GRPC_ERROR_REFCOUNT_DEBUG grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, const char *func) { - if (is_special(err)) return err; + if (grpc_error_is_special(err)) return err; gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, err->refs.count, err->refs.count + 1, file, line, func); gpr_ref(&err->refs); @@ -197,7 +197,7 @@ static void error_destroy(grpc_error *err) { #ifdef GRPC_ERROR_REFCOUNT_DEBUG void grpc_error_unref(grpc_error *err, const char *file, int line, const char *func) { - if (is_special(err)) return; + if (grpc_error_is_special(err)) return; gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, err->refs.count, err->refs.count - 1, file, line, func); if (gpr_unref(&err->refs)) { diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index ffacdac3934..23e85f20b3a 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -165,7 +165,7 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, #define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \ grpc_error_create(__FILE__, __LINE__, desc, errs, count) -//#define GRPC_ERROR_REFCOUNT_DEBUG +#define GRPC_ERROR_REFCOUNT_DEBUG #ifdef GRPC_ERROR_REFCOUNT_DEBUG grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, const char *func); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index f53e940fde0..fde34303882 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -536,7 +536,6 @@ static void done_termination(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { termination_closure *tc = tcp; GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "termination"); - GRPC_ERROR_UNREF(tc->error); gpr_free(tc); } @@ -966,9 +965,14 @@ static grpc_error *consolidate_batch_errors(batch_control *bctl) { if (n == 0) { return GRPC_ERROR_NONE; } else if (n == 1) { - return GRPC_ERROR_REF(bctl->errors[0]); + return bctl->errors[0]; } else { - return GRPC_ERROR_CREATE_REFERENCING("Call batch failed", bctl->errors, n); + grpc_error *error = + GRPC_ERROR_CREATE_REFERENCING("Call batch failed", bctl->errors, n); + for (size_t i = 0; i < n; i++) { + GRPC_ERROR_UNREF(bctl->errors[i]); + } + return error; } } From 707894a76d6cd928b61aa7cf76dce9b8244d0a70 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 6 Jan 2017 16:25:29 -0800 Subject: [PATCH 145/261] Fix bugs --- src/core/lib/transport/transport.c | 1 + test/core/end2end/fuzzers/client_fuzzer.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/lib/transport/transport.c b/src/core/lib/transport/transport.c index 4841dc3143b..0462d449f26 100644 --- a/src/core/lib/transport/transport.c +++ b/src/core/lib/transport/transport.c @@ -173,6 +173,7 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, grpc_closure_sched(exec_ctx, op->recv_initial_metadata_ready, GRPC_ERROR_REF(error)); grpc_closure_sched(exec_ctx, op->on_complete, error); + GRPC_ERROR_UNREF(op->cancel_error); } typedef struct { diff --git a/test/core/end2end/fuzzers/client_fuzzer.c b/test/core/end2end/fuzzers/client_fuzzer.c index 0972a4c8e7d..1fdc86356c6 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.c +++ b/test/core/end2end/fuzzers/client_fuzzer.c @@ -83,7 +83,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_metadata_array trailing_metadata_recv; grpc_metadata_array_init(&trailing_metadata_recv); grpc_status_code status; - grpc_slice details; + grpc_slice details = grpc_empty_slice(); grpc_op ops[6]; memset(ops, 0, sizeof(ops)); From c17ed124eca8fc6bed31c6e0d192fde386bdb3c2 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Mon, 9 Jan 2017 09:37:43 -0800 Subject: [PATCH 146/261] Ran generate-projects.sh --- tools/doxygen/Doxyfile.c++ | 32 ++++++++--------- tools/doxygen/Doxyfile.c++.internal | 32 ++++++++--------- tools/doxygen/Doxyfile.core | 32 ++++++++--------- tools/doxygen/Doxyfile.core.internal | 52 ++++++++++++++-------------- 4 files changed, 74 insertions(+), 74 deletions(-) diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 2cd59863b62..13f440441bc 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -850,31 +850,31 @@ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ doc/fail_fast.md \ +doc/g_stands_for.md \ +doc/wait-for-ready.md \ +doc/binary-logging.md \ doc/compression.md \ -doc/environment_variables.md \ -doc/stress_test_framework.md \ +doc/c-style-guide.md \ doc/PROTOCOL-WEB.md \ doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ +doc/server-reflection.md \ +doc/interop-test-descriptions.md \ +doc/PROTOCOL-HTTP2.md \ +doc/compression_cookbook.md \ +doc/connection-backoff.md \ doc/epoll-polling-engine.md \ -doc/naming.md \ -doc/binary-logging.md \ doc/connectivity-semantics-and-api.md \ -doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ doc/load-balancing.md \ +doc/environment_variables.md \ +doc/naming.md \ +doc/stress_test_framework.md \ +doc/http-grpc-status-mapping.md \ +doc/health-checking.md \ +doc/connection-backoff-interop-test-description.md \ doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ +doc/command_line_tool.md \ doc/statuscodes.md \ -doc/g_stands_for.md \ doc/cpp/perf_notes.md \ doc/cpp/pending_api_cleanups.md diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 6ab452eaba9..a86dfde1726 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -896,31 +896,31 @@ src/cpp/util/string_ref.cc \ src/cpp/util/time_cc.cc \ src/cpp/codegen/codegen_init.cc \ doc/fail_fast.md \ +doc/g_stands_for.md \ +doc/wait-for-ready.md \ +doc/binary-logging.md \ doc/compression.md \ -doc/environment_variables.md \ -doc/stress_test_framework.md \ +doc/c-style-guide.md \ doc/PROTOCOL-WEB.md \ doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ +doc/server-reflection.md \ +doc/interop-test-descriptions.md \ +doc/PROTOCOL-HTTP2.md \ +doc/compression_cookbook.md \ +doc/connection-backoff.md \ doc/epoll-polling-engine.md \ -doc/naming.md \ -doc/binary-logging.md \ doc/connectivity-semantics-and-api.md \ -doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ doc/load-balancing.md \ +doc/environment_variables.md \ +doc/naming.md \ +doc/stress_test_framework.md \ +doc/http-grpc-status-mapping.md \ +doc/health-checking.md \ +doc/connection-backoff-interop-test-description.md \ doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ +doc/command_line_tool.md \ doc/statuscodes.md \ -doc/g_stands_for.md \ doc/cpp/perf_notes.md \ doc/cpp/pending_api_cleanups.md \ src/cpp/README.md diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index 16f8dcc29e5..ec4d6813e83 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -829,31 +829,31 @@ include/grpc/impl/codegen/sync_generic.h \ include/grpc/impl/codegen/sync_posix.h \ include/grpc/impl/codegen/sync_windows.h \ doc/fail_fast.md \ +doc/g_stands_for.md \ +doc/wait-for-ready.md \ +doc/binary-logging.md \ doc/compression.md \ -doc/environment_variables.md \ -doc/stress_test_framework.md \ +doc/c-style-guide.md \ doc/PROTOCOL-WEB.md \ doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ +doc/server-reflection.md \ +doc/interop-test-descriptions.md \ +doc/PROTOCOL-HTTP2.md \ +doc/compression_cookbook.md \ +doc/connection-backoff.md \ doc/epoll-polling-engine.md \ -doc/naming.md \ -doc/binary-logging.md \ doc/connectivity-semantics-and-api.md \ -doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ doc/load-balancing.md \ +doc/environment_variables.md \ +doc/naming.md \ +doc/stress_test_framework.md \ +doc/http-grpc-status-mapping.md \ +doc/health-checking.md \ +doc/connection-backoff-interop-test-description.md \ doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ +doc/command_line_tool.md \ doc/statuscodes.md \ -doc/g_stands_for.md \ doc/core/pending_api_cleanups.md # This tag can be used to specify the character encoding of the source files diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index d9f69427b1b..34e5304ce4e 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1280,53 +1280,53 @@ src/core/lib/support/tmpfile_posix.c \ src/core/lib/support/tmpfile_windows.c \ src/core/lib/support/wrap_memcpy.c \ doc/fail_fast.md \ +doc/g_stands_for.md \ +doc/wait-for-ready.md \ +doc/binary-logging.md \ doc/compression.md \ -doc/environment_variables.md \ -doc/stress_test_framework.md \ +doc/c-style-guide.md \ doc/PROTOCOL-WEB.md \ doc/cpp-style-guide.md \ -doc/http-grpc-status-mapping.md \ -doc/wait-for-ready.md \ -doc/command_line_tool.md \ -doc/c-style-guide.md \ doc/server_reflection_tutorial.md \ -doc/health-checking.md \ -doc/connection-backoff-interop-test-description.md \ +doc/server-reflection.md \ +doc/interop-test-descriptions.md \ +doc/PROTOCOL-HTTP2.md \ +doc/compression_cookbook.md \ +doc/connection-backoff.md \ doc/epoll-polling-engine.md \ -doc/naming.md \ -doc/binary-logging.md \ doc/connectivity-semantics-and-api.md \ -doc/connection-backoff.md \ -doc/compression_cookbook.md \ -doc/PROTOCOL-HTTP2.md \ doc/load-balancing.md \ +doc/environment_variables.md \ +doc/naming.md \ +doc/stress_test_framework.md \ +doc/http-grpc-status-mapping.md \ +doc/health-checking.md \ +doc/connection-backoff-interop-test-description.md \ doc/negative-http2-interop-test-descriptions.md \ -doc/server-reflection.md \ -doc/interop-test-descriptions.md \ +doc/command_line_tool.md \ doc/statuscodes.md \ -doc/g_stands_for.md \ doc/core/pending_api_cleanups.md \ src/core/README.md \ src/core/ext/README.md \ +src/core/ext/resolver/README.md \ +src/core/ext/resolver/dns/native/README.md \ +src/core/ext/resolver/sockaddr/README.md \ +src/core/ext/client_channel/README.md \ src/core/ext/transport/README.md \ src/core/ext/transport/chttp2/README.md \ -src/core/ext/transport/chttp2/client/secure/README.md \ src/core/ext/transport/chttp2/client/insecure/README.md \ -src/core/ext/transport/chttp2/transport/README.md \ -src/core/ext/transport/chttp2/server/secure/README.md \ +src/core/ext/transport/chttp2/client/secure/README.md \ src/core/ext/transport/chttp2/server/insecure/README.md \ -src/core/ext/client_channel/README.md \ -src/core/ext/resolver/README.md \ -src/core/ext/resolver/sockaddr/README.md \ -src/core/ext/resolver/dns/native/README.md \ +src/core/ext/transport/chttp2/server/secure/README.md \ +src/core/ext/transport/chttp2/transport/README.md \ src/core/ext/census/README.md \ src/core/ext/census/gen/README.md \ src/core/lib/README.md \ +src/core/lib/iomgr/README.md \ src/core/lib/tsi/README.md \ -src/core/lib/channel/README.md \ +src/core/lib/surface/README.md \ src/core/lib/transport/README.md \ -src/core/lib/iomgr/README.md \ -src/core/lib/surface/README.md +src/core/lib/channel/README.md # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses From 065b139febfcdaf9d2cdca99f183edb423c35a5b Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 Jan 2017 14:05:07 -0800 Subject: [PATCH 147/261] Fixes --- .../chttp2/transport/chttp2_transport.c | 2 + src/core/lib/iomgr/error.h | 2 +- src/core/lib/surface/call.c | 39 +++++++++---------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 84357b80753..855e490bc58 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -2034,6 +2034,8 @@ static void incoming_byte_stream_publish_error( grpc_closure_sched(exec_ctx, bs->on_next, GRPC_ERROR_REF(error)); bs->on_next = NULL; GRPC_ERROR_UNREF(bs->error); + grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream, + GRPC_ERROR_REF(error)); bs->error = error; } diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index 23e85f20b3a..ffacdac3934 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -165,7 +165,7 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, #define GRPC_ERROR_CREATE_REFERENCING(desc, errs, count) \ grpc_error_create(__FILE__, __LINE__, desc, errs, count) -#define GRPC_ERROR_REFCOUNT_DEBUG +//#define GRPC_ERROR_REFCOUNT_DEBUG #ifdef GRPC_ERROR_REFCOUNT_DEBUG grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, const char *func); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index fde34303882..009e36fd874 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -1053,6 +1053,17 @@ static void post_batch_completion(grpc_exec_ctx *exec_ctx, } } +static void finish_batch_step(grpc_exec_ctx *exec_ctx, batch_control *bctl, + const char *but_why) { + gpr_log(GPR_DEBUG, + "finish_batch_step: call=%p bctl=%p why='%s' still_needed=%" PRIdPTR, + bctl->call, bctl, but_why, + gpr_atm_no_barrier_load(&bctl->steps_to_complete.count)); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } +} + static void continue_receiving_slices(grpc_exec_ctx *exec_ctx, batch_control *bctl) { grpc_call *call = bctl->call; @@ -1063,9 +1074,7 @@ static void continue_receiving_slices(grpc_exec_ctx *exec_ctx, call->receiving_message = 0; grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = NULL; - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } + finish_batch_step(exec_ctx, bctl, "continue_receiving_slices"); return; } if (grpc_byte_stream_next(exec_ctx, call->receiving_stream, @@ -1096,9 +1105,7 @@ static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, call->receiving_stream = NULL; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = NULL; - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } + finish_batch_step(exec_ctx, bctl, "receiving_slice_ready with error"); } } @@ -1108,9 +1115,7 @@ static void process_data_after_md(grpc_exec_ctx *exec_ctx, if (call->receiving_stream == NULL) { *call->receiving_buffer = NULL; call->receiving_message = 0; - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } + finish_batch_step(exec_ctx, bctl, "no message"); } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && @@ -1130,18 +1135,17 @@ static void receiving_stream_ready(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error) { batch_control *bctl = bctlp; grpc_call *call = bctl->call; + gpr_mu_lock(&bctl->call->mu); if (error != GRPC_ERROR_NONE) { cancel_with_error(exec_ctx, call, GRPC_ERROR_REF(error)); } - gpr_mu_lock(&bctl->call->mu); - if (bctl->call->has_initial_md_been_received || error != GRPC_ERROR_NONE || + if (call->has_initial_md_been_received || error != GRPC_ERROR_NONE || call->receiving_stream == NULL) { - gpr_mu_unlock(&bctl->call->mu); process_data_after_md(exec_ctx, bctlp); } else { call->saved_receiving_stream_ready_bctlp = bctlp; - gpr_mu_unlock(&bctl->call->mu); } + gpr_mu_unlock(&bctl->call->mu); } static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, @@ -1239,9 +1243,7 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, gpr_mu_unlock(&call->mu); - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } + finish_batch_step(exec_ctx, bctl, "receiving_initial_metadata_ready"); } static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, @@ -1249,10 +1251,7 @@ static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, batch_control *bctl = bctlp; add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); - - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } + finish_batch_step(exec_ctx, bctl, "finish_batch"); } static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, From 5cf481d2c90586626ba01d53d077608b77ccddc5 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 Jan 2017 14:50:27 -0800 Subject: [PATCH 148/261] Fix C++ build --- src/cpp/common/channel_filter.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 6f524daf15d..5f9fd8790b5 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -133,7 +133,7 @@ class TransportOp { grpc_error *disconnect_with_error() const { return op_->disconnect_with_error; } - bool send_goaway() const { return op_->send_goaway; } + bool send_goaway() const { return op_->goaway_error != GRPC_ERROR_NONE; } // TODO(roth): Add methods for additional fields as needed. From 737b625ad84e35cc947c80102d29d34e27250cf3 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 Jan 2017 15:25:15 -0800 Subject: [PATCH 149/261] Fixes for choosing errors --- .../chttp2/transport/chttp2_transport.c | 15 +++---- src/core/lib/surface/call.c | 39 ++++++++++++++----- 2 files changed, 38 insertions(+), 16 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 855e490bc58..a37b53e8cdf 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -889,12 +889,9 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, } static bool contains_non_ok_status(grpc_metadata_batch *batch) { - grpc_linked_mdelem *l; - for (l = batch->list.head; l; l = l->next) { - if (grpc_slice_eq(GRPC_MDKEY(l->md), GRPC_MDSTR_GRPC_STATUS) && - !grpc_mdelem_eq(l->md, GRPC_MDELEM_GRPC_STATUS_0)) { - return true; - } + if (batch->idx.named.grpc_status != NULL) { + return !grpc_mdelem_eq(batch->idx.named.grpc_status->md, + GRPC_MDELEM_GRPC_STATUS_0); } return false; } @@ -1078,9 +1075,13 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->fetching_send_message_finished = add_closure_barrier(op->on_complete); if (s->write_closed) { + gpr_log(GPR_DEBUG, "write_closed_error=%s", + grpc_error_string(s->write_closed_error)); grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->fetching_send_message_finished, - GRPC_ERROR_CREATE("Attempt to send message after stream was closed"), + GRPC_ERROR_CREATE_REFERENCING( + "Attempt to send message after stream was closed", + &s->write_closed_error, 1), "fetching_send_message_finished"); } else { GPR_ASSERT(s->fetching_send_message == NULL); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 0d63ef051af..830795fc785 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -595,25 +595,46 @@ static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, * FINAL STATUS CODE MANIPULATION */ +static void get_final_status_from(grpc_call *call, status_source from_source, + void (*set_value)(grpc_status_code code, + void *user_data), + void *set_value_user_data, + grpc_slice *details) { + grpc_status_code code; + const char *msg = NULL; + grpc_error_get_status(call->status[from_source].error, call->send_deadline, + &code, &msg, NULL); + + set_value(code, set_value_user_data); + if (details != NULL) { + *details = grpc_slice_from_copied_string(msg); + } +} + static void get_final_status(grpc_call *call, void (*set_value)(grpc_status_code code, void *user_data), void *set_value_user_data, grpc_slice *details) { int i; + /* search for the best status we can present: ideally the error we use has a + clearly defined grpc-status, and we'll prefer that. */ + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + if (call->status[i].is_set && + grpc_error_has_clear_grpc_status(call->status[i].error)) { + get_final_status_from(call, (status_source)i, set_value, + set_value_user_data, details); + return; + } + } + /* If no clearly defined status exists, search for 'anything' */ for (i = 0; i < STATUS_SOURCE_COUNT; i++) { if (call->status[i].is_set) { - grpc_status_code code; - const char *msg = NULL; - grpc_error_get_status(call->status[i].error, call->send_deadline, &code, - &msg, NULL); - - set_value(code, set_value_user_data); - if (details != NULL) { - *details = grpc_slice_from_copied_string(msg); - } + get_final_status_from(call, (status_source)i, set_value, + set_value_user_data, details); return; } } + /* If nothing exists, set some default */ if (call->is_client) { set_value(GRPC_STATUS_UNKNOWN, set_value_user_data); } else { From cae37f3bde6114d37d3b2277b27032bd145f81a9 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 Jan 2017 15:50:03 -0800 Subject: [PATCH 150/261] Add missing cast --- src/core/lib/surface/call.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 830795fc785..eef315bead6 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -859,7 +859,8 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, status_code == GRPC_STATUS_OK ? GRPC_ERROR_NONE : grpc_error_set_int(GRPC_ERROR_CREATE("Error received from peer"), - GRPC_ERROR_INT_GRPC_STATUS, status_code); + GRPC_ERROR_INT_GRPC_STATUS, + (intptr_t)status_code); if (b->idx.named.grpc_message != NULL) { char *msg = From 7ea1370a2106a08772f2209f1f3e776890825df1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 9 Jan 2017 16:11:32 -0800 Subject: [PATCH 151/261] Fix bad response test --- .../ext/transport/chttp2/transport/chttp2_transport.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index a37b53e8cdf..1e9f4f1656f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -404,7 +404,7 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, grpc_error_add_child(t->close_transport_on_writes_finished, error); return; } - if (!grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { + if (!grpc_error_has_clear_grpc_status(error)) { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); } @@ -1773,8 +1773,10 @@ static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx, if (parse_error == GRPC_ERROR_NONE && (parse_error = grpc_http_parser_eof(&parser)) == GRPC_ERROR_NONE) { error = grpc_error_set_int( - GRPC_ERROR_CREATE("Trying to connect an http1.x server"), - GRPC_ERROR_INT_HTTP_STATUS, response.status); + grpc_error_set_int( + GRPC_ERROR_CREATE("Trying to connect an http1.x server"), + GRPC_ERROR_INT_HTTP_STATUS, response.status), + GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); } GRPC_ERROR_UNREF(parse_error); From 871626ff160b6431c3b20ba906d80f4aa7edc0c1 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Mon, 9 Jan 2017 18:06:49 -0800 Subject: [PATCH 152/261] clang-format --- src/core/ext/transport/cronet/transport/cronet_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 099f50b4065..06c7e41dad7 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -1001,7 +1001,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, stream_state->rs.length_field_received = false; CRONET_LOG(GPR_DEBUG, "bidirectional_stream_read(%p)", s->cbs); bidirectional_stream_read(s->cbs, stream_state->rs.read_buffer, - stream_state->rs.remaining_bytes); + stream_state->rs.remaining_bytes); result = ACTION_TAKEN_NO_CALLBACK; } } else if (stream_op->recv_trailing_metadata && From a52032ed09924f4e939ee4b87ad4e39854fe7a59 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Tue, 10 Jan 2017 03:35:41 +0000 Subject: [PATCH 153/261] Build fix --- Makefile | 13 ++ .../generated/sources_and_headers.json | 23 +++- .../vcxproj/benchmark/benchmark.vcxproj | 48 ++++++- .../benchmark/benchmark.vcxproj.filters | 118 ++++++++++++++++++ 4 files changed, 200 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 6e690a46eb0..a26842e71b1 100644 --- a/Makefile +++ b/Makefile @@ -7017,6 +7017,19 @@ endif LIBBENCHMARK_SRC = \ + third_party/benchmark/src/benchmark.cc \ + third_party/benchmark/src/benchmark_register.cc \ + third_party/benchmark/src/colorprint.cc \ + third_party/benchmark/src/commandlineflags.cc \ + third_party/benchmark/src/complexity.cc \ + third_party/benchmark/src/console_reporter.cc \ + third_party/benchmark/src/csv_reporter.cc \ + third_party/benchmark/src/json_reporter.cc \ + third_party/benchmark/src/reporter.cc \ + third_party/benchmark/src/sleep.cc \ + third_party/benchmark/src/string_util.cc \ + third_party/benchmark/src/sysinfo.cc \ + third_party/benchmark/src/timers.cc \ PUBLIC_HEADERS_CXX += \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index bd5b76ec1da..e80937be17f 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6206,7 +6206,28 @@ }, { "deps": [], - "headers": [], + "headers": [ + "third_party/benchmark/include/benchmark/benchmark.h", + "third_party/benchmark/include/benchmark/benchmark_api.h", + "third_party/benchmark/include/benchmark/macros.h", + "third_party/benchmark/include/benchmark/reporter.h", + "third_party/benchmark/src/arraysize.h", + "third_party/benchmark/src/benchmark_api_internal.h", + "third_party/benchmark/src/check.h", + "third_party/benchmark/src/colorprint.h", + "third_party/benchmark/src/commandlineflags.h", + "third_party/benchmark/src/complexity.h", + "third_party/benchmark/src/cycleclock.h", + "third_party/benchmark/src/internal_macros.h", + "third_party/benchmark/src/log.h", + "third_party/benchmark/src/mutex.h", + "third_party/benchmark/src/re.h", + "third_party/benchmark/src/sleep.h", + "third_party/benchmark/src/stat.h", + "third_party/benchmark/src/string_util.h", + "third_party/benchmark/src/sysinfo.h", + "third_party/benchmark/src/timers.h" + ], "is_filegroup": false, "language": "c++", "name": "benchmark", diff --git a/vsprojects/vcxproj/benchmark/benchmark.vcxproj b/vsprojects/vcxproj/benchmark/benchmark.vcxproj index 811317595f4..9f262b3b00c 100644 --- a/vsprojects/vcxproj/benchmark/benchmark.vcxproj +++ b/vsprojects/vcxproj/benchmark/benchmark.vcxproj @@ -147,7 +147,53 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vsprojects/vcxproj/benchmark/benchmark.vcxproj.filters b/vsprojects/vcxproj/benchmark/benchmark.vcxproj.filters index 00e4276f1d4..ccc9ca2cae7 100644 --- a/vsprojects/vcxproj/benchmark/benchmark.vcxproj.filters +++ b/vsprojects/vcxproj/benchmark/benchmark.vcxproj.filters @@ -1,7 +1,125 @@ + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + + + third_party\benchmark\include\benchmark + + + third_party\benchmark\include\benchmark + + + third_party\benchmark\include\benchmark + + + third_party\benchmark\include\benchmark + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + third_party\benchmark\src + + + + {7b593518-9fee-107e-6b64-24bdce73f939} + + + {f0d35de1-6b41-778d-0ba0-faad514fb0f4} + + + {cbc02dfa-face-8cc6-0efb-efacc0c3369c} + + + {4f2f03fc-b82d-df33-63ee-bedebeb2c0ee} + + + {f42a8e0a-5a76-0e6f-d708-f0306858f673} + From 8f24d6a8d21dd05dd3fd4d90acabfaab38e65cbc Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 06:36:46 -0800 Subject: [PATCH 154/261] Fix async_end2end_test --- src/core/lib/surface/call.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index eef315bead6..9c9ac46bedf 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -607,7 +607,8 @@ static void get_final_status_from(grpc_call *call, status_source from_source, set_value(code, set_value_user_data); if (details != NULL) { - *details = grpc_slice_from_copied_string(msg); + *details = + msg == NULL ? grpc_empty_slice() : grpc_slice_from_copied_string(msg); } } @@ -868,6 +869,8 @@ static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); gpr_free(msg); grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); + } else { + error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, ""); } set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); From 2e900b1fe36d9b2693400b26fafd0891c9de3f00 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 06:48:34 -0800 Subject: [PATCH 155/261] Fix large metadata test - it was previously overconstrained now that we return better status --- test/core/bad_client/tests/large_metadata.c | 41 ++++++++++----------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index 2a0a56950ba..f672776a9fb 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -188,29 +188,26 @@ static void client_validator(grpc_slice_buffer *incoming) { grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); GPR_ASSERT(last_frame_buffer.count == 1); grpc_slice last_frame = last_frame_buffer.slices[0]; - // Construct expected frame. - grpc_slice expected = grpc_slice_malloc(13); - uint8_t *p = GRPC_SLICE_START_PTR(expected); - // Length. - *p++ = 0; - *p++ = 0; - *p++ = 4; - // Frame type (RST_STREAM). - *p++ = 3; - // Flags. - *p++ = 0; + const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); + // Length = 4 + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 4); + // Frame type (RST_STREAM) + GPR_ASSERT(*p++ == 3); + // Flags + GPR_ASSERT(*p++ == 0); // Stream ID. - *p++ = 0; - *p++ = 0; - *p++ = 0; - *p++ = 1; - // Payload (error code). - *p++ = 0; - *p++ = 0; - *p++ = 0; - *p++ = 11; - // Compare actual and expected. - GPR_ASSERT(grpc_slice_eq(last_frame, expected)); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 1); + // Payload (error code) + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p++ == 0); + GPR_ASSERT(*p == 0 || *p == 11); + grpc_slice_buffer_destroy(&last_frame_buffer); } From f2b5b7ede79093e8058b6a9f0d19bd4331b95d8d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 08:28:59 -0800 Subject: [PATCH 156/261] Better error messages for bad metadata --- src/core/lib/surface/call.c | 14 ++++---- src/core/lib/surface/validate_metadata.c | 41 ++++++++++++++++++++---- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 9c9ac46bedf..1425913f5a4 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -56,6 +56,7 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/completion_queue.h" +#include "src/core/lib/surface/validate_metadata.h" #include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/static_metadata.h" @@ -768,16 +769,13 @@ static int prepare_application_metadata( get_md_elem(metadata, additional_metadata, i, count); grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); - if (!grpc_header_key_is_legal(md->key)) { - char *str = grpc_slice_to_c_string(md->key); - gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); - gpr_free(str); + if (!GRPC_LOG_IF_ERROR("validate_metadata", + grpc_validate_header_key_is_legal(md->key))) { break; } else if (!grpc_is_binary_header(md->key) && - !grpc_header_nonbin_value_is_legal(md->value)) { - char *str = grpc_dump_slice(md->value, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); - gpr_free(str); + !GRPC_LOG_IF_ERROR( + "validate_metadata", + grpc_validate_header_nonbin_value_is_legal(md->value))) { break; } l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata *)md); diff --git a/src/core/lib/surface/validate_metadata.c b/src/core/lib/surface/validate_metadata.c index 4201192e7aa..8c11345c658 100644 --- a/src/core/lib/surface/validate_metadata.c +++ b/src/core/lib/surface/validate_metadata.c @@ -35,21 +35,40 @@ #include #include +#include #include -static int conforms_to(grpc_slice slice, const uint8_t *legal_bits) { +#include "src/core/lib/iomgr/error.h" +#include "src/core/lib/slice/slice_string_helpers.h" + +static grpc_error *conforms_to(grpc_slice slice, const uint8_t *legal_bits, + const char *err_desc) { const uint8_t *p = GRPC_SLICE_START_PTR(slice); const uint8_t *e = GRPC_SLICE_END_PTR(slice); for (; p != e; p++) { int idx = *p; int byte = idx / 8; int bit = idx % 8; - if ((legal_bits[byte] & (1 << bit)) == 0) return 0; + if ((legal_bits[byte] & (1 << bit)) == 0) { + char *dump = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); + grpc_error *error = grpc_error_set_str( + grpc_error_set_int(GRPC_ERROR_CREATE(err_desc), GRPC_ERROR_INT_OFFSET, + p - GRPC_SLICE_START_PTR(slice)), + GRPC_ERROR_STR_RAW_BYTES, dump); + gpr_free(dump); + return error; + } } - return 1; + return GRPC_ERROR_NONE; } -int grpc_header_key_is_legal(grpc_slice slice) { +static int error2int(grpc_error *error) { + int r = (error == GRPC_ERROR_NONE); + GRPC_ERROR_UNREF(error); + return r; +} + +grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -57,15 +76,23 @@ int grpc_header_key_is_legal(grpc_slice slice) { if (GRPC_SLICE_LENGTH(slice) == 0 || GRPC_SLICE_START_PTR(slice)[0] == ':') { return 0; } - return conforms_to(slice, legal_header_bits); + return conforms_to(slice, legal_header_bits, "Illegal header key"); } -int grpc_header_nonbin_value_is_legal(grpc_slice slice) { +int grpc_header_key_is_legal(grpc_slice slice) { + return error2int(grpc_validate_header_key_is_legal(slice)); +} + +grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - return conforms_to(slice, legal_header_bits); + return conforms_to(slice, legal_header_bits, "Illegal header value"); +} + +int grpc_header_nonbin_value_is_legal(grpc_slice slice) { + return error2int(grpc_validate_header_nonbin_value_is_legal(slice)); } int grpc_is_binary_header(grpc_slice slice) { From 446d18ff3863ffb419575a7c1ff99c49fa361aaa Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 08:46:04 -0800 Subject: [PATCH 157/261] Fix build --- src/core/lib/surface/validate_metadata.h | 43 ++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/core/lib/surface/validate_metadata.h diff --git a/src/core/lib/surface/validate_metadata.h b/src/core/lib/surface/validate_metadata.h new file mode 100644 index 00000000000..2b800d25a43 --- /dev/null +++ b/src/core/lib/surface/validate_metadata.h @@ -0,0 +1,43 @@ +/* + * + * Copyright 2017, 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_SURFACE_VALIDATE_METADATA_H +#define GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H + +#include +#include "src/core/lib/iomgr/error.h" + +grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice); +grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice); + +#endif /* GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H */ From 2d9f8e8179b661d0d81bb592f4520d712d021296 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 08:48:48 -0800 Subject: [PATCH 158/261] Fix build --- BUILD | 1 + build.yaml | 1 + gRPC-Core.podspec | 2 ++ grpc.gemspec | 1 + package.xml | 1 + tools/doxygen/Doxyfile.core.internal | 1 + tools/run_tests/generated/sources_and_headers.json | 2 ++ vsprojects/vcxproj/grpc/grpc.vcxproj | 1 + vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 3 +++ vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj | 1 + .../vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters | 3 +++ vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj | 1 + vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters | 3 +++ 13 files changed, 21 insertions(+) diff --git a/BUILD b/BUILD index 75ce780d161..0cac6164e18 100644 --- a/BUILD +++ b/BUILD @@ -622,6 +622,7 @@ grpc_cc_library( "src/core/lib/surface/completion_queue.h", "src/core/lib/surface/event_string.h", "src/core/lib/surface/init.h", + "src/core/lib/surface/validate_metadata.h", "src/core/lib/surface/lame_client.h", "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", diff --git a/build.yaml b/build.yaml index 94cb53fcfa8..27dc48bd2b0 100644 --- a/build.yaml +++ b/build.yaml @@ -254,6 +254,7 @@ filegroups: - src/core/lib/surface/init.h - src/core/lib/surface/lame_client.h - src/core/lib/surface/server.h + - src/core/lib/surface/validate_metadata.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h - src/core/lib/transport/error_utils.h diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index 718ca095a28..e1da95ca80e 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -339,6 +339,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', + 'src/core/lib/surface/validate_metadata.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', 'src/core/lib/transport/error_utils.h', @@ -755,6 +756,7 @@ Pod::Spec.new do |s| 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', + 'src/core/lib/surface/validate_metadata.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', 'src/core/lib/transport/error_utils.h', diff --git a/grpc.gemspec b/grpc.gemspec index 2fcc18f119f..bbef356b642 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -256,6 +256,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/init.h ) s.files += %w( src/core/lib/surface/lame_client.h ) s.files += %w( src/core/lib/surface/server.h ) + s.files += %w( src/core/lib/surface/validate_metadata.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) s.files += %w( src/core/lib/transport/error_utils.h ) diff --git a/package.xml b/package.xml index 778178380ba..a22ba085f3a 100644 --- a/package.xml +++ b/package.xml @@ -264,6 +264,7 @@ + diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 9b21689bb1a..0da94babba0 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -880,6 +880,7 @@ src/core/lib/surface/event_string.h \ src/core/lib/surface/init.h \ src/core/lib/surface/lame_client.h \ src/core/lib/surface/server.h \ +src/core/lib/surface/validate_metadata.h \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.h \ src/core/lib/transport/error_utils.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 54029b0f76b..90d6a0f0ee9 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -6764,6 +6764,7 @@ "src/core/lib/surface/init.h", "src/core/lib/surface/lame_client.h", "src/core/lib/surface/server.h", + "src/core/lib/surface/validate_metadata.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", "src/core/lib/transport/error_utils.h", @@ -6986,6 +6987,7 @@ "src/core/lib/surface/server.c", "src/core/lib/surface/server.h", "src/core/lib/surface/validate_metadata.c", + "src/core/lib/surface/validate_metadata.h", "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/byte_stream.h", diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index b1841072085..25e9d755cae 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -389,6 +389,7 @@ + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 96c9364263e..da9a08cf511 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -1022,6 +1022,9 @@ src\core\lib\surface + + src\core\lib\surface + 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 72536a62165..a5baf795cef 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -282,6 +282,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 7deb60e8bca..8b3b6698fe9 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -815,6 +815,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\transport diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj index 72238af255e..1a6933ed692 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -379,6 +379,7 @@ + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 405c7ea9911..42cd041a9c3 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -935,6 +935,9 @@ src\core\lib\surface + + src\core\lib\surface + src\core\lib\transport From 296c7bb8fa9711f580a01a7d61482f8240cba55d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 15:34:02 -0800 Subject: [PATCH 159/261] Fix metadata validation --- src/core/lib/surface/validate_metadata.c | 7 +++++-- test/core/end2end/invalid_call_argument_test.c | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/lib/surface/validate_metadata.c b/src/core/lib/surface/validate_metadata.c index 8c11345c658..7ec9137265d 100644 --- a/src/core/lib/surface/validate_metadata.c +++ b/src/core/lib/surface/validate_metadata.c @@ -73,8 +73,11 @@ grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (GRPC_SLICE_LENGTH(slice) == 0 || GRPC_SLICE_START_PTR(slice)[0] == ':') { - return 0; + if (GRPC_SLICE_LENGTH(slice) == 0) { + return GRPC_ERROR_CREATE("Metadata keys cannot be zero length"); + } + if (GRPC_SLICE_START_PTR(slice)[0] == ':') { + return GRPC_ERROR_CREATE("Metadata keys cannot start with :"); } return conforms_to(slice, legal_header_bits, "Illegal header key"); } diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index 9067b24168c..a9d0287952e 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -597,6 +597,7 @@ static void test_invalid_initial_metadata_reserved_key() { int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); + test_invalid_initial_metadata_reserved_key(); test_non_null_reserved_on_start_batch(); test_non_null_reserved_on_op(); test_send_initial_metadata_more_than_once(); @@ -616,7 +617,6 @@ int main(int argc, char **argv) { test_send_server_status_twice(); test_recv_close_on_server_with_invalid_flags(); test_recv_close_on_server_twice(); - test_invalid_initial_metadata_reserved_key(); grpc_shutdown(); return 0; From f3ed2bf8ca73d7abece4060497d0e1e72ab6ff16 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 17:01:26 -0800 Subject: [PATCH 160/261] Fix interop --- test/cpp/interop/client.cc | 180 +++++++++++------------------ test/cpp/interop/interop_client.cc | 9 +- test/cpp/interop/interop_client.h | 1 + test/cpp/interop/interop_server.cc | 2 +- 4 files changed, 78 insertions(+), 114 deletions(-) diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index c58910abc3f..bd4c5e2635d 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -32,6 +32,7 @@ */ #include +#include #include @@ -107,119 +108,78 @@ int main(int argc, char** argv) { grpc::testing::InteropClient client(CreateChannelForTestCase(FLAGS_test_case), true, FLAGS_do_not_abort_on_transient_failures); - if (FLAGS_test_case == "empty_unary") { - client.DoEmpty(); - } else if (FLAGS_test_case == "large_unary") { - client.DoLargeUnary(); - } else if (FLAGS_test_case == "server_compressed_unary") { - client.DoServerCompressedUnary(); - } else if (FLAGS_test_case == "client_compressed_unary") { - client.DoClientCompressedUnary(); - } else if (FLAGS_test_case == "client_streaming") { - client.DoRequestStreaming(); - } else if (FLAGS_test_case == "server_streaming") { - client.DoResponseStreaming(); - } else if (FLAGS_test_case == "server_compressed_streaming") { - client.DoServerCompressedStreaming(); - } else if (FLAGS_test_case == "client_compressed_streaming") { - client.DoClientCompressedStreaming(); - } else if (FLAGS_test_case == "slow_consumer") { - client.DoResponseStreamingWithSlowConsumer(); - } else if (FLAGS_test_case == "half_duplex") { - client.DoHalfDuplex(); - } else if (FLAGS_test_case == "ping_pong") { - client.DoPingPong(); - } else if (FLAGS_test_case == "cancel_after_begin") { - client.DoCancelAfterBegin(); - } else if (FLAGS_test_case == "cancel_after_first_response") { - client.DoCancelAfterFirstResponse(); - } else if (FLAGS_test_case == "timeout_on_sleeping_server") { - client.DoTimeoutOnSleepingServer(); - } else if (FLAGS_test_case == "empty_stream") { - client.DoEmptyStream(); - } else if (FLAGS_test_case == "compute_engine_creds") { - client.DoComputeEngineCreds(FLAGS_default_service_account, - FLAGS_oauth_scope); - } else if (FLAGS_test_case == "jwt_token_creds") { - grpc::string json_key = GetServiceAccountJsonKey(); - client.DoJwtTokenCreds(json_key); - } else if (FLAGS_test_case == "oauth2_auth_token") { - client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope); - } else if (FLAGS_test_case == "per_rpc_creds") { - grpc::string json_key = GetServiceAccountJsonKey(); - client.DoPerRpcCreds(json_key); - } else if (FLAGS_test_case == "status_code_and_message") { - client.DoStatusWithMessage(); - } else if (FLAGS_test_case == "custom_metadata") { - client.DoCustomMetadata(); - } else if (FLAGS_test_case == "unimplemented_method") { - client.DoUnimplementedMethod(); - } else if (FLAGS_test_case == "unimplemented_service") { - client.DoUnimplementedService(); - } else if (FLAGS_test_case == "cacheable_unary") { - client.DoCacheableUnary(); - } else if (FLAGS_test_case == "all") { - client.DoEmpty(); - client.DoLargeUnary(); - client.DoClientCompressedUnary(); - client.DoServerCompressedUnary(); - client.DoRequestStreaming(); - client.DoResponseStreaming(); - client.DoClientCompressedStreaming(); - client.DoServerCompressedStreaming(); - client.DoHalfDuplex(); - client.DoPingPong(); - client.DoCancelAfterBegin(); - client.DoCancelAfterFirstResponse(); - client.DoTimeoutOnSleepingServer(); - client.DoEmptyStream(); - client.DoStatusWithMessage(); - client.DoCustomMetadata(); - client.DoUnimplementedMethod(); - client.DoUnimplementedService(); - client.DoCacheableUnary(); - // service_account_creds and jwt_token_creds can only run with ssl. - if (FLAGS_use_tls) { - grpc::string json_key = GetServiceAccountJsonKey(); - client.DoJwtTokenCreds(json_key); - client.DoOauth2AuthToken(FLAGS_default_service_account, - FLAGS_oauth_scope); - client.DoPerRpcCreds(json_key); + + std::unordered_map> actions; + actions["empty_unary"] = + std::bind(&grpc::testing::InteropClient::DoEmpty, &client); + actions["large_unary"] = + std::bind(&grpc::testing::InteropClient::DoLargeUnary, &client); + actions["server_compressed_unary"] = std::bind( + &grpc::testing::InteropClient::DoServerCompressedUnary, &client); + actions["client_compressed_unary"] = std::bind( + &grpc::testing::InteropClient::DoClientCompressedUnary, &client); + actions["client_streaming"] = + std::bind(&grpc::testing::InteropClient::DoRequestStreaming, &client); + actions["server_streaming"] = + std::bind(&grpc::testing::InteropClient::DoResponseStreaming, &client); + actions["server_compressed_streaming"] = std::bind( + &grpc::testing::InteropClient::DoServerCompressedStreaming, &client); + actions["client_compressed_streaming"] = std::bind( + &grpc::testing::InteropClient::DoClientCompressedStreaming, &client); + actions["slow_consumer"] = std::bind( + &grpc::testing::InteropClient::DoResponseStreamingWithSlowConsumer, + &client); + actions["half_duplex"] = + std::bind(&grpc::testing::InteropClient::DoHalfDuplex, &client); + actions["ping_pong"] = + std::bind(&grpc::testing::InteropClient::DoPingPong, &client); + actions["cancel_after_begin"] = + std::bind(&grpc::testing::InteropClient::DoCancelAfterBegin, &client); + actions["cancel_after_first_response"] = std::bind( + &grpc::testing::InteropClient::DoCancelAfterFirstResponse, &client); + actions["timeout_on_sleeping_server"] = std::bind( + &grpc::testing::InteropClient::DoTimeoutOnSleepingServer, &client); + actions["empty_stream"] = + std::bind(&grpc::testing::InteropClient::DoEmptyStream, &client); + if (FLAGS_use_tls) { + actions["compute_engine_creds"] = + std::bind(&grpc::testing::InteropClient::DoComputeEngineCreds, &client, + FLAGS_default_service_account, FLAGS_oauth_scope); + actions["jwt_token_creds"] = + std::bind(&grpc::testing::InteropClient::DoJwtTokenCreds, &client, + GetServiceAccountJsonKey()); + actions["oauth2_auth_token"] = + std::bind(&grpc::testing::InteropClient::DoOauth2AuthToken, &client, + FLAGS_default_service_account, FLAGS_oauth_scope); + actions["per_rpc_creds"] = + std::bind(&grpc::testing::InteropClient::DoPerRpcCreds, &client, + GetServiceAccountJsonKey()); + } + actions["status_code_and_message"] = + std::bind(&grpc::testing::InteropClient::DoStatusWithMessage, &client); + actions["custom_metadata"] = + std::bind(&grpc::testing::InteropClient::DoCustomMetadata, &client); + actions["unimplemented_method"] = + std::bind(&grpc::testing::InteropClient::DoUnimplementedMethod, &client); + actions["unimplemented_service"] = + std::bind(&grpc::testing::InteropClient::DoUnimplementedService, &client); + // actions["cacheable_unary"] = + // std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); + + if (FLAGS_test_case == "all") { + for (const auto& action : actions) { + action.second(); } - // compute_engine_creds only runs in GCE. + } else if (actions.find(FLAGS_test_case) != actions.end()) { + actions.find(FLAGS_test_case)->second(); } else { - const char* testcases[] = {"all", - "cacheable_unary", - "cancel_after_begin", - "cancel_after_first_response", - "client_compressed_streaming", - "client_compressed_unary", - "client_streaming", - "compute_engine_creds", - "custom_metadata", - "empty_stream", - "empty_unary", - "half_duplex", - "jwt_token_creds", - "large_unary", - "oauth2_auth_token", - "oauth2_auth_token", - "per_rpc_creds", - "per_rpc_creds", - "ping_pong", - "server_compressed_streaming", - "server_compressed_unary", - "server_streaming", - "status_code_and_message", - "timeout_on_sleeping_server", - "unimplemented_method", - "unimplemented_service"}; - char* joined_testcases = - gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL); - + grpc::string test_cases; + for (const auto& action : actions) { + if (!test_cases.empty()) test_cases += "\n"; + test_cases += action.first; + } gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - FLAGS_test_case.c_str(), joined_testcases); - gpr_free(joined_testcases); + FLAGS_test_case.c_str(), test_cases.c_str()); ret = 1; } diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index d1242627ef3..aa34d94f61f 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -109,7 +109,10 @@ TestService::Stub* InteropClient::ServiceStub::Get() { UnimplementedService::Stub* InteropClient::ServiceStub::GetUnimplementedServiceStub() { - return UnimplementedService::NewStub(channel_).get(); + if (unimplemented_service_stub_ == nullptr) { + unimplemented_service_stub_ = UnimplementedService::NewStub(channel_); + } + return unimplemented_service_stub_.get(); } void InteropClient::ServiceStub::Reset(std::shared_ptr channel) { @@ -943,7 +946,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second.data() == kInitialMetadataValue); + GPR_ASSERT(iter->second == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); @@ -994,7 +997,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second.data() == kInitialMetadataValue); + GPR_ASSERT(iter->second == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 7ec7ebee209..74f4db6b789 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -107,6 +107,7 @@ class InteropClient { private: std::unique_ptr stub_; + std::unique_ptr unimplemented_service_stub_; std::shared_ptr channel_; bool new_stub_every_call_; // If true, a new stub is returned by every // Get() call diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 67456ce18bb..ecf4d74f876 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -90,7 +90,7 @@ void MaybeEchoMetadata(ServerContext* context) { auto iter = client_metadata.find(kEchoInitialMetadataKey); if (iter != client_metadata.end()) { - context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data()); + context->AddInitialMetadata(kEchoInitialMetadataKey, grpc::string(iter->second.begin(), iter->second.end())); } iter = client_metadata.find(kEchoTrailingBinMetadataKey); if (iter != client_metadata.end()) { From e4fae4ef9f6c6f8b11cac0a263bf3ccb325613de Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 10 Jan 2017 17:01:51 -0800 Subject: [PATCH 161/261] clang-format --- test/cpp/interop/interop_server.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index ecf4d74f876..ab9a5d9b2f3 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -90,7 +90,9 @@ void MaybeEchoMetadata(ServerContext* context) { auto iter = client_metadata.find(kEchoInitialMetadataKey); if (iter != client_metadata.end()) { - context->AddInitialMetadata(kEchoInitialMetadataKey, grpc::string(iter->second.begin(), iter->second.end())); + context->AddInitialMetadata( + kEchoInitialMetadataKey, + grpc::string(iter->second.begin(), iter->second.end())); } iter = client_metadata.find(kEchoTrailingBinMetadataKey); if (iter != client_metadata.end()) { From 0029802be49f9ce4c4fac0a724f006497f2a4e21 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 11 Jan 2017 01:49:02 -0800 Subject: [PATCH 162/261] bug fix --- .../ext/transport/cronet/transport/cronet_transport.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 296c4063249..00eefa28403 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -855,11 +855,11 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_INITIAL_METADATA", oas); if (stream_state->state_op_done[OP_CANCEL_ERROR]) { grpc_closure_sched(exec_ctx, stream_op->recv_initial_metadata_ready, - GRPC_ERROR_CANCELLED); + GRPC_ERROR_NONE); } else if (stream_state->state_callback_received[OP_FAILED]) { grpc_closure_sched( exec_ctx, stream_op->recv_initial_metadata_ready, - make_error_with_desc(GRPC_STATUS_UNAVAILABLE, "Unavailable.")); + GRPC_ERROR_NONE); } else { grpc_chttp2_incoming_metadata_buffer_publish( &oas->s->state.rs.initial_metadata, stream_op->recv_initial_metadata); @@ -916,14 +916,14 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, if (stream_state->state_op_done[OP_CANCEL_ERROR]) { CRONET_LOG(GPR_DEBUG, "Stream is cancelled."); grpc_closure_sched(exec_ctx, stream_op->recv_message_ready, - GRPC_ERROR_CANCELLED); + GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->state_callback_received[OP_FAILED]) { CRONET_LOG(GPR_DEBUG, "Stream failed."); grpc_closure_sched( exec_ctx, stream_op->recv_message_ready, - make_error_with_desc(GRPC_STATUS_UNAVAILABLE, "Unavailable.")); + GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->rs.read_stream_closed == true) { From defc58bbc41aba50937c30dd040aae1058c48525 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 11 Jan 2017 01:50:12 -0800 Subject: [PATCH 163/261] test fix --- .../tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m index 4ba7badd866..e885011d044 100644 --- a/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m +++ b/src/objective-c/tests/CoreCronetEnd2EndTests/CoreCronetEnd2EndTests.m @@ -124,11 +124,12 @@ static void chttp2_tear_down_secure_fullstack(grpc_end2end_test_fixture *f) { static void cronet_init_client_simple_ssl_secure_fullstack( grpc_end2end_test_fixture *f, grpc_channel_args *client_args) { + grpc_exec_ctx ctx = GRPC_EXEC_CTX_INIT; cronet_engine *cronetEngine = [Cronet getGlobalEngine]; grpc_channel_args *new_client_args = grpc_channel_args_copy(client_args); cronet_init_client_secure_fullstack(f, new_client_args, cronetEngine); - grpc_channel_args_destroy(new_client_args); + grpc_channel_args_destroy(&ctx, new_client_args); } static int fail_server_auth_check(grpc_channel_args *server_args) { From a6e796f58f691ae130fe6e3b8ed746d67e189d79 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 11 Jan 2017 13:49:43 -0800 Subject: [PATCH 164/261] ignore core counts and core lists in qps json driver --- test/cpp/qps/driver.cc | 91 +------------------ test/cpp/qps/driver.h | 3 +- test/cpp/qps/qps_json_driver.cc | 5 +- .../run_tests/performance/scenario_config.py | 24 +++-- 4 files changed, 18 insertions(+), 105 deletions(-) diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 93ef32db770..42722b7e9d1 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -76,30 +76,6 @@ static std::string get_host(const std::string& worker) { return s; } -static std::unordered_map> get_hosts_and_cores( - const deque& workers) { - std::unordered_map> hosts; - for (auto it = workers.begin(); it != workers.end(); it++) { - const string host = get_host(*it); - if (hosts.find(host) == hosts.end()) { - auto stub = WorkerService::NewStub( - CreateChannel(*it, InsecureChannelCredentials())); - grpc::ClientContext ctx; - ctx.set_wait_for_ready(true); - CoreRequest dummy; - CoreResponse cores; - grpc::Status s = stub->CoreCount(&ctx, dummy, &cores); - GPR_ASSERT(s.ok()); - std::deque dq; - for (int i = 0; i < cores.cores(); i++) { - dq.push_back(i); - } - hosts[host] = dq; - } - } - return hosts; -} - static deque get_workers(const string& env_name) { char* env = gpr_getenv(env_name.c_str()); if (!env) { @@ -210,7 +186,7 @@ std::unique_ptr RunScenario( const ClientConfig& initial_client_config, size_t num_clients, const ServerConfig& initial_server_config, size_t num_servers, int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count, - const char* qps_server_target_override, bool configure_core_lists) { + const char* qps_server_target_override) { // Log everything from the driver gpr_set_log_verbosity(GPR_LOG_SEVERITY_DEBUG); @@ -279,9 +255,6 @@ std::unique_ptr RunScenario( std::vector servers(num_servers); std::unordered_map> hosts_cores; - if (configure_core_lists) { - hosts_cores = get_hosts_and_cores(workers); - } for (size_t i = 0; i < num_servers; i++) { gpr_log(GPR_INFO, "Starting server on %s (worker #%" PRIuPTR ")", workers[i].c_str(), i); @@ -289,37 +262,8 @@ std::unique_ptr RunScenario( CreateChannel(workers[i], InsecureChannelCredentials())); ServerConfig server_config = initial_server_config; - int server_core_limit = initial_server_config.core_limit(); - int client_core_limit = initial_client_config.core_limit(); - - if (configure_core_lists) { - string host_str(get_host(workers[i])); - if (server_core_limit == 0 && client_core_limit > 0) { - // In this case, limit the server cores if it matches the - // same host as one or more clients - const auto& dq = hosts_cores.at(host_str); - bool match = false; - int limit = dq.size(); - for (size_t cli = 0; cli < num_clients; cli++) { - if (host_str == get_host(workers[cli + num_servers])) { - limit -= client_core_limit; - match = true; - } - } - if (match) { - GPR_ASSERT(limit > 0); - server_core_limit = limit; - } - } - if (server_core_limit > 0) { - auto& dq = hosts_cores.at(host_str); - GPR_ASSERT(dq.size() >= static_cast(server_core_limit)); - gpr_log(GPR_INFO, "Setting server core_list"); - for (int core = 0; core < server_core_limit; core++) { - server_config.add_core_list(dq.front()); - dq.pop_front(); - } - } + if(server_config.core_limit() != 0) { + gpr_log(GPR_WARN, "server config core limit is set but ignored by driver"); } ServerArgs args; @@ -364,33 +308,8 @@ std::unique_ptr RunScenario( CreateChannel(worker, InsecureChannelCredentials())); ClientConfig per_client_config = client_config; - int server_core_limit = initial_server_config.core_limit(); - int client_core_limit = initial_client_config.core_limit(); - if (configure_core_lists && - ((server_core_limit > 0) || (client_core_limit > 0))) { - auto& dq = hosts_cores.at(get_host(worker)); - if (client_core_limit == 0) { - // limit client cores if it matches a server host - bool match = false; - int limit = dq.size(); - for (size_t srv = 0; srv < num_servers; srv++) { - if (get_host(worker) == get_host(workers[srv])) { - match = true; - } - } - if (match) { - GPR_ASSERT(limit > 0); - client_core_limit = limit; - } - } - if (client_core_limit > 0) { - GPR_ASSERT(dq.size() >= static_cast(client_core_limit)); - gpr_log(GPR_INFO, "Setting client core_list"); - for (int core = 0; core < client_core_limit; core++) { - per_client_config.add_core_list(dq.front()); - dq.pop_front(); - } - } + if(initial_client_config.core_limit() != 0) { + gpr_log(GPR_WARN, "client config core limit set but ignored"); } // Reduce channel count so that total channels specified is held regardless diff --git a/test/cpp/qps/driver.h b/test/cpp/qps/driver.h index b5c8152e1bc..e72d30a4eff 100644 --- a/test/cpp/qps/driver.h +++ b/test/cpp/qps/driver.h @@ -46,8 +46,7 @@ std::unique_ptr RunScenario( const grpc::testing::ClientConfig& client_config, size_t num_clients, const grpc::testing::ServerConfig& server_config, size_t num_servers, int warmup_seconds, int benchmark_seconds, int spawn_local_worker_count, - const char* qps_server_target_override = "", - bool configure_core_lists = true); + const char* qps_server_target_override = ""); bool RunQuit(); } // namespace testing diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index da835b995ab..ca4c6865784 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -70,9 +70,6 @@ DEFINE_double(error_tolerance, 0.01, DEFINE_string(qps_server_target_override, "", "Override QPS server target to configure in client configs." "Only applicable if there is a single benchmark server."); -DEFINE_bool(configure_core_lists, true, - "Provide 'core_list' parameters to workers. Value determined " - "by cores available and 'core_limit' parameters of the scenarios."); namespace grpc { namespace testing { @@ -85,7 +82,7 @@ static std::unique_ptr RunAndReport(const Scenario& scenario, scenario.server_config(), scenario.num_servers(), scenario.warmup_seconds(), scenario.benchmark_seconds(), scenario.spawn_local_worker_count(), - FLAGS_qps_server_target_override.c_str(), FLAGS_configure_core_lists); + FLAGS_qps_server_target_override.c_str()); // Amend the result with scenario config. Eventually we should adjust // RunScenario contract so we don't need to touch the result here. diff --git a/tools/run_tests/performance/scenario_config.py b/tools/run_tests/performance/scenario_config.py index c3c5ece3628..b20bb40eb1b 100644 --- a/tools/run_tests/performance/scenario_config.py +++ b/tools/run_tests/performance/scenario_config.py @@ -109,7 +109,6 @@ def _ping_pong_scenario(name, rpc_type, unconstrained_client=None, client_language=None, server_language=None, - server_core_limit=0, async_server_threads=0, warmup_seconds=WARMUP_SECONDS, categories=DEFAULT_CATEGORIES, @@ -136,7 +135,6 @@ def _ping_pong_scenario(name, rpc_type, 'server_config': { 'server_type': server_type, 'security_params': _get_secargs(secure), - 'core_limit': server_core_limit, 'async_server_threads': async_server_threads, }, 'warmup_seconds': warmup_seconds, @@ -200,7 +198,7 @@ class CXXLanguage: rpc_type='STREAMING', client_type='ASYNC_CLIENT', server_type='ASYNC_GENERIC_SERVER', - use_generic_payload=True, server_core_limit=1, async_server_threads=1, + use_generic_payload=True, async_server_threads=1, secure=secure, categories=smoketest_categories) @@ -219,7 +217,7 @@ class CXXLanguage: client_type='ASYNC_CLIENT', server_type='ASYNC_GENERIC_SERVER', unconstrained_client='async', use_generic_payload=True, - server_core_limit=1, async_server_threads=1, + async_server_threads=1, secure=secure) yield _ping_pong_scenario( @@ -248,7 +246,7 @@ class CXXLanguage: rpc_type=rpc_type.upper(), client_type='%s_CLIENT' % synchronicity.upper(), server_type='%s_SERVER' % synchronicity.upper(), - server_core_limit=1, async_server_threads=1, + async_server_threads=1, secure=secure) yield _ping_pong_scenario( @@ -332,13 +330,13 @@ class CSharpLanguage: yield _ping_pong_scenario( 'csharp_to_cpp_protobuf_sync_unary_ping_pong', rpc_type='UNARY', client_type='SYNC_CLIENT', server_type='SYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1, + server_language='c++', async_server_threads=1, categories=[SMOKETEST, SCALABLE]) yield _ping_pong_scenario( 'csharp_to_cpp_protobuf_async_streaming_ping_pong', rpc_type='STREAMING', client_type='ASYNC_CLIENT', server_type='ASYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1) + server_language='c++', async_server_threads=1) yield _ping_pong_scenario( 'csharp_to_cpp_protobuf_async_unary_qps_unconstrained', rpc_type='UNARY', @@ -414,13 +412,13 @@ class NodeLanguage: #yield _ping_pong_scenario( # 'node_to_cpp_protobuf_async_unary_ping_pong', rpc_type='UNARY', # client_type='ASYNC_CLIENT', server_type='ASYNC_SERVER', - # server_language='c++', server_core_limit=1, async_server_threads=1) + # server_language='c++', async_server_threads=1) # TODO(jtattermusch): make this scenario work #yield _ping_pong_scenario( # 'node_to_cpp_protobuf_async_streaming_ping_pong', rpc_type='STREAMING', # client_type='ASYNC_CLIENT', server_type='ASYNC_SERVER', - # server_language='c++', server_core_limit=1, async_server_threads=1) + # server_language='c++', async_server_threads=1) def __str__(self): return 'node' @@ -469,13 +467,13 @@ class PythonLanguage: yield _ping_pong_scenario( 'python_to_cpp_protobuf_sync_unary_ping_pong', rpc_type='UNARY', client_type='SYNC_CLIENT', server_type='ASYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1, + server_language='c++', async_server_threads=1, categories=[SMOKETEST, SCALABLE]) yield _ping_pong_scenario( 'python_to_cpp_protobuf_sync_streaming_ping_pong', rpc_type='STREAMING', client_type='SYNC_CLIENT', server_type='ASYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1) + server_language='c++', async_server_threads=1) def __str__(self): return 'python' @@ -516,12 +514,12 @@ class RubyLanguage: yield _ping_pong_scenario( 'ruby_to_cpp_protobuf_sync_unary_ping_pong', rpc_type='UNARY', client_type='SYNC_CLIENT', server_type='SYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1) + server_language='c++', async_server_threads=1) yield _ping_pong_scenario( 'ruby_to_cpp_protobuf_sync_streaming_ping_pong', rpc_type='STREAMING', client_type='SYNC_CLIENT', server_type='SYNC_SERVER', - server_language='c++', server_core_limit=1, async_server_threads=1) + server_language='c++', async_server_threads=1) def __str__(self): return 'ruby' From 8a0ef63dea1546a04fd00c6be7f4f223e3e559f1 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 11 Jan 2017 13:52:01 -0800 Subject: [PATCH 165/261] remove LimitCores in c++ benchmark --- test/cpp/qps/client.h | 2 +- test/cpp/qps/limit_cores.cc | 87 ------------------------------------- test/cpp/qps/limit_cores.h | 49 --------------------- test/cpp/qps/server.h | 2 +- 4 files changed, 2 insertions(+), 138 deletions(-) delete mode 100644 test/cpp/qps/limit_cores.cc delete mode 100644 test/cpp/qps/limit_cores.h diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index fdd78ebb899..3018c21f326 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -374,7 +374,7 @@ class ClientImpl : public Client { ClientImpl(const ClientConfig& config, std::function(std::shared_ptr)> create_stub) - : cores_(LimitCores(config.core_list().data(), config.core_list_size())), + : cores_(gpr_cpu_num_cores()), channels_(config.client_channels()), create_stub_(create_stub) { for (int i = 0; i < config.client_channels(); i++) { diff --git a/test/cpp/qps/limit_cores.cc b/test/cpp/qps/limit_cores.cc deleted file mode 100644 index b5c222542be..00000000000 --- a/test/cpp/qps/limit_cores.cc +++ /dev/null @@ -1,87 +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. - * - */ - -#include "test/cpp/qps/limit_cores.h" - -#include -#include -#include - -#ifdef GPR_CPU_LINUX -#ifndef _GNU_SOURCE -#define _GNU_SOURCE -#endif -#include - -namespace grpc { -namespace testing { - -int LimitCores(const int* cores, int cores_size) { - const int num_cores = gpr_cpu_num_cores(); - int cores_set = 0; - - cpu_set_t* cpup = CPU_ALLOC(num_cores); - GPR_ASSERT(cpup); - const size_t size = CPU_ALLOC_SIZE(num_cores); - CPU_ZERO_S(size, cpup); - - if (cores_size > 0) { - for (int i = 0; i < cores_size; i++) { - if (cores[i] < num_cores) { - CPU_SET_S(cores[i], size, cpup); - cores_set++; - } - } - } else { - for (int i = 0; i < num_cores; i++) { - CPU_SET_S(i, size, cpup); - cores_set++; - } - } - bool affinity_set = (sched_setaffinity(0, size, cpup) == 0); - CPU_FREE(cpup); - return affinity_set ? cores_set : num_cores; -} - -} // namespace testing -} // namespace grpc -#else -namespace grpc { -namespace testing { - -// LimitCores is not currently supported for non-Linux platforms -int LimitCores(const int*, int) { return gpr_cpu_num_cores(); } - -} // namespace testing -} // namespace grpc -#endif diff --git a/test/cpp/qps/limit_cores.h b/test/cpp/qps/limit_cores.h deleted file mode 100644 index 5482904a3c4..00000000000 --- a/test/cpp/qps/limit_cores.h +++ /dev/null @@ -1,49 +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 TEST_QPS_LIMIT_CORES_H -#define TEST_QPS_LIMIT_CORES_H - -namespace grpc { -namespace testing { -/// LimitCores: allow this worker to only run on the cores specified in the -/// array \a cores, which is of length \a cores_size. -/// -/// LimitCores takes array and size arguments (instead of vector) for direct -/// conversion from repeated field of protobuf. Use a cores_size of 0 to remove -/// existing limits (from an empty repeated field) -int LimitCores(const int *cores, int cores_size); -} // namespace testing -} // namespace grpc - -#endif // TEST_QPS_LIMIT_CORES_H diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index c3d18e57892..5f4c34c9ad2 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -51,7 +51,7 @@ namespace testing { class Server { public: explicit Server(const ServerConfig& config) : timer_(new UsageTimer) { - cores_ = LimitCores(config.core_list().data(), config.core_list_size()); + cores_ = gpr_cpu_num_cores(); if (config.port()) { port_ = config.port(); From 032baa8308cfa1273d2085e5c690d34bf1a59c11 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Jan 2017 13:56:57 -0800 Subject: [PATCH 166/261] Fix sanity: check_sources_and_headers --- CMakeLists.txt | 3 +++ Makefile | 4 ++++ build.yaml | 1 + tools/doxygen/Doxyfile.c++ | 1 + tools/doxygen/Doxyfile.c++.internal | 1 + tools/run_tests/generated/sources_and_headers.json | 2 ++ vsprojects/vcxproj/grpc++/grpc++.vcxproj | 1 + vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters | 3 +++ vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj | 1 + .../vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters | 3 +++ vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj | 1 + .../vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters | 3 +++ .../vcxproj/test/codegen_test_full/codegen_test_full.vcxproj | 1 + .../test/codegen_test_full/codegen_test_full.vcxproj.filters | 3 +++ .../test/codegen_test_minimal/codegen_test_minimal.vcxproj | 1 + .../codegen_test_minimal/codegen_test_minimal.vcxproj.filters | 3 +++ vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj | 1 + .../test/grpc_tool_test/grpc_tool_test.vcxproj.filters | 3 +++ 18 files changed, 36 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dc0162ca24..40ed9d84e02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1200,6 +1200,7 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h + include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -1538,6 +1539,7 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h + include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -1745,6 +1747,7 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h + include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h diff --git a/Makefile b/Makefile index bc2be439ac0..27a7254b24b 100644 --- a/Makefile +++ b/Makefile @@ -3883,6 +3883,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ + include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4250,6 +4251,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ + include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4606,6 +4608,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ + include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4785,6 +4788,7 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ + include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ diff --git a/build.yaml b/build.yaml index 27dc48bd2b0..a6209abd78f 100644 --- a/build.yaml +++ b/build.yaml @@ -826,6 +826,7 @@ filegroups: - include/grpc++/impl/codegen/server_context.h - include/grpc++/impl/codegen/server_interface.h - include/grpc++/impl/codegen/service_type.h + - include/grpc++/impl/codegen/slice.h - include/grpc++/impl/codegen/status.h - include/grpc++/impl/codegen/status_code_enum.h - include/grpc++/impl/codegen/status_helper.h diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index fa9b7057c57..e4c0d6aa16e 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -821,6 +821,7 @@ include/grpc++/impl/codegen/serialization_traits.h \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ +include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index bca5652a463..01b563d411d 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -822,6 +822,7 @@ include/grpc++/impl/codegen/serialization_traits.h \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ +include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 90d6a0f0ee9..f9a54559a9a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -7787,6 +7787,7 @@ "include/grpc++/impl/codegen/server_context.h", "include/grpc++/impl/codegen/server_interface.h", "include/grpc++/impl/codegen/service_type.h", + "include/grpc++/impl/codegen/slice.h", "include/grpc++/impl/codegen/status.h", "include/grpc++/impl/codegen/status_code_enum.h", "include/grpc++/impl/codegen/status_helper.h", @@ -7820,6 +7821,7 @@ "include/grpc++/impl/codegen/server_context.h", "include/grpc++/impl/codegen/server_interface.h", "include/grpc++/impl/codegen/service_type.h", + "include/grpc++/impl/codegen/slice.h", "include/grpc++/impl/codegen/status.h", "include/grpc++/impl/codegen/status_code_enum.h", "include/grpc++/impl/codegen/status_helper.h", diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index 7dd0b85a0a8..c35538869be 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -321,6 +321,7 @@ + diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index 28766bf76ed..af933d42836 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -303,6 +303,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index 5b05d0918c8..5bc4f53babb 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -168,6 +168,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 b1fa72a8410..71a1168a908 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters @@ -96,6 +96,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index 48fb7619a2d..26087a9376c 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -321,6 +321,7 @@ + diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index 7ce21ad286e..c55ba228ab1 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -288,6 +288,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj index d2699a5729f..b3e4e192f78 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj @@ -181,6 +181,7 @@ + diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters index dc0d89ecd57..9b7ec04b726 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters @@ -84,6 +84,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj index 742c9a6865c..74700786f3f 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj @@ -181,6 +181,7 @@ + diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters index 88165167bda..7f395691d01 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters @@ -87,6 +87,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj index 65719c31002..3026b375887 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj @@ -182,6 +182,7 @@ + diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters index 7f3745c7a93..d0e560c7b75 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters @@ -78,6 +78,9 @@ include\grpc++\impl\codegen + + include\grpc++\impl\codegen + include\grpc++\impl\codegen From aa16d3f47dbfce9278491eb0a4dd9abe2e2670ab Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Jan 2017 13:57:20 -0800 Subject: [PATCH 167/261] Fix sanity: check_include_guards --- src/core/lib/iomgr/error_internal.h | 6 +++--- src/core/lib/transport/error_utils.h | 6 +++--- src/core/lib/transport/http2_errors.h | 6 +++--- src/core/lib/transport/status_conversion.h | 6 +++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h index 8f49ba39922..1c89ead4ed6 100644 --- a/src/core/lib/iomgr/error_internal.h +++ b/src/core/lib/iomgr/error_internal.h @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_ERROR_INTERNAL_H -#define GRPC_ERROR_INTERNAL_H +#ifndef GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H +#define GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H #include #include @@ -51,4 +51,4 @@ struct grpc_error { bool grpc_error_is_special(grpc_error *err); -#endif +#endif /* GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H */ diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h index f72c3dca0ed..105338880ac 100644 --- a/src/core/lib/transport/error_utils.h +++ b/src/core/lib/transport/error_utils.h @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_ERROR_UTILS_H -#define GRPC_ERROR_UTILS_H +#ifndef GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H +#define GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H #include "src/core/lib/iomgr/error.h" #include "src/core/lib/transport/http2_errors.h" @@ -53,4 +53,4 @@ void grpc_error_get_status(grpc_error *error, gpr_timespec deadline, /// GRPC_ERROR_CANCELLED bool grpc_error_has_clear_grpc_status(grpc_error *error); -#endif +#endif /* GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H */ diff --git a/src/core/lib/transport/http2_errors.h b/src/core/lib/transport/http2_errors.h index bf24438dde3..330bc987f6e 100644 --- a/src/core/lib/transport/http2_errors.h +++ b/src/core/lib/transport/http2_errors.h @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H -#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H +#ifndef GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H +#define GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H /* error codes for RST_STREAM from http2 draft 14 section 7 */ typedef enum { @@ -53,4 +53,4 @@ typedef enum { GRPC_HTTP2__ERROR_DO_NOT_USE = -1 } grpc_http2_error_code; -#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H */ +#endif /* GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H */ diff --git a/src/core/lib/transport/status_conversion.h b/src/core/lib/transport/status_conversion.h index 3885ac90a53..e6a23a606b4 100644 --- a/src/core/lib/transport/status_conversion.h +++ b/src/core/lib/transport/status_conversion.h @@ -31,8 +31,8 @@ * */ -#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H -#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H +#ifndef GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H +#define GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H #include #include "src/core/lib/transport/http2_errors.h" @@ -46,4 +46,4 @@ grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, grpc_status_code grpc_http2_status_to_grpc_status(int status); int grpc_status_to_http2_status(grpc_status_code status); -#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H */ +#endif /* GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H */ From 3e8deb188f63f5acb0f06c1169b230f82d5eed14 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Jan 2017 14:06:16 -0800 Subject: [PATCH 168/261] Fix sanity: core_banned_functions --- .../ext/transport/chttp2/transport/hpack_encoder.c | 2 +- src/core/lib/channel/http_server_filter.c | 13 +++++++------ .../credentials/plugin/plugin_credentials.c | 4 ++-- src/core/lib/slice/slice_hash_table.c | 2 +- src/core/lib/surface/call_details.c | 4 ++-- src/core/lib/surface/channel.c | 8 ++++---- src/core/lib/surface/server.c | 4 ++-- src/core/lib/transport/metadata_batch.c | 6 +++--- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index ae2055bc3e9..63df8e135f8 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -296,7 +296,7 @@ static grpc_slice get_wire_value(grpc_mdelem elem, uint8_t *huffman_prefix) { } /* TODO(ctiller): opportunistically compress non-binary headers */ *huffman_prefix = 0x00; - return grpc_slice_ref(GRPC_MDVALUE(elem)); + return grpc_slice_ref_internal(GRPC_MDVALUE(elem)); } static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 776eff456d1..da105d06fdb 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -199,12 +199,13 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, } if (b->idx.named.host != NULL) { - add_error(error_name, &error, - grpc_metadata_batch_substitute( - exec_ctx, b, b->idx.named.host, - grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref(GRPC_MDVALUE(b->idx.named.host->md))))); + add_error( + error_name, &error, + grpc_metadata_batch_substitute( + exec_ctx, b, b->idx.named.host, + grpc_mdelem_from_slices( + exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.host->md))))); } if (b->idx.named.authority == NULL) { diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index f98c9cd8ef2..c5e8d67039d 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -97,8 +97,8 @@ static void plugin_md_request_metadata_ready(void *request, } else if (num_md > 0) { md_array = gpr_malloc(num_md * sizeof(grpc_credentials_md)); for (i = 0; i < num_md; i++) { - md_array[i].key = grpc_slice_ref(md[i].key); - md_array[i].value = grpc_slice_ref(md[i].value); + md_array[i].key = grpc_slice_ref_internal(md[i].key); + md_array[i].value = grpc_slice_ref_internal(md[i].value); } r->cb(&exec_ctx, r->user_data, md_array, num_md, GRPC_CREDENTIALS_OK, NULL); diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 1f3ca72ce6b..46c109439b4 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -75,7 +75,7 @@ static void grpc_slice_hash_table_add( grpc_slice_hash_table_find_index(table, key, true /* find_empty */); GPR_ASSERT(idx != table->size); // Table should never be full. grpc_slice_hash_table_entry* entry = &table->entries[idx]; - entry->key = grpc_slice_ref(key); + entry->key = grpc_slice_ref_internal(key); entry->value = vtable->copy_value(value); entry->vtable = vtable; } diff --git a/src/core/lib/surface/call_details.c b/src/core/lib/surface/call_details.c index 5efa3b0141b..51e84c29459 100644 --- a/src/core/lib/surface/call_details.c +++ b/src/core/lib/surface/call_details.c @@ -47,6 +47,6 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_slice_unref(cd->method); - grpc_slice_unref(cd->host); + grpc_slice_unref_internal(exec_ctx, cd->method); + grpc_slice_unref_internal(exec_ctx, cd->host); } diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 1ef023ed628..1a257489779 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -234,9 +234,9 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, cq, NULL, grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref(method)), + grpc_slice_ref_internal(method)), host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref(*host)) + grpc_slice_ref_internal(*host)) : GRPC_MDNULL, deadline); grpc_exec_ctx_finish(&exec_ctx); @@ -251,9 +251,9 @@ grpc_call *grpc_channel_create_pollset_set_call( return grpc_channel_create_call_internal( exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set, grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref(method)), + grpc_slice_ref_internal(method)), host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref(*host)) + grpc_slice_ref_internal(*host)) : GRPC_MDNULL, deadline); } diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 7d0b30e97a6..3782b491226 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -748,9 +748,9 @@ static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, if (error == GRPC_ERROR_NONE) { GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != NULL); GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != NULL); - calld->path = grpc_slice_ref( + calld->path = grpc_slice_ref_internal( GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); - calld->host = grpc_slice_ref( + calld->host = grpc_slice_ref_internal( GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); calld->path_set = true; calld->host_set = true; diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 18b0f161ab5..c11c797d394 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -74,7 +74,7 @@ static void assert_valid_callouts(grpc_metadata_batch *batch) { if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { GPR_ASSERT(batch->idx.array[callout_idx] == l); } - grpc_slice_unref(key_interned); + grpc_slice_unref_internal(exec_ctx, key_interned); } #endif } @@ -242,8 +242,8 @@ void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, grpc_linked_mdelem *storage, grpc_slice value) { grpc_mdelem old = storage->md; - grpc_mdelem new = - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref(GRPC_MDKEY(old)), value); + grpc_mdelem new = grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(old)), value); storage->md = new; GRPC_MDELEM_UNREF(exec_ctx, old); } From 9277aa74aeb01cf166fe471614027a94b3bee1b6 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Jan 2017 14:15:38 -0800 Subject: [PATCH 169/261] Fix sanity: core_banned_functions --- src/core/ext/lb_policy/grpclb/grpclb.c | 10 +++--- .../chttp2/transport/incoming_metadata.c | 6 ++-- src/core/lib/channel/compress_filter.c | 4 +-- src/core/lib/channel/http_client_filter.c | 18 +++++----- src/core/lib/channel/http_server_filter.c | 6 ++-- .../security/transport/client_auth_filter.c | 2 +- src/core/lib/surface/call.c | 7 ++-- src/core/lib/surface/call_details.c | 8 +++-- src/core/lib/surface/channel.c | 1 + src/core/lib/transport/metadata_batch.c | 36 +++++++++++-------- src/core/lib/transport/metadata_batch.h | 20 +++++------ 11 files changed, 66 insertions(+), 52 deletions(-) diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index 3cdd96e7ae9..ded457f64a8 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -136,12 +136,12 @@ int grpc_lb_glb_trace = 0; /* add lb_token of selected subchannel (address) to the call's initial * metadata */ static grpc_error *initial_metadata_add_lb_token( - grpc_metadata_batch *initial_metadata, + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *initial_metadata, grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem lb_token) { GPR_ASSERT(lb_token_mdelem_storage != NULL); GPR_ASSERT(!GRPC_MDISNULL(lb_token)); - return grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, - lb_token); + return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, + lb_token_mdelem_storage, lb_token); } typedef struct wrapped_rr_closure_arg { @@ -189,7 +189,7 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, * available */ if (*wc_arg->target != NULL) { if (!GRPC_MDISNULL(wc_arg->lb_token)) { - initial_metadata_add_lb_token(wc_arg->initial_metadata, + initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); } else { @@ -568,7 +568,7 @@ static bool pick_from_internal_rr_locked( GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); /* add the load reporting initial metadata */ - initial_metadata_add_lb_token(pick_args->initial_metadata, + initial_metadata_add_lb_token(exec_ctx, pick_args->initial_metadata, pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index 4e4e41734a2..c91b019aa05 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -96,9 +96,9 @@ void grpc_chttp2_incoming_metadata_buffer_publish( size_t i; for (i = 0; i < buffer->count; i++) { /* TODO(ctiller): do something better here */ - if (!GRPC_LOG_IF_ERROR( - "grpc_chttp2_incoming_metadata_buffer_publish", - grpc_metadata_batch_link_tail(batch, &buffer->elems[i]))) { + if (!GRPC_LOG_IF_ERROR("grpc_chttp2_incoming_metadata_buffer_publish", + grpc_metadata_batch_link_tail( + exec_ctx, batch, &buffer->elems[i]))) { GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md); } } diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index 62075ed6134..c860d60d881 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -146,14 +146,14 @@ static grpc_error *process_send_initial_metadata( /* hint compression algorithm */ error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->compression_algorithm_storage, + exec_ctx, initial_metadata, &calld->compression_algorithm_storage, grpc_compression_encoding_mdelem(calld->compression_algorithm)); if (error != GRPC_ERROR_NONE) return error; /* convey supported compression algorithms */ error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->accept_encoding_storage, + exec_ctx, initial_metadata, &calld->accept_encoding_storage, GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( channeld->supported_compression_algorithms)); diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index c2ee0a0047e..49a2a980e0d 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -298,8 +298,9 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN, grpc_slice_from_copied_buffer((const char *)calld->payload_bytes, op->send_message->length)); - error = grpc_metadata_batch_add_tail(op->send_initial_metadata, - &calld->payload_bin, payload_bin); + error = + grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, + &calld->payload_bin, payload_bin); if (error != GRPC_ERROR_NONE) return error; calld->on_complete = op->on_complete; op->on_complete = &calld->hc_on_complete; @@ -323,21 +324,22 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, /* Send : prefixed headers, which have to be before any application layer headers. */ - error = grpc_metadata_batch_add_head(op->send_initial_metadata, + error = grpc_metadata_batch_add_head(exec_ctx, op->send_initial_metadata, &calld->method, method); if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_head( - op->send_initial_metadata, &calld->scheme, channeld->static_scheme); + error = + grpc_metadata_batch_add_head(exec_ctx, op->send_initial_metadata, + &calld->scheme, channeld->static_scheme); if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_tail(op->send_initial_metadata, + error = grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, &calld->te_trailers, GRPC_MDELEM_TE_TRAILERS); if (error != GRPC_ERROR_NONE) return error; error = grpc_metadata_batch_add_tail( - op->send_initial_metadata, &calld->content_type, + exec_ctx, op->send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_tail(op->send_initial_metadata, + error = grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, &calld->user_agent, GRPC_MDELEM_REF(channeld->user_agent)); if (error != GRPC_ERROR_NONE) return error; diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index da105d06fdb..3f992977c08 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -279,11 +279,11 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_error *error = GRPC_ERROR_NONE; static const char *error_name = "Failed sending initial metadata"; add_error(error_name, &error, grpc_metadata_batch_add_head( - op->send_initial_metadata, &calld->status, - GRPC_MDELEM_STATUS_200)); + exec_ctx, op->send_initial_metadata, + &calld->status, GRPC_MDELEM_STATUS_200)); add_error(error_name, &error, grpc_metadata_batch_add_tail( - op->send_initial_metadata, &calld->content_type, + exec_ctx, op->send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); add_error(error_name, &error, server_filter_outgoing_metadata(exec_ctx, elem, diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index b20e88851ab..cf7de493458 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -136,7 +136,7 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, } else { add_error(&error, grpc_metadata_batch_add_tail( - mdb, &calld->md_links[i], + exec_ctx, mdb, &calld->md_links[i], grpc_mdelem_from_slices( exec_ctx, grpc_slice_ref_internal(md_elems[i].key), grpc_slice_ref_internal(md_elems[i].value)))); diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 1425913f5a4..63b0683df56 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -796,14 +796,15 @@ static int prepare_application_metadata( for (i = 0; i < call->send_extra_metadata_count; i++) { GRPC_LOG_IF_ERROR("prepare_application_metadata", grpc_metadata_batch_link_tail( - batch, &call->send_extra_metadata[i])); + exec_ctx, batch, &call->send_extra_metadata[i])); } } } for (i = 0; i < total_count; i++) { grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - GRPC_LOG_IF_ERROR("prepare_application_metadata", - grpc_metadata_batch_link_tail(batch, linked_from_md(md))); + GRPC_LOG_IF_ERROR( + "prepare_application_metadata", + grpc_metadata_batch_link_tail(exec_ctx, batch, linked_from_md(md))); } call->send_extra_metadata_count = 0; diff --git a/src/core/lib/surface/call_details.c b/src/core/lib/surface/call_details.c index 51e84c29459..d0f88e19690 100644 --- a/src/core/lib/surface/call_details.c +++ b/src/core/lib/surface/call_details.c @@ -36,6 +36,8 @@ #include +#include "src/core/lib/iomgr/exec_ctx.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" void grpc_call_details_init(grpc_call_details* cd) { @@ -47,6 +49,8 @@ void grpc_call_details_init(grpc_call_details* cd) { void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_slice_unref_internal(exec_ctx, cd->method); - grpc_slice_unref_internal(exec_ctx, cd->host); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_slice_unref_internal(&exec_ctx, cd->method); + grpc_slice_unref_internal(&exec_ctx, cd->host); + grpc_exec_ctx_finish(&exec_ctx); } diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 1a257489779..429dbad7c77 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -43,6 +43,7 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index c11c797d394..95b71d33d77 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -40,6 +40,7 @@ #include #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" static void assert_valid_list(grpc_mdelem_list *list) { @@ -65,7 +66,8 @@ static void assert_valid_list(grpc_mdelem_list *list) { #endif /* NDEBUG */ } -static void assert_valid_callouts(grpc_metadata_batch *batch) { +static void assert_valid_callouts(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch) { #ifndef NDEBUG for (grpc_linked_mdelem *l = batch->list.head; l != NULL; l = l->next) { grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); @@ -138,12 +140,13 @@ static void maybe_unlink_callout(grpc_metadata_batch *batch, batch->idx.array[idx] = NULL; } -grpc_error *grpc_metadata_batch_add_head(grpc_metadata_batch *batch, +grpc_error *grpc_metadata_batch_add_head(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_head(batch, storage); + return grpc_metadata_batch_link_head(exec_ctx, batch, storage); } static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { @@ -161,25 +164,27 @@ static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); } -grpc_error *grpc_metadata_batch_link_head(grpc_metadata_batch *batch, +grpc_error *grpc_metadata_batch_link_head(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); grpc_error *err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return err; } link_head(&batch->list, storage); - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return GRPC_ERROR_NONE; } -grpc_error *grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, +grpc_error *grpc_metadata_batch_add_tail(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) { GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); storage->md = elem_to_add; - return grpc_metadata_batch_link_tail(batch, storage); + return grpc_metadata_batch_link_tail(exec_ctx, batch, storage); } static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { @@ -198,16 +203,17 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); } -grpc_error *grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, +grpc_error *grpc_metadata_batch_link_tail(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); grpc_error *err = maybe_link_callout(batch, storage); if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return err; } link_tail(&batch->list, storage); - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); return GRPC_ERROR_NONE; } @@ -231,11 +237,11 @@ static void unlink_storage(grpc_mdelem_list *list, void grpc_metadata_batch_remove(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, grpc_linked_mdelem *storage) { - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); maybe_unlink_callout(batch, storage); unlink_storage(&batch->list, storage); GRPC_MDELEM_UNREF(exec_ctx, storage->md); - assert_valid_callouts(batch); + assert_valid_callouts(exec_ctx, batch); } void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 894a927d3e9..5471539e824 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -100,17 +100,17 @@ void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error *grpc_metadata_batch_link_head(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) - GRPC_MUST_USE_RESULT; +grpc_error *grpc_metadata_batch_link_head( + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) GRPC_MUST_USE_RESULT; /** Add \a storage to the end of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error *grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) - GRPC_MUST_USE_RESULT; +grpc_error *grpc_metadata_batch_link_tail( + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the first element in \a batch, using \a storage as backing storage for the linked list element. @@ -119,8 +119,8 @@ grpc_error *grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error *grpc_metadata_batch_add_head( - grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the @@ -128,8 +128,8 @@ grpc_error *grpc_metadata_batch_add_head( for the lifetime of the call. Takes ownership of \a elem_to_add */ grpc_error *grpc_metadata_batch_add_tail( - grpc_metadata_batch *batch, grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; + grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md); From e5d8e02aa6efd3ce97f788560df3994473df8327 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 11 Jan 2017 14:20:28 -0800 Subject: [PATCH 170/261] Fix sanity: core_banned_functions --- src/cpp/common/channel_filter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 35cd6ca6475..253614ca9b4 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -50,7 +50,7 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), SliceFromCopiedString(value)); GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(batch_, storage)); + grpc_metadata_batch_link_head(exec_ctx, batch_, storage)); return storage; } From 6ff1ca4871d73dd018e33bfca0df896570c0d429 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 11 Jan 2017 14:25:55 -0800 Subject: [PATCH 171/261] re-run generate project to build qps json driver --- Makefile | 3 - build.yaml | 1 - test/cpp/qps/client.h | 1 - test/cpp/qps/driver.cc | 4 +- test/cpp/qps/server.h | 1 - .../generated/sources_and_headers.json | 1 - tools/run_tests/generated/tests.json | 136 +++++++++--------- vsprojects/vcxproj/qps/qps.vcxproj | 2 - vsprojects/vcxproj/qps/qps.vcxproj.filters | 3 - 9 files changed, 70 insertions(+), 82 deletions(-) diff --git a/Makefile b/Makefile index 8f7328ae285..314db9f4c1b 100644 --- a/Makefile +++ b/Makefile @@ -5200,7 +5200,6 @@ LIBQPS_SRC = \ test/cpp/qps/client_async.cc \ test/cpp/qps/client_sync.cc \ test/cpp/qps/driver.cc \ - test/cpp/qps/limit_cores.cc \ test/cpp/qps/parse_json.cc \ test/cpp/qps/qps_worker.cc \ test/cpp/qps/report.cc \ @@ -5256,7 +5255,6 @@ endif $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_async.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/client_sync.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/driver.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc -$(OBJDIR)/$(CONFIG)/test/cpp/qps/limit_cores.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/parse_json.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/qps_worker.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/qps/report.o: $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.pb.cc $(GENDIR)/src/proto/grpc/testing/payloads.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.pb.cc $(GENDIR)/src/proto/grpc/testing/stats.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/control.pb.cc $(GENDIR)/src/proto/grpc/testing/control.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/services.pb.cc $(GENDIR)/src/proto/grpc/testing/services.grpc.pb.cc @@ -16812,7 +16810,6 @@ test/cpp/interop/server_helper.cc: $(OPENSSL_DEP) test/cpp/qps/client_async.cc: $(OPENSSL_DEP) test/cpp/qps/client_sync.cc: $(OPENSSL_DEP) test/cpp/qps/driver.cc: $(OPENSSL_DEP) -test/cpp/qps/limit_cores.cc: $(OPENSSL_DEP) test/cpp/qps/parse_json.cc: $(OPENSSL_DEP) test/cpp/qps/qps_worker.cc: $(OPENSSL_DEP) test/cpp/qps/report.cc: $(OPENSSL_DEP) diff --git a/build.yaml b/build.yaml index de9d253ef1c..8f217682c2a 100644 --- a/build.yaml +++ b/build.yaml @@ -1306,7 +1306,6 @@ libs: - test/cpp/qps/client_async.cc - test/cpp/qps/client_sync.cc - test/cpp/qps/driver.cc - - test/cpp/qps/limit_cores.cc - test/cpp/qps/parse_json.cc - test/cpp/qps/qps_worker.cc - test/cpp/qps/report.cc diff --git a/test/cpp/qps/client.h b/test/cpp/qps/client.h index 3018c21f326..ae7264c9c16 100644 --- a/test/cpp/qps/client.h +++ b/test/cpp/qps/client.h @@ -51,7 +51,6 @@ #include "test/cpp/qps/histogram.h" #include "test/cpp/qps/interarrival.h" -#include "test/cpp/qps/limit_cores.h" #include "test/cpp/qps/usage_timer.h" #include "test/cpp/util/create_test_channel.h" diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 42722b7e9d1..7494ced460e 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -263,7 +263,7 @@ std::unique_ptr RunScenario( ServerConfig server_config = initial_server_config; if(server_config.core_limit() != 0) { - gpr_log(GPR_WARN, "server config core limit is set but ignored by driver"); + gpr_log(GPR_ERROR, "server config core limit is set but ignored by driver"); } ServerArgs args; @@ -309,7 +309,7 @@ std::unique_ptr RunScenario( ClientConfig per_client_config = client_config; if(initial_client_config.core_limit() != 0) { - gpr_log(GPR_WARN, "client config core limit set but ignored"); + gpr_log(GPR_ERROR, "client config core limit set but ignored"); } // Reduce channel count so that total channels specified is held regardless diff --git a/test/cpp/qps/server.h b/test/cpp/qps/server.h index 5f4c34c9ad2..821d5935beb 100644 --- a/test/cpp/qps/server.h +++ b/test/cpp/qps/server.h @@ -42,7 +42,6 @@ #include "src/proto/grpc/testing/messages.grpc.pb.h" #include "test/core/end2end/data/ssl_test_data.h" #include "test/core/util/port.h" -#include "test/cpp/qps/limit_cores.h" #include "test/cpp/qps/usage_timer.h" namespace grpc { diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 6ae269cc20d..deadec29a44 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -5545,7 +5545,6 @@ "test/cpp/qps/driver.h", "test/cpp/qps/histogram.h", "test/cpp/qps/interarrival.h", - "test/cpp/qps/limit_cores.cc", "test/cpp/qps/limit_cores.h", "test/cpp/qps/parse_json.cc", "test/cpp/qps/parse_json.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b76263b8b98..7b46e8256c7 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -36756,7 +36756,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36780,7 +36780,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36804,7 +36804,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36828,7 +36828,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36852,7 +36852,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36876,7 +36876,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36900,7 +36900,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36924,7 +36924,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36948,7 +36948,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36972,7 +36972,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -36996,7 +36996,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37020,7 +37020,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37044,7 +37044,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37068,7 +37068,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37092,7 +37092,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37116,7 +37116,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37140,7 +37140,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37164,7 +37164,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37188,7 +37188,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37212,7 +37212,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37236,7 +37236,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37260,7 +37260,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37284,7 +37284,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37308,7 +37308,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37332,7 +37332,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37356,7 +37356,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37380,7 +37380,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37404,7 +37404,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37428,7 +37428,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37452,7 +37452,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37476,7 +37476,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 16, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37500,7 +37500,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37524,7 +37524,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37548,7 +37548,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37572,7 +37572,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37609,7 +37609,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37646,7 +37646,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37683,7 +37683,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37720,7 +37720,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37757,7 +37757,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37794,7 +37794,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37831,7 +37831,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37868,7 +37868,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37905,7 +37905,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37942,7 +37942,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -37979,7 +37979,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38016,7 +38016,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38053,7 +38053,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38090,7 +38090,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38127,7 +38127,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38164,7 +38164,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_secure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": {\"use_test_ca\": true, \"server_host_override\": \"foo.test.google.fr\"}, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38201,7 +38201,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38238,7 +38238,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38275,7 +38275,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_generic_async_streaming_qps_one_server_core_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"server_type\": \"ASYNC_GENERIC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"bytebuf_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38312,7 +38312,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38349,7 +38349,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_client_sync_server_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 10, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38386,7 +38386,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38423,7 +38423,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38460,7 +38460,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38497,7 +38497,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38534,7 +38534,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38571,7 +38571,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_unary_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"UNARY\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38608,7 +38608,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38645,7 +38645,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38682,7 +38682,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_sync_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"SYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"SYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38719,7 +38719,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"core_limit\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_ping_pong_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 1, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 1, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 1, \"async_client_threads\": 1, \"outstanding_rpcs_per_channel\": 1, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38756,7 +38756,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ @@ -38793,7 +38793,7 @@ { "args": [ "--scenarios_json", - "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"core_limit\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" + "{\"scenarios\": [{\"name\": \"cpp_protobuf_async_streaming_qps_unconstrained_insecure_500kib_resource_quota\", \"warmup_seconds\": 0, \"benchmark_seconds\": 1, \"num_servers\": 1, \"server_config\": {\"resource_quota_size\": 512000, \"async_server_threads\": 0, \"security_params\": null, \"server_type\": \"ASYNC_SERVER\"}, \"num_clients\": 0, \"client_config\": {\"client_type\": \"ASYNC_CLIENT\", \"security_params\": null, \"payload_config\": {\"simple_params\": {\"resp_size\": 0, \"req_size\": 0}}, \"client_channels\": 64, \"async_client_threads\": 0, \"outstanding_rpcs_per_channel\": 100, \"rpc_type\": \"STREAMING\", \"load_params\": {\"closed_loop\": {}}, \"histogram_params\": {\"max_possible\": 60000000000.0, \"resolution\": 0.01}}}]}" ], "boringssl": true, "ci_platforms": [ diff --git a/vsprojects/vcxproj/qps/qps.vcxproj b/vsprojects/vcxproj/qps/qps.vcxproj index 004cf7c9f0e..8b98b5e67c5 100644 --- a/vsprojects/vcxproj/qps/qps.vcxproj +++ b/vsprojects/vcxproj/qps/qps.vcxproj @@ -207,8 +207,6 @@ - - diff --git a/vsprojects/vcxproj/qps/qps.vcxproj.filters b/vsprojects/vcxproj/qps/qps.vcxproj.filters index d3a440ba730..111b133d719 100644 --- a/vsprojects/vcxproj/qps/qps.vcxproj.filters +++ b/vsprojects/vcxproj/qps/qps.vcxproj.filters @@ -25,9 +25,6 @@ test\cpp\qps - - test\cpp\qps - test\cpp\qps From 20ce39a4fe664b73cd271044e59377ee4d91d950 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Wed, 11 Jan 2017 15:44:13 -0800 Subject: [PATCH 172/261] remove limit_cores.h from build.yaml --- build.yaml | 1 - tools/run_tests/generated/sources_and_headers.json | 2 -- vsprojects/vcxproj/qps/qps.vcxproj | 1 - vsprojects/vcxproj/qps/qps.vcxproj.filters | 3 --- 4 files changed, 7 deletions(-) diff --git a/build.yaml b/build.yaml index 8f217682c2a..8f478066f76 100644 --- a/build.yaml +++ b/build.yaml @@ -1289,7 +1289,6 @@ libs: - test/cpp/qps/driver.h - test/cpp/qps/histogram.h - test/cpp/qps/interarrival.h - - test/cpp/qps/limit_cores.h - test/cpp/qps/parse_json.h - test/cpp/qps/qps_worker.h - test/cpp/qps/report.h diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index deadec29a44..8bf9dfd617a 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -5525,7 +5525,6 @@ "test/cpp/qps/driver.h", "test/cpp/qps/histogram.h", "test/cpp/qps/interarrival.h", - "test/cpp/qps/limit_cores.h", "test/cpp/qps/parse_json.h", "test/cpp/qps/qps_worker.h", "test/cpp/qps/report.h", @@ -5545,7 +5544,6 @@ "test/cpp/qps/driver.h", "test/cpp/qps/histogram.h", "test/cpp/qps/interarrival.h", - "test/cpp/qps/limit_cores.h", "test/cpp/qps/parse_json.cc", "test/cpp/qps/parse_json.h", "test/cpp/qps/qps_worker.cc", diff --git a/vsprojects/vcxproj/qps/qps.vcxproj b/vsprojects/vcxproj/qps/qps.vcxproj index 8b98b5e67c5..2d7892683a8 100644 --- a/vsprojects/vcxproj/qps/qps.vcxproj +++ b/vsprojects/vcxproj/qps/qps.vcxproj @@ -151,7 +151,6 @@ - diff --git a/vsprojects/vcxproj/qps/qps.vcxproj.filters b/vsprojects/vcxproj/qps/qps.vcxproj.filters index 111b133d719..f25be9af191 100644 --- a/vsprojects/vcxproj/qps/qps.vcxproj.filters +++ b/vsprojects/vcxproj/qps/qps.vcxproj.filters @@ -60,9 +60,6 @@ test\cpp\qps - - test\cpp\qps - test\cpp\qps From 43dc9ed3b7faf24c02896b2307739630a3c92154 Mon Sep 17 00:00:00 2001 From: yang-g Date: Wed, 11 Jan 2017 16:05:25 -0800 Subject: [PATCH 173/261] Add licenses to all BUILD files and missing copyright --- bazel/BUILD | 31 ++++++++++++++++++++++++++ src/proto/grpc/testing/BUILD | 30 +++++++++++++++++++++++++ src/proto/grpc/testing/duplicate/BUILD | 30 +++++++++++++++++++++++++ test/core/bad_client/BUILD | 2 ++ test/core/bad_ssl/BUILD | 2 ++ test/core/end2end/BUILD | 2 ++ test/core/end2end/fuzzers/BUILD | 2 ++ test/core/http/BUILD | 2 ++ test/core/json/BUILD | 2 ++ test/core/nanopb/BUILD | 2 ++ test/core/transport/chttp2/BUILD | 2 ++ test/core/util/BUILD | 29 ++++++++++++++++++++++++ 12 files changed, 136 insertions(+) diff --git a/bazel/BUILD b/bazel/BUILD index 940a379404f..2d3c576aa0e 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,3 +1,34 @@ +# 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. + +licenses(["notice"]) # 3-clause BSD + package(default_visibility = ["//:__subpackages__"]) load(":cc_grpc_library.bzl", "cc_grpc_library") diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index f9f9cbceaf3..8d5c32d35cb 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -1,3 +1,33 @@ +# 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. + +licenses(["notice"]) # 3-clause BSD package(default_visibility = ["//visibility:public"]) diff --git a/src/proto/grpc/testing/duplicate/BUILD b/src/proto/grpc/testing/duplicate/BUILD index 255e699bec0..f58de9bec69 100644 --- a/src/proto/grpc/testing/duplicate/BUILD +++ b/src/proto/grpc/testing/duplicate/BUILD @@ -1,3 +1,33 @@ +# 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. + +licenses(["notice"]) # 3-clause BSD package(default_visibility = ["//visibility:public"]) diff --git a/test/core/bad_client/BUILD b/test/core/bad_client/BUILD index 5406eb9a4b0..6b06955efe7 100644 --- a/test/core/bad_client/BUILD +++ b/test/core/bad_client/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load(":generate_tests.bzl", "grpc_bad_client_tests") grpc_bad_client_tests() diff --git a/test/core/bad_ssl/BUILD b/test/core/bad_ssl/BUILD index 630733dd4d7..288788a52d3 100644 --- a/test/core/bad_ssl/BUILD +++ b/test/core/bad_ssl/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load(":generate_tests.bzl", "grpc_bad_ssl_tests") grpc_bad_ssl_tests() diff --git a/test/core/end2end/BUILD b/test/core/end2end/BUILD index 681cea1de74..a40fb8e083f 100644 --- a/test/core/end2end/BUILD +++ b/test/core/end2end/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load(":generate_tests.bzl", "grpc_end2end_tests") cc_library( diff --git a/test/core/end2end/fuzzers/BUILD b/test/core/end2end/fuzzers/BUILD index 2adda560b40..4d98aa0725c 100644 --- a/test/core/end2end/fuzzers/BUILD +++ b/test/core/end2end/fuzzers/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( diff --git a/test/core/http/BUILD b/test/core/http/BUILD index 58d265bd8fb..037ede3cd1c 100644 --- a/test/core/http/BUILD +++ b/test/core/http/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( diff --git a/test/core/json/BUILD b/test/core/json/BUILD index 4b3fbd60768..05d4c6e0c5e 100644 --- a/test/core/json/BUILD +++ b/test/core/json/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( diff --git a/test/core/nanopb/BUILD b/test/core/nanopb/BUILD index bdf79b7fefa..b02d750f325 100644 --- a/test/core/nanopb/BUILD +++ b/test/core/nanopb/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( diff --git a/test/core/transport/chttp2/BUILD b/test/core/transport/chttp2/BUILD index 5dd205174f9..94b48301386 100644 --- a/test/core/transport/chttp2/BUILD +++ b/test/core/transport/chttp2/BUILD @@ -27,6 +27,8 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +licenses(["notice"]) # 3-clause BSD + load("//test/core/util:grpc_fuzzer.bzl", "grpc_fuzzer") grpc_fuzzer( diff --git a/test/core/util/BUILD b/test/core/util/BUILD index e50e595d039..e7ed5ea2f59 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -1,4 +1,33 @@ +# 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. +licenses(["notice"]) # 3-clause BSD cc_library( name = "gpr_test_util", From 1ace58c5bc0c816cc61f5592123b1a07110ee7fd Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Wed, 11 Jan 2017 02:13:53 -0800 Subject: [PATCH 174/261] Unit test framework for Cronet --- .../tests/CronetUnitTests/CronetUnitTests.m | 189 ++++++++++++++++ .../tests/CronetUnitTests/Info.plist | 24 +++ src/objective-c/tests/Podfile | 19 +- .../tests/Tests.xcodeproj/project.pbxproj | 204 +++++++++++++++++- .../xcschemes/CronetUnitTests.xcscheme | 56 +++++ 5 files changed, 477 insertions(+), 15 deletions(-) create mode 100644 src/objective-c/tests/CronetUnitTests/CronetUnitTests.m create mode 100644 src/objective-c/tests/CronetUnitTests/Info.plist create mode 100644 src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/CronetUnitTests.xcscheme diff --git a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m new file mode 100644 index 00000000000..3bdcca92503 --- /dev/null +++ b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m @@ -0,0 +1,189 @@ +// +// CronetUnitTest.m +// CronetUnitTest +// +// Created by Muxi Yan on 1/10/17. +// Copyright © 2017 gRPC. All rights reserved. +// + +#import +#import +#import + +#import +#import +#import +#import +#import "test/core/end2end/cq_verifier.h" +#import "test/core/util/port.h" + +#import +#import + +#import "src/core/lib/channel/channel_args.h" +#import "src/core/lib/support/env.h" +#import "src/core/lib/support/string.h" +#import "src/core/lib/support/tmpfile.h" +#import "test/core/util/test_config.h" + +static void drain_cq(grpc_completion_queue *cq) { + grpc_event ev; + do { + ev = grpc_completion_queue_next(cq, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL); + } while (ev.type != GRPC_QUEUE_SHUTDOWN); +} + + +@interface CronetUnitTests : XCTestCase + +@end + +@implementation CronetUnitTests + ++ (void)setUp { + [super setUp]; + +/*** FILE *roots_file; + size_t roots_size = strlen(test_root_cert);*/ + + char *argv[] = {"CoreCronetEnd2EndTests"}; + grpc_test_init(1, argv); + + grpc_init(); + + [Cronet setHttp2Enabled:YES]; + NSURL *url = [[[NSFileManager defaultManager] + URLsForDirectory:NSDocumentDirectory + inDomains:NSUserDomainMask] lastObject]; + NSLog(@"Documents directory: %@", url); + [Cronet start]; + [Cronet startNetLogToFile:@"Documents/cronet_netlog.json" logBytes:YES]; +} + ++ (void)tearDown { + grpc_shutdown(); + + [super tearDown]; +} + +- (void)testInternalError { + grpc_call *c; + grpc_slice request_payload_slice = + grpc_slice_from_copied_string("hello world"); + grpc_byte_buffer *request_payload = + grpc_raw_byte_buffer_create(&request_payload_slice, 1); + gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); + grpc_metadata meta_c[2] = { + {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + + int port = grpc_pick_unused_port_or_die(); + char *addr; + gpr_join_host_port(&addr, "127.0.0.1", port); + grpc_completion_queue *cq = grpc_completion_queue_create(NULL); + cronet_engine *cronetEngine = [Cronet getGlobalEngine]; + grpc_channel *client = grpc_cronet_secure_channel_create(cronetEngine, addr, + NULL, NULL); + + cq_verifier *cqv = cq_verifier_create(cq); + grpc_op ops[6]; + grpc_op *op; + grpc_metadata_array initial_metadata_recv; + grpc_metadata_array trailing_metadata_recv; + grpc_metadata_array request_metadata_recv; + grpc_byte_buffer *response_payload_recv = NULL; + grpc_call_details call_details; + grpc_status_code status; + grpc_call_error error; + char *details = NULL; + size_t details_capacity = 0; + + c = grpc_channel_create_call( + client, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", + NULL, deadline, NULL); + GPR_ASSERT(c); + + grpc_metadata_array_init(&initial_metadata_recv); + grpc_metadata_array_init(&trailing_metadata_recv); + grpc_metadata_array_init(&request_metadata_recv); + grpc_call_details_init(&call_details); + + memset(ops, 0, sizeof(ops)); + op = ops; + op->op = GRPC_OP_SEND_INITIAL_METADATA; + op->data.send_initial_metadata.count = 2; + op->data.send_initial_metadata.metadata = meta_c; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_MESSAGE; + op->data.send_message = request_payload; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_INITIAL_METADATA; + op->data.recv_initial_metadata = &initial_metadata_recv; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_MESSAGE; + op->data.recv_message = &response_payload_recv; + op->flags = 0; + op->reserved = NULL; + op++; + op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; + op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; + op->data.recv_status_on_client.status = &status; + op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; + op->flags = 0; + op->reserved = NULL; + op++; + error = grpc_call_start_batch(c, ops, (size_t)(op - ops), (void*)1, NULL); + GPR_ASSERT(GRPC_CALL_OK == error); + + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ + int sl = socket(AF_INET, SOCK_STREAM, 0); + GPR_ASSERT(sl >= 0); + struct sockaddr_in s_addr; + memset(&s_addr, 0, sizeof(s_addr)); + s_addr.sin_family = AF_INET; + s_addr.sin_addr.s_addr = htonl(INADDR_ANY); + s_addr.sin_port = htons(port); + bind(sl, (struct sockaddr*)&s_addr, sizeof(s_addr)); + listen(sl, 5); + int s = accept(sl, NULL, NULL); + sleep(1); + close(s); + close(sl); + }); + + CQ_EXPECT_COMPLETION(cqv, (void*)1, 1); + cq_verify(cqv); + + GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); + + gpr_free(details); + grpc_metadata_array_destroy(&initial_metadata_recv); + grpc_metadata_array_destroy(&trailing_metadata_recv); + grpc_metadata_array_destroy(&request_metadata_recv); + grpc_call_details_destroy(&call_details); + + grpc_call_destroy(c); + + cq_verifier_destroy(cqv); + + grpc_byte_buffer_destroy(request_payload); + grpc_byte_buffer_destroy(response_payload_recv); + + grpc_channel_destroy(client); + grpc_completion_queue_shutdown(cq); + drain_cq(cq); + grpc_completion_queue_destroy(cq); +} + +@end diff --git a/src/objective-c/tests/CronetUnitTests/Info.plist b/src/objective-c/tests/CronetUnitTests/Info.plist new file mode 100644 index 00000000000..ba72822e872 --- /dev/null +++ b/src/objective-c/tests/CronetUnitTests/Info.plist @@ -0,0 +1,24 @@ + + + + + CFBundleDevelopmentRegion + en + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + BNDL + CFBundleShortVersionString + 1.0 + CFBundleSignature + ???? + CFBundleVersion + 1 + + diff --git a/src/objective-c/tests/Podfile b/src/objective-c/tests/Podfile index 5785b976f2d..3760330be9a 100644 --- a/src/objective-c/tests/Podfile +++ b/src/objective-c/tests/Podfile @@ -37,13 +37,18 @@ GRPC_LOCAL_SRC = '../../..' end end -target 'CoreCronetEnd2EndTests' do - pod 'BoringSSL', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c", :inhibit_warnings => true - pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" - pod 'gRPC-Core', :path => GRPC_LOCAL_SRC - pod 'gRPC-Core/Cronet-Interface', :path => GRPC_LOCAL_SRC - pod 'gRPC-Core/Cronet-Implementation', :path => GRPC_LOCAL_SRC - pod 'gRPC-Core/Tests', :path => GRPC_LOCAL_SRC +%w( + CoreCronetEnd2EndTests + CronetUnitTests +).each do |target_name| + target target_name do + pod 'BoringSSL', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c", :inhibit_warnings => true + pod 'CronetFramework', :podspec => "#{GRPC_LOCAL_SRC}/src/objective-c" + pod 'gRPC-Core', :path => GRPC_LOCAL_SRC + pod 'gRPC-Core/Cronet-Interface', :path => GRPC_LOCAL_SRC + pod 'gRPC-Core/Cronet-Implementation', :path => GRPC_LOCAL_SRC + pod 'gRPC-Core/Tests', :path => GRPC_LOCAL_SRC + end end # gRPC-Core.podspec needs to be modified to be successfully used for local development. A Podfile's diff --git a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj index c4a6567ae0e..4a6b332dfd1 100644 --- a/src/objective-c/tests/Tests.xcodeproj/project.pbxproj +++ b/src/objective-c/tests/Tests.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 06467F3A8D01EC493D12ADA2 /* libPods-CronetUnitTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C6134277D2EB8B380862A03F /* libPods-CronetUnitTests.a */; }; 09B76D9585ACE7403804D9DC /* libPods-InteropTestsRemoteWithCronet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */; }; 0F9232F984C08643FD40C34F /* libPods-InteropTestsRemote.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBE059B4AC7A51919467EEC0 /* libPods-InteropTestsRemote.a */; }; 16A9E77B6E336B3C0B9BA6E0 /* libPods-InteropTestsLocalSSL.a in Frameworks */ = {isa = PBXBuildFile; fileRef = DBEDE45BDA60DF1E1C8950C0 /* libPods-InteropTestsLocalSSL.a */; }; @@ -15,6 +16,8 @@ 3D7C85F6AA68C4A205E3BA16 /* libPods-Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */; }; 5E8A5DA71D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E8A5DA61D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m */; }; 5E8A5DA91D3840B4000F8BC4 /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; }; + 5EAD6D271E27047400002378 /* CronetUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EAD6D261E27047400002378 /* CronetUnitTests.m */; }; + 5EAD6D291E27047400002378 /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; }; 5EE84BF41D4717E40050C6CC /* InteropTestsRemoteWithCronet.m in Sources */ = {isa = PBXBuildFile; fileRef = 5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */; }; 5EE84BF61D4717E40050C6CC /* libTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 635697C71B14FC11007A7283 /* libTests.a */; }; 5EE84BFE1D471D400050C6CC /* InteropTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 635ED2EB1B1A3BC400FDE5C3 /* InteropTests.m */; }; @@ -52,6 +55,13 @@ remoteGlobalIDString = 635697C61B14FC11007A7283; remoteInfo = Tests; }; + 5EAD6D2A1E27047400002378 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 635697BF1B14FC11007A7283 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 635697C61B14FC11007A7283; + remoteInfo = Tests; + }; 5EE84BF71D4717E40050C6CC /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 635697BF1B14FC11007A7283 /* Project object */; @@ -109,6 +119,7 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 02192CF1FF9534E3D18C65FC /* Pods-CronetUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CronetUnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CronetUnitTests/Pods-CronetUnitTests.release.xcconfig"; sourceTree = ""; }; 060EF32D7EC0DF67ED617507 /* Pods-Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-Tests/Pods-Tests.debug.xcconfig"; sourceTree = ""; }; 07D10A965323BEA7FE59A74B /* Pods-RxLibraryUnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLibraryUnitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests.debug.xcconfig"; sourceTree = ""; }; 0A4F89D9C90E9C30990218F0 /* Pods.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.release.xcconfig; path = "Pods/Target Support Files/Pods/Pods.release.xcconfig"; sourceTree = ""; }; @@ -117,6 +128,7 @@ 17F60BF2871F6AF85FB3FA12 /* Pods-InteropTestsRemoteWithCronet.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsRemoteWithCronet.debug.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet.debug.xcconfig"; sourceTree = ""; }; 20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 35F2B6BF3BAE8F0DC4AFD76E /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 386712AEACF7C2190C4B8B3F /* Pods-CronetUnitTests.cronet.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CronetUnitTests.cronet.xcconfig"; path = "Pods/Target Support Files/Pods-CronetUnitTests/Pods-CronetUnitTests.cronet.xcconfig"; sourceTree = ""; }; 3B0861FC805389C52DB260D4 /* Pods-RxLibraryUnitTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLibraryUnitTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests.release.xcconfig"; sourceTree = ""; }; 3F27B2E744482771EB93C394 /* Pods-InteropTestsRemoteWithCronet.cronet.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsRemoteWithCronet.cronet.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet.cronet.xcconfig"; sourceTree = ""; }; 4AD97096D13D7416DC91A72A /* Pods-CoreCronetEnd2EndTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CoreCronetEnd2EndTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-CoreCronetEnd2EndTests/Pods-CoreCronetEnd2EndTests.release.xcconfig"; sourceTree = ""; }; @@ -127,6 +139,9 @@ 5761E98978DDDF136A58CB7E /* Pods-AllTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AllTests.release.xcconfig"; path = "Pods/Target Support Files/Pods-AllTests/Pods-AllTests.release.xcconfig"; sourceTree = ""; }; 5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CoreCronetEnd2EndTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 5E8A5DA61D3840B4000F8BC4 /* CoreCronetEnd2EndTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CoreCronetEnd2EndTests.m; sourceTree = ""; }; + 5EAD6D241E27047400002378 /* CronetUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CronetUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; + 5EAD6D261E27047400002378 /* CronetUnitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = CronetUnitTests.m; sourceTree = ""; }; + 5EAD6D281E27047400002378 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 5EE84BF11D4717E40050C6CC /* InteropTestsRemoteWithCronet.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = InteropTestsRemoteWithCronet.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 5EE84BF31D4717E40050C6CC /* InteropTestsRemoteWithCronet.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = InteropTestsRemoteWithCronet.m; sourceTree = ""; }; 5EE84BF51D4717E40050C6CC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -146,6 +161,7 @@ 63E240CC1B6C4D3A005F3B0E /* InteropTests.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InteropTests.h; sourceTree = ""; }; 63E240CD1B6C4E2B005F3B0E /* InteropTestsLocalSSL.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = InteropTestsLocalSSL.m; sourceTree = ""; }; 63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.plug-in"; path = TestCertificates.bundle; sourceTree = ""; }; + 64F68A9A6A63CC930DD30A6E /* Pods-CronetUnitTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-CronetUnitTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-CronetUnitTests/Pods-CronetUnitTests.debug.xcconfig"; sourceTree = ""; }; 79C68EFFCB5533475D810B79 /* Pods-RxLibraryUnitTests.cronet.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-RxLibraryUnitTests.cronet.xcconfig"; path = "Pods/Target Support Files/Pods-RxLibraryUnitTests/Pods-RxLibraryUnitTests.cronet.xcconfig"; sourceTree = ""; }; 7A2E97E3F469CC2A758D77DE /* Pods-InteropTestsLocalSSL.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsLocalSSL.release.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsLocalSSL/Pods-InteropTestsLocalSSL.release.xcconfig"; sourceTree = ""; }; 9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InteropTestsRemoteWithCronet.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -153,6 +169,7 @@ AA7CB64B4DD9915AE7C03163 /* Pods-InteropTestsLocalCleartext.cronet.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsLocalCleartext.cronet.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsLocalCleartext/Pods-InteropTestsLocalCleartext.cronet.xcconfig"; sourceTree = ""; }; AC414EF7A6BF76ED02B6E480 /* Pods-InteropTestsRemoteWithCronet.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-InteropTestsRemoteWithCronet.release.xcconfig"; path = "Pods/Target Support Files/Pods-InteropTestsRemoteWithCronet/Pods-InteropTestsRemoteWithCronet.release.xcconfig"; sourceTree = ""; }; B94C27C06733CF98CE1B2757 /* Pods-AllTests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-AllTests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-AllTests/Pods-AllTests.debug.xcconfig"; sourceTree = ""; }; + C6134277D2EB8B380862A03F /* libPods-CronetUnitTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-CronetUnitTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; CAE086D5B470DA367D415AB0 /* libPods-AllTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-AllTests.a"; sourceTree = BUILT_PRODUCTS_DIR; }; DBE059B4AC7A51919467EEC0 /* libPods-InteropTestsRemote.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InteropTestsRemote.a"; sourceTree = BUILT_PRODUCTS_DIR; }; DBEDE45BDA60DF1E1C8950C0 /* libPods-InteropTestsLocalSSL.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-InteropTestsLocalSSL.a"; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -177,6 +194,15 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5EAD6D211E27047400002378 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EAD6D291E27047400002378 /* libTests.a in Frameworks */, + 06467F3A8D01EC493D12ADA2 /* libPods-CronetUnitTests.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 5EE84BEE1D4717E40050C6CC /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -254,6 +280,7 @@ 20DFF2F3C97EF098FE5A3171 /* libPods-Tests.a */, FBD98AC417B9882D32B19F28 /* libPods-CoreCronetEnd2EndTests.a */, 9E9444C764F0FFF64A7EB58E /* libPods-InteropTestsRemoteWithCronet.a */, + C6134277D2EB8B380862A03F /* libPods-CronetUnitTests.a */, ); name = Frameworks; sourceTree = ""; @@ -287,6 +314,9 @@ 3F27B2E744482771EB93C394 /* Pods-InteropTestsRemoteWithCronet.cronet.xcconfig */, 79C68EFFCB5533475D810B79 /* Pods-RxLibraryUnitTests.cronet.xcconfig */, F671D4CAD2864FB203B920B4 /* Pods-Tests.cronet.xcconfig */, + 64F68A9A6A63CC930DD30A6E /* Pods-CronetUnitTests.debug.xcconfig */, + 386712AEACF7C2190C4B8B3F /* Pods-CronetUnitTests.cronet.xcconfig */, + 02192CF1FF9534E3D18C65FC /* Pods-CronetUnitTests.release.xcconfig */, ); name = Pods; sourceTree = ""; @@ -299,6 +329,15 @@ path = CoreCronetEnd2EndTests; sourceTree = ""; }; + 5EAD6D251E27047400002378 /* CronetUnitTests */ = { + isa = PBXGroup; + children = ( + 5EAD6D261E27047400002378 /* CronetUnitTests.m */, + 5EAD6D281E27047400002378 /* Info.plist */, + ); + path = CronetUnitTests; + sourceTree = ""; + }; 5EE84BF21D4717E40050C6CC /* InteropTestsRemoteWithCronet */ = { isa = PBXGroup; children = ( @@ -315,6 +354,7 @@ 63E240CF1B6C63DC005F3B0E /* TestCertificates.bundle */, 5E8A5DA51D3840B4000F8BC4 /* CoreCronetEnd2EndTests */, 5EE84BF21D4717E40050C6CC /* InteropTestsRemoteWithCronet */, + 5EAD6D251E27047400002378 /* CronetUnitTests */, 635697C81B14FC11007A7283 /* Products */, 51E4650F34F854F41FF053B3 /* Pods */, 136D535E19727099B941D7B1 /* Frameworks */, @@ -332,6 +372,7 @@ 63DC84431BE152B5000708E8 /* InteropTestsLocalCleartext.xctest */, 5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */, 5EE84BF11D4717E40050C6CC /* InteropTestsRemoteWithCronet.xctest */, + 5EAD6D241E27047400002378 /* CronetUnitTests.xctest */, ); name = Products; sourceTree = ""; @@ -384,6 +425,27 @@ productReference = 5E8A5DA41D3840B4000F8BC4 /* CoreCronetEnd2EndTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; + 5EAD6D231E27047400002378 /* CronetUnitTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 5EAD6D2F1E27047400002378 /* Build configuration list for PBXNativeTarget "CronetUnitTests" */; + buildPhases = ( + 80E2DDD2EC04A4009F45E933 /* [CP] Check Pods Manifest.lock */, + 5EAD6D201E27047400002378 /* Sources */, + 5EAD6D211E27047400002378 /* Frameworks */, + 5EAD6D221E27047400002378 /* Resources */, + A686B9967BB4CB81B1CBF8F8 /* [CP] Embed Pods Frameworks */, + 051806D6A59B19C8A0B76BED /* [CP] Copy Pods Resources */, + ); + buildRules = ( + ); + dependencies = ( + 5EAD6D2B1E27047400002378 /* PBXTargetDependency */, + ); + name = CronetUnitTests; + productName = CronetUnitTests; + productReference = 5EAD6D241E27047400002378 /* CronetUnitTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; 5EE84BF01D4717E40050C6CC /* InteropTestsRemoteWithCronet */ = { isa = PBXNativeTarget; buildConfigurationList = 5EE84BFB1D4717E40050C6CC /* Build configuration list for PBXNativeTarget "InteropTestsRemoteWithCronet" */; @@ -541,6 +603,9 @@ 5E8A5DA31D3840B4000F8BC4 = { CreatedOnToolsVersion = 7.3.1; }; + 5EAD6D231E27047400002378 = { + CreatedOnToolsVersion = 7.3.1; + }; 5EE84BF01D4717E40050C6CC = { CreatedOnToolsVersion = 7.3.1; }; @@ -584,6 +649,7 @@ 63DC84421BE152B5000708E8 /* InteropTestsLocalCleartext */, 5E8A5DA31D3840B4000F8BC4 /* CoreCronetEnd2EndTests */, 5EE84BF01D4717E40050C6CC /* InteropTestsRemoteWithCronet */, + 5EAD6D231E27047400002378 /* CronetUnitTests */, ); }; /* End PBXProject section */ @@ -596,6 +662,13 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5EAD6D221E27047400002378 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; 5EE84BEF1D4717E40050C6CC /* Resources */ = { isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; @@ -643,6 +716,21 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 051806D6A59B19C8A0B76BED /* [CP] Copy Pods Resources */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Copy Pods Resources"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CronetUnitTests/Pods-CronetUnitTests-resources.sh\"\n"; + showEnvVarsInLog = 0; + }; 31F8D1C407195CBF0C02929B /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -670,7 +758,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 4F5690DC0E6AD6663FE78B8B /* [CP] Embed Pods Frameworks */ = { @@ -700,7 +788,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 5F14F59509E10C2852014F9E /* [CP] Embed Pods Frameworks */ = { @@ -760,7 +848,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 796680C7599CB4ED736DD62A /* [CP] Check Pods Manifest.lock */ = { @@ -775,7 +863,22 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; + showEnvVarsInLog = 0; + }; + 80E2DDD2EC04A4009F45E933 /* [CP] Check Pods Manifest.lock */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Check Pods Manifest.lock"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; 8AD3130D3C58A0FB32FF2A36 /* [CP] Copy Pods Resources */ = { @@ -820,7 +923,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; A441F71824DCB9D0CA297748 /* [CP] Copy Pods Resources */ = { @@ -838,6 +941,21 @@ shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-AllTests/Pods-AllTests-resources.sh\"\n"; showEnvVarsInLog = 0; }; + A686B9967BB4CB81B1CBF8F8 /* [CP] Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "[CP] Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-CronetUnitTests/Pods-CronetUnitTests-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; A8E3AC66DF770B774114A30E /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; @@ -880,7 +998,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; C0F7B1FF6F88CC5FBF362F4C /* [CP] Check Pods Manifest.lock */ = { @@ -895,7 +1013,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; C2E09DC4BD239F71160F0CC1 /* [CP] Copy Pods Resources */ = { @@ -985,7 +1103,7 @@ ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; + shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n"; showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -999,6 +1117,14 @@ ); runOnlyForDeploymentPostprocessing = 0; }; + 5EAD6D201E27047400002378 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 5EAD6D271E27047400002378 /* CronetUnitTests.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 5EE84BED1D4717E40050C6CC /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -1073,6 +1199,11 @@ target = 635697C61B14FC11007A7283 /* Tests */; targetProxy = 5E8A5DAA1D3840B4000F8BC4 /* PBXContainerItemProxy */; }; + 5EAD6D2B1E27047400002378 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 635697C61B14FC11007A7283 /* Tests */; + targetProxy = 5EAD6D2A1E27047400002378 /* PBXContainerItemProxy */; + }; 5EE84BF81D4717E40050C6CC /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 635697C61B14FC11007A7283 /* Tests */; @@ -1138,6 +1269,53 @@ }; name = Release; }; + 5EAD6D2C1E27047400002378 /* Debug */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 64F68A9A6A63CC930DD30A6E /* Pods-CronetUnitTests.debug.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_TESTABILITY = YES; + INFOPLIST_FILE = CronetUnitTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.grpc.CronetUnitTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + USER_HEADER_SEARCH_PATHS = "\"${PODS_ROOT}/../../../..\" $(inherited)"; + }; + name = Debug; + }; + 5EAD6D2D1E27047400002378 /* Cronet */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 386712AEACF7C2190C4B8B3F /* Pods-CronetUnitTests.cronet.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + INFOPLIST_FILE = CronetUnitTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.grpc.CronetUnitTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + USER_HEADER_SEARCH_PATHS = "\"${PODS_ROOT}/../../../..\" $(inherited)"; + }; + name = Cronet; + }; + 5EAD6D2E1E27047400002378 /* Release */ = { + isa = XCBuildConfiguration; + baseConfigurationReference = 02192CF1FF9534E3D18C65FC /* Pods-CronetUnitTests.release.xcconfig */; + buildSettings = { + CLANG_ANALYZER_NONNULL = YES; + "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; + INFOPLIST_FILE = CronetUnitTests/Info.plist; + IPHONEOS_DEPLOYMENT_TARGET = 9.3; + LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; + PRODUCT_BUNDLE_IDENTIFIER = io.grpc.CronetUnitTests; + PRODUCT_NAME = "$(TARGET_NAME)"; + USER_HEADER_SEARCH_PATHS = "\"${PODS_ROOT}/../../../..\" $(inherited)"; + }; + name = Release; + }; 5EC3C7A01D4FC18C000330E2 /* Cronet */ = { isa = XCBuildConfiguration; buildSettings = { @@ -1597,6 +1775,16 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; + 5EAD6D2F1E27047400002378 /* Build configuration list for PBXNativeTarget "CronetUnitTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 5EAD6D2C1E27047400002378 /* Debug */, + 5EAD6D2D1E27047400002378 /* Cronet */, + 5EAD6D2E1E27047400002378 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; 5EE84BFB1D4717E40050C6CC /* Build configuration list for PBXNativeTarget "InteropTestsRemoteWithCronet" */ = { isa = XCConfigurationList; buildConfigurations = ( diff --git a/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/CronetUnitTests.xcscheme b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/CronetUnitTests.xcscheme new file mode 100644 index 00000000000..ea711e09e97 --- /dev/null +++ b/src/objective-c/tests/Tests.xcodeproj/xcshareddata/xcschemes/CronetUnitTests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + From a2341eaed05cb5713dc95ff52fe59730a006f389 Mon Sep 17 00:00:00 2001 From: yang-g Date: Wed, 11 Jan 2017 23:01:24 -0800 Subject: [PATCH 175/261] omg it is 2017 --- bazel/BUILD | 2 +- src/proto/grpc/testing/BUILD | 2 +- src/proto/grpc/testing/duplicate/BUILD | 2 +- test/core/util/BUILD | 2 +- tools/distrib/check_copyright.py | 1 + 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bazel/BUILD b/bazel/BUILD index 2d3c576aa0e..fe776b20ef2 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -1,4 +1,4 @@ -# Copyright 2016, Google Inc. +# Copyright 2017, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD index 8d5c32d35cb..283740839d9 100644 --- a/src/proto/grpc/testing/BUILD +++ b/src/proto/grpc/testing/BUILD @@ -1,4 +1,4 @@ -# Copyright 2016, Google Inc. +# Copyright 2017, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/src/proto/grpc/testing/duplicate/BUILD b/src/proto/grpc/testing/duplicate/BUILD index f58de9bec69..8fc5a96af40 100644 --- a/src/proto/grpc/testing/duplicate/BUILD +++ b/src/proto/grpc/testing/duplicate/BUILD @@ -1,4 +1,4 @@ -# Copyright 2016, Google Inc. +# Copyright 2017, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/test/core/util/BUILD b/test/core/util/BUILD index e7ed5ea2f59..8769683b23a 100644 --- a/test/core/util/BUILD +++ b/test/core/util/BUILD @@ -1,4 +1,4 @@ -# Copyright 2016, Google Inc. +# Copyright 2017, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without diff --git a/tools/distrib/check_copyright.py b/tools/distrib/check_copyright.py index 718bb563f3a..c993407eb24 100755 --- a/tools/distrib/check_copyright.py +++ b/tools/distrib/check_copyright.py @@ -90,6 +90,7 @@ LICENSE_PREFIX = { 'Makefile': r'#\s*', 'Dockerfile': r'#\s*', 'LICENSE': '', + 'BUILD': r'#\s*', } _EXEMPT = frozenset(( From 62a7ca8c9516b071593e7cea63d3466678589085 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Thu, 12 Jan 2017 11:32:15 -0800 Subject: [PATCH 176/261] re-run clang-format.sh --- test/cpp/qps/driver.cc | 7 ++++--- test/cpp/qps/qps_json_driver.cc | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/cpp/qps/driver.cc b/test/cpp/qps/driver.cc index 7494ced460e..74fe3662c1c 100644 --- a/test/cpp/qps/driver.cc +++ b/test/cpp/qps/driver.cc @@ -262,8 +262,9 @@ std::unique_ptr RunScenario( CreateChannel(workers[i], InsecureChannelCredentials())); ServerConfig server_config = initial_server_config; - if(server_config.core_limit() != 0) { - gpr_log(GPR_ERROR, "server config core limit is set but ignored by driver"); + if (server_config.core_limit() != 0) { + gpr_log(GPR_ERROR, + "server config core limit is set but ignored by driver"); } ServerArgs args; @@ -308,7 +309,7 @@ std::unique_ptr RunScenario( CreateChannel(worker, InsecureChannelCredentials())); ClientConfig per_client_config = client_config; - if(initial_client_config.core_limit() != 0) { + if (initial_client_config.core_limit() != 0) { gpr_log(GPR_ERROR, "client config core limit set but ignored"); } diff --git a/test/cpp/qps/qps_json_driver.cc b/test/cpp/qps/qps_json_driver.cc index ca4c6865784..db77a827468 100644 --- a/test/cpp/qps/qps_json_driver.cc +++ b/test/cpp/qps/qps_json_driver.cc @@ -77,12 +77,12 @@ namespace testing { static std::unique_ptr RunAndReport(const Scenario& scenario, bool* success) { std::cerr << "RUNNING SCENARIO: " << scenario.name() << "\n"; - auto result = RunScenario( - scenario.client_config(), scenario.num_clients(), - scenario.server_config(), scenario.num_servers(), - scenario.warmup_seconds(), scenario.benchmark_seconds(), - scenario.spawn_local_worker_count(), - FLAGS_qps_server_target_override.c_str()); + auto result = + RunScenario(scenario.client_config(), scenario.num_clients(), + scenario.server_config(), scenario.num_servers(), + scenario.warmup_seconds(), scenario.benchmark_seconds(), + scenario.spawn_local_worker_count(), + FLAGS_qps_server_target_override.c_str()); // Amend the result with scenario config. Eventually we should adjust // RunScenario contract so we don't need to touch the result here. From 95beab22843369189836828a0116a9760482ce7f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 13:41:52 -0800 Subject: [PATCH 177/261] Uncover the badness --- src/core/lib/iomgr/closure.c | 1 + src/core/lib/iomgr/closure.h | 1 + src/core/lib/iomgr/combiner.c | 12 ++++++---- src/core/lib/iomgr/ev_epoll_linux.c | 2 +- src/core/lib/iomgr/exec_ctx.c | 2 +- src/core/lib/iomgr/executor.c | 4 ++-- .../credentials/plugin/plugin_credentials.c | 11 +++++---- .../security/transport/client_auth_filter.c | 24 +++++-------------- src/cpp/client/secure_credentials.h | 2 +- src/cpp/server/dynamic_thread_pool.cc | 9 ++++++- test/cpp/end2end/end2end_test.cc | 1 + 11 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/core/lib/iomgr/closure.c b/src/core/lib/iomgr/closure.c index da0ec878a39..8e4efd3370d 100644 --- a/src/core/lib/iomgr/closure.c +++ b/src/core/lib/iomgr/closure.c @@ -34,6 +34,7 @@ #include "src/core/lib/iomgr/closure.h" #include +#include #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index ee386fbc767..6748b21e59c 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -66,6 +66,7 @@ typedef struct grpc_closure_scheduler_vtable { grpc_error *error); void (*sched)(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error); + const char *name; } grpc_closure_scheduler_vtable; /** Abstract type that can schedule closures for execution */ diff --git a/src/core/lib/iomgr/combiner.c b/src/core/lib/iomgr/combiner.c index c26a73b2b71..ba6c7087a92 100644 --- a/src/core/lib/iomgr/combiner.c +++ b/src/core/lib/iomgr/combiner.c @@ -86,13 +86,17 @@ static void combiner_finally_exec_covered(grpc_exec_ctx *exec_ctx, grpc_error *error); static const grpc_closure_scheduler_vtable scheduler_uncovered = { - combiner_exec_uncovered, combiner_exec_uncovered}; + combiner_exec_uncovered, combiner_exec_uncovered, + "combiner:immediately:uncovered"}; static const grpc_closure_scheduler_vtable scheduler_covered = { - combiner_exec_covered, combiner_exec_covered}; + combiner_exec_covered, combiner_exec_covered, + "combiner:immediately:covered"}; static const grpc_closure_scheduler_vtable finally_scheduler_uncovered = { - combiner_finally_exec_uncovered, combiner_finally_exec_uncovered}; + combiner_finally_exec_uncovered, combiner_finally_exec_uncovered, + "combiner:finally:uncovered"}; static const grpc_closure_scheduler_vtable finally_scheduler_covered = { - combiner_finally_exec_covered, combiner_finally_exec_covered}; + combiner_finally_exec_covered, combiner_finally_exec_covered, + "combiner:finally:covered"}; static void offload(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error); diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index d6664aead2e..39b5c0032e8 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -321,7 +321,7 @@ gpr_atm g_epoll_sync; #endif /* defined(GRPC_TSAN) */ static const grpc_closure_scheduler_vtable workqueue_scheduler_vtable = { - workqueue_enqueue, workqueue_enqueue}; + workqueue_enqueue, workqueue_enqueue, "workqueue"}; static void pi_add_ref(polling_island *pi); static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi); diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c index 6aa788f8e5f..fabe6c69887 100644 --- a/src/core/lib/iomgr/exec_ctx.c +++ b/src/core/lib/iomgr/exec_ctx.c @@ -101,6 +101,6 @@ void grpc_exec_ctx_global_init(void) {} void grpc_exec_ctx_global_shutdown(void) {} static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { - exec_ctx_run, exec_ctx_sched}; + exec_ctx_run, exec_ctx_sched, "exec_ctx"}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; grpc_closure_scheduler *grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; diff --git a/src/core/lib/iomgr/executor.c b/src/core/lib/iomgr/executor.c index 852775564f6..a5b62aa8888 100644 --- a/src/core/lib/iomgr/executor.c +++ b/src/core/lib/iomgr/executor.c @@ -158,7 +158,7 @@ void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx) { gpr_mu_destroy(&g_executor.mu); } -static const grpc_closure_scheduler_vtable executor_vtable = {executor_push, - executor_push}; +static const grpc_closure_scheduler_vtable executor_vtable = { + executor_push, executor_push, "executor"}; static grpc_closure_scheduler executor_scheduler = {&executor_vtable}; grpc_closure_scheduler *grpc_executor_scheduler = &executor_scheduler; diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index c5e8d67039d..afce6a6b12c 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -44,6 +44,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/api_trace.h" +#include "src/core/lib/surface/validate_metadata.h" typedef struct { void *user_data; @@ -78,14 +79,14 @@ static void plugin_md_request_metadata_ready(void *request, bool seen_illegal_header = false; grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md[i].key)) { - char *key = grpc_slice_to_c_string(md[i].key); - gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", key); - gpr_free(key); + if (!GRPC_LOG_IF_ERROR("validate_metadata_from_plugin", + grpc_validate_header_key_is_legal(md[i].key))) { seen_illegal_header = true; break; } else if (!grpc_is_binary_header(md[i].key) && - !grpc_header_nonbin_value_is_legal(md[i].value)) { + !GRPC_LOG_IF_ERROR( + "validate_metadata_from_plugin", + grpc_validate_header_nonbin_value_is_legal(md[i].value))) { gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); seen_illegal_header = true; break; diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index cf7de493458..cf056e80080 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -123,24 +123,12 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, GPR_ASSERT(op->send_initial_metadata != NULL); mdb = op->send_initial_metadata; for (i = 0; i < num_md; i++) { - if (!grpc_header_key_is_legal(md_elems[i].key)) { - char *str = grpc_slice_to_c_string(md_elems[i].key); - gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", str); - gpr_free(str); - } else if (!grpc_is_binary_header(md_elems[i].key) && - !grpc_header_nonbin_value_is_legal(md_elems[i].value)) { - char *str = - grpc_dump_slice(md_elems[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_ERROR, "attempt to send invalid metadata value: %s", str); - gpr_free(str); - } else { - add_error(&error, - grpc_metadata_batch_add_tail( - exec_ctx, mdb, &calld->md_links[i], - grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value)))); - } + add_error(&error, + grpc_metadata_batch_add_tail( + exec_ctx, mdb, &calld->md_links[i], + grpc_mdelem_from_slices( + exec_ctx, grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value)))); } } if (error == GRPC_ERROR_NONE) { diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 281db17e983..713654ad5ba 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -70,7 +70,7 @@ class SecureCallCredentials final : public CallCredentials { grpc_call_credentials* const c_creds_; }; -class MetadataCredentialsPluginWrapper final { +class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { public: static void Destroy(void* wrapper); static void GetMetadata(void* wrapper, grpc_auth_metadata_context context, diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 1fdc2edb259..e7721bc9902 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -31,12 +31,16 @@ * */ +#include "src/cpp/server/dynamic_thread_pool.h" + #include #include -#include "src/cpp/server/dynamic_thread_pool.h" +#include namespace grpc { +static thread_local bool g_is_dynamic_thread_pool_thread; + DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, @@ -47,6 +51,7 @@ DynamicThreadPool::DynamicThread::~DynamicThread() { } void DynamicThreadPool::DynamicThread::ThreadFunc() { + g_is_dynamic_thread_pool_thread = true; pool_->ThreadFunc(); // Now that we have killed ourselves, we should reduce the thread count std::unique_lock lock(pool_->mu_); @@ -99,11 +104,13 @@ DynamicThreadPool::DynamicThreadPool(int reserve_threads) void DynamicThreadPool::ReapThreads(std::list* tlist) { for (auto t = tlist->begin(); t != tlist->end(); t = tlist->erase(t)) { + gpr_log(GPR_DEBUG, "delete %p", *t); delete *t; } } DynamicThreadPool::~DynamicThreadPool() { + GPR_ASSERT(!g_is_dynamic_thread_pool_thread); std::unique_lock lock(mu_); shutdown_ = true; cv_.notify_all(); diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index 620b3ae7bcb..dff5c3d9ecd 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -1302,6 +1302,7 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { EXPECT_FALSE(s.ok()); EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); } + TEST_P(SecureEnd2endTest, SetPerCallCredentials) { ResetStub(); EchoRequest request; From 85e15a0bdedf18928dd19735c590bd59ddd4e831 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 13:42:41 -0800 Subject: [PATCH 178/261] Spam cleanup --- src/cpp/server/dynamic_thread_pool.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index e7721bc9902..0361768c04e 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -104,7 +104,6 @@ DynamicThreadPool::DynamicThreadPool(int reserve_threads) void DynamicThreadPool::ReapThreads(std::list* tlist) { for (auto t = tlist->begin(); t != tlist->end(); t = tlist->erase(t)) { - gpr_log(GPR_DEBUG, "delete %p", *t); delete *t; } } From 45d318351b398ed2231f82988af88ee13befaff4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 13:45:42 -0800 Subject: [PATCH 179/261] Kill ESAN --- Makefile | 178 ++++++++++--------------- build.yaml | 30 ----- src/core/lib/iomgr/exec_ctx.h | 10 -- tools/run_tests/generated/configs.json | 72 ++++------ tools/run_tests/generated/tests.json | 102 -------------- 5 files changed, 101 insertions(+), 291 deletions(-) diff --git a/Makefile b/Makefile index fcaba06e1e0..dd63fe2dcef 100644 --- a/Makefile +++ b/Makefile @@ -95,56 +95,6 @@ LDXX_opt = $(DEFAULT_CXX) CPPFLAGS_opt = -O2 DEFINES_opt = NDEBUG -VALID_CONFIG_asan-trace-cmp = 1 -REQUIRE_CUSTOM_LIBRARIES_asan-trace-cmp = 1 -CC_asan-trace-cmp = clang -CXX_asan-trace-cmp = clang++ -LD_asan-trace-cmp = clang -LDXX_asan-trace-cmp = clang++ -CPPFLAGS_asan-trace-cmp = -O0 -fsanitize-coverage=edge -fsanitize-coverage=trace-cmp -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_asan-trace-cmp = -fsanitize=address -DEFINES_asan-trace-cmp += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_dbg = 1 -CC_dbg = $(DEFAULT_CC) -CXX_dbg = $(DEFAULT_CXX) -LD_dbg = $(DEFAULT_CC) -LDXX_dbg = $(DEFAULT_CXX) -CPPFLAGS_dbg = -O0 -DEFINES_dbg = _DEBUG DEBUG - -VALID_CONFIG_easan = 1 -REQUIRE_CUSTOM_LIBRARIES_easan = 1 -CC_easan = clang -CXX_easan = clang++ -LD_easan = clang -LDXX_easan = clang++ -CPPFLAGS_easan = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_easan = -fsanitize=address -DEFINES_easan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER -DEFINES_easan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_asan = 1 -REQUIRE_CUSTOM_LIBRARIES_asan = 1 -CC_asan = clang -CXX_asan = clang++ -LD_asan = clang -LDXX_asan = clang++ -CPPFLAGS_asan = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_asan = -fsanitize=address -DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - -VALID_CONFIG_msan = 1 -REQUIRE_CUSTOM_LIBRARIES_msan = 1 -CC_msan = clang -CXX_msan = clang++ -LD_msan = clang -LDXX_msan = clang++ -CPPFLAGS_msan = -O0 -fsanitize-coverage=edge -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) -DEFINES_msan = NDEBUG -DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 - VALID_CONFIG_basicprof = 1 CC_basicprof = $(DEFAULT_CC) CXX_basicprof = $(DEFAULT_CXX) @@ -173,35 +123,23 @@ CPPFLAGS_asan-noleaks = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omi LDFLAGS_asan-noleaks = -fsanitize=address DEFINES_asan-noleaks += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 -VALID_CONFIG_edbg = 1 -CC_edbg = $(DEFAULT_CC) -CXX_edbg = $(DEFAULT_CXX) -LD_edbg = $(DEFAULT_CC) -LDXX_edbg = $(DEFAULT_CXX) -CPPFLAGS_edbg = -O0 -DEFINES_edbg = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER - -VALID_CONFIG_ubsan = 1 -REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 -CC_ubsan = clang -CXX_ubsan = clang++ -LD_ubsan = clang -LDXX_ubsan = clang++ -CPPFLAGS_ubsan = -O0 -fsanitize-coverage=edge -fsanitize=undefined,unsigned-integer-overflow -fno-omit-frame-pointer -Wno-unused-command-line-argument -Wvarargs -LDFLAGS_ubsan = -fsanitize=undefined,unsigned-integer-overflow -DEFINES_ubsan = NDEBUG -DEFINES_ubsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=1.5 +VALID_CONFIG_asan-trace-cmp = 1 +REQUIRE_CUSTOM_LIBRARIES_asan-trace-cmp = 1 +CC_asan-trace-cmp = clang +CXX_asan-trace-cmp = clang++ +LD_asan-trace-cmp = clang +LDXX_asan-trace-cmp = clang++ +CPPFLAGS_asan-trace-cmp = -O0 -fsanitize-coverage=edge -fsanitize-coverage=trace-cmp -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_asan-trace-cmp = -fsanitize=address +DEFINES_asan-trace-cmp += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 -VALID_CONFIG_tsan = 1 -REQUIRE_CUSTOM_LIBRARIES_tsan = 1 -CC_tsan = clang -CXX_tsan = clang++ -LD_tsan = clang -LDXX_tsan = clang++ -CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_tsan = -fsanitize=thread -DEFINES_tsan = GRPC_TSAN -DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 +VALID_CONFIG_dbg = 1 +CC_dbg = $(DEFAULT_CC) +CXX_dbg = $(DEFAULT_CXX) +LD_dbg = $(DEFAULT_CC) +LDXX_dbg = $(DEFAULT_CXX) +CPPFLAGS_dbg = -O0 +DEFINES_dbg = _DEBUG DEBUG VALID_CONFIG_stapprof = 1 CC_stapprof = $(DEFAULT_CC) @@ -211,14 +149,14 @@ LDXX_stapprof = $(DEFAULT_CXX) CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER DEFINES_stapprof = NDEBUG -VALID_CONFIG_mutrace = 1 -CC_mutrace = $(DEFAULT_CC) -CXX_mutrace = $(DEFAULT_CXX) -LD_mutrace = $(DEFAULT_CC) -LDXX_mutrace = $(DEFAULT_CXX) -CPPFLAGS_mutrace = -O3 -fno-omit-frame-pointer -LDFLAGS_mutrace = -rdynamic -DEFINES_mutrace = NDEBUG +VALID_CONFIG_gcov = 1 +CC_gcov = gcc +CXX_gcov = g++ +LD_gcov = gcc +LDXX_gcov = g++ +CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type +LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic +DEFINES_gcov = _DEBUG DEBUG GPR_GCOV VALID_CONFIG_memcheck = 1 CC_memcheck = $(DEFAULT_CC) @@ -230,25 +168,57 @@ LDFLAGS_memcheck = -rdynamic DEFINES_memcheck = _DEBUG DEBUG DEFINES_memcheck += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 -VALID_CONFIG_etsan = 1 -REQUIRE_CUSTOM_LIBRARIES_etsan = 1 -CC_etsan = clang -CXX_etsan = clang++ -LD_etsan = clang -LDXX_etsan = clang++ -CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_etsan = -fsanitize=thread -DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER -DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 +VALID_CONFIG_asan = 1 +REQUIRE_CUSTOM_LIBRARIES_asan = 1 +CC_asan = clang +CXX_asan = clang++ +LD_asan = clang +LDXX_asan = clang++ +CPPFLAGS_asan = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_asan = -fsanitize=address +DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 -VALID_CONFIG_gcov = 1 -CC_gcov = gcc -CXX_gcov = g++ -LD_gcov = gcc -LDXX_gcov = g++ -CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type -LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic -DEFINES_gcov = _DEBUG DEBUG GPR_GCOV +VALID_CONFIG_tsan = 1 +REQUIRE_CUSTOM_LIBRARIES_tsan = 1 +CC_tsan = clang +CXX_tsan = clang++ +LD_tsan = clang +LDXX_tsan = clang++ +CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_tsan = -fsanitize=thread +DEFINES_tsan = GRPC_TSAN +DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 + +VALID_CONFIG_ubsan = 1 +REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 +CC_ubsan = clang +CXX_ubsan = clang++ +LD_ubsan = clang +LDXX_ubsan = clang++ +CPPFLAGS_ubsan = -O0 -fsanitize-coverage=edge -fsanitize=undefined,unsigned-integer-overflow -fno-omit-frame-pointer -Wno-unused-command-line-argument -Wvarargs +LDFLAGS_ubsan = -fsanitize=undefined,unsigned-integer-overflow +DEFINES_ubsan = NDEBUG +DEFINES_ubsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=1.5 + +VALID_CONFIG_msan = 1 +REQUIRE_CUSTOM_LIBRARIES_msan = 1 +CC_msan = clang +CXX_msan = clang++ +LD_msan = clang +LDXX_msan = clang++ +CPPFLAGS_msan = -O0 -fsanitize-coverage=edge -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +DEFINES_msan = NDEBUG +DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 + +VALID_CONFIG_mutrace = 1 +CC_mutrace = $(DEFAULT_CC) +CXX_mutrace = $(DEFAULT_CXX) +LD_mutrace = $(DEFAULT_CC) +LDXX_mutrace = $(DEFAULT_CXX) +CPPFLAGS_mutrace = -O3 -fno-omit-frame-pointer +LDFLAGS_mutrace = -rdynamic +DEFINES_mutrace = NDEBUG diff --git a/build.yaml b/build.yaml index a6209abd78f..2decc76f194 100644 --- a/build.yaml +++ b/build.yaml @@ -3698,36 +3698,6 @@ configs: dbg: CPPFLAGS: -O0 DEFINES: _DEBUG DEBUG - easan: - CC: clang - CPPFLAGS: -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer - -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS - CXX: clang++ - DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER - LD: clang - LDFLAGS: -fsanitize=address - LDXX: clang++ - compile_the_world: true - test_environ: - ASAN_OPTIONS: detect_leaks=1:color=always - LSAN_OPTIONS: suppressions=tools/lsan_suppressions.txt:report_objects=1 - timeout_multiplier: 3 - edbg: - CPPFLAGS: -O0 - DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER - etsan: - CC: clang - CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument - -DGPR_NO_DIRECT_SYSCALLS - CXX: clang++ - DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER - LD: clang - LDFLAGS: -fsanitize=thread - LDXX: clang++ - compile_the_world: true - test_environ: - TSAN_OPTIONS: suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1 - timeout_multiplier: 5 gcov: CC: gcc CPPFLAGS: -O0 -fprofile-arcs -ftest-coverage -Wno-return-type diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index e566f1b3e89..82ce49cc212 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -63,7 +63,6 @@ typedef struct grpc_combiner grpc_combiner; * - Instances are always passed as the first argument to a function that * takes it, and always as a pointer (grpc_exec_ctx is never copied). */ -#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER struct grpc_exec_ctx { grpc_closure_list closure_list; /** currently active combiner: updated only via combiner.c */ @@ -79,15 +78,6 @@ struct grpc_exec_ctx { prefer to use GRPC_EXEC_CTX_INIT whenever possible */ #define GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(finish_check, finish_check_arg) \ { GRPC_CLOSURE_LIST_INIT, NULL, NULL, false, finish_check_arg, finish_check } -#else -struct grpc_exec_ctx { - bool cached_ready_to_finish; - void *check_ready_to_finish_arg; - bool (*check_ready_to_finish)(grpc_exec_ctx *exec_ctx, void *arg); -}; -#define GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(finish_check, finish_check_arg) \ - { false, finish_check_arg, finish_check } -#endif /* initialize an execution context at the top level of an API call into grpc (this is safe to use elsewhere, though possibly not as efficient) */ diff --git a/tools/run_tests/generated/configs.json b/tools/run_tests/generated/configs.json index b0839ef026a..f2c110766b2 100644 --- a/tools/run_tests/generated/configs.json +++ b/tools/run_tests/generated/configs.json @@ -2,37 +2,6 @@ { "config": "opt" }, - { - "config": "asan-trace-cmp", - "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" - }, - "timeout_multiplier": 3 - }, - { - "config": "dbg" - }, - { - "config": "easan", - "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" - }, - "timeout_multiplier": 3 - }, - { - "config": "asan", - "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" - }, - "timeout_multiplier": 3 - }, - { - "config": "msan", - "timeout_multiplier": 4 - }, { "config": "basicprof" }, @@ -52,27 +21,21 @@ "timeout_multiplier": 3 }, { - "config": "edbg" - }, - { - "config": "ubsan", + "config": "asan-trace-cmp", "environ": { - "UBSAN_OPTIONS": "halt_on_error=1:print_stacktrace=1" + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" }, - "timeout_multiplier": 1.5 + "timeout_multiplier": 3 }, { - "config": "tsan", - "environ": { - "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" - }, - "timeout_multiplier": 5 + "config": "dbg" }, { "config": "stapprof" }, { - "config": "mutrace" + "config": "gcov" }, { "config": "memcheck", @@ -84,13 +47,32 @@ ] }, { - "config": "etsan", + "config": "asan", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "tsan", "environ": { "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" }, "timeout_multiplier": 5 }, { - "config": "gcov" + "config": "ubsan", + "environ": { + "UBSAN_OPTIONS": "halt_on_error=1:print_stacktrace=1" + }, + "timeout_multiplier": 1.5 + }, + { + "config": "msan", + "timeout_multiplier": 4 + }, + { + "config": "mutrace" } ] diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 3eeed5a24b0..e0e53489973 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -37585,9 +37585,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37622,9 +37619,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37659,9 +37653,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37696,9 +37687,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37733,9 +37721,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37770,9 +37755,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37807,9 +37789,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37844,9 +37823,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37881,9 +37857,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37918,9 +37891,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37955,9 +37925,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -37992,9 +37959,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38029,9 +37993,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38066,9 +38027,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38103,9 +38061,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38140,9 +38095,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38177,9 +38129,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38214,9 +38163,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38251,9 +38197,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38288,9 +38231,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38325,9 +38265,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38362,9 +38299,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38399,9 +38333,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38436,9 +38367,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38473,9 +38401,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38510,9 +38435,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38547,9 +38469,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38584,9 +38503,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38621,9 +38537,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38658,9 +38571,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38695,9 +38605,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38732,9 +38639,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38769,9 +38673,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", @@ -38806,9 +38707,6 @@ "asan-trace-cmp", "basicprof", "dbg", - "easan", - "edbg", - "etsan", "gcov", "helgrind", "memcheck", From 8cf88f1eb169f5bae7ddfbdd571fd4c27ba5e1bf Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 14:04:43 -0800 Subject: [PATCH 180/261] Add a mechanism for tagging threads that might be owned by calls/channels Use it to ensure we don't delete the call from that thread: doing so would create a cycle that's kind of bad. --- src/core/lib/iomgr/exec_ctx.c | 15 ++++++++++----- src/core/lib/iomgr/exec_ctx.h | 15 +++++++++++---- .../credentials/plugin/plugin_credentials.c | 4 +++- src/core/lib/surface/completion_queue.c | 8 ++++---- src/core/lib/transport/transport.c | 11 +++++++++++ 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c index fabe6c69887..83bb436bd0a 100644 --- a/src/core/lib/iomgr/exec_ctx.c +++ b/src/core/lib/iomgr/exec_ctx.c @@ -42,11 +42,16 @@ #include "src/core/lib/profiling/timers.h" bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx *exec_ctx) { - if (!exec_ctx->cached_ready_to_finish) { - exec_ctx->cached_ready_to_finish = exec_ctx->check_ready_to_finish( - exec_ctx, exec_ctx->check_ready_to_finish_arg); + if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { + if (exec_ctx->check_ready_to_finish(exec_ctx, + exec_ctx->check_ready_to_finish_arg)) { + exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + return true; + } + return false; + } else { + return true; } - return exec_ctx->cached_ready_to_finish; } bool grpc_never_ready_to_finish(grpc_exec_ctx *exec_ctx, void *arg_ignored) { @@ -82,7 +87,7 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { } void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) { - exec_ctx->cached_ready_to_finish = true; + exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; grpc_exec_ctx_flush(exec_ctx); } diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index 82ce49cc212..f99a0fee5fc 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -43,6 +43,13 @@ typedef struct grpc_workqueue grpc_workqueue; typedef struct grpc_combiner grpc_combiner; +/* This exec_ctx is ready to return: either pre-populated, or cached as soon as + the finish_check returns true */ +#define GRPC_EXEC_CTX_FLAG_IS_FINISHED 1 +/* The exec_ctx's thread is (potentially) owned by a call or channel: care + should be given to not delete said call/channel from this exec_ctx */ +#define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 + /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -69,20 +76,20 @@ struct grpc_exec_ctx { grpc_combiner *active_combiner; /** last active combiner in the active combiner list */ grpc_combiner *last_combiner; - bool cached_ready_to_finish; + uintptr_t flags; void *check_ready_to_finish_arg; bool (*check_ready_to_finish)(grpc_exec_ctx *exec_ctx, void *arg); }; /* initializer for grpc_exec_ctx: prefer to use GRPC_EXEC_CTX_INIT whenever possible */ -#define GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(finish_check, finish_check_arg) \ - { GRPC_CLOSURE_LIST_INIT, NULL, NULL, false, finish_check_arg, finish_check } +#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \ + { GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, finish_check_arg, finish_check } /* initialize an execution context at the top level of an API call into grpc (this is safe to use elsewhere, though possibly not as efficient) */ #define GRPC_EXEC_CTX_INIT \ - GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(grpc_always_ready_to_finish, NULL) + GRPC_EXEC_CTX_INITIALIZER(GRPC_EXEC_CTX_FLAG_IS_FINISHED, NULL, NULL) extern grpc_closure_scheduler *grpc_schedule_on_exec_ctx; diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index afce6a6b12c..7bc5dfb4035 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -65,7 +65,9 @@ static void plugin_md_request_metadata_ready(void *request, grpc_status_code status, const char *error_details) { /* called from application code */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( + GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, + NULL, NULL); grpc_metadata_plugin_request *r = (grpc_metadata_plugin_request *)request; if (status != GRPC_STATUS_OK) { if (error_details != NULL) { diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index 20c22ea2bc4..1830842d00b 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -402,8 +402,8 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, .stolen_completion = NULL, .tag = NULL, .first_loop = true}; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK( - cq_is_next_finished, &is_finished_arg); + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cc->mu); @@ -571,8 +571,8 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, .stolen_completion = NULL, .tag = tag, .first_loop = true}; - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK( - cq_is_pluck_finished, &is_finished_arg); + grpc_exec_ctx exec_ctx = + GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cc->mu); diff --git a/src/core/lib/transport/transport.c b/src/core/lib/transport/transport.c index 0462d449f26..004e748f251 100644 --- a/src/core/lib/transport/transport.c +++ b/src/core/lib/transport/transport.c @@ -40,6 +40,7 @@ #include #include +#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" @@ -69,6 +70,16 @@ void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount) { #endif if (gpr_unref(&refcount->refs)) { + if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { + /* Ick. + The thread we're running on MAY be owned (indirectly) by a call-stack. + If that's the case, destroying the call-stack MAY try to destroy the + thread, which is a tangled mess that we just don't want to ever have to + cope with. + Throw this over to the executor (on a core-owned thread) and process it + there. */ + refcount->destroy.scheduler = grpc_executor_scheduler; + } grpc_closure_sched(exec_ctx, &refcount->destroy, GRPC_ERROR_NONE); } } From 81eceb31ccab4a91e84ef06833d43d8c9e49de0f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 14:27:01 -0800 Subject: [PATCH 181/261] Remove bogus assert --- include/grpc++/impl/codegen/client_unary_call.h | 9 ++++++++- include/grpc++/impl/codegen/core_codegen.h | 3 ++- .../grpc++/impl/codegen/core_codegen_interface.h | 13 +++++++------ .../transport/chttp2/transport/chttp2_transport.c | 2 -- src/cpp/common/core_codegen.cc | 6 ++++-- 5 files changed, 21 insertions(+), 12 deletions(-) diff --git a/include/grpc++/impl/codegen/client_unary_call.h b/include/grpc++/impl/codegen/client_unary_call.h index 70d65549c80..201e52ae073 100644 --- a/include/grpc++/impl/codegen/client_unary_call.h +++ b/include/grpc++/impl/codegen/client_unary_call.h @@ -69,7 +69,14 @@ Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, ops.ClientSendClose(); ops.ClientRecvStatus(context, &status); call.PerformOps(&ops); - GPR_CODEGEN_ASSERT((cq.Pluck(&ops) && ops.got_message) || !status.ok()); + if (cq.Pluck(&ops)) { + if (!ops.got_message && status.ok()) { + return Status(StatusCode::UNIMPLEMENTED, + "No message returned for unary request"); + } + } else { + GPR_CODEGEN_ASSERT(!status.ok()); + } return status; } diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index b5ab26154e2..754bf14b259 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -94,7 +94,8 @@ class CoreCodegen : public CoreCodegenInterface { virtual const Status& ok() override; virtual const Status& cancelled() override; - void assert_fail(const char* failed_assertion) override; + void assert_fail(const char* failed_assertion, const char* file, + int line) override; }; } // namespace grpc diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h index 9c1af972b3c..45ea0403031 100644 --- a/include/grpc++/impl/codegen/core_codegen_interface.h +++ b/include/grpc++/impl/codegen/core_codegen_interface.h @@ -56,7 +56,8 @@ namespace grpc { class CoreCodegenInterface { public: /// Upon a failed assertion, log the error. - virtual void assert_fail(const char* failed_assertion) = 0; + virtual void assert_fail(const char* failed_assertion, const char* file, + int line) = 0; virtual grpc_completion_queue* grpc_completion_queue_create( void* reserved) = 0; @@ -117,11 +118,11 @@ class CoreCodegenInterface { extern CoreCodegenInterface* g_core_codegen_interface; /// Codegen specific version of \a GPR_ASSERT. -#define GPR_CODEGEN_ASSERT(x) \ - do { \ - if (!(x)) { \ - grpc::g_core_codegen_interface->assert_fail(#x); \ - } \ +#define GPR_CODEGEN_ASSERT(x) \ + do { \ + if (!(x)) { \ + grpc::g_core_codegen_interface->assert_fail(#x, __FILE__, __LINE__); \ + } \ } while (0) } // namespace grpc diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 1e9f4f1656f..eb9ffd67738 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1075,8 +1075,6 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE; s->fetching_send_message_finished = add_closure_barrier(op->on_complete); if (s->write_closed) { - gpr_log(GPR_DEBUG, "write_closed_error=%s", - grpc_error_string(s->write_closed_error)); grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_CREATE_REFERENCING( diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index a09e08ef4cf..36e4c893540 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -163,8 +163,10 @@ gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) { return ::gpr_time_0(type); } -void CoreCodegen::assert_fail(const char* failed_assertion) { - gpr_log(GPR_ERROR, "assertion failed: %s", failed_assertion); +void CoreCodegen::assert_fail(const char* failed_assertion, const char* file, + int line) { + gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s", + failed_assertion); abort(); } From 4dd97f901939c75ad9b77dc490cc642b2bc52161 Mon Sep 17 00:00:00 2001 From: Makarand Dharmapurikar Date: Thu, 12 Jan 2017 15:04:31 -0800 Subject: [PATCH 182/261] dockerfile update for http2_badserver_interop added h2 and twisted python modules --- tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile index 05e963d1e67..03ff179f718 100644 --- a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile @@ -46,6 +46,7 @@ RUN apt-get update && apt-get install -y \ RUN pip install pip --upgrade RUN pip install virtualenv RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 +RUN pip install twisted h2 # Define the default command. CMD ["bash"] From d87b9fb4c445182bf24d4e7782d624cc0ba557dd Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Thu, 12 Jan 2017 17:40:24 -0800 Subject: [PATCH 183/261] clang-format and add copyright info --- .../cronet/transport/cronet_transport.c | 10 ++--- .../tests/CronetUnitTests/CronetUnitTests.m | 39 +++++++++++++++---- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 00eefa28403..f1af696712a 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -857,9 +857,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, grpc_closure_sched(exec_ctx, stream_op->recv_initial_metadata_ready, GRPC_ERROR_NONE); } else if (stream_state->state_callback_received[OP_FAILED]) { - grpc_closure_sched( - exec_ctx, stream_op->recv_initial_metadata_ready, - GRPC_ERROR_NONE); + grpc_closure_sched(exec_ctx, stream_op->recv_initial_metadata_ready, + GRPC_ERROR_NONE); } else { grpc_chttp2_incoming_metadata_buffer_publish( &oas->s->state.rs.initial_metadata, stream_op->recv_initial_metadata); @@ -921,9 +920,8 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->state_callback_received[OP_FAILED]) { CRONET_LOG(GPR_DEBUG, "Stream failed."); - grpc_closure_sched( - exec_ctx, stream_op->recv_message_ready, - GRPC_ERROR_NONE); + grpc_closure_sched(exec_ctx, stream_op->recv_message_ready, + GRPC_ERROR_NONE); stream_state->state_op_done[OP_RECV_MESSAGE] = true; result = ACTION_TAKEN_NO_CALLBACK; } else if (stream_state->rs.read_stream_closed == true) { diff --git a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m index 3bdcca92503..dbd28076ddb 100644 --- a/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m +++ b/src/objective-c/tests/CronetUnitTests/CronetUnitTests.m @@ -1,10 +1,35 @@ -// -// CronetUnitTest.m -// CronetUnitTest -// -// Created by Muxi Yan on 1/10/17. -// Copyright © 2017 gRPC. All rights reserved. -// +/* + * + * 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. + * + */ #import #import From 24263c3f7a3b04f073712e40376829e47772d7db Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Wed, 11 Jan 2017 01:03:09 +0100 Subject: [PATCH 184/261] Fixing a few items with the new Bazel BUILD system: -) Fixing Bazel 0.4.x breakage -) Adding helloworld BUILD examples -) Fixing grpc++ missing files. -) Adding helloworld example as a test for Bazel basic. --- BUILD | 2 + bazel/BUILD | 8 +++- bazel/cc_grpc_library.bzl | 1 - bazel/generate_cc.bzl | 4 +- examples/cpp/helloworld/BUILD | 42 +++++++++++++++++ examples/cpp/helloworld/greeter_client.cc | 4 ++ examples/cpp/helloworld/greeter_server.cc | 4 ++ examples/protos/BUILD | 52 ++++++++++++++++++++++ tools/jenkins/run_bazel_basic_in_docker.sh | 2 +- 9 files changed, 115 insertions(+), 4 deletions(-) create mode 100644 examples/cpp/helloworld/BUILD create mode 100644 examples/protos/BUILD diff --git a/BUILD b/BUILD index 3122dc0a321..2c9a6f35a17 100644 --- a/BUILD +++ b/BUILD @@ -1078,6 +1078,7 @@ grpc_cc_library( "src/cpp/common/completion_queue_cc.cc", "src/cpp/common/core_codegen.cc", "src/cpp/common/rpc_method.cc", + "src/cpp/common/version_cc.cc", "src/cpp/server/async_generic_service.cc", "src/cpp/server/create_default_thread_pool.cc", "src/cpp/server/dynamic_thread_pool.cc", @@ -1086,6 +1087,7 @@ grpc_cc_library( "src/cpp/server/server_context.cc", "src/cpp/server/server_credentials.cc", "src/cpp/server/server_posix.cc", + "src/cpp/thread_manager/thread_manager.cc", "src/cpp/util/byte_buffer_cc.cc", "src/cpp/util/slice_cc.cc", "src/cpp/util/status.cc", diff --git a/bazel/BUILD b/bazel/BUILD index 940a379404f..44a1673212e 100644 --- a/bazel/BUILD +++ b/bazel/BUILD @@ -2,8 +2,14 @@ package(default_visibility = ["//:__subpackages__"]) load(":cc_grpc_library.bzl", "cc_grpc_library") +proto_library( + name = "well_known_protos_list", + srcs = ["@submodule_protobuf//:well_known_protos"], +) + cc_grpc_library( name = "well_known_protos", - srcs = "@submodule_protobuf//:well_known_protos", + srcs = "well_known_protos_list", + deps = [], proto_only = True, ) diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl index e1dd27b0c3f..9020eacb740 100644 --- a/bazel/cc_grpc_library.bzl +++ b/bazel/cc_grpc_library.bzl @@ -44,7 +44,6 @@ def cc_grpc_library(name, srcs, deps, proto_only, **kwargs): **kwargs ) - if not proto_only: native.cc_library( name = name, srcs = [":" + codegen_grpc_target, ":" + codegen_target], diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 3665733681e..d49cbe8d728 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -24,13 +24,15 @@ def generate_cc_impl(ctx): if ctx.executable.plugin: arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path] arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] + additional_input = [ctx.executable.plugin] else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] + additional_input = [] arguments += ["-I{0}={0}".format(include.path) for include in includes] arguments += [proto.path for proto in protos] ctx.action( - inputs = protos + includes, + inputs = protos + includes + additional_input, outputs = out_files, executable = ctx.executable._protoc, arguments = arguments, diff --git a/examples/cpp/helloworld/BUILD b/examples/cpp/helloworld/BUILD new file mode 100644 index 00000000000..b9c3f5dfbed --- /dev/null +++ b/examples/cpp/helloworld/BUILD @@ -0,0 +1,42 @@ +# Copyright 2017, 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. + +cc_binary( + name = "greeter_client", + srcs = ["greeter_client.cc"], + deps = ["//examples/protos:helloworld"], + defines = ["BAZEL_BUILD"], +) + +cc_binary( + name = "greeter_server", + srcs = ["greeter_server.cc"], + deps = ["//examples/protos:helloworld"], + defines = ["BAZEL_BUILD"], +) diff --git a/examples/cpp/helloworld/greeter_client.cc b/examples/cpp/helloworld/greeter_client.cc index 61f3953056a..8ee33b1383b 100644 --- a/examples/cpp/helloworld/greeter_client.cc +++ b/examples/cpp/helloworld/greeter_client.cc @@ -37,7 +37,11 @@ #include +#ifdef BAZEL_BUILD +#include "examples/protos/helloworld.grpc.pb.h" +#else #include "helloworld.grpc.pb.h" +#endif using grpc::Channel; using grpc::ClientContext; diff --git a/examples/cpp/helloworld/greeter_server.cc b/examples/cpp/helloworld/greeter_server.cc index 9eab32c62b4..c8a6d8ae86a 100644 --- a/examples/cpp/helloworld/greeter_server.cc +++ b/examples/cpp/helloworld/greeter_server.cc @@ -37,7 +37,11 @@ #include +#ifdef BAZEL_BUILD +#include "examples/protos/helloworld.grpc.pb.h" +#else #include "helloworld.grpc.pb.h" +#endif using grpc::Server; using grpc::ServerBuilder; diff --git a/examples/protos/BUILD b/examples/protos/BUILD new file mode 100644 index 00000000000..2ffdf64f9af --- /dev/null +++ b/examples/protos/BUILD @@ -0,0 +1,52 @@ +# Copyright 2017, 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. + +package(default_visibility = ["//visibility:public"]) + +load("//bazel:grpc_build_system.bzl", "grpc_proto_library") + +grpc_proto_library( + name = "auth_sample", + srcs = ["auth_sample.proto"], +) + +grpc_proto_library( + name = "hellostreamingworld", + srcs = ["hellostreamingworld.proto"], +) + +grpc_proto_library( + name = "helloworld", + srcs = ["helloworld.proto"], +) + +grpc_proto_library( + name = "route_guide", + srcs = ["route_guide.proto"], +) diff --git a/tools/jenkins/run_bazel_basic_in_docker.sh b/tools/jenkins/run_bazel_basic_in_docker.sh index 51aaa90ff82..b1d498a07d3 100755 --- a/tools/jenkins/run_bazel_basic_in_docker.sh +++ b/tools/jenkins/run_bazel_basic_in_docker.sh @@ -39,4 +39,4 @@ git clone /var/local/jenkins/grpc /var/local/git/grpc && git submodule update --init --reference /var/local/jenkins/grpc/${name} \ ${name}') cd /var/local/git/grpc -bazel build --spawn_strategy=standalone --genrule_strategy=standalone :all test/... +bazel build --spawn_strategy=standalone --genrule_strategy=standalone :all test/... examples/cpp/... From 6d353e2a72d1313bc4d1e9938a1f5ffe157a4db4 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 12 Jan 2017 21:23:00 -0800 Subject: [PATCH 185/261] Fix mac --- src/cpp/server/dynamic_thread_pool.cc | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index 0361768c04e..afb5beaadec 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -39,7 +39,6 @@ #include namespace grpc { -static thread_local bool g_is_dynamic_thread_pool_thread; DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), @@ -51,7 +50,6 @@ DynamicThreadPool::DynamicThread::~DynamicThread() { } void DynamicThreadPool::DynamicThread::ThreadFunc() { - g_is_dynamic_thread_pool_thread = true; pool_->ThreadFunc(); // Now that we have killed ourselves, we should reduce the thread count std::unique_lock lock(pool_->mu_); @@ -109,7 +107,6 @@ void DynamicThreadPool::ReapThreads(std::list* tlist) { } DynamicThreadPool::~DynamicThreadPool() { - GPR_ASSERT(!g_is_dynamic_thread_pool_thread); std::unique_lock lock(mu_); shutdown_ = true; cv_.notify_all(); From 28ea6f0fbc1a48e092d92e7619a332598ce39941 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 13 Jan 2017 08:21:24 -0800 Subject: [PATCH 186/261] Fix memory corruption --- src/cpp/client/secure_credentials.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 21445c91fd8..7fc315bb381 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -206,8 +206,8 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( std::vector md; for (auto it = metadata.begin(); it != metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceReferencingString(it->first); - md_entry.value = SliceReferencingString(it->second); + md_entry.key = SliceFromCopiedString(it->first); + md_entry.value = SliceFromCopiedString(it->second); md_entry.flags = 0; md.push_back(md_entry); } From 0748f3925cf0892b4780de25199bdd82aab30e57 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 13 Jan 2017 09:22:44 -0800 Subject: [PATCH 187/261] Store subchannel address in a channel arg. --- src/core/ext/client_channel/connector.h | 3 -- src/core/ext/client_channel/subchannel.c | 40 ++++++++++++++----- src/core/ext/client_channel/subchannel.h | 8 +++- .../ext/client_channel/subchannel_index.c | 12 ------ .../ext/lb_policy/pick_first/pick_first.c | 15 +++++-- .../ext/lb_policy/round_robin/round_robin.c | 15 +++++-- .../chttp2/client/chttp2_connector.c | 10 ++++- 7 files changed, 69 insertions(+), 34 deletions(-) diff --git a/src/core/ext/client_channel/connector.h b/src/core/ext/client_channel/connector.h index 3de061620e3..395f89b3b2c 100644 --- a/src/core/ext/client_channel/connector.h +++ b/src/core/ext/client_channel/connector.h @@ -48,9 +48,6 @@ struct grpc_connector { typedef struct { /** set of pollsets interested in this connection */ grpc_pollset_set *interested_parties; - /** address to connect to */ - const grpc_resolved_address *addr; - size_t addr_len; /** initial connect string to send */ grpc_slice initial_connect_string; /** deadline for connection */ diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 1bac82b4512..7a2ad984333 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -41,9 +41,12 @@ #include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/client_channel/initial_connect_string.h" +#include "src/core/ext/client_channel/parse_address.h" #include "src/core/ext/client_channel/subchannel_index.h" +#include "src/core/ext/client_channel/uri_parser.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/connected_channel.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/iomgr/timer.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" @@ -95,8 +98,6 @@ struct grpc_subchannel { size_t num_filters; /** channel arguments */ grpc_channel_args *args; - /** address to connect to */ - grpc_resolved_address *addr; grpc_subchannel_key *key; @@ -211,7 +212,6 @@ static void subchannel_destroy(grpc_exec_ctx *exec_ctx, void *arg, grpc_subchannel *c = arg; gpr_free((void *)c->filters); grpc_channel_args_destroy(exec_ctx, c->args); - gpr_free(c->addr); grpc_slice_unref_internal(exec_ctx, c->initial_connect_string); grpc_connectivity_state_destroy(exec_ctx, &c->state_tracker); grpc_connector_unref(exec_ctx, c->connector); @@ -327,12 +327,22 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, } else { c->filters = NULL; } - c->addr = gpr_malloc(sizeof(grpc_resolved_address)); - if (args->addr->len) - memcpy(c->addr, args->addr, sizeof(grpc_resolved_address)); c->pollset_set = grpc_pollset_set_create(); - grpc_set_initial_connect_string(&c->addr, &c->initial_connect_string); - c->args = grpc_channel_args_copy(args->args); + const grpc_arg *addr_arg = + grpc_channel_args_find(args->args, GRPC_ARG_SUBCHANNEL_ADDRESS); + GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. + grpc_resolved_address *addr = gpr_malloc(sizeof(*addr)); + grpc_uri_to_sockaddr(addr_arg->value.string, addr); + grpc_set_initial_connect_string(&addr, &c->initial_connect_string); + static const char *keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS}; + grpc_arg new_arg; + new_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; + new_arg.type = GRPC_ARG_STRING; + new_arg.value.string = grpc_sockaddr_to_uri(addr); + gpr_free(addr); + c->args = grpc_channel_args_copy_and_add_and_remove( + args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); + gpr_free(new_arg.value.string); c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; grpc_closure_init(&c->connected, subchannel_connected, c, @@ -385,7 +395,6 @@ static void continue_connect_locked(grpc_exec_ctx *exec_ctx, grpc_connect_in_args args; args.interested_parties = c->pollset_set; - args.addr = c->addr; args.deadline = c->next_attempt; args.channel_args = c->args; args.initial_connect_string = c->initial_connect_string; @@ -771,3 +780,16 @@ grpc_call_stack *grpc_subchannel_call_get_call_stack( grpc_subchannel_call *subchannel_call) { return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); } + +void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr) { + grpc_uri *uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */); + GPR_ASSERT(uri != NULL); + if (strcmp(uri->scheme, "ipv4") == 0) { + GPR_ASSERT(parse_ipv4(uri, addr)); + } else if (strcmp(uri->scheme, "ipv6") == 0) { + GPR_ASSERT(parse_ipv6(uri, addr)); + } else { + GPR_ASSERT(parse_unix(uri, addr)); + } + grpc_uri_destroy(uri); +} diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index 24aa9f73dca..4cc33fc79bf 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -40,6 +40,9 @@ #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/metadata.h" +// Channel arg containing a grpc_resolved_address to connect to. +#define GRPC_ARG_SUBCHANNEL_ADDRESS "grpc.subchannel_address" + /** A (sub-)channel that knows how to connect to exactly one target address. Provides a target for load balancing. */ typedef struct grpc_subchannel grpc_subchannel; @@ -164,8 +167,6 @@ struct grpc_subchannel_args { size_t filter_count; /** Channel arguments to be supplied to the newly created channel */ const grpc_channel_args *args; - /** Address to connect to */ - grpc_resolved_address *addr; }; /** create a subchannel given a connector */ @@ -173,4 +174,7 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, grpc_connector *connector, const grpc_subchannel_args *args); +/// Sets \a addr from \a uri_str. +void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr); + #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_SUBCHANNEL_H */ diff --git a/src/core/ext/client_channel/subchannel_index.c b/src/core/ext/client_channel/subchannel_index.c index 1ebe03ef119..11889300a2c 100644 --- a/src/core/ext/client_channel/subchannel_index.c +++ b/src/core/ext/client_channel/subchannel_index.c @@ -86,11 +86,6 @@ static grpc_subchannel_key *create_key( } else { k->args.filters = NULL; } - k->args.addr = gpr_malloc(sizeof(grpc_resolved_address)); - k->args.addr->len = args->addr->len; - if (k->args.addr->len > 0) { - memcpy(k->args.addr, args->addr, sizeof(grpc_resolved_address)); - } k->args.args = copy_channel_args(args->args); return k; } @@ -108,14 +103,8 @@ static int subchannel_key_compare(grpc_subchannel_key *a, grpc_subchannel_key *b) { int c = GPR_ICMP(a->connector, b->connector); if (c != 0) return c; - c = GPR_ICMP(a->args.addr->len, b->args.addr->len); - if (c != 0) return c; c = GPR_ICMP(a->args.filter_count, b->args.filter_count); if (c != 0) return c; - if (a->args.addr->len) { - c = memcmp(a->args.addr->addr, b->args.addr->addr, a->args.addr->len); - if (c != 0) return c; - } if (a->args.filter_count > 0) { c = memcmp(a->args.filters, b->args.filters, a->args.filter_count * sizeof(*a->args.filters)); @@ -129,7 +118,6 @@ void grpc_subchannel_key_destroy(grpc_exec_ctx *exec_ctx, grpc_connector_unref(exec_ctx, k->connector); gpr_free((grpc_channel_args *)k->args.filters); grpc_channel_args_destroy(exec_ctx, (grpc_channel_args *)k->args.args); - gpr_free(k->args.addr); gpr_free(k); } diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 821becff69d..4677fb23435 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -36,7 +36,9 @@ #include #include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/subchannel.h" #include "src/core/lib/channel/channel_args.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" typedef struct pending_pick { @@ -466,11 +468,18 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, } memset(&sc_args, 0, sizeof(grpc_subchannel_args)); - sc_args.addr = &addresses->addresses[i].address; - sc_args.args = args->args; - + grpc_arg addr_arg; + addr_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; + addr_arg.type = GRPC_ARG_STRING; + addr_arg.value.string = + grpc_sockaddr_to_uri(&addresses->addresses[i].address); + grpc_channel_args *new_args = + grpc_channel_args_copy_and_add(args->args, &addr_arg, 1); + gpr_free(addr_arg.value.string); + sc_args.args = new_args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); + grpc_channel_args_destroy(exec_ctx, new_args); if (subchannel != NULL) { p->subchannels[subchannel_idx++] = subchannel; diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index cb679489c3e..3fe157a23c8 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -64,8 +64,10 @@ #include #include "src/core/ext/client_channel/lb_policy_registry.h" +#include "src/core/ext/client_channel/subchannel.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/debug/trace.h" +#include "src/core/lib/iomgr/sockaddr_utils.h" #include "src/core/lib/transport/connectivity_state.h" #include "src/core/lib/transport/static_metadata.h" @@ -729,11 +731,18 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, if (addresses->addresses[i].is_balancer) continue; memset(&sc_args, 0, sizeof(grpc_subchannel_args)); - sc_args.addr = &addresses->addresses[i].address; - sc_args.args = args->args; - + grpc_arg addr_arg; + addr_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; + addr_arg.type = GRPC_ARG_STRING; + addr_arg.value.string = + grpc_sockaddr_to_uri(&addresses->addresses[i].address); + grpc_channel_args *new_args = + grpc_channel_args_copy_and_add(args->args, &addr_arg, 1); + gpr_free(addr_arg.value.string); + sc_args.args = new_args; grpc_subchannel *subchannel = grpc_client_channel_factory_create_subchannel( exec_ctx, args->client_channel_factory, &sc_args); + grpc_channel_args_destroy(exec_ctx, new_args); if (subchannel != NULL) { subchannel_data *sd = gpr_malloc(sizeof(*sd)); diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.c b/src/core/ext/transport/chttp2/client/chttp2_connector.c index 2c5dfaea601..ebe884b1158 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.c +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.c @@ -43,6 +43,7 @@ #include "src/core/ext/client_channel/connector.h" #include "src/core/ext/client_channel/http_connect_handshaker.h" +#include "src/core/ext/client_channel/subchannel.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/channel/handshaker.h" @@ -220,6 +221,11 @@ static void chttp2_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connect_out_args *result, grpc_closure *notify) { chttp2_connector *c = (chttp2_connector *)con; + const grpc_arg *addr_arg = + grpc_channel_args_find(args->channel_args, GRPC_ARG_SUBCHANNEL_ADDRESS); + GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. + grpc_resolved_address addr; + grpc_uri_to_sockaddr(addr_arg->value.string, &addr); gpr_mu_lock(&c->mu); GPR_ASSERT(c->notify == NULL); c->notify = notify; @@ -231,8 +237,8 @@ static void chttp2_connector_connect(grpc_exec_ctx *exec_ctx, GPR_ASSERT(!c->connecting); c->connecting = true; grpc_tcp_client_connect(exec_ctx, &c->connected, &c->endpoint, - args->interested_parties, args->channel_args, - args->addr, args->deadline); + args->interested_parties, args->channel_args, &addr, + args->deadline); gpr_mu_unlock(&c->mu); } From aaddb5cb93bd983265002f189ae65e72765c36a5 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 13 Jan 2017 09:42:12 -0800 Subject: [PATCH 188/261] continue use of host_cpu and use x86 whenever not x86_64 --- src/ruby/tools/platform_check.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/ruby/tools/platform_check.rb b/src/ruby/tools/platform_check.rb index 2c5ccffdda6..1f4d5a68b71 100644 --- a/src/ruby/tools/platform_check.rb +++ b/src/ruby/tools/platform_check.rb @@ -42,15 +42,13 @@ module PLATFORM 'linux' end end - + def PLATFORM.architecture - case RbConfig::CONFIG['target_cpu'] + case RbConfig::CONFIG['host_cpu'] when /x86_64/ 'x86_64' - when /x86|i386/ - 'x86' else - fail 'cpu architecture detection failed' + 'x86' end end end From 4d08937206b81d0e2462ff2088d2e8cd8fe12233 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Fri, 13 Jan 2017 10:00:50 -0800 Subject: [PATCH 189/261] update grpc-tools.gemspec after with os_check -> plactform_check.rb --- src/ruby/tools/grpc-tools.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/tools/grpc-tools.gemspec b/src/ruby/tools/grpc-tools.gemspec index 68e2a7a1133..bc142ae3cb5 100644 --- a/src/ruby/tools/grpc-tools.gemspec +++ b/src/ruby/tools/grpc-tools.gemspec @@ -11,7 +11,7 @@ Gem::Specification.new do |s| s.description = 'protoc and the Ruby gRPC protoc plugin' s.license = 'BSD-3-Clause' - s.files = %w( version.rb os_check.rb README.md ) + s.files = %w( version.rb platform_check.rb README.md ) s.files += Dir.glob('bin/**/*') s.bindir = 'bin' From a5fd2d53f43ce99a7aa220ea37fc6264cf42a675 Mon Sep 17 00:00:00 2001 From: Steve Jenson Date: Fri, 13 Jan 2017 12:12:09 -0800 Subject: [PATCH 190/261] adding content-type to the example response --- doc/PROTOCOL-HTTP2.md | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/PROTOCOL-HTTP2.md b/doc/PROTOCOL-HTTP2.md index 18803f2a097..2df1c74beef 100644 --- a/doc/PROTOCOL-HTTP2.md +++ b/doc/PROTOCOL-HTTP2.md @@ -153,6 +153,7 @@ DATA (flags = END_STREAM) HEADERS (flags = END_HEADERS) :status = 200 grpc-encoding = gzip +content-type = application/grpc+proto DATA From df8f12203ce662860d514376af92c76237fd5b7f Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 13 Jan 2017 22:59:39 +0000 Subject: [PATCH 191/261] Fix API fuzzer tests. --- src/core/ext/client_channel/subchannel.c | 35 ++++++++++++++----- src/core/ext/client_channel/subchannel.h | 9 +++-- .../ext/lb_policy/pick_first/pick_first.c | 7 ++-- .../ext/lb_policy/round_robin/round_robin.c | 7 ++-- .../chttp2/client/chttp2_connector.c | 5 +-- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index 7a2ad984333..f9de9993b7b 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -38,6 +38,7 @@ #include #include +#include #include "src/core/ext/client_channel/client_channel.h" #include "src/core/ext/client_channel/initial_connect_string.h" @@ -328,21 +329,16 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, c->filters = NULL; } c->pollset_set = grpc_pollset_set_create(); - const grpc_arg *addr_arg = - grpc_channel_args_find(args->args, GRPC_ARG_SUBCHANNEL_ADDRESS); - GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. grpc_resolved_address *addr = gpr_malloc(sizeof(*addr)); - grpc_uri_to_sockaddr(addr_arg->value.string, addr); + grpc_get_subchannel_address_arg(args->args, addr); grpc_set_initial_connect_string(&addr, &c->initial_connect_string); static const char *keys_to_remove[] = {GRPC_ARG_SUBCHANNEL_ADDRESS}; - grpc_arg new_arg; - new_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; - new_arg.type = GRPC_ARG_STRING; - new_arg.value.string = grpc_sockaddr_to_uri(addr); + grpc_arg new_arg = grpc_create_subchannel_address_arg(addr); gpr_free(addr); c->args = grpc_channel_args_copy_and_add_and_remove( args->args, keys_to_remove, GPR_ARRAY_SIZE(keys_to_remove), &new_arg, 1); gpr_free(new_arg.value.string); + c->root_external_state_watcher.next = c->root_external_state_watcher.prev = &c->root_external_state_watcher; grpc_closure_init(&c->connected, subchannel_connected, c, @@ -781,7 +777,7 @@ grpc_call_stack *grpc_subchannel_call_get_call_stack( return SUBCHANNEL_CALL_TO_CALL_STACK(subchannel_call); } -void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr) { +static void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr) { grpc_uri *uri = grpc_uri_parse(uri_str, 0 /* suppress_errors */); GPR_ASSERT(uri != NULL); if (strcmp(uri->scheme, "ipv4") == 0) { @@ -793,3 +789,24 @@ void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr) { } grpc_uri_destroy(uri); } + +void grpc_get_subchannel_address_arg(const grpc_channel_args *args, + grpc_resolved_address *addr) { + const grpc_arg *addr_arg = + grpc_channel_args_find(args, GRPC_ARG_SUBCHANNEL_ADDRESS); + GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. + GPR_ASSERT(addr_arg->type == GRPC_ARG_STRING); + memset(addr, 0, sizeof(*addr)); + if (*addr_arg->value.string != '\0') { + grpc_uri_to_sockaddr(addr_arg->value.string, addr); + } +} + +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr) { + grpc_arg new_arg; + new_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; + new_arg.type = GRPC_ARG_STRING; + new_arg.value.string = + addr->len > 0 ? grpc_sockaddr_to_uri(addr) : gpr_strdup(""); + return new_arg; +} diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index 4cc33fc79bf..c7a9577ce99 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -174,7 +174,12 @@ grpc_subchannel *grpc_subchannel_create(grpc_exec_ctx *exec_ctx, grpc_connector *connector, const grpc_subchannel_args *args); -/// Sets \a addr from \a uri_str. -void grpc_uri_to_sockaddr(char *uri_str, grpc_resolved_address *addr); +/// Sets \a addr from \a args. +void grpc_get_subchannel_address_arg(const grpc_channel_args *args, + grpc_resolved_address *addr); + +/// Returns a new channel arg encoding the subchannel address as a string. +/// Caller is responsible for freeing the string. +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_SUBCHANNEL_H */ diff --git a/src/core/ext/lb_policy/pick_first/pick_first.c b/src/core/ext/lb_policy/pick_first/pick_first.c index 4677fb23435..9f2aa461bed 100644 --- a/src/core/ext/lb_policy/pick_first/pick_first.c +++ b/src/core/ext/lb_policy/pick_first/pick_first.c @@ -468,11 +468,8 @@ static grpc_lb_policy *create_pick_first(grpc_exec_ctx *exec_ctx, } memset(&sc_args, 0, sizeof(grpc_subchannel_args)); - grpc_arg addr_arg; - addr_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; - addr_arg.type = GRPC_ARG_STRING; - addr_arg.value.string = - grpc_sockaddr_to_uri(&addresses->addresses[i].address); + grpc_arg addr_arg = + grpc_create_subchannel_address_arg(&addresses->addresses[i].address); grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args->args, &addr_arg, 1); gpr_free(addr_arg.value.string); diff --git a/src/core/ext/lb_policy/round_robin/round_robin.c b/src/core/ext/lb_policy/round_robin/round_robin.c index 3fe157a23c8..d17d8fa057a 100644 --- a/src/core/ext/lb_policy/round_robin/round_robin.c +++ b/src/core/ext/lb_policy/round_robin/round_robin.c @@ -731,11 +731,8 @@ static grpc_lb_policy *round_robin_create(grpc_exec_ctx *exec_ctx, if (addresses->addresses[i].is_balancer) continue; memset(&sc_args, 0, sizeof(grpc_subchannel_args)); - grpc_arg addr_arg; - addr_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; - addr_arg.type = GRPC_ARG_STRING; - addr_arg.value.string = - grpc_sockaddr_to_uri(&addresses->addresses[i].address); + grpc_arg addr_arg = + grpc_create_subchannel_address_arg(&addresses->addresses[i].address); grpc_channel_args *new_args = grpc_channel_args_copy_and_add(args->args, &addr_arg, 1); gpr_free(addr_arg.value.string); diff --git a/src/core/ext/transport/chttp2/client/chttp2_connector.c b/src/core/ext/transport/chttp2/client/chttp2_connector.c index ebe884b1158..013c96dc703 100644 --- a/src/core/ext/transport/chttp2/client/chttp2_connector.c +++ b/src/core/ext/transport/chttp2/client/chttp2_connector.c @@ -221,11 +221,8 @@ static void chttp2_connector_connect(grpc_exec_ctx *exec_ctx, grpc_connect_out_args *result, grpc_closure *notify) { chttp2_connector *c = (chttp2_connector *)con; - const grpc_arg *addr_arg = - grpc_channel_args_find(args->channel_args, GRPC_ARG_SUBCHANNEL_ADDRESS); - GPR_ASSERT(addr_arg != NULL); // Should have been set by LB policy. grpc_resolved_address addr; - grpc_uri_to_sockaddr(addr_arg->value.string, &addr); + grpc_get_subchannel_address_arg(args->channel_args, &addr); gpr_mu_lock(&c->mu); GPR_ASSERT(c->notify == NULL); c->notify = notify; From 92c93b99a0a46b7112288ca138df7e772a0431f0 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Fri, 13 Jan 2017 15:07:57 -0800 Subject: [PATCH 192/261] Ran generate_projects.sh. --- tools/doxygen/Doxyfile.c++ | 1 + tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core | 2 ++ tools/doxygen/Doxyfile.core.internal | 2 ++ 4 files changed, 6 insertions(+) diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index fa9b7057c57..84daed1041c 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -866,6 +866,7 @@ include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/exec_ctx_fwd.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/port_platform.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index bca5652a463..37e4ad3f373 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -867,6 +867,7 @@ include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/exec_ctx_fwd.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ include/grpc/impl/codegen/port_platform.h \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index ccbfe3a4e66..da990379ce4 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -807,6 +807,8 @@ include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/exec_ctx_fwd.h \ +include/grpc/impl/codegen/gpr_slice.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index fc8fac32f0d..4591aa50e3c 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -807,6 +807,8 @@ include/grpc/impl/codegen/byte_buffer_reader.h \ include/grpc/impl/codegen/compression_types.h \ include/grpc/impl/codegen/connectivity_state.h \ include/grpc/impl/codegen/exec_ctx_fwd.h \ +include/grpc/impl/codegen/gpr_slice.h \ +include/grpc/impl/codegen/gpr_slice.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/gpr_types.h \ include/grpc/impl/codegen/grpc_types.h \ From 4242075c335473f8c3fc0b578196bdc878a3b9df Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Fri, 13 Jan 2017 15:23:11 -0800 Subject: [PATCH 193/261] PHP: Prepare for 1.1.0 release --- package.xml | 46 ++++++++++++++++++++++++++++------ src/php/README.md | 7 ++++++ templates/package.xml.template | 46 ++++++++++++++++++++++++++++------ 3 files changed, 85 insertions(+), 14 deletions(-) diff --git a/package.xml b/package.xml index 4df15258275..ac5bcc54bf6 100644 --- a/package.xml +++ b/package.xml @@ -10,19 +10,20 @@ grpc-packages@google.com yes - 2016-08-22 + 2017-01-13 1.1.0dev 1.1.0dev - stable - stable + beta + beta BSD -- Reject metadata keys which are not legal #7881 +- PHP Proto3 adoption #8179 +- Various bug fixes

@@ -1215,18 +1216,49 @@ Update to wrap gRPC C Core version 0.10.0 - 1.1.0dev - 1.1.0dev + 1.0.1RC1 + 1.0.1RC1 + + + beta + beta + + 2016-10-06 + BSD + +- Reject metadata keys which are not legal #7881 + + + + + 1.0.1 + 1.0.1 stable stable - 2016-08-22 + 2016-10-27 BSD - Reject metadata keys which are not legal #7881 + + + 1.1.0dev + 1.1.0dev + + + beta + beta + + 2017-01-13 + BSD + +- PHP Proto3 adoption #8179 +- Various bug fixes + + diff --git a/src/php/README.md b/src/php/README.md index 1b15768d44a..320220d3e4a 100644 --- a/src/php/README.md +++ b/src/php/README.md @@ -163,6 +163,13 @@ of this repo. The plugin can be found in the `bins/opt` directory. We are planning to provide a better way to download and install the plugin in the future. +You can also just build the gRPC PHP protoc plugin by running: + +```sh +$ cd grpc +$ make grpc_php_plugin +``` + ### Client Stub diff --git a/templates/package.xml.template b/templates/package.xml.template index 32ed3b633e8..80f1a1fe974 100644 --- a/templates/package.xml.template +++ b/templates/package.xml.template @@ -12,19 +12,20 @@ grpc-packages@google.com yes - 2016-08-22 + 2017-01-13 ${settings.php_version.php()} ${settings.php_version.php()} - stable - stable + beta + beta BSD - - Reject metadata keys which are not legal #7881 + - PHP Proto3 adoption #8179 + - Various bug fixes @@ -281,18 +282,49 @@ - ${settings.php_version.php()} - ${settings.php_version.php()} + 1.0.1RC1 + 1.0.1RC1 + + + beta + beta + + 2016-10-06 + BSD + + - Reject metadata keys which are not legal #7881 + + + + + 1.0.1 + 1.0.1 stable stable - 2016-08-22 + 2016-10-27 BSD - Reject metadata keys which are not legal #7881 + + + 1.1.0dev + 1.1.0dev + + + beta + beta + + 2017-01-13 + BSD + + - PHP Proto3 adoption #8179 + - Various bug fixes + + From 0a5a31868a3166fd4e5b5581def5630e09e675a1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 13 Jan 2017 16:54:03 -0800 Subject: [PATCH 194/261] Name constant --- src/core/ext/transport/chttp2/transport/chttp2_transport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 339d2138c65..68a6a2155dd 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -62,7 +62,7 @@ #define DEFAULT_WINDOW 65535 #define DEFAULT_CONNECTION_WINDOW_TARGET (1024 * 1024) #define MAX_WINDOW 0x7fffffffu - +#define MAX_WRITE_BUFFER_SIZE (64 * 1024 * 1024) #define DEFAULT_MAX_HEADER_LIST_SIZE (16 * 1024) #define MAX_CLIENT_STREAM_ID 0x7fffffffu @@ -326,7 +326,7 @@ static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) { t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer( &channel_args->args[i], - (grpc_integer_options){0, 0, 64 * 1024 * 1024}); + (grpc_integer_options){0, 0, MAX_WRITE_BUFFER_SIZE}); } else { static const struct { const char *channel_arg_name; From c1002c9f22e7bddc9d71831a6c20e0cb844f7846 Mon Sep 17 00:00:00 2001 From: Matt Kwong Date: Fri, 13 Jan 2017 17:26:11 -0800 Subject: [PATCH 195/261] Add api-fuzzer corpus --- .../08455b3ef9d516deb8155d8db7d51c43ce0ff07a | Bin 0 -> 426 bytes .../0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4 | Bin 0 -> 167 bytes .../14064ac4844c709b247a4345a92d8be9766785c4 | Bin 0 -> 316 bytes .../1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2 | Bin 0 -> 345 bytes .../20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12 | Bin 0 -> 199 bytes .../2378c3f1206f20711468391ce739116ffe58374b | Bin 0 -> 216 bytes .../40640a91fda4e4e42d3063a28b9ffbba1b8c3701 | Bin 0 -> 226 bytes .../49f564289c79de9e0342f8b0821a167bc8c5ec00 | Bin 0 -> 183 bytes .../507865c4a5ce880b80400d93fa85def2682581cb | Bin 0 -> 314 bytes .../5f2fdb01d8ff632803ca2b732a7c088c6843d7d3 | Bin 0 -> 349 bytes .../61de97a9d6c4b082602c02277d8d763921f5f95b | Bin 0 -> 175 bytes .../62b039b8a318cc08471f13629da08c68c414d8e7 | Bin 0 -> 176 bytes .../641739453f7d4d3b55a1c7b79bed7da6dfd62ae0 | Bin 0 -> 175 bytes .../6589505362ffb5164a3c7cb1b9feadcddfba44e9 | Bin 0 -> 33 bytes .../724f5400f19e5a0be97022341c39eeaaaffeb390 | Bin 0 -> 336 bytes .../7254b9ff59ab3fcf345effdabbc25ebd2e907b23 | Bin 0 -> 167 bytes .../784d6f5c093ab5360670173ce001e1a446f95822 | Bin 0 -> 202 bytes .../79328fdc89d0af0e38da089dab062fd3ea5aae59 | Bin 0 -> 474 bytes .../7a2569f4daf4480ad142cb4ee7c675bed82db74c | Bin 0 -> 547 bytes .../87a300cd25d2e57745bd00499d4d2352a10a2fa1 | Bin 0 -> 35 bytes .../8a1c629910280f8beebb88687696de98da988ecc | Bin 0 -> 41 bytes .../8ff7b1568d2da2e4196c2e28617e1911d62021e6 | Bin 0 -> 371 bytes .../982f375b183d984958667461c7767206062eb4cb | Bin 0 -> 429 bytes .../98739af631223fa05ad88f1e63a52052a9bb4b1c | Bin 0 -> 178 bytes .../a78bca1ef8829d720dd5dedac3a9d4d12684da34 | Bin 0 -> 373 bytes .../ac763d89466ebfad676e75be0076831c03fe2a5d | Bin 0 -> 473 bytes .../b165523f699e6ae9b2ad15873b9d56465d1af546 | Bin 0 -> 224 bytes .../b2a5ec3ef40c68d594638218e3c943a479f82215 | Bin 0 -> 474 bytes .../b92b1c5e0dba009a9516e7185f5df019c62c5cc9 | Bin 0 -> 414 bytes .../c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533 | Bin 0 -> 425 bytes ...h-da39a3ee5e6b4b0d3255bfef95601890afd80709 | 0 .../e28ffd8c2816f12f6395805199c792d1718191df | Bin 0 -> 371 bytes .../ec823f4018389e64a99f6580277fba28df6bd136 | Bin 0 -> 226 bytes .../ee2c1ac1e668f22836cf25a59495e778b0e2c7a8 | Bin 0 -> 338 bytes .../ee6855178435d2046d8763ecae46e1e0a71a95f4 | Bin 0 -> 178 bytes .../eeb310d91038cb02862e187e68c5d6578233485b | Bin 0 -> 46 bytes .../f07bc2907c95f2aeb79ca60e2ad826e13b848f45 | Bin 0 -> 351 bytes .../fb655905396b768cf3ff015afdb0b564dae2cdfd | Bin 0 -> 349 bytes .../fdb038087233cd176746558875932029f779221d | Bin 0 -> 371 bytes tools/run_tests/generated/tests.json | 932 +++++++++++++++++- 40 files changed, 895 insertions(+), 37 deletions(-) create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374b create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95b create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988ecc create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485b create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45 create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd create mode 100644 test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221d diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a b/test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a new file mode 100644 index 0000000000000000000000000000000000000000..4b698ba9ee26c4cd200fcbdc446d61490dafbd70 GIT binary patch literal 426 zcmZutJx;?g6#neANgz=db|fYcLp!n13vdf7G;UQX#L;t-iixEIOk98~^a>oN$EXnI zIRP~wEWPD@fA6!jnp#c32&b4W&D>c1#tSL`0KE6a6;+~}3#xuoF3mTk$EjLOtu0hW zD_yHHd(g_Tp4PdBo!U>gC{&%%yY|=-dUfvUEJ=egB>0Va#Nh>q1$sZ${AQBjo>TR^&`3x2qGEE*^T~S!L$F9uG5cPj5ZTZ zrYUnp=6)?8LtjANCh2*rClrU9t826ZB4*cs#}lGCkfZ|SxbJok=fsv%gZ&OCF`^yr F@CB$9iKhSn literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4 b/test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4 new file mode 100644 index 0000000000000000000000000000000000000000..2889e7040e8eaf3d989ac735a1f866b4fef66b9f GIT binary patch literal 167 zcmZQ7PAw`+En;9`Vc=rWSI^If@EOyK3P3nnuedlTKCvo2wIn_-F*h|nAE>xUGczTX zp;)i@-~Z&C_>#mTs4PShB-j7{|Nl_NdTt(OCI(gpFkt-E$-}_Fc$9@fn4O6&l}Xv) wzkRTNM-dZSIbSMAQJIDoLm6Yyf1r|dUg!cAtJxD|r@XJuJxCeF<- zF}06mW;rn@BSO~8eteu7XL(G{1oPi}^WHzTb{jPrP*PcO_5BjQaNdIk+{Te=0-vNC z;s&*CsU%AXhWe5;eCH^Ks7iDWQ7@ix;5EcYQN4OP9$eg>uUV>PlQid17r9^`<`mUN zJ0-p5yQu5K#ClPkZJ~uIPd!0i=Q@4?gGq_&Z~pWl)Z#WC8lv#Pl%FyEo0{KHhZVT$WgwbCKNHTTb#&EVG+y zhMTxgpJqw%>vm@F{4>12qKBQqu&1zw<)QbdAwVyEZ0m}Rlxn0a&%Je}S?!C23wP7FCgmw>Y9g+SJjhCpQ(eT+p ly0EL%vv2D2*B|N_$!Y|V@?RDWLS4Gx4TA3pQjfUFamM1UU6|wd}2|0YDs)vVs2`D zK2S$;Mq*xGYEFD{Nn&z#d{Sv{{$FNx!?Ja&XlQ)?^ zGf@<LFC9L4vo?Pdn~41iy$C|yvdiTp$4zR TFY8(xuH(YYX3{a;wz_=)JcdB; literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701 b/test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701 new file mode 100644 index 0000000000000000000000000000000000000000..f11821acc9a961be2847021d76fabc0f07f5bea6 GIT binary patch literal 226 zcmZvVJ8r^26h-fh5nqdjB~XAUfEo%&M~|pS6Z^?n*kknkK{QE25f;NTvJo0~kRpxq zkW$jz;(pH6IdMe{r6N8C)0~3Lg_h5zl)%`CTmcQBfi7mFEE8AyZx3nzFY?4#j;Jus zrerdK1$*lpB_=Oya4_#>oP_dVQ{xs?aU9xXjJn>b&q2@kG?d`6ev10N`l8jr64~uuY@5!&kCqJGbJ&T;s5_o#(H6H9%d#6#ttS11_lQp zh6Bc5ojeRY3=E7%Ss0kvnb=a9lnt!ygY`R#nApnsQaOssG_)AX7>oV`m9%_&1T@Wx Sv4xT05r-z{T86a@9t;3_wlwYl literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb b/test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb new file mode 100644 index 0000000000000000000000000000000000000000..c4473eacbb20789a2fb08b49a3affb734ee8e81f GIT binary patch literal 314 zcmXw!u}T9$6h-e$WSwY;NWj`4$Qno_ZJM<9g6%NbJd?$B6W>fWq_Wu}*!U4*xj*5L z2n+s%h2t#Zs~-0h=iW0J0TANUtW!v_;B_*Z)4kbbPMeKet~hl&g!m6xo9U%<>oIck zNP1Whb2=y3k^S*Wrk&vhIUS&0{j*o^{d4cQ(~`j?BO|_nR(PA6av$eW7x*OA5hrLx zQsPiZW<+0-X73yqjXfD9l-nl@1@TeVFP<)@!%V^sr#qj`zU>}y0brW6Dp6}v8 zGpcOEN2rGf=phcuqYB=OQnj(|DwyB;LzCZ1nNov MZG{Rqcmvb~zi}X0q5uE@ literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3 b/test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3 new file mode 100644 index 0000000000000000000000000000000000000000..b91a052534a42714136e08b8481e1cc6604783b1 GIT binary patch literal 349 zcmZ9GJxjw-6o%h(TVt#xi{R)74hlNd!F|^reLX9fG&C%53)=)GsTq0B6&0_it8Yhn9CpymmFle99@NJ z$`s2`V~(=)GL%(tqfJ2=b6Nu5*4hQ#?d|qETOe#6eLeO8dg-FGZ5%cyli7UyAja7@ zj{dKA$e^ROdNr41`LC1^3p6rg2bKww`DjhQdMbSDu`8AD4^fHwq#Tt=m6WTXD8rKR zr=?bwXL5Yxc!0dK-gDms&WGWPCuK>fCbWJgj5QD#aiL;wH(|3ew;g}Hf{nHU%u85kH#7$AW0 zS0@jUdz6KNnVpF(l}Xv)zkRTNM-dZSIbSMAQJIDoLm6Yyf1r|dnVPtr; NmVuLlVJ(9P0{}^oHBJBk literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7 b/test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7 new file mode 100644 index 0000000000000000000000000000000000000000..e5e218acc372b72f89d20710875377e0a1ff8da9 GIT binary patch literal 176 zcmZQ7PAw`+En;9`Vc=rWSI^If@EOyK3P3nnuehirH9kGDI43?YF*h|nAE-DvBQY;8 zH7CBfBr(Y}GAB8^GzDlvVlG&+C^IFMq5uE?|DlZa!rVN}Obm<+V89BY7=K;rgj5QD#aiL;wH(|3ew;g}Hf{nHU%u85kH#KnMsJ ze|7Qz$)hX`%+?)3b5mP|ngXrl+O8D^U-du9=u{64<5iBu+ZGS!MQDvXII1nb*t6(rK}ig>5A z%(&9TYqg9~RpqEZXnE-1@x)~h3|9k>li=~WIPmp&D>YfGLXrukp^H$6bHyjS6IY0x t_~ir*kJ9w|^X-}c1x3!~_yvJM$1jj-fKZD}S&L2wbf-9A!9sygx&ch5YXJZN literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23 b/test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23 new file mode 100644 index 0000000000000000000000000000000000000000..92371e031fd5a3a16eb92dcc275eff45ee322ad8 GIT binary patch literal 167 zcmZQ7PAw`+En;9`Vc=rWSI^HcP6zQB(~Al~I9ac_I47|vK0UQ0J})shH9j9GnU& literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822 b/test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822 new file mode 100644 index 0000000000000000000000000000000000000000..79885b7f2a89ad24923574be3e4f35e300028aee GIT binary patch literal 202 zcmXYqy$%6E6ot>775~wA1O-u`)`(6o>dDx>Sz>oq?yeP;MnUCCJcbwX5DLwhgp-`& zBwxOxa+Z<>sGx~)Kg)i59?PD5!%?0m+DOcWwkBnrc{tn{YdO(*VZxnWAGS&44JOrg z$|Bo{ad*zG=-h3!0|g@B@8U4Ck&%-=_#16vwgsrbFZ8*!J^8F4sHrNe-o(w81weEm2?-)ZCoaGhat0;_ zu91ZsFm%8?TSTI}tB6(x^u*z`6@XZQx6vn<5x$&4=&Q0js_Y>&JF1@fZ+$BEv^>eIvh z!-Bz(+TwBd=y-BIev#C^+Z2wh`~WH%@tWty^@3KcirgR7SLM?>|J!${piYXO>|wHlihA zO`vVSbqMfjtmPd5kw8)TrHO=tCqGa)-~ST*3er9e1LLS$w~h7eI^ZI^4jK#K41NK} C*OFTR literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c b/test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c new file mode 100644 index 0000000000000000000000000000000000000000..75b55e7e107328f55f696cc1053637e8f9b78ed8 GIT binary patch literal 547 zcmZuuJ5Iwu6r5crj=@$M`bbnDilm|m7vL6_v7dt_V_WM_L`9PVDlWhYka7hMlVe1P z<*l87R$yt1-I+I^XQ{R7NC6|9Vv&|NWleAVAZ1M!!0+b1QkCe>xvFf+MR}kMxT@lL zUFTt>R@8(=^gvb4i{=Hnx#+-u~N>JQXh-G2lG7!m4wo$&6_Z41&}q5=v%;67`- zW+`U+{WvW~>nW+SEs{``cbR~6O#`{~gIPyY<+~*LAulukbtG2zl9%_%j;wLrY`=}@==Qu#0xX;67zX1j|vuFSS literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1 b/test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1 new file mode 100644 index 0000000000000000000000000000000000000000..c8f79862bc3c1721fbcccce5198bfe48ea3d3eec GIT binary patch literal 35 qcmZQ#<0?Ap3uLHfBQZ4d91=9D#gaO3^Q&DA!NIL8v==M&hz>% literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb b/test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb new file mode 100644 index 0000000000000000000000000000000000000000..01d07d64087e8f4ad4c927b72adff6746ad91a4b GIT binary patch literal 429 zcmZXQF;Bu!6ot=wkXnJ%7>y%pOcWV_nWd{cgJV<5wKkTP+&*fUTu8*pU*Xul;^c19 z#6RIuZ&h5p$s2C&yXT(o?E7(yBW(c+QmUasUIc>$M{}Q7-ZCTh{E!kObFJXmR>osCNq!IX;j}CsuV8#L literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c b/test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c new file mode 100644 index 0000000000000000000000000000000000000000..a4adb7aee6aed697073e4b761c17810c122928c5 GIT binary patch literal 178 zcmWkmy$*sv80!J?m(53T&^V|wlWx9%^W}gGUW7Yx2du_~#fRZBd=VDkz`+GSnzTuq zww{x=kroKBz+qzyc?!;-%$AIp?48TGu$ip57KP-7+R065EpzT-!RvdKs63?$QE(m6 zTBV{?7=|l*td^ngfjt?3(_C+zrL@z_Q)~B`GhZe5ypijyHWg=0 zfMi!3{__98MoM-^4zuRgx%MvIw&poVKkhlRyH`#N&YL2*@&4`VVjU4qF^Bqo2i7## z(HX^yMrB^Iys7hEglm^sCu}NjAXz3Idxdk20rwCPMw&VTbqIDN=#59H$3a2#512u7HUIzs literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d b/test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d new file mode 100644 index 0000000000000000000000000000000000000000..64c9720c9b9d11d6183076147266f1ea1cd0115f GIT binary patch literal 473 zcmZXQy-veG5QOKB=s1$dh#yfx5E6tGN$NCi=_x2J$610!Vn-XtQ7Rfsgo>x2^s7+O zBU$1lkdRpeso3i7_I7sW+c!(HoNC7`OKR9Xe=@<5Hh_YZ+EQbl1>G5kQ=eDfVovP& zV~P^#YX!%Wdmh~RQA8T^#1HOi;0+hrES*Z#?UbUC9qtx6E<*~_a55r>VhiY6GG>Uj z?irM%(7*1kS({gfIBj>3auADbkjPZB@Eid)FY8hS9nUSEWrBbo0b#)fo zsG*MDZ5;pJD>A=y=JSb{_&lb>i~K2hv546LWQM~LA?W`5uxUL@j)#NBj|rjDLXp8X uRfUh^MKtm_9)^`C_4$NBqkr97^I$_)AT^JLZ>snQb0JtHvakiVw!Z;s1d5#i literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546 b/test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546 new file mode 100644 index 0000000000000000000000000000000000000000..b0b7452924d35154493a18fe3db2c24b524d5e17 GIT binary patch literal 224 zcmZQ7PAw`+En;9~OfM=()+;E=%uOt+j4uTW$0w$z=9MroF)%Q&FmN&GtLNtfMS-dv zp99rG)E5`$#3vS|re<)+UFgFh~69XgAcm@X$!T76_2S^@eVPIxwVoPOGHn6r2*6%1{Vk_rM og_)HJmA6qc9c81W+9k>NN(WpjyG`6(>#t615a zT;i87G3T6U~6UKhgT@o8v-~{{KGjHE|OW`%E#?~1MAs}#Q*>R literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9 b/test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9 new file mode 100644 index 0000000000000000000000000000000000000000..3d542f38ec941b8daf69e53a4efdc309ce989ba2 GIT binary patch literal 414 zcmZvYJx;_h5QU!|6wI=Ugg65YMJPDHw)7mpGRcr#kw1-10yH#fs5r@9YL7rkW1NIY zD}g0zjN!#5UrIa;!fbstQ@_Zdh%tw5G0Bea~nlM!7 zhF|q_VArOg+D&uOsf_3F%Dm_>l=aNC04gtr!ydKM)-joC5P%ilBZyhtUneS+ai5Sn z-g)L8SuyWRAbk3XPsHeC5j)qO}Azf>)aWbSn21IcTbfV%(y literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533 b/test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533 new file mode 100644 index 0000000000000000000000000000000000000000..c8fca17ad38310b58ac412d25d5a72f963576097 GIT binary patch literal 425 zcmZutJ5Iwu5S?8+w!u~!dL$|kMN-kg1-Qj(i6@aIA%X4aNU z(+V3^=|@zC@2SWU?96_-MX4H1ALy|o^yb|2S(*hCkic)kBlfQViGV?mZ~hfzD-U_| zG4W`e<9M&CaVj5*od@eZ3?ex$bz3${w;ZBqo}ljlK`bLVzrj!DzxXfdD;=&yxSk@J zw#pTmheCjiIDaT_)9k#%DJ9YR>KZx$B4O2l#}i_1m}UaVaox=hoD&GiTD5j literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709 b/test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709 new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df b/test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df new file mode 100644 index 0000000000000000000000000000000000000000..a867a8b0be95755dba75d7a18e644d00086fbdc0 GIT binary patch literal 371 zcmZvYJx;_h5QU!|6wI=Ugg65YMJPDHw)7mpGRcr#kw1;C1kuo>q2eUDRE|JNW1O{C zLIO*p@yzIZe&Z`s*N{?L;(-`A!v=THU1w#wIkrT_{TfAXZLOX8s%WGg-{{sfq`Ls| zp`8Bm|Gb;@5JmqiW?2HF2nPsKil7ugp9`c%)E0t?g#>XlYuRNQ7oo~Ye2iSghoC@$ zVU4AXG{yWk^ZyvnlCuC29x#7N({`przM9_5yx+%bNjQr?*9VT%uq+?DEyK_JRX6)M z`=>1oOn;%eqVMrw*sGXBDhc%jby=bBPyr6~9+Gbn%tuQA literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8 b/test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8 new file mode 100644 index 0000000000000000000000000000000000000000..f1990ac2315efdb5d9d0f2ee1dd090355d4811d6 GIT binary patch literal 338 zcmXv}!AiqG6r9~kOtloG;MpQbEVSyimtMUKUYBk1OoK5kZ#OADdC8%8@gu}ze!?FS z0{(;t*A3#FhM9qxIh6qbAx`urgA^%m;#oouy3DQ8rCqH#vpabC&oU-gD{D75DD)Gl zX+_LgLNGJ)suH)z~i>nWyAgEaE+FOX7y;z4K-u;1SmOCLSZBl6EljJdcku<)6 zg`ne2HYsH=arHhPrOee$8*Y}NB2NcD&;&| z-V17vVN67O#k literal 0 HcmV?d00001 diff --git a/test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd b/test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd new file mode 100644 index 0000000000000000000000000000000000000000..b02dabe03a80f708a041d18d13df473b2d7a97b5 GIT binary patch literal 349 zcmZXQy-ve06ot=qOE9#mC_Dg2NPrkxb_T@8j+i4W-2O;`RM$~5vSfgXC&^>*B3XC? z1|%?cQz{iKdGI;+$KM&6G=;J(1q;x{F2<)>*1l;fi*S>XwP|c*%6a@~9yrc?u}tRo z3_G&lE=l8j?Y5@(+$)^Bqo;#jzoW2)<)P1)K0t3>?3=|LQOQ~gHHb>booyAdI=*m+ zw>>Yi`w~#q)R%i&Md3r59kmjP9zTnU%0Xy9J4Zp{{MhQF@jIy^G)HKvfc1xJxWx61 ony*fhnb{q2eUDRE|JNW1O{C zLIO*p@yzIZe&Z`s*N{?L;(-`A!v=THU1w#wIkrT_{TfAXZLOX8s%WGg-{{sfq`Ls| zp`8Bm|GY{787@1n9tz$BcMS#U5u*@jZ@itSrOvjAW?^U9m)dJ!g1j46}uZk3d%mPG; thmd^8QauKl^{dorkj2SBUf@Du#sfImTjbhdh$*;DpmrYNzRUuwegOCOaY6t9 literal 0 HcmV?d00001 diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index b76263b8b98..b595ef50558 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -40169,6 +40169,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/08455b3ef9d516deb8155d8db7d51c43ce0ff07a" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/085865a209776911782f592c9f30ffe0ad3814a0" @@ -40895,6 +40917,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/0d19e60f4eb1b729e272dd5dec68e8b67f03a5f4" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/0d604693a9d3e76f54d28a26142abd729b0a9acd" @@ -41907,6 +41951,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/14064ac4844c709b247a4345a92d8be9766785c4" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/143789594154049441d565b65ce725fc4f8c12bc" @@ -42677,6 +42743,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/1901234bd7c9cb6ee19ff8b17179c481bdc7c5f2" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/190c4ca0cf29c99bc987d2792c7f62e1007c0245" @@ -43777,6 +43865,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/20ff1f8d5d34cb01d58aa334dc46a6644e6e1d12" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/21357c3613a47180eb668b1c6c849ce9096a46eb" @@ -44041,6 +44151,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/2378c3f1206f20711468391ce739116ffe58374b" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/23982956d17d2f55e61a5d9111b1c0c7ee530214" @@ -48639,6 +48771,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/40640a91fda4e4e42d3063a28b9ffbba1b8c3701" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/40b4b92460c4e76a39af9042fb3d86d491a98e16" @@ -50157,6 +50311,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/49f564289c79de9e0342f8b0821a167bc8c5ec00" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/49ff30e0f070fe37b642dd0d361c5cbca139f223" @@ -50971,6 +51147,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/507865c4a5ce880b80400d93fa85def2682581cb" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/507b8ecbb9fd3eea9084087bce22a94cca8a7c41" @@ -53303,6 +53501,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/5f2fdb01d8ff632803ca2b732a7c088c6843d7d3" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/5f52309deaa1b641fe199889d18f921d6909fc14" @@ -53679,7 +53899,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/61f410c711bc5d53be9e932217ebd035f2716417" + "test/core/end2end/fuzzers/api_fuzzer_corpus/61de97a9d6c4b082602c02277d8d763921f5f95b" ], "ci_platforms": [ "linux" @@ -53701,7 +53921,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/622a3505d10767b795fc2c2922c0d5305d9b84e6" + "test/core/end2end/fuzzers/api_fuzzer_corpus/61f410c711bc5d53be9e932217ebd035f2716417" ], "ci_platforms": [ "linux" @@ -53723,7 +53943,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/6230cce2862a18c4c92dc6fb4e034a1d15e1ff18" + "test/core/end2end/fuzzers/api_fuzzer_corpus/622a3505d10767b795fc2c2922c0d5305d9b84e6" ], "ci_platforms": [ "linux" @@ -53745,7 +53965,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/6245a105123761558a71a9207b3048d2f3d691f0" + "test/core/end2end/fuzzers/api_fuzzer_corpus/6230cce2862a18c4c92dc6fb4e034a1d15e1ff18" ], "ci_platforms": [ "linux" @@ -53767,7 +53987,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/629eac0e7443a273b5c351757c03fe15a0b87c1c" + "test/core/end2end/fuzzers/api_fuzzer_corpus/6245a105123761558a71a9207b3048d2f3d691f0" ], "ci_platforms": [ "linux" @@ -53789,7 +54009,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/62c995646f15be1819bd13e32a60af46297d73b4" + "test/core/end2end/fuzzers/api_fuzzer_corpus/629eac0e7443a273b5c351757c03fe15a0b87c1c" ], "ci_platforms": [ "linux" @@ -53811,7 +54031,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/62fbfe90a1b9ac471bc2644c896f64515f6b3c7e" + "test/core/end2end/fuzzers/api_fuzzer_corpus/62b039b8a318cc08471f13629da08c68c414d8e7" ], "ci_platforms": [ "linux" @@ -53833,7 +54053,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/634d809c430738b89f0e677eec36506e537e86b3" + "test/core/end2end/fuzzers/api_fuzzer_corpus/62c995646f15be1819bd13e32a60af46297d73b4" ], "ci_platforms": [ "linux" @@ -53855,7 +54075,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/63626e71d4e8e15905f13933f5b88d89073b3411" + "test/core/end2end/fuzzers/api_fuzzer_corpus/62fbfe90a1b9ac471bc2644c896f64515f6b3c7e" ], "ci_platforms": [ "linux" @@ -53877,7 +54097,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/638c36cfe098b98008e594eddf90fdacfc078fae" + "test/core/end2end/fuzzers/api_fuzzer_corpus/634d809c430738b89f0e677eec36506e537e86b3" ], "ci_platforms": [ "linux" @@ -53899,7 +54119,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/63b74d17bfbd015bb55dda59a05101bee001369c" + "test/core/end2end/fuzzers/api_fuzzer_corpus/63626e71d4e8e15905f13933f5b88d89073b3411" ], "ci_platforms": [ "linux" @@ -53921,7 +54141,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/63b91deaac58a7b64fb5999628ff3ff5d32b719d" + "test/core/end2end/fuzzers/api_fuzzer_corpus/638c36cfe098b98008e594eddf90fdacfc078fae" ], "ci_platforms": [ "linux" @@ -53943,7 +54163,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/63babc04d35adbe48add6e93386dfc838b0bbd25" + "test/core/end2end/fuzzers/api_fuzzer_corpus/63b74d17bfbd015bb55dda59a05101bee001369c" ], "ci_platforms": [ "linux" @@ -53965,7 +54185,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/63d83cb5580d3222eb5e2d7982f7f995634ba5c1" + "test/core/end2end/fuzzers/api_fuzzer_corpus/63b91deaac58a7b64fb5999628ff3ff5d32b719d" ], "ci_platforms": [ "linux" @@ -53987,7 +54207,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/6421db654fff309bc191aba0330fbcd1347655e3" + "test/core/end2end/fuzzers/api_fuzzer_corpus/63babc04d35adbe48add6e93386dfc838b0bbd25" ], "ci_platforms": [ "linux" @@ -54009,7 +54229,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/645b8377f905399af625a01c76ff088745fe1640" + "test/core/end2end/fuzzers/api_fuzzer_corpus/63d83cb5580d3222eb5e2d7982f7f995634ba5c1" ], "ci_platforms": [ "linux" @@ -54031,7 +54251,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/646c501021c79bf6eb1a39a9bcc82e018f31bca2" + "test/core/end2end/fuzzers/api_fuzzer_corpus/641739453f7d4d3b55a1c7b79bed7da6dfd62ae0" ], "ci_platforms": [ "linux" @@ -54053,7 +54273,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/649cf0ee983cb5792042687181ce7e4d81f090a5" + "test/core/end2end/fuzzers/api_fuzzer_corpus/6421db654fff309bc191aba0330fbcd1347655e3" ], "ci_platforms": [ "linux" @@ -54075,7 +54295,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/64c572e594c2d491a902e8fdff7b617ac0c6881b" + "test/core/end2end/fuzzers/api_fuzzer_corpus/645b8377f905399af625a01c76ff088745fe1640" ], "ci_platforms": [ "linux" @@ -54097,7 +54317,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/64ce7e5553de2c081991af4fc386bffdd8d2e210" + "test/core/end2end/fuzzers/api_fuzzer_corpus/646c501021c79bf6eb1a39a9bcc82e018f31bca2" ], "ci_platforms": [ "linux" @@ -54119,7 +54339,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/64d55e872c2148eefb0d7c3df101fd955b709f24" + "test/core/end2end/fuzzers/api_fuzzer_corpus/649cf0ee983cb5792042687181ce7e4d81f090a5" ], "ci_platforms": [ "linux" @@ -54141,7 +54361,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/64eb970cc80162a4b80d49364f4227db3429e156" + "test/core/end2end/fuzzers/api_fuzzer_corpus/64c572e594c2d491a902e8fdff7b617ac0c6881b" ], "ci_platforms": [ "linux" @@ -54163,7 +54383,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/6531f1c311678c9247ad6820519bc7e73f56cb81" + "test/core/end2end/fuzzers/api_fuzzer_corpus/64ce7e5553de2c081991af4fc386bffdd8d2e210" ], "ci_platforms": [ "linux" @@ -54185,7 +54405,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/655b880459e6e00100727af9df52b64f6d77a653" + "test/core/end2end/fuzzers/api_fuzzer_corpus/64d55e872c2148eefb0d7c3df101fd955b709f24" ], "ci_platforms": [ "linux" @@ -54207,7 +54427,95 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/655f952ec49cbc6176ad1bcfa45a87bd6c3542f0" + "test/core/end2end/fuzzers/api_fuzzer_corpus/64eb970cc80162a4b80d49364f4227db3429e156" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/6531f1c311678c9247ad6820519bc7e73f56cb81" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/655b880459e6e00100727af9df52b64f6d77a653" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/655f952ec49cbc6176ad1bcfa45a87bd6c3542f0" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/6589505362ffb5164a3c7cb1b9feadcddfba44e9" ], "ci_platforms": [ "linux" @@ -56141,6 +56449,50 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/724f5400f19e5a0be97022341c39eeaaaffeb390" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/7254b9ff59ab3fcf345effdabbc25ebd2e907b23" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/727f43500183aec9c0d9be7d2363fa1761cda5d5" @@ -57131,6 +57483,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/784d6f5c093ab5360670173ce001e1a446f95822" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/788f18727a0aeb5e200527bca7c889c9954be343" @@ -57219,6 +57593,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/79328fdc89d0af0e38da089dab062fd3ea5aae59" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/7957953ca449974ec39c6a137c0acdedb71c3b02" @@ -57417,6 +57813,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/7a2569f4daf4480ad142cb4ee7c675bed82db74c" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/7a5a769942efac79863bb154cf1e7574e6d98e22" @@ -59397,6 +59815,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/87a300cd25d2e57745bd00499d4d2352a10a2fa1" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/87add83a18a25fe585df8adc124eae6d70733f74" @@ -59793,6 +60233,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/8a1c629910280f8beebb88687696de98da988ecc" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/8a4183e6bb75036228a42039d678fca0ea6751b7" @@ -60653,7 +61115,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/901c9a33205897999e7e78063ccdc5d363267568" + "test/core/end2end/fuzzers/api_fuzzer_corpus/8ff7b1568d2da2e4196c2e28617e1911d62021e6" ], "ci_platforms": [ "linux" @@ -60675,7 +61137,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/90230730fae07c8eeb6b5bd571a119b486a21473" + "test/core/end2end/fuzzers/api_fuzzer_corpus/901c9a33205897999e7e78063ccdc5d363267568" ], "ci_platforms": [ "linux" @@ -60697,7 +61159,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/904edc7bb14e4da0172f3d58a74c8abf141da9fb" + "test/core/end2end/fuzzers/api_fuzzer_corpus/90230730fae07c8eeb6b5bd571a119b486a21473" ], "ci_platforms": [ "linux" @@ -60719,7 +61181,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/9080684608701e015c764f643dc45fa939d86ed3" + "test/core/end2end/fuzzers/api_fuzzer_corpus/904edc7bb14e4da0172f3d58a74c8abf141da9fb" ], "ci_platforms": [ "linux" @@ -60741,7 +61203,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/908b1f170a721682465838d0c0eca40810beb722" + "test/core/end2end/fuzzers/api_fuzzer_corpus/9080684608701e015c764f643dc45fa939d86ed3" ], "ci_platforms": [ "linux" @@ -60763,7 +61225,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/90a94b19bcf5aed7bfee94764acc906e889e47f8" + "test/core/end2end/fuzzers/api_fuzzer_corpus/908b1f170a721682465838d0c0eca40810beb722" ], "ci_platforms": [ "linux" @@ -60785,7 +61247,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/90cd72030567bddbce06152fa0af1a024d542fa7" + "test/core/end2end/fuzzers/api_fuzzer_corpus/90a94b19bcf5aed7bfee94764acc906e889e47f8" ], "ci_platforms": [ "linux" @@ -60807,7 +61269,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/910246d4e894dbf88b09e9c1994e0f7bd563bcc5" + "test/core/end2end/fuzzers/api_fuzzer_corpus/90cd72030567bddbce06152fa0af1a024d542fa7" ], "ci_platforms": [ "linux" @@ -60829,7 +61291,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/913614cd0ae1b1210d2f1bc354b876080726f7a8" + "test/core/end2end/fuzzers/api_fuzzer_corpus/910246d4e894dbf88b09e9c1994e0f7bd563bcc5" ], "ci_platforms": [ "linux" @@ -60851,7 +61313,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/91434e8bf241b54d98e0f664a12ecf5c9d144a8d" + "test/core/end2end/fuzzers/api_fuzzer_corpus/913614cd0ae1b1210d2f1bc354b876080726f7a8" ], "ci_platforms": [ "linux" @@ -60873,7 +61335,7 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/91e2f574e7ceb7f69a93011aac68903cd014a6c7" + "test/core/end2end/fuzzers/api_fuzzer_corpus/91434e8bf241b54d98e0f664a12ecf5c9d144a8d" ], "ci_platforms": [ "linux" @@ -60895,7 +61357,29 @@ }, { "args": [ - "test/core/end2end/fuzzers/api_fuzzer_corpus/92273cf09f18534ae700c1f35dfab49faa091c54" + "test/core/end2end/fuzzers/api_fuzzer_corpus/91e2f574e7ceb7f69a93011aac68903cd014a6c7" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/92273cf09f18534ae700c1f35dfab49faa091c54" ], "ci_platforms": [ "linux" @@ -61597,6 +62081,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/982f375b183d984958667461c7767206062eb4cb" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/984b6ee241b92be62923c6dc5bacaadb36183b89" @@ -61663,6 +62169,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/98739af631223fa05ad88f1e63a52052a9bb4b1c" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/988bd333d5dabe1561cf4429e7481ff110be0da4" @@ -63797,6 +64325,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/a78bca1ef8829d720dd5dedac3a9d4d12684da34" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/a7ccc1f7db49512983fe4d42c16b2160357e3585" @@ -64523,6 +65073,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/ac763d89466ebfad676e75be0076831c03fe2a5d" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/ac7b2971ff39a368145148524511dd68df83d522" @@ -64985,6 +65557,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/b165523f699e6ae9b2ad15873b9d56465d1af546" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/b1e28018e26e6baaba5a907e5e6ff9b7a7942018" @@ -65095,6 +65689,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/b2a5ec3ef40c68d594638218e3c943a479f82215" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/b2af0db70de3a6ddcb188d1f6f2a673133a8f9c7" @@ -66239,6 +66855,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/b92b1c5e0dba009a9516e7185f5df019c62c5cc9" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/b9318513eb6b1db553855cd062ebbd4d1db9b846" @@ -68373,6 +69011,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/c5cd7af16e7bc0049445d5a0b92a3d4b7e5e3533" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/c5dbc50d9174bde5542b2bb18c63f6583a23ff13" @@ -71871,6 +72531,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/crash-da39a3ee5e6b4b0d3255bfef95601890afd80709" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/crash-dc6abf90d5e8e1b96f7e25f418b1a7f572e6a738" @@ -75039,6 +75721,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/e28ffd8c2816f12f6395805199c792d1718191df" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/e29bab478641dd412057dfb6b0a0d78afd96dd60" @@ -76513,6 +77217,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/ec823f4018389e64a99f6580277fba28df6bd136" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/ec89eb7e84e6cf7859ab478362e0ae5227a5e154" @@ -76843,6 +77569,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/ee2c1ac1e668f22836cf25a59495e778b0e2c7a8" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/ee624b408f8a50c79cdaebf4fb4195e6162b70da" @@ -76865,6 +77613,50 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/ee6855178435d2046d8763ecae46e1e0a71a95f4" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/eeb310d91038cb02862e187e68c5d6578233485b" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/eed65ac63a044c87423f333f3b9c5f0d3bc7bd3b" @@ -77129,6 +77921,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/f07bc2907c95f2aeb79ca60e2ad826e13b848f45" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/f0a7e39c194ee3f30312ae2f4827bdbd43416a42" @@ -78779,6 +79593,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/fb655905396b768cf3ff015afdb0b564dae2cdfd" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/fb76689d3c70bd5927b3256eda9738a2208e2b13" @@ -79197,6 +80033,28 @@ ], "uses_polling": false }, + { + "args": [ + "test/core/end2end/fuzzers/api_fuzzer_corpus/fdb038087233cd176746558875932029f779221d" + ], + "ci_platforms": [ + "linux" + ], + "cpu_cost": 0.1, + "exclude_configs": [ + "tsan" + ], + "exclude_iomgrs": [ + "uv" + ], + "flaky": false, + "language": "c", + "name": "api_fuzzer_one_entry", + "platforms": [ + "linux" + ], + "uses_polling": false + }, { "args": [ "test/core/end2end/fuzzers/api_fuzzer_corpus/fdecd05733278ece9993eb2bef13917675cc062c" From 62d895bc77ec9a06659ad66bddc7930eb3ce24fe Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 12 Jan 2017 17:16:48 -0800 Subject: [PATCH 196/261] Paper-over Python errors This reads directly off of the slices rather than ref'ing and unref'ing them. There's likely some silliness w.r.t. interned slices and references to them outliving their associated call objects, but we are just ignoring that for now. --- .gitignore | 5 +- .../_cython/_cygrpc/completion_queue.pyx.pxi | 6 +- .../grpc/_cython/_cygrpc/records.pxd.pxi | 5 ++ .../grpc/_cython/_cygrpc/records.pyx.pxi | 57 +++++++++++++------ src/python/grpcio/grpc/_server.py | 2 + 5 files changed, 56 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 31124451768..06a3d25c3d5 100644 --- a/.gitignore +++ b/.gitignore @@ -31,7 +31,7 @@ coverage # python compiled objects *.pyc -#eclipse project files +# eclipse project files .cproject .project .settings @@ -110,3 +110,6 @@ bazel-genfiles bazel-grpc bazel-out bazel-testlogs + +# Debug output +gdb.txt diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index a258ba40639..2b5cce88a4f 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -70,6 +70,8 @@ cdef class CompletionQueue: operation_call = tag.operation_call request_call_details = tag.request_call_details request_metadata = tag.request_metadata + if request_metadata is not None: + request_metadata._claim_slice_ownership() batch_operations = tag.batch_operations if tag.is_new_request: # Stuff in the tag not explicitly handled by us needs to live through @@ -91,7 +93,7 @@ cdef class CompletionQueue: c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME) if deadline is not None: c_deadline = deadline.c_time - + while True: c_timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c_increment) if gpr_time_cmp(c_timeout, c_deadline) > 0: @@ -100,7 +102,7 @@ cdef class CompletionQueue: self.c_completion_queue, c_timeout, NULL) if event.type != GRPC_QUEUE_TIMEOUT or gpr_time_cmp(c_timeout, c_deadline) == 0: break; - + # Handle any signals with gil: cpython.PyErr_CheckSignals() diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index 870da51fa8b..3644b7cdae5 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -77,6 +77,8 @@ cdef class Slice: cdef void _assign_slice(self, grpc_slice new_slice) nogil @staticmethod cdef Slice from_slice(grpc_slice slice) + @staticmethod + cdef bytes bytes_from_slice(grpc_slice slice) cdef class ByteBuffer: @@ -113,7 +115,10 @@ cdef class Metadatum: cdef class Metadata: cdef grpc_metadata_array c_metadata_array + cdef bint owns_metadata_slices cdef object metadata + cdef void _claim_slice_ownership(self) nogil + cdef void _drop_slice_ownership(self) nogil cdef class Operation: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index b7a75cd97a0..30e7b9657a9 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -189,11 +189,11 @@ cdef class CallDetails: @property def method(self): - return Slice.from_slice(self.c_details.method).bytes() + return Slice.bytes_from_slice(self.c_details.method) @property def host(self): - return Slice.from_slice(self.c_details.host).bytes() + return Slice.bytes_from_slice(self.c_details.host) @property def deadline(self): @@ -251,12 +251,16 @@ cdef class Slice: self._assign_slice(slice) return self - def bytes(self): + @staticmethod + cdef bytes bytes_from_slice(grpc_slice slice): with nogil: - pointer = grpc_slice_start_ptr(self.c_slice) - length = grpc_slice_length(self.c_slice) + pointer = grpc_slice_start_ptr(slice) + length = grpc_slice_length(slice) return (pointer)[:length] + def bytes(self): + return Slice.bytes_from_slice(self.c_slice) + def __dealloc__(self): with nogil: grpc_slice_unref(self.c_slice) @@ -466,13 +470,14 @@ cdef class _MetadataIterator: cdef class Metadata: def __cinit__(self, metadata): - grpc_init() + with nogil: + grpc_init() + grpc_metadata_array_init(&self.c_metadata_array) + self.owns_metadata_slices = False self.metadata = list(metadata) - for metadatum in metadata: + for metadatum in self.metadata: if not isinstance(metadatum, Metadatum): raise TypeError("expected list of Metadatum") - with nogil: - grpc_metadata_array_init(&self.c_metadata_array) self.c_metadata_array.count = len(self.metadata) self.c_metadata_array.capacity = len(self.metadata) with nogil: @@ -484,23 +489,43 @@ cdef class Metadata: (self.metadata[i]).c_metadata) def __dealloc__(self): - # this frees the allocated memory for the grpc_metadata_array (although - # it'd be nice if that were documented somewhere...) - # TODO(atash): document this in the C core - grpc_metadata_array_destroy(&self.c_metadata_array) - grpc_shutdown() + with nogil: + self._drop_slice_ownership() + # this frees the allocated memory for the grpc_metadata_array (although + # it'd be nice if that were documented somewhere...) + # TODO(atash): document this in the C core + grpc_metadata_array_destroy(&self.c_metadata_array) + grpc_shutdown() def __len__(self): return self.c_metadata_array.count def __getitem__(self, size_t i): + if i >= self.c_metadata_array.count: + raise IndexError return Metadatum( - key=Slice.from_slice(self.c_metadata_array.metadata[i].key).bytes(), - value=Slice.from_slice(self.c_metadata_array.metadata[i].value).bytes()) + key=Slice.bytes_from_slice(self.c_metadata_array.metadata[i].key), + value=Slice.bytes_from_slice(self.c_metadata_array.metadata[i].value)) def __iter__(self): return _MetadataIterator(self) + cdef void _claim_slice_ownership(self) nogil: + if self.owns_metadata_slices: + return + for i in range(self.c_metadata_array.count): + grpc_slice_ref(self.c_metadata_array.metadata[i].key) + grpc_slice_ref(self.c_metadata_array.metadata[i].value) + self.owns_metadata_slices = True + + cdef void _drop_slice_ownership(self) nogil: + if not self.owns_metadata_slices: + return + for i in range(self.c_metadata_array.count): + grpc_slice_unref(self.c_metadata_array.metadata[i].key) + grpc_slice_unref(self.c_metadata_array.metadata[i].value) + self.owns_metadata_slices = False + cdef class Operation: diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index 5223712dfa7..75f661340cf 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -576,6 +576,8 @@ def _handle_with_method_handler(rpc_event, method_handler, thread_pool): def _handle_call(rpc_event, generic_handlers, thread_pool): + if not rpc_event.success: + return None if rpc_event.request_call_details.method is not None: method_handler = _find_method_handler(rpc_event, generic_handlers) if method_handler is None: From 180b32380c30c2562dca1e158555f024b076f13c Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 13 Jan 2017 17:42:53 -0800 Subject: [PATCH 197/261] Use grpc_slice at core boudary --- .../GRPCClient/private/GRPCChannel.m | 2 +- .../GRPCClient/private/GRPCWrappedCall.m | 7 +++---- .../GRPCClient/private/NSDictionary+GRPC.m | 18 +++++++++--------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index e49aceefe18..b4a7c247efd 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -200,7 +200,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { return grpc_channel_create_call(_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS, queue.unmanagedQueue, - path.UTF8String, + grpc_slice_from_copied_string(path.UTF8String), NULL, // Passing NULL for host gpr_inf_future(GPR_CLOCK_REALTIME), NULL); } diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 38fcae0299d..7e734950431 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -194,7 +194,7 @@ @implementation GRPCOpRecvStatus{ grpc_status_code _statusCode; - char *_details; + grpc_slice _details; size_t _detailsCapacity; grpc_metadata_array _trailers; } @@ -208,7 +208,6 @@ _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; _op.data.recv_status_on_client.status = &_statusCode; _op.data.recv_status_on_client.status_details = &_details; - _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity; grpc_metadata_array_init(&_trailers); _op.data.recv_status_on_client.trailing_metadata = &_trailers; if (handler) { @@ -217,7 +216,7 @@ _handler = ^{ __strong typeof(self) strongSelf = weakSelf; NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode - details:strongSelf->_details]; + details:(char*)GRPC_SLICE_START_PTR(strongSelf->_details)]; NSDictionary *trailers = [NSDictionary grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; handler(error, trailers); @@ -229,7 +228,7 @@ - (void)dealloc { grpc_metadata_array_destroy(&_trailers); - gpr_free(_details); + grpc_slice_unref(_details); } @end diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index 7477da7619e..f834fef5e93 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -47,12 +47,12 @@ @implementation NSData (GRPCMetadata) + (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata { // TODO(jcanizales): Should we use a non-copy constructor? - return [self dataWithBytes:metadata->value length:metadata->value_length]; + return [self dataWithBytes:GRPC_SLICE_START_PTR(metadata->value) + length:GRPC_SLICE_LENGTH(metadata->value)]; } - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = self.bytes; - metadata->value_length = self.length; + metadata->value = grpc_slice_from_copied_buffer(self.bytes, self.length); } @end @@ -67,15 +67,14 @@ @implementation NSString (GRPCMetadata) + (instancetype)grpc_stringFromMetadataValue:(grpc_metadata *)metadata { - return [[self alloc] initWithBytes:metadata->value - length:metadata->value_length + return [[self alloc] initWithBytes:GRPC_SLICE_START_PTR(metadata->value) + length:GRPC_SLICE_LENGTH(metadata->value) encoding:NSASCIIStringEncoding]; } // Precondition: This object contains only ASCII characters. - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = self.UTF8String; - metadata->value_length = self.length; + metadata->value = grpc_slice_from_copied_string(self.UTF8String); } @end @@ -89,7 +88,8 @@ + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count { NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { - NSString *name = [NSString stringWithCString:entry->key encoding:NSASCIIStringEncoding]; + NSString *name = [NSString stringWithCString:(char*)GRPC_SLICE_START_PTR(entry->key) + encoding:NSASCIIStringEncoding]; if (!name || metadata[name]) { // Log if name is nil? continue; @@ -112,7 +112,7 @@ grpc_metadata *current = metadata; for (NSString* key in self) { id value = self[key]; - current->key = key.UTF8String; + current->key = grpc_slice_from_copied_string(key.UTF8String); if ([value respondsToSelector:@selector(grpc_initMetadata:)]) { [value grpc_initMetadata:current]; } else { From d3c2594883ff9aaadd387158b51fbad5dffb8624 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Mon, 16 Jan 2017 21:57:21 -0800 Subject: [PATCH 198/261] Fix test errors on string copy --- .../GRPCClient/private/GRPCWrappedCall.m | 14 +++++++++----- .../GRPCClient/private/NSDictionary+GRPC.m | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 7e734950431..43c564552bf 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -215,11 +215,15 @@ __weak typeof(self) weakSelf = self; _handler = ^{ __strong typeof(self) strongSelf = weakSelf; - NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode - details:(char*)GRPC_SLICE_START_PTR(strongSelf->_details)]; - NSDictionary *trailers = [NSDictionary - grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; - handler(error, trailers); + if (strongSelf) { + char *details = grpc_slice_to_c_string(strongSelf->_details); + NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode + details:details]; + NSDictionary *trailers = [NSDictionary + grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; + handler(error, trailers); + gpr_free(details); + } }; } } diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index f834fef5e93..feb2bb5ed8f 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -88,8 +88,10 @@ + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count { NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { - NSString *name = [NSString stringWithCString:(char*)GRPC_SLICE_START_PTR(entry->key) + char *key = grpc_slice_to_c_string(entry->key); + NSString *name = [NSString stringWithCString:key encoding:NSASCIIStringEncoding]; + gpr_free(key); if (!name || metadata[name]) { // Log if name is nil? continue; From cc641688296a3cf7efbfd30b942b4cdf8d8049e7 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Jan 2017 11:59:31 +0100 Subject: [PATCH 199/261] cmake support for generating from .proto files --- templates/CMakeLists.txt.template | 95 ++++++++++++++++++++++++++++--- 1 file changed, 87 insertions(+), 8 deletions(-) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 028c1b8c328..7868d412290 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -40,6 +40,17 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. <%! + + import re + + proto_re = re.compile('(.*)\\.proto') + + def proto_replace_ext(filename, ext): + m = proto_re.match(filename) + if not m: + return filename + return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext + def get_deps(target_dict): deps = [] if target_dict.get('baselib', False): @@ -140,6 +151,9 @@ if(TARGET libprotoc) set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc) endif() + if(TARGET protoc) + set(_gRPC_PROTOBUF_PROTOC protoc) + endif() else() message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong") endif() @@ -152,6 +166,9 @@ if(TARGET protobuf::libprotoc) set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc) endif() + if(TARGET protobuf::protoc) + set(_gRPC_PROTOBUF_PROTOC protobuf::protoc) + endif() set(_gRPC_FIND_PROTOBUF "if(NOT protobuf_FOUND)\n find_package(protobuf CONFIG)\nendif()") else() find_package(Protobuf MODULE) @@ -192,16 +209,60 @@ if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR) set(CMAKE_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_LIBDIR}/cmake/gRPC") endif() - + + # Create directory for generated .proto files + set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens) + file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}) + + # protobuf_generate_grpc_cpp + # -------------------------- + # + # Add custom commands to process ``.proto`` files to C++ using protoc and + # GRPC plugin:: + # + # protobuf_generate_grpc_cpp [...] + # + # ``ARGN`` + # ``.proto`` files + # + function(protobuf_generate_grpc_cpp) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files") + return() + endif() + + set(_protobuf_include_path -I .) + foreach(FIL <%text>${ARGN}) + get_filename_component(ABS_FIL <%text>${FIL} ABSOLUTE) + get_filename_component(FIL_WE <%text>${FIL} NAME_WE) + file(RELATIVE_PATH REL_FIL <%text>${CMAKE_SOURCE_DIR} <%text>${ABS_FIL}) + get_filename_component(REL_DIR <%text>${REL_FIL} DIRECTORY) + set(RELFIL_WE "<%text>${REL_DIR}/${FIL_WE}") + + add_custom_command( + OUTPUT <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" + <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" + <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" + <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" + COMMAND <%text>${_gRPC_PROTOBUF_PROTOC} + ARGS --grpc_out=<%text>${_gRPC_PROTO_GENS_DIR} + --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR} + --plugin=protoc-gen-grpc=$ + <%text>${_protobuf_include_path} + <%text>${REL_FIL} + DEPENDS <%text>${ABS_FIL} <%text>${_gRPC_PROTOBUF_PROTOC} grpc_cpp_plugin + WORKING_DIRECTORY <%text>${CMAKE_SOURCE_DIR} + COMMENT "Running gRPC C++ protocol buffer compiler on <%text>${FIL}" + VERBATIM) + + <%text>set_source_files_properties("${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" PROPERTIES GENERATED TRUE) + endforeach() + endfunction() + % for lib in libs: % if lib.build in ["all", "protoc", "tool"] and lib.language in ['c', 'c++']: - ## TODO(jtattermusch): grpc++_reflection includes .proto files - ## which is not yet supported and thus fails the entire build. - ## Re-enable once fixed. - % if lib.name != 'grpc++_reflection': - ${cc_library(lib)} - ${cc_install(lib)} - % endif + ${cc_library(lib)} + ${cc_install(lib)} % endif % endfor @@ -215,9 +276,24 @@ <%def name="cc_library(lib)"> add_library(${lib.name} % for src in lib.src: + % if not proto_re.match(src): ${src} + % else: + ${proto_replace_ext(src, '.pb.cc')} + ${proto_replace_ext(src, '.grpc.pb.cc')} + ${proto_replace_ext(src, '.pb.h')} + ${proto_replace_ext(src, '.grpc.pb.h')} + % endif % endfor ) + + % for src in lib.src: + % if proto_re.match(src): + protobuf_generate_grpc_cpp( + ${src} + ) + % endif + % endfor target_include_directories(${lib.name} PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR} @@ -226,6 +302,9 @@ PRIVATE <%text>${PROTOBUF_ROOT_DIR}/src PRIVATE <%text>${ZLIB_INCLUDE_DIR} PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + % if any(proto_re.match(src) for src in lib.src): + PRIVATE <%text>${_gRPC_PROTO_GENS_DIR} + % endif ) % if len(get_deps(lib)) > 0: From 54492aa70f366bfe9626f857c08702c5d010988c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Jan 2017 11:53:33 +0100 Subject: [PATCH 200/261] regenerate --- CMakeLists.txt | 142 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 126 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4627c10e2e8..a87e150b539 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -122,6 +122,9 @@ if("${gRPC_PROTOBUF_PROVIDER}" STREQUAL "module") if(TARGET libprotoc) set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc) endif() + if(TARGET protoc) + set(_gRPC_PROTOBUF_PROTOC protoc) + endif() else() message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong") endif() @@ -134,6 +137,9 @@ elseif("${gRPC_PROTOBUF_PROVIDER}" STREQUAL "package") if(TARGET protobuf::libprotoc) set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc) endif() + if(TARGET protobuf::protoc) + set(_gRPC_PROTOBUF_PROTOC protobuf::protoc) + endif() set(_gRPC_FIND_PROTOBUF "if(NOT protobuf_FOUND)\n find_package(protobuf CONFIG)\nendif()") else() find_package(Protobuf MODULE) @@ -175,7 +181,56 @@ if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR) set(CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/gRPC") endif() - +# Create directory for generated .proto files +set(_gRPC_PROTO_GENS_DIR ${CMAKE_BINARY_DIR}/gens) +file(MAKE_DIRECTORY ${_gRPC_PROTO_GENS_DIR}) + +# protobuf_generate_grpc_cpp +# -------------------------- +# +# Add custom commands to process ``.proto`` files to C++ using protoc and +# GRPC plugin:: +# +# protobuf_generate_grpc_cpp [...] +# +# ``ARGN`` +# ``.proto`` files +# +function(protobuf_generate_grpc_cpp) + if(NOT ARGN) + message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files") + return() + endif() + + set(_protobuf_include_path -I .) + foreach(FIL ${ARGN}) + get_filename_component(ABS_FIL ${FIL} ABSOLUTE) + get_filename_component(FIL_WE ${FIL} NAME_WE) + file(RELATIVE_PATH REL_FIL ${CMAKE_SOURCE_DIR} ${ABS_FIL}) + get_filename_component(REL_DIR ${REL_FIL} DIRECTORY) + set(RELFIL_WE "${REL_DIR}/${FIL_WE}") + + add_custom_command( + OUTPUT "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" + "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" + "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" + "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" + COMMAND ${_gRPC_PROTOBUF_PROTOC} + ARGS --grpc_out=${_gRPC_PROTO_GENS_DIR} + --cpp_out=${_gRPC_PROTO_GENS_DIR} + --plugin=protoc-gen-grpc=$ + ${_protobuf_include_path} + ${REL_FIL} + DEPENDS ${ABS_FIL} ${_gRPC_PROTOBUF_PROTOC} grpc_cpp_plugin + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + COMMENT "Running gRPC C++ protocol buffer compiler on ${FIL}" + VERBATIM) + + set_source_files_properties("${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" PROPERTIES GENERATED TRUE) + endforeach() +endfunction() + + add_library(gpr src/core/lib/profiling/basic_timers.c src/core/lib/profiling/stap_timers.c @@ -223,6 +278,7 @@ add_library(gpr src/core/lib/support/wrap_memcpy.c ) + target_include_directories(gpr PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -279,7 +335,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS gpr EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -288,7 +344,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc src/core/lib/surface/init.c src/core/lib/channel/channel_args.c @@ -509,6 +565,7 @@ add_library(grpc src/core/plugin_registry/grpc_plugin_registry.c ) + target_include_directories(grpc PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -563,7 +620,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -572,7 +629,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc_cronet src/core/lib/surface/init.c src/core/lib/channel/channel_args.c @@ -764,6 +821,7 @@ add_library(grpc_cronet src/core/plugin_registry/grpc_cronet_plugin_registry.c ) + target_include_directories(grpc_cronet PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -817,7 +875,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc_cronet EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -826,7 +884,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc_unsecure src/core/lib/surface/init.c src/core/lib/surface/init_unsecure.c @@ -1019,6 +1077,7 @@ add_library(grpc_unsecure src/core/plugin_registry/grpc_unsecure_plugin_registry.c ) + target_include_directories(grpc_unsecure PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -1070,7 +1129,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc_unsecure EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -1079,7 +1138,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc++ src/cpp/client/insecure_credentials.cc src/cpp/client/secure_credentials.cc @@ -1120,6 +1179,7 @@ add_library(grpc++ src/cpp/codegen/codegen_init.cc ) + target_include_directories(grpc++ PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -1233,7 +1293,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc++ EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -1242,7 +1302,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc++_cronet src/cpp/client/cronet_credentials.cc src/cpp/client/insecure_credentials.cc @@ -1456,6 +1516,7 @@ add_library(grpc++_cronet third_party/nanopb/pb_encode.c ) + target_include_directories(grpc++_cronet PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -1579,7 +1640,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc++_cronet EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -1588,7 +1649,54 @@ if (gRPC_INSTALL) ) endif() - + +add_library(grpc++_reflection + src/cpp/ext/proto_server_reflection.cc + src/cpp/ext/proto_server_reflection_plugin.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/reflection/v1alpha/reflection.proto +) + +target_include_directories(grpc++_reflection + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc++_reflection + grpc++ +) + +foreach(_hdr + include/grpc++/ext/proto_server_reflection_plugin.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + + +if (gRPC_INSTALL) + install(TARGETS grpc++_reflection EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + add_library(grpc++_unsecure src/cpp/client/insecure_credentials.cc src/cpp/common/insecure_create_auth_context.cc @@ -1624,6 +1732,7 @@ add_library(grpc++_unsecure src/cpp/codegen/codegen_init.cc ) + target_include_directories(grpc++_unsecure PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -1737,7 +1846,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc++_unsecure EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} @@ -1746,7 +1855,7 @@ if (gRPC_INSTALL) ) endif() - + add_library(grpc_plugin_support src/compiler/cpp_generator.cc src/compiler/csharp_generator.cc @@ -1757,6 +1866,7 @@ add_library(grpc_plugin_support src/compiler/ruby_generator.cc ) + target_include_directories(grpc_plugin_support PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include @@ -1780,7 +1890,7 @@ foreach(_hdr ) endforeach() - + if (gRPC_INSTALL) install(TARGETS grpc_plugin_support EXPORT gRPCTargets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} From 31f2dd43e22f41c89cfdd3d25002972247d01954 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 17 Jan 2017 07:25:06 -0800 Subject: [PATCH 201/261] clang-format --- src/core/ext/client_channel/subchannel.c | 2 +- src/core/ext/client_channel/subchannel.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index f9de9993b7b..8bd284507d2 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -802,7 +802,7 @@ void grpc_get_subchannel_address_arg(const grpc_channel_args *args, } } -grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr) { +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address *addr) { grpc_arg new_arg; new_arg.key = GRPC_ARG_SUBCHANNEL_ADDRESS; new_arg.type = GRPC_ARG_STRING; diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index c7a9577ce99..684675eb37d 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -180,6 +180,6 @@ void grpc_get_subchannel_address_arg(const grpc_channel_args *args, /// Returns a new channel arg encoding the subchannel address as a string. /// Caller is responsible for freeing the string. -grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address* addr); +grpc_arg grpc_create_subchannel_address_arg(const grpc_resolved_address *addr); #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_SUBCHANNEL_H */ From ce0105fac4986f63ea86d75cc4c8b0f46a71d372 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Tue, 17 Jan 2017 07:36:51 -0800 Subject: [PATCH 202/261] Ran generate_projects.sh --- tools/doxygen/Doxyfile.c++ | 1 + tools/doxygen/Doxyfile.c++.internal | 1 + tools/doxygen/Doxyfile.core | 1 + tools/doxygen/Doxyfile.core.internal | 1 + 4 files changed, 4 insertions(+) diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index fa9b7057c57..ffa167898cd 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -785,6 +785,7 @@ doc/naming.md \ doc/negative-http2-interop-test-descriptions.md \ doc/server-reflection.md \ doc/server_reflection_tutorial.md \ +doc/service_config.md \ doc/statuscodes.md \ doc/stress_test_framework.md \ doc/wait-for-ready.md \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index bca5652a463..0a12e458d64 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -785,6 +785,7 @@ doc/naming.md \ doc/negative-http2-interop-test-descriptions.md \ doc/server-reflection.md \ doc/server_reflection_tutorial.md \ +doc/service_config.md \ doc/statuscodes.md \ doc/stress_test_framework.md \ doc/wait-for-ready.md \ diff --git a/tools/doxygen/Doxyfile.core b/tools/doxygen/Doxyfile.core index ccbfe3a4e66..6e66ba0f39e 100644 --- a/tools/doxygen/Doxyfile.core +++ b/tools/doxygen/Doxyfile.core @@ -784,6 +784,7 @@ doc/naming.md \ doc/negative-http2-interop-test-descriptions.md \ doc/server-reflection.md \ doc/server_reflection_tutorial.md \ +doc/service_config.md \ doc/statuscodes.md \ doc/stress_test_framework.md \ doc/wait-for-ready.md \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index fc8fac32f0d..d8c2f197040 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -784,6 +784,7 @@ doc/naming.md \ doc/negative-http2-interop-test-descriptions.md \ doc/server-reflection.md \ doc/server_reflection_tutorial.md \ +doc/service_config.md \ doc/statuscodes.md \ doc/stress_test_framework.md \ doc/wait-for-ready.md \ From 40204d7791871fbe6b7cbfe2c887b6b0974cf5f7 Mon Sep 17 00:00:00 2001 From: Robbie Shade Date: Tue, 17 Jan 2017 10:47:18 -0500 Subject: [PATCH 203/261] Fix GRPC_TRACE doc formatting Add newlines so that the description of 'all' and the example appear on separate lines (and not as part of the final bullet point) --- doc/environment_variables.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/environment_variables.md b/doc/environment_variables.md index d02801bc9bd..832762a5f52 100644 --- a/doc/environment_variables.md +++ b/doc/environment_variables.md @@ -55,10 +55,12 @@ some configuration as environment variables that can be set. - secure_endpoint - traces bytes flowing through encrypted channels - transport_security - traces metadata about secure channel establishment - tcp - traces bytes in and out of a channel + 'all' can additionally be used to turn all traces on. Individual traces can be disabled by prefixing them with '-'. + Example: - export GRPC_TRACE=all,-pending_tags + export GRPC_TRACE=all,-pending_tags * GRPC_VERBOSITY Default gRPC logging verbosity - one of: From 020d1884f5092ceada11b818cbb73eae22c9cd58 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 17 Jan 2017 08:21:00 -0800 Subject: [PATCH 204/261] Port to new C Core API --- test/core/memory_usage/client.c | 51 ++++++++++++++++----------------- test/core/memory_usage/server.c | 28 ++++++++++-------- 2 files changed, 40 insertions(+), 39 deletions(-) diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c index 9fc122b4c36..9c1947d0cd8 100644 --- a/test/core/memory_usage/client.c +++ b/test/core/memory_usage/client.c @@ -58,8 +58,7 @@ typedef struct { grpc_call *call; grpc_metadata_array initial_metadata_recv; grpc_status_code status; - char *details; - size_t details_capacity; + grpc_slice details; grpc_metadata_array trailing_metadata_recv; } fling_call; @@ -84,9 +83,11 @@ static void init_ping_pong_request(int call_idx) { op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv; op++; + grpc_slice hostname = grpc_slice_from_static_string("localhost"); calls[call_idx].call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/Reflector/reflectUnary", - "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + grpc_slice_from_static_string("/Reflector/reflectUnary"), &hostname, + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, metadata_ops, @@ -106,8 +107,6 @@ static void finish_ping_pong_request(int call_idx) { &calls[call_idx].trailing_metadata_recv; op->data.recv_status_on_client.status = &calls[call_idx].status; op->data.recv_status_on_client.status_details = &calls[call_idx].details; - op->data.recv_status_on_client.status_details_capacity = - &calls[call_idx].details_capacity; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, @@ -117,13 +116,13 @@ static void finish_ping_pong_request(int call_idx) { grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv); grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv); - gpr_free(calls[call_idx].details); + grpc_slice_unref(calls[call_idx].details); grpc_call_destroy(calls[call_idx].call); calls[call_idx].call = NULL; } -static struct grpc_memory_counters send_snapshot_request( - int call_idx, const char *call_type) { +static struct grpc_memory_counters send_snapshot_request(int call_idx, + grpc_slice call_type) { grpc_metadata_array_init(&calls[call_idx].initial_metadata_recv); grpc_metadata_array_init(&calls[call_idx].trailing_metadata_recv); @@ -147,12 +146,11 @@ static struct grpc_memory_counters send_snapshot_request( &calls[call_idx].trailing_metadata_recv; op->data.recv_status_on_client.status = &calls[call_idx].status; op->data.recv_status_on_client.status_details = &calls[call_idx].details; - op->data.recv_status_on_client.status_details_capacity = - &calls[call_idx].details_capacity; op++; + grpc_slice hostname = grpc_slice_from_static_string("localhost"); calls[call_idx].call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, "localhost", + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, &hostname, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch( calls[call_idx].call, snapshot_ops, @@ -182,9 +180,8 @@ static struct grpc_memory_counters send_snapshot_request( grpc_slice_unref(response); grpc_byte_buffer_reader_destroy(&reader); grpc_byte_buffer_destroy(response_payload_recv); - gpr_free(calls[call_idx].details); - calls[call_idx].details = NULL; - calls[call_idx].details_capacity = 0; + grpc_slice_unref(calls[call_idx].details); + calls[call_idx].details = grpc_empty_slice(); grpc_call_destroy(calls[call_idx].call); calls[call_idx].call = NULL; @@ -217,9 +214,8 @@ int main(int argc, char **argv) { gpr_cmdline_parse(cl, argc, argv); gpr_cmdline_destroy(cl); - for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call)); k++) { - calls[k].details = NULL; - calls[k].details_capacity = 0; + for (size_t k = 0; k < GPR_ARRAY_SIZE(calls); k++) { + calls[k].details = grpc_empty_slice(); } cq = grpc_completion_queue_create(NULL); @@ -230,10 +226,10 @@ int main(int argc, char **argv) { int call_idx = 0; - struct grpc_memory_counters before_server_create = - send_snapshot_request(0, "Reflector/GetBeforeSvrCreation"); - struct grpc_memory_counters after_server_create = - send_snapshot_request(0, "Reflector/GetAfterSvrCreation"); + struct grpc_memory_counters before_server_create = send_snapshot_request( + 0, grpc_slice_from_static_string("Reflector/GetBeforeSvrCreation")); + struct grpc_memory_counters after_server_create = send_snapshot_request( + 0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation")); // warmup period for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) { @@ -241,7 +237,8 @@ int main(int argc, char **argv) { } struct grpc_memory_counters server_benchmark_calls_start = - send_snapshot_request(0, "Reflector/SimpleSnapshot"); + send_snapshot_request( + 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot")); struct grpc_memory_counters client_benchmark_calls_start = grpc_memory_counters_snapshot(); @@ -254,8 +251,8 @@ int main(int argc, char **argv) { struct grpc_memory_counters client_calls_inflight = grpc_memory_counters_snapshot(); - struct grpc_memory_counters server_calls_inflight = - send_snapshot_request(0, "Reflector/DestroyCalls"); + struct grpc_memory_counters server_calls_inflight = send_snapshot_request( + 0, grpc_slice_from_static_string("Reflector/DestroyCalls")); do { event = grpc_completion_queue_next( @@ -270,8 +267,8 @@ int main(int argc, char **argv) { finish_ping_pong_request(call_idx + 1); } - struct grpc_memory_counters server_calls_end = - send_snapshot_request(0, "Reflector/SimpleSnapshot"); + struct grpc_memory_counters server_calls_end = send_snapshot_request( + 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot")); struct grpc_memory_counters client_channel_end = grpc_memory_counters_snapshot(); diff --git a/test/core/memory_usage/server.c b/test/core/memory_usage/server.c index c0710930b07..e8774bd9769 100644 --- a/test/core/memory_usage/server.c +++ b/test/core/memory_usage/server.c @@ -110,7 +110,8 @@ static void send_status(void *tag) { status_op.op = GRPC_OP_SEND_STATUS_FROM_SERVER; status_op.data.send_status_from_server.status = GRPC_STATUS_OK; status_op.data.send_status_from_server.trailing_metadata_count = 0; - status_op.data.send_status_from_server.status_details = ""; + grpc_slice details = grpc_slice_from_static_string(""); + status_op.data.send_status_from_server.status_details = &details; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call *)tag).call, &status_op, 1, tag, NULL)); @@ -140,7 +141,8 @@ static void send_snapshot(void *tag, struct grpc_memory_counters *snapshot) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.status = GRPC_STATUS_OK; op->data.send_status_from_server.trailing_metadata_count = 0; - op->data.send_status_from_server.status_details = ""; + grpc_slice details = grpc_slice_from_static_string(""); + op->data.send_status_from_server.status_details = &details; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; @@ -245,25 +247,27 @@ int main(int argc, char **argv) { switch (s->state) { case FLING_SERVER_NEW_REQUEST: request_call_unary(++next_call_idx); - if (0 == - strcmp(s->call_details.method, "/Reflector/reflectUnary")) { + if (0 == grpc_slice_str_cmp(s->call_details.method, + "/Reflector/reflectUnary")) { s->state = FLING_SERVER_SEND_INIT_METADATA; send_initial_metadata_unary(s); - } else if (0 == strcmp(s->call_details.method, - "Reflector/GetBeforeSvrCreation")) { + } else if (0 == + grpc_slice_str_cmp(s->call_details.method, + "Reflector/GetBeforeSvrCreation")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; send_snapshot(s, &before_server_create); - } else if (0 == strcmp(s->call_details.method, - "Reflector/GetAfterSvrCreation")) { + } else if (0 == + grpc_slice_str_cmp(s->call_details.method, + "Reflector/GetAfterSvrCreation")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; send_snapshot(s, &after_server_create); - } else if (0 == strcmp(s->call_details.method, - "Reflector/SimpleSnapshot")) { + } else if (0 == grpc_slice_str_cmp(s->call_details.method, + "Reflector/SimpleSnapshot")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; current_snapshot = grpc_memory_counters_snapshot(); send_snapshot(s, ¤t_snapshot); - } else if (0 == strcmp(s->call_details.method, - "Reflector/DestroyCalls")) { + } else if (0 == grpc_slice_str_cmp(s->call_details.method, + "Reflector/DestroyCalls")) { s->state = FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL; current_snapshot = grpc_memory_counters_snapshot(); send_snapshot(s, ¤t_snapshot); From 1d83a701b69e0b29b5ae3b471f724650f3eea241 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 17 Jan 2017 09:35:42 -0800 Subject: [PATCH 205/261] Fix memory leak --- src/cpp/client/secure_credentials.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 7fc315bb381..25f6bab7f25 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -214,6 +214,10 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( cb(user_data, md.empty() ? nullptr : &md[0], md.size(), static_cast(status.error_code()), status.error_message().c_str()); + for (auto it = md.begin(); it != md.end(); ++it) { + grpc_slice_unref(it->key); + grpc_slice_unref(it->value); + } } MetadataCredentialsPluginWrapper::MetadataCredentialsPluginWrapper( From 886fb1245c97878725e0f82ffde0779e3ec8d394 Mon Sep 17 00:00:00 2001 From: Robbie Shade Date: Tue, 17 Jan 2017 13:22:11 -0500 Subject: [PATCH 206/261] Force client to wait for server to start --- test/core/memory_usage/client.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c index 9fc122b4c36..f4432bf5727 100644 --- a/test/core/memory_usage/client.c +++ b/test/core/memory_usage/client.c @@ -79,6 +79,7 @@ static void init_ping_pong_request(int call_idx) { op = metadata_ops; op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; + op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY; op++; op->op = GRPC_OP_RECV_INITIAL_METADATA; op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv; @@ -133,6 +134,7 @@ static struct grpc_memory_counters send_snapshot_request( op->op = GRPC_OP_SEND_INITIAL_METADATA; op->data.send_initial_metadata.count = 0; + op->flags = GRPC_INITIAL_METADATA_WAIT_FOR_READY; op++; op->op = GRPC_OP_SEND_CLOSE_FROM_CLIENT; op++; From 06dea573daa2175b244a430bb89b49bb5c8e8c5b Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 11 May 2016 12:01:40 -0700 Subject: [PATCH 207/261] Enable running Python formatting --- .gitignore | 1 + setup.cfg | 4 ++ tools/distrib/pyformat_code.sh | 60 ++++++++++++++++++++++++ tools/run_tests/sanity/sanity_tests.yaml | 1 + 4 files changed, 66 insertions(+) create mode 100755 tools/distrib/pyformat_code.sh diff --git a/.gitignore b/.gitignore index 31124451768..618c9ba5ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ objs # Python items cython_debug/ python_build/ +python_format_venv/ .coverage* .eggs htmlcov/ diff --git a/setup.cfg b/setup.cfg index dd9161ca8b9..218792e674c 100644 --- a/setup.cfg +++ b/setup.cfg @@ -11,3 +11,7 @@ inplace=1 [build_package_protos] exclude=.*protoc_plugin/protoc_plugin_test\.proto$ + +# Style settings +[yapf] +based_on_style = google diff --git a/tools/distrib/pyformat_code.sh b/tools/distrib/pyformat_code.sh new file mode 100755 index 00000000000..e3ebf1c4908 --- /dev/null +++ b/tools/distrib/pyformat_code.sh @@ -0,0 +1,60 @@ +#!/bin/bash +# 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. + +set -ex + +# change to root directory +cd $(dirname $0)/../.. + +DIRS=src/python +EXCLUSIONS='src/python/grpcio/grpc_*.py src/python/grpcio_health_checking/grpc_*.py src/python/grpcio_reflection/grpc_*.py src/python/grpcio_tests/grpc_*.py' + +VIRTUALENV=python_format_venv + +virtualenv $VIRTUALENV +PYTHON=`realpath $VIRTUALENV/bin/python` +$PYTHON -m pip install --upgrade futures yapf + +exclusion_args="" +for exclusion in $EXCLUSIONS; do + exclusion_args="$exclusion_args --exclude $exclusion" +done + +script_result=0 +for dir in $DIRS; do + tempdir=`mktemp -d` + cp -RT $dir $tempdir + $PYTHON -m yapf -i -r -p $exclusion_args $dir + if ! diff -rq $dir $tempdir; then + script_result=1 + fi + rm -rf $tempdir +done +exit $script_result diff --git a/tools/run_tests/sanity/sanity_tests.yaml b/tools/run_tests/sanity/sanity_tests.yaml index 37819166e33..f29b700572b 100644 --- a/tools/run_tests/sanity/sanity_tests.yaml +++ b/tools/run_tests/sanity/sanity_tests.yaml @@ -12,5 +12,6 @@ - script: tools/distrib/check_trailing_newlines.sh - script: tools/distrib/check_nanopb_output.sh - script: tools/distrib/check_include_guards.py +- script: tools/distrib/pyformat_code.sh - script: tools/distrib/python/check_grpcio_tools.py From cc793703bfba6f661f523b6fec82ff8a913e1759 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Fri, 13 Jan 2017 19:20:10 -0800 Subject: [PATCH 208/261] Run Python formatting --- src/python/grpcio/_spawn_patch.py | 46 +- src/python/grpcio/commands.py | 352 ++-- src/python/grpcio/grpc/__init__.py | 744 ++++---- src/python/grpcio/grpc/_auth.py | 83 +- src/python/grpcio/grpc/_channel.py | 1529 +++++++++-------- src/python/grpcio/grpc/_common.py | 123 +- .../grpcio/grpc/_credential_composition.py | 18 +- src/python/grpcio/grpc/_plugin_wrapping.py | 123 +- src/python/grpcio/grpc/_server.py | 1092 ++++++------ src/python/grpcio/grpc/_utilities.py | 235 +-- .../grpcio/grpc/beta/_client_adaptations.py | 1028 ++++++----- .../grpcio/grpc/beta/_connectivity_channel.py | 213 +-- .../grpcio/grpc/beta/_server_adaptations.py | 544 +++--- .../grpcio/grpc/beta/implementations.py | 173 +- src/python/grpcio/grpc/beta/interfaces.py | 78 +- src/python/grpcio/grpc/beta/utilities.py | 202 ++- src/python/grpcio/grpc/framework/__init__.py | 2 - .../grpcio/grpc/framework/common/__init__.py | 2 - .../grpc/framework/common/cardinality.py | 11 +- .../grpcio/grpc/framework/common/style.py | 7 +- .../grpc/framework/foundation/__init__.py | 2 - .../grpc/framework/foundation/abandonment.py | 3 +- .../framework/foundation/callable_util.py | 47 +- .../grpc/framework/foundation/future.py | 129 +- .../grpc/framework/foundation/logging_pool.py | 55 +- .../grpc/framework/foundation/stream.py | 28 +- .../grpc/framework/foundation/stream_util.py | 227 ++- .../grpc/framework/interfaces/__init__.py | 2 - .../framework/interfaces/base/__init__.py | 2 - .../grpc/framework/interfaces/base/base.py | 184 +- .../framework/interfaces/base/utilities.py | 42 +- .../framework/interfaces/face/__init__.py | 2 - .../grpc/framework/interfaces/face/face.py | 610 ++++--- .../framework/interfaces/face/utilities.py | 87 +- src/python/grpcio/support.py | 103 +- .../grpc_health/__init__.py | 2 - .../grpc_health/v1/__init__.py | 2 - .../grpc_health/v1/health.py | 33 +- .../grpcio_health_checking/health_commands.py | 53 +- src/python/grpcio_health_checking/setup.py | 14 +- .../grpc_reflection/__init__.py | 1 - .../grpc_reflection/v1alpha/__init__.py | 1 - .../grpc_reflection/v1alpha/reflection.py | 168 +- .../grpcio_reflection/reflection_commands.py | 57 +- src/python/grpcio_reflection/setup.py | 14 +- src/python/grpcio_tests/commands.py | 266 ++- src/python/grpcio_tests/setup.py | 42 +- src/python/grpcio_tests/tests/_loader.py | 89 +- src/python/grpcio_tests/tests/_result.py | 618 +++---- src/python/grpcio_tests/tests/_runner.py | 273 +-- .../health_check/_health_servicer_test.py | 87 +- .../tests/http2/_negative_http2_client.py | 175 +- .../grpcio_tests/tests/interop/__init__.py | 2 - .../tests/interop/_insecure_intraop_test.py | 24 +- .../tests/interop/_intraop_test_case.py | 38 +- .../tests/interop/_secure_intraop_test.py | 35 +- .../grpcio_tests/tests/interop/client.py | 163 +- .../grpcio_tests/tests/interop/methods.py | 759 ++++---- .../grpcio_tests/tests/interop/resources.py | 21 +- .../grpcio_tests/tests/interop/server.py | 57 +- .../tests/protoc_plugin/__init__.py | 2 - .../protoc_plugin/_python_plugin_test.py | 754 ++++---- .../protoc_plugin/_split_definitions_test.py | 446 ++--- .../protoc_plugin/beta_python_plugin_test.py | 716 ++++---- .../tests/protoc_plugin/protos/__init__.py | 2 - .../protos/invocation_testing/__init__.py | 2 - .../split_messages/__init__.py | 2 - .../split_services/__init__.py | 2 - .../protoc_plugin/protos/payload/__init__.py | 2 - .../protoc_plugin/protos/requests/__init__.py | 2 - .../protos/requests/r/__init__.py | 2 - .../protos/responses/__init__.py | 2 - .../protoc_plugin/protos/service/__init__.py | 2 - .../tests/qps/benchmark_client.py | 280 +-- .../tests/qps/benchmark_server.py | 32 +- .../grpcio_tests/tests/qps/client_runner.py | 107 +- .../grpcio_tests/tests/qps/histogram.py | 82 +- .../grpcio_tests/tests/qps/qps_worker.py | 34 +- .../grpcio_tests/tests/qps/worker_server.py | 297 ++-- .../reflection/_reflection_servicer_test.py | 234 ++- .../grpcio_tests/tests/stress/client.py | 217 +-- .../tests/stress/metrics_server.py | 41 +- .../grpcio_tests/tests/stress/test_runner.py | 59 +- .../grpcio_tests/tests/unit/__init__.py | 2 - .../grpcio_tests/tests/unit/_api_test.py | 117 +- .../grpcio_tests/tests/unit/_auth_test.py | 69 +- .../tests/unit/_channel_args_test.py | 20 +- .../tests/unit/_channel_connectivity_test.py | 209 ++- .../tests/unit/_channel_ready_future_test.py | 108 +- .../tests/unit/_compression_test.py | 147 +- .../tests/unit/_credentials_test.py | 56 +- .../unit/_cython/_cancel_many_calls_test.py | 302 ++-- .../tests/unit/_cython/_channel_test.py | 55 +- .../_read_some_but_not_all_responses_test.py | 402 ++--- .../tests/unit/_cython/cygrpc_test.py | 710 ++++---- .../tests/unit/_cython/test_utilities.py | 45 +- .../tests/unit/_empty_message_test.py | 125 +- .../tests/unit/_exit_scenarios.py | 269 ++- .../grpcio_tests/tests/unit/_exit_test.py | 243 +-- .../tests/unit/_invalid_metadata_test.py | 223 +-- .../tests/unit/_invocation_defects_test.py | 316 ++-- .../tests/unit/_junkdrawer/__init__.py | 2 - .../tests/unit/_junkdrawer/stock_pb2.py | 209 ++- .../tests/unit/_metadata_code_details_test.py | 901 +++++----- .../grpcio_tests/tests/unit/_metadata_test.py | 254 +-- .../grpcio_tests/tests/unit/_rpc_test.py | 1414 +++++++-------- .../tests/unit/_sanity/__init__.py | 2 - .../tests/unit/_sanity/_sanity_test.py | 32 +- .../tests/unit/_thread_cleanup_test.py | 143 +- .../grpcio_tests/tests/unit/_thread_pool.py | 25 +- .../grpcio_tests/tests/unit/beta/__init__.py | 2 - .../tests/unit/beta/_beta_features_test.py | 528 +++--- .../unit/beta/_connectivity_channel_test.py | 15 +- .../tests/unit/beta/_face_interface_test.py | 160 +- .../tests/unit/beta/_implementations_test.py | 44 +- .../tests/unit/beta/_not_found_test.py | 58 +- .../tests/unit/beta/_utilities_test.py | 113 +- .../tests/unit/beta/test_utilities.py | 17 +- .../tests/unit/framework/__init__.py | 2 - .../tests/unit/framework/common/__init__.py | 2 - .../unit/framework/common/test_constants.py | 1 - .../unit/framework/common/test_control.py | 97 +- .../unit/framework/common/test_coverage.py | 117 +- .../unit/framework/foundation/__init__.py | 2 - .../foundation/_logging_pool_test.py | 64 +- .../framework/foundation/stream_testing.py | 55 +- .../unit/framework/interfaces/__init__.py | 2 - .../interfaces/face/_3069_test_constant.py | 1 - .../framework/interfaces/face/__init__.py | 2 - .../_blocking_invocation_inline_service.py | 465 ++--- .../unit/framework/interfaces/face/_digest.py | 550 +++--- ...e_invocation_asynchronous_event_service.py | 876 +++++----- .../framework/interfaces/face/_invocation.py | 187 +- .../framework/interfaces/face/_service.py | 159 +- .../interfaces/face/_stock_service.py | 519 +++--- .../framework/interfaces/face/test_cases.py | 27 +- .../interfaces/face/test_interfaces.py | 144 +- .../grpcio_tests/tests/unit/resources.py | 11 +- .../grpcio_tests/tests/unit/test_common.py | 69 +- 139 files changed, 12827 insertions(+), 12303 deletions(-) diff --git a/src/python/grpcio/_spawn_patch.py b/src/python/grpcio/_spawn_patch.py index 24306f0dd95..75d0a8b3527 100644 --- a/src/python/grpcio/_spawn_patch.py +++ b/src/python/grpcio/_spawn_patch.py @@ -26,7 +26,6 @@ # 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. - """Patches the spawn() command for windows compilers. Windows has an 8191 character command line limit, but some compilers @@ -45,29 +44,32 @@ MAX_COMMAND_LENGTH = 8191 _classic_spawn = ccompiler.CCompiler.spawn + def _commandfile_spawn(self, command): - command_length = sum([len(arg) for arg in command]) - if os.name == 'nt' and command_length > MAX_COMMAND_LENGTH: - # Even if this command doesn't support the @command_file, it will - # fail as is so we try blindly - print('Command line length exceeded, using command file') - print(' '.join(command)) - temporary_directory = tempfile.mkdtemp() - command_filename = os.path.abspath( - os.path.join(temporary_directory, 'command')) - with open(command_filename, 'w') as command_file: - escaped_args = ['"' + arg.replace('\\', '\\\\') + '"' for arg in command[1:]] - command_file.write(' '.join(escaped_args)) - modified_command = command[:1] + ['@{}'.format(command_filename)] - try: - _classic_spawn(self, modified_command) - finally: - shutil.rmtree(temporary_directory) - else: - _classic_spawn(self, command) + command_length = sum([len(arg) for arg in command]) + if os.name == 'nt' and command_length > MAX_COMMAND_LENGTH: + # Even if this command doesn't support the @command_file, it will + # fail as is so we try blindly + print('Command line length exceeded, using command file') + print(' '.join(command)) + temporary_directory = tempfile.mkdtemp() + command_filename = os.path.abspath( + os.path.join(temporary_directory, 'command')) + with open(command_filename, 'w') as command_file: + escaped_args = [ + '"' + arg.replace('\\', '\\\\') + '"' for arg in command[1:] + ] + command_file.write(' '.join(escaped_args)) + modified_command = command[:1] + ['@{}'.format(command_filename)] + try: + _classic_spawn(self, modified_command) + finally: + shutil.rmtree(temporary_directory) + else: + _classic_spawn(self, command) def monkeypatch_spawn(): - """Monkeypatching is dumb, but it's either that or we become maintainers of + """Monkeypatching is dumb, but it's either that or we become maintainers of something much, much bigger.""" - ccompiler.CCompiler.spawn = _commandfile_spawn + ccompiler.CCompiler.spawn = _commandfile_spawn diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index 701c6af0179..e09f9225912 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -26,7 +26,6 @@ # 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. - """Provides distutils command classes for the GRPC Python setup process.""" import distutils @@ -87,138 +86,144 @@ Glossary class CommandError(Exception): - """Simple exception class for GRPC custom commands.""" + """Simple exception class for GRPC custom commands.""" # TODO(atash): Remove this once PyPI has better Linux bdist support. See # https://bitbucket.org/pypa/pypi/issues/120/binary-wheels-for-linux-are-not-supported def _get_grpc_custom_bdist(decorated_basename, target_bdist_basename): - """Returns a string path to a bdist file for Linux to install. + """Returns a string path to a bdist file for Linux to install. If we can retrieve a pre-compiled bdist from online, uses it. Else, emits a warning and builds from source. """ - # TODO(atash): somehow the name that's returned from `wheel` is different - # between different versions of 'wheel' (but from a compatibility standpoint, - # the names are compatible); we should have some way of determining name - # compatibility in the same way `wheel` does to avoid having to rename all of - # the custom wheels that we build/upload to GCS. - - # Break import style to ensure that setup.py has had a chance to install the - # relevant package. - from six.moves.urllib import request - decorated_path = decorated_basename + GRPC_CUSTOM_BDIST_EXT - try: - url = BINARIES_REPOSITORY + '/{target}'.format(target=decorated_path) - bdist_data = request.urlopen(url).read() - except IOError as error: - raise CommandError( - '{}\n\nCould not find the bdist {}: {}' - .format(traceback.format_exc(), decorated_path, error.message)) - # Our chosen local bdist path. - bdist_path = target_bdist_basename + GRPC_CUSTOM_BDIST_EXT - try: - with open(bdist_path, 'w') as bdist_file: - bdist_file.write(bdist_data) - except IOError as error: - raise CommandError( - '{}\n\nCould not write grpcio bdist: {}' - .format(traceback.format_exc(), error.message)) - return bdist_path + # TODO(atash): somehow the name that's returned from `wheel` is different + # between different versions of 'wheel' (but from a compatibility standpoint, + # the names are compatible); we should have some way of determining name + # compatibility in the same way `wheel` does to avoid having to rename all of + # the custom wheels that we build/upload to GCS. + + # Break import style to ensure that setup.py has had a chance to install the + # relevant package. + from six.moves.urllib import request + decorated_path = decorated_basename + GRPC_CUSTOM_BDIST_EXT + try: + url = BINARIES_REPOSITORY + '/{target}'.format(target=decorated_path) + bdist_data = request.urlopen(url).read() + except IOError as error: + raise CommandError('{}\n\nCould not find the bdist {}: {}'.format( + traceback.format_exc(), decorated_path, error.message)) + # Our chosen local bdist path. + bdist_path = target_bdist_basename + GRPC_CUSTOM_BDIST_EXT + try: + with open(bdist_path, 'w') as bdist_file: + bdist_file.write(bdist_data) + except IOError as error: + raise CommandError('{}\n\nCould not write grpcio bdist: {}' + .format(traceback.format_exc(), error.message)) + return bdist_path class SphinxDocumentation(setuptools.Command): - """Command to generate documentation via sphinx.""" - - description = 'generate sphinx documentation' - user_options = [] - - def initialize_options(self): - pass - - def finalize_options(self): - pass - - def run(self): - # We import here to ensure that setup.py has had a chance to install the - # relevant package eggs first. - import sphinx - import sphinx.apidoc - metadata = self.distribution.metadata - src_dir = os.path.join(PYTHON_STEM, 'grpc') - sys.path.append(src_dir) - sphinx.apidoc.main([ - '', '--force', '--full', '-H', metadata.name, '-A', metadata.author, - '-V', metadata.version, '-R', metadata.version, - '-o', os.path.join('doc', 'src'), src_dir]) - conf_filepath = os.path.join('doc', 'src', 'conf.py') - with open(conf_filepath, 'a') as conf_file: - conf_file.write(CONF_PY_ADDENDUM) - glossary_filepath = os.path.join('doc', 'src', 'grpc.rst') - with open(glossary_filepath, 'a') as glossary_filepath: - glossary_filepath.write(API_GLOSSARY) - sphinx.main(['', os.path.join('doc', 'src'), os.path.join('doc', 'build')]) + """Command to generate documentation via sphinx.""" + + description = 'generate sphinx documentation' + user_options = [] + + def initialize_options(self): + pass + + def finalize_options(self): + pass + + def run(self): + # We import here to ensure that setup.py has had a chance to install the + # relevant package eggs first. + import sphinx + import sphinx.apidoc + metadata = self.distribution.metadata + src_dir = os.path.join(PYTHON_STEM, 'grpc') + sys.path.append(src_dir) + sphinx.apidoc.main([ + '', '--force', '--full', '-H', metadata.name, '-A', metadata.author, + '-V', metadata.version, '-R', metadata.version, '-o', + os.path.join('doc', 'src'), src_dir + ]) + conf_filepath = os.path.join('doc', 'src', 'conf.py') + with open(conf_filepath, 'a') as conf_file: + conf_file.write(CONF_PY_ADDENDUM) + glossary_filepath = os.path.join('doc', 'src', 'grpc.rst') + with open(glossary_filepath, 'a') as glossary_filepath: + glossary_filepath.write(API_GLOSSARY) + sphinx.main( + ['', os.path.join('doc', 'src'), os.path.join('doc', 'build')]) class BuildProjectMetadata(setuptools.Command): - """Command to generate project metadata in a module.""" + """Command to generate project metadata in a module.""" - description = 'build grpcio project metadata files' - user_options = [] + description = 'build grpcio project metadata files' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - with open(os.path.join(PYTHON_STEM, 'grpc/_grpcio_metadata.py'), 'w') as module_file: - module_file.write('__version__ = """{}"""'.format( - self.distribution.get_version())) + def run(self): + with open(os.path.join(PYTHON_STEM, 'grpc/_grpcio_metadata.py'), + 'w') as module_file: + module_file.write('__version__ = """{}"""'.format( + self.distribution.get_version())) class BuildPy(build_py.build_py): - """Custom project build command.""" + """Custom project build command.""" - def run(self): - self.run_command('build_project_metadata') - build_py.build_py.run(self) + def run(self): + self.run_command('build_project_metadata') + build_py.build_py.run(self) def _poison_extensions(extensions, message): - """Includes a file that will always fail to compile in all extensions.""" - poison_filename = os.path.join(PYTHON_STEM, 'poison.c') - with open(poison_filename, 'w') as poison: - poison.write('#error {}'.format(message)) - for extension in extensions: - extension.sources = [poison_filename] + """Includes a file that will always fail to compile in all extensions.""" + poison_filename = os.path.join(PYTHON_STEM, 'poison.c') + with open(poison_filename, 'w') as poison: + poison.write('#error {}'.format(message)) + for extension in extensions: + extension.sources = [poison_filename] + def check_and_update_cythonization(extensions): - """Replace .pyx files with their generated counterparts and return whether or + """Replace .pyx files with their generated counterparts and return whether or not cythonization still needs to occur.""" - for extension in extensions: - generated_pyx_sources = [] - other_sources = [] - for source in extension.sources: - base, file_ext = os.path.splitext(source) - if file_ext == '.pyx': - generated_pyx_source = next( - (base + gen_ext for gen_ext in ('.c', '.cpp',) - if os.path.isfile(base + gen_ext)), None) - if generated_pyx_source: - generated_pyx_sources.append(generated_pyx_source) - else: - sys.stderr.write('Cython-generated files are missing...\n') - return False - else: - other_sources.append(source) - extension.sources = generated_pyx_sources + other_sources - sys.stderr.write('Found cython-generated files...\n') - return True + for extension in extensions: + generated_pyx_sources = [] + other_sources = [] + for source in extension.sources: + base, file_ext = os.path.splitext(source) + if file_ext == '.pyx': + generated_pyx_source = next((base + gen_ext + for gen_ext in ( + '.c', + '.cpp',) + if os.path.isfile(base + gen_ext)), + None) + if generated_pyx_source: + generated_pyx_sources.append(generated_pyx_source) + else: + sys.stderr.write('Cython-generated files are missing...\n') + return False + else: + other_sources.append(source) + extension.sources = generated_pyx_sources + other_sources + sys.stderr.write('Found cython-generated files...\n') + return True + def try_cythonize(extensions, linetracing=False, mandatory=True): - """Attempt to cythonize the extensions. + """Attempt to cythonize the extensions. Args: extensions: A list of `distutils.extension.Extension`. @@ -226,78 +231,83 @@ def try_cythonize(extensions, linetracing=False, mandatory=True): mandatory: Whether or not having Cython-generated files is mandatory. If it is, extensions will be poisoned when they can't be fully generated. """ - try: - # Break import style to ensure we have access to Cython post-setup_requires - import Cython.Build - except ImportError: - if mandatory: - sys.stderr.write( - "This package needs to generate C files with Cython but it cannot. " - "Poisoning extension sources to disallow extension commands...") - _poison_extensions( - extensions, - "Extensions have been poisoned due to missing Cython-generated code.") - return extensions - cython_compiler_directives = {} - if linetracing: - additional_define_macros = [('CYTHON_TRACE_NOGIL', '1')] - cython_compiler_directives['linetrace'] = True - return Cython.Build.cythonize( - extensions, - include_path=[ - include_dir for extension in extensions for include_dir in extension.include_dirs - ] + [CYTHON_STEM], - compiler_directives=cython_compiler_directives - ) + try: + # Break import style to ensure we have access to Cython post-setup_requires + import Cython.Build + except ImportError: + if mandatory: + sys.stderr.write( + "This package needs to generate C files with Cython but it cannot. " + "Poisoning extension sources to disallow extension commands...") + _poison_extensions( + extensions, + "Extensions have been poisoned due to missing Cython-generated code." + ) + return extensions + cython_compiler_directives = {} + if linetracing: + additional_define_macros = [('CYTHON_TRACE_NOGIL', '1')] + cython_compiler_directives['linetrace'] = True + return Cython.Build.cythonize( + extensions, + include_path=[ + include_dir + for extension in extensions + for include_dir in extension.include_dirs + ] + [CYTHON_STEM], + compiler_directives=cython_compiler_directives) class BuildExt(build_ext.build_ext): - """Custom build_ext command to enable compiler-specific flags.""" - - C_OPTIONS = { - 'unix': ('-pthread', '-std=gnu99'), - 'msvc': (), - } - LINK_OPTIONS = {} - - def build_extensions(self): - compiler = self.compiler.compiler_type - if compiler in BuildExt.C_OPTIONS: - for extension in self.extensions: - extension.extra_compile_args += list(BuildExt.C_OPTIONS[compiler]) - if compiler in BuildExt.LINK_OPTIONS: - for extension in self.extensions: - extension.extra_link_args += list(BuildExt.LINK_OPTIONS[compiler]) - if not check_and_update_cythonization(self.extensions): - self.extensions = try_cythonize(self.extensions) - try: - build_ext.build_ext.build_extensions(self) - except Exception as error: - formatted_exception = traceback.format_exc() - support.diagnose_build_ext_error(self, error, formatted_exception) - raise CommandError( - "Failed `build_ext` step:\n{}".format(formatted_exception)) + """Custom build_ext command to enable compiler-specific flags.""" + + C_OPTIONS = { + 'unix': ('-pthread', '-std=gnu99'), + 'msvc': (), + } + LINK_OPTIONS = {} + + def build_extensions(self): + compiler = self.compiler.compiler_type + if compiler in BuildExt.C_OPTIONS: + for extension in self.extensions: + extension.extra_compile_args += list(BuildExt.C_OPTIONS[ + compiler]) + if compiler in BuildExt.LINK_OPTIONS: + for extension in self.extensions: + extension.extra_link_args += list(BuildExt.LINK_OPTIONS[ + compiler]) + if not check_and_update_cythonization(self.extensions): + self.extensions = try_cythonize(self.extensions) + try: + build_ext.build_ext.build_extensions(self) + except Exception as error: + formatted_exception = traceback.format_exc() + support.diagnose_build_ext_error(self, error, formatted_exception) + raise CommandError("Failed `build_ext` step:\n{}".format( + formatted_exception)) class Gather(setuptools.Command): - """Command to gather project dependencies.""" - - description = 'gather dependencies for grpcio' - user_options = [ - ('test', 't', 'flag indicating to gather test dependencies'), - ('install', 'i', 'flag indicating to gather install dependencies') - ] - - def initialize_options(self): - self.test = False - self.install = False - - def finalize_options(self): - # distutils requires this override. - pass - - def run(self): - if self.install and self.distribution.install_requires: - self.distribution.fetch_build_eggs(self.distribution.install_requires) - if self.test and self.distribution.tests_require: - self.distribution.fetch_build_eggs(self.distribution.tests_require) + """Command to gather project dependencies.""" + + description = 'gather dependencies for grpcio' + user_options = [ + ('test', 't', 'flag indicating to gather test dependencies'), + ('install', 'i', 'flag indicating to gather install dependencies') + ] + + def initialize_options(self): + self.test = False + self.install = False + + def finalize_options(self): + # distutils requires this override. + pass + + def run(self): + if self.install and self.distribution.install_requires: + self.distribution.fetch_build_eggs( + self.distribution.install_requires) + if self.test and self.distribution.tests_require: + self.distribution.fetch_build_eggs(self.distribution.tests_require) diff --git a/src/python/grpcio/grpc/__init__.py b/src/python/grpcio/grpc/__init__.py index e3c10156d0f..abe14e70498 100644 --- a/src/python/grpcio/grpc/__init__.py +++ b/src/python/grpcio/grpc/__init__.py @@ -26,7 +26,6 @@ # 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. - """gRPC's Python API.""" import abc @@ -37,28 +36,27 @@ import six from grpc._cython import cygrpc as _cygrpc - ############################## Future Interface ############################### class FutureTimeoutError(Exception): - """Indicates that a method call on a Future timed out.""" + """Indicates that a method call on a Future timed out.""" class FutureCancelledError(Exception): - """Indicates that the computation underlying a Future was cancelled.""" + """Indicates that the computation underlying a Future was cancelled.""" class Future(six.with_metaclass(abc.ABCMeta)): - """A representation of a computation in another control flow. + """A representation of a computation in another control flow. Computations represented by a Future may be yet to be begun, may be ongoing, or may have already completed. """ - @abc.abstractmethod - def cancel(self): - """Attempts to cancel the computation. + @abc.abstractmethod + def cancel(self): + """Attempts to cancel the computation. This method does not block. @@ -71,11 +69,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): remote system for which a determination of whether or not it commenced before being cancelled cannot be made without blocking. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def cancelled(self): - """Describes whether the computation was cancelled. + @abc.abstractmethod + def cancelled(self): + """Describes whether the computation was cancelled. This method does not block. @@ -85,11 +83,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): not limited to this object's cancel method not having been called and the computation's result having become immediately available. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def running(self): - """Describes whether the computation is taking place. + @abc.abstractmethod + def running(self): + """Describes whether the computation is taking place. This method does not block. @@ -98,11 +96,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): taking place now, or False if the computation took place in the past or was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def done(self): - """Describes whether the computation has taken place. + @abc.abstractmethod + def done(self): + """Describes whether the computation has taken place. This method does not block. @@ -111,11 +109,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): unscheduled or interrupted. False if the computation may possibly be executing or scheduled to execute later. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def result(self, timeout=None): - """Accesses the outcome of the computation or raises its exception. + @abc.abstractmethod + def result(self, timeout=None): + """Accesses the outcome of the computation or raises its exception. This method may return immediately or may block. @@ -134,11 +132,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): Exception: If the computation raised an exception, this call will raise the same exception. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def exception(self, timeout=None): - """Return the exception raised by the computation. + @abc.abstractmethod + def exception(self, timeout=None): + """Return the exception raised by the computation. This method may return immediately or may block. @@ -157,11 +155,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): not terminate within the allotted time. FutureCancelledError: If the computation was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def traceback(self, timeout=None): - """Access the traceback of the exception raised by the computation. + @abc.abstractmethod + def traceback(self, timeout=None): + """Access the traceback of the exception raised by the computation. This method may return immediately or may block. @@ -180,11 +178,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): not terminate within the allotted time. FutureCancelledError: If the computation was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_done_callback(self, fn): - """Adds a function to be called at completion of the computation. + @abc.abstractmethod + def add_done_callback(self, fn): + """Adds a function to be called at completion of the computation. The callback will be passed this Future object describing the outcome of the computation. @@ -195,7 +193,7 @@ class Future(six.with_metaclass(abc.ABCMeta)): Args: fn: A callable taking this Future object as its single parameter. """ - raise NotImplementedError() + raise NotImplementedError() ################################ gRPC Enums ################################## @@ -203,7 +201,7 @@ class Future(six.with_metaclass(abc.ABCMeta)): @enum.unique class ChannelConnectivity(enum.Enum): - """Mirrors grpc_connectivity_state in the gRPC Core. + """Mirrors grpc_connectivity_state in the gRPC Core. Attributes: IDLE: The channel is idle. @@ -213,81 +211,80 @@ class ChannelConnectivity(enum.Enum): recover. SHUTDOWN: The channel has seen a failure from which it cannot recover. """ - IDLE = (_cygrpc.ConnectivityState.idle, 'idle') - CONNECTING = (_cygrpc.ConnectivityState.connecting, 'connecting') - READY = (_cygrpc.ConnectivityState.ready, 'ready') - TRANSIENT_FAILURE = ( - _cygrpc.ConnectivityState.transient_failure, 'transient failure') - SHUTDOWN = (_cygrpc.ConnectivityState.shutdown, 'shutdown') + IDLE = (_cygrpc.ConnectivityState.idle, 'idle') + CONNECTING = (_cygrpc.ConnectivityState.connecting, 'connecting') + READY = (_cygrpc.ConnectivityState.ready, 'ready') + TRANSIENT_FAILURE = (_cygrpc.ConnectivityState.transient_failure, + 'transient failure') + SHUTDOWN = (_cygrpc.ConnectivityState.shutdown, 'shutdown') @enum.unique class StatusCode(enum.Enum): - """Mirrors grpc_status_code in the gRPC Core.""" - OK = (_cygrpc.StatusCode.ok, 'ok') - CANCELLED = (_cygrpc.StatusCode.cancelled, 'cancelled') - UNKNOWN = (_cygrpc.StatusCode.unknown, 'unknown') - INVALID_ARGUMENT = ( - _cygrpc.StatusCode.invalid_argument, 'invalid argument') - DEADLINE_EXCEEDED = ( - _cygrpc.StatusCode.deadline_exceeded, 'deadline exceeded') - NOT_FOUND = (_cygrpc.StatusCode.not_found, 'not found') - ALREADY_EXISTS = (_cygrpc.StatusCode.already_exists, 'already exists') - PERMISSION_DENIED = ( - _cygrpc.StatusCode.permission_denied, 'permission denied') - RESOURCE_EXHAUSTED = ( - _cygrpc.StatusCode.resource_exhausted, 'resource exhausted') - FAILED_PRECONDITION = ( - _cygrpc.StatusCode.failed_precondition, 'failed precondition') - ABORTED = (_cygrpc.StatusCode.aborted, 'aborted') - OUT_OF_RANGE = (_cygrpc.StatusCode.out_of_range, 'out of range') - UNIMPLEMENTED = (_cygrpc.StatusCode.unimplemented, 'unimplemented') - INTERNAL = (_cygrpc.StatusCode.internal, 'internal') - UNAVAILABLE = (_cygrpc.StatusCode.unavailable, 'unavailable') - DATA_LOSS = (_cygrpc.StatusCode.data_loss, 'data loss') - UNAUTHENTICATED = (_cygrpc.StatusCode.unauthenticated, 'unauthenticated') + """Mirrors grpc_status_code in the gRPC Core.""" + OK = (_cygrpc.StatusCode.ok, 'ok') + CANCELLED = (_cygrpc.StatusCode.cancelled, 'cancelled') + UNKNOWN = (_cygrpc.StatusCode.unknown, 'unknown') + INVALID_ARGUMENT = (_cygrpc.StatusCode.invalid_argument, 'invalid argument') + DEADLINE_EXCEEDED = (_cygrpc.StatusCode.deadline_exceeded, + 'deadline exceeded') + NOT_FOUND = (_cygrpc.StatusCode.not_found, 'not found') + ALREADY_EXISTS = (_cygrpc.StatusCode.already_exists, 'already exists') + PERMISSION_DENIED = (_cygrpc.StatusCode.permission_denied, + 'permission denied') + RESOURCE_EXHAUSTED = (_cygrpc.StatusCode.resource_exhausted, + 'resource exhausted') + FAILED_PRECONDITION = (_cygrpc.StatusCode.failed_precondition, + 'failed precondition') + ABORTED = (_cygrpc.StatusCode.aborted, 'aborted') + OUT_OF_RANGE = (_cygrpc.StatusCode.out_of_range, 'out of range') + UNIMPLEMENTED = (_cygrpc.StatusCode.unimplemented, 'unimplemented') + INTERNAL = (_cygrpc.StatusCode.internal, 'internal') + UNAVAILABLE = (_cygrpc.StatusCode.unavailable, 'unavailable') + DATA_LOSS = (_cygrpc.StatusCode.data_loss, 'data loss') + UNAUTHENTICATED = (_cygrpc.StatusCode.unauthenticated, 'unauthenticated') ############################# gRPC Exceptions ################################ class RpcError(Exception): - """Raised by the gRPC library to indicate non-OK-status RPC termination.""" + """Raised by the gRPC library to indicate non-OK-status RPC termination.""" ############################## Shared Context ################################ class RpcContext(six.with_metaclass(abc.ABCMeta)): - """Provides RPC-related information and action.""" + """Provides RPC-related information and action.""" - @abc.abstractmethod - def is_active(self): - """Describes whether the RPC is active or has terminated.""" - raise NotImplementedError() + @abc.abstractmethod + def is_active(self): + """Describes whether the RPC is active or has terminated.""" + raise NotImplementedError() - @abc.abstractmethod - def time_remaining(self): - """Describes the length of allowed time remaining for the RPC. + @abc.abstractmethod + def time_remaining(self): + """Describes the length of allowed time remaining for the RPC. Returns: A nonnegative float indicating the length of allowed time in seconds remaining for the RPC to complete before it is considered to have timed out, or None if no deadline was specified for the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def cancel(self): - """Cancels the RPC. + @abc.abstractmethod + def cancel(self): + """Cancels the RPC. Idempotent and has no effect if the RPC has already terminated. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_callback(self, callback): - """Registers a callback to be called on RPC termination. + @abc.abstractmethod + def add_callback(self, callback): + """Registers a callback to be called on RPC termination. Args: callback: A no-parameter callable to be called on RPC termination. @@ -297,76 +294,76 @@ class RpcContext(six.with_metaclass(abc.ABCMeta)): callback was not added and will not later be called (because the RPC already terminated or some other reason). """ - raise NotImplementedError() + raise NotImplementedError() ######################### Invocation-Side Context ############################ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): - """Invocation-side utility object for an RPC.""" + """Invocation-side utility object for an RPC.""" - @abc.abstractmethod - def initial_metadata(self): - """Accesses the initial metadata from the service-side of the RPC. + @abc.abstractmethod + def initial_metadata(self): + """Accesses the initial metadata from the service-side of the RPC. This method blocks until the value is available. Returns: The initial :term:`metadata`. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def trailing_metadata(self): - """Accesses the trailing metadata from the service-side of the RPC. + @abc.abstractmethod + def trailing_metadata(self): + """Accesses the trailing metadata from the service-side of the RPC. This method blocks until the value is available. Returns: The trailing :term:`metadata`. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def code(self): - """Accesses the status code emitted by the service-side of the RPC. + @abc.abstractmethod + def code(self): + """Accesses the status code emitted by the service-side of the RPC. This method blocks until the value is available. Returns: The StatusCode value for the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def details(self): - """Accesses the details value emitted by the service-side of the RPC. + @abc.abstractmethod + def details(self): + """Accesses the details value emitted by the service-side of the RPC. This method blocks until the value is available. Returns: The details string of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() ############ Authentication & Authorization Interfaces & Classes ############# class ChannelCredentials(object): - """A value encapsulating the data required to create a secure Channel. + """A value encapsulating the data required to create a secure Channel. This class has no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions. """ - def __init__(self, credentials): - self._credentials = credentials + def __init__(self, credentials): + self._credentials = credentials class CallCredentials(object): - """A value encapsulating data asserting an identity over a channel. + """A value encapsulating data asserting an identity over a channel. A CallCredentials may be composed with ChannelCredentials to always assert identity for every call over that Channel. @@ -375,12 +372,12 @@ class CallCredentials(object): instances and its instances exist to be passed to other functions. """ - def __init__(self, credentials): - self._credentials = credentials + def __init__(self, credentials): + self._credentials = credentials class AuthMetadataContext(six.with_metaclass(abc.ABCMeta)): - """Provides information to call credentials metadata plugins. + """Provides information to call credentials metadata plugins. Attributes: service_url: A string URL of the service being called into. @@ -389,23 +386,23 @@ class AuthMetadataContext(six.with_metaclass(abc.ABCMeta)): class AuthMetadataPluginCallback(six.with_metaclass(abc.ABCMeta)): - """Callback object received by a metadata plugin.""" + """Callback object received by a metadata plugin.""" - def __call__(self, metadata, error): - """Inform the gRPC runtime of the metadata to construct a CallCredentials. + def __call__(self, metadata, error): + """Inform the gRPC runtime of the metadata to construct a CallCredentials. Args: metadata: The :term:`metadata` used to construct the CallCredentials. error: An Exception to indicate error or None to indicate success. """ - raise NotImplementedError() + raise NotImplementedError() class AuthMetadataPlugin(six.with_metaclass(abc.ABCMeta)): - """A specification for custom authentication.""" + """A specification for custom authentication.""" - def __call__(self, context, callback): - """Implements authentication by passing metadata to a callback. + def __call__(self, context, callback): + """Implements authentication by passing metadata to a callback. Implementations of this method must not block. @@ -415,29 +412,29 @@ class AuthMetadataPlugin(six.with_metaclass(abc.ABCMeta)): callback: An AuthMetadataPluginCallback to be invoked either synchronously or asynchronously. """ - raise NotImplementedError() + raise NotImplementedError() class ServerCredentials(object): - """A value encapsulating the data required to open a secure port on a Server. + """A value encapsulating the data required to open a secure port on a Server. This class has no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions. """ - def __init__(self, credentials): - self._credentials = credentials + def __init__(self, credentials): + self._credentials = credentials ######################## Multi-Callable Interfaces ########################### class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a unary-unary RPC.""" + """Affords invoking a unary-unary RPC.""" - @abc.abstractmethod - def __call__(self, request, timeout=None, metadata=None, credentials=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, request, timeout=None, metadata=None, credentials=None): + """Synchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -454,11 +451,11 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): raised RpcError will also be a Call for the RPC affording the RPC's metadata, status code, and details. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def with_call(self, request, timeout=None, metadata=None, credentials=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def with_call(self, request, timeout=None, metadata=None, credentials=None): + """Synchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -475,11 +472,11 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): raised RpcError will also be a Call for the RPC affording the RPC's metadata, status code, and details. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def future(self, request, timeout=None, metadata=None, credentials=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def future(self, request, timeout=None, metadata=None, credentials=None): + """Asynchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -494,15 +491,15 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): message of the RPC. Should the event terminate with non-OK status, the returned Future's exception value will be an RpcError. """ - raise NotImplementedError() + raise NotImplementedError() class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a unary-stream RPC.""" + """Affords invoking a unary-stream RPC.""" - @abc.abstractmethod - def __call__(self, request, timeout=None, metadata=None, credentials=None): - """Invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, request, timeout=None, metadata=None, credentials=None): + """Invokes the underlying RPC. Args: request: The request value for the RPC. @@ -516,16 +513,19 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise RpcError indicating termination of the RPC with non-OK status. """ - raise NotImplementedError() + raise NotImplementedError() class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a stream-unary RPC in any call style.""" + """Affords invoking a stream-unary RPC in any call style.""" - @abc.abstractmethod - def __call__( - self, request_iterator, timeout=None, metadata=None, credentials=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + """Synchronously invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -543,12 +543,15 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): raised RpcError will also be a Call for the RPC affording the RPC's metadata, status code, and details. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def with_call( - self, request_iterator, timeout=None, metadata=None, credentials=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def with_call(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + """Synchronously invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -565,12 +568,15 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): raised RpcError will also be a Call for the RPC affording the RPC's metadata, status code, and details. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def future( - self, request_iterator, timeout=None, metadata=None, credentials=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def future(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + """Asynchronously invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -585,16 +591,19 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): message of the RPC. Should the event terminate with non-OK status, the returned Future's exception value will be an RpcError. """ - raise NotImplementedError() + raise NotImplementedError() class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a stream-stream RPC in any call style.""" + """Affords invoking a stream-stream RPC in any call style.""" - @abc.abstractmethod - def __call__( - self, request_iterator, timeout=None, metadata=None, credentials=None): - """Invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + """Invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -608,18 +617,18 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise RpcError indicating termination of the RPC with non-OK status. """ - raise NotImplementedError() + raise NotImplementedError() ############################# Channel Interface ############################## class Channel(six.with_metaclass(abc.ABCMeta)): - """Affords RPC invocation via generic methods.""" + """Affords RPC invocation via generic methods.""" - @abc.abstractmethod - def subscribe(self, callback, try_to_connect=False): - """Subscribes to this Channel's connectivity. + @abc.abstractmethod + def subscribe(self, callback, try_to_connect=False): + """Subscribes to this Channel's connectivity. Args: callback: A callable to be invoked and passed a ChannelConnectivity value @@ -631,22 +640,24 @@ class Channel(six.with_metaclass(abc.ABCMeta)): attempt to connect if it is not already connected and ready to conduct RPCs. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unsubscribe(self, callback): - """Unsubscribes a callback from this Channel's connectivity. + @abc.abstractmethod + def unsubscribe(self, callback): + """Unsubscribes a callback from this Channel's connectivity. Args: callback: A callable previously registered with this Channel from having been passed to its "subscribe" method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unary_unary( - self, method, request_serializer=None, response_deserializer=None): - """Creates a UnaryUnaryMultiCallable for a unary-unary method. + @abc.abstractmethod + def unary_unary(self, + method, + request_serializer=None, + response_deserializer=None): + """Creates a UnaryUnaryMultiCallable for a unary-unary method. Args: method: The name of the RPC method. @@ -658,12 +669,14 @@ class Channel(six.with_metaclass(abc.ABCMeta)): Returns: A UnaryUnaryMultiCallable value for the named unary-unary method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unary_stream( - self, method, request_serializer=None, response_deserializer=None): - """Creates a UnaryStreamMultiCallable for a unary-stream method. + @abc.abstractmethod + def unary_stream(self, + method, + request_serializer=None, + response_deserializer=None): + """Creates a UnaryStreamMultiCallable for a unary-stream method. Args: method: The name of the RPC method. @@ -675,12 +688,14 @@ class Channel(six.with_metaclass(abc.ABCMeta)): Returns: A UnaryStreamMultiCallable value for the name unary-stream method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_unary( - self, method, request_serializer=None, response_deserializer=None): - """Creates a StreamUnaryMultiCallable for a stream-unary method. + @abc.abstractmethod + def stream_unary(self, + method, + request_serializer=None, + response_deserializer=None): + """Creates a StreamUnaryMultiCallable for a stream-unary method. Args: method: The name of the RPC method. @@ -692,12 +707,14 @@ class Channel(six.with_metaclass(abc.ABCMeta)): Returns: A StreamUnaryMultiCallable value for the named stream-unary method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_stream( - self, method, request_serializer=None, response_deserializer=None): - """Creates a StreamStreamMultiCallable for a stream-stream method. + @abc.abstractmethod + def stream_stream(self, + method, + request_serializer=None, + response_deserializer=None): + """Creates a StreamStreamMultiCallable for a stream-stream method. Args: method: The name of the RPC method. @@ -709,36 +726,36 @@ class Channel(six.with_metaclass(abc.ABCMeta)): Returns: A StreamStreamMultiCallable value for the named stream-stream method. """ - raise NotImplementedError() + raise NotImplementedError() ########################## Service-Side Context ############################## class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): - """A context object passed to method implementations.""" + """A context object passed to method implementations.""" - @abc.abstractmethod - def invocation_metadata(self): - """Accesses the metadata from the invocation-side of the RPC. + @abc.abstractmethod + def invocation_metadata(self): + """Accesses the metadata from the invocation-side of the RPC. Returns: The invocation :term:`metadata`. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def peer(self): - """Identifies the peer that invoked the RPC being serviced. + @abc.abstractmethod + def peer(self): + """Identifies the peer that invoked the RPC being serviced. Returns: A string identifying the peer that invoked the RPC being serviced. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def send_initial_metadata(self, initial_metadata): - """Sends the initial metadata value to the invocation-side of the RPC. + @abc.abstractmethod + def send_initial_metadata(self, initial_metadata): + """Sends the initial metadata value to the invocation-side of the RPC. This method need not be called by method implementations if they have no service-side initial metadata to transmit. @@ -746,11 +763,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): Args: initial_metadata: The initial :term:`metadata`. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def set_trailing_metadata(self, trailing_metadata): - """Accepts the trailing metadata value of the RPC. + @abc.abstractmethod + def set_trailing_metadata(self, trailing_metadata): + """Accepts the trailing metadata value of the RPC. This method need not be called by method implementations if they have no service-side trailing metadata to transmit. @@ -758,11 +775,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): Args: trailing_metadata: The trailing :term:`metadata`. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def set_code(self, code): - """Accepts the status code of the RPC. + @abc.abstractmethod + def set_code(self, code): + """Accepts the status code of the RPC. This method need not be called by method implementations if they wish the gRPC runtime to determine the status code of the RPC. @@ -771,11 +788,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): code: A StatusCode value to be transmitted to the invocation side of the RPC as the status code of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def set_details(self, details): - """Accepts the service-side details of the RPC. + @abc.abstractmethod + def set_details(self, details): + """Accepts the service-side details of the RPC. This method need not be called by method implementations if they have no details to transmit. @@ -784,14 +801,14 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): details: A string to be transmitted to the invocation side of the RPC as the status details of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() ##################### Service-Side Handler Interfaces ######################## class RpcMethodHandler(six.with_metaclass(abc.ABCMeta)): - """An implementation of a single RPC method. + """An implementation of a single RPC method. Attributes: request_streaming: Whether the RPC supports exactly one request message or @@ -826,7 +843,7 @@ class RpcMethodHandler(six.with_metaclass(abc.ABCMeta)): class HandlerCallDetails(six.with_metaclass(abc.ABCMeta)): - """Describes an RPC that has just arrived for service. + """Describes an RPC that has just arrived for service. Attributes: method: The method name of the RPC. invocation_metadata: The :term:`metadata` from the invocation side of the RPC. @@ -834,11 +851,11 @@ class HandlerCallDetails(six.with_metaclass(abc.ABCMeta)): class GenericRpcHandler(six.with_metaclass(abc.ABCMeta)): - """An implementation of arbitrarily many RPC methods.""" + """An implementation of arbitrarily many RPC methods.""" - @abc.abstractmethod - def service(self, handler_call_details): - """Services an RPC (or not). + @abc.abstractmethod + def service(self, handler_call_details): + """Services an RPC (or not). Args: handler_call_details: A HandlerCallDetails describing the RPC. @@ -847,11 +864,11 @@ class GenericRpcHandler(six.with_metaclass(abc.ABCMeta)): An RpcMethodHandler with which the RPC may be serviced, or None to indicate that this object will not be servicing the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class ServiceRpcHandler(six.with_metaclass(abc.ABCMeta, GenericRpcHandler)): - """An implementation of RPC methods belonging to a service. + """An implementation of RPC methods belonging to a service. A service handles RPC methods with structured names of the form '/Service.Name/Service.MethodX', where 'Service.Name' is the value @@ -860,25 +877,25 @@ class ServiceRpcHandler(six.with_metaclass(abc.ABCMeta, GenericRpcHandler)): service name. """ - @abc.abstractmethod - def service_name(self): - """Returns this services name. + @abc.abstractmethod + def service_name(self): + """Returns this services name. Returns: The service name. """ - raise NotImplementedError() + raise NotImplementedError() ############################# Server Interface ############################### class Server(six.with_metaclass(abc.ABCMeta)): - """Services RPCs.""" + """Services RPCs.""" - @abc.abstractmethod - def add_generic_rpc_handlers(self, generic_rpc_handlers): - """Registers GenericRpcHandlers with this Server. + @abc.abstractmethod + def add_generic_rpc_handlers(self, generic_rpc_handlers): + """Registers GenericRpcHandlers with this Server. This method is only safe to call before the server is started. @@ -886,11 +903,11 @@ class Server(six.with_metaclass(abc.ABCMeta)): generic_rpc_handlers: An iterable of GenericRpcHandlers that will be used to service RPCs after this Server is started. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_insecure_port(self, address): - """Reserves a port for insecure RPC service once this Server becomes active. + @abc.abstractmethod + def add_insecure_port(self, address): + """Reserves a port for insecure RPC service once this Server becomes active. This method may only be called before calling this Server's start method is called. @@ -904,11 +921,11 @@ class Server(six.with_metaclass(abc.ABCMeta)): in the passed address, but will likely be different if the port number contained in the passed address was zero. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_secure_port(self, address, server_credentials): - """Reserves a port for secure RPC service after this Server becomes active. + @abc.abstractmethod + def add_secure_port(self, address, server_credentials): + """Reserves a port for secure RPC service after this Server becomes active. This method may only be called before calling this Server's start method is called. @@ -923,20 +940,20 @@ class Server(six.with_metaclass(abc.ABCMeta)): in the passed address, but will likely be different if the port number contained in the passed address was zero. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def start(self): - """Starts this Server's service of RPCs. + @abc.abstractmethod + def start(self): + """Starts this Server's service of RPCs. This method may only be called while the server is not serving RPCs (i.e. it is not idempotent). """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stop(self, grace): - """Stops this Server's service of RPCs. + @abc.abstractmethod + def stop(self, grace): + """Stops this Server's service of RPCs. All calls to this method immediately stop service of new RPCs. When existing RPCs are aborted is controlled by the grace period parameter passed to this @@ -967,15 +984,16 @@ class Server(six.with_metaclass(abc.ABCMeta)): at the time it was stopped or if all RPCs that it had underway completed very early in the grace period). """ - raise NotImplementedError() + raise NotImplementedError() ################################# Functions ################################ -def unary_unary_rpc_method_handler( - behavior, request_deserializer=None, response_serializer=None): - """Creates an RpcMethodHandler for a unary-unary RPC method. +def unary_unary_rpc_method_handler(behavior, + request_deserializer=None, + response_serializer=None): + """Creates an RpcMethodHandler for a unary-unary RPC method. Args: behavior: The implementation of an RPC method as a callable behavior taking @@ -987,15 +1005,16 @@ def unary_unary_rpc_method_handler( An RpcMethodHandler for a unary-unary RPC method constructed from the given parameters. """ - from grpc import _utilities - return _utilities.RpcMethodHandler( - False, False, request_deserializer, response_serializer, behavior, None, - None, None) + from grpc import _utilities + return _utilities.RpcMethodHandler(False, False, request_deserializer, + response_serializer, behavior, None, + None, None) -def unary_stream_rpc_method_handler( - behavior, request_deserializer=None, response_serializer=None): - """Creates an RpcMethodHandler for a unary-stream RPC method. +def unary_stream_rpc_method_handler(behavior, + request_deserializer=None, + response_serializer=None): + """Creates an RpcMethodHandler for a unary-stream RPC method. Args: behavior: The implementation of an RPC method as a callable behavior taking @@ -1007,15 +1026,16 @@ def unary_stream_rpc_method_handler( An RpcMethodHandler for a unary-stream RPC method constructed from the given parameters. """ - from grpc import _utilities - return _utilities.RpcMethodHandler( - False, True, request_deserializer, response_serializer, None, behavior, - None, None) + from grpc import _utilities + return _utilities.RpcMethodHandler(False, True, request_deserializer, + response_serializer, None, behavior, + None, None) -def stream_unary_rpc_method_handler( - behavior, request_deserializer=None, response_serializer=None): - """Creates an RpcMethodHandler for a stream-unary RPC method. +def stream_unary_rpc_method_handler(behavior, + request_deserializer=None, + response_serializer=None): + """Creates an RpcMethodHandler for a stream-unary RPC method. Args: behavior: The implementation of an RPC method as a callable behavior taking @@ -1027,15 +1047,16 @@ def stream_unary_rpc_method_handler( An RpcMethodHandler for a stream-unary RPC method constructed from the given parameters. """ - from grpc import _utilities - return _utilities.RpcMethodHandler( - True, False, request_deserializer, response_serializer, None, None, - behavior, None) + from grpc import _utilities + return _utilities.RpcMethodHandler(True, False, request_deserializer, + response_serializer, None, None, + behavior, None) -def stream_stream_rpc_method_handler( - behavior, request_deserializer=None, response_serializer=None): - """Creates an RpcMethodHandler for a stream-stream RPC method. +def stream_stream_rpc_method_handler(behavior, + request_deserializer=None, + response_serializer=None): + """Creates an RpcMethodHandler for a stream-stream RPC method. Args: behavior: The implementation of an RPC method as a callable behavior taking @@ -1048,14 +1069,14 @@ def stream_stream_rpc_method_handler( An RpcMethodHandler for a stream-stream RPC method constructed from the given parameters. """ - from grpc import _utilities - return _utilities.RpcMethodHandler( - True, True, request_deserializer, response_serializer, None, None, None, - behavior) + from grpc import _utilities + return _utilities.RpcMethodHandler(True, True, request_deserializer, + response_serializer, None, None, None, + behavior) def method_handlers_generic_handler(service, method_handlers): - """Creates a grpc.GenericRpcHandler from RpcMethodHandlers. + """Creates a grpc.GenericRpcHandler from RpcMethodHandlers. Args: service: A service name to be used for the given method handlers. @@ -1065,13 +1086,14 @@ def method_handlers_generic_handler(service, method_handlers): Returns: A GenericRpcHandler constructed from the given parameters. """ - from grpc import _utilities - return _utilities.DictionaryGenericHandler(service, method_handlers) + from grpc import _utilities + return _utilities.DictionaryGenericHandler(service, method_handlers) -def ssl_channel_credentials( - root_certificates=None, private_key=None, certificate_chain=None): - """Creates a ChannelCredentials for use with an SSL-enabled Channel. +def ssl_channel_credentials(root_certificates=None, + private_key=None, + certificate_chain=None): + """Creates a ChannelCredentials for use with an SSL-enabled Channel. Args: root_certificates: The PEM-encoded root certificates or unset to ask for @@ -1084,16 +1106,16 @@ def ssl_channel_credentials( Returns: A ChannelCredentials for use with an SSL-enabled Channel. """ - if private_key is not None or certificate_chain is not None: - pair = _cygrpc.SslPemKeyCertPair(private_key, certificate_chain) - else: - pair = None - return ChannelCredentials( - _cygrpc.channel_credentials_ssl(root_certificates, pair)) + if private_key is not None or certificate_chain is not None: + pair = _cygrpc.SslPemKeyCertPair(private_key, certificate_chain) + else: + pair = None + return ChannelCredentials( + _cygrpc.channel_credentials_ssl(root_certificates, pair)) def metadata_call_credentials(metadata_plugin, name=None): - """Construct CallCredentials from an AuthMetadataPlugin. + """Construct CallCredentials from an AuthMetadataPlugin. Args: metadata_plugin: An AuthMetadataPlugin to use as the authentication behavior @@ -1103,21 +1125,21 @@ def metadata_call_credentials(metadata_plugin, name=None): Returns: A CallCredentials. """ - from grpc import _plugin_wrapping - if name is None: - try: - effective_name = metadata_plugin.__name__ - except AttributeError: - effective_name = metadata_plugin.__class__.__name__ - else: - effective_name = name - return CallCredentials( - _plugin_wrapping.call_credentials_metadata_plugin( - metadata_plugin, effective_name)) + from grpc import _plugin_wrapping + if name is None: + try: + effective_name = metadata_plugin.__name__ + except AttributeError: + effective_name = metadata_plugin.__class__.__name__ + else: + effective_name = name + return CallCredentials( + _plugin_wrapping.call_credentials_metadata_plugin(metadata_plugin, + effective_name)) def access_token_call_credentials(access_token): - """Construct CallCredentials from an access token. + """Construct CallCredentials from an access token. Args: access_token: A string to place directly in the http request @@ -1126,13 +1148,13 @@ def access_token_call_credentials(access_token): Returns: A CallCredentials. """ - from grpc import _auth - return metadata_call_credentials( - _auth.AccessTokenCallCredentials(access_token)) + from grpc import _auth + return metadata_call_credentials( + _auth.AccessTokenCallCredentials(access_token)) def composite_call_credentials(*call_credentials): - """Compose multiple CallCredentials to make a new CallCredentials. + """Compose multiple CallCredentials to make a new CallCredentials. Args: *call_credentials: At least two CallCredentials objects. @@ -1140,16 +1162,16 @@ def composite_call_credentials(*call_credentials): Returns: A CallCredentials object composed of the given CallCredentials objects. """ - from grpc import _credential_composition - cygrpc_call_credentials = tuple( - single_call_credentials._credentials - for single_call_credentials in call_credentials) - return CallCredentials( - _credential_composition.call(cygrpc_call_credentials)) + from grpc import _credential_composition + cygrpc_call_credentials = tuple( + single_call_credentials._credentials + for single_call_credentials in call_credentials) + return CallCredentials( + _credential_composition.call(cygrpc_call_credentials)) def composite_channel_credentials(channel_credentials, *call_credentials): - """Compose a ChannelCredentials and one or more CallCredentials objects. + """Compose a ChannelCredentials and one or more CallCredentials objects. Args: channel_credentials: A ChannelCredentials. @@ -1159,19 +1181,19 @@ def composite_channel_credentials(channel_credentials, *call_credentials): A ChannelCredentials composed of the given ChannelCredentials and CallCredentials objects. """ - from grpc import _credential_composition - cygrpc_call_credentials = tuple( - single_call_credentials._credentials - for single_call_credentials in call_credentials) - return ChannelCredentials( - _credential_composition.channel( - channel_credentials._credentials, cygrpc_call_credentials)) + from grpc import _credential_composition + cygrpc_call_credentials = tuple( + single_call_credentials._credentials + for single_call_credentials in call_credentials) + return ChannelCredentials( + _credential_composition.channel(channel_credentials._credentials, + cygrpc_call_credentials)) -def ssl_server_credentials( - private_key_certificate_chain_pairs, root_certificates=None, - require_client_auth=False): - """Creates a ServerCredentials for use with an SSL-enabled Server. +def ssl_server_credentials(private_key_certificate_chain_pairs, + root_certificates=None, + require_client_auth=False): + """Creates a ServerCredentials for use with an SSL-enabled Server. Args: private_key_certificate_chain_pairs: A nonempty sequence each element of @@ -1187,23 +1209,23 @@ def ssl_server_credentials( Returns: A ServerCredentials for use with an SSL-enabled Server. """ - if len(private_key_certificate_chain_pairs) == 0: - raise ValueError( - 'At least one private key-certificate chain pair is required!') - elif require_client_auth and root_certificates is None: - raise ValueError( - 'Illegal to require client auth without providing root certificates!') - else: - return ServerCredentials( - _cygrpc.server_credentials_ssl( - root_certificates, - [_cygrpc.SslPemKeyCertPair(key, pem) - for key, pem in private_key_certificate_chain_pairs], - require_client_auth)) + if len(private_key_certificate_chain_pairs) == 0: + raise ValueError( + 'At least one private key-certificate chain pair is required!') + elif require_client_auth and root_certificates is None: + raise ValueError( + 'Illegal to require client auth without providing root certificates!' + ) + else: + return ServerCredentials( + _cygrpc.server_credentials_ssl(root_certificates, [ + _cygrpc.SslPemKeyCertPair(key, pem) + for key, pem in private_key_certificate_chain_pairs + ], require_client_auth)) def channel_ready_future(channel): - """Creates a Future tracking when a Channel is ready. + """Creates a Future tracking when a Channel is ready. Cancelling the returned Future does not tell the given Channel to abandon attempts it may have been making to connect; cancelling merely deactivates the @@ -1216,12 +1238,12 @@ def channel_ready_future(channel): A Future that matures when the given Channel has connectivity ChannelConnectivity.READY. """ - from grpc import _utilities - return _utilities.channel_ready_future(channel) + from grpc import _utilities + return _utilities.channel_ready_future(channel) def insecure_channel(target, options=None): - """Creates an insecure Channel to a server. + """Creates an insecure Channel to a server. Args: target: The target to which to connect. @@ -1231,12 +1253,12 @@ def insecure_channel(target, options=None): Returns: A Channel to the target through which RPCs may be conducted. """ - from grpc import _channel - return _channel.Channel(target, () if options is None else options, None) + from grpc import _channel + return _channel.Channel(target, () if options is None else options, None) def secure_channel(target, credentials, options=None): - """Creates a secure Channel to a server. + """Creates a secure Channel to a server. Args: target: The target to which to connect. @@ -1247,13 +1269,13 @@ def secure_channel(target, credentials, options=None): Returns: A Channel to the target through which RPCs may be conducted. """ - from grpc import _channel - return _channel.Channel(target, () if options is None else options, - credentials._credentials) + from grpc import _channel + return _channel.Channel(target, () if options is None else options, + credentials._credentials) def server(thread_pool, handlers=None, options=None): - """Creates a Server with which RPCs can be serviced. + """Creates a Server with which RPCs can be serviced. Args: thread_pool: A futures.ThreadPoolExecutor to be used by the returned Server @@ -1269,14 +1291,13 @@ def server(thread_pool, handlers=None, options=None): Returns: A Server with which RPCs can be serviced. """ - from grpc import _server - return _server.Server(thread_pool, () if handlers is None else handlers, - () if options is None else options) + from grpc import _server + return _server.Server(thread_pool, () if handlers is None else handlers, () + if options is None else options) ################################### __all__ ################################# - __all__ = ( 'FutureTimeoutError', 'FutureCancelledError', @@ -1317,26 +1338,23 @@ __all__ = ( 'channel_ready_future', 'insecure_channel', 'secure_channel', - 'server', -) - + 'server',) ############################### Extension Shims ################################ - # Here to maintain backwards compatibility; avoid using these in new code! try: - import grpc_tools - sys.modules.update({'grpc.tools': grpc_tools}) + import grpc_tools + sys.modules.update({'grpc.tools': grpc_tools}) except ImportError: - pass + pass try: - import grpc_health - sys.modules.update({'grpc.health': grpc_health}) + import grpc_health + sys.modules.update({'grpc.health': grpc_health}) except ImportError: - pass + pass try: - import grpc_reflection - sys.modules.update({'grpc.reflection': grpc_reflection}) + import grpc_reflection + sys.modules.update({'grpc.reflection': grpc_reflection}) except ImportError: - pass + pass diff --git a/src/python/grpcio/grpc/_auth.py b/src/python/grpcio/grpc/_auth.py index dea3221c9d8..e8a90cf5047 100644 --- a/src/python/grpcio/grpc/_auth.py +++ b/src/python/grpcio/grpc/_auth.py @@ -26,7 +26,6 @@ # 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. - """GRPCAuthMetadataPlugins for standard authentication.""" import inspect @@ -36,51 +35,53 @@ import grpc def _sign_request(callback, token, error): - metadata = (('authorization', 'Bearer {}'.format(token)),) - callback(metadata, error) + metadata = (('authorization', 'Bearer {}'.format(token)),) + callback(metadata, error) class GoogleCallCredentials(grpc.AuthMetadataPlugin): - """Metadata wrapper for GoogleCredentials from the oauth2client library.""" - - def __init__(self, credentials): - self._credentials = credentials - self._pool = futures.ThreadPoolExecutor(max_workers=1) - - # Hack to determine if these are JWT creds and we need to pass - # additional_claims when getting a token - if 'additional_claims' in inspect.getargspec( - credentials.get_access_token).args: - self._is_jwt = True - else: - self._is_jwt = False - - def __call__(self, context, callback): - # MetadataPlugins cannot block (see grpc.beta.interfaces.py) - if self._is_jwt: - future = self._pool.submit(self._credentials.get_access_token, - additional_claims={'aud': context.service_url}) - else: - future = self._pool.submit(self._credentials.get_access_token) - future.add_done_callback(lambda x: self._get_token_callback(callback, x)) - - def _get_token_callback(self, callback, future): - try: - access_token = future.result().access_token - except Exception as e: - _sign_request(callback, None, e) - else: - _sign_request(callback, access_token, None) - - def __del__(self): - self._pool.shutdown(wait=False) + """Metadata wrapper for GoogleCredentials from the oauth2client library.""" + + def __init__(self, credentials): + self._credentials = credentials + self._pool = futures.ThreadPoolExecutor(max_workers=1) + + # Hack to determine if these are JWT creds and we need to pass + # additional_claims when getting a token + if 'additional_claims' in inspect.getargspec( + credentials.get_access_token).args: + self._is_jwt = True + else: + self._is_jwt = False + + def __call__(self, context, callback): + # MetadataPlugins cannot block (see grpc.beta.interfaces.py) + if self._is_jwt: + future = self._pool.submit( + self._credentials.get_access_token, + additional_claims={'aud': context.service_url}) + else: + future = self._pool.submit(self._credentials.get_access_token) + future.add_done_callback( + lambda x: self._get_token_callback(callback, x)) + + def _get_token_callback(self, callback, future): + try: + access_token = future.result().access_token + except Exception as e: + _sign_request(callback, None, e) + else: + _sign_request(callback, access_token, None) + + def __del__(self): + self._pool.shutdown(wait=False) class AccessTokenCallCredentials(grpc.AuthMetadataPlugin): - """Metadata wrapper for raw access token credentials.""" + """Metadata wrapper for raw access token credentials.""" - def __init__(self, access_token): - self._access_token = access_token + def __init__(self, access_token): + self._access_token = access_token - def __call__(self, context, callback): - _sign_request(callback, self._access_token, None) + def __call__(self, context, callback): + _sign_request(callback, self._access_token, None) diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index e8c6a99cb18..77412236cc6 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -26,7 +26,6 @@ # 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. - """Invocation-side implementation of gRPC Python.""" import sys @@ -52,692 +51,710 @@ _UNARY_UNARY_INITIAL_DUE = ( cygrpc.OperationType.send_close_from_client, cygrpc.OperationType.receive_initial_metadata, cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client, -) + cygrpc.OperationType.receive_status_on_client,) _UNARY_STREAM_INITIAL_DUE = ( cygrpc.OperationType.send_initial_metadata, cygrpc.OperationType.send_message, cygrpc.OperationType.send_close_from_client, cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_status_on_client, -) + cygrpc.OperationType.receive_status_on_client,) _STREAM_UNARY_INITIAL_DUE = ( cygrpc.OperationType.send_initial_metadata, cygrpc.OperationType.receive_initial_metadata, cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client, -) + cygrpc.OperationType.receive_status_on_client,) _STREAM_STREAM_INITIAL_DUE = ( cygrpc.OperationType.send_initial_metadata, cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_status_on_client, -) + cygrpc.OperationType.receive_status_on_client,) _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE = ( 'Exception calling channel subscription callback!') def _deadline(timeout): - if timeout is None: - return None, _INFINITE_FUTURE - else: - deadline = time.time() + timeout - return deadline, cygrpc.Timespec(deadline) + if timeout is None: + return None, _INFINITE_FUTURE + else: + deadline = time.time() + timeout + return deadline, cygrpc.Timespec(deadline) def _unknown_code_details(unknown_cygrpc_code, details): - return 'Server sent unknown code {} and details "{}"'.format( - unknown_cygrpc_code, details) + return 'Server sent unknown code {} and details "{}"'.format( + unknown_cygrpc_code, details) def _wait_once_until(condition, until): - if until is None: - condition.wait() - else: - remaining = until - time.time() - if remaining < 0: - raise grpc.FutureTimeoutError() + if until is None: + condition.wait() else: - condition.wait(timeout=remaining) + remaining = until - time.time() + if remaining < 0: + raise grpc.FutureTimeoutError() + else: + condition.wait(timeout=remaining) + _INTERNAL_CALL_ERROR_MESSAGE_FORMAT = ( 'Internal gRPC call error %d. ' + 'Please report to https://github.com/grpc/grpc/issues') + def _check_call_error(call_error, metadata): - if call_error == cygrpc.CallError.invalid_metadata: - raise ValueError('metadata was invalid: %s' % metadata) - elif call_error != cygrpc.CallError.ok: - raise ValueError(_INTERNAL_CALL_ERROR_MESSAGE_FORMAT % call_error) + if call_error == cygrpc.CallError.invalid_metadata: + raise ValueError('metadata was invalid: %s' % metadata) + elif call_error != cygrpc.CallError.ok: + raise ValueError(_INTERNAL_CALL_ERROR_MESSAGE_FORMAT % call_error) + def _call_error_set_RPCstate(state, call_error, metadata): - if call_error == cygrpc.CallError.invalid_metadata: - _abort(state, grpc.StatusCode.INTERNAL, 'metadata was invalid: %s' % metadata) - else: - _abort(state, grpc.StatusCode.INTERNAL, - _INTERNAL_CALL_ERROR_MESSAGE_FORMAT % call_error) + if call_error == cygrpc.CallError.invalid_metadata: + _abort(state, grpc.StatusCode.INTERNAL, + 'metadata was invalid: %s' % metadata) + else: + _abort(state, grpc.StatusCode.INTERNAL, + _INTERNAL_CALL_ERROR_MESSAGE_FORMAT % call_error) + class _RPCState(object): - def __init__(self, due, initial_metadata, trailing_metadata, code, details): - self.condition = threading.Condition() - # The cygrpc.OperationType objects representing events due from the RPC's - # completion queue. - self.due = set(due) - self.initial_metadata = initial_metadata - self.response = None - self.trailing_metadata = trailing_metadata - self.code = code - self.details = details - # The semantics of grpc.Future.cancel and grpc.Future.cancelled are - # slightly wonky, so they have to be tracked separately from the rest of the - # result of the RPC. This field tracks whether cancellation was requested - # prior to termination of the RPC. - self.cancelled = False - self.callbacks = [] + def __init__(self, due, initial_metadata, trailing_metadata, code, details): + self.condition = threading.Condition() + # The cygrpc.OperationType objects representing events due from the RPC's + # completion queue. + self.due = set(due) + self.initial_metadata = initial_metadata + self.response = None + self.trailing_metadata = trailing_metadata + self.code = code + self.details = details + # The semantics of grpc.Future.cancel and grpc.Future.cancelled are + # slightly wonky, so they have to be tracked separately from the rest of the + # result of the RPC. This field tracks whether cancellation was requested + # prior to termination of the RPC. + self.cancelled = False + self.callbacks = [] def _abort(state, code, details): - if state.code is None: - state.code = code - state.details = details - if state.initial_metadata is None: - state.initial_metadata = _EMPTY_METADATA - state.trailing_metadata = _EMPTY_METADATA + if state.code is None: + state.code = code + state.details = details + if state.initial_metadata is None: + state.initial_metadata = _EMPTY_METADATA + state.trailing_metadata = _EMPTY_METADATA def _handle_event(event, state, response_deserializer): - callbacks = [] - for batch_operation in event.batch_operations: - operation_type = batch_operation.type - state.due.remove(operation_type) - if operation_type == cygrpc.OperationType.receive_initial_metadata: - state.initial_metadata = batch_operation.received_metadata - elif operation_type == cygrpc.OperationType.receive_message: - serialized_response = batch_operation.received_message.bytes() - if serialized_response is not None: - response = _common.deserialize( - serialized_response, response_deserializer) - if response is None: - details = 'Exception deserializing response!' - _abort(state, grpc.StatusCode.INTERNAL, details) - else: - state.response = response - elif operation_type == cygrpc.OperationType.receive_status_on_client: - state.trailing_metadata = batch_operation.received_metadata - if state.code is None: - code = _common.CYGRPC_STATUS_CODE_TO_STATUS_CODE.get( - batch_operation.received_status_code) - if code is None: - state.code = grpc.StatusCode.UNKNOWN - state.details = _unknown_code_details( - batch_operation.received_status_code, - batch_operation.received_status_details) - else: - state.code = code - state.details = batch_operation.received_status_details - callbacks.extend(state.callbacks) - state.callbacks = None - return callbacks + callbacks = [] + for batch_operation in event.batch_operations: + operation_type = batch_operation.type + state.due.remove(operation_type) + if operation_type == cygrpc.OperationType.receive_initial_metadata: + state.initial_metadata = batch_operation.received_metadata + elif operation_type == cygrpc.OperationType.receive_message: + serialized_response = batch_operation.received_message.bytes() + if serialized_response is not None: + response = _common.deserialize(serialized_response, + response_deserializer) + if response is None: + details = 'Exception deserializing response!' + _abort(state, grpc.StatusCode.INTERNAL, details) + else: + state.response = response + elif operation_type == cygrpc.OperationType.receive_status_on_client: + state.trailing_metadata = batch_operation.received_metadata + if state.code is None: + code = _common.CYGRPC_STATUS_CODE_TO_STATUS_CODE.get( + batch_operation.received_status_code) + if code is None: + state.code = grpc.StatusCode.UNKNOWN + state.details = _unknown_code_details( + batch_operation.received_status_code, + batch_operation.received_status_details) + else: + state.code = code + state.details = batch_operation.received_status_details + callbacks.extend(state.callbacks) + state.callbacks = None + return callbacks def _event_handler(state, call, response_deserializer): - def handle_event(event): - with state.condition: - callbacks = _handle_event(event, state, response_deserializer) - state.condition.notify_all() - done = not state.due - for callback in callbacks: - callback() - return call if done else None - return handle_event - - -def _consume_request_iterator( - request_iterator, state, call, request_serializer): - event_handler = _event_handler(state, call, None) - - def consume_request_iterator(): - while True: - try: - request = next(request_iterator) - except StopIteration: - break - except Exception as e: - logging.exception("Exception iterating requests!") - call.cancel() - _abort(state, grpc.StatusCode.UNKNOWN, "Exception iterating requests!") - return - serialized_request = _common.serialize(request, request_serializer) - with state.condition: - if state.code is None and not state.cancelled: - if serialized_request is None: - call.cancel() - details = 'Exception serializing request!' - _abort(state, grpc.StatusCode.INTERNAL, details) - return - else: - operations = ( - cygrpc.operation_send_message( - serialized_request, _EMPTY_FLAGS), - ) - call.start_client_batch(cygrpc.Operations(operations), - event_handler) - state.due.add(cygrpc.OperationType.send_message) - while True: - state.condition.wait() - if state.code is None: - if cygrpc.OperationType.send_message not in state.due: - break - else: + + def handle_event(event): + with state.condition: + callbacks = _handle_event(event, state, response_deserializer) + state.condition.notify_all() + done = not state.due + for callback in callbacks: + callback() + return call if done else None + + return handle_event + + +def _consume_request_iterator(request_iterator, state, call, + request_serializer): + event_handler = _event_handler(state, call, None) + + def consume_request_iterator(): + while True: + try: + request = next(request_iterator) + except StopIteration: + break + except Exception as e: + logging.exception("Exception iterating requests!") + call.cancel() + _abort(state, grpc.StatusCode.UNKNOWN, + "Exception iterating requests!") return - else: - return - with state.condition: - if state.code is None: - operations = ( - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - ) - call.start_client_batch(cygrpc.Operations(operations), event_handler) - state.due.add(cygrpc.OperationType.send_close_from_client) - - def stop_consumption_thread(timeout): - with state.condition: - if state.code is None: - call.cancel() - state.cancelled = True - _abort(state, grpc.StatusCode.CANCELLED, 'Cancelled!') - state.condition.notify_all() - - consumption_thread = _common.CleanupThread( - stop_consumption_thread, target=consume_request_iterator) - consumption_thread.start() + serialized_request = _common.serialize(request, request_serializer) + with state.condition: + if state.code is None and not state.cancelled: + if serialized_request is None: + call.cancel() + details = 'Exception serializing request!' + _abort(state, grpc.StatusCode.INTERNAL, details) + return + else: + operations = (cygrpc.operation_send_message( + serialized_request, _EMPTY_FLAGS),) + call.start_client_batch( + cygrpc.Operations(operations), event_handler) + state.due.add(cygrpc.OperationType.send_message) + while True: + state.condition.wait() + if state.code is None: + if cygrpc.OperationType.send_message not in state.due: + break + else: + return + else: + return + with state.condition: + if state.code is None: + operations = ( + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS),) + call.start_client_batch( + cygrpc.Operations(operations), event_handler) + state.due.add(cygrpc.OperationType.send_close_from_client) + + def stop_consumption_thread(timeout): + with state.condition: + if state.code is None: + call.cancel() + state.cancelled = True + _abort(state, grpc.StatusCode.CANCELLED, 'Cancelled!') + state.condition.notify_all() + + consumption_thread = _common.CleanupThread( + stop_consumption_thread, target=consume_request_iterator) + consumption_thread.start() class _Rendezvous(grpc.RpcError, grpc.Future, grpc.Call): - def __init__(self, state, call, response_deserializer, deadline): - super(_Rendezvous, self).__init__() - self._state = state - self._call = call - self._response_deserializer = response_deserializer - self._deadline = deadline - - def cancel(self): - with self._state.condition: - if self._state.code is None: - self._call.cancel() - self._state.cancelled = True - _abort(self._state, grpc.StatusCode.CANCELLED, 'Cancelled!') - self._state.condition.notify_all() - return False - - def cancelled(self): - with self._state.condition: - return self._state.cancelled - - def running(self): - with self._state.condition: - return self._state.code is None - - def done(self): - with self._state.condition: - return self._state.code is not None - - def result(self, timeout=None): - until = None if timeout is None else time.time() + timeout - with self._state.condition: - while True: - if self._state.code is None: - _wait_once_until(self._state.condition, until) - elif self._state.code is grpc.StatusCode.OK: - return self._state.response - elif self._state.cancelled: - raise grpc.FutureCancelledError() - else: - raise self - - def exception(self, timeout=None): - until = None if timeout is None else time.time() + timeout - with self._state.condition: - while True: - if self._state.code is None: - _wait_once_until(self._state.condition, until) - elif self._state.code is grpc.StatusCode.OK: - return None - elif self._state.cancelled: - raise grpc.FutureCancelledError() - else: - return self - - def traceback(self, timeout=None): - until = None if timeout is None else time.time() + timeout - with self._state.condition: - while True: - if self._state.code is None: - _wait_once_until(self._state.condition, until) - elif self._state.code is grpc.StatusCode.OK: - return None - elif self._state.cancelled: - raise grpc.FutureCancelledError() + def __init__(self, state, call, response_deserializer, deadline): + super(_Rendezvous, self).__init__() + self._state = state + self._call = call + self._response_deserializer = response_deserializer + self._deadline = deadline + + def cancel(self): + with self._state.condition: + if self._state.code is None: + self._call.cancel() + self._state.cancelled = True + _abort(self._state, grpc.StatusCode.CANCELLED, 'Cancelled!') + self._state.condition.notify_all() + return False + + def cancelled(self): + with self._state.condition: + return self._state.cancelled + + def running(self): + with self._state.condition: + return self._state.code is None + + def done(self): + with self._state.condition: + return self._state.code is not None + + def result(self, timeout=None): + until = None if timeout is None else time.time() + timeout + with self._state.condition: + while True: + if self._state.code is None: + _wait_once_until(self._state.condition, until) + elif self._state.code is grpc.StatusCode.OK: + return self._state.response + elif self._state.cancelled: + raise grpc.FutureCancelledError() + else: + raise self + + def exception(self, timeout=None): + until = None if timeout is None else time.time() + timeout + with self._state.condition: + while True: + if self._state.code is None: + _wait_once_until(self._state.condition, until) + elif self._state.code is grpc.StatusCode.OK: + return None + elif self._state.cancelled: + raise grpc.FutureCancelledError() + else: + return self + + def traceback(self, timeout=None): + until = None if timeout is None else time.time() + timeout + with self._state.condition: + while True: + if self._state.code is None: + _wait_once_until(self._state.condition, until) + elif self._state.code is grpc.StatusCode.OK: + return None + elif self._state.cancelled: + raise grpc.FutureCancelledError() + else: + try: + raise self + except grpc.RpcError: + return sys.exc_info()[2] + + def add_done_callback(self, fn): + with self._state.condition: + if self._state.code is None: + self._state.callbacks.append(lambda: fn(self)) + return + + fn(self) + + def _next(self): + with self._state.condition: + if self._state.code is None: + event_handler = _event_handler(self._state, self._call, + self._response_deserializer) + self._call.start_client_batch( + cygrpc.Operations( + (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), + event_handler) + self._state.due.add(cygrpc.OperationType.receive_message) + elif self._state.code is grpc.StatusCode.OK: + raise StopIteration() + else: + raise self + while True: + self._state.condition.wait() + if self._state.response is not None: + response = self._state.response + self._state.response = None + return response + elif cygrpc.OperationType.receive_message not in self._state.due: + if self._state.code is grpc.StatusCode.OK: + raise StopIteration() + elif self._state.code is not None: + raise self + + def __iter__(self): + return self + + def __next__(self): + return self._next() + + def next(self): + return self._next() + + def is_active(self): + with self._state.condition: + return self._state.code is None + + def time_remaining(self): + if self._deadline is None: + return None else: - try: - raise self - except grpc.RpcError: - return sys.exc_info()[2] - - def add_done_callback(self, fn): - with self._state.condition: - if self._state.code is None: - self._state.callbacks.append(lambda: fn(self)) - return - - fn(self) - - def _next(self): - with self._state.condition: - if self._state.code is None: - event_handler = _event_handler( - self._state, self._call, self._response_deserializer) - self._call.start_client_batch( - cygrpc.Operations( - (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), - event_handler) - self._state.due.add(cygrpc.OperationType.receive_message) - elif self._state.code is grpc.StatusCode.OK: - raise StopIteration() - else: - raise self - while True: - self._state.condition.wait() - if self._state.response is not None: - response = self._state.response - self._state.response = None - return response - elif cygrpc.OperationType.receive_message not in self._state.due: - if self._state.code is grpc.StatusCode.OK: - raise StopIteration() - elif self._state.code is not None: - raise self - - def __iter__(self): - return self - - def __next__(self): - return self._next() - - def next(self): - return self._next() - - def is_active(self): - with self._state.condition: - return self._state.code is None - - def time_remaining(self): - if self._deadline is None: - return None - else: - return max(self._deadline - time.time(), 0) - - def add_callback(self, callback): - with self._state.condition: - if self._state.callbacks is None: - return False - else: - self._state.callbacks.append(callback) - return True - - def initial_metadata(self): - with self._state.condition: - while self._state.initial_metadata is None: - self._state.condition.wait() - return _common.application_metadata(self._state.initial_metadata) - - def trailing_metadata(self): - with self._state.condition: - while self._state.trailing_metadata is None: - self._state.condition.wait() - return _common.application_metadata(self._state.trailing_metadata) - - def code(self): - with self._state.condition: - while self._state.code is None: - self._state.condition.wait() - return self._state.code - - def details(self): - with self._state.condition: - while self._state.details is None: - self._state.condition.wait() - return _common.decode(self._state.details) - - def _repr(self): - with self._state.condition: - if self._state.code is None: - return '<_Rendezvous object of in-flight RPC>' - else: - return '<_Rendezvous of RPC that terminated with ({}, {})>'.format( - self._state.code, _common.decode(self._state.details)) - - def __repr__(self): - return self._repr() - - def __str__(self): - return self._repr() - - def __del__(self): - with self._state.condition: - if self._state.code is None: - self._call.cancel() - self._state.cancelled = True - self._state.code = grpc.StatusCode.CANCELLED - self._state.condition.notify_all() + return max(self._deadline - time.time(), 0) + + def add_callback(self, callback): + with self._state.condition: + if self._state.callbacks is None: + return False + else: + self._state.callbacks.append(callback) + return True + + def initial_metadata(self): + with self._state.condition: + while self._state.initial_metadata is None: + self._state.condition.wait() + return _common.application_metadata(self._state.initial_metadata) + + def trailing_metadata(self): + with self._state.condition: + while self._state.trailing_metadata is None: + self._state.condition.wait() + return _common.application_metadata(self._state.trailing_metadata) + + def code(self): + with self._state.condition: + while self._state.code is None: + self._state.condition.wait() + return self._state.code + + def details(self): + with self._state.condition: + while self._state.details is None: + self._state.condition.wait() + return _common.decode(self._state.details) + + def _repr(self): + with self._state.condition: + if self._state.code is None: + return '<_Rendezvous object of in-flight RPC>' + else: + return '<_Rendezvous of RPC that terminated with ({}, {})>'.format( + self._state.code, _common.decode(self._state.details)) + + def __repr__(self): + return self._repr() + + def __str__(self): + return self._repr() + + def __del__(self): + with self._state.condition: + if self._state.code is None: + self._call.cancel() + self._state.cancelled = True + self._state.code = grpc.StatusCode.CANCELLED + self._state.condition.notify_all() def _start_unary_request(request, timeout, request_serializer): - deadline, deadline_timespec = _deadline(timeout) - serialized_request = _common.serialize(request, request_serializer) - if serialized_request is None: - state = _RPCState( - (), _EMPTY_METADATA, _EMPTY_METADATA, grpc.StatusCode.INTERNAL, - 'Exception serializing request!') - rendezvous = _Rendezvous(state, None, None, deadline) - return deadline, deadline_timespec, None, rendezvous - else: - return deadline, deadline_timespec, serialized_request, None + deadline, deadline_timespec = _deadline(timeout) + serialized_request = _common.serialize(request, request_serializer) + if serialized_request is None: + state = _RPCState((), _EMPTY_METADATA, _EMPTY_METADATA, + grpc.StatusCode.INTERNAL, + 'Exception serializing request!') + rendezvous = _Rendezvous(state, None, None, deadline) + return deadline, deadline_timespec, None, rendezvous + else: + return deadline, deadline_timespec, serialized_request, None def _end_unary_response_blocking(state, with_call, deadline): - if state.code is grpc.StatusCode.OK: - if with_call: - rendezvous = _Rendezvous(state, None, None, deadline) - return state.response, rendezvous + if state.code is grpc.StatusCode.OK: + if with_call: + rendezvous = _Rendezvous(state, None, None, deadline) + return state.response, rendezvous + else: + return state.response else: - return state.response - else: - raise _Rendezvous(state, None, None, deadline) + raise _Rendezvous(state, None, None, deadline) class _UnaryUnaryMultiCallable(grpc.UnaryUnaryMultiCallable): - def __init__( - self, channel, managed_call, method, request_serializer, - response_deserializer): - self._channel = channel - self._managed_call = managed_call - self._method = method - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def _prepare(self, request, timeout, metadata): - deadline, deadline_timespec, serialized_request, rendezvous = ( - _start_unary_request(request, timeout, self._request_serializer)) - if serialized_request is None: - return None, None, None, None, rendezvous - else: - state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None) - operations = ( - cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), - cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - return state, operations, deadline, deadline_timespec, None - - def _blocking(self, request, timeout, metadata, credentials): - state, operations, deadline, deadline_timespec, rendezvous = self._prepare( - request, timeout, metadata) - if rendezvous: - raise rendezvous - else: - completion_queue = cygrpc.CompletionQueue() - call = self._channel.create_call( - None, 0, completion_queue, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - call_error = call.start_client_batch(cygrpc.Operations(operations), None) - _check_call_error(call_error, metadata) - _handle_event(completion_queue.poll(), state, self._response_deserializer) - return state, deadline - - def __call__(self, request, timeout=None, metadata=None, credentials=None): - state, deadline, = self._blocking(request, timeout, metadata, credentials) - return _end_unary_response_blocking(state, False, deadline) - - def with_call(self, request, timeout=None, metadata=None, credentials=None): - state, deadline, = self._blocking(request, timeout, metadata, credentials) - return _end_unary_response_blocking(state, True, deadline) - - def future(self, request, timeout=None, metadata=None, credentials=None): - state, operations, deadline, deadline_timespec, rendezvous = self._prepare( - request, timeout, metadata) - if rendezvous: - return rendezvous - else: - call, drive_call = self._managed_call( - None, 0, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - event_handler = _event_handler(state, call, self._response_deserializer) - with state.condition: - call_error = call.start_client_batch(cygrpc.Operations(operations), - event_handler) - if call_error != cygrpc.CallError.ok: - _call_error_set_RPCstate(state, call_error, metadata) - return _Rendezvous(state, None, None, deadline) - drive_call() - return _Rendezvous(state, call, self._response_deserializer, deadline) + def __init__(self, channel, managed_call, method, request_serializer, + response_deserializer): + self._channel = channel + self._managed_call = managed_call + self._method = method + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def _prepare(self, request, timeout, metadata): + deadline, deadline_timespec, serialized_request, rendezvous = ( + _start_unary_request(request, timeout, self._request_serializer)) + if serialized_request is None: + return None, None, None, None, rendezvous + else: + state = _RPCState(_UNARY_UNARY_INITIAL_DUE, None, None, None, None) + operations = ( + cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), + cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS), + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + return state, operations, deadline, deadline_timespec, None + + def _blocking(self, request, timeout, metadata, credentials): + state, operations, deadline, deadline_timespec, rendezvous = self._prepare( + request, timeout, metadata) + if rendezvous: + raise rendezvous + else: + completion_queue = cygrpc.CompletionQueue() + call = self._channel.create_call(None, 0, completion_queue, + self._method, None, + deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + call_error = call.start_client_batch( + cygrpc.Operations(operations), None) + _check_call_error(call_error, metadata) + _handle_event(completion_queue.poll(), state, + self._response_deserializer) + return state, deadline + + def __call__(self, request, timeout=None, metadata=None, credentials=None): + state, deadline, = self._blocking(request, timeout, metadata, + credentials) + return _end_unary_response_blocking(state, False, deadline) + + def with_call(self, request, timeout=None, metadata=None, credentials=None): + state, deadline, = self._blocking(request, timeout, metadata, + credentials) + return _end_unary_response_blocking(state, True, deadline) + + def future(self, request, timeout=None, metadata=None, credentials=None): + state, operations, deadline, deadline_timespec, rendezvous = self._prepare( + request, timeout, metadata) + if rendezvous: + return rendezvous + else: + call, drive_call = self._managed_call(None, 0, self._method, None, + deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + event_handler = _event_handler(state, call, + self._response_deserializer) + with state.condition: + call_error = call.start_client_batch( + cygrpc.Operations(operations), event_handler) + if call_error != cygrpc.CallError.ok: + _call_error_set_RPCstate(state, call_error, metadata) + return _Rendezvous(state, None, None, deadline) + drive_call() + return _Rendezvous(state, call, self._response_deserializer, + deadline) class _UnaryStreamMultiCallable(grpc.UnaryStreamMultiCallable): - def __init__( - self, channel, managed_call, method, request_serializer, - response_deserializer): - self._channel = channel - self._managed_call = managed_call - self._method = method - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__(self, request, timeout=None, metadata=None, credentials=None): - deadline, deadline_timespec, serialized_request, rendezvous = ( - _start_unary_request(request, timeout, self._request_serializer)) - if serialized_request is None: - raise rendezvous - else: - state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None) - call, drive_call = self._managed_call( - None, 0, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - event_handler = _event_handler(state, call, self._response_deserializer) - with state.condition: - call.start_client_batch( - cygrpc.Operations( - (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), - event_handler) - operations = ( - cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), - cygrpc.operation_send_message(serialized_request, _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - call_error = call.start_client_batch(cygrpc.Operations(operations), - event_handler) - if call_error != cygrpc.CallError.ok: - _call_error_set_RPCstate(state, call_error, metadata) - return _Rendezvous(state, None, None, deadline) - drive_call() - return _Rendezvous(state, call, self._response_deserializer, deadline) + def __init__(self, channel, managed_call, method, request_serializer, + response_deserializer): + self._channel = channel + self._managed_call = managed_call + self._method = method + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, request, timeout=None, metadata=None, credentials=None): + deadline, deadline_timespec, serialized_request, rendezvous = ( + _start_unary_request(request, timeout, self._request_serializer)) + if serialized_request is None: + raise rendezvous + else: + state = _RPCState(_UNARY_STREAM_INITIAL_DUE, None, None, None, None) + call, drive_call = self._managed_call(None, 0, self._method, None, + deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + event_handler = _event_handler(state, call, + self._response_deserializer) + with state.condition: + call.start_client_batch( + cygrpc.Operations(( + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + )), event_handler) + operations = ( + cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), + cygrpc.operation_send_message(serialized_request, + _EMPTY_FLAGS), + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + call_error = call.start_client_batch( + cygrpc.Operations(operations), event_handler) + if call_error != cygrpc.CallError.ok: + _call_error_set_RPCstate(state, call_error, metadata) + return _Rendezvous(state, None, None, deadline) + drive_call() + return _Rendezvous(state, call, self._response_deserializer, + deadline) class _StreamUnaryMultiCallable(grpc.StreamUnaryMultiCallable): - def __init__( - self, channel, managed_call, method, request_serializer, - response_deserializer): - self._channel = channel - self._managed_call = managed_call - self._method = method - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def _blocking(self, request_iterator, timeout, metadata, credentials): - deadline, deadline_timespec = _deadline(timeout) - state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) - completion_queue = cygrpc.CompletionQueue() - call = self._channel.create_call( - None, 0, completion_queue, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - with state.condition: - call.start_client_batch( - cygrpc.Operations( - (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), - None) - operations = ( - cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - call_error = call.start_client_batch(cygrpc.Operations(operations), None) - _check_call_error(call_error, metadata) - _consume_request_iterator( - request_iterator, state, call, self._request_serializer) - while True: - event = completion_queue.poll() - with state.condition: - _handle_event(event, state, self._response_deserializer) - state.condition.notify_all() - if not state.due: - break - return state, deadline - - def __call__( - self, request_iterator, timeout=None, metadata=None, credentials=None): - state, deadline, = self._blocking( - request_iterator, timeout, metadata, credentials) - return _end_unary_response_blocking(state, False, deadline) - - def with_call( - self, request_iterator, timeout=None, metadata=None, credentials=None): - state, deadline, = self._blocking( - request_iterator, timeout, metadata, credentials) - return _end_unary_response_blocking(state, True, deadline) - - def future( - self, request_iterator, timeout=None, metadata=None, credentials=None): - deadline, deadline_timespec = _deadline(timeout) - state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) - call, drive_call = self._managed_call( - None, 0, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - event_handler = _event_handler(state, call, self._response_deserializer) - with state.condition: - call.start_client_batch( - cygrpc.Operations( - (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), - event_handler) - operations = ( - cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - call_error = call.start_client_batch(cygrpc.Operations(operations), - event_handler) - if call_error != cygrpc.CallError.ok: - _call_error_set_RPCstate(state, call_error, metadata) - return _Rendezvous(state, None, None, deadline) - drive_call() - _consume_request_iterator( - request_iterator, state, call, self._request_serializer) - return _Rendezvous(state, call, self._response_deserializer, deadline) + def __init__(self, channel, managed_call, method, request_serializer, + response_deserializer): + self._channel = channel + self._managed_call = managed_call + self._method = method + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def _blocking(self, request_iterator, timeout, metadata, credentials): + deadline, deadline_timespec = _deadline(timeout) + state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) + completion_queue = cygrpc.CompletionQueue() + call = self._channel.create_call(None, 0, completion_queue, + self._method, None, deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + with state.condition: + call.start_client_batch( + cygrpc.Operations( + (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), + None) + operations = ( + cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + call_error = call.start_client_batch( + cygrpc.Operations(operations), None) + _check_call_error(call_error, metadata) + _consume_request_iterator(request_iterator, state, call, + self._request_serializer) + while True: + event = completion_queue.poll() + with state.condition: + _handle_event(event, state, self._response_deserializer) + state.condition.notify_all() + if not state.due: + break + return state, deadline + + def __call__(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + state, deadline, = self._blocking(request_iterator, timeout, metadata, + credentials) + return _end_unary_response_blocking(state, False, deadline) + + def with_call(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + state, deadline, = self._blocking(request_iterator, timeout, metadata, + credentials) + return _end_unary_response_blocking(state, True, deadline) + + def future(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + deadline, deadline_timespec = _deadline(timeout) + state = _RPCState(_STREAM_UNARY_INITIAL_DUE, None, None, None, None) + call, drive_call = self._managed_call(None, 0, self._method, None, + deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + event_handler = _event_handler(state, call, self._response_deserializer) + with state.condition: + call.start_client_batch( + cygrpc.Operations( + (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), + event_handler) + operations = ( + cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + call_error = call.start_client_batch( + cygrpc.Operations(operations), event_handler) + if call_error != cygrpc.CallError.ok: + _call_error_set_RPCstate(state, call_error, metadata) + return _Rendezvous(state, None, None, deadline) + drive_call() + _consume_request_iterator(request_iterator, state, call, + self._request_serializer) + return _Rendezvous(state, call, self._response_deserializer, deadline) class _StreamStreamMultiCallable(grpc.StreamStreamMultiCallable): - def __init__( - self, channel, managed_call, method, request_serializer, - response_deserializer): - self._channel = channel - self._managed_call = managed_call - self._method = method - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__( - self, request_iterator, timeout=None, metadata=None, credentials=None): - deadline, deadline_timespec = _deadline(timeout) - state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None) - call, drive_call = self._managed_call( - None, 0, self._method, None, deadline_timespec) - if credentials is not None: - call.set_credentials(credentials._credentials) - event_handler = _event_handler(state, call, self._response_deserializer) - with state.condition: - call.start_client_batch( - cygrpc.Operations( - (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), - event_handler) - operations = ( - cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - call_error = call.start_client_batch(cygrpc.Operations(operations), - event_handler) - if call_error != cygrpc.CallError.ok: - _call_error_set_RPCstate(state, call_error, metadata) - return _Rendezvous(state, None, None, deadline) - drive_call() - _consume_request_iterator( - request_iterator, state, call, self._request_serializer) - return _Rendezvous(state, call, self._response_deserializer, deadline) + def __init__(self, channel, managed_call, method, request_serializer, + response_deserializer): + self._channel = channel + self._managed_call = managed_call + self._method = method + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, + request_iterator, + timeout=None, + metadata=None, + credentials=None): + deadline, deadline_timespec = _deadline(timeout) + state = _RPCState(_STREAM_STREAM_INITIAL_DUE, None, None, None, None) + call, drive_call = self._managed_call(None, 0, self._method, None, + deadline_timespec) + if credentials is not None: + call.set_credentials(credentials._credentials) + event_handler = _event_handler(state, call, self._response_deserializer) + with state.condition: + call.start_client_batch( + cygrpc.Operations( + (cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS),)), + event_handler) + operations = ( + cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(metadata), _EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + call_error = call.start_client_batch( + cygrpc.Operations(operations), event_handler) + if call_error != cygrpc.CallError.ok: + _call_error_set_RPCstate(state, call_error, metadata) + return _Rendezvous(state, None, None, deadline) + drive_call() + _consume_request_iterator(request_iterator, state, call, + self._request_serializer) + return _Rendezvous(state, call, self._response_deserializer, deadline) class _ChannelCallState(object): - def __init__(self, channel): - self.lock = threading.Lock() - self.channel = channel - self.completion_queue = cygrpc.CompletionQueue() - self.managed_calls = None + def __init__(self, channel): + self.lock = threading.Lock() + self.channel = channel + self.completion_queue = cygrpc.CompletionQueue() + self.managed_calls = None def _run_channel_spin_thread(state): - def channel_spin(): - while True: - event = state.completion_queue.poll() - completed_call = event.tag(event) - if completed_call is not None: - with state.lock: - state.managed_calls.remove(completed_call) - if not state.managed_calls: - state.managed_calls = None - return - def stop_channel_spin(timeout): - with state.lock: - if state.managed_calls is not None: - for call in state.managed_calls: - call.cancel() + def channel_spin(): + while True: + event = state.completion_queue.poll() + completed_call = event.tag(event) + if completed_call is not None: + with state.lock: + state.managed_calls.remove(completed_call) + if not state.managed_calls: + state.managed_calls = None + return + + def stop_channel_spin(timeout): + with state.lock: + if state.managed_calls is not None: + for call in state.managed_calls: + call.cancel() - channel_spin_thread = _common.CleanupThread( - stop_channel_spin, target=channel_spin) - channel_spin_thread.start() + channel_spin_thread = _common.CleanupThread( + stop_channel_spin, target=channel_spin) + channel_spin_thread.start() def _channel_managed_call_management(state): - def create(parent, flags, method, host, deadline): - """Creates a managed cygrpc.Call and a function to call to drive it. + + def create(parent, flags, method, host, deadline): + """Creates a managed cygrpc.Call and a function to call to drive it. If operations are successfully added to the returned cygrpc.Call, the returned function must be called. If operations are not successfully added @@ -754,193 +771,213 @@ def _channel_managed_call_management(state): A cygrpc.Call with which to conduct an RPC and a function to call if operations are successfully started on the call. """ - call = state.channel.create_call( - parent, flags, state.completion_queue, method, host, deadline) - - def drive(): - with state.lock: - if state.managed_calls is None: - state.managed_calls = set((call,)) - _run_channel_spin_thread(state) - else: - state.managed_calls.add(call) + call = state.channel.create_call(parent, flags, state.completion_queue, + method, host, deadline) + + def drive(): + with state.lock: + if state.managed_calls is None: + state.managed_calls = set((call,)) + _run_channel_spin_thread(state) + else: + state.managed_calls.add(call) + + return call, drive - return call, drive - return create + return create class _ChannelConnectivityState(object): - def __init__(self, channel): - self.lock = threading.Lock() - self.channel = channel - self.polling = False - self.connectivity = None - self.try_to_connect = False - self.callbacks_and_connectivities = [] - self.delivering = False + def __init__(self, channel): + self.lock = threading.Lock() + self.channel = channel + self.polling = False + self.connectivity = None + self.try_to_connect = False + self.callbacks_and_connectivities = [] + self.delivering = False def _deliveries(state): - callbacks_needing_update = [] - for callback_and_connectivity in state.callbacks_and_connectivities: - callback, callback_connectivity, = callback_and_connectivity - if callback_connectivity is not state.connectivity: - callbacks_needing_update.append(callback) - callback_and_connectivity[1] = state.connectivity - return callbacks_needing_update + callbacks_needing_update = [] + for callback_and_connectivity in state.callbacks_and_connectivities: + callback, callback_connectivity, = callback_and_connectivity + if callback_connectivity is not state.connectivity: + callbacks_needing_update.append(callback) + callback_and_connectivity[1] = state.connectivity + return callbacks_needing_update def _deliver(state, initial_connectivity, initial_callbacks): - connectivity = initial_connectivity - callbacks = initial_callbacks - while True: - for callback in callbacks: - callable_util.call_logging_exceptions( - callback, _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE, - connectivity) - with state.lock: - callbacks = _deliveries(state) - if callbacks: - connectivity = state.connectivity - else: - state.delivering = False - return + connectivity = initial_connectivity + callbacks = initial_callbacks + while True: + for callback in callbacks: + callable_util.call_logging_exceptions( + callback, _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE, + connectivity) + with state.lock: + callbacks = _deliveries(state) + if callbacks: + connectivity = state.connectivity + else: + state.delivering = False + return def _spawn_delivery(state, callbacks): - delivering_thread = threading.Thread( - target=_deliver, args=(state, state.connectivity, callbacks,)) - delivering_thread.start() - state.delivering = True + delivering_thread = threading.Thread( + target=_deliver, args=( + state, + state.connectivity, + callbacks,)) + delivering_thread.start() + state.delivering = True # NOTE(https://github.com/grpc/grpc/issues/3064): We'd rather not poll. def _poll_connectivity(state, channel, initial_try_to_connect): - try_to_connect = initial_try_to_connect - connectivity = channel.check_connectivity_state(try_to_connect) - with state.lock: - state.connectivity = ( - _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ - connectivity]) - callbacks = tuple( - callback for callback, unused_but_known_to_be_none_connectivity - in state.callbacks_and_connectivities) - for callback_and_connectivity in state.callbacks_and_connectivities: - callback_and_connectivity[1] = state.connectivity - if callbacks: - _spawn_delivery(state, callbacks) - completion_queue = cygrpc.CompletionQueue() - while True: - channel.watch_connectivity_state( - connectivity, cygrpc.Timespec(time.time() + 0.2), - completion_queue, None) - event = completion_queue.poll() + try_to_connect = initial_try_to_connect + connectivity = channel.check_connectivity_state(try_to_connect) with state.lock: - if not state.callbacks_and_connectivities and not state.try_to_connect: - state.polling = False - state.connectivity = None - break - try_to_connect = state.try_to_connect - state.try_to_connect = False - if event.success or try_to_connect: - connectivity = channel.check_connectivity_state(try_to_connect) - with state.lock: state.connectivity = ( _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ connectivity]) - if not state.delivering: - callbacks = _deliveries(state) - if callbacks: + callbacks = tuple(callback + for callback, unused_but_known_to_be_none_connectivity + in state.callbacks_and_connectivities) + for callback_and_connectivity in state.callbacks_and_connectivities: + callback_and_connectivity[1] = state.connectivity + if callbacks: _spawn_delivery(state, callbacks) + completion_queue = cygrpc.CompletionQueue() + while True: + channel.watch_connectivity_state(connectivity, + cygrpc.Timespec(time.time() + 0.2), + completion_queue, None) + event = completion_queue.poll() + with state.lock: + if not state.callbacks_and_connectivities and not state.try_to_connect: + state.polling = False + state.connectivity = None + break + try_to_connect = state.try_to_connect + state.try_to_connect = False + if event.success or try_to_connect: + connectivity = channel.check_connectivity_state(try_to_connect) + with state.lock: + state.connectivity = ( + _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ + connectivity]) + if not state.delivering: + callbacks = _deliveries(state) + if callbacks: + _spawn_delivery(state, callbacks) def _moot(state): - with state.lock: - del state.callbacks_and_connectivities[:] + with state.lock: + del state.callbacks_and_connectivities[:] def _subscribe(state, callback, try_to_connect): - with state.lock: - if not state.callbacks_and_connectivities and not state.polling: - def cancel_all_subscriptions(timeout): - _moot(state) - polling_thread = _common.CleanupThread( - cancel_all_subscriptions, target=_poll_connectivity, - args=(state, state.channel, bool(try_to_connect))) - polling_thread.start() - state.polling = True - state.callbacks_and_connectivities.append([callback, None]) - elif not state.delivering and state.connectivity is not None: - _spawn_delivery(state, (callback,)) - state.try_to_connect |= bool(try_to_connect) - state.callbacks_and_connectivities.append( - [callback, state.connectivity]) - else: - state.try_to_connect |= bool(try_to_connect) - state.callbacks_and_connectivities.append([callback, None]) + with state.lock: + if not state.callbacks_and_connectivities and not state.polling: + + def cancel_all_subscriptions(timeout): + _moot(state) + + polling_thread = _common.CleanupThread( + cancel_all_subscriptions, + target=_poll_connectivity, + args=(state, state.channel, bool(try_to_connect))) + polling_thread.start() + state.polling = True + state.callbacks_and_connectivities.append([callback, None]) + elif not state.delivering and state.connectivity is not None: + _spawn_delivery(state, (callback,)) + state.try_to_connect |= bool(try_to_connect) + state.callbacks_and_connectivities.append( + [callback, state.connectivity]) + else: + state.try_to_connect |= bool(try_to_connect) + state.callbacks_and_connectivities.append([callback, None]) def _unsubscribe(state, callback): - with state.lock: - for index, (subscribed_callback, unused_connectivity) in enumerate( - state.callbacks_and_connectivities): - if callback == subscribed_callback: - state.callbacks_and_connectivities.pop(index) - break + with state.lock: + for index, (subscribed_callback, unused_connectivity + ) in enumerate(state.callbacks_and_connectivities): + if callback == subscribed_callback: + state.callbacks_and_connectivities.pop(index) + break def _options(options): - return list(options) + [ - (cygrpc.ChannelArgKey.primary_user_agent_string, _USER_AGENT)] + return list(options) + [ + (cygrpc.ChannelArgKey.primary_user_agent_string, _USER_AGENT) + ] class Channel(grpc.Channel): - """A cygrpc.Channel-backed implementation of grpc.Channel.""" + """A cygrpc.Channel-backed implementation of grpc.Channel.""" - def __init__(self, target, options, credentials): - """Constructor. + def __init__(self, target, options, credentials): + """Constructor. Args: target: The target to which to connect. options: Configuration options for the channel. credentials: A cygrpc.ChannelCredentials or None. """ - self._channel = cygrpc.Channel( - _common.encode(target), _common.channel_args(_options(options)), - credentials) - self._call_state = _ChannelCallState(self._channel) - self._connectivity_state = _ChannelConnectivityState(self._channel) - - def subscribe(self, callback, try_to_connect=None): - _subscribe(self._connectivity_state, callback, try_to_connect) - - def unsubscribe(self, callback): - _unsubscribe(self._connectivity_state, callback) - - def unary_unary( - self, method, request_serializer=None, response_deserializer=None): - return _UnaryUnaryMultiCallable( - self._channel, _channel_managed_call_management(self._call_state), - _common.encode(method), request_serializer, response_deserializer) - - def unary_stream( - self, method, request_serializer=None, response_deserializer=None): - return _UnaryStreamMultiCallable( - self._channel, _channel_managed_call_management(self._call_state), - _common.encode(method), request_serializer, response_deserializer) - - def stream_unary( - self, method, request_serializer=None, response_deserializer=None): - return _StreamUnaryMultiCallable( - self._channel, _channel_managed_call_management(self._call_state), - _common.encode(method), request_serializer, response_deserializer) - - def stream_stream( - self, method, request_serializer=None, response_deserializer=None): - return _StreamStreamMultiCallable( - self._channel, _channel_managed_call_management(self._call_state), - _common.encode(method), request_serializer, response_deserializer) - - def __del__(self): - _moot(self._connectivity_state) + self._channel = cygrpc.Channel( + _common.encode(target), + _common.channel_args(_options(options)), credentials) + self._call_state = _ChannelCallState(self._channel) + self._connectivity_state = _ChannelConnectivityState(self._channel) + + def subscribe(self, callback, try_to_connect=None): + _subscribe(self._connectivity_state, callback, try_to_connect) + + def unsubscribe(self, callback): + _unsubscribe(self._connectivity_state, callback) + + def unary_unary(self, + method, + request_serializer=None, + response_deserializer=None): + return _UnaryUnaryMultiCallable( + self._channel, + _channel_managed_call_management(self._call_state), + _common.encode(method), request_serializer, response_deserializer) + + def unary_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return _UnaryStreamMultiCallable( + self._channel, + _channel_managed_call_management(self._call_state), + _common.encode(method), request_serializer, response_deserializer) + + def stream_unary(self, + method, + request_serializer=None, + response_deserializer=None): + return _StreamUnaryMultiCallable( + self._channel, + _channel_managed_call_management(self._call_state), + _common.encode(method), request_serializer, response_deserializer) + + def stream_stream(self, + method, + request_serializer=None, + response_deserializer=None): + return _StreamStreamMultiCallable( + self._channel, + _channel_managed_call_management(self._call_state), + _common.encode(method), request_serializer, response_deserializer) + + def __del__(self): + _moot(self._connectivity_state) diff --git a/src/python/grpcio/grpc/_common.py b/src/python/grpcio/grpc/_common.py index cc0984c8c63..7ef2571379b 100644 --- a/src/python/grpcio/grpc/_common.py +++ b/src/python/grpcio/grpc/_common.py @@ -26,7 +26,6 @@ # 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. - """Shared implementation.""" import logging @@ -45,9 +44,8 @@ CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY = { cygrpc.ConnectivityState.connecting: grpc.ChannelConnectivity.CONNECTING, cygrpc.ConnectivityState.ready: grpc.ChannelConnectivity.READY, cygrpc.ConnectivityState.transient_failure: - grpc.ChannelConnectivity.TRANSIENT_FAILURE, - cygrpc.ConnectivityState.shutdown: - grpc.ChannelConnectivity.SHUTDOWN, + grpc.ChannelConnectivity.TRANSIENT_FAILURE, + cygrpc.ConnectivityState.shutdown: grpc.ChannelConnectivity.SHUTDOWN, } CYGRPC_STATUS_CODE_TO_STATUS_CODE = { @@ -77,83 +75,88 @@ STATUS_CODE_TO_CYGRPC_STATUS_CODE = { def encode(s): - if isinstance(s, bytes): - return s - else: - return s.encode('ascii') + if isinstance(s, bytes): + return s + else: + return s.encode('ascii') def decode(b): - if isinstance(b, str): - return b - else: - try: - return b.decode('utf8') - except UnicodeDecodeError: - logging.exception('Invalid encoding on {}'.format(b)) - return b.decode('latin1') + if isinstance(b, str): + return b + else: + try: + return b.decode('utf8') + except UnicodeDecodeError: + logging.exception('Invalid encoding on {}'.format(b)) + return b.decode('latin1') def channel_args(options): - channel_args = [] - for key, value in options: - if isinstance(value, six.string_types): - channel_args.append(cygrpc.ChannelArg(encode(key), encode(value))) - else: - channel_args.append(cygrpc.ChannelArg(encode(key), value)) - return cygrpc.ChannelArgs(channel_args) + channel_args = [] + for key, value in options: + if isinstance(value, six.string_types): + channel_args.append(cygrpc.ChannelArg(encode(key), encode(value))) + else: + channel_args.append(cygrpc.ChannelArg(encode(key), value)) + return cygrpc.ChannelArgs(channel_args) def cygrpc_metadata(application_metadata): - return _EMPTY_METADATA if application_metadata is None else cygrpc.Metadata( - cygrpc.Metadatum(encode(key), encode(value)) - for key, value in application_metadata) + return _EMPTY_METADATA if application_metadata is None else cygrpc.Metadata( + cygrpc.Metadatum(encode(key), encode(value)) + for key, value in application_metadata) def application_metadata(cygrpc_metadata): - if cygrpc_metadata is None: - return () - else: - return tuple( - (decode(key), value if key[-4:] == b'-bin' else decode(value)) - for key, value in cygrpc_metadata) + if cygrpc_metadata is None: + return () + else: + return tuple((decode(key), value + if key[-4:] == b'-bin' else decode(value)) + for key, value in cygrpc_metadata) def _transform(message, transformer, exception_message): - if transformer is None: - return message - else: - try: - return transformer(message) - except Exception: # pylint: disable=broad-except - logging.exception(exception_message) - return None + if transformer is None: + return message + else: + try: + return transformer(message) + except Exception: # pylint: disable=broad-except + logging.exception(exception_message) + return None def serialize(message, serializer): - return _transform(message, serializer, 'Exception serializing message!') + return _transform(message, serializer, 'Exception serializing message!') def deserialize(serialized_message, deserializer): - return _transform(serialized_message, deserializer, - 'Exception deserializing message!') + return _transform(serialized_message, deserializer, + 'Exception deserializing message!') def fully_qualified_method(group, method): - return '/{}/{}'.format(group, method) + return '/{}/{}'.format(group, method) class CleanupThread(threading.Thread): - """A threading.Thread subclass supporting custom behavior on join(). + """A threading.Thread subclass supporting custom behavior on join(). On Python Interpreter exit, Python will attempt to join outstanding threads prior to garbage collection. We may need to do additional cleanup, and we accomplish this by overriding the join() method. """ - def __init__(self, behavior, group=None, target=None, name=None, - args=(), kwargs={}): - """Constructor. + def __init__(self, + behavior, + group=None, + target=None, + name=None, + args=(), + kwargs={}): + """Constructor. Args: behavior (function): Function called on join() with a single @@ -169,15 +172,15 @@ class CleanupThread(threading.Thread): kwargs (dict[str,object]): A dictionary of keyword arguments to pass to `target`. """ - super(CleanupThread, self).__init__(group=group, target=target, - name=name, args=args, kwargs=kwargs) - self._behavior = behavior - - def join(self, timeout=None): - start_time = time.time() - self._behavior(timeout) - end_time = time.time() - if timeout is not None: - timeout -= end_time - start_time - timeout = max(timeout, 0) - super(CleanupThread, self).join(timeout) + super(CleanupThread, self).__init__( + group=group, target=target, name=name, args=args, kwargs=kwargs) + self._behavior = behavior + + def join(self, timeout=None): + start_time = time.time() + self._behavior(timeout) + end_time = time.time() + if timeout is not None: + timeout -= end_time - start_time + timeout = max(timeout, 0) + super(CleanupThread, self).join(timeout) diff --git a/src/python/grpcio/grpc/_credential_composition.py b/src/python/grpcio/grpc/_credential_composition.py index 9cb5508e27c..bdf017baa56 100644 --- a/src/python/grpcio/grpc/_credential_composition.py +++ b/src/python/grpcio/grpc/_credential_composition.py @@ -31,18 +31,18 @@ from grpc._cython import cygrpc def _call(call_credentialses): - call_credentials_iterator = iter(call_credentialses) - composition = next(call_credentials_iterator) - for additional_call_credentials in call_credentials_iterator: - composition = cygrpc.call_credentials_composite( - composition, additional_call_credentials) - return composition + call_credentials_iterator = iter(call_credentialses) + composition = next(call_credentials_iterator) + for additional_call_credentials in call_credentials_iterator: + composition = cygrpc.call_credentials_composite( + composition, additional_call_credentials) + return composition def call(call_credentialses): - return _call(call_credentialses) + return _call(call_credentialses) def channel(channel_credentials, call_credentialses): - return cygrpc.channel_credentials_composite( - channel_credentials, _call(call_credentialses)) + return cygrpc.channel_credentials_composite(channel_credentials, + _call(call_credentialses)) diff --git a/src/python/grpcio/grpc/_plugin_wrapping.py b/src/python/grpcio/grpc/_plugin_wrapping.py index 7cb5218c22b..bb9a42f3ffe 100644 --- a/src/python/grpcio/grpc/_plugin_wrapping.py +++ b/src/python/grpcio/grpc/_plugin_wrapping.py @@ -36,82 +36,82 @@ from grpc._cython import cygrpc class AuthMetadataContext( - collections.namedtuple( - 'AuthMetadataContext', ('service_url', 'method_name',)), - grpc.AuthMetadataContext): - pass + collections.namedtuple('AuthMetadataContext', ( + 'service_url', + 'method_name',)), grpc.AuthMetadataContext): + pass class AuthMetadataPluginCallback(grpc.AuthMetadataContext): - def __init__(self, callback): - self._callback = callback + def __init__(self, callback): + self._callback = callback - def __call__(self, metadata, error): - self._callback(metadata, error) + def __call__(self, metadata, error): + self._callback(metadata, error) class _WrappedCygrpcCallback(object): - def __init__(self, cygrpc_callback): - self.is_called = False - self.error = None - self.is_called_lock = threading.Lock() - self.cygrpc_callback = cygrpc_callback - - def _invoke_failure(self, error): - # TODO(atash) translate different Exception superclasses into different - # status codes. - self.cygrpc_callback( - _common.EMPTY_METADATA, cygrpc.StatusCode.internal, - _common.encode(str(error))) - - def _invoke_success(self, metadata): - try: - cygrpc_metadata = _common.cygrpc_metadata(metadata) - except Exception as error: - self._invoke_failure(error) - return - self.cygrpc_callback(cygrpc_metadata, cygrpc.StatusCode.ok, b'') - - def __call__(self, metadata, error): - with self.is_called_lock: - if self.is_called: - raise RuntimeError('callback should only ever be invoked once') - if self.error: - self._invoke_failure(self.error) - return - self.is_called = True - if error is None: - self._invoke_success(metadata) - else: - self._invoke_failure(error) - - def notify_failure(self, error): - with self.is_called_lock: - if not self.is_called: - self.error = error + def __init__(self, cygrpc_callback): + self.is_called = False + self.error = None + self.is_called_lock = threading.Lock() + self.cygrpc_callback = cygrpc_callback + + def _invoke_failure(self, error): + # TODO(atash) translate different Exception superclasses into different + # status codes. + self.cygrpc_callback(_common.EMPTY_METADATA, cygrpc.StatusCode.internal, + _common.encode(str(error))) + + def _invoke_success(self, metadata): + try: + cygrpc_metadata = _common.cygrpc_metadata(metadata) + except Exception as error: + self._invoke_failure(error) + return + self.cygrpc_callback(cygrpc_metadata, cygrpc.StatusCode.ok, b'') + + def __call__(self, metadata, error): + with self.is_called_lock: + if self.is_called: + raise RuntimeError('callback should only ever be invoked once') + if self.error: + self._invoke_failure(self.error) + return + self.is_called = True + if error is None: + self._invoke_success(metadata) + else: + self._invoke_failure(error) + + def notify_failure(self, error): + with self.is_called_lock: + if not self.is_called: + self.error = error class _WrappedPlugin(object): - def __init__(self, plugin): - self.plugin = plugin + def __init__(self, plugin): + self.plugin = plugin - def __call__(self, context, cygrpc_callback): - wrapped_cygrpc_callback = _WrappedCygrpcCallback(cygrpc_callback) - wrapped_context = AuthMetadataContext( - _common.decode(context.service_url), _common.decode(context.method_name)) - try: - self.plugin( - wrapped_context, AuthMetadataPluginCallback(wrapped_cygrpc_callback)) - except Exception as error: - wrapped_cygrpc_callback.notify_failure(error) - raise + def __call__(self, context, cygrpc_callback): + wrapped_cygrpc_callback = _WrappedCygrpcCallback(cygrpc_callback) + wrapped_context = AuthMetadataContext( + _common.decode(context.service_url), + _common.decode(context.method_name)) + try: + self.plugin(wrapped_context, + AuthMetadataPluginCallback(wrapped_cygrpc_callback)) + except Exception as error: + wrapped_cygrpc_callback.notify_failure(error) + raise def call_credentials_metadata_plugin(plugin, name): - """ + """ Args: plugin: A callable accepting a grpc.AuthMetadataContext object and a callback (itself accepting a list of metadata key/value @@ -119,5 +119,6 @@ def call_credentials_metadata_plugin(plugin, name): called, but need not be called in plugin's invocation. plugin's invocation must be non-blocking. """ - return cygrpc.call_credentials_metadata_plugin( - cygrpc.CredentialsMetadataPlugin(_WrappedPlugin(plugin), _common.encode(name))) + return cygrpc.call_credentials_metadata_plugin( + cygrpc.CredentialsMetadataPlugin( + _WrappedPlugin(plugin), _common.encode(name))) diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index 5223712dfa7..158cdf8b0e6 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -26,7 +26,6 @@ # 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. - """Service-side implementation of gRPC Python.""" import collections @@ -64,692 +63,715 @@ _UNEXPECTED_EXIT_SERVER_GRACE = 1.0 def _serialized_request(request_event): - return request_event.batch_operations[0].received_message.bytes() + return request_event.batch_operations[0].received_message.bytes() def _application_code(code): - cygrpc_code = _common.STATUS_CODE_TO_CYGRPC_STATUS_CODE.get(code) - return cygrpc.StatusCode.unknown if cygrpc_code is None else cygrpc_code + cygrpc_code = _common.STATUS_CODE_TO_CYGRPC_STATUS_CODE.get(code) + return cygrpc.StatusCode.unknown if cygrpc_code is None else cygrpc_code def _completion_code(state): - if state.code is None: - return cygrpc.StatusCode.ok - else: - return _application_code(state.code) + if state.code is None: + return cygrpc.StatusCode.ok + else: + return _application_code(state.code) def _abortion_code(state, code): - if state.code is None: - return code - else: - return _application_code(state.code) + if state.code is None: + return code + else: + return _application_code(state.code) def _details(state): - return b'' if state.details is None else state.details + return b'' if state.details is None else state.details class _HandlerCallDetails( - collections.namedtuple( - '_HandlerCallDetails', ('method', 'invocation_metadata',)), - grpc.HandlerCallDetails): - pass + collections.namedtuple('_HandlerCallDetails', ( + 'method', + 'invocation_metadata',)), grpc.HandlerCallDetails): + pass class _RPCState(object): - def __init__(self): - self.condition = threading.Condition() - self.due = set() - self.request = None - self.client = _OPEN - self.initial_metadata_allowed = True - self.disable_next_compression = False - self.trailing_metadata = None - self.code = None - self.details = None - self.statused = False - self.rpc_errors = [] - self.callbacks = [] + def __init__(self): + self.condition = threading.Condition() + self.due = set() + self.request = None + self.client = _OPEN + self.initial_metadata_allowed = True + self.disable_next_compression = False + self.trailing_metadata = None + self.code = None + self.details = None + self.statused = False + self.rpc_errors = [] + self.callbacks = [] def _raise_rpc_error(state): - rpc_error = grpc.RpcError() - state.rpc_errors.append(rpc_error) - raise rpc_error + rpc_error = grpc.RpcError() + state.rpc_errors.append(rpc_error) + raise rpc_error def _possibly_finish_call(state, token): - state.due.remove(token) - if (state.client is _CANCELLED or state.statused) and not state.due: - callbacks = state.callbacks - state.callbacks = None - return state, callbacks - else: - return None, () + state.due.remove(token) + if (state.client is _CANCELLED or state.statused) and not state.due: + callbacks = state.callbacks + state.callbacks = None + return state, callbacks + else: + return None, () def _send_status_from_server(state, token): - def send_status_from_server(unused_send_status_from_server_event): - with state.condition: - return _possibly_finish_call(state, token) - return send_status_from_server + + def send_status_from_server(unused_send_status_from_server_event): + with state.condition: + return _possibly_finish_call(state, token) + + return send_status_from_server def _abort(state, call, code, details): - if state.client is not _CANCELLED: - effective_code = _abortion_code(state, code) - effective_details = details if state.details is None else state.details - if state.initial_metadata_allowed: - operations = ( - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - _common.cygrpc_metadata(state.trailing_metadata), effective_code, - effective_details, _EMPTY_FLAGS), - ) - token = _SEND_INITIAL_METADATA_AND_SEND_STATUS_FROM_SERVER_TOKEN - else: - operations = ( - cygrpc.operation_send_status_from_server( - _common.cygrpc_metadata(state.trailing_metadata), effective_code, - effective_details, _EMPTY_FLAGS), - ) - token = _SEND_STATUS_FROM_SERVER_TOKEN - call.start_server_batch( - cygrpc.Operations(operations), - _send_status_from_server(state, token)) - state.statused = True - state.due.add(token) + if state.client is not _CANCELLED: + effective_code = _abortion_code(state, code) + effective_details = details if state.details is None else state.details + if state.initial_metadata_allowed: + operations = ( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + _common.cygrpc_metadata(state.trailing_metadata), + effective_code, effective_details, _EMPTY_FLAGS),) + token = _SEND_INITIAL_METADATA_AND_SEND_STATUS_FROM_SERVER_TOKEN + else: + operations = (cygrpc.operation_send_status_from_server( + _common.cygrpc_metadata(state.trailing_metadata), + effective_code, effective_details, _EMPTY_FLAGS),) + token = _SEND_STATUS_FROM_SERVER_TOKEN + call.start_server_batch( + cygrpc.Operations(operations), + _send_status_from_server(state, token)) + state.statused = True + state.due.add(token) def _receive_close_on_server(state): - def receive_close_on_server(receive_close_on_server_event): - with state.condition: - if receive_close_on_server_event.batch_operations[0].received_cancelled: - state.client = _CANCELLED - elif state.client is _OPEN: - state.client = _CLOSED - state.condition.notify_all() - return _possibly_finish_call(state, _RECEIVE_CLOSE_ON_SERVER_TOKEN) - return receive_close_on_server + + def receive_close_on_server(receive_close_on_server_event): + with state.condition: + if receive_close_on_server_event.batch_operations[ + 0].received_cancelled: + state.client = _CANCELLED + elif state.client is _OPEN: + state.client = _CLOSED + state.condition.notify_all() + return _possibly_finish_call(state, _RECEIVE_CLOSE_ON_SERVER_TOKEN) + + return receive_close_on_server def _receive_message(state, call, request_deserializer): - def receive_message(receive_message_event): - serialized_request = _serialized_request(receive_message_event) - if serialized_request is None: - with state.condition: - if state.client is _OPEN: - state.client = _CLOSED - state.condition.notify_all() - return _possibly_finish_call(state, _RECEIVE_MESSAGE_TOKEN) - else: - request = _common.deserialize(serialized_request, request_deserializer) - with state.condition: - if request is None: - _abort( - state, call, cygrpc.StatusCode.internal, - b'Exception deserializing request!') + + def receive_message(receive_message_event): + serialized_request = _serialized_request(receive_message_event) + if serialized_request is None: + with state.condition: + if state.client is _OPEN: + state.client = _CLOSED + state.condition.notify_all() + return _possibly_finish_call(state, _RECEIVE_MESSAGE_TOKEN) else: - state.request = request - state.condition.notify_all() - return _possibly_finish_call(state, _RECEIVE_MESSAGE_TOKEN) - return receive_message + request = _common.deserialize(serialized_request, + request_deserializer) + with state.condition: + if request is None: + _abort(state, call, cygrpc.StatusCode.internal, + b'Exception deserializing request!') + else: + state.request = request + state.condition.notify_all() + return _possibly_finish_call(state, _RECEIVE_MESSAGE_TOKEN) + + return receive_message def _send_initial_metadata(state): - def send_initial_metadata(unused_send_initial_metadata_event): - with state.condition: - return _possibly_finish_call(state, _SEND_INITIAL_METADATA_TOKEN) - return send_initial_metadata + + def send_initial_metadata(unused_send_initial_metadata_event): + with state.condition: + return _possibly_finish_call(state, _SEND_INITIAL_METADATA_TOKEN) + + return send_initial_metadata def _send_message(state, token): - def send_message(unused_send_message_event): - with state.condition: - state.condition.notify_all() - return _possibly_finish_call(state, token) - return send_message + + def send_message(unused_send_message_event): + with state.condition: + state.condition.notify_all() + return _possibly_finish_call(state, token) + + return send_message class _Context(grpc.ServicerContext): - def __init__(self, rpc_event, state, request_deserializer): - self._rpc_event = rpc_event - self._state = state - self._request_deserializer = request_deserializer + def __init__(self, rpc_event, state, request_deserializer): + self._rpc_event = rpc_event + self._state = state + self._request_deserializer = request_deserializer - def is_active(self): - with self._state.condition: - return self._state.client is not _CANCELLED and not self._state.statused + def is_active(self): + with self._state.condition: + return self._state.client is not _CANCELLED and not self._state.statused - def time_remaining(self): - return max(self._rpc_event.request_call_details.deadline - time.time(), 0) + def time_remaining(self): + return max(self._rpc_event.request_call_details.deadline - time.time(), + 0) - def cancel(self): - self._rpc_event.operation_call.cancel() + def cancel(self): + self._rpc_event.operation_call.cancel() - def add_callback(self, callback): - with self._state.condition: - if self._state.callbacks is None: - return False - else: - self._state.callbacks.append(callback) - return True + def add_callback(self, callback): + with self._state.condition: + if self._state.callbacks is None: + return False + else: + self._state.callbacks.append(callback) + return True - def disable_next_message_compression(self): - with self._state.condition: - self._state.disable_next_compression = True - - def invocation_metadata(self): - return _common.application_metadata(self._rpc_event.request_metadata) - - def peer(self): - return _common.decode(self._rpc_event.operation_call.peer()) - - def send_initial_metadata(self, initial_metadata): - with self._state.condition: - if self._state.client is _CANCELLED: - _raise_rpc_error(self._state) - else: - if self._state.initial_metadata_allowed: - operation = cygrpc.operation_send_initial_metadata( - _common.cygrpc_metadata(initial_metadata), _EMPTY_FLAGS) - self._rpc_event.operation_call.start_server_batch( - cygrpc.Operations((operation,)), - _send_initial_metadata(self._state)) - self._state.initial_metadata_allowed = False - self._state.due.add(_SEND_INITIAL_METADATA_TOKEN) - else: - raise ValueError('Initial metadata no longer allowed!') + def disable_next_message_compression(self): + with self._state.condition: + self._state.disable_next_compression = True - def set_trailing_metadata(self, trailing_metadata): - with self._state.condition: - self._state.trailing_metadata = _common.cygrpc_metadata( - trailing_metadata) + def invocation_metadata(self): + return _common.application_metadata(self._rpc_event.request_metadata) - def set_code(self, code): - with self._state.condition: - self._state.code = code + def peer(self): + return _common.decode(self._rpc_event.operation_call.peer()) - def set_details(self, details): - with self._state.condition: - self._state.details = _common.encode(details) + def send_initial_metadata(self, initial_metadata): + with self._state.condition: + if self._state.client is _CANCELLED: + _raise_rpc_error(self._state) + else: + if self._state.initial_metadata_allowed: + operation = cygrpc.operation_send_initial_metadata( + _common.cygrpc_metadata(initial_metadata), _EMPTY_FLAGS) + self._rpc_event.operation_call.start_server_batch( + cygrpc.Operations((operation,)), + _send_initial_metadata(self._state)) + self._state.initial_metadata_allowed = False + self._state.due.add(_SEND_INITIAL_METADATA_TOKEN) + else: + raise ValueError('Initial metadata no longer allowed!') + + def set_trailing_metadata(self, trailing_metadata): + with self._state.condition: + self._state.trailing_metadata = _common.cygrpc_metadata( + trailing_metadata) + + def set_code(self, code): + with self._state.condition: + self._state.code = code + + def set_details(self, details): + with self._state.condition: + self._state.details = _common.encode(details) class _RequestIterator(object): - def __init__(self, state, call, request_deserializer): - self._state = state - self._call = call - self._request_deserializer = request_deserializer + def __init__(self, state, call, request_deserializer): + self._state = state + self._call = call + self._request_deserializer = request_deserializer - def _raise_or_start_receive_message(self): - if self._state.client is _CANCELLED: - _raise_rpc_error(self._state) - elif self._state.client is _CLOSED or self._state.statused: - raise StopIteration() - else: - self._call.start_server_batch( - cygrpc.Operations((cygrpc.operation_receive_message(_EMPTY_FLAGS),)), - _receive_message(self._state, self._call, self._request_deserializer)) - self._state.due.add(_RECEIVE_MESSAGE_TOKEN) - - def _look_for_request(self): - if self._state.client is _CANCELLED: - _raise_rpc_error(self._state) - elif (self._state.request is None and - _RECEIVE_MESSAGE_TOKEN not in self._state.due): - raise StopIteration() - else: - request = self._state.request - self._state.request = None - return request + def _raise_or_start_receive_message(self): + if self._state.client is _CANCELLED: + _raise_rpc_error(self._state) + elif self._state.client is _CLOSED or self._state.statused: + raise StopIteration() + else: + self._call.start_server_batch( + cygrpc.Operations( + (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), + _receive_message(self._state, self._call, + self._request_deserializer)) + self._state.due.add(_RECEIVE_MESSAGE_TOKEN) + + def _look_for_request(self): + if self._state.client is _CANCELLED: + _raise_rpc_error(self._state) + elif (self._state.request is None and + _RECEIVE_MESSAGE_TOKEN not in self._state.due): + raise StopIteration() + else: + request = self._state.request + self._state.request = None + return request - def _next(self): - with self._state.condition: - self._raise_or_start_receive_message() - while True: - self._state.condition.wait() - request = self._look_for_request() - if request is not None: - return request + def _next(self): + with self._state.condition: + self._raise_or_start_receive_message() + while True: + self._state.condition.wait() + request = self._look_for_request() + if request is not None: + return request - def __iter__(self): - return self + def __iter__(self): + return self - def __next__(self): - return self._next() + def __next__(self): + return self._next() - def next(self): - return self._next() + def next(self): + return self._next() def _unary_request(rpc_event, state, request_deserializer): - def unary_request(): - with state.condition: - if state.client is _CANCELLED or state.statused: - return None - else: - start_server_batch_result = rpc_event.operation_call.start_server_batch( - cygrpc.Operations( - (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), - _receive_message( - state, rpc_event.operation_call, request_deserializer)) - state.due.add(_RECEIVE_MESSAGE_TOKEN) - while True: - state.condition.wait() - if state.request is None: - if state.client is _CLOSED: - details = '"{}" requires exactly one request message.'.format( - rpc_event.request_call_details.method) - _abort( - state, rpc_event.operation_call, - cygrpc.StatusCode.unimplemented, _common.encode(details)) - return None - elif state.client is _CANCELLED: - return None - else: - request = state.request - state.request = None - return request - return unary_request + + def unary_request(): + with state.condition: + if state.client is _CANCELLED or state.statused: + return None + else: + start_server_batch_result = rpc_event.operation_call.start_server_batch( + cygrpc.Operations( + (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), + _receive_message(state, rpc_event.operation_call, + request_deserializer)) + state.due.add(_RECEIVE_MESSAGE_TOKEN) + while True: + state.condition.wait() + if state.request is None: + if state.client is _CLOSED: + details = '"{}" requires exactly one request message.'.format( + rpc_event.request_call_details.method) + _abort(state, rpc_event.operation_call, + cygrpc.StatusCode.unimplemented, + _common.encode(details)) + return None + elif state.client is _CANCELLED: + return None + else: + request = state.request + state.request = None + return request + + return unary_request def _call_behavior(rpc_event, state, behavior, argument, request_deserializer): - context = _Context(rpc_event, state, request_deserializer) - try: - return behavior(argument, context), True - except Exception as e: # pylint: disable=broad-except - with state.condition: - if e not in state.rpc_errors: - details = 'Exception calling application: {}'.format(e) - logging.exception(details) - _abort(state, rpc_event.operation_call, - cygrpc.StatusCode.unknown, _common.encode(details)) - return None, False + context = _Context(rpc_event, state, request_deserializer) + try: + return behavior(argument, context), True + except Exception as e: # pylint: disable=broad-except + with state.condition: + if e not in state.rpc_errors: + details = 'Exception calling application: {}'.format(e) + logging.exception(details) + _abort(state, rpc_event.operation_call, + cygrpc.StatusCode.unknown, _common.encode(details)) + return None, False def _take_response_from_response_iterator(rpc_event, state, response_iterator): - try: - return next(response_iterator), True - except StopIteration: - return None, True - except Exception as e: # pylint: disable=broad-except - with state.condition: - if e not in state.rpc_errors: - details = 'Exception iterating responses: {}'.format(e) - logging.exception(details) - _abort(state, rpc_event.operation_call, - cygrpc.StatusCode.unknown, _common.encode(details)) - return None, False + try: + return next(response_iterator), True + except StopIteration: + return None, True + except Exception as e: # pylint: disable=broad-except + with state.condition: + if e not in state.rpc_errors: + details = 'Exception iterating responses: {}'.format(e) + logging.exception(details) + _abort(state, rpc_event.operation_call, + cygrpc.StatusCode.unknown, _common.encode(details)) + return None, False def _serialize_response(rpc_event, state, response, response_serializer): - serialized_response = _common.serialize(response, response_serializer) - if serialized_response is None: - with state.condition: - _abort( - state, rpc_event.operation_call, cygrpc.StatusCode.internal, - b'Failed to serialize response!') - return None - else: - return serialized_response + serialized_response = _common.serialize(response, response_serializer) + if serialized_response is None: + with state.condition: + _abort(state, rpc_event.operation_call, cygrpc.StatusCode.internal, + b'Failed to serialize response!') + return None + else: + return serialized_response def _send_response(rpc_event, state, serialized_response): - with state.condition: - if state.client is _CANCELLED or state.statused: - return False - else: - if state.initial_metadata_allowed: - operations = ( - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_send_message(serialized_response, _EMPTY_FLAGS), - ) - state.initial_metadata_allowed = False - token = _SEND_INITIAL_METADATA_AND_SEND_MESSAGE_TOKEN - else: - operations = ( - cygrpc.operation_send_message(serialized_response, _EMPTY_FLAGS), - ) - token = _SEND_MESSAGE_TOKEN - rpc_event.operation_call.start_server_batch( - cygrpc.Operations(operations), _send_message(state, token)) - state.due.add(token) - while True: - state.condition.wait() - if token not in state.due: - return state.client is not _CANCELLED and not state.statused + with state.condition: + if state.client is _CANCELLED or state.statused: + return False + else: + if state.initial_metadata_allowed: + operations = ( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_send_message(serialized_response, + _EMPTY_FLAGS),) + state.initial_metadata_allowed = False + token = _SEND_INITIAL_METADATA_AND_SEND_MESSAGE_TOKEN + else: + operations = (cygrpc.operation_send_message(serialized_response, + _EMPTY_FLAGS),) + token = _SEND_MESSAGE_TOKEN + rpc_event.operation_call.start_server_batch( + cygrpc.Operations(operations), _send_message(state, token)) + state.due.add(token) + while True: + state.condition.wait() + if token not in state.due: + return state.client is not _CANCELLED and not state.statused def _status(rpc_event, state, serialized_response): - with state.condition: - if state.client is not _CANCELLED: - trailing_metadata = _common.cygrpc_metadata(state.trailing_metadata) - code = _completion_code(state) - details = _details(state) - operations = [ - cygrpc.operation_send_status_from_server( - trailing_metadata, code, details, _EMPTY_FLAGS), - ] - if state.initial_metadata_allowed: - operations.append( - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS)) - if serialized_response is not None: - operations.append(cygrpc.operation_send_message( - serialized_response, _EMPTY_FLAGS)) - rpc_event.operation_call.start_server_batch( - cygrpc.Operations(operations), - _send_status_from_server(state, _SEND_STATUS_FROM_SERVER_TOKEN)) - state.statused = True - state.due.add(_SEND_STATUS_FROM_SERVER_TOKEN) - - -def _unary_response_in_pool( - rpc_event, state, behavior, argument_thunk, request_deserializer, - response_serializer): - argument = argument_thunk() - if argument is not None: - response, proceed = _call_behavior( - rpc_event, state, behavior, argument, request_deserializer) - if proceed: - serialized_response = _serialize_response( - rpc_event, state, response, response_serializer) - if serialized_response is not None: - _status(rpc_event, state, serialized_response) - - -def _stream_response_in_pool( - rpc_event, state, behavior, argument_thunk, request_deserializer, - response_serializer): - argument = argument_thunk() - if argument is not None: - response_iterator, proceed = _call_behavior( - rpc_event, state, behavior, argument, request_deserializer) - if proceed: - while True: - response, proceed = _take_response_from_response_iterator( - rpc_event, state, response_iterator) + with state.condition: + if state.client is not _CANCELLED: + trailing_metadata = _common.cygrpc_metadata(state.trailing_metadata) + code = _completion_code(state) + details = _details(state) + operations = [ + cygrpc.operation_send_status_from_server( + trailing_metadata, code, details, _EMPTY_FLAGS), + ] + if state.initial_metadata_allowed: + operations.append( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS)) + if serialized_response is not None: + operations.append( + cygrpc.operation_send_message(serialized_response, + _EMPTY_FLAGS)) + rpc_event.operation_call.start_server_batch( + cygrpc.Operations(operations), + _send_status_from_server(state, _SEND_STATUS_FROM_SERVER_TOKEN)) + state.statused = True + state.due.add(_SEND_STATUS_FROM_SERVER_TOKEN) + + +def _unary_response_in_pool(rpc_event, state, behavior, argument_thunk, + request_deserializer, response_serializer): + argument = argument_thunk() + if argument is not None: + response, proceed = _call_behavior(rpc_event, state, behavior, argument, + request_deserializer) if proceed: - if response is None: - _status(rpc_event, state, None) - break - else: serialized_response = _serialize_response( rpc_event, state, response, response_serializer) if serialized_response is not None: - proceed = _send_response(rpc_event, state, serialized_response) - if not proceed: - break - else: - break - else: - break + _status(rpc_event, state, serialized_response) + + +def _stream_response_in_pool(rpc_event, state, behavior, argument_thunk, + request_deserializer, response_serializer): + argument = argument_thunk() + if argument is not None: + response_iterator, proceed = _call_behavior( + rpc_event, state, behavior, argument, request_deserializer) + if proceed: + while True: + response, proceed = _take_response_from_response_iterator( + rpc_event, state, response_iterator) + if proceed: + if response is None: + _status(rpc_event, state, None) + break + else: + serialized_response = _serialize_response( + rpc_event, state, response, response_serializer) + if serialized_response is not None: + proceed = _send_response(rpc_event, state, + serialized_response) + if not proceed: + break + else: + break + else: + break def _handle_unary_unary(rpc_event, state, method_handler, thread_pool): - unary_request = _unary_request( - rpc_event, state, method_handler.request_deserializer) - thread_pool.submit( - _unary_response_in_pool, rpc_event, state, method_handler.unary_unary, - unary_request, method_handler.request_deserializer, - method_handler.response_serializer) + unary_request = _unary_request(rpc_event, state, + method_handler.request_deserializer) + thread_pool.submit(_unary_response_in_pool, rpc_event, state, + method_handler.unary_unary, unary_request, + method_handler.request_deserializer, + method_handler.response_serializer) def _handle_unary_stream(rpc_event, state, method_handler, thread_pool): - unary_request = _unary_request( - rpc_event, state, method_handler.request_deserializer) - thread_pool.submit( - _stream_response_in_pool, rpc_event, state, method_handler.unary_stream, - unary_request, method_handler.request_deserializer, - method_handler.response_serializer) + unary_request = _unary_request(rpc_event, state, + method_handler.request_deserializer) + thread_pool.submit(_stream_response_in_pool, rpc_event, state, + method_handler.unary_stream, unary_request, + method_handler.request_deserializer, + method_handler.response_serializer) def _handle_stream_unary(rpc_event, state, method_handler, thread_pool): - request_iterator = _RequestIterator( - state, rpc_event.operation_call, method_handler.request_deserializer) - thread_pool.submit( - _unary_response_in_pool, rpc_event, state, method_handler.stream_unary, - lambda: request_iterator, method_handler.request_deserializer, - method_handler.response_serializer) + request_iterator = _RequestIterator(state, rpc_event.operation_call, + method_handler.request_deserializer) + thread_pool.submit(_unary_response_in_pool, rpc_event, state, + method_handler.stream_unary, lambda: request_iterator, + method_handler.request_deserializer, + method_handler.response_serializer) def _handle_stream_stream(rpc_event, state, method_handler, thread_pool): - request_iterator = _RequestIterator( - state, rpc_event.operation_call, method_handler.request_deserializer) - thread_pool.submit( - _stream_response_in_pool, rpc_event, state, method_handler.stream_stream, - lambda: request_iterator, method_handler.request_deserializer, - method_handler.response_serializer) + request_iterator = _RequestIterator(state, rpc_event.operation_call, + method_handler.request_deserializer) + thread_pool.submit(_stream_response_in_pool, rpc_event, state, + method_handler.stream_stream, lambda: request_iterator, + method_handler.request_deserializer, + method_handler.response_serializer) def _find_method_handler(rpc_event, generic_handlers): - for generic_handler in generic_handlers: - method_handler = generic_handler.service( - _HandlerCallDetails( - _common.decode(rpc_event.request_call_details.method), - rpc_event.request_metadata)) - if method_handler is not None: - return method_handler - else: - return None + for generic_handler in generic_handlers: + method_handler = generic_handler.service( + _HandlerCallDetails( + _common.decode(rpc_event.request_call_details.method), + rpc_event.request_metadata)) + if method_handler is not None: + return method_handler + else: + return None def _handle_unrecognized_method(rpc_event): - operations = ( - cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - _EMPTY_METADATA, cygrpc.StatusCode.unimplemented, - b'Method not found!', _EMPTY_FLAGS), - ) - rpc_state = _RPCState() - rpc_event.operation_call.start_server_batch( - operations, lambda ignored_event: (rpc_state, (),)) - return rpc_state + operations = ( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, _EMPTY_FLAGS), + cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + _EMPTY_METADATA, cygrpc.StatusCode.unimplemented, + b'Method not found!', _EMPTY_FLAGS),) + rpc_state = _RPCState() + rpc_event.operation_call.start_server_batch(operations, + lambda ignored_event: ( + rpc_state, + (),)) + return rpc_state def _handle_with_method_handler(rpc_event, method_handler, thread_pool): - state = _RPCState() - with state.condition: - rpc_event.operation_call.start_server_batch( - cygrpc.Operations( - (cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS),)), - _receive_close_on_server(state)) - state.due.add(_RECEIVE_CLOSE_ON_SERVER_TOKEN) - if method_handler.request_streaming: - if method_handler.response_streaming: - _handle_stream_stream(rpc_event, state, method_handler, thread_pool) - else: - _handle_stream_unary(rpc_event, state, method_handler, thread_pool) - else: - if method_handler.response_streaming: - _handle_unary_stream(rpc_event, state, method_handler, thread_pool) - else: - _handle_unary_unary(rpc_event, state, method_handler, thread_pool) - return state + state = _RPCState() + with state.condition: + rpc_event.operation_call.start_server_batch( + cygrpc.Operations( + (cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS),)), + _receive_close_on_server(state)) + state.due.add(_RECEIVE_CLOSE_ON_SERVER_TOKEN) + if method_handler.request_streaming: + if method_handler.response_streaming: + _handle_stream_stream(rpc_event, state, method_handler, + thread_pool) + else: + _handle_stream_unary(rpc_event, state, method_handler, + thread_pool) + else: + if method_handler.response_streaming: + _handle_unary_stream(rpc_event, state, method_handler, + thread_pool) + else: + _handle_unary_unary(rpc_event, state, method_handler, + thread_pool) + return state def _handle_call(rpc_event, generic_handlers, thread_pool): - if rpc_event.request_call_details.method is not None: - method_handler = _find_method_handler(rpc_event, generic_handlers) - if method_handler is None: - return _handle_unrecognized_method(rpc_event) + if rpc_event.request_call_details.method is not None: + method_handler = _find_method_handler(rpc_event, generic_handlers) + if method_handler is None: + return _handle_unrecognized_method(rpc_event) + else: + return _handle_with_method_handler(rpc_event, method_handler, + thread_pool) else: - return _handle_with_method_handler(rpc_event, method_handler, thread_pool) - else: - return None + return None @enum.unique class _ServerStage(enum.Enum): - STOPPED = 'stopped' - STARTED = 'started' - GRACE = 'grace' + STOPPED = 'stopped' + STARTED = 'started' + GRACE = 'grace' class _ServerState(object): - def __init__(self, completion_queue, server, generic_handlers, thread_pool): - self.lock = threading.Lock() - self.completion_queue = completion_queue - self.server = server - self.generic_handlers = list(generic_handlers) - self.thread_pool = thread_pool - self.stage = _ServerStage.STOPPED - self.shutdown_events = None + def __init__(self, completion_queue, server, generic_handlers, thread_pool): + self.lock = threading.Lock() + self.completion_queue = completion_queue + self.server = server + self.generic_handlers = list(generic_handlers) + self.thread_pool = thread_pool + self.stage = _ServerStage.STOPPED + self.shutdown_events = None - # TODO(https://github.com/grpc/grpc/issues/6597): eliminate these fields. - self.rpc_states = set() - self.due = set() + # TODO(https://github.com/grpc/grpc/issues/6597): eliminate these fields. + self.rpc_states = set() + self.due = set() def _add_generic_handlers(state, generic_handlers): - with state.lock: - state.generic_handlers.extend(generic_handlers) + with state.lock: + state.generic_handlers.extend(generic_handlers) def _add_insecure_port(state, address): - with state.lock: - return state.server.add_http2_port(address) + with state.lock: + return state.server.add_http2_port(address) def _add_secure_port(state, address, server_credentials): - with state.lock: - return state.server.add_http2_port(address, server_credentials._credentials) + with state.lock: + return state.server.add_http2_port(address, + server_credentials._credentials) def _request_call(state): - state.server.request_call( - state.completion_queue, state.completion_queue, _REQUEST_CALL_TAG) - state.due.add(_REQUEST_CALL_TAG) + state.server.request_call(state.completion_queue, state.completion_queue, + _REQUEST_CALL_TAG) + state.due.add(_REQUEST_CALL_TAG) # TODO(https://github.com/grpc/grpc/issues/6597): delete this function. def _stop_serving(state): - if not state.rpc_states and not state.due: - for shutdown_event in state.shutdown_events: - shutdown_event.set() - state.stage = _ServerStage.STOPPED - return True - else: - return False + if not state.rpc_states and not state.due: + for shutdown_event in state.shutdown_events: + shutdown_event.set() + state.stage = _ServerStage.STOPPED + return True + else: + return False def _serve(state): - while True: - event = state.completion_queue.poll() - if event.tag is _SHUTDOWN_TAG: - with state.lock: - state.due.remove(_SHUTDOWN_TAG) - if _stop_serving(state): - return - elif event.tag is _REQUEST_CALL_TAG: - with state.lock: - state.due.remove(_REQUEST_CALL_TAG) - rpc_state = _handle_call( - event, state.generic_handlers, state.thread_pool) - if rpc_state is not None: - state.rpc_states.add(rpc_state) - if state.stage is _ServerStage.STARTED: - _request_call(state) - elif _stop_serving(state): - return - else: - rpc_state, callbacks = event.tag(event) - for callback in callbacks: - callable_util.call_logging_exceptions( - callback, 'Exception calling callback!') - if rpc_state is not None: - with state.lock: - state.rpc_states.remove(rpc_state) - if _stop_serving(state): - return + while True: + event = state.completion_queue.poll() + if event.tag is _SHUTDOWN_TAG: + with state.lock: + state.due.remove(_SHUTDOWN_TAG) + if _stop_serving(state): + return + elif event.tag is _REQUEST_CALL_TAG: + with state.lock: + state.due.remove(_REQUEST_CALL_TAG) + rpc_state = _handle_call(event, state.generic_handlers, + state.thread_pool) + if rpc_state is not None: + state.rpc_states.add(rpc_state) + if state.stage is _ServerStage.STARTED: + _request_call(state) + elif _stop_serving(state): + return + else: + rpc_state, callbacks = event.tag(event) + for callback in callbacks: + callable_util.call_logging_exceptions( + callback, 'Exception calling callback!') + if rpc_state is not None: + with state.lock: + state.rpc_states.remove(rpc_state) + if _stop_serving(state): + return def _stop(state, grace): - with state.lock: - if state.stage is _ServerStage.STOPPED: - shutdown_event = threading.Event() - shutdown_event.set() - return shutdown_event - else: - if state.stage is _ServerStage.STARTED: - state.server.shutdown(state.completion_queue, _SHUTDOWN_TAG) - state.stage = _ServerStage.GRACE - state.shutdown_events = [] - state.due.add(_SHUTDOWN_TAG) - shutdown_event = threading.Event() - state.shutdown_events.append(shutdown_event) - if grace is None: - state.server.cancel_all_calls() - # TODO(https://github.com/grpc/grpc/issues/6597): delete this loop. - for rpc_state in state.rpc_states: - with rpc_state.condition: - rpc_state.client = _CANCELLED - rpc_state.condition.notify_all() - else: - def cancel_all_calls_after_grace(): - shutdown_event.wait(timeout=grace) - with state.lock: - state.server.cancel_all_calls() - # TODO(https://github.com/grpc/grpc/issues/6597): delete this loop. - for rpc_state in state.rpc_states: - with rpc_state.condition: - rpc_state.client = _CANCELLED - rpc_state.condition.notify_all() - thread = threading.Thread(target=cancel_all_calls_after_grace) - thread.start() - return shutdown_event - shutdown_event.wait() - return shutdown_event + with state.lock: + if state.stage is _ServerStage.STOPPED: + shutdown_event = threading.Event() + shutdown_event.set() + return shutdown_event + else: + if state.stage is _ServerStage.STARTED: + state.server.shutdown(state.completion_queue, _SHUTDOWN_TAG) + state.stage = _ServerStage.GRACE + state.shutdown_events = [] + state.due.add(_SHUTDOWN_TAG) + shutdown_event = threading.Event() + state.shutdown_events.append(shutdown_event) + if grace is None: + state.server.cancel_all_calls() + # TODO(https://github.com/grpc/grpc/issues/6597): delete this loop. + for rpc_state in state.rpc_states: + with rpc_state.condition: + rpc_state.client = _CANCELLED + rpc_state.condition.notify_all() + else: + + def cancel_all_calls_after_grace(): + shutdown_event.wait(timeout=grace) + with state.lock: + state.server.cancel_all_calls() + # TODO(https://github.com/grpc/grpc/issues/6597): delete this loop. + for rpc_state in state.rpc_states: + with rpc_state.condition: + rpc_state.client = _CANCELLED + rpc_state.condition.notify_all() + + thread = threading.Thread(target=cancel_all_calls_after_grace) + thread.start() + return shutdown_event + shutdown_event.wait() + return shutdown_event def _start(state): - with state.lock: - if state.stage is not _ServerStage.STOPPED: - raise ValueError('Cannot start already-started server!') - state.server.start() - state.stage = _ServerStage.STARTED - _request_call(state) - def cleanup_server(timeout): - if timeout is None: - _stop(state, _UNEXPECTED_EXIT_SERVER_GRACE).wait() - else: - _stop(state, timeout).wait() - - thread = _common.CleanupThread( - cleanup_server, target=_serve, args=(state,)) - thread.start() + with state.lock: + if state.stage is not _ServerStage.STOPPED: + raise ValueError('Cannot start already-started server!') + state.server.start() + state.stage = _ServerStage.STARTED + _request_call(state) + + def cleanup_server(timeout): + if timeout is None: + _stop(state, _UNEXPECTED_EXIT_SERVER_GRACE).wait() + else: + _stop(state, timeout).wait() + + thread = _common.CleanupThread( + cleanup_server, target=_serve, args=(state,)) + thread.start() + class Server(grpc.Server): - def __init__(self, thread_pool, generic_handlers, options): - completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(_common.channel_args(options)) - server.register_completion_queue(completion_queue) - self._state = _ServerState( - completion_queue, server, generic_handlers, thread_pool) + def __init__(self, thread_pool, generic_handlers, options): + completion_queue = cygrpc.CompletionQueue() + server = cygrpc.Server(_common.channel_args(options)) + server.register_completion_queue(completion_queue) + self._state = _ServerState(completion_queue, server, generic_handlers, + thread_pool) - def add_generic_rpc_handlers(self, generic_rpc_handlers): - _add_generic_handlers(self._state, generic_rpc_handlers) + def add_generic_rpc_handlers(self, generic_rpc_handlers): + _add_generic_handlers(self._state, generic_rpc_handlers) - def add_insecure_port(self, address): - return _add_insecure_port(self._state, _common.encode(address)) + def add_insecure_port(self, address): + return _add_insecure_port(self._state, _common.encode(address)) - def add_secure_port(self, address, server_credentials): - return _add_secure_port(self._state, _common.encode(address), server_credentials) + def add_secure_port(self, address, server_credentials): + return _add_secure_port(self._state, + _common.encode(address), server_credentials) - def start(self): - _start(self._state) + def start(self): + _start(self._state) - def stop(self, grace): - return _stop(self._state, grace) + def stop(self, grace): + return _stop(self._state, grace) - def __del__(self): - _stop(self._state, None) + def __del__(self): + _stop(self._state, None) diff --git a/src/python/grpcio/grpc/_utilities.py b/src/python/grpcio/grpc/_utilities.py index a375896e6e6..7c602eb37e3 100644 --- a/src/python/grpcio/grpc/_utilities.py +++ b/src/python/grpcio/grpc/_utilities.py @@ -26,7 +26,6 @@ # 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. - """Internal utilities for gRPC Python.""" import collections @@ -44,132 +43,136 @@ _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE = ( class RpcMethodHandler( - collections.namedtuple( - '_RpcMethodHandler', - ('request_streaming', 'response_streaming', 'request_deserializer', - 'response_serializer', 'unary_unary', 'unary_stream', 'stream_unary', - 'stream_stream',)), - grpc.RpcMethodHandler): - pass + collections.namedtuple('_RpcMethodHandler', ( + 'request_streaming', + 'response_streaming', + 'request_deserializer', + 'response_serializer', + 'unary_unary', + 'unary_stream', + 'stream_unary', + 'stream_stream',)), grpc.RpcMethodHandler): + pass class DictionaryGenericHandler(grpc.ServiceRpcHandler): - def __init__(self, service, method_handlers): - self._name = service - self._method_handlers = { - _common.fully_qualified_method(service, method): method_handler - for method, method_handler in six.iteritems(method_handlers)} + def __init__(self, service, method_handlers): + self._name = service + self._method_handlers = { + _common.fully_qualified_method(service, method): method_handler + for method, method_handler in six.iteritems(method_handlers) + } - def service_name(self): - return self._name + def service_name(self): + return self._name - def service(self, handler_call_details): - return self._method_handlers.get(handler_call_details.method) + def service(self, handler_call_details): + return self._method_handlers.get(handler_call_details.method) class _ChannelReadyFuture(grpc.Future): - def __init__(self, channel): - self._condition = threading.Condition() - self._channel = channel - - self._matured = False - self._cancelled = False - self._done_callbacks = [] - - def _block(self, timeout): - until = None if timeout is None else time.time() + timeout - with self._condition: - while True: - if self._cancelled: - raise grpc.FutureCancelledError() - elif self._matured: - return - else: - if until is None: - self._condition.wait() - else: - remaining = until - time.time() - if remaining < 0: - raise grpc.FutureTimeoutError() + def __init__(self, channel): + self._condition = threading.Condition() + self._channel = channel + + self._matured = False + self._cancelled = False + self._done_callbacks = [] + + def _block(self, timeout): + until = None if timeout is None else time.time() + timeout + with self._condition: + while True: + if self._cancelled: + raise grpc.FutureCancelledError() + elif self._matured: + return + else: + if until is None: + self._condition.wait() + else: + remaining = until - time.time() + if remaining < 0: + raise grpc.FutureTimeoutError() + else: + self._condition.wait(timeout=remaining) + + def _update(self, connectivity): + with self._condition: + if (not self._cancelled and + connectivity is grpc.ChannelConnectivity.READY): + self._matured = True + self._channel.unsubscribe(self._update) + self._condition.notify_all() + done_callbacks = tuple(self._done_callbacks) + self._done_callbacks = None + else: + return + + for done_callback in done_callbacks: + callable_util.call_logging_exceptions( + done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) + + def cancel(self): + with self._condition: + if not self._matured: + self._cancelled = True + self._channel.unsubscribe(self._update) + self._condition.notify_all() + done_callbacks = tuple(self._done_callbacks) + self._done_callbacks = None else: - self._condition.wait(timeout=remaining) - - def _update(self, connectivity): - with self._condition: - if (not self._cancelled and - connectivity is grpc.ChannelConnectivity.READY): - self._matured = True - self._channel.unsubscribe(self._update) - self._condition.notify_all() - done_callbacks = tuple(self._done_callbacks) - self._done_callbacks = None - else: - return - - for done_callback in done_callbacks: - callable_util.call_logging_exceptions( - done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) - - def cancel(self): - with self._condition: - if not self._matured: - self._cancelled = True - self._channel.unsubscribe(self._update) - self._condition.notify_all() - done_callbacks = tuple(self._done_callbacks) - self._done_callbacks = None - else: - return False - - for done_callback in done_callbacks: - callable_util.call_logging_exceptions( - done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) - - def cancelled(self): - with self._condition: - return self._cancelled - - def running(self): - with self._condition: - return not self._cancelled and not self._matured - - def done(self): - with self._condition: - return self._cancelled or self._matured - - def result(self, timeout=None): - self._block(timeout) - return None - - def exception(self, timeout=None): - self._block(timeout) - return None - - def traceback(self, timeout=None): - self._block(timeout) - return None - - def add_done_callback(self, fn): - with self._condition: - if not self._cancelled and not self._matured: - self._done_callbacks.append(fn) - return - - fn(self) - - def start(self): - with self._condition: - self._channel.subscribe(self._update, try_to_connect=True) - - def __del__(self): - with self._condition: - if not self._cancelled and not self._matured: - self._channel.unsubscribe(self._update) + return False + + for done_callback in done_callbacks: + callable_util.call_logging_exceptions( + done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) + + def cancelled(self): + with self._condition: + return self._cancelled + + def running(self): + with self._condition: + return not self._cancelled and not self._matured + + def done(self): + with self._condition: + return self._cancelled or self._matured + + def result(self, timeout=None): + self._block(timeout) + return None + + def exception(self, timeout=None): + self._block(timeout) + return None + + def traceback(self, timeout=None): + self._block(timeout) + return None + + def add_done_callback(self, fn): + with self._condition: + if not self._cancelled and not self._matured: + self._done_callbacks.append(fn) + return + + fn(self) + + def start(self): + with self._condition: + self._channel.subscribe(self._update, try_to_connect=True) + + def __del__(self): + with self._condition: + if not self._cancelled and not self._matured: + self._channel.unsubscribe(self._update) def channel_ready_future(channel): - ready_future = _ChannelReadyFuture(channel) - ready_future.start() - return ready_future + ready_future = _ChannelReadyFuture(channel) + ready_future.start() + return ready_future diff --git a/src/python/grpcio/grpc/beta/_client_adaptations.py b/src/python/grpcio/grpc/beta/_client_adaptations.py index e4ee44d7a3e..e5b28e9408e 100644 --- a/src/python/grpcio/grpc/beta/_client_adaptations.py +++ b/src/python/grpcio/grpc/beta/_client_adaptations.py @@ -26,7 +26,6 @@ # 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. - """Translates gRPC's client-side API into gRPC's client-side Beta API.""" import grpc @@ -38,531 +37,654 @@ from grpc.framework.foundation import future from grpc.framework.interfaces.face import face _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS = { - grpc.StatusCode.CANCELLED: ( - face.Abortion.Kind.CANCELLED, face.CancellationError), - grpc.StatusCode.UNKNOWN: ( - face.Abortion.Kind.REMOTE_FAILURE, face.RemoteError), - grpc.StatusCode.DEADLINE_EXCEEDED: ( - face.Abortion.Kind.EXPIRED, face.ExpirationError), - grpc.StatusCode.UNIMPLEMENTED: ( - face.Abortion.Kind.LOCAL_FAILURE, face.LocalError), + grpc.StatusCode.CANCELLED: (face.Abortion.Kind.CANCELLED, + face.CancellationError), + grpc.StatusCode.UNKNOWN: (face.Abortion.Kind.REMOTE_FAILURE, + face.RemoteError), + grpc.StatusCode.DEADLINE_EXCEEDED: (face.Abortion.Kind.EXPIRED, + face.ExpirationError), + grpc.StatusCode.UNIMPLEMENTED: (face.Abortion.Kind.LOCAL_FAILURE, + face.LocalError), } def _effective_metadata(metadata, metadata_transformer): - non_none_metadata = () if metadata is None else metadata - if metadata_transformer is None: - return non_none_metadata - else: - return metadata_transformer(non_none_metadata) + non_none_metadata = () if metadata is None else metadata + if metadata_transformer is None: + return non_none_metadata + else: + return metadata_transformer(non_none_metadata) def _credentials(grpc_call_options): - return None if grpc_call_options is None else grpc_call_options.credentials + return None if grpc_call_options is None else grpc_call_options.credentials def _abortion(rpc_error_call): - code = rpc_error_call.code() - pair = _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS.get(code) - error_kind = face.Abortion.Kind.LOCAL_FAILURE if pair is None else pair[0] - return face.Abortion( - error_kind, rpc_error_call.initial_metadata(), - rpc_error_call.trailing_metadata(), code, rpc_error_call.details()) + code = rpc_error_call.code() + pair = _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS.get(code) + error_kind = face.Abortion.Kind.LOCAL_FAILURE if pair is None else pair[0] + return face.Abortion(error_kind, + rpc_error_call.initial_metadata(), + rpc_error_call.trailing_metadata(), code, + rpc_error_call.details()) def _abortion_error(rpc_error_call): - code = rpc_error_call.code() - pair = _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS.get(code) - exception_class = face.AbortionError if pair is None else pair[1] - return exception_class( - rpc_error_call.initial_metadata(), rpc_error_call.trailing_metadata(), - code, rpc_error_call.details()) + code = rpc_error_call.code() + pair = _STATUS_CODE_TO_ABORTION_KIND_AND_ABORTION_ERROR_CLASS.get(code) + exception_class = face.AbortionError if pair is None else pair[1] + return exception_class(rpc_error_call.initial_metadata(), + rpc_error_call.trailing_metadata(), code, + rpc_error_call.details()) class _InvocationProtocolContext(interfaces.GRPCInvocationContext): - def disable_next_request_compression(self): - pass # TODO(https://github.com/grpc/grpc/issues/4078): design, implement. + def disable_next_request_compression(self): + pass # TODO(https://github.com/grpc/grpc/issues/4078): design, implement. class _Rendezvous(future.Future, face.Call): - def __init__(self, response_future, response_iterator, call): - self._future = response_future - self._iterator = response_iterator - self._call = call + def __init__(self, response_future, response_iterator, call): + self._future = response_future + self._iterator = response_iterator + self._call = call - def cancel(self): - return self._call.cancel() + def cancel(self): + return self._call.cancel() - def cancelled(self): - return self._future.cancelled() + def cancelled(self): + return self._future.cancelled() - def running(self): - return self._future.running() + def running(self): + return self._future.running() - def done(self): - return self._future.done() + def done(self): + return self._future.done() - def result(self, timeout=None): - try: - return self._future.result(timeout=timeout) - except grpc.RpcError as rpc_error_call: - raise _abortion_error(rpc_error_call) - except grpc.FutureTimeoutError: - raise future.TimeoutError() - except grpc.FutureCancelledError: - raise future.CancelledError() + def result(self, timeout=None): + try: + return self._future.result(timeout=timeout) + except grpc.RpcError as rpc_error_call: + raise _abortion_error(rpc_error_call) + except grpc.FutureTimeoutError: + raise future.TimeoutError() + except grpc.FutureCancelledError: + raise future.CancelledError() - def exception(self, timeout=None): - try: - rpc_error_call = self._future.exception(timeout=timeout) - if rpc_error_call is None: - return None - else: - return _abortion_error(rpc_error_call) - except grpc.FutureTimeoutError: - raise future.TimeoutError() - except grpc.FutureCancelledError: - raise future.CancelledError() - - def traceback(self, timeout=None): - try: - return self._future.traceback(timeout=timeout) - except grpc.FutureTimeoutError: - raise future.TimeoutError() - except grpc.FutureCancelledError: - raise future.CancelledError() + def exception(self, timeout=None): + try: + rpc_error_call = self._future.exception(timeout=timeout) + if rpc_error_call is None: + return None + else: + return _abortion_error(rpc_error_call) + except grpc.FutureTimeoutError: + raise future.TimeoutError() + except grpc.FutureCancelledError: + raise future.CancelledError() - def add_done_callback(self, fn): - self._future.add_done_callback(lambda ignored_callback: fn(self)) + def traceback(self, timeout=None): + try: + return self._future.traceback(timeout=timeout) + except grpc.FutureTimeoutError: + raise future.TimeoutError() + except grpc.FutureCancelledError: + raise future.CancelledError() - def __iter__(self): - return self + def add_done_callback(self, fn): + self._future.add_done_callback(lambda ignored_callback: fn(self)) - def _next(self): - try: - return next(self._iterator) - except grpc.RpcError as rpc_error_call: - raise _abortion_error(rpc_error_call) + def __iter__(self): + return self + + def _next(self): + try: + return next(self._iterator) + except grpc.RpcError as rpc_error_call: + raise _abortion_error(rpc_error_call) + + def __next__(self): + return self._next() - def __next__(self): - return self._next() + def next(self): + return self._next() - def next(self): - return self._next() + def is_active(self): + return self._call.is_active() - def is_active(self): - return self._call.is_active() + def time_remaining(self): + return self._call.time_remaining() - def time_remaining(self): - return self._call.time_remaining() + def add_abortion_callback(self, abortion_callback): - def add_abortion_callback(self, abortion_callback): - def done_callback(): - if self.code() is not grpc.StatusCode.OK: - abortion_callback(_abortion(self._call)) - registered = self._call.add_callback(done_callback) - return None if registered else done_callback() + def done_callback(): + if self.code() is not grpc.StatusCode.OK: + abortion_callback(_abortion(self._call)) - def protocol_context(self): - return _InvocationProtocolContext() + registered = self._call.add_callback(done_callback) + return None if registered else done_callback() - def initial_metadata(self): - return self._call.initial_metadata() + def protocol_context(self): + return _InvocationProtocolContext() - def terminal_metadata(self): - return self._call.terminal_metadata() + def initial_metadata(self): + return self._call.initial_metadata() - def code(self): - return self._call.code() + def terminal_metadata(self): + return self._call.terminal_metadata() - def details(self): - return self._call.details() + def code(self): + return self._call.code() + def details(self): + return self._call.details() -def _blocking_unary_unary( - channel, group, method, timeout, with_call, protocol_options, metadata, - metadata_transformer, request, request_serializer, response_deserializer): - try: + +def _blocking_unary_unary(channel, group, method, timeout, with_call, + protocol_options, metadata, metadata_transformer, + request, request_serializer, response_deserializer): + try: + multi_callable = channel.unary_unary( + _common.fully_qualified_method(group, method), + request_serializer=request_serializer, + response_deserializer=response_deserializer) + effective_metadata = _effective_metadata(metadata, metadata_transformer) + if with_call: + response, call = multi_callable.with_call( + request, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return response, _Rendezvous(None, None, call) + else: + return multi_callable( + request, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + except grpc.RpcError as rpc_error_call: + raise _abortion_error(rpc_error_call) + + +def _future_unary_unary(channel, group, method, timeout, protocol_options, + metadata, metadata_transformer, request, + request_serializer, response_deserializer): multi_callable = channel.unary_unary( _common.fully_qualified_method(group, method), request_serializer=request_serializer, response_deserializer=response_deserializer) effective_metadata = _effective_metadata(metadata, metadata_transformer) - if with_call: - response, call = multi_callable.with_call( - request, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return response, _Rendezvous(None, None, call) - else: - return multi_callable( - request, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - except grpc.RpcError as rpc_error_call: - raise _abortion_error(rpc_error_call) - - -def _future_unary_unary( - channel, group, method, timeout, protocol_options, metadata, - metadata_transformer, request, request_serializer, response_deserializer): - multi_callable = channel.unary_unary( - _common.fully_qualified_method(group, method), - request_serializer=request_serializer, - response_deserializer=response_deserializer) - effective_metadata = _effective_metadata(metadata, metadata_transformer) - response_future = multi_callable.future( - request, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return _Rendezvous(response_future, None, response_future) - - -def _unary_stream( - channel, group, method, timeout, protocol_options, metadata, - metadata_transformer, request, request_serializer, response_deserializer): - multi_callable = channel.unary_stream( - _common.fully_qualified_method(group, method), - request_serializer=request_serializer, - response_deserializer=response_deserializer) - effective_metadata = _effective_metadata(metadata, metadata_transformer) - response_iterator = multi_callable( - request, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return _Rendezvous(None, response_iterator, response_iterator) - - -def _blocking_stream_unary( - channel, group, method, timeout, with_call, protocol_options, metadata, - metadata_transformer, request_iterator, request_serializer, - response_deserializer): - try: + response_future = multi_callable.future( + request, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return _Rendezvous(response_future, None, response_future) + + +def _unary_stream(channel, group, method, timeout, protocol_options, metadata, + metadata_transformer, request, request_serializer, + response_deserializer): + multi_callable = channel.unary_stream( + _common.fully_qualified_method(group, method), + request_serializer=request_serializer, + response_deserializer=response_deserializer) + effective_metadata = _effective_metadata(metadata, metadata_transformer) + response_iterator = multi_callable( + request, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return _Rendezvous(None, response_iterator, response_iterator) + + +def _blocking_stream_unary(channel, group, method, timeout, with_call, + protocol_options, metadata, metadata_transformer, + request_iterator, request_serializer, + response_deserializer): + try: + multi_callable = channel.stream_unary( + _common.fully_qualified_method(group, method), + request_serializer=request_serializer, + response_deserializer=response_deserializer) + effective_metadata = _effective_metadata(metadata, metadata_transformer) + if with_call: + response, call = multi_callable.with_call( + request_iterator, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return response, _Rendezvous(None, None, call) + else: + return multi_callable( + request_iterator, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + except grpc.RpcError as rpc_error_call: + raise _abortion_error(rpc_error_call) + + +def _future_stream_unary(channel, group, method, timeout, protocol_options, + metadata, metadata_transformer, request_iterator, + request_serializer, response_deserializer): multi_callable = channel.stream_unary( _common.fully_qualified_method(group, method), request_serializer=request_serializer, response_deserializer=response_deserializer) effective_metadata = _effective_metadata(metadata, metadata_transformer) - if with_call: - response, call = multi_callable.with_call( - request_iterator, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return response, _Rendezvous(None, None, call) - else: - return multi_callable( - request_iterator, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - except grpc.RpcError as rpc_error_call: - raise _abortion_error(rpc_error_call) - - -def _future_stream_unary( - channel, group, method, timeout, protocol_options, metadata, - metadata_transformer, request_iterator, request_serializer, - response_deserializer): - multi_callable = channel.stream_unary( - _common.fully_qualified_method(group, method), - request_serializer=request_serializer, - response_deserializer=response_deserializer) - effective_metadata = _effective_metadata(metadata, metadata_transformer) - response_future = multi_callable.future( - request_iterator, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return _Rendezvous(response_future, None, response_future) - - -def _stream_stream( - channel, group, method, timeout, protocol_options, metadata, - metadata_transformer, request_iterator, request_serializer, - response_deserializer): - multi_callable = channel.stream_stream( - _common.fully_qualified_method(group, method), - request_serializer=request_serializer, - response_deserializer=response_deserializer) - effective_metadata = _effective_metadata(metadata, metadata_transformer) - response_iterator = multi_callable( - request_iterator, timeout=timeout, metadata=effective_metadata, - credentials=_credentials(protocol_options)) - return _Rendezvous(None, response_iterator, response_iterator) + response_future = multi_callable.future( + request_iterator, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return _Rendezvous(response_future, None, response_future) + + +def _stream_stream(channel, group, method, timeout, protocol_options, metadata, + metadata_transformer, request_iterator, request_serializer, + response_deserializer): + multi_callable = channel.stream_stream( + _common.fully_qualified_method(group, method), + request_serializer=request_serializer, + response_deserializer=response_deserializer) + effective_metadata = _effective_metadata(metadata, metadata_transformer) + response_iterator = multi_callable( + request_iterator, + timeout=timeout, + metadata=effective_metadata, + credentials=_credentials(protocol_options)) + return _Rendezvous(None, response_iterator, response_iterator) class _UnaryUnaryMultiCallable(face.UnaryUnaryMultiCallable): - def __init__( - self, channel, group, method, metadata_transformer, request_serializer, - response_deserializer): - self._channel = channel - self._group = group - self._method = method - self._metadata_transformer = metadata_transformer - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__( - self, request, timeout, metadata=None, with_call=False, - protocol_options=None): - return _blocking_unary_unary( - self._channel, self._group, self._method, timeout, with_call, - protocol_options, metadata, self._metadata_transformer, request, - self._request_serializer, self._response_deserializer) - - def future(self, request, timeout, metadata=None, protocol_options=None): - return _future_unary_unary( - self._channel, self._group, self._method, timeout, protocol_options, - metadata, self._metadata_transformer, request, self._request_serializer, - self._response_deserializer) - - def event( - self, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() + def __init__(self, channel, group, method, metadata_transformer, + request_serializer, response_deserializer): + self._channel = channel + self._group = group + self._method = method + self._metadata_transformer = metadata_transformer + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, + request, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + return _blocking_unary_unary( + self._channel, self._group, self._method, timeout, with_call, + protocol_options, metadata, self._metadata_transformer, request, + self._request_serializer, self._response_deserializer) + + def future(self, request, timeout, metadata=None, protocol_options=None): + return _future_unary_unary( + self._channel, self._group, self._method, timeout, protocol_options, + metadata, self._metadata_transformer, request, + self._request_serializer, self._response_deserializer) + + def event(self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() class _UnaryStreamMultiCallable(face.UnaryStreamMultiCallable): - def __init__( - self, channel, group, method, metadata_transformer, request_serializer, - response_deserializer): - self._channel = channel - self._group = group - self._method = method - self._metadata_transformer = metadata_transformer - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__(self, request, timeout, metadata=None, protocol_options=None): - return _unary_stream( - self._channel, self._group, self._method, timeout, protocol_options, - metadata, self._metadata_transformer, request, self._request_serializer, - self._response_deserializer) - - def event( - self, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() + def __init__(self, channel, group, method, metadata_transformer, + request_serializer, response_deserializer): + self._channel = channel + self._group = group + self._method = method + self._metadata_transformer = metadata_transformer + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, request, timeout, metadata=None, protocol_options=None): + return _unary_stream( + self._channel, self._group, self._method, timeout, protocol_options, + metadata, self._metadata_transformer, request, + self._request_serializer, self._response_deserializer) + + def event(self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() class _StreamUnaryMultiCallable(face.StreamUnaryMultiCallable): - def __init__( - self, channel, group, method, metadata_transformer, request_serializer, - response_deserializer): - self._channel = channel - self._group = group - self._method = method - self._metadata_transformer = metadata_transformer - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__( - self, request_iterator, timeout, metadata=None, with_call=False, - protocol_options=None): - return _blocking_stream_unary( - self._channel, self._group, self._method, timeout, with_call, - protocol_options, metadata, self._metadata_transformer, - request_iterator, self._request_serializer, self._response_deserializer) - - def future( - self, request_iterator, timeout, metadata=None, protocol_options=None): - return _future_stream_unary( - self._channel, self._group, self._method, timeout, protocol_options, - metadata, self._metadata_transformer, request_iterator, - self._request_serializer, self._response_deserializer) - - def event( - self, receiver, abortion_callback, timeout, metadata=None, - protocol_options=None): - raise NotImplementedError() + def __init__(self, channel, group, method, metadata_transformer, + request_serializer, response_deserializer): + self._channel = channel + self._group = group + self._method = method + self._metadata_transformer = metadata_transformer + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, + request_iterator, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + return _blocking_stream_unary( + self._channel, self._group, self._method, timeout, with_call, + protocol_options, metadata, self._metadata_transformer, + request_iterator, self._request_serializer, + self._response_deserializer) + + def future(self, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + return _future_stream_unary( + self._channel, self._group, self._method, timeout, protocol_options, + metadata, self._metadata_transformer, request_iterator, + self._request_serializer, self._response_deserializer) + + def event(self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() class _StreamStreamMultiCallable(face.StreamStreamMultiCallable): - def __init__( - self, channel, group, method, metadata_transformer, request_serializer, - response_deserializer): - self._channel = channel - self._group = group - self._method = method - self._metadata_transformer = metadata_transformer - self._request_serializer = request_serializer - self._response_deserializer = response_deserializer - - def __call__( - self, request_iterator, timeout, metadata=None, protocol_options=None): - return _stream_stream( - self._channel, self._group, self._method, timeout, protocol_options, - metadata, self._metadata_transformer, request_iterator, - self._request_serializer, self._response_deserializer) - - def event( - self, receiver, abortion_callback, timeout, metadata=None, - protocol_options=None): - raise NotImplementedError() + def __init__(self, channel, group, method, metadata_transformer, + request_serializer, response_deserializer): + self._channel = channel + self._group = group + self._method = method + self._metadata_transformer = metadata_transformer + self._request_serializer = request_serializer + self._response_deserializer = response_deserializer + + def __call__(self, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + return _stream_stream( + self._channel, self._group, self._method, timeout, protocol_options, + metadata, self._metadata_transformer, request_iterator, + self._request_serializer, self._response_deserializer) + + def event(self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() class _GenericStub(face.GenericStub): - def __init__( - self, channel, metadata_transformer, request_serializers, - response_deserializers): - self._channel = channel - self._metadata_transformer = metadata_transformer - self._request_serializers = request_serializers or {} - self._response_deserializers = response_deserializers or {} - - def blocking_unary_unary( - self, group, method, request, timeout, metadata=None, - with_call=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _blocking_unary_unary( - self._channel, group, method, timeout, with_call, protocol_options, - metadata, self._metadata_transformer, request, request_serializer, - response_deserializer) - - def future_unary_unary( - self, group, method, request, timeout, metadata=None, - protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _future_unary_unary( - self._channel, group, method, timeout, protocol_options, metadata, - self._metadata_transformer, request, request_serializer, - response_deserializer) - - def inline_unary_stream( - self, group, method, request, timeout, metadata=None, - protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _unary_stream( - self._channel, group, method, timeout, protocol_options, metadata, - self._metadata_transformer, request, request_serializer, - response_deserializer) - - def blocking_stream_unary( - self, group, method, request_iterator, timeout, metadata=None, - with_call=None, protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _blocking_stream_unary( - self._channel, group, method, timeout, with_call, protocol_options, - metadata, self._metadata_transformer, request_iterator, - request_serializer, response_deserializer) - - def future_stream_unary( - self, group, method, request_iterator, timeout, metadata=None, - protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _future_stream_unary( - self._channel, group, method, timeout, protocol_options, metadata, - self._metadata_transformer, request_iterator, request_serializer, - response_deserializer) - - def inline_stream_stream( - self, group, method, request_iterator, timeout, metadata=None, - protocol_options=None): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _stream_stream( - self._channel, group, method, timeout, protocol_options, metadata, - self._metadata_transformer, request_iterator, request_serializer, - response_deserializer) - - def event_unary_unary( - self, group, method, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() - - def event_unary_stream( - self, group, method, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() - - def event_stream_unary( - self, group, method, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() - - def event_stream_stream( - self, group, method, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - raise NotImplementedError() - - def unary_unary(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _UnaryUnaryMultiCallable( - self._channel, group, method, self._metadata_transformer, - request_serializer, response_deserializer) - - def unary_stream(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _UnaryStreamMultiCallable( - self._channel, group, method, self._metadata_transformer, - request_serializer, response_deserializer) - - def stream_unary(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _StreamUnaryMultiCallable( - self._channel, group, method, self._metadata_transformer, - request_serializer, response_deserializer) - - def stream_stream(self, group, method): - request_serializer = self._request_serializers.get((group, method,)) - response_deserializer = self._response_deserializers.get((group, method,)) - return _StreamStreamMultiCallable( - self._channel, group, method, self._metadata_transformer, - request_serializer, response_deserializer) - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - return False + def __init__(self, channel, metadata_transformer, request_serializers, + response_deserializers): + self._channel = channel + self._metadata_transformer = metadata_transformer + self._request_serializers = request_serializers or {} + self._response_deserializers = response_deserializers or {} + + def blocking_unary_unary(self, + group, + method, + request, + timeout, + metadata=None, + with_call=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _blocking_unary_unary(self._channel, group, method, timeout, + with_call, protocol_options, metadata, + self._metadata_transformer, request, + request_serializer, response_deserializer) + + def future_unary_unary(self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _future_unary_unary(self._channel, group, method, timeout, + protocol_options, metadata, + self._metadata_transformer, request, + request_serializer, response_deserializer) + + def inline_unary_stream(self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _unary_stream(self._channel, group, method, timeout, + protocol_options, metadata, + self._metadata_transformer, request, + request_serializer, response_deserializer) + + def blocking_stream_unary(self, + group, + method, + request_iterator, + timeout, + metadata=None, + with_call=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _blocking_stream_unary( + self._channel, group, method, timeout, with_call, protocol_options, + metadata, self._metadata_transformer, request_iterator, + request_serializer, response_deserializer) + + def future_stream_unary(self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _future_stream_unary( + self._channel, group, method, timeout, protocol_options, metadata, + self._metadata_transformer, request_iterator, request_serializer, + response_deserializer) + + def inline_stream_stream(self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _stream_stream(self._channel, group, method, timeout, + protocol_options, metadata, + self._metadata_transformer, request_iterator, + request_serializer, response_deserializer) + + def event_unary_unary(self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() + + def event_unary_stream(self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() + + def event_stream_unary(self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() + + def event_stream_stream(self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + raise NotImplementedError() + + def unary_unary(self, group, method): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _UnaryUnaryMultiCallable( + self._channel, group, method, self._metadata_transformer, + request_serializer, response_deserializer) + + def unary_stream(self, group, method): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _UnaryStreamMultiCallable( + self._channel, group, method, self._metadata_transformer, + request_serializer, response_deserializer) + + def stream_unary(self, group, method): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _StreamUnaryMultiCallable( + self._channel, group, method, self._metadata_transformer, + request_serializer, response_deserializer) + + def stream_stream(self, group, method): + request_serializer = self._request_serializers.get(( + group, + method,)) + response_deserializer = self._response_deserializers.get(( + group, + method,)) + return _StreamStreamMultiCallable( + self._channel, group, method, self._metadata_transformer, + request_serializer, response_deserializer) + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + return False class _DynamicStub(face.DynamicStub): - def __init__(self, generic_stub, group, cardinalities): - self._generic_stub = generic_stub - self._group = group - self._cardinalities = cardinalities - - def __getattr__(self, attr): - method_cardinality = self._cardinalities.get(attr) - if method_cardinality is cardinality.Cardinality.UNARY_UNARY: - return self._generic_stub.unary_unary(self._group, attr) - elif method_cardinality is cardinality.Cardinality.UNARY_STREAM: - return self._generic_stub.unary_stream(self._group, attr) - elif method_cardinality is cardinality.Cardinality.STREAM_UNARY: - return self._generic_stub.stream_unary(self._group, attr) - elif method_cardinality is cardinality.Cardinality.STREAM_STREAM: - return self._generic_stub.stream_stream(self._group, attr) - else: - raise AttributeError('_DynamicStub object has no attribute "%s"!' % attr) - - def __enter__(self): - return self - - def __exit__(self, exc_type, exc_val, exc_tb): - return False - - -def generic_stub( - channel, host, metadata_transformer, request_serializers, - response_deserializers): - return _GenericStub( - channel, metadata_transformer, request_serializers, - response_deserializers) - - -def dynamic_stub( - channel, service, cardinalities, host, metadata_transformer, - request_serializers, response_deserializers): - return _DynamicStub( - _GenericStub( - channel, metadata_transformer, request_serializers, - response_deserializers), - service, cardinalities) + def __init__(self, generic_stub, group, cardinalities): + self._generic_stub = generic_stub + self._group = group + self._cardinalities = cardinalities + + def __getattr__(self, attr): + method_cardinality = self._cardinalities.get(attr) + if method_cardinality is cardinality.Cardinality.UNARY_UNARY: + return self._generic_stub.unary_unary(self._group, attr) + elif method_cardinality is cardinality.Cardinality.UNARY_STREAM: + return self._generic_stub.unary_stream(self._group, attr) + elif method_cardinality is cardinality.Cardinality.STREAM_UNARY: + return self._generic_stub.stream_unary(self._group, attr) + elif method_cardinality is cardinality.Cardinality.STREAM_STREAM: + return self._generic_stub.stream_stream(self._group, attr) + else: + raise AttributeError('_DynamicStub object has no attribute "%s"!' % + attr) + + def __enter__(self): + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + return False + + +def generic_stub(channel, host, metadata_transformer, request_serializers, + response_deserializers): + return _GenericStub(channel, metadata_transformer, request_serializers, + response_deserializers) + + +def dynamic_stub(channel, service, cardinalities, host, metadata_transformer, + request_serializers, response_deserializers): + return _DynamicStub( + _GenericStub(channel, metadata_transformer, request_serializers, + response_deserializers), service, cardinalities) diff --git a/src/python/grpcio/grpc/beta/_connectivity_channel.py b/src/python/grpcio/grpc/beta/_connectivity_channel.py index 61674a70add..39020d2b4ef 100644 --- a/src/python/grpcio/grpc/beta/_connectivity_channel.py +++ b/src/python/grpcio/grpc/beta/_connectivity_channel.py @@ -26,7 +26,6 @@ # 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. - """Affords a connectivity-state-listenable channel.""" import threading @@ -41,116 +40,122 @@ _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE = ( 'Exception calling channel subscription callback!') _LOW_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY = { - state: connectivity for state, connectivity in zip( - _types.ConnectivityState, interfaces.ChannelConnectivity) + state: connectivity + for state, connectivity in zip(_types.ConnectivityState, + interfaces.ChannelConnectivity) } class ConnectivityChannel(object): - def __init__(self, low_channel): - self._lock = threading.Lock() - self._low_channel = low_channel - - self._polling = False - self._connectivity = None - self._try_to_connect = False - self._callbacks_and_connectivities = [] - self._delivering = False - - def _deliveries(self, connectivity): - callbacks_needing_update = [] - for callback_and_connectivity in self._callbacks_and_connectivities: - callback, callback_connectivity = callback_and_connectivity - if callback_connectivity is not connectivity: - callbacks_needing_update.append(callback) - callback_and_connectivity[1] = connectivity - return callbacks_needing_update - - def _deliver(self, initial_connectivity, initial_callbacks): - connectivity = initial_connectivity - callbacks = initial_callbacks - while True: - for callback in callbacks: - callable_util.call_logging_exceptions( - callback, _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE, - connectivity) - with self._lock: - callbacks = self._deliveries(self._connectivity) - if callbacks: - connectivity = self._connectivity - else: - self._delivering = False - return - - def _spawn_delivery(self, connectivity, callbacks): - delivering_thread = threading.Thread( - target=self._deliver, args=(connectivity, callbacks,)) - delivering_thread.start() - self._delivering = True + def __init__(self, low_channel): + self._lock = threading.Lock() + self._low_channel = low_channel - # TODO(issue 3064): Don't poll. - def _poll_connectivity(self, low_channel, initial_try_to_connect): - try_to_connect = initial_try_to_connect - low_connectivity = low_channel.check_connectivity_state(try_to_connect) - with self._lock: - self._connectivity = _LOW_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ - low_connectivity] - callbacks = tuple( - callback for callback, unused_but_known_to_be_none_connectivity - in self._callbacks_and_connectivities) - for callback_and_connectivity in self._callbacks_and_connectivities: - callback_and_connectivity[1] = self._connectivity - if callbacks: - self._spawn_delivery(self._connectivity, callbacks) - completion_queue = _low.CompletionQueue() - while True: - low_channel.watch_connectivity_state( - low_connectivity, time.time() + 0.2, completion_queue, None) - event = completion_queue.next() - with self._lock: - if not self._callbacks_and_connectivities and not self._try_to_connect: - self._polling = False - self._connectivity = None - completion_queue.shutdown() - break - try_to_connect = self._try_to_connect + self._polling = False + self._connectivity = None self._try_to_connect = False - if event.success or try_to_connect: + self._callbacks_and_connectivities = [] + self._delivering = False + + def _deliveries(self, connectivity): + callbacks_needing_update = [] + for callback_and_connectivity in self._callbacks_and_connectivities: + callback, callback_connectivity = callback_and_connectivity + if callback_connectivity is not connectivity: + callbacks_needing_update.append(callback) + callback_and_connectivity[1] = connectivity + return callbacks_needing_update + + def _deliver(self, initial_connectivity, initial_callbacks): + connectivity = initial_connectivity + callbacks = initial_callbacks + while True: + for callback in callbacks: + callable_util.call_logging_exceptions( + callback, _CHANNEL_SUBSCRIPTION_CALLBACK_ERROR_LOG_MESSAGE, + connectivity) + with self._lock: + callbacks = self._deliveries(self._connectivity) + if callbacks: + connectivity = self._connectivity + else: + self._delivering = False + return + + def _spawn_delivery(self, connectivity, callbacks): + delivering_thread = threading.Thread( + target=self._deliver, args=( + connectivity, + callbacks,)) + delivering_thread.start() + self._delivering = True + + # TODO(issue 3064): Don't poll. + def _poll_connectivity(self, low_channel, initial_try_to_connect): + try_to_connect = initial_try_to_connect low_connectivity = low_channel.check_connectivity_state(try_to_connect) with self._lock: - self._connectivity = _LOW_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ - low_connectivity] - if not self._delivering: - callbacks = self._deliveries(self._connectivity) + self._connectivity = _LOW_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ + low_connectivity] + callbacks = tuple( + callback + for callback, unused_but_known_to_be_none_connectivity in + self._callbacks_and_connectivities) + for callback_and_connectivity in self._callbacks_and_connectivities: + callback_and_connectivity[1] = self._connectivity if callbacks: - self._spawn_delivery(self._connectivity, callbacks) - - def subscribe(self, callback, try_to_connect): - with self._lock: - if not self._callbacks_and_connectivities and not self._polling: - polling_thread = threading.Thread( - target=self._poll_connectivity, - args=(self._low_channel, bool(try_to_connect))) - polling_thread.start() - self._polling = True - self._callbacks_and_connectivities.append([callback, None]) - elif not self._delivering and self._connectivity is not None: - self._spawn_delivery(self._connectivity, (callback,)) - self._try_to_connect |= bool(try_to_connect) - self._callbacks_and_connectivities.append( - [callback, self._connectivity]) - else: - self._try_to_connect |= bool(try_to_connect) - self._callbacks_and_connectivities.append([callback, None]) - - def unsubscribe(self, callback): - with self._lock: - for index, (subscribed_callback, unused_connectivity) in enumerate( - self._callbacks_and_connectivities): - if callback == subscribed_callback: - self._callbacks_and_connectivities.pop(index) - break - - def low_channel(self): - return self._low_channel + self._spawn_delivery(self._connectivity, callbacks) + completion_queue = _low.CompletionQueue() + while True: + low_channel.watch_connectivity_state(low_connectivity, + time.time() + 0.2, + completion_queue, None) + event = completion_queue.next() + with self._lock: + if not self._callbacks_and_connectivities and not self._try_to_connect: + self._polling = False + self._connectivity = None + completion_queue.shutdown() + break + try_to_connect = self._try_to_connect + self._try_to_connect = False + if event.success or try_to_connect: + low_connectivity = low_channel.check_connectivity_state( + try_to_connect) + with self._lock: + self._connectivity = _LOW_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ + low_connectivity] + if not self._delivering: + callbacks = self._deliveries(self._connectivity) + if callbacks: + self._spawn_delivery(self._connectivity, callbacks) + + def subscribe(self, callback, try_to_connect): + with self._lock: + if not self._callbacks_and_connectivities and not self._polling: + polling_thread = threading.Thread( + target=self._poll_connectivity, + args=(self._low_channel, bool(try_to_connect))) + polling_thread.start() + self._polling = True + self._callbacks_and_connectivities.append([callback, None]) + elif not self._delivering and self._connectivity is not None: + self._spawn_delivery(self._connectivity, (callback,)) + self._try_to_connect |= bool(try_to_connect) + self._callbacks_and_connectivities.append( + [callback, self._connectivity]) + else: + self._try_to_connect |= bool(try_to_connect) + self._callbacks_and_connectivities.append([callback, None]) + + def unsubscribe(self, callback): + with self._lock: + for index, (subscribed_callback, unused_connectivity + ) in enumerate(self._callbacks_and_connectivities): + if callback == subscribed_callback: + self._callbacks_and_connectivities.pop(index) + break + + def low_channel(self): + return self._low_channel diff --git a/src/python/grpcio/grpc/beta/_server_adaptations.py b/src/python/grpcio/grpc/beta/_server_adaptations.py index cca4a1797a1..bb7c0960d5d 100644 --- a/src/python/grpcio/grpc/beta/_server_adaptations.py +++ b/src/python/grpcio/grpc/beta/_server_adaptations.py @@ -26,7 +26,6 @@ # 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. - """Translates gRPC's server-side API into gRPC's server-side Beta API.""" import collections @@ -47,329 +46,352 @@ _DEFAULT_POOL_SIZE = 8 class _ServerProtocolContext(interfaces.GRPCServicerContext): - def __init__(self, servicer_context): - self._servicer_context = servicer_context + def __init__(self, servicer_context): + self._servicer_context = servicer_context - def peer(self): - return self._servicer_context.peer() + def peer(self): + return self._servicer_context.peer() - def disable_next_response_compression(self): - pass # TODO(https://github.com/grpc/grpc/issues/4078): design, implement. + def disable_next_response_compression(self): + pass # TODO(https://github.com/grpc/grpc/issues/4078): design, implement. class _FaceServicerContext(face.ServicerContext): - def __init__(self, servicer_context): - self._servicer_context = servicer_context + def __init__(self, servicer_context): + self._servicer_context = servicer_context - def is_active(self): - return self._servicer_context.is_active() + def is_active(self): + return self._servicer_context.is_active() - def time_remaining(self): - return self._servicer_context.time_remaining() + def time_remaining(self): + return self._servicer_context.time_remaining() - def add_abortion_callback(self, abortion_callback): - raise NotImplementedError( - 'add_abortion_callback no longer supported server-side!') + def add_abortion_callback(self, abortion_callback): + raise NotImplementedError( + 'add_abortion_callback no longer supported server-side!') - def cancel(self): - self._servicer_context.cancel() + def cancel(self): + self._servicer_context.cancel() - def protocol_context(self): - return _ServerProtocolContext(self._servicer_context) + def protocol_context(self): + return _ServerProtocolContext(self._servicer_context) - def invocation_metadata(self): - return _common.cygrpc_metadata( - self._servicer_context.invocation_metadata()) + def invocation_metadata(self): + return _common.cygrpc_metadata( + self._servicer_context.invocation_metadata()) - def initial_metadata(self, initial_metadata): - self._servicer_context.send_initial_metadata(initial_metadata) + def initial_metadata(self, initial_metadata): + self._servicer_context.send_initial_metadata(initial_metadata) - def terminal_metadata(self, terminal_metadata): - self._servicer_context.set_terminal_metadata(terminal_metadata) + def terminal_metadata(self, terminal_metadata): + self._servicer_context.set_terminal_metadata(terminal_metadata) - def code(self, code): - self._servicer_context.set_code(code) + def code(self, code): + self._servicer_context.set_code(code) - def details(self, details): - self._servicer_context.set_details(details) + def details(self, details): + self._servicer_context.set_details(details) def _adapt_unary_request_inline(unary_request_inline): - def adaptation(request, servicer_context): - return unary_request_inline(request, _FaceServicerContext(servicer_context)) - return adaptation + + def adaptation(request, servicer_context): + return unary_request_inline(request, + _FaceServicerContext(servicer_context)) + + return adaptation def _adapt_stream_request_inline(stream_request_inline): - def adaptation(request_iterator, servicer_context): - return stream_request_inline( - request_iterator, _FaceServicerContext(servicer_context)) - return adaptation + + def adaptation(request_iterator, servicer_context): + return stream_request_inline(request_iterator, + _FaceServicerContext(servicer_context)) + + return adaptation class _Callback(stream.Consumer): - def __init__(self): - self._condition = threading.Condition() - self._values = [] - self._terminated = False - self._cancelled = False - - def consume(self, value): - with self._condition: - self._values.append(value) - self._condition.notify_all() - - def terminate(self): - with self._condition: - self._terminated = True - self._condition.notify_all() - - def consume_and_terminate(self, value): - with self._condition: - self._values.append(value) - self._terminated = True - self._condition.notify_all() - - def cancel(self): - with self._condition: - self._cancelled = True - self._condition.notify_all() - - def draw_one_value(self): - with self._condition: - while True: - if self._cancelled: - raise abandonment.Abandoned() - elif self._values: - return self._values.pop(0) - elif self._terminated: - return None - else: - self._condition.wait() - - def draw_all_values(self): - with self._condition: - while True: - if self._cancelled: - raise abandonment.Abandoned() - elif self._terminated: - all_values = tuple(self._values) - self._values = None - return all_values - else: - self._condition.wait() + def __init__(self): + self._condition = threading.Condition() + self._values = [] + self._terminated = False + self._cancelled = False + + def consume(self, value): + with self._condition: + self._values.append(value) + self._condition.notify_all() + + def terminate(self): + with self._condition: + self._terminated = True + self._condition.notify_all() + + def consume_and_terminate(self, value): + with self._condition: + self._values.append(value) + self._terminated = True + self._condition.notify_all() + + def cancel(self): + with self._condition: + self._cancelled = True + self._condition.notify_all() + + def draw_one_value(self): + with self._condition: + while True: + if self._cancelled: + raise abandonment.Abandoned() + elif self._values: + return self._values.pop(0) + elif self._terminated: + return None + else: + self._condition.wait() + + def draw_all_values(self): + with self._condition: + while True: + if self._cancelled: + raise abandonment.Abandoned() + elif self._terminated: + all_values = tuple(self._values) + self._values = None + return all_values + else: + self._condition.wait() def _run_request_pipe_thread(request_iterator, request_consumer, servicer_context): - thread_joined = threading.Event() - def pipe_requests(): - for request in request_iterator: - if not servicer_context.is_active() or thread_joined.is_set(): - return - request_consumer.consume(request) - if not servicer_context.is_active() or thread_joined.is_set(): - return - request_consumer.terminate() + thread_joined = threading.Event() + + def pipe_requests(): + for request in request_iterator: + if not servicer_context.is_active() or thread_joined.is_set(): + return + request_consumer.consume(request) + if not servicer_context.is_active() or thread_joined.is_set(): + return + request_consumer.terminate() - def stop_request_pipe(timeout): - thread_joined.set() + def stop_request_pipe(timeout): + thread_joined.set() - request_pipe_thread = _common.CleanupThread( - stop_request_pipe, target=pipe_requests) - request_pipe_thread.start() + request_pipe_thread = _common.CleanupThread( + stop_request_pipe, target=pipe_requests) + request_pipe_thread.start() def _adapt_unary_unary_event(unary_unary_event): - def adaptation(request, servicer_context): - callback = _Callback() - if not servicer_context.add_callback(callback.cancel): - raise abandonment.Abandoned() - unary_unary_event( - request, callback.consume_and_terminate, - _FaceServicerContext(servicer_context)) - return callback.draw_all_values()[0] - return adaptation + + def adaptation(request, servicer_context): + callback = _Callback() + if not servicer_context.add_callback(callback.cancel): + raise abandonment.Abandoned() + unary_unary_event(request, callback.consume_and_terminate, + _FaceServicerContext(servicer_context)) + return callback.draw_all_values()[0] + + return adaptation def _adapt_unary_stream_event(unary_stream_event): - def adaptation(request, servicer_context): - callback = _Callback() - if not servicer_context.add_callback(callback.cancel): - raise abandonment.Abandoned() - unary_stream_event( - request, callback, _FaceServicerContext(servicer_context)) - while True: - response = callback.draw_one_value() - if response is None: - return - else: - yield response - return adaptation + + def adaptation(request, servicer_context): + callback = _Callback() + if not servicer_context.add_callback(callback.cancel): + raise abandonment.Abandoned() + unary_stream_event(request, callback, + _FaceServicerContext(servicer_context)) + while True: + response = callback.draw_one_value() + if response is None: + return + else: + yield response + + return adaptation def _adapt_stream_unary_event(stream_unary_event): - def adaptation(request_iterator, servicer_context): - callback = _Callback() - if not servicer_context.add_callback(callback.cancel): - raise abandonment.Abandoned() - request_consumer = stream_unary_event( - callback.consume_and_terminate, _FaceServicerContext(servicer_context)) - _run_request_pipe_thread( - request_iterator, request_consumer, servicer_context) - return callback.draw_all_values()[0] - return adaptation + + def adaptation(request_iterator, servicer_context): + callback = _Callback() + if not servicer_context.add_callback(callback.cancel): + raise abandonment.Abandoned() + request_consumer = stream_unary_event( + callback.consume_and_terminate, + _FaceServicerContext(servicer_context)) + _run_request_pipe_thread(request_iterator, request_consumer, + servicer_context) + return callback.draw_all_values()[0] + + return adaptation def _adapt_stream_stream_event(stream_stream_event): - def adaptation(request_iterator, servicer_context): - callback = _Callback() - if not servicer_context.add_callback(callback.cancel): - raise abandonment.Abandoned() - request_consumer = stream_stream_event( - callback, _FaceServicerContext(servicer_context)) - _run_request_pipe_thread( - request_iterator, request_consumer, servicer_context) - while True: - response = callback.draw_one_value() - if response is None: - return - else: - yield response - return adaptation + + def adaptation(request_iterator, servicer_context): + callback = _Callback() + if not servicer_context.add_callback(callback.cancel): + raise abandonment.Abandoned() + request_consumer = stream_stream_event( + callback, _FaceServicerContext(servicer_context)) + _run_request_pipe_thread(request_iterator, request_consumer, + servicer_context) + while True: + response = callback.draw_one_value() + if response is None: + return + else: + yield response + + return adaptation class _SimpleMethodHandler( - collections.namedtuple( - '_MethodHandler', - ('request_streaming', 'response_streaming', 'request_deserializer', - 'response_serializer', 'unary_unary', 'unary_stream', 'stream_unary', - 'stream_stream',)), - grpc.RpcMethodHandler): - pass - - -def _simple_method_handler( - implementation, request_deserializer, response_serializer): - if implementation.style is style.Service.INLINE: - if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: - return _SimpleMethodHandler( - False, False, request_deserializer, response_serializer, - _adapt_unary_request_inline(implementation.unary_unary_inline), None, - None, None) - elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: - return _SimpleMethodHandler( - False, True, request_deserializer, response_serializer, None, - _adapt_unary_request_inline(implementation.unary_stream_inline), None, - None) - elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: - return _SimpleMethodHandler( - True, False, request_deserializer, response_serializer, None, None, - _adapt_stream_request_inline(implementation.stream_unary_inline), - None) - elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM: - return _SimpleMethodHandler( - True, True, request_deserializer, response_serializer, None, None, - None, - _adapt_stream_request_inline(implementation.stream_stream_inline)) - elif implementation.style is style.Service.EVENT: - if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: - return _SimpleMethodHandler( - False, False, request_deserializer, response_serializer, - _adapt_unary_unary_event(implementation.unary_unary_event), None, - None, None) - elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: - return _SimpleMethodHandler( - False, True, request_deserializer, response_serializer, None, - _adapt_unary_stream_event(implementation.unary_stream_event), None, - None) - elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: - return _SimpleMethodHandler( - True, False, request_deserializer, response_serializer, None, None, - _adapt_stream_unary_event(implementation.stream_unary_event), None) - elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM: - return _SimpleMethodHandler( - True, True, request_deserializer, response_serializer, None, None, - None, _adapt_stream_stream_event(implementation.stream_stream_event)) + collections.namedtuple('_MethodHandler', ( + 'request_streaming', + 'response_streaming', + 'request_deserializer', + 'response_serializer', + 'unary_unary', + 'unary_stream', + 'stream_unary', + 'stream_stream',)), grpc.RpcMethodHandler): + pass + + +def _simple_method_handler(implementation, request_deserializer, + response_serializer): + if implementation.style is style.Service.INLINE: + if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: + return _SimpleMethodHandler( + False, False, request_deserializer, response_serializer, + _adapt_unary_request_inline(implementation.unary_unary_inline), + None, None, None) + elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: + return _SimpleMethodHandler( + False, True, request_deserializer, response_serializer, None, + _adapt_unary_request_inline(implementation.unary_stream_inline), + None, None) + elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: + return _SimpleMethodHandler(True, False, request_deserializer, + response_serializer, None, None, + _adapt_stream_request_inline( + implementation.stream_unary_inline), + None) + elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM: + return _SimpleMethodHandler( + True, True, request_deserializer, response_serializer, None, + None, None, + _adapt_stream_request_inline( + implementation.stream_stream_inline)) + elif implementation.style is style.Service.EVENT: + if implementation.cardinality is cardinality.Cardinality.UNARY_UNARY: + return _SimpleMethodHandler( + False, False, request_deserializer, response_serializer, + _adapt_unary_unary_event(implementation.unary_unary_event), + None, None, None) + elif implementation.cardinality is cardinality.Cardinality.UNARY_STREAM: + return _SimpleMethodHandler( + False, True, request_deserializer, response_serializer, None, + _adapt_unary_stream_event(implementation.unary_stream_event), + None, None) + elif implementation.cardinality is cardinality.Cardinality.STREAM_UNARY: + return _SimpleMethodHandler( + True, False, request_deserializer, response_serializer, None, + None, + _adapt_stream_unary_event(implementation.stream_unary_event), + None) + elif implementation.cardinality is cardinality.Cardinality.STREAM_STREAM: + return _SimpleMethodHandler( + True, True, request_deserializer, response_serializer, None, + None, None, + _adapt_stream_stream_event(implementation.stream_stream_event)) def _flatten_method_pair_map(method_pair_map): - method_pair_map = method_pair_map or {} - flat_map = {} - for method_pair in method_pair_map: - method = _common.fully_qualified_method(method_pair[0], method_pair[1]) - flat_map[method] = method_pair_map[method_pair] - return flat_map + method_pair_map = method_pair_map or {} + flat_map = {} + for method_pair in method_pair_map: + method = _common.fully_qualified_method(method_pair[0], method_pair[1]) + flat_map[method] = method_pair_map[method_pair] + return flat_map class _GenericRpcHandler(grpc.GenericRpcHandler): - def __init__( - self, method_implementations, multi_method_implementation, - request_deserializers, response_serializers): - self._method_implementations = _flatten_method_pair_map( - method_implementations) - self._request_deserializers = _flatten_method_pair_map( - request_deserializers) - self._response_serializers = _flatten_method_pair_map( - response_serializers) - self._multi_method_implementation = multi_method_implementation - - def service(self, handler_call_details): - method_implementation = self._method_implementations.get( - handler_call_details.method) - if method_implementation is not None: - return _simple_method_handler( - method_implementation, - self._request_deserializers.get(handler_call_details.method), - self._response_serializers.get(handler_call_details.method)) - elif self._multi_method_implementation is None: - return None - else: - try: - return None #TODO(nathaniel): call the multimethod. - except face.NoSuchMethodError: - return None + def __init__(self, method_implementations, multi_method_implementation, + request_deserializers, response_serializers): + self._method_implementations = _flatten_method_pair_map( + method_implementations) + self._request_deserializers = _flatten_method_pair_map( + request_deserializers) + self._response_serializers = _flatten_method_pair_map( + response_serializers) + self._multi_method_implementation = multi_method_implementation + + def service(self, handler_call_details): + method_implementation = self._method_implementations.get( + handler_call_details.method) + if method_implementation is not None: + return _simple_method_handler( + method_implementation, + self._request_deserializers.get(handler_call_details.method), + self._response_serializers.get(handler_call_details.method)) + elif self._multi_method_implementation is None: + return None + else: + try: + return None #TODO(nathaniel): call the multimethod. + except face.NoSuchMethodError: + return None class _Server(interfaces.Server): - def __init__(self, server): - self._server = server + def __init__(self, server): + self._server = server - def add_insecure_port(self, address): - return self._server.add_insecure_port(address) + def add_insecure_port(self, address): + return self._server.add_insecure_port(address) - def add_secure_port(self, address, server_credentials): - return self._server.add_secure_port(address, server_credentials) + def add_secure_port(self, address, server_credentials): + return self._server.add_secure_port(address, server_credentials) - def start(self): - self._server.start() + def start(self): + self._server.start() - def stop(self, grace): - return self._server.stop(grace) + def stop(self, grace): + return self._server.stop(grace) - def __enter__(self): - self._server.start() - return self + def __enter__(self): + self._server.start() + return self - def __exit__(self, exc_type, exc_val, exc_tb): - self._server.stop(None) - return False + def __exit__(self, exc_type, exc_val, exc_tb): + self._server.stop(None) + return False -def server( - service_implementations, multi_method_implementation, request_deserializers, - response_serializers, thread_pool, thread_pool_size): - generic_rpc_handler = _GenericRpcHandler( - service_implementations, multi_method_implementation, - request_deserializers, response_serializers) - if thread_pool is None: - effective_thread_pool = logging_pool.pool( - _DEFAULT_POOL_SIZE if thread_pool_size is None else thread_pool_size) - else: - effective_thread_pool = thread_pool - return _Server( - grpc.server(effective_thread_pool, handlers=(generic_rpc_handler,))) +def server(service_implementations, multi_method_implementation, + request_deserializers, response_serializers, thread_pool, + thread_pool_size): + generic_rpc_handler = _GenericRpcHandler( + service_implementations, multi_method_implementation, + request_deserializers, response_serializers) + if thread_pool is None: + effective_thread_pool = logging_pool.pool(_DEFAULT_POOL_SIZE + if thread_pool_size is None + else thread_pool_size) + else: + effective_thread_pool = thread_pool + return _Server( + grpc.server( + effective_thread_pool, handlers=(generic_rpc_handler,))) diff --git a/src/python/grpcio/grpc/beta/implementations.py b/src/python/grpcio/grpc/beta/implementations.py index ab25fd5eec7..70938522781 100644 --- a/src/python/grpcio/grpc/beta/implementations.py +++ b/src/python/grpcio/grpc/beta/implementations.py @@ -26,7 +26,6 @@ # 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. - """Entry points into the Beta API of gRPC Python.""" # threading is referenced from specification in this module. @@ -43,7 +42,6 @@ from grpc.beta import interfaces from grpc.framework.common import cardinality # pylint: disable=unused-import from grpc.framework.interfaces.face import face # pylint: disable=unused-import - ChannelCredentials = grpc.ChannelCredentials ssl_channel_credentials = grpc.ssl_channel_credentials CallCredentials = grpc.CallCredentials @@ -51,7 +49,7 @@ metadata_call_credentials = grpc.metadata_call_credentials def google_call_credentials(credentials): - """Construct CallCredentials from GoogleCredentials. + """Construct CallCredentials from GoogleCredentials. Args: credentials: A GoogleCredentials object from the oauth2client library. @@ -59,7 +57,8 @@ def google_call_credentials(credentials): Returns: A CallCredentials object for use in a GRPCCallOptions object. """ - return metadata_call_credentials(_auth.GoogleCallCredentials(credentials)) + return metadata_call_credentials(_auth.GoogleCallCredentials(credentials)) + access_token_call_credentials = grpc.access_token_call_credentials composite_call_credentials = grpc.composite_call_credentials @@ -67,18 +66,18 @@ composite_channel_credentials = grpc.composite_channel_credentials class Channel(object): - """A channel to a remote host through which RPCs may be conducted. + """A channel to a remote host through which RPCs may be conducted. Only the "subscribe" and "unsubscribe" methods are supported for application use. This class' instance constructor and all other attributes are unsupported. """ - def __init__(self, channel): - self._channel = channel + def __init__(self, channel): + self._channel = channel - def subscribe(self, callback, try_to_connect=None): - """Subscribes to this Channel's connectivity. + def subscribe(self, callback, try_to_connect=None): + """Subscribes to this Channel's connectivity. Args: callback: A callable to be invoked and passed an @@ -90,20 +89,20 @@ class Channel(object): attempt to connect if it is not already connected and ready to conduct RPCs. """ - self._channel.subscribe(callback, try_to_connect=try_to_connect) + self._channel.subscribe(callback, try_to_connect=try_to_connect) - def unsubscribe(self, callback): - """Unsubscribes a callback from this Channel's connectivity. + def unsubscribe(self, callback): + """Unsubscribes a callback from this Channel's connectivity. Args: callback: A callable previously registered with this Channel from having been passed to its "subscribe" method. """ - self._channel.unsubscribe(callback) + self._channel.unsubscribe(callback) def insecure_channel(host, port): - """Creates an insecure Channel to a remote host. + """Creates an insecure Channel to a remote host. Args: host: The name of the remote host to which to connect. @@ -113,13 +112,13 @@ def insecure_channel(host, port): Returns: A Channel to the remote host through which RPCs may be conducted. """ - channel = grpc.insecure_channel( - host if port is None else '%s:%d' % (host, port)) - return Channel(channel) + channel = grpc.insecure_channel(host + if port is None else '%s:%d' % (host, port)) + return Channel(channel) def secure_channel(host, port, channel_credentials): - """Creates a secure Channel to a remote host. + """Creates a secure Channel to a remote host. Args: host: The name of the remote host to which to connect. @@ -130,37 +129,39 @@ def secure_channel(host, port, channel_credentials): Returns: A secure Channel to the remote host through which RPCs may be conducted. """ - channel = grpc.secure_channel( - host if port is None else '%s:%d' % (host, port), channel_credentials) - return Channel(channel) + channel = grpc.secure_channel(host if port is None else + '%s:%d' % (host, port), channel_credentials) + return Channel(channel) class StubOptions(object): - """A value encapsulating the various options for creation of a Stub. + """A value encapsulating the various options for creation of a Stub. This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions. """ - def __init__( - self, host, request_serializers, response_deserializers, - metadata_transformer, thread_pool, thread_pool_size): - self.host = host - self.request_serializers = request_serializers - self.response_deserializers = response_deserializers - self.metadata_transformer = metadata_transformer - self.thread_pool = thread_pool - self.thread_pool_size = thread_pool_size + def __init__(self, host, request_serializers, response_deserializers, + metadata_transformer, thread_pool, thread_pool_size): + self.host = host + self.request_serializers = request_serializers + self.response_deserializers = response_deserializers + self.metadata_transformer = metadata_transformer + self.thread_pool = thread_pool + self.thread_pool_size = thread_pool_size -_EMPTY_STUB_OPTIONS = StubOptions( - None, None, None, None, None, None) +_EMPTY_STUB_OPTIONS = StubOptions(None, None, None, None, None, None) -def stub_options( - host=None, request_serializers=None, response_deserializers=None, - metadata_transformer=None, thread_pool=None, thread_pool_size=None): - """Creates a StubOptions value to be passed at stub creation. + +def stub_options(host=None, + request_serializers=None, + response_deserializers=None, + metadata_transformer=None, + thread_pool=None, + thread_pool_size=None): + """Creates a StubOptions value to be passed at stub creation. All parameters are optional and should always be passed by keyword. @@ -180,13 +181,12 @@ def stub_options( Returns: A StubOptions value created from the passed parameters. """ - return StubOptions( - host, request_serializers, response_deserializers, - metadata_transformer, thread_pool, thread_pool_size) + return StubOptions(host, request_serializers, response_deserializers, + metadata_transformer, thread_pool, thread_pool_size) def generic_stub(channel, options=None): - """Creates a face.GenericStub on which RPCs can be made. + """Creates a face.GenericStub on which RPCs can be made. Args: channel: A Channel for use by the created stub. @@ -195,16 +195,17 @@ def generic_stub(channel, options=None): Returns: A face.GenericStub on which RPCs can be made. """ - effective_options = _EMPTY_STUB_OPTIONS if options is None else options - return _client_adaptations.generic_stub( - channel._channel, # pylint: disable=protected-access - effective_options.host, effective_options.metadata_transformer, - effective_options.request_serializers, - effective_options.response_deserializers) + effective_options = _EMPTY_STUB_OPTIONS if options is None else options + return _client_adaptations.generic_stub( + channel._channel, # pylint: disable=protected-access + effective_options.host, + effective_options.metadata_transformer, + effective_options.request_serializers, + effective_options.response_deserializers) def dynamic_stub(channel, service, cardinalities, options=None): - """Creates a face.DynamicStub with which RPCs can be invoked. + """Creates a face.DynamicStub with which RPCs can be invoked. Args: channel: A Channel for the returned face.DynamicStub to use. @@ -217,13 +218,15 @@ def dynamic_stub(channel, service, cardinalities, options=None): Returns: A face.DynamicStub with which RPCs can be invoked. """ - effective_options = StubOptions() if options is None else options - return _client_adaptations.dynamic_stub( - channel._channel, # pylint: disable=protected-access - service, cardinalities, effective_options.host, - effective_options.metadata_transformer, - effective_options.request_serializers, - effective_options.response_deserializers) + effective_options = StubOptions() if options is None else options + return _client_adaptations.dynamic_stub( + channel._channel, # pylint: disable=protected-access + service, + cardinalities, + effective_options.host, + effective_options.metadata_transformer, + effective_options.request_serializers, + effective_options.response_deserializers) ServerCredentials = grpc.ServerCredentials @@ -231,34 +234,36 @@ ssl_server_credentials = grpc.ssl_server_credentials class ServerOptions(object): - """A value encapsulating the various options for creation of a Server. + """A value encapsulating the various options for creation of a Server. This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions. """ - def __init__( - self, multi_method_implementation, request_deserializers, - response_serializers, thread_pool, thread_pool_size, default_timeout, - maximum_timeout): - self.multi_method_implementation = multi_method_implementation - self.request_deserializers = request_deserializers - self.response_serializers = response_serializers - self.thread_pool = thread_pool - self.thread_pool_size = thread_pool_size - self.default_timeout = default_timeout - self.maximum_timeout = maximum_timeout + def __init__(self, multi_method_implementation, request_deserializers, + response_serializers, thread_pool, thread_pool_size, + default_timeout, maximum_timeout): + self.multi_method_implementation = multi_method_implementation + self.request_deserializers = request_deserializers + self.response_serializers = response_serializers + self.thread_pool = thread_pool + self.thread_pool_size = thread_pool_size + self.default_timeout = default_timeout + self.maximum_timeout = maximum_timeout + -_EMPTY_SERVER_OPTIONS = ServerOptions( - None, None, None, None, None, None, None) +_EMPTY_SERVER_OPTIONS = ServerOptions(None, None, None, None, None, None, None) -def server_options( - multi_method_implementation=None, request_deserializers=None, - response_serializers=None, thread_pool=None, thread_pool_size=None, - default_timeout=None, maximum_timeout=None): - """Creates a ServerOptions value to be passed at server creation. +def server_options(multi_method_implementation=None, + request_deserializers=None, + response_serializers=None, + thread_pool=None, + thread_pool_size=None, + default_timeout=None, + maximum_timeout=None): + """Creates a ServerOptions value to be passed at server creation. All parameters are optional and should always be passed by keyword. @@ -282,13 +287,13 @@ def server_options( Returns: A StubOptions value created from the passed parameters. """ - return ServerOptions( - multi_method_implementation, request_deserializers, response_serializers, - thread_pool, thread_pool_size, default_timeout, maximum_timeout) + return ServerOptions(multi_method_implementation, request_deserializers, + response_serializers, thread_pool, thread_pool_size, + default_timeout, maximum_timeout) def server(service_implementations, options=None): - """Creates an interfaces.Server with which RPCs can be serviced. + """Creates an interfaces.Server with which RPCs can be serviced. Args: service_implementations: A dictionary from service name-method name pair to @@ -299,9 +304,9 @@ def server(service_implementations, options=None): Returns: An interfaces.Server with which RPCs can be serviced. """ - effective_options = _EMPTY_SERVER_OPTIONS if options is None else options - return _server_adaptations.server( - service_implementations, effective_options.multi_method_implementation, - effective_options.request_deserializers, - effective_options.response_serializers, effective_options.thread_pool, - effective_options.thread_pool_size) + effective_options = _EMPTY_SERVER_OPTIONS if options is None else options + return _server_adaptations.server( + service_implementations, effective_options.multi_method_implementation, + effective_options.request_deserializers, + effective_options.response_serializers, effective_options.thread_pool, + effective_options.thread_pool_size) diff --git a/src/python/grpcio/grpc/beta/interfaces.py b/src/python/grpcio/grpc/beta/interfaces.py index 90f6bbbfcc1..361d1bcffea 100644 --- a/src/python/grpcio/grpc/beta/interfaces.py +++ b/src/python/grpcio/grpc/beta/interfaces.py @@ -26,7 +26,6 @@ # 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. - """Constants and interfaces of the Beta API of gRPC Python.""" import abc @@ -43,21 +42,21 @@ StatusCode = grpc.StatusCode class GRPCCallOptions(object): - """A value encapsulating gRPC-specific options passed on RPC invocation. + """A value encapsulating gRPC-specific options passed on RPC invocation. This class and its instances have no supported interface - it exists to define the type of its instances and its instances exist to be passed to other functions. """ - def __init__(self, disable_compression, subcall_of, credentials): - self.disable_compression = disable_compression - self.subcall_of = subcall_of - self.credentials = credentials + def __init__(self, disable_compression, subcall_of, credentials): + self.disable_compression = disable_compression + self.subcall_of = subcall_of + self.credentials = credentials def grpc_call_options(disable_compression=False, credentials=None): - """Creates a GRPCCallOptions value to be passed at RPC invocation. + """Creates a GRPCCallOptions value to be passed at RPC invocation. All parameters are optional and should always be passed by keyword. @@ -67,7 +66,8 @@ def grpc_call_options(disable_compression=False, credentials=None): request-unary RPCs. credentials: A CallCredentials object to use for the invoked RPC. """ - return GRPCCallOptions(disable_compression, None, credentials) + return GRPCCallOptions(disable_compression, None, credentials) + GRPCAuthMetadataContext = grpc.AuthMetadataContext GRPCAuthMetadataPluginCallback = grpc.AuthMetadataPluginCallback @@ -75,38 +75,38 @@ GRPCAuthMetadataPlugin = grpc.AuthMetadataPlugin class GRPCServicerContext(six.with_metaclass(abc.ABCMeta)): - """Exposes gRPC-specific options and behaviors to code servicing RPCs.""" + """Exposes gRPC-specific options and behaviors to code servicing RPCs.""" - @abc.abstractmethod - def peer(self): - """Identifies the peer that invoked the RPC being serviced. + @abc.abstractmethod + def peer(self): + """Identifies the peer that invoked the RPC being serviced. Returns: A string identifying the peer that invoked the RPC being serviced. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def disable_next_response_compression(self): - """Disables compression of the next response passed by the application.""" - raise NotImplementedError() + @abc.abstractmethod + def disable_next_response_compression(self): + """Disables compression of the next response passed by the application.""" + raise NotImplementedError() class GRPCInvocationContext(six.with_metaclass(abc.ABCMeta)): - """Exposes gRPC-specific options and behaviors to code invoking RPCs.""" + """Exposes gRPC-specific options and behaviors to code invoking RPCs.""" - @abc.abstractmethod - def disable_next_request_compression(self): - """Disables compression of the next request passed by the application.""" - raise NotImplementedError() + @abc.abstractmethod + def disable_next_request_compression(self): + """Disables compression of the next request passed by the application.""" + raise NotImplementedError() class Server(six.with_metaclass(abc.ABCMeta)): - """Services RPCs.""" + """Services RPCs.""" - @abc.abstractmethod - def add_insecure_port(self, address): - """Reserves a port for insecure RPC service once this Server becomes active. + @abc.abstractmethod + def add_insecure_port(self, address): + """Reserves a port for insecure RPC service once this Server becomes active. This method may only be called before calling this Server's start method is called. @@ -120,11 +120,11 @@ class Server(six.with_metaclass(abc.ABCMeta)): in the passed address, but will likely be different if the port number contained in the passed address was zero. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_secure_port(self, address, server_credentials): - """Reserves a port for secure RPC service after this Server becomes active. + @abc.abstractmethod + def add_secure_port(self, address, server_credentials): + """Reserves a port for secure RPC service after this Server becomes active. This method may only be called before calling this Server's start method is called. @@ -139,20 +139,20 @@ class Server(six.with_metaclass(abc.ABCMeta)): in the passed address, but will likely be different if the port number contained in the passed address was zero. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def start(self): - """Starts this Server's service of RPCs. + @abc.abstractmethod + def start(self): + """Starts this Server's service of RPCs. This method may only be called while the server is not serving RPCs (i.e. it is not idempotent). """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stop(self, grace): - """Stops this Server's service of RPCs. + @abc.abstractmethod + def stop(self, grace): + """Stops this Server's service of RPCs. All calls to this method immediately stop service of new RPCs. When existing RPCs are aborted is controlled by the grace period parameter passed to this @@ -177,4 +177,4 @@ class Server(six.with_metaclass(abc.ABCMeta)): at the time it was stopped or if all RPCs that it had underway completed very early in the grace period). """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio/grpc/beta/utilities.py b/src/python/grpcio/grpc/beta/utilities.py index fb07a765795..60525350a7c 100644 --- a/src/python/grpcio/grpc/beta/utilities.py +++ b/src/python/grpcio/grpc/beta/utilities.py @@ -26,7 +26,6 @@ # 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. - """Utilities for the gRPC Python Beta API.""" import threading @@ -44,107 +43,107 @@ _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE = ( class _ChannelReadyFuture(future.Future): - def __init__(self, channel): - self._condition = threading.Condition() - self._channel = channel - - self._matured = False - self._cancelled = False - self._done_callbacks = [] - - def _block(self, timeout): - until = None if timeout is None else time.time() + timeout - with self._condition: - while True: - if self._cancelled: - raise future.CancelledError() - elif self._matured: - return - else: - if until is None: - self._condition.wait() - else: - remaining = until - time.time() - if remaining < 0: - raise future.TimeoutError() + def __init__(self, channel): + self._condition = threading.Condition() + self._channel = channel + + self._matured = False + self._cancelled = False + self._done_callbacks = [] + + def _block(self, timeout): + until = None if timeout is None else time.time() + timeout + with self._condition: + while True: + if self._cancelled: + raise future.CancelledError() + elif self._matured: + return + else: + if until is None: + self._condition.wait() + else: + remaining = until - time.time() + if remaining < 0: + raise future.TimeoutError() + else: + self._condition.wait(timeout=remaining) + + def _update(self, connectivity): + with self._condition: + if (not self._cancelled and + connectivity is interfaces.ChannelConnectivity.READY): + self._matured = True + self._channel.unsubscribe(self._update) + self._condition.notify_all() + done_callbacks = tuple(self._done_callbacks) + self._done_callbacks = None + else: + return + + for done_callback in done_callbacks: + callable_util.call_logging_exceptions( + done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) + + def cancel(self): + with self._condition: + if not self._matured: + self._cancelled = True + self._channel.unsubscribe(self._update) + self._condition.notify_all() + done_callbacks = tuple(self._done_callbacks) + self._done_callbacks = None else: - self._condition.wait(timeout=remaining) - - def _update(self, connectivity): - with self._condition: - if (not self._cancelled and - connectivity is interfaces.ChannelConnectivity.READY): - self._matured = True - self._channel.unsubscribe(self._update) - self._condition.notify_all() - done_callbacks = tuple(self._done_callbacks) - self._done_callbacks = None - else: - return - - for done_callback in done_callbacks: - callable_util.call_logging_exceptions( - done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) - - def cancel(self): - with self._condition: - if not self._matured: - self._cancelled = True - self._channel.unsubscribe(self._update) - self._condition.notify_all() - done_callbacks = tuple(self._done_callbacks) - self._done_callbacks = None - else: - return False - - for done_callback in done_callbacks: - callable_util.call_logging_exceptions( - done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) - - def cancelled(self): - with self._condition: - return self._cancelled - - def running(self): - with self._condition: - return not self._cancelled and not self._matured - - def done(self): - with self._condition: - return self._cancelled or self._matured - - def result(self, timeout=None): - self._block(timeout) - return None - - def exception(self, timeout=None): - self._block(timeout) - return None - - def traceback(self, timeout=None): - self._block(timeout) - return None - - def add_done_callback(self, fn): - with self._condition: - if not self._cancelled and not self._matured: - self._done_callbacks.append(fn) - return - - fn(self) - - def start(self): - with self._condition: - self._channel.subscribe(self._update, try_to_connect=True) - - def __del__(self): - with self._condition: - if not self._cancelled and not self._matured: - self._channel.unsubscribe(self._update) + return False + + for done_callback in done_callbacks: + callable_util.call_logging_exceptions( + done_callback, _DONE_CALLBACK_EXCEPTION_LOG_MESSAGE, self) + + def cancelled(self): + with self._condition: + return self._cancelled + + def running(self): + with self._condition: + return not self._cancelled and not self._matured + + def done(self): + with self._condition: + return self._cancelled or self._matured + + def result(self, timeout=None): + self._block(timeout) + return None + + def exception(self, timeout=None): + self._block(timeout) + return None + + def traceback(self, timeout=None): + self._block(timeout) + return None + + def add_done_callback(self, fn): + with self._condition: + if not self._cancelled and not self._matured: + self._done_callbacks.append(fn) + return + + fn(self) + + def start(self): + with self._condition: + self._channel.subscribe(self._update, try_to_connect=True) + + def __del__(self): + with self._condition: + if not self._cancelled and not self._matured: + self._channel.unsubscribe(self._update) def channel_ready_future(channel): - """Creates a future.Future tracking when an implementations.Channel is ready. + """Creates a future.Future tracking when an implementations.Channel is ready. Cancelling the returned future.Future does not tell the given implementations.Channel to abandon attempts it may have been making to @@ -158,7 +157,6 @@ def channel_ready_future(channel): A future.Future that matures when the given Channel has connectivity interfaces.ChannelConnectivity.READY. """ - ready_future = _ChannelReadyFuture(channel) - ready_future.start() - return ready_future - + ready_future = _ChannelReadyFuture(channel) + ready_future.start() + return ready_future diff --git a/src/python/grpcio/grpc/framework/__init__.py b/src/python/grpcio/grpc/framework/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/__init__.py +++ b/src/python/grpcio/grpc/framework/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/common/__init__.py b/src/python/grpcio/grpc/framework/common/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/common/__init__.py +++ b/src/python/grpcio/grpc/framework/common/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/common/cardinality.py b/src/python/grpcio/grpc/framework/common/cardinality.py index 610425e8032..d8927cf9b06 100644 --- a/src/python/grpcio/grpc/framework/common/cardinality.py +++ b/src/python/grpcio/grpc/framework/common/cardinality.py @@ -26,7 +26,6 @@ # 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. - """Defines an enum for classifying RPC methods by streaming semantics.""" import enum @@ -34,9 +33,9 @@ import enum @enum.unique class Cardinality(enum.Enum): - """Describes the streaming semantics of an RPC method.""" + """Describes the streaming semantics of an RPC method.""" - UNARY_UNARY = 'request-unary/response-unary' - UNARY_STREAM = 'request-unary/response-streaming' - STREAM_UNARY = 'request-streaming/response-unary' - STREAM_STREAM = 'request-streaming/response-streaming' + UNARY_UNARY = 'request-unary/response-unary' + UNARY_STREAM = 'request-unary/response-streaming' + STREAM_UNARY = 'request-streaming/response-unary' + STREAM_STREAM = 'request-streaming/response-streaming' diff --git a/src/python/grpcio/grpc/framework/common/style.py b/src/python/grpcio/grpc/framework/common/style.py index 6ae694bdcb4..43f4211145d 100644 --- a/src/python/grpcio/grpc/framework/common/style.py +++ b/src/python/grpcio/grpc/framework/common/style.py @@ -26,7 +26,6 @@ # 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. - """Defines an enum for classifying RPC methods by control flow semantics.""" import enum @@ -34,7 +33,7 @@ import enum @enum.unique class Service(enum.Enum): - """Describes the control flow style of RPC method implementation.""" + """Describes the control flow style of RPC method implementation.""" - INLINE = 'inline' - EVENT = 'event' + INLINE = 'inline' + EVENT = 'event' diff --git a/src/python/grpcio/grpc/framework/foundation/__init__.py b/src/python/grpcio/grpc/framework/foundation/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/foundation/__init__.py +++ b/src/python/grpcio/grpc/framework/foundation/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/foundation/abandonment.py b/src/python/grpcio/grpc/framework/foundation/abandonment.py index 960b4d06b49..32385b96574 100644 --- a/src/python/grpcio/grpc/framework/foundation/abandonment.py +++ b/src/python/grpcio/grpc/framework/foundation/abandonment.py @@ -26,12 +26,11 @@ # 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. - """Utilities for indicating abandonment of computation.""" class Abandoned(Exception): - """Indicates that some computation is being abandoned. + """Indicates that some computation is being abandoned. Abandoning a computation is different than returning a value or raising an exception indicating some operational or programming defect. diff --git a/src/python/grpcio/grpc/framework/foundation/callable_util.py b/src/python/grpcio/grpc/framework/foundation/callable_util.py index 4f029f97bb8..3b8351c19bd 100644 --- a/src/python/grpcio/grpc/framework/foundation/callable_util.py +++ b/src/python/grpcio/grpc/framework/foundation/callable_util.py @@ -26,7 +26,6 @@ # 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. - """Utilities for working with callables.""" import abc @@ -39,7 +38,7 @@ import six class Outcome(six.with_metaclass(abc.ABCMeta)): - """A sum type describing the outcome of some call. + """A sum type describing the outcome of some call. Attributes: kind: One of Kind.RETURNED or Kind.RAISED respectively indicating that the @@ -50,31 +49,31 @@ class Outcome(six.with_metaclass(abc.ABCMeta)): Kind.RAISED. """ - @enum.unique - class Kind(enum.Enum): - """Identifies the general kind of the outcome of some call.""" + @enum.unique + class Kind(enum.Enum): + """Identifies the general kind of the outcome of some call.""" - RETURNED = object() - RAISED = object() + RETURNED = object() + RAISED = object() class _EasyOutcome( - collections.namedtuple( - '_EasyOutcome', ['kind', 'return_value', 'exception']), - Outcome): - """A trivial implementation of Outcome.""" + collections.namedtuple('_EasyOutcome', + ['kind', 'return_value', 'exception']), Outcome): + """A trivial implementation of Outcome.""" def _call_logging_exceptions(behavior, message, *args, **kwargs): - try: - return _EasyOutcome(Outcome.Kind.RETURNED, behavior(*args, **kwargs), None) - except Exception as e: # pylint: disable=broad-except - logging.exception(message) - return _EasyOutcome(Outcome.Kind.RAISED, None, e) + try: + return _EasyOutcome(Outcome.Kind.RETURNED, + behavior(*args, **kwargs), None) + except Exception as e: # pylint: disable=broad-except + logging.exception(message) + return _EasyOutcome(Outcome.Kind.RAISED, None, e) def with_exceptions_logged(behavior, message): - """Wraps a callable in a try-except that logs any exceptions it raises. + """Wraps a callable in a try-except that logs any exceptions it raises. Args: behavior: Any callable. @@ -86,14 +85,16 @@ def with_exceptions_logged(behavior, message): future.Outcome describing whether the given behavior returned a value or raised an exception. """ - @functools.wraps(behavior) - def wrapped_behavior(*args, **kwargs): - return _call_logging_exceptions(behavior, message, *args, **kwargs) - return wrapped_behavior + + @functools.wraps(behavior) + def wrapped_behavior(*args, **kwargs): + return _call_logging_exceptions(behavior, message, *args, **kwargs) + + return wrapped_behavior def call_logging_exceptions(behavior, message, *args, **kwargs): - """Calls a behavior in a try-except that logs any exceptions it raises. + """Calls a behavior in a try-except that logs any exceptions it raises. Args: behavior: Any callable. @@ -105,4 +106,4 @@ def call_logging_exceptions(behavior, message, *args, **kwargs): An Outcome describing whether the given behavior returned a value or raised an exception. """ - return _call_logging_exceptions(behavior, message, *args, **kwargs) + return _call_logging_exceptions(behavior, message, *args, **kwargs) diff --git a/src/python/grpcio/grpc/framework/foundation/future.py b/src/python/grpcio/grpc/framework/foundation/future.py index 6fb58eadb60..e2ecf629210 100644 --- a/src/python/grpcio/grpc/framework/foundation/future.py +++ b/src/python/grpcio/grpc/framework/foundation/future.py @@ -26,7 +26,6 @@ # 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. - """A Future interface. Python doesn't have a Future interface in its standard library. In the absence @@ -53,33 +52,33 @@ import six class TimeoutError(Exception): - """Indicates that a particular call timed out.""" + """Indicates that a particular call timed out.""" class CancelledError(Exception): - """Indicates that the computation underlying a Future was cancelled.""" + """Indicates that the computation underlying a Future was cancelled.""" class Future(six.with_metaclass(abc.ABCMeta)): - """A representation of a computation in another control flow. + """A representation of a computation in another control flow. Computations represented by a Future may be yet to be begun, may be ongoing, or may have already completed. """ - # NOTE(nathaniel): This isn't the return type that I would want to have if it - # were up to me. Were this interface being written from scratch, the return - # type of this method would probably be a sum type like: - # - # NOT_COMMENCED - # COMMENCED_AND_NOT_COMPLETED - # PARTIAL_RESULT - # COMPLETED - # UNCANCELLABLE - # NOT_IMMEDIATELY_DETERMINABLE - @abc.abstractmethod - def cancel(self): - """Attempts to cancel the computation. + # NOTE(nathaniel): This isn't the return type that I would want to have if it + # were up to me. Were this interface being written from scratch, the return + # type of this method would probably be a sum type like: + # + # NOT_COMMENCED + # COMMENCED_AND_NOT_COMPLETED + # PARTIAL_RESULT + # COMPLETED + # UNCANCELLABLE + # NOT_IMMEDIATELY_DETERMINABLE + @abc.abstractmethod + def cancel(self): + """Attempts to cancel the computation. This method does not block. @@ -92,25 +91,25 @@ class Future(six.with_metaclass(abc.ABCMeta)): remote system for which a determination of whether or not it commenced before being cancelled cannot be made without blocking. """ - raise NotImplementedError() - - # NOTE(nathaniel): Here too this isn't the return type that I'd want this - # method to have if it were up to me. I think I'd go with another sum type - # like: - # - # NOT_CANCELLED (this object's cancel method hasn't been called) - # NOT_COMMENCED - # COMMENCED_AND_NOT_COMPLETED - # PARTIAL_RESULT - # COMPLETED - # UNCANCELLABLE - # NOT_IMMEDIATELY_DETERMINABLE - # - # Notice how giving the cancel method the right semantics obviates most - # reasons for this method to exist. - @abc.abstractmethod - def cancelled(self): - """Describes whether the computation was cancelled. + raise NotImplementedError() + + # NOTE(nathaniel): Here too this isn't the return type that I'd want this + # method to have if it were up to me. I think I'd go with another sum type + # like: + # + # NOT_CANCELLED (this object's cancel method hasn't been called) + # NOT_COMMENCED + # COMMENCED_AND_NOT_COMPLETED + # PARTIAL_RESULT + # COMPLETED + # UNCANCELLABLE + # NOT_IMMEDIATELY_DETERMINABLE + # + # Notice how giving the cancel method the right semantics obviates most + # reasons for this method to exist. + @abc.abstractmethod + def cancelled(self): + """Describes whether the computation was cancelled. This method does not block. @@ -120,11 +119,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): not limited to this object's cancel method not having been called and the computation's result having become immediately available. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def running(self): - """Describes whether the computation is taking place. + @abc.abstractmethod + def running(self): + """Describes whether the computation is taking place. This method does not block. @@ -133,15 +132,15 @@ class Future(six.with_metaclass(abc.ABCMeta)): taking place now, or False if the computation took place in the past or was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - # NOTE(nathaniel): These aren't quite the semantics I'd like here either. I - # would rather this only returned True in cases in which the underlying - # computation completed successfully. A computation's having been cancelled - # conflicts with considering that computation "done". - @abc.abstractmethod - def done(self): - """Describes whether the computation has taken place. + # NOTE(nathaniel): These aren't quite the semantics I'd like here either. I + # would rather this only returned True in cases in which the underlying + # computation completed successfully. A computation's having been cancelled + # conflicts with considering that computation "done". + @abc.abstractmethod + def done(self): + """Describes whether the computation has taken place. This method does not block. @@ -150,11 +149,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): unscheduled or interrupted. False if the computation may possibly be executing or scheduled to execute later. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def result(self, timeout=None): - """Accesses the outcome of the computation or raises its exception. + @abc.abstractmethod + def result(self, timeout=None): + """Accesses the outcome of the computation or raises its exception. This method may return immediately or may block. @@ -173,11 +172,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): Exception: If the computation raised an exception, this call will raise the same exception. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def exception(self, timeout=None): - """Return the exception raised by the computation. + @abc.abstractmethod + def exception(self, timeout=None): + """Return the exception raised by the computation. This method may return immediately or may block. @@ -196,11 +195,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): terminate within the allotted time. CancelledError: If the computation was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def traceback(self, timeout=None): - """Access the traceback of the exception raised by the computation. + @abc.abstractmethod + def traceback(self, timeout=None): + """Access the traceback of the exception raised by the computation. This method may return immediately or may block. @@ -219,11 +218,11 @@ class Future(six.with_metaclass(abc.ABCMeta)): terminate within the allotted time. CancelledError: If the computation was cancelled. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_done_callback(self, fn): - """Adds a function to be called at completion of the computation. + @abc.abstractmethod + def add_done_callback(self, fn): + """Adds a function to be called at completion of the computation. The callback will be passed this Future object describing the outcome of the computation. @@ -234,4 +233,4 @@ class Future(six.with_metaclass(abc.ABCMeta)): Args: fn: A callable taking this Future object as its single parameter. """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio/grpc/framework/foundation/logging_pool.py b/src/python/grpcio/grpc/framework/foundation/logging_pool.py index 9b469a1452e..9164173d348 100644 --- a/src/python/grpcio/grpc/framework/foundation/logging_pool.py +++ b/src/python/grpcio/grpc/framework/foundation/logging_pool.py @@ -26,7 +26,6 @@ # 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. - """A thread pool that logs exceptions raised by tasks executed within it.""" import logging @@ -35,42 +34,46 @@ from concurrent import futures def _wrap(behavior): - """Wraps an arbitrary callable behavior in exception-logging.""" - def _wrapping(*args, **kwargs): - try: - return behavior(*args, **kwargs) - except Exception as e: - logging.exception( - 'Unexpected exception from %s executed in logging pool!', behavior) - raise - return _wrapping + """Wraps an arbitrary callable behavior in exception-logging.""" + + def _wrapping(*args, **kwargs): + try: + return behavior(*args, **kwargs) + except Exception as e: + logging.exception( + 'Unexpected exception from %s executed in logging pool!', + behavior) + raise + + return _wrapping class _LoggingPool(object): - """An exception-logging futures.ThreadPoolExecutor-compatible thread pool.""" + """An exception-logging futures.ThreadPoolExecutor-compatible thread pool.""" - def __init__(self, backing_pool): - self._backing_pool = backing_pool + def __init__(self, backing_pool): + self._backing_pool = backing_pool - def __enter__(self): - return self + def __enter__(self): + return self - def __exit__(self, exc_type, exc_val, exc_tb): - self._backing_pool.shutdown(wait=True) + def __exit__(self, exc_type, exc_val, exc_tb): + self._backing_pool.shutdown(wait=True) - def submit(self, fn, *args, **kwargs): - return self._backing_pool.submit(_wrap(fn), *args, **kwargs) + def submit(self, fn, *args, **kwargs): + return self._backing_pool.submit(_wrap(fn), *args, **kwargs) - def map(self, func, *iterables, **kwargs): - return self._backing_pool.map( - _wrap(func), *iterables, timeout=kwargs.get('timeout', None)) + def map(self, func, *iterables, **kwargs): + return self._backing_pool.map(_wrap(func), + *iterables, + timeout=kwargs.get('timeout', None)) - def shutdown(self, wait=True): - self._backing_pool.shutdown(wait=wait) + def shutdown(self, wait=True): + self._backing_pool.shutdown(wait=wait) def pool(max_workers): - """Creates a thread pool that logs exceptions raised by the tasks within it. + """Creates a thread pool that logs exceptions raised by the tasks within it. Args: max_workers: The maximum number of worker threads to allow the pool. @@ -79,4 +82,4 @@ def pool(max_workers): A futures.ThreadPoolExecutor-compatible thread pool that logs exceptions raised by the tasks executed within it. """ - return _LoggingPool(futures.ThreadPoolExecutor(max_workers)) + return _LoggingPool(futures.ThreadPoolExecutor(max_workers)) diff --git a/src/python/grpcio/grpc/framework/foundation/stream.py b/src/python/grpcio/grpc/framework/foundation/stream.py index ddd6cc496a9..2529a6944b8 100644 --- a/src/python/grpcio/grpc/framework/foundation/stream.py +++ b/src/python/grpcio/grpc/framework/foundation/stream.py @@ -26,35 +26,35 @@ # 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. - """Interfaces related to streams of values or objects.""" import abc import six + class Consumer(six.with_metaclass(abc.ABCMeta)): - """Interface for consumers of finite streams of values or objects.""" + """Interface for consumers of finite streams of values or objects.""" - @abc.abstractmethod - def consume(self, value): - """Accepts a value. + @abc.abstractmethod + def consume(self, value): + """Accepts a value. Args: value: Any value accepted by this Consumer. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def terminate(self): - """Indicates to this Consumer that no more values will be supplied.""" - raise NotImplementedError() + @abc.abstractmethod + def terminate(self): + """Indicates to this Consumer that no more values will be supplied.""" + raise NotImplementedError() - @abc.abstractmethod - def consume_and_terminate(self, value): - """Supplies a value and signals that no more values will be supplied. + @abc.abstractmethod + def consume_and_terminate(self, value): + """Supplies a value and signals that no more values will be supplied. Args: value: Any value accepted by this Consumer. """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio/grpc/framework/foundation/stream_util.py b/src/python/grpcio/grpc/framework/foundation/stream_util.py index a6f234f1feb..6b356f176fc 100644 --- a/src/python/grpcio/grpc/framework/foundation/stream_util.py +++ b/src/python/grpcio/grpc/framework/foundation/stream_util.py @@ -26,7 +26,6 @@ # 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. - """Helpful utilities related to the stream module.""" import logging @@ -38,126 +37,126 @@ _NO_VALUE = object() class TransformingConsumer(stream.Consumer): - """A stream.Consumer that passes a transformation of its input to another.""" + """A stream.Consumer that passes a transformation of its input to another.""" - def __init__(self, transformation, downstream): - self._transformation = transformation - self._downstream = downstream + def __init__(self, transformation, downstream): + self._transformation = transformation + self._downstream = downstream - def consume(self, value): - self._downstream.consume(self._transformation(value)) + def consume(self, value): + self._downstream.consume(self._transformation(value)) - def terminate(self): - self._downstream.terminate() + def terminate(self): + self._downstream.terminate() - def consume_and_terminate(self, value): - self._downstream.consume_and_terminate(self._transformation(value)) + def consume_and_terminate(self, value): + self._downstream.consume_and_terminate(self._transformation(value)) class IterableConsumer(stream.Consumer): - """A Consumer that when iterated over emits the values it has consumed.""" - - def __init__(self): - self._condition = threading.Condition() - self._values = [] - self._active = True - - def consume(self, stock_reply): - with self._condition: - if self._active: - self._values.append(stock_reply) - self._condition.notify() - - def terminate(self): - with self._condition: - self._active = False - self._condition.notify() - - def consume_and_terminate(self, stock_reply): - with self._condition: - if self._active: - self._values.append(stock_reply) - self._active = False - self._condition.notify() - - def __iter__(self): - return self - - def __next__(self): - return self.next() - - def next(self): - with self._condition: - while self._active and not self._values: - self._condition.wait() - if self._values: - return self._values.pop(0) - else: - raise StopIteration() + """A Consumer that when iterated over emits the values it has consumed.""" + + def __init__(self): + self._condition = threading.Condition() + self._values = [] + self._active = True + + def consume(self, stock_reply): + with self._condition: + if self._active: + self._values.append(stock_reply) + self._condition.notify() + + def terminate(self): + with self._condition: + self._active = False + self._condition.notify() + + def consume_and_terminate(self, stock_reply): + with self._condition: + if self._active: + self._values.append(stock_reply) + self._active = False + self._condition.notify() + + def __iter__(self): + return self + + def __next__(self): + return self.next() + + def next(self): + with self._condition: + while self._active and not self._values: + self._condition.wait() + if self._values: + return self._values.pop(0) + else: + raise StopIteration() class ThreadSwitchingConsumer(stream.Consumer): - """A Consumer decorator that affords serialization and asynchrony.""" - - def __init__(self, sink, pool): - self._lock = threading.Lock() - self._sink = sink - self._pool = pool - # True if self._spin has been submitted to the pool to be called once and - # that call has not yet returned, False otherwise. - self._spinning = False - self._values = [] - self._active = True - - def _spin(self, sink, value, terminate): - while True: - try: - if value is _NO_VALUE: - sink.terminate() - elif terminate: - sink.consume_and_terminate(value) - else: - sink.consume(value) - except Exception as e: # pylint:disable=broad-except - logging.exception(e) - - with self._lock: - if terminate: - self._spinning = False - return - elif self._values: - value = self._values.pop(0) - terminate = not self._values and not self._active - elif not self._active: - value = _NO_VALUE - terminate = True - else: - self._spinning = False - return - - def consume(self, value): - with self._lock: - if self._active: - if self._spinning: - self._values.append(value) - else: - self._pool.submit(self._spin, self._sink, value, False) - self._spinning = True - - def terminate(self): - with self._lock: - if self._active: - self._active = False - if not self._spinning: - self._pool.submit(self._spin, self._sink, _NO_VALUE, True) - self._spinning = True - - def consume_and_terminate(self, value): - with self._lock: - if self._active: - self._active = False - if self._spinning: - self._values.append(value) - else: - self._pool.submit(self._spin, self._sink, value, True) - self._spinning = True + """A Consumer decorator that affords serialization and asynchrony.""" + + def __init__(self, sink, pool): + self._lock = threading.Lock() + self._sink = sink + self._pool = pool + # True if self._spin has been submitted to the pool to be called once and + # that call has not yet returned, False otherwise. + self._spinning = False + self._values = [] + self._active = True + + def _spin(self, sink, value, terminate): + while True: + try: + if value is _NO_VALUE: + sink.terminate() + elif terminate: + sink.consume_and_terminate(value) + else: + sink.consume(value) + except Exception as e: # pylint:disable=broad-except + logging.exception(e) + + with self._lock: + if terminate: + self._spinning = False + return + elif self._values: + value = self._values.pop(0) + terminate = not self._values and not self._active + elif not self._active: + value = _NO_VALUE + terminate = True + else: + self._spinning = False + return + + def consume(self, value): + with self._lock: + if self._active: + if self._spinning: + self._values.append(value) + else: + self._pool.submit(self._spin, self._sink, value, False) + self._spinning = True + + def terminate(self): + with self._lock: + if self._active: + self._active = False + if not self._spinning: + self._pool.submit(self._spin, self._sink, _NO_VALUE, True) + self._spinning = True + + def consume_and_terminate(self, value): + with self._lock: + if self._active: + self._active = False + if self._spinning: + self._values.append(value) + else: + self._pool.submit(self._spin, self._sink, value, True) + self._spinning = True diff --git a/src/python/grpcio/grpc/framework/interfaces/__init__.py b/src/python/grpcio/grpc/framework/interfaces/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/interfaces/__init__.py +++ b/src/python/grpcio/grpc/framework/interfaces/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/interfaces/base/__init__.py b/src/python/grpcio/grpc/framework/interfaces/base/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/interfaces/base/__init__.py +++ b/src/python/grpcio/grpc/framework/interfaces/base/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/interfaces/base/base.py b/src/python/grpcio/grpc/framework/interfaces/base/base.py index a2ddd9c4747..cb3328296c5 100644 --- a/src/python/grpcio/grpc/framework/interfaces/base/base.py +++ b/src/python/grpcio/grpc/framework/interfaces/base/base.py @@ -26,7 +26,6 @@ # 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. - """The base interface of RPC Framework. Implementations of this interface support the conduct of "operations": @@ -49,7 +48,7 @@ from grpc.framework.foundation import abandonment # pylint: disable=unused-impo class NoSuchMethodError(Exception): - """Indicates that an unrecognized operation has been called. + """Indicates that an unrecognized operation has been called. Attributes: code: A code value to communicate to the other side of the operation along @@ -58,8 +57,8 @@ class NoSuchMethodError(Exception): along with indication of operation termination. May be None. """ - def __init__(self, code, details): - """Constructor. + def __init__(self, code, details): + """Constructor. Args: code: A code value to communicate to the other side of the operation @@ -67,12 +66,12 @@ class NoSuchMethodError(Exception): details: A details value to communicate to the other side of the operation along with indication of operation termination. May be None. """ - self.code = code - self.details = details + self.code = code + self.details = details class Outcome(object): - """The outcome of an operation. + """The outcome of an operation. Attributes: kind: A Kind value coarsely identifying how the operation terminated. @@ -82,23 +81,23 @@ class Outcome(object): provided. """ - @enum.unique - class Kind(enum.Enum): - """Ways in which an operation can terminate.""" + @enum.unique + class Kind(enum.Enum): + """Ways in which an operation can terminate.""" - COMPLETED = 'completed' - CANCELLED = 'cancelled' - EXPIRED = 'expired' - LOCAL_SHUTDOWN = 'local shutdown' - REMOTE_SHUTDOWN = 'remote shutdown' - RECEPTION_FAILURE = 'reception failure' - TRANSMISSION_FAILURE = 'transmission failure' - LOCAL_FAILURE = 'local failure' - REMOTE_FAILURE = 'remote failure' + COMPLETED = 'completed' + CANCELLED = 'cancelled' + EXPIRED = 'expired' + LOCAL_SHUTDOWN = 'local shutdown' + REMOTE_SHUTDOWN = 'remote shutdown' + RECEPTION_FAILURE = 'reception failure' + TRANSMISSION_FAILURE = 'transmission failure' + LOCAL_FAILURE = 'local failure' + REMOTE_FAILURE = 'remote failure' class Completion(six.with_metaclass(abc.ABCMeta)): - """An aggregate of the values exchanged upon operation completion. + """An aggregate of the values exchanged upon operation completion. Attributes: terminal_metadata: A terminal metadata value for the operaton. @@ -108,21 +107,21 @@ class Completion(six.with_metaclass(abc.ABCMeta)): class OperationContext(six.with_metaclass(abc.ABCMeta)): - """Provides operation-related information and action.""" + """Provides operation-related information and action.""" - @abc.abstractmethod - def outcome(self): - """Indicates the operation's outcome (or that the operation is ongoing). + @abc.abstractmethod + def outcome(self): + """Indicates the operation's outcome (or that the operation is ongoing). Returns: None if the operation is still active or the Outcome value for the operation if it has terminated. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_termination_callback(self, callback): - """Adds a function to be called upon operation termination. + @abc.abstractmethod + def add_termination_callback(self, callback): + """Adds a function to be called upon operation termination. Args: callback: A callable to be passed an Outcome value on operation @@ -134,42 +133,44 @@ class OperationContext(six.with_metaclass(abc.ABCMeta)): terminated an Outcome value describing the operation termination and the passed callback will not be called as a result of this method call. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def time_remaining(self): - """Describes the length of allowed time remaining for the operation. + @abc.abstractmethod + def time_remaining(self): + """Describes the length of allowed time remaining for the operation. Returns: A nonnegative float indicating the length of allowed time in seconds remaining for the operation to complete before it is considered to have timed out. Zero is returned if the operation has terminated. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def cancel(self): - """Cancels the operation if the operation has not yet terminated.""" - raise NotImplementedError() + @abc.abstractmethod + def cancel(self): + """Cancels the operation if the operation has not yet terminated.""" + raise NotImplementedError() - @abc.abstractmethod - def fail(self, exception): - """Indicates that the operation has failed. + @abc.abstractmethod + def fail(self, exception): + """Indicates that the operation has failed. Args: exception: An exception germane to the operation failure. May be None. """ - raise NotImplementedError() + raise NotImplementedError() class Operator(six.with_metaclass(abc.ABCMeta)): - """An interface through which to participate in an operation.""" + """An interface through which to participate in an operation.""" - @abc.abstractmethod - def advance( - self, initial_metadata=None, payload=None, completion=None, - allowance=None): - """Progresses the operation. + @abc.abstractmethod + def advance(self, + initial_metadata=None, + payload=None, + completion=None, + allowance=None): + """Progresses the operation. Args: initial_metadata: An initial metadata value. Only one may ever be @@ -181,23 +182,24 @@ class Operator(six.with_metaclass(abc.ABCMeta)): allowance: A positive integer communicating the number of additional payloads allowed to be passed by the remote side of the operation. """ - raise NotImplementedError() + raise NotImplementedError() + class ProtocolReceiver(six.with_metaclass(abc.ABCMeta)): - """A means of receiving protocol values during an operation.""" + """A means of receiving protocol values during an operation.""" - @abc.abstractmethod - def context(self, protocol_context): - """Accepts the protocol context object for the operation. + @abc.abstractmethod + def context(self, protocol_context): + """Accepts the protocol context object for the operation. Args: protocol_context: The protocol context object for the operation. """ - raise NotImplementedError() + raise NotImplementedError() class Subscription(six.with_metaclass(abc.ABCMeta)): - """Describes customer code's interest in values from the other side. + """Describes customer code's interest in values from the other side. Attributes: kind: A Kind value describing the overall kind of this value. @@ -215,20 +217,20 @@ class Subscription(six.with_metaclass(abc.ABCMeta)): Kind.FULL. """ - @enum.unique - class Kind(enum.Enum): + @enum.unique + class Kind(enum.Enum): - NONE = 'none' - TERMINATION_ONLY = 'termination only' - FULL = 'full' + NONE = 'none' + TERMINATION_ONLY = 'termination only' + FULL = 'full' class Servicer(six.with_metaclass(abc.ABCMeta)): - """Interface for service implementations.""" + """Interface for service implementations.""" - @abc.abstractmethod - def service(self, group, method, context, output_operator): - """Services an operation. + @abc.abstractmethod + def service(self, group, method, context, output_operator): + """Services an operation. Args: group: The group identifier of the operation to be serviced. @@ -248,20 +250,20 @@ class Servicer(six.with_metaclass(abc.ABCMeta)): abandonment.Abandoned: If the operation has been aborted and there no longer is any reason to service the operation. """ - raise NotImplementedError() + raise NotImplementedError() class End(six.with_metaclass(abc.ABCMeta)): - """Common type for entry-point objects on both sides of an operation.""" + """Common type for entry-point objects on both sides of an operation.""" - @abc.abstractmethod - def start(self): - """Starts this object's service of operations.""" - raise NotImplementedError() + @abc.abstractmethod + def start(self): + """Starts this object's service of operations.""" + raise NotImplementedError() - @abc.abstractmethod - def stop(self, grace): - """Stops this object's service of operations. + @abc.abstractmethod + def stop(self, grace): + """Stops this object's service of operations. This object will refuse service of new operations as soon as this method is called but operations under way at the time of the call may be given a @@ -281,13 +283,19 @@ class End(six.with_metaclass(abc.ABCMeta)): much sooner (if for example this End had no operations in progress at the time its stop method was called). """ - raise NotImplementedError() - - @abc.abstractmethod - def operate( - self, group, method, subscription, timeout, initial_metadata=None, - payload=None, completion=None, protocol_options=None): - """Commences an operation. + raise NotImplementedError() + + @abc.abstractmethod + def operate(self, + group, + method, + subscription, + timeout, + initial_metadata=None, + payload=None, + completion=None, + protocol_options=None): + """Commences an operation. Args: group: The group identifier of the invoked operation. @@ -312,23 +320,23 @@ class End(six.with_metaclass(abc.ABCMeta)): returned pair is an Operator to which operation values not passed in this call should later be passed. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def operation_stats(self): - """Reports the number of terminated operations broken down by outcome. + @abc.abstractmethod + def operation_stats(self): + """Reports the number of terminated operations broken down by outcome. Returns: A dictionary from Outcome.Kind value to an integer identifying the number of operations that terminated with that outcome kind. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_idle_action(self, action): - """Adds an action to be called when this End has no ongoing operations. + @abc.abstractmethod + def add_idle_action(self, action): + """Adds an action to be called when this End has no ongoing operations. Args: action: A callable that accepts no arguments. """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio/grpc/framework/interfaces/base/utilities.py b/src/python/grpcio/grpc/framework/interfaces/base/utilities.py index 87a85018f52..461706ff9f2 100644 --- a/src/python/grpcio/grpc/framework/interfaces/base/utilities.py +++ b/src/python/grpcio/grpc/framework/interfaces/base/utilities.py @@ -26,7 +26,6 @@ # 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. - """Utilities for use with the base interface of RPC Framework.""" import collections @@ -34,27 +33,30 @@ import collections from grpc.framework.interfaces.base import base -class _Completion( - base.Completion, - collections.namedtuple( - '_Completion', ('terminal_metadata', 'code', 'message',))): - """A trivial implementation of base.Completion.""" +class _Completion(base.Completion, + collections.namedtuple('_Completion', ( + 'terminal_metadata', + 'code', + 'message',))): + """A trivial implementation of base.Completion.""" + +class _Subscription(base.Subscription, + collections.namedtuple('_Subscription', ( + 'kind', + 'termination_callback', + 'allowance', + 'operator', + 'protocol_receiver',))): + """A trivial implementation of base.Subscription.""" -class _Subscription( - base.Subscription, - collections.namedtuple( - '_Subscription', - ('kind', 'termination_callback', 'allowance', 'operator', - 'protocol_receiver',))): - """A trivial implementation of base.Subscription.""" -_NONE_SUBSCRIPTION = _Subscription( - base.Subscription.Kind.NONE, None, None, None, None) +_NONE_SUBSCRIPTION = _Subscription(base.Subscription.Kind.NONE, None, None, + None, None) def completion(terminal_metadata, code, message): - """Creates a base.Completion aggregating the given operation values. + """Creates a base.Completion aggregating the given operation values. Args: terminal_metadata: A terminal metadata value for an operaton. @@ -64,11 +66,11 @@ def completion(terminal_metadata, code, message): Returns: A base.Completion aggregating the given operation values. """ - return _Completion(terminal_metadata, code, message) + return _Completion(terminal_metadata, code, message) def full_subscription(operator, protocol_receiver): - """Creates a "full" base.Subscription for the given base.Operator. + """Creates a "full" base.Subscription for the given base.Operator. Args: operator: A base.Operator to be used in an operation. @@ -78,5 +80,5 @@ def full_subscription(operator, protocol_receiver): A base.Subscription of kind base.Subscription.Kind.FULL wrapping the given base.Operator and base.ProtocolReceiver. """ - return _Subscription( - base.Subscription.Kind.FULL, None, None, operator, protocol_receiver) + return _Subscription(base.Subscription.Kind.FULL, None, None, operator, + protocol_receiver) diff --git a/src/python/grpcio/grpc/framework/interfaces/face/__init__.py b/src/python/grpcio/grpc/framework/interfaces/face/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio/grpc/framework/interfaces/face/__init__.py +++ b/src/python/grpcio/grpc/framework/interfaces/face/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio/grpc/framework/interfaces/face/face.py b/src/python/grpcio/grpc/framework/interfaces/face/face.py index 4826e7fff64..36ddca18c14 100644 --- a/src/python/grpcio/grpc/framework/interfaces/face/face.py +++ b/src/python/grpcio/grpc/framework/interfaces/face/face.py @@ -26,7 +26,6 @@ # 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. - """Interfaces defining the Face layer of RPC Framework.""" import abc @@ -45,33 +44,38 @@ from grpc.framework.foundation import stream # pylint: disable=unused-import class NoSuchMethodError(Exception): - """Raised by customer code to indicate an unrecognized method. + """Raised by customer code to indicate an unrecognized method. Attributes: group: The group of the unrecognized method. name: The name of the unrecognized method. """ - def __init__(self, group, method): - """Constructor. + def __init__(self, group, method): + """Constructor. Args: group: The group identifier of the unrecognized RPC name. method: The method identifier of the unrecognized RPC name. """ - super(NoSuchMethodError, self).__init__() - self.group = group - self.method = method + super(NoSuchMethodError, self).__init__() + self.group = group + self.method = method - def __repr__(self): - return 'face.NoSuchMethodError(%s, %s)' % (self.group, self.method,) + def __repr__(self): + return 'face.NoSuchMethodError(%s, %s)' % ( + self.group, + self.method,) class Abortion( - collections.namedtuple( - 'Abortion', - ('kind', 'initial_metadata', 'terminal_metadata', 'code', 'details',))): - """A value describing RPC abortion. + collections.namedtuple('Abortion', ( + 'kind', + 'initial_metadata', + 'terminal_metadata', + 'code', + 'details',))): + """A value describing RPC abortion. Attributes: kind: A Kind value identifying how the RPC failed. @@ -85,21 +89,21 @@ class Abortion( details value was received. """ - @enum.unique - class Kind(enum.Enum): - """Types of RPC abortion.""" + @enum.unique + class Kind(enum.Enum): + """Types of RPC abortion.""" - CANCELLED = 'cancelled' - EXPIRED = 'expired' - LOCAL_SHUTDOWN = 'local shutdown' - REMOTE_SHUTDOWN = 'remote shutdown' - NETWORK_FAILURE = 'network failure' - LOCAL_FAILURE = 'local failure' - REMOTE_FAILURE = 'remote failure' + CANCELLED = 'cancelled' + EXPIRED = 'expired' + LOCAL_SHUTDOWN = 'local shutdown' + REMOTE_SHUTDOWN = 'remote shutdown' + NETWORK_FAILURE = 'network failure' + LOCAL_FAILURE = 'local failure' + REMOTE_FAILURE = 'remote failure' class AbortionError(six.with_metaclass(abc.ABCMeta, Exception)): - """Common super type for exceptions indicating RPC abortion. + """Common super type for exceptions indicating RPC abortion. initial_metadata: The initial metadata from the other side of the RPC or None if no initial metadata value was received. @@ -111,100 +115,100 @@ class AbortionError(six.with_metaclass(abc.ABCMeta, Exception)): details value was received. """ - def __init__(self, initial_metadata, terminal_metadata, code, details): - super(AbortionError, self).__init__() - self.initial_metadata = initial_metadata - self.terminal_metadata = terminal_metadata - self.code = code - self.details = details + def __init__(self, initial_metadata, terminal_metadata, code, details): + super(AbortionError, self).__init__() + self.initial_metadata = initial_metadata + self.terminal_metadata = terminal_metadata + self.code = code + self.details = details - def __str__(self): - return '%s(code=%s, details="%s")' % ( - self.__class__.__name__, self.code, self.details) + def __str__(self): + return '%s(code=%s, details="%s")' % (self.__class__.__name__, + self.code, self.details) class CancellationError(AbortionError): - """Indicates that an RPC has been cancelled.""" + """Indicates that an RPC has been cancelled.""" class ExpirationError(AbortionError): - """Indicates that an RPC has expired ("timed out").""" + """Indicates that an RPC has expired ("timed out").""" class LocalShutdownError(AbortionError): - """Indicates that an RPC has terminated due to local shutdown of RPCs.""" + """Indicates that an RPC has terminated due to local shutdown of RPCs.""" class RemoteShutdownError(AbortionError): - """Indicates that an RPC has terminated due to remote shutdown of RPCs.""" + """Indicates that an RPC has terminated due to remote shutdown of RPCs.""" class NetworkError(AbortionError): - """Indicates that some error occurred on the network.""" + """Indicates that some error occurred on the network.""" class LocalError(AbortionError): - """Indicates that an RPC has terminated due to a local defect.""" + """Indicates that an RPC has terminated due to a local defect.""" class RemoteError(AbortionError): - """Indicates that an RPC has terminated due to a remote defect.""" + """Indicates that an RPC has terminated due to a remote defect.""" class RpcContext(six.with_metaclass(abc.ABCMeta)): - """Provides RPC-related information and action.""" + """Provides RPC-related information and action.""" - @abc.abstractmethod - def is_active(self): - """Describes whether the RPC is active or has terminated.""" - raise NotImplementedError() + @abc.abstractmethod + def is_active(self): + """Describes whether the RPC is active or has terminated.""" + raise NotImplementedError() - @abc.abstractmethod - def time_remaining(self): - """Describes the length of allowed time remaining for the RPC. + @abc.abstractmethod + def time_remaining(self): + """Describes the length of allowed time remaining for the RPC. Returns: A nonnegative float indicating the length of allowed time in seconds remaining for the RPC to complete before it is considered to have timed out. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def add_abortion_callback(self, abortion_callback): - """Registers a callback to be called if the RPC is aborted. + @abc.abstractmethod + def add_abortion_callback(self, abortion_callback): + """Registers a callback to be called if the RPC is aborted. Args: abortion_callback: A callable to be called and passed an Abortion value in the event of RPC abortion. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def cancel(self): - """Cancels the RPC. + @abc.abstractmethod + def cancel(self): + """Cancels the RPC. Idempotent and has no effect if the RPC has already terminated. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def protocol_context(self): - """Accesses a custom object specified by an implementation provider. + @abc.abstractmethod + def protocol_context(self): + """Accesses a custom object specified by an implementation provider. Returns: A value specified by the provider of a Face interface implementation affording custom state and behavior. """ - raise NotImplementedError() + raise NotImplementedError() class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): - """Invocation-side utility object for an RPC.""" + """Invocation-side utility object for an RPC.""" - @abc.abstractmethod - def initial_metadata(self): - """Accesses the initial metadata from the service-side of the RPC. + @abc.abstractmethod + def initial_metadata(self): + """Accesses the initial metadata from the service-side of the RPC. This method blocks until the value is available or is known not to have been emitted from the service-side of the RPC. @@ -213,11 +217,11 @@ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): The initial metadata object emitted by the service-side of the RPC, or None if there was no such value. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def terminal_metadata(self): - """Accesses the terminal metadata from the service-side of the RPC. + @abc.abstractmethod + def terminal_metadata(self): + """Accesses the terminal metadata from the service-side of the RPC. This method blocks until the value is available or is known not to have been emitted from the service-side of the RPC. @@ -226,11 +230,11 @@ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): The terminal metadata object emitted by the service-side of the RPC, or None if there was no such value. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def code(self): - """Accesses the code emitted by the service-side of the RPC. + @abc.abstractmethod + def code(self): + """Accesses the code emitted by the service-side of the RPC. This method blocks until the value is available or is known not to have been emitted from the service-side of the RPC. @@ -239,11 +243,11 @@ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): The code object emitted by the service-side of the RPC, or None if there was no such value. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def details(self): - """Accesses the details value emitted by the service-side of the RPC. + @abc.abstractmethod + def details(self): + """Accesses the details value emitted by the service-side of the RPC. This method blocks until the value is available or is known not to have been emitted from the service-side of the RPC. @@ -252,15 +256,15 @@ class Call(six.with_metaclass(abc.ABCMeta, RpcContext)): The details value emitted by the service-side of the RPC, or None if there was no such value. """ - raise NotImplementedError() + raise NotImplementedError() class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): - """A context object passed to method implementations.""" + """A context object passed to method implementations.""" - @abc.abstractmethod - def invocation_metadata(self): - """Accesses the metadata from the invocation-side of the RPC. + @abc.abstractmethod + def invocation_metadata(self): + """Accesses the metadata from the invocation-side of the RPC. This method blocks until the value is available or is known not to have been emitted from the invocation-side of the RPC. @@ -269,11 +273,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): The metadata object emitted by the invocation-side of the RPC, or None if there was no such value. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def initial_metadata(self, initial_metadata): - """Accepts the service-side initial metadata value of the RPC. + @abc.abstractmethod + def initial_metadata(self, initial_metadata): + """Accepts the service-side initial metadata value of the RPC. This method need not be called by method implementations if they have no service-side initial metadata to transmit. @@ -282,11 +286,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): initial_metadata: The service-side initial metadata value of the RPC to be transmitted to the invocation side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def terminal_metadata(self, terminal_metadata): - """Accepts the service-side terminal metadata value of the RPC. + @abc.abstractmethod + def terminal_metadata(self, terminal_metadata): + """Accepts the service-side terminal metadata value of the RPC. This method need not be called by method implementations if they have no service-side terminal metadata to transmit. @@ -295,11 +299,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): terminal_metadata: The service-side terminal metadata value of the RPC to be transmitted to the invocation side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def code(self, code): - """Accepts the service-side code of the RPC. + @abc.abstractmethod + def code(self, code): + """Accepts the service-side code of the RPC. This method need not be called by method implementations if they have no code to transmit. @@ -308,11 +312,11 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): code: The code of the RPC to be transmitted to the invocation side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def details(self, details): - """Accepts the service-side details of the RPC. + @abc.abstractmethod + def details(self, details): + """Accepts the service-side details of the RPC. This method need not be called by method implementations if they have no service-side details to transmit. @@ -321,34 +325,34 @@ class ServicerContext(six.with_metaclass(abc.ABCMeta, RpcContext)): details: The service-side details value of the RPC to be transmitted to the invocation side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class ResponseReceiver(six.with_metaclass(abc.ABCMeta)): - """Invocation-side object used to accept the output of an RPC.""" + """Invocation-side object used to accept the output of an RPC.""" - @abc.abstractmethod - def initial_metadata(self, initial_metadata): - """Receives the initial metadata from the service-side of the RPC. + @abc.abstractmethod + def initial_metadata(self, initial_metadata): + """Receives the initial metadata from the service-side of the RPC. Args: initial_metadata: The initial metadata object emitted from the service-side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def response(self, response): - """Receives a response from the service-side of the RPC. + @abc.abstractmethod + def response(self, response): + """Receives a response from the service-side of the RPC. Args: response: A response object emitted from the service-side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def complete(self, terminal_metadata, code, details): - """Receives the completion values emitted from the service-side of the RPC. + @abc.abstractmethod + def complete(self, terminal_metadata, code, details): + """Receives the completion values emitted from the service-side of the RPC. Args: terminal_metadata: The terminal metadata object emitted from the @@ -356,17 +360,20 @@ class ResponseReceiver(six.with_metaclass(abc.ABCMeta)): code: The code object emitted from the service-side of the RPC. details: The details object emitted from the service-side of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a unary-unary RPC in any call style.""" + """Affords invoking a unary-unary RPC in any call style.""" - @abc.abstractmethod - def __call__( - self, request, timeout, metadata=None, with_call=False, - protocol_options=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, + request, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + """Synchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -385,11 +392,11 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): Raises: AbortionError: Indicating that the RPC was aborted. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def future(self, request, timeout, metadata=None, protocol_options=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def future(self, request, timeout, metadata=None, protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -405,13 +412,17 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): response value of the RPC. In the event of RPC abortion, the returned Future's exception value will be an AbortionError. """ - raise NotImplementedError() - - @abc.abstractmethod - def event( - self, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Asynchronously invokes the underlying RPC. + raise NotImplementedError() + + @abc.abstractmethod + def event(self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -427,15 +438,15 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: A Call for the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a unary-stream RPC in any call style.""" + """Affords invoking a unary-stream RPC in any call style.""" - @abc.abstractmethod - def __call__(self, request, timeout, metadata=None, protocol_options=None): - """Invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, request, timeout, metadata=None, protocol_options=None): + """Invokes the underlying RPC. Args: request: The request value for the RPC. @@ -450,13 +461,17 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise AbortionError indicating abortion of the RPC. """ - raise NotImplementedError() - - @abc.abstractmethod - def event( - self, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Asynchronously invokes the underlying RPC. + raise NotImplementedError() + + @abc.abstractmethod + def event(self, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: request: The request value for the RPC. @@ -472,17 +487,20 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: A Call object for the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a stream-unary RPC in any call style.""" + """Affords invoking a stream-unary RPC in any call style.""" - @abc.abstractmethod - def __call__( - self, request_iterator, timeout, metadata=None, - with_call=False, protocol_options=None): - """Synchronously invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, + request_iterator, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + """Synchronously invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -501,12 +519,15 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): Raises: AbortionError: Indicating that the RPC was aborted. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def future( - self, request_iterator, timeout, metadata=None, protocol_options=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def future(self, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -522,13 +543,16 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): response value of the RPC. In the event of RPC abortion, the returned Future's exception value will be an AbortionError. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def event( - self, receiver, abortion_callback, timeout, metadata=None, - protocol_options=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def event(self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: receiver: A ResponseReceiver to be passed the response data of the RPC. @@ -544,16 +568,19 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): A single object that is both a Call object for the RPC and a stream.Consumer to which the request values of the RPC should be passed. """ - raise NotImplementedError() + raise NotImplementedError() class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): - """Affords invoking a stream-stream RPC in any call style.""" + """Affords invoking a stream-stream RPC in any call style.""" - @abc.abstractmethod - def __call__( - self, request_iterator, timeout, metadata=None, protocol_options=None): - """Invokes the underlying RPC. + @abc.abstractmethod + def __call__(self, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + """Invokes the underlying RPC. Args: request_iterator: An iterator that yields request values for the RPC. @@ -568,13 +595,16 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise AbortionError indicating abortion of the RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def event( - self, receiver, abortion_callback, timeout, metadata=None, - protocol_options=None): - """Asynchronously invokes the underlying RPC. + @abc.abstractmethod + def event(self, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Asynchronously invokes the underlying RPC. Args: receiver: A ResponseReceiver to be passed the response data of the RPC. @@ -590,11 +620,11 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): A single object that is both a Call object for the RPC and a stream.Consumer to which the request values of the RPC should be passed. """ - raise NotImplementedError() + raise NotImplementedError() class MethodImplementation(six.with_metaclass(abc.ABCMeta)): - """A sum type that describes a method implementation. + """A sum type that describes a method implementation. Attributes: cardinality: A cardinality.Cardinality value. @@ -639,11 +669,11 @@ class MethodImplementation(six.with_metaclass(abc.ABCMeta)): class MultiMethodImplementation(six.with_metaclass(abc.ABCMeta)): - """A general type able to service many methods.""" + """A general type able to service many methods.""" - @abc.abstractmethod - def service(self, group, method, response_consumer, context): - """Services an RPC. + @abc.abstractmethod + def service(self, group, method, response_consumer, context): + """Services an RPC. Args: group: The group identifier of the RPC. @@ -666,17 +696,22 @@ class MultiMethodImplementation(six.with_metaclass(abc.ABCMeta)): NoSuchMethodError: If this MultiMethod does not recognize the given group and name for the RPC and is not able to service the RPC. """ - raise NotImplementedError() + raise NotImplementedError() class GenericStub(six.with_metaclass(abc.ABCMeta)): - """Affords RPC invocation via generic methods.""" - - @abc.abstractmethod - def blocking_unary_unary( - self, group, method, request, timeout, metadata=None, - with_call=False, protocol_options=None): - """Invokes a unary-request-unary-response method. + """Affords RPC invocation via generic methods.""" + + @abc.abstractmethod + def blocking_unary_unary(self, + group, + method, + request, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + """Invokes a unary-request-unary-response method. This method blocks until either returning the response value of the RPC (in the event of RPC completion) or raising an exception (in the event of @@ -700,13 +735,17 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Raises: AbortionError: Indicating that the RPC was aborted. """ - raise NotImplementedError() - - @abc.abstractmethod - def future_unary_unary( - self, group, method, request, timeout, metadata=None, - protocol_options=None): - """Invokes a unary-request-unary-response method. + raise NotImplementedError() + + @abc.abstractmethod + def future_unary_unary(self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None): + """Invokes a unary-request-unary-response method. Args: group: The group identifier of the RPC. @@ -723,13 +762,17 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): response value of the RPC. In the event of RPC abortion, the returned Future's exception value will be an AbortionError. """ - raise NotImplementedError() - - @abc.abstractmethod - def inline_unary_stream( - self, group, method, request, timeout, metadata=None, - protocol_options=None): - """Invokes a unary-request-stream-response method. + raise NotImplementedError() + + @abc.abstractmethod + def inline_unary_stream(self, + group, + method, + request, + timeout, + metadata=None, + protocol_options=None): + """Invokes a unary-request-stream-response method. Args: group: The group identifier of the RPC. @@ -745,13 +788,18 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise AbortionError indicating abortion of the RPC. """ - raise NotImplementedError() - - @abc.abstractmethod - def blocking_stream_unary( - self, group, method, request_iterator, timeout, metadata=None, - with_call=False, protocol_options=None): - """Invokes a stream-request-unary-response method. + raise NotImplementedError() + + @abc.abstractmethod + def blocking_stream_unary(self, + group, + method, + request_iterator, + timeout, + metadata=None, + with_call=False, + protocol_options=None): + """Invokes a stream-request-unary-response method. This method blocks until either returning the response value of the RPC (in the event of RPC completion) or raising an exception (in the event of @@ -775,13 +823,17 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Raises: AbortionError: Indicating that the RPC was aborted. """ - raise NotImplementedError() - - @abc.abstractmethod - def future_stream_unary( - self, group, method, request_iterator, timeout, metadata=None, - protocol_options=None): - """Invokes a stream-request-unary-response method. + raise NotImplementedError() + + @abc.abstractmethod + def future_stream_unary(self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + """Invokes a stream-request-unary-response method. Args: group: The group identifier of the RPC. @@ -798,13 +850,17 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): response value of the RPC. In the event of RPC abortion, the returned Future's exception value will be an AbortionError. """ - raise NotImplementedError() - - @abc.abstractmethod - def inline_stream_stream( - self, group, method, request_iterator, timeout, metadata=None, - protocol_options=None): - """Invokes a stream-request-stream-response method. + raise NotImplementedError() + + @abc.abstractmethod + def inline_stream_stream(self, + group, + method, + request_iterator, + timeout, + metadata=None, + protocol_options=None): + """Invokes a stream-request-stream-response method. Args: group: The group identifier of the RPC. @@ -820,13 +876,19 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): values. Drawing response values from the returned iterator may raise AbortionError indicating abortion of the RPC. """ - raise NotImplementedError() - - @abc.abstractmethod - def event_unary_unary( - self, group, method, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Event-driven invocation of a unary-request-unary-response method. + raise NotImplementedError() + + @abc.abstractmethod + def event_unary_unary(self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Event-driven invocation of a unary-request-unary-response method. Args: group: The group identifier of the RPC. @@ -843,13 +905,19 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A Call for the RPC. """ - raise NotImplementedError() - - @abc.abstractmethod - def event_unary_stream( - self, group, method, request, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Event-driven invocation of a unary-request-stream-response method. + raise NotImplementedError() + + @abc.abstractmethod + def event_unary_stream(self, + group, + method, + request, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Event-driven invocation of a unary-request-stream-response method. Args: group: The group identifier of the RPC. @@ -866,13 +934,18 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A Call for the RPC. """ - raise NotImplementedError() - - @abc.abstractmethod - def event_stream_unary( - self, group, method, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Event-driven invocation of a unary-request-unary-response method. + raise NotImplementedError() + + @abc.abstractmethod + def event_stream_unary(self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Event-driven invocation of a unary-request-unary-response method. Args: group: The group identifier of the RPC. @@ -889,13 +962,18 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): A pair of a Call object for the RPC and a stream.Consumer to which the request values of the RPC should be passed. """ - raise NotImplementedError() - - @abc.abstractmethod - def event_stream_stream( - self, group, method, receiver, abortion_callback, timeout, - metadata=None, protocol_options=None): - """Event-driven invocation of a unary-request-stream-response method. + raise NotImplementedError() + + @abc.abstractmethod + def event_stream_stream(self, + group, + method, + receiver, + abortion_callback, + timeout, + metadata=None, + protocol_options=None): + """Event-driven invocation of a unary-request-stream-response method. Args: group: The group identifier of the RPC. @@ -912,11 +990,11 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): A pair of a Call object for the RPC and a stream.Consumer to which the request values of the RPC should be passed. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unary_unary(self, group, method): - """Creates a UnaryUnaryMultiCallable for a unary-unary method. + @abc.abstractmethod + def unary_unary(self, group, method): + """Creates a UnaryUnaryMultiCallable for a unary-unary method. Args: group: The group identifier of the RPC. @@ -925,11 +1003,11 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A UnaryUnaryMultiCallable value for the named unary-unary method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unary_stream(self, group, method): - """Creates a UnaryStreamMultiCallable for a unary-stream method. + @abc.abstractmethod + def unary_stream(self, group, method): + """Creates a UnaryStreamMultiCallable for a unary-stream method. Args: group: The group identifier of the RPC. @@ -938,11 +1016,11 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A UnaryStreamMultiCallable value for the name unary-stream method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_unary(self, group, method): - """Creates a StreamUnaryMultiCallable for a stream-unary method. + @abc.abstractmethod + def stream_unary(self, group, method): + """Creates a StreamUnaryMultiCallable for a stream-unary method. Args: group: The group identifier of the RPC. @@ -951,11 +1029,11 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A StreamUnaryMultiCallable value for the named stream-unary method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_stream(self, group, method): - """Creates a StreamStreamMultiCallable for a stream-stream method. + @abc.abstractmethod + def stream_stream(self, group, method): + """Creates a StreamStreamMultiCallable for a stream-stream method. Args: group: The group identifier of the RPC. @@ -964,11 +1042,11 @@ class GenericStub(six.with_metaclass(abc.ABCMeta)): Returns: A StreamStreamMultiCallable value for the named stream-stream method. """ - raise NotImplementedError() + raise NotImplementedError() class DynamicStub(six.with_metaclass(abc.ABCMeta)): - """Affords RPC invocation via attributes corresponding to afforded methods. + """Affords RPC invocation via attributes corresponding to afforded methods. Instances of this type may be scoped to a single group so that attribute access is unambiguous. diff --git a/src/python/grpcio/grpc/framework/interfaces/face/utilities.py b/src/python/grpcio/grpc/framework/interfaces/face/utilities.py index db2ec6ed87f..39a642f0ae2 100644 --- a/src/python/grpcio/grpc/framework/interfaces/face/utilities.py +++ b/src/python/grpcio/grpc/framework/interfaces/face/utilities.py @@ -26,7 +26,6 @@ # 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. - """Utilities for RPC Framework's Face interface.""" import collections @@ -38,18 +37,24 @@ from grpc.framework.foundation import stream # pylint: disable=unused-import from grpc.framework.interfaces.face import face -class _MethodImplementation( - face.MethodImplementation, - collections.namedtuple( - '_MethodImplementation', - ['cardinality', 'style', 'unary_unary_inline', 'unary_stream_inline', - 'stream_unary_inline', 'stream_stream_inline', 'unary_unary_event', - 'unary_stream_event', 'stream_unary_event', 'stream_stream_event',])): - pass +class _MethodImplementation(face.MethodImplementation, + collections.namedtuple('_MethodImplementation', [ + 'cardinality', + 'style', + 'unary_unary_inline', + 'unary_stream_inline', + 'stream_unary_inline', + 'stream_stream_inline', + 'unary_unary_event', + 'unary_stream_event', + 'stream_unary_event', + 'stream_stream_event', + ])): + pass def unary_unary_inline(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a unary-unary RPC method as a callable value @@ -59,13 +64,13 @@ def unary_unary_inline(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.UNARY_UNARY, style.Service.INLINE, behavior, - None, None, None, None, None, None, None) + return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY, + style.Service.INLINE, behavior, None, None, + None, None, None, None, None) def unary_stream_inline(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a unary-stream RPC method as a callable @@ -75,13 +80,13 @@ def unary_stream_inline(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.UNARY_STREAM, style.Service.INLINE, None, - behavior, None, None, None, None, None, None) + return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM, + style.Service.INLINE, None, behavior, None, + None, None, None, None, None) def stream_unary_inline(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a stream-unary RPC method as a callable @@ -91,13 +96,13 @@ def stream_unary_inline(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.STREAM_UNARY, style.Service.INLINE, None, None, - behavior, None, None, None, None, None) + return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY, + style.Service.INLINE, None, None, behavior, + None, None, None, None, None) def stream_stream_inline(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a stream-stream RPC method as a callable @@ -107,13 +112,13 @@ def stream_stream_inline(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.STREAM_STREAM, style.Service.INLINE, None, None, - None, behavior, None, None, None, None) + return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM, + style.Service.INLINE, None, None, None, + behavior, None, None, None, None) def unary_unary_event(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a unary-unary RPC method as a callable @@ -123,13 +128,13 @@ def unary_unary_event(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.UNARY_UNARY, style.Service.EVENT, None, None, - None, None, behavior, None, None, None) + return _MethodImplementation(cardinality.Cardinality.UNARY_UNARY, + style.Service.EVENT, None, None, None, None, + behavior, None, None, None) def unary_stream_event(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a unary-stream RPC method as a callable @@ -139,13 +144,13 @@ def unary_stream_event(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.UNARY_STREAM, style.Service.EVENT, None, None, - None, None, None, behavior, None, None) + return _MethodImplementation(cardinality.Cardinality.UNARY_STREAM, + style.Service.EVENT, None, None, None, None, + None, behavior, None, None) def stream_unary_event(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a stream-unary RPC method as a callable @@ -156,13 +161,13 @@ def stream_unary_event(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.STREAM_UNARY, style.Service.EVENT, None, None, - None, None, None, None, behavior, None) + return _MethodImplementation(cardinality.Cardinality.STREAM_UNARY, + style.Service.EVENT, None, None, None, None, + None, None, behavior, None) def stream_stream_event(behavior): - """Creates an face.MethodImplementation for the given behavior. + """Creates an face.MethodImplementation for the given behavior. Args: behavior: The implementation of a stream-stream RPC method as a callable @@ -173,6 +178,6 @@ def stream_stream_event(behavior): Returns: An face.MethodImplementation derived from the given behavior. """ - return _MethodImplementation( - cardinality.Cardinality.STREAM_STREAM, style.Service.EVENT, None, None, - None, None, None, None, None, behavior) + return _MethodImplementation(cardinality.Cardinality.STREAM_STREAM, + style.Service.EVENT, None, None, None, None, + None, None, None, behavior) diff --git a/src/python/grpcio/support.py b/src/python/grpcio/support.py index b226e690fdd..a228ba4a482 100644 --- a/src/python/grpcio/support.py +++ b/src/python/grpcio/support.py @@ -27,7 +27,6 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - import os import os.path import shutil @@ -38,7 +37,6 @@ from distutils import errors import commands - C_PYTHON_DEV = """ #include int main(int argc, char **argv) { return 0; } @@ -55,69 +53,70 @@ Could not find . This could mean the following: (check your environment variables or try re-installing?) """ -C_CHECKS = { - C_PYTHON_DEV: C_PYTHON_DEV_ERROR_MESSAGE, -} +C_CHECKS = {C_PYTHON_DEV: C_PYTHON_DEV_ERROR_MESSAGE,} + def _compile(compiler, source_string): - tempdir = tempfile.mkdtemp() - cpath = os.path.join(tempdir, 'a.c') - with open(cpath, 'w') as cfile: - cfile.write(source_string) - try: - compiler.compile([cpath]) - except errors.CompileError as error: - return error - finally: - shutil.rmtree(tempdir) + tempdir = tempfile.mkdtemp() + cpath = os.path.join(tempdir, 'a.c') + with open(cpath, 'w') as cfile: + cfile.write(source_string) + try: + compiler.compile([cpath]) + except errors.CompileError as error: + return error + finally: + shutil.rmtree(tempdir) + def _expect_compile(compiler, source_string, error_message): - if _compile(compiler, source_string) is not None: - sys.stderr.write(error_message) - raise commands.CommandError( - "Diagnostics found a compilation environment issue:\n{}" + if _compile(compiler, source_string) is not None: + sys.stderr.write(error_message) + raise commands.CommandError( + "Diagnostics found a compilation environment issue:\n{}" .format(error_message)) + def diagnose_compile_error(build_ext, error): - """Attempt to diagnose an error during compilation.""" - for c_check, message in C_CHECKS.items(): - _expect_compile(build_ext.compiler, c_check, message) - python_sources = [ - source for source in build_ext.get_source_files() - if source.startswith('./src/python') and source.endswith('c') - ] - for source in python_sources: - if not os.path.isfile(source): - raise commands.CommandError( - ("Diagnostics found a missing Python extension source file:\n{}\n\n" - "This is usually because the Cython sources haven't been transpiled " - "into C yet and you're building from source.\n" - "Try setting the environment variable " - "`GRPC_PYTHON_BUILD_WITH_CYTHON=1` when invoking `setup.py` or " - "when using `pip`, e.g.:\n\n" - "pip install -rrequirements.txt\n" - "GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .") - .format(source) - ) + """Attempt to diagnose an error during compilation.""" + for c_check, message in C_CHECKS.items(): + _expect_compile(build_ext.compiler, c_check, message) + python_sources = [ + source for source in build_ext.get_source_files() + if source.startswith('./src/python') and source.endswith('c') + ] + for source in python_sources: + if not os.path.isfile(source): + raise commands.CommandError(( + "Diagnostics found a missing Python extension source file:\n{}\n\n" + "This is usually because the Cython sources haven't been transpiled " + "into C yet and you're building from source.\n" + "Try setting the environment variable " + "`GRPC_PYTHON_BUILD_WITH_CYTHON=1` when invoking `setup.py` or " + "when using `pip`, e.g.:\n\n" + "pip install -rrequirements.txt\n" + "GRPC_PYTHON_BUILD_WITH_CYTHON=1 pip install .").format(source)) + def diagnose_attribute_error(build_ext, error): - if any('_needs_stub' in arg for arg in error.args): - raise commands.CommandError( - "We expect a missing `_needs_stub` attribute from older versions of " - "setuptools. Consider upgrading setuptools.") + if any('_needs_stub' in arg for arg in error.args): + raise commands.CommandError( + "We expect a missing `_needs_stub` attribute from older versions of " + "setuptools. Consider upgrading setuptools.") + _ERROR_DIAGNOSES = { errors.CompileError: diagnose_compile_error, AttributeError: diagnose_attribute_error } -def diagnose_build_ext_error(build_ext, error, formatted): - diagnostic = _ERROR_DIAGNOSES.get(type(error)) - if diagnostic is None: - raise commands.CommandError( - "\n\nWe could not diagnose your build failure. Please file an issue at " - "http://www.github.com/grpc/grpc with `[Python install]` in the title." - "\n\n{}".format(formatted)) - else: - diagnostic(build_ext, error) +def diagnose_build_ext_error(build_ext, error, formatted): + diagnostic = _ERROR_DIAGNOSES.get(type(error)) + if diagnostic is None: + raise commands.CommandError( + "\n\nWe could not diagnose your build failure. Please file an issue at " + "http://www.github.com/grpc/grpc with `[Python install]` in the title." + "\n\n{}".format(formatted)) + else: + diagnostic(build_ext, error) diff --git a/src/python/grpcio_health_checking/grpc_health/__init__.py b/src/python/grpcio_health_checking/grpc_health/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_health_checking/grpc_health/__init__.py +++ b/src/python/grpcio_health_checking/grpc_health/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_health_checking/grpc_health/v1/__init__.py b/src/python/grpcio_health_checking/grpc_health/v1/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/__init__.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_health_checking/grpc_health/v1/health.py b/src/python/grpcio_health_checking/grpc_health/v1/health.py index 0df679b0e22..f0f11cf84b0 100644 --- a/src/python/grpcio_health_checking/grpc_health/v1/health.py +++ b/src/python/grpcio_health_checking/grpc_health/v1/health.py @@ -26,7 +26,6 @@ # 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. - """Reference implementation for health checking in gRPC Python.""" import threading @@ -37,23 +36,23 @@ from grpc_health.v1 import health_pb2 class HealthServicer(health_pb2.HealthServicer): - """Servicer handling RPCs for service statuses.""" + """Servicer handling RPCs for service statuses.""" - def __init__(self): - self._server_status_lock = threading.Lock() - self._server_status = {} + def __init__(self): + self._server_status_lock = threading.Lock() + self._server_status = {} - def Check(self, request, context): - with self._server_status_lock: - status = self._server_status.get(request.service) - if status is None: - context.set_code(grpc.StatusCode.NOT_FOUND) - return health_pb2.HealthCheckResponse() - else: - return health_pb2.HealthCheckResponse(status=status) + def Check(self, request, context): + with self._server_status_lock: + status = self._server_status.get(request.service) + if status is None: + context.set_code(grpc.StatusCode.NOT_FOUND) + return health_pb2.HealthCheckResponse() + else: + return health_pb2.HealthCheckResponse(status=status) - def set(self, service, status): - """Sets the status of a service. + def set(self, service, status): + """Sets the status of a service. Args: service: string, the name of the service. @@ -61,5 +60,5 @@ class HealthServicer(health_pb2.HealthServicer): status: HealthCheckResponse.status enum value indicating the status of the service """ - with self._server_status_lock: - self._server_status[service] = status + with self._server_status_lock: + self._server_status[service] = status diff --git a/src/python/grpcio_health_checking/health_commands.py b/src/python/grpcio_health_checking/health_commands.py index 0c420a655f5..14375a74c0e 100644 --- a/src/python/grpcio_health_checking/health_commands.py +++ b/src/python/grpcio_health_checking/health_commands.py @@ -26,7 +26,6 @@ # 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. - """Provides distutils command classes for the GRPC Python setup process.""" import os @@ -39,40 +38,40 @@ HEALTH_PROTO = os.path.join(ROOT_DIR, '../../proto/grpc/health/v1/health.proto') class CopyProtoModules(setuptools.Command): - """Command to copy proto modules from grpc/src/proto.""" + """Command to copy proto modules from grpc/src/proto.""" - description = '' - user_options = [] + description = '' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - if os.path.isfile(HEALTH_PROTO): - shutil.copyfile( - HEALTH_PROTO, - os.path.join(ROOT_DIR, 'grpc_health/v1/health.proto')) + def run(self): + if os.path.isfile(HEALTH_PROTO): + shutil.copyfile( + HEALTH_PROTO, + os.path.join(ROOT_DIR, 'grpc_health/v1/health.proto')) class BuildPackageProtos(setuptools.Command): - """Command to generate project *_pb2.py modules from proto files.""" + """Command to generate project *_pb2.py modules from proto files.""" - description = 'build grpc protobuf modules' - user_options = [] + description = 'build grpc protobuf modules' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - # due to limitations of the proto generator, we require that only *one* - # directory is provided as an 'include' directory. We assume it's the '' key - # to `self.distribution.package_dir` (and get a key error if it's not - # there). - from grpc_tools import command - command.build_package_protos(self.distribution.package_dir['']) + def run(self): + # due to limitations of the proto generator, we require that only *one* + # directory is provided as an 'include' directory. We assume it's the '' key + # to `self.distribution.package_dir` (and get a key error if it's not + # there). + from grpc_tools import command + command.build_package_protos(self.distribution.package_dir['']) diff --git a/src/python/grpcio_health_checking/setup.py b/src/python/grpcio_health_checking/setup.py index e88f389ba8a..4c3991dcc4a 100644 --- a/src/python/grpcio_health_checking/setup.py +++ b/src/python/grpcio_health_checking/setup.py @@ -26,7 +26,6 @@ # 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. - """Setup module for the GRPC Python package's optional health checking.""" import os @@ -41,18 +40,14 @@ os.chdir(os.path.dirname(os.path.abspath(__file__))) import health_commands import grpc_version -PACKAGE_DIRECTORIES = { - '': '.', -} +PACKAGE_DIRECTORIES = {'': '.',} SETUP_REQUIRES = ( - 'grpcio-tools>={version}'.format(version=grpc_version.VERSION), -) + 'grpcio-tools>={version}'.format(version=grpc_version.VERSION),) INSTALL_REQUIRES = ( 'protobuf>=3.0.0', - 'grpcio>={version}'.format(version=grpc_version.VERSION), -) + 'grpcio>={version}'.format(version=grpc_version.VERSION),) COMMAND_CLASS = { # Run preprocess from the repository *before* doing any packaging! @@ -68,5 +63,4 @@ setuptools.setup( packages=setuptools.find_packages('.'), install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, - cmdclass=COMMAND_CLASS -) + cmdclass=COMMAND_CLASS) diff --git a/src/python/grpcio_reflection/grpc_reflection/__init__.py b/src/python/grpcio_reflection/grpc_reflection/__init__.py index d5ad73a74ab..100a624dc9c 100644 --- a/src/python/grpcio_reflection/grpc_reflection/__init__.py +++ b/src/python/grpcio_reflection/grpc_reflection/__init__.py @@ -26,4 +26,3 @@ # 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. - diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/__init__.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/__init__.py index d5ad73a74ab..100a624dc9c 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/__init__.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/__init__.py @@ -26,4 +26,3 @@ # 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. - diff --git a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py index bfcbce8e041..87f28396ce2 100644 --- a/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py +++ b/src/python/grpcio_reflection/grpc_reflection/v1alpha/reflection.py @@ -26,7 +26,6 @@ # 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. - """Reference implementation for reflection in gRPC Python.""" import threading @@ -39,105 +38,96 @@ from grpc_reflection.v1alpha import reflection_pb2 _POOL = descriptor_pool.Default() + def _not_found_error(): - return reflection_pb2.ServerReflectionResponse( - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.NOT_FOUND.value[0], - error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - ) - ) + return reflection_pb2.ServerReflectionResponse( + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.NOT_FOUND.value[0], + error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(),)) + def _file_descriptor_response(descriptor): - proto = descriptor_pb2.FileDescriptorProto() - descriptor.CopyToProto(proto) - serialized_proto = proto.SerializeToString() - return reflection_pb2.ServerReflectionResponse( - file_descriptor_response=reflection_pb2.FileDescriptorResponse( - file_descriptor_proto=(serialized_proto,) - ), - ) + proto = descriptor_pb2.FileDescriptorProto() + descriptor.CopyToProto(proto) + serialized_proto = proto.SerializeToString() + return reflection_pb2.ServerReflectionResponse( + file_descriptor_response=reflection_pb2.FileDescriptorResponse( + file_descriptor_proto=(serialized_proto,)),) class ReflectionServicer(reflection_pb2.ServerReflectionServicer): - """Servicer handling RPCs for service statuses.""" + """Servicer handling RPCs for service statuses.""" - def __init__(self, service_names, pool=None): - """Constructor. + def __init__(self, service_names, pool=None): + """Constructor. Args: service_names: Iterable of fully-qualified service names available. """ - self._service_names = list(service_names) - self._pool = _POOL if pool is None else pool - - def _file_by_filename(self, filename): - try: - descriptor = self._pool.FindFileByName(filename) - except KeyError: - return _not_found_error() - else: - return _file_descriptor_response(descriptor) - - def _file_containing_symbol(self, fully_qualified_name): - try: - descriptor = self._pool.FindFileContainingSymbol(fully_qualified_name) - except KeyError: - return _not_found_error() - else: - return _file_descriptor_response(descriptor) - - def _file_containing_extension(containing_type, extension_number): - # TODO(atash) Python protobuf currently doesn't support querying extensions. - # https://github.com/google/protobuf/issues/2248 - return reflection_pb2.ServerReflectionResponse( - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.UNIMPLEMENTED.value[0], - error_message=grpc.StatusCode.UNIMPLMENTED.value[1].encode(), - ) - ) - - def _extension_numbers_of_type(fully_qualified_name): - # TODO(atash) We're allowed to leave this unsupported according to the - # protocol, but we should still eventually implement it. Hits the same issue - # as `_file_containing_extension`, however. - # https://github.com/google/protobuf/issues/2248 - return reflection_pb2.ServerReflectionResponse( - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.UNIMPLEMENTED.value[0], - error_message=grpc.StatusCode.UNIMPLMENTED.value[1].encode(), - ) - ) + self._service_names = list(service_names) + self._pool = _POOL if pool is None else pool + + def _file_by_filename(self, filename): + try: + descriptor = self._pool.FindFileByName(filename) + except KeyError: + return _not_found_error() + else: + return _file_descriptor_response(descriptor) + + def _file_containing_symbol(self, fully_qualified_name): + try: + descriptor = self._pool.FindFileContainingSymbol( + fully_qualified_name) + except KeyError: + return _not_found_error() + else: + return _file_descriptor_response(descriptor) + + def _file_containing_extension(containing_type, extension_number): + # TODO(atash) Python protobuf currently doesn't support querying extensions. + # https://github.com/google/protobuf/issues/2248 + return reflection_pb2.ServerReflectionResponse( + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.UNIMPLEMENTED.value[0], + error_message=grpc.StatusCode.UNIMPLMENTED.value[1].encode(),)) + + def _extension_numbers_of_type(fully_qualified_name): + # TODO(atash) We're allowed to leave this unsupported according to the + # protocol, but we should still eventually implement it. Hits the same issue + # as `_file_containing_extension`, however. + # https://github.com/google/protobuf/issues/2248 + return reflection_pb2.ServerReflectionResponse( + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.UNIMPLEMENTED.value[0], + error_message=grpc.StatusCode.UNIMPLMENTED.value[1].encode(),)) - def _list_services(self): - return reflection_pb2.ServerReflectionResponse( - list_services_response=reflection_pb2.ListServiceResponse( - service=[ + def _list_services(self): + return reflection_pb2.ServerReflectionResponse( + list_services_response=reflection_pb2.ListServiceResponse(service=[ reflection_pb2.ServiceResponse(name=service_name) for service_name in self._service_names - ] - ) - ) - - def ServerReflectionInfo(self, request_iterator, context): - for request in request_iterator: - if request.HasField('file_by_filename'): - yield self._file_by_filename(request.file_by_filename) - elif request.HasField('file_containing_symbol'): - yield self._file_containing_symbol(request.file_containing_symbol) - elif request.HasField('file_containing_extension'): - yield self._file_containing_extension( - request.file_containing_extension.containing_type, - request.file_containing_extension.extension_number) - elif request.HasField('all_extension_numbers_of_type'): - yield _all_extension_numbers_of_type( - request.all_extension_numbers_of_type) - elif request.HasField('list_services'): - yield self._list_services() - else: - yield reflection_pb2.ServerReflectionResponse( - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0], - error_message=grpc.StatusCode.INVALID_ARGUMENT.value[1].encode(), - ) - ) - + ])) + + def ServerReflectionInfo(self, request_iterator, context): + for request in request_iterator: + if request.HasField('file_by_filename'): + yield self._file_by_filename(request.file_by_filename) + elif request.HasField('file_containing_symbol'): + yield self._file_containing_symbol( + request.file_containing_symbol) + elif request.HasField('file_containing_extension'): + yield self._file_containing_extension( + request.file_containing_extension.containing_type, + request.file_containing_extension.extension_number) + elif request.HasField('all_extension_numbers_of_type'): + yield _all_extension_numbers_of_type( + request.all_extension_numbers_of_type) + elif request.HasField('list_services'): + yield self._list_services() + else: + yield reflection_pb2.ServerReflectionResponse( + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.INVALID_ARGUMENT.value[0], + error_message=grpc.StatusCode.INVALID_ARGUMENT.value[1] + .encode(),)) diff --git a/src/python/grpcio_reflection/reflection_commands.py b/src/python/grpcio_reflection/reflection_commands.py index dee5491e0ad..62237e09719 100644 --- a/src/python/grpcio_reflection/reflection_commands.py +++ b/src/python/grpcio_reflection/reflection_commands.py @@ -26,7 +26,6 @@ # 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. - """Provides distutils command classes for the GRPC Python setup process.""" import os @@ -35,44 +34,46 @@ import shutil import setuptools ROOT_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) -HEALTH_PROTO = os.path.join(ROOT_DIR, '../../proto/grpc/reflection/v1alpha/reflection.proto') +HEALTH_PROTO = os.path.join( + ROOT_DIR, '../../proto/grpc/reflection/v1alpha/reflection.proto') class CopyProtoModules(setuptools.Command): - """Command to copy proto modules from grpc/src/proto.""" + """Command to copy proto modules from grpc/src/proto.""" - description = '' - user_options = [] + description = '' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - if os.path.isfile(HEALTH_PROTO): - shutil.copyfile( - HEALTH_PROTO, - os.path.join(ROOT_DIR, 'grpc_reflection/v1alpha/reflection.proto')) + def run(self): + if os.path.isfile(HEALTH_PROTO): + shutil.copyfile( + HEALTH_PROTO, + os.path.join(ROOT_DIR, + 'grpc_reflection/v1alpha/reflection.proto')) class BuildPackageProtos(setuptools.Command): - """Command to generate project *_pb2.py modules from proto files.""" + """Command to generate project *_pb2.py modules from proto files.""" - description = 'build grpc protobuf modules' - user_options = [] + description = 'build grpc protobuf modules' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - # due to limitations of the proto generator, we require that only *one* - # directory is provided as an 'include' directory. We assume it's the '' key - # to `self.distribution.package_dir` (and get a key error if it's not - # there). - from grpc_tools import command - command.build_package_protos(self.distribution.package_dir['']) + def run(self): + # due to limitations of the proto generator, we require that only *one* + # directory is provided as an 'include' directory. We assume it's the '' key + # to `self.distribution.package_dir` (and get a key error if it's not + # there). + from grpc_tools import command + command.build_package_protos(self.distribution.package_dir['']) diff --git a/src/python/grpcio_reflection/setup.py b/src/python/grpcio_reflection/setup.py index cfc41f4fe74..2926923029a 100644 --- a/src/python/grpcio_reflection/setup.py +++ b/src/python/grpcio_reflection/setup.py @@ -26,7 +26,6 @@ # 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. - """Setup module for the GRPC Python package's optional reflection.""" import os @@ -41,18 +40,14 @@ os.chdir(os.path.dirname(os.path.abspath(__file__))) import reflection_commands import grpc_version -PACKAGE_DIRECTORIES = { - '': '.', -} +PACKAGE_DIRECTORIES = {'': '.',} SETUP_REQUIRES = ( - 'grpcio-tools>={version}'.format(version=grpc_version.VERSION), -) + 'grpcio-tools>={version}'.format(version=grpc_version.VERSION),) INSTALL_REQUIRES = ( 'protobuf>=3.0.0', - 'grpcio>={version}'.format(version=grpc_version.VERSION), -) + 'grpcio>={version}'.format(version=grpc_version.VERSION),) COMMAND_CLASS = { # Run preprocess from the repository *before* doing any packaging! @@ -68,5 +63,4 @@ setuptools.setup( packages=setuptools.find_packages('.'), install_requires=INSTALL_REQUIRES, setup_requires=SETUP_REQUIRES, - cmdclass=COMMAND_CLASS -) + cmdclass=COMMAND_CLASS) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index e822971fe09..845b7f598c0 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -26,7 +26,6 @@ # 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. - """Provides distutils command classes for the gRPC Python setup process.""" import distutils @@ -55,163 +54,162 @@ PYTHON_PROTO_TOP_LEVEL = os.path.join(PYTHON_STEM, 'src') class CommandError(object): - pass + pass class GatherProto(setuptools.Command): - description = 'gather proto dependencies' - user_options = [] + description = 'gather proto dependencies' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - pass + def finalize_options(self): + pass - def run(self): - # TODO(atash) ensure that we're running from the repository directory when - # this command is used - try: - shutil.rmtree(PROTO_STEM) - except Exception as error: - # We don't care if this command fails - pass - shutil.copytree(GRPC_PROTO_STEM, PROTO_STEM) - for root, _, _ in os.walk(PYTHON_PROTO_TOP_LEVEL): - path = os.path.join(root, '__init__.py') - open(path, 'a').close() + def run(self): + # TODO(atash) ensure that we're running from the repository directory when + # this command is used + try: + shutil.rmtree(PROTO_STEM) + except Exception as error: + # We don't care if this command fails + pass + shutil.copytree(GRPC_PROTO_STEM, PROTO_STEM) + for root, _, _ in os.walk(PYTHON_PROTO_TOP_LEVEL): + path = os.path.join(root, '__init__.py') + open(path, 'a').close() class BuildProtoModules(setuptools.Command): - """Command to generate project *_pb2.py modules from proto files.""" - - description = 'build protobuf modules' - user_options = [ - ('include=', None, 'path patterns to include in protobuf generation'), - ('exclude=', None, 'path patterns to exclude from protobuf generation') - ] - - def initialize_options(self): - self.exclude = None - self.include = r'.*\.proto$' - - def finalize_options(self): - pass - - def run(self): - import grpc_tools.protoc as protoc - - include_regex = re.compile(self.include) - exclude_regex = re.compile(self.exclude) if self.exclude else None - paths = [] - for walk_root, directories, filenames in os.walk(PROTO_STEM): - for filename in filenames: - path = os.path.join(walk_root, filename) - if include_regex.match(path) and not ( - exclude_regex and exclude_regex.match(path)): - paths.append(path) - - # TODO(kpayson): It would be nice to do this in a batch command, - # but we currently have name conflicts in src/proto - for path in paths: - command = [ - 'grpc_tools.protoc', - '-I {}'.format(PROTO_STEM), - '--python_out={}'.format(PROTO_STEM), - '--grpc_python_out={}'.format(PROTO_STEM), - ] + [path] - if protoc.main(command) != 0: - sys.stderr.write( - 'warning: Command:\n{}\nFailed'.format( - command)) - - # Generated proto directories dont include __init__.py, but - # these are needed for python package resolution - for walk_root, _, _ in os.walk(PROTO_STEM): - path = os.path.join(walk_root, '__init__.py') - open(path, 'a').close() + """Command to generate project *_pb2.py modules from proto files.""" + + description = 'build protobuf modules' + user_options = [ + ('include=', None, 'path patterns to include in protobuf generation'), + ('exclude=', None, 'path patterns to exclude from protobuf generation') + ] + + def initialize_options(self): + self.exclude = None + self.include = r'.*\.proto$' + + def finalize_options(self): + pass + + def run(self): + import grpc_tools.protoc as protoc + + include_regex = re.compile(self.include) + exclude_regex = re.compile(self.exclude) if self.exclude else None + paths = [] + for walk_root, directories, filenames in os.walk(PROTO_STEM): + for filename in filenames: + path = os.path.join(walk_root, filename) + if include_regex.match(path) and not ( + exclude_regex and exclude_regex.match(path)): + paths.append(path) + + # TODO(kpayson): It would be nice to do this in a batch command, + # but we currently have name conflicts in src/proto + for path in paths: + command = [ + 'grpc_tools.protoc', + '-I {}'.format(PROTO_STEM), + '--python_out={}'.format(PROTO_STEM), + '--grpc_python_out={}'.format(PROTO_STEM), + ] + [path] + if protoc.main(command) != 0: + sys.stderr.write('warning: Command:\n{}\nFailed'.format( + command)) + + # Generated proto directories dont include __init__.py, but + # these are needed for python package resolution + for walk_root, _, _ in os.walk(PROTO_STEM): + path = os.path.join(walk_root, '__init__.py') + open(path, 'a').close() class BuildPy(build_py.build_py): - """Custom project build command.""" + """Custom project build command.""" - def run(self): - try: - self.run_command('build_package_protos') - except CommandError as error: - sys.stderr.write('warning: %s\n' % error.message) - build_py.build_py.run(self) + def run(self): + try: + self.run_command('build_package_protos') + except CommandError as error: + sys.stderr.write('warning: %s\n' % error.message) + build_py.build_py.run(self) class TestLite(setuptools.Command): - """Command to run tests without fetching or building anything.""" + """Command to run tests without fetching or building anything.""" - description = 'run tests without fetching or building anything.' - user_options = [] + description = 'run tests without fetching or building anything.' + user_options = [] - def initialize_options(self): - pass + def initialize_options(self): + pass - def finalize_options(self): - # distutils requires this override. - pass + def finalize_options(self): + # distutils requires this override. + pass - def run(self): - self._add_eggs_to_path() + def run(self): + self._add_eggs_to_path() - import tests - loader = tests.Loader() - loader.loadTestsFromNames(['tests']) - runner = tests.Runner() - result = runner.run(loader.suite) - if not result.wasSuccessful(): - sys.exit('Test failure') + import tests + loader = tests.Loader() + loader.loadTestsFromNames(['tests']) + runner = tests.Runner() + result = runner.run(loader.suite) + if not result.wasSuccessful(): + sys.exit('Test failure') - def _add_eggs_to_path(self): - """Fetch install and test requirements""" - self.distribution.fetch_build_eggs(self.distribution.install_requires) - self.distribution.fetch_build_eggs(self.distribution.tests_require) + def _add_eggs_to_path(self): + """Fetch install and test requirements""" + self.distribution.fetch_build_eggs(self.distribution.install_requires) + self.distribution.fetch_build_eggs(self.distribution.tests_require) class RunInterop(test.test): - description = 'run interop test client/server' - user_options = [ - ('args=', 'a', 'pass-thru arguments for the client/server'), - ('client', 'c', 'flag indicating to run the client'), - ('server', 's', 'flag indicating to run the server') - ] - - def initialize_options(self): - self.args = '' - self.client = False - self.server = False - - def finalize_options(self): - if self.client and self.server: - raise DistutilsOptionError('you may only specify one of client or server') - - def run(self): - if self.distribution.install_requires: - self.distribution.fetch_build_eggs(self.distribution.install_requires) - if self.distribution.tests_require: - self.distribution.fetch_build_eggs(self.distribution.tests_require) - if self.client: - self.run_client() - elif self.server: - self.run_server() - - def run_server(self): - # We import here to ensure that our setuptools parent has had a chance to - # edit the Python system path. - from tests.interop import server - sys.argv[1:] = self.args.split() - server.serve() - - def run_client(self): - # We import here to ensure that our setuptools parent has had a chance to - # edit the Python system path. - from tests.interop import client - sys.argv[1:] = self.args.split() - client.test_interoperability() + description = 'run interop test client/server' + user_options = [('args=', 'a', 'pass-thru arguments for the client/server'), + ('client', 'c', 'flag indicating to run the client'), + ('server', 's', 'flag indicating to run the server')] + + def initialize_options(self): + self.args = '' + self.client = False + self.server = False + + def finalize_options(self): + if self.client and self.server: + raise DistutilsOptionError( + 'you may only specify one of client or server') + + def run(self): + if self.distribution.install_requires: + self.distribution.fetch_build_eggs( + self.distribution.install_requires) + if self.distribution.tests_require: + self.distribution.fetch_build_eggs(self.distribution.tests_require) + if self.client: + self.run_client() + elif self.server: + self.run_server() + + def run_server(self): + # We import here to ensure that our setuptools parent has had a chance to + # edit the Python system path. + from tests.interop import server + sys.argv[1:] = self.args.split() + server.serve() + + def run_client(self): + # We import here to ensure that our setuptools parent has had a chance to + # edit the Python system path. + from tests.interop import client + sys.argv[1:] = self.args.split() + client.test_interoperability() diff --git a/src/python/grpcio_tests/setup.py b/src/python/grpcio_tests/setup.py index 375fbd6c77d..f0407d1a557 100644 --- a/src/python/grpcio_tests/setup.py +++ b/src/python/grpcio_tests/setup.py @@ -26,7 +26,6 @@ # 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. - """A setup module for the gRPC Python package.""" import os @@ -48,9 +47,7 @@ import grpc_version LICENSE = '3-clause BSD' -PACKAGE_DIRECTORIES = { - '': '.', -} +PACKAGE_DIRECTORIES = {'': '.',} INSTALL_REQUIRES = ( 'coverage>=4.0', @@ -61,13 +58,11 @@ INSTALL_REQUIRES = ( 'grpcio-health-checking>={version}'.format(version=grpc_version.VERSION), 'oauth2client>=1.4.7', 'protobuf>=3.0.0', - 'six>=1.10', -) + 'six>=1.10',) COMMAND_CLASS = { # Run `preprocess` *before* doing any packaging! 'preprocess': commands.GatherProto, - 'build_package_protos': grpc_tools.command.BuildPackageProtos, 'build_py': commands.BuildPy, 'run_interop': commands.RunInterop, @@ -80,9 +75,7 @@ PACKAGE_DATA = { 'credentials/server1.key', 'credentials/server1.pem', ], - 'tests.protoc_plugin.protos.invocation_testing': [ - 'same.proto', - ], + 'tests.protoc_plugin.protos.invocation_testing': ['same.proto',], 'tests.protoc_plugin.protos.invocation_testing.split_messages': [ 'messages.proto', ], @@ -94,9 +87,7 @@ PACKAGE_DATA = { 'credentials/server1.key', 'credentials/server1.pem', ], - 'tests': [ - 'tests.json' - ], + 'tests': ['tests.json'], } TEST_SUITE = 'tests' @@ -107,16 +98,15 @@ TESTS_REQUIRE = INSTALL_REQUIRES PACKAGES = setuptools.find_packages('.') setuptools.setup( - name='grpcio-tests', - version=grpc_version.VERSION, - license=LICENSE, - packages=list(PACKAGES), - package_dir=PACKAGE_DIRECTORIES, - package_data=PACKAGE_DATA, - install_requires=INSTALL_REQUIRES, - cmdclass=COMMAND_CLASS, - tests_require=TESTS_REQUIRE, - test_suite=TEST_SUITE, - test_loader=TEST_LOADER, - test_runner=TEST_RUNNER, -) + name='grpcio-tests', + version=grpc_version.VERSION, + license=LICENSE, + packages=list(PACKAGES), + package_dir=PACKAGE_DIRECTORIES, + package_data=PACKAGE_DATA, + install_requires=INSTALL_REQUIRES, + cmdclass=COMMAND_CLASS, + tests_require=TESTS_REQUIRE, + test_suite=TEST_SUITE, + test_loader=TEST_LOADER, + test_runner=TEST_RUNNER,) diff --git a/src/python/grpcio_tests/tests/_loader.py b/src/python/grpcio_tests/tests/_loader.py index 621bedc7bb8..42cf9ab4cac 100644 --- a/src/python/grpcio_tests/tests/_loader.py +++ b/src/python/grpcio_tests/tests/_loader.py @@ -40,7 +40,7 @@ TEST_MODULE_REGEX = r'^.*_test$' class Loader(object): - """Test loader for setuptools test suite support. + """Test loader for setuptools test suite support. Attributes: suite (unittest.TestSuite): All tests collected by the loader. @@ -51,57 +51,57 @@ class Loader(object): contributes to the test suite. """ - def __init__(self): - self.suite = unittest.TestSuite() - self.loader = unittest.TestLoader() - self.module_matcher = re.compile(TEST_MODULE_REGEX) + def __init__(self): + self.suite = unittest.TestSuite() + self.loader = unittest.TestLoader() + self.module_matcher = re.compile(TEST_MODULE_REGEX) - def loadTestsFromNames(self, names, module=None): - """Function mirroring TestLoader::loadTestsFromNames, as expected by + def loadTestsFromNames(self, names, module=None): + """Function mirroring TestLoader::loadTestsFromNames, as expected by setuptools.setup argument `test_loader`.""" - # ensure that we capture decorators and definitions (else our coverage - # measure unnecessarily suffers) - coverage_context = coverage.Coverage(data_suffix=True) - coverage_context.start() - modules = [importlib.import_module(name) for name in names] - for module in modules: - self.visit_module(module) - for module in modules: - try: - package_paths = module.__path__ - except: - continue - self.walk_packages(package_paths) - coverage_context.stop() - coverage_context.save() - return self.suite - - def walk_packages(self, package_paths): - """Walks over the packages, dispatching `visit_module` calls. + # ensure that we capture decorators and definitions (else our coverage + # measure unnecessarily suffers) + coverage_context = coverage.Coverage(data_suffix=True) + coverage_context.start() + modules = [importlib.import_module(name) for name in names] + for module in modules: + self.visit_module(module) + for module in modules: + try: + package_paths = module.__path__ + except: + continue + self.walk_packages(package_paths) + coverage_context.stop() + coverage_context.save() + return self.suite + + def walk_packages(self, package_paths): + """Walks over the packages, dispatching `visit_module` calls. Args: package_paths (list): A list of paths over which to walk through modules along. """ - for importer, module_name, is_package in ( - pkgutil.walk_packages(package_paths)): - module = importer.find_module(module_name).load_module(module_name) - self.visit_module(module) + for importer, module_name, is_package in ( + pkgutil.walk_packages(package_paths)): + module = importer.find_module(module_name).load_module(module_name) + self.visit_module(module) - def visit_module(self, module): - """Visits the module, adding discovered tests to the test suite. + def visit_module(self, module): + """Visits the module, adding discovered tests to the test suite. Args: module (module): Module to match against self.module_matcher; if matched it has its tests loaded via self.loader into self.suite. """ - if self.module_matcher.match(module.__name__): - module_suite = self.loader.loadTestsFromModule(module) - self.suite.addTest(module_suite) + if self.module_matcher.match(module.__name__): + module_suite = self.loader.loadTestsFromModule(module) + self.suite.addTest(module_suite) def iterate_suite_cases(suite): - """Generator over all unittest.TestCases in a unittest.TestSuite. + """Generator over all unittest.TestCases in a unittest.TestSuite. Args: suite (unittest.TestSuite): Suite to iterate over in the generator. @@ -109,11 +109,12 @@ def iterate_suite_cases(suite): Returns: generator: A generator over all unittest.TestCases in `suite`. """ - for item in suite: - if isinstance(item, unittest.TestSuite): - for child_item in iterate_suite_cases(item): - yield child_item - elif isinstance(item, unittest.TestCase): - yield item - else: - raise ValueError('unexpected suite item of type {}'.format(type(item))) + for item in suite: + if isinstance(item, unittest.TestSuite): + for child_item in iterate_suite_cases(item): + yield child_item + elif isinstance(item, unittest.TestCase): + yield item + else: + raise ValueError('unexpected suite item of type {}'.format( + type(item))) diff --git a/src/python/grpcio_tests/tests/_result.py b/src/python/grpcio_tests/tests/_result.py index 1acec6a9b59..794b7540f14 100644 --- a/src/python/grpcio_tests/tests/_result.py +++ b/src/python/grpcio_tests/tests/_result.py @@ -41,9 +41,11 @@ from six import moves from tests import _loader -class CaseResult(collections.namedtuple('CaseResult', [ - 'id', 'name', 'kind', 'stdout', 'stderr', 'skip_reason', 'traceback'])): - """A serializable result of a single test case. +class CaseResult( + collections.namedtuple('CaseResult', [ + 'id', 'name', 'kind', 'stdout', 'stderr', 'skip_reason', 'traceback' + ])): + """A serializable result of a single test case. Attributes: id (object): Any serializable object used to denote the identity of this @@ -59,62 +61,78 @@ class CaseResult(collections.namedtuple('CaseResult', [ None. """ - class Kind: - UNTESTED = 'untested' - RUNNING = 'running' - ERROR = 'error' - FAILURE = 'failure' - SUCCESS = 'success' - SKIP = 'skip' - EXPECTED_FAILURE = 'expected failure' - UNEXPECTED_SUCCESS = 'unexpected success' - - def __new__(cls, id=None, name=None, kind=None, stdout=None, stderr=None, - skip_reason=None, traceback=None): - """Helper keyword constructor for the namedtuple. + class Kind: + UNTESTED = 'untested' + RUNNING = 'running' + ERROR = 'error' + FAILURE = 'failure' + SUCCESS = 'success' + SKIP = 'skip' + EXPECTED_FAILURE = 'expected failure' + UNEXPECTED_SUCCESS = 'unexpected success' + + def __new__(cls, + id=None, + name=None, + kind=None, + stdout=None, + stderr=None, + skip_reason=None, + traceback=None): + """Helper keyword constructor for the namedtuple. See this class' attributes for information on the arguments.""" - assert id is not None - assert name is None or isinstance(name, str) - if kind is CaseResult.Kind.UNTESTED: - pass - elif kind is CaseResult.Kind.RUNNING: - pass - elif kind is CaseResult.Kind.ERROR: - assert traceback is not None - elif kind is CaseResult.Kind.FAILURE: - assert traceback is not None - elif kind is CaseResult.Kind.SUCCESS: - pass - elif kind is CaseResult.Kind.SKIP: - assert skip_reason is not None - elif kind is CaseResult.Kind.EXPECTED_FAILURE: - assert traceback is not None - elif kind is CaseResult.Kind.UNEXPECTED_SUCCESS: - pass - else: - assert False - return super(cls, CaseResult).__new__( - cls, id, name, kind, stdout, stderr, skip_reason, traceback) - - def updated(self, name=None, kind=None, stdout=None, stderr=None, - skip_reason=None, traceback=None): - """Get a new validated CaseResult with the fields updated. + assert id is not None + assert name is None or isinstance(name, str) + if kind is CaseResult.Kind.UNTESTED: + pass + elif kind is CaseResult.Kind.RUNNING: + pass + elif kind is CaseResult.Kind.ERROR: + assert traceback is not None + elif kind is CaseResult.Kind.FAILURE: + assert traceback is not None + elif kind is CaseResult.Kind.SUCCESS: + pass + elif kind is CaseResult.Kind.SKIP: + assert skip_reason is not None + elif kind is CaseResult.Kind.EXPECTED_FAILURE: + assert traceback is not None + elif kind is CaseResult.Kind.UNEXPECTED_SUCCESS: + pass + else: + assert False + return super(cls, CaseResult).__new__(cls, id, name, kind, stdout, + stderr, skip_reason, traceback) + + def updated(self, + name=None, + kind=None, + stdout=None, + stderr=None, + skip_reason=None, + traceback=None): + """Get a new validated CaseResult with the fields updated. See this class' attributes for information on the arguments.""" - name = self.name if name is None else name - kind = self.kind if kind is None else kind - stdout = self.stdout if stdout is None else stdout - stderr = self.stderr if stderr is None else stderr - skip_reason = self.skip_reason if skip_reason is None else skip_reason - traceback = self.traceback if traceback is None else traceback - return CaseResult(id=self.id, name=name, kind=kind, stdout=stdout, - stderr=stderr, skip_reason=skip_reason, - traceback=traceback) + name = self.name if name is None else name + kind = self.kind if kind is None else kind + stdout = self.stdout if stdout is None else stdout + stderr = self.stderr if stderr is None else stderr + skip_reason = self.skip_reason if skip_reason is None else skip_reason + traceback = self.traceback if traceback is None else traceback + return CaseResult( + id=self.id, + name=name, + kind=kind, + stdout=stdout, + stderr=stderr, + skip_reason=skip_reason, + traceback=traceback) class AugmentedResult(unittest.TestResult): - """unittest.Result that keeps track of additional information. + """unittest.Result that keeps track of additional information. Uses CaseResult objects to store test-case results, providing additional information beyond that of the standard Python unittest library, such as @@ -127,228 +145,215 @@ class AugmentedResult(unittest.TestResult): to CaseResult objects corresponding to those IDs. """ - def __init__(self, id_map): - """Initialize the object with an identifier mapping. + def __init__(self, id_map): + """Initialize the object with an identifier mapping. Arguments: id_map (callable): Corresponds to the attribute `id_map`.""" - super(AugmentedResult, self).__init__() - self.id_map = id_map - self.cases = None - - def startTestRun(self): - """See unittest.TestResult.startTestRun.""" - super(AugmentedResult, self).startTestRun() - self.cases = dict() - - def stopTestRun(self): - """See unittest.TestResult.stopTestRun.""" - super(AugmentedResult, self).stopTestRun() - - def startTest(self, test): - """See unittest.TestResult.startTest.""" - super(AugmentedResult, self).startTest(test) - case_id = self.id_map(test) - self.cases[case_id] = CaseResult( - id=case_id, name=test.id(), kind=CaseResult.Kind.RUNNING) - - def addError(self, test, error): - """See unittest.TestResult.addError.""" - super(AugmentedResult, self).addError(test, error) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.ERROR, traceback=error) - - def addFailure(self, test, error): - """See unittest.TestResult.addFailure.""" - super(AugmentedResult, self).addFailure(test, error) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.FAILURE, traceback=error) - - def addSuccess(self, test): - """See unittest.TestResult.addSuccess.""" - super(AugmentedResult, self).addSuccess(test) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.SUCCESS) - - def addSkip(self, test, reason): - """See unittest.TestResult.addSkip.""" - super(AugmentedResult, self).addSkip(test, reason) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.SKIP, skip_reason=reason) - - def addExpectedFailure(self, test, error): - """See unittest.TestResult.addExpectedFailure.""" - super(AugmentedResult, self).addExpectedFailure(test, error) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.EXPECTED_FAILURE, traceback=error) - - def addUnexpectedSuccess(self, test): - """See unittest.TestResult.addUnexpectedSuccess.""" - super(AugmentedResult, self).addUnexpectedSuccess(test) - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - kind=CaseResult.Kind.UNEXPECTED_SUCCESS) - - def set_output(self, test, stdout, stderr): - """Set the output attributes for the CaseResult corresponding to a test. + super(AugmentedResult, self).__init__() + self.id_map = id_map + self.cases = None + + def startTestRun(self): + """See unittest.TestResult.startTestRun.""" + super(AugmentedResult, self).startTestRun() + self.cases = dict() + + def stopTestRun(self): + """See unittest.TestResult.stopTestRun.""" + super(AugmentedResult, self).stopTestRun() + + def startTest(self, test): + """See unittest.TestResult.startTest.""" + super(AugmentedResult, self).startTest(test) + case_id = self.id_map(test) + self.cases[case_id] = CaseResult( + id=case_id, name=test.id(), kind=CaseResult.Kind.RUNNING) + + def addError(self, test, error): + """See unittest.TestResult.addError.""" + super(AugmentedResult, self).addError(test, error) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.ERROR, traceback=error) + + def addFailure(self, test, error): + """See unittest.TestResult.addFailure.""" + super(AugmentedResult, self).addFailure(test, error) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.FAILURE, traceback=error) + + def addSuccess(self, test): + """See unittest.TestResult.addSuccess.""" + super(AugmentedResult, self).addSuccess(test) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.SUCCESS) + + def addSkip(self, test, reason): + """See unittest.TestResult.addSkip.""" + super(AugmentedResult, self).addSkip(test, reason) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.SKIP, skip_reason=reason) + + def addExpectedFailure(self, test, error): + """See unittest.TestResult.addExpectedFailure.""" + super(AugmentedResult, self).addExpectedFailure(test, error) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.EXPECTED_FAILURE, traceback=error) + + def addUnexpectedSuccess(self, test): + """See unittest.TestResult.addUnexpectedSuccess.""" + super(AugmentedResult, self).addUnexpectedSuccess(test) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + kind=CaseResult.Kind.UNEXPECTED_SUCCESS) + + def set_output(self, test, stdout, stderr): + """Set the output attributes for the CaseResult corresponding to a test. Args: test (unittest.TestCase): The TestCase to set the outputs of. stdout (str): Output from stdout to assign to self.id_map(test). stderr (str): Output from stderr to assign to self.id_map(test). """ - case_id = self.id_map(test) - self.cases[case_id] = self.cases[case_id].updated( - stdout=stdout.decode(), stderr=stderr.decode()) + case_id = self.id_map(test) + self.cases[case_id] = self.cases[case_id].updated( + stdout=stdout.decode(), stderr=stderr.decode()) - def augmented_results(self, filter): - """Convenience method to retrieve filtered case results. + def augmented_results(self, filter): + """Convenience method to retrieve filtered case results. Args: filter (callable): A unary predicate to filter over CaseResult objects. """ - return (self.cases[case_id] for case_id in self.cases - if filter(self.cases[case_id])) + return (self.cases[case_id] for case_id in self.cases + if filter(self.cases[case_id])) class CoverageResult(AugmentedResult): - """Extension to AugmentedResult adding coverage.py support per test.\ + """Extension to AugmentedResult adding coverage.py support per test.\ Attributes: coverage_context (coverage.Coverage): coverage.py management object. """ - def __init__(self, id_map): - """See AugmentedResult.__init__.""" - super(CoverageResult, self).__init__(id_map=id_map) - self.coverage_context = None + def __init__(self, id_map): + """See AugmentedResult.__init__.""" + super(CoverageResult, self).__init__(id_map=id_map) + self.coverage_context = None - def startTest(self, test): - """See unittest.TestResult.startTest. + def startTest(self, test): + """See unittest.TestResult.startTest. Additionally initializes and begins code coverage tracking.""" - super(CoverageResult, self).startTest(test) - self.coverage_context = coverage.Coverage(data_suffix=True) - self.coverage_context.start() + super(CoverageResult, self).startTest(test) + self.coverage_context = coverage.Coverage(data_suffix=True) + self.coverage_context.start() - def stopTest(self, test): - """See unittest.TestResult.stopTest. + def stopTest(self, test): + """See unittest.TestResult.stopTest. Additionally stops and deinitializes code coverage tracking.""" - super(CoverageResult, self).stopTest(test) - self.coverage_context.stop() - self.coverage_context.save() - self.coverage_context = None + super(CoverageResult, self).stopTest(test) + self.coverage_context.stop() + self.coverage_context.save() + self.coverage_context = None - def stopTestRun(self): - """See unittest.TestResult.stopTestRun.""" - super(CoverageResult, self).stopTestRun() - # TODO(atash): Dig deeper into why the following line fails to properly - # combine coverage data from the Cython plugin. - #coverage.Coverage().combine() + def stopTestRun(self): + """See unittest.TestResult.stopTestRun.""" + super(CoverageResult, self).stopTestRun() + # TODO(atash): Dig deeper into why the following line fails to properly + # combine coverage data from the Cython plugin. + #coverage.Coverage().combine() class _Colors: - """Namespaced constants for terminal color magic numbers.""" - HEADER = '\033[95m' - INFO = '\033[94m' - OK = '\033[92m' - WARN = '\033[93m' - FAIL = '\033[91m' - BOLD = '\033[1m' - UNDERLINE = '\033[4m' - END = '\033[0m' + """Namespaced constants for terminal color magic numbers.""" + HEADER = '\033[95m' + INFO = '\033[94m' + OK = '\033[92m' + WARN = '\033[93m' + FAIL = '\033[91m' + BOLD = '\033[1m' + UNDERLINE = '\033[4m' + END = '\033[0m' class TerminalResult(CoverageResult): - """Extension to CoverageResult adding basic terminal reporting.""" + """Extension to CoverageResult adding basic terminal reporting.""" - def __init__(self, out, id_map): - """Initialize the result object. + def __init__(self, out, id_map): + """Initialize the result object. Args: out (file-like): Output file to which terminal-colored live results will be written. id_map (callable): See AugmentedResult.__init__. """ - super(TerminalResult, self).__init__(id_map=id_map) - self.out = out - - def startTestRun(self): - """See unittest.TestResult.startTestRun.""" - super(TerminalResult, self).startTestRun() - self.out.write( - _Colors.HEADER + - 'Testing gRPC Python...\n' + - _Colors.END) - - def stopTestRun(self): - """See unittest.TestResult.stopTestRun.""" - super(TerminalResult, self).stopTestRun() - self.out.write(summary(self)) - self.out.flush() - - def addError(self, test, error): - """See unittest.TestResult.addError.""" - super(TerminalResult, self).addError(test, error) - self.out.write( - _Colors.FAIL + - 'ERROR {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() - - def addFailure(self, test, error): - """See unittest.TestResult.addFailure.""" - super(TerminalResult, self).addFailure(test, error) - self.out.write( - _Colors.FAIL + - 'FAILURE {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() - - def addSuccess(self, test): - """See unittest.TestResult.addSuccess.""" - super(TerminalResult, self).addSuccess(test) - self.out.write( - _Colors.OK + - 'SUCCESS {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() - - def addSkip(self, test, reason): - """See unittest.TestResult.addSkip.""" - super(TerminalResult, self).addSkip(test, reason) - self.out.write( - _Colors.INFO + - 'SKIP {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() - - def addExpectedFailure(self, test, error): - """See unittest.TestResult.addExpectedFailure.""" - super(TerminalResult, self).addExpectedFailure(test, error) - self.out.write( - _Colors.INFO + - 'FAILURE_OK {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() - - def addUnexpectedSuccess(self, test): - """See unittest.TestResult.addUnexpectedSuccess.""" - super(TerminalResult, self).addUnexpectedSuccess(test) - self.out.write( - _Colors.INFO + - 'UNEXPECTED_OK {}\n'.format(test.id()) + - _Colors.END) - self.out.flush() + super(TerminalResult, self).__init__(id_map=id_map) + self.out = out + + def startTestRun(self): + """See unittest.TestResult.startTestRun.""" + super(TerminalResult, self).startTestRun() + self.out.write(_Colors.HEADER + 'Testing gRPC Python...\n' + + _Colors.END) + + def stopTestRun(self): + """See unittest.TestResult.stopTestRun.""" + super(TerminalResult, self).stopTestRun() + self.out.write(summary(self)) + self.out.flush() + + def addError(self, test, error): + """See unittest.TestResult.addError.""" + super(TerminalResult, self).addError(test, error) + self.out.write(_Colors.FAIL + 'ERROR {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + + def addFailure(self, test, error): + """See unittest.TestResult.addFailure.""" + super(TerminalResult, self).addFailure(test, error) + self.out.write(_Colors.FAIL + 'FAILURE {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + + def addSuccess(self, test): + """See unittest.TestResult.addSuccess.""" + super(TerminalResult, self).addSuccess(test) + self.out.write(_Colors.OK + 'SUCCESS {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + + def addSkip(self, test, reason): + """See unittest.TestResult.addSkip.""" + super(TerminalResult, self).addSkip(test, reason) + self.out.write(_Colors.INFO + 'SKIP {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + + def addExpectedFailure(self, test, error): + """See unittest.TestResult.addExpectedFailure.""" + super(TerminalResult, self).addExpectedFailure(test, error) + self.out.write(_Colors.INFO + 'FAILURE_OK {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + + def addUnexpectedSuccess(self, test): + """See unittest.TestResult.addUnexpectedSuccess.""" + super(TerminalResult, self).addUnexpectedSuccess(test) + self.out.write(_Colors.INFO + 'UNEXPECTED_OK {}\n'.format(test.id()) + + _Colors.END) + self.out.flush() + def _traceback_string(type, value, trace): - """Generate a descriptive string of a Python exception traceback. + """Generate a descriptive string of a Python exception traceback. Args: type (class): The type of the exception. @@ -358,12 +363,13 @@ def _traceback_string(type, value, trace): Returns: str: Formatted exception descriptive string. """ - buffer = moves.cStringIO() - traceback.print_exception(type, value, trace, file=buffer) - return buffer.getvalue() + buffer = moves.cStringIO() + traceback.print_exception(type, value, trace, file=buffer) + return buffer.getvalue() + def summary(result): - """A summary string of a result object. + """A summary string of a result object. Args: result (AugmentedResult): The result object to get the summary of. @@ -371,62 +377,68 @@ def summary(result): Returns: str: The summary string. """ - assert isinstance(result, AugmentedResult) - untested = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.UNTESTED)) - running = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.RUNNING)) - failures = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.FAILURE)) - errors = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.ERROR)) - successes = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.SUCCESS)) - skips = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.SKIP)) - expected_failures = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.EXPECTED_FAILURE)) - unexpected_successes = list(result.augmented_results( - lambda case_result: case_result.kind is CaseResult.Kind.UNEXPECTED_SUCCESS)) - running_names = [case.name for case in running] - finished_count = (len(failures) + len(errors) + len(successes) + - len(expected_failures) + len(unexpected_successes)) - statistics = ( - '{finished} tests finished:\n' - '\t{successful} successful\n' - '\t{unsuccessful} unsuccessful\n' - '\t{skipped} skipped\n' - '\t{expected_fail} expected failures\n' - '\t{unexpected_successful} unexpected successes\n' - 'Interrupted Tests:\n' - '\t{interrupted}\n' - .format(finished=finished_count, - successful=len(successes), - unsuccessful=(len(failures)+len(errors)), - skipped=len(skips), - expected_fail=len(expected_failures), - unexpected_successful=len(unexpected_successes), - interrupted=str(running_names))) - tracebacks = '\n\n'.join([ - (_Colors.FAIL + '{test_name}' + _Colors.END + '\n' + - _Colors.BOLD + 'traceback:' + _Colors.END + '\n' + - '{traceback}\n' + - _Colors.BOLD + 'stdout:' + _Colors.END + '\n' + - '{stdout}\n' + - _Colors.BOLD + 'stderr:' + _Colors.END + '\n' + - '{stderr}\n').format( - test_name=result.name, - traceback=_traceback_string(*result.traceback), - stdout=result.stdout, stderr=result.stderr) - for result in itertools.chain(failures, errors) - ]) - notes = 'Unexpected successes: {}\n'.format([ - result.name for result in unexpected_successes]) - return statistics + '\nErrors/Failures: \n' + tracebacks + '\n' + notes + assert isinstance(result, AugmentedResult) + untested = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.UNTESTED)) + running = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.RUNNING)) + failures = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.FAILURE)) + errors = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.ERROR)) + successes = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.SUCCESS)) + skips = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.SKIP)) + expected_failures = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.EXPECTED_FAILURE + )) + unexpected_successes = list( + result.augmented_results( + lambda case_result: case_result.kind is CaseResult.Kind.UNEXPECTED_SUCCESS + )) + running_names = [case.name for case in running] + finished_count = (len(failures) + len(errors) + len(successes) + + len(expected_failures) + len(unexpected_successes)) + statistics = ('{finished} tests finished:\n' + '\t{successful} successful\n' + '\t{unsuccessful} unsuccessful\n' + '\t{skipped} skipped\n' + '\t{expected_fail} expected failures\n' + '\t{unexpected_successful} unexpected successes\n' + 'Interrupted Tests:\n' + '\t{interrupted}\n'.format( + finished=finished_count, + successful=len(successes), + unsuccessful=(len(failures) + len(errors)), + skipped=len(skips), + expected_fail=len(expected_failures), + unexpected_successful=len(unexpected_successes), + interrupted=str(running_names))) + tracebacks = '\n\n'.join( + [(_Colors.FAIL + '{test_name}' + _Colors.END + '\n' + _Colors.BOLD + + 'traceback:' + _Colors.END + '\n' + '{traceback}\n' + _Colors.BOLD + + 'stdout:' + _Colors.END + '\n' + '{stdout}\n' + _Colors.BOLD + + 'stderr:' + _Colors.END + '\n' + '{stderr}\n').format( + test_name=result.name, + traceback=_traceback_string(*result.traceback), + stdout=result.stdout, + stderr=result.stderr) + for result in itertools.chain(failures, errors)]) + notes = 'Unexpected successes: {}\n'.format( + [result.name for result in unexpected_successes]) + return statistics + '\nErrors/Failures: \n' + tracebacks + '\n' + notes def jenkins_junit_xml(result): - """An XML tree object that when written is recognizable by Jenkins. + """An XML tree object that when written is recognizable by Jenkins. Args: result (AugmentedResult): The result object to get the junit xml output of. @@ -434,20 +446,18 @@ def jenkins_junit_xml(result): Returns: ElementTree.ElementTree: The XML tree. """ - assert isinstance(result, AugmentedResult) - root = ElementTree.Element('testsuites') - suite = ElementTree.SubElement(root, 'testsuite', { - 'name': 'Python gRPC tests', - }) - for case in result.cases.values(): - if case.kind is CaseResult.Kind.SUCCESS: - ElementTree.SubElement(suite, 'testcase', { - 'name': case.name, - }) - elif case.kind in (CaseResult.Kind.ERROR, CaseResult.Kind.FAILURE): - case_xml = ElementTree.SubElement(suite, 'testcase', { - 'name': case.name, - }) - error_xml = ElementTree.SubElement(case_xml, 'error', {}) - error_xml.text = ''.format(case.stderr, case.traceback) - return ElementTree.ElementTree(element=root) + assert isinstance(result, AugmentedResult) + root = ElementTree.Element('testsuites') + suite = ElementTree.SubElement(root, 'testsuite', { + 'name': 'Python gRPC tests', + }) + for case in result.cases.values(): + if case.kind is CaseResult.Kind.SUCCESS: + ElementTree.SubElement(suite, 'testcase', {'name': case.name,}) + elif case.kind in (CaseResult.Kind.ERROR, CaseResult.Kind.FAILURE): + case_xml = ElementTree.SubElement(suite, 'testcase', { + 'name': case.name, + }) + error_xml = ElementTree.SubElement(case_xml, 'error', {}) + error_xml.text = ''.format(case.stderr, case.traceback) + return ElementTree.ElementTree(element=root) diff --git a/src/python/grpcio_tests/tests/_runner.py b/src/python/grpcio_tests/tests/_runner.py index 926dcbe23a1..59964b271c7 100644 --- a/src/python/grpcio_tests/tests/_runner.py +++ b/src/python/grpcio_tests/tests/_runner.py @@ -49,7 +49,7 @@ from tests import _result class CaptureFile(object): - """A context-managed file to redirect output to a byte array. + """A context-managed file to redirect output to a byte array. Use by invoking `start` (`__enter__`) and at some point invoking `stop` (`__exit__`). At any point after the initial call to `start` call `output` to @@ -66,57 +66,56 @@ class CaptureFile(object): Only non-None when self is started. """ - def __init__(self, fd): - self._redirected_fd = fd - self._saved_fd = os.dup(self._redirected_fd) - self._into_file = None + def __init__(self, fd): + self._redirected_fd = fd + self._saved_fd = os.dup(self._redirected_fd) + self._into_file = None - def output(self): - """Get all output from the redirected-to file if it exists.""" - if self._into_file: - self._into_file.seek(0) - return bytes(self._into_file.read()) - else: - return bytes() + def output(self): + """Get all output from the redirected-to file if it exists.""" + if self._into_file: + self._into_file.seek(0) + return bytes(self._into_file.read()) + else: + return bytes() - def start(self): - """Start redirection of writes to the file descriptor.""" - self._into_file = tempfile.TemporaryFile() - os.dup2(self._into_file.fileno(), self._redirected_fd) + def start(self): + """Start redirection of writes to the file descriptor.""" + self._into_file = tempfile.TemporaryFile() + os.dup2(self._into_file.fileno(), self._redirected_fd) - def stop(self): - """Stop redirection of writes to the file descriptor.""" - # n.b. this dup2 call auto-closes self._redirected_fd - os.dup2(self._saved_fd, self._redirected_fd) + def stop(self): + """Stop redirection of writes to the file descriptor.""" + # n.b. this dup2 call auto-closes self._redirected_fd + os.dup2(self._saved_fd, self._redirected_fd) - def write_bypass(self, value): - """Bypass the redirection and write directly to the original file. + def write_bypass(self, value): + """Bypass the redirection and write directly to the original file. Arguments: value (str): What to write to the original file. """ - if six.PY3 and not isinstance(value, six.binary_type): - value = bytes(value, 'ascii') - if self._saved_fd is None: - os.write(self._redirect_fd, value) - else: - os.write(self._saved_fd, value) + if six.PY3 and not isinstance(value, six.binary_type): + value = bytes(value, 'ascii') + if self._saved_fd is None: + os.write(self._redirect_fd, value) + else: + os.write(self._saved_fd, value) - def __enter__(self): - self.start() - return self + def __enter__(self): + self.start() + return self - def __exit__(self, type, value, traceback): - self.stop() + def __exit__(self, type, value, traceback): + self.stop() - def close(self): - """Close any resources used by self not closed by stop().""" - os.close(self._saved_fd) + def close(self): + """Close any resources used by self not closed by stop().""" + os.close(self._saved_fd) -class AugmentedCase(collections.namedtuple('AugmentedCase', [ - 'case', 'id'])): - """A test case with a guaranteed unique externally specified identifier. +class AugmentedCase(collections.namedtuple('AugmentedCase', ['case', 'id'])): + """A test case with a guaranteed unique externally specified identifier. Attributes: case (unittest.TestCase): TestCase we're decorating with an additional @@ -125,105 +124,107 @@ class AugmentedCase(collections.namedtuple('AugmentedCase', [ purposes. """ - def __new__(cls, case, id=None): - if id is None: - id = uuid.uuid4() - return super(cls, AugmentedCase).__new__(cls, case, id) + def __new__(cls, case, id=None): + if id is None: + id = uuid.uuid4() + return super(cls, AugmentedCase).__new__(cls, case, id) class Runner(object): - def run(self, suite): - """See setuptools' test_runner setup argument for information.""" - # only run test cases with id starting with given prefix - testcase_filter = os.getenv('GRPC_PYTHON_TESTRUNNER_FILTER') - filtered_cases = [] - for case in _loader.iterate_suite_cases(suite): - if not testcase_filter or case.id().startswith(testcase_filter): - filtered_cases.append(case) - - # Ensure that every test case has no collision with any other test case in - # the augmented results. - augmented_cases = [AugmentedCase(case, uuid.uuid4()) - for case in filtered_cases] - case_id_by_case = dict((augmented_case.case, augmented_case.id) - for augmented_case in augmented_cases) - result_out = moves.cStringIO() - result = _result.TerminalResult( - result_out, id_map=lambda case: case_id_by_case[case]) - stdout_pipe = CaptureFile(sys.stdout.fileno()) - stderr_pipe = CaptureFile(sys.stderr.fileno()) - kill_flag = [False] - - def sigint_handler(signal_number, frame): - if signal_number == signal.SIGINT: - kill_flag[0] = True # Python 2.7 not having 'local'... :-( - signal.signal(signal_number, signal.SIG_DFL) - - def fault_handler(signal_number, frame): - stdout_pipe.write_bypass( - 'Received fault signal {}\nstdout:\n{}\n\nstderr:{}\n' - .format(signal_number, stdout_pipe.output(), - stderr_pipe.output())) - os._exit(1) - - def check_kill_self(): - if kill_flag[0]: - stdout_pipe.write_bypass('Stopping tests short...') - result.stopTestRun() - stdout_pipe.write_bypass(result_out.getvalue()) - stdout_pipe.write_bypass( - '\ninterrupted stdout:\n{}\n'.format(stdout_pipe.output().decode())) - stderr_pipe.write_bypass( - '\ninterrupted stderr:\n{}\n'.format(stderr_pipe.output().decode())) - os._exit(1) - def try_set_handler(name, handler): - try: - signal.signal(getattr(signal, name), handler) - except AttributeError: - pass - try_set_handler('SIGINT', sigint_handler) - try_set_handler('SIGSEGV', fault_handler) - try_set_handler('SIGBUS', fault_handler) - try_set_handler('SIGABRT', fault_handler) - try_set_handler('SIGFPE', fault_handler) - try_set_handler('SIGILL', fault_handler) - # Sometimes output will lag after a test has successfully finished; we - # ignore such writes to our pipes. - try_set_handler('SIGPIPE', signal.SIG_IGN) - - # Run the tests - result.startTestRun() - for augmented_case in augmented_cases: - sys.stdout.write('Running {}\n'.format(augmented_case.case.id())) - sys.stdout.flush() - case_thread = threading.Thread( - target=augmented_case.case.run, args=(result,)) - try: - with stdout_pipe, stderr_pipe: - case_thread.start() - while case_thread.is_alive(): + def run(self, suite): + """See setuptools' test_runner setup argument for information.""" + # only run test cases with id starting with given prefix + testcase_filter = os.getenv('GRPC_PYTHON_TESTRUNNER_FILTER') + filtered_cases = [] + for case in _loader.iterate_suite_cases(suite): + if not testcase_filter or case.id().startswith(testcase_filter): + filtered_cases.append(case) + + # Ensure that every test case has no collision with any other test case in + # the augmented results. + augmented_cases = [ + AugmentedCase(case, uuid.uuid4()) for case in filtered_cases + ] + case_id_by_case = dict((augmented_case.case, augmented_case.id) + for augmented_case in augmented_cases) + result_out = moves.cStringIO() + result = _result.TerminalResult( + result_out, id_map=lambda case: case_id_by_case[case]) + stdout_pipe = CaptureFile(sys.stdout.fileno()) + stderr_pipe = CaptureFile(sys.stderr.fileno()) + kill_flag = [False] + + def sigint_handler(signal_number, frame): + if signal_number == signal.SIGINT: + kill_flag[0] = True # Python 2.7 not having 'local'... :-( + signal.signal(signal_number, signal.SIG_DFL) + + def fault_handler(signal_number, frame): + stdout_pipe.write_bypass( + 'Received fault signal {}\nstdout:\n{}\n\nstderr:{}\n'.format( + signal_number, stdout_pipe.output(), stderr_pipe.output())) + os._exit(1) + + def check_kill_self(): + if kill_flag[0]: + stdout_pipe.write_bypass('Stopping tests short...') + result.stopTestRun() + stdout_pipe.write_bypass(result_out.getvalue()) + stdout_pipe.write_bypass('\ninterrupted stdout:\n{}\n'.format( + stdout_pipe.output().decode())) + stderr_pipe.write_bypass('\ninterrupted stderr:\n{}\n'.format( + stderr_pipe.output().decode())) + os._exit(1) + + def try_set_handler(name, handler): + try: + signal.signal(getattr(signal, name), handler) + except AttributeError: + pass + + try_set_handler('SIGINT', sigint_handler) + try_set_handler('SIGSEGV', fault_handler) + try_set_handler('SIGBUS', fault_handler) + try_set_handler('SIGABRT', fault_handler) + try_set_handler('SIGFPE', fault_handler) + try_set_handler('SIGILL', fault_handler) + # Sometimes output will lag after a test has successfully finished; we + # ignore such writes to our pipes. + try_set_handler('SIGPIPE', signal.SIG_IGN) + + # Run the tests + result.startTestRun() + for augmented_case in augmented_cases: + sys.stdout.write('Running {}\n'.format(augmented_case.case.id( + ))) + sys.stdout.flush() + case_thread = threading.Thread( + target=augmented_case.case.run, args=(result,)) + try: + with stdout_pipe, stderr_pipe: + case_thread.start() + while case_thread.is_alive(): + check_kill_self() + time.sleep(0) + case_thread.join() + except: + # re-raise the exception after forcing the with-block to end + raise + result.set_output(augmented_case.case, + stdout_pipe.output(), stderr_pipe.output()) + sys.stdout.write(result_out.getvalue()) + sys.stdout.flush() + result_out.truncate(0) check_kill_self() - time.sleep(0) - case_thread.join() - except: - # re-raise the exception after forcing the with-block to end - raise - result.set_output( - augmented_case.case, stdout_pipe.output(), stderr_pipe.output()) - sys.stdout.write(result_out.getvalue()) - sys.stdout.flush() - result_out.truncate(0) - check_kill_self() - result.stopTestRun() - stdout_pipe.close() - stderr_pipe.close() - - # Report results - sys.stdout.write(result_out.getvalue()) - sys.stdout.flush() - signal.signal(signal.SIGINT, signal.SIG_DFL) - with open('report.xml', 'wb') as report_xml_file: - _result.jenkins_junit_xml(result).write(report_xml_file) - return result - + result.stopTestRun() + stdout_pipe.close() + stderr_pipe.close() + + # Report results + sys.stdout.write(result_out.getvalue()) + sys.stdout.flush() + signal.signal(signal.SIGINT, signal.SIG_DFL) + with open('report.xml', 'wb') as report_xml_file: + _result.jenkins_junit_xml(result).write(report_xml_file) + return result diff --git a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py index 5dde72b1698..363b4c5f994 100644 --- a/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py +++ b/src/python/grpcio_tests/tests/health_check/_health_servicer_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc_health.v1.health.""" import unittest @@ -41,55 +40,55 @@ from tests.unit.framework.common import test_constants class HealthServicerTest(unittest.TestCase): - def setUp(self): - servicer = health.HealthServicer() - servicer.set('', health_pb2.HealthCheckResponse.SERVING) - servicer.set('grpc.test.TestServiceServing', - health_pb2.HealthCheckResponse.SERVING) - servicer.set('grpc.test.TestServiceUnknown', - health_pb2.HealthCheckResponse.UNKNOWN) - servicer.set('grpc.test.TestServiceNotServing', - health_pb2.HealthCheckResponse.NOT_SERVING) - server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server(server_pool) - port = self._server.add_insecure_port('[::]:0') - health_pb2.add_HealthServicer_to_server(servicer, self._server) - self._server.start() + def setUp(self): + servicer = health.HealthServicer() + servicer.set('', health_pb2.HealthCheckResponse.SERVING) + servicer.set('grpc.test.TestServiceServing', + health_pb2.HealthCheckResponse.SERVING) + servicer.set('grpc.test.TestServiceUnknown', + health_pb2.HealthCheckResponse.UNKNOWN) + servicer.set('grpc.test.TestServiceNotServing', + health_pb2.HealthCheckResponse.NOT_SERVING) + server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server(server_pool) + port = self._server.add_insecure_port('[::]:0') + health_pb2.add_HealthServicer_to_server(servicer, self._server) + self._server.start() + + channel = grpc.insecure_channel('localhost:%d' % port) + self._stub = health_pb2.HealthStub(channel) - channel = grpc.insecure_channel('localhost:%d' % port) - self._stub = health_pb2.HealthStub(channel) + def test_empty_service(self): + request = health_pb2.HealthCheckRequest() + resp = self._stub.Check(request) + self.assertEqual(health_pb2.HealthCheckResponse.SERVING, resp.status) - def test_empty_service(self): - request = health_pb2.HealthCheckRequest() - resp = self._stub.Check(request) - self.assertEqual(health_pb2.HealthCheckResponse.SERVING, resp.status) + def test_serving_service(self): + request = health_pb2.HealthCheckRequest( + service='grpc.test.TestServiceServing') + resp = self._stub.Check(request) + self.assertEqual(health_pb2.HealthCheckResponse.SERVING, resp.status) - def test_serving_service(self): - request = health_pb2.HealthCheckRequest( - service='grpc.test.TestServiceServing') - resp = self._stub.Check(request) - self.assertEqual(health_pb2.HealthCheckResponse.SERVING, resp.status) + def test_unknown_serivce(self): + request = health_pb2.HealthCheckRequest( + service='grpc.test.TestServiceUnknown') + resp = self._stub.Check(request) + self.assertEqual(health_pb2.HealthCheckResponse.UNKNOWN, resp.status) - def test_unknown_serivce(self): - request = health_pb2.HealthCheckRequest( - service='grpc.test.TestServiceUnknown') - resp = self._stub.Check(request) - self.assertEqual(health_pb2.HealthCheckResponse.UNKNOWN, resp.status) + def test_not_serving_service(self): + request = health_pb2.HealthCheckRequest( + service='grpc.test.TestServiceNotServing') + resp = self._stub.Check(request) + self.assertEqual(health_pb2.HealthCheckResponse.NOT_SERVING, + resp.status) - def test_not_serving_service(self): - request = health_pb2.HealthCheckRequest( - service='grpc.test.TestServiceNotServing') - resp = self._stub.Check(request) - self.assertEqual(health_pb2.HealthCheckResponse.NOT_SERVING, resp.status) + def test_not_found_service(self): + request = health_pb2.HealthCheckRequest(service='not-found') + with self.assertRaises(grpc.RpcError) as context: + resp = self._stub.Check(request) - def test_not_found_service(self): - request = health_pb2.HealthCheckRequest( - service='not-found') - with self.assertRaises(grpc.RpcError) as context: - resp = self._stub.Check(request) - - self.assertEqual(grpc.StatusCode.NOT_FOUND, context.exception.code()) + self.assertEqual(grpc.StatusCode.NOT_FOUND, context.exception.code()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/http2/_negative_http2_client.py b/src/python/grpcio_tests/tests/http2/_negative_http2_client.py index f8604683b3a..c192d827c40 100644 --- a/src/python/grpcio_tests/tests/http2/_negative_http2_client.py +++ b/src/python/grpcio_tests/tests/http2/_negative_http2_client.py @@ -26,7 +26,6 @@ # 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. - """The Python client used to test negative http2 conditions.""" import argparse @@ -35,29 +34,32 @@ import grpc from src.proto.grpc.testing import test_pb2 from src.proto.grpc.testing import messages_pb2 + def _validate_payload_type_and_length(response, expected_type, expected_length): - if response.payload.type is not expected_type: - raise ValueError( - 'expected payload type %s, got %s' % - (expected_type, type(response.payload.type))) - elif len(response.payload.body) != expected_length: - raise ValueError( - 'expected payload body size %d, got %d' % - (expected_length, len(response.payload.body))) + if response.payload.type is not expected_type: + raise ValueError('expected payload type %s, got %s' % + (expected_type, type(response.payload.type))) + elif len(response.payload.body) != expected_length: + raise ValueError('expected payload body size %d, got %d' % + (expected_length, len(response.payload.body))) + def _expect_status_code(call, expected_code): - if call.code() != expected_code: - raise ValueError( - 'expected code %s, got %s' % (expected_code, call.code())) + if call.code() != expected_code: + raise ValueError('expected code %s, got %s' % + (expected_code, call.code())) + def _expect_status_details(call, expected_details): - if call.details() != expected_details: - raise ValueError( - 'expected message %s, got %s' % (expected_details, call.details())) + if call.details() != expected_details: + raise ValueError('expected message %s, got %s' % + (expected_details, call.details())) + def _validate_status_code_and_details(call, expected_code, expected_details): - _expect_status_code(call, expected_code) - _expect_status_details(call, expected_details) + _expect_status_code(call, expected_code) + _expect_status_details(call, expected_details) + # common requests _REQUEST_SIZE = 314159 @@ -68,86 +70,103 @@ _SIMPLE_REQUEST = messages_pb2.SimpleRequest( response_size=_RESPONSE_SIZE, payload=messages_pb2.Payload(body=b'\x00' * _REQUEST_SIZE)) + def _goaway(stub): - first_response = stub.UnaryCall(_SIMPLE_REQUEST) - _validate_payload_type_and_length(first_response, - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) - second_response = stub.UnaryCall(_SIMPLE_REQUEST) - _validate_payload_type_and_length(second_response, - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + first_response = stub.UnaryCall(_SIMPLE_REQUEST) + _validate_payload_type_and_length(first_response, messages_pb2.COMPRESSABLE, + _RESPONSE_SIZE) + second_response = stub.UnaryCall(_SIMPLE_REQUEST) + _validate_payload_type_and_length(second_response, + messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + def _rst_after_header(stub): - resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNAVAILABLE, "") + resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) + _validate_status_code_and_details(resp_future, grpc.StatusCode.UNAVAILABLE, + "") + def _rst_during_data(stub): - resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) + _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + def _rst_after_data(stub): - resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_payload_type_and_length(next(resp_future), - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) + _validate_payload_type_and_length( + next(resp_future), messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + def _ping(stub): - response = stub.UnaryCall(_SIMPLE_REQUEST) - _validate_payload_type_and_length(response, - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + response = stub.UnaryCall(_SIMPLE_REQUEST) + _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, + _RESPONSE_SIZE) + def _max_streams(stub): - # send one req to ensure server sets MAX_STREAMS - response = stub.UnaryCall(_SIMPLE_REQUEST) - _validate_payload_type_and_length(response, - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) - - # give the streams a workout - futures = [] - for _ in range(15): - futures.append(stub.UnaryCall.future(_SIMPLE_REQUEST)) - for future in futures: - _validate_payload_type_and_length(future.result(), - messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + # send one req to ensure server sets MAX_STREAMS + response = stub.UnaryCall(_SIMPLE_REQUEST) + _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, + _RESPONSE_SIZE) + + # give the streams a workout + futures = [] + for _ in range(15): + futures.append(stub.UnaryCall.future(_SIMPLE_REQUEST)) + for future in futures: + _validate_payload_type_and_length( + future.result(), messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) + def _run_test_case(test_case, stub): - if test_case == 'goaway': - _goaway(stub) - elif test_case == 'rst_after_header': - _rst_after_header(stub) - elif test_case == 'rst_during_data': - _rst_during_data(stub) - elif test_case == 'rst_after_data': - _rst_after_data(stub) - elif test_case =='ping': - _ping(stub) - elif test_case == 'max_streams': - _max_streams(stub) - else: - raise ValueError("Invalid test case: %s" % test_case) + if test_case == 'goaway': + _goaway(stub) + elif test_case == 'rst_after_header': + _rst_after_header(stub) + elif test_case == 'rst_during_data': + _rst_during_data(stub) + elif test_case == 'rst_after_data': + _rst_after_data(stub) + elif test_case == 'ping': + _ping(stub) + elif test_case == 'max_streams': + _max_streams(stub) + else: + raise ValueError("Invalid test case: %s" % test_case) + def _args(): - parser = argparse.ArgumentParser() - parser.add_argument( - '--server_host', help='the host to which to connect', type=str, - default="127.0.0.1") - parser.add_argument( - '--server_port', help='the port to which to connect', type=int, - default="8080") - parser.add_argument( - '--test_case', help='the test case to execute', type=str, - default="goaway") - return parser.parse_args() + parser = argparse.ArgumentParser() + parser.add_argument( + '--server_host', + help='the host to which to connect', + type=str, + default="127.0.0.1") + parser.add_argument( + '--server_port', + help='the port to which to connect', + type=int, + default="8080") + parser.add_argument( + '--test_case', + help='the test case to execute', + type=str, + default="goaway") + return parser.parse_args() + def _stub(server_host, server_port): - target = '{}:{}'.format(server_host, server_port) - channel = grpc.insecure_channel(target) - return test_pb2.TestServiceStub(channel) + target = '{}:{}'.format(server_host, server_port) + channel = grpc.insecure_channel(target) + return test_pb2.TestServiceStub(channel) + def main(): - args = _args() - stub = _stub(args.server_host, args.server_port) - _run_test_case(args.test_case, stub) + args = _args() + stub = _stub(args.server_host, args.server_port) + _run_test_case(args.test_case, stub) if __name__ == '__main__': - main() + main() diff --git a/src/python/grpcio_tests/tests/interop/__init__.py b/src/python/grpcio_tests/tests/interop/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/interop/__init__.py +++ b/src/python/grpcio_tests/tests/interop/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/interop/_insecure_intraop_test.py b/src/python/grpcio_tests/tests/interop/_insecure_intraop_test.py index 4fb22b4d9df..58f3b364bad 100644 --- a/src/python/grpcio_tests/tests/interop/_insecure_intraop_test.py +++ b/src/python/grpcio_tests/tests/interop/_insecure_intraop_test.py @@ -26,7 +26,6 @@ # 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. - """Insecure client-server interoperability as a unit test.""" from concurrent import futures @@ -40,19 +39,18 @@ from tests.interop import methods from tests.interop import server -class InsecureIntraopTest( - _intraop_test_case.IntraopTestCase, - unittest.TestCase): +class InsecureIntraopTest(_intraop_test_case.IntraopTestCase, + unittest.TestCase): - def setUp(self): - self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - test_pb2.add_TestServiceServicer_to_server( - methods.TestService(), self.server) - port = self.server.add_insecure_port('[::]:0') - self.server.start() - self.stub = test_pb2.TestServiceStub( - grpc.insecure_channel('localhost:{}'.format(port))) + def setUp(self): + self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + test_pb2.add_TestServiceServicer_to_server(methods.TestService(), + self.server) + port = self.server.add_insecure_port('[::]:0') + self.server.start() + self.stub = test_pb2.TestServiceStub( + grpc.insecure_channel('localhost:{}'.format(port))) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/interop/_intraop_test_case.py b/src/python/grpcio_tests/tests/interop/_intraop_test_case.py index fe1c1739929..424f93980cf 100644 --- a/src/python/grpcio_tests/tests/interop/_intraop_test_case.py +++ b/src/python/grpcio_tests/tests/interop/_intraop_test_case.py @@ -26,39 +26,41 @@ # 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. - """Common code for unit tests of the interoperability test code.""" from tests.interop import methods class IntraopTestCase(object): - """Unit test methods. + """Unit test methods. This class must be mixed in with unittest.TestCase and a class that defines setUp and tearDown methods that manage a stub attribute. """ - def testEmptyUnary(self): - methods.TestCase.EMPTY_UNARY.test_interoperability(self.stub, None) + def testEmptyUnary(self): + methods.TestCase.EMPTY_UNARY.test_interoperability(self.stub, None) - def testLargeUnary(self): - methods.TestCase.LARGE_UNARY.test_interoperability(self.stub, None) + def testLargeUnary(self): + methods.TestCase.LARGE_UNARY.test_interoperability(self.stub, None) - def testServerStreaming(self): - methods.TestCase.SERVER_STREAMING.test_interoperability(self.stub, None) + def testServerStreaming(self): + methods.TestCase.SERVER_STREAMING.test_interoperability(self.stub, None) - def testClientStreaming(self): - methods.TestCase.CLIENT_STREAMING.test_interoperability(self.stub, None) + def testClientStreaming(self): + methods.TestCase.CLIENT_STREAMING.test_interoperability(self.stub, None) - def testPingPong(self): - methods.TestCase.PING_PONG.test_interoperability(self.stub, None) + def testPingPong(self): + methods.TestCase.PING_PONG.test_interoperability(self.stub, None) - def testCancelAfterBegin(self): - methods.TestCase.CANCEL_AFTER_BEGIN.test_interoperability(self.stub, None) + def testCancelAfterBegin(self): + methods.TestCase.CANCEL_AFTER_BEGIN.test_interoperability(self.stub, + None) - def testCancelAfterFirstResponse(self): - methods.TestCase.CANCEL_AFTER_FIRST_RESPONSE.test_interoperability(self.stub, None) + def testCancelAfterFirstResponse(self): + methods.TestCase.CANCEL_AFTER_FIRST_RESPONSE.test_interoperability( + self.stub, None) - def testTimeoutOnSleepingServer(self): - methods.TestCase.TIMEOUT_ON_SLEEPING_SERVER.test_interoperability(self.stub, None) + def testTimeoutOnSleepingServer(self): + methods.TestCase.TIMEOUT_ON_SLEEPING_SERVER.test_interoperability( + self.stub, None) diff --git a/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py b/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py index 3665c69726c..b28406ed3ff 100644 --- a/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py +++ b/src/python/grpcio_tests/tests/interop/_secure_intraop_test.py @@ -26,7 +26,6 @@ # 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. - """Secure client-server interoperability as a unit test.""" from concurrent import futures @@ -42,24 +41,24 @@ from tests.interop import resources _SERVER_HOST_OVERRIDE = 'foo.test.google.fr' -class SecureIntraopTest( - _intraop_test_case.IntraopTestCase, - unittest.TestCase): +class SecureIntraopTest(_intraop_test_case.IntraopTestCase, unittest.TestCase): - def setUp(self): - self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - test_pb2.add_TestServiceServicer_to_server( - methods.TestService(), self.server) - port = self.server.add_secure_port( - '[::]:0', grpc.ssl_server_credentials( - [(resources.private_key(), resources.certificate_chain())])) - self.server.start() - self.stub = test_pb2.TestServiceStub( - grpc.secure_channel( - 'localhost:{}'.format(port), - grpc.ssl_channel_credentials(resources.test_root_certificates()), - (('grpc.ssl_target_name_override', _SERVER_HOST_OVERRIDE,),))) + def setUp(self): + self.server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + test_pb2.add_TestServiceServicer_to_server(methods.TestService(), + self.server) + port = self.server.add_secure_port( + '[::]:0', + grpc.ssl_server_credentials( + [(resources.private_key(), resources.certificate_chain())])) + self.server.start() + self.stub = test_pb2.TestServiceStub( + grpc.secure_channel('localhost:{}'.format(port), + grpc.ssl_channel_credentials( + resources.test_root_certificates()), (( + 'grpc.ssl_target_name_override', + _SERVER_HOST_OVERRIDE,),))) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/interop/client.py b/src/python/grpcio_tests/tests/interop/client.py index afaa4662541..f177896e8e6 100644 --- a/src/python/grpcio_tests/tests/interop/client.py +++ b/src/python/grpcio_tests/tests/interop/client.py @@ -26,7 +26,6 @@ # 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. - """The Python implementation of the GRPC interoperability test client.""" import argparse @@ -41,93 +40,107 @@ from tests.interop import resources def _args(): - parser = argparse.ArgumentParser() - parser.add_argument( - '--server_host', help='the host to which to connect', type=str, - default="127.0.0.1") - parser.add_argument( - '--server_port', help='the port to which to connect', type=int) - parser.add_argument( - '--test_case', help='the test case to execute', type=str, - default="large_unary") - parser.add_argument( - '--use_tls', help='require a secure connection', default=False, - type=resources.parse_bool) - parser.add_argument( - '--use_test_ca', help='replace platform root CAs with ca.pem', - default=False, type=resources.parse_bool) - parser.add_argument( - '--server_host_override', default="foo.test.google.fr", - help='the server host to which to claim to connect', type=str) - parser.add_argument('--oauth_scope', help='scope for OAuth tokens', type=str) - parser.add_argument( - '--default_service_account', - help='email address of the default service account', type=str) - return parser.parse_args() + parser = argparse.ArgumentParser() + parser.add_argument( + '--server_host', + help='the host to which to connect', + type=str, + default="127.0.0.1") + parser.add_argument( + '--server_port', help='the port to which to connect', type=int) + parser.add_argument( + '--test_case', + help='the test case to execute', + type=str, + default="large_unary") + parser.add_argument( + '--use_tls', + help='require a secure connection', + default=False, + type=resources.parse_bool) + parser.add_argument( + '--use_test_ca', + help='replace platform root CAs with ca.pem', + default=False, + type=resources.parse_bool) + parser.add_argument( + '--server_host_override', + default="foo.test.google.fr", + help='the server host to which to claim to connect', + type=str) + parser.add_argument( + '--oauth_scope', help='scope for OAuth tokens', type=str) + parser.add_argument( + '--default_service_account', + help='email address of the default service account', + type=str) + return parser.parse_args() def _application_default_credentials(): - return oauth2client_client.GoogleCredentials.get_application_default() + return oauth2client_client.GoogleCredentials.get_application_default() def _stub(args): - target = '{}:{}'.format(args.server_host, args.server_port) - if args.test_case == 'oauth2_auth_token': - google_credentials = _application_default_credentials() - scoped_credentials = google_credentials.create_scoped([args.oauth_scope]) - access_token = scoped_credentials.get_access_token().access_token - call_credentials = grpc.access_token_call_credentials(access_token) - elif args.test_case == 'compute_engine_creds': - google_credentials = _application_default_credentials() - scoped_credentials = google_credentials.create_scoped([args.oauth_scope]) - # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last - # remaining use of the Beta API. - call_credentials = implementations.google_call_credentials( - scoped_credentials) - elif args.test_case == 'jwt_token_creds': - google_credentials = _application_default_credentials() - # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last - # remaining use of the Beta API. - call_credentials = implementations.google_call_credentials( - google_credentials) - else: - call_credentials = None - if args.use_tls: - if args.use_test_ca: - root_certificates = resources.test_root_certificates() + target = '{}:{}'.format(args.server_host, args.server_port) + if args.test_case == 'oauth2_auth_token': + google_credentials = _application_default_credentials() + scoped_credentials = google_credentials.create_scoped( + [args.oauth_scope]) + access_token = scoped_credentials.get_access_token().access_token + call_credentials = grpc.access_token_call_credentials(access_token) + elif args.test_case == 'compute_engine_creds': + google_credentials = _application_default_credentials() + scoped_credentials = google_credentials.create_scoped( + [args.oauth_scope]) + # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last + # remaining use of the Beta API. + call_credentials = implementations.google_call_credentials( + scoped_credentials) + elif args.test_case == 'jwt_token_creds': + google_credentials = _application_default_credentials() + # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last + # remaining use of the Beta API. + call_credentials = implementations.google_call_credentials( + google_credentials) else: - root_certificates = None # will load default roots. - - channel_credentials = grpc.ssl_channel_credentials(root_certificates) - if call_credentials is not None: - channel_credentials = grpc.composite_channel_credentials( - channel_credentials, call_credentials) - - channel = grpc.secure_channel( - target, channel_credentials, - (('grpc.ssl_target_name_override', args.server_host_override,),)) - else: - channel = grpc.insecure_channel(target) - if args.test_case == "unimplemented_service": - return test_pb2.UnimplementedServiceStub(channel) - else: - return test_pb2.TestServiceStub(channel) + call_credentials = None + if args.use_tls: + if args.use_test_ca: + root_certificates = resources.test_root_certificates() + else: + root_certificates = None # will load default roots. + + channel_credentials = grpc.ssl_channel_credentials(root_certificates) + if call_credentials is not None: + channel_credentials = grpc.composite_channel_credentials( + channel_credentials, call_credentials) + + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + args.server_host_override,),)) + else: + channel = grpc.insecure_channel(target) + if args.test_case == "unimplemented_service": + return test_pb2.UnimplementedServiceStub(channel) + else: + return test_pb2.TestServiceStub(channel) def _test_case_from_arg(test_case_arg): - for test_case in methods.TestCase: - if test_case_arg == test_case.value: - return test_case - else: - raise ValueError('No test case "%s"!' % test_case_arg) + for test_case in methods.TestCase: + if test_case_arg == test_case.value: + return test_case + else: + raise ValueError('No test case "%s"!' % test_case_arg) def test_interoperability(): - args = _args() - stub = _stub(args) - test_case = _test_case_from_arg(args.test_case) - test_case.test_interoperability(stub, args) + args = _args() + stub = _stub(args) + test_case = _test_case_from_arg(args.test_case) + test_case.test_interoperability(stub, args) if __name__ == '__main__': - test_interoperability() + test_interoperability() diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py index 9038ae57515..e1f87221686 100644 --- a/src/python/grpcio_tests/tests/interop/methods.py +++ b/src/python/grpcio_tests/tests/interop/methods.py @@ -26,7 +26,6 @@ # 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. - """Implementations of interoperability test methods.""" import enum @@ -46,463 +45,483 @@ from src.proto.grpc.testing import test_pb2 _INITIAL_METADATA_KEY = "x-grpc-test-echo-initial" _TRAILING_METADATA_KEY = "x-grpc-test-echo-trailing-bin" + def _maybe_echo_metadata(servicer_context): - """Copies metadata from request to response if it is present.""" - invocation_metadata = dict(servicer_context.invocation_metadata()) - if _INITIAL_METADATA_KEY in invocation_metadata: - initial_metadatum = ( - _INITIAL_METADATA_KEY, invocation_metadata[_INITIAL_METADATA_KEY]) - servicer_context.send_initial_metadata((initial_metadatum,)) - if _TRAILING_METADATA_KEY in invocation_metadata: - trailing_metadatum = ( - _TRAILING_METADATA_KEY, invocation_metadata[_TRAILING_METADATA_KEY]) - servicer_context.set_trailing_metadata((trailing_metadatum,)) + """Copies metadata from request to response if it is present.""" + invocation_metadata = dict(servicer_context.invocation_metadata()) + if _INITIAL_METADATA_KEY in invocation_metadata: + initial_metadatum = (_INITIAL_METADATA_KEY, + invocation_metadata[_INITIAL_METADATA_KEY]) + servicer_context.send_initial_metadata((initial_metadatum,)) + if _TRAILING_METADATA_KEY in invocation_metadata: + trailing_metadatum = (_TRAILING_METADATA_KEY, + invocation_metadata[_TRAILING_METADATA_KEY]) + servicer_context.set_trailing_metadata((trailing_metadatum,)) + def _maybe_echo_status_and_message(request, servicer_context): - """Sets the response context code and details if the request asks for them""" - if request.HasField('response_status'): - servicer_context.set_code(request.response_status.code) - servicer_context.set_details(request.response_status.message) + """Sets the response context code and details if the request asks for them""" + if request.HasField('response_status'): + servicer_context.set_code(request.response_status.code) + servicer_context.set_details(request.response_status.message) + class TestService(test_pb2.TestServiceServicer): - def EmptyCall(self, request, context): - _maybe_echo_metadata(context) - return empty_pb2.Empty() + def EmptyCall(self, request, context): + _maybe_echo_metadata(context) + return empty_pb2.Empty() - def UnaryCall(self, request, context): - _maybe_echo_metadata(context) - _maybe_echo_status_and_message(request, context) - return messages_pb2.SimpleResponse( - payload=messages_pb2.Payload( + def UnaryCall(self, request, context): + _maybe_echo_metadata(context) + _maybe_echo_status_and_message(request, context) + return messages_pb2.SimpleResponse(payload=messages_pb2.Payload( type=messages_pb2.COMPRESSABLE, body=b'\x00' * request.response_size)) - def StreamingOutputCall(self, request, context): - _maybe_echo_status_and_message(request, context) - for response_parameters in request.response_parameters: - yield messages_pb2.StreamingOutputCallResponse( - payload=messages_pb2.Payload( - type=request.response_type, - body=b'\x00' * response_parameters.size)) - - def StreamingInputCall(self, request_iterator, context): - aggregate_size = 0 - for request in request_iterator: - if request.payload is not None and request.payload.body: - aggregate_size += len(request.payload.body) - return messages_pb2.StreamingInputCallResponse( - aggregated_payload_size=aggregate_size) - - def FullDuplexCall(self, request_iterator, context): - _maybe_echo_metadata(context) - for request in request_iterator: - _maybe_echo_status_and_message(request, context) - for response_parameters in request.response_parameters: - yield messages_pb2.StreamingOutputCallResponse( - payload=messages_pb2.Payload( - type=request.payload.type, - body=b'\x00' * response_parameters.size)) - - # NOTE(nathaniel): Apparently this is the same as the full-duplex call? - # NOTE(atash): It isn't even called in the interop spec (Oct 22 2015)... - def HalfDuplexCall(self, request_iterator, context): - return self.FullDuplexCall(request_iterator, context) + def StreamingOutputCall(self, request, context): + _maybe_echo_status_and_message(request, context) + for response_parameters in request.response_parameters: + yield messages_pb2.StreamingOutputCallResponse( + payload=messages_pb2.Payload( + type=request.response_type, + body=b'\x00' * response_parameters.size)) + + def StreamingInputCall(self, request_iterator, context): + aggregate_size = 0 + for request in request_iterator: + if request.payload is not None and request.payload.body: + aggregate_size += len(request.payload.body) + return messages_pb2.StreamingInputCallResponse( + aggregated_payload_size=aggregate_size) + + def FullDuplexCall(self, request_iterator, context): + _maybe_echo_metadata(context) + for request in request_iterator: + _maybe_echo_status_and_message(request, context) + for response_parameters in request.response_parameters: + yield messages_pb2.StreamingOutputCallResponse( + payload=messages_pb2.Payload( + type=request.payload.type, + body=b'\x00' * response_parameters.size)) + + # NOTE(nathaniel): Apparently this is the same as the full-duplex call? + # NOTE(atash): It isn't even called in the interop spec (Oct 22 2015)... + def HalfDuplexCall(self, request_iterator, context): + return self.FullDuplexCall(request_iterator, context) def _expect_status_code(call, expected_code): - if call.code() != expected_code: - raise ValueError( - 'expected code %s, got %s' % (expected_code, call.code())) + if call.code() != expected_code: + raise ValueError('expected code %s, got %s' % + (expected_code, call.code())) def _expect_status_details(call, expected_details): - if call.details() != expected_details: - raise ValueError( - 'expected message %s, got %s' % (expected_details, call.details())) + if call.details() != expected_details: + raise ValueError('expected message %s, got %s' % + (expected_details, call.details())) def _validate_status_code_and_details(call, expected_code, expected_details): - _expect_status_code(call, expected_code) - _expect_status_details(call, expected_details) + _expect_status_code(call, expected_code) + _expect_status_details(call, expected_details) def _validate_payload_type_and_length(response, expected_type, expected_length): - if response.payload.type is not expected_type: - raise ValueError( - 'expected payload type %s, got %s' % - (expected_type, type(response.payload.type))) - elif len(response.payload.body) != expected_length: - raise ValueError( - 'expected payload body size %d, got %d' % - (expected_length, len(response.payload.body))) - - -def _large_unary_common_behavior( - stub, fill_username, fill_oauth_scope, call_credentials): - size = 314159 - request = messages_pb2.SimpleRequest( - response_type=messages_pb2.COMPRESSABLE, response_size=size, - payload=messages_pb2.Payload(body=b'\x00' * 271828), - fill_username=fill_username, fill_oauth_scope=fill_oauth_scope) - response_future = stub.UnaryCall.future( - request, credentials=call_credentials) - response = response_future.result() - _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, size) - return response + if response.payload.type is not expected_type: + raise ValueError('expected payload type %s, got %s' % + (expected_type, type(response.payload.type))) + elif len(response.payload.body) != expected_length: + raise ValueError('expected payload body size %d, got %d' % + (expected_length, len(response.payload.body))) + + +def _large_unary_common_behavior(stub, fill_username, fill_oauth_scope, + call_credentials): + size = 314159 + request = messages_pb2.SimpleRequest( + response_type=messages_pb2.COMPRESSABLE, + response_size=size, + payload=messages_pb2.Payload(body=b'\x00' * 271828), + fill_username=fill_username, + fill_oauth_scope=fill_oauth_scope) + response_future = stub.UnaryCall.future( + request, credentials=call_credentials) + response = response_future.result() + _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, size) + return response def _empty_unary(stub): - response = stub.EmptyCall(empty_pb2.Empty()) - if not isinstance(response, empty_pb2.Empty): - raise TypeError( - 'response is of type "%s", not empty_pb2.Empty!', type(response)) + response = stub.EmptyCall(empty_pb2.Empty()) + if not isinstance(response, empty_pb2.Empty): + raise TypeError('response is of type "%s", not empty_pb2.Empty!', + type(response)) def _large_unary(stub): - _large_unary_common_behavior(stub, False, False, None) + _large_unary_common_behavior(stub, False, False, None) def _client_streaming(stub): - payload_body_sizes = (27182, 8, 1828, 45904,) - payloads = ( - messages_pb2.Payload(body=b'\x00' * size) - for size in payload_body_sizes) - requests = ( - messages_pb2.StreamingInputCallRequest(payload=payload) - for payload in payloads) - response = stub.StreamingInputCall(requests) - if response.aggregated_payload_size != 74922: - raise ValueError( - 'incorrect size %d!' % response.aggregated_payload_size) + payload_body_sizes = ( + 27182, + 8, + 1828, + 45904,) + payloads = (messages_pb2.Payload(body=b'\x00' * size) + for size in payload_body_sizes) + requests = (messages_pb2.StreamingInputCallRequest(payload=payload) + for payload in payloads) + response = stub.StreamingInputCall(requests) + if response.aggregated_payload_size != 74922: + raise ValueError('incorrect size %d!' % + response.aggregated_payload_size) def _server_streaming(stub): - sizes = (31415, 9, 2653, 58979,) - - request = messages_pb2.StreamingOutputCallRequest( - response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=sizes[0]), - messages_pb2.ResponseParameters(size=sizes[1]), - messages_pb2.ResponseParameters(size=sizes[2]), - messages_pb2.ResponseParameters(size=sizes[3]), - ) - ) - response_iterator = stub.StreamingOutputCall(request) - for index, response in enumerate(response_iterator): - _validate_payload_type_and_length( - response, messages_pb2.COMPRESSABLE, sizes[index]) + sizes = ( + 31415, + 9, + 2653, + 58979,) + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=( + messages_pb2.ResponseParameters(size=sizes[0]), + messages_pb2.ResponseParameters(size=sizes[1]), + messages_pb2.ResponseParameters(size=sizes[2]), + messages_pb2.ResponseParameters(size=sizes[3]),)) + response_iterator = stub.StreamingOutputCall(request) + for index, response in enumerate(response_iterator): + _validate_payload_type_and_length(response, messages_pb2.COMPRESSABLE, + sizes[index]) class _Pipe(object): - def __init__(self): - self._condition = threading.Condition() - self._values = [] - self._open = True + def __init__(self): + self._condition = threading.Condition() + self._values = [] + self._open = True - def __iter__(self): - return self + def __iter__(self): + return self - def __next__(self): - return self.next() + def __next__(self): + return self.next() - def next(self): - with self._condition: - while not self._values and self._open: - self._condition.wait() - if self._values: - return self._values.pop(0) - else: - raise StopIteration() + def next(self): + with self._condition: + while not self._values and self._open: + self._condition.wait() + if self._values: + return self._values.pop(0) + else: + raise StopIteration() - def add(self, value): - with self._condition: - self._values.append(value) - self._condition.notify() + def add(self, value): + with self._condition: + self._values.append(value) + self._condition.notify() - def close(self): - with self._condition: - self._open = False - self._condition.notify() + def close(self): + with self._condition: + self._open = False + self._condition.notify() - def __enter__(self): - return self + def __enter__(self): + return self - def __exit__(self, type, value, traceback): - self.close() + def __exit__(self, type, value, traceback): + self.close() def _ping_pong(stub): - request_response_sizes = (31415, 9, 2653, 58979,) - request_payload_sizes = (27182, 8, 1828, 45904,) - - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe) - for response_size, payload_size in zip( - request_response_sizes, request_payload_sizes): - request = messages_pb2.StreamingOutputCallRequest( - response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=response_size),), - payload=messages_pb2.Payload(body=b'\x00' * payload_size)) - pipe.add(request) - response = next(response_iterator) - _validate_payload_type_and_length( - response, messages_pb2.COMPRESSABLE, response_size) + request_response_sizes = ( + 31415, + 9, + 2653, + 58979,) + request_payload_sizes = ( + 27182, + 8, + 1828, + 45904,) + + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe) + for response_size, payload_size in zip(request_response_sizes, + request_payload_sizes): + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=( + messages_pb2.ResponseParameters(size=response_size),), + payload=messages_pb2.Payload(body=b'\x00' * payload_size)) + pipe.add(request) + response = next(response_iterator) + _validate_payload_type_and_length( + response, messages_pb2.COMPRESSABLE, response_size) def _cancel_after_begin(stub): - with _Pipe() as pipe: - response_future = stub.StreamingInputCall.future(pipe) - response_future.cancel() - if not response_future.cancelled(): - raise ValueError('expected cancelled method to return True') - if response_future.code() is not grpc.StatusCode.CANCELLED: - raise ValueError('expected status code CANCELLED') + with _Pipe() as pipe: + response_future = stub.StreamingInputCall.future(pipe) + response_future.cancel() + if not response_future.cancelled(): + raise ValueError('expected cancelled method to return True') + if response_future.code() is not grpc.StatusCode.CANCELLED: + raise ValueError('expected status code CANCELLED') def _cancel_after_first_response(stub): - request_response_sizes = (31415, 9, 2653, 58979,) - request_payload_sizes = (27182, 8, 1828, 45904,) - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe) - - response_size = request_response_sizes[0] - payload_size = request_payload_sizes[0] - request = messages_pb2.StreamingOutputCallRequest( - response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=response_size),), - payload=messages_pb2.Payload(body=b'\x00' * payload_size)) - pipe.add(request) - response = next(response_iterator) - # We test the contents of `response` in the Ping Pong test - don't check - # them here. - response_iterator.cancel() - - try: - next(response_iterator) - except grpc.RpcError as rpc_error: - if rpc_error.code() is not grpc.StatusCode.CANCELLED: - raise - else: - raise ValueError('expected call to be cancelled') + request_response_sizes = ( + 31415, + 9, + 2653, + 58979,) + request_payload_sizes = ( + 27182, + 8, + 1828, + 45904,) + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe) + + response_size = request_response_sizes[0] + payload_size = request_payload_sizes[0] + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=( + messages_pb2.ResponseParameters(size=response_size),), + payload=messages_pb2.Payload(body=b'\x00' * payload_size)) + pipe.add(request) + response = next(response_iterator) + # We test the contents of `response` in the Ping Pong test - don't check + # them here. + response_iterator.cancel() + + try: + next(response_iterator) + except grpc.RpcError as rpc_error: + if rpc_error.code() is not grpc.StatusCode.CANCELLED: + raise + else: + raise ValueError('expected call to be cancelled') def _timeout_on_sleeping_server(stub): - request_payload_size = 27182 - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe, timeout=0.001) - - request = messages_pb2.StreamingOutputCallRequest( - response_type=messages_pb2.COMPRESSABLE, - payload=messages_pb2.Payload(body=b'\x00' * request_payload_size)) - pipe.add(request) - try: - next(response_iterator) - except grpc.RpcError as rpc_error: - if rpc_error.code() is not grpc.StatusCode.DEADLINE_EXCEEDED: - raise - else: - raise ValueError('expected call to exceed deadline') + request_payload_size = 27182 + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe, timeout=0.001) + + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + payload=messages_pb2.Payload(body=b'\x00' * request_payload_size)) + pipe.add(request) + try: + next(response_iterator) + except grpc.RpcError as rpc_error: + if rpc_error.code() is not grpc.StatusCode.DEADLINE_EXCEEDED: + raise + else: + raise ValueError('expected call to exceed deadline') def _empty_stream(stub): - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe) - pipe.close() - try: - next(response_iterator) - raise ValueError('expected exactly 0 responses') - except StopIteration: - pass + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe) + pipe.close() + try: + next(response_iterator) + raise ValueError('expected exactly 0 responses') + except StopIteration: + pass def _status_code_and_message(stub): - details = 'test status message' - code = 2 - status = grpc.StatusCode.UNKNOWN # code = 2 - - # Test with a UnaryCall - request = messages_pb2.SimpleRequest( - response_type=messages_pb2.COMPRESSABLE, - response_size=1, - payload=messages_pb2.Payload(body=b'\x00'), - response_status=messages_pb2.EchoStatus(code=code, message=details) - ) - response_future = stub.UnaryCall.future(request) - _validate_status_code_and_details(response_future, status, details) - - # Test with a FullDuplexCall - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe) - request = messages_pb2.StreamingOutputCallRequest( + details = 'test status message' + code = 2 + status = grpc.StatusCode.UNKNOWN # code = 2 + + # Test with a UnaryCall + request = messages_pb2.SimpleRequest( response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=1),), + response_size=1, payload=messages_pb2.Payload(body=b'\x00'), - response_status=messages_pb2.EchoStatus(code=code, message=details)) - pipe.add(request) # sends the initial request. - # Dropping out of with block closes the pipe - _validate_status_code_and_details(response_iterator, status, details) + response_status=messages_pb2.EchoStatus( + code=code, message=details)) + response_future = stub.UnaryCall.future(request) + _validate_status_code_and_details(response_future, status, details) + + # Test with a FullDuplexCall + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe) + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=(messages_pb2.ResponseParameters(size=1),), + payload=messages_pb2.Payload(body=b'\x00'), + response_status=messages_pb2.EchoStatus( + code=code, message=details)) + pipe.add(request) # sends the initial request. + # Dropping out of with block closes the pipe + _validate_status_code_and_details(response_iterator, status, details) def _unimplemented_method(test_service_stub): - response_future = ( - test_service_stub.UnimplementedCall.future(empty_pb2.Empty())) - _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) + response_future = ( + test_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) def _unimplemented_service(unimplemented_service_stub): - response_future = ( - unimplemented_service_stub.UnimplementedCall.future(empty_pb2.Empty())) - _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) + response_future = ( + unimplemented_service_stub.UnimplementedCall.future(empty_pb2.Empty())) + _expect_status_code(response_future, grpc.StatusCode.UNIMPLEMENTED) def _custom_metadata(stub): - initial_metadata_value = "test_initial_metadata_value" - trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b" - metadata = ( - (_INITIAL_METADATA_KEY, initial_metadata_value), - (_TRAILING_METADATA_KEY, trailing_metadata_value)) - - def _validate_metadata(response): - initial_metadata = dict(response.initial_metadata()) - if initial_metadata[_INITIAL_METADATA_KEY] != initial_metadata_value: - raise ValueError( - 'expected initial metadata %s, got %s' % ( - initial_metadata_value, initial_metadata[_INITIAL_METADATA_KEY])) - trailing_metadata = dict(response.trailing_metadata()) - if trailing_metadata[_TRAILING_METADATA_KEY] != trailing_metadata_value: - raise ValueError( - 'expected trailing metadata %s, got %s' % ( - trailing_metadata_value, initial_metadata[_TRAILING_METADATA_KEY])) - - # Testing with UnaryCall - request = messages_pb2.SimpleRequest( - response_type=messages_pb2.COMPRESSABLE, - response_size=1, - payload=messages_pb2.Payload(body=b'\x00')) - response_future = stub.UnaryCall.future(request, metadata=metadata) - _validate_metadata(response_future) - - # Testing with FullDuplexCall - with _Pipe() as pipe: - response_iterator = stub.FullDuplexCall(pipe, metadata=metadata) - request = messages_pb2.StreamingOutputCallRequest( + initial_metadata_value = "test_initial_metadata_value" + trailing_metadata_value = "\x0a\x0b\x0a\x0b\x0a\x0b" + metadata = ((_INITIAL_METADATA_KEY, initial_metadata_value), + (_TRAILING_METADATA_KEY, trailing_metadata_value)) + + def _validate_metadata(response): + initial_metadata = dict(response.initial_metadata()) + if initial_metadata[_INITIAL_METADATA_KEY] != initial_metadata_value: + raise ValueError('expected initial metadata %s, got %s' % + (initial_metadata_value, + initial_metadata[_INITIAL_METADATA_KEY])) + trailing_metadata = dict(response.trailing_metadata()) + if trailing_metadata[_TRAILING_METADATA_KEY] != trailing_metadata_value: + raise ValueError('expected trailing metadata %s, got %s' % + (trailing_metadata_value, + initial_metadata[_TRAILING_METADATA_KEY])) + + # Testing with UnaryCall + request = messages_pb2.SimpleRequest( response_type=messages_pb2.COMPRESSABLE, - response_parameters=( - messages_pb2.ResponseParameters(size=1),)) - pipe.add(request) # Sends the request - next(response_iterator) # Causes server to send trailing metadata - # Dropping out of the with block closes the pipe - _validate_metadata(response_iterator) + response_size=1, + payload=messages_pb2.Payload(body=b'\x00')) + response_future = stub.UnaryCall.future(request, metadata=metadata) + _validate_metadata(response_future) + + # Testing with FullDuplexCall + with _Pipe() as pipe: + response_iterator = stub.FullDuplexCall(pipe, metadata=metadata) + request = messages_pb2.StreamingOutputCallRequest( + response_type=messages_pb2.COMPRESSABLE, + response_parameters=(messages_pb2.ResponseParameters(size=1),)) + pipe.add(request) # Sends the request + next(response_iterator) # Causes server to send trailing metadata + # Dropping out of the with block closes the pipe + _validate_metadata(response_iterator) + def _compute_engine_creds(stub, args): - response = _large_unary_common_behavior(stub, True, True, None) - if args.default_service_account != response.username: - raise ValueError( - 'expected username %s, got %s' % ( - args.default_service_account, response.username)) + response = _large_unary_common_behavior(stub, True, True, None) + if args.default_service_account != response.username: + raise ValueError('expected username %s, got %s' % + (args.default_service_account, response.username)) def _oauth2_auth_token(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] - wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] - response = _large_unary_common_behavior(stub, True, True, None) - if wanted_email != response.username: - raise ValueError( - 'expected username %s, got %s' % (wanted_email, response.username)) - if args.oauth_scope.find(response.oauth_scope) == -1: - raise ValueError( - 'expected to find oauth scope "{}" in received "{}"'.format( - response.oauth_scope, args.oauth_scope)) + json_key_filename = os.environ[ + oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] + response = _large_unary_common_behavior(stub, True, True, None) + if wanted_email != response.username: + raise ValueError('expected username %s, got %s' % + (wanted_email, response.username)) + if args.oauth_scope.find(response.oauth_scope) == -1: + raise ValueError('expected to find oauth scope "{}" in received "{}"'. + format(response.oauth_scope, args.oauth_scope)) def _jwt_token_creds(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] - wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] - response = _large_unary_common_behavior(stub, True, False, None) - if wanted_email != response.username: - raise ValueError( - 'expected username %s, got %s' % (wanted_email, response.username)) + json_key_filename = os.environ[ + oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] + response = _large_unary_common_behavior(stub, True, False, None) + if wanted_email != response.username: + raise ValueError('expected username %s, got %s' % + (wanted_email, response.username)) def _per_rpc_creds(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] - wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] - credentials = oauth2client_client.GoogleCredentials.get_application_default() - scoped_credentials = credentials.create_scoped([args.oauth_scope]) - # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last - # remaining use of the Beta API. - call_credentials = implementations.google_call_credentials( - scoped_credentials) - response = _large_unary_common_behavior(stub, True, False, call_credentials) - if wanted_email != response.username: - raise ValueError( - 'expected username %s, got %s' % (wanted_email, response.username)) + json_key_filename = os.environ[ + oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] + credentials = oauth2client_client.GoogleCredentials.get_application_default( + ) + scoped_credentials = credentials.create_scoped([args.oauth_scope]) + # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last + # remaining use of the Beta API. + call_credentials = implementations.google_call_credentials( + scoped_credentials) + response = _large_unary_common_behavior(stub, True, False, call_credentials) + if wanted_email != response.username: + raise ValueError('expected username %s, got %s' % + (wanted_email, response.username)) @enum.unique class TestCase(enum.Enum): - EMPTY_UNARY = 'empty_unary' - LARGE_UNARY = 'large_unary' - SERVER_STREAMING = 'server_streaming' - CLIENT_STREAMING = 'client_streaming' - PING_PONG = 'ping_pong' - CANCEL_AFTER_BEGIN = 'cancel_after_begin' - CANCEL_AFTER_FIRST_RESPONSE = 'cancel_after_first_response' - EMPTY_STREAM = 'empty_stream' - STATUS_CODE_AND_MESSAGE = 'status_code_and_message' - UNIMPLEMENTED_METHOD = 'unimplemented_method' - UNIMPLEMENTED_SERVICE = 'unimplemented_service' - CUSTOM_METADATA = "custom_metadata" - COMPUTE_ENGINE_CREDS = 'compute_engine_creds' - OAUTH2_AUTH_TOKEN = 'oauth2_auth_token' - JWT_TOKEN_CREDS = 'jwt_token_creds' - PER_RPC_CREDS = 'per_rpc_creds' - TIMEOUT_ON_SLEEPING_SERVER = 'timeout_on_sleeping_server' - - def test_interoperability(self, stub, args): - if self is TestCase.EMPTY_UNARY: - _empty_unary(stub) - elif self is TestCase.LARGE_UNARY: - _large_unary(stub) - elif self is TestCase.SERVER_STREAMING: - _server_streaming(stub) - elif self is TestCase.CLIENT_STREAMING: - _client_streaming(stub) - elif self is TestCase.PING_PONG: - _ping_pong(stub) - elif self is TestCase.CANCEL_AFTER_BEGIN: - _cancel_after_begin(stub) - elif self is TestCase.CANCEL_AFTER_FIRST_RESPONSE: - _cancel_after_first_response(stub) - elif self is TestCase.TIMEOUT_ON_SLEEPING_SERVER: - _timeout_on_sleeping_server(stub) - elif self is TestCase.EMPTY_STREAM: - _empty_stream(stub) - elif self is TestCase.STATUS_CODE_AND_MESSAGE: - _status_code_and_message(stub) - elif self is TestCase.UNIMPLEMENTED_METHOD: - _unimplemented_method(stub) - elif self is TestCase.UNIMPLEMENTED_SERVICE: - _unimplemented_service(stub) - elif self is TestCase.CUSTOM_METADATA: - _custom_metadata(stub) - elif self is TestCase.COMPUTE_ENGINE_CREDS: - _compute_engine_creds(stub, args) - elif self is TestCase.OAUTH2_AUTH_TOKEN: - _oauth2_auth_token(stub, args) - elif self is TestCase.JWT_TOKEN_CREDS: - _jwt_token_creds(stub, args) - elif self is TestCase.PER_RPC_CREDS: - _per_rpc_creds(stub, args) - else: - raise NotImplementedError('Test case "%s" not implemented!' % self.name) + EMPTY_UNARY = 'empty_unary' + LARGE_UNARY = 'large_unary' + SERVER_STREAMING = 'server_streaming' + CLIENT_STREAMING = 'client_streaming' + PING_PONG = 'ping_pong' + CANCEL_AFTER_BEGIN = 'cancel_after_begin' + CANCEL_AFTER_FIRST_RESPONSE = 'cancel_after_first_response' + EMPTY_STREAM = 'empty_stream' + STATUS_CODE_AND_MESSAGE = 'status_code_and_message' + UNIMPLEMENTED_METHOD = 'unimplemented_method' + UNIMPLEMENTED_SERVICE = 'unimplemented_service' + CUSTOM_METADATA = "custom_metadata" + COMPUTE_ENGINE_CREDS = 'compute_engine_creds' + OAUTH2_AUTH_TOKEN = 'oauth2_auth_token' + JWT_TOKEN_CREDS = 'jwt_token_creds' + PER_RPC_CREDS = 'per_rpc_creds' + TIMEOUT_ON_SLEEPING_SERVER = 'timeout_on_sleeping_server' + + def test_interoperability(self, stub, args): + if self is TestCase.EMPTY_UNARY: + _empty_unary(stub) + elif self is TestCase.LARGE_UNARY: + _large_unary(stub) + elif self is TestCase.SERVER_STREAMING: + _server_streaming(stub) + elif self is TestCase.CLIENT_STREAMING: + _client_streaming(stub) + elif self is TestCase.PING_PONG: + _ping_pong(stub) + elif self is TestCase.CANCEL_AFTER_BEGIN: + _cancel_after_begin(stub) + elif self is TestCase.CANCEL_AFTER_FIRST_RESPONSE: + _cancel_after_first_response(stub) + elif self is TestCase.TIMEOUT_ON_SLEEPING_SERVER: + _timeout_on_sleeping_server(stub) + elif self is TestCase.EMPTY_STREAM: + _empty_stream(stub) + elif self is TestCase.STATUS_CODE_AND_MESSAGE: + _status_code_and_message(stub) + elif self is TestCase.UNIMPLEMENTED_METHOD: + _unimplemented_method(stub) + elif self is TestCase.UNIMPLEMENTED_SERVICE: + _unimplemented_service(stub) + elif self is TestCase.CUSTOM_METADATA: + _custom_metadata(stub) + elif self is TestCase.COMPUTE_ENGINE_CREDS: + _compute_engine_creds(stub, args) + elif self is TestCase.OAUTH2_AUTH_TOKEN: + _oauth2_auth_token(stub, args) + elif self is TestCase.JWT_TOKEN_CREDS: + _jwt_token_creds(stub, args) + elif self is TestCase.PER_RPC_CREDS: + _per_rpc_creds(stub, args) + else: + raise NotImplementedError('Test case "%s" not implemented!' % + self.name) diff --git a/src/python/grpcio_tests/tests/interop/resources.py b/src/python/grpcio_tests/tests/interop/resources.py index c424385cf60..2ec2eb92b4f 100644 --- a/src/python/grpcio_tests/tests/interop/resources.py +++ b/src/python/grpcio_tests/tests/interop/resources.py @@ -26,7 +26,6 @@ # 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. - """Constants and functions for data used in interoperability testing.""" import argparse @@ -40,22 +39,22 @@ _CERTIFICATE_CHAIN_RESOURCE_PATH = 'credentials/server1.pem' def test_root_certificates(): - return pkg_resources.resource_string( - __name__, _ROOT_CERTIFICATES_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, + _ROOT_CERTIFICATES_RESOURCE_PATH) def private_key(): - return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH) def certificate_chain(): - return pkg_resources.resource_string( - __name__, _CERTIFICATE_CHAIN_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, + _CERTIFICATE_CHAIN_RESOURCE_PATH) def parse_bool(value): - if value == 'true': - return True - if value == 'false': - return False - raise argparse.ArgumentTypeError('Only true/false allowed') + if value == 'true': + return True + if value == 'false': + return False + raise argparse.ArgumentTypeError('Only true/false allowed') diff --git a/src/python/grpcio_tests/tests/interop/server.py b/src/python/grpcio_tests/tests/interop/server.py index 1ae83bc57d0..65f1604eb82 100644 --- a/src/python/grpcio_tests/tests/interop/server.py +++ b/src/python/grpcio_tests/tests/interop/server.py @@ -26,7 +26,6 @@ # 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. - """The Python implementation of the GRPC interoperability test server.""" import argparse @@ -44,34 +43,36 @@ _ONE_DAY_IN_SECONDS = 60 * 60 * 24 def serve(): - parser = argparse.ArgumentParser() - parser.add_argument( - '--port', help='the port on which to serve', type=int) - parser.add_argument( - '--use_tls', help='require a secure connection', - default=False, type=resources.parse_bool) - args = parser.parse_args() + parser = argparse.ArgumentParser() + parser.add_argument('--port', help='the port on which to serve', type=int) + parser.add_argument( + '--use_tls', + help='require a secure connection', + default=False, + type=resources.parse_bool) + args = parser.parse_args() + + server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) + test_pb2.add_TestServiceServicer_to_server(methods.TestService(), server) + if args.use_tls: + private_key = resources.private_key() + certificate_chain = resources.certificate_chain() + credentials = grpc.ssl_server_credentials(( + (private_key, certificate_chain),)) + server.add_secure_port('[::]:{}'.format(args.port), credentials) + else: + server.add_insecure_port('[::]:{}'.format(args.port)) - server = grpc.server(futures.ThreadPoolExecutor(max_workers=10)) - test_pb2.add_TestServiceServicer_to_server(methods.TestService(), server) - if args.use_tls: - private_key = resources.private_key() - certificate_chain = resources.certificate_chain() - credentials = grpc.ssl_server_credentials( - ((private_key, certificate_chain),)) - server.add_secure_port('[::]:{}'.format(args.port), credentials) - else: - server.add_insecure_port('[::]:{}'.format(args.port)) + server.start() + logging.info('Server serving.') + try: + while True: + time.sleep(_ONE_DAY_IN_SECONDS) + except BaseException as e: + logging.info('Caught exception "%s"; stopping server...', e) + server.stop(None) + logging.info('Server stopped; exiting.') - server.start() - logging.info('Server serving.') - try: - while True: - time.sleep(_ONE_DAY_IN_SECONDS) - except BaseException as e: - logging.info('Caught exception "%s"; stopping server...', e) - server.stop(None) - logging.info('Server stopped; exiting.') if __name__ == '__main__': - serve() + serve() diff --git a/src/python/grpcio_tests/tests/protoc_plugin/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py b/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py index 7ca2bcff383..ae5da2c3dbe 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/_python_plugin_test.py @@ -58,436 +58,440 @@ ADD_SERVICER_TO_SERVER_IDENTIFIER = 'add_TestServiceServicer_to_server' class _ServicerMethods(object): - def __init__(self): - self._condition = threading.Condition() - self._paused = False - self._fail = False - - @contextlib.contextmanager - def pause(self): # pylint: disable=invalid-name - with self._condition: - self._paused = True - yield - with self._condition: - self._paused = False - self._condition.notify_all() - - @contextlib.contextmanager - def fail(self): # pylint: disable=invalid-name - with self._condition: - self._fail = True - yield - with self._condition: - self._fail = False - - def _control(self): # pylint: disable=invalid-name - with self._condition: - if self._fail: - raise ValueError() - while self._paused: - self._condition.wait() - - def UnaryCall(self, request, unused_rpc_context): - response = response_pb2.SimpleResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * request.response_size - self._control() - return response - - def StreamingOutputCall(self, request, unused_rpc_context): - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size - self._control() - yield response - - def StreamingInputCall(self, request_iter, unused_rpc_context): - response = response_pb2.StreamingInputCallResponse() - aggregated_payload_size = 0 - for request in request_iter: - aggregated_payload_size += len(request.payload.payload_compressable) - response.aggregated_payload_size = aggregated_payload_size - self._control() - return response - - def FullDuplexCall(self, request_iter, unused_rpc_context): - for request in request_iter: - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size - self._control() - yield response + def __init__(self): + self._condition = threading.Condition() + self._paused = False + self._fail = False + + @contextlib.contextmanager + def pause(self): # pylint: disable=invalid-name + with self._condition: + self._paused = True + yield + with self._condition: + self._paused = False + self._condition.notify_all() - def HalfDuplexCall(self, request_iter, unused_rpc_context): - responses = [] - for request in request_iter: - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() + @contextlib.contextmanager + def fail(self): # pylint: disable=invalid-name + with self._condition: + self._fail = True + yield + with self._condition: + self._fail = False + + def _control(self): # pylint: disable=invalid-name + with self._condition: + if self._fail: + raise ValueError() + while self._paused: + self._condition.wait() + + def UnaryCall(self, request, unused_rpc_context): + response = response_pb2.SimpleResponse() response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size + response.payload.payload_compressable = 'a' * request.response_size + self._control() + return response + + def StreamingOutputCall(self, request, unused_rpc_context): + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + yield response + + def StreamingInputCall(self, request_iter, unused_rpc_context): + response = response_pb2.StreamingInputCallResponse() + aggregated_payload_size = 0 + for request in request_iter: + aggregated_payload_size += len(request.payload.payload_compressable) + response.aggregated_payload_size = aggregated_payload_size self._control() - responses.append(response) - for response in responses: - yield response + return response + + def FullDuplexCall(self, request_iter, unused_rpc_context): + for request in request_iter: + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + yield response + + def HalfDuplexCall(self, request_iter, unused_rpc_context): + responses = [] + for request in request_iter: + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + responses.append(response) + for response in responses: + yield response class _Service( - collections.namedtuple( - '_Service', ('servicer_methods', 'server', 'stub',))): - """A live and running service. + collections.namedtuple('_Service', ( + 'servicer_methods', + 'server', + 'stub',))): + """A live and running service. Attributes: servicer_methods: The _ServicerMethods servicing RPCs. server: The grpc.Server servicing RPCs. stub: A stub on which to invoke RPCs. """ - + def _CreateService(): - """Provides a servicer backend and a stub. + """Provides a servicer backend and a stub. Returns: A _Service with which to test RPCs. """ - servicer_methods = _ServicerMethods() + servicer_methods = _ServicerMethods() - class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): + class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): - def UnaryCall(self, request, context): - return servicer_methods.UnaryCall(request, context) + def UnaryCall(self, request, context): + return servicer_methods.UnaryCall(request, context) - def StreamingOutputCall(self, request, context): - return servicer_methods.StreamingOutputCall(request, context) + def StreamingOutputCall(self, request, context): + return servicer_methods.StreamingOutputCall(request, context) - def StreamingInputCall(self, request_iter, context): - return servicer_methods.StreamingInputCall(request_iter, context) + def StreamingInputCall(self, request_iter, context): + return servicer_methods.StreamingInputCall(request_iter, context) - def FullDuplexCall(self, request_iter, context): - return servicer_methods.FullDuplexCall(request_iter, context) + def FullDuplexCall(self, request_iter, context): + return servicer_methods.FullDuplexCall(request_iter, context) - def HalfDuplexCall(self, request_iter, context): - return servicer_methods.HalfDuplexCall(request_iter, context) + def HalfDuplexCall(self, request_iter, context): + return servicer_methods.HalfDuplexCall(request_iter, context) - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) - getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:{}'.format(port)) - stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) - return _Service(servicer_methods, server, stub) + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) + getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:{}'.format(port)) + stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) + return _Service(servicer_methods, server, stub) def _CreateIncompleteService(): - """Provides a servicer backend that fails to implement methods and its stub. + """Provides a servicer backend that fails to implement methods and its stub. Returns: A _Service with which to test RPCs. The returned _Service's servicer_methods implements none of the methods required of it. """ - class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): - pass + class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): + pass - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) - getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:{}'.format(port)) - stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) - return _Service(None, server, stub) + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) + getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER)(Servicer(), server) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:{}'.format(port)) + stub = getattr(service_pb2, STUB_IDENTIFIER)(channel) + return _Service(None, server, stub) def _streaming_input_request_iterator(): - for _ in range(3): - request = request_pb2.StreamingInputCallRequest() - request.payload.payload_type = payload_pb2.COMPRESSABLE - request.payload.payload_compressable = 'a' - yield request + for _ in range(3): + request = request_pb2.StreamingInputCallRequest() + request.payload.payload_type = payload_pb2.COMPRESSABLE + request.payload.payload_compressable = 'a' + yield request def _streaming_output_request(): - request = request_pb2.StreamingOutputCallRequest() - sizes = [1, 2, 3] - request.response_parameters.add(size=sizes[0], interval_us=0) - request.response_parameters.add(size=sizes[1], interval_us=0) - request.response_parameters.add(size=sizes[2], interval_us=0) - return request + request = request_pb2.StreamingOutputCallRequest() + sizes = [1, 2, 3] + request.response_parameters.add(size=sizes[0], interval_us=0) + request.response_parameters.add(size=sizes[1], interval_us=0) + request.response_parameters.add(size=sizes[2], interval_us=0) + return request def _full_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=2, interval_us=0) - request.response_parameters.add(size=3, interval_us=0) - yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=2, interval_us=0) + request.response_parameters.add(size=3, interval_us=0) + yield request class PythonPluginTest(unittest.TestCase): - """Test case for the gRPC Python protoc-plugin. + """Test case for the gRPC Python protoc-plugin. While reading these tests, remember that the futures API (`stub.method.future()`) only gives futures for the *response-unary* methods and does not exist for response-streaming methods. """ - def testImportAttributes(self): - # check that we can access the generated module and its members. - self.assertIsNotNone( - getattr(service_pb2, STUB_IDENTIFIER, None)) - self.assertIsNotNone( - getattr(service_pb2, SERVICER_IDENTIFIER, None)) - self.assertIsNotNone( - getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER, None)) - - def testUpDown(self): - service = _CreateService() - self.assertIsNotNone(service.servicer_methods) - self.assertIsNotNone(service.server) - self.assertIsNotNone(service.stub) - - def testIncompleteServicer(self): - service = _CreateIncompleteService() - request = request_pb2.SimpleRequest(response_size=13) - with self.assertRaises(grpc.RpcError) as exception_context: - service.stub.UnaryCall(request) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.UNIMPLEMENTED) - - def testUnaryCall(self): - service = _CreateService() - request = request_pb2.SimpleRequest(response_size=13) - response = service.stub.UnaryCall(request) - expected_response = service.servicer_methods.UnaryCall( - request, 'not a real context!') - self.assertEqual(expected_response, response) - - def testUnaryCallFuture(self): - service = _CreateService() - request = request_pb2.SimpleRequest(response_size=13) - # Check that the call does not block waiting for the server to respond. - with service.servicer_methods.pause(): - response_future = service.stub.UnaryCall.future(request) - response = response_future.result() - expected_response = service.servicer_methods.UnaryCall( - request, 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testUnaryCallFutureExpired(self): - service = _CreateService() - request = request_pb2.SimpleRequest(response_size=13) - with service.servicer_methods.pause(): - response_future = service.stub.UnaryCall.future( - request, timeout=test_constants.SHORT_TIMEOUT) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) - self.assertIs(response_future.code(), grpc.StatusCode.DEADLINE_EXCEEDED) - - def testUnaryCallFutureCancelled(self): - service = _CreateService() - request = request_pb2.SimpleRequest(response_size=13) - with service.servicer_methods.pause(): - response_future = service.stub.UnaryCall.future(request) - response_future.cancel() - self.assertTrue(response_future.cancelled()) - self.assertIs(response_future.code(), grpc.StatusCode.CANCELLED) - - def testUnaryCallFutureFailed(self): - service = _CreateService() - request = request_pb2.SimpleRequest(response_size=13) - with service.servicer_methods.fail(): - response_future = service.stub.UnaryCall.future(request) - self.assertIsNotNone(response_future.exception()) - self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN) - - def testStreamingOutputCall(self): - service = _CreateService() - request = _streaming_output_request() - responses = service.stub.StreamingOutputCall(request) - expected_responses = service.servicer_methods.StreamingOutputCall( - request, 'not a real RpcContext!') - for expected_response, response in moves.zip_longest( - expected_responses, responses): - self.assertEqual(expected_response, response) - - def testStreamingOutputCallExpired(self): - service = _CreateService() - request = _streaming_output_request() - with service.servicer_methods.pause(): - responses = service.stub.StreamingOutputCall( - request, timeout=test_constants.SHORT_TIMEOUT) - with self.assertRaises(grpc.RpcError) as exception_context: - list(responses) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) - - def testStreamingOutputCallCancelled(self): - service = _CreateService() - request = _streaming_output_request() - responses = service.stub.StreamingOutputCall(request) - next(responses) - responses.cancel() - with self.assertRaises(grpc.RpcError) as exception_context: - next(responses) - self.assertIs(responses.code(), grpc.StatusCode.CANCELLED) - - def testStreamingOutputCallFailed(self): - service = _CreateService() - request = _streaming_output_request() - with service.servicer_methods.fail(): - responses = service.stub.StreamingOutputCall(request) - self.assertIsNotNone(responses) - with self.assertRaises(grpc.RpcError) as exception_context: - next(responses) - self.assertIs(exception_context.exception.code(), grpc.StatusCode.UNKNOWN) - - def testStreamingInputCall(self): - service = _CreateService() - response = service.stub.StreamingInputCall( - _streaming_input_request_iterator()) - expected_response = service.servicer_methods.StreamingInputCall( - _streaming_input_request_iterator(), - 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testStreamingInputCallFuture(self): - service = _CreateService() - with service.servicer_methods.pause(): - response_future = service.stub.StreamingInputCall.future( - _streaming_input_request_iterator()) - response = response_future.result() - expected_response = service.servicer_methods.StreamingInputCall( - _streaming_input_request_iterator(), - 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testStreamingInputCallFutureExpired(self): - service = _CreateService() - with service.servicer_methods.pause(): - response_future = service.stub.StreamingInputCall.future( - _streaming_input_request_iterator(), - timeout=test_constants.SHORT_TIMEOUT) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIsInstance(response_future.exception(), grpc.RpcError) - self.assertIs( - response_future.exception().code(), grpc.StatusCode.DEADLINE_EXCEEDED) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) - - def testStreamingInputCallFutureCancelled(self): - service = _CreateService() - with service.servicer_methods.pause(): - response_future = service.stub.StreamingInputCall.future( - _streaming_input_request_iterator()) - response_future.cancel() - self.assertTrue(response_future.cancelled()) - with self.assertRaises(grpc.FutureCancelledError): - response_future.result() - - def testStreamingInputCallFutureFailed(self): - service = _CreateService() - with service.servicer_methods.fail(): - response_future = service.stub.StreamingInputCall.future( - _streaming_input_request_iterator()) - self.assertIsNotNone(response_future.exception()) - self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN) - - def testFullDuplexCall(self): - service = _CreateService() - responses = service.stub.FullDuplexCall( - _full_duplex_request_iterator()) - expected_responses = service.servicer_methods.FullDuplexCall( - _full_duplex_request_iterator(), - 'not a real RpcContext!') - for expected_response, response in moves.zip_longest( - expected_responses, responses): - self.assertEqual(expected_response, response) - - def testFullDuplexCallExpired(self): - request_iterator = _full_duplex_request_iterator() - service = _CreateService() - with service.servicer_methods.pause(): - responses = service.stub.FullDuplexCall( - request_iterator, timeout=test_constants.SHORT_TIMEOUT) - with self.assertRaises(grpc.RpcError) as exception_context: - list(responses) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) - - def testFullDuplexCallCancelled(self): - service = _CreateService() - request_iterator = _full_duplex_request_iterator() - responses = service.stub.FullDuplexCall(request_iterator) - next(responses) - responses.cancel() - with self.assertRaises(grpc.RpcError) as exception_context: - next(responses) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.CANCELLED) - - def testFullDuplexCallFailed(self): - request_iterator = _full_duplex_request_iterator() - service = _CreateService() - with service.servicer_methods.fail(): - responses = service.stub.FullDuplexCall(request_iterator) - with self.assertRaises(grpc.RpcError) as exception_context: + def testImportAttributes(self): + # check that we can access the generated module and its members. + self.assertIsNotNone(getattr(service_pb2, STUB_IDENTIFIER, None)) + self.assertIsNotNone(getattr(service_pb2, SERVICER_IDENTIFIER, None)) + self.assertIsNotNone( + getattr(service_pb2, ADD_SERVICER_TO_SERVER_IDENTIFIER, None)) + + def testUpDown(self): + service = _CreateService() + self.assertIsNotNone(service.servicer_methods) + self.assertIsNotNone(service.server) + self.assertIsNotNone(service.stub) + + def testIncompleteServicer(self): + service = _CreateIncompleteService() + request = request_pb2.SimpleRequest(response_size=13) + with self.assertRaises(grpc.RpcError) as exception_context: + service.stub.UnaryCall(request) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.UNIMPLEMENTED) + + def testUnaryCall(self): + service = _CreateService() + request = request_pb2.SimpleRequest(response_size=13) + response = service.stub.UnaryCall(request) + expected_response = service.servicer_methods.UnaryCall( + request, 'not a real context!') + self.assertEqual(expected_response, response) + + def testUnaryCallFuture(self): + service = _CreateService() + request = request_pb2.SimpleRequest(response_size=13) + # Check that the call does not block waiting for the server to respond. + with service.servicer_methods.pause(): + response_future = service.stub.UnaryCall.future(request) + response = response_future.result() + expected_response = service.servicer_methods.UnaryCall( + request, 'not a real RpcContext!') + self.assertEqual(expected_response, response) + + def testUnaryCallFutureExpired(self): + service = _CreateService() + request = request_pb2.SimpleRequest(response_size=13) + with service.servicer_methods.pause(): + response_future = service.stub.UnaryCall.future( + request, timeout=test_constants.SHORT_TIMEOUT) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.DEADLINE_EXCEEDED) + self.assertIs(response_future.code(), grpc.StatusCode.DEADLINE_EXCEEDED) + + def testUnaryCallFutureCancelled(self): + service = _CreateService() + request = request_pb2.SimpleRequest(response_size=13) + with service.servicer_methods.pause(): + response_future = service.stub.UnaryCall.future(request) + response_future.cancel() + self.assertTrue(response_future.cancelled()) + self.assertIs(response_future.code(), grpc.StatusCode.CANCELLED) + + def testUnaryCallFutureFailed(self): + service = _CreateService() + request = request_pb2.SimpleRequest(response_size=13) + with service.servicer_methods.fail(): + response_future = service.stub.UnaryCall.future(request) + self.assertIsNotNone(response_future.exception()) + self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN) + + def testStreamingOutputCall(self): + service = _CreateService() + request = _streaming_output_request() + responses = service.stub.StreamingOutputCall(request) + expected_responses = service.servicer_methods.StreamingOutputCall( + request, 'not a real RpcContext!') + for expected_response, response in moves.zip_longest(expected_responses, + responses): + self.assertEqual(expected_response, response) + + def testStreamingOutputCallExpired(self): + service = _CreateService() + request = _streaming_output_request() + with service.servicer_methods.pause(): + responses = service.stub.StreamingOutputCall( + request, timeout=test_constants.SHORT_TIMEOUT) + with self.assertRaises(grpc.RpcError) as exception_context: + list(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.DEADLINE_EXCEEDED) + + def testStreamingOutputCallCancelled(self): + service = _CreateService() + request = _streaming_output_request() + responses = service.stub.StreamingOutputCall(request) next(responses) - self.assertIs(exception_context.exception.code(), grpc.StatusCode.UNKNOWN) - - def testHalfDuplexCall(self): - service = _CreateService() - def half_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=2, interval_us=0) - request.response_parameters.add(size=3, interval_us=0) - yield request - responses = service.stub.HalfDuplexCall(half_duplex_request_iterator()) - expected_responses = service.servicer_methods.HalfDuplexCall( - half_duplex_request_iterator(), 'not a real RpcContext!') - for expected_response, response in moves.zip_longest( - expected_responses, responses): - self.assertEqual(expected_response, response) - - def testHalfDuplexCallWedged(self): - condition = threading.Condition() - wait_cell = [False] - @contextlib.contextmanager - def wait(): # pylint: disable=invalid-name - # Where's Python 3's 'nonlocal' statement when you need it? - with condition: - wait_cell[0] = True - yield - with condition: - wait_cell[0] = False - condition.notify_all() - def half_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - with condition: - while wait_cell[0]: - condition.wait() - service = _CreateService() - with wait(): - responses = service.stub.HalfDuplexCall( - half_duplex_request_iterator(), timeout=test_constants.SHORT_TIMEOUT) - # half-duplex waits for the client to send all info - with self.assertRaises(grpc.RpcError) as exception_context: + responses.cancel() + with self.assertRaises(grpc.RpcError) as exception_context: + next(responses) + self.assertIs(responses.code(), grpc.StatusCode.CANCELLED) + + def testStreamingOutputCallFailed(self): + service = _CreateService() + request = _streaming_output_request() + with service.servicer_methods.fail(): + responses = service.stub.StreamingOutputCall(request) + self.assertIsNotNone(responses) + with self.assertRaises(grpc.RpcError) as exception_context: + next(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.UNKNOWN) + + def testStreamingInputCall(self): + service = _CreateService() + response = service.stub.StreamingInputCall( + _streaming_input_request_iterator()) + expected_response = service.servicer_methods.StreamingInputCall( + _streaming_input_request_iterator(), 'not a real RpcContext!') + self.assertEqual(expected_response, response) + + def testStreamingInputCallFuture(self): + service = _CreateService() + with service.servicer_methods.pause(): + response_future = service.stub.StreamingInputCall.future( + _streaming_input_request_iterator()) + response = response_future.result() + expected_response = service.servicer_methods.StreamingInputCall( + _streaming_input_request_iterator(), 'not a real RpcContext!') + self.assertEqual(expected_response, response) + + def testStreamingInputCallFutureExpired(self): + service = _CreateService() + with service.servicer_methods.pause(): + response_future = service.stub.StreamingInputCall.future( + _streaming_input_request_iterator(), + timeout=test_constants.SHORT_TIMEOUT) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIsInstance(response_future.exception(), grpc.RpcError) + self.assertIs(response_future.exception().code(), + grpc.StatusCode.DEADLINE_EXCEEDED) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.DEADLINE_EXCEEDED) + + def testStreamingInputCallFutureCancelled(self): + service = _CreateService() + with service.servicer_methods.pause(): + response_future = service.stub.StreamingInputCall.future( + _streaming_input_request_iterator()) + response_future.cancel() + self.assertTrue(response_future.cancelled()) + with self.assertRaises(grpc.FutureCancelledError): + response_future.result() + + def testStreamingInputCallFutureFailed(self): + service = _CreateService() + with service.servicer_methods.fail(): + response_future = service.stub.StreamingInputCall.future( + _streaming_input_request_iterator()) + self.assertIsNotNone(response_future.exception()) + self.assertIs(response_future.code(), grpc.StatusCode.UNKNOWN) + + def testFullDuplexCall(self): + service = _CreateService() + responses = service.stub.FullDuplexCall(_full_duplex_request_iterator()) + expected_responses = service.servicer_methods.FullDuplexCall( + _full_duplex_request_iterator(), 'not a real RpcContext!') + for expected_response, response in moves.zip_longest(expected_responses, + responses): + self.assertEqual(expected_response, response) + + def testFullDuplexCallExpired(self): + request_iterator = _full_duplex_request_iterator() + service = _CreateService() + with service.servicer_methods.pause(): + responses = service.stub.FullDuplexCall( + request_iterator, timeout=test_constants.SHORT_TIMEOUT) + with self.assertRaises(grpc.RpcError) as exception_context: + list(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.DEADLINE_EXCEEDED) + + def testFullDuplexCallCancelled(self): + service = _CreateService() + request_iterator = _full_duplex_request_iterator() + responses = service.stub.FullDuplexCall(request_iterator) next(responses) - self.assertIs( - exception_context.exception.code(), grpc.StatusCode.DEADLINE_EXCEEDED) + responses.cancel() + with self.assertRaises(grpc.RpcError) as exception_context: + next(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.CANCELLED) + + def testFullDuplexCallFailed(self): + request_iterator = _full_duplex_request_iterator() + service = _CreateService() + with service.servicer_methods.fail(): + responses = service.stub.FullDuplexCall(request_iterator) + with self.assertRaises(grpc.RpcError) as exception_context: + next(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.UNKNOWN) + + def testHalfDuplexCall(self): + service = _CreateService() + + def half_duplex_request_iterator(): + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=2, interval_us=0) + request.response_parameters.add(size=3, interval_us=0) + yield request + + responses = service.stub.HalfDuplexCall(half_duplex_request_iterator()) + expected_responses = service.servicer_methods.HalfDuplexCall( + half_duplex_request_iterator(), 'not a real RpcContext!') + for expected_response, response in moves.zip_longest(expected_responses, + responses): + self.assertEqual(expected_response, response) + + def testHalfDuplexCallWedged(self): + condition = threading.Condition() + wait_cell = [False] + + @contextlib.contextmanager + def wait(): # pylint: disable=invalid-name + # Where's Python 3's 'nonlocal' statement when you need it? + with condition: + wait_cell[0] = True + yield + with condition: + wait_cell[0] = False + condition.notify_all() + + def half_duplex_request_iterator(): + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + with condition: + while wait_cell[0]: + condition.wait() + + service = _CreateService() + with wait(): + responses = service.stub.HalfDuplexCall( + half_duplex_request_iterator(), + timeout=test_constants.SHORT_TIMEOUT) + # half-duplex waits for the client to send all info + with self.assertRaises(grpc.RpcError) as exception_context: + next(responses) + self.assertIs(exception_context.exception.code(), + grpc.StatusCode.DEADLINE_EXCEEDED) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py b/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py index f8ae05bb7a9..bcc01f39787 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/_split_definitions_test.py @@ -49,256 +49,264 @@ from tests.unit.framework.common import test_constants _MESSAGES_IMPORT = b'import "messages.proto";' + @contextlib.contextmanager def _system_path(path): - old_system_path = sys.path[:] - sys.path = sys.path[0:1] + path + sys.path[1:] - yield - sys.path = old_system_path + old_system_path = sys.path[:] + sys.path = sys.path[0:1] + path + sys.path[1:] + yield + sys.path = old_system_path class DummySplitServicer(object): - def __init__(self, request_class, response_class): - self.request_class = request_class - self.response_class = response_class + def __init__(self, request_class, response_class): + self.request_class = request_class + self.response_class = response_class - def Call(self, request, context): - return self.response_class() + def Call(self, request, context): + return self.response_class() class SeparateTestMixin(object): - def testImportAttributes(self): - with _system_path([self.python_out_directory]): - pb2 = importlib.import_module(self.pb2_import) - pb2.Request - pb2.Response - if self.should_find_services_in_pb2: - pb2.TestServiceServicer - else: - with self.assertRaises(AttributeError): - pb2.TestServiceServicer - - with _system_path([self.grpc_python_out_directory]): - pb2_grpc = importlib.import_module(self.pb2_grpc_import) - pb2_grpc.TestServiceServicer - with self.assertRaises(AttributeError): - pb2_grpc.Request - with self.assertRaises(AttributeError): - pb2_grpc.Response - - def testCall(self): - with _system_path([self.python_out_directory]): - pb2 = importlib.import_module(self.pb2_import) - with _system_path([self.grpc_python_out_directory]): - pb2_grpc = importlib.import_module(self.pb2_grpc_import) - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) - pb2_grpc.add_TestServiceServicer_to_server( - DummySplitServicer( - pb2.Request, pb2.Response), server) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:{}'.format(port)) - stub = pb2_grpc.TestServiceStub(channel) - request = pb2.Request() - expected_response = pb2.Response() - response = stub.Call(request) - self.assertEqual(expected_response, response) + def testImportAttributes(self): + with _system_path([self.python_out_directory]): + pb2 = importlib.import_module(self.pb2_import) + pb2.Request + pb2.Response + if self.should_find_services_in_pb2: + pb2.TestServiceServicer + else: + with self.assertRaises(AttributeError): + pb2.TestServiceServicer + + with _system_path([self.grpc_python_out_directory]): + pb2_grpc = importlib.import_module(self.pb2_grpc_import) + pb2_grpc.TestServiceServicer + with self.assertRaises(AttributeError): + pb2_grpc.Request + with self.assertRaises(AttributeError): + pb2_grpc.Response + + def testCall(self): + with _system_path([self.python_out_directory]): + pb2 = importlib.import_module(self.pb2_import) + with _system_path([self.grpc_python_out_directory]): + pb2_grpc = importlib.import_module(self.pb2_grpc_import) + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) + pb2_grpc.add_TestServiceServicer_to_server( + DummySplitServicer(pb2.Request, pb2.Response), server) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:{}'.format(port)) + stub = pb2_grpc.TestServiceStub(channel) + request = pb2.Request() + expected_response = pb2.Response() + response = stub.Call(request) + self.assertEqual(expected_response, response) class CommonTestMixin(object): - def testImportAttributes(self): - with _system_path([self.python_out_directory]): - pb2 = importlib.import_module(self.pb2_import) - pb2.Request - pb2.Response - if self.should_find_services_in_pb2: - pb2.TestServiceServicer - else: - with self.assertRaises(AttributeError): - pb2.TestServiceServicer - - with _system_path([self.grpc_python_out_directory]): - pb2_grpc = importlib.import_module(self.pb2_grpc_import) - pb2_grpc.TestServiceServicer - with self.assertRaises(AttributeError): - pb2_grpc.Request - with self.assertRaises(AttributeError): - pb2_grpc.Response - - def testCall(self): - with _system_path([self.python_out_directory]): - pb2 = importlib.import_module(self.pb2_import) - with _system_path([self.grpc_python_out_directory]): - pb2_grpc = importlib.import_module(self.pb2_grpc_import) - server = grpc.server( - futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) - pb2_grpc.add_TestServiceServicer_to_server( - DummySplitServicer( - pb2.Request, pb2.Response), server) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:{}'.format(port)) - stub = pb2_grpc.TestServiceStub(channel) - request = pb2.Request() - expected_response = pb2.Response() - response = stub.Call(request) - self.assertEqual(expected_response, response) + def testImportAttributes(self): + with _system_path([self.python_out_directory]): + pb2 = importlib.import_module(self.pb2_import) + pb2.Request + pb2.Response + if self.should_find_services_in_pb2: + pb2.TestServiceServicer + else: + with self.assertRaises(AttributeError): + pb2.TestServiceServicer + + with _system_path([self.grpc_python_out_directory]): + pb2_grpc = importlib.import_module(self.pb2_grpc_import) + pb2_grpc.TestServiceServicer + with self.assertRaises(AttributeError): + pb2_grpc.Request + with self.assertRaises(AttributeError): + pb2_grpc.Response + + def testCall(self): + with _system_path([self.python_out_directory]): + pb2 = importlib.import_module(self.pb2_import) + with _system_path([self.grpc_python_out_directory]): + pb2_grpc = importlib.import_module(self.pb2_grpc_import) + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=test_constants.POOL_SIZE)) + pb2_grpc.add_TestServiceServicer_to_server( + DummySplitServicer(pb2.Request, pb2.Response), server) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:{}'.format(port)) + stub = pb2_grpc.TestServiceStub(channel) + request = pb2.Request() + expected_response = pb2.Response() + response = stub.Call(request) + self.assertEqual(expected_response, response) class SameSeparateTest(unittest.TestCase, SeparateTestMixin): - def setUp(self): - same_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing', 'same.proto') - self.directory = tempfile.mkdtemp(suffix='same_separate', dir='.') - self.proto_directory = os.path.join(self.directory, 'proto_path') - self.python_out_directory = os.path.join(self.directory, 'python_out') - self.grpc_python_out_directory = os.path.join(self.directory, 'grpc_python_out') - os.makedirs(self.proto_directory) - os.makedirs(self.python_out_directory) - os.makedirs(self.grpc_python_out_directory) - same_proto_file = os.path.join(self.proto_directory, 'same_separate.proto') - open(same_proto_file, 'wb').write(same_proto_contents) - protoc_result = protoc.main([ - '', - '--proto_path={}'.format(self.proto_directory), - '--python_out={}'.format(self.python_out_directory), - '--grpc_python_out=grpc_2_0:{}'.format(self.grpc_python_out_directory), - same_proto_file, - ]) - if protoc_result != 0: - raise Exception("unexpected protoc error") - open(os.path.join(self.grpc_python_out_directory, '__init__.py'), 'w').write('') - open(os.path.join(self.python_out_directory, '__init__.py'), 'w').write('') - self.pb2_import = 'same_separate_pb2' - self.pb2_grpc_import = 'same_separate_pb2_grpc' - self.should_find_services_in_pb2 = False - - def tearDown(self): - shutil.rmtree(self.directory) + def setUp(self): + same_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing', 'same.proto') + self.directory = tempfile.mkdtemp(suffix='same_separate', dir='.') + self.proto_directory = os.path.join(self.directory, 'proto_path') + self.python_out_directory = os.path.join(self.directory, 'python_out') + self.grpc_python_out_directory = os.path.join(self.directory, + 'grpc_python_out') + os.makedirs(self.proto_directory) + os.makedirs(self.python_out_directory) + os.makedirs(self.grpc_python_out_directory) + same_proto_file = os.path.join(self.proto_directory, + 'same_separate.proto') + open(same_proto_file, 'wb').write(same_proto_contents) + protoc_result = protoc.main([ + '', + '--proto_path={}'.format(self.proto_directory), + '--python_out={}'.format(self.python_out_directory), + '--grpc_python_out=grpc_2_0:{}'.format( + self.grpc_python_out_directory), + same_proto_file, + ]) + if protoc_result != 0: + raise Exception("unexpected protoc error") + open(os.path.join(self.grpc_python_out_directory, '__init__.py'), + 'w').write('') + open(os.path.join(self.python_out_directory, '__init__.py'), + 'w').write('') + self.pb2_import = 'same_separate_pb2' + self.pb2_grpc_import = 'same_separate_pb2_grpc' + self.should_find_services_in_pb2 = False + + def tearDown(self): + shutil.rmtree(self.directory) class SameCommonTest(unittest.TestCase, CommonTestMixin): - def setUp(self): - same_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing', 'same.proto') - self.directory = tempfile.mkdtemp(suffix='same_common', dir='.') - self.proto_directory = os.path.join(self.directory, 'proto_path') - self.python_out_directory = os.path.join(self.directory, 'python_out') - self.grpc_python_out_directory = self.python_out_directory - os.makedirs(self.proto_directory) - os.makedirs(self.python_out_directory) - same_proto_file = os.path.join(self.proto_directory, 'same_common.proto') - open(same_proto_file, 'wb').write(same_proto_contents) - protoc_result = protoc.main([ - '', - '--proto_path={}'.format(self.proto_directory), - '--python_out={}'.format(self.python_out_directory), - '--grpc_python_out={}'.format(self.grpc_python_out_directory), - same_proto_file, - ]) - if protoc_result != 0: - raise Exception("unexpected protoc error") - open(os.path.join(self.python_out_directory, '__init__.py'), 'w').write('') - self.pb2_import = 'same_common_pb2' - self.pb2_grpc_import = 'same_common_pb2_grpc' - self.should_find_services_in_pb2 = True - - def tearDown(self): - shutil.rmtree(self.directory) + def setUp(self): + same_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing', 'same.proto') + self.directory = tempfile.mkdtemp(suffix='same_common', dir='.') + self.proto_directory = os.path.join(self.directory, 'proto_path') + self.python_out_directory = os.path.join(self.directory, 'python_out') + self.grpc_python_out_directory = self.python_out_directory + os.makedirs(self.proto_directory) + os.makedirs(self.python_out_directory) + same_proto_file = os.path.join(self.proto_directory, + 'same_common.proto') + open(same_proto_file, 'wb').write(same_proto_contents) + protoc_result = protoc.main([ + '', + '--proto_path={}'.format(self.proto_directory), + '--python_out={}'.format(self.python_out_directory), + '--grpc_python_out={}'.format(self.grpc_python_out_directory), + same_proto_file, + ]) + if protoc_result != 0: + raise Exception("unexpected protoc error") + open(os.path.join(self.python_out_directory, '__init__.py'), + 'w').write('') + self.pb2_import = 'same_common_pb2' + self.pb2_grpc_import = 'same_common_pb2_grpc' + self.should_find_services_in_pb2 = True + + def tearDown(self): + shutil.rmtree(self.directory) class SplitCommonTest(unittest.TestCase, CommonTestMixin): - def setUp(self): - services_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing.split_services', - 'services.proto') - messages_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing.split_messages', - 'messages.proto') - self.directory = tempfile.mkdtemp(suffix='split_common', dir='.') - self.proto_directory = os.path.join(self.directory, 'proto_path') - self.python_out_directory = os.path.join(self.directory, 'python_out') - self.grpc_python_out_directory = self.python_out_directory - os.makedirs(self.proto_directory) - os.makedirs(self.python_out_directory) - services_proto_file = os.path.join(self.proto_directory, - 'split_common_services.proto') - messages_proto_file = os.path.join(self.proto_directory, - 'split_common_messages.proto') - open(services_proto_file, 'wb').write(services_proto_contents.replace( - _MESSAGES_IMPORT, - b'import "split_common_messages.proto";' - )) - open(messages_proto_file, 'wb').write(messages_proto_contents) - protoc_result = protoc.main([ - '', - '--proto_path={}'.format(self.proto_directory), - '--python_out={}'.format(self.python_out_directory), - '--grpc_python_out={}'.format(self.grpc_python_out_directory), - services_proto_file, - messages_proto_file, - ]) - if protoc_result != 0: - raise Exception("unexpected protoc error") - open(os.path.join(self.python_out_directory, '__init__.py'), 'w').write('') - self.pb2_import = 'split_common_messages_pb2' - self.pb2_grpc_import = 'split_common_services_pb2_grpc' - self.should_find_services_in_pb2 = False - - def tearDown(self): - shutil.rmtree(self.directory) + def setUp(self): + services_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing.split_services', + 'services.proto') + messages_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing.split_messages', + 'messages.proto') + self.directory = tempfile.mkdtemp(suffix='split_common', dir='.') + self.proto_directory = os.path.join(self.directory, 'proto_path') + self.python_out_directory = os.path.join(self.directory, 'python_out') + self.grpc_python_out_directory = self.python_out_directory + os.makedirs(self.proto_directory) + os.makedirs(self.python_out_directory) + services_proto_file = os.path.join(self.proto_directory, + 'split_common_services.proto') + messages_proto_file = os.path.join(self.proto_directory, + 'split_common_messages.proto') + open(services_proto_file, 'wb').write( + services_proto_contents.replace( + _MESSAGES_IMPORT, b'import "split_common_messages.proto";')) + open(messages_proto_file, 'wb').write(messages_proto_contents) + protoc_result = protoc.main([ + '', + '--proto_path={}'.format(self.proto_directory), + '--python_out={}'.format(self.python_out_directory), + '--grpc_python_out={}'.format(self.grpc_python_out_directory), + services_proto_file, + messages_proto_file, + ]) + if protoc_result != 0: + raise Exception("unexpected protoc error") + open(os.path.join(self.python_out_directory, '__init__.py'), + 'w').write('') + self.pb2_import = 'split_common_messages_pb2' + self.pb2_grpc_import = 'split_common_services_pb2_grpc' + self.should_find_services_in_pb2 = False + + def tearDown(self): + shutil.rmtree(self.directory) class SplitSeparateTest(unittest.TestCase, SeparateTestMixin): - def setUp(self): - services_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing.split_services', - 'services.proto') - messages_proto_contents = pkgutil.get_data( - 'tests.protoc_plugin.protos.invocation_testing.split_messages', - 'messages.proto') - self.directory = tempfile.mkdtemp(suffix='split_separate', dir='.') - self.proto_directory = os.path.join(self.directory, 'proto_path') - self.python_out_directory = os.path.join(self.directory, 'python_out') - self.grpc_python_out_directory = os.path.join(self.directory, 'grpc_python_out') - os.makedirs(self.proto_directory) - os.makedirs(self.python_out_directory) - os.makedirs(self.grpc_python_out_directory) - services_proto_file = os.path.join(self.proto_directory, - 'split_separate_services.proto') - messages_proto_file = os.path.join(self.proto_directory, - 'split_separate_messages.proto') - open(services_proto_file, 'wb').write(services_proto_contents.replace( - _MESSAGES_IMPORT, - b'import "split_separate_messages.proto";' - )) - open(messages_proto_file, 'wb').write(messages_proto_contents) - protoc_result = protoc.main([ - '', - '--proto_path={}'.format(self.proto_directory), - '--python_out={}'.format(self.python_out_directory), - '--grpc_python_out=grpc_2_0:{}'.format(self.grpc_python_out_directory), - services_proto_file, - messages_proto_file, - ]) - if protoc_result != 0: - raise Exception("unexpected protoc error") - open(os.path.join(self.python_out_directory, '__init__.py'), 'w').write('') - self.pb2_import = 'split_separate_messages_pb2' - self.pb2_grpc_import = 'split_separate_services_pb2_grpc' - self.should_find_services_in_pb2 = False - - def tearDown(self): - shutil.rmtree(self.directory) + def setUp(self): + services_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing.split_services', + 'services.proto') + messages_proto_contents = pkgutil.get_data( + 'tests.protoc_plugin.protos.invocation_testing.split_messages', + 'messages.proto') + self.directory = tempfile.mkdtemp(suffix='split_separate', dir='.') + self.proto_directory = os.path.join(self.directory, 'proto_path') + self.python_out_directory = os.path.join(self.directory, 'python_out') + self.grpc_python_out_directory = os.path.join(self.directory, + 'grpc_python_out') + os.makedirs(self.proto_directory) + os.makedirs(self.python_out_directory) + os.makedirs(self.grpc_python_out_directory) + services_proto_file = os.path.join(self.proto_directory, + 'split_separate_services.proto') + messages_proto_file = os.path.join(self.proto_directory, + 'split_separate_messages.proto') + open(services_proto_file, 'wb').write( + services_proto_contents.replace( + _MESSAGES_IMPORT, b'import "split_separate_messages.proto";')) + open(messages_proto_file, 'wb').write(messages_proto_contents) + protoc_result = protoc.main([ + '', + '--proto_path={}'.format(self.proto_directory), + '--python_out={}'.format(self.python_out_directory), + '--grpc_python_out=grpc_2_0:{}'.format( + self.grpc_python_out_directory), + services_proto_file, + messages_proto_file, + ]) + if protoc_result != 0: + raise Exception("unexpected protoc error") + open(os.path.join(self.python_out_directory, '__init__.py'), + 'w').write('') + self.pb2_import = 'split_separate_messages_pb2' + self.pb2_grpc_import = 'split_separate_services_pb2_grpc' + self.should_find_services_in_pb2 = False + + def tearDown(self): + shutil.rmtree(self.directory) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py b/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py index 1eba9c93543..f64f4e962ba 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/beta_python_plugin_test.py @@ -64,84 +64,84 @@ STUB_FACTORY_IDENTIFIER = 'beta_create_TestService_stub' class _ServicerMethods(object): - def __init__(self): - self._condition = threading.Condition() - self._paused = False - self._fail = False - - @contextlib.contextmanager - def pause(self): # pylint: disable=invalid-name - with self._condition: - self._paused = True - yield - with self._condition: - self._paused = False - self._condition.notify_all() - - @contextlib.contextmanager - def fail(self): # pylint: disable=invalid-name - with self._condition: - self._fail = True - yield - with self._condition: - self._fail = False - - def _control(self): # pylint: disable=invalid-name - with self._condition: - if self._fail: - raise ValueError() - while self._paused: - self._condition.wait() - - def UnaryCall(self, request, unused_rpc_context): - response = response_pb2.SimpleResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * request.response_size - self._control() - return response - - def StreamingOutputCall(self, request, unused_rpc_context): - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size - self._control() - yield response - - def StreamingInputCall(self, request_iter, unused_rpc_context): - response = response_pb2.StreamingInputCallResponse() - aggregated_payload_size = 0 - for request in request_iter: - aggregated_payload_size += len(request.payload.payload_compressable) - response.aggregated_payload_size = aggregated_payload_size - self._control() - return response - - def FullDuplexCall(self, request_iter, unused_rpc_context): - for request in request_iter: - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() - response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size - self._control() - yield response + def __init__(self): + self._condition = threading.Condition() + self._paused = False + self._fail = False + + @contextlib.contextmanager + def pause(self): # pylint: disable=invalid-name + with self._condition: + self._paused = True + yield + with self._condition: + self._paused = False + self._condition.notify_all() - def HalfDuplexCall(self, request_iter, unused_rpc_context): - responses = [] - for request in request_iter: - for parameter in request.response_parameters: - response = response_pb2.StreamingOutputCallResponse() + @contextlib.contextmanager + def fail(self): # pylint: disable=invalid-name + with self._condition: + self._fail = True + yield + with self._condition: + self._fail = False + + def _control(self): # pylint: disable=invalid-name + with self._condition: + if self._fail: + raise ValueError() + while self._paused: + self._condition.wait() + + def UnaryCall(self, request, unused_rpc_context): + response = response_pb2.SimpleResponse() response.payload.payload_type = payload_pb2.COMPRESSABLE - response.payload.payload_compressable = 'a' * parameter.size + response.payload.payload_compressable = 'a' * request.response_size + self._control() + return response + + def StreamingOutputCall(self, request, unused_rpc_context): + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + yield response + + def StreamingInputCall(self, request_iter, unused_rpc_context): + response = response_pb2.StreamingInputCallResponse() + aggregated_payload_size = 0 + for request in request_iter: + aggregated_payload_size += len(request.payload.payload_compressable) + response.aggregated_payload_size = aggregated_payload_size self._control() - responses.append(response) - for response in responses: - yield response + return response + + def FullDuplexCall(self, request_iter, unused_rpc_context): + for request in request_iter: + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + yield response + + def HalfDuplexCall(self, request_iter, unused_rpc_context): + responses = [] + for request in request_iter: + for parameter in request.response_parameters: + response = response_pb2.StreamingOutputCallResponse() + response.payload.payload_type = payload_pb2.COMPRESSABLE + response.payload.payload_compressable = 'a' * parameter.size + self._control() + responses.append(response) + for response in responses: + yield response @contextlib.contextmanager def _CreateService(): - """Provides a servicer backend and a stub. + """Provides a servicer backend and a stub. The servicer is just the implementation of the actual servicer passed to the face player of the python RPC implementation; the two are detached. @@ -151,38 +151,38 @@ def _CreateService(): the service bound to the stub and and stub is the stub on which to invoke RPCs. """ - servicer_methods = _ServicerMethods() + servicer_methods = _ServicerMethods() - class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): + class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): - def UnaryCall(self, request, context): - return servicer_methods.UnaryCall(request, context) + def UnaryCall(self, request, context): + return servicer_methods.UnaryCall(request, context) - def StreamingOutputCall(self, request, context): - return servicer_methods.StreamingOutputCall(request, context) + def StreamingOutputCall(self, request, context): + return servicer_methods.StreamingOutputCall(request, context) - def StreamingInputCall(self, request_iter, context): - return servicer_methods.StreamingInputCall(request_iter, context) + def StreamingInputCall(self, request_iter, context): + return servicer_methods.StreamingInputCall(request_iter, context) - def FullDuplexCall(self, request_iter, context): - return servicer_methods.FullDuplexCall(request_iter, context) + def FullDuplexCall(self, request_iter, context): + return servicer_methods.FullDuplexCall(request_iter, context) - def HalfDuplexCall(self, request_iter, context): - return servicer_methods.HalfDuplexCall(request_iter, context) + def HalfDuplexCall(self, request_iter, context): + return servicer_methods.HalfDuplexCall(request_iter, context) - servicer = Servicer() - server = getattr(service_pb2, SERVER_FACTORY_IDENTIFIER)(servicer) - port = server.add_insecure_port('[::]:0') - server.start() - channel = implementations.insecure_channel('localhost', port) - stub = getattr(service_pb2, STUB_FACTORY_IDENTIFIER)(channel) - yield (servicer_methods, stub) - server.stop(0) + servicer = Servicer() + server = getattr(service_pb2, SERVER_FACTORY_IDENTIFIER)(servicer) + port = server.add_insecure_port('[::]:0') + server.start() + channel = implementations.insecure_channel('localhost', port) + stub = getattr(service_pb2, STUB_FACTORY_IDENTIFIER)(channel) + yield (servicer_methods, stub) + server.stop(0) @contextlib.contextmanager def _CreateIncompleteService(): - """Provides a servicer backend that fails to implement methods and its stub. + """Provides a servicer backend that fails to implement methods and its stub. The servicer is just the implementation of the actual servicer passed to the face player of the python RPC implementation; the two are detached. @@ -194,297 +194,297 @@ def _CreateIncompleteService(): RPCs. """ - class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): - pass + class Servicer(getattr(service_pb2, SERVICER_IDENTIFIER)): + pass - servicer = Servicer() - server = getattr(service_pb2, SERVER_FACTORY_IDENTIFIER)(servicer) - port = server.add_insecure_port('[::]:0') - server.start() - channel = implementations.insecure_channel('localhost', port) - stub = getattr(service_pb2, STUB_FACTORY_IDENTIFIER)(channel) - yield None, stub - server.stop(0) + servicer = Servicer() + server = getattr(service_pb2, SERVER_FACTORY_IDENTIFIER)(servicer) + port = server.add_insecure_port('[::]:0') + server.start() + channel = implementations.insecure_channel('localhost', port) + stub = getattr(service_pb2, STUB_FACTORY_IDENTIFIER)(channel) + yield None, stub + server.stop(0) def _streaming_input_request_iterator(): - for _ in range(3): - request = request_pb2.StreamingInputCallRequest() - request.payload.payload_type = payload_pb2.COMPRESSABLE - request.payload.payload_compressable = 'a' - yield request + for _ in range(3): + request = request_pb2.StreamingInputCallRequest() + request.payload.payload_type = payload_pb2.COMPRESSABLE + request.payload.payload_compressable = 'a' + yield request def _streaming_output_request(): - request = request_pb2.StreamingOutputCallRequest() - sizes = [1, 2, 3] - request.response_parameters.add(size=sizes[0], interval_us=0) - request.response_parameters.add(size=sizes[1], interval_us=0) - request.response_parameters.add(size=sizes[2], interval_us=0) - return request + request = request_pb2.StreamingOutputCallRequest() + sizes = [1, 2, 3] + request.response_parameters.add(size=sizes[0], interval_us=0) + request.response_parameters.add(size=sizes[1], interval_us=0) + request.response_parameters.add(size=sizes[2], interval_us=0) + return request def _full_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=2, interval_us=0) - request.response_parameters.add(size=3, interval_us=0) - yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=2, interval_us=0) + request.response_parameters.add(size=3, interval_us=0) + yield request class PythonPluginTest(unittest.TestCase): - """Test case for the gRPC Python protoc-plugin. + """Test case for the gRPC Python protoc-plugin. While reading these tests, remember that the futures API (`stub.method.future()`) only gives futures for the *response-unary* methods and does not exist for response-streaming methods. """ - def testImportAttributes(self): - # check that we can access the generated module and its members. - self.assertIsNotNone( - getattr(service_pb2, SERVICER_IDENTIFIER, None)) - self.assertIsNotNone( - getattr(service_pb2, STUB_IDENTIFIER, None)) - self.assertIsNotNone( - getattr(service_pb2, SERVER_FACTORY_IDENTIFIER, None)) - self.assertIsNotNone( - getattr(service_pb2, STUB_FACTORY_IDENTIFIER, None)) - - def testUpDown(self): - with _CreateService(): - request_pb2.SimpleRequest(response_size=13) - - def testIncompleteServicer(self): - with _CreateIncompleteService() as (_, stub): - request = request_pb2.SimpleRequest(response_size=13) - try: - stub.UnaryCall(request, test_constants.LONG_TIMEOUT) - except face.AbortionError as error: - self.assertEqual(interfaces.StatusCode.UNIMPLEMENTED, error.code) - - def testUnaryCall(self): - with _CreateService() as (methods, stub): - request = request_pb2.SimpleRequest(response_size=13) - response = stub.UnaryCall(request, test_constants.LONG_TIMEOUT) - expected_response = methods.UnaryCall(request, 'not a real context!') - self.assertEqual(expected_response, response) - - def testUnaryCallFuture(self): - with _CreateService() as (methods, stub): - request = request_pb2.SimpleRequest(response_size=13) - # Check that the call does not block waiting for the server to respond. - with methods.pause(): - response_future = stub.UnaryCall.future( - request, test_constants.LONG_TIMEOUT) - response = response_future.result() - expected_response = methods.UnaryCall(request, 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testUnaryCallFutureExpired(self): - with _CreateService() as (methods, stub): - request = request_pb2.SimpleRequest(response_size=13) - with methods.pause(): - response_future = stub.UnaryCall.future( - request, test_constants.SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - response_future.result() - - def testUnaryCallFutureCancelled(self): - with _CreateService() as (methods, stub): - request = request_pb2.SimpleRequest(response_size=13) - with methods.pause(): - response_future = stub.UnaryCall.future(request, 1) - response_future.cancel() - self.assertTrue(response_future.cancelled()) - - def testUnaryCallFutureFailed(self): - with _CreateService() as (methods, stub): - request = request_pb2.SimpleRequest(response_size=13) - with methods.fail(): - response_future = stub.UnaryCall.future( - request, test_constants.LONG_TIMEOUT) - self.assertIsNotNone(response_future.exception()) - - def testStreamingOutputCall(self): - with _CreateService() as (methods, stub): - request = _streaming_output_request() - responses = stub.StreamingOutputCall( - request, test_constants.LONG_TIMEOUT) - expected_responses = methods.StreamingOutputCall( - request, 'not a real RpcContext!') - for expected_response, response in moves.zip_longest( - expected_responses, responses): + def testImportAttributes(self): + # check that we can access the generated module and its members. + self.assertIsNotNone(getattr(service_pb2, SERVICER_IDENTIFIER, None)) + self.assertIsNotNone(getattr(service_pb2, STUB_IDENTIFIER, None)) + self.assertIsNotNone( + getattr(service_pb2, SERVER_FACTORY_IDENTIFIER, None)) + self.assertIsNotNone( + getattr(service_pb2, STUB_FACTORY_IDENTIFIER, None)) + + def testUpDown(self): + with _CreateService(): + request_pb2.SimpleRequest(response_size=13) + + def testIncompleteServicer(self): + with _CreateIncompleteService() as (_, stub): + request = request_pb2.SimpleRequest(response_size=13) + try: + stub.UnaryCall(request, test_constants.LONG_TIMEOUT) + except face.AbortionError as error: + self.assertEqual(interfaces.StatusCode.UNIMPLEMENTED, + error.code) + + def testUnaryCall(self): + with _CreateService() as (methods, stub): + request = request_pb2.SimpleRequest(response_size=13) + response = stub.UnaryCall(request, test_constants.LONG_TIMEOUT) + expected_response = methods.UnaryCall(request, 'not a real context!') self.assertEqual(expected_response, response) - def testStreamingOutputCallExpired(self): - with _CreateService() as (methods, stub): - request = _streaming_output_request() - with methods.pause(): - responses = stub.StreamingOutputCall( - request, test_constants.SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - list(responses) - - def testStreamingOutputCallCancelled(self): - with _CreateService() as (methods, stub): - request = _streaming_output_request() - responses = stub.StreamingOutputCall( - request, test_constants.LONG_TIMEOUT) - next(responses) - responses.cancel() - with self.assertRaises(face.CancellationError): - next(responses) - - def testStreamingOutputCallFailed(self): - with _CreateService() as (methods, stub): - request = _streaming_output_request() - with methods.fail(): - responses = stub.StreamingOutputCall(request, 1) - self.assertIsNotNone(responses) - with self.assertRaises(face.RemoteError): - next(responses) - - def testStreamingInputCall(self): - with _CreateService() as (methods, stub): - response = stub.StreamingInputCall( - _streaming_input_request_iterator(), - test_constants.LONG_TIMEOUT) - expected_response = methods.StreamingInputCall( - _streaming_input_request_iterator(), - 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testStreamingInputCallFuture(self): - with _CreateService() as (methods, stub): - with methods.pause(): - response_future = stub.StreamingInputCall.future( - _streaming_input_request_iterator(), - test_constants.LONG_TIMEOUT) - response = response_future.result() - expected_response = methods.StreamingInputCall( - _streaming_input_request_iterator(), - 'not a real RpcContext!') - self.assertEqual(expected_response, response) - - def testStreamingInputCallFutureExpired(self): - with _CreateService() as (methods, stub): - with methods.pause(): - response_future = stub.StreamingInputCall.future( - _streaming_input_request_iterator(), - test_constants.SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - response_future.result() - self.assertIsInstance( - response_future.exception(), face.ExpirationError) - - def testStreamingInputCallFutureCancelled(self): - with _CreateService() as (methods, stub): - with methods.pause(): - response_future = stub.StreamingInputCall.future( - _streaming_input_request_iterator(), - test_constants.LONG_TIMEOUT) - response_future.cancel() - self.assertTrue(response_future.cancelled()) - with self.assertRaises(future.CancelledError): - response_future.result() - - def testStreamingInputCallFutureFailed(self): - with _CreateService() as (methods, stub): - with methods.fail(): - response_future = stub.StreamingInputCall.future( - _streaming_input_request_iterator(), - test_constants.LONG_TIMEOUT) - self.assertIsNotNone(response_future.exception()) - - def testFullDuplexCall(self): - with _CreateService() as (methods, stub): - responses = stub.FullDuplexCall( - _full_duplex_request_iterator(), - test_constants.LONG_TIMEOUT) - expected_responses = methods.FullDuplexCall( - _full_duplex_request_iterator(), - 'not a real RpcContext!') - for expected_response, response in moves.zip_longest( - expected_responses, responses): + def testUnaryCallFuture(self): + with _CreateService() as (methods, stub): + request = request_pb2.SimpleRequest(response_size=13) + # Check that the call does not block waiting for the server to respond. + with methods.pause(): + response_future = stub.UnaryCall.future( + request, test_constants.LONG_TIMEOUT) + response = response_future.result() + expected_response = methods.UnaryCall(request, 'not a real RpcContext!') self.assertEqual(expected_response, response) - def testFullDuplexCallExpired(self): - request_iterator = _full_duplex_request_iterator() - with _CreateService() as (methods, stub): - with methods.pause(): - responses = stub.FullDuplexCall( - request_iterator, test_constants.SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - list(responses) - - def testFullDuplexCallCancelled(self): - with _CreateService() as (methods, stub): - request_iterator = _full_duplex_request_iterator() - responses = stub.FullDuplexCall( - request_iterator, test_constants.LONG_TIMEOUT) - next(responses) - responses.cancel() - with self.assertRaises(face.CancellationError): - next(responses) - - def testFullDuplexCallFailed(self): - request_iterator = _full_duplex_request_iterator() - with _CreateService() as (methods, stub): - with methods.fail(): - responses = stub.FullDuplexCall( - request_iterator, test_constants.LONG_TIMEOUT) - self.assertIsNotNone(responses) - with self.assertRaises(face.RemoteError): - next(responses) - - def testHalfDuplexCall(self): - with _CreateService() as (methods, stub): - def half_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=2, interval_us=0) - request.response_parameters.add(size=3, interval_us=0) - yield request - responses = stub.HalfDuplexCall( - half_duplex_request_iterator(), test_constants.LONG_TIMEOUT) - expected_responses = methods.HalfDuplexCall( - half_duplex_request_iterator(), 'not a real RpcContext!') - for check in moves.zip_longest(expected_responses, responses): - expected_response, response = check + def testUnaryCallFutureExpired(self): + with _CreateService() as (methods, stub): + request = request_pb2.SimpleRequest(response_size=13) + with methods.pause(): + response_future = stub.UnaryCall.future( + request, test_constants.SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + response_future.result() + + def testUnaryCallFutureCancelled(self): + with _CreateService() as (methods, stub): + request = request_pb2.SimpleRequest(response_size=13) + with methods.pause(): + response_future = stub.UnaryCall.future(request, 1) + response_future.cancel() + self.assertTrue(response_future.cancelled()) + + def testUnaryCallFutureFailed(self): + with _CreateService() as (methods, stub): + request = request_pb2.SimpleRequest(response_size=13) + with methods.fail(): + response_future = stub.UnaryCall.future( + request, test_constants.LONG_TIMEOUT) + self.assertIsNotNone(response_future.exception()) + + def testStreamingOutputCall(self): + with _CreateService() as (methods, stub): + request = _streaming_output_request() + responses = stub.StreamingOutputCall(request, + test_constants.LONG_TIMEOUT) + expected_responses = methods.StreamingOutputCall( + request, 'not a real RpcContext!') + for expected_response, response in moves.zip_longest( + expected_responses, responses): + self.assertEqual(expected_response, response) + + def testStreamingOutputCallExpired(self): + with _CreateService() as (methods, stub): + request = _streaming_output_request() + with methods.pause(): + responses = stub.StreamingOutputCall( + request, test_constants.SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + list(responses) + + def testStreamingOutputCallCancelled(self): + with _CreateService() as (methods, stub): + request = _streaming_output_request() + responses = stub.StreamingOutputCall(request, + test_constants.LONG_TIMEOUT) + next(responses) + responses.cancel() + with self.assertRaises(face.CancellationError): + next(responses) + + def testStreamingOutputCallFailed(self): + with _CreateService() as (methods, stub): + request = _streaming_output_request() + with methods.fail(): + responses = stub.StreamingOutputCall(request, 1) + self.assertIsNotNone(responses) + with self.assertRaises(face.RemoteError): + next(responses) + + def testStreamingInputCall(self): + with _CreateService() as (methods, stub): + response = stub.StreamingInputCall( + _streaming_input_request_iterator(), + test_constants.LONG_TIMEOUT) + expected_response = methods.StreamingInputCall( + _streaming_input_request_iterator(), 'not a real RpcContext!') self.assertEqual(expected_response, response) - def testHalfDuplexCallWedged(self): - condition = threading.Condition() - wait_cell = [False] - @contextlib.contextmanager - def wait(): # pylint: disable=invalid-name - # Where's Python 3's 'nonlocal' statement when you need it? - with condition: - wait_cell[0] = True - yield - with condition: - wait_cell[0] = False - condition.notify_all() - def half_duplex_request_iterator(): - request = request_pb2.StreamingOutputCallRequest() - request.response_parameters.add(size=1, interval_us=0) - yield request - with condition: - while wait_cell[0]: - condition.wait() - with _CreateService() as (methods, stub): - with wait(): - responses = stub.HalfDuplexCall( - half_duplex_request_iterator(), test_constants.SHORT_TIMEOUT) - # half-duplex waits for the client to send all info - with self.assertRaises(face.ExpirationError): - next(responses) + def testStreamingInputCallFuture(self): + with _CreateService() as (methods, stub): + with methods.pause(): + response_future = stub.StreamingInputCall.future( + _streaming_input_request_iterator(), + test_constants.LONG_TIMEOUT) + response = response_future.result() + expected_response = methods.StreamingInputCall( + _streaming_input_request_iterator(), 'not a real RpcContext!') + self.assertEqual(expected_response, response) + + def testStreamingInputCallFutureExpired(self): + with _CreateService() as (methods, stub): + with methods.pause(): + response_future = stub.StreamingInputCall.future( + _streaming_input_request_iterator(), + test_constants.SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + response_future.result() + self.assertIsInstance(response_future.exception(), + face.ExpirationError) + + def testStreamingInputCallFutureCancelled(self): + with _CreateService() as (methods, stub): + with methods.pause(): + response_future = stub.StreamingInputCall.future( + _streaming_input_request_iterator(), + test_constants.LONG_TIMEOUT) + response_future.cancel() + self.assertTrue(response_future.cancelled()) + with self.assertRaises(future.CancelledError): + response_future.result() + + def testStreamingInputCallFutureFailed(self): + with _CreateService() as (methods, stub): + with methods.fail(): + response_future = stub.StreamingInputCall.future( + _streaming_input_request_iterator(), + test_constants.LONG_TIMEOUT) + self.assertIsNotNone(response_future.exception()) + + def testFullDuplexCall(self): + with _CreateService() as (methods, stub): + responses = stub.FullDuplexCall(_full_duplex_request_iterator(), + test_constants.LONG_TIMEOUT) + expected_responses = methods.FullDuplexCall( + _full_duplex_request_iterator(), 'not a real RpcContext!') + for expected_response, response in moves.zip_longest( + expected_responses, responses): + self.assertEqual(expected_response, response) + + def testFullDuplexCallExpired(self): + request_iterator = _full_duplex_request_iterator() + with _CreateService() as (methods, stub): + with methods.pause(): + responses = stub.FullDuplexCall(request_iterator, + test_constants.SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + list(responses) + + def testFullDuplexCallCancelled(self): + with _CreateService() as (methods, stub): + request_iterator = _full_duplex_request_iterator() + responses = stub.FullDuplexCall(request_iterator, + test_constants.LONG_TIMEOUT) + next(responses) + responses.cancel() + with self.assertRaises(face.CancellationError): + next(responses) + + def testFullDuplexCallFailed(self): + request_iterator = _full_duplex_request_iterator() + with _CreateService() as (methods, stub): + with methods.fail(): + responses = stub.FullDuplexCall(request_iterator, + test_constants.LONG_TIMEOUT) + self.assertIsNotNone(responses) + with self.assertRaises(face.RemoteError): + next(responses) + + def testHalfDuplexCall(self): + with _CreateService() as (methods, stub): + + def half_duplex_request_iterator(): + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=2, interval_us=0) + request.response_parameters.add(size=3, interval_us=0) + yield request + + responses = stub.HalfDuplexCall(half_duplex_request_iterator(), + test_constants.LONG_TIMEOUT) + expected_responses = methods.HalfDuplexCall( + half_duplex_request_iterator(), 'not a real RpcContext!') + for check in moves.zip_longest(expected_responses, responses): + expected_response, response = check + self.assertEqual(expected_response, response) + + def testHalfDuplexCallWedged(self): + condition = threading.Condition() + wait_cell = [False] + + @contextlib.contextmanager + def wait(): # pylint: disable=invalid-name + # Where's Python 3's 'nonlocal' statement when you need it? + with condition: + wait_cell[0] = True + yield + with condition: + wait_cell[0] = False + condition.notify_all() + + def half_duplex_request_iterator(): + request = request_pb2.StreamingOutputCallRequest() + request.response_parameters.add(size=1, interval_us=0) + yield request + with condition: + while wait_cell[0]: + condition.wait() + + with _CreateService() as (methods, stub): + with wait(): + responses = stub.HalfDuplexCall(half_duplex_request_iterator(), + test_constants.SHORT_TIMEOUT) + # half-duplex waits for the client to send all info + with self.assertRaises(face.ExpirationError): + next(responses) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/__init__.py index 2f88fa04122..100a624dc9c 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_messages/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_messages/__init__.py index 2f88fa04122..100a624dc9c 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_messages/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_messages/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_services/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_services/__init__.py index 2f88fa04122..100a624dc9c 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_services/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/invocation_testing/split_services/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/payload/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/payload/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/payload/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/payload/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/r/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/r/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/r/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/requests/r/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/responses/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/responses/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/responses/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/responses/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/protoc_plugin/protos/service/__init__.py b/src/python/grpcio_tests/tests/protoc_plugin/protos/service/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/protoc_plugin/protos/service/__init__.py +++ b/src/python/grpcio_tests/tests/protoc_plugin/protos/service/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/qps/benchmark_client.py b/src/python/grpcio_tests/tests/qps/benchmark_client.py index 650e4756e72..2e8afc8e7f9 100644 --- a/src/python/grpcio_tests/tests/qps/benchmark_client.py +++ b/src/python/grpcio_tests/tests/qps/benchmark_client.py @@ -26,7 +26,6 @@ # 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. - """Defines test client behaviors (UNARY/STREAMING) (SYNC/ASYNC).""" import abc @@ -47,165 +46,168 @@ _TIMEOUT = 60 * 60 * 24 class GenericStub(object): - def __init__(self, channel): - self.UnaryCall = channel.unary_unary( - '/grpc.testing.BenchmarkService/UnaryCall') - self.StreamingCall = channel.stream_stream( - '/grpc.testing.BenchmarkService/StreamingCall') + def __init__(self, channel): + self.UnaryCall = channel.unary_unary( + '/grpc.testing.BenchmarkService/UnaryCall') + self.StreamingCall = channel.stream_stream( + '/grpc.testing.BenchmarkService/StreamingCall') class BenchmarkClient: - """Benchmark client interface that exposes a non-blocking send_request().""" - - __metaclass__ = abc.ABCMeta - - def __init__(self, server, config, hist): - # Create the stub - if config.HasField('security_params'): - creds = grpc.ssl_channel_credentials(resources.test_root_certificates()) - channel = test_common.test_secure_channel( - server, creds, config.security_params.server_host_override) - else: - channel = grpc.insecure_channel(server) - - # waits for the channel to be ready before we start sending messages - grpc.channel_ready_future(channel).result() - - if config.payload_config.WhichOneof('payload') == 'simple_params': - self._generic = False - self._stub = services_pb2.BenchmarkServiceStub(channel) - payload = messages_pb2.Payload( - body='\0' * config.payload_config.simple_params.req_size) - self._request = messages_pb2.SimpleRequest( - payload=payload, - response_size=config.payload_config.simple_params.resp_size) - else: - self._generic = True - self._stub = GenericStub(channel) - self._request = '\0' * config.payload_config.bytebuf_params.req_size - - self._hist = hist - self._response_callbacks = [] - - def add_response_callback(self, callback): - """callback will be invoked as callback(client, query_time)""" - self._response_callbacks.append(callback) - - @abc.abstractmethod - def send_request(self): - """Non-blocking wrapper for a client's request operation.""" - raise NotImplementedError() - - def start(self): - pass - - def stop(self): - pass - - def _handle_response(self, client, query_time): - self._hist.add(query_time * 1e9) # Report times in nanoseconds - for callback in self._response_callbacks: - callback(client, query_time) + """Benchmark client interface that exposes a non-blocking send_request().""" + + __metaclass__ = abc.ABCMeta + + def __init__(self, server, config, hist): + # Create the stub + if config.HasField('security_params'): + creds = grpc.ssl_channel_credentials( + resources.test_root_certificates()) + channel = test_common.test_secure_channel( + server, creds, config.security_params.server_host_override) + else: + channel = grpc.insecure_channel(server) + + # waits for the channel to be ready before we start sending messages + grpc.channel_ready_future(channel).result() + + if config.payload_config.WhichOneof('payload') == 'simple_params': + self._generic = False + self._stub = services_pb2.BenchmarkServiceStub(channel) + payload = messages_pb2.Payload( + body='\0' * config.payload_config.simple_params.req_size) + self._request = messages_pb2.SimpleRequest( + payload=payload, + response_size=config.payload_config.simple_params.resp_size) + else: + self._generic = True + self._stub = GenericStub(channel) + self._request = '\0' * config.payload_config.bytebuf_params.req_size + + self._hist = hist + self._response_callbacks = [] + + def add_response_callback(self, callback): + """callback will be invoked as callback(client, query_time)""" + self._response_callbacks.append(callback) + + @abc.abstractmethod + def send_request(self): + """Non-blocking wrapper for a client's request operation.""" + raise NotImplementedError() + + def start(self): + pass + + def stop(self): + pass + + def _handle_response(self, client, query_time): + self._hist.add(query_time * 1e9) # Report times in nanoseconds + for callback in self._response_callbacks: + callback(client, query_time) class UnarySyncBenchmarkClient(BenchmarkClient): - def __init__(self, server, config, hist): - super(UnarySyncBenchmarkClient, self).__init__(server, config, hist) - self._pool = futures.ThreadPoolExecutor( - max_workers=config.outstanding_rpcs_per_channel) + def __init__(self, server, config, hist): + super(UnarySyncBenchmarkClient, self).__init__(server, config, hist) + self._pool = futures.ThreadPoolExecutor( + max_workers=config.outstanding_rpcs_per_channel) - def send_request(self): - # Send requests in seperate threads to support multiple outstanding rpcs - # (See src/proto/grpc/testing/control.proto) - self._pool.submit(self._dispatch_request) + def send_request(self): + # Send requests in seperate threads to support multiple outstanding rpcs + # (See src/proto/grpc/testing/control.proto) + self._pool.submit(self._dispatch_request) - def stop(self): - self._pool.shutdown(wait=True) - self._stub = None + def stop(self): + self._pool.shutdown(wait=True) + self._stub = None - def _dispatch_request(self): - start_time = time.time() - self._stub.UnaryCall(self._request, _TIMEOUT) - end_time = time.time() - self._handle_response(self, end_time - start_time) + def _dispatch_request(self): + start_time = time.time() + self._stub.UnaryCall(self._request, _TIMEOUT) + end_time = time.time() + self._handle_response(self, end_time - start_time) class UnaryAsyncBenchmarkClient(BenchmarkClient): - def send_request(self): - # Use the Future callback api to support multiple outstanding rpcs - start_time = time.time() - response_future = self._stub.UnaryCall.future(self._request, _TIMEOUT) - response_future.add_done_callback( - lambda resp: self._response_received(start_time, resp)) + def send_request(self): + # Use the Future callback api to support multiple outstanding rpcs + start_time = time.time() + response_future = self._stub.UnaryCall.future(self._request, _TIMEOUT) + response_future.add_done_callback( + lambda resp: self._response_received(start_time, resp)) - def _response_received(self, start_time, resp): - resp.result() - end_time = time.time() - self._handle_response(self, end_time - start_time) + def _response_received(self, start_time, resp): + resp.result() + end_time = time.time() + self._handle_response(self, end_time - start_time) - def stop(self): - self._stub = None + def stop(self): + self._stub = None class _SyncStream(object): - def __init__(self, stub, generic, request, handle_response): - self._stub = stub - self._generic = generic - self._request = request - self._handle_response = handle_response - self._is_streaming = False - self._request_queue = queue.Queue() - self._send_time_queue = queue.Queue() - - def send_request(self): - self._send_time_queue.put(time.time()) - self._request_queue.put(self._request) - - def start(self): - self._is_streaming = True - response_stream = self._stub.StreamingCall( - self._request_generator(), _TIMEOUT) - for _ in response_stream: - self._handle_response( - self, time.time() - self._send_time_queue.get_nowait()) - - def stop(self): - self._is_streaming = False - - def _request_generator(self): - while self._is_streaming: - try: - request = self._request_queue.get(block=True, timeout=1.0) - yield request - except queue.Empty: - pass + def __init__(self, stub, generic, request, handle_response): + self._stub = stub + self._generic = generic + self._request = request + self._handle_response = handle_response + self._is_streaming = False + self._request_queue = queue.Queue() + self._send_time_queue = queue.Queue() + + def send_request(self): + self._send_time_queue.put(time.time()) + self._request_queue.put(self._request) + + def start(self): + self._is_streaming = True + response_stream = self._stub.StreamingCall(self._request_generator(), + _TIMEOUT) + for _ in response_stream: + self._handle_response( + self, time.time() - self._send_time_queue.get_nowait()) + + def stop(self): + self._is_streaming = False + + def _request_generator(self): + while self._is_streaming: + try: + request = self._request_queue.get(block=True, timeout=1.0) + yield request + except queue.Empty: + pass class StreamingSyncBenchmarkClient(BenchmarkClient): - def __init__(self, server, config, hist): - super(StreamingSyncBenchmarkClient, self).__init__(server, config, hist) - self._pool = futures.ThreadPoolExecutor( - max_workers=config.outstanding_rpcs_per_channel) - self._streams = [_SyncStream(self._stub, self._generic, - self._request, self._handle_response) - for _ in xrange(config.outstanding_rpcs_per_channel)] - self._curr_stream = 0 - - def send_request(self): - # Use a round_robin scheduler to determine what stream to send on - self._streams[self._curr_stream].send_request() - self._curr_stream = (self._curr_stream + 1) % len(self._streams) - - def start(self): - for stream in self._streams: - self._pool.submit(stream.start) - - def stop(self): - for stream in self._streams: - stream.stop() - self._pool.shutdown(wait=True) - self._stub = None + def __init__(self, server, config, hist): + super(StreamingSyncBenchmarkClient, self).__init__(server, config, hist) + self._pool = futures.ThreadPoolExecutor( + max_workers=config.outstanding_rpcs_per_channel) + self._streams = [ + _SyncStream(self._stub, self._generic, self._request, + self._handle_response) + for _ in xrange(config.outstanding_rpcs_per_channel) + ] + self._curr_stream = 0 + + def send_request(self): + # Use a round_robin scheduler to determine what stream to send on + self._streams[self._curr_stream].send_request() + self._curr_stream = (self._curr_stream + 1) % len(self._streams) + + def start(self): + for stream in self._streams: + self._pool.submit(stream.start) + + def stop(self): + for stream in self._streams: + stream.stop() + self._pool.shutdown(wait=True) + self._stub = None diff --git a/src/python/grpcio_tests/tests/qps/benchmark_server.py b/src/python/grpcio_tests/tests/qps/benchmark_server.py index 2b76b810cdd..423d03b8042 100644 --- a/src/python/grpcio_tests/tests/qps/benchmark_server.py +++ b/src/python/grpcio_tests/tests/qps/benchmark_server.py @@ -32,27 +32,27 @@ from src.proto.grpc.testing import services_pb2 class BenchmarkServer(services_pb2.BenchmarkServiceServicer): - """Synchronous Server implementation for the Benchmark service.""" + """Synchronous Server implementation for the Benchmark service.""" - def UnaryCall(self, request, context): - payload = messages_pb2.Payload(body='\0' * request.response_size) - return messages_pb2.SimpleResponse(payload=payload) + def UnaryCall(self, request, context): + payload = messages_pb2.Payload(body='\0' * request.response_size) + return messages_pb2.SimpleResponse(payload=payload) - def StreamingCall(self, request_iterator, context): - for request in request_iterator: - payload = messages_pb2.Payload(body='\0' * request.response_size) - yield messages_pb2.SimpleResponse(payload=payload) + def StreamingCall(self, request_iterator, context): + for request in request_iterator: + payload = messages_pb2.Payload(body='\0' * request.response_size) + yield messages_pb2.SimpleResponse(payload=payload) class GenericBenchmarkServer(services_pb2.BenchmarkServiceServicer): - """Generic Server implementation for the Benchmark service.""" + """Generic Server implementation for the Benchmark service.""" - def __init__(self, resp_size): - self._response = '\0' * resp_size + def __init__(self, resp_size): + self._response = '\0' * resp_size - def UnaryCall(self, request, context): - return self._response + def UnaryCall(self, request, context): + return self._response - def StreamingCall(self, request_iterator, context): - for request in request_iterator: - yield self._response + def StreamingCall(self, request_iterator, context): + for request in request_iterator: + yield self._response diff --git a/src/python/grpcio_tests/tests/qps/client_runner.py b/src/python/grpcio_tests/tests/qps/client_runner.py index 1fd58687ad4..037092313c1 100644 --- a/src/python/grpcio_tests/tests/qps/client_runner.py +++ b/src/python/grpcio_tests/tests/qps/client_runner.py @@ -26,7 +26,6 @@ # 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. - """Defines behavior for WHEN clients send requests. Each client exposes a non-blocking send_request() method that the @@ -39,68 +38,68 @@ import time class ClientRunner: - """Abstract interface for sending requests from clients.""" + """Abstract interface for sending requests from clients.""" - __metaclass__ = abc.ABCMeta + __metaclass__ = abc.ABCMeta - def __init__(self, client): - self._client = client + def __init__(self, client): + self._client = client - @abc.abstractmethod - def start(self): - raise NotImplementedError() + @abc.abstractmethod + def start(self): + raise NotImplementedError() - @abc.abstractmethod - def stop(self): - raise NotImplementedError() + @abc.abstractmethod + def stop(self): + raise NotImplementedError() class OpenLoopClientRunner(ClientRunner): - def __init__(self, client, interval_generator): - super(OpenLoopClientRunner, self).__init__(client) - self._is_running = False - self._interval_generator = interval_generator - self._dispatch_thread = threading.Thread( - target=self._dispatch_requests, args=()) - - def start(self): - self._is_running = True - self._client.start() - self._dispatch_thread.start() - - def stop(self): - self._is_running = False - self._client.stop() - self._dispatch_thread.join() - self._client = None - - def _dispatch_requests(self): - while self._is_running: - self._client.send_request() - time.sleep(next(self._interval_generator)) + def __init__(self, client, interval_generator): + super(OpenLoopClientRunner, self).__init__(client) + self._is_running = False + self._interval_generator = interval_generator + self._dispatch_thread = threading.Thread( + target=self._dispatch_requests, args=()) + + def start(self): + self._is_running = True + self._client.start() + self._dispatch_thread.start() + + def stop(self): + self._is_running = False + self._client.stop() + self._dispatch_thread.join() + self._client = None + + def _dispatch_requests(self): + while self._is_running: + self._client.send_request() + time.sleep(next(self._interval_generator)) class ClosedLoopClientRunner(ClientRunner): - def __init__(self, client, request_count): - super(ClosedLoopClientRunner, self).__init__(client) - self._is_running = False - self._request_count = request_count - # Send a new request on each response for closed loop - self._client.add_response_callback(self._send_request) - - def start(self): - self._is_running = True - self._client.start() - for _ in xrange(self._request_count): - self._client.send_request() - - def stop(self): - self._is_running = False - self._client.stop() - self._client = None - - def _send_request(self, client, response_time): - if self._is_running: - client.send_request() + def __init__(self, client, request_count): + super(ClosedLoopClientRunner, self).__init__(client) + self._is_running = False + self._request_count = request_count + # Send a new request on each response for closed loop + self._client.add_response_callback(self._send_request) + + def start(self): + self._is_running = True + self._client.start() + for _ in xrange(self._request_count): + self._client.send_request() + + def stop(self): + self._is_running = False + self._client.stop() + self._client = None + + def _send_request(self, client, response_time): + if self._is_running: + client.send_request() diff --git a/src/python/grpcio_tests/tests/qps/histogram.py b/src/python/grpcio_tests/tests/qps/histogram.py index 9a7b5eb2ba6..61040b6f3bf 100644 --- a/src/python/grpcio_tests/tests/qps/histogram.py +++ b/src/python/grpcio_tests/tests/qps/histogram.py @@ -34,52 +34,52 @@ from src.proto.grpc.testing import stats_pb2 class Histogram(object): - """Histogram class used for recording performance testing data. + """Histogram class used for recording performance testing data. This class is thread safe. """ - def __init__(self, resolution, max_possible): - self._lock = threading.Lock() - self._resolution = resolution - self._max_possible = max_possible - self._sum = 0 - self._sum_of_squares = 0 - self.multiplier = 1.0 + self._resolution - self._count = 0 - self._min = self._max_possible - self._max = 0 - self._buckets = [0] * (self._bucket_for(self._max_possible) + 1) + def __init__(self, resolution, max_possible): + self._lock = threading.Lock() + self._resolution = resolution + self._max_possible = max_possible + self._sum = 0 + self._sum_of_squares = 0 + self.multiplier = 1.0 + self._resolution + self._count = 0 + self._min = self._max_possible + self._max = 0 + self._buckets = [0] * (self._bucket_for(self._max_possible) + 1) - def reset(self): - with self._lock: - self._sum = 0 - self._sum_of_squares = 0 - self._count = 0 - self._min = self._max_possible - self._max = 0 - self._buckets = [0] * (self._bucket_for(self._max_possible) + 1) + def reset(self): + with self._lock: + self._sum = 0 + self._sum_of_squares = 0 + self._count = 0 + self._min = self._max_possible + self._max = 0 + self._buckets = [0] * (self._bucket_for(self._max_possible) + 1) - def add(self, val): - with self._lock: - self._sum += val - self._sum_of_squares += val * val - self._count += 1 - self._min = min(self._min, val) - self._max = max(self._max, val) - self._buckets[self._bucket_for(val)] += 1 + def add(self, val): + with self._lock: + self._sum += val + self._sum_of_squares += val * val + self._count += 1 + self._min = min(self._min, val) + self._max = max(self._max, val) + self._buckets[self._bucket_for(val)] += 1 - def get_data(self): - with self._lock: - data = stats_pb2.HistogramData() - data.bucket.extend(self._buckets) - data.min_seen = self._min - data.max_seen = self._max - data.sum = self._sum - data.sum_of_squares = self._sum_of_squares - data.count = self._count - return data + def get_data(self): + with self._lock: + data = stats_pb2.HistogramData() + data.bucket.extend(self._buckets) + data.min_seen = self._min + data.max_seen = self._max + data.sum = self._sum + data.sum_of_squares = self._sum_of_squares + data.count = self._count + return data - def _bucket_for(self, val): - val = min(val, self._max_possible) - return int(math.log(val, self.multiplier)) + def _bucket_for(self, val): + val = min(val, self._max_possible) + return int(math.log(val, self.multiplier)) diff --git a/src/python/grpcio_tests/tests/qps/qps_worker.py b/src/python/grpcio_tests/tests/qps/qps_worker.py index 2371ff09562..025dfb9d4a7 100644 --- a/src/python/grpcio_tests/tests/qps/qps_worker.py +++ b/src/python/grpcio_tests/tests/qps/qps_worker.py @@ -26,7 +26,6 @@ # 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. - """The entry point for the qps worker.""" import argparse @@ -40,22 +39,23 @@ from tests.qps import worker_server def run_worker_server(port): - server = grpc.server(futures.ThreadPoolExecutor(max_workers=5)) - servicer = worker_server.WorkerServer() - services_pb2.add_WorkerServiceServicer_to_server(servicer, server) - server.add_insecure_port('[::]:{}'.format(port)) - server.start() - servicer.wait_for_quit() - server.stop(0) + server = grpc.server(futures.ThreadPoolExecutor(max_workers=5)) + servicer = worker_server.WorkerServer() + services_pb2.add_WorkerServiceServicer_to_server(servicer, server) + server.add_insecure_port('[::]:{}'.format(port)) + server.start() + servicer.wait_for_quit() + server.stop(0) if __name__ == '__main__': - parser = argparse.ArgumentParser( - description='gRPC Python performance testing worker') - parser.add_argument('--driver_port', - type=int, - dest='port', - help='The port the worker should listen on') - args = parser.parse_args() - - run_worker_server(args.port) + parser = argparse.ArgumentParser( + description='gRPC Python performance testing worker') + parser.add_argument( + '--driver_port', + type=int, + dest='port', + help='The port the worker should listen on') + args = parser.parse_args() + + run_worker_server(args.port) diff --git a/src/python/grpcio_tests/tests/qps/worker_server.py b/src/python/grpcio_tests/tests/qps/worker_server.py index 46d542940f1..1deb7ed698c 100644 --- a/src/python/grpcio_tests/tests/qps/worker_server.py +++ b/src/python/grpcio_tests/tests/qps/worker_server.py @@ -46,149 +46,156 @@ from tests.unit import resources class WorkerServer(services_pb2.WorkerServiceServicer): - """Python Worker Server implementation.""" - - def __init__(self): - self._quit_event = threading.Event() - - def RunServer(self, request_iterator, context): - config = next(request_iterator).setup - server, port = self._create_server(config) - cores = multiprocessing.cpu_count() - server.start() - start_time = time.time() - yield self._get_server_status(start_time, start_time, port, cores) - - for request in request_iterator: - end_time = time.time() - status = self._get_server_status(start_time, end_time, port, cores) - if request.mark.reset: - start_time = end_time - yield status - server.stop(None) - - def _get_server_status(self, start_time, end_time, port, cores): - end_time = time.time() - elapsed_time = end_time - start_time - stats = stats_pb2.ServerStats(time_elapsed=elapsed_time, - time_user=elapsed_time, - time_system=elapsed_time) - return control_pb2.ServerStatus(stats=stats, port=port, cores=cores) - - def _create_server(self, config): - if config.async_server_threads == 0: - # This is the default concurrent.futures thread pool size, but - # None doesn't seem to work - server_threads = multiprocessing.cpu_count() * 5 - else: - server_threads = config.async_server_threads - server = grpc.server(futures.ThreadPoolExecutor( - max_workers=server_threads)) - if config.server_type == control_pb2.ASYNC_SERVER: - servicer = benchmark_server.BenchmarkServer() - services_pb2.add_BenchmarkServiceServicer_to_server(servicer, server) - elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER: - resp_size = config.payload_config.bytebuf_params.resp_size - servicer = benchmark_server.GenericBenchmarkServer(resp_size) - method_implementations = { - 'StreamingCall': - grpc.stream_stream_rpc_method_handler(servicer.StreamingCall), - 'UnaryCall': - grpc.unary_unary_rpc_method_handler(servicer.UnaryCall), - } - handler = grpc.method_handlers_generic_handler( - 'grpc.testing.BenchmarkService', method_implementations) - server.add_generic_rpc_handlers((handler,)) - else: - raise Exception('Unsupported server type {}'.format(config.server_type)) - - if config.HasField('security_params'): # Use SSL - server_creds = grpc.ssl_server_credentials( - ((resources.private_key(), resources.certificate_chain()),)) - port = server.add_secure_port('[::]:{}'.format(config.port), server_creds) - else: - port = server.add_insecure_port('[::]:{}'.format(config.port)) - - return (server, port) - - def RunClient(self, request_iterator, context): - config = next(request_iterator).setup - client_runners = [] - qps_data = histogram.Histogram(config.histogram_params.resolution, - config.histogram_params.max_possible) - start_time = time.time() - - # Create a client for each channel - for i in xrange(config.client_channels): - server = config.server_targets[i % len(config.server_targets)] - runner = self._create_client_runner(server, config, qps_data) - client_runners.append(runner) - runner.start() - - end_time = time.time() - yield self._get_client_status(start_time, end_time, qps_data) - - # Respond to stat requests - for request in request_iterator: - end_time = time.time() - status = self._get_client_status(start_time, end_time, qps_data) - if request.mark.reset: - qps_data.reset() + """Python Worker Server implementation.""" + + def __init__(self): + self._quit_event = threading.Event() + + def RunServer(self, request_iterator, context): + config = next(request_iterator).setup + server, port = self._create_server(config) + cores = multiprocessing.cpu_count() + server.start() start_time = time.time() - yield status - - # Cleanup the clients - for runner in client_runners: - runner.stop() - - def _get_client_status(self, start_time, end_time, qps_data): - latencies = qps_data.get_data() - end_time = time.time() - elapsed_time = end_time - start_time - stats = stats_pb2.ClientStats(latencies=latencies, - time_elapsed=elapsed_time, - time_user=elapsed_time, - time_system=elapsed_time) - return control_pb2.ClientStatus(stats=stats) - - def _create_client_runner(self, server, config, qps_data): - if config.client_type == control_pb2.SYNC_CLIENT: - if config.rpc_type == control_pb2.UNARY: - client = benchmark_client.UnarySyncBenchmarkClient( - server, config, qps_data) - elif config.rpc_type == control_pb2.STREAMING: - client = benchmark_client.StreamingSyncBenchmarkClient( - server, config, qps_data) - elif config.client_type == control_pb2.ASYNC_CLIENT: - if config.rpc_type == control_pb2.UNARY: - client = benchmark_client.UnaryAsyncBenchmarkClient( - server, config, qps_data) - else: - raise Exception('Async streaming client not supported') - else: - raise Exception('Unsupported client type {}'.format(config.client_type)) - - # In multi-channel tests, we split the load across all channels - load_factor = float(config.client_channels) - if config.load_params.WhichOneof('load') == 'closed_loop': - runner = client_runner.ClosedLoopClientRunner( - client, config.outstanding_rpcs_per_channel) - else: # Open loop Poisson - alpha = config.load_params.poisson.offered_load / load_factor - def poisson(): - while True: - yield random.expovariate(alpha) - - runner = client_runner.OpenLoopClientRunner(client, poisson()) - - return runner - - def CoreCount(self, request, context): - return control_pb2.CoreResponse(cores=multiprocessing.cpu_count()) - - def QuitWorker(self, request, context): - self._quit_event.set() - return control_pb2.Void() - - def wait_for_quit(self): - self._quit_event.wait() + yield self._get_server_status(start_time, start_time, port, cores) + + for request in request_iterator: + end_time = time.time() + status = self._get_server_status(start_time, end_time, port, cores) + if request.mark.reset: + start_time = end_time + yield status + server.stop(None) + + def _get_server_status(self, start_time, end_time, port, cores): + end_time = time.time() + elapsed_time = end_time - start_time + stats = stats_pb2.ServerStats( + time_elapsed=elapsed_time, + time_user=elapsed_time, + time_system=elapsed_time) + return control_pb2.ServerStatus(stats=stats, port=port, cores=cores) + + def _create_server(self, config): + if config.async_server_threads == 0: + # This is the default concurrent.futures thread pool size, but + # None doesn't seem to work + server_threads = multiprocessing.cpu_count() * 5 + else: + server_threads = config.async_server_threads + server = grpc.server( + futures.ThreadPoolExecutor(max_workers=server_threads)) + if config.server_type == control_pb2.ASYNC_SERVER: + servicer = benchmark_server.BenchmarkServer() + services_pb2.add_BenchmarkServiceServicer_to_server(servicer, + server) + elif config.server_type == control_pb2.ASYNC_GENERIC_SERVER: + resp_size = config.payload_config.bytebuf_params.resp_size + servicer = benchmark_server.GenericBenchmarkServer(resp_size) + method_implementations = { + 'StreamingCall': + grpc.stream_stream_rpc_method_handler(servicer.StreamingCall), + 'UnaryCall': + grpc.unary_unary_rpc_method_handler(servicer.UnaryCall), + } + handler = grpc.method_handlers_generic_handler( + 'grpc.testing.BenchmarkService', method_implementations) + server.add_generic_rpc_handlers((handler,)) + else: + raise Exception('Unsupported server type {}'.format( + config.server_type)) + + if config.HasField('security_params'): # Use SSL + server_creds = grpc.ssl_server_credentials(( + (resources.private_key(), resources.certificate_chain()),)) + port = server.add_secure_port('[::]:{}'.format(config.port), + server_creds) + else: + port = server.add_insecure_port('[::]:{}'.format(config.port)) + + return (server, port) + + def RunClient(self, request_iterator, context): + config = next(request_iterator).setup + client_runners = [] + qps_data = histogram.Histogram(config.histogram_params.resolution, + config.histogram_params.max_possible) + start_time = time.time() + + # Create a client for each channel + for i in xrange(config.client_channels): + server = config.server_targets[i % len(config.server_targets)] + runner = self._create_client_runner(server, config, qps_data) + client_runners.append(runner) + runner.start() + + end_time = time.time() + yield self._get_client_status(start_time, end_time, qps_data) + + # Respond to stat requests + for request in request_iterator: + end_time = time.time() + status = self._get_client_status(start_time, end_time, qps_data) + if request.mark.reset: + qps_data.reset() + start_time = time.time() + yield status + + # Cleanup the clients + for runner in client_runners: + runner.stop() + + def _get_client_status(self, start_time, end_time, qps_data): + latencies = qps_data.get_data() + end_time = time.time() + elapsed_time = end_time - start_time + stats = stats_pb2.ClientStats( + latencies=latencies, + time_elapsed=elapsed_time, + time_user=elapsed_time, + time_system=elapsed_time) + return control_pb2.ClientStatus(stats=stats) + + def _create_client_runner(self, server, config, qps_data): + if config.client_type == control_pb2.SYNC_CLIENT: + if config.rpc_type == control_pb2.UNARY: + client = benchmark_client.UnarySyncBenchmarkClient( + server, config, qps_data) + elif config.rpc_type == control_pb2.STREAMING: + client = benchmark_client.StreamingSyncBenchmarkClient( + server, config, qps_data) + elif config.client_type == control_pb2.ASYNC_CLIENT: + if config.rpc_type == control_pb2.UNARY: + client = benchmark_client.UnaryAsyncBenchmarkClient( + server, config, qps_data) + else: + raise Exception('Async streaming client not supported') + else: + raise Exception('Unsupported client type {}'.format( + config.client_type)) + + # In multi-channel tests, we split the load across all channels + load_factor = float(config.client_channels) + if config.load_params.WhichOneof('load') == 'closed_loop': + runner = client_runner.ClosedLoopClientRunner( + client, config.outstanding_rpcs_per_channel) + else: # Open loop Poisson + alpha = config.load_params.poisson.offered_load / load_factor + + def poisson(): + while True: + yield random.expovariate(alpha) + + runner = client_runner.OpenLoopClientRunner(client, poisson()) + + return runner + + def CoreCount(self, request, context): + return control_pb2.CoreResponse(cores=multiprocessing.cpu_count()) + + def QuitWorker(self, request, context): + self._quit_event.set() + return control_pb2.Void() + + def wait_for_quit(self): + self._quit_event.wait() diff --git a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py index 43d6c971b52..76e89ca039f 100644 --- a/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py +++ b/src/python/grpcio_tests/tests/reflection/_reflection_servicer_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc_reflection.v1alpha.reflection.""" import unittest @@ -45,141 +44,112 @@ from tests.unit.framework.common import test_constants _EMPTY_PROTO_FILE_NAME = 'src/proto/grpc/testing/empty.proto' _EMPTY_PROTO_SYMBOL_NAME = 'grpc.testing.Empty' -_SERVICE_NAMES = ( - 'Angstrom', 'Bohr', 'Curie', 'Dyson', 'Einstein', 'Feynman', 'Galilei') +_SERVICE_NAMES = ('Angstrom', 'Bohr', 'Curie', 'Dyson', 'Einstein', 'Feynman', + 'Galilei') + def _file_descriptor_to_proto(descriptor): - proto = descriptor_pb2.FileDescriptorProto() - descriptor.CopyToProto(proto) - return proto.SerializeToString() + proto = descriptor_pb2.FileDescriptorProto() + descriptor.CopyToProto(proto) + return proto.SerializeToString() + class ReflectionServicerTest(unittest.TestCase): - def setUp(self): - servicer = reflection.ReflectionServicer(service_names=_SERVICE_NAMES) - server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server(server_pool) - port = self._server.add_insecure_port('[::]:0') - reflection_pb2.add_ServerReflectionServicer_to_server(servicer, self._server) - self._server.start() - - channel = grpc.insecure_channel('localhost:%d' % port) - self._stub = reflection_pb2.ServerReflectionStub(channel) - - def testFileByName(self): - requests = ( - reflection_pb2.ServerReflectionRequest( - file_by_filename=_EMPTY_PROTO_FILE_NAME - ), - reflection_pb2.ServerReflectionRequest( - file_by_filename='i-donut-exist' - ), - ) - responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) - expected_responses = ( - reflection_pb2.ServerReflectionResponse( - valid_host='', - file_descriptor_response=reflection_pb2.FileDescriptorResponse( - file_descriptor_proto=( - _file_descriptor_to_proto(empty_pb2.DESCRIPTOR), - ) - ) - ), - reflection_pb2.ServerReflectionResponse( - valid_host='', - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.NOT_FOUND.value[0], - error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - ) - ), - ) - self.assertSequenceEqual(expected_responses, responses) - - def testFileBySymbol(self): - requests = ( - reflection_pb2.ServerReflectionRequest( - file_containing_symbol=_EMPTY_PROTO_SYMBOL_NAME - ), - reflection_pb2.ServerReflectionRequest( - file_containing_symbol='i.donut.exist.co.uk.org.net.me.name.foo' - ), - ) - responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) - expected_responses = ( - reflection_pb2.ServerReflectionResponse( - valid_host='', - file_descriptor_response=reflection_pb2.FileDescriptorResponse( - file_descriptor_proto=( - _file_descriptor_to_proto(empty_pb2.DESCRIPTOR), - ) - ) - ), - reflection_pb2.ServerReflectionResponse( - valid_host='', - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.NOT_FOUND.value[0], - error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - ) - ), - ) - self.assertSequenceEqual(expected_responses, responses) - - @unittest.skip('TODO(atash): implement file-containing-extension reflection ' - '(see https://github.com/google/protobuf/issues/2248)') - def testFileContainingExtension(self): - requests = ( - reflection_pb2.ServerReflectionRequest( - file_containing_extension=reflection_pb2.ExtensionRequest( - containing_type='grpc.testing.proto2.Empty', - extension_number=125, - ), - ), - reflection_pb2.ServerReflectionRequest( - file_containing_extension=reflection_pb2.ExtensionRequest( - containing_type='i.donut.exist.co.uk.org.net.me.name.foo', - extension_number=55, - ), - ), - ) - responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) - expected_responses = ( - reflection_pb2.ServerReflectionResponse( - valid_host='', - file_descriptor_response=reflection_pb2.FileDescriptorResponse( - file_descriptor_proto=( - _file_descriptor_to_proto(empty_extensions_pb2.DESCRIPTOR), - ) - ) - ), - reflection_pb2.ServerReflectionResponse( - valid_host='', - error_response=reflection_pb2.ErrorResponse( - error_code=grpc.StatusCode.NOT_FOUND.value[0], - error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), - ) - ), - ) - self.assertSequenceEqual(expected_responses, responses) - - def testListServices(self): - requests = ( - reflection_pb2.ServerReflectionRequest( - list_services='', - ), - ) - responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) - expected_responses = ( - reflection_pb2.ServerReflectionResponse( - valid_host='', - list_services_response=reflection_pb2.ListServiceResponse( - service=tuple( - reflection_pb2.ServiceResponse(name=name) - for name in _SERVICE_NAMES - ) - ) - ), - ) - self.assertSequenceEqual(expected_responses, responses) + def setUp(self): + servicer = reflection.ReflectionServicer(service_names=_SERVICE_NAMES) + server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server(server_pool) + port = self._server.add_insecure_port('[::]:0') + reflection_pb2.add_ServerReflectionServicer_to_server(servicer, + self._server) + self._server.start() + + channel = grpc.insecure_channel('localhost:%d' % port) + self._stub = reflection_pb2.ServerReflectionStub(channel) + + def testFileByName(self): + requests = ( + reflection_pb2.ServerReflectionRequest( + file_by_filename=_EMPTY_PROTO_FILE_NAME), + reflection_pb2.ServerReflectionRequest( + file_by_filename='i-donut-exist'),) + responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) + expected_responses = ( + reflection_pb2.ServerReflectionResponse( + valid_host='', + file_descriptor_response=reflection_pb2.FileDescriptorResponse( + file_descriptor_proto=( + _file_descriptor_to_proto(empty_pb2.DESCRIPTOR),))), + reflection_pb2.ServerReflectionResponse( + valid_host='', + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.NOT_FOUND.value[0], + error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), + )),) + self.assertSequenceEqual(expected_responses, responses) + + def testFileBySymbol(self): + requests = ( + reflection_pb2.ServerReflectionRequest( + file_containing_symbol=_EMPTY_PROTO_SYMBOL_NAME), + reflection_pb2.ServerReflectionRequest( + file_containing_symbol='i.donut.exist.co.uk.org.net.me.name.foo' + ),) + responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) + expected_responses = ( + reflection_pb2.ServerReflectionResponse( + valid_host='', + file_descriptor_response=reflection_pb2.FileDescriptorResponse( + file_descriptor_proto=( + _file_descriptor_to_proto(empty_pb2.DESCRIPTOR),))), + reflection_pb2.ServerReflectionResponse( + valid_host='', + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.NOT_FOUND.value[0], + error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), + )),) + self.assertSequenceEqual(expected_responses, responses) + + @unittest.skip( + 'TODO(atash): implement file-containing-extension reflection ' + '(see https://github.com/google/protobuf/issues/2248)') + def testFileContainingExtension(self): + requests = ( + reflection_pb2.ServerReflectionRequest( + file_containing_extension=reflection_pb2.ExtensionRequest( + containing_type='grpc.testing.proto2.Empty', + extension_number=125,),), + reflection_pb2.ServerReflectionRequest( + file_containing_extension=reflection_pb2.ExtensionRequest( + containing_type='i.donut.exist.co.uk.org.net.me.name.foo', + extension_number=55,),),) + responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) + expected_responses = ( + reflection_pb2.ServerReflectionResponse( + valid_host='', + file_descriptor_response=reflection_pb2.FileDescriptorResponse( + file_descriptor_proto=(_file_descriptor_to_proto( + empty_extensions_pb2.DESCRIPTOR),))), + reflection_pb2.ServerReflectionResponse( + valid_host='', + error_response=reflection_pb2.ErrorResponse( + error_code=grpc.StatusCode.NOT_FOUND.value[0], + error_message=grpc.StatusCode.NOT_FOUND.value[1].encode(), + )),) + self.assertSequenceEqual(expected_responses, responses) + + def testListServices(self): + requests = (reflection_pb2.ServerReflectionRequest(list_services='',),) + responses = tuple(self._stub.ServerReflectionInfo(iter(requests))) + expected_responses = (reflection_pb2.ServerReflectionResponse( + valid_host='', + list_services_response=reflection_pb2.ListServiceResponse( + service=tuple( + reflection_pb2.ServiceResponse(name=name) + for name in _SERVICE_NAMES))),) + self.assertSequenceEqual(expected_responses, responses) + if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/stress/client.py b/src/python/grpcio_tests/tests/stress/client.py index b8116729b57..61f9e1c6b17 100644 --- a/src/python/grpcio_tests/tests/stress/client.py +++ b/src/python/grpcio_tests/tests/stress/client.py @@ -26,7 +26,6 @@ # 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. - """Entry point for running stress tests.""" import argparse @@ -46,118 +45,132 @@ from tests.stress import test_runner def _args(): - parser = argparse.ArgumentParser(description='gRPC Python stress test client') - parser.add_argument( - '--server_addresses', - help='comma seperated list of hostname:port to run servers on', - default='localhost:8080', type=str) - parser.add_argument( - '--test_cases', - help='comma seperated list of testcase:weighting of tests to run', - default='large_unary:100', - type=str) - parser.add_argument( - '--test_duration_secs', - help='number of seconds to run the stress test', - default=-1, type=int) - parser.add_argument( - '--num_channels_per_server', - help='number of channels per server', - default=1, type=int) - parser.add_argument( - '--num_stubs_per_channel', - help='number of stubs to create per channel', - default=1, type=int) - parser.add_argument( - '--metrics_port', - help='the port to listen for metrics requests on', - default=8081, type=int) - parser.add_argument( - '--use_test_ca', - help='Whether to use our fake CA. Requires --use_tls=true', - default=False, type=bool) - parser.add_argument( - '--use_tls', - help='Whether to use TLS', default=False, type=bool) - parser.add_argument( - '--server_host_override', default="foo.test.google.fr", - help='the server host to which to claim to connect', type=str) - return parser.parse_args() + parser = argparse.ArgumentParser( + description='gRPC Python stress test client') + parser.add_argument( + '--server_addresses', + help='comma seperated list of hostname:port to run servers on', + default='localhost:8080', + type=str) + parser.add_argument( + '--test_cases', + help='comma seperated list of testcase:weighting of tests to run', + default='large_unary:100', + type=str) + parser.add_argument( + '--test_duration_secs', + help='number of seconds to run the stress test', + default=-1, + type=int) + parser.add_argument( + '--num_channels_per_server', + help='number of channels per server', + default=1, + type=int) + parser.add_argument( + '--num_stubs_per_channel', + help='number of stubs to create per channel', + default=1, + type=int) + parser.add_argument( + '--metrics_port', + help='the port to listen for metrics requests on', + default=8081, + type=int) + parser.add_argument( + '--use_test_ca', + help='Whether to use our fake CA. Requires --use_tls=true', + default=False, + type=bool) + parser.add_argument( + '--use_tls', help='Whether to use TLS', default=False, type=bool) + parser.add_argument( + '--server_host_override', + default="foo.test.google.fr", + help='the server host to which to claim to connect', + type=str) + return parser.parse_args() def _test_case_from_arg(test_case_arg): - for test_case in methods.TestCase: - if test_case_arg == test_case.value: - return test_case - else: - raise ValueError('No test case {}!'.format(test_case_arg)) + for test_case in methods.TestCase: + if test_case_arg == test_case.value: + return test_case + else: + raise ValueError('No test case {}!'.format(test_case_arg)) def _parse_weighted_test_cases(test_case_args): - weighted_test_cases = {} - for test_case_arg in test_case_args.split(','): - name, weight = test_case_arg.split(':', 1) - test_case = _test_case_from_arg(name) - weighted_test_cases[test_case] = int(weight) - return weighted_test_cases + weighted_test_cases = {} + for test_case_arg in test_case_args.split(','): + name, weight = test_case_arg.split(':', 1) + test_case = _test_case_from_arg(name) + weighted_test_cases[test_case] = int(weight) + return weighted_test_cases + def _get_channel(target, args): - if args.use_tls: - if args.use_test_ca: - root_certificates = resources.test_root_certificates() + if args.use_tls: + if args.use_test_ca: + root_certificates = resources.test_root_certificates() + else: + root_certificates = None # will load default roots. + channel_credentials = grpc.ssl_channel_credentials( + root_certificates=root_certificates) + options = (( + 'grpc.ssl_target_name_override', + args.server_host_override,),) + channel = grpc.secure_channel( + target, channel_credentials, options=options) else: - root_certificates = None # will load default roots. - channel_credentials = grpc.ssl_channel_credentials( - root_certificates=root_certificates) - options = (('grpc.ssl_target_name_override', args.server_host_override,),) - channel = grpc.secure_channel(target, channel_credentials, options=options) - else: - channel = grpc.insecure_channel(target) - - # waits for the channel to be ready before we start sending messages - grpc.channel_ready_future(channel).result() - return channel + channel = grpc.insecure_channel(target) + + # waits for the channel to be ready before we start sending messages + grpc.channel_ready_future(channel).result() + return channel + def run_test(args): - test_cases = _parse_weighted_test_cases(args.test_cases) - test_server_targets = args.server_addresses.split(',') - # Propagate any client exceptions with a queue - exception_queue = queue.Queue() - stop_event = threading.Event() - hist = histogram.Histogram(1, 1) - runners = [] - - server = grpc.server(futures.ThreadPoolExecutor(max_workers=25)) - metrics_pb2.add_MetricsServiceServicer_to_server( - metrics_server.MetricsServer(hist), server) - server.add_insecure_port('[::]:{}'.format(args.metrics_port)) - server.start() - - for test_server_target in test_server_targets: - for _ in xrange(args.num_channels_per_server): - channel = _get_channel(test_server_target, args) - for _ in xrange(args.num_stubs_per_channel): - stub = test_pb2.TestServiceStub(channel) - runner = test_runner.TestRunner(stub, test_cases, hist, - exception_queue, stop_event) - runners.append(runner) - - for runner in runners: - runner.start() - try: - timeout_secs = args.test_duration_secs - if timeout_secs < 0: - timeout_secs = None - raise exception_queue.get(block=True, timeout=timeout_secs) - except queue.Empty: - # No exceptions thrown, success - pass - finally: - stop_event.set() + test_cases = _parse_weighted_test_cases(args.test_cases) + test_server_targets = args.server_addresses.split(',') + # Propagate any client exceptions with a queue + exception_queue = queue.Queue() + stop_event = threading.Event() + hist = histogram.Histogram(1, 1) + runners = [] + + server = grpc.server(futures.ThreadPoolExecutor(max_workers=25)) + metrics_pb2.add_MetricsServiceServicer_to_server( + metrics_server.MetricsServer(hist), server) + server.add_insecure_port('[::]:{}'.format(args.metrics_port)) + server.start() + + for test_server_target in test_server_targets: + for _ in xrange(args.num_channels_per_server): + channel = _get_channel(test_server_target, args) + for _ in xrange(args.num_stubs_per_channel): + stub = test_pb2.TestServiceStub(channel) + runner = test_runner.TestRunner(stub, test_cases, hist, + exception_queue, stop_event) + runners.append(runner) + for runner in runners: - runner.join() - runner = None - server.stop(None) + runner.start() + try: + timeout_secs = args.test_duration_secs + if timeout_secs < 0: + timeout_secs = None + raise exception_queue.get(block=True, timeout=timeout_secs) + except queue.Empty: + # No exceptions thrown, success + pass + finally: + stop_event.set() + for runner in runners: + runner.join() + runner = None + server.stop(None) + if __name__ == '__main__': - run_test(_args()) + run_test(_args()) diff --git a/src/python/grpcio_tests/tests/stress/metrics_server.py b/src/python/grpcio_tests/tests/stress/metrics_server.py index 33dd1d6f2ad..3a4cbc27ba3 100644 --- a/src/python/grpcio_tests/tests/stress/metrics_server.py +++ b/src/python/grpcio_tests/tests/stress/metrics_server.py @@ -26,7 +26,6 @@ # 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. - """MetricsService for publishing stress test qps data.""" import time @@ -38,23 +37,23 @@ GAUGE_NAME = 'python_overall_qps' class MetricsServer(metrics_pb2.MetricsServiceServicer): - def __init__(self, histogram): - self._start_time = time.time() - self._histogram = histogram - - def _get_qps(self): - count = self._histogram.get_data().count - delta = time.time() - self._start_time - self._histogram.reset() - self._start_time = time.time() - return int(count/delta) - - def GetAllGauges(self, request, context): - qps = self._get_qps() - return [metrics_pb2.GaugeResponse(name=GAUGE_NAME, long_value=qps)] - - def GetGauge(self, request, context): - if request.name != GAUGE_NAME: - raise Exception('Gauge {} does not exist'.format(request.name)) - qps = self._get_qps() - return metrics_pb2.GaugeResponse(name=GAUGE_NAME, long_value=qps) + def __init__(self, histogram): + self._start_time = time.time() + self._histogram = histogram + + def _get_qps(self): + count = self._histogram.get_data().count + delta = time.time() - self._start_time + self._histogram.reset() + self._start_time = time.time() + return int(count / delta) + + def GetAllGauges(self, request, context): + qps = self._get_qps() + return [metrics_pb2.GaugeResponse(name=GAUGE_NAME, long_value=qps)] + + def GetGauge(self, request, context): + if request.name != GAUGE_NAME: + raise Exception('Gauge {} does not exist'.format(request.name)) + qps = self._get_qps() + return metrics_pb2.GaugeResponse(name=GAUGE_NAME, long_value=qps) diff --git a/src/python/grpcio_tests/tests/stress/test_runner.py b/src/python/grpcio_tests/tests/stress/test_runner.py index 88f13727e37..258abe9c217 100644 --- a/src/python/grpcio_tests/tests/stress/test_runner.py +++ b/src/python/grpcio_tests/tests/stress/test_runner.py @@ -26,7 +26,6 @@ # 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. - """Thread that sends random weighted requests on a TestService stub.""" import random @@ -36,38 +35,38 @@ import traceback def _weighted_test_case_generator(weighted_cases): - weight_sum = sum(weighted_cases.itervalues()) + weight_sum = sum(weighted_cases.itervalues()) - while True: - val = random.uniform(0, weight_sum) - partial_sum = 0 - for case in weighted_cases: - partial_sum += weighted_cases[case] - if val <= partial_sum: - yield case - break + while True: + val = random.uniform(0, weight_sum) + partial_sum = 0 + for case in weighted_cases: + partial_sum += weighted_cases[case] + if val <= partial_sum: + yield case + break class TestRunner(threading.Thread): - def __init__(self, stub, test_cases, hist, exception_queue, stop_event): - super(TestRunner, self).__init__() - self._exception_queue = exception_queue - self._stop_event = stop_event - self._stub = stub - self._test_cases = _weighted_test_case_generator(test_cases) - self._histogram = hist + def __init__(self, stub, test_cases, hist, exception_queue, stop_event): + super(TestRunner, self).__init__() + self._exception_queue = exception_queue + self._stop_event = stop_event + self._stub = stub + self._test_cases = _weighted_test_case_generator(test_cases) + self._histogram = hist - def run(self): - while not self._stop_event.is_set(): - try: - test_case = next(self._test_cases) - start_time = time.time() - test_case.test_interoperability(self._stub, None) - end_time = time.time() - self._histogram.add((end_time - start_time)*1e9) - except Exception as e: - traceback.print_exc() - self._exception_queue.put( - Exception("An exception occured during test {}" - .format(test_case), e)) + def run(self): + while not self._stop_event.is_set(): + try: + test_case = next(self._test_cases) + start_time = time.time() + test_case.test_interoperability(self._stub, None) + end_time = time.time() + self._histogram.add((end_time - start_time) * 1e9) + except Exception as e: + traceback.print_exc() + self._exception_queue.put( + Exception("An exception occured during test {}" + .format(test_case), e)) diff --git a/src/python/grpcio_tests/tests/unit/__init__.py b/src/python/grpcio_tests/tests/unit/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/__init__.py +++ b/src/python/grpcio_tests/tests/unit/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/_api_test.py b/src/python/grpcio_tests/tests/unit/_api_test.py index 51dc4254208..5435c5500cc 100644 --- a/src/python/grpcio_tests/tests/unit/_api_test.py +++ b/src/python/grpcio_tests/tests/unit/_api_test.py @@ -26,7 +26,6 @@ # 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. - """Test of gRPC Python's application-layer API.""" import unittest @@ -40,73 +39,71 @@ from tests.unit import _from_grpc_import_star class AllTest(unittest.TestCase): - def testAll(self): - expected_grpc_code_elements = ( - 'FutureTimeoutError', - 'FutureCancelledError', - 'Future', - 'ChannelConnectivity', - 'StatusCode', - 'RpcError', - 'RpcContext', - 'Call', - 'ChannelCredentials', - 'CallCredentials', - 'AuthMetadataContext', - 'AuthMetadataPluginCallback', - 'AuthMetadataPlugin', - 'ServerCredentials', - 'UnaryUnaryMultiCallable', - 'UnaryStreamMultiCallable', - 'StreamUnaryMultiCallable', - 'StreamStreamMultiCallable', - 'Channel', - 'ServicerContext', - 'RpcMethodHandler', - 'HandlerCallDetails', - 'GenericRpcHandler', - 'ServiceRpcHandler', - 'Server', - 'unary_unary_rpc_method_handler', - 'unary_stream_rpc_method_handler', - 'stream_unary_rpc_method_handler', - 'stream_stream_rpc_method_handler', - 'method_handlers_generic_handler', - 'ssl_channel_credentials', - 'metadata_call_credentials', - 'access_token_call_credentials', - 'composite_call_credentials', - 'composite_channel_credentials', - 'ssl_server_credentials', - 'channel_ready_future', - 'insecure_channel', - 'secure_channel', - 'server', - ) - - six.assertCountEqual( - self, expected_grpc_code_elements, - _from_grpc_import_star.GRPC_ELEMENTS) + def testAll(self): + expected_grpc_code_elements = ( + 'FutureTimeoutError', + 'FutureCancelledError', + 'Future', + 'ChannelConnectivity', + 'StatusCode', + 'RpcError', + 'RpcContext', + 'Call', + 'ChannelCredentials', + 'CallCredentials', + 'AuthMetadataContext', + 'AuthMetadataPluginCallback', + 'AuthMetadataPlugin', + 'ServerCredentials', + 'UnaryUnaryMultiCallable', + 'UnaryStreamMultiCallable', + 'StreamUnaryMultiCallable', + 'StreamStreamMultiCallable', + 'Channel', + 'ServicerContext', + 'RpcMethodHandler', + 'HandlerCallDetails', + 'GenericRpcHandler', + 'ServiceRpcHandler', + 'Server', + 'unary_unary_rpc_method_handler', + 'unary_stream_rpc_method_handler', + 'stream_unary_rpc_method_handler', + 'stream_stream_rpc_method_handler', + 'method_handlers_generic_handler', + 'ssl_channel_credentials', + 'metadata_call_credentials', + 'access_token_call_credentials', + 'composite_call_credentials', + 'composite_channel_credentials', + 'ssl_server_credentials', + 'channel_ready_future', + 'insecure_channel', + 'secure_channel', + 'server',) + + six.assertCountEqual(self, expected_grpc_code_elements, + _from_grpc_import_star.GRPC_ELEMENTS) class ChannelConnectivityTest(unittest.TestCase): - def testChannelConnectivity(self): - self.assertSequenceEqual( - (grpc.ChannelConnectivity.IDLE, - grpc.ChannelConnectivity.CONNECTING, - grpc.ChannelConnectivity.READY, - grpc.ChannelConnectivity.TRANSIENT_FAILURE, - grpc.ChannelConnectivity.SHUTDOWN,), - tuple(grpc.ChannelConnectivity)) + def testChannelConnectivity(self): + self.assertSequenceEqual(( + grpc.ChannelConnectivity.IDLE, + grpc.ChannelConnectivity.CONNECTING, + grpc.ChannelConnectivity.READY, + grpc.ChannelConnectivity.TRANSIENT_FAILURE, + grpc.ChannelConnectivity.SHUTDOWN,), + tuple(grpc.ChannelConnectivity)) class ChannelTest(unittest.TestCase): - def test_secure_channel(self): - channel_credentials = grpc.ssl_channel_credentials() - channel = grpc.secure_channel('google.com:443', channel_credentials) + def test_secure_channel(self): + channel_credentials = grpc.ssl_channel_credentials() + channel = grpc.secure_channel('google.com:443', channel_credentials) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_auth_test.py b/src/python/grpcio_tests/tests/unit/_auth_test.py index c31f7b06f73..52bd1cb7ba4 100644 --- a/src/python/grpcio_tests/tests/unit/_auth_test.py +++ b/src/python/grpcio_tests/tests/unit/_auth_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of standard AuthMetadataPlugins.""" import collections @@ -38,59 +37,59 @@ from grpc import _auth class MockGoogleCreds(object): - def get_access_token(self): - token = collections.namedtuple('MockAccessTokenInfo', - ('access_token', 'expires_in')) - token.access_token = 'token' - return token + def get_access_token(self): + token = collections.namedtuple('MockAccessTokenInfo', + ('access_token', 'expires_in')) + token.access_token = 'token' + return token class MockExceptionGoogleCreds(object): - def get_access_token(self): - raise Exception() + def get_access_token(self): + raise Exception() class GoogleCallCredentialsTest(unittest.TestCase): - def test_google_call_credentials_success(self): - callback_event = threading.Event() + def test_google_call_credentials_success(self): + callback_event = threading.Event() - def mock_callback(metadata, error): - self.assertEqual(metadata, (('authorization', 'Bearer token'),)) - self.assertIsNone(error) - callback_event.set() + def mock_callback(metadata, error): + self.assertEqual(metadata, (('authorization', 'Bearer token'),)) + self.assertIsNone(error) + callback_event.set() - call_creds = _auth.GoogleCallCredentials(MockGoogleCreds()) - call_creds(None, mock_callback) - self.assertTrue(callback_event.wait(1.0)) + call_creds = _auth.GoogleCallCredentials(MockGoogleCreds()) + call_creds(None, mock_callback) + self.assertTrue(callback_event.wait(1.0)) - def test_google_call_credentials_error(self): - callback_event = threading.Event() + def test_google_call_credentials_error(self): + callback_event = threading.Event() - def mock_callback(metadata, error): - self.assertIsNotNone(error) - callback_event.set() + def mock_callback(metadata, error): + self.assertIsNotNone(error) + callback_event.set() - call_creds = _auth.GoogleCallCredentials(MockExceptionGoogleCreds()) - call_creds(None, mock_callback) - self.assertTrue(callback_event.wait(1.0)) + call_creds = _auth.GoogleCallCredentials(MockExceptionGoogleCreds()) + call_creds(None, mock_callback) + self.assertTrue(callback_event.wait(1.0)) class AccessTokenCallCredentialsTest(unittest.TestCase): - def test_google_call_credentials_success(self): - callback_event = threading.Event() + def test_google_call_credentials_success(self): + callback_event = threading.Event() - def mock_callback(metadata, error): - self.assertEqual(metadata, (('authorization', 'Bearer token'),)) - self.assertIsNone(error) - callback_event.set() + def mock_callback(metadata, error): + self.assertEqual(metadata, (('authorization', 'Bearer token'),)) + self.assertIsNone(error) + callback_event.set() - call_creds = _auth.AccessTokenCallCredentials('token') - call_creds(None, mock_callback) - self.assertTrue(callback_event.wait(1.0)) + call_creds = _auth.AccessTokenCallCredentials('token') + call_creds(None, mock_callback) + self.assertTrue(callback_event.wait(1.0)) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_channel_args_test.py b/src/python/grpcio_tests/tests/unit/_channel_args_test.py index b46497afd60..845db777a4c 100644 --- a/src/python/grpcio_tests/tests/unit/_channel_args_test.py +++ b/src/python/grpcio_tests/tests/unit/_channel_args_test.py @@ -26,17 +26,17 @@ # 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. - """Tests of Channel Args on client/server side.""" import unittest import grpc + class TestPointerWrapper(object): - def __int__(self): - return 123456 + def __int__(self): + return 123456 TEST_CHANNEL_ARGS = ( @@ -44,17 +44,17 @@ TEST_CHANNEL_ARGS = ( ('arg2', 'str_val'), ('arg3', 1), (b'arg4', 'str_val'), - ('arg6', TestPointerWrapper()), -) + ('arg6', TestPointerWrapper()),) class ChannelArgsTest(unittest.TestCase): - def test_client(self): - grpc.insecure_channel('localhost:8080', options=TEST_CHANNEL_ARGS) + def test_client(self): + grpc.insecure_channel('localhost:8080', options=TEST_CHANNEL_ARGS) + + def test_server(self): + grpc.server(None, options=TEST_CHANNEL_ARGS) - def test_server(self): - grpc.server(None, options=TEST_CHANNEL_ARGS) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_channel_connectivity_test.py b/src/python/grpcio_tests/tests/unit/_channel_connectivity_test.py index 3d9dd17ff68..d67693154b8 100644 --- a/src/python/grpcio_tests/tests/unit/_channel_connectivity_test.py +++ b/src/python/grpcio_tests/tests/unit/_channel_connectivity_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc._channel.Channel connectivity.""" import threading @@ -39,125 +38,123 @@ from tests.unit import _thread_pool def _ready_in_connectivities(connectivities): - return grpc.ChannelConnectivity.READY in connectivities + return grpc.ChannelConnectivity.READY in connectivities def _last_connectivity_is_not_ready(connectivities): - return connectivities[-1] is not grpc.ChannelConnectivity.READY + return connectivities[-1] is not grpc.ChannelConnectivity.READY class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._connectivities = [] + def __init__(self): + self._condition = threading.Condition() + self._connectivities = [] - def update(self, connectivity): - with self._condition: - self._connectivities.append(connectivity) - self._condition.notify() + def update(self, connectivity): + with self._condition: + self._connectivities.append(connectivity) + self._condition.notify() - def connectivities(self): - with self._condition: - return tuple(self._connectivities) + def connectivities(self): + with self._condition: + return tuple(self._connectivities) - def block_until_connectivities_satisfy(self, predicate): - with self._condition: - while True: - connectivities = tuple(self._connectivities) - if predicate(connectivities): - return connectivities - else: - self._condition.wait() + def block_until_connectivities_satisfy(self, predicate): + with self._condition: + while True: + connectivities = tuple(self._connectivities) + if predicate(connectivities): + return connectivities + else: + self._condition.wait() class ChannelConnectivityTest(unittest.TestCase): - def test_lonely_channel_connectivity(self): - callback = _Callback() - - channel = grpc.insecure_channel('localhost:12345') - channel.subscribe(callback.update, try_to_connect=False) - first_connectivities = callback.block_until_connectivities_satisfy(bool) - channel.subscribe(callback.update, try_to_connect=True) - second_connectivities = callback.block_until_connectivities_satisfy( - lambda connectivities: 2 <= len(connectivities)) - # Wait for a connection that will never happen. - time.sleep(test_constants.SHORT_TIMEOUT) - third_connectivities = callback.connectivities() - channel.unsubscribe(callback.update) - fourth_connectivities = callback.connectivities() - channel.unsubscribe(callback.update) - fifth_connectivities = callback.connectivities() - - self.assertSequenceEqual( - (grpc.ChannelConnectivity.IDLE,), first_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.READY, second_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.READY, third_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.READY, fourth_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.READY, fifth_connectivities) - - def test_immediately_connectable_channel_connectivity(self): - thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) - server = grpc.server(thread_pool) - port = server.add_insecure_port('[::]:0') - server.start() - first_callback = _Callback() - second_callback = _Callback() - - channel = grpc.insecure_channel('localhost:{}'.format(port)) - channel.subscribe(first_callback.update, try_to_connect=False) - first_connectivities = first_callback.block_until_connectivities_satisfy( - bool) - # Wait for a connection that will never happen because try_to_connect=True - # has not yet been passed. - time.sleep(test_constants.SHORT_TIMEOUT) - second_connectivities = first_callback.connectivities() - channel.subscribe(second_callback.update, try_to_connect=True) - third_connectivities = first_callback.block_until_connectivities_satisfy( - lambda connectivities: 2 <= len(connectivities)) - fourth_connectivities = second_callback.block_until_connectivities_satisfy( - bool) - # Wait for a connection that will happen (or may already have happened). - first_callback.block_until_connectivities_satisfy(_ready_in_connectivities) - second_callback.block_until_connectivities_satisfy(_ready_in_connectivities) - del channel - - self.assertSequenceEqual( - (grpc.ChannelConnectivity.IDLE,), first_connectivities) - self.assertSequenceEqual( - (grpc.ChannelConnectivity.IDLE,), second_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.TRANSIENT_FAILURE, third_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.SHUTDOWN, third_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.TRANSIENT_FAILURE, - fourth_connectivities) - self.assertNotIn( - grpc.ChannelConnectivity.SHUTDOWN, fourth_connectivities) - self.assertFalse(thread_pool.was_used()) - - def test_reachable_then_unreachable_channel_connectivity(self): - thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) - server = grpc.server(thread_pool) - port = server.add_insecure_port('[::]:0') - server.start() - callback = _Callback() - - channel = grpc.insecure_channel('localhost:{}'.format(port)) - channel.subscribe(callback.update, try_to_connect=True) - callback.block_until_connectivities_satisfy(_ready_in_connectivities) - # Now take down the server and confirm that channel readiness is repudiated. - server.stop(None) - callback.block_until_connectivities_satisfy(_last_connectivity_is_not_ready) - channel.unsubscribe(callback.update) - self.assertFalse(thread_pool.was_used()) + def test_lonely_channel_connectivity(self): + callback = _Callback() + + channel = grpc.insecure_channel('localhost:12345') + channel.subscribe(callback.update, try_to_connect=False) + first_connectivities = callback.block_until_connectivities_satisfy(bool) + channel.subscribe(callback.update, try_to_connect=True) + second_connectivities = callback.block_until_connectivities_satisfy( + lambda connectivities: 2 <= len(connectivities)) + # Wait for a connection that will never happen. + time.sleep(test_constants.SHORT_TIMEOUT) + third_connectivities = callback.connectivities() + channel.unsubscribe(callback.update) + fourth_connectivities = callback.connectivities() + channel.unsubscribe(callback.update) + fifth_connectivities = callback.connectivities() + + self.assertSequenceEqual((grpc.ChannelConnectivity.IDLE,), + first_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.READY, second_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.READY, third_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.READY, fourth_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.READY, fifth_connectivities) + + def test_immediately_connectable_channel_connectivity(self): + thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) + server = grpc.server(thread_pool) + port = server.add_insecure_port('[::]:0') + server.start() + first_callback = _Callback() + second_callback = _Callback() + + channel = grpc.insecure_channel('localhost:{}'.format(port)) + channel.subscribe(first_callback.update, try_to_connect=False) + first_connectivities = first_callback.block_until_connectivities_satisfy( + bool) + # Wait for a connection that will never happen because try_to_connect=True + # has not yet been passed. + time.sleep(test_constants.SHORT_TIMEOUT) + second_connectivities = first_callback.connectivities() + channel.subscribe(second_callback.update, try_to_connect=True) + third_connectivities = first_callback.block_until_connectivities_satisfy( + lambda connectivities: 2 <= len(connectivities)) + fourth_connectivities = second_callback.block_until_connectivities_satisfy( + bool) + # Wait for a connection that will happen (or may already have happened). + first_callback.block_until_connectivities_satisfy( + _ready_in_connectivities) + second_callback.block_until_connectivities_satisfy( + _ready_in_connectivities) + del channel + + self.assertSequenceEqual((grpc.ChannelConnectivity.IDLE,), + first_connectivities) + self.assertSequenceEqual((grpc.ChannelConnectivity.IDLE,), + second_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.TRANSIENT_FAILURE, + third_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.SHUTDOWN, + third_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.TRANSIENT_FAILURE, + fourth_connectivities) + self.assertNotIn(grpc.ChannelConnectivity.SHUTDOWN, + fourth_connectivities) + self.assertFalse(thread_pool.was_used()) + + def test_reachable_then_unreachable_channel_connectivity(self): + thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) + server = grpc.server(thread_pool) + port = server.add_insecure_port('[::]:0') + server.start() + callback = _Callback() + + channel = grpc.insecure_channel('localhost:{}'.format(port)) + channel.subscribe(callback.update, try_to_connect=True) + callback.block_until_connectivities_satisfy(_ready_in_connectivities) + # Now take down the server and confirm that channel readiness is repudiated. + server.stop(None) + callback.block_until_connectivities_satisfy( + _last_connectivity_is_not_ready) + channel.unsubscribe(callback.update) + self.assertFalse(thread_pool.was_used()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_channel_ready_future_test.py b/src/python/grpcio_tests/tests/unit/_channel_ready_future_test.py index 46a964db8cf..2d1b63e15f3 100644 --- a/src/python/grpcio_tests/tests/unit/_channel_ready_future_test.py +++ b/src/python/grpcio_tests/tests/unit/_channel_ready_future_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc.channel_ready_future.""" import threading @@ -39,65 +38,66 @@ from tests.unit import _thread_pool class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._value = None + def __init__(self): + self._condition = threading.Condition() + self._value = None - def accept_value(self, value): - with self._condition: - self._value = value - self._condition.notify_all() + def accept_value(self, value): + with self._condition: + self._value = value + self._condition.notify_all() - def block_until_called(self): - with self._condition: - while self._value is None: - self._condition.wait() - return self._value + def block_until_called(self): + with self._condition: + while self._value is None: + self._condition.wait() + return self._value class ChannelReadyFutureTest(unittest.TestCase): - def test_lonely_channel_connectivity(self): - channel = grpc.insecure_channel('localhost:12345') - callback = _Callback() - - ready_future = grpc.channel_ready_future(channel) - ready_future.add_done_callback(callback.accept_value) - with self.assertRaises(grpc.FutureTimeoutError): - ready_future.result(timeout=test_constants.SHORT_TIMEOUT) - self.assertFalse(ready_future.cancelled()) - self.assertFalse(ready_future.done()) - self.assertTrue(ready_future.running()) - ready_future.cancel() - value_passed_to_callback = callback.block_until_called() - self.assertIs(ready_future, value_passed_to_callback) - self.assertTrue(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - - def test_immediately_connectable_channel_connectivity(self): - thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) - server = grpc.server(thread_pool) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:{}'.format(port)) - callback = _Callback() - - ready_future = grpc.channel_ready_future(channel) - ready_future.add_done_callback(callback.accept_value) - self.assertIsNone(ready_future.result(timeout=test_constants.LONG_TIMEOUT)) - value_passed_to_callback = callback.block_until_called() - self.assertIs(ready_future, value_passed_to_callback) - self.assertFalse(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - # Cancellation after maturity has no effect. - ready_future.cancel() - self.assertFalse(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - self.assertFalse(thread_pool.was_used()) + def test_lonely_channel_connectivity(self): + channel = grpc.insecure_channel('localhost:12345') + callback = _Callback() + + ready_future = grpc.channel_ready_future(channel) + ready_future.add_done_callback(callback.accept_value) + with self.assertRaises(grpc.FutureTimeoutError): + ready_future.result(timeout=test_constants.SHORT_TIMEOUT) + self.assertFalse(ready_future.cancelled()) + self.assertFalse(ready_future.done()) + self.assertTrue(ready_future.running()) + ready_future.cancel() + value_passed_to_callback = callback.block_until_called() + self.assertIs(ready_future, value_passed_to_callback) + self.assertTrue(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + + def test_immediately_connectable_channel_connectivity(self): + thread_pool = _thread_pool.RecordingThreadPool(max_workers=None) + server = grpc.server(thread_pool) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:{}'.format(port)) + callback = _Callback() + + ready_future = grpc.channel_ready_future(channel) + ready_future.add_done_callback(callback.accept_value) + self.assertIsNone( + ready_future.result(timeout=test_constants.LONG_TIMEOUT)) + value_passed_to_callback = callback.block_until_called() + self.assertIs(ready_future, value_passed_to_callback) + self.assertFalse(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + # Cancellation after maturity has no effect. + ready_future.cancel() + self.assertFalse(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + self.assertFalse(thread_pool.was_used()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_compression_test.py b/src/python/grpcio_tests/tests/unit/_compression_test.py index 4d3f02e9175..7dd944e6008 100644 --- a/src/python/grpcio_tests/tests/unit/_compression_test.py +++ b/src/python/grpcio_tests/tests/unit/_compression_test.py @@ -42,93 +42,96 @@ _STREAM_STREAM = '/test/StreamStream' def handle_unary(request, servicer_context): - servicer_context.send_initial_metadata([ - ('grpc-internal-encoding-request', 'gzip')]) - return request + servicer_context.send_initial_metadata( + [('grpc-internal-encoding-request', 'gzip')]) + return request def handle_stream(request_iterator, servicer_context): - # TODO(issue:#6891) We should be able to remove this loop, - # and replace with return; yield - servicer_context.send_initial_metadata([ - ('grpc-internal-encoding-request', 'gzip')]) - for request in request_iterator: - yield request + # TODO(issue:#6891) We should be able to remove this loop, + # and replace with return; yield + servicer_context.send_initial_metadata( + [('grpc-internal-encoding-request', 'gzip')]) + for request in request_iterator: + yield request class _MethodHandler(grpc.RpcMethodHandler): - def __init__(self, request_streaming, response_streaming): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = None - self.response_serializer = None - self.unary_unary = None - self.unary_stream = None - self.stream_unary = None - self.stream_stream = None - if self.request_streaming and self.response_streaming: - self.stream_stream = lambda x, y: handle_stream(x, y) - elif not self.request_streaming and not self.response_streaming: - self.unary_unary = lambda x, y: handle_unary(x, y) + def __init__(self, request_streaming, response_streaming): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = None + self.response_serializer = None + self.unary_unary = None + self.unary_stream = None + self.stream_unary = None + self.stream_stream = None + if self.request_streaming and self.response_streaming: + self.stream_stream = lambda x, y: handle_stream(x, y) + elif not self.request_streaming and not self.response_streaming: + self.unary_unary = lambda x, y: handle_unary(x, y) class _GenericHandler(grpc.GenericRpcHandler): - def service(self, handler_call_details): - if handler_call_details.method == _UNARY_UNARY: - return _MethodHandler(False, False) - elif handler_call_details.method == _STREAM_STREAM: - return _MethodHandler(True, True) - else: - return None + def service(self, handler_call_details): + if handler_call_details.method == _UNARY_UNARY: + return _MethodHandler(False, False) + elif handler_call_details.method == _STREAM_STREAM: + return _MethodHandler(True, True) + else: + return None class CompressionTest(unittest.TestCase): - def setUp(self): - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server( - self._server_pool, handlers=(_GenericHandler(),)) - self._port = self._server.add_insecure_port('[::]:0') - self._server.start() - - def testUnary(self): - request = b'\x00' * 100 - - # Client -> server compressed through default client channel compression - # settings. Server -> client compressed via server-side metadata setting. - # TODO(https://github.com/grpc/grpc/issues/4078): replace the "1" integer - # literal with proper use of the public API. - compressed_channel = grpc.insecure_channel('localhost:%d' % self._port, - options=[('grpc.default_compression_algorithm', 1)]) - multi_callable = compressed_channel.unary_unary(_UNARY_UNARY) - response = multi_callable(request) - self.assertEqual(request, response) - - # Client -> server compressed through client metadata setting. Server -> - # client compressed via server-side metadata setting. - # TODO(https://github.com/grpc/grpc/issues/4078): replace the "0" integer - # literal with proper use of the public API. - uncompressed_channel = grpc.insecure_channel('localhost:%d' % self._port, - options=[('grpc.default_compression_algorithm', 0)]) - multi_callable = compressed_channel.unary_unary(_UNARY_UNARY) - response = multi_callable(request, metadata=[ - ('grpc-internal-encoding-request', 'gzip')]) - self.assertEqual(request, response) - - def testStreaming(self): - request = b'\x00' * 100 - - # TODO(https://github.com/grpc/grpc/issues/4078): replace the "1" integer - # literal with proper use of the public API. - compressed_channel = grpc.insecure_channel('localhost:%d' % self._port, - options=[('grpc.default_compression_algorithm', 1)]) - multi_callable = compressed_channel.stream_stream(_STREAM_STREAM) - call = multi_callable(iter([request] * test_constants.STREAM_LENGTH)) - for response in call: - self.assertEqual(request, response) + def setUp(self): + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server( + self._server_pool, handlers=(_GenericHandler(),)) + self._port = self._server.add_insecure_port('[::]:0') + self._server.start() + + def testUnary(self): + request = b'\x00' * 100 + + # Client -> server compressed through default client channel compression + # settings. Server -> client compressed via server-side metadata setting. + # TODO(https://github.com/grpc/grpc/issues/4078): replace the "1" integer + # literal with proper use of the public API. + compressed_channel = grpc.insecure_channel( + 'localhost:%d' % self._port, + options=[('grpc.default_compression_algorithm', 1)]) + multi_callable = compressed_channel.unary_unary(_UNARY_UNARY) + response = multi_callable(request) + self.assertEqual(request, response) + + # Client -> server compressed through client metadata setting. Server -> + # client compressed via server-side metadata setting. + # TODO(https://github.com/grpc/grpc/issues/4078): replace the "0" integer + # literal with proper use of the public API. + uncompressed_channel = grpc.insecure_channel( + 'localhost:%d' % self._port, + options=[('grpc.default_compression_algorithm', 0)]) + multi_callable = compressed_channel.unary_unary(_UNARY_UNARY) + response = multi_callable( + request, metadata=[('grpc-internal-encoding-request', 'gzip')]) + self.assertEqual(request, response) + + def testStreaming(self): + request = b'\x00' * 100 + + # TODO(https://github.com/grpc/grpc/issues/4078): replace the "1" integer + # literal with proper use of the public API. + compressed_channel = grpc.insecure_channel( + 'localhost:%d' % self._port, + options=[('grpc.default_compression_algorithm', 1)]) + multi_callable = compressed_channel.stream_stream(_STREAM_STREAM) + call = multi_callable(iter([request] * test_constants.STREAM_LENGTH)) + for response in call: + self.assertEqual(request, response) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_credentials_test.py b/src/python/grpcio_tests/tests/unit/_credentials_test.py index 87af85a0b9b..21bf29789a7 100644 --- a/src/python/grpcio_tests/tests/unit/_credentials_test.py +++ b/src/python/grpcio_tests/tests/unit/_credentials_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of credentials.""" import unittest @@ -36,37 +35,38 @@ import grpc class CredentialsTest(unittest.TestCase): - def test_call_credentials_composition(self): - first = grpc.access_token_call_credentials('abc') - second = grpc.access_token_call_credentials('def') - third = grpc.access_token_call_credentials('ghi') + def test_call_credentials_composition(self): + first = grpc.access_token_call_credentials('abc') + second = grpc.access_token_call_credentials('def') + third = grpc.access_token_call_credentials('ghi') + + first_and_second = grpc.composite_call_credentials(first, second) + first_second_and_third = grpc.composite_call_credentials(first, second, + third) - first_and_second = grpc.composite_call_credentials(first, second) - first_second_and_third = grpc.composite_call_credentials( - first, second, third) - - self.assertIsInstance(first_and_second, grpc.CallCredentials) - self.assertIsInstance(first_second_and_third, grpc.CallCredentials) + self.assertIsInstance(first_and_second, grpc.CallCredentials) + self.assertIsInstance(first_second_and_third, grpc.CallCredentials) - def test_channel_credentials_composition(self): - first_call_credentials = grpc.access_token_call_credentials('abc') - second_call_credentials = grpc.access_token_call_credentials('def') - third_call_credentials = grpc.access_token_call_credentials('ghi') - channel_credentials = grpc.ssl_channel_credentials() + def test_channel_credentials_composition(self): + first_call_credentials = grpc.access_token_call_credentials('abc') + second_call_credentials = grpc.access_token_call_credentials('def') + third_call_credentials = grpc.access_token_call_credentials('ghi') + channel_credentials = grpc.ssl_channel_credentials() - channel_and_first = grpc.composite_channel_credentials( - channel_credentials, first_call_credentials) - channel_first_and_second = grpc.composite_channel_credentials( - channel_credentials, first_call_credentials, second_call_credentials) - channel_first_second_and_third = grpc.composite_channel_credentials( - channel_credentials, first_call_credentials, second_call_credentials, - third_call_credentials) + channel_and_first = grpc.composite_channel_credentials( + channel_credentials, first_call_credentials) + channel_first_and_second = grpc.composite_channel_credentials( + channel_credentials, first_call_credentials, + second_call_credentials) + channel_first_second_and_third = grpc.composite_channel_credentials( + channel_credentials, first_call_credentials, + second_call_credentials, third_call_credentials) - self.assertIsInstance(channel_and_first, grpc.ChannelCredentials) - self.assertIsInstance(channel_first_and_second, grpc.ChannelCredentials) - self.assertIsInstance( - channel_first_second_and_third, grpc.ChannelCredentials) + self.assertIsInstance(channel_and_first, grpc.ChannelCredentials) + self.assertIsInstance(channel_first_and_second, grpc.ChannelCredentials) + self.assertIsInstance(channel_first_second_and_third, + grpc.ChannelCredentials) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py b/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py index 20115fb22cb..d77f5ecb27e 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_cancel_many_calls_test.py @@ -26,7 +26,6 @@ # 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. - """Test making many calls and immediately cancelling most of them.""" import threading @@ -51,173 +50,178 @@ _SUCCESS_CALL_FRACTION = 1.0 / 8.0 class _State(object): - def __init__(self): - self.condition = threading.Condition() - self.handlers_released = False - self.parked_handlers = 0 - self.handled_rpcs = 0 + def __init__(self): + self.condition = threading.Condition() + self.handlers_released = False + self.parked_handlers = 0 + self.handled_rpcs = 0 def _is_cancellation_event(event): - return ( - event.tag is _RECEIVE_CLOSE_ON_SERVER_TAG and - event.batch_operations[0].received_cancelled) + return (event.tag is _RECEIVE_CLOSE_ON_SERVER_TAG and + event.batch_operations[0].received_cancelled) class _Handler(object): - def __init__(self, state, completion_queue, rpc_event): - self._state = state - self._lock = threading.Lock() - self._completion_queue = completion_queue - self._call = rpc_event.operation_call - - def __call__(self): - with self._state.condition: - self._state.parked_handlers += 1 - if self._state.parked_handlers == test_constants.THREAD_CONCURRENCY: - self._state.condition.notify_all() - while not self._state.handlers_released: - self._state.condition.wait() - - with self._lock: - self._call.start_server_batch( - cygrpc.Operations( - (cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS),)), - _RECEIVE_CLOSE_ON_SERVER_TAG) - self._call.start_server_batch( - cygrpc.Operations((cygrpc.operation_receive_message(_EMPTY_FLAGS),)), - _RECEIVE_MESSAGE_TAG) - first_event = self._completion_queue.poll() - if _is_cancellation_event(first_event): - self._completion_queue.poll() - else: - with self._lock: - operations = ( - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_send_message(b'\x79\x57', _EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - _EMPTY_METADATA, cygrpc.StatusCode.ok, b'test details!', - _EMPTY_FLAGS), - ) - self._call.start_server_batch( - cygrpc.Operations(operations), _SERVER_COMPLETE_CALL_TAG) - self._completion_queue.poll() - self._completion_queue.poll() + def __init__(self, state, completion_queue, rpc_event): + self._state = state + self._lock = threading.Lock() + self._completion_queue = completion_queue + self._call = rpc_event.operation_call + + def __call__(self): + with self._state.condition: + self._state.parked_handlers += 1 + if self._state.parked_handlers == test_constants.THREAD_CONCURRENCY: + self._state.condition.notify_all() + while not self._state.handlers_released: + self._state.condition.wait() + + with self._lock: + self._call.start_server_batch( + cygrpc.Operations( + (cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS),)), + _RECEIVE_CLOSE_ON_SERVER_TAG) + self._call.start_server_batch( + cygrpc.Operations( + (cygrpc.operation_receive_message(_EMPTY_FLAGS),)), + _RECEIVE_MESSAGE_TAG) + first_event = self._completion_queue.poll() + if _is_cancellation_event(first_event): + self._completion_queue.poll() + else: + with self._lock: + operations = ( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_send_message(b'\x79\x57', _EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + _EMPTY_METADATA, cygrpc.StatusCode.ok, b'test details!', + _EMPTY_FLAGS),) + self._call.start_server_batch( + cygrpc.Operations(operations), _SERVER_COMPLETE_CALL_TAG) + self._completion_queue.poll() + self._completion_queue.poll() def _serve(state, server, server_completion_queue, thread_pool): - for _ in range(test_constants.RPC_CONCURRENCY): - call_completion_queue = cygrpc.CompletionQueue() - server.request_call( - call_completion_queue, server_completion_queue, _REQUEST_CALL_TAG) - rpc_event = server_completion_queue.poll() - thread_pool.submit(_Handler(state, call_completion_queue, rpc_event)) - with state.condition: - state.handled_rpcs += 1 - if test_constants.RPC_CONCURRENCY <= state.handled_rpcs: - state.condition.notify_all() - server_completion_queue.poll() + for _ in range(test_constants.RPC_CONCURRENCY): + call_completion_queue = cygrpc.CompletionQueue() + server.request_call(call_completion_queue, server_completion_queue, + _REQUEST_CALL_TAG) + rpc_event = server_completion_queue.poll() + thread_pool.submit(_Handler(state, call_completion_queue, rpc_event)) + with state.condition: + state.handled_rpcs += 1 + if test_constants.RPC_CONCURRENCY <= state.handled_rpcs: + state.condition.notify_all() + server_completion_queue.poll() class _QueueDriver(object): - def __init__(self, condition, completion_queue, due): - self._condition = condition - self._completion_queue = completion_queue - self._due = due - self._events = [] - self._returned = False - - def start(self): - def in_thread(): - while True: - event = self._completion_queue.poll() + def __init__(self, condition, completion_queue, due): + self._condition = condition + self._completion_queue = completion_queue + self._due = due + self._events = [] + self._returned = False + + def start(self): + + def in_thread(): + while True: + event = self._completion_queue.poll() + with self._condition: + self._events.append(event) + self._due.remove(event.tag) + self._condition.notify_all() + if not self._due: + self._returned = True + return + + thread = threading.Thread(target=in_thread) + thread.start() + + def events(self, at_least): with self._condition: - self._events.append(event) - self._due.remove(event.tag) - self._condition.notify_all() - if not self._due: - self._returned = True - return - thread = threading.Thread(target=in_thread) - thread.start() - - def events(self, at_least): - with self._condition: - while len(self._events) < at_least: - self._condition.wait() - return tuple(self._events) + while len(self._events) < at_least: + self._condition.wait() + return tuple(self._events) class CancelManyCallsTest(unittest.TestCase): - def testCancelManyCalls(self): - server_thread_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - - server_completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(cygrpc.ChannelArgs([])) - server.register_completion_queue(server_completion_queue) - port = server.add_http2_port(b'[::]:0') - server.start() - channel = cygrpc.Channel('localhost:{}'.format(port).encode(), - cygrpc.ChannelArgs([])) - - state = _State() - - server_thread_args = ( - state, server, server_completion_queue, server_thread_pool,) - server_thread = threading.Thread(target=_serve, args=server_thread_args) - server_thread.start() - - client_condition = threading.Condition() - client_due = set() - client_completion_queue = cygrpc.CompletionQueue() - client_driver = _QueueDriver( - client_condition, client_completion_queue, client_due) - client_driver.start() - - with client_condition: - client_calls = [] - for index in range(test_constants.RPC_CONCURRENCY): - client_call = channel.create_call( - None, _EMPTY_FLAGS, client_completion_queue, b'/twinkies', None, - _INFINITE_FUTURE) - operations = ( - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_send_message(b'\x45\x56', _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ) - tag = 'client_complete_call_{0:04d}_tag'.format(index) - client_call.start_client_batch(cygrpc.Operations(operations), tag) - client_due.add(tag) - client_calls.append(client_call) - - with state.condition: - while True: - if state.parked_handlers < test_constants.THREAD_CONCURRENCY: - state.condition.wait() - elif state.handled_rpcs < test_constants.RPC_CONCURRENCY: - state.condition.wait() - else: - state.handlers_released = True - state.condition.notify_all() - break - - client_driver.events( - test_constants.RPC_CONCURRENCY * _SUCCESS_CALL_FRACTION) - with client_condition: - for client_call in client_calls: - client_call.cancel() - - with state.condition: - server.shutdown(server_completion_queue, _SERVER_SHUTDOWN_TAG) + def testCancelManyCalls(self): + server_thread_pool = logging_pool.pool( + test_constants.THREAD_CONCURRENCY) + + server_completion_queue = cygrpc.CompletionQueue() + server = cygrpc.Server(cygrpc.ChannelArgs([])) + server.register_completion_queue(server_completion_queue) + port = server.add_http2_port(b'[::]:0') + server.start() + channel = cygrpc.Channel('localhost:{}'.format(port).encode(), + cygrpc.ChannelArgs([])) + + state = _State() + + server_thread_args = ( + state, + server, + server_completion_queue, + server_thread_pool,) + server_thread = threading.Thread(target=_serve, args=server_thread_args) + server_thread.start() + + client_condition = threading.Condition() + client_due = set() + client_completion_queue = cygrpc.CompletionQueue() + client_driver = _QueueDriver(client_condition, client_completion_queue, + client_due) + client_driver.start() + + with client_condition: + client_calls = [] + for index in range(test_constants.RPC_CONCURRENCY): + client_call = channel.create_call( + None, _EMPTY_FLAGS, client_completion_queue, b'/twinkies', + None, _INFINITE_FUTURE) + operations = ( + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_send_message(b'\x45\x56', _EMPTY_FLAGS), + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS),) + tag = 'client_complete_call_{0:04d}_tag'.format(index) + client_call.start_client_batch( + cygrpc.Operations(operations), tag) + client_due.add(tag) + client_calls.append(client_call) + + with state.condition: + while True: + if state.parked_handlers < test_constants.THREAD_CONCURRENCY: + state.condition.wait() + elif state.handled_rpcs < test_constants.RPC_CONCURRENCY: + state.condition.wait() + else: + state.handlers_released = True + state.condition.notify_all() + break + + client_driver.events(test_constants.RPC_CONCURRENCY * + _SUCCESS_CALL_FRACTION) + with client_condition: + for client_call in client_calls: + client_call.cancel() + + with state.condition: + server.shutdown(server_completion_queue, _SERVER_SHUTDOWN_TAG) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py b/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py index f9c8a3ac62b..0ca06868b2d 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_channel_test.py @@ -37,46 +37,49 @@ from tests.unit.framework.common import test_constants def _channel_and_completion_queue(): - channel = cygrpc.Channel(b'localhost:54321', cygrpc.ChannelArgs(())) - completion_queue = cygrpc.CompletionQueue() - return channel, completion_queue + channel = cygrpc.Channel(b'localhost:54321', cygrpc.ChannelArgs(())) + completion_queue = cygrpc.CompletionQueue() + return channel, completion_queue def _connectivity_loop(channel, completion_queue): - for _ in range(100): - connectivity = channel.check_connectivity_state(True) - channel.watch_connectivity_state( - connectivity, cygrpc.Timespec(time.time() + 0.2), completion_queue, - None) - completion_queue.poll(deadline=cygrpc.Timespec(float('+inf'))) + for _ in range(100): + connectivity = channel.check_connectivity_state(True) + channel.watch_connectivity_state(connectivity, + cygrpc.Timespec(time.time() + 0.2), + completion_queue, None) + completion_queue.poll(deadline=cygrpc.Timespec(float('+inf'))) def _create_loop_destroy(): - channel, completion_queue = _channel_and_completion_queue() - _connectivity_loop(channel, completion_queue) - completion_queue.shutdown() + channel, completion_queue = _channel_and_completion_queue() + _connectivity_loop(channel, completion_queue) + completion_queue.shutdown() def _in_parallel(behavior, arguments): - threads = tuple( - threading.Thread(target=behavior, args=arguments) - for _ in range(test_constants.THREAD_CONCURRENCY)) - for thread in threads: - thread.start() - for thread in threads: - thread.join() + threads = tuple( + threading.Thread( + target=behavior, args=arguments) + for _ in range(test_constants.THREAD_CONCURRENCY)) + for thread in threads: + thread.start() + for thread in threads: + thread.join() class ChannelTest(unittest.TestCase): - def test_single_channel_lonely_connectivity(self): - channel, completion_queue = _channel_and_completion_queue() - _in_parallel(_connectivity_loop, (channel, completion_queue,)) - completion_queue.shutdown() + def test_single_channel_lonely_connectivity(self): + channel, completion_queue = _channel_and_completion_queue() + _in_parallel(_connectivity_loop, ( + channel, + completion_queue,)) + completion_queue.shutdown() - def test_multiple_channels_lonely_connectivity(self): - _in_parallel(_create_loop_destroy, ()) + def test_multiple_channels_lonely_connectivity(self): + _in_parallel(_create_loop_destroy, ()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py b/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py index 2ae5285232c..9fbfcbb9c02 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/_read_some_but_not_all_responses_test.py @@ -26,7 +26,6 @@ # 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. - """Test a corner-case at the level of the Cython API.""" import threading @@ -41,212 +40,221 @@ _EMPTY_METADATA = cygrpc.Metadata(()) class _ServerDriver(object): - def __init__(self, completion_queue, shutdown_tag): - self._condition = threading.Condition() - self._completion_queue = completion_queue - self._shutdown_tag = shutdown_tag - self._events = [] - self._saw_shutdown_tag = False - - def start(self): - def in_thread(): - while True: - event = self._completion_queue.poll() + def __init__(self, completion_queue, shutdown_tag): + self._condition = threading.Condition() + self._completion_queue = completion_queue + self._shutdown_tag = shutdown_tag + self._events = [] + self._saw_shutdown_tag = False + + def start(self): + + def in_thread(): + while True: + event = self._completion_queue.poll() + with self._condition: + self._events.append(event) + self._condition.notify() + if event.tag is self._shutdown_tag: + self._saw_shutdown_tag = True + break + + thread = threading.Thread(target=in_thread) + thread.start() + + def done(self): + with self._condition: + return self._saw_shutdown_tag + + def first_event(self): + with self._condition: + while not self._events: + self._condition.wait() + return self._events[0] + + def events(self): with self._condition: - self._events.append(event) - self._condition.notify() - if event.tag is self._shutdown_tag: - self._saw_shutdown_tag = True - break - thread = threading.Thread(target=in_thread) - thread.start() - - def done(self): - with self._condition: - return self._saw_shutdown_tag - - def first_event(self): - with self._condition: - while not self._events: - self._condition.wait() - return self._events[0] - - def events(self): - with self._condition: - while not self._saw_shutdown_tag: - self._condition.wait() - return tuple(self._events) + while not self._saw_shutdown_tag: + self._condition.wait() + return tuple(self._events) class _QueueDriver(object): - def __init__(self, condition, completion_queue, due): - self._condition = condition - self._completion_queue = completion_queue - self._due = due - self._events = [] - self._returned = False - - def start(self): - def in_thread(): - while True: - event = self._completion_queue.poll() + def __init__(self, condition, completion_queue, due): + self._condition = condition + self._completion_queue = completion_queue + self._due = due + self._events = [] + self._returned = False + + def start(self): + + def in_thread(): + while True: + event = self._completion_queue.poll() + with self._condition: + self._events.append(event) + self._due.remove(event.tag) + self._condition.notify_all() + if not self._due: + self._returned = True + return + + thread = threading.Thread(target=in_thread) + thread.start() + + def done(self): + with self._condition: + return self._returned + + def event_with_tag(self, tag): + with self._condition: + while True: + for event in self._events: + if event.tag is tag: + return event + self._condition.wait() + + def events(self): with self._condition: - self._events.append(event) - self._due.remove(event.tag) - self._condition.notify_all() - if not self._due: - self._returned = True - return - thread = threading.Thread(target=in_thread) - thread.start() - - def done(self): - with self._condition: - return self._returned - - def event_with_tag(self, tag): - with self._condition: - while True: - for event in self._events: - if event.tag is tag: - return event - self._condition.wait() - - def events(self): - with self._condition: - while not self._returned: - self._condition.wait() - return tuple(self._events) + while not self._returned: + self._condition.wait() + return tuple(self._events) class ReadSomeButNotAllResponsesTest(unittest.TestCase): - def testReadSomeButNotAllResponses(self): - server_completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(cygrpc.ChannelArgs([])) - server.register_completion_queue(server_completion_queue) - port = server.add_http2_port(b'[::]:0') - server.start() - channel = cygrpc.Channel('localhost:{}'.format(port).encode(), - cygrpc.ChannelArgs([])) - - server_shutdown_tag = 'server_shutdown_tag' - server_driver = _ServerDriver(server_completion_queue, server_shutdown_tag) - server_driver.start() - - client_condition = threading.Condition() - client_due = set() - client_completion_queue = cygrpc.CompletionQueue() - client_driver = _QueueDriver( - client_condition, client_completion_queue, client_due) - client_driver.start() - - server_call_condition = threading.Condition() - server_send_initial_metadata_tag = 'server_send_initial_metadata_tag' - server_send_first_message_tag = 'server_send_first_message_tag' - server_send_second_message_tag = 'server_send_second_message_tag' - server_complete_rpc_tag = 'server_complete_rpc_tag' - server_call_due = set(( - server_send_initial_metadata_tag, - server_send_first_message_tag, - server_send_second_message_tag, - server_complete_rpc_tag, - )) - server_call_completion_queue = cygrpc.CompletionQueue() - server_call_driver = _QueueDriver( - server_call_condition, server_call_completion_queue, server_call_due) - server_call_driver.start() - - server_rpc_tag = 'server_rpc_tag' - request_call_result = server.request_call( - server_call_completion_queue, server_completion_queue, server_rpc_tag) - - client_call = channel.create_call( - None, _EMPTY_FLAGS, client_completion_queue, b'/twinkies', None, - _INFINITE_FUTURE) - client_receive_initial_metadata_tag = 'client_receive_initial_metadata_tag' - client_complete_rpc_tag = 'client_complete_rpc_tag' - with client_condition: - client_receive_initial_metadata_start_batch_result = ( - client_call.start_client_batch(cygrpc.Operations([ - cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), - ]), client_receive_initial_metadata_tag)) - client_due.add(client_receive_initial_metadata_tag) - client_complete_rpc_start_batch_result = ( - client_call.start_client_batch(cygrpc.Operations([ - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), - ]), client_complete_rpc_tag)) - client_due.add(client_complete_rpc_tag) - - server_rpc_event = server_driver.first_event() - - with server_call_condition: - server_send_initial_metadata_start_batch_result = ( - server_rpc_event.operation_call.start_server_batch([ - cygrpc.operation_send_initial_metadata( - _EMPTY_METADATA, _EMPTY_FLAGS), - ], server_send_initial_metadata_tag)) - server_send_first_message_start_batch_result = ( - server_rpc_event.operation_call.start_server_batch([ - cygrpc.operation_send_message(b'\x07', _EMPTY_FLAGS), - ], server_send_first_message_tag)) - server_send_initial_metadata_event = server_call_driver.event_with_tag( - server_send_initial_metadata_tag) - server_send_first_message_event = server_call_driver.event_with_tag( - server_send_first_message_tag) - with server_call_condition: - server_send_second_message_start_batch_result = ( - server_rpc_event.operation_call.start_server_batch([ - cygrpc.operation_send_message(b'\x07', _EMPTY_FLAGS), - ], server_send_second_message_tag)) - server_complete_rpc_start_batch_result = ( - server_rpc_event.operation_call.start_server_batch([ - cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - cygrpc.Metadata(()), cygrpc.StatusCode.ok, b'test details', - _EMPTY_FLAGS), - ], server_complete_rpc_tag)) - server_send_second_message_event = server_call_driver.event_with_tag( - server_send_second_message_tag) - server_complete_rpc_event = server_call_driver.event_with_tag( - server_complete_rpc_tag) - server_call_driver.events() - - with client_condition: - client_receive_first_message_tag = 'client_receive_first_message_tag' - client_receive_first_message_start_batch_result = ( - client_call.start_client_batch(cygrpc.Operations([ - cygrpc.operation_receive_message(_EMPTY_FLAGS), - ]), client_receive_first_message_tag)) - client_due.add(client_receive_first_message_tag) - client_receive_first_message_event = client_driver.event_with_tag( - client_receive_first_message_tag) - - client_call_cancel_result = client_call.cancel() - client_driver.events() - - server.shutdown(server_completion_queue, server_shutdown_tag) - server.cancel_all_calls() - server_driver.events() - - self.assertEqual(cygrpc.CallError.ok, request_call_result) - self.assertEqual( - cygrpc.CallError.ok, server_send_initial_metadata_start_batch_result) - self.assertEqual( - cygrpc.CallError.ok, client_receive_initial_metadata_start_batch_result) - self.assertEqual( - cygrpc.CallError.ok, client_complete_rpc_start_batch_result) - self.assertEqual(cygrpc.CallError.ok, client_call_cancel_result) - self.assertIs(server_rpc_tag, server_rpc_event.tag) - self.assertEqual( - cygrpc.CompletionType.operation_complete, server_rpc_event.type) - self.assertIsInstance(server_rpc_event.operation_call, cygrpc.Call) - self.assertEqual(0, len(server_rpc_event.batch_operations)) + def testReadSomeButNotAllResponses(self): + server_completion_queue = cygrpc.CompletionQueue() + server = cygrpc.Server(cygrpc.ChannelArgs([])) + server.register_completion_queue(server_completion_queue) + port = server.add_http2_port(b'[::]:0') + server.start() + channel = cygrpc.Channel('localhost:{}'.format(port).encode(), + cygrpc.ChannelArgs([])) + + server_shutdown_tag = 'server_shutdown_tag' + server_driver = _ServerDriver(server_completion_queue, + server_shutdown_tag) + server_driver.start() + + client_condition = threading.Condition() + client_due = set() + client_completion_queue = cygrpc.CompletionQueue() + client_driver = _QueueDriver(client_condition, client_completion_queue, + client_due) + client_driver.start() + + server_call_condition = threading.Condition() + server_send_initial_metadata_tag = 'server_send_initial_metadata_tag' + server_send_first_message_tag = 'server_send_first_message_tag' + server_send_second_message_tag = 'server_send_second_message_tag' + server_complete_rpc_tag = 'server_complete_rpc_tag' + server_call_due = set(( + server_send_initial_metadata_tag, + server_send_first_message_tag, + server_send_second_message_tag, + server_complete_rpc_tag,)) + server_call_completion_queue = cygrpc.CompletionQueue() + server_call_driver = _QueueDriver(server_call_condition, + server_call_completion_queue, + server_call_due) + server_call_driver.start() + + server_rpc_tag = 'server_rpc_tag' + request_call_result = server.request_call(server_call_completion_queue, + server_completion_queue, + server_rpc_tag) + + client_call = channel.create_call(None, _EMPTY_FLAGS, + client_completion_queue, b'/twinkies', + None, _INFINITE_FUTURE) + client_receive_initial_metadata_tag = 'client_receive_initial_metadata_tag' + client_complete_rpc_tag = 'client_complete_rpc_tag' + with client_condition: + client_receive_initial_metadata_start_batch_result = ( + client_call.start_client_batch( + cygrpc.Operations([ + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + ]), client_receive_initial_metadata_tag)) + client_due.add(client_receive_initial_metadata_tag) + client_complete_rpc_start_batch_result = ( + client_call.start_client_batch( + cygrpc.Operations([ + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS), + ]), client_complete_rpc_tag)) + client_due.add(client_complete_rpc_tag) + + server_rpc_event = server_driver.first_event() + + with server_call_condition: + server_send_initial_metadata_start_batch_result = ( + server_rpc_event.operation_call.start_server_batch([ + cygrpc.operation_send_initial_metadata(_EMPTY_METADATA, + _EMPTY_FLAGS), + ], server_send_initial_metadata_tag)) + server_send_first_message_start_batch_result = ( + server_rpc_event.operation_call.start_server_batch([ + cygrpc.operation_send_message(b'\x07', _EMPTY_FLAGS), + ], server_send_first_message_tag)) + server_send_initial_metadata_event = server_call_driver.event_with_tag( + server_send_initial_metadata_tag) + server_send_first_message_event = server_call_driver.event_with_tag( + server_send_first_message_tag) + with server_call_condition: + server_send_second_message_start_batch_result = ( + server_rpc_event.operation_call.start_server_batch([ + cygrpc.operation_send_message(b'\x07', _EMPTY_FLAGS), + ], server_send_second_message_tag)) + server_complete_rpc_start_batch_result = ( + server_rpc_event.operation_call.start_server_batch([ + cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + cygrpc.Metadata(()), cygrpc.StatusCode.ok, + b'test details', _EMPTY_FLAGS), + ], server_complete_rpc_tag)) + server_send_second_message_event = server_call_driver.event_with_tag( + server_send_second_message_tag) + server_complete_rpc_event = server_call_driver.event_with_tag( + server_complete_rpc_tag) + server_call_driver.events() + + with client_condition: + client_receive_first_message_tag = 'client_receive_first_message_tag' + client_receive_first_message_start_batch_result = ( + client_call.start_client_batch( + cygrpc.Operations([ + cygrpc.operation_receive_message(_EMPTY_FLAGS), + ]), client_receive_first_message_tag)) + client_due.add(client_receive_first_message_tag) + client_receive_first_message_event = client_driver.event_with_tag( + client_receive_first_message_tag) + + client_call_cancel_result = client_call.cancel() + client_driver.events() + + server.shutdown(server_completion_queue, server_shutdown_tag) + server.cancel_all_calls() + server_driver.events() + + self.assertEqual(cygrpc.CallError.ok, request_call_result) + self.assertEqual(cygrpc.CallError.ok, + server_send_initial_metadata_start_batch_result) + self.assertEqual(cygrpc.CallError.ok, + client_receive_initial_metadata_start_batch_result) + self.assertEqual(cygrpc.CallError.ok, + client_complete_rpc_start_batch_result) + self.assertEqual(cygrpc.CallError.ok, client_call_cancel_result) + self.assertIs(server_rpc_tag, server_rpc_event.tag) + self.assertEqual(cygrpc.CompletionType.operation_complete, + server_rpc_event.type) + self.assertIsInstance(server_rpc_event.operation_call, cygrpc.Call) + self.assertEqual(0, len(server_rpc_event.batch_operations)) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py index 8dedebfabee..7aec316b95d 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py @@ -37,399 +37,421 @@ from tests.unit._cython import test_utilities from tests.unit import test_common from tests.unit import resources - _SSL_HOST_OVERRIDE = b'foo.test.google.fr' _CALL_CREDENTIALS_METADATA_KEY = 'call-creds-key' _CALL_CREDENTIALS_METADATA_VALUE = 'call-creds-value' _EMPTY_FLAGS = 0 + def _metadata_plugin_callback(context, callback): - callback(cygrpc.Metadata( - [cygrpc.Metadatum(_CALL_CREDENTIALS_METADATA_KEY, - _CALL_CREDENTIALS_METADATA_VALUE)]), - cygrpc.StatusCode.ok, b'') + callback( + cygrpc.Metadata([ + cygrpc.Metadatum(_CALL_CREDENTIALS_METADATA_KEY, + _CALL_CREDENTIALS_METADATA_VALUE) + ]), cygrpc.StatusCode.ok, b'') class TypeSmokeTest(unittest.TestCase): - def testStringsInUtilitiesUpDown(self): - self.assertEqual(0, cygrpc.StatusCode.ok) - metadatum = cygrpc.Metadatum(b'a', b'b') - self.assertEqual(b'a', metadatum.key) - self.assertEqual(b'b', metadatum.value) - metadata = cygrpc.Metadata([metadatum]) - self.assertEqual(1, len(metadata)) - self.assertEqual(metadatum.key, metadata[0].key) - - def testMetadataIteration(self): - metadata = cygrpc.Metadata([ - cygrpc.Metadatum(b'a', b'b'), cygrpc.Metadatum(b'c', b'd')]) - iterator = iter(metadata) - metadatum = next(iterator) - self.assertIsInstance(metadatum, cygrpc.Metadatum) - self.assertEqual(metadatum.key, b'a') - self.assertEqual(metadatum.value, b'b') - metadatum = next(iterator) - self.assertIsInstance(metadatum, cygrpc.Metadatum) - self.assertEqual(metadatum.key, b'c') - self.assertEqual(metadatum.value, b'd') - with self.assertRaises(StopIteration): - next(iterator) - - def testOperationsIteration(self): - operations = cygrpc.Operations([ - cygrpc.operation_send_message(b'asdf', _EMPTY_FLAGS)]) - iterator = iter(operations) - operation = next(iterator) - self.assertIsInstance(operation, cygrpc.Operation) - # `Operation`s are write-only structures; can't directly debug anything out - # of them. Just check that we stop iterating. - with self.assertRaises(StopIteration): - next(iterator) - - def testOperationFlags(self): - operation = cygrpc.operation_send_message(b'asdf', - cygrpc.WriteFlag.no_compress) - self.assertEqual(cygrpc.WriteFlag.no_compress, operation.flags) - - def testTimespec(self): - now = time.time() - timespec = cygrpc.Timespec(now) - self.assertAlmostEqual(now, float(timespec), places=8) - - def testCompletionQueueUpDown(self): - completion_queue = cygrpc.CompletionQueue() - del completion_queue - - def testServerUpDown(self): - server = cygrpc.Server(cygrpc.ChannelArgs([])) - del server - - def testChannelUpDown(self): - channel = cygrpc.Channel(b'[::]:0', cygrpc.ChannelArgs([])) - del channel - - def testCredentialsMetadataPluginUpDown(self): - plugin = cygrpc.CredentialsMetadataPlugin( - lambda ignored_a, ignored_b: None, b'') - del plugin - - def testCallCredentialsFromPluginUpDown(self): - plugin = cygrpc.CredentialsMetadataPlugin(_metadata_plugin_callback, b'') - call_credentials = cygrpc.call_credentials_metadata_plugin(plugin) - del plugin - del call_credentials - - def testServerStartNoExplicitShutdown(self): - server = cygrpc.Server(cygrpc.ChannelArgs([])) - completion_queue = cygrpc.CompletionQueue() - server.register_completion_queue(completion_queue) - port = server.add_http2_port(b'[::]:0') - self.assertIsInstance(port, int) - server.start() - del server - - def testServerStartShutdown(self): - completion_queue = cygrpc.CompletionQueue() - server = cygrpc.Server(cygrpc.ChannelArgs([])) - server.add_http2_port(b'[::]:0') - server.register_completion_queue(completion_queue) - server.start() - shutdown_tag = object() - server.shutdown(completion_queue, shutdown_tag) - event = completion_queue.poll() - self.assertEqual(cygrpc.CompletionType.operation_complete, event.type) - self.assertIs(shutdown_tag, event.tag) - del server - del completion_queue + def testStringsInUtilitiesUpDown(self): + self.assertEqual(0, cygrpc.StatusCode.ok) + metadatum = cygrpc.Metadatum(b'a', b'b') + self.assertEqual(b'a', metadatum.key) + self.assertEqual(b'b', metadatum.value) + metadata = cygrpc.Metadata([metadatum]) + self.assertEqual(1, len(metadata)) + self.assertEqual(metadatum.key, metadata[0].key) + + def testMetadataIteration(self): + metadata = cygrpc.Metadata( + [cygrpc.Metadatum(b'a', b'b'), cygrpc.Metadatum(b'c', b'd')]) + iterator = iter(metadata) + metadatum = next(iterator) + self.assertIsInstance(metadatum, cygrpc.Metadatum) + self.assertEqual(metadatum.key, b'a') + self.assertEqual(metadatum.value, b'b') + metadatum = next(iterator) + self.assertIsInstance(metadatum, cygrpc.Metadatum) + self.assertEqual(metadatum.key, b'c') + self.assertEqual(metadatum.value, b'd') + with self.assertRaises(StopIteration): + next(iterator) + + def testOperationsIteration(self): + operations = cygrpc.Operations( + [cygrpc.operation_send_message(b'asdf', _EMPTY_FLAGS)]) + iterator = iter(operations) + operation = next(iterator) + self.assertIsInstance(operation, cygrpc.Operation) + # `Operation`s are write-only structures; can't directly debug anything out + # of them. Just check that we stop iterating. + with self.assertRaises(StopIteration): + next(iterator) + + def testOperationFlags(self): + operation = cygrpc.operation_send_message(b'asdf', + cygrpc.WriteFlag.no_compress) + self.assertEqual(cygrpc.WriteFlag.no_compress, operation.flags) + + def testTimespec(self): + now = time.time() + timespec = cygrpc.Timespec(now) + self.assertAlmostEqual(now, float(timespec), places=8) + + def testCompletionQueueUpDown(self): + completion_queue = cygrpc.CompletionQueue() + del completion_queue + + def testServerUpDown(self): + server = cygrpc.Server(cygrpc.ChannelArgs([])) + del server + + def testChannelUpDown(self): + channel = cygrpc.Channel(b'[::]:0', cygrpc.ChannelArgs([])) + del channel + + def testCredentialsMetadataPluginUpDown(self): + plugin = cygrpc.CredentialsMetadataPlugin( + lambda ignored_a, ignored_b: None, b'') + del plugin + + def testCallCredentialsFromPluginUpDown(self): + plugin = cygrpc.CredentialsMetadataPlugin(_metadata_plugin_callback, + b'') + call_credentials = cygrpc.call_credentials_metadata_plugin(plugin) + del plugin + del call_credentials + + def testServerStartNoExplicitShutdown(self): + server = cygrpc.Server(cygrpc.ChannelArgs([])) + completion_queue = cygrpc.CompletionQueue() + server.register_completion_queue(completion_queue) + port = server.add_http2_port(b'[::]:0') + self.assertIsInstance(port, int) + server.start() + del server + + def testServerStartShutdown(self): + completion_queue = cygrpc.CompletionQueue() + server = cygrpc.Server(cygrpc.ChannelArgs([])) + server.add_http2_port(b'[::]:0') + server.register_completion_queue(completion_queue) + server.start() + shutdown_tag = object() + server.shutdown(completion_queue, shutdown_tag) + event = completion_queue.poll() + self.assertEqual(cygrpc.CompletionType.operation_complete, event.type) + self.assertIs(shutdown_tag, event.tag) + del server + del completion_queue class ServerClientMixin(object): - def setUpMixin(self, server_credentials, client_credentials, host_override): - self.server_completion_queue = cygrpc.CompletionQueue() - self.server = cygrpc.Server(cygrpc.ChannelArgs([])) - self.server.register_completion_queue(self.server_completion_queue) - if server_credentials: - self.port = self.server.add_http2_port(b'[::]:0', server_credentials) - else: - self.port = self.server.add_http2_port(b'[::]:0') - self.server.start() - self.client_completion_queue = cygrpc.CompletionQueue() - if client_credentials: - client_channel_arguments = cygrpc.ChannelArgs([ - cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override, - host_override)]) - self.client_channel = cygrpc.Channel( - 'localhost:{}'.format(self.port).encode(), client_channel_arguments, - client_credentials) - else: - self.client_channel = cygrpc.Channel( - 'localhost:{}'.format(self.port).encode(), cygrpc.ChannelArgs([])) - if host_override: - self.host_argument = None # default host - self.expected_host = host_override - else: - # arbitrary host name necessitating no further identification - self.host_argument = b'hostess' - self.expected_host = self.host_argument - - def tearDownMixin(self): - del self.server - del self.client_completion_queue - del self.server_completion_queue - - def _perform_operations(self, operations, call, queue, deadline, description): - """Perform the list of operations with given call, queue, and deadline. + def setUpMixin(self, server_credentials, client_credentials, host_override): + self.server_completion_queue = cygrpc.CompletionQueue() + self.server = cygrpc.Server(cygrpc.ChannelArgs([])) + self.server.register_completion_queue(self.server_completion_queue) + if server_credentials: + self.port = self.server.add_http2_port(b'[::]:0', + server_credentials) + else: + self.port = self.server.add_http2_port(b'[::]:0') + self.server.start() + self.client_completion_queue = cygrpc.CompletionQueue() + if client_credentials: + client_channel_arguments = cygrpc.ChannelArgs([ + cygrpc.ChannelArg(cygrpc.ChannelArgKey.ssl_target_name_override, + host_override) + ]) + self.client_channel = cygrpc.Channel( + 'localhost:{}'.format(self.port).encode(), + client_channel_arguments, client_credentials) + else: + self.client_channel = cygrpc.Channel( + 'localhost:{}'.format(self.port).encode(), + cygrpc.ChannelArgs([])) + if host_override: + self.host_argument = None # default host + self.expected_host = host_override + else: + # arbitrary host name necessitating no further identification + self.host_argument = b'hostess' + self.expected_host = self.host_argument + + def tearDownMixin(self): + del self.server + del self.client_completion_queue + del self.server_completion_queue + + def _perform_operations(self, operations, call, queue, deadline, + description): + """Perform the list of operations with given call, queue, and deadline. Invocation errors are reported with as an exception with `description` in the message. Performs the operations asynchronously, returning a future. """ - def performer(): - tag = object() - try: - call_result = call.start_client_batch( - cygrpc.Operations(operations), tag) - self.assertEqual(cygrpc.CallError.ok, call_result) - event = queue.poll(deadline) - self.assertEqual(cygrpc.CompletionType.operation_complete, event.type) - self.assertTrue(event.success) - self.assertIs(tag, event.tag) - except Exception as error: - raise Exception("Error in '{}': {}".format(description, error.message)) - return event - return test_utilities.SimpleFuture(performer) - - def testEcho(self): - DEADLINE = time.time()+5 - DEADLINE_TOLERANCE = 0.25 - CLIENT_METADATA_ASCII_KEY = b'key' - CLIENT_METADATA_ASCII_VALUE = b'val' - CLIENT_METADATA_BIN_KEY = b'key-bin' - CLIENT_METADATA_BIN_VALUE = b'\0'*1000 - SERVER_INITIAL_METADATA_KEY = b'init_me_me_me' - SERVER_INITIAL_METADATA_VALUE = b'whodawha?' - SERVER_TRAILING_METADATA_KEY = b'california_is_in_a_drought' - SERVER_TRAILING_METADATA_VALUE = b'zomg it is' - SERVER_STATUS_CODE = cygrpc.StatusCode.ok - SERVER_STATUS_DETAILS = b'our work is never over' - REQUEST = b'in death a member of project mayhem has a name' - RESPONSE = b'his name is robert paulson' - METHOD = b'twinkies' - - cygrpc_deadline = cygrpc.Timespec(DEADLINE) - - server_request_tag = object() - request_call_result = self.server.request_call( - self.server_completion_queue, self.server_completion_queue, - server_request_tag) - - self.assertEqual(cygrpc.CallError.ok, request_call_result) - - client_call_tag = object() - client_call = self.client_channel.create_call( - None, 0, self.client_completion_queue, METHOD, self.host_argument, - cygrpc_deadline) - client_initial_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(CLIENT_METADATA_ASCII_KEY, - CLIENT_METADATA_ASCII_VALUE), - cygrpc.Metadatum(CLIENT_METADATA_BIN_KEY, CLIENT_METADATA_BIN_VALUE)]) - client_start_batch_result = client_call.start_client_batch([ - cygrpc.operation_send_initial_metadata(client_initial_metadata, - _EMPTY_FLAGS), - cygrpc.operation_send_message(REQUEST, _EMPTY_FLAGS), - cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), - cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS) - ], client_call_tag) - self.assertEqual(cygrpc.CallError.ok, client_start_batch_result) - client_event_future = test_utilities.CompletionQueuePollFuture( - self.client_completion_queue, cygrpc_deadline) - - request_event = self.server_completion_queue.poll(cygrpc_deadline) - self.assertEqual(cygrpc.CompletionType.operation_complete, - request_event.type) - self.assertIsInstance(request_event.operation_call, cygrpc.Call) - self.assertIs(server_request_tag, request_event.tag) - self.assertEqual(0, len(request_event.batch_operations)) - self.assertTrue( - test_common.metadata_transmitted(client_initial_metadata, - request_event.request_metadata)) - self.assertEqual(METHOD, request_event.request_call_details.method) - self.assertEqual(self.expected_host, - request_event.request_call_details.host) - self.assertLess( - abs(DEADLINE - float(request_event.request_call_details.deadline)), - DEADLINE_TOLERANCE) - - server_call_tag = object() - server_call = request_event.operation_call - server_initial_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(SERVER_INITIAL_METADATA_KEY, - SERVER_INITIAL_METADATA_VALUE)]) - server_trailing_metadata = cygrpc.Metadata([ - cygrpc.Metadatum(SERVER_TRAILING_METADATA_KEY, - SERVER_TRAILING_METADATA_VALUE)]) - server_start_batch_result = server_call.start_server_batch([ - cygrpc.operation_send_initial_metadata(server_initial_metadata, - _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - cygrpc.operation_send_message(RESPONSE, _EMPTY_FLAGS), - cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), - cygrpc.operation_send_status_from_server( - server_trailing_metadata, SERVER_STATUS_CODE, - SERVER_STATUS_DETAILS, _EMPTY_FLAGS) - ], server_call_tag) - self.assertEqual(cygrpc.CallError.ok, server_start_batch_result) - - server_event = self.server_completion_queue.poll(cygrpc_deadline) - client_event = client_event_future.result() - - self.assertEqual(6, len(client_event.batch_operations)) - found_client_op_types = set() - for client_result in client_event.batch_operations: - # we expect each op type to be unique - self.assertNotIn(client_result.type, found_client_op_types) - found_client_op_types.add(client_result.type) - if client_result.type == cygrpc.OperationType.receive_initial_metadata: - self.assertTrue( - test_common.metadata_transmitted(server_initial_metadata, - client_result.received_metadata)) - elif client_result.type == cygrpc.OperationType.receive_message: - self.assertEqual(RESPONSE, client_result.received_message.bytes()) - elif client_result.type == cygrpc.OperationType.receive_status_on_client: + + def performer(): + tag = object() + try: + call_result = call.start_client_batch( + cygrpc.Operations(operations), tag) + self.assertEqual(cygrpc.CallError.ok, call_result) + event = queue.poll(deadline) + self.assertEqual(cygrpc.CompletionType.operation_complete, + event.type) + self.assertTrue(event.success) + self.assertIs(tag, event.tag) + except Exception as error: + raise Exception("Error in '{}': {}".format(description, + error.message)) + return event + + return test_utilities.SimpleFuture(performer) + + def testEcho(self): + DEADLINE = time.time() + 5 + DEADLINE_TOLERANCE = 0.25 + CLIENT_METADATA_ASCII_KEY = b'key' + CLIENT_METADATA_ASCII_VALUE = b'val' + CLIENT_METADATA_BIN_KEY = b'key-bin' + CLIENT_METADATA_BIN_VALUE = b'\0' * 1000 + SERVER_INITIAL_METADATA_KEY = b'init_me_me_me' + SERVER_INITIAL_METADATA_VALUE = b'whodawha?' + SERVER_TRAILING_METADATA_KEY = b'california_is_in_a_drought' + SERVER_TRAILING_METADATA_VALUE = b'zomg it is' + SERVER_STATUS_CODE = cygrpc.StatusCode.ok + SERVER_STATUS_DETAILS = b'our work is never over' + REQUEST = b'in death a member of project mayhem has a name' + RESPONSE = b'his name is robert paulson' + METHOD = b'twinkies' + + cygrpc_deadline = cygrpc.Timespec(DEADLINE) + + server_request_tag = object() + request_call_result = self.server.request_call( + self.server_completion_queue, self.server_completion_queue, + server_request_tag) + + self.assertEqual(cygrpc.CallError.ok, request_call_result) + + client_call_tag = object() + client_call = self.client_channel.create_call( + None, 0, self.client_completion_queue, METHOD, self.host_argument, + cygrpc_deadline) + client_initial_metadata = cygrpc.Metadata([ + cygrpc.Metadatum(CLIENT_METADATA_ASCII_KEY, + CLIENT_METADATA_ASCII_VALUE), + cygrpc.Metadatum(CLIENT_METADATA_BIN_KEY, CLIENT_METADATA_BIN_VALUE) + ]) + client_start_batch_result = client_call.start_client_batch([ + cygrpc.operation_send_initial_metadata(client_initial_metadata, + _EMPTY_FLAGS), + cygrpc.operation_send_message(REQUEST, _EMPTY_FLAGS), + cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), + cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS) + ], client_call_tag) + self.assertEqual(cygrpc.CallError.ok, client_start_batch_result) + client_event_future = test_utilities.CompletionQueuePollFuture( + self.client_completion_queue, cygrpc_deadline) + + request_event = self.server_completion_queue.poll(cygrpc_deadline) + self.assertEqual(cygrpc.CompletionType.operation_complete, + request_event.type) + self.assertIsInstance(request_event.operation_call, cygrpc.Call) + self.assertIs(server_request_tag, request_event.tag) + self.assertEqual(0, len(request_event.batch_operations)) self.assertTrue( - test_common.metadata_transmitted(server_trailing_metadata, - client_result.received_metadata)) - self.assertEqual(SERVER_STATUS_DETAILS, - client_result.received_status_details) - self.assertEqual(SERVER_STATUS_CODE, client_result.received_status_code) - self.assertEqual(set([ - cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.send_message, - cygrpc.OperationType.send_close_from_client, - cygrpc.OperationType.receive_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.receive_status_on_client - ]), found_client_op_types) - - self.assertEqual(5, len(server_event.batch_operations)) - found_server_op_types = set() - for server_result in server_event.batch_operations: - self.assertNotIn(client_result.type, found_server_op_types) - found_server_op_types.add(server_result.type) - if server_result.type == cygrpc.OperationType.receive_message: - self.assertEqual(REQUEST, server_result.received_message.bytes()) - elif server_result.type == cygrpc.OperationType.receive_close_on_server: - self.assertFalse(server_result.received_cancelled) - self.assertEqual(set([ - cygrpc.OperationType.send_initial_metadata, - cygrpc.OperationType.receive_message, - cygrpc.OperationType.send_message, - cygrpc.OperationType.receive_close_on_server, - cygrpc.OperationType.send_status_from_server - ]), found_server_op_types) - - del client_call - del server_call - - def test6522(self): - DEADLINE = time.time()+5 - DEADLINE_TOLERANCE = 0.25 - METHOD = b'twinkies' - - cygrpc_deadline = cygrpc.Timespec(DEADLINE) - empty_metadata = cygrpc.Metadata([]) - - server_request_tag = object() - self.server.request_call( - self.server_completion_queue, self.server_completion_queue, - server_request_tag) - client_call = self.client_channel.create_call( - None, 0, self.client_completion_queue, METHOD, self.host_argument, - cygrpc_deadline) - - # Prologue - def perform_client_operations(operations, description): - return self._perform_operations( - operations, client_call, - self.client_completion_queue, cygrpc_deadline, description) - - client_event_future = perform_client_operations([ + test_common.metadata_transmitted(client_initial_metadata, + request_event.request_metadata)) + self.assertEqual(METHOD, request_event.request_call_details.method) + self.assertEqual(self.expected_host, + request_event.request_call_details.host) + self.assertLess( + abs(DEADLINE - float(request_event.request_call_details.deadline)), + DEADLINE_TOLERANCE) + + server_call_tag = object() + server_call = request_event.operation_call + server_initial_metadata = cygrpc.Metadata([ + cygrpc.Metadatum(SERVER_INITIAL_METADATA_KEY, + SERVER_INITIAL_METADATA_VALUE) + ]) + server_trailing_metadata = cygrpc.Metadata([ + cygrpc.Metadatum(SERVER_TRAILING_METADATA_KEY, + SERVER_TRAILING_METADATA_VALUE) + ]) + server_start_batch_result = server_call.start_server_batch([ + cygrpc.operation_send_initial_metadata( + server_initial_metadata, + _EMPTY_FLAGS), cygrpc.operation_receive_message(_EMPTY_FLAGS), + cygrpc.operation_send_message(RESPONSE, _EMPTY_FLAGS), + cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), + cygrpc.operation_send_status_from_server( + server_trailing_metadata, SERVER_STATUS_CODE, + SERVER_STATUS_DETAILS, _EMPTY_FLAGS) + ], server_call_tag) + self.assertEqual(cygrpc.CallError.ok, server_start_batch_result) + + server_event = self.server_completion_queue.poll(cygrpc_deadline) + client_event = client_event_future.result() + + self.assertEqual(6, len(client_event.batch_operations)) + found_client_op_types = set() + for client_result in client_event.batch_operations: + # we expect each op type to be unique + self.assertNotIn(client_result.type, found_client_op_types) + found_client_op_types.add(client_result.type) + if client_result.type == cygrpc.OperationType.receive_initial_metadata: + self.assertTrue( + test_common.metadata_transmitted( + server_initial_metadata, + client_result.received_metadata)) + elif client_result.type == cygrpc.OperationType.receive_message: + self.assertEqual(RESPONSE, + client_result.received_message.bytes()) + elif client_result.type == cygrpc.OperationType.receive_status_on_client: + self.assertTrue( + test_common.metadata_transmitted( + server_trailing_metadata, + client_result.received_metadata)) + self.assertEqual(SERVER_STATUS_DETAILS, + client_result.received_status_details) + self.assertEqual(SERVER_STATUS_CODE, + client_result.received_status_code) + self.assertEqual( + set([ + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.send_message, + cygrpc.OperationType.send_close_from_client, + cygrpc.OperationType.receive_initial_metadata, + cygrpc.OperationType.receive_message, + cygrpc.OperationType.receive_status_on_client + ]), found_client_op_types) + + self.assertEqual(5, len(server_event.batch_operations)) + found_server_op_types = set() + for server_result in server_event.batch_operations: + self.assertNotIn(client_result.type, found_server_op_types) + found_server_op_types.add(server_result.type) + if server_result.type == cygrpc.OperationType.receive_message: + self.assertEqual(REQUEST, + server_result.received_message.bytes()) + elif server_result.type == cygrpc.OperationType.receive_close_on_server: + self.assertFalse(server_result.received_cancelled) + self.assertEqual( + set([ + cygrpc.OperationType.send_initial_metadata, + cygrpc.OperationType.receive_message, + cygrpc.OperationType.send_message, + cygrpc.OperationType.receive_close_on_server, + cygrpc.OperationType.send_status_from_server + ]), found_server_op_types) + + del client_call + del server_call + + def test6522(self): + DEADLINE = time.time() + 5 + DEADLINE_TOLERANCE = 0.25 + METHOD = b'twinkies' + + cygrpc_deadline = cygrpc.Timespec(DEADLINE) + empty_metadata = cygrpc.Metadata([]) + + server_request_tag = object() + self.server.request_call(self.server_completion_queue, + self.server_completion_queue, + server_request_tag) + client_call = self.client_channel.create_call( + None, 0, self.client_completion_queue, METHOD, self.host_argument, + cygrpc_deadline) + + # Prologue + def perform_client_operations(operations, description): + return self._perform_operations(operations, client_call, + self.client_completion_queue, + cygrpc_deadline, description) + + client_event_future = perform_client_operations([ cygrpc.operation_send_initial_metadata(empty_metadata, _EMPTY_FLAGS), cygrpc.operation_receive_initial_metadata(_EMPTY_FLAGS), ], "Client prologue") - request_event = self.server_completion_queue.poll(cygrpc_deadline) - server_call = request_event.operation_call + request_event = self.server_completion_queue.poll(cygrpc_deadline) + server_call = request_event.operation_call - def perform_server_operations(operations, description): - return self._perform_operations( - operations, server_call, - self.server_completion_queue, cygrpc_deadline, description) + def perform_server_operations(operations, description): + return self._perform_operations(operations, server_call, + self.server_completion_queue, + cygrpc_deadline, description) - server_event_future = perform_server_operations([ + server_event_future = perform_server_operations([ cygrpc.operation_send_initial_metadata(empty_metadata, _EMPTY_FLAGS), ], "Server prologue") - client_event_future.result() # force completion - server_event_future.result() - - # Messaging - for _ in range(10): - client_event_future = perform_client_operations([ - cygrpc.operation_send_message(b'', _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - ], "Client message") - server_event_future = perform_server_operations([ - cygrpc.operation_send_message(b'', _EMPTY_FLAGS), - cygrpc.operation_receive_message(_EMPTY_FLAGS), - ], "Server receive") - - client_event_future.result() # force completion - server_event_future.result() - - # Epilogue - client_event_future = perform_client_operations([ + client_event_future.result() # force completion + server_event_future.result() + + # Messaging + for _ in range(10): + client_event_future = perform_client_operations([ + cygrpc.operation_send_message(b'', _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + ], "Client message") + server_event_future = perform_server_operations([ + cygrpc.operation_send_message(b'', _EMPTY_FLAGS), + cygrpc.operation_receive_message(_EMPTY_FLAGS), + ], "Server receive") + + client_event_future.result() # force completion + server_event_future.result() + + # Epilogue + client_event_future = perform_client_operations([ cygrpc.operation_send_close_from_client(_EMPTY_FLAGS), cygrpc.operation_receive_status_on_client(_EMPTY_FLAGS) ], "Client epilogue") - server_event_future = perform_server_operations([ + server_event_future = perform_server_operations([ cygrpc.operation_receive_close_on_server(_EMPTY_FLAGS), cygrpc.operation_send_status_from_server( empty_metadata, cygrpc.StatusCode.ok, b'', _EMPTY_FLAGS) ], "Server epilogue") - client_event_future.result() # force completion - server_event_future.result() + client_event_future.result() # force completion + server_event_future.result() class InsecureServerInsecureClient(unittest.TestCase, ServerClientMixin): - def setUp(self): - self.setUpMixin(None, None, None) + def setUp(self): + self.setUpMixin(None, None, None) - def tearDown(self): - self.tearDownMixin() + def tearDown(self): + self.tearDownMixin() class SecureServerSecureClient(unittest.TestCase, ServerClientMixin): - def setUp(self): - server_credentials = cygrpc.server_credentials_ssl( - None, [cygrpc.SslPemKeyCertPair(resources.private_key(), - resources.certificate_chain())], False) - client_credentials = cygrpc.channel_credentials_ssl( - resources.test_root_certificates(), None) - self.setUpMixin(server_credentials, client_credentials, _SSL_HOST_OVERRIDE) + def setUp(self): + server_credentials = cygrpc.server_credentials_ssl(None, [ + cygrpc.SslPemKeyCertPair(resources.private_key(), + resources.certificate_chain()) + ], False) + client_credentials = cygrpc.channel_credentials_ssl( + resources.test_root_certificates(), None) + self.setUpMixin(server_credentials, client_credentials, + _SSL_HOST_OVERRIDE) - def tearDown(self): - self.tearDownMixin() + def tearDown(self): + self.tearDownMixin() if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py b/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py index 6280ce74c47..dffb3733b6f 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py +++ b/src/python/grpcio_tests/tests/unit/_cython/test_utilities.py @@ -33,34 +33,35 @@ from grpc._cython import cygrpc class SimpleFuture(object): - """A simple future mechanism.""" + """A simple future mechanism.""" - def __init__(self, function, *args, **kwargs): - def wrapped_function(): - try: - self._result = function(*args, **kwargs) - except Exception as error: - self._error = error - self._result = None - self._error = None - self._thread = threading.Thread(target=wrapped_function) - self._thread.start() + def __init__(self, function, *args, **kwargs): - def result(self): - """The resulting value of this future. + def wrapped_function(): + try: + self._result = function(*args, **kwargs) + except Exception as error: + self._error = error + + self._result = None + self._error = None + self._thread = threading.Thread(target=wrapped_function) + self._thread.start() + + def result(self): + """The resulting value of this future. Re-raises any exceptions. """ - self._thread.join() - if self._error: - # TODO(atash): re-raise exceptions in a way that preserves tracebacks - raise self._error - return self._result + self._thread.join() + if self._error: + # TODO(atash): re-raise exceptions in a way that preserves tracebacks + raise self._error + return self._result class CompletionQueuePollFuture(SimpleFuture): - def __init__(self, completion_queue, deadline): - super(CompletionQueuePollFuture, self).__init__( - lambda: completion_queue.poll(deadline)) - + def __init__(self, completion_queue, deadline): + super(CompletionQueuePollFuture, + self).__init__(lambda: completion_queue.poll(deadline)) diff --git a/src/python/grpcio_tests/tests/unit/_empty_message_test.py b/src/python/grpcio_tests/tests/unit/_empty_message_test.py index 69f46892790..4588688ea60 100644 --- a/src/python/grpcio_tests/tests/unit/_empty_message_test.py +++ b/src/python/grpcio_tests/tests/unit/_empty_message_test.py @@ -44,95 +44,94 @@ _STREAM_STREAM = '/test/StreamStream' def handle_unary_unary(request, servicer_context): - return _RESPONSE + return _RESPONSE def handle_unary_stream(request, servicer_context): - for _ in range(test_constants.STREAM_LENGTH): - yield _RESPONSE + for _ in range(test_constants.STREAM_LENGTH): + yield _RESPONSE def handle_stream_unary(request_iterator, servicer_context): - for request in request_iterator: - pass - return _RESPONSE + for request in request_iterator: + pass + return _RESPONSE def handle_stream_stream(request_iterator, servicer_context): - for request in request_iterator: - yield _RESPONSE + for request in request_iterator: + yield _RESPONSE class _MethodHandler(grpc.RpcMethodHandler): - def __init__(self, request_streaming, response_streaming): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = None - self.response_serializer = None - self.unary_unary = None - self.unary_stream = None - self.stream_unary = None - self.stream_stream = None - if self.request_streaming and self.response_streaming: - self.stream_stream = handle_stream_stream - elif self.request_streaming: - self.stream_unary = handle_stream_unary - elif self.response_streaming: - self.unary_stream = handle_unary_stream - else: - self.unary_unary = handle_unary_unary + def __init__(self, request_streaming, response_streaming): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = None + self.response_serializer = None + self.unary_unary = None + self.unary_stream = None + self.stream_unary = None + self.stream_stream = None + if self.request_streaming and self.response_streaming: + self.stream_stream = handle_stream_stream + elif self.request_streaming: + self.stream_unary = handle_stream_unary + elif self.response_streaming: + self.unary_stream = handle_unary_stream + else: + self.unary_unary = handle_unary_unary class _GenericHandler(grpc.GenericRpcHandler): - def service(self, handler_call_details): - if handler_call_details.method == _UNARY_UNARY: - return _MethodHandler(False, False) - elif handler_call_details.method == _UNARY_STREAM: - return _MethodHandler(False, True) - elif handler_call_details.method == _STREAM_UNARY: - return _MethodHandler(True, False) - elif handler_call_details.method == _STREAM_STREAM: - return _MethodHandler(True, True) - else: - return None + def service(self, handler_call_details): + if handler_call_details.method == _UNARY_UNARY: + return _MethodHandler(False, False) + elif handler_call_details.method == _UNARY_STREAM: + return _MethodHandler(False, True) + elif handler_call_details.method == _STREAM_UNARY: + return _MethodHandler(True, False) + elif handler_call_details.method == _STREAM_STREAM: + return _MethodHandler(True, True) + else: + return None class EmptyMessageTest(unittest.TestCase): - def setUp(self): - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server( - self._server_pool, handlers=(_GenericHandler(),)) - port = self._server.add_insecure_port('[::]:0') - self._server.start() - self._channel = grpc.insecure_channel('localhost:%d' % port) + def setUp(self): + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server( + self._server_pool, handlers=(_GenericHandler(),)) + port = self._server.add_insecure_port('[::]:0') + self._server.start() + self._channel = grpc.insecure_channel('localhost:%d' % port) - def tearDown(self): - self._server.stop(0) + def tearDown(self): + self._server.stop(0) - def testUnaryUnary(self): - response = self._channel.unary_unary(_UNARY_UNARY)(_REQUEST) - self.assertEqual(_RESPONSE, response) + def testUnaryUnary(self): + response = self._channel.unary_unary(_UNARY_UNARY)(_REQUEST) + self.assertEqual(_RESPONSE, response) - def testUnaryStream(self): - response_iterator = self._channel.unary_stream(_UNARY_STREAM)(_REQUEST) - self.assertSequenceEqual( - [_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator)) + def testUnaryStream(self): + response_iterator = self._channel.unary_stream(_UNARY_STREAM)(_REQUEST) + self.assertSequenceEqual([_RESPONSE] * test_constants.STREAM_LENGTH, + list(response_iterator)) - def testStreamUnary(self): - response = self._channel.stream_unary(_STREAM_UNARY)( - iter([_REQUEST] * test_constants.STREAM_LENGTH)) - self.assertEqual(_RESPONSE, response) + def testStreamUnary(self): + response = self._channel.stream_unary(_STREAM_UNARY)(iter( + [_REQUEST] * test_constants.STREAM_LENGTH)) + self.assertEqual(_RESPONSE, response) - def testStreamStream(self): - response_iterator = self._channel.stream_stream(_STREAM_STREAM)( - iter([_REQUEST] * test_constants.STREAM_LENGTH)) - self.assertSequenceEqual( - [_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator)) + def testStreamStream(self): + response_iterator = self._channel.stream_stream(_STREAM_STREAM)(iter( + [_REQUEST] * test_constants.STREAM_LENGTH)) + self.assertSequenceEqual([_RESPONSE] * test_constants.STREAM_LENGTH, + list(response_iterator)) if __name__ == '__main__': - unittest.main(verbosity=2) - + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_exit_scenarios.py b/src/python/grpcio_tests/tests/unit/_exit_scenarios.py index 777527137f0..22a66438485 100644 --- a/src/python/grpcio_tests/tests/unit/_exit_scenarios.py +++ b/src/python/grpcio_tests/tests/unit/_exit_scenarios.py @@ -26,7 +26,6 @@ # 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. - """Defines a number of module-scope gRPC scenarios to test clean exit.""" import argparse @@ -73,88 +72,88 @@ TEST_TO_METHOD = { def hang_unary_unary(request, servicer_context): - time.sleep(WAIT_TIME) + time.sleep(WAIT_TIME) def hang_unary_stream(request, servicer_context): - time.sleep(WAIT_TIME) + time.sleep(WAIT_TIME) def hang_partial_unary_stream(request, servicer_context): - for _ in range(test_constants.STREAM_LENGTH // 2): - yield request - time.sleep(WAIT_TIME) + for _ in range(test_constants.STREAM_LENGTH // 2): + yield request + time.sleep(WAIT_TIME) def hang_stream_unary(request_iterator, servicer_context): - time.sleep(WAIT_TIME) + time.sleep(WAIT_TIME) def hang_partial_stream_unary(request_iterator, servicer_context): - for _ in range(test_constants.STREAM_LENGTH // 2): - next(request_iterator) - time.sleep(WAIT_TIME) + for _ in range(test_constants.STREAM_LENGTH // 2): + next(request_iterator) + time.sleep(WAIT_TIME) def hang_stream_stream(request_iterator, servicer_context): - time.sleep(WAIT_TIME) + time.sleep(WAIT_TIME) def hang_partial_stream_stream(request_iterator, servicer_context): - for _ in range(test_constants.STREAM_LENGTH // 2): - yield next(request_iterator) - time.sleep(WAIT_TIME) + for _ in range(test_constants.STREAM_LENGTH // 2): + yield next(request_iterator) + time.sleep(WAIT_TIME) class MethodHandler(grpc.RpcMethodHandler): - def __init__(self, request_streaming, response_streaming, partial_hang): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = None - self.response_serializer = None - self.unary_unary = None - self.unary_stream = None - self.stream_unary = None - self.stream_stream = None - if self.request_streaming and self.response_streaming: - if partial_hang: - self.stream_stream = hang_partial_stream_stream - else: - self.stream_stream = hang_stream_stream - elif self.request_streaming: - if partial_hang: - self.stream_unary = hang_partial_stream_unary - else: - self.stream_unary = hang_stream_unary - elif self.response_streaming: - if partial_hang: - self.unary_stream = hang_partial_unary_stream - else: - self.unary_stream = hang_unary_stream - else: - self.unary_unary = hang_unary_unary + def __init__(self, request_streaming, response_streaming, partial_hang): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = None + self.response_serializer = None + self.unary_unary = None + self.unary_stream = None + self.stream_unary = None + self.stream_stream = None + if self.request_streaming and self.response_streaming: + if partial_hang: + self.stream_stream = hang_partial_stream_stream + else: + self.stream_stream = hang_stream_stream + elif self.request_streaming: + if partial_hang: + self.stream_unary = hang_partial_stream_unary + else: + self.stream_unary = hang_stream_unary + elif self.response_streaming: + if partial_hang: + self.unary_stream = hang_partial_unary_stream + else: + self.unary_stream = hang_unary_stream + else: + self.unary_unary = hang_unary_unary class GenericHandler(grpc.GenericRpcHandler): - def service(self, handler_call_details): - if handler_call_details.method == UNARY_UNARY: - return MethodHandler(False, False, False) - elif handler_call_details.method == UNARY_STREAM: - return MethodHandler(False, True, False) - elif handler_call_details.method == STREAM_UNARY: - return MethodHandler(True, False, False) - elif handler_call_details.method == STREAM_STREAM: - return MethodHandler(True, True, False) - elif handler_call_details.method == PARTIAL_UNARY_STREAM: - return MethodHandler(False, True, True) - elif handler_call_details.method == PARTIAL_STREAM_UNARY: - return MethodHandler(True, False, True) - elif handler_call_details.method == PARTIAL_STREAM_STREAM: - return MethodHandler(True, True, True) - else: - return None + def service(self, handler_call_details): + if handler_call_details.method == UNARY_UNARY: + return MethodHandler(False, False, False) + elif handler_call_details.method == UNARY_STREAM: + return MethodHandler(False, True, False) + elif handler_call_details.method == STREAM_UNARY: + return MethodHandler(True, False, False) + elif handler_call_details.method == STREAM_STREAM: + return MethodHandler(True, True, False) + elif handler_call_details.method == PARTIAL_UNARY_STREAM: + return MethodHandler(False, True, True) + elif handler_call_details.method == PARTIAL_STREAM_UNARY: + return MethodHandler(True, False, True) + elif handler_call_details.method == PARTIAL_STREAM_STREAM: + return MethodHandler(True, True, True) + else: + return None # Traditional executors will not exit until all their @@ -162,88 +161,88 @@ class GenericHandler(grpc.GenericRpcHandler): # never finish, we don't want to block exit on these jobs. class DaemonPool(object): - def submit(self, fn, *args, **kwargs): - thread = threading.Thread(target=fn, args=args, kwargs=kwargs) - thread.daemon = True - thread.start() + def submit(self, fn, *args, **kwargs): + thread = threading.Thread(target=fn, args=args, kwargs=kwargs) + thread.daemon = True + thread.start() - def shutdown(self, wait=True): - pass + def shutdown(self, wait=True): + pass def infinite_request_iterator(): - while True: - yield REQUEST + while True: + yield REQUEST if __name__ == '__main__': - parser = argparse.ArgumentParser() - parser.add_argument('scenario', type=str) - parser.add_argument( - '--wait_for_interrupt', dest='wait_for_interrupt', action='store_true') - args = parser.parse_args() - - if args.scenario == UNSTARTED_SERVER: - server = grpc.server(DaemonPool()) - if args.wait_for_interrupt: - time.sleep(WAIT_TIME) - elif args.scenario == RUNNING_SERVER: - server = grpc.server(DaemonPool()) - port = server.add_insecure_port('[::]:0') - server.start() - if args.wait_for_interrupt: - time.sleep(WAIT_TIME) - elif args.scenario == POLL_CONNECTIVITY_NO_SERVER: - channel = grpc.insecure_channel('localhost:12345') - - def connectivity_callback(connectivity): - pass - - channel.subscribe(connectivity_callback, try_to_connect=True) - if args.wait_for_interrupt: - time.sleep(WAIT_TIME) - elif args.scenario == POLL_CONNECTIVITY: - server = grpc.server(DaemonPool()) - port = server.add_insecure_port('[::]:0') - server.start() - channel = grpc.insecure_channel('localhost:%d' % port) - - def connectivity_callback(connectivity): - pass - - channel.subscribe(connectivity_callback, try_to_connect=True) - if args.wait_for_interrupt: - time.sleep(WAIT_TIME) - - else: - handler = GenericHandler() - server = grpc.server(DaemonPool()) - port = server.add_insecure_port('[::]:0') - server.add_generic_rpc_handlers((handler,)) - server.start() - channel = grpc.insecure_channel('localhost:%d' % port) - - method = TEST_TO_METHOD[args.scenario] - - if args.scenario == IN_FLIGHT_UNARY_UNARY_CALL: - multi_callable = channel.unary_unary(method) - future = multi_callable.future(REQUEST) - result, call = multi_callable.with_call(REQUEST) - elif (args.scenario == IN_FLIGHT_UNARY_STREAM_CALL or - args.scenario == IN_FLIGHT_PARTIAL_UNARY_STREAM_CALL): - multi_callable = channel.unary_stream(method) - response_iterator = multi_callable(REQUEST) - for response in response_iterator: - pass - elif (args.scenario == IN_FLIGHT_STREAM_UNARY_CALL or - args.scenario == IN_FLIGHT_PARTIAL_STREAM_UNARY_CALL): - multi_callable = channel.stream_unary(method) - future = multi_callable.future(infinite_request_iterator()) - result, call = multi_callable.with_call( - iter([REQUEST] * test_constants.STREAM_LENGTH)) - elif (args.scenario == IN_FLIGHT_STREAM_STREAM_CALL or - args.scenario == IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL): - multi_callable = channel.stream_stream(method) - response_iterator = multi_callable(infinite_request_iterator()) - for response in response_iterator: - pass + parser = argparse.ArgumentParser() + parser.add_argument('scenario', type=str) + parser.add_argument( + '--wait_for_interrupt', dest='wait_for_interrupt', action='store_true') + args = parser.parse_args() + + if args.scenario == UNSTARTED_SERVER: + server = grpc.server(DaemonPool()) + if args.wait_for_interrupt: + time.sleep(WAIT_TIME) + elif args.scenario == RUNNING_SERVER: + server = grpc.server(DaemonPool()) + port = server.add_insecure_port('[::]:0') + server.start() + if args.wait_for_interrupt: + time.sleep(WAIT_TIME) + elif args.scenario == POLL_CONNECTIVITY_NO_SERVER: + channel = grpc.insecure_channel('localhost:12345') + + def connectivity_callback(connectivity): + pass + + channel.subscribe(connectivity_callback, try_to_connect=True) + if args.wait_for_interrupt: + time.sleep(WAIT_TIME) + elif args.scenario == POLL_CONNECTIVITY: + server = grpc.server(DaemonPool()) + port = server.add_insecure_port('[::]:0') + server.start() + channel = grpc.insecure_channel('localhost:%d' % port) + + def connectivity_callback(connectivity): + pass + + channel.subscribe(connectivity_callback, try_to_connect=True) + if args.wait_for_interrupt: + time.sleep(WAIT_TIME) + + else: + handler = GenericHandler() + server = grpc.server(DaemonPool()) + port = server.add_insecure_port('[::]:0') + server.add_generic_rpc_handlers((handler,)) + server.start() + channel = grpc.insecure_channel('localhost:%d' % port) + + method = TEST_TO_METHOD[args.scenario] + + if args.scenario == IN_FLIGHT_UNARY_UNARY_CALL: + multi_callable = channel.unary_unary(method) + future = multi_callable.future(REQUEST) + result, call = multi_callable.with_call(REQUEST) + elif (args.scenario == IN_FLIGHT_UNARY_STREAM_CALL or + args.scenario == IN_FLIGHT_PARTIAL_UNARY_STREAM_CALL): + multi_callable = channel.unary_stream(method) + response_iterator = multi_callable(REQUEST) + for response in response_iterator: + pass + elif (args.scenario == IN_FLIGHT_STREAM_UNARY_CALL or + args.scenario == IN_FLIGHT_PARTIAL_STREAM_UNARY_CALL): + multi_callable = channel.stream_unary(method) + future = multi_callable.future(infinite_request_iterator()) + result, call = multi_callable.with_call( + iter([REQUEST] * test_constants.STREAM_LENGTH)) + elif (args.scenario == IN_FLIGHT_STREAM_STREAM_CALL or + args.scenario == IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL): + multi_callable = channel.stream_stream(method) + response_iterator = multi_callable(infinite_request_iterator()) + for response in response_iterator: + pass diff --git a/src/python/grpcio_tests/tests/unit/_exit_test.py b/src/python/grpcio_tests/tests/unit/_exit_test.py index 5a4a32887c3..b99605dcb85 100644 --- a/src/python/grpcio_tests/tests/unit/_exit_test.py +++ b/src/python/grpcio_tests/tests/unit/_exit_test.py @@ -26,7 +26,6 @@ # 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. - """Tests clean exit of server/client on Python Interpreter exit/sigint. The tests in this module spawn a subprocess for each test case, the @@ -45,15 +44,15 @@ import unittest from tests.unit import _exit_scenarios -SCENARIO_FILE = os.path.abspath(os.path.join( - os.path.dirname(os.path.realpath(__file__)), '_exit_scenarios.py')) +SCENARIO_FILE = os.path.abspath( + os.path.join( + os.path.dirname(os.path.realpath(__file__)), '_exit_scenarios.py')) INTERPRETER = sys.executable BASE_COMMAND = [INTERPRETER, SCENARIO_FILE] BASE_SIGTERM_COMMAND = BASE_COMMAND + ['--wait_for_interrupt'] INIT_TIME = 1.0 - processes = [] process_lock = threading.Lock() @@ -61,126 +60,146 @@ process_lock = threading.Lock() # Make sure we attempt to clean up any # processes we may have left running def cleanup_processes(): - with process_lock: - for process in processes: - try: - process.kill() - except Exception: - pass + with process_lock: + for process in processes: + try: + process.kill() + except Exception: + pass + + atexit.register(cleanup_processes) def interrupt_and_wait(process): - with process_lock: - processes.append(process) - time.sleep(INIT_TIME) - os.kill(process.pid, signal.SIGINT) - process.wait() + with process_lock: + processes.append(process) + time.sleep(INIT_TIME) + os.kill(process.pid, signal.SIGINT) + process.wait() def wait(process): - with process_lock: - processes.append(process) - process.wait() + with process_lock: + processes.append(process) + process.wait() @unittest.skip('https://github.com/grpc/grpc/issues/7311') class ExitTest(unittest.TestCase): - def test_unstarted_server(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.UNSTARTED_SERVER], - stdout=sys.stdout, stderr=sys.stderr) - wait(process) - - def test_unstarted_server_terminate(self): - process = subprocess.Popen( - BASE_SIGTERM_COMMAND + [_exit_scenarios.UNSTARTED_SERVER], - stdout=sys.stdout) - interrupt_and_wait(process) - - def test_running_server(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.RUNNING_SERVER], - stdout=sys.stdout, stderr=sys.stderr) - wait(process) - - def test_running_server_terminate(self): - process = subprocess.Popen( - BASE_SIGTERM_COMMAND + [_exit_scenarios.RUNNING_SERVER], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - def test_poll_connectivity_no_server(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY_NO_SERVER], - stdout=sys.stdout, stderr=sys.stderr) - wait(process) - - def test_poll_connectivity_no_server_terminate(self): - process = subprocess.Popen( - BASE_SIGTERM_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY_NO_SERVER], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - def test_poll_connectivity(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY], - stdout=sys.stdout, stderr=sys.stderr) - wait(process) - - def test_poll_connectivity_terminate(self): - process = subprocess.Popen( - BASE_SIGTERM_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - def test_in_flight_unary_unary_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_UNARY_UNARY_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') - def test_in_flight_unary_stream_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_UNARY_STREAM_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - def test_in_flight_stream_unary_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_STREAM_UNARY_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') - def test_in_flight_stream_stream_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_STREAM_STREAM_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') - def test_in_flight_partial_unary_stream_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_PARTIAL_UNARY_STREAM_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - def test_in_flight_partial_stream_unary_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_PARTIAL_STREAM_UNARY_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) - - @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') - def test_in_flight_partial_stream_stream_call(self): - process = subprocess.Popen( - BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL], - stdout=sys.stdout, stderr=sys.stderr) - interrupt_and_wait(process) + def test_unstarted_server(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.UNSTARTED_SERVER], + stdout=sys.stdout, + stderr=sys.stderr) + wait(process) + + def test_unstarted_server_terminate(self): + process = subprocess.Popen( + BASE_SIGTERM_COMMAND + [_exit_scenarios.UNSTARTED_SERVER], + stdout=sys.stdout) + interrupt_and_wait(process) + + def test_running_server(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.RUNNING_SERVER], + stdout=sys.stdout, + stderr=sys.stderr) + wait(process) + + def test_running_server_terminate(self): + process = subprocess.Popen( + BASE_SIGTERM_COMMAND + [_exit_scenarios.RUNNING_SERVER], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + def test_poll_connectivity_no_server(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY_NO_SERVER], + stdout=sys.stdout, + stderr=sys.stderr) + wait(process) + + def test_poll_connectivity_no_server_terminate(self): + process = subprocess.Popen( + BASE_SIGTERM_COMMAND + + [_exit_scenarios.POLL_CONNECTIVITY_NO_SERVER], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + def test_poll_connectivity(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY], + stdout=sys.stdout, + stderr=sys.stderr) + wait(process) + + def test_poll_connectivity_terminate(self): + process = subprocess.Popen( + BASE_SIGTERM_COMMAND + [_exit_scenarios.POLL_CONNECTIVITY], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + def test_in_flight_unary_unary_call(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_UNARY_UNARY_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') + def test_in_flight_unary_stream_call(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_UNARY_STREAM_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + def test_in_flight_stream_unary_call(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_STREAM_UNARY_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') + def test_in_flight_stream_stream_call(self): + process = subprocess.Popen( + BASE_COMMAND + [_exit_scenarios.IN_FLIGHT_STREAM_STREAM_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') + def test_in_flight_partial_unary_stream_call(self): + process = subprocess.Popen( + BASE_COMMAND + + [_exit_scenarios.IN_FLIGHT_PARTIAL_UNARY_STREAM_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + def test_in_flight_partial_stream_unary_call(self): + process = subprocess.Popen( + BASE_COMMAND + + [_exit_scenarios.IN_FLIGHT_PARTIAL_STREAM_UNARY_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) + + @unittest.skipIf(six.PY2, 'https://github.com/grpc/grpc/issues/6999') + def test_in_flight_partial_stream_stream_call(self): + process = subprocess.Popen( + BASE_COMMAND + + [_exit_scenarios.IN_FLIGHT_PARTIAL_STREAM_STREAM_CALL], + stdout=sys.stdout, + stderr=sys.stderr) + interrupt_and_wait(process) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py b/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py index 2dc225de292..1b1b1bd598c 100644 --- a/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py +++ b/src/python/grpcio_tests/tests/unit/_invalid_metadata_test.py @@ -26,7 +26,6 @@ # 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. - """Test of RPCs made against gRPC Python's application-layer API.""" import unittest @@ -47,129 +46,131 @@ _STREAM_STREAM = '/test/StreamStream' def _unary_unary_multi_callable(channel): - return channel.unary_unary(_UNARY_UNARY) + return channel.unary_unary(_UNARY_UNARY) def _unary_stream_multi_callable(channel): - return channel.unary_stream( - _UNARY_STREAM, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.unary_stream( + _UNARY_STREAM, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_unary_multi_callable(channel): - return channel.stream_unary( - _STREAM_UNARY, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.stream_unary( + _STREAM_UNARY, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_stream_multi_callable(channel): - return channel.stream_stream(_STREAM_STREAM) + return channel.stream_stream(_STREAM_STREAM) class InvalidMetadataTest(unittest.TestCase): - def setUp(self): - self._channel = grpc.insecure_channel('localhost:8080') - self._unary_unary = _unary_unary_multi_callable(self._channel) - self._unary_stream = _unary_stream_multi_callable(self._channel) - self._stream_unary = _stream_unary_multi_callable(self._channel) - self._stream_stream = _stream_stream_multi_callable(self._channel) - - def testUnaryRequestBlockingUnaryResponse(self): - request = b'\x07\x08' - metadata = (('InVaLiD', 'UnaryRequestBlockingUnaryResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - with self.assertRaises(ValueError) as exception_context: - self._unary_unary(request, metadata=metadata) - self.assertIn(expected_error_details, str(exception_context.exception)) - - def testUnaryRequestBlockingUnaryResponseWithCall(self): - request = b'\x07\x08' - metadata = (('InVaLiD', 'UnaryRequestBlockingUnaryResponseWithCall'),) - expected_error_details = "metadata was invalid: %s" % metadata - with self.assertRaises(ValueError) as exception_context: - self._unary_unary.with_call(request, metadata=metadata) - self.assertIn(expected_error_details, str(exception_context.exception)) - - def testUnaryRequestFutureUnaryResponse(self): - request = b'\x07\x08' - metadata = (('InVaLiD', 'UnaryRequestFutureUnaryResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - response_future = self._unary_unary.future(request, metadata=metadata) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertEqual( - exception_context.exception.details(), expected_error_details) - self.assertEqual( - exception_context.exception.code(), grpc.StatusCode.INTERNAL) - self.assertEqual(response_future.details(), expected_error_details) - self.assertEqual(response_future.code(), grpc.StatusCode.INTERNAL) - - def testUnaryRequestStreamResponse(self): - request = b'\x37\x58' - metadata = (('InVaLiD', 'UnaryRequestStreamResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - response_iterator = self._unary_stream(request, metadata=metadata) - with self.assertRaises(grpc.RpcError) as exception_context: - next(response_iterator) - self.assertEqual( - exception_context.exception.details(), expected_error_details) - self.assertEqual( - exception_context.exception.code(), grpc.StatusCode.INTERNAL) - self.assertEqual(response_iterator.details(), expected_error_details) - self.assertEqual(response_iterator.code(), grpc.StatusCode.INTERNAL) - - def testStreamRequestBlockingUnaryResponse(self): - request_iterator = (b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - with self.assertRaises(ValueError) as exception_context: - self._stream_unary(request_iterator, metadata=metadata) - self.assertIn(expected_error_details, str(exception_context.exception)) - - def testStreamRequestBlockingUnaryResponseWithCall(self): - request_iterator = ( - b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponseWithCall'),) - expected_error_details = "metadata was invalid: %s" % metadata - multi_callable = _stream_unary_multi_callable(self._channel) - with self.assertRaises(ValueError) as exception_context: - multi_callable.with_call(request_iterator, metadata=metadata) - self.assertIn(expected_error_details, str(exception_context.exception)) - - def testStreamRequestFutureUnaryResponse(self): - request_iterator = ( - b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - metadata = (('InVaLiD', 'StreamRequestFutureUnaryResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - response_future = self._stream_unary.future( - request_iterator, metadata=metadata) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertEqual( - exception_context.exception.details(), expected_error_details) - self.assertEqual( - exception_context.exception.code(), grpc.StatusCode.INTERNAL) - self.assertEqual(response_future.details(), expected_error_details) - self.assertEqual(response_future.code(), grpc.StatusCode.INTERNAL) - - def testStreamRequestStreamResponse(self): - request_iterator = ( - b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - metadata = (('InVaLiD', 'StreamRequestStreamResponse'),) - expected_error_details = "metadata was invalid: %s" % metadata - response_iterator = self._stream_stream(request_iterator, metadata=metadata) - with self.assertRaises(grpc.RpcError) as exception_context: - next(response_iterator) - self.assertEqual( - exception_context.exception.details(), expected_error_details) - self.assertEqual( - exception_context.exception.code(), grpc.StatusCode.INTERNAL) - self.assertEqual(response_iterator.details(), expected_error_details) - self.assertEqual(response_iterator.code(), grpc.StatusCode.INTERNAL) + def setUp(self): + self._channel = grpc.insecure_channel('localhost:8080') + self._unary_unary = _unary_unary_multi_callable(self._channel) + self._unary_stream = _unary_stream_multi_callable(self._channel) + self._stream_unary = _stream_unary_multi_callable(self._channel) + self._stream_stream = _stream_stream_multi_callable(self._channel) + + def testUnaryRequestBlockingUnaryResponse(self): + request = b'\x07\x08' + metadata = (('InVaLiD', 'UnaryRequestBlockingUnaryResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + with self.assertRaises(ValueError) as exception_context: + self._unary_unary(request, metadata=metadata) + self.assertIn(expected_error_details, str(exception_context.exception)) + + def testUnaryRequestBlockingUnaryResponseWithCall(self): + request = b'\x07\x08' + metadata = (('InVaLiD', 'UnaryRequestBlockingUnaryResponseWithCall'),) + expected_error_details = "metadata was invalid: %s" % metadata + with self.assertRaises(ValueError) as exception_context: + self._unary_unary.with_call(request, metadata=metadata) + self.assertIn(expected_error_details, str(exception_context.exception)) + + def testUnaryRequestFutureUnaryResponse(self): + request = b'\x07\x08' + metadata = (('InVaLiD', 'UnaryRequestFutureUnaryResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + response_future = self._unary_unary.future(request, metadata=metadata) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertEqual(exception_context.exception.details(), + expected_error_details) + self.assertEqual(exception_context.exception.code(), + grpc.StatusCode.INTERNAL) + self.assertEqual(response_future.details(), expected_error_details) + self.assertEqual(response_future.code(), grpc.StatusCode.INTERNAL) + + def testUnaryRequestStreamResponse(self): + request = b'\x37\x58' + metadata = (('InVaLiD', 'UnaryRequestStreamResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + response_iterator = self._unary_stream(request, metadata=metadata) + with self.assertRaises(grpc.RpcError) as exception_context: + next(response_iterator) + self.assertEqual(exception_context.exception.details(), + expected_error_details) + self.assertEqual(exception_context.exception.code(), + grpc.StatusCode.INTERNAL) + self.assertEqual(response_iterator.details(), expected_error_details) + self.assertEqual(response_iterator.code(), grpc.StatusCode.INTERNAL) + + def testStreamRequestBlockingUnaryResponse(self): + request_iterator = (b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + with self.assertRaises(ValueError) as exception_context: + self._stream_unary(request_iterator, metadata=metadata) + self.assertIn(expected_error_details, str(exception_context.exception)) + + def testStreamRequestBlockingUnaryResponseWithCall(self): + request_iterator = (b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + metadata = (('InVaLiD', 'StreamRequestBlockingUnaryResponseWithCall'),) + expected_error_details = "metadata was invalid: %s" % metadata + multi_callable = _stream_unary_multi_callable(self._channel) + with self.assertRaises(ValueError) as exception_context: + multi_callable.with_call(request_iterator, metadata=metadata) + self.assertIn(expected_error_details, str(exception_context.exception)) + + def testStreamRequestFutureUnaryResponse(self): + request_iterator = (b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + metadata = (('InVaLiD', 'StreamRequestFutureUnaryResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + response_future = self._stream_unary.future( + request_iterator, metadata=metadata) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertEqual(exception_context.exception.details(), + expected_error_details) + self.assertEqual(exception_context.exception.code(), + grpc.StatusCode.INTERNAL) + self.assertEqual(response_future.details(), expected_error_details) + self.assertEqual(response_future.code(), grpc.StatusCode.INTERNAL) + + def testStreamRequestStreamResponse(self): + request_iterator = (b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + metadata = (('InVaLiD', 'StreamRequestStreamResponse'),) + expected_error_details = "metadata was invalid: %s" % metadata + response_iterator = self._stream_stream( + request_iterator, metadata=metadata) + with self.assertRaises(grpc.RpcError) as exception_context: + next(response_iterator) + self.assertEqual(exception_context.exception.details(), + expected_error_details) + self.assertEqual(exception_context.exception.code(), + grpc.StatusCode.INTERNAL) + self.assertEqual(response_iterator.details(), expected_error_details) + self.assertEqual(response_iterator.code(), grpc.StatusCode.INTERNAL) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py b/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py index 4312679bb96..efeb237874f 100644 --- a/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py +++ b/src/python/grpcio_tests/tests/unit/_invocation_defects_test.py @@ -50,106 +50,117 @@ _STREAM_STREAM = '/test/StreamStream' class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._value = None - self._called = False - def __call__(self, value): - with self._condition: - self._value = value - self._called = True - self._condition.notify_all() + def __init__(self): + self._condition = threading.Condition() + self._value = None + self._called = False - def value(self): - with self._condition: - while not self._called: - self._condition.wait() - return self._value + def __call__(self, value): + with self._condition: + self._value = value + self._called = True + self._condition.notify_all() + + def value(self): + with self._condition: + while not self._called: + self._condition.wait() + return self._value class _Handler(object): - def __init__(self, control): - self._control = control - - def handle_unary_unary(self, request, servicer_context): - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - return request - - def handle_unary_stream(self, request, servicer_context): - for _ in range(test_constants.STREAM_LENGTH): - self._control.control() - yield request - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - - def handle_stream_unary(self, request_iterator, servicer_context): - if servicer_context is not None: - servicer_context.invocation_metadata() - self._control.control() - response_elements = [] - for request in request_iterator: - self._control.control() - response_elements.append(request) - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - return b''.join(response_elements) - - def handle_stream_stream(self, request_iterator, servicer_context): - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - for request in request_iterator: - self._control.control() - yield request - self._control.control() + + def __init__(self, control): + self._control = control + + def handle_unary_unary(self, request, servicer_context): + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + return request + + def handle_unary_stream(self, request, servicer_context): + for _ in range(test_constants.STREAM_LENGTH): + self._control.control() + yield request + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + + def handle_stream_unary(self, request_iterator, servicer_context): + if servicer_context is not None: + servicer_context.invocation_metadata() + self._control.control() + response_elements = [] + for request in request_iterator: + self._control.control() + response_elements.append(request) + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + return b''.join(response_elements) + + def handle_stream_stream(self, request_iterator, servicer_context): + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + for request in request_iterator: + self._control.control() + yield request + self._control.control() class _MethodHandler(grpc.RpcMethodHandler): - def __init__( - self, request_streaming, response_streaming, request_deserializer, - response_serializer, unary_unary, unary_stream, stream_unary, - stream_stream): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = request_deserializer - self.response_serializer = response_serializer - self.unary_unary = unary_unary - self.unary_stream = unary_stream - self.stream_unary = stream_unary - self.stream_stream = stream_stream + + def __init__(self, request_streaming, response_streaming, + request_deserializer, response_serializer, unary_unary, + unary_stream, stream_unary, stream_stream): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = request_deserializer + self.response_serializer = response_serializer + self.unary_unary = unary_unary + self.unary_stream = unary_stream + self.stream_unary = stream_unary + self.stream_stream = stream_stream class _GenericHandler(grpc.GenericRpcHandler): - def __init__(self, handler): - self._handler = handler - - def service(self, handler_call_details): - if handler_call_details.method == _UNARY_UNARY: - return _MethodHandler( - False, False, None, None, self._handler.handle_unary_unary, None, - None, None) - elif handler_call_details.method == _UNARY_STREAM: - return _MethodHandler( - False, True, _DESERIALIZE_REQUEST, _SERIALIZE_RESPONSE, None, - self._handler.handle_unary_stream, None, None) - elif handler_call_details.method == _STREAM_UNARY: - return _MethodHandler( - True, False, _DESERIALIZE_REQUEST, _SERIALIZE_RESPONSE, None, None, - self._handler.handle_stream_unary, None) - elif handler_call_details.method == _STREAM_STREAM: - return _MethodHandler( - True, True, None, None, None, None, None, - self._handler.handle_stream_stream) - else: - return None + + def __init__(self, handler): + self._handler = handler + + def service(self, handler_call_details): + if handler_call_details.method == _UNARY_UNARY: + return _MethodHandler(False, False, None, None, + self._handler.handle_unary_unary, None, None, + None) + elif handler_call_details.method == _UNARY_STREAM: + return _MethodHandler(False, True, _DESERIALIZE_REQUEST, + _SERIALIZE_RESPONSE, None, + self._handler.handle_unary_stream, None, None) + elif handler_call_details.method == _STREAM_UNARY: + return _MethodHandler(True, False, _DESERIALIZE_REQUEST, + _SERIALIZE_RESPONSE, None, None, + self._handler.handle_stream_unary, None) + elif handler_call_details.method == _STREAM_STREAM: + return _MethodHandler(True, True, None, None, None, None, None, + self._handler.handle_stream_stream) + else: + return None class FailAfterFewIterationsCounter(object): + def __init__(self, high, bytestring): self._current = 0 self._high = high @@ -167,81 +178,82 @@ class FailAfterFewIterationsCounter(object): def _unary_unary_multi_callable(channel): - return channel.unary_unary(_UNARY_UNARY) + return channel.unary_unary(_UNARY_UNARY) def _unary_stream_multi_callable(channel): - return channel.unary_stream( - _UNARY_STREAM, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.unary_stream( + _UNARY_STREAM, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_unary_multi_callable(channel): - return channel.stream_unary( - _STREAM_UNARY, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.stream_unary( + _STREAM_UNARY, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_stream_multi_callable(channel): - return channel.stream_stream(_STREAM_STREAM) + return channel.stream_stream(_STREAM_STREAM) class InvocationDefectsTest(unittest.TestCase): - def setUp(self): - self._control = test_control.PauseFailControl() - self._handler = _Handler(self._control) - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - - self._server = grpc.server(self._server_pool) - port = self._server.add_insecure_port('[::]:0') - self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),)) - self._server.start() - - self._channel = grpc.insecure_channel('localhost:%d' % port) - - def tearDown(self): - self._server.stop(0) - - def testIterableStreamRequestBlockingUnaryResponse(self): - requests = [b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)] - multi_callable = _stream_unary_multi_callable(self._channel) - - with self.assertRaises(grpc.RpcError): - response = multi_callable( - requests, - metadata=(('test', 'IterableStreamRequestBlockingUnaryResponse'),)) - - def testIterableStreamRequestFutureUnaryResponse(self): - requests = [b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)] - multi_callable = _stream_unary_multi_callable(self._channel) - response_future = multi_callable.future( - requests, - metadata=( - ('test', 'IterableStreamRequestFutureUnaryResponse'),)) - - with self.assertRaises(grpc.RpcError): - response = response_future.result() - - def testIterableStreamRequestStreamResponse(self): - requests = [b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)] - multi_callable = _stream_stream_multi_callable(self._channel) - response_iterator = multi_callable( - requests, - metadata=(('test', 'IterableStreamRequestStreamResponse'),)) - - with self.assertRaises(grpc.RpcError): - next(response_iterator) - - def testIteratorStreamRequestStreamResponse(self): - requests_iterator = FailAfterFewIterationsCounter( - test_constants.STREAM_LENGTH // 2, b'\x07\x08') - multi_callable = _stream_stream_multi_callable(self._channel) - response_iterator = multi_callable( - requests_iterator, - metadata=(('test', 'IteratorStreamRequestStreamResponse'),)) - - with self.assertRaises(grpc.RpcError): - for _ in range(test_constants.STREAM_LENGTH // 2 + 1): - next(response_iterator) + + def setUp(self): + self._control = test_control.PauseFailControl() + self._handler = _Handler(self._control) + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + + self._server = grpc.server(self._server_pool) + port = self._server.add_insecure_port('[::]:0') + self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),)) + self._server.start() + + self._channel = grpc.insecure_channel('localhost:%d' % port) + + def tearDown(self): + self._server.stop(0) + + def testIterableStreamRequestBlockingUnaryResponse(self): + requests = [b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)] + multi_callable = _stream_unary_multi_callable(self._channel) + + with self.assertRaises(grpc.RpcError): + response = multi_callable( + requests, + metadata=( + ('test', 'IterableStreamRequestBlockingUnaryResponse'),)) + + def testIterableStreamRequestFutureUnaryResponse(self): + requests = [b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)] + multi_callable = _stream_unary_multi_callable(self._channel) + response_future = multi_callable.future( + requests, + metadata=(('test', 'IterableStreamRequestFutureUnaryResponse'),)) + + with self.assertRaises(grpc.RpcError): + response = response_future.result() + + def testIterableStreamRequestStreamResponse(self): + requests = [b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)] + multi_callable = _stream_stream_multi_callable(self._channel) + response_iterator = multi_callable( + requests, + metadata=(('test', 'IterableStreamRequestStreamResponse'),)) + + with self.assertRaises(grpc.RpcError): + next(response_iterator) + + def testIteratorStreamRequestStreamResponse(self): + requests_iterator = FailAfterFewIterationsCounter( + test_constants.STREAM_LENGTH // 2, b'\x07\x08') + multi_callable = _stream_stream_multi_callable(self._channel) + response_iterator = multi_callable( + requests_iterator, + metadata=(('test', 'IteratorStreamRequestStreamResponse'),)) + + with self.assertRaises(grpc.RpcError): + for _ in range(test_constants.STREAM_LENGTH // 2 + 1): + next(response_iterator) diff --git a/src/python/grpcio_tests/tests/unit/_junkdrawer/__init__.py b/src/python/grpcio_tests/tests/unit/_junkdrawer/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/_junkdrawer/__init__.py +++ b/src/python/grpcio_tests/tests/unit/_junkdrawer/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/_junkdrawer/stock_pb2.py b/src/python/grpcio_tests/tests/unit/_junkdrawer/stock_pb2.py index eef18f82d65..70f437bc83c 100644 --- a/src/python/grpcio_tests/tests/unit/_junkdrawer/stock_pb2.py +++ b/src/python/grpcio_tests/tests/unit/_junkdrawer/stock_pb2.py @@ -35,7 +35,7 @@ # source: stock.proto import sys -_b=sys.version_info[0]<3 and (lambda x:x) or (lambda x:x.encode('latin1')) +_b = sys.version_info[0] < 3 and (lambda x: x) or (lambda x: x.encode('latin1')) from google.protobuf import descriptor as _descriptor from google.protobuf import message as _message from google.protobuf import reflection as _reflection @@ -45,108 +45,135 @@ from google.protobuf import descriptor_pb2 _sym_db = _symbol_database.Default() - - - DESCRIPTOR = _descriptor.FileDescriptor( - name='stock.proto', - package='stock', - serialized_pb=_b('\n\x0bstock.proto\x12\x05stock\">\n\x0cStockRequest\x12\x0e\n\x06symbol\x18\x01 \x01(\t\x12\x1e\n\x13num_trades_to_watch\x18\x02 \x01(\x05:\x01\x30\"+\n\nStockReply\x12\r\n\x05price\x18\x01 \x01(\x02\x12\x0e\n\x06symbol\x18\x02 \x01(\t2\x96\x02\n\x05Stock\x12=\n\x11GetLastTradePrice\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00\x12I\n\x19GetLastTradePriceMultiple\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00(\x01\x30\x01\x12?\n\x11WatchFutureTrades\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00\x30\x01\x12\x42\n\x14GetHighestTradePrice\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00(\x01') -) + name='stock.proto', + package='stock', + serialized_pb=_b( + '\n\x0bstock.proto\x12\x05stock\">\n\x0cStockRequest\x12\x0e\n\x06symbol\x18\x01 \x01(\t\x12\x1e\n\x13num_trades_to_watch\x18\x02 \x01(\x05:\x01\x30\"+\n\nStockReply\x12\r\n\x05price\x18\x01 \x01(\x02\x12\x0e\n\x06symbol\x18\x02 \x01(\t2\x96\x02\n\x05Stock\x12=\n\x11GetLastTradePrice\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00\x12I\n\x19GetLastTradePriceMultiple\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00(\x01\x30\x01\x12?\n\x11WatchFutureTrades\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00\x30\x01\x12\x42\n\x14GetHighestTradePrice\x12\x13.stock.StockRequest\x1a\x11.stock.StockReply\"\x00(\x01' + )) _sym_db.RegisterFileDescriptor(DESCRIPTOR) - - - _STOCKREQUEST = _descriptor.Descriptor( - name='StockRequest', - full_name='stock.StockRequest', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='symbol', full_name='stock.StockRequest.symbol', index=0, - number=1, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='num_trades_to_watch', full_name='stock.StockRequest.num_trades_to_watch', index=1, - number=2, type=5, cpp_type=1, label=1, - has_default_value=True, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - extension_ranges=[], - oneofs=[ - ], - serialized_start=22, - serialized_end=84, -) - + name='StockRequest', + full_name='stock.StockRequest', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='symbol', + full_name='stock.StockRequest.symbol', + index=0, + number=1, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode('utf-8'), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='num_trades_to_watch', + full_name='stock.StockRequest.num_trades_to_watch', + index=1, + number=2, + type=5, + cpp_type=1, + label=1, + has_default_value=True, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None), + ], + extensions=[], + nested_types=[], + enum_types=[], + options=None, + is_extendable=False, + extension_ranges=[], + oneofs=[], + serialized_start=22, + serialized_end=84,) _STOCKREPLY = _descriptor.Descriptor( - name='StockReply', - full_name='stock.StockReply', - filename=None, - file=DESCRIPTOR, - containing_type=None, - fields=[ - _descriptor.FieldDescriptor( - name='price', full_name='stock.StockReply.price', index=0, - number=1, type=2, cpp_type=6, label=1, - has_default_value=False, default_value=0, - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - _descriptor.FieldDescriptor( - name='symbol', full_name='stock.StockReply.symbol', index=1, - number=2, type=9, cpp_type=9, label=1, - has_default_value=False, default_value=_b("").decode('utf-8'), - message_type=None, enum_type=None, containing_type=None, - is_extension=False, extension_scope=None, - options=None), - ], - extensions=[ - ], - nested_types=[], - enum_types=[ - ], - options=None, - is_extendable=False, - extension_ranges=[], - oneofs=[ - ], - serialized_start=86, - serialized_end=129, -) + name='StockReply', + full_name='stock.StockReply', + filename=None, + file=DESCRIPTOR, + containing_type=None, + fields=[ + _descriptor.FieldDescriptor( + name='price', + full_name='stock.StockReply.price', + index=0, + number=1, + type=2, + cpp_type=6, + label=1, + has_default_value=False, + default_value=0, + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None), + _descriptor.FieldDescriptor( + name='symbol', + full_name='stock.StockReply.symbol', + index=1, + number=2, + type=9, + cpp_type=9, + label=1, + has_default_value=False, + default_value=_b("").decode('utf-8'), + message_type=None, + enum_type=None, + containing_type=None, + is_extension=False, + extension_scope=None, + options=None), + ], + extensions=[], + nested_types=[], + enum_types=[], + options=None, + is_extendable=False, + extension_ranges=[], + oneofs=[], + serialized_start=86, + serialized_end=129,) DESCRIPTOR.message_types_by_name['StockRequest'] = _STOCKREQUEST DESCRIPTOR.message_types_by_name['StockReply'] = _STOCKREPLY -StockRequest = _reflection.GeneratedProtocolMessageType('StockRequest', (_message.Message,), dict( - DESCRIPTOR = _STOCKREQUEST, - __module__ = 'stock_pb2' - # @@protoc_insertion_point(class_scope:stock.StockRequest) - )) +StockRequest = _reflection.GeneratedProtocolMessageType( + 'StockRequest', + (_message.Message,), + dict( + DESCRIPTOR=_STOCKREQUEST, + __module__='stock_pb2' + # @@protoc_insertion_point(class_scope:stock.StockRequest) + )) _sym_db.RegisterMessage(StockRequest) -StockReply = _reflection.GeneratedProtocolMessageType('StockReply', (_message.Message,), dict( - DESCRIPTOR = _STOCKREPLY, - __module__ = 'stock_pb2' - # @@protoc_insertion_point(class_scope:stock.StockReply) - )) +StockReply = _reflection.GeneratedProtocolMessageType( + 'StockReply', + (_message.Message,), + dict( + DESCRIPTOR=_STOCKREPLY, + __module__='stock_pb2' + # @@protoc_insertion_point(class_scope:stock.StockReply) + )) _sym_db.RegisterMessage(StockReply) - # @@protoc_insertion_point(module_scope) diff --git a/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py b/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py index fb3e5477815..af2ce64dcea 100644 --- a/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py +++ b/src/python/grpcio_tests/tests/unit/_metadata_code_details_test.py @@ -26,7 +26,6 @@ # 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. - """Tests application-provided metadata, status code, and details.""" import threading @@ -53,20 +52,16 @@ _UNARY_STREAM = 'UnaryStream' _STREAM_UNARY = 'StreamUnary' _STREAM_STREAM = 'StreamStream' -_CLIENT_METADATA = ( - ('client-md-key', 'client-md-key'), - ('client-md-key-bin', b'\x00\x01') -) +_CLIENT_METADATA = (('client-md-key', 'client-md-key'), + ('client-md-key-bin', b'\x00\x01')) _SERVER_INITIAL_METADATA = ( ('server-initial-md-key', 'server-initial-md-value'), - ('server-initial-md-key-bin', b'\x00\x02') -) + ('server-initial-md-key-bin', b'\x00\x02')) _SERVER_TRAILING_METADATA = ( ('server-trailing-md-key', 'server-trailing-md-value'), - ('server-trailing-md-key-bin', b'\x00\x03') -) + ('server-trailing-md-key-bin', b'\x00\x03')) _NON_OK_CODE = grpc.StatusCode.NOT_FOUND _DETAILS = 'Test details!' @@ -74,450 +69,464 @@ _DETAILS = 'Test details!' class _Servicer(object): - def __init__(self): - self._lock = threading.Lock() - self._code = None - self._details = None - self._exception = False - self._return_none = False - self._received_client_metadata = None - - def unary_unary(self, request, context): - with self._lock: - self._received_client_metadata = context.invocation_metadata() - context.send_initial_metadata(_SERVER_INITIAL_METADATA) - context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - if self._code is not None: - context.set_code(self._code) - if self._details is not None: - context.set_details(self._details) - if self._exception: - raise test_control.Defect() - else: - return None if self._return_none else object() - - def unary_stream(self, request, context): - with self._lock: - self._received_client_metadata = context.invocation_metadata() - context.send_initial_metadata(_SERVER_INITIAL_METADATA) - context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - if self._code is not None: - context.set_code(self._code) - if self._details is not None: - context.set_details(self._details) - for _ in range(test_constants.STREAM_LENGTH // 2): - yield _SERIALIZED_RESPONSE - if self._exception: - raise test_control.Defect() - - def stream_unary(self, request_iterator, context): - with self._lock: - self._received_client_metadata = context.invocation_metadata() - context.send_initial_metadata(_SERVER_INITIAL_METADATA) - context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - if self._code is not None: - context.set_code(self._code) - if self._details is not None: - context.set_details(self._details) - # TODO(https://github.com/grpc/grpc/issues/6891): just ignore the - # request iterator. - for ignored_request in request_iterator: - pass - if self._exception: - raise test_control.Defect() - else: - return None if self._return_none else _SERIALIZED_RESPONSE - - def stream_stream(self, request_iterator, context): - with self._lock: - self._received_client_metadata = context.invocation_metadata() - context.send_initial_metadata(_SERVER_INITIAL_METADATA) - context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - if self._code is not None: - context.set_code(self._code) - if self._details is not None: - context.set_details(self._details) - # TODO(https://github.com/grpc/grpc/issues/6891): just ignore the - # request iterator. - for ignored_request in request_iterator: - pass - for _ in range(test_constants.STREAM_LENGTH // 3): - yield object() - if self._exception: - raise test_control.Defect() - - def set_code(self, code): - with self._lock: - self._code = code - - def set_details(self, details): - with self._lock: - self._details = details - - def set_exception(self): - with self._lock: - self._exception = True - - def set_return_none(self): - with self._lock: - self._return_none = True - - def received_client_metadata(self): - with self._lock: - return self._received_client_metadata + def __init__(self): + self._lock = threading.Lock() + self._code = None + self._details = None + self._exception = False + self._return_none = False + self._received_client_metadata = None + + def unary_unary(self, request, context): + with self._lock: + self._received_client_metadata = context.invocation_metadata() + context.send_initial_metadata(_SERVER_INITIAL_METADATA) + context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + if self._code is not None: + context.set_code(self._code) + if self._details is not None: + context.set_details(self._details) + if self._exception: + raise test_control.Defect() + else: + return None if self._return_none else object() + + def unary_stream(self, request, context): + with self._lock: + self._received_client_metadata = context.invocation_metadata() + context.send_initial_metadata(_SERVER_INITIAL_METADATA) + context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + if self._code is not None: + context.set_code(self._code) + if self._details is not None: + context.set_details(self._details) + for _ in range(test_constants.STREAM_LENGTH // 2): + yield _SERIALIZED_RESPONSE + if self._exception: + raise test_control.Defect() + + def stream_unary(self, request_iterator, context): + with self._lock: + self._received_client_metadata = context.invocation_metadata() + context.send_initial_metadata(_SERVER_INITIAL_METADATA) + context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + if self._code is not None: + context.set_code(self._code) + if self._details is not None: + context.set_details(self._details) + # TODO(https://github.com/grpc/grpc/issues/6891): just ignore the + # request iterator. + for ignored_request in request_iterator: + pass + if self._exception: + raise test_control.Defect() + else: + return None if self._return_none else _SERIALIZED_RESPONSE + + def stream_stream(self, request_iterator, context): + with self._lock: + self._received_client_metadata = context.invocation_metadata() + context.send_initial_metadata(_SERVER_INITIAL_METADATA) + context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + if self._code is not None: + context.set_code(self._code) + if self._details is not None: + context.set_details(self._details) + # TODO(https://github.com/grpc/grpc/issues/6891): just ignore the + # request iterator. + for ignored_request in request_iterator: + pass + for _ in range(test_constants.STREAM_LENGTH // 3): + yield object() + if self._exception: + raise test_control.Defect() + + def set_code(self, code): + with self._lock: + self._code = code + + def set_details(self, details): + with self._lock: + self._details = details + + def set_exception(self): + with self._lock: + self._exception = True + + def set_return_none(self): + with self._lock: + self._return_none = True + + def received_client_metadata(self): + with self._lock: + return self._received_client_metadata def _generic_handler(servicer): - method_handlers = { - _UNARY_UNARY: grpc.unary_unary_rpc_method_handler( - servicer.unary_unary, request_deserializer=_REQUEST_DESERIALIZER, - response_serializer=_RESPONSE_SERIALIZER), - _UNARY_STREAM: grpc.unary_stream_rpc_method_handler( - servicer.unary_stream), - _STREAM_UNARY: grpc.stream_unary_rpc_method_handler( - servicer.stream_unary), - _STREAM_STREAM: grpc.stream_stream_rpc_method_handler( - servicer.stream_stream, request_deserializer=_REQUEST_DESERIALIZER, - response_serializer=_RESPONSE_SERIALIZER), - } - return grpc.method_handlers_generic_handler(_SERVICE, method_handlers) + method_handlers = { + _UNARY_UNARY: grpc.unary_unary_rpc_method_handler( + servicer.unary_unary, + request_deserializer=_REQUEST_DESERIALIZER, + response_serializer=_RESPONSE_SERIALIZER), + _UNARY_STREAM: + grpc.unary_stream_rpc_method_handler(servicer.unary_stream), + _STREAM_UNARY: + grpc.stream_unary_rpc_method_handler(servicer.stream_unary), + _STREAM_STREAM: grpc.stream_stream_rpc_method_handler( + servicer.stream_stream, + request_deserializer=_REQUEST_DESERIALIZER, + response_serializer=_RESPONSE_SERIALIZER), + } + return grpc.method_handlers_generic_handler(_SERVICE, method_handlers) class MetadataCodeDetailsTest(unittest.TestCase): - def setUp(self): - self._servicer = _Servicer() - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server( - self._server_pool, handlers=(_generic_handler(self._servicer),)) - port = self._server.add_insecure_port('[::]:0') - self._server.start() - - channel = grpc.insecure_channel('localhost:{}'.format(port)) - self._unary_unary = channel.unary_unary( - '/'.join(('', _SERVICE, _UNARY_UNARY,)), - request_serializer=_REQUEST_SERIALIZER, - response_deserializer=_RESPONSE_DESERIALIZER,) - self._unary_stream = channel.unary_stream( - '/'.join(('', _SERVICE, _UNARY_STREAM,)),) - self._stream_unary = channel.stream_unary( - '/'.join(('', _SERVICE, _STREAM_UNARY,)),) - self._stream_stream = channel.stream_stream( - '/'.join(('', _SERVICE, _STREAM_STREAM,)), - request_serializer=_REQUEST_SERIALIZER, - response_deserializer=_RESPONSE_DESERIALIZER,) - - - def testSuccessfulUnaryUnary(self): - self._servicer.set_details(_DETAILS) - - unused_response, call = self._unary_unary.with_call( - object(), metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(grpc.StatusCode.OK, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testSuccessfulUnaryStream(self): - self._servicer.set_details(_DETAILS) - - call = self._unary_stream(_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(grpc.StatusCode.OK, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testSuccessfulStreamUnary(self): - self._servicer.set_details(_DETAILS) - - unused_response, call = self._stream_unary.with_call( - iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(grpc.StatusCode.OK, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testSuccessfulStreamStream(self): - self._servicer.set_details(_DETAILS) - - call = self._stream_stream( - iter([object()] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(grpc.StatusCode.OK, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testCustomCodeUnaryUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - - with self.assertRaises(grpc.RpcError) as exception_context: - self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeUnaryStream(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - - call = self._unary_stream(_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - with self.assertRaises(grpc.RpcError): - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(_NON_OK_CODE, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testCustomCodeStreamUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - - with self.assertRaises(grpc.RpcError) as exception_context: - self._stream_unary.with_call( - iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeStreamStream(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - - call = self._stream_stream( - iter([object()] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - with self.assertRaises(grpc.RpcError) as exception_context: - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeExceptionUnaryUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_exception() - - with self.assertRaises(grpc.RpcError) as exception_context: - self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeExceptionUnaryStream(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_exception() - - call = self._unary_stream(_SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - with self.assertRaises(grpc.RpcError): - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(_NON_OK_CODE, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testCustomCodeExceptionStreamUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_exception() - - with self.assertRaises(grpc.RpcError) as exception_context: - self._stream_unary.with_call( - iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeExceptionStreamStream(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_exception() - - call = self._stream_stream( - iter([object()] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - received_initial_metadata = call.initial_metadata() - with self.assertRaises(grpc.RpcError): - for _ in call: - pass - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, received_initial_metadata)) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - self.assertIs(_NON_OK_CODE, call.code()) - self.assertEqual(_DETAILS, call.details()) - - def testCustomCodeReturnNoneUnaryUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_return_none() - - with self.assertRaises(grpc.RpcError) as exception_context: - self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) - - def testCustomCodeReturnNoneStreamUnary(self): - self._servicer.set_code(_NON_OK_CODE) - self._servicer.set_details(_DETAILS) - self._servicer.set_return_none() - - with self.assertRaises(grpc.RpcError) as exception_context: - self._stream_unary.with_call( - iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - - self.assertTrue( - test_common.metadata_transmitted( - _CLIENT_METADATA, self._servicer.received_client_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, - exception_context.exception.initial_metadata())) - self.assertTrue( - test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, - exception_context.exception.trailing_metadata())) - self.assertIs(_NON_OK_CODE, exception_context.exception.code()) - self.assertEqual(_DETAILS, exception_context.exception.details()) + def setUp(self): + self._servicer = _Servicer() + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server( + self._server_pool, handlers=(_generic_handler(self._servicer),)) + port = self._server.add_insecure_port('[::]:0') + self._server.start() + + channel = grpc.insecure_channel('localhost:{}'.format(port)) + self._unary_unary = channel.unary_unary( + '/'.join(( + '', + _SERVICE, + _UNARY_UNARY,)), + request_serializer=_REQUEST_SERIALIZER, + response_deserializer=_RESPONSE_DESERIALIZER,) + self._unary_stream = channel.unary_stream('/'.join(( + '', + _SERVICE, + _UNARY_STREAM,)),) + self._stream_unary = channel.stream_unary('/'.join(( + '', + _SERVICE, + _STREAM_UNARY,)),) + self._stream_stream = channel.stream_stream( + '/'.join(( + '', + _SERVICE, + _STREAM_STREAM,)), + request_serializer=_REQUEST_SERIALIZER, + response_deserializer=_RESPONSE_DESERIALIZER,) + + def testSuccessfulUnaryUnary(self): + self._servicer.set_details(_DETAILS) + + unused_response, call = self._unary_unary.with_call( + object(), metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(grpc.StatusCode.OK, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testSuccessfulUnaryStream(self): + self._servicer.set_details(_DETAILS) + + call = self._unary_stream( + _SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(grpc.StatusCode.OK, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testSuccessfulStreamUnary(self): + self._servicer.set_details(_DETAILS) + + unused_response, call = self._stream_unary.with_call( + iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(grpc.StatusCode.OK, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testSuccessfulStreamStream(self): + self._servicer.set_details(_DETAILS) + + call = self._stream_stream( + iter([object()] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(grpc.StatusCode.OK, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testCustomCodeUnaryUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + + with self.assertRaises(grpc.RpcError) as exception_context: + self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeUnaryStream(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + + call = self._unary_stream( + _SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + with self.assertRaises(grpc.RpcError): + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(_NON_OK_CODE, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testCustomCodeStreamUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + + with self.assertRaises(grpc.RpcError) as exception_context: + self._stream_unary.with_call( + iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeStreamStream(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + + call = self._stream_stream( + iter([object()] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + with self.assertRaises(grpc.RpcError) as exception_context: + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeExceptionUnaryUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_exception() + + with self.assertRaises(grpc.RpcError) as exception_context: + self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeExceptionUnaryStream(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_exception() + + call = self._unary_stream( + _SERIALIZED_REQUEST, metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + with self.assertRaises(grpc.RpcError): + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(_NON_OK_CODE, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testCustomCodeExceptionStreamUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_exception() + + with self.assertRaises(grpc.RpcError) as exception_context: + self._stream_unary.with_call( + iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeExceptionStreamStream(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_exception() + + call = self._stream_stream( + iter([object()] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + received_initial_metadata = call.initial_metadata() + with self.assertRaises(grpc.RpcError): + for _ in call: + pass + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + received_initial_metadata)) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + self.assertIs(_NON_OK_CODE, call.code()) + self.assertEqual(_DETAILS, call.details()) + + def testCustomCodeReturnNoneUnaryUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_return_none() + + with self.assertRaises(grpc.RpcError) as exception_context: + self._unary_unary.with_call(object(), metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) + + def testCustomCodeReturnNoneStreamUnary(self): + self._servicer.set_code(_NON_OK_CODE) + self._servicer.set_details(_DETAILS) + self._servicer.set_return_none() + + with self.assertRaises(grpc.RpcError) as exception_context: + self._stream_unary.with_call( + iter([_SERIALIZED_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + + self.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, self._servicer.received_client_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_INITIAL_METADATA, + exception_context.exception.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted( + _SERVER_TRAILING_METADATA, + exception_context.exception.trailing_metadata())) + self.assertIs(_NON_OK_CODE, exception_context.exception.code()) + self.assertEqual(_DETAILS, exception_context.exception.details()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_metadata_test.py b/src/python/grpcio_tests/tests/unit/_metadata_test.py index caba53ffcc9..53fe7ba8aa5 100644 --- a/src/python/grpcio_tests/tests/unit/_metadata_test.py +++ b/src/python/grpcio_tests/tests/unit/_metadata_test.py @@ -51,166 +51,174 @@ _STREAM_STREAM = '/test/StreamStream' _USER_AGENT = 'Python-gRPC-{}'.format(_grpcio_metadata.__version__) -_CLIENT_METADATA = ( - ('client-md-key', 'client-md-key'), - ('client-md-key-bin', b'\x00\x01') -) +_CLIENT_METADATA = (('client-md-key', 'client-md-key'), + ('client-md-key-bin', b'\x00\x01')) _SERVER_INITIAL_METADATA = ( ('server-initial-md-key', 'server-initial-md-value'), - ('server-initial-md-key-bin', b'\x00\x02') -) + ('server-initial-md-key-bin', b'\x00\x02')) _SERVER_TRAILING_METADATA = ( ('server-trailing-md-key', 'server-trailing-md-value'), - ('server-trailing-md-key-bin', b'\x00\x03') -) + ('server-trailing-md-key-bin', b'\x00\x03')) def user_agent(metadata): - for key, val in metadata: - if key == 'user-agent': - return val - raise KeyError('No user agent!') + for key, val in metadata: + if key == 'user-agent': + return val + raise KeyError('No user agent!') def validate_client_metadata(test, servicer_context): - test.assertTrue(test_common.metadata_transmitted( - _CLIENT_METADATA, servicer_context.invocation_metadata())) - test.assertTrue(user_agent(servicer_context.invocation_metadata()) - .startswith('primary-agent ' + _USER_AGENT)) - test.assertTrue(user_agent(servicer_context.invocation_metadata()) - .endswith('secondary-agent')) + test.assertTrue( + test_common.metadata_transmitted( + _CLIENT_METADATA, servicer_context.invocation_metadata())) + test.assertTrue( + user_agent(servicer_context.invocation_metadata()) + .startswith('primary-agent ' + _USER_AGENT)) + test.assertTrue( + user_agent(servicer_context.invocation_metadata()) + .endswith('secondary-agent')) def handle_unary_unary(test, request, servicer_context): - validate_client_metadata(test, servicer_context) - servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) - servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - return _RESPONSE + validate_client_metadata(test, servicer_context) + servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) + servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + return _RESPONSE def handle_unary_stream(test, request, servicer_context): - validate_client_metadata(test, servicer_context) - servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) - servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - for _ in range(test_constants.STREAM_LENGTH): - yield _RESPONSE + validate_client_metadata(test, servicer_context) + servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) + servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + for _ in range(test_constants.STREAM_LENGTH): + yield _RESPONSE def handle_stream_unary(test, request_iterator, servicer_context): - validate_client_metadata(test, servicer_context) - servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) - servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - # TODO(issue:#6891) We should be able to remove this loop - for request in request_iterator: - pass - return _RESPONSE + validate_client_metadata(test, servicer_context) + servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) + servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + # TODO(issue:#6891) We should be able to remove this loop + for request in request_iterator: + pass + return _RESPONSE def handle_stream_stream(test, request_iterator, servicer_context): - validate_client_metadata(test, servicer_context) - servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) - servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) - # TODO(issue:#6891) We should be able to remove this loop, - # and replace with return; yield - for request in request_iterator: - yield _RESPONSE + validate_client_metadata(test, servicer_context) + servicer_context.send_initial_metadata(_SERVER_INITIAL_METADATA) + servicer_context.set_trailing_metadata(_SERVER_TRAILING_METADATA) + # TODO(issue:#6891) We should be able to remove this loop, + # and replace with return; yield + for request in request_iterator: + yield _RESPONSE class _MethodHandler(grpc.RpcMethodHandler): - def __init__(self, test, request_streaming, response_streaming): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = None - self.response_serializer = None - self.unary_unary = None - self.unary_stream = None - self.stream_unary = None - self.stream_stream = None - if self.request_streaming and self.response_streaming: - self.stream_stream = lambda x, y: handle_stream_stream(test, x, y) - elif self.request_streaming: - self.stream_unary = lambda x, y: handle_stream_unary(test, x, y) - elif self.response_streaming: - self.unary_stream = lambda x, y: handle_unary_stream(test, x, y) - else: - self.unary_unary = lambda x, y: handle_unary_unary(test, x, y) + def __init__(self, test, request_streaming, response_streaming): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = None + self.response_serializer = None + self.unary_unary = None + self.unary_stream = None + self.stream_unary = None + self.stream_stream = None + if self.request_streaming and self.response_streaming: + self.stream_stream = lambda x, y: handle_stream_stream(test, x, y) + elif self.request_streaming: + self.stream_unary = lambda x, y: handle_stream_unary(test, x, y) + elif self.response_streaming: + self.unary_stream = lambda x, y: handle_unary_stream(test, x, y) + else: + self.unary_unary = lambda x, y: handle_unary_unary(test, x, y) class _GenericHandler(grpc.GenericRpcHandler): - def __init__(self, test): - self._test = test + def __init__(self, test): + self._test = test - def service(self, handler_call_details): - if handler_call_details.method == _UNARY_UNARY: - return _MethodHandler(self._test, False, False) - elif handler_call_details.method == _UNARY_STREAM: - return _MethodHandler(self._test, False, True) - elif handler_call_details.method == _STREAM_UNARY: - return _MethodHandler(self._test, True, False) - elif handler_call_details.method == _STREAM_STREAM: - return _MethodHandler(self._test, True, True) - else: - return None + def service(self, handler_call_details): + if handler_call_details.method == _UNARY_UNARY: + return _MethodHandler(self._test, False, False) + elif handler_call_details.method == _UNARY_STREAM: + return _MethodHandler(self._test, False, True) + elif handler_call_details.method == _STREAM_UNARY: + return _MethodHandler(self._test, True, False) + elif handler_call_details.method == _STREAM_STREAM: + return _MethodHandler(self._test, True, True) + else: + return None class MetadataTest(unittest.TestCase): - def setUp(self): - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server( - self._server_pool, handlers=(_GenericHandler(weakref.proxy(self)),)) - port = self._server.add_insecure_port('[::]:0') - self._server.start() - self._channel = grpc.insecure_channel('localhost:%d' % port, - options=_CHANNEL_ARGS) - - def tearDown(self): - self._server.stop(0) - - def testUnaryUnary(self): - multi_callable = self._channel.unary_unary(_UNARY_UNARY) - unused_response, call = multi_callable.with_call( - _REQUEST, metadata=_CLIENT_METADATA) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - - def testUnaryStream(self): - multi_callable = self._channel.unary_stream(_UNARY_STREAM) - call = multi_callable(_REQUEST, metadata=_CLIENT_METADATA) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - for _ in call: - pass - self.assertTrue(test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - - def testStreamUnary(self): - multi_callable = self._channel.stream_unary(_STREAM_UNARY) - unused_response, call = multi_callable.with_call( - iter([_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) - - def testStreamStream(self): - multi_callable = self._channel.stream_stream(_STREAM_STREAM) - call = multi_callable(iter([_REQUEST] * test_constants.STREAM_LENGTH), - metadata=_CLIENT_METADATA) - self.assertTrue(test_common.metadata_transmitted( - _SERVER_INITIAL_METADATA, call.initial_metadata())) - for _ in call: - pass - self.assertTrue(test_common.metadata_transmitted( - _SERVER_TRAILING_METADATA, call.trailing_metadata())) + def setUp(self): + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + self._server = grpc.server( + self._server_pool, handlers=(_GenericHandler(weakref.proxy(self)),)) + port = self._server.add_insecure_port('[::]:0') + self._server.start() + self._channel = grpc.insecure_channel( + 'localhost:%d' % port, options=_CHANNEL_ARGS) + + def tearDown(self): + self._server.stop(0) + + def testUnaryUnary(self): + multi_callable = self._channel.unary_unary(_UNARY_UNARY) + unused_response, call = multi_callable.with_call( + _REQUEST, metadata=_CLIENT_METADATA) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + + def testUnaryStream(self): + multi_callable = self._channel.unary_stream(_UNARY_STREAM) + call = multi_callable(_REQUEST, metadata=_CLIENT_METADATA) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + for _ in call: + pass + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + + def testStreamUnary(self): + multi_callable = self._channel.stream_unary(_STREAM_UNARY) + unused_response, call = multi_callable.with_call( + iter([_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) + + def testStreamStream(self): + multi_callable = self._channel.stream_stream(_STREAM_STREAM) + call = multi_callable( + iter([_REQUEST] * test_constants.STREAM_LENGTH), + metadata=_CLIENT_METADATA) + self.assertTrue( + test_common.metadata_transmitted(_SERVER_INITIAL_METADATA, + call.initial_metadata())) + for _ in call: + pass + self.assertTrue( + test_common.metadata_transmitted(_SERVER_TRAILING_METADATA, + call.trailing_metadata())) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_rpc_test.py b/src/python/grpcio_tests/tests/unit/_rpc_test.py index eb00156da51..2cf6dfea620 100644 --- a/src/python/grpcio_tests/tests/unit/_rpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_rpc_test.py @@ -26,7 +26,6 @@ # 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. - """Test of RPCs made against gRPC Python's application-layer API.""" import itertools @@ -53,742 +52,797 @@ _STREAM_STREAM = '/test/StreamStream' class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._value = None - self._called = False + def __init__(self): + self._condition = threading.Condition() + self._value = None + self._called = False - def __call__(self, value): - with self._condition: - self._value = value - self._called = True - self._condition.notify_all() + def __call__(self, value): + with self._condition: + self._value = value + self._called = True + self._condition.notify_all() - def value(self): - with self._condition: - while not self._called: - self._condition.wait() - return self._value + def value(self): + with self._condition: + while not self._called: + self._condition.wait() + return self._value class _Handler(object): - def __init__(self, control): - self._control = control - - def handle_unary_unary(self, request, servicer_context): - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - return request - - def handle_unary_stream(self, request, servicer_context): - for _ in range(test_constants.STREAM_LENGTH): - self._control.control() - yield request - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - - def handle_stream_unary(self, request_iterator, servicer_context): - if servicer_context is not None: - servicer_context.invocation_metadata() - self._control.control() - response_elements = [] - for request in request_iterator: - self._control.control() - response_elements.append(request) - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - return b''.join(response_elements) - - def handle_stream_stream(self, request_iterator, servicer_context): - self._control.control() - if servicer_context is not None: - servicer_context.set_trailing_metadata((('testkey', 'testvalue',),)) - for request in request_iterator: - self._control.control() - yield request - self._control.control() + def __init__(self, control): + self._control = control + + def handle_unary_unary(self, request, servicer_context): + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + return request + + def handle_unary_stream(self, request, servicer_context): + for _ in range(test_constants.STREAM_LENGTH): + self._control.control() + yield request + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + + def handle_stream_unary(self, request_iterator, servicer_context): + if servicer_context is not None: + servicer_context.invocation_metadata() + self._control.control() + response_elements = [] + for request in request_iterator: + self._control.control() + response_elements.append(request) + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + return b''.join(response_elements) + + def handle_stream_stream(self, request_iterator, servicer_context): + self._control.control() + if servicer_context is not None: + servicer_context.set_trailing_metadata((( + 'testkey', + 'testvalue',),)) + for request in request_iterator: + self._control.control() + yield request + self._control.control() class _MethodHandler(grpc.RpcMethodHandler): - def __init__( - self, request_streaming, response_streaming, request_deserializer, - response_serializer, unary_unary, unary_stream, stream_unary, - stream_stream): - self.request_streaming = request_streaming - self.response_streaming = response_streaming - self.request_deserializer = request_deserializer - self.response_serializer = response_serializer - self.unary_unary = unary_unary - self.unary_stream = unary_stream - self.stream_unary = stream_unary - self.stream_stream = stream_stream + def __init__(self, request_streaming, response_streaming, + request_deserializer, response_serializer, unary_unary, + unary_stream, stream_unary, stream_stream): + self.request_streaming = request_streaming + self.response_streaming = response_streaming + self.request_deserializer = request_deserializer + self.response_serializer = response_serializer + self.unary_unary = unary_unary + self.unary_stream = unary_stream + self.stream_unary = stream_unary + self.stream_stream = stream_stream class _GenericHandler(grpc.GenericRpcHandler): - def __init__(self, handler): - self._handler = handler - - def service(self, handler_call_details): - if handler_call_details.method == _UNARY_UNARY: - return _MethodHandler( - False, False, None, None, self._handler.handle_unary_unary, None, - None, None) - elif handler_call_details.method == _UNARY_STREAM: - return _MethodHandler( - False, True, _DESERIALIZE_REQUEST, _SERIALIZE_RESPONSE, None, - self._handler.handle_unary_stream, None, None) - elif handler_call_details.method == _STREAM_UNARY: - return _MethodHandler( - True, False, _DESERIALIZE_REQUEST, _SERIALIZE_RESPONSE, None, None, - self._handler.handle_stream_unary, None) - elif handler_call_details.method == _STREAM_STREAM: - return _MethodHandler( - True, True, None, None, None, None, None, - self._handler.handle_stream_stream) - else: - return None + def __init__(self, handler): + self._handler = handler + + def service(self, handler_call_details): + if handler_call_details.method == _UNARY_UNARY: + return _MethodHandler(False, False, None, None, + self._handler.handle_unary_unary, None, None, + None) + elif handler_call_details.method == _UNARY_STREAM: + return _MethodHandler(False, True, _DESERIALIZE_REQUEST, + _SERIALIZE_RESPONSE, None, + self._handler.handle_unary_stream, None, None) + elif handler_call_details.method == _STREAM_UNARY: + return _MethodHandler(True, False, _DESERIALIZE_REQUEST, + _SERIALIZE_RESPONSE, None, None, + self._handler.handle_stream_unary, None) + elif handler_call_details.method == _STREAM_STREAM: + return _MethodHandler(True, True, None, None, None, None, None, + self._handler.handle_stream_stream) + else: + return None def _unary_unary_multi_callable(channel): - return channel.unary_unary(_UNARY_UNARY) + return channel.unary_unary(_UNARY_UNARY) def _unary_stream_multi_callable(channel): - return channel.unary_stream( - _UNARY_STREAM, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.unary_stream( + _UNARY_STREAM, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_unary_multi_callable(channel): - return channel.stream_unary( - _STREAM_UNARY, - request_serializer=_SERIALIZE_REQUEST, - response_deserializer=_DESERIALIZE_RESPONSE) + return channel.stream_unary( + _STREAM_UNARY, + request_serializer=_SERIALIZE_REQUEST, + response_deserializer=_DESERIALIZE_RESPONSE) def _stream_stream_multi_callable(channel): - return channel.stream_stream(_STREAM_STREAM) + return channel.stream_stream(_STREAM_STREAM) class RPCTest(unittest.TestCase): - def setUp(self): - self._control = test_control.PauseFailControl() - self._handler = _Handler(self._control) - self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + def setUp(self): + self._control = test_control.PauseFailControl() + self._handler = _Handler(self._control) + self._server_pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - self._server = grpc.server(self._server_pool) - port = self._server.add_insecure_port('[::]:0') - self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),)) - self._server.start() + self._server = grpc.server(self._server_pool) + port = self._server.add_insecure_port('[::]:0') + self._server.add_generic_rpc_handlers((_GenericHandler(self._handler),)) + self._server.start() - self._channel = grpc.insecure_channel('localhost:%d' % port) - - def tearDown(self): - self._server.stop(None) - self._server_pool.shutdown(wait=True) - - def testUnrecognizedMethod(self): - request = b'abc' - - with self.assertRaises(grpc.RpcError) as exception_context: - self._channel.unary_unary('NoSuchMethod')(request) - - self.assertEqual( - grpc.StatusCode.UNIMPLEMENTED, exception_context.exception.code()) - - def testSuccessfulUnaryRequestBlockingUnaryResponse(self): - request = b'\x07\x08' - expected_response = self._handler.handle_unary_unary(request, None) - - multi_callable = _unary_unary_multi_callable(self._channel) - response = multi_callable( - request, metadata=( - ('test', 'SuccessfulUnaryRequestBlockingUnaryResponse'),)) - - self.assertEqual(expected_response, response) - - def testSuccessfulUnaryRequestBlockingUnaryResponseWithCall(self): - request = b'\x07\x08' - expected_response = self._handler.handle_unary_unary(request, None) - - multi_callable = _unary_unary_multi_callable(self._channel) - response, call = multi_callable.with_call( - request, metadata=( - ('test', 'SuccessfulUnaryRequestBlockingUnaryResponseWithCall'),)) - - self.assertEqual(expected_response, response) - self.assertIs(grpc.StatusCode.OK, call.code()) - - def testSuccessfulUnaryRequestFutureUnaryResponse(self): - request = b'\x07\x08' - expected_response = self._handler.handle_unary_unary(request, None) - - multi_callable = _unary_unary_multi_callable(self._channel) - response_future = multi_callable.future( - request, metadata=( - ('test', 'SuccessfulUnaryRequestFutureUnaryResponse'),)) - response = response_future.result() - - self.assertIsInstance(response_future, grpc.Future) - self.assertIsInstance(response_future, grpc.Call) - self.assertEqual(expected_response, response) - self.assertIsNone(response_future.exception()) - self.assertIsNone(response_future.traceback()) - - def testSuccessfulUnaryRequestStreamResponse(self): - request = b'\x37\x58' - expected_responses = tuple(self._handler.handle_unary_stream(request, None)) - - multi_callable = _unary_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request, - metadata=(('test', 'SuccessfulUnaryRequestStreamResponse'),)) - responses = tuple(response_iterator) - - self.assertSequenceEqual(expected_responses, responses) - - def testSuccessfulStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - expected_response = self._handler.handle_stream_unary(iter(requests), None) - request_iterator = iter(requests) - - multi_callable = _stream_unary_multi_callable(self._channel) - response = multi_callable( - request_iterator, - metadata=(('test', 'SuccessfulStreamRequestBlockingUnaryResponse'),)) - - self.assertEqual(expected_response, response) - - def testSuccessfulStreamRequestBlockingUnaryResponseWithCall(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - expected_response = self._handler.handle_stream_unary(iter(requests), None) - request_iterator = iter(requests) - - multi_callable = _stream_unary_multi_callable(self._channel) - response, call = multi_callable.with_call( - request_iterator, - metadata=( - ('test', 'SuccessfulStreamRequestBlockingUnaryResponseWithCall'), - )) - - self.assertEqual(expected_response, response) - self.assertIs(grpc.StatusCode.OK, call.code()) - - def testSuccessfulStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - expected_response = self._handler.handle_stream_unary(iter(requests), None) - request_iterator = iter(requests) - - multi_callable = _stream_unary_multi_callable(self._channel) - response_future = multi_callable.future( - request_iterator, - metadata=( - ('test', 'SuccessfulStreamRequestFutureUnaryResponse'),)) - response = response_future.result() - - self.assertEqual(expected_response, response) - self.assertIsNone(response_future.exception()) - self.assertIsNone(response_future.traceback()) - - def testSuccessfulStreamRequestStreamResponse(self): - requests = tuple(b'\x77\x58' for _ in range(test_constants.STREAM_LENGTH)) - expected_responses = tuple( - self._handler.handle_stream_stream(iter(requests), None)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request_iterator, - metadata=(('test', 'SuccessfulStreamRequestStreamResponse'),)) - responses = tuple(response_iterator) - - self.assertSequenceEqual(expected_responses, responses) - - def testSequentialInvocations(self): - first_request = b'\x07\x08' - second_request = b'\x0809' - expected_first_response = self._handler.handle_unary_unary( - first_request, None) - expected_second_response = self._handler.handle_unary_unary( - second_request, None) - - multi_callable = _unary_unary_multi_callable(self._channel) - first_response = multi_callable( - first_request, metadata=(('test', 'SequentialInvocations'),)) - second_response = multi_callable( - second_request, metadata=(('test', 'SequentialInvocations'),)) - - self.assertEqual(expected_first_response, first_response) - self.assertEqual(expected_second_response, second_response) - - def testConcurrentBlockingInvocations(self): - pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - expected_response = self._handler.handle_stream_unary(iter(requests), None) - expected_responses = [expected_response] * test_constants.THREAD_CONCURRENCY - response_futures = [None] * test_constants.THREAD_CONCURRENCY - - multi_callable = _stream_unary_multi_callable(self._channel) - for index in range(test_constants.THREAD_CONCURRENCY): - request_iterator = iter(requests) - response_future = pool.submit( - multi_callable, request_iterator, - metadata=(('test', 'ConcurrentBlockingInvocations'),)) - response_futures[index] = response_future - responses = tuple( - response_future.result() for response_future in response_futures) - - pool.shutdown(wait=True) - self.assertSequenceEqual(expected_responses, responses) - - def testConcurrentFutureInvocations(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - expected_response = self._handler.handle_stream_unary(iter(requests), None) - expected_responses = [expected_response] * test_constants.THREAD_CONCURRENCY - response_futures = [None] * test_constants.THREAD_CONCURRENCY - - multi_callable = _stream_unary_multi_callable(self._channel) - for index in range(test_constants.THREAD_CONCURRENCY): - request_iterator = iter(requests) - response_future = multi_callable.future( - request_iterator, - metadata=(('test', 'ConcurrentFutureInvocations'),)) - response_futures[index] = response_future - responses = tuple( - response_future.result() for response_future in response_futures) - - self.assertSequenceEqual(expected_responses, responses) - - def testWaitingForSomeButNotAllConcurrentFutureInvocations(self): - pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - request = b'\x67\x68' - expected_response = self._handler.handle_unary_unary(request, None) - response_futures = [None] * test_constants.THREAD_CONCURRENCY - lock = threading.Lock() - test_is_running_cell = [True] - def wrap_future(future): - def wrap(): - try: - return future.result() - except grpc.RpcError: - with lock: - if test_is_running_cell[0]: - raise - return None - return wrap - - multi_callable = _unary_unary_multi_callable(self._channel) - for index in range(test_constants.THREAD_CONCURRENCY): - inner_response_future = multi_callable.future( - request, - metadata=( - ('test', - 'WaitingForSomeButNotAllConcurrentFutureInvocations'),)) - outer_response_future = pool.submit(wrap_future(inner_response_future)) - response_futures[index] = outer_response_future - - some_completed_response_futures_iterator = itertools.islice( - futures.as_completed(response_futures), - test_constants.THREAD_CONCURRENCY // 2) - for response_future in some_completed_response_futures_iterator: - self.assertEqual(expected_response, response_future.result()) - with lock: - test_is_running_cell[0] = False - - def testConsumingOneStreamResponseUnaryRequest(self): - request = b'\x57\x38' - - multi_callable = _unary_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request, - metadata=( - ('test', 'ConsumingOneStreamResponseUnaryRequest'),)) - next(response_iterator) - - def testConsumingSomeButNotAllStreamResponsesUnaryRequest(self): - request = b'\x57\x38' - - multi_callable = _unary_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request, - metadata=( - ('test', 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) - for _ in range(test_constants.STREAM_LENGTH // 2): - next(response_iterator) - - def testConsumingSomeButNotAllStreamResponsesStreamRequest(self): - requests = tuple(b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request_iterator, - metadata=( - ('test', 'ConsumingSomeButNotAllStreamResponsesStreamRequest'),)) - for _ in range(test_constants.STREAM_LENGTH // 2): - next(response_iterator) - - def testConsumingTooManyStreamResponsesStreamRequest(self): - requests = tuple(b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - response_iterator = multi_callable( - request_iterator, - metadata=( - ('test', 'ConsumingTooManyStreamResponsesStreamRequest'),)) - for _ in range(test_constants.STREAM_LENGTH): - next(response_iterator) - for _ in range(test_constants.STREAM_LENGTH): - with self.assertRaises(StopIteration): - next(response_iterator) + self._channel = grpc.insecure_channel('localhost:%d' % port) - self.assertIsNotNone(response_iterator.initial_metadata()) - self.assertIs(grpc.StatusCode.OK, response_iterator.code()) - self.assertIsNotNone(response_iterator.details()) - self.assertIsNotNone(response_iterator.trailing_metadata()) - - def testCancelledUnaryRequestUnaryResponse(self): - request = b'\x07\x17' - - multi_callable = _unary_unary_multi_callable(self._channel) - with self._control.pause(): - response_future = multi_callable.future( - request, - metadata=(('test', 'CancelledUnaryRequestUnaryResponse'),)) - response_future.cancel() - - self.assertTrue(response_future.cancelled()) - with self.assertRaises(grpc.FutureCancelledError): - response_future.result() - with self.assertRaises(grpc.FutureCancelledError): - response_future.exception() - with self.assertRaises(grpc.FutureCancelledError): - response_future.traceback() - self.assertIs(grpc.StatusCode.CANCELLED, response_future.code()) - - def testCancelledUnaryRequestStreamResponse(self): - request = b'\x07\x19' - - multi_callable = _unary_stream_multi_callable(self._channel) - with self._control.pause(): - response_iterator = multi_callable( - request, - metadata=(('test', 'CancelledUnaryRequestStreamResponse'),)) - self._control.block_until_paused() - response_iterator.cancel() - - with self.assertRaises(grpc.RpcError) as exception_context: - next(response_iterator) - self.assertIs(grpc.StatusCode.CANCELLED, exception_context.exception.code()) - self.assertIsNotNone(response_iterator.initial_metadata()) - self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code()) - self.assertIsNotNone(response_iterator.details()) - self.assertIsNotNone(response_iterator.trailing_metadata()) - - def testCancelledStreamRequestUnaryResponse(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_unary_multi_callable(self._channel) - with self._control.pause(): - response_future = multi_callable.future( - request_iterator, - metadata=(('test', 'CancelledStreamRequestUnaryResponse'),)) - self._control.block_until_paused() - response_future.cancel() - - self.assertTrue(response_future.cancelled()) - with self.assertRaises(grpc.FutureCancelledError): - response_future.result() - with self.assertRaises(grpc.FutureCancelledError): - response_future.exception() - with self.assertRaises(grpc.FutureCancelledError): - response_future.traceback() - self.assertIsNotNone(response_future.initial_metadata()) - self.assertIs(grpc.StatusCode.CANCELLED, response_future.code()) - self.assertIsNotNone(response_future.details()) - self.assertIsNotNone(response_future.trailing_metadata()) - - def testCancelledStreamRequestStreamResponse(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - with self._control.pause(): - response_iterator = multi_callable( - request_iterator, - metadata=(('test', 'CancelledStreamRequestStreamResponse'),)) - response_iterator.cancel() - - with self.assertRaises(grpc.RpcError): - next(response_iterator) - self.assertIsNotNone(response_iterator.initial_metadata()) - self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code()) - self.assertIsNotNone(response_iterator.details()) - self.assertIsNotNone(response_iterator.trailing_metadata()) - - def testExpiredUnaryRequestBlockingUnaryResponse(self): - request = b'\x07\x17' - - multi_callable = _unary_unary_multi_callable(self._channel) - with self._control.pause(): - with self.assertRaises(grpc.RpcError) as exception_context: - multi_callable.with_call( - request, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredUnaryRequestBlockingUnaryResponse'),)) - - self.assertIsInstance(exception_context.exception, grpc.Call) - self.assertIsNotNone(exception_context.exception.initial_metadata()) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIsNotNone(exception_context.exception.details()) - self.assertIsNotNone(exception_context.exception.trailing_metadata()) - - def testExpiredUnaryRequestFutureUnaryResponse(self): - request = b'\x07\x17' - callback = _Callback() - - multi_callable = _unary_unary_multi_callable(self._channel) - with self._control.pause(): - response_future = multi_callable.future( - request, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredUnaryRequestFutureUnaryResponse'),)) - response_future.add_done_callback(callback) - value_passed_to_callback = callback.value() - - self.assertIs(response_future, value_passed_to_callback) - self.assertIsNotNone(response_future.initial_metadata()) - self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) - self.assertIsNotNone(response_future.details()) - self.assertIsNotNone(response_future.trailing_metadata()) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIsInstance(response_future.exception(), grpc.RpcError) - self.assertIsNotNone(response_future.traceback()) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, response_future.exception().code()) - - def testExpiredUnaryRequestStreamResponse(self): - request = b'\x07\x19' - - multi_callable = _unary_stream_multi_callable(self._channel) - with self._control.pause(): - with self.assertRaises(grpc.RpcError) as exception_context: - response_iterator = multi_callable( - request, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredUnaryRequestStreamResponse'),)) - next(response_iterator) + def tearDown(self): + self._server.stop(None) + self._server_pool.shutdown(wait=True) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_iterator.code()) + def testUnrecognizedMethod(self): + request = b'abc' - def testExpiredStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x07\x08' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) + with self.assertRaises(grpc.RpcError) as exception_context: + self._channel.unary_unary('NoSuchMethod')(request) - multi_callable = _stream_unary_multi_callable(self._channel) - with self._control.pause(): - with self.assertRaises(grpc.RpcError) as exception_context: - multi_callable( - request_iterator, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredStreamRequestBlockingUnaryResponse'),)) - - self.assertIsInstance(exception_context.exception, grpc.RpcError) - self.assertIsInstance(exception_context.exception, grpc.Call) - self.assertIsNotNone(exception_context.exception.initial_metadata()) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIsNotNone(exception_context.exception.details()) - self.assertIsNotNone(exception_context.exception.trailing_metadata()) - - def testExpiredStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - callback = _Callback() - - multi_callable = _stream_unary_multi_callable(self._channel) - with self._control.pause(): - response_future = multi_callable.future( - request_iterator, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredStreamRequestFutureUnaryResponse'),)) - with self.assertRaises(grpc.FutureTimeoutError): - response_future.result(timeout=test_constants.SHORT_TIMEOUT / 2.0) - response_future.add_done_callback(callback) - value_passed_to_callback = callback.value() - - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIsInstance(response_future.exception(), grpc.RpcError) - self.assertIsNotNone(response_future.traceback()) - self.assertIs(response_future, value_passed_to_callback) - self.assertIsNotNone(response_future.initial_metadata()) - self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) - self.assertIsNotNone(response_future.details()) - self.assertIsNotNone(response_future.trailing_metadata()) - - def testExpiredStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x18' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - with self._control.pause(): - with self.assertRaises(grpc.RpcError) as exception_context: - response_iterator = multi_callable( - request_iterator, timeout=test_constants.SHORT_TIMEOUT, - metadata=(('test', 'ExpiredStreamRequestStreamResponse'),)) - next(response_iterator) + self.assertEqual(grpc.StatusCode.UNIMPLEMENTED, + exception_context.exception.code()) + + def testSuccessfulUnaryRequestBlockingUnaryResponse(self): + request = b'\x07\x08' + expected_response = self._handler.handle_unary_unary(request, None) + + multi_callable = _unary_unary_multi_callable(self._channel) + response = multi_callable( + request, + metadata=(('test', 'SuccessfulUnaryRequestBlockingUnaryResponse'),)) + + self.assertEqual(expected_response, response) - self.assertIs( - grpc.StatusCode.DEADLINE_EXCEEDED, exception_context.exception.code()) - self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_iterator.code()) + def testSuccessfulUnaryRequestBlockingUnaryResponseWithCall(self): + request = b'\x07\x08' + expected_response = self._handler.handle_unary_unary(request, None) - def testFailedUnaryRequestBlockingUnaryResponse(self): - request = b'\x37\x17' + multi_callable = _unary_unary_multi_callable(self._channel) + response, call = multi_callable.with_call( + request, + metadata=(('test', + 'SuccessfulUnaryRequestBlockingUnaryResponseWithCall'),)) + + self.assertEqual(expected_response, response) + self.assertIs(grpc.StatusCode.OK, call.code()) + + def testSuccessfulUnaryRequestFutureUnaryResponse(self): + request = b'\x07\x08' + expected_response = self._handler.handle_unary_unary(request, None) - multi_callable = _unary_unary_multi_callable(self._channel) - with self._control.fail(): - with self.assertRaises(grpc.RpcError) as exception_context: - multi_callable.with_call( + multi_callable = _unary_unary_multi_callable(self._channel) + response_future = multi_callable.future( request, - metadata=(('test', 'FailedUnaryRequestBlockingUnaryResponse'),)) - - self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) - - def testFailedUnaryRequestFutureUnaryResponse(self): - request = b'\x37\x17' - callback = _Callback() - - multi_callable = _unary_unary_multi_callable(self._channel) - with self._control.fail(): - response_future = multi_callable.future( - request, - metadata=(('test', 'FailedUnaryRequestFutureUnaryResponse'),)) - response_future.add_done_callback(callback) - value_passed_to_callback = callback.value() - - self.assertIsInstance(response_future, grpc.Future) - self.assertIsInstance(response_future, grpc.Call) - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIs( - grpc.StatusCode.UNKNOWN, exception_context.exception.code()) - self.assertIsInstance(response_future.exception(), grpc.RpcError) - self.assertIsNotNone(response_future.traceback()) - self.assertIs(grpc.StatusCode.UNKNOWN, response_future.exception().code()) - self.assertIs(response_future, value_passed_to_callback) - - def testFailedUnaryRequestStreamResponse(self): - request = b'\x37\x17' - - multi_callable = _unary_stream_multi_callable(self._channel) - with self.assertRaises(grpc.RpcError) as exception_context: - with self._control.fail(): + metadata=(('test', 'SuccessfulUnaryRequestFutureUnaryResponse'),)) + response = response_future.result() + + self.assertIsInstance(response_future, grpc.Future) + self.assertIsInstance(response_future, grpc.Call) + self.assertEqual(expected_response, response) + self.assertIsNone(response_future.exception()) + self.assertIsNone(response_future.traceback()) + + def testSuccessfulUnaryRequestStreamResponse(self): + request = b'\x37\x58' + expected_responses = tuple( + self._handler.handle_unary_stream(request, None)) + + multi_callable = _unary_stream_multi_callable(self._channel) response_iterator = multi_callable( request, - metadata=(('test', 'FailedUnaryRequestStreamResponse'),)) - next(response_iterator) + metadata=(('test', 'SuccessfulUnaryRequestStreamResponse'),)) + responses = tuple(response_iterator) - self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) + self.assertSequenceEqual(expected_responses, responses) - def testFailedStreamRequestBlockingUnaryResponse(self): - requests = tuple(b'\x47\x58' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) + def testSuccessfulStreamRequestBlockingUnaryResponse(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + expected_response = self._handler.handle_stream_unary( + iter(requests), None) + request_iterator = iter(requests) - multi_callable = _stream_unary_multi_callable(self._channel) - with self._control.fail(): - with self.assertRaises(grpc.RpcError) as exception_context: - multi_callable( + multi_callable = _stream_unary_multi_callable(self._channel) + response = multi_callable( + request_iterator, + metadata=( + ('test', 'SuccessfulStreamRequestBlockingUnaryResponse'),)) + + self.assertEqual(expected_response, response) + + def testSuccessfulStreamRequestBlockingUnaryResponseWithCall(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + expected_response = self._handler.handle_stream_unary( + iter(requests), None) + request_iterator = iter(requests) + + multi_callable = _stream_unary_multi_callable(self._channel) + response, call = multi_callable.with_call( + request_iterator, + metadata=( + ('test', + 'SuccessfulStreamRequestBlockingUnaryResponseWithCall'),)) + + self.assertEqual(expected_response, response) + self.assertIs(grpc.StatusCode.OK, call.code()) + + def testSuccessfulStreamRequestFutureUnaryResponse(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + expected_response = self._handler.handle_stream_unary( + iter(requests), None) + request_iterator = iter(requests) + + multi_callable = _stream_unary_multi_callable(self._channel) + response_future = multi_callable.future( request_iterator, - metadata=(('test', 'FailedStreamRequestBlockingUnaryResponse'),)) - - self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) - - def testFailedStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - callback = _Callback() - - multi_callable = _stream_unary_multi_callable(self._channel) - with self._control.fail(): - response_future = multi_callable.future( - request_iterator, - metadata=(('test', 'FailedStreamRequestFutureUnaryResponse'),)) - response_future.add_done_callback(callback) - value_passed_to_callback = callback.value() - - with self.assertRaises(grpc.RpcError) as exception_context: - response_future.result() - self.assertIs(grpc.StatusCode.UNKNOWN, response_future.code()) - self.assertIs( - grpc.StatusCode.UNKNOWN, exception_context.exception.code()) - self.assertIsInstance(response_future.exception(), grpc.RpcError) - self.assertIsNotNone(response_future.traceback()) - self.assertIs(response_future, value_passed_to_callback) - - def testFailedStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) - - multi_callable = _stream_stream_multi_callable(self._channel) - with self._control.fail(): - with self.assertRaises(grpc.RpcError) as exception_context: + metadata=(('test', 'SuccessfulStreamRequestFutureUnaryResponse'),)) + response = response_future.result() + + self.assertEqual(expected_response, response) + self.assertIsNone(response_future.exception()) + self.assertIsNone(response_future.traceback()) + + def testSuccessfulStreamRequestStreamResponse(self): + requests = tuple(b'\x77\x58' + for _ in range(test_constants.STREAM_LENGTH)) + expected_responses = tuple( + self._handler.handle_stream_stream(iter(requests), None)) + request_iterator = iter(requests) + + multi_callable = _stream_stream_multi_callable(self._channel) response_iterator = multi_callable( request_iterator, - metadata=(('test', 'FailedStreamRequestStreamResponse'),)) - tuple(response_iterator) + metadata=(('test', 'SuccessfulStreamRequestStreamResponse'),)) + responses = tuple(response_iterator) + + self.assertSequenceEqual(expected_responses, responses) + + def testSequentialInvocations(self): + first_request = b'\x07\x08' + second_request = b'\x0809' + expected_first_response = self._handler.handle_unary_unary( + first_request, None) + expected_second_response = self._handler.handle_unary_unary( + second_request, None) + + multi_callable = _unary_unary_multi_callable(self._channel) + first_response = multi_callable( + first_request, metadata=(('test', 'SequentialInvocations'),)) + second_response = multi_callable( + second_request, metadata=(('test', 'SequentialInvocations'),)) + + self.assertEqual(expected_first_response, first_response) + self.assertEqual(expected_second_response, second_response) + + def testConcurrentBlockingInvocations(self): + pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + expected_response = self._handler.handle_stream_unary( + iter(requests), None) + expected_responses = [expected_response + ] * test_constants.THREAD_CONCURRENCY + response_futures = [None] * test_constants.THREAD_CONCURRENCY + + multi_callable = _stream_unary_multi_callable(self._channel) + for index in range(test_constants.THREAD_CONCURRENCY): + request_iterator = iter(requests) + response_future = pool.submit( + multi_callable, + request_iterator, + metadata=(('test', 'ConcurrentBlockingInvocations'),)) + response_futures[index] = response_future + responses = tuple(response_future.result() + for response_future in response_futures) + + pool.shutdown(wait=True) + self.assertSequenceEqual(expected_responses, responses) + + def testConcurrentFutureInvocations(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + expected_response = self._handler.handle_stream_unary( + iter(requests), None) + expected_responses = [expected_response + ] * test_constants.THREAD_CONCURRENCY + response_futures = [None] * test_constants.THREAD_CONCURRENCY + + multi_callable = _stream_unary_multi_callable(self._channel) + for index in range(test_constants.THREAD_CONCURRENCY): + request_iterator = iter(requests) + response_future = multi_callable.future( + request_iterator, + metadata=(('test', 'ConcurrentFutureInvocations'),)) + response_futures[index] = response_future + responses = tuple(response_future.result() + for response_future in response_futures) + + self.assertSequenceEqual(expected_responses, responses) + + def testWaitingForSomeButNotAllConcurrentFutureInvocations(self): + pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + request = b'\x67\x68' + expected_response = self._handler.handle_unary_unary(request, None) + response_futures = [None] * test_constants.THREAD_CONCURRENCY + lock = threading.Lock() + test_is_running_cell = [True] + + def wrap_future(future): + + def wrap(): + try: + return future.result() + except grpc.RpcError: + with lock: + if test_is_running_cell[0]: + raise + return None + + return wrap + + multi_callable = _unary_unary_multi_callable(self._channel) + for index in range(test_constants.THREAD_CONCURRENCY): + inner_response_future = multi_callable.future( + request, + metadata=( + ('test', + 'WaitingForSomeButNotAllConcurrentFutureInvocations'),)) + outer_response_future = pool.submit( + wrap_future(inner_response_future)) + response_futures[index] = outer_response_future + + some_completed_response_futures_iterator = itertools.islice( + futures.as_completed(response_futures), + test_constants.THREAD_CONCURRENCY // 2) + for response_future in some_completed_response_futures_iterator: + self.assertEqual(expected_response, response_future.result()) + with lock: + test_is_running_cell[0] = False + + def testConsumingOneStreamResponseUnaryRequest(self): + request = b'\x57\x38' + + multi_callable = _unary_stream_multi_callable(self._channel) + response_iterator = multi_callable( + request, + metadata=(('test', 'ConsumingOneStreamResponseUnaryRequest'),)) + next(response_iterator) + + def testConsumingSomeButNotAllStreamResponsesUnaryRequest(self): + request = b'\x57\x38' + + multi_callable = _unary_stream_multi_callable(self._channel) + response_iterator = multi_callable( + request, + metadata=( + ('test', 'ConsumingSomeButNotAllStreamResponsesUnaryRequest'),)) + for _ in range(test_constants.STREAM_LENGTH // 2): + next(response_iterator) - self.assertIs(grpc.StatusCode.UNKNOWN, exception_context.exception.code()) - self.assertIs(grpc.StatusCode.UNKNOWN, response_iterator.code()) + def testConsumingSomeButNotAllStreamResponsesStreamRequest(self): + requests = tuple(b'\x67\x88' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) - def testIgnoredUnaryRequestFutureUnaryResponse(self): - request = b'\x37\x17' + multi_callable = _stream_stream_multi_callable(self._channel) + response_iterator = multi_callable( + request_iterator, + metadata=(('test', + 'ConsumingSomeButNotAllStreamResponsesStreamRequest'),)) + for _ in range(test_constants.STREAM_LENGTH // 2): + next(response_iterator) - multi_callable = _unary_unary_multi_callable(self._channel) - multi_callable.future( - request, - metadata=(('test', 'IgnoredUnaryRequestFutureUnaryResponse'),)) + def testConsumingTooManyStreamResponsesStreamRequest(self): + requests = tuple(b'\x67\x88' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) - def testIgnoredUnaryRequestStreamResponse(self): - request = b'\x37\x17' + multi_callable = _stream_stream_multi_callable(self._channel) + response_iterator = multi_callable( + request_iterator, + metadata=( + ('test', 'ConsumingTooManyStreamResponsesStreamRequest'),)) + for _ in range(test_constants.STREAM_LENGTH): + next(response_iterator) + for _ in range(test_constants.STREAM_LENGTH): + with self.assertRaises(StopIteration): + next(response_iterator) + + self.assertIsNotNone(response_iterator.initial_metadata()) + self.assertIs(grpc.StatusCode.OK, response_iterator.code()) + self.assertIsNotNone(response_iterator.details()) + self.assertIsNotNone(response_iterator.trailing_metadata()) + + def testCancelledUnaryRequestUnaryResponse(self): + request = b'\x07\x17' + + multi_callable = _unary_unary_multi_callable(self._channel) + with self._control.pause(): + response_future = multi_callable.future( + request, + metadata=(('test', 'CancelledUnaryRequestUnaryResponse'),)) + response_future.cancel() + + self.assertTrue(response_future.cancelled()) + with self.assertRaises(grpc.FutureCancelledError): + response_future.result() + with self.assertRaises(grpc.FutureCancelledError): + response_future.exception() + with self.assertRaises(grpc.FutureCancelledError): + response_future.traceback() + self.assertIs(grpc.StatusCode.CANCELLED, response_future.code()) + + def testCancelledUnaryRequestStreamResponse(self): + request = b'\x07\x19' + + multi_callable = _unary_stream_multi_callable(self._channel) + with self._control.pause(): + response_iterator = multi_callable( + request, + metadata=(('test', 'CancelledUnaryRequestStreamResponse'),)) + self._control.block_until_paused() + response_iterator.cancel() + + with self.assertRaises(grpc.RpcError) as exception_context: + next(response_iterator) + self.assertIs(grpc.StatusCode.CANCELLED, + exception_context.exception.code()) + self.assertIsNotNone(response_iterator.initial_metadata()) + self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code()) + self.assertIsNotNone(response_iterator.details()) + self.assertIsNotNone(response_iterator.trailing_metadata()) + + def testCancelledStreamRequestUnaryResponse(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_unary_multi_callable(self._channel) + with self._control.pause(): + response_future = multi_callable.future( + request_iterator, + metadata=(('test', 'CancelledStreamRequestUnaryResponse'),)) + self._control.block_until_paused() + response_future.cancel() + + self.assertTrue(response_future.cancelled()) + with self.assertRaises(grpc.FutureCancelledError): + response_future.result() + with self.assertRaises(grpc.FutureCancelledError): + response_future.exception() + with self.assertRaises(grpc.FutureCancelledError): + response_future.traceback() + self.assertIsNotNone(response_future.initial_metadata()) + self.assertIs(grpc.StatusCode.CANCELLED, response_future.code()) + self.assertIsNotNone(response_future.details()) + self.assertIsNotNone(response_future.trailing_metadata()) + + def testCancelledStreamRequestStreamResponse(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_stream_multi_callable(self._channel) + with self._control.pause(): + response_iterator = multi_callable( + request_iterator, + metadata=(('test', 'CancelledStreamRequestStreamResponse'),)) + response_iterator.cancel() + + with self.assertRaises(grpc.RpcError): + next(response_iterator) + self.assertIsNotNone(response_iterator.initial_metadata()) + self.assertIs(grpc.StatusCode.CANCELLED, response_iterator.code()) + self.assertIsNotNone(response_iterator.details()) + self.assertIsNotNone(response_iterator.trailing_metadata()) + + def testExpiredUnaryRequestBlockingUnaryResponse(self): + request = b'\x07\x17' + + multi_callable = _unary_unary_multi_callable(self._channel) + with self._control.pause(): + with self.assertRaises(grpc.RpcError) as exception_context: + multi_callable.with_call( + request, + timeout=test_constants.SHORT_TIMEOUT, + metadata=( + ('test', 'ExpiredUnaryRequestBlockingUnaryResponse'),)) + + self.assertIsInstance(exception_context.exception, grpc.Call) + self.assertIsNotNone(exception_context.exception.initial_metadata()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIsNotNone(exception_context.exception.details()) + self.assertIsNotNone(exception_context.exception.trailing_metadata()) + + def testExpiredUnaryRequestFutureUnaryResponse(self): + request = b'\x07\x17' + callback = _Callback() + + multi_callable = _unary_unary_multi_callable(self._channel) + with self._control.pause(): + response_future = multi_callable.future( + request, + timeout=test_constants.SHORT_TIMEOUT, + metadata=(('test', 'ExpiredUnaryRequestFutureUnaryResponse'),)) + response_future.add_done_callback(callback) + value_passed_to_callback = callback.value() + + self.assertIs(response_future, value_passed_to_callback) + self.assertIsNotNone(response_future.initial_metadata()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) + self.assertIsNotNone(response_future.details()) + self.assertIsNotNone(response_future.trailing_metadata()) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIsInstance(response_future.exception(), grpc.RpcError) + self.assertIsNotNone(response_future.traceback()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + response_future.exception().code()) + + def testExpiredUnaryRequestStreamResponse(self): + request = b'\x07\x19' + + multi_callable = _unary_stream_multi_callable(self._channel) + with self._control.pause(): + with self.assertRaises(grpc.RpcError) as exception_context: + response_iterator = multi_callable( + request, + timeout=test_constants.SHORT_TIMEOUT, + metadata=(('test', 'ExpiredUnaryRequestStreamResponse'),)) + next(response_iterator) + + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + response_iterator.code()) + + def testExpiredStreamRequestBlockingUnaryResponse(self): + requests = tuple(b'\x07\x08' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_unary_multi_callable(self._channel) + with self._control.pause(): + with self.assertRaises(grpc.RpcError) as exception_context: + multi_callable( + request_iterator, + timeout=test_constants.SHORT_TIMEOUT, + metadata=( + ('test', 'ExpiredStreamRequestBlockingUnaryResponse'),)) + + self.assertIsInstance(exception_context.exception, grpc.RpcError) + self.assertIsInstance(exception_context.exception, grpc.Call) + self.assertIsNotNone(exception_context.exception.initial_metadata()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIsNotNone(exception_context.exception.details()) + self.assertIsNotNone(exception_context.exception.trailing_metadata()) + + def testExpiredStreamRequestFutureUnaryResponse(self): + requests = tuple(b'\x07\x18' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + callback = _Callback() + + multi_callable = _stream_unary_multi_callable(self._channel) + with self._control.pause(): + response_future = multi_callable.future( + request_iterator, + timeout=test_constants.SHORT_TIMEOUT, + metadata=(('test', 'ExpiredStreamRequestFutureUnaryResponse'),)) + with self.assertRaises(grpc.FutureTimeoutError): + response_future.result(timeout=test_constants.SHORT_TIMEOUT / + 2.0) + response_future.add_done_callback(callback) + value_passed_to_callback = callback.value() + + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIsInstance(response_future.exception(), grpc.RpcError) + self.assertIsNotNone(response_future.traceback()) + self.assertIs(response_future, value_passed_to_callback) + self.assertIsNotNone(response_future.initial_metadata()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, response_future.code()) + self.assertIsNotNone(response_future.details()) + self.assertIsNotNone(response_future.trailing_metadata()) + + def testExpiredStreamRequestStreamResponse(self): + requests = tuple(b'\x67\x18' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_stream_multi_callable(self._channel) + with self._control.pause(): + with self.assertRaises(grpc.RpcError) as exception_context: + response_iterator = multi_callable( + request_iterator, + timeout=test_constants.SHORT_TIMEOUT, + metadata=(('test', 'ExpiredStreamRequestStreamResponse'),)) + next(response_iterator) + + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + exception_context.exception.code()) + self.assertIs(grpc.StatusCode.DEADLINE_EXCEEDED, + response_iterator.code()) + + def testFailedUnaryRequestBlockingUnaryResponse(self): + request = b'\x37\x17' + + multi_callable = _unary_unary_multi_callable(self._channel) + with self._control.fail(): + with self.assertRaises(grpc.RpcError) as exception_context: + multi_callable.with_call( + request, + metadata=( + ('test', 'FailedUnaryRequestBlockingUnaryResponse'),)) + + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + + def testFailedUnaryRequestFutureUnaryResponse(self): + request = b'\x37\x17' + callback = _Callback() + + multi_callable = _unary_unary_multi_callable(self._channel) + with self._control.fail(): + response_future = multi_callable.future( + request, + metadata=(('test', 'FailedUnaryRequestFutureUnaryResponse'),)) + response_future.add_done_callback(callback) + value_passed_to_callback = callback.value() + + self.assertIsInstance(response_future, grpc.Future) + self.assertIsInstance(response_future, grpc.Call) + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + self.assertIsInstance(response_future.exception(), grpc.RpcError) + self.assertIsNotNone(response_future.traceback()) + self.assertIs(grpc.StatusCode.UNKNOWN, + response_future.exception().code()) + self.assertIs(response_future, value_passed_to_callback) + + def testFailedUnaryRequestStreamResponse(self): + request = b'\x37\x17' + + multi_callable = _unary_stream_multi_callable(self._channel) + with self.assertRaises(grpc.RpcError) as exception_context: + with self._control.fail(): + response_iterator = multi_callable( + request, + metadata=(('test', 'FailedUnaryRequestStreamResponse'),)) + next(response_iterator) + + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + + def testFailedStreamRequestBlockingUnaryResponse(self): + requests = tuple(b'\x47\x58' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_unary_multi_callable(self._channel) + with self._control.fail(): + with self.assertRaises(grpc.RpcError) as exception_context: + multi_callable( + request_iterator, + metadata=( + ('test', 'FailedStreamRequestBlockingUnaryResponse'),)) + + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + + def testFailedStreamRequestFutureUnaryResponse(self): + requests = tuple(b'\x07\x18' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + callback = _Callback() + + multi_callable = _stream_unary_multi_callable(self._channel) + with self._control.fail(): + response_future = multi_callable.future( + request_iterator, + metadata=(('test', 'FailedStreamRequestFutureUnaryResponse'),)) + response_future.add_done_callback(callback) + value_passed_to_callback = callback.value() + + with self.assertRaises(grpc.RpcError) as exception_context: + response_future.result() + self.assertIs(grpc.StatusCode.UNKNOWN, response_future.code()) + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + self.assertIsInstance(response_future.exception(), grpc.RpcError) + self.assertIsNotNone(response_future.traceback()) + self.assertIs(response_future, value_passed_to_callback) + + def testFailedStreamRequestStreamResponse(self): + requests = tuple(b'\x67\x88' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) + + multi_callable = _stream_stream_multi_callable(self._channel) + with self._control.fail(): + with self.assertRaises(grpc.RpcError) as exception_context: + response_iterator = multi_callable( + request_iterator, + metadata=(('test', 'FailedStreamRequestStreamResponse'),)) + tuple(response_iterator) + + self.assertIs(grpc.StatusCode.UNKNOWN, + exception_context.exception.code()) + self.assertIs(grpc.StatusCode.UNKNOWN, response_iterator.code()) + + def testIgnoredUnaryRequestFutureUnaryResponse(self): + request = b'\x37\x17' + + multi_callable = _unary_unary_multi_callable(self._channel) + multi_callable.future( + request, + metadata=(('test', 'IgnoredUnaryRequestFutureUnaryResponse'),)) - multi_callable = _unary_stream_multi_callable(self._channel) - multi_callable( - request, - metadata=(('test', 'IgnoredUnaryRequestStreamResponse'),)) + def testIgnoredUnaryRequestStreamResponse(self): + request = b'\x37\x17' - def testIgnoredStreamRequestFutureUnaryResponse(self): - requests = tuple(b'\x07\x18' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) + multi_callable = _unary_stream_multi_callable(self._channel) + multi_callable( + request, metadata=(('test', 'IgnoredUnaryRequestStreamResponse'),)) + + def testIgnoredStreamRequestFutureUnaryResponse(self): + requests = tuple(b'\x07\x18' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) - multi_callable = _stream_unary_multi_callable(self._channel) - multi_callable.future( - request_iterator, - metadata=(('test', 'IgnoredStreamRequestFutureUnaryResponse'),)) + multi_callable = _stream_unary_multi_callable(self._channel) + multi_callable.future( + request_iterator, + metadata=(('test', 'IgnoredStreamRequestFutureUnaryResponse'),)) - def testIgnoredStreamRequestStreamResponse(self): - requests = tuple(b'\x67\x88' for _ in range(test_constants.STREAM_LENGTH)) - request_iterator = iter(requests) + def testIgnoredStreamRequestStreamResponse(self): + requests = tuple(b'\x67\x88' + for _ in range(test_constants.STREAM_LENGTH)) + request_iterator = iter(requests) - multi_callable = _stream_stream_multi_callable(self._channel) - multi_callable( - request_iterator, - metadata=(('test', 'IgnoredStreamRequestStreamResponse'),)) + multi_callable = _stream_stream_multi_callable(self._channel) + multi_callable( + request_iterator, + metadata=(('test', 'IgnoredStreamRequestStreamResponse'),)) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_sanity/__init__.py b/src/python/grpcio_tests/tests/unit/_sanity/__init__.py index 2f88fa04122..100a624dc9c 100644 --- a/src/python/grpcio_tests/tests/unit/_sanity/__init__.py +++ b/src/python/grpcio_tests/tests/unit/_sanity/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py b/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py index e9fdf217aef..0fbe6a2b5d0 100644 --- a/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py +++ b/src/python/grpcio_tests/tests/unit/_sanity/_sanity_test.py @@ -38,21 +38,23 @@ import tests class Sanity(unittest.TestCase): - def testTestsJsonUpToDate(self): - """Autodiscovers all test suites and checks that tests.json is up to date""" - loader = tests.Loader() - loader.loadTestsFromNames(['tests']) - test_suite_names = [ - test_case_class.id().rsplit('.', 1)[0] - for test_case_class in tests._loader.iterate_suite_cases(loader.suite)] - test_suite_names = sorted(set(test_suite_names)) - - tests_json_string = pkg_resources.resource_string('tests', 'tests.json') - if six.PY3: - tests_json_string = tests_json_string.decode() - tests_json = json.loads(tests_json_string) - self.assertListEqual(test_suite_names, tests_json) + def testTestsJsonUpToDate(self): + """Autodiscovers all test suites and checks that tests.json is up to date""" + loader = tests.Loader() + loader.loadTestsFromNames(['tests']) + test_suite_names = [ + test_case_class.id().rsplit('.', 1)[0] + for test_case_class in tests._loader.iterate_suite_cases( + loader.suite) + ] + test_suite_names = sorted(set(test_suite_names)) + + tests_json_string = pkg_resources.resource_string('tests', 'tests.json') + if six.PY3: + tests_json_string = tests_json_string.decode() + tests_json = json.loads(tests_json_string) + self.assertListEqual(test_suite_names, tests_json) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py b/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py index 3e4f317edcd..be3522f46f2 100644 --- a/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py +++ b/src/python/grpcio_tests/tests/unit/_thread_cleanup_test.py @@ -40,78 +40,89 @@ _EPSILON = 0.1 def cleanup(timeout): - if timeout is not None: - time.sleep(timeout) - else: - time.sleep(_LONG_TIME) + if timeout is not None: + time.sleep(timeout) + else: + time.sleep(_LONG_TIME) def slow_cleanup(timeout): - # Don't respect timeout - time.sleep(_LONG_TIME) + # Don't respect timeout + time.sleep(_LONG_TIME) class CleanupThreadTest(unittest.TestCase): - def testTargetInvocation(self): - event = threading.Event() - def target(arg1, arg2, arg3=None): - self.assertEqual('arg1', arg1) - self.assertEqual('arg2', arg2) - self.assertEqual('arg3', arg3) - event.set() - - cleanup_thread = _common.CleanupThread(behavior=lambda x: None, - target=target, name='test-name', - args=('arg1', 'arg2'), kwargs={'arg3': 'arg3'}) - cleanup_thread.start() - cleanup_thread.join() - self.assertEqual(cleanup_thread.name, 'test-name') - self.assertTrue(event.is_set()) - - def testJoinNoTimeout(self): - cleanup_thread = _common.CleanupThread(behavior=cleanup) - cleanup_thread.start() - start_time = time.time() - cleanup_thread.join() - end_time = time.time() - self.assertAlmostEqual(_LONG_TIME, end_time - start_time, delta=_EPSILON) - - def testJoinTimeout(self): - cleanup_thread = _common.CleanupThread(behavior=cleanup) - cleanup_thread.start() - start_time = time.time() - cleanup_thread.join(_SHORT_TIME) - end_time = time.time() - self.assertAlmostEqual(_SHORT_TIME, end_time - start_time, delta=_EPSILON) - - def testJoinTimeoutSlowBehavior(self): - cleanup_thread = _common.CleanupThread(behavior=slow_cleanup) - cleanup_thread.start() - start_time = time.time() - cleanup_thread.join(_SHORT_TIME) - end_time = time.time() - self.assertAlmostEqual(_LONG_TIME, end_time - start_time, delta=_EPSILON) - - def testJoinTimeoutSlowTarget(self): - event = threading.Event() - def target(): - event.wait(_LONG_TIME) - cleanup_thread = _common.CleanupThread(behavior=cleanup, target=target) - cleanup_thread.start() - start_time = time.time() - cleanup_thread.join(_SHORT_TIME) - end_time = time.time() - self.assertAlmostEqual(_SHORT_TIME, end_time - start_time, delta=_EPSILON) - event.set() - - def testJoinZeroTimeout(self): - cleanup_thread = _common.CleanupThread(behavior=cleanup) - cleanup_thread.start() - start_time = time.time() - cleanup_thread.join(0) - end_time = time.time() - self.assertAlmostEqual(0, end_time - start_time, delta=_EPSILON) + def testTargetInvocation(self): + event = threading.Event() + + def target(arg1, arg2, arg3=None): + self.assertEqual('arg1', arg1) + self.assertEqual('arg2', arg2) + self.assertEqual('arg3', arg3) + event.set() + + cleanup_thread = _common.CleanupThread( + behavior=lambda x: None, + target=target, + name='test-name', + args=('arg1', 'arg2'), + kwargs={'arg3': 'arg3'}) + cleanup_thread.start() + cleanup_thread.join() + self.assertEqual(cleanup_thread.name, 'test-name') + self.assertTrue(event.is_set()) + + def testJoinNoTimeout(self): + cleanup_thread = _common.CleanupThread(behavior=cleanup) + cleanup_thread.start() + start_time = time.time() + cleanup_thread.join() + end_time = time.time() + self.assertAlmostEqual( + _LONG_TIME, end_time - start_time, delta=_EPSILON) + + def testJoinTimeout(self): + cleanup_thread = _common.CleanupThread(behavior=cleanup) + cleanup_thread.start() + start_time = time.time() + cleanup_thread.join(_SHORT_TIME) + end_time = time.time() + self.assertAlmostEqual( + _SHORT_TIME, end_time - start_time, delta=_EPSILON) + + def testJoinTimeoutSlowBehavior(self): + cleanup_thread = _common.CleanupThread(behavior=slow_cleanup) + cleanup_thread.start() + start_time = time.time() + cleanup_thread.join(_SHORT_TIME) + end_time = time.time() + self.assertAlmostEqual( + _LONG_TIME, end_time - start_time, delta=_EPSILON) + + def testJoinTimeoutSlowTarget(self): + event = threading.Event() + + def target(): + event.wait(_LONG_TIME) + + cleanup_thread = _common.CleanupThread(behavior=cleanup, target=target) + cleanup_thread.start() + start_time = time.time() + cleanup_thread.join(_SHORT_TIME) + end_time = time.time() + self.assertAlmostEqual( + _SHORT_TIME, end_time - start_time, delta=_EPSILON) + event.set() + + def testJoinZeroTimeout(self): + cleanup_thread = _common.CleanupThread(behavior=cleanup) + cleanup_thread.start() + start_time = time.time() + cleanup_thread.join(0) + end_time = time.time() + self.assertAlmostEqual(0, end_time - start_time, delta=_EPSILON) + if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/_thread_pool.py b/src/python/grpcio_tests/tests/unit/_thread_pool.py index f13cc2f86fc..fad2e1c8f6d 100644 --- a/src/python/grpcio_tests/tests/unit/_thread_pool.py +++ b/src/python/grpcio_tests/tests/unit/_thread_pool.py @@ -32,17 +32,18 @@ from concurrent import futures class RecordingThreadPool(futures.Executor): - """A thread pool that records if used.""" - def __init__(self, max_workers): - self._tp_executor = futures.ThreadPoolExecutor(max_workers=max_workers) - self._lock = threading.Lock() - self._was_used = False + """A thread pool that records if used.""" - def submit(self, fn, *args, **kwargs): - with self._lock: - self._was_used = True - self._tp_executor.submit(fn, *args, **kwargs) + def __init__(self, max_workers): + self._tp_executor = futures.ThreadPoolExecutor(max_workers=max_workers) + self._lock = threading.Lock() + self._was_used = False - def was_used(self): - with self._lock: - return self._was_used + def submit(self, fn, *args, **kwargs): + with self._lock: + self._was_used = True + self._tp_executor.submit(fn, *args, **kwargs) + + def was_used(self): + with self._lock: + return self._was_used diff --git a/src/python/grpcio_tests/tests/unit/beta/__init__.py b/src/python/grpcio_tests/tests/unit/beta/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/beta/__init__.py +++ b/src/python/grpcio_tests/tests/unit/beta/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py b/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py index 3a9701b8ebe..b5fdac26c11 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_beta_features_test.py @@ -26,7 +26,6 @@ # 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. - """Tests Face interface compliance of the gRPC Python Beta API.""" import threading @@ -57,290 +56,303 @@ _RESPONSE = b'123' class _Servicer(object): - def __init__(self): - self._condition = threading.Condition() - self._peer = None - self._serviced = False - - def unary_unary(self, request, context): - with self._condition: - self._request = request - self._peer = context.protocol_context().peer() - self._invocation_metadata = context.invocation_metadata() - context.protocol_context().disable_next_response_compression() - self._serviced = True - self._condition.notify_all() - return _RESPONSE - - def unary_stream(self, request, context): - with self._condition: - self._request = request - self._peer = context.protocol_context().peer() - self._invocation_metadata = context.invocation_metadata() - context.protocol_context().disable_next_response_compression() - self._serviced = True - self._condition.notify_all() - return - yield - - def stream_unary(self, request_iterator, context): - for request in request_iterator: - self._request = request - with self._condition: - self._peer = context.protocol_context().peer() - self._invocation_metadata = context.invocation_metadata() - context.protocol_context().disable_next_response_compression() - self._serviced = True - self._condition.notify_all() - return _RESPONSE - - def stream_stream(self, request_iterator, context): - for request in request_iterator: - with self._condition: - self._peer = context.protocol_context().peer() - context.protocol_context().disable_next_response_compression() - yield _RESPONSE - with self._condition: - self._invocation_metadata = context.invocation_metadata() - self._serviced = True - self._condition.notify_all() - - def peer(self): - with self._condition: - return self._peer - - def block_until_serviced(self): - with self._condition: - while not self._serviced: - self._condition.wait() + def __init__(self): + self._condition = threading.Condition() + self._peer = None + self._serviced = False + + def unary_unary(self, request, context): + with self._condition: + self._request = request + self._peer = context.protocol_context().peer() + self._invocation_metadata = context.invocation_metadata() + context.protocol_context().disable_next_response_compression() + self._serviced = True + self._condition.notify_all() + return _RESPONSE + + def unary_stream(self, request, context): + with self._condition: + self._request = request + self._peer = context.protocol_context().peer() + self._invocation_metadata = context.invocation_metadata() + context.protocol_context().disable_next_response_compression() + self._serviced = True + self._condition.notify_all() + return + yield + + def stream_unary(self, request_iterator, context): + for request in request_iterator: + self._request = request + with self._condition: + self._peer = context.protocol_context().peer() + self._invocation_metadata = context.invocation_metadata() + context.protocol_context().disable_next_response_compression() + self._serviced = True + self._condition.notify_all() + return _RESPONSE + + def stream_stream(self, request_iterator, context): + for request in request_iterator: + with self._condition: + self._peer = context.protocol_context().peer() + context.protocol_context().disable_next_response_compression() + yield _RESPONSE + with self._condition: + self._invocation_metadata = context.invocation_metadata() + self._serviced = True + self._condition.notify_all() + + def peer(self): + with self._condition: + return self._peer + + def block_until_serviced(self): + with self._condition: + while not self._serviced: + self._condition.wait() class _BlockingIterator(object): - def __init__(self, upstream): - self._condition = threading.Condition() - self._upstream = upstream - self._allowed = [] + def __init__(self, upstream): + self._condition = threading.Condition() + self._upstream = upstream + self._allowed = [] - def __iter__(self): - return self + def __iter__(self): + return self - def __next__(self): - return self.next() + def __next__(self): + return self.next() - def next(self): - with self._condition: - while True: - if self._allowed is None: - raise StopIteration() - elif self._allowed: - return self._allowed.pop(0) - else: - self._condition.wait() + def next(self): + with self._condition: + while True: + if self._allowed is None: + raise StopIteration() + elif self._allowed: + return self._allowed.pop(0) + else: + self._condition.wait() - def allow(self): - with self._condition: - try: - self._allowed.append(next(self._upstream)) - except StopIteration: - self._allowed = None - self._condition.notify_all() + def allow(self): + with self._condition: + try: + self._allowed.append(next(self._upstream)) + except StopIteration: + self._allowed = None + self._condition.notify_all() def _metadata_plugin(context, callback): - callback([(_PER_RPC_CREDENTIALS_METADATA_KEY, - _PER_RPC_CREDENTIALS_METADATA_VALUE)], None) + callback([(_PER_RPC_CREDENTIALS_METADATA_KEY, + _PER_RPC_CREDENTIALS_METADATA_VALUE)], None) class BetaFeaturesTest(unittest.TestCase): - def setUp(self): - self._servicer = _Servicer() - method_implementations = { - (_GROUP, _UNARY_UNARY): + def setUp(self): + self._servicer = _Servicer() + method_implementations = { + (_GROUP, _UNARY_UNARY): utilities.unary_unary_inline(self._servicer.unary_unary), - (_GROUP, _UNARY_STREAM): + (_GROUP, _UNARY_STREAM): utilities.unary_stream_inline(self._servicer.unary_stream), - (_GROUP, _STREAM_UNARY): + (_GROUP, _STREAM_UNARY): utilities.stream_unary_inline(self._servicer.stream_unary), - (_GROUP, _STREAM_STREAM): + (_GROUP, _STREAM_STREAM): utilities.stream_stream_inline(self._servicer.stream_stream), - } - - cardinalities = { - _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, - _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, - _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, - _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, - } - - server_options = implementations.server_options( - thread_pool_size=test_constants.POOL_SIZE) - self._server = implementations.server( - method_implementations, options=server_options) - server_credentials = implementations.ssl_server_credentials( - [(resources.private_key(), resources.certificate_chain(),),]) - port = self._server.add_secure_port('[::]:0', server_credentials) - self._server.start() - self._channel_credentials = implementations.ssl_channel_credentials( - resources.test_root_certificates()) - self._call_credentials = implementations.metadata_call_credentials( - _metadata_plugin) - channel = test_utilities.not_really_secure_channel( - 'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE) - stub_options = implementations.stub_options( - thread_pool_size=test_constants.POOL_SIZE) - self._dynamic_stub = implementations.dynamic_stub( - channel, _GROUP, cardinalities, options=stub_options) - - def tearDown(self): - self._dynamic_stub = None - self._server.stop(test_constants.SHORT_TIMEOUT).wait() - - def test_unary_unary(self): - call_options = interfaces.grpc_call_options( - disable_compression=True, credentials=self._call_credentials) - response = getattr(self._dynamic_stub, _UNARY_UNARY)( - _REQUEST, test_constants.LONG_TIMEOUT, protocol_options=call_options) - self.assertEqual(_RESPONSE, response) - self.assertIsNotNone(self._servicer.peer()) - invocation_metadata = [(metadatum.key, metadatum.value) for metadatum in - self._servicer._invocation_metadata] - self.assertIn( - (_PER_RPC_CREDENTIALS_METADATA_KEY, - _PER_RPC_CREDENTIALS_METADATA_VALUE), - invocation_metadata) - - def test_unary_stream(self): - call_options = interfaces.grpc_call_options( - disable_compression=True, credentials=self._call_credentials) - response_iterator = getattr(self._dynamic_stub, _UNARY_STREAM)( - _REQUEST, test_constants.LONG_TIMEOUT, protocol_options=call_options) - self._servicer.block_until_serviced() - self.assertIsNotNone(self._servicer.peer()) - invocation_metadata = [(metadatum.key, metadatum.value) for metadatum in - self._servicer._invocation_metadata] - self.assertIn( - (_PER_RPC_CREDENTIALS_METADATA_KEY, - _PER_RPC_CREDENTIALS_METADATA_VALUE), - invocation_metadata) - - def test_stream_unary(self): - call_options = interfaces.grpc_call_options( - credentials=self._call_credentials) - request_iterator = _BlockingIterator(iter((_REQUEST,))) - response_future = getattr(self._dynamic_stub, _STREAM_UNARY).future( - request_iterator, test_constants.LONG_TIMEOUT, - protocol_options=call_options) - response_future.protocol_context().disable_next_request_compression() - request_iterator.allow() - response_future.protocol_context().disable_next_request_compression() - request_iterator.allow() - self._servicer.block_until_serviced() - self.assertIsNotNone(self._servicer.peer()) - self.assertEqual(_RESPONSE, response_future.result()) - invocation_metadata = [(metadatum.key, metadatum.value) for metadatum in - self._servicer._invocation_metadata] - self.assertIn( - (_PER_RPC_CREDENTIALS_METADATA_KEY, - _PER_RPC_CREDENTIALS_METADATA_VALUE), - invocation_metadata) - - def test_stream_stream(self): - call_options = interfaces.grpc_call_options( - credentials=self._call_credentials) - request_iterator = _BlockingIterator(iter((_REQUEST,))) - response_iterator = getattr(self._dynamic_stub, _STREAM_STREAM)( - request_iterator, test_constants.SHORT_TIMEOUT, - protocol_options=call_options) - response_iterator.protocol_context().disable_next_request_compression() - request_iterator.allow() - response = next(response_iterator) - response_iterator.protocol_context().disable_next_request_compression() - request_iterator.allow() - self._servicer.block_until_serviced() - self.assertIsNotNone(self._servicer.peer()) - self.assertEqual(_RESPONSE, response) - invocation_metadata = [(metadatum.key, metadatum.value) for metadatum in - self._servicer._invocation_metadata] - self.assertIn( - (_PER_RPC_CREDENTIALS_METADATA_KEY, - _PER_RPC_CREDENTIALS_METADATA_VALUE), - invocation_metadata) + } + + cardinalities = { + _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, + _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, + _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, + _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, + } + + server_options = implementations.server_options( + thread_pool_size=test_constants.POOL_SIZE) + self._server = implementations.server( + method_implementations, options=server_options) + server_credentials = implementations.ssl_server_credentials([( + resources.private_key(), + resources.certificate_chain(),),]) + port = self._server.add_secure_port('[::]:0', server_credentials) + self._server.start() + self._channel_credentials = implementations.ssl_channel_credentials( + resources.test_root_certificates()) + self._call_credentials = implementations.metadata_call_credentials( + _metadata_plugin) + channel = test_utilities.not_really_secure_channel( + 'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE) + stub_options = implementations.stub_options( + thread_pool_size=test_constants.POOL_SIZE) + self._dynamic_stub = implementations.dynamic_stub( + channel, _GROUP, cardinalities, options=stub_options) + + def tearDown(self): + self._dynamic_stub = None + self._server.stop(test_constants.SHORT_TIMEOUT).wait() + + def test_unary_unary(self): + call_options = interfaces.grpc_call_options( + disable_compression=True, credentials=self._call_credentials) + response = getattr(self._dynamic_stub, _UNARY_UNARY)( + _REQUEST, + test_constants.LONG_TIMEOUT, + protocol_options=call_options) + self.assertEqual(_RESPONSE, response) + self.assertIsNotNone(self._servicer.peer()) + invocation_metadata = [ + (metadatum.key, metadatum.value) + for metadatum in self._servicer._invocation_metadata + ] + self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY, + _PER_RPC_CREDENTIALS_METADATA_VALUE), + invocation_metadata) + + def test_unary_stream(self): + call_options = interfaces.grpc_call_options( + disable_compression=True, credentials=self._call_credentials) + response_iterator = getattr(self._dynamic_stub, _UNARY_STREAM)( + _REQUEST, + test_constants.LONG_TIMEOUT, + protocol_options=call_options) + self._servicer.block_until_serviced() + self.assertIsNotNone(self._servicer.peer()) + invocation_metadata = [ + (metadatum.key, metadatum.value) + for metadatum in self._servicer._invocation_metadata + ] + self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY, + _PER_RPC_CREDENTIALS_METADATA_VALUE), + invocation_metadata) + + def test_stream_unary(self): + call_options = interfaces.grpc_call_options( + credentials=self._call_credentials) + request_iterator = _BlockingIterator(iter((_REQUEST,))) + response_future = getattr(self._dynamic_stub, _STREAM_UNARY).future( + request_iterator, + test_constants.LONG_TIMEOUT, + protocol_options=call_options) + response_future.protocol_context().disable_next_request_compression() + request_iterator.allow() + response_future.protocol_context().disable_next_request_compression() + request_iterator.allow() + self._servicer.block_until_serviced() + self.assertIsNotNone(self._servicer.peer()) + self.assertEqual(_RESPONSE, response_future.result()) + invocation_metadata = [ + (metadatum.key, metadatum.value) + for metadatum in self._servicer._invocation_metadata + ] + self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY, + _PER_RPC_CREDENTIALS_METADATA_VALUE), + invocation_metadata) + + def test_stream_stream(self): + call_options = interfaces.grpc_call_options( + credentials=self._call_credentials) + request_iterator = _BlockingIterator(iter((_REQUEST,))) + response_iterator = getattr(self._dynamic_stub, _STREAM_STREAM)( + request_iterator, + test_constants.SHORT_TIMEOUT, + protocol_options=call_options) + response_iterator.protocol_context().disable_next_request_compression() + request_iterator.allow() + response = next(response_iterator) + response_iterator.protocol_context().disable_next_request_compression() + request_iterator.allow() + self._servicer.block_until_serviced() + self.assertIsNotNone(self._servicer.peer()) + self.assertEqual(_RESPONSE, response) + invocation_metadata = [ + (metadatum.key, metadatum.value) + for metadatum in self._servicer._invocation_metadata + ] + self.assertIn((_PER_RPC_CREDENTIALS_METADATA_KEY, + _PER_RPC_CREDENTIALS_METADATA_VALUE), + invocation_metadata) class ContextManagementAndLifecycleTest(unittest.TestCase): - def setUp(self): - self._servicer = _Servicer() - self._method_implementations = { - (_GROUP, _UNARY_UNARY): + def setUp(self): + self._servicer = _Servicer() + self._method_implementations = { + (_GROUP, _UNARY_UNARY): utilities.unary_unary_inline(self._servicer.unary_unary), - (_GROUP, _UNARY_STREAM): + (_GROUP, _UNARY_STREAM): utilities.unary_stream_inline(self._servicer.unary_stream), - (_GROUP, _STREAM_UNARY): + (_GROUP, _STREAM_UNARY): utilities.stream_unary_inline(self._servicer.stream_unary), - (_GROUP, _STREAM_STREAM): + (_GROUP, _STREAM_STREAM): utilities.stream_stream_inline(self._servicer.stream_stream), - } - - self._cardinalities = { - _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, - _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, - _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, - _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, - } - - self._server_options = implementations.server_options( - thread_pool_size=test_constants.POOL_SIZE) - self._server_credentials = implementations.ssl_server_credentials( - [(resources.private_key(), resources.certificate_chain(),),]) - self._channel_credentials = implementations.ssl_channel_credentials( - resources.test_root_certificates()) - self._stub_options = implementations.stub_options( - thread_pool_size=test_constants.POOL_SIZE) - - def test_stub_context(self): - server = implementations.server( - self._method_implementations, options=self._server_options) - port = server.add_secure_port('[::]:0', self._server_credentials) - server.start() - - channel = test_utilities.not_really_secure_channel( - 'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE) - dynamic_stub = implementations.dynamic_stub( - channel, _GROUP, self._cardinalities, options=self._stub_options) - for _ in range(100): - with dynamic_stub: - pass - for _ in range(10): - with dynamic_stub: - call_options = interfaces.grpc_call_options( - disable_compression=True) - response = getattr(dynamic_stub, _UNARY_UNARY)( - _REQUEST, test_constants.LONG_TIMEOUT, - protocol_options=call_options) - self.assertEqual(_RESPONSE, response) - self.assertIsNotNone(self._servicer.peer()) - - server.stop(test_constants.SHORT_TIMEOUT).wait() - - def test_server_lifecycle(self): - for _ in range(100): - server = implementations.server( - self._method_implementations, options=self._server_options) - port = server.add_secure_port('[::]:0', self._server_credentials) - server.start() - server.stop(test_constants.SHORT_TIMEOUT).wait() - for _ in range(100): - server = implementations.server( - self._method_implementations, options=self._server_options) - server.add_secure_port('[::]:0', self._server_credentials) - server.add_insecure_port('[::]:0') - with server: - server.stop(test_constants.SHORT_TIMEOUT) - server.stop(test_constants.SHORT_TIMEOUT) + } + + self._cardinalities = { + _UNARY_UNARY: cardinality.Cardinality.UNARY_UNARY, + _UNARY_STREAM: cardinality.Cardinality.UNARY_STREAM, + _STREAM_UNARY: cardinality.Cardinality.STREAM_UNARY, + _STREAM_STREAM: cardinality.Cardinality.STREAM_STREAM, + } + + self._server_options = implementations.server_options( + thread_pool_size=test_constants.POOL_SIZE) + self._server_credentials = implementations.ssl_server_credentials([( + resources.private_key(), + resources.certificate_chain(),),]) + self._channel_credentials = implementations.ssl_channel_credentials( + resources.test_root_certificates()) + self._stub_options = implementations.stub_options( + thread_pool_size=test_constants.POOL_SIZE) + + def test_stub_context(self): + server = implementations.server( + self._method_implementations, options=self._server_options) + port = server.add_secure_port('[::]:0', self._server_credentials) + server.start() + + channel = test_utilities.not_really_secure_channel( + 'localhost', port, self._channel_credentials, _SERVER_HOST_OVERRIDE) + dynamic_stub = implementations.dynamic_stub( + channel, _GROUP, self._cardinalities, options=self._stub_options) + for _ in range(100): + with dynamic_stub: + pass + for _ in range(10): + with dynamic_stub: + call_options = interfaces.grpc_call_options( + disable_compression=True) + response = getattr(dynamic_stub, _UNARY_UNARY)( + _REQUEST, + test_constants.LONG_TIMEOUT, + protocol_options=call_options) + self.assertEqual(_RESPONSE, response) + self.assertIsNotNone(self._servicer.peer()) + + server.stop(test_constants.SHORT_TIMEOUT).wait() + + def test_server_lifecycle(self): + for _ in range(100): + server = implementations.server( + self._method_implementations, options=self._server_options) + port = server.add_secure_port('[::]:0', self._server_credentials) + server.start() + server.stop(test_constants.SHORT_TIMEOUT).wait() + for _ in range(100): + server = implementations.server( + self._method_implementations, options=self._server_options) + server.add_secure_port('[::]:0', self._server_credentials) + server.add_insecure_port('[::]:0') + with server: + server.stop(test_constants.SHORT_TIMEOUT) + server.stop(test_constants.SHORT_TIMEOUT) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/_connectivity_channel_test.py b/src/python/grpcio_tests/tests/unit/beta/_connectivity_channel_test.py index 5d826a269db..49d683b8a6c 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_connectivity_channel_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_connectivity_channel_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc.beta._connectivity_channel.""" import unittest @@ -36,13 +35,13 @@ from grpc.beta import interfaces class ConnectivityStatesTest(unittest.TestCase): - def testBetaConnectivityStates(self): - self.assertIsNotNone(interfaces.ChannelConnectivity.IDLE) - self.assertIsNotNone(interfaces.ChannelConnectivity.CONNECTING) - self.assertIsNotNone(interfaces.ChannelConnectivity.READY) - self.assertIsNotNone(interfaces.ChannelConnectivity.TRANSIENT_FAILURE) - self.assertIsNotNone(interfaces.ChannelConnectivity.FATAL_FAILURE) + def testBetaConnectivityStates(self): + self.assertIsNotNone(interfaces.ChannelConnectivity.IDLE) + self.assertIsNotNone(interfaces.ChannelConnectivity.CONNECTING) + self.assertIsNotNone(interfaces.ChannelConnectivity.READY) + self.assertIsNotNone(interfaces.ChannelConnectivity.TRANSIENT_FAILURE) + self.assertIsNotNone(interfaces.ChannelConnectivity.FATAL_FAILURE) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py b/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py index 3a67516906d..f4214426241 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_face_interface_test.py @@ -26,7 +26,6 @@ # 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. - """Tests Face interface compliance of the gRPC Python Beta API.""" import collections @@ -47,94 +46,97 @@ _SERVER_HOST_OVERRIDE = 'foo.test.google.fr' class _SerializationBehaviors( - collections.namedtuple( - '_SerializationBehaviors', - ('request_serializers', 'request_deserializers', 'response_serializers', - 'response_deserializers',))): - pass + collections.namedtuple('_SerializationBehaviors', ( + 'request_serializers', + 'request_deserializers', + 'response_serializers', + 'response_deserializers',))): + pass def _serialization_behaviors_from_test_methods(test_methods): - request_serializers = {} - request_deserializers = {} - response_serializers = {} - response_deserializers = {} - for (group, method), test_method in six.iteritems(test_methods): - request_serializers[group, method] = test_method.serialize_request - request_deserializers[group, method] = test_method.deserialize_request - response_serializers[group, method] = test_method.serialize_response - response_deserializers[group, method] = test_method.deserialize_response - return _SerializationBehaviors( - request_serializers, request_deserializers, response_serializers, - response_deserializers) + request_serializers = {} + request_deserializers = {} + response_serializers = {} + response_deserializers = {} + for (group, method), test_method in six.iteritems(test_methods): + request_serializers[group, method] = test_method.serialize_request + request_deserializers[group, method] = test_method.deserialize_request + response_serializers[group, method] = test_method.serialize_response + response_deserializers[group, method] = test_method.deserialize_response + return _SerializationBehaviors(request_serializers, request_deserializers, + response_serializers, response_deserializers) class _Implementation(test_interfaces.Implementation): - def instantiate( - self, methods, method_implementations, multi_method_implementation): - serialization_behaviors = _serialization_behaviors_from_test_methods( - methods) - # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest. - service = next(iter(methods))[0] - # TODO(nathaniel): Add a "cardinalities_by_group" attribute to - # _digest.TestServiceDigest. - cardinalities = { - method: method_object.cardinality() - for (group, method), method_object in six.iteritems(methods)} - - server_options = implementations.server_options( - request_deserializers=serialization_behaviors.request_deserializers, - response_serializers=serialization_behaviors.response_serializers, - thread_pool_size=test_constants.POOL_SIZE) - server = implementations.server( - method_implementations, options=server_options) - server_credentials = implementations.ssl_server_credentials( - [(resources.private_key(), resources.certificate_chain(),),]) - port = server.add_secure_port('[::]:0', server_credentials) - server.start() - channel_credentials = implementations.ssl_channel_credentials( - resources.test_root_certificates()) - channel = test_utilities.not_really_secure_channel( - 'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE) - stub_options = implementations.stub_options( - request_serializers=serialization_behaviors.request_serializers, - response_deserializers=serialization_behaviors.response_deserializers, - thread_pool_size=test_constants.POOL_SIZE) - generic_stub = implementations.generic_stub(channel, options=stub_options) - dynamic_stub = implementations.dynamic_stub( - channel, service, cardinalities, options=stub_options) - return generic_stub, {service: dynamic_stub}, server - - def destantiate(self, memo): - memo.stop(test_constants.SHORT_TIMEOUT).wait() - - def invocation_metadata(self): - return grpc_test_common.INVOCATION_INITIAL_METADATA - - def initial_metadata(self): - return grpc_test_common.SERVICE_INITIAL_METADATA - - def terminal_metadata(self): - return grpc_test_common.SERVICE_TERMINAL_METADATA - - def code(self): - return interfaces.StatusCode.OK - - def details(self): - return grpc_test_common.DETAILS - - def metadata_transmitted(self, original_metadata, transmitted_metadata): - return original_metadata is None or grpc_test_common.metadata_transmitted( - original_metadata, transmitted_metadata) + def instantiate(self, methods, method_implementations, + multi_method_implementation): + serialization_behaviors = _serialization_behaviors_from_test_methods( + methods) + # TODO(nathaniel): Add a "groups" attribute to _digest.TestServiceDigest. + service = next(iter(methods))[0] + # TODO(nathaniel): Add a "cardinalities_by_group" attribute to + # _digest.TestServiceDigest. + cardinalities = { + method: method_object.cardinality() + for (group, method), method_object in six.iteritems(methods) + } + + server_options = implementations.server_options( + request_deserializers=serialization_behaviors.request_deserializers, + response_serializers=serialization_behaviors.response_serializers, + thread_pool_size=test_constants.POOL_SIZE) + server = implementations.server( + method_implementations, options=server_options) + server_credentials = implementations.ssl_server_credentials([( + resources.private_key(), + resources.certificate_chain(),),]) + port = server.add_secure_port('[::]:0', server_credentials) + server.start() + channel_credentials = implementations.ssl_channel_credentials( + resources.test_root_certificates()) + channel = test_utilities.not_really_secure_channel( + 'localhost', port, channel_credentials, _SERVER_HOST_OVERRIDE) + stub_options = implementations.stub_options( + request_serializers=serialization_behaviors.request_serializers, + response_deserializers=serialization_behaviors. + response_deserializers, + thread_pool_size=test_constants.POOL_SIZE) + generic_stub = implementations.generic_stub( + channel, options=stub_options) + dynamic_stub = implementations.dynamic_stub( + channel, service, cardinalities, options=stub_options) + return generic_stub, {service: dynamic_stub}, server + + def destantiate(self, memo): + memo.stop(test_constants.SHORT_TIMEOUT).wait() + + def invocation_metadata(self): + return grpc_test_common.INVOCATION_INITIAL_METADATA + + def initial_metadata(self): + return grpc_test_common.SERVICE_INITIAL_METADATA + + def terminal_metadata(self): + return grpc_test_common.SERVICE_TERMINAL_METADATA + + def code(self): + return interfaces.StatusCode.OK + + def details(self): + return grpc_test_common.DETAILS + + def metadata_transmitted(self, original_metadata, transmitted_metadata): + return original_metadata is None or grpc_test_common.metadata_transmitted( + original_metadata, transmitted_metadata) def load_tests(loader, tests, pattern): - return unittest.TestSuite( - tests=tuple( - loader.loadTestsFromTestCase(test_case_class) - for test_case_class in test_cases.test_cases(_Implementation()))) + return unittest.TestSuite(tests=tuple( + loader.loadTestsFromTestCase(test_case_class) + for test_case_class in test_cases.test_cases(_Implementation()))) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py b/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py index 127f93e9bb5..69bb5cc2a53 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_implementations_test.py @@ -26,7 +26,6 @@ # 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. - """Tests the implementations module of the gRPC Python Beta API.""" import datetime @@ -40,31 +39,32 @@ from tests.unit import resources class ChannelCredentialsTest(unittest.TestCase): - def test_runtime_provided_root_certificates(self): - channel_credentials = implementations.ssl_channel_credentials() - self.assertIsInstance( - channel_credentials, implementations.ChannelCredentials) - - def test_application_provided_root_certificates(self): - channel_credentials = implementations.ssl_channel_credentials( - resources.test_root_certificates()) - self.assertIsInstance( - channel_credentials, implementations.ChannelCredentials) + def test_runtime_provided_root_certificates(self): + channel_credentials = implementations.ssl_channel_credentials() + self.assertIsInstance(channel_credentials, + implementations.ChannelCredentials) + + def test_application_provided_root_certificates(self): + channel_credentials = implementations.ssl_channel_credentials( + resources.test_root_certificates()) + self.assertIsInstance(channel_credentials, + implementations.ChannelCredentials) class CallCredentialsTest(unittest.TestCase): - def test_google_call_credentials(self): - creds = oauth2client_client.GoogleCredentials( - 'token', 'client_id', 'secret', 'refresh_token', - datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', - 'user_agent') - call_creds = implementations.google_call_credentials(creds) - self.assertIsInstance(call_creds, implementations.CallCredentials) + def test_google_call_credentials(self): + creds = oauth2client_client.GoogleCredentials( + 'token', 'client_id', 'secret', 'refresh_token', + datetime.datetime(2008, 6, 24), 'https://refresh.uri.com/', + 'user_agent') + call_creds = implementations.google_call_credentials(creds) + self.assertIsInstance(call_creds, implementations.CallCredentials) + + def test_access_token_call_credentials(self): + call_creds = implementations.access_token_call_credentials('token') + self.assertIsInstance(call_creds, implementations.CallCredentials) - def test_access_token_call_credentials(self): - call_creds = implementations.access_token_call_credentials('token') - self.assertIsInstance(call_creds, implementations.CallCredentials) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py b/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py index 37b8c49120f..664e47c7696 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of RPC-method-not-found behavior.""" import unittest @@ -39,37 +38,38 @@ from tests.unit.framework.common import test_constants class NotFoundTest(unittest.TestCase): - def setUp(self): - self._server = implementations.server({}) - port = self._server.add_insecure_port('[::]:0') - channel = implementations.insecure_channel('localhost', port) - self._generic_stub = implementations.generic_stub(channel) - self._server.start() + def setUp(self): + self._server = implementations.server({}) + port = self._server.add_insecure_port('[::]:0') + channel = implementations.insecure_channel('localhost', port) + self._generic_stub = implementations.generic_stub(channel) + self._server.start() - def tearDown(self): - self._server.stop(0).wait() - self._generic_stub = None + def tearDown(self): + self._server.stop(0).wait() + self._generic_stub = None - def test_blocking_unary_unary_not_found(self): - with self.assertRaises(face.LocalError) as exception_assertion_context: - self._generic_stub.blocking_unary_unary( - 'groop', 'meffod', b'abc', test_constants.LONG_TIMEOUT, - with_call=True) - self.assertIs( - exception_assertion_context.exception.code, - interfaces.StatusCode.UNIMPLEMENTED) + def test_blocking_unary_unary_not_found(self): + with self.assertRaises(face.LocalError) as exception_assertion_context: + self._generic_stub.blocking_unary_unary( + 'groop', + 'meffod', + b'abc', + test_constants.LONG_TIMEOUT, + with_call=True) + self.assertIs(exception_assertion_context.exception.code, + interfaces.StatusCode.UNIMPLEMENTED) - def test_future_stream_unary_not_found(self): - rpc_future = self._generic_stub.future_stream_unary( - 'grupe', 'mevvod', [b'def'], test_constants.LONG_TIMEOUT) - with self.assertRaises(face.LocalError) as exception_assertion_context: - rpc_future.result() - self.assertIs( - exception_assertion_context.exception.code, - interfaces.StatusCode.UNIMPLEMENTED) - self.assertIs( - rpc_future.exception().code, interfaces.StatusCode.UNIMPLEMENTED) + def test_future_stream_unary_not_found(self): + rpc_future = self._generic_stub.future_stream_unary( + 'grupe', 'mevvod', [b'def'], test_constants.LONG_TIMEOUT) + with self.assertRaises(face.LocalError) as exception_assertion_context: + rpc_future.result() + self.assertIs(exception_assertion_context.exception.code, + interfaces.StatusCode.UNIMPLEMENTED) + self.assertIs(rpc_future.exception().code, + interfaces.StatusCode.UNIMPLEMENTED) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/_utilities_test.py b/src/python/grpcio_tests/tests/unit/beta/_utilities_test.py index 9cce96cc85c..e8e62c322a7 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_utilities_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_utilities_test.py @@ -26,7 +26,6 @@ # 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. - """Tests of grpc.beta.utilities.""" import threading @@ -41,68 +40,68 @@ from tests.unit.framework.common import test_constants class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._value = None + def __init__(self): + self._condition = threading.Condition() + self._value = None - def accept_value(self, value): - with self._condition: - self._value = value - self._condition.notify_all() + def accept_value(self, value): + with self._condition: + self._value = value + self._condition.notify_all() - def block_until_called(self): - with self._condition: - while self._value is None: - self._condition.wait() - return self._value + def block_until_called(self): + with self._condition: + while self._value is None: + self._condition.wait() + return self._value class ChannelConnectivityTest(unittest.TestCase): - def test_lonely_channel_connectivity(self): - channel = implementations.insecure_channel('localhost', 12345) - callback = _Callback() - - ready_future = utilities.channel_ready_future(channel) - ready_future.add_done_callback(callback.accept_value) - with self.assertRaises(future.TimeoutError): - ready_future.result(timeout=test_constants.SHORT_TIMEOUT) - self.assertFalse(ready_future.cancelled()) - self.assertFalse(ready_future.done()) - self.assertTrue(ready_future.running()) - ready_future.cancel() - value_passed_to_callback = callback.block_until_called() - self.assertIs(ready_future, value_passed_to_callback) - self.assertTrue(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - - def test_immediately_connectable_channel_connectivity(self): - server = implementations.server({}) - port = server.add_insecure_port('[::]:0') - server.start() - channel = implementations.insecure_channel('localhost', port) - callback = _Callback() - - try: - ready_future = utilities.channel_ready_future(channel) - ready_future.add_done_callback(callback.accept_value) - self.assertIsNone( - ready_future.result(timeout=test_constants.LONG_TIMEOUT)) - value_passed_to_callback = callback.block_until_called() - self.assertIs(ready_future, value_passed_to_callback) - self.assertFalse(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - # Cancellation after maturity has no effect. - ready_future.cancel() - self.assertFalse(ready_future.cancelled()) - self.assertTrue(ready_future.done()) - self.assertFalse(ready_future.running()) - finally: - ready_future.cancel() - server.stop(0) + def test_lonely_channel_connectivity(self): + channel = implementations.insecure_channel('localhost', 12345) + callback = _Callback() + + ready_future = utilities.channel_ready_future(channel) + ready_future.add_done_callback(callback.accept_value) + with self.assertRaises(future.TimeoutError): + ready_future.result(timeout=test_constants.SHORT_TIMEOUT) + self.assertFalse(ready_future.cancelled()) + self.assertFalse(ready_future.done()) + self.assertTrue(ready_future.running()) + ready_future.cancel() + value_passed_to_callback = callback.block_until_called() + self.assertIs(ready_future, value_passed_to_callback) + self.assertTrue(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + + def test_immediately_connectable_channel_connectivity(self): + server = implementations.server({}) + port = server.add_insecure_port('[::]:0') + server.start() + channel = implementations.insecure_channel('localhost', port) + callback = _Callback() + + try: + ready_future = utilities.channel_ready_future(channel) + ready_future.add_done_callback(callback.accept_value) + self.assertIsNone( + ready_future.result(timeout=test_constants.LONG_TIMEOUT)) + value_passed_to_callback = callback.block_until_called() + self.assertIs(ready_future, value_passed_to_callback) + self.assertFalse(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + # Cancellation after maturity has no effect. + ready_future.cancel() + self.assertFalse(ready_future.cancelled()) + self.assertTrue(ready_future.done()) + self.assertFalse(ready_future.running()) + finally: + ready_future.cancel() + server.stop(0) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/beta/test_utilities.py b/src/python/grpcio_tests/tests/unit/beta/test_utilities.py index 692da9c97d7..f5424206837 100644 --- a/src/python/grpcio_tests/tests/unit/beta/test_utilities.py +++ b/src/python/grpcio_tests/tests/unit/beta/test_utilities.py @@ -26,16 +26,15 @@ # 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. - """Test-appropriate entry points into the gRPC Python Beta API.""" import grpc from grpc.beta import implementations -def not_really_secure_channel( - host, port, channel_credentials, server_host_override): - """Creates an insecure Channel to a remote host. +def not_really_secure_channel(host, port, channel_credentials, + server_host_override): + """Creates an insecure Channel to a remote host. Args: host: The name of the remote host to which to connect. @@ -48,8 +47,8 @@ def not_really_secure_channel( An implementations.Channel to the remote host through which RPCs may be conducted. """ - target = '%s:%d' % (host, port) - channel = grpc.secure_channel( - target, channel_credentials, - (('grpc.ssl_target_name_override', server_host_override,),)) - return implementations.Channel(channel) + target = '%s:%d' % (host, port) + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + server_host_override,),)) + return implementations.Channel(channel) diff --git a/src/python/grpcio_tests/tests/unit/framework/__init__.py b/src/python/grpcio_tests/tests/unit/framework/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/framework/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/framework/common/__init__.py b/src/python/grpcio_tests/tests/unit/framework/common/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/framework/common/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/common/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/framework/common/test_constants.py b/src/python/grpcio_tests/tests/unit/framework/common/test_constants.py index b6682d396c9..905483c08d7 100644 --- a/src/python/grpcio_tests/tests/unit/framework/common/test_constants.py +++ b/src/python/grpcio_tests/tests/unit/framework/common/test_constants.py @@ -26,7 +26,6 @@ # 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. - """Constants shared among tests throughout RPC Framework.""" # Value for maximum duration in seconds that a test is allowed for its actual diff --git a/src/python/grpcio_tests/tests/unit/framework/common/test_control.py b/src/python/grpcio_tests/tests/unit/framework/common/test_control.py index 088e2f8b885..af08731b1ee 100644 --- a/src/python/grpcio_tests/tests/unit/framework/common/test_control.py +++ b/src/python/grpcio_tests/tests/unit/framework/common/test_control.py @@ -26,7 +26,6 @@ # 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. - """Code for instructing systems under test to block or fail.""" import abc @@ -37,7 +36,7 @@ import six class Defect(Exception): - """Simulates a programming defect raised into in a system under test. + """Simulates a programming defect raised into in a system under test. Use of a standard exception type is too easily misconstrued as an actual defect in either the test infrastructure or the system under test. @@ -45,7 +44,7 @@ class Defect(Exception): class Control(six.with_metaclass(abc.ABCMeta)): - """An object that accepts program control from a system under test. + """An object that accepts program control from a system under test. Systems under test passed a Control should call its control() method frequently during execution. The control() method may block, raise an @@ -53,61 +52,61 @@ class Control(six.with_metaclass(abc.ABCMeta)): the system under test to simulate hanging, failing, or functioning. """ - @abc.abstractmethod - def control(self): - """Potentially does anything.""" - raise NotImplementedError() + @abc.abstractmethod + def control(self): + """Potentially does anything.""" + raise NotImplementedError() class PauseFailControl(Control): - """A Control that can be used to pause or fail code under control. + """A Control that can be used to pause or fail code under control. This object is only safe for use from two threads: one of the system under test calling control and the other from the test system calling pause, block_until_paused, and fail. """ - def __init__(self): - self._condition = threading.Condition() - self._pause = False - self._paused = False - self._fail = False - - def control(self): - with self._condition: - if self._fail: - raise Defect() - - while self._pause: - self._paused = True - self._condition.notify_all() - self._condition.wait() - self._paused = False - - @contextlib.contextmanager - def pause(self): - """Pauses code under control while controlling code is in context.""" - with self._condition: - self._pause = True - yield - with self._condition: - self._pause = False - self._condition.notify_all() - - def block_until_paused(self): - """Blocks controlling code until code under control is paused. + def __init__(self): + self._condition = threading.Condition() + self._pause = False + self._paused = False + self._fail = False + + def control(self): + with self._condition: + if self._fail: + raise Defect() + + while self._pause: + self._paused = True + self._condition.notify_all() + self._condition.wait() + self._paused = False + + @contextlib.contextmanager + def pause(self): + """Pauses code under control while controlling code is in context.""" + with self._condition: + self._pause = True + yield + with self._condition: + self._pause = False + self._condition.notify_all() + + def block_until_paused(self): + """Blocks controlling code until code under control is paused. May only be called within the context of a pause call. """ - with self._condition: - while not self._paused: - self._condition.wait() - - @contextlib.contextmanager - def fail(self): - """Fails code under control while controlling code is in context.""" - with self._condition: - self._fail = True - yield - with self._condition: - self._fail = False + with self._condition: + while not self._paused: + self._condition.wait() + + @contextlib.contextmanager + def fail(self): + """Fails code under control while controlling code is in context.""" + with self._condition: + self._fail = True + yield + with self._condition: + self._fail = False diff --git a/src/python/grpcio_tests/tests/unit/framework/common/test_coverage.py b/src/python/grpcio_tests/tests/unit/framework/common/test_coverage.py index ea2d2812ce6..13ceec31a01 100644 --- a/src/python/grpcio_tests/tests/unit/framework/common/test_coverage.py +++ b/src/python/grpcio_tests/tests/unit/framework/common/test_coverage.py @@ -26,7 +26,6 @@ # 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. - """Governs coverage for tests of RPCs throughout RPC Framework.""" import abc @@ -38,80 +37,80 @@ import six class Coverage(six.with_metaclass(abc.ABCMeta)): - """Specification of test coverage.""" + """Specification of test coverage.""" - @abc.abstractmethod - def testSuccessfulUnaryRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testSuccessfulUnaryRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testSuccessfulUnaryRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testSuccessfulUnaryRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testSuccessfulStreamRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testSuccessfulStreamRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testSuccessfulStreamRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testSuccessfulStreamRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testSequentialInvocations(self): - raise NotImplementedError() + @abc.abstractmethod + def testSequentialInvocations(self): + raise NotImplementedError() - @abc.abstractmethod - def testParallelInvocations(self): - raise NotImplementedError() + @abc.abstractmethod + def testParallelInvocations(self): + raise NotImplementedError() - @abc.abstractmethod - def testWaitingForSomeButNotAllParallelInvocations(self): - raise NotImplementedError() + @abc.abstractmethod + def testWaitingForSomeButNotAllParallelInvocations(self): + raise NotImplementedError() - @abc.abstractmethod - def testCancelledUnaryRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testCancelledUnaryRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testCancelledUnaryRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testCancelledUnaryRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testCancelledStreamRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testCancelledStreamRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testCancelledStreamRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testCancelledStreamRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testExpiredUnaryRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testExpiredUnaryRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testExpiredUnaryRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testExpiredUnaryRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testExpiredStreamRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testExpiredStreamRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testExpiredStreamRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testExpiredStreamRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testFailedUnaryRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testFailedUnaryRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testFailedUnaryRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testFailedUnaryRequestStreamResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testFailedStreamRequestUnaryResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testFailedStreamRequestUnaryResponse(self): + raise NotImplementedError() - @abc.abstractmethod - def testFailedStreamRequestStreamResponse(self): - raise NotImplementedError() + @abc.abstractmethod + def testFailedStreamRequestStreamResponse(self): + raise NotImplementedError() diff --git a/src/python/grpcio_tests/tests/unit/framework/foundation/__init__.py b/src/python/grpcio_tests/tests/unit/framework/foundation/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/framework/foundation/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/foundation/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/framework/foundation/_logging_pool_test.py b/src/python/grpcio_tests/tests/unit/framework/foundation/_logging_pool_test.py index 330e445d433..19e8cbdd8eb 100644 --- a/src/python/grpcio_tests/tests/unit/framework/foundation/_logging_pool_test.py +++ b/src/python/grpcio_tests/tests/unit/framework/foundation/_logging_pool_test.py @@ -26,7 +26,6 @@ # 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. - """Tests for grpc.framework.foundation.logging_pool.""" import threading @@ -39,50 +38,51 @@ _POOL_SIZE = 16 class _CallableObject(object): - def __init__(self): - self._lock = threading.Lock() - self._passed_values = [] + def __init__(self): + self._lock = threading.Lock() + self._passed_values = [] - def __call__(self, value): - with self._lock: - self._passed_values.append(value) + def __call__(self, value): + with self._lock: + self._passed_values.append(value) - def passed_values(self): - with self._lock: - return tuple(self._passed_values) + def passed_values(self): + with self._lock: + return tuple(self._passed_values) class LoggingPoolTest(unittest.TestCase): - def testUpAndDown(self): - pool = logging_pool.pool(_POOL_SIZE) - pool.shutdown(wait=True) + def testUpAndDown(self): + pool = logging_pool.pool(_POOL_SIZE) + pool.shutdown(wait=True) - with logging_pool.pool(_POOL_SIZE) as pool: - self.assertIsNotNone(pool) + with logging_pool.pool(_POOL_SIZE) as pool: + self.assertIsNotNone(pool) - def testTaskExecuted(self): - test_list = [] + def testTaskExecuted(self): + test_list = [] - with logging_pool.pool(_POOL_SIZE) as pool: - pool.submit(lambda: test_list.append(object())).result() + with logging_pool.pool(_POOL_SIZE) as pool: + pool.submit(lambda: test_list.append(object())).result() - self.assertTrue(test_list) + self.assertTrue(test_list) - def testException(self): - with logging_pool.pool(_POOL_SIZE) as pool: - raised_exception = pool.submit(lambda: 1/0).exception() + def testException(self): + with logging_pool.pool(_POOL_SIZE) as pool: + raised_exception = pool.submit(lambda: 1 / 0).exception() - self.assertIsNotNone(raised_exception) + self.assertIsNotNone(raised_exception) - def testCallableObjectExecuted(self): - callable_object = _CallableObject() - passed_object = object() - with logging_pool.pool(_POOL_SIZE) as pool: - future = pool.submit(callable_object, passed_object) - self.assertIsNone(future.result()) - self.assertSequenceEqual((passed_object,), callable_object.passed_values()) + def testCallableObjectExecuted(self): + callable_object = _CallableObject() + passed_object = object() + with logging_pool.pool(_POOL_SIZE) as pool: + future = pool.submit(callable_object, passed_object) + self.assertIsNone(future.result()) + self.assertSequenceEqual((passed_object,), + callable_object.passed_values()) if __name__ == '__main__': - unittest.main(verbosity=2) + unittest.main(verbosity=2) diff --git a/src/python/grpcio_tests/tests/unit/framework/foundation/stream_testing.py b/src/python/grpcio_tests/tests/unit/framework/foundation/stream_testing.py index 098a53d5e75..2929e4dd786 100644 --- a/src/python/grpcio_tests/tests/unit/framework/foundation/stream_testing.py +++ b/src/python/grpcio_tests/tests/unit/framework/foundation/stream_testing.py @@ -26,48 +26,47 @@ # 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. - """Utilities for testing stream-related code.""" from grpc.framework.foundation import stream class TestConsumer(stream.Consumer): - """A stream.Consumer instrumented for testing. + """A stream.Consumer instrumented for testing. Attributes: calls: A sequence of value-termination pairs describing the history of calls made on this object. """ - def __init__(self): - self.calls = [] + def __init__(self): + self.calls = [] - def consume(self, value): - """See stream.Consumer.consume for specification.""" - self.calls.append((value, False)) + def consume(self, value): + """See stream.Consumer.consume for specification.""" + self.calls.append((value, False)) - def terminate(self): - """See stream.Consumer.terminate for specification.""" - self.calls.append((None, True)) + def terminate(self): + """See stream.Consumer.terminate for specification.""" + self.calls.append((None, True)) - def consume_and_terminate(self, value): - """See stream.Consumer.consume_and_terminate for specification.""" - self.calls.append((value, True)) + def consume_and_terminate(self, value): + """See stream.Consumer.consume_and_terminate for specification.""" + self.calls.append((value, True)) - def is_legal(self): - """Reports whether or not a legal sequence of calls has been made.""" - terminated = False - for value, terminal in self.calls: - if terminated: - return False - elif terminal: - terminated = True - elif value is None: - return False - else: # pylint: disable=useless-else-on-loop - return True + def is_legal(self): + """Reports whether or not a legal sequence of calls has been made.""" + terminated = False + for value, terminal in self.calls: + if terminated: + return False + elif terminal: + terminated = True + elif value is None: + return False + else: # pylint: disable=useless-else-on-loop + return True - def values(self): - """Returns the sequence of values that have been passed to this Consumer.""" - return [value for value, _ in self.calls if value] + def values(self): + """Returns the sequence of values that have been passed to this Consumer.""" + return [value for value, _ in self.calls if value] diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/__init__.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_3069_test_constant.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_3069_test_constant.py index 1ea356c0bf2..2aec25c9eff 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_3069_test_constant.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_3069_test_constant.py @@ -26,7 +26,6 @@ # 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. - """A test constant working around issue 3069.""" # test_constants is referenced from specification in this module. diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/__init__.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/__init__.py index 70865191060..b89398809fa 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/__init__.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/__init__.py @@ -26,5 +26,3 @@ # 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. - - diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py index e338aaa396d..a79834f96ff 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_blocking_invocation_inline_service.py @@ -26,7 +26,6 @@ # 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. - """Test code for the Face layer of RPC Framework.""" from __future__ import division @@ -50,246 +49,254 @@ from tests.unit.framework.interfaces.face import _stock_service from tests.unit.framework.interfaces.face import test_interfaces # pylint: disable=unused-import -class TestCase(six.with_metaclass(abc.ABCMeta, test_coverage.Coverage, unittest.TestCase)): - """A test of the Face layer of RPC Framework. +class TestCase( + six.with_metaclass(abc.ABCMeta, test_coverage.Coverage, + unittest.TestCase)): + """A test of the Face layer of RPC Framework. Concrete subclasses must have an "implementation" attribute of type test_interfaces.Implementation and an "invoker_constructor" attribute of type _invocation.InvokerConstructor. """ - NAME = 'BlockingInvocationInlineServiceTest' + NAME = 'BlockingInvocationInlineServiceTest' - def setUp(self): - """See unittest.TestCase.setUp for full specification. + def setUp(self): + """See unittest.TestCase.setUp for full specification. Overriding implementations must call this implementation. """ - self._control = test_control.PauseFailControl() - self._digest = _digest.digest( - _stock_service.STOCK_TEST_SERVICE, self._control, None) + self._control = test_control.PauseFailControl() + self._digest = _digest.digest(_stock_service.STOCK_TEST_SERVICE, + self._control, None) - generic_stub, dynamic_stubs, self._memo = self.implementation.instantiate( - self._digest.methods, self._digest.inline_method_implementations, None) - self._invoker = self.invoker_constructor.construct_invoker( - generic_stub, dynamic_stubs, self._digest.methods) + generic_stub, dynamic_stubs, self._memo = self.implementation.instantiate( + self._digest.methods, self._digest.inline_method_implementations, + None) + self._invoker = self.invoker_constructor.construct_invoker( + generic_stub, dynamic_stubs, self._digest.methods) - def tearDown(self): - """See unittest.TestCase.tearDown for full specification. + def tearDown(self): + """See unittest.TestCase.tearDown for full specification. Overriding implementations must call this implementation. """ - self._invoker = None - self.implementation.destantiate(self._memo) - - def testSuccessfulUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - response, call = self._invoker.blocking(group, method)( - request, test_constants.LONG_TIMEOUT, with_call=True) - - test_messages.verify(request, response, self) - - def testSuccessfulUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - response_iterator = self._invoker.blocking(group, method)( - request, test_constants.LONG_TIMEOUT) - responses = list(response_iterator) - - test_messages.verify(request, responses, self) - - def testSuccessfulStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - response, call = self._invoker.blocking(group, method)( - iter(requests), test_constants.LONG_TIMEOUT, with_call=True) - - test_messages.verify(requests, response, self) - - def testSuccessfulStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - response_iterator = self._invoker.blocking(group, method)( - iter(requests), test_constants.LONG_TIMEOUT) - responses = list(response_iterator) - - test_messages.verify(requests, responses, self) - - def testSequentialInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - first_request = test_messages.request() - second_request = test_messages.request() - - first_response = self._invoker.blocking(group, method)( - first_request, test_constants.LONG_TIMEOUT) - - test_messages.verify(first_request, first_response, self) - - second_response = self._invoker.blocking(group, method)( - second_request, test_constants.LONG_TIMEOUT) - - test_messages.verify(second_request, second_response, self) - - def testParallelInvocations(self): - pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = [] - response_futures = [] - for _ in range(test_constants.THREAD_CONCURRENCY): - request = test_messages.request() - response_future = pool.submit( - self._invoker.blocking(group, method), request, - test_constants.LONG_TIMEOUT) - requests.append(request) - response_futures.append(response_future) - - responses = [ - response_future.result() for response_future in response_futures] - - for request, response in zip(requests, responses): - test_messages.verify(request, response, self) - pool.shutdown(wait=True) - - def testWaitingForSomeButNotAllParallelInvocations(self): - pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = [] - response_futures_to_indices = {} - for index in range(test_constants.THREAD_CONCURRENCY): - request = test_messages.request() - response_future = pool.submit( - self._invoker.blocking(group, method), request, - test_constants.LONG_TIMEOUT) - requests.append(request) - response_futures_to_indices[response_future] = index - - some_completed_response_futures_iterator = itertools.islice( - futures.as_completed(response_futures_to_indices), - test_constants.THREAD_CONCURRENCY // 2) - for response_future in some_completed_response_futures_iterator: - index = response_futures_to_indices[response_future] - test_messages.verify(requests[index], response_future.result(), self) - pool.shutdown(wait=True) - - @unittest.skip('Cancellation impossible with blocking control flow!') - def testCancelledUnaryRequestUnaryResponse(self): - raise NotImplementedError() - - @unittest.skip('Cancellation impossible with blocking control flow!') - def testCancelledUnaryRequestStreamResponse(self): - raise NotImplementedError() - - @unittest.skip('Cancellation impossible with blocking control flow!') - def testCancelledStreamRequestUnaryResponse(self): - raise NotImplementedError() - - @unittest.skip('Cancellation impossible with blocking control flow!') - def testCancelledStreamRequestStreamResponse(self): - raise NotImplementedError() - - def testExpiredUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.pause(), self.assertRaises( - face.ExpirationError): - self._invoker.blocking(group, method)( - request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - - def testExpiredUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.pause(), self.assertRaises( - face.ExpirationError): - response_iterator = self._invoker.blocking(group, method)( - request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - list(response_iterator) - - def testExpiredStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.pause(), self.assertRaises( - face.ExpirationError): - self._invoker.blocking(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - - def testExpiredStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.pause(), self.assertRaises( - face.ExpirationError): - response_iterator = self._invoker.blocking(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - list(response_iterator) - - def testFailedUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.fail(), self.assertRaises(face.RemoteError): - self._invoker.blocking(group, method)( - request, test_constants.LONG_TIMEOUT) - - def testFailedUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.fail(), self.assertRaises(face.RemoteError): - response_iterator = self._invoker.blocking(group, method)( - request, test_constants.LONG_TIMEOUT) - list(response_iterator) - - def testFailedStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.fail(), self.assertRaises(face.RemoteError): - self._invoker.blocking(group, method)( - iter(requests), test_constants.LONG_TIMEOUT) - - def testFailedStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.fail(), self.assertRaises(face.RemoteError): - response_iterator = self._invoker.blocking(group, method)( - iter(requests), test_constants.LONG_TIMEOUT) - list(response_iterator) + self._invoker = None + self.implementation.destantiate(self._memo) + + def testSuccessfulUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + response, call = self._invoker.blocking(group, method)( + request, test_constants.LONG_TIMEOUT, with_call=True) + + test_messages.verify(request, response, self) + + def testSuccessfulUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + response_iterator = self._invoker.blocking(group, method)( + request, test_constants.LONG_TIMEOUT) + responses = list(response_iterator) + + test_messages.verify(request, responses, self) + + def testSuccessfulStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + response, call = self._invoker.blocking(group, method)( + iter(requests), test_constants.LONG_TIMEOUT, with_call=True) + + test_messages.verify(requests, response, self) + + def testSuccessfulStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + response_iterator = self._invoker.blocking(group, method)( + iter(requests), test_constants.LONG_TIMEOUT) + responses = list(response_iterator) + + test_messages.verify(requests, responses, self) + + def testSequentialInvocations(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + first_request = test_messages.request() + second_request = test_messages.request() + + first_response = self._invoker.blocking(group, method)( + first_request, test_constants.LONG_TIMEOUT) + + test_messages.verify(first_request, first_response, self) + + second_response = self._invoker.blocking(group, method)( + second_request, test_constants.LONG_TIMEOUT) + + test_messages.verify(second_request, second_response, self) + + def testParallelInvocations(self): + pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = [] + response_futures = [] + for _ in range(test_constants.THREAD_CONCURRENCY): + request = test_messages.request() + response_future = pool.submit( + self._invoker.blocking(group, method), request, + test_constants.LONG_TIMEOUT) + requests.append(request) + response_futures.append(response_future) + + responses = [ + response_future.result() + for response_future in response_futures + ] + + for request, response in zip(requests, responses): + test_messages.verify(request, response, self) + pool.shutdown(wait=True) + + def testWaitingForSomeButNotAllParallelInvocations(self): + pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = [] + response_futures_to_indices = {} + for index in range(test_constants.THREAD_CONCURRENCY): + request = test_messages.request() + response_future = pool.submit( + self._invoker.blocking(group, method), request, + test_constants.LONG_TIMEOUT) + requests.append(request) + response_futures_to_indices[response_future] = index + + some_completed_response_futures_iterator = itertools.islice( + futures.as_completed(response_futures_to_indices), + test_constants.THREAD_CONCURRENCY // 2) + for response_future in some_completed_response_futures_iterator: + index = response_futures_to_indices[response_future] + test_messages.verify(requests[index], + response_future.result(), self) + pool.shutdown(wait=True) + + @unittest.skip('Cancellation impossible with blocking control flow!') + def testCancelledUnaryRequestUnaryResponse(self): + raise NotImplementedError() + + @unittest.skip('Cancellation impossible with blocking control flow!') + def testCancelledUnaryRequestStreamResponse(self): + raise NotImplementedError() + + @unittest.skip('Cancellation impossible with blocking control flow!') + def testCancelledStreamRequestUnaryResponse(self): + raise NotImplementedError() + + @unittest.skip('Cancellation impossible with blocking control flow!') + def testCancelledStreamRequestStreamResponse(self): + raise NotImplementedError() + + def testExpiredUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.pause(), self.assertRaises( + face.ExpirationError): + self._invoker.blocking(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + + def testExpiredUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.pause(), self.assertRaises( + face.ExpirationError): + response_iterator = self._invoker.blocking(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + list(response_iterator) + + def testExpiredStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.pause(), self.assertRaises( + face.ExpirationError): + self._invoker.blocking(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + + def testExpiredStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.pause(), self.assertRaises( + face.ExpirationError): + response_iterator = self._invoker.blocking(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + list(response_iterator) + + def testFailedUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.fail(), self.assertRaises(face.RemoteError): + self._invoker.blocking(group, method)( + request, test_constants.LONG_TIMEOUT) + + def testFailedUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.fail(), self.assertRaises(face.RemoteError): + response_iterator = self._invoker.blocking(group, method)( + request, test_constants.LONG_TIMEOUT) + list(response_iterator) + + def testFailedStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.fail(), self.assertRaises(face.RemoteError): + self._invoker.blocking(group, method)( + iter(requests), test_constants.LONG_TIMEOUT) + + def testFailedStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.fail(), self.assertRaises(face.RemoteError): + response_iterator = self._invoker.blocking(group, method)( + iter(requests), test_constants.LONG_TIMEOUT) + list(response_iterator) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py index f0befb0b273..0411da0a667 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_digest.py @@ -26,7 +26,6 @@ # 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. - """Code for making a service.TestService more amenable to use in tests.""" import collections @@ -49,17 +48,16 @@ _IDENTITY = lambda x: x class TestServiceDigest( - collections.namedtuple( - 'TestServiceDigest', - ('methods', - 'inline_method_implementations', - 'event_method_implementations', - 'multi_method_implementation', - 'unary_unary_messages_sequences', - 'unary_stream_messages_sequences', - 'stream_unary_messages_sequences', - 'stream_stream_messages_sequences',))): - """A transformation of a service.TestService. + collections.namedtuple('TestServiceDigest', ( + 'methods', + 'inline_method_implementations', + 'event_method_implementations', + 'multi_method_implementation', + 'unary_unary_messages_sequences', + 'unary_stream_messages_sequences', + 'stream_unary_messages_sequences', + 'stream_stream_messages_sequences',))): + """A transformation of a service.TestService. Attributes: methods: A dict from method group-name pair to test_interfaces.Method object @@ -88,303 +86,308 @@ class TestServiceDigest( class _BufferingConsumer(stream.Consumer): - """A trivial Consumer that dumps what it consumes in a user-mutable buffer.""" + """A trivial Consumer that dumps what it consumes in a user-mutable buffer.""" - def __init__(self): - self.consumed = [] - self.terminated = False + def __init__(self): + self.consumed = [] + self.terminated = False - def consume(self, value): - self.consumed.append(value) + def consume(self, value): + self.consumed.append(value) - def terminate(self): - self.terminated = True + def terminate(self): + self.terminated = True - def consume_and_terminate(self, value): - self.consumed.append(value) - self.terminated = True + def consume_and_terminate(self, value): + self.consumed.append(value) + self.terminated = True class _InlineUnaryUnaryMethod(face.MethodImplementation): - def __init__(self, unary_unary_test_method, control): - self._test_method = unary_unary_test_method - self._control = control + def __init__(self, unary_unary_test_method, control): + self._test_method = unary_unary_test_method + self._control = control - self.cardinality = cardinality.Cardinality.UNARY_UNARY - self.style = style.Service.INLINE + self.cardinality = cardinality.Cardinality.UNARY_UNARY + self.style = style.Service.INLINE - def unary_unary_inline(self, request, context): - response_list = [] - self._test_method.service( - request, response_list.append, context, self._control) - return response_list.pop(0) + def unary_unary_inline(self, request, context): + response_list = [] + self._test_method.service(request, response_list.append, context, + self._control) + return response_list.pop(0) class _EventUnaryUnaryMethod(face.MethodImplementation): - def __init__(self, unary_unary_test_method, control, pool): - self._test_method = unary_unary_test_method - self._control = control - self._pool = pool + def __init__(self, unary_unary_test_method, control, pool): + self._test_method = unary_unary_test_method + self._control = control + self._pool = pool - self.cardinality = cardinality.Cardinality.UNARY_UNARY - self.style = style.Service.EVENT + self.cardinality = cardinality.Cardinality.UNARY_UNARY + self.style = style.Service.EVENT - def unary_unary_event(self, request, response_callback, context): - if self._pool is None: - self._test_method.service( - request, response_callback, context, self._control) - else: - self._pool.submit( - self._test_method.service, request, response_callback, context, - self._control) + def unary_unary_event(self, request, response_callback, context): + if self._pool is None: + self._test_method.service(request, response_callback, context, + self._control) + else: + self._pool.submit(self._test_method.service, request, + response_callback, context, self._control) class _InlineUnaryStreamMethod(face.MethodImplementation): - def __init__(self, unary_stream_test_method, control): - self._test_method = unary_stream_test_method - self._control = control + def __init__(self, unary_stream_test_method, control): + self._test_method = unary_stream_test_method + self._control = control - self.cardinality = cardinality.Cardinality.UNARY_STREAM - self.style = style.Service.INLINE + self.cardinality = cardinality.Cardinality.UNARY_STREAM + self.style = style.Service.INLINE - def unary_stream_inline(self, request, context): - response_consumer = _BufferingConsumer() - self._test_method.service( - request, response_consumer, context, self._control) - for response in response_consumer.consumed: - yield response + def unary_stream_inline(self, request, context): + response_consumer = _BufferingConsumer() + self._test_method.service(request, response_consumer, context, + self._control) + for response in response_consumer.consumed: + yield response class _EventUnaryStreamMethod(face.MethodImplementation): - def __init__(self, unary_stream_test_method, control, pool): - self._test_method = unary_stream_test_method - self._control = control - self._pool = pool + def __init__(self, unary_stream_test_method, control, pool): + self._test_method = unary_stream_test_method + self._control = control + self._pool = pool - self.cardinality = cardinality.Cardinality.UNARY_STREAM - self.style = style.Service.EVENT + self.cardinality = cardinality.Cardinality.UNARY_STREAM + self.style = style.Service.EVENT - def unary_stream_event(self, request, response_consumer, context): - if self._pool is None: - self._test_method.service( - request, response_consumer, context, self._control) - else: - self._pool.submit( - self._test_method.service, request, response_consumer, context, - self._control) + def unary_stream_event(self, request, response_consumer, context): + if self._pool is None: + self._test_method.service(request, response_consumer, context, + self._control) + else: + self._pool.submit(self._test_method.service, request, + response_consumer, context, self._control) class _InlineStreamUnaryMethod(face.MethodImplementation): - def __init__(self, stream_unary_test_method, control): - self._test_method = stream_unary_test_method - self._control = control + def __init__(self, stream_unary_test_method, control): + self._test_method = stream_unary_test_method + self._control = control - self.cardinality = cardinality.Cardinality.STREAM_UNARY - self.style = style.Service.INLINE + self.cardinality = cardinality.Cardinality.STREAM_UNARY + self.style = style.Service.INLINE - def stream_unary_inline(self, request_iterator, context): - response_list = [] - request_consumer = self._test_method.service( - response_list.append, context, self._control) - for request in request_iterator: - request_consumer.consume(request) - request_consumer.terminate() - return response_list.pop(0) + def stream_unary_inline(self, request_iterator, context): + response_list = [] + request_consumer = self._test_method.service(response_list.append, + context, self._control) + for request in request_iterator: + request_consumer.consume(request) + request_consumer.terminate() + return response_list.pop(0) class _EventStreamUnaryMethod(face.MethodImplementation): - def __init__(self, stream_unary_test_method, control, pool): - self._test_method = stream_unary_test_method - self._control = control - self._pool = pool + def __init__(self, stream_unary_test_method, control, pool): + self._test_method = stream_unary_test_method + self._control = control + self._pool = pool - self.cardinality = cardinality.Cardinality.STREAM_UNARY - self.style = style.Service.EVENT + self.cardinality = cardinality.Cardinality.STREAM_UNARY + self.style = style.Service.EVENT - def stream_unary_event(self, response_callback, context): - request_consumer = self._test_method.service( - response_callback, context, self._control) - if self._pool is None: - return request_consumer - else: - return stream_util.ThreadSwitchingConsumer(request_consumer, self._pool) + def stream_unary_event(self, response_callback, context): + request_consumer = self._test_method.service(response_callback, context, + self._control) + if self._pool is None: + return request_consumer + else: + return stream_util.ThreadSwitchingConsumer(request_consumer, + self._pool) class _InlineStreamStreamMethod(face.MethodImplementation): - def __init__(self, stream_stream_test_method, control): - self._test_method = stream_stream_test_method - self._control = control + def __init__(self, stream_stream_test_method, control): + self._test_method = stream_stream_test_method + self._control = control - self.cardinality = cardinality.Cardinality.STREAM_STREAM - self.style = style.Service.INLINE + self.cardinality = cardinality.Cardinality.STREAM_STREAM + self.style = style.Service.INLINE - def stream_stream_inline(self, request_iterator, context): - response_consumer = _BufferingConsumer() - request_consumer = self._test_method.service( - response_consumer, context, self._control) + def stream_stream_inline(self, request_iterator, context): + response_consumer = _BufferingConsumer() + request_consumer = self._test_method.service(response_consumer, context, + self._control) - for request in request_iterator: - request_consumer.consume(request) - while response_consumer.consumed: - yield response_consumer.consumed.pop(0) - response_consumer.terminate() + for request in request_iterator: + request_consumer.consume(request) + while response_consumer.consumed: + yield response_consumer.consumed.pop(0) + response_consumer.terminate() class _EventStreamStreamMethod(face.MethodImplementation): - def __init__(self, stream_stream_test_method, control, pool): - self._test_method = stream_stream_test_method - self._control = control - self._pool = pool + def __init__(self, stream_stream_test_method, control, pool): + self._test_method = stream_stream_test_method + self._control = control + self._pool = pool - self.cardinality = cardinality.Cardinality.STREAM_STREAM - self.style = style.Service.EVENT + self.cardinality = cardinality.Cardinality.STREAM_STREAM + self.style = style.Service.EVENT - def stream_stream_event(self, response_consumer, context): - request_consumer = self._test_method.service( - response_consumer, context, self._control) - if self._pool is None: - return request_consumer - else: - return stream_util.ThreadSwitchingConsumer(request_consumer, self._pool) + def stream_stream_event(self, response_consumer, context): + request_consumer = self._test_method.service(response_consumer, context, + self._control) + if self._pool is None: + return request_consumer + else: + return stream_util.ThreadSwitchingConsumer(request_consumer, + self._pool) class _UnaryConsumer(stream.Consumer): - """A Consumer that only allows consumption of exactly one value.""" - - def __init__(self, action): - self._lock = threading.Lock() - self._action = action - self._consumed = False - self._terminated = False - - def consume(self, value): - with self._lock: - if self._consumed: - raise ValueError('Unary consumer already consumed!') - elif self._terminated: - raise ValueError('Unary consumer already terminated!') - else: - self._consumed = True - - self._action(value) - - def terminate(self): - with self._lock: - if not self._consumed: - raise ValueError('Unary consumer hasn\'t yet consumed!') - elif self._terminated: - raise ValueError('Unary consumer already terminated!') - else: - self._terminated = True - - def consume_and_terminate(self, value): - with self._lock: - if self._consumed: - raise ValueError('Unary consumer already consumed!') - elif self._terminated: - raise ValueError('Unary consumer already terminated!') - else: - self._consumed = True - self._terminated = True - - self._action(value) + """A Consumer that only allows consumption of exactly one value.""" + + def __init__(self, action): + self._lock = threading.Lock() + self._action = action + self._consumed = False + self._terminated = False + + def consume(self, value): + with self._lock: + if self._consumed: + raise ValueError('Unary consumer already consumed!') + elif self._terminated: + raise ValueError('Unary consumer already terminated!') + else: + self._consumed = True + + self._action(value) + + def terminate(self): + with self._lock: + if not self._consumed: + raise ValueError('Unary consumer hasn\'t yet consumed!') + elif self._terminated: + raise ValueError('Unary consumer already terminated!') + else: + self._terminated = True + + def consume_and_terminate(self, value): + with self._lock: + if self._consumed: + raise ValueError('Unary consumer already consumed!') + elif self._terminated: + raise ValueError('Unary consumer already terminated!') + else: + self._consumed = True + self._terminated = True + + self._action(value) class _UnaryUnaryAdaptation(object): - def __init__(self, unary_unary_test_method): - self._method = unary_unary_test_method + def __init__(self, unary_unary_test_method): + self._method = unary_unary_test_method + + def service(self, response_consumer, context, control): + + def action(request): + self._method.service(request, + response_consumer.consume_and_terminate, + context, control) - def service(self, response_consumer, context, control): - def action(request): - self._method.service( - request, response_consumer.consume_and_terminate, context, control) - return _UnaryConsumer(action) + return _UnaryConsumer(action) class _UnaryStreamAdaptation(object): - def __init__(self, unary_stream_test_method): - self._method = unary_stream_test_method + def __init__(self, unary_stream_test_method): + self._method = unary_stream_test_method + + def service(self, response_consumer, context, control): + + def action(request): + self._method.service(request, response_consumer, context, control) - def service(self, response_consumer, context, control): - def action(request): - self._method.service(request, response_consumer, context, control) - return _UnaryConsumer(action) + return _UnaryConsumer(action) class _StreamUnaryAdaptation(object): - def __init__(self, stream_unary_test_method): - self._method = stream_unary_test_method + def __init__(self, stream_unary_test_method): + self._method = stream_unary_test_method - def service(self, response_consumer, context, control): - return self._method.service( - response_consumer.consume_and_terminate, context, control) + def service(self, response_consumer, context, control): + return self._method.service(response_consumer.consume_and_terminate, + context, control) class _MultiMethodImplementation(face.MultiMethodImplementation): - def __init__(self, methods, control, pool): - self._methods = methods - self._control = control - self._pool = pool + def __init__(self, methods, control, pool): + self._methods = methods + self._control = control + self._pool = pool - def service(self, group, name, response_consumer, context): - method = self._methods.get(group, name, None) - if method is None: - raise face.NoSuchMethodError(group, name) - elif self._pool is None: - return method(response_consumer, context, self._control) - else: - request_consumer = method(response_consumer, context, self._control) - return stream_util.ThreadSwitchingConsumer(request_consumer, self._pool) + def service(self, group, name, response_consumer, context): + method = self._methods.get(group, name, None) + if method is None: + raise face.NoSuchMethodError(group, name) + elif self._pool is None: + return method(response_consumer, context, self._control) + else: + request_consumer = method(response_consumer, context, self._control) + return stream_util.ThreadSwitchingConsumer(request_consumer, + self._pool) class _Assembly( - collections.namedtuple( - '_Assembly', - ['methods', 'inlines', 'events', 'adaptations', 'messages'])): - """An intermediate structure created when creating a TestServiceDigest.""" - - -def _assemble( - scenarios, identifiers, inline_method_constructor, event_method_constructor, - adapter, control, pool): - """Creates an _Assembly from the given scenarios.""" - methods = {} - inlines = {} - events = {} - adaptations = {} - messages = {} - for identifier, scenario in six.iteritems(scenarios): - if identifier in identifiers: - raise ValueError('Repeated identifier "(%s, %s)"!' % identifier) - - test_method = scenario[0] - inline_method = inline_method_constructor(test_method, control) - event_method = event_method_constructor(test_method, control, pool) - adaptation = adapter(test_method) - - methods[identifier] = test_method - inlines[identifier] = inline_method - events[identifier] = event_method - adaptations[identifier] = adaptation - messages[identifier] = scenario[1] - - return _Assembly(methods, inlines, events, adaptations, messages) + collections.namedtuple( + '_Assembly', + ['methods', 'inlines', 'events', 'adaptations', 'messages'])): + """An intermediate structure created when creating a TestServiceDigest.""" + + +def _assemble(scenarios, identifiers, inline_method_constructor, + event_method_constructor, adapter, control, pool): + """Creates an _Assembly from the given scenarios.""" + methods = {} + inlines = {} + events = {} + adaptations = {} + messages = {} + for identifier, scenario in six.iteritems(scenarios): + if identifier in identifiers: + raise ValueError('Repeated identifier "(%s, %s)"!' % identifier) + + test_method = scenario[0] + inline_method = inline_method_constructor(test_method, control) + event_method = event_method_constructor(test_method, control, pool) + adaptation = adapter(test_method) + + methods[identifier] = test_method + inlines[identifier] = inline_method + events[identifier] = event_method + adaptations[identifier] = adaptation + messages[identifier] = scenario[1] + + return _Assembly(methods, inlines, events, adaptations, messages) def digest(service, control, pool): - """Creates a TestServiceDigest from a TestService. + """Creates a TestServiceDigest from a TestService. Args: service: A _service.TestService. @@ -396,51 +399,48 @@ def digest(service, control, pool): Returns: A TestServiceDigest synthesized from the given service.TestService. """ - identifiers = set() - - unary_unary = _assemble( - service.unary_unary_scenarios(), identifiers, _InlineUnaryUnaryMethod, - _EventUnaryUnaryMethod, _UnaryUnaryAdaptation, control, pool) - identifiers.update(unary_unary.inlines) - - unary_stream = _assemble( - service.unary_stream_scenarios(), identifiers, _InlineUnaryStreamMethod, - _EventUnaryStreamMethod, _UnaryStreamAdaptation, control, pool) - identifiers.update(unary_stream.inlines) - - stream_unary = _assemble( - service.stream_unary_scenarios(), identifiers, _InlineStreamUnaryMethod, - _EventStreamUnaryMethod, _StreamUnaryAdaptation, control, pool) - identifiers.update(stream_unary.inlines) - - stream_stream = _assemble( - service.stream_stream_scenarios(), identifiers, _InlineStreamStreamMethod, - _EventStreamStreamMethod, _IDENTITY, control, pool) - identifiers.update(stream_stream.inlines) - - methods = dict(unary_unary.methods) - methods.update(unary_stream.methods) - methods.update(stream_unary.methods) - methods.update(stream_stream.methods) - adaptations = dict(unary_unary.adaptations) - adaptations.update(unary_stream.adaptations) - adaptations.update(stream_unary.adaptations) - adaptations.update(stream_stream.adaptations) - inlines = dict(unary_unary.inlines) - inlines.update(unary_stream.inlines) - inlines.update(stream_unary.inlines) - inlines.update(stream_stream.inlines) - events = dict(unary_unary.events) - events.update(unary_stream.events) - events.update(stream_unary.events) - events.update(stream_stream.events) - - return TestServiceDigest( - methods, - inlines, - events, - _MultiMethodImplementation(adaptations, control, pool), - unary_unary.messages, - unary_stream.messages, - stream_unary.messages, - stream_stream.messages) + identifiers = set() + + unary_unary = _assemble(service.unary_unary_scenarios(), identifiers, + _InlineUnaryUnaryMethod, _EventUnaryUnaryMethod, + _UnaryUnaryAdaptation, control, pool) + identifiers.update(unary_unary.inlines) + + unary_stream = _assemble(service.unary_stream_scenarios(), identifiers, + _InlineUnaryStreamMethod, _EventUnaryStreamMethod, + _UnaryStreamAdaptation, control, pool) + identifiers.update(unary_stream.inlines) + + stream_unary = _assemble(service.stream_unary_scenarios(), identifiers, + _InlineStreamUnaryMethod, _EventStreamUnaryMethod, + _StreamUnaryAdaptation, control, pool) + identifiers.update(stream_unary.inlines) + + stream_stream = _assemble(service.stream_stream_scenarios(), identifiers, + _InlineStreamStreamMethod, + _EventStreamStreamMethod, _IDENTITY, control, + pool) + identifiers.update(stream_stream.inlines) + + methods = dict(unary_unary.methods) + methods.update(unary_stream.methods) + methods.update(stream_unary.methods) + methods.update(stream_stream.methods) + adaptations = dict(unary_unary.adaptations) + adaptations.update(unary_stream.adaptations) + adaptations.update(stream_unary.adaptations) + adaptations.update(stream_stream.adaptations) + inlines = dict(unary_unary.inlines) + inlines.update(unary_stream.inlines) + inlines.update(stream_unary.inlines) + inlines.update(stream_stream.inlines) + events = dict(unary_unary.events) + events.update(unary_stream.events) + events.update(stream_unary.events) + events.update(stream_stream.events) + + return TestServiceDigest( + methods, inlines, events, + _MultiMethodImplementation(adaptations, control, pool), + unary_unary.messages, unary_stream.messages, stream_unary.messages, + stream_stream.messages) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py index df620b19ba5..703eef3a82c 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_future_invocation_asynchronous_event_service.py @@ -26,7 +26,6 @@ # 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. - """Test code for the Face layer of RPC Framework.""" from __future__ import division @@ -55,457 +54,470 @@ from tests.unit.framework.interfaces.face import test_interfaces # pylint: disa class _PauseableIterator(object): - def __init__(self, upstream): - self._upstream = upstream - self._condition = threading.Condition() - self._paused = False + def __init__(self, upstream): + self._upstream = upstream + self._condition = threading.Condition() + self._paused = False - @contextlib.contextmanager - def pause(self): - with self._condition: - self._paused = True - yield - with self._condition: - self._paused = False - self._condition.notify_all() + @contextlib.contextmanager + def pause(self): + with self._condition: + self._paused = True + yield + with self._condition: + self._paused = False + self._condition.notify_all() - def __iter__(self): - return self + def __iter__(self): + return self - def __next__(self): - return self.next() + def __next__(self): + return self.next() - def next(self): - with self._condition: - while self._paused: - self._condition.wait() - return next(self._upstream) + def next(self): + with self._condition: + while self._paused: + self._condition.wait() + return next(self._upstream) class _Callback(object): - def __init__(self): - self._condition = threading.Condition() - self._called = False - self._passed_future = None - self._passed_other_stuff = None - - def __call__(self, *args, **kwargs): - with self._condition: - self._called = True - if args: - self._passed_future = args[0] - if 1 < len(args) or kwargs: - self._passed_other_stuff = tuple(args[1:]), dict(kwargs) - self._condition.notify_all() - - def future(self): - with self._condition: - while True: - if self._passed_other_stuff is not None: - raise ValueError( - 'Test callback passed unexpected values: %s', - self._passed_other_stuff) - elif self._called: - return self._passed_future - else: - self._condition.wait() - - -class TestCase(six.with_metaclass(abc.ABCMeta, test_coverage.Coverage, unittest.TestCase)): - """A test of the Face layer of RPC Framework. + def __init__(self): + self._condition = threading.Condition() + self._called = False + self._passed_future = None + self._passed_other_stuff = None + + def __call__(self, *args, **kwargs): + with self._condition: + self._called = True + if args: + self._passed_future = args[0] + if 1 < len(args) or kwargs: + self._passed_other_stuff = tuple(args[1:]), dict(kwargs) + self._condition.notify_all() + + def future(self): + with self._condition: + while True: + if self._passed_other_stuff is not None: + raise ValueError( + 'Test callback passed unexpected values: %s', + self._passed_other_stuff) + elif self._called: + return self._passed_future + else: + self._condition.wait() + + +class TestCase( + six.with_metaclass(abc.ABCMeta, test_coverage.Coverage, + unittest.TestCase)): + """A test of the Face layer of RPC Framework. Concrete subclasses must have an "implementation" attribute of type test_interfaces.Implementation and an "invoker_constructor" attribute of type _invocation.InvokerConstructor. """ - NAME = 'FutureInvocationAsynchronousEventServiceTest' + NAME = 'FutureInvocationAsynchronousEventServiceTest' - def setUp(self): - """See unittest.TestCase.setUp for full specification. + def setUp(self): + """See unittest.TestCase.setUp for full specification. Overriding implementations must call this implementation. """ - self._control = test_control.PauseFailControl() - self._digest_pool = logging_pool.pool(test_constants.POOL_SIZE) - self._digest = _digest.digest( - _stock_service.STOCK_TEST_SERVICE, self._control, self._digest_pool) + self._control = test_control.PauseFailControl() + self._digest_pool = logging_pool.pool(test_constants.POOL_SIZE) + self._digest = _digest.digest(_stock_service.STOCK_TEST_SERVICE, + self._control, self._digest_pool) - generic_stub, dynamic_stubs, self._memo = self.implementation.instantiate( - self._digest.methods, self._digest.event_method_implementations, None) - self._invoker = self.invoker_constructor.construct_invoker( - generic_stub, dynamic_stubs, self._digest.methods) + generic_stub, dynamic_stubs, self._memo = self.implementation.instantiate( + self._digest.methods, self._digest.event_method_implementations, + None) + self._invoker = self.invoker_constructor.construct_invoker( + generic_stub, dynamic_stubs, self._digest.methods) - def tearDown(self): - """See unittest.TestCase.tearDown for full specification. + def tearDown(self): + """See unittest.TestCase.tearDown for full specification. Overriding implementations must call this implementation. """ - self._invoker = None - self.implementation.destantiate(self._memo) - self._digest_pool.shutdown(wait=True) - - def testSuccessfulUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - callback = _Callback() - - response_future = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - response_future.add_done_callback(callback) - response = response_future.result() - - test_messages.verify(request, response, self) - self.assertIs(callback.future(), response_future) - self.assertIsNone(response_future.exception()) - self.assertIsNone(response_future.traceback()) - - def testSuccessfulUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - response_iterator = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - responses = list(response_iterator) - - test_messages.verify(request, responses, self) - - def testSuccessfulStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - request_iterator = _PauseableIterator(iter(requests)) - callback = _Callback() - - # Use of a paused iterator of requests allows us to test that control is - # returned to calling code before the iterator yields any requests. - with request_iterator.pause(): - response_future = self._invoker.future(group, method)( - request_iterator, test_constants.LONG_TIMEOUT) - response_future.add_done_callback(callback) - future_passed_to_callback = callback.future() - response = future_passed_to_callback.result() - - test_messages.verify(requests, response, self) - self.assertIs(future_passed_to_callback, response_future) - self.assertIsNone(response_future.exception()) - self.assertIsNone(response_future.traceback()) - - def testSuccessfulStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - request_iterator = _PauseableIterator(iter(requests)) - - # Use of a paused iterator of requests allows us to test that control is - # returned to calling code before the iterator yields any requests. - with request_iterator.pause(): - response_iterator = self._invoker.future(group, method)( - request_iterator, test_constants.LONG_TIMEOUT) - responses = list(response_iterator) - - test_messages.verify(requests, responses, self) - - def testSequentialInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - first_request = test_messages.request() - second_request = test_messages.request() - - first_response_future = self._invoker.future(group, method)( - first_request, test_constants.LONG_TIMEOUT) - first_response = first_response_future.result() - - test_messages.verify(first_request, first_response, self) - - second_response_future = self._invoker.future(group, method)( - second_request, test_constants.LONG_TIMEOUT) - second_response = second_response_future.result() - - test_messages.verify(second_request, second_response, self) - - def testParallelInvocations(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - first_request = test_messages.request() - second_request = test_messages.request() - - first_response_future = self._invoker.future(group, method)( - first_request, test_constants.LONG_TIMEOUT) - second_response_future = self._invoker.future(group, method)( - second_request, test_constants.LONG_TIMEOUT) - first_response = first_response_future.result() - second_response = second_response_future.result() - - test_messages.verify(first_request, first_response, self) - test_messages.verify(second_request, second_response, self) - - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = [] - response_futures = [] - for _ in range(test_constants.THREAD_CONCURRENCY): - request = test_messages.request() - response_future = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - requests.append(request) - response_futures.append(response_future) - - responses = [ - response_future.result() for response_future in response_futures] - - for request, response in zip(requests, responses): - test_messages.verify(request, response, self) - - def testWaitingForSomeButNotAllParallelInvocations(self): - pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = [] - response_futures_to_indices = {} - for index in range(test_constants.THREAD_CONCURRENCY): - request = test_messages.request() - inner_response_future = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - outer_response_future = pool.submit(inner_response_future.result) - requests.append(request) - response_futures_to_indices[outer_response_future] = index - - some_completed_response_futures_iterator = itertools.islice( - futures.as_completed(response_futures_to_indices), - test_constants.THREAD_CONCURRENCY // 2) - for response_future in some_completed_response_futures_iterator: - index = response_futures_to_indices[response_future] - test_messages.verify(requests[index], response_future.result(), self) - pool.shutdown(wait=True) - - def testCancelledUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - callback = _Callback() - - with self._control.pause(): - response_future = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - response_future.add_done_callback(callback) - cancel_method_return_value = response_future.cancel() - - self.assertIs(callback.future(), response_future) - self.assertFalse(cancel_method_return_value) - self.assertTrue(response_future.cancelled()) - with self.assertRaises(future.CancelledError): - response_future.result() - with self.assertRaises(future.CancelledError): - response_future.exception() - with self.assertRaises(future.CancelledError): - response_future.traceback() - - def testCancelledUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.pause(): - response_iterator = self._invoker.future(group, method)( - request, test_constants.LONG_TIMEOUT) - response_iterator.cancel() - - with self.assertRaises(face.CancellationError): - next(response_iterator) - - def testCancelledStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - callback = _Callback() - - with self._control.pause(): - response_future = self._invoker.future(group, method)( - iter(requests), test_constants.LONG_TIMEOUT) - response_future.add_done_callback(callback) - cancel_method_return_value = response_future.cancel() - - self.assertIs(callback.future(), response_future) - self.assertFalse(cancel_method_return_value) - self.assertTrue(response_future.cancelled()) - with self.assertRaises(future.CancelledError): - response_future.result() - with self.assertRaises(future.CancelledError): - response_future.exception() - with self.assertRaises(future.CancelledError): - response_future.traceback() - - def testCancelledStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.pause(): - response_iterator = self._invoker.future(group, method)( - iter(requests), test_constants.LONG_TIMEOUT) - response_iterator.cancel() - - with self.assertRaises(face.CancellationError): - next(response_iterator) - - def testExpiredUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - callback = _Callback() - - with self._control.pause(): - response_future = self._invoker.future( - group, method)(request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - response_future.add_done_callback(callback) - self.assertIs(callback.future(), response_future) - self.assertIsInstance( - response_future.exception(), face.ExpirationError) - with self.assertRaises(face.ExpirationError): - response_future.result() - self.assertIsInstance( - response_future.exception(), face.AbortionError) - self.assertIsNotNone(response_future.traceback()) - - def testExpiredUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - with self._control.pause(): - response_iterator = self._invoker.future(group, method)( - request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - list(response_iterator) - - def testExpiredStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - callback = _Callback() - - with self._control.pause(): - response_future = self._invoker.future(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - response_future.add_done_callback(callback) - self.assertIs(callback.future(), response_future) - self.assertIsInstance( - response_future.exception(), face.ExpirationError) - with self.assertRaises(face.ExpirationError): - response_future.result() - self.assertIsInstance( - response_future.exception(), face.AbortionError) - self.assertIsNotNone(response_future.traceback()) - - def testExpiredStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - with self._control.pause(): - response_iterator = self._invoker.future(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - with self.assertRaises(face.ExpirationError): - list(response_iterator) - - def testFailedUnaryRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_unary_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - callback = _Callback() - abortion_callback = _Callback() - - with self._control.fail(): - response_future = self._invoker.future(group, method)( - request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - response_future.add_done_callback(callback) - response_future.add_abortion_callback(abortion_callback) - - self.assertIs(callback.future(), response_future) - # Because the servicer fails outside of the thread from which the - # servicer-side runtime called into it its failure is - # indistinguishable from simply not having called its - # response_callback before the expiration of the RPC. - self.assertIsInstance( - response_future.exception(), face.ExpirationError) - with self.assertRaises(face.ExpirationError): - response_future.result() - self.assertIsNotNone(response_future.traceback()) - self.assertIsNotNone(abortion_callback.future()) - - def testFailedUnaryRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.unary_stream_messages_sequences)): - for test_messages in test_messages_sequence: - request = test_messages.request() - - # Because the servicer fails outside of the thread from which the - # servicer-side runtime called into it its failure is indistinguishable - # from simply not having called its response_consumer before the - # expiration of the RPC. - with self._control.fail(), self.assertRaises(face.ExpirationError): - response_iterator = self._invoker.future(group, method)( - request, _3069_test_constant.REALLY_SHORT_TIMEOUT) - list(response_iterator) - - def testFailedStreamRequestUnaryResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_unary_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - callback = _Callback() - abortion_callback = _Callback() - - with self._control.fail(): - response_future = self._invoker.future(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - response_future.add_done_callback(callback) - response_future.add_abortion_callback(abortion_callback) - - self.assertIs(callback.future(), response_future) - # Because the servicer fails outside of the thread from which the - # servicer-side runtime called into it its failure is - # indistinguishable from simply not having called its - # response_callback before the expiration of the RPC. - self.assertIsInstance( - response_future.exception(), face.ExpirationError) - with self.assertRaises(face.ExpirationError): - response_future.result() - self.assertIsNotNone(response_future.traceback()) - self.assertIsNotNone(abortion_callback.future()) - - def testFailedStreamRequestStreamResponse(self): - for (group, method), test_messages_sequence in ( - six.iteritems(self._digest.stream_stream_messages_sequences)): - for test_messages in test_messages_sequence: - requests = test_messages.requests() - - # Because the servicer fails outside of the thread from which the - # servicer-side runtime called into it its failure is indistinguishable - # from simply not having called its response_consumer before the - # expiration of the RPC. - with self._control.fail(), self.assertRaises(face.ExpirationError): - response_iterator = self._invoker.future(group, method)( - iter(requests), _3069_test_constant.REALLY_SHORT_TIMEOUT) - list(response_iterator) + self._invoker = None + self.implementation.destantiate(self._memo) + self._digest_pool.shutdown(wait=True) + + def testSuccessfulUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + callback = _Callback() + + response_future = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + response_future.add_done_callback(callback) + response = response_future.result() + + test_messages.verify(request, response, self) + self.assertIs(callback.future(), response_future) + self.assertIsNone(response_future.exception()) + self.assertIsNone(response_future.traceback()) + + def testSuccessfulUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + response_iterator = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + responses = list(response_iterator) + + test_messages.verify(request, responses, self) + + def testSuccessfulStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + request_iterator = _PauseableIterator(iter(requests)) + callback = _Callback() + + # Use of a paused iterator of requests allows us to test that control is + # returned to calling code before the iterator yields any requests. + with request_iterator.pause(): + response_future = self._invoker.future(group, method)( + request_iterator, test_constants.LONG_TIMEOUT) + response_future.add_done_callback(callback) + future_passed_to_callback = callback.future() + response = future_passed_to_callback.result() + + test_messages.verify(requests, response, self) + self.assertIs(future_passed_to_callback, response_future) + self.assertIsNone(response_future.exception()) + self.assertIsNone(response_future.traceback()) + + def testSuccessfulStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + request_iterator = _PauseableIterator(iter(requests)) + + # Use of a paused iterator of requests allows us to test that control is + # returned to calling code before the iterator yields any requests. + with request_iterator.pause(): + response_iterator = self._invoker.future(group, method)( + request_iterator, test_constants.LONG_TIMEOUT) + responses = list(response_iterator) + + test_messages.verify(requests, responses, self) + + def testSequentialInvocations(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + first_request = test_messages.request() + second_request = test_messages.request() + + first_response_future = self._invoker.future(group, method)( + first_request, test_constants.LONG_TIMEOUT) + first_response = first_response_future.result() + + test_messages.verify(first_request, first_response, self) + + second_response_future = self._invoker.future(group, method)( + second_request, test_constants.LONG_TIMEOUT) + second_response = second_response_future.result() + + test_messages.verify(second_request, second_response, self) + + def testParallelInvocations(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + first_request = test_messages.request() + second_request = test_messages.request() + + first_response_future = self._invoker.future(group, method)( + first_request, test_constants.LONG_TIMEOUT) + second_response_future = self._invoker.future(group, method)( + second_request, test_constants.LONG_TIMEOUT) + first_response = first_response_future.result() + second_response = second_response_future.result() + + test_messages.verify(first_request, first_response, self) + test_messages.verify(second_request, second_response, self) + + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = [] + response_futures = [] + for _ in range(test_constants.THREAD_CONCURRENCY): + request = test_messages.request() + response_future = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + requests.append(request) + response_futures.append(response_future) + + responses = [ + response_future.result() + for response_future in response_futures + ] + + for request, response in zip(requests, responses): + test_messages.verify(request, response, self) + + def testWaitingForSomeButNotAllParallelInvocations(self): + pool = logging_pool.pool(test_constants.THREAD_CONCURRENCY) + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = [] + response_futures_to_indices = {} + for index in range(test_constants.THREAD_CONCURRENCY): + request = test_messages.request() + inner_response_future = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + outer_response_future = pool.submit( + inner_response_future.result) + requests.append(request) + response_futures_to_indices[outer_response_future] = index + + some_completed_response_futures_iterator = itertools.islice( + futures.as_completed(response_futures_to_indices), + test_constants.THREAD_CONCURRENCY // 2) + for response_future in some_completed_response_futures_iterator: + index = response_futures_to_indices[response_future] + test_messages.verify(requests[index], + response_future.result(), self) + pool.shutdown(wait=True) + + def testCancelledUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + callback = _Callback() + + with self._control.pause(): + response_future = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + response_future.add_done_callback(callback) + cancel_method_return_value = response_future.cancel() + + self.assertIs(callback.future(), response_future) + self.assertFalse(cancel_method_return_value) + self.assertTrue(response_future.cancelled()) + with self.assertRaises(future.CancelledError): + response_future.result() + with self.assertRaises(future.CancelledError): + response_future.exception() + with self.assertRaises(future.CancelledError): + response_future.traceback() + + def testCancelledUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.pause(): + response_iterator = self._invoker.future(group, method)( + request, test_constants.LONG_TIMEOUT) + response_iterator.cancel() + + with self.assertRaises(face.CancellationError): + next(response_iterator) + + def testCancelledStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + callback = _Callback() + + with self._control.pause(): + response_future = self._invoker.future(group, method)( + iter(requests), test_constants.LONG_TIMEOUT) + response_future.add_done_callback(callback) + cancel_method_return_value = response_future.cancel() + + self.assertIs(callback.future(), response_future) + self.assertFalse(cancel_method_return_value) + self.assertTrue(response_future.cancelled()) + with self.assertRaises(future.CancelledError): + response_future.result() + with self.assertRaises(future.CancelledError): + response_future.exception() + with self.assertRaises(future.CancelledError): + response_future.traceback() + + def testCancelledStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.pause(): + response_iterator = self._invoker.future(group, method)( + iter(requests), test_constants.LONG_TIMEOUT) + response_iterator.cancel() + + with self.assertRaises(face.CancellationError): + next(response_iterator) + + def testExpiredUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + callback = _Callback() + + with self._control.pause(): + response_future = self._invoker.future(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future.add_done_callback(callback) + self.assertIs(callback.future(), response_future) + self.assertIsInstance(response_future.exception(), + face.ExpirationError) + with self.assertRaises(face.ExpirationError): + response_future.result() + self.assertIsInstance(response_future.exception(), + face.AbortionError) + self.assertIsNotNone(response_future.traceback()) + + def testExpiredUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + with self._control.pause(): + response_iterator = self._invoker.future(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + list(response_iterator) + + def testExpiredStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + callback = _Callback() + + with self._control.pause(): + response_future = self._invoker.future(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future.add_done_callback(callback) + self.assertIs(callback.future(), response_future) + self.assertIsInstance(response_future.exception(), + face.ExpirationError) + with self.assertRaises(face.ExpirationError): + response_future.result() + self.assertIsInstance(response_future.exception(), + face.AbortionError) + self.assertIsNotNone(response_future.traceback()) + + def testExpiredStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + with self._control.pause(): + response_iterator = self._invoker.future(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + with self.assertRaises(face.ExpirationError): + list(response_iterator) + + def testFailedUnaryRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_unary_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + callback = _Callback() + abortion_callback = _Callback() + + with self._control.fail(): + response_future = self._invoker.future(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future.add_done_callback(callback) + response_future.add_abortion_callback(abortion_callback) + + self.assertIs(callback.future(), response_future) + # Because the servicer fails outside of the thread from which the + # servicer-side runtime called into it its failure is + # indistinguishable from simply not having called its + # response_callback before the expiration of the RPC. + self.assertIsInstance(response_future.exception(), + face.ExpirationError) + with self.assertRaises(face.ExpirationError): + response_future.result() + self.assertIsNotNone(response_future.traceback()) + self.assertIsNotNone(abortion_callback.future()) + + def testFailedUnaryRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.unary_stream_messages_sequences)): + for test_messages in test_messages_sequence: + request = test_messages.request() + + # Because the servicer fails outside of the thread from which the + # servicer-side runtime called into it its failure is indistinguishable + # from simply not having called its response_consumer before the + # expiration of the RPC. + with self._control.fail(), self.assertRaises( + face.ExpirationError): + response_iterator = self._invoker.future(group, method)( + request, _3069_test_constant.REALLY_SHORT_TIMEOUT) + list(response_iterator) + + def testFailedStreamRequestUnaryResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_unary_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + callback = _Callback() + abortion_callback = _Callback() + + with self._control.fail(): + response_future = self._invoker.future(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + response_future.add_done_callback(callback) + response_future.add_abortion_callback(abortion_callback) + + self.assertIs(callback.future(), response_future) + # Because the servicer fails outside of the thread from which the + # servicer-side runtime called into it its failure is + # indistinguishable from simply not having called its + # response_callback before the expiration of the RPC. + self.assertIsInstance(response_future.exception(), + face.ExpirationError) + with self.assertRaises(face.ExpirationError): + response_future.result() + self.assertIsNotNone(response_future.traceback()) + self.assertIsNotNone(abortion_callback.future()) + + def testFailedStreamRequestStreamResponse(self): + for (group, method), test_messages_sequence in ( + six.iteritems(self._digest.stream_stream_messages_sequences)): + for test_messages in test_messages_sequence: + requests = test_messages.requests() + + # Because the servicer fails outside of the thread from which the + # servicer-side runtime called into it its failure is indistinguishable + # from simply not having called its response_consumer before the + # expiration of the RPC. + with self._control.fail(), self.assertRaises( + face.ExpirationError): + response_iterator = self._invoker.future(group, method)( + iter(requests), + _3069_test_constant.REALLY_SHORT_TIMEOUT) + list(response_iterator) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py index ac487bed4f9..4e144a36352 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_invocation.py @@ -26,7 +26,6 @@ # 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. - """Coverage across the Face layer's generic-to-dynamic range for invocation.""" import abc @@ -65,149 +64,149 @@ _CARDINALITY_TO_MULTI_CALLABLE_ATTRIBUTE = { class Invoker(six.with_metaclass(abc.ABCMeta)): - """A type used to invoke test RPCs.""" + """A type used to invoke test RPCs.""" - @abc.abstractmethod - def blocking(self, group, name): - """Invokes an RPC with blocking control flow.""" - raise NotImplementedError() + @abc.abstractmethod + def blocking(self, group, name): + """Invokes an RPC with blocking control flow.""" + raise NotImplementedError() - @abc.abstractmethod - def future(self, group, name): - """Invokes an RPC with future control flow.""" - raise NotImplementedError() + @abc.abstractmethod + def future(self, group, name): + """Invokes an RPC with future control flow.""" + raise NotImplementedError() - @abc.abstractmethod - def event(self, group, name): - """Invokes an RPC with event control flow.""" - raise NotImplementedError() + @abc.abstractmethod + def event(self, group, name): + """Invokes an RPC with event control flow.""" + raise NotImplementedError() class InvokerConstructor(six.with_metaclass(abc.ABCMeta)): - """A type used to create Invokers.""" + """A type used to create Invokers.""" - @abc.abstractmethod - def name(self): - """Specifies the name of the Invoker constructed by this object.""" - raise NotImplementedError() + @abc.abstractmethod + def name(self): + """Specifies the name of the Invoker constructed by this object.""" + raise NotImplementedError() - @abc.abstractmethod - def construct_invoker(self, generic_stub, dynamic_stubs, methods): - """Constructs an Invoker for the given stubs and methods.""" - raise NotImplementedError() + @abc.abstractmethod + def construct_invoker(self, generic_stub, dynamic_stubs, methods): + """Constructs an Invoker for the given stubs and methods.""" + raise NotImplementedError() class _GenericInvoker(Invoker): - def __init__(self, generic_stub, methods): - self._stub = generic_stub - self._methods = methods + def __init__(self, generic_stub, methods): + self._stub = generic_stub + self._methods = methods - def _behavior(self, group, name, cardinality_to_generic_method): - method_cardinality = self._methods[group, name].cardinality() - behavior = getattr( - self._stub, cardinality_to_generic_method[method_cardinality]) - return lambda *args, **kwargs: behavior(group, name, *args, **kwargs) + def _behavior(self, group, name, cardinality_to_generic_method): + method_cardinality = self._methods[group, name].cardinality() + behavior = getattr(self._stub, + cardinality_to_generic_method[method_cardinality]) + return lambda *args, **kwargs: behavior(group, name, *args, **kwargs) - def blocking(self, group, name): - return self._behavior( - group, name, _CARDINALITY_TO_GENERIC_BLOCKING_BEHAVIOR) + def blocking(self, group, name): + return self._behavior(group, name, + _CARDINALITY_TO_GENERIC_BLOCKING_BEHAVIOR) - def future(self, group, name): - return self._behavior(group, name, _CARDINALITY_TO_GENERIC_FUTURE_BEHAVIOR) + def future(self, group, name): + return self._behavior(group, name, + _CARDINALITY_TO_GENERIC_FUTURE_BEHAVIOR) - def event(self, group, name): - return self._behavior(group, name, _CARDINALITY_TO_GENERIC_EVENT_BEHAVIOR) + def event(self, group, name): + return self._behavior(group, name, + _CARDINALITY_TO_GENERIC_EVENT_BEHAVIOR) class _GenericInvokerConstructor(InvokerConstructor): - def name(self): - return 'GenericInvoker' + def name(self): + return 'GenericInvoker' - def construct_invoker(self, generic_stub, dynamic_stub, methods): - return _GenericInvoker(generic_stub, methods) + def construct_invoker(self, generic_stub, dynamic_stub, methods): + return _GenericInvoker(generic_stub, methods) class _MultiCallableInvoker(Invoker): - def __init__(self, generic_stub, methods): - self._stub = generic_stub - self._methods = methods + def __init__(self, generic_stub, methods): + self._stub = generic_stub + self._methods = methods - def _multi_callable(self, group, name): - method_cardinality = self._methods[group, name].cardinality() - behavior = getattr( - self._stub, - _CARDINALITY_TO_MULTI_CALLABLE_ATTRIBUTE[method_cardinality]) - return behavior(group, name) + def _multi_callable(self, group, name): + method_cardinality = self._methods[group, name].cardinality() + behavior = getattr( + self._stub, + _CARDINALITY_TO_MULTI_CALLABLE_ATTRIBUTE[method_cardinality]) + return behavior(group, name) - def blocking(self, group, name): - return self._multi_callable(group, name) + def blocking(self, group, name): + return self._multi_callable(group, name) - def future(self, group, name): - method_cardinality = self._methods[group, name].cardinality() - behavior = getattr( - self._stub, - _CARDINALITY_TO_MULTI_CALLABLE_ATTRIBUTE[method_cardinality]) - if method_cardinality in ( - cardinality.Cardinality.UNARY_UNARY, - cardinality.Cardinality.STREAM_UNARY): - return behavior(group, name).future - else: - return behavior(group, name) + def future(self, group, name): + method_cardinality = self._methods[group, name].cardinality() + behavior = getattr( + self._stub, + _CARDINALITY_TO_MULTI_CALLABLE_ATTRIBUTE[method_cardinality]) + if method_cardinality in (cardinality.Cardinality.UNARY_UNARY, + cardinality.Cardinality.STREAM_UNARY): + return behavior(group, name).future + else: + return behavior(group, name) - def event(self, group, name): - return self._multi_callable(group, name).event + def event(self, group, name): + return self._multi_callable(group, name).event class _MultiCallableInvokerConstructor(InvokerConstructor): - def name(self): - return 'MultiCallableInvoker' + def name(self): + return 'MultiCallableInvoker' - def construct_invoker(self, generic_stub, dynamic_stub, methods): - return _MultiCallableInvoker(generic_stub, methods) + def construct_invoker(self, generic_stub, dynamic_stub, methods): + return _MultiCallableInvoker(generic_stub, methods) class _DynamicInvoker(Invoker): - def __init__(self, dynamic_stubs, methods): - self._stubs = dynamic_stubs - self._methods = methods + def __init__(self, dynamic_stubs, methods): + self._stubs = dynamic_stubs + self._methods = methods - def blocking(self, group, name): - return getattr(self._stubs[group], name) + def blocking(self, group, name): + return getattr(self._stubs[group], name) - def future(self, group, name): - if self._methods[group, name].cardinality() in ( - cardinality.Cardinality.UNARY_UNARY, - cardinality.Cardinality.STREAM_UNARY): - return getattr(self._stubs[group], name).future - else: - return getattr(self._stubs[group], name) + def future(self, group, name): + if self._methods[group, name].cardinality() in ( + cardinality.Cardinality.UNARY_UNARY, + cardinality.Cardinality.STREAM_UNARY): + return getattr(self._stubs[group], name).future + else: + return getattr(self._stubs[group], name) - def event(self, group, name): - return getattr(self._stubs[group], name).event + def event(self, group, name): + return getattr(self._stubs[group], name).event class _DynamicInvokerConstructor(InvokerConstructor): - def name(self): - return 'DynamicInvoker' + def name(self): + return 'DynamicInvoker' - def construct_invoker(self, generic_stub, dynamic_stubs, methods): - return _DynamicInvoker(dynamic_stubs, methods) + def construct_invoker(self, generic_stub, dynamic_stubs, methods): + return _DynamicInvoker(dynamic_stubs, methods) def invoker_constructors(): - """Creates a sequence of InvokerConstructors to use in tests of RPCs. + """Creates a sequence of InvokerConstructors to use in tests of RPCs. Returns: A sequence of InvokerConstructors. """ - return ( - _GenericInvokerConstructor(), - _MultiCallableInvokerConstructor(), - _DynamicInvokerConstructor(), - ) + return ( + _GenericInvokerConstructor(), + _MultiCallableInvokerConstructor(), + _DynamicInvokerConstructor(),) diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_service.py index f13dff05585..f14ac6a9871 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_service.py @@ -26,7 +26,6 @@ # 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. - """Private interfaces implemented by data sets used in Face-layer tests.""" import abc @@ -38,12 +37,13 @@ from grpc.framework.interfaces.face import face # pylint: disable=unused-import from tests.unit.framework.interfaces.face import test_interfaces -class UnaryUnaryTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): - """A controllable implementation of a unary-unary method.""" +class UnaryUnaryTestMethodImplementation( + six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): + """A controllable implementation of a unary-unary method.""" - @abc.abstractmethod - def service(self, request, response_callback, context, control): - """Services an RPC that accepts one message and produces one message. + @abc.abstractmethod + def service(self, request, response_callback, context, control): + """Services an RPC that accepts one message and produces one message. Args: request: The single request message for the RPC. @@ -56,15 +56,15 @@ class UnaryUnaryTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_in abandonment.Abandoned: May or may not be raised when the RPC has been aborted. """ - raise NotImplementedError() + raise NotImplementedError() class UnaryUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): - """A type for unary-request-unary-response message pairings.""" + """A type for unary-request-unary-response message pairings.""" - @abc.abstractmethod - def request(self): - """Affords a request message. + @abc.abstractmethod + def request(self): + """Affords a request message. Implementations of this method should return a different message with each call so that multiple test executions of the test method may be made with @@ -73,11 +73,11 @@ class UnaryUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): Returns: A request message. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def verify(self, request, response, test_case): - """Verifies that the computed response matches the given request. + @abc.abstractmethod + def verify(self, request, response, test_case): + """Verifies that the computed response matches the given request. Args: request: A request message. @@ -88,15 +88,16 @@ class UnaryUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): AssertionError: If the request and response do not match, indicating that there was some problem executing the RPC under test. """ - raise NotImplementedError() + raise NotImplementedError() -class UnaryStreamTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): - """A controllable implementation of a unary-stream method.""" +class UnaryStreamTestMethodImplementation( + six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): + """A controllable implementation of a unary-stream method.""" - @abc.abstractmethod - def service(self, request, response_consumer, context, control): - """Services an RPC that takes one message and produces a stream of messages. + @abc.abstractmethod + def service(self, request, response_consumer, context, control): + """Services an RPC that takes one message and produces a stream of messages. Args: request: The single request message for the RPC. @@ -109,15 +110,15 @@ class UnaryStreamTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_i abandonment.Abandoned: May or may not be raised when the RPC has been aborted. """ - raise NotImplementedError() + raise NotImplementedError() class UnaryStreamTestMessages(six.with_metaclass(abc.ABCMeta)): - """A type for unary-request-stream-response message pairings.""" + """A type for unary-request-stream-response message pairings.""" - @abc.abstractmethod - def request(self): - """Affords a request message. + @abc.abstractmethod + def request(self): + """Affords a request message. Implementations of this method should return a different message with each call so that multiple test executions of the test method may be made with @@ -126,11 +127,11 @@ class UnaryStreamTestMessages(six.with_metaclass(abc.ABCMeta)): Returns: A request message. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def verify(self, request, responses, test_case): - """Verifies that the computed responses match the given request. + @abc.abstractmethod + def verify(self, request, responses, test_case): + """Verifies that the computed responses match the given request. Args: request: A request message. @@ -141,15 +142,16 @@ class UnaryStreamTestMessages(six.with_metaclass(abc.ABCMeta)): AssertionError: If the request and responses do not match, indicating that there was some problem executing the RPC under test. """ - raise NotImplementedError() + raise NotImplementedError() -class StreamUnaryTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): - """A controllable implementation of a stream-unary method.""" +class StreamUnaryTestMethodImplementation( + six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): + """A controllable implementation of a stream-unary method.""" - @abc.abstractmethod - def service(self, response_callback, context, control): - """Services an RPC that takes a stream of messages and produces one message. + @abc.abstractmethod + def service(self, response_callback, context, control): + """Services an RPC that takes a stream of messages and produces one message. Args: response_callback: A callback to be called to accept the response message @@ -169,15 +171,15 @@ class StreamUnaryTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_i abandonment.Abandoned: May or may not be raised when the RPC has been aborted. """ - raise NotImplementedError() + raise NotImplementedError() class StreamUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): - """A type for stream-request-unary-response message pairings.""" + """A type for stream-request-unary-response message pairings.""" - @abc.abstractmethod - def requests(self): - """Affords a sequence of request messages. + @abc.abstractmethod + def requests(self): + """Affords a sequence of request messages. Implementations of this method should return a different sequences with each call so that multiple test executions of the test method may be made with @@ -186,11 +188,11 @@ class StreamUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): Returns: A sequence of request messages. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def verify(self, requests, response, test_case): - """Verifies that the computed response matches the given requests. + @abc.abstractmethod + def verify(self, requests, response, test_case): + """Verifies that the computed response matches the given requests. Args: requests: A sequence of request messages. @@ -201,15 +203,16 @@ class StreamUnaryTestMessages(six.with_metaclass(abc.ABCMeta)): AssertionError: If the requests and response do not match, indicating that there was some problem executing the RPC under test. """ - raise NotImplementedError() + raise NotImplementedError() -class StreamStreamTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): - """A controllable implementation of a stream-stream method.""" +class StreamStreamTestMethodImplementation( + six.with_metaclass(abc.ABCMeta, test_interfaces.Method)): + """A controllable implementation of a stream-stream method.""" - @abc.abstractmethod - def service(self, response_consumer, context, control): - """Services an RPC that accepts and produces streams of messages. + @abc.abstractmethod + def service(self, response_consumer, context, control): + """Services an RPC that accepts and produces streams of messages. Args: response_consumer: A stream.Consumer to be called to accept the response @@ -229,15 +232,15 @@ class StreamStreamTestMethodImplementation(six.with_metaclass(abc.ABCMeta, test_ abandonment.Abandoned: May or may not be raised when the RPC has been aborted. """ - raise NotImplementedError() + raise NotImplementedError() class StreamStreamTestMessages(six.with_metaclass(abc.ABCMeta)): - """A type for stream-request-stream-response message pairings.""" + """A type for stream-request-stream-response message pairings.""" - @abc.abstractmethod - def requests(self): - """Affords a sequence of request messages. + @abc.abstractmethod + def requests(self): + """Affords a sequence of request messages. Implementations of this method should return a different sequences with each call so that multiple test executions of the test method may be made with @@ -246,11 +249,11 @@ class StreamStreamTestMessages(six.with_metaclass(abc.ABCMeta)): Returns: A sequence of request messages. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def verify(self, requests, responses, test_case): - """Verifies that the computed response matches the given requests. + @abc.abstractmethod + def verify(self, requests, responses, test_case): + """Verifies that the computed response matches the given requests. Args: requests: A sequence of request messages. @@ -261,15 +264,15 @@ class StreamStreamTestMessages(six.with_metaclass(abc.ABCMeta)): AssertionError: If the requests and responses do not match, indicating that there was some problem executing the RPC under test. """ - raise NotImplementedError() + raise NotImplementedError() class TestService(six.with_metaclass(abc.ABCMeta)): - """A specification of implemented methods to use in tests.""" + """A specification of implemented methods to use in tests.""" - @abc.abstractmethod - def unary_unary_scenarios(self): - """Affords unary-request-unary-response test methods and their messages. + @abc.abstractmethod + def unary_unary_scenarios(self): + """Affords unary-request-unary-response test methods and their messages. Returns: A dict from method group-name pair to implementation/messages pair. The @@ -277,11 +280,11 @@ class TestService(six.with_metaclass(abc.ABCMeta)): and the second element is a sequence of UnaryUnaryTestMethodMessages objects. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def unary_stream_scenarios(self): - """Affords unary-request-stream-response test methods and their messages. + @abc.abstractmethod + def unary_stream_scenarios(self): + """Affords unary-request-stream-response test methods and their messages. Returns: A dict from method group-name pair to implementation/messages pair. The @@ -289,11 +292,11 @@ class TestService(six.with_metaclass(abc.ABCMeta)): object and the second element is a sequence of UnaryStreamTestMethodMessages objects. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_unary_scenarios(self): - """Affords stream-request-unary-response test methods and their messages. + @abc.abstractmethod + def stream_unary_scenarios(self): + """Affords stream-request-unary-response test methods and their messages. Returns: A dict from method group-name pair to implementation/messages pair. The @@ -301,11 +304,11 @@ class TestService(six.with_metaclass(abc.ABCMeta)): object and the second element is a sequence of StreamUnaryTestMethodMessages objects. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def stream_stream_scenarios(self): - """Affords stream-request-stream-response test methods and their messages. + @abc.abstractmethod + def stream_stream_scenarios(self): + """Affords stream-request-stream-response test methods and their messages. Returns: A dict from method group-name pair to implementation/messages pair. The @@ -313,4 +316,4 @@ class TestService(six.with_metaclass(abc.ABCMeta)): object and the second element is a sequence of StreamStreamTestMethodMessages objects. """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py index 5299655bb3b..41a55c13f4d 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/_stock_service.py @@ -26,7 +26,6 @@ # 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. - """Examples of Python implementations of the stock.proto Stock service.""" from grpc.framework.common import cardinality @@ -44,353 +43,363 @@ _price = lambda symbol_name: float(hash(symbol_name) % 4096) def _get_last_trade_price(stock_request, stock_reply_callback, control, active): - """A unary-request, unary-response test method.""" - control.control() - if active(): - stock_reply_callback( - stock_pb2.StockReply( - symbol=stock_request.symbol, price=_price(stock_request.symbol))) - else: - raise abandonment.Abandoned() - - -def _get_last_trade_price_multiple(stock_reply_consumer, control, active): - """A stream-request, stream-response test method.""" - def stock_reply_for_stock_request(stock_request): + """A unary-request, unary-response test method.""" control.control() if active(): - return stock_pb2.StockReply( - symbol=stock_request.symbol, price=_price(stock_request.symbol)) + stock_reply_callback( + stock_pb2.StockReply( + symbol=stock_request.symbol, price=_price( + stock_request.symbol))) else: - raise abandonment.Abandoned() - - class StockRequestConsumer(stream.Consumer): + raise abandonment.Abandoned() - def consume(self, stock_request): - stock_reply_consumer.consume(stock_reply_for_stock_request(stock_request)) - def terminate(self): - control.control() - stock_reply_consumer.terminate() +def _get_last_trade_price_multiple(stock_reply_consumer, control, active): + """A stream-request, stream-response test method.""" - def consume_and_terminate(self, stock_request): - stock_reply_consumer.consume_and_terminate( - stock_reply_for_stock_request(stock_request)) + def stock_reply_for_stock_request(stock_request): + control.control() + if active(): + return stock_pb2.StockReply( + symbol=stock_request.symbol, price=_price(stock_request.symbol)) + else: + raise abandonment.Abandoned() - return StockRequestConsumer() + class StockRequestConsumer(stream.Consumer): + def consume(self, stock_request): + stock_reply_consumer.consume( + stock_reply_for_stock_request(stock_request)) -def _watch_future_trades(stock_request, stock_reply_consumer, control, active): - """A unary-request, stream-response test method.""" - base_price = _price(stock_request.symbol) - for index in range(stock_request.num_trades_to_watch): - control.control() - if active(): - stock_reply_consumer.consume( - stock_pb2.StockReply( - symbol=stock_request.symbol, price=base_price + index)) - else: - raise abandonment.Abandoned() - stock_reply_consumer.terminate() + def terminate(self): + control.control() + stock_reply_consumer.terminate() + def consume_and_terminate(self, stock_request): + stock_reply_consumer.consume_and_terminate( + stock_reply_for_stock_request(stock_request)) -def _get_highest_trade_price(stock_reply_callback, control, active): - """A stream-request, unary-response test method.""" + return StockRequestConsumer() - class StockRequestConsumer(stream.Consumer): - """Keeps an ongoing record of the most valuable symbol yet consumed.""" - def __init__(self): - self._symbol = None - self._price = None - - def consume(self, stock_request): - control.control() - if active(): - if self._price is None: - self._symbol = stock_request.symbol - self._price = _price(stock_request.symbol) - else: - candidate_price = _price(stock_request.symbol) - if self._price < candidate_price: - self._symbol = stock_request.symbol - self._price = candidate_price - - def terminate(self): - control.control() - if active(): - if self._symbol is None: - raise ValueError() - else: - stock_reply_callback( - stock_pb2.StockReply(symbol=self._symbol, price=self._price)) - self._symbol = None - self._price = None - - def consume_and_terminate(self, stock_request): - control.control() - if active(): - if self._price is None: - stock_reply_callback( - stock_pb2.StockReply( - symbol=stock_request.symbol, - price=_price(stock_request.symbol))) - else: - candidate_price = _price(stock_request.symbol) - if self._price < candidate_price: - stock_reply_callback( - stock_pb2.StockReply( - symbol=stock_request.symbol, price=candidate_price)) - else: - stock_reply_callback( +def _watch_future_trades(stock_request, stock_reply_consumer, control, active): + """A unary-request, stream-response test method.""" + base_price = _price(stock_request.symbol) + for index in range(stock_request.num_trades_to_watch): + control.control() + if active(): + stock_reply_consumer.consume( stock_pb2.StockReply( - symbol=self._symbol, price=self._price)) + symbol=stock_request.symbol, price=base_price + index)) + else: + raise abandonment.Abandoned() + stock_reply_consumer.terminate() - self._symbol = None - self._price = None - return StockRequestConsumer() +def _get_highest_trade_price(stock_reply_callback, control, active): + """A stream-request, unary-response test method.""" + + class StockRequestConsumer(stream.Consumer): + """Keeps an ongoing record of the most valuable symbol yet consumed.""" + + def __init__(self): + self._symbol = None + self._price = None + + def consume(self, stock_request): + control.control() + if active(): + if self._price is None: + self._symbol = stock_request.symbol + self._price = _price(stock_request.symbol) + else: + candidate_price = _price(stock_request.symbol) + if self._price < candidate_price: + self._symbol = stock_request.symbol + self._price = candidate_price + + def terminate(self): + control.control() + if active(): + if self._symbol is None: + raise ValueError() + else: + stock_reply_callback( + stock_pb2.StockReply( + symbol=self._symbol, price=self._price)) + self._symbol = None + self._price = None + + def consume_and_terminate(self, stock_request): + control.control() + if active(): + if self._price is None: + stock_reply_callback( + stock_pb2.StockReply( + symbol=stock_request.symbol, + price=_price(stock_request.symbol))) + else: + candidate_price = _price(stock_request.symbol) + if self._price < candidate_price: + stock_reply_callback( + stock_pb2.StockReply( + symbol=stock_request.symbol, + price=candidate_price)) + else: + stock_reply_callback( + stock_pb2.StockReply( + symbol=self._symbol, price=self._price)) + + self._symbol = None + self._price = None + + return StockRequestConsumer() class GetLastTradePrice(_service.UnaryUnaryTestMethodImplementation): - """GetLastTradePrice for use in tests.""" + """GetLastTradePrice for use in tests.""" - def group(self): - return _STOCK_GROUP_NAME + def group(self): + return _STOCK_GROUP_NAME - def name(self): - return 'GetLastTradePrice' + def name(self): + return 'GetLastTradePrice' - def cardinality(self): - return cardinality.Cardinality.UNARY_UNARY + def cardinality(self): + return cardinality.Cardinality.UNARY_UNARY - def request_class(self): - return stock_pb2.StockRequest + def request_class(self): + return stock_pb2.StockRequest - def response_class(self): - return stock_pb2.StockReply + def response_class(self): + return stock_pb2.StockReply - def serialize_request(self, request): - return request.SerializeToString() + def serialize_request(self, request): + return request.SerializeToString() - def deserialize_request(self, serialized_request): - return stock_pb2.StockRequest.FromString(serialized_request) + def deserialize_request(self, serialized_request): + return stock_pb2.StockRequest.FromString(serialized_request) - def serialize_response(self, response): - return response.SerializeToString() + def serialize_response(self, response): + return response.SerializeToString() - def deserialize_response(self, serialized_response): - return stock_pb2.StockReply.FromString(serialized_response) + def deserialize_response(self, serialized_response): + return stock_pb2.StockReply.FromString(serialized_response) - def service(self, request, response_callback, context, control): - _get_last_trade_price( - request, response_callback, control, context.is_active) + def service(self, request, response_callback, context, control): + _get_last_trade_price(request, response_callback, control, + context.is_active) class GetLastTradePriceMessages(_service.UnaryUnaryTestMessages): - def __init__(self): - self._index = 0 + def __init__(self): + self._index = 0 - def request(self): - symbol = _SYMBOL_FORMAT % self._index - self._index += 1 - return stock_pb2.StockRequest(symbol=symbol) + def request(self): + symbol = _SYMBOL_FORMAT % self._index + self._index += 1 + return stock_pb2.StockRequest(symbol=symbol) - def verify(self, request, response, test_case): - test_case.assertEqual(request.symbol, response.symbol) - test_case.assertEqual(_price(request.symbol), response.price) + def verify(self, request, response, test_case): + test_case.assertEqual(request.symbol, response.symbol) + test_case.assertEqual(_price(request.symbol), response.price) class GetLastTradePriceMultiple(_service.StreamStreamTestMethodImplementation): - """GetLastTradePriceMultiple for use in tests.""" + """GetLastTradePriceMultiple for use in tests.""" - def group(self): - return _STOCK_GROUP_NAME + def group(self): + return _STOCK_GROUP_NAME - def name(self): - return 'GetLastTradePriceMultiple' + def name(self): + return 'GetLastTradePriceMultiple' - def cardinality(self): - return cardinality.Cardinality.STREAM_STREAM + def cardinality(self): + return cardinality.Cardinality.STREAM_STREAM - def request_class(self): - return stock_pb2.StockRequest + def request_class(self): + return stock_pb2.StockRequest - def response_class(self): - return stock_pb2.StockReply + def response_class(self): + return stock_pb2.StockReply - def serialize_request(self, request): - return request.SerializeToString() + def serialize_request(self, request): + return request.SerializeToString() - def deserialize_request(self, serialized_request): - return stock_pb2.StockRequest.FromString(serialized_request) + def deserialize_request(self, serialized_request): + return stock_pb2.StockRequest.FromString(serialized_request) - def serialize_response(self, response): - return response.SerializeToString() + def serialize_response(self, response): + return response.SerializeToString() - def deserialize_response(self, serialized_response): - return stock_pb2.StockReply.FromString(serialized_response) + def deserialize_response(self, serialized_response): + return stock_pb2.StockReply.FromString(serialized_response) - def service(self, response_consumer, context, control): - return _get_last_trade_price_multiple( - response_consumer, control, context.is_active) + def service(self, response_consumer, context, control): + return _get_last_trade_price_multiple(response_consumer, control, + context.is_active) class GetLastTradePriceMultipleMessages(_service.StreamStreamTestMessages): - """Pairs of message streams for use with GetLastTradePriceMultiple.""" + """Pairs of message streams for use with GetLastTradePriceMultiple.""" - def __init__(self): - self._index = 0 + def __init__(self): + self._index = 0 - def requests(self): - base_index = self._index - self._index += 1 - return [ - stock_pb2.StockRequest(symbol=_SYMBOL_FORMAT % (base_index + index)) - for index in range(test_constants.STREAM_LENGTH)] + def requests(self): + base_index = self._index + self._index += 1 + return [ + stock_pb2.StockRequest(symbol=_SYMBOL_FORMAT % (base_index + index)) + for index in range(test_constants.STREAM_LENGTH) + ] - def verify(self, requests, responses, test_case): - test_case.assertEqual(len(requests), len(responses)) - for stock_request, stock_reply in zip(requests, responses): - test_case.assertEqual(stock_request.symbol, stock_reply.symbol) - test_case.assertEqual(_price(stock_request.symbol), stock_reply.price) + def verify(self, requests, responses, test_case): + test_case.assertEqual(len(requests), len(responses)) + for stock_request, stock_reply in zip(requests, responses): + test_case.assertEqual(stock_request.symbol, stock_reply.symbol) + test_case.assertEqual( + _price(stock_request.symbol), stock_reply.price) class WatchFutureTrades(_service.UnaryStreamTestMethodImplementation): - """WatchFutureTrades for use in tests.""" + """WatchFutureTrades for use in tests.""" - def group(self): - return _STOCK_GROUP_NAME + def group(self): + return _STOCK_GROUP_NAME - def name(self): - return 'WatchFutureTrades' + def name(self): + return 'WatchFutureTrades' - def cardinality(self): - return cardinality.Cardinality.UNARY_STREAM + def cardinality(self): + return cardinality.Cardinality.UNARY_STREAM - def request_class(self): - return stock_pb2.StockRequest + def request_class(self): + return stock_pb2.StockRequest - def response_class(self): - return stock_pb2.StockReply + def response_class(self): + return stock_pb2.StockReply - def serialize_request(self, request): - return request.SerializeToString() + def serialize_request(self, request): + return request.SerializeToString() - def deserialize_request(self, serialized_request): - return stock_pb2.StockRequest.FromString(serialized_request) + def deserialize_request(self, serialized_request): + return stock_pb2.StockRequest.FromString(serialized_request) - def serialize_response(self, response): - return response.SerializeToString() + def serialize_response(self, response): + return response.SerializeToString() - def deserialize_response(self, serialized_response): - return stock_pb2.StockReply.FromString(serialized_response) + def deserialize_response(self, serialized_response): + return stock_pb2.StockReply.FromString(serialized_response) - def service(self, request, response_consumer, context, control): - _watch_future_trades(request, response_consumer, control, context.is_active) + def service(self, request, response_consumer, context, control): + _watch_future_trades(request, response_consumer, control, + context.is_active) class WatchFutureTradesMessages(_service.UnaryStreamTestMessages): - """Pairs of a single request message and a sequence of response messages.""" + """Pairs of a single request message and a sequence of response messages.""" - def __init__(self): - self._index = 0 + def __init__(self): + self._index = 0 - def request(self): - symbol = _SYMBOL_FORMAT % self._index - self._index += 1 - return stock_pb2.StockRequest( - symbol=symbol, num_trades_to_watch=test_constants.STREAM_LENGTH) + def request(self): + symbol = _SYMBOL_FORMAT % self._index + self._index += 1 + return stock_pb2.StockRequest( + symbol=symbol, num_trades_to_watch=test_constants.STREAM_LENGTH) - def verify(self, request, responses, test_case): - test_case.assertEqual(test_constants.STREAM_LENGTH, len(responses)) - base_price = _price(request.symbol) - for index, response in enumerate(responses): - test_case.assertEqual(base_price + index, response.price) + def verify(self, request, responses, test_case): + test_case.assertEqual(test_constants.STREAM_LENGTH, len(responses)) + base_price = _price(request.symbol) + for index, response in enumerate(responses): + test_case.assertEqual(base_price + index, response.price) class GetHighestTradePrice(_service.StreamUnaryTestMethodImplementation): - """GetHighestTradePrice for use in tests.""" + """GetHighestTradePrice for use in tests.""" - def group(self): - return _STOCK_GROUP_NAME + def group(self): + return _STOCK_GROUP_NAME - def name(self): - return 'GetHighestTradePrice' + def name(self): + return 'GetHighestTradePrice' - def cardinality(self): - return cardinality.Cardinality.STREAM_UNARY + def cardinality(self): + return cardinality.Cardinality.STREAM_UNARY - def request_class(self): - return stock_pb2.StockRequest + def request_class(self): + return stock_pb2.StockRequest - def response_class(self): - return stock_pb2.StockReply + def response_class(self): + return stock_pb2.StockReply - def serialize_request(self, request): - return request.SerializeToString() + def serialize_request(self, request): + return request.SerializeToString() - def deserialize_request(self, serialized_request): - return stock_pb2.StockRequest.FromString(serialized_request) + def deserialize_request(self, serialized_request): + return stock_pb2.StockRequest.FromString(serialized_request) - def serialize_response(self, response): - return response.SerializeToString() + def serialize_response(self, response): + return response.SerializeToString() - def deserialize_response(self, serialized_response): - return stock_pb2.StockReply.FromString(serialized_response) + def deserialize_response(self, serialized_response): + return stock_pb2.StockReply.FromString(serialized_response) - def service(self, response_callback, context, control): - return _get_highest_trade_price( - response_callback, control, context.is_active) + def service(self, response_callback, context, control): + return _get_highest_trade_price(response_callback, control, + context.is_active) class GetHighestTradePriceMessages(_service.StreamUnaryTestMessages): - def requests(self): - return [ - stock_pb2.StockRequest(symbol=_SYMBOL_FORMAT % index) - for index in range(test_constants.STREAM_LENGTH)] - - def verify(self, requests, response, test_case): - price = None - symbol = None - for stock_request in requests: - current_symbol = stock_request.symbol - current_price = _price(current_symbol) - if price is None or price < current_price: - price = current_price - symbol = current_symbol - test_case.assertEqual(price, response.price) - test_case.assertEqual(symbol, response.symbol) + def requests(self): + return [ + stock_pb2.StockRequest(symbol=_SYMBOL_FORMAT % index) + for index in range(test_constants.STREAM_LENGTH) + ] + + def verify(self, requests, response, test_case): + price = None + symbol = None + for stock_request in requests: + current_symbol = stock_request.symbol + current_price = _price(current_symbol) + if price is None or price < current_price: + price = current_price + symbol = current_symbol + test_case.assertEqual(price, response.price) + test_case.assertEqual(symbol, response.symbol) class StockTestService(_service.TestService): - """A corpus of test data with one method of each RPC cardinality.""" - - def unary_unary_scenarios(self): - return { - (_STOCK_GROUP_NAME, 'GetLastTradePrice'): ( - GetLastTradePrice(), [GetLastTradePriceMessages()]), - } - - def unary_stream_scenarios(self): - return { - (_STOCK_GROUP_NAME, 'WatchFutureTrades'): ( - WatchFutureTrades(), [WatchFutureTradesMessages()]), - } - - def stream_unary_scenarios(self): - return { - (_STOCK_GROUP_NAME, 'GetHighestTradePrice'): ( - GetHighestTradePrice(), [GetHighestTradePriceMessages()]) - } - - def stream_stream_scenarios(self): - return { - (_STOCK_GROUP_NAME, 'GetLastTradePriceMultiple'): ( - GetLastTradePriceMultiple(), [GetLastTradePriceMultipleMessages()]), - } + """A corpus of test data with one method of each RPC cardinality.""" + + def unary_unary_scenarios(self): + return { + (_STOCK_GROUP_NAME, 'GetLastTradePrice'): + (GetLastTradePrice(), [GetLastTradePriceMessages()]), + } + + def unary_stream_scenarios(self): + return { + (_STOCK_GROUP_NAME, 'WatchFutureTrades'): + (WatchFutureTrades(), [WatchFutureTradesMessages()]), + } + + def stream_unary_scenarios(self): + return { + (_STOCK_GROUP_NAME, 'GetHighestTradePrice'): + (GetHighestTradePrice(), [GetHighestTradePriceMessages()]) + } + + def stream_stream_scenarios(self): + return { + (_STOCK_GROUP_NAME, 'GetLastTradePriceMultiple'): + (GetLastTradePriceMultiple(), + [GetLastTradePriceMultipleMessages()]), + } STOCK_TEST_SERVICE = StockTestService() diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py index 71de9d835e9..d84e1fc1361 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_cases.py @@ -26,7 +26,6 @@ # 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. - """Tools for creating tests of implementations of the Face layer.""" # unittest is referenced from specification in this module. @@ -40,12 +39,11 @@ from tests.unit.framework.interfaces.face import test_interfaces # pylint: disa _TEST_CASE_SUPERCLASSES = ( _blocking_invocation_inline_service.TestCase, - _future_invocation_asynchronous_event_service.TestCase, -) + _future_invocation_asynchronous_event_service.TestCase,) def test_cases(implementation): - """Creates unittest.TestCase classes for a given Face layer implementation. + """Creates unittest.TestCase classes for a given Face layer implementation. Args: implementation: A test_interfaces.Implementation specifying creation and @@ -55,13 +53,14 @@ def test_cases(implementation): A sequence of subclasses of unittest.TestCase defining tests of the specified Face layer implementation. """ - test_case_classes = [] - for invoker_constructor in _invocation.invoker_constructors(): - for super_class in _TEST_CASE_SUPERCLASSES: - test_case_classes.append( - type(invoker_constructor.name() + super_class.NAME, (super_class,), - {'implementation': implementation, - 'invoker_constructor': invoker_constructor, - '__module__': implementation.__module__, - })) - return test_case_classes + test_case_classes = [] + for invoker_constructor in _invocation.invoker_constructors(): + for super_class in _TEST_CASE_SUPERCLASSES: + test_case_classes.append( + type(invoker_constructor.name() + super_class.NAME, ( + super_class,), { + 'implementation': implementation, + 'invoker_constructor': invoker_constructor, + '__module__': implementation.__module__, + })) + return test_case_classes diff --git a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_interfaces.py b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_interfaces.py index 40f38e68ba1..a789d435b48 100644 --- a/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_interfaces.py +++ b/src/python/grpcio_tests/tests/unit/framework/interfaces/face/test_interfaces.py @@ -26,7 +26,6 @@ # 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. - """Interfaces used in tests of implementations of the Face layer.""" import abc @@ -38,103 +37,102 @@ from grpc.framework.interfaces.face import face # pylint: disable=unused-import class Method(six.with_metaclass(abc.ABCMeta)): - """Specifies a method to be used in tests.""" + """Specifies a method to be used in tests.""" - @abc.abstractmethod - def group(self): - """Identify the group of the method. + @abc.abstractmethod + def group(self): + """Identify the group of the method. Returns: The group of the method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def name(self): - """Identify the name of the method. + @abc.abstractmethod + def name(self): + """Identify the name of the method. Returns: The name of the method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def cardinality(self): - """Identify the cardinality of the method. + @abc.abstractmethod + def cardinality(self): + """Identify the cardinality of the method. Returns: A cardinality.Cardinality value describing the streaming semantics of the method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def request_class(self): - """Identify the class used for the method's request objects. + @abc.abstractmethod + def request_class(self): + """Identify the class used for the method's request objects. Returns: The class object of the class to which the method's request objects belong. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def response_class(self): - """Identify the class used for the method's response objects. + @abc.abstractmethod + def response_class(self): + """Identify the class used for the method's response objects. Returns: The class object of the class to which the method's response objects belong. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def serialize_request(self, request): - """Serialize the given request object. + @abc.abstractmethod + def serialize_request(self, request): + """Serialize the given request object. Args: request: A request object appropriate for this method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def deserialize_request(self, serialized_request): - """Synthesize a request object from a given bytestring. + @abc.abstractmethod + def deserialize_request(self, serialized_request): + """Synthesize a request object from a given bytestring. Args: serialized_request: A bytestring deserializable into a request object appropriate for this method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def serialize_response(self, response): - """Serialize the given response object. + @abc.abstractmethod + def serialize_response(self, response): + """Serialize the given response object. Args: response: A response object appropriate for this method. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def deserialize_response(self, serialized_response): - """Synthesize a response object from a given bytestring. + @abc.abstractmethod + def deserialize_response(self, serialized_response): + """Synthesize a response object from a given bytestring. Args: serialized_response: A bytestring deserializable into a response object appropriate for this method. """ - raise NotImplementedError() + raise NotImplementedError() class Implementation(six.with_metaclass(abc.ABCMeta)): - """Specifies an implementation of the Face layer.""" + """Specifies an implementation of the Face layer.""" - @abc.abstractmethod - def instantiate( - self, methods, method_implementations, - multi_method_implementation): - """Instantiates the Face layer implementation to be used in a test. + @abc.abstractmethod + def instantiate(self, methods, method_implementations, + multi_method_implementation): + """Instantiates the Face layer implementation to be used in a test. Args: methods: A sequence of Method objects describing the methods available to @@ -151,69 +149,69 @@ class Implementation(six.with_metaclass(abc.ABCMeta)): passed to destantiate at the conclusion of the test. The returned stubs must be backed by the provided implementations. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def destantiate(self, memo): - """Destroys the Face layer implementation under test. + @abc.abstractmethod + def destantiate(self, memo): + """Destroys the Face layer implementation under test. Args: memo: The object from the third position of the return value of a call to instantiate. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def invocation_metadata(self): - """Provides the metadata to be used when invoking a test RPC. + @abc.abstractmethod + def invocation_metadata(self): + """Provides the metadata to be used when invoking a test RPC. Returns: An object to use as the supplied-at-invocation-time metadata in a test RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def initial_metadata(self): - """Provides the metadata for use as a test RPC's first servicer metadata. + @abc.abstractmethod + def initial_metadata(self): + """Provides the metadata for use as a test RPC's first servicer metadata. Returns: An object to use as the from-the-servicer-before-responses metadata in a test RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def terminal_metadata(self): - """Provides the metadata for use as a test RPC's second servicer metadata. + @abc.abstractmethod + def terminal_metadata(self): + """Provides the metadata for use as a test RPC's second servicer metadata. Returns: An object to use as the from-the-servicer-after-all-responses metadata in a test RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def code(self): - """Provides the value for use as a test RPC's code. + @abc.abstractmethod + def code(self): + """Provides the value for use as a test RPC's code. Returns: An object to use as the from-the-servicer code in a test RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def details(self): - """Provides the value for use as a test RPC's details. + @abc.abstractmethod + def details(self): + """Provides the value for use as a test RPC's details. Returns: An object to use as the from-the-servicer details in a test RPC. """ - raise NotImplementedError() + raise NotImplementedError() - @abc.abstractmethod - def metadata_transmitted(self, original_metadata, transmitted_metadata): - """Identifies whether or not metadata was properly transmitted. + @abc.abstractmethod + def metadata_transmitted(self, original_metadata, transmitted_metadata): + """Identifies whether or not metadata was properly transmitted. Args: original_metadata: A metadata value passed to the Face interface @@ -226,4 +224,4 @@ class Implementation(six.with_metaclass(abc.ABCMeta)): Whether or not the metadata was properly transmitted by the Face interface implementation under test. """ - raise NotImplementedError() + raise NotImplementedError() diff --git a/src/python/grpcio_tests/tests/unit/resources.py b/src/python/grpcio_tests/tests/unit/resources.py index 023cdb155f2..55a2fff979b 100644 --- a/src/python/grpcio_tests/tests/unit/resources.py +++ b/src/python/grpcio_tests/tests/unit/resources.py @@ -26,7 +26,6 @@ # 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. - """Constants and functions for data used in interoperability testing.""" import os @@ -39,14 +38,14 @@ _CERTIFICATE_CHAIN_RESOURCE_PATH = 'credentials/server1.pem' def test_root_certificates(): - return pkg_resources.resource_string( - __name__, _ROOT_CERTIFICATES_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, + _ROOT_CERTIFICATES_RESOURCE_PATH) def private_key(): - return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, _PRIVATE_KEY_RESOURCE_PATH) def certificate_chain(): - return pkg_resources.resource_string( - __name__, _CERTIFICATE_CHAIN_RESOURCE_PATH) + return pkg_resources.resource_string(__name__, + _CERTIFICATE_CHAIN_RESOURCE_PATH) diff --git a/src/python/grpcio_tests/tests/unit/test_common.py b/src/python/grpcio_tests/tests/unit/test_common.py index cd71bd80d75..00fbe0567a2 100644 --- a/src/python/grpcio_tests/tests/unit/test_common.py +++ b/src/python/grpcio_tests/tests/unit/test_common.py @@ -26,7 +26,6 @@ # 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. - """Common code used throughout tests of gRPC.""" import collections @@ -34,14 +33,23 @@ import collections import grpc import six -INVOCATION_INITIAL_METADATA = (('0', 'abc'), ('1', 'def'), ('2', 'ghi'),) -SERVICE_INITIAL_METADATA = (('3', 'jkl'), ('4', 'mno'), ('5', 'pqr'),) -SERVICE_TERMINAL_METADATA = (('6', 'stu'), ('7', 'vwx'), ('8', 'yza'),) +INVOCATION_INITIAL_METADATA = ( + ('0', 'abc'), + ('1', 'def'), + ('2', 'ghi'),) +SERVICE_INITIAL_METADATA = ( + ('3', 'jkl'), + ('4', 'mno'), + ('5', 'pqr'),) +SERVICE_TERMINAL_METADATA = ( + ('6', 'stu'), + ('7', 'vwx'), + ('8', 'yza'),) DETAILS = 'test details' def metadata_transmitted(original_metadata, transmitted_metadata): - """Judges whether or not metadata was acceptably transmitted. + """Judges whether or not metadata was acceptably transmitted. gRPC is allowed to insert key-value pairs into the metadata values given by applications and to reorder key-value pairs with different keys but it is not @@ -59,31 +67,30 @@ def metadata_transmitted(original_metadata, transmitted_metadata): A boolean indicating whether transmitted_metadata accurately reflects original_metadata after having been transmitted via gRPC. """ - original = collections.defaultdict(list) - for key, value in original_metadata: - original[key].append(value) - transmitted = collections.defaultdict(list) - for key, value in transmitted_metadata: - transmitted[key].append(value) + original = collections.defaultdict(list) + for key, value in original_metadata: + original[key].append(value) + transmitted = collections.defaultdict(list) + for key, value in transmitted_metadata: + transmitted[key].append(value) - for key, values in six.iteritems(original): - transmitted_values = transmitted[key] - transmitted_iterator = iter(transmitted_values) - try: - for value in values: - while True: - transmitted_value = next(transmitted_iterator) - if value == transmitted_value: - break - except StopIteration: - return False - else: - return True + for key, values in six.iteritems(original): + transmitted_values = transmitted[key] + transmitted_iterator = iter(transmitted_values) + try: + for value in values: + while True: + transmitted_value = next(transmitted_iterator) + if value == transmitted_value: + break + except StopIteration: + return False + else: + return True -def test_secure_channel( - target, channel_credentials, server_host_override): - """Creates an insecure Channel to a remote host. +def test_secure_channel(target, channel_credentials, server_host_override): + """Creates an insecure Channel to a remote host. Args: host: The name of the remote host to which to connect. @@ -96,7 +103,7 @@ def test_secure_channel( An implementations.Channel to the remote host through which RPCs may be conducted. """ - channel = grpc.secure_channel( - target, channel_credentials, - (('grpc.ssl_target_name_override', server_host_override,),)) - return channel + channel = grpc.secure_channel(target, channel_credentials, (( + 'grpc.ssl_target_name_override', + server_host_override,),)) + return channel From 7ad582e9458de9d0bf56bfc5026c0f907817f07a Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 17 Jan 2017 11:32:26 -0800 Subject: [PATCH 209/261] Fix merge problems --- test/core/end2end/tests/write_buffering.c | 18 +++++++++--------- .../end2end/tests/write_buffering_at_end.c | 18 +++++++++--------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/test/core/end2end/tests/write_buffering.c b/test/core/end2end/tests/write_buffering.c index 856e9f0306f..fc175595a55 100644 --- a/test/core/end2end/tests/write_buffering.c +++ b/test/core/end2end/tests/write_buffering.c @@ -120,13 +120,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details = grpc_empty_slice(); int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -228,7 +228,6 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -244,7 +243,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -256,15 +256,15 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv2, "abc123")); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/write_buffering_at_end.c b/test/core/end2end/tests/write_buffering_at_end.c index 43aefcbdbcc..6b9a4c58f15 100644 --- a/test/core/end2end/tests/write_buffering_at_end.c +++ b/test/core/end2end/tests/write_buffering_at_end.c @@ -117,13 +117,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - char *details = NULL; - size_t details_capacity = 0; + grpc_slice details = grpc_empty_slice(); int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", - get_host_override_string("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + grpc_slice_from_static_string("/foo"), + get_host_override_slice("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -219,7 +219,6 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; - op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -235,7 +234,8 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - op->data.send_status_from_server.status_details = "xyz"; + grpc_slice status_details = grpc_slice_from_static_string("xyz"); + op->data.send_status_from_server.status_details = &status_details; op->flags = 0; op->reserved = NULL; op++; @@ -247,15 +247,15 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == strcmp(details, "xyz")); - GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); GPR_ASSERT(request_payload_recv2 == NULL); - gpr_free(details); + grpc_slice_unref(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); From c781f6451887ee5b47623c511ba337b08532f583 Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 17 Jan 2017 11:47:06 -0800 Subject: [PATCH 210/261] Use config file template instead of Rakefile template --- Rakefile | 4 +- build_config.rb | 3 + templates/Rakefile.template | 126 ----------------------------- templates/build_config.rb.template | 5 ++ 4 files changed, 11 insertions(+), 127 deletions(-) create mode 100644 build_config.rb delete mode 100644 templates/Rakefile.template create mode 100644 templates/build_config.rb.template diff --git a/Rakefile b/Rakefile index 8a88b4401f5..c8bca20ad1d 100755 --- a/Rakefile +++ b/Rakefile @@ -5,6 +5,8 @@ require 'rubocop/rake_task' require 'bundler/gem_tasks' require 'fileutils' +require_relative 'build_config.rb' + load 'tools/distrib/docker_for_windows.rb' # Add rubocop style checking tasks @@ -83,7 +85,7 @@ task 'dlls' do env += 'EMBED_ZLIB=true ' env += 'BUILDDIR=/tmp ' env += "V=#{verbose} " - out = '/tmp/libs/opt/grpc-2.dll' + out = GrpcBuildConfig::CORE_WINDOWS_DLL w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } diff --git a/build_config.rb b/build_config.rb new file mode 100644 index 00000000000..83edb1c3900 --- /dev/null +++ b/build_config.rb @@ -0,0 +1,3 @@ +module GrpcBuildConfig + CORE_WINDOWS_DLL = '/tmp/libs/opt/grpc-2.dll' +end diff --git a/templates/Rakefile.template b/templates/Rakefile.template deleted file mode 100644 index 2ab505b7c10..00000000000 --- a/templates/Rakefile.template +++ /dev/null @@ -1,126 +0,0 @@ -%YAML 1.2 ---- | - # -*- ruby -*- - require 'rake/extensiontask' - require 'rspec/core/rake_task' - require 'rubocop/rake_task' - require 'bundler/gem_tasks' - require 'fileutils' - - load 'tools/distrib/docker_for_windows.rb' - - # Add rubocop style checking tasks - RuboCop::RakeTask.new(:rubocop) do |task| - task.options = ['-c', 'src/ruby/.rubocop.yml'] - task.patterns = ['src/ruby/{lib,spec}/**/*.rb'] - end - - spec = Gem::Specification.load('grpc.gemspec') - - Gem::PackageTask.new(spec) do |pkg| - end - - # Add the extension compiler task - Rake::ExtensionTask.new('grpc_c', spec) do |ext| - ext.source_pattern = '**/*.{c,h}' - ext.ext_dir = File.join('src', 'ruby', 'ext', 'grpc') - ext.lib_dir = File.join('src', 'ruby', 'lib', 'grpc') - ext.cross_compile = true - ext.cross_platform = [ - 'x86-mingw32', 'x64-mingw32', - 'x86_64-linux', 'x86-linux', - 'universal-darwin' - ] - ext.cross_compiling do |spec| - spec.files = %w( etc/roots.pem grpc_c.32.ruby grpc_c.64.ruby ) - spec.files += Dir.glob('src/ruby/bin/**/*') - spec.files += Dir.glob('src/ruby/ext/**/*') - spec.files += Dir.glob('src/ruby/lib/**/*') - spec.files += Dir.glob('src/ruby/pb/**/*') - end - end - - # Define the test suites - SPEC_SUITES = [ - { id: :wrapper, title: 'wrapper layer', files: %w(src/ruby/spec/*.rb) }, - { id: :idiomatic, title: 'idiomatic layer', dir: %w(src/ruby/spec/generic), - tags: ['~bidi', '~server'] }, - { id: :bidi, title: 'bidi tests', dir: %w(src/ruby/spec/generic), - tag: 'bidi' }, - { id: :server, title: 'rpc server thread tests', dir: %w(src/ruby/spec/generic), - tag: 'server' }, - { id: :pb, title: 'protobuf service tests', dir: %w(src/ruby/spec/pb) } - ] - namespace :suite do - SPEC_SUITES.each do |suite| - desc "Run all specs in the #{suite[:title]} spec suite" - RSpec::Core::RakeTask.new(suite[:id]) do |t| - ENV['COVERAGE_NAME'] = suite[:id].to_s - spec_files = [] - suite[:files].each { |f| spec_files += Dir[f] } if suite[:files] - - if suite[:dir] - suite[:dir].each { |f| spec_files += Dir["#{f}/**/*_spec.rb"] } - end - helper = 'src/ruby/spec/spec_helper.rb' - spec_files << helper unless spec_files.include?(helper) - - t.pattern = spec_files - t.rspec_opts = "--tag #{suite[:tag]}" if suite[:tag] - if suite[:tags] - t.rspec_opts = suite[:tags].map { |x| "--tag #{x}" }.join(' ') - end - end - end - end - - desc 'Build the Windows gRPC DLLs for Ruby' - task 'dlls' do - grpc_config = ENV['GRPC_CONFIG'] || 'opt' - verbose = ENV['V'] || '0' - - env = 'CPPFLAGS="-D_WIN32_WINNT=0x600 -DUNICODE -D_UNICODE -Wno-unused-variable -Wno-unused-result" ' - env += 'LDFLAGS=-static ' - env += 'SYSTEM=MINGW32 ' - env += 'EMBED_ZLIB=true ' - env += 'BUILDDIR=/tmp ' - env += "V=#{verbose} " - out = '/tmp/libs/opt/grpc-${settings.core_version.major}.dll' - - w64 = { cross: 'x86_64-w64-mingw32', out: 'grpc_c.64.ruby' } - w32 = { cross: 'i686-w64-mingw32', out: 'grpc_c.32.ruby' } - - [ w64, w32 ].each do |opt| - env_comp = "CC=#{opt[:cross]}-gcc " - env_comp += "LD=#{opt[:cross]}-gcc " - docker_for_windows "#{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}" - end - - end - - desc 'Build the native gem file under rake_compiler_dock' - task 'gem:native' do - verbose = ENV['V'] || '0' - - grpc_config = ENV['GRPC_CONFIG'] || 'opt' - - if RUBY_PLATFORM =~ /darwin/ - FileUtils.touch 'grpc_c.32.ruby' - FileUtils.touch 'grpc_c.64.ruby' - system "rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}" - else - Rake::Task['dlls'].execute - docker_for_windows "bundle && rake cross native gem RUBY_CC_VERSION=2.3.0:2.2.2:2.1.5:2.0.0 V=#{verbose} GRPC_CONFIG=#{grpc_config}" - end - end - - # Define dependencies between the suites. - task 'suite:wrapper' => [:compile, :rubocop] - task 'suite:idiomatic' => 'suite:wrapper' - task 'suite:bidi' => 'suite:wrapper' - task 'suite:server' => 'suite:wrapper' - task 'suite:pb' => 'suite:server' - - desc 'Compiles the gRPC extension then runs all the tests' - task all: ['suite:idiomatic', 'suite:bidi', 'suite:pb', 'suite:server'] - task default: :all diff --git a/templates/build_config.rb.template b/templates/build_config.rb.template new file mode 100644 index 00000000000..4cb4810d335 --- /dev/null +++ b/templates/build_config.rb.template @@ -0,0 +1,5 @@ +%YAML 1.2 +--- | + module GrpcBuildConfig + CORE_WINDOWS_DLL = '/tmp/libs/opt/grpc-${settings.core_version.major}.dll' + end \ No newline at end of file From 824da1cc0482e1e5595ea447834f78e8f99391a8 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 17 Jan 2017 12:26:56 -0800 Subject: [PATCH 211/261] Remove dead files --- src/core/lib/transport/method_config.c | 321 ------------------------- src/core/lib/transport/method_config.h | 139 ----------- 2 files changed, 460 deletions(-) delete mode 100644 src/core/lib/transport/method_config.c delete mode 100644 src/core/lib/transport/method_config.h diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c deleted file mode 100644 index 75317d426de..00000000000 --- a/src/core/lib/transport/method_config.c +++ /dev/null @@ -1,321 +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 - -#include "src/core/lib/slice/slice_hash_table.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/transport/metadata.h" -#include "src/core/lib/transport/static_metadata.h" - -// -// grpc_method_config -// - -// bool vtable - -static void *bool_copy(void *valuep) { - bool value = *(bool *)valuep; - bool *new_value = gpr_malloc(sizeof(bool)); - *new_value = value; - return new_value; -} - -static int bool_cmp(void *v1, void *v2) { - bool b1 = *(bool *)v1; - bool b2 = *(bool *)v2; - if (!b1 && b2) return -1; - if (b1 && !b2) return 1; - return 0; -} - -static void free_mem(grpc_exec_ctx *exec_ctx, void *p) { gpr_free(p); } - -static grpc_slice_hash_table_vtable bool_vtable = {free_mem, bool_copy, - bool_cmp}; - -// timespec vtable - -static void *timespec_copy(void *valuep) { - gpr_timespec value = *(gpr_timespec *)valuep; - gpr_timespec *new_value = gpr_malloc(sizeof(gpr_timespec)); - *new_value = value; - return new_value; -} - -static int timespec_cmp(void *v1, void *v2) { - return gpr_time_cmp(*(gpr_timespec *)v1, *(gpr_timespec *)v2); -} - -static grpc_slice_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, - timespec_cmp}; - -// int32 vtable - -static void *int32_copy(void *valuep) { - int32_t value = *(int32_t *)valuep; - int32_t *new_value = gpr_malloc(sizeof(int32_t)); - *new_value = value; - return new_value; -} - -static int int32_cmp(void *v1, void *v2) { - int32_t i1 = *(int32_t *)v1; - int32_t i2 = *(int32_t *)v2; - if (i1 < i2) return -1; - if (i1 > i2) return 1; - return 0; -} - -static grpc_slice_hash_table_vtable int32_vtable = {free_mem, int32_copy, - int32_cmp}; - -struct grpc_method_config { - grpc_slice_hash_table *table; -}; - -grpc_method_config *grpc_method_config_create( - bool *wait_for_ready, gpr_timespec *timeout, - int32_t *max_request_message_bytes, int32_t *max_response_message_bytes) { - grpc_method_config *method_config = gpr_malloc(sizeof(grpc_method_config)); - memset(method_config, 0, sizeof(grpc_method_config)); - grpc_slice_hash_table_entry entries[4]; - size_t num_entries = 0; - if (wait_for_ready != NULL) { - entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY; - entries[num_entries].value = wait_for_ready; - entries[num_entries].vtable = &bool_vtable; - ++num_entries; - } - if (timeout != NULL) { - entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_TIMEOUT; - entries[num_entries].value = timeout; - entries[num_entries].vtable = ×pec_vtable; - ++num_entries; - } - if (max_request_message_bytes != NULL) { - entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES; - entries[num_entries].value = max_request_message_bytes; - entries[num_entries].vtable = &int32_vtable; - ++num_entries; - } - if (max_response_message_bytes != NULL) { - entries[num_entries].key = GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES; - entries[num_entries].value = max_response_message_bytes; - entries[num_entries].vtable = &int32_vtable; - ++num_entries; - } - method_config->table = grpc_slice_hash_table_create(num_entries, entries); - return method_config; -} - -grpc_method_config *grpc_method_config_ref(grpc_method_config *method_config) { - grpc_slice_hash_table_ref(method_config->table); - return method_config; -} - -void grpc_method_config_unref(grpc_exec_ctx *exec_ctx, - grpc_method_config *method_config) { - if (grpc_slice_hash_table_unref(exec_ctx, method_config->table)) { - gpr_free(method_config); - } -} - -int grpc_method_config_cmp(const grpc_method_config *method_config1, - const grpc_method_config *method_config2) { - return grpc_slice_hash_table_cmp(method_config1->table, - method_config2->table); -} - -const bool *grpc_method_config_get_wait_for_ready( - const grpc_method_config *method_config) { - return grpc_slice_hash_table_get(method_config->table, - GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY); -} - -const gpr_timespec *grpc_method_config_get_timeout( - const grpc_method_config *method_config) { - return grpc_slice_hash_table_get(method_config->table, - GRPC_MDSTR_GRPC_DOT_TIMEOUT); -} - -const int32_t *grpc_method_config_get_max_request_message_bytes( - const grpc_method_config *method_config) { - return grpc_slice_hash_table_get( - method_config->table, GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES); -} - -const int32_t *grpc_method_config_get_max_response_message_bytes( - const grpc_method_config *method_config) { - return grpc_slice_hash_table_get( - method_config->table, GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES); -} - -// -// grpc_method_config_table -// - -static void method_config_unref(grpc_exec_ctx *exec_ctx, void *valuep) { - grpc_method_config_unref(exec_ctx, valuep); -} - -static void *method_config_ref(void *valuep) { - return grpc_method_config_ref(valuep); -} - -static int method_config_cmp(void *valuep1, void *valuep2) { - return grpc_method_config_cmp(valuep1, valuep2); -} - -static const grpc_slice_hash_table_vtable method_config_table_vtable = { - method_config_unref, method_config_ref, method_config_cmp}; - -grpc_method_config_table *grpc_method_config_table_create( - size_t num_entries, grpc_method_config_table_entry *entries) { - grpc_slice_hash_table_entry *hash_table_entries = - gpr_malloc(sizeof(grpc_slice_hash_table_entry) * num_entries); - for (size_t i = 0; i < num_entries; ++i) { - hash_table_entries[i].key = entries[i].method_name; - hash_table_entries[i].value = entries[i].method_config; - hash_table_entries[i].vtable = &method_config_table_vtable; - } - grpc_method_config_table *method_config_table = - grpc_slice_hash_table_create(num_entries, hash_table_entries); - gpr_free(hash_table_entries); - return method_config_table; -} - -grpc_method_config_table *grpc_method_config_table_ref( - grpc_method_config_table *table) { - return grpc_slice_hash_table_ref(table); -} - -void grpc_method_config_table_unref(grpc_exec_ctx *exec_ctx, - grpc_method_config_table *table) { - grpc_slice_hash_table_unref(exec_ctx, table); -} - -int grpc_method_config_table_cmp(const grpc_method_config_table *table1, - const grpc_method_config_table *table2) { - return grpc_slice_hash_table_cmp(table1, table2); -} - -void *grpc_method_config_table_get(grpc_exec_ctx *exec_ctx, - const grpc_slice_hash_table *table, - const grpc_slice path) { - void *value = grpc_slice_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) { - int sep_pos = grpc_slice_rchr(path, '/') + 1; - grpc_slice search = grpc_slice_malloc((size_t)(sep_pos + 1)); - memcpy(GRPC_SLICE_START_PTR(search), GRPC_SLICE_START_PTR(path), - (size_t)sep_pos); - GRPC_SLICE_START_PTR(search)[sep_pos] = '*'; - value = grpc_slice_hash_table_get(table, search); - grpc_slice_unref_internal(exec_ctx, search); - } - return value; -} - -static void *copy_arg(void *p) { return grpc_method_config_table_ref(p); } - -static void destroy_arg(grpc_exec_ctx *exec_ctx, void *p) { - grpc_method_config_table_unref(exec_ctx, p); -} - -static int cmp_arg(void *p1, void *p2) { - return grpc_method_config_table_cmp(p1, p2); -} - -static grpc_arg_pointer_vtable arg_vtable = {copy_arg, destroy_arg, cmp_arg}; - -grpc_arg grpc_method_config_table_create_channel_arg( - grpc_method_config_table *table) { - grpc_arg arg; - arg.type = GRPC_ARG_POINTER; - arg.key = GRPC_ARG_SERVICE_CONFIG; - arg.value.pointer.p = table; - arg.value.pointer.vtable = &arg_vtable; - return arg; -} - -// State used by convert_entry() below. -typedef struct conversion_state { - void *(*convert_value)(const grpc_method_config *method_config); - const grpc_slice_hash_table_vtable *vtable; - size_t num_entries; - grpc_slice_hash_table_entry *entries; -} conversion_state; - -// A function to be passed to grpc_slice_hash_table_iterate() to create -// a copy of the entries. -static void convert_entry(const grpc_slice_hash_table_entry *entry, - void *user_data) { - conversion_state *state = user_data; - state->entries[state->num_entries].key = grpc_slice_ref_internal(entry->key); - state->entries[state->num_entries].value = state->convert_value(entry->value); - state->entries[state->num_entries].vtable = state->vtable; - ++state->num_entries; -} - -grpc_slice_hash_table *grpc_method_config_table_convert( - grpc_exec_ctx *exec_ctx, const grpc_method_config_table *table, - void *(*convert_value)(const grpc_method_config *method_config), - const grpc_slice_hash_table_vtable *vtable) { - // Create an array of the entries in the table with converted values. - conversion_state state; - state.convert_value = convert_value; - state.vtable = vtable; - state.num_entries = 0; - state.entries = gpr_malloc(sizeof(grpc_slice_hash_table_entry) * - grpc_slice_hash_table_num_entries(table)); - grpc_slice_hash_table_iterate(table, convert_entry, &state); - // Create a new table based on the array we just constructed. - grpc_slice_hash_table *new_table = - grpc_slice_hash_table_create(state.num_entries, state.entries); - // Clean up the array. - for (size_t i = 0; i < state.num_entries; ++i) { - grpc_slice_unref_internal(exec_ctx, state.entries[i].key); - vtable->destroy_value(exec_ctx, state.entries[i].value); - } - gpr_free(state.entries); - // Return the new table. - return new_table; -} diff --git a/src/core/lib/transport/method_config.h b/src/core/lib/transport/method_config.h deleted file mode 100644 index 3e266a6ecd4..00000000000 --- a/src/core/lib/transport/method_config.h +++ /dev/null @@ -1,139 +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 -#include - -#include "src/core/lib/slice/slice_hash_table.h" -#include "src/core/lib/transport/metadata.h" - -/// Per-method configuration. -typedef struct grpc_method_config grpc_method_config; - -/// Creates a grpc_method_config with the specified parameters. -/// Any parameter may be NULL to indicate that the value is unset. -/// -/// \a wait_for_ready indicates whether the client should wait until the -/// request deadline for the channel to become ready, even if there is a -/// temporary failure before the deadline while attempting to connect. -/// -/// \a timeout indicates the timeout for calls. -/// -/// \a max_request_message_bytes and \a max_response_message_bytes -/// indicate the maximum sizes of the request (checked when sending) and -/// response (checked when receiving) messages. -grpc_method_config *grpc_method_config_create( - bool *wait_for_ready, gpr_timespec *timeout, - int32_t *max_request_message_bytes, int32_t *max_response_message_bytes); - -grpc_method_config *grpc_method_config_ref(grpc_method_config *method_config); -void grpc_method_config_unref(grpc_exec_ctx *exec_ctx, - grpc_method_config *method_config); - -/// Compares two grpc_method_configs. -/// The sort order is stable but undefined. -int grpc_method_config_cmp(const grpc_method_config *method_config1, - const grpc_method_config *method_config2); - -/// These methods return NULL if the requested field is unset. -/// The caller does NOT take ownership of the result. -const bool *grpc_method_config_get_wait_for_ready( - const grpc_method_config *method_config); -const gpr_timespec *grpc_method_config_get_timeout( - const grpc_method_config *method_config); -const int32_t *grpc_method_config_get_max_request_message_bytes( - const grpc_method_config *method_config); -const int32_t *grpc_method_config_get_max_response_message_bytes( - const grpc_method_config *method_config); - -/// A table of method configs. -typedef grpc_slice_hash_table grpc_method_config_table; - -typedef struct grpc_method_config_table_entry { - /// The name is of one of the following forms: - /// service/method -- specifies exact service and method name - /// service/* -- matches all methods for the specified service - grpc_slice method_name; - grpc_method_config *method_config; -} grpc_method_config_table_entry; - -/// Takes new references to all keys and values in \a entries. -grpc_method_config_table *grpc_method_config_table_create( - size_t num_entries, grpc_method_config_table_entry *entries); - -grpc_method_config_table *grpc_method_config_table_ref( - grpc_method_config_table *table); -void grpc_method_config_table_unref(grpc_exec_ctx *exec_ctx, - grpc_method_config_table *table); - -/// Compares two grpc_method_config_tables. -/// The sort order is stable but undefined. -int grpc_method_config_table_cmp(const grpc_method_config_table *table1, - const grpc_method_config_table *table2); - -/// 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. -/// -/// Note: This returns a void *instead of a grpc_method_config *so that -/// it can also be used for tables constructed via -/// grpc_method_config_table_convert(). -void *grpc_method_config_table_get(grpc_exec_ctx *exec_ctx, - const grpc_slice_hash_table *table, - const grpc_slice path); - -/// Returns a channel arg containing \a table. -grpc_arg grpc_method_config_table_create_channel_arg( - grpc_method_config_table *table); - -/// Generates a new table from \a table whose values are converted to a -/// new form via the \a convert_value function. The new table will use -/// \a vtable for its values. -/// -/// This is generally used to convert the table's value type from -/// grpc_method_config to a simple struct containing only the parameters -/// relevant to a particular filter, thus avoiding the need for a hash -/// table lookup on the fast path. In that scenario, \a convert_value -/// will return a new instance of the struct containing the values from -/// the grpc_method_config, and \a vtable provides the methods for -/// operating on the struct type. -grpc_slice_hash_table *grpc_method_config_table_convert( - grpc_exec_ctx *exec_ctx, const grpc_method_config_table *table, - void *(*convert_value)(const grpc_method_config *method_config), - const grpc_slice_hash_table_vtable *vtable); - -#endif /* GRPC_CORE_LIB_TRANSPORT_METHOD_CONFIG_H */ From 7bb90fa57c07741556eb14ae8f058ecfff3e838c Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 17 Jan 2017 12:28:21 -0800 Subject: [PATCH 212/261] Respond to review comments --- src/core/lib/slice/slice_hash_table.c | 2 +- src/core/lib/slice/slice_hash_table.h | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/slice/slice_hash_table.c index 46c109439b4..46f807f4a52 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/slice/slice_hash_table.c @@ -60,7 +60,7 @@ static size_t grpc_slice_hash_table_find_index( if (is_empty(&table->entries[idx])) { return find_empty ? idx : table->size; } - if (grpc_slice_cmp(table->entries[idx].key, key) == 0) { + if (grpc_slice_eq(table->entries[idx].key, key)) { return idx; } } diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/slice/slice_hash_table.h index d16a95bd1d2..d0c27122d7f 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/slice/slice_hash_table.h @@ -66,7 +66,6 @@ grpc_slice_hash_table *grpc_slice_hash_table_create( size_t num_entries, grpc_slice_hash_table_entry *entries); grpc_slice_hash_table *grpc_slice_hash_table_ref(grpc_slice_hash_table *table); -/** Returns 1 when \a table is destroyed. */ void grpc_slice_hash_table_unref(grpc_exec_ctx *exec_ctx, grpc_slice_hash_table *table); From 9c627c2032c44af55e1a2dfec43d109ea7b5c4d7 Mon Sep 17 00:00:00 2001 From: Dan Born Date: Tue, 17 Jan 2017 13:01:38 -0800 Subject: [PATCH 213/261] Document new function grpc_resource_user_quota --- src/core/lib/iomgr/resource_quota.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/core/lib/iomgr/resource_quota.h b/src/core/lib/iomgr/resource_quota.h index 14475c864e1..cfacee13ef3 100644 --- a/src/core/lib/iomgr/resource_quota.h +++ b/src/core/lib/iomgr/resource_quota.h @@ -88,8 +88,12 @@ typedef struct grpc_resource_user grpc_resource_user; grpc_resource_user *grpc_resource_user_create( grpc_resource_quota *resource_quota, const char *name); + +/* Returns a borrowed reference to the underlying resource quota for this + resource user. */ grpc_resource_quota *grpc_resource_user_quota( grpc_resource_user *resource_user); + void grpc_resource_user_ref(grpc_resource_user *resource_user); void grpc_resource_user_unref(grpc_exec_ctx *exec_ctx, grpc_resource_user *resource_user); From 5aa2bcfd4dea92ca18b7b6b0b3f40d1b8fabc246 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 17 Jan 2017 23:31:17 +0000 Subject: [PATCH 214/261] Pass an iterator rather than an iterable This should have been included in dd52a31337616fe935f79debfe5d56c6d73a but was missed because it falsely passes almost all of the time. --- src/python/grpcio_tests/tests/unit/beta/_not_found_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py b/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py index 664e47c7696..ce7b91e9fe9 100644 --- a/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py +++ b/src/python/grpcio_tests/tests/unit/beta/_not_found_test.py @@ -62,7 +62,7 @@ class NotFoundTest(unittest.TestCase): def test_future_stream_unary_not_found(self): rpc_future = self._generic_stub.future_stream_unary( - 'grupe', 'mevvod', [b'def'], test_constants.LONG_TIMEOUT) + 'grupe', 'mevvod', iter([b'def']), test_constants.LONG_TIMEOUT) with self.assertRaises(face.LocalError) as exception_assertion_context: rpc_future.result() self.assertIs(exception_assertion_context.exception.code, From 00ac6288fd5be1100310fcead8f46d199da4c823 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Tue, 17 Jan 2017 23:40:38 +0000 Subject: [PATCH 215/261] =?UTF-8?q?pyformat=5Fcode.sh=20=E2=86=92=20yapf?= =?UTF-8?q?=5Fcode.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This should have been a part of 06dea573daa2175b244a430bb89b49bb5c8e8. --- tools/distrib/{pyformat_code.sh => yapf_code.sh} | 0 tools/run_tests/sanity/sanity_tests.yaml | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename tools/distrib/{pyformat_code.sh => yapf_code.sh} (100%) diff --git a/tools/distrib/pyformat_code.sh b/tools/distrib/yapf_code.sh similarity index 100% rename from tools/distrib/pyformat_code.sh rename to tools/distrib/yapf_code.sh diff --git a/tools/run_tests/sanity/sanity_tests.yaml b/tools/run_tests/sanity/sanity_tests.yaml index f29b700572b..ce41da802d0 100644 --- a/tools/run_tests/sanity/sanity_tests.yaml +++ b/tools/run_tests/sanity/sanity_tests.yaml @@ -12,6 +12,6 @@ - script: tools/distrib/check_trailing_newlines.sh - script: tools/distrib/check_nanopb_output.sh - script: tools/distrib/check_include_guards.py -- script: tools/distrib/pyformat_code.sh +- script: tools/distrib/yapf_code.sh - script: tools/distrib/python/check_grpcio_tools.py From a47245112ba370bf411c3c90cff02da962775fa8 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Tue, 17 Jan 2017 16:43:59 -0800 Subject: [PATCH 216/261] Fix Python errors --- .../grpcio/grpc/_cython/_cygrpc/records.pxd.pxi | 4 ++-- .../grpcio/grpc/_cython/_cygrpc/records.pyx.pxi | 16 +++++++++++----- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index 3644b7cdae5..e9276053845 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -117,8 +117,8 @@ cdef class Metadata: cdef grpc_metadata_array c_metadata_array cdef bint owns_metadata_slices cdef object metadata - cdef void _claim_slice_ownership(self) nogil - cdef void _drop_slice_ownership(self) nogil + cdef void _claim_slice_ownership(self) + cdef void _drop_slice_ownership(self) cdef class Operation: diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index 30e7b9657a9..d7a77133325 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -466,6 +466,10 @@ cdef class _MetadataIterator: else: raise StopIteration +cdef grpc_slice _copy_slice(grpc_slice slice) nogil: + cdef void *start = grpc_slice_start_ptr(slice) + cdef size_t length = grpc_slice_length(slice) + return grpc_slice_from_copied_buffer(start, length) cdef class Metadata: @@ -489,8 +493,8 @@ cdef class Metadata: (self.metadata[i]).c_metadata) def __dealloc__(self): + self._drop_slice_ownership() with nogil: - self._drop_slice_ownership() # this frees the allocated memory for the grpc_metadata_array (although # it'd be nice if that were documented somewhere...) # TODO(atash): document this in the C core @@ -510,15 +514,17 @@ cdef class Metadata: def __iter__(self): return _MetadataIterator(self) - cdef void _claim_slice_ownership(self) nogil: + cdef void _claim_slice_ownership(self): if self.owns_metadata_slices: return for i in range(self.c_metadata_array.count): - grpc_slice_ref(self.c_metadata_array.metadata[i].key) - grpc_slice_ref(self.c_metadata_array.metadata[i].value) + self.c_metadata_array.metadata[i].key = _copy_slice( + self.c_metadata_array.metadata[i].key) + self.c_metadata_array.metadata[i].value = _copy_slice( + self.c_metadata_array.metadata[i].value) self.owns_metadata_slices = True - cdef void _drop_slice_ownership(self) nogil: + cdef void _drop_slice_ownership(self): if not self.owns_metadata_slices: return for i in range(self.c_metadata_array.count): From 57b02fcaba2162631d787b4349b42146efdc45ab Mon Sep 17 00:00:00 2001 From: Adele Zhou Date: Tue, 17 Jan 2017 14:18:41 -0800 Subject: [PATCH 217/261] merge --- tools/run_tests/run_interop_tests.py | 44 ++++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index 56efac50ca0..b2dac7d1a87 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -86,7 +86,7 @@ class CXXLanguage: return {} def server_cmd(self, args): - return ['bins/opt/interop_server', '--use_tls=true'] + args + return ['bins/opt/interop_server'] + args def global_env(self): return {} @@ -115,7 +115,7 @@ class CSharpLanguage: return {} def server_cmd(self, args): - return ['mono', 'Grpc.IntegrationTesting.Server.exe', '--use_tls=true'] + args + return ['mono', 'Grpc.IntegrationTesting.Server.exe'] + args def global_env(self): return {} @@ -144,7 +144,7 @@ class CSharpCoreCLRLanguage: return {} def server_cmd(self, args): - return ['dotnet', 'exec', 'Grpc.IntegrationTesting.Server.dll', '--use_tls=true'] + args + return ['dotnet', 'exec', 'Grpc.IntegrationTesting.Server.dll'] + args def global_env(self): return {} @@ -176,7 +176,7 @@ class JavaLanguage: return {} def server_cmd(self, args): - return ['./run-test-server.sh', '--use_tls=true'] + args + return ['./run-test-server.sh'] + args def global_env(self): return {} @@ -206,7 +206,7 @@ class GoLanguage: return {} def server_cmd(self, args): - return ['go', 'run', 'server.go', '--use_tls=true'] + args + return ['go', 'run', 'server.go'] + args def global_env(self): return {} @@ -292,8 +292,7 @@ class NodeLanguage: def server_cmd(self, args): return ['tools/run_tests/interop/with_nvm.sh', - 'node', 'src/node/interop/interop_server.js', - '--use_tls=true'] + args + 'node', 'src/node/interop/interop_server.js'] + args def global_env(self): return {} @@ -374,7 +373,7 @@ class RubyLanguage: def server_cmd(self, args): return ['tools/run_tests/interop/with_rvm.sh', - 'ruby', 'src/ruby/pb/test/server.rb', '--use_tls=true'] + args + 'ruby', 'src/ruby/pb/test/server.rb'] + args def global_env(self): return {} @@ -419,7 +418,7 @@ class PythonLanguage: 'src/python/grpcio_tests/setup.py', 'run_interop', '--server', - '--args="{}"'.format(' '.join(args) + ' --use_tls=true') + '--args="{}"'.format(' '.join(args)) ] def global_env(self): @@ -586,11 +585,11 @@ def cloud_to_prod_jobspec(language, test_case, server_host_name, def cloud_to_cloud_jobspec(language, test_case, server_name, server_host, - server_port, docker_image=None): + server_port, docker_image=None, insecure=False): """Creates jobspec for cloud-to-cloud interop test""" interop_only_options = [ '--server_host_override=foo.test.google.fr', - '--use_tls=true', + '--use_tls=%s' % ('false' if insecure else 'true'), '--use_test_ca=true', ] common_options = [ @@ -634,11 +633,12 @@ def cloud_to_cloud_jobspec(language, test_case, server_name, server_host, return test_job -def server_jobspec(language, docker_image): +def server_jobspec(language, docker_image, insecure=False): """Create jobspec for running a server""" container_name = dockerjob.random_name('interop_server_%s' % language.safename) cmdline = bash_cmdline( - language.server_cmd(['--port=%s' % _DEFAULT_SERVER_PORT])) + language.server_cmd(['--port=%s' % _DEFAULT_SERVER_PORT, + '--use_tls=%s' % ('false' if insecure else 'true')])) environ = language.global_env() if language.safename == 'http2': # we are running the http2 interop server. Open next N ports beginning @@ -803,6 +803,11 @@ argp.add_argument('--http2_badserver_interop', action='store_const', const=True, help='Enable HTTP/2 server edge case testing. (Good client, bad server)') +argp.add_argument('--insecure', + default=False, + action='store_const', + const=True, + help='Whether to use secure channel.') args = argp.parse_args() @@ -868,7 +873,8 @@ server_addresses={} try: for s in servers: lang = str(s) - spec = server_jobspec(_LANGUAGES[lang], docker_images.get(lang)) + spec = server_jobspec(_LANGUAGES[lang], docker_images.get(lang), + args.insecure) job = dockerjob.DockerJob(spec) server_jobs[lang] = job server_addresses[lang] = ('localhost', job.mapped_port(_DEFAULT_SERVER_PORT)) @@ -883,6 +889,8 @@ try: jobs = [] if args.cloud_to_prod: + if args.insecure: + print('TLS is always enabled for cloud_to_prod scenarios.') for server_host_name in args.prod_servers: for language in languages: for test_case in _TEST_CASES: @@ -903,6 +911,8 @@ try: jobs.append(test_job) if args.cloud_to_prod_auth: + if args.insecure: + print('TLS is always enabled for cloud_to_prod scenarios.') for server_host_name in args.prod_servers: for language in languages: for test_case in _AUTH_TEST_CASES: @@ -934,7 +944,8 @@ try: server_name, server_host, server_port, - docker_image=docker_images.get(str(language))) + docker_image=docker_images.get(str(language)), + insecure=args.insecure) jobs.append(test_job) if args.http2_interop: @@ -947,7 +958,8 @@ try: server_name, server_host, server_port, - docker_image=docker_images.get(str(http2Interop))) + docker_image=docker_images.get(str(http2Interop)), + insecure=args.insecure) jobs.append(test_job) if args.http2_badserver_interop: From e375975e0d9e80516698271233a1d92ff1160a7f Mon Sep 17 00:00:00 2001 From: murgatroid99 Date: Tue, 17 Jan 2017 16:32:23 -0800 Subject: [PATCH 218/261] Fixed sanity errors --- build_config.rb | 29 ++++++++++++++++++++++++++++ src/core/ext/census/tracing.c | 2 +- templates/build_config.rb.template | 31 +++++++++++++++++++++++++++++- 3 files changed, 60 insertions(+), 2 deletions(-) diff --git a/build_config.rb b/build_config.rb index 83edb1c3900..35e887ef621 100644 --- a/build_config.rb +++ b/build_config.rb @@ -1,3 +1,32 @@ +# Copyright 2017, 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. + module GrpcBuildConfig CORE_WINDOWS_DLL = '/tmp/libs/opt/grpc-2.dll' end diff --git a/src/core/ext/census/tracing.c b/src/core/ext/census/tracing.c index afb70441d28..9371fffc8d7 100644 --- a/src/core/ext/census/tracing.c +++ b/src/core/ext/census/tracing.c @@ -33,8 +33,8 @@ //#include "src/core/ext/census/tracing.h" -#include #include +#include /* TODO(aveitch): These are all placeholder implementations. */ diff --git a/templates/build_config.rb.template b/templates/build_config.rb.template index 4cb4810d335..0d9191b1a07 100644 --- a/templates/build_config.rb.template +++ b/templates/build_config.rb.template @@ -1,5 +1,34 @@ %YAML 1.2 --- | + # Copyright 2017, 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. + module GrpcBuildConfig CORE_WINDOWS_DLL = '/tmp/libs/opt/grpc-${settings.core_version.major}.dll' - end \ No newline at end of file + end From 79e8d81e8127590bf9489db371a65bc7493747e8 Mon Sep 17 00:00:00 2001 From: Alexander Polcyn Date: Tue, 17 Jan 2017 15:01:33 -0800 Subject: [PATCH 219/261] update path to build_artifacts_ruby.sh in jenkins script --- tools/jenkins/build_artifacts.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jenkins/build_artifacts.sh b/tools/jenkins/build_artifacts.sh index c0acbdfb276..b15db2cdc2b 100755 --- a/tools/jenkins/build_artifacts.sh +++ b/tools/jenkins/build_artifacts.sh @@ -40,7 +40,7 @@ curr_platform="$platform" unset platform # variable named 'platform' breaks the windows build if [ "$curr_platform" == "linux" ] && [ "$language" == "ruby" ] ; then - ./tools/run_tests/build_artifact_ruby.sh + ./tools/run_tests/artifacts/build_artifact_ruby.sh else python tools/run_tests/task_runner.py -f artifact $language $curr_platform $architecture fi From b4227370fc8b84fdf8d11c3d1ba94492347da1a8 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 18 Jan 2017 09:21:20 -0800 Subject: [PATCH 220/261] Code review changes and other improvements. --- doc/images/load-balancing.png | Bin 27733 -> 28073 bytes doc/images/load-balancing.svg | 2 +- doc/load-balancing.md | 67 +++++++++++++++++++++------------- doc/naming.md | 18 ++++++--- 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/doc/images/load-balancing.png b/doc/images/load-balancing.png index 18b68bfdad83d15b33f37eeeb98f582feb8ee0c0..7c70465e653dcf732875e96ab80e65331ff7c67d 100644 GIT binary patch literal 28073 zcmeEug;x~s`{*pvh=i0M6r`I4LAnGK1qnsEMM_w@mRuD?K)|9Kl#9 z!4WgB8x;TmbAF_J@0s`H?*@u5H}(9NeaFA+Pqfk@9fAZBTfSSDSg|om#=sy-g!~JT z7i{mZ?pOd2R$_hy2}7-tt9baOp@2oF_e38d2OpgPRXDY>t^^ z6!?FF0&~W69Y`_c@Wer<=MQxEM8*W+YpcVP!=3k51~LEnL8|tq>@B8rw3PLpt>3tM z9RlP<1@zev7Bh##>>cvYBc2C1_?Px)<$@@u^~P^>$)-G}@5@$Zw+80fqe! zE79494;}1napHkcTskiO+`ctG@%EOf1%Oa385wK!^{fqLk;73mC8N139ef?!>_`EGYuan_E23AxQ3a!k zxt9ZP0}}9Xj|70)TVn>2Z$YII$0Qm(Y?uH6$I>hdTq_O4h(id0mD@^12l%dX>bUWt zC#WvZ<|keRKpNX#&E$)Xa9f=ELD*TSIIw|FS2+E-Oze--KXDq?9mphW0I-GjNdLqV z*WhjkX9`*)^D*awUqKWAK=q2H2!If~jm0wb-hSc2_>9 z&JG6;VkARKfcNd)#4HfDe-bUx3L=0)@JbZyHuApX%V9o|bFqp-0#QET%S}oCnBl7c zpnWNPE8_-`_UPn!IO*e*FcVYrx9@2S++>hXnl?o9w9`U7x}L5l9jx~`?o4!@)y^X; zHrykpOD-KGJZ2ctQ;p@fjspOpkHL~nQ6S~;RZRL5@c^M45WgScEfpIFsi~^xopHd- z{3Qh}@OF^WJw7N_?(*l%1gbh=-18g#PoK*Y`##3{cIMF=&?LQfF$T0$px`8G2@fJO z2(3c)Z}@&sCj;2CA6sTE*O4( z8Gc^2{^qcC1AQC>y9P8w1dt&|L820y1GcwzUT?ZA!t2XK9H+>nr-A^ct=`{BLBI^g zERnv(^t%h&M}DGn++cT{XJc(;?p_txAaxFCf7RzB*c^3N;${vlmYBE z`dV<_fLS`~RAfN?xF`Je#;q-ENOTU#D?*?X1^{Ot@Dvz79_r0E8MwWPS|V=oiB8j7 zCY~x_)eo7jAt*dRQT6p-%-rSUT_>5lFDQTM{rS@2(b`nV+V3kMDDTk#Fo~b;0hnK{ zK6747zsbU&`znT5v>5xYx2VThlzc?E$&?|ZzAX?H_Huu6Af1kE&ckuaQtrc@QwNi^ zspX{#X*>pivKhzSTNybE+X#Dpe5s@|Ti7dL(|#+CpS^Cz4-?UMh5wa*-Ybl?I156& z_9SI1BG;{W90?Lx0l9UnH%=Ghov)4uc%H@L z!MvJTihCdAub~G7p}M0T6){Jcn6CrA2A!p{bPi5^$?LhLZknU1lOZro+ETC6ecTGT z9V=j6-g~XId}@L~lnQ9BxCd@L9OWx0gX#JF#Q7z@$)GUo#)VT(lyQB3A7pE2mb8Cya6FlvOxv- zN6x{Mzgq)5xs3qrRU5;9ui_p89zCr9IP^bH2f!Ol6TnFz^Z?LYO%4D@ECk>w4nUmL zfTuWkR&Knt!=2;M`FnuO`g?$PYTfFz{qI%zuefn7Izrsg|2Q4Idh1{W{|{HdsW|z> z(E>ac#ehGkgW$R_0t$mdQ=PElcQCfM9^Z9`lK-j&V6=twk}bj_SyUN>1&4Fm;&(QB zff`KwaLCNb&8znLt5UmfUPrjg{-uoqljR0YGc}j|=}aL5N_W)bEsk z+_`Gs<326%l*n+Bp56>@wbw}B#L&hWS44L5=Lv0;%>rvS)FMWgzt|X1Ush`^v}Pt7 zxl4CPy&A9M=7rN8R5rMa<6wCUJOJ2Mgz$y%7}g0OkEuXj{~v=&IPu2;#fA{R3V9E7 z;#A28p+6_Y=2szC|NO#H^xvz9zf=DF`QIjhoT6-Iz+=GS0{Qa`@PUMxTM(P$mLtR$ z(j|w;D0qQ}AF#xYy}pK9veXo}+`rGlzl8%9yb1t0Ilx7CQDUZ&nGxlADwe;Xu224V z!?&l;`y-`$_YC4A_b)Hng1cQ-oubI*YDxu^z}x0xM5K{A7YuLL_@zh3vNq9_Xli^R zR3@G`R7nqXCuo}a0x@O3tVqX5YkY=B87& z+2)kO=x_6jK!B?Ge(!{whw42^r@?z=M;Y8+Oc;mt9vZl9YvByo)RbA<z1%%npywZ=}b}l>E4S|DZ)y7?n(7()uWR{pS`u%K2Yuur8C!? z?JcEO%i27$uqD!}Gq$D}Th4YRA!vZYH-l*wA<9ik5DIUidtu0CHN zNqLIShUZplN?XJA`ZM##cdXI1Qk{$`hwqjB40T}FlMH7EF1N;=RD&uHEN6aK07&GI zfL6Cp;)Yo4_D7m!7@~i`C&eh6K{?>U-@1w&mR;(AiLBoW zh28xZ36TnWt=T(}f^lkZL0Zye(+7Au3*yO8{^8~NY*A1-2BmAsRiAhM@`oplTGXc# ze_5Wu{9@`|=lv)i4Z@yA-C{9OS(s`0*h%yBbL?1sd;0Bb1QqyM1A6GYP*)!#6rofX zKZJj~aIt)_pWPhh`!Y~~jl#|66cyv?$7#$_pe9F7{YS1;&hm&+0eXoq3*JSS7OFK= z$uG+OD_3^MEU;W4=9^M_c$j%Nn!Cm3xWNEVLcqN;dC&DuFmDK}7OS3VpF4p~yrO@l zgVcCs4rxVuYEYeWZfgREZn<(1zAs7+LyJ0Km*LRD2#nj4Jgp3r5;rK`uc=2Gba4q6 zy7lqB=CH{3j}!kn*;U`b=}Oy^B&WN3+lVpIS>5*w)xRY4(IfNK6~ro-)1e9!^~7ee z9}*c@8(PQm6b4lQOIc0?5koB=u=fto2vN+A{ph6~oX_v1mjy0ase@Pj-Pd0CS-cdK zNWT~(slLpY$PIH(r5>VArT%dcFH^yLC)z{KPP;BnMN$p84ADg47uEOEZ5H^)uT*)2 z^-azMt-l~O^Uw$Qg$vNoJGlEN)^KYDvwoXBaX0J=Iai7$ox<0ultJm-+F~ z-booM+Dj~1{^nbb_0td8x?RP*{RZiah66iZyGsz%ML}5w8EH^3ygi-!n*8Uki5L}} zxx;scQmL1g?77OR?MPdp663x+yc(QEo7R(1UL9}u zLG;@P_0kvji`f}A;@bQZs>TLj>nF<(3^p9`ot=lqQ_|AtQ71d&7x3;wQ8ljDtB+P8-F?oD%)9P%a)XA2f?(*ic zc;mUV`z28TNA2$2D&?x#-Ha8CQ?;z&;kT;09tEkVn{QuSLQMjU$|5)p8zp?!Rm@`R znFXr?e&6aAwoCOnA3}*&HS`DWM#%*MMdoI|#UT7F@p8}xQ$I}fH_6U%GqdoQs^R^` zjVEI?EqI`nT=mea_XGAgNHu#xt%6fA{jh(ZRytd8;G>Ef00`WJXndsGX;qGd1BB} z;VvUpTMwo8IyaBN8x5Ji;}PRTF8sl z57J==)80Dn(*lDL)@Dz9t68bg-(40b^Ebi;8ul1 z*`#;L`d^c}RvCdTMm|lnf@S6iOtK@QjjDN&Ivnd!32Rnw?CZ;5JOs|D?eCd9E_s7W zE;e`)YQ&Q^ZBbLwEtUm`jse|d13oYM6ZxPea&=hQVt$#<{=gE!+M^MJP}ws~mFCfJ z*;HSl+PNE=nn4~Z0Ll#h3OyV!=~)}0%8uxrbW$A!^}#3<5l=`00Bgd=48+~bKQHcDwI#J$UI5S>qk2cg; z58B8)RBz9ZP`iyNoIR^-!{+mFV(^G?y@&yY}j2&%#0SFqVzwA4V3KexCO`X zeLhsu%&t$8#x{r>Y+8Cv)1I#sIz=?P4$6k|(CcC!-4577qBGzOB5vxOgES@r%ITOv+JuplaG(`+3uTo}QIpvCNES)84n?tq5_> zEab!GgDirQNVC(2%uxgPmva~Wv4vF{wrZ6d^n^qrQTNh+Ofunu8p>vUT6|~JoNV4Z z;Mzur%dUm`J2zNwo#3o2l!UHpc8RM{E1` zfgVDK5|vRt$K^X`Z<%Ha&K9hd(qgYQvD;mTN6{t-XwSG!N*9ThJHz5*L@25zh0kVa zrR3D{CQkZ4hV3P49CW<7?_Wxbr{AiFu02}SjB>30UAFQ%TUMYJwmG%3Lk4}^Zpy8U ztvQ%n$=Dr~_w}QOQ)fe~_eNHZ%Wb&US1OU;HXg17pZfe7kj}iZoE+<*bUNfZ894)` zZuX})OL8#s+{MIlp@(Xz7w<1~vgGcY?Vc@jtxvgj(0045HMH0lJql_RI5nHydb=V? zKNhC=^2Ubt<)H79$mhX?Zpg(iHPcT?O^;9O-K_=gFYD0@CY40&DdF9UiZO8=)4|0B zVDRvbwt1fro4&EX{-xtU%(-tKsJFyBO1M~NfBm?o+(!VL8}uRui243m|EhZLLw8m7 zw;d&6_$6V+!LP?n`5wc|mRT(FVL4kmnd?8UH}{SU7V5}FU8+{}y7&2Dr&HmhLCE1_ zwXK&oLOm+;cj5&G;r}S5Lx=$nzEgL)@3V0HnKq(ERCOt8J|Q3dYKhEzKd*|R7{yKz$&HKfJRy2 z5VYN$wGRPiC-b36^@H(b%4WKly0yjP)U8I|yEY_qGTJL;uHJ31I8c^FXnXEB?UtuX zFFQz-k{~nIh9Z_G#73>bl!;6&*=D`qZh8wDovf20dJ4IhMbi6S?f28;j?vo)-@@67 zLa2rg&^yZgie5vS{d77#{V|09W8BPJ&>J_C!q;CArini^(c{~y4#f13^ga?&y{SsG zL}CsP7)}393Pst#=ljxuftOrx?+rh8iOM8oyr~AOPHM!Azn2o8e)_17z`fLKT`2hE zwrc%4L#x%VT-2fP7*8}VEW~7dxnCmW@Ci?!slcif7QVq;_v6ahVQEAsnBY{A1`SQy zjkg3w92n3)q_VFmG1OxjrGB%zuLLRJ?Mvsu>M_j<#iC@IwRse*n9Sk1plO2nN-ga@ z)96u&@v7pMk;!jHi4xD1%qF#7nQ}Ih`M4RbP1{Ttmb4#VUj?!k63c<0jY*2uv`?{U zh@saJi)YoRe!FVLkyKuvV}N&*csLzv)Ti1yt!&S*=8)xK^5Dod1wejSesDhzp0!V@ z2ou!w>JBp}7jh@~6Zg&)v~=_lwma*%A}(1NYzH4gXB{C9iaaJ0-R*`AH_hP=(Tt2f zZj2+hR-E^ke5}jEJRVi^VQaue#Jn&1^)$Dhhv-5e#`^)I z-HqNEIXGt3y(aD5(aIulK9ZtohNFqAiZ{mcmy);;}w*|D-C+T z9cpU=>oQgmy7e(fD0|vjQUaGyoY!|7=N(P+4$Y@sr1G*NG?%Vcm}C=_D5jb`7<+O3 zYXnWp9W0ESIFYuw=X11o^hBT01A_7|Hb&3x8JzMPK9H;%;*<17^N^UXJLio%CbTFp2RpFCnn*NJ-$@5SwqWMO8IGRJGKjR$iU~?-9^Du;EWrr@mVeIYd2U{H6c-8j! zB}?gJ#xst~6_1pmalwbAdc8v>f&`!Uz>^_tc z?ysw&n8!thhBm7~)uGMp6xYNnoL8?mu1sr7GQPLdPi+1(e|CFkN_B|S80*(B5RBGZ zLE@K0awVxv$Z5MkG5dyhSA8U#NwK;CZYv(B%SjDx6dyMtf8<}qp@UGhsESwumPzIc z>c`x#l?0V2SJJ*!^;P5$+QoN{an{Ayj+s zb?-`9xMQ1)IXrU1e|H9Ty&087eKxNI*}b#gqOiiD$7pwIkO2xRn6jEHqHIp}u{GWM ztv0ABlR3(QClOmg z5}9V7z|PSN^%26Io9LY#q4kES`g2tBbY_1pcsw=Vi?6%0N8hOl9_@Ax(%ABt$Jfm?}D6ormFAShY-75(nBbIjIf z+aCubyFk-MR^kBZQ}u=yZX1Ry`7#iP-Rpey`sne?{=O>(i=T#m)K12b{Lqr&JJjv9 zMT0K)){8_ZiN0Rg3np`4&5hjM3L;Xe%RS+|6`dV(?=ZJZRxs&F+5D}d=@=DGozCO5 z?EZTejh;zy z9E1;2RdJq}dMtBz5R_c3?Qi8T|B@rt`tBih)tJemQuAj+Gx6L3sd+FBpQyg6dT+dr zl?|qW_XoXjDDW0VY>sKPR%c@$%589s?n-YaKXU_@TScmM`vufyUm7 zdD?HhqZ51U2VizO#$s9CUx{VmLL?U!ZGJ9zq8 zFkYweb}w#6j)489cF&JM%)?kNy#wE?yDhE$k|%#kM;`MT+)uh*01UlYnK_I zS<3~Pa*4~##SE9C@}&f@#VAQIVF&3NLk@&`-z0Km0fq0yfXf9p5eGsbX;P-dU_tB_X)+h0t={TZVk2`fB9SsCRsu>< z(>KfUH%ngk2(X;C5}<3o@+VWj^+j3R@T=;F+SkW$b=y2w_muBULkph2cH3wjf=ojD?BXR7>DRPu>;P(g zQp_2~(0a+M!5Yv^Ay|W8o+@l+W6yK@PYy%~XX^i0&IP;)SEErpRQoes+j8ZsEagu^ zl{e=~xOEMcHFW?m414gpHsw!trkgyrJ8@ZDG+2?ZNmAfUXRg=kSpqKI2|npIqBN3h z?r-s7>+565N~zAhsVeF!Ug~eTfvr6~dBlZ67CKtG*9tMqs-lLQ1+5_hqP0&Te&`5# z4#ly@tta-W0ReXoi~X72a?q2QlLaHs(RcD33iD7>y2(!7rYB~*SL%}BuM0^l6w`5O zwLdkA_kR^WDJhszb&Mg>oiPhFkFU>5*nD`YX8bbJ+(=_AjW(sgt@5UE=!@&c5yW$> zpPOU61rip;p_dX3ea!M>seL>SsgEdoe^(9&^Zho$s_ltTfK?MPRr@#9c^kpUkHAb< z*hP$_c3TXwT#;|6as4)vkKbMmpTjW`7%fx$ZZgSLUm} z9v@Wi8kj%V@h@Nh-lV|xe!muo;nCBBmwz_U!+RoGC#4tsbezvm=i8PI?Lb~@DeK=I z`L_gQE*1EYj{{NqlJW1J2eXP%#B-2Z#{blusNDb5jP_sut(^UD)vEuiFjadWz<#TP z{P9gezT6AJ?S1_!vN?m&Qw;QT}bNZ(A#9_+y;#rX)@S zFkSuQA{!ZO3^KN5JT|KQ&m*PQ9Wi^7BD>2)z`w3p>+hs18Mv%T>0eP^{e*Tt5RSQvVKK9+{lD%XX97H13|WmH|GQy;#XZ7MfOty7N2clv92hR zs>;}VoC;`VXVa#0)_$=5nyi>%p^}JHWBPN8&+YTeF{;vh|=Az0^Og*}rAFLUtd8}AxKBw6QJBD(AbyED_EPA^$n}ZDIXs0PG zrr>n2NS7W0Nb$W6q&W+uX7Rh$b1M4~M71JDAadb4phdnJwqa)MDOW60@8*VIgn75V z8|eCTW|lw{s?eqE9Cw<3c9Bdx|M-WXy)7YtK;0Ri{lE>@$E_ZuZ`y!u4mP{&8{54F zuE+EJBCj`sQqLPM^D_`_q9VAvPv)f+y;;?aVYNB&#$Z*sP(_nI1bhrPOHUx9+x2WU z_=NgZ7t@v4>3Eg^b@q@Zm%z==aMOMbSm1jImje2JNsx)@fUIKmL9<5sAYZjH03JRe z#{rbKOp~-NbIyUc^^@rfFIRTlg1iXOCLe?W=7ZA`yN~a}AhygAG@ff#EcL?siC`@q z7L>#Ya9<%iN9bLdW!s#(IUR6W6FT9elhXEFAAV&k*wHU#UOTeh98q>gxA%#X$+=R< zh4c#^;J%`A=oeGpw((6po9 zOAf^haBjrN@=Lc^`-Ds#zxx0%*4*kLs{WnwiacQZiQH7;f$2k}rO;$3t3KnK-JuE& zx8s-KJsu3s&k6{E9QKoW)MvHeO>TFWSo+SOD|iZ2YSYStc6CJYS736?{bTT{REk|s zyxT!KCb$)%S3UXTQJr?`eUCrAg1$~a`(IIJ_3MLegUG~~ zv9=Pn0GT~~hu)i`jDMTrnng#|cZqQgJHTVaSANBZ$58Gl(;*TWG58~8IR{3+Sgwq8r(?0 zf}KRIxQ7o}Jj1xF2x(3I%JPcb(&)P~#qD2uYp*Nw!^)VkAV6$^o0P+OUV7^q;aepR ziL5&$=IJ%}R9-{&d;}SRAkd)zfM?o3s_R|o^4X`G+CTA2N?Yam)1*WJ#XtQWygkqL z$leH&SY zayuydp_v1piGZvX@5+4AlBd~bmXo10xH=*-V`>K0V(#ch5D9ONwq%;Kp7iz|>NJ|( z(_kY2#%Nm;UTy?kPRsoYG~(R#&6wq&6`xwJN{0zz>_OQ=I9fL{E5v)bN~(_>yjs68 zJ40mLAASYgvDV7@0r|1`#Zj71tBVd7#LxVtn#aMsI56FFNB%=tJ@IDtBdOMmiAcgL z7%Nc{K(YFs_0f4yaTH+_n@_{f%dGYD20{79hAe~rE$h(%vP!A2L-a=>rUgEbHHf@2 z8HTTR2$68kRqpaPukJ(_fZOf!z1JRI4s}!B#CwF|OePuU5!HrqZdAMHJ}P)0^Ed1? zb_)ZfeJ(39KQQCy{v|%(Lq%j(oG!5>5hyia!$Cw%LWt+RlEFrW_G_nu;S5_{9us8N zrR~g4aYh9~>otCb;C)&;+^zV4mOqQkLKU|DXnLum;J_^n0&(DGKdGQ^Z&NS8wTc4j ztWHWIH6>Sy40X~H?_0c;Ndq@q_Qz&*y*0gUUNX0tWdi5aKw16UFK88$1yelwK>61G zzPtUyMs2$N%o2P8VkCWPM!jfCveE5K!M-5WBTtONS)^}wqqK|4kr+WKcPK7fFi|{C zg!iOCX2#;Oi7Dgf-h<8sg`0fXLoMe({rM`{@g}d4h-G{3NXUaB9i{m(%mU7SC^{U2>M1vV3{qdpCqu6sJaha349o! z#TP~mFBR3_vD8UP$XaDM$ZDC98$YVAZeT}r$jr)JFBiVGur*gPF6$3a%Et{V z=eLP{5(!#v>+iw`G9H22K@@D{0^G@V4wARuBtJ>G@?5vwv&Zauh%tQGkMOVHD=69C zF7J)dbWz^sB3=b0Waqhe94Dy14|6C@=Rtp|%z;3j7IdOim>Sqx5Y{~EcsIDu;QS0{ zYnL}f$v}Y#3EB#qs~6@Uq-+5I4(sm`AyqH)(&Q4@Et;PYNJUu$_WynWfXdJJF)^3+ zFO#uAJ@?Zxv$hhFto2smU{*k3H6GjXz8)@O7a98IrsMPAE3=XyVta9v8k^+Q(%AFD z>kMKo?j}N>pcW(CwZ+3lK)8k;uy+a9u@)gRPW6BSLAhzl@^42J?dt_y;yKR@zqy8h zlDhXx;FkAFr~KQkgdj~@Ymh#R+W9Bp3S_Eto&V-)*PzmaAyT@Vxnu zu=3~I2y~y6UZR@eM%Ca)%WJ?iThN~f4oGX~_gd7xdCRpjY!Cr#;;TKEUP5mLv7Ipi zwMxW)VkLj1^Dv8!5$Kg7+U>I9^yg)IB$PtPOJVzet1U|G5qfc@mlkJhiw6HgeNawVJRX zum&PA`tgx=#~}goJ{@_5xKa%Fi$>;~T63g%Z%HeE?iuINHN4}5AV`Vl!K54gV2xDi zom-=1SfAU+e?sODAxpcJJdwzen*uf<4{N7w1Ln>h>&?-I3HX4jAV>pTPy;B0d|Y~&SH`Q$rQ-Ss}#in4jS^^W{I zokZr)!c-6jYSQ_X>&;H*eH57lSDZpq_LJ5>c`V5VKG`cHlBX>^-q|MUZP+D~k973y zC(7VEp-Y**&^h8C%%mAxVXsBa@%+-g|>s&R($1xC|P&yV&g;YqH;}ETm>^FS|j6TZx75ENU&F9fDUKK7149 z9SBJ)P^``dOEuNY$>MCeLpK|t!+D-1dHtL(M|G00vnA4Sv)=Xnx(5OOm^jaKgdUAu zBBvUd&uaZ`a9oN*v?|*SflYj1<90Y@N+?kDbIa-M{zw3{dhx~u_|Aa&9YycH2))eIS3nWTTuW7e*sdFGTN&*8m4fHGh8JgKf?#*jvrVkS{oMBq3M0xQI0D(H3U00*G(VM zsMy<5Bism!Rs5JgGML``3@C&LZKVZCXJJ{7i#|%v?Km2jX|Whv^!)@WIqx zOW4=4(LZ}1vn)>2Zc(&VU}F*rhO{fCiQ7*uGvTbrdkOfruVa>A6oh$3w}R&Z^EJgI zvp2J}BC_vICkyfP7j&0DT8ViT@4!78$7g&r?=Y8ynyDLn)v}@O8S(Xp)=C>_>>f|b zRgfo6J|rmm?Y~QBFHik*vItq6VFuvi*dWS=oBjhJ9vlze zSQvji%t==J1fWma#i!U<826Wm&lW#3Hk~i|5G_-;)Dm5S+BwPpV1prD7ujXy96f%H)?_ukK?l4 zxq}qGmYaRh#VT><^cR=>@nF7Q@x^jWOAEIO4WHRj=3nItOcU<{di0oKX4hr9VhA9i z#_vNBgeTFP;=K?W=y$f=b-Ag;d@^L#w5skTRqwsMfK_AoSKkVgCK{@VfP0_K!E=$; zc>jE!oDf0M-s*|^tSNW=3{1x%^{=MJ30o5W&5zKet$h^p;&D4=MWnmUrs{;wEOwGj zfc-*LWaAvAuy-&chtucMGX-1w2eZ)ntyc9&N?Tmc=R>cmUZUbX`L{%t>zR)zn}>u& zQx9A&W!JEPI^K}U`^d-v-<@tQB1@yYckX=p*_GlleA`Pt&_~=y<`}ux-F!J5FSyC6rt7wbDI{W`Lg;yyb=eFnKH4S%+%GTl+)DV z(hUTn?$+w^;#XzG-~nGKQtjN+@< z>4k)Xn>#^XzH{qXhC}-uy>Mjw8=#2E($ccr@>Q)65>r}j!hC5GUzs#BNSRG)b1^#6 zNLzgRaKNYcyiDaenyJZ@5n9JRgY7%oXGT#q**s0bJS8^oPffHsEVv-7U+BwQxr8)(t#4TM+(ULmEIyuoD#fXs%)`&oM4={_ z#ZJ~|qm;?tDU<8UQQ^V1W@kTZy&Dcye|MsfUC&O^;4X{fzU3(Gmi(h#$s5?gh}p|t z{&~irhZHu`j9Ert6;(1k)$@X2xR>ed$JgLWWO@^^A&$D4-_aEv5x%Tx2{`LZn1fgD zZzlV@Q(L{W{x(x6EIA*8&<<_t_dD)2ODXo7(ibg?yp*H6?5BZbW@d(qD1M~qKx(gd zAX)8YgIT&fd3)8?gSVC*M2?cp3eYKTbT~3-oReK%WW66#V?!*1MoaXJG0+9YN4UxT**;?YEu^_59HA+d)&7!ahOG|0 zyl9OXVd^&2WEtEk$df9E@>^l~*x{k1hL{5JQL?ejQiob!oNpe5e*C&;MX!#irxJhRIJVpNU@yr!6C*CogA|NFmnt9G% z6VEZSO#0b!F`x18nq2% z4_}i(Lj~)9h5dqpT}f$`wv^_!Pzy-Z>d zDARQ|>mhg3XY$lUx3r*))SN^%v}uSP;7~BTSnA^9hej2~X!<@^=kFa&09(3~_6;+{ zjWy9vN(;3n5^|z##Ent-dq(oRZ6vK?({HJ(easd-#$uQ`(6J#Bd!*}uB+o-VulFF$ zq#ramrQ$sItjH8ntOw{s7p6Y~YTweDKKof;MrQlzDO-zg^H^(&SB)W6f%8A?Bs0Sk zV%4GAoE~>)J{yS^Y6gOxssX5Nzomta1661R#aB|*!h!4Eg>r|tyS%&@6RSnR7Sv(I zH~qhEdCYv~rLybgbCAgAjtPCTO9!?^;AgkHR11iNYK0DK0rrKfsS=#ctGse?UN z>M`DhZ(#pIOl4%2hbk6q2Z_>{NFkXM`jU7P++nB^F#RPKcGmooM15rJszjc`A?vy6 zSzapktE6iG)ypBp^Jnt|>Ehm@mx3V;K+%hUs``(4aRq);N0;OYQV)-F12)kYQh53^ zW3r@NNI&DyDP1y6EXM%#B&iFNdVe~at}M(5Q>iHq_8m~#hN{8?!ItIhc^m9mYt;37 zb}U`7X617Q<^$K8t@)UKe)jf^w&#QJX_m))UeO3qSPlgd!JN@0r^2&5-rGT|T9fzV z;Wg@jHu&ZPxOJR8Ixlm&ugJu5uKL6gReL>Q$WpY6@3}guaqrY3g~&NRm^fY=tkI5^qx}~O7s)r z-r89UduX=d{e8#9@*}cW^On1m=J&jvvcX>2G(Y2hm;BXN>_RFkD$A9N`q9OF>FZH0 zfxKVfUh$J-dQqESw+g=iVi2BTp26Z^wR}bQ>LhshF8&tIWr7!;O}T$BQ%vJxLvUnp zq?AV*vHX;JfZ2VS?B21=kBhP^D0U!VbRuGh_mC~hCS`myM1UUdDjmaSq@pF*O=cBS z{bi0{JMlEEKbfX6nyPtcQq>%+9n~9>XvRMIu4)~fCNM50fG9-hND)nB87903#ERVv zr+CLFCXu#+mhd8vfS6I7-vlPhlzg@JLZ046O0nMaxz^jI^WDiIk=>yob}uL>gO_QU z_^yDjGSf56V%~yF{mdQpTR(EOEa2%4=EjAK-PgBCtqx{Z$@6Z@{*?5RKAN+T8u_RS zq9x{WGyT!8JRu!!CJs{=DSLi9e{qS9$u$BeLm-h$H^n@^fPdZ&Uj3P>+3Dg(Do1o) zB{|tJ%B%r(%8AseG3@eRUYGy$&ZpN2<=aE9q4x?GJUk9S)V;F?@P%HaDSGRYDU5}j z+J4$pOlf~@=PO3%?Lr%7lrT#g{E+Xg##GTA40cUGL??p zs)k8%Uf*1LbxplhV(%dvxIH+dNN0X;Uoln&Yn3cy=VCYa$2+?xVusnrTEp{L;0}vT zMws~h<7%6Fg{g$fl)(s{V9dr&1~2pYpovj!#=E6xjrjT@wEK)zoKqFmyuD;2soMiU zQ&j!Z(uDSu)WZu^LCBuwl`eb1%-@$HWQxmggK?5*S9bvZ)rO@Ye6@f zx>;Y69CR~v?rGmlK9JWxwMfLbIcCcxXVi%4J{xY+AiHx54jUtC^SaX*c(qv+4$GRj#hb-EG)j+0d}$j zqP^65;Y>djv@7UBnQ5Q*ByxTq)J(*5L_d^?qwg{1@Ea~D(6SD;C>F?7NTRur<}2U& z>)hwapwFUy%N;Y0&@E2l#+xmoUCR}YPxZ@rMPr4T#VO#) z4Me`mEd7$Kf%ohCm{Q&NHJ!&z?S0aoP~D6A^V*P>!HIFowCJ-fK0?lFhKCBV$A)gaSTpuI_}&&-Q@X{Rb7c2#NgPlhyi(NV`rW^1?OJM7 zA|3qWQf9xQW^gt?vpDji9+Ri)7x2aaZ?y07Ql7zMk5nD-Q&+;sA&#Cc9m{jKcOb1MYwZ(uPo%Urz{r-+_7g;f);3Ot`d#9*_eWVB_M*NtGsS)~WTxbN z_qpVHp>B1#Ou}?r@ftJX)#KG*PaE%=!7u)i)2lR%CQmEK{^YpQe%OY+)4u4kjax!k z6G=|Bn}_jx+|?{8;?M~<6-~}iZvElQ$1#VDc>jLSN`Nsu`us+8h}Ws2&bm*>n|QVz zP3vF0*k^UzO_k`@Dz2Xo80)l-aFtXc;LAVc3J<2L53PQTWy#`!N-BGJYT@*J|Lcd9 z%H+vXXsx@D<%NEEJTnc=KK|AC#I;o&Ds5rYaWvp)JG zR;~2^0{o``$_3F%McXbJv3XnoJ8M<7i{{o>R|_4P@0zJ1zrr8D_S37?T-zs+&*U~C z@*xFTV+Lc3DO0$p3vHqIVAGXdxX;Syag?cicf)+%MICkN8;kVSTJzsvZOeKnB7~92 zRhyMpz|Sd42WAc4w3ib#H=MC1bc|r2-I@HMt!`VHLy8#2#Cv ze`FY09Okn>v0Ci8IBdlbW0QaU4M1p=j_H)lfi>cEE`lJL4{dUf;dO@tMFUj!jQrVm zkZm*TbvmtjctKiIBpFSb^WCOt8@-8v`WsnR6%M9?qQA&y=X|Dy-l&&O&N2$|_fj^2 z-&3$YVotdsN&r67;m9s%XUE0LXg5eDc1c^~MrvK%jIWdCi;7hZ!`%JWDzb1RFpml5 zY^a*GZj)LcQ(D5Q#|e(BRh|Ld_P5Ml@Q_sPN5@okU-82>9B$Unzh%5QK^ZyulL(;q zl!DXUxyuLFr_&Tog90_l{l`7tYSE=mvYhudOo_GX zOdi-rv+>$n>+UmGa5Wc%<9%(x-)@V$cGtkHhgML#?TovC>32G~D~0EgGv-_t6S!D` zP1&jbwv)LJJg3J*%If0#*d!nX?Ae59P17k9c|4{O>y9k2uypgTBU=-}t2Z5bmOt}-Q zyzD-8`Rc2>lI+j@x#2TY9m?1*YDZ6}!0%jb^AZm z$5_Yb2SWridD7nCT+OPRw8Brl^9NUx;@MI(etDB~e7*Jyv#aR4Jr)zSn+ zRMeWngAjdHb5ZM1XJe!&cENOAQHuAR;!ffQTSX zdhely&{PzWfRsoJAT87o2m}%W=fnRQ=k9UuxDWfj-krCs@vS-6`pvoKDzl_t*H3b< zY*V&8740OeoJvM?z}VJWK>5r9tVURB#1tqwH+mWNr{ffG3~G8~9os2`pt~f%4H7h@ z?vLpf7ki7tGwU-q18LAwd9n9DN+jhT)*I|LYnpsU*4b9CEXv~Wi zpI%&ESPM~YfKB%k{GbBe-Q{>!Qs{Y{g4$nz+!KVd{@lue^ET2S3l!SOoVemFzXy48 z!tT99=357+pVhK&3~k(&Dh6xKKbJc+Z6eF!ELcD%^*5&pTb9W8JUtGMC>608Ho)(5 zN(ufo6`CK7yz;{!dvSKEsEb9UolGi(qnE^0`;QFuRhD9%Ts)uW@+q;LMF@4lT*LPw zCk7L&7T)a=w^lg+Y?ofrtfZJ4%WOT{ZIMjKYp96VIWh#=d!w^ozRdhimFDjGhFF=_ zXgARyewJggh|8lyPP{?Ac8%D)`)RQe(`}i!$fVIUtj{I0dHv_C&x80woC%cxe^J45 z!<76<*qQYWV5Kb5H4}&q^6Y}y)_Q&S6fE6UqOJXE~nq@m@p z**6WfNs>VDmu%SZ*J|zk zAbcfQ&f_&m_Q02AuW|APdVCkOj-m9%x7c5)VdT~z!es4*dwiQ#Yci_MI$9oezTW^G zNr>gDi%35uMhg~a$M84Do^#z1u~e<;e7BXtwe^suq-*C9i;C<`8dv-y8Ie5`-1x2# zRwk3|IGo1ERB3?r(^RrNuC=6BwLq18UzfK##qk&G;{%9GAOCm)E;8V-m3DXTMk2pT zwMO;Tt5<8X8Lu-LJbgu{n#w~Tcon%OsoJZl;uLWh;#<16&=Vnl4hX@ZD~V^aW1aw> zw7Zm846!bo#f6!6%Y_FKy^Gk3m>r8un{9^Op+&93y{yPN2{E<(ZxXK}EmwR%>;^FY z2%k_6SNMY1$B#s*bEs>`dtlxRqh9zlv4^ueJmt-tA#kIw zxAd{l<1BZ(Ow~92#KROI`Oot(G~d*nFK08SS3mXy0#*F%w3Q5l_Ev=tYqMJ9c!p#z z(alcc2tSFOz^^Z!I40hg?PoZD>z(e3?1KM>S`gK@Bvs?wN+JK-6S&;a62`ig(&=F?M%yFMCr2bg;1H!A%%s-?)ebigT6P<8Vv&Ut~debS@T8V>uh#y!47YFQV1h64@ zg~}1&xmANe2uG;J$u$FBhLV%BDAs&jZ3=K!Z&-WXY1EQ;;bglc_bK42$YsXc6RCQ_ z4fn1-QM8N{D6?fTAlzZqZ)!faJ#c>Xm>N3W>u4`s*ZuM&k*f3N*yXr;7hjU+DmXSD za>Wk^%oqQ(!@wqyKJA4X1`*ThuU~;g*datv`|wpbWCo_b81sTPkBImLmfLLGqO@uW z2%Vc9?Zj66G}j0OB!a(`EaWa4Gs#H^C??M2u)$M_zl6`VXefwb*Ws1h3#B6y~;R70D+d=oOQ%3-j;;Vg{?UB)D4`8o& zF6gvK`?T)T4t^sI@Fizo7eLL19qf3=;%=0FF8y2qJR9&jl}3mvY4{BG1*M(c`#FKw z0OCXNQ9CWfla1%na%*=l&*w)iXZ3p7qq0>Cf0gs|rw#IAIFj|Wg?}7j=RapDQFF}T zg^7U9krsrgaknyyY+Xl+#L2^6t@>*@FMUWhRZVHgB-3%pim3z$iX+0r71q9e`-Tu_ z-3;o4S2R_u`Em2~5G0qgf8o*nil=m%t^RK4t@P(G=DbKjd^hqs?)NU?K?H+%7bwgy zIOU>)#qfJCBN?{m8XJ23fb=e-{I?cDqyidB`*jm}sxN%`k@=QVW=oOm|3jo$d#dd{Rp(akL z``Edb$wfJLBYxiEpdjE#-ot&IcUy<M< zlQjPFue88(aTB8K4$3W;Fy!HE{Z0$D=TQbP{L;3RO}$jEt>@|q%fLsm|joTYEwrJWINL$Yv2ZCE|&2Skte8< zJ`FlxE#ae5npZb|=4WU;MTwimy#A@gH~n3Jbh#)#?7_YM!?a~BDyTY`#bI8G(tkkf z(8f`i;)=7qwWw{$81K9HYqNS(} zA!lqET&o|+`NwkvD){-w;7TxG1B`2k__`B0|0@vV|)DzW6b0x?#R z&A17xML=5&`YK!YhaQCjZn`#B(GxTWS|2u4`^XNE1Yc=V@TdmVy!;`RvQmi=bp34} z&WHB?ope!Q9goMO7|z)zC$(e*9KU!=ot;wjgLwCLvRxbz)eoOi@%T)0yN8+(nZkWBeo^rMVO$v&ESv07X>cE#J_h7|D%?wy%|I-xdJxllXHp>7ovm4oyLw z(|=G~eJ?5+|2)T!`Bc)h1Y26{E^XMpN+BE0M?AE23{xrR0N*&nL{sE9#QqUG?T7Sw za{pAM6nl4_Mri(VS5khL=I00_+0K0Wi@)BJv~Qd79opz0Q^nE+`1$Ot+IaeWtF7S2fT2Osz`(#4Ly=?PmvK4))hd6Y zs+HDx^lK>&&9~lB5?{SEjkfEV7It}brmv^=5cEDxs8NR~6nDHDu#egCk1I#{+jhS= zyP_&%sG@eKvd<}*TF;X-WrO%g`C0tzo%&wth}$n_%8RL!GwPqnS%0Y0T#>^hKA=<} zorS>UH|6`+S~h!R#bEfH_#OMi0Er!BL+ctSd^*u@i368>c$m~lEn(vY zzd1EG+8JBW8*vIB{p+USJGEIf+xHD@@KhkBISB+vLEi+Fs~3(s55-coUe5n+!TLQF#cfpM2VO<1L-$p* z_<;u{!!xh7YL?6$BXG@^_FY^g9OI%?M0O6iz=D1dQqn-T);6SWKG;6@jdWHXfgWC| zhg^tlGY0h&fE_&ea<tpm{qU4&m`1Uh~IpoHk4`|5&-iXZqt8}P6*Hvz<4E+g)- zGvUL}0BHZOE_DBX1Hk1T2}}_^B1*@^cm^1u$V~vrf4d=kOQ&ak`uGh42IzX1T~9w7ds$^AE||3gE`Pu9Bp+388*Tf>&%>3823 zK|A{{o$Ah$G}=U{6Ph&q{YvyACi-KOR_kG6e3X3J;Ul3>g+Ei@O!Siu)8fURp`&*R zf|~2n$hDVF>boWQ5B$z=eRZP)oHsY|<|g|vCPq_Al=V=&>m6q*1^=LJ&y_S46%^D7 zg=z(4V6_@AF7ZcDCpPCRrQl(UMlzJV)BKW9eH9>91!7a;{DJQ+h{fJ{!a_s5mV(pm0~BsmzCp&8wRp(&J6@NYLB0Z~l#YBXeN*4s$d`f+CvSOen6z zH)EO?N4MqQ6vta26Gd;1!sRCktLR+xJ9ISsPq4G*csFU|Hhe3lp-fZu$?z+|h>cQM z+V&L|NXz0V;qm&jBXw}O+@D8x3A*h2M+pqUfROQ;r0Tig$&EGevwIvDLl`les!J@* zBLmZInal<%@Q93GCKKCZOtWp<+lQSlbOs8Dt)1MMI`A1*G0o9zkWWSi>`+7Cu}{Xv zOcKftYQjjU)3<#zd?OTWvH=eeHby4#xt*iWko>&_GrdXw5gWg`?kt7aR%u01k|`;g z)?zHwM#{VOjOFyDP|}9=%B}v>B9)XHaGvoCH*j*z!T1_i7C!t)U}>!NLkX&c3&CJ| zIYl!slZF)zoSWd&l>%Qzf1$_GUet<-P^Ibqt7B2%nQR?{k;Toc9uXbAJOw)F&ktJ* z*9EKg*9p<#cl|2-e8k4ATWOwwNju4kXNscQ24e*s0S{zAE`w_1F7GAtfDM1Hw)o3GDoEo8Q7W?rD7S8UeKS(~*LH4qZo zh&L+uZLkr!Wbp((sbB?GYSI|m$)+Ktm<-bXYxXV|3%&J+2v$*qZUzO9WZS4j#hF}_ z04kIXUrm|Cew&`WQS0B_tmb_-dyRKZU*!u_#br_>gDb}vR_kk;(-DyRs)(E%?mKgT zMAYk5>X_cz1DqUec|EAJL~>#KL)@!0>9eg_At2kvj2q4Jg~FapjKhTRW?ZO{|L@DoG0^KfiePHGG3QQi^vAl28}QMU3o%5vR%k))5BNrkms4|_C+83hXf%$ z?f3pDvfG-s6ivF?>35g<`BcectfASyDp5S+Qpy%DziG7WWFCV+_9^~#VjLPF>_4ID z0_@4bCo6n9MN?B%?sCQYB7PUqS!G?*;dc@O>ZP#ijHq)n&UBT2hp2Bc{oyWDH;E{c zgueJB6OsU=)K~O5#x;gG37)sN2TF#7ZG&>rpAI}?{pQUIz?S#Mm+oc7r7ffC!R5J{ zQg^f(2hn_QKGBq@)6dY>eQ16s#^x#f7@HVW`66QLdeRDu%bFI-WUM}&zj)~763$(% z3o4TbWNGVh`LBkzN5yx-%pgBkobnFN4uZ|d;@b+(B53|@ld$a%YxWGzYZXXj(S>pH z6Ce<*e_=$dUaa14Ab|Pr)~7wFV#rcOYPT&Ax=Xno_ZKJAbDcb8n$r-XO}9 zA>;i?2YIdme}t{cOyPZ7CuNS15XBKq-7973WhsLQmCB6XJFbk6Nl5{)6DOeqA?$(^ z_Ic8Bc9BQuh+ zOkO@*qOY&721nLlZ5d${r+RAU_5IokdRYI5)9to;RdaiF-{`h;s<6g7b zZlDVL+Q@Fl`WLIbN}1MYN86COAiF1`M96d`X$}gM0Kyj7_Mg>O*{BO2W_lY@(4nmw z7*J2gxg}Tc$L1K;Q75Misg@?%-XGK$l!6%173%(~%c@&+U=-trjLChz=3~GLiWYLU zNjFi(yy?(Zqh`eQc{nm!oiDsam)>oSO=B9f&G|YLn(4+JJJa4e%ub~TlF3Vyj zMGg2^rmL2l*P|&J#xUzO6%9;?(Xvw#`lg*ELibcjyyIr}lNsE-7&(@^@6AvA5`84g zErH_Cm$)Il;PhE&bl^D#K`26=V+WsXi4eDGO{{9YF5%~91Ad4nb4a&-TQ{8gAt|1I3L z*qG(*mO78CE7THxhVqVvd@ff%=^u=~Dc86v=ckkvr|_=gSCy))4y(ND)Kj3e4vKav z<43an1FquLoOf}0OR!Av zSwFoKA+2d=!nCend?m=@D~zWZGOW8Le5K>=#dFp9de@8BMvdK?xk3>EoX=jDv(q6! zF*W_XH^MF)-hLax3!6%I?b5B~H=ny)_-tb`J2+#r6gVe-t~}fB-tUABYi~xnw!Sg zzMxaCaAF~BJM3*lH{LGEZo)P$@i8d>7M(plKXD-Fk#5cdf}2Ro*rkst zKqf~9t-|xQFV-(tuSzaUMI>fmRr@a1u{EYqA5&lXJ-oGa{@&boX&wsi5=;8~nD9PoCsxN>xiE~gA;EBzMB5LYJ~XP9UE2nsg( zB<`$yTu5Obl=*0cD3y{3hNY;9*DIffqYvQGhruPk4O5K}Q;Oli=iR49yj2N~$Dvk1 zgvE8+kxdg^MGIkrE>a~eI)xZ zu($t6j|t5#{a&W#`AhkQ`-CFBQ$WY%*h2}PY1`M{{$GZ&r!e7A?CNm>&2f_FVe3fE z;s*>Chxd97%dDTVF}bjYfhT&UVeK6qj1Yy@yQ-@4k&cmhw*wE`Fd&ZK(4n4VyWn8! zYoqBRV86n(kdjmTzI^yv><1Cs72_Oz!S8AP-vhPAsmr0`J08TW+!fJR{@YheCzS>K z(=WAMYp)H&Q8bJks1vnC)=fU#nq->{k$cuW)7v3G)OzX(k;_jVF>00Orx&dPse}oD zSGZ=qUtRh3BrdgIS-q*ngJGiYV-sWNDlgQP0cC9b!!}|CPQtn8lW|+4ZzcsWi|lVR z3o+O*+&o9p%0Y{0b>@#N%ZxkKp5W3sZw8H|-B)fM-MQoFcNnK!Y#Q~%RPbR?6XW!S z1PBk7DZ8oMAl8j>O_Sc=6fKxKHaPyk`?HX%&toc8-e}8=XOd1cfn;do)AQ;yQ4KU% zgHcW(4{wonKb*xppiWl6zWK0MMDZI<_>^hdcQi4%q@{ld96DBB8T^Cbptu1JR*5LS zSAL=Vitk+wkoAJHe1mI|UqKe(VQs1*#~RdR9VT@GE@s%ZUp=9|>N&hz3wud+tiiD^ ztwvB#M#<8JwRQyP>07UwD2~ZfwcScAPSSr`jia4Sv@)jlMkPrNEu-dJs)A^sSsaF1J|r2zu2r!v;9%;7E2x1n4o7>` z9KKxKGtL*-g*N#x4?^LSQ5+i%?+^HvN4`=`z^_(`pi!U2uLJeS;IwrKkdLzஎ zovxofG6*vO=hi6X6wBzzQ)1kAT33g+Wv!i9Iv@lm476@HDZkg!OjcS>qWR1eK?#5RSML$IyG z2uyvO!4AY|XRKqWe#fzLY_1`rmC8DI#D3OY+l%QnND@|4ILAr%6Y-1vY`DRWtI2l} zx-|NHf!ClW^BQRw@MS-{%umF`h0!GNsCf`G;;7r4@psYx>Gmz-E%;x$0R;bcQ)2vw z%wGn^N2nVpW&>pZZw$59lUKiI0uwv>@N76z@n1eXVgc}%45#yCN_Ic`^4!0UOm`=F zf<9XSK=1FEk4C1g=(1t{-~SEPkN#&XG5#e3%%L5m#He*ZpzhZjy{%__qvE>DqyGYX>j7;5 literal 27733 zcmeFZg;!M3_cwfJXb@>pDFFecrBjd)gOu))?qzK{e9Q_yzlc5ylXvox$tuCxhM8MXYYMJ`*VpSU3!CB*Am+_s3`Lm094P0pkTrK=5C6~4pEZi(E<|_PW{9#=c+`a$v&+x02TAkY;hvgR(Ub+AvA!n+UQXI$(4h8`D*&Njz-&%uR%J{R&WnhbP-`|Sh$-4yr zQ&Ib>M~a~{U>SJH(h3R|u3YeD-pBs-498LsfQ#Hgp$PwuP5rhO>6wCpwk-g!;ZI}7 zR=G!$l7?*$ygY?HvZt;w2-*?@@UgPH*?Tl#p{)LJ)srGyd;tC+A?LG~YQ2}W z2yC0x**Ms6%3Gw{c_>iilQ>FgdZtB?b^ih|lOk~sVuApfL@^4&F2n#*0e6pr1HZDS zH!w&5O=k)9ZN$vi2BwoA;USuu{AX?aDGjMcn`*eyzK>zTv%8wwqGlhYdAGw9EpQ?b z9&6c7PMqXOj~RCdum^(KdhB#%Nrvylod!e9vY~ZPz94*hui@dknhr=D)n_D^_czx* zuu0>XT{~R;@iG75F7DnEa!oLG?_C=5I?;lv8!qG;*u;>ZMKb6=u8C1_4z3$rbIalFhi(SPQ95 z4Ql#M5*wgUO%TuV-*%~NDAQNlj8+s}bD(-5La-NPjaG>w%y1=v*W)I9_HFeW^f4m! zs;p4o+UXiTEw4-B>N#35(G@PfgPPj;W|VF=JML}ZW-SERlP3n86y{9BuHLNTGYwF@ zKID8p&4K{gAWX` z6C!Yc9GM<6QIlj=+zZYj%2%t043X{HpQCagNoCW#+Uitoe#_*iLy+6})~=sUwCd;_|pre9Sf3mgmkD&Kf-?9#ITcomX}d^m}8 z7fc~X#y&ojUW~OKXf~Nm(wg*suM{gfTko z$>66@K!>@+QgvqFhrV@-`$D`RT9bF_j*foPlo_ZfMJz4@ zuKlYV|hGuH$AAJ?h;^Tfv<@lbAM$*LP0vmv(@5 zv#D*ebC?~AY3A=Ma4PV5b(>F5Zgkq$d>XT;omuLG@sZF^f0#RZoGmCV?7geMYIS5j zt*N+e>?{rT@VASoN$N29ZEjKThbp)Lzm+;2SPp8AM`7_B@%$l)>ixkZ1+CWa)S!`d z#sL<>sR7OqxsZgx!gIY9fGN7mUE|Ls^uNy-sHxJM8_xMU1@x7sI~`oS-_xW6)!P7j}uue8JwS-#Ej*fGzlY{XeUN zPZ^GeK)ryQ3%t6V002q$*M}^N0Dr{-4%dwikR9Zo=yEE3vaNA#D-Mw<2~HE+Ozvx% zU8UO{5_WIF*RhkA?T%OCH3=9&FU2-3hus|08Sz@h$BX@W2sV!0IIwqBn!xka^KE}o zOFcuC@mttduq&BgTjmR)*)_<_t?$*{-_!E=ESg8g&o=C_BLho|pr4HV-_5|zSRR{# zedF@K0d|Rg26^|Z@I|8h_Ox$~ecWh>c*0<7XKLg*Y4wM|z?}~M_xI_)Dxkprw+gaeHy;6( zgl5>e;Q##rtmEB#9mWi&z>a|&sV9ucLgYIwJDL_GcfPPca_ToN&TE* z>-1;qQ9mugmTn*gDW~bGOU>y2zOR&h>}!!iIsJa(NB%i1meA}SiykPdg&!nllVj1k zUSEOBg`UZRvV$Eb8D!@SD z5b8TMdBxsx(r(u_v`|R0AagP!TyNg3YaHa<(06s#MM}6(K!cQz;PIJO#I|rGC|&+4 z{|3zbJ8Ki&Kj{Gg!mO+hdXj}PiK8P<0c7p)t0}Yb$ zWt5Ab2|u;OT{v6SL3&eH?W`DUP@Ce~m(s&=Q&kkA4xN2c@qFN^hx5hCUB<)o8s-s< zs1bU`?OV;=!j-i2%hbvx!xEWb&%lUg9YV7mwce9E!uhd_{drsNj#{NVnq_WA$EZtKf=(CwbXLi$Z*WI z#5~&BjPj-`p={aBWo*5q5d@bmxLdfj0-Q}Prio}<6XWZIVsjHmYN}HCgrWvi z7)KmwY$N1XE;rHRGk$GiY6UwZO~0n{7%H2JR)hnu#nJPT@%?)?({j^E@Udgt9qVpB4TRICloK6x zla7r*eN8OFa|~{`3t@NbV{jW*MS7EN8nVL=4WN8Ip>j4!@v;dg{i`I;4-^M9H%ZKh z)lx;y1)rcI+K4&$|hosS_&Xzkz zcvZN$1G>|~eD2FUey+MHPfEWRPa%}&562>}Mq!zC#Aw|21T(T7O%rn`wRTOY_MCfj;vH>_jmL*W zgN$AWI*Er7c4?L-6x>9HI~`3w#vZQj2*($xuWpwo6HHD`ggT7nyaPpKDQ%4VT)dUo zfA`pt0&64k4g@{%fOQH;DrwjNFDojSSXY0pM7h_n#Gwe+RcoPHn5$4ZEeWT1d_UD1 zouKkjq(P0yHbRZa9;3`?K=YY6O>OKK@2UnEVPEYPBqI}QC)?Ai`KT^xRO9uhQ(V)Y zEEZiSG1JZpq{ND4TD6r5sXrZsHFjVut_c+bSDSH{LY%wJO4vb|8y8*~ZegTWwdL)* z=(wH_+u=6PA^b<)c($2(pR`R!lcATnb}s>vfD*@td1hsfBJ zOC4z7)DO{6A-^(uvck)GOQ6ODEpPvIM!1kjY$ii(V4@Oyi-c-G=icSA&04h<@Z79d zlP)<&*StTd9AS-D7Gs>%tC1U*pzVFVIy|(vkk7#wW>b0E5u{hqLI$(+AclkkfhJ6IwEvy-_J(2 zlpg~rpFTc02+O6(B<|Or=@WXA{Nj7AUPZPpj(7g0;3gd#D#qqOl@hb%vr){J?1ppMTUMJlVuv=65OHk2jSDq9du~u96cVm(Uu!?=rKPV zw|kY)>+-a={A4$&8+CG$^7Hs&Wh}OdOPYO0vy^FSUv_%>T=Z(472LCXA5%hK9yJ~K z4O=B8tlpdtaN;Sv&n41&b~dhwO9B85@_-Fm+36NlCb32$@&myOsES43YPM4tAVQW; zBuiw%6~xBp`CV{kTMEg(er{P+@TN+Q$b{-E7Usf+S)meY}OFf0HY*w~mD_}8&eOn-N~JVRaDpSKs;YbI@!)|i*B z83{@Tou@F-*UB_s{n2dV9tWTaOfMSvTR6`n$i%-BGw#i9&*lUT6|xEG365z-gJYPnMJ24kGGTUW*TBi;usM`<)&elmt>`t?=GYPu#W zM9yJ2(?@jTwb^p|Q!#QWmA&^<4aJ-He?6NiB&}E+pse4=<@%)uH3;^)oE&m()}eb6 zw?$tyyDh%ywLXJD9DYW*4W@_0$UEii6d`_DXE{+Y#HYu+%WCD9Ds;T095)Vtw9 zH0=kSP$+w7xVM=UvwQVkoc3!XEekga(FD3(b2)LYpvv|kxtdC-UiT&gGr1iI4I5 zr0L~~5UtO8b*akyv2@zL`)(a(*Rx)2#!cxw$ES()vd7rxYp#)AGsmlwMMLL^tCJSY zYs^m!-3^{+Nh5zS=_4$V;+g5g)`RDN0@15qF?M(P^e{i&rrjR;c90fajBT0F8kxYF zGJ;mPmfN;U)l{6~`*-?@%@|sb;-wkWq6Rd(F_$SWjN^&+(|p&i;l@77`Za|;Z-Sw* z9u2Om?H;490)RQ{NQL-zs?FI5gabkKToHaC>L9G@8_VBVt$)q6eO z)a-|#H*F4DF1`MnG4Du&FIXqtbiRYGhtF9A*YC#y*H4l7W4)|NffZ?+=4E?9lJP`4 zakOg@!v)GXYgzLy95GK{@}za+rKyzqFIq!pI9ot9f+QWCdeRWZ7c(f0**-~}tXzIR zAjwDL-$LHJRamry9u&7ZIJvujSJl*gSn7fS7WyLji=7Pg{*Tc~b2~lG|JHJ#vmxUfK%`BJR z%kkPKwxGq+>g+g!$CzJN9_hzT2bI?DaGAqM-7jl=BM*j^dGYIk95mWV>^$ zXibB}|06*=JlE#7Mi>7X39E8xQu<060QCuIai1g6e3Uz*-<)`?B_{xeb^CX31da$$ zrcp)&Jtzh>%A(t{P(4npnZ6EtGGR~088EsoafrLOU;W%ZVemsM<&FSD<(xmtW=^EU z$@7x3$>6bt@lIiYb+1QyJNY{2amvqwZ$F65U~(!G$$6SAzZ5KVfZn^G*k<~oINKav zzev|<=5WbZD96o&J!T`Xo+&D+v#9E+OdNNJ7?BA;r+9#&TDlfh@qWXzd(TqOSVYu- z=dKt=Jy`x>%VqMK?vifrshp09Wpmz9*#(GgNr+HQ?;A`Xp|*=gNr&C^48IG~pFR8y z!$wV>WT0^_j>6q5$Hzy^z6_ovf;gJj7d<>(bwd@s@OT2OeU?i~=-6`U0C#e7fqEh= z#dI%QKWDL%eIl|@UNqTqS~+Eu3c0^N(0Y-)ARm&%9q^~FrrzoY>2hLxl334gTD4ce zZgtQ|O^cX5gj+2KH(h2YZrdk`mz3BnqH|jW6!1v}Gm{FY~nIz*&BbdU2zzy^IJHdRZb{jc|GJ_6xGTc@B}(30Vs! zR4C|U@|bQoCVZ5K>amQun^%{}<+9;dZegH$+Mfb7=Srnof_M=yIEN;@M+&+BqE-%= zKJx6FEJ*zr%Z+l@@b%3{j!_euwa%w@;>@_3N~P~afoFpok@RQEbJN8@BAf&qB3t;r zUB4h0O=b76zrcOo&fi!Z>hV45HYIYtX)S%mLWgpf-QYsqMi4=V*PaBL&M+xa&KLcH zh;VXy4_L!<9o(V}@KE^oycv#9J3>d^q5T7LN#K$x&C?jrh*w7R)zO@T%Hhx*zEZC3 zT#V{>x{E8}kjR?Sk2qAxnoRB$)e7xVem!&C_a@ToX&o1;J{_nLsXOc9>VlOA7QulM zzrTCignY^K`KK3vwQ6r{=uPO?+jM#c3n5KU$dT3H43>%ZgRhY4e)nGYt8uYw&;~+0wvE{@2i-m76UpE&ahdLWE`v> zU`3PkW<=%@_FUHz4nv=rtr9K7x$3N}=eNFrh{un(w8yEC$>~qG@?Ddfy6m|kmK?urJ;p7YQrx<4)b#n;C<8fi2m;yGwH7fi zl$yYH1A?J)u>PE)`w4g7A;c23#l}R6vnwu>Idtl46ty#*3hzpGSr^JWh?~Y)7s+n< zR!hU2FQm+1F*||iIS}C<%cVTOl!u@Nw%Xt*HeEV94D+xu1&A)FS3O-Vh7QGuS3Q3ofb z(iG_%M0yP2omI;1y3-}11Z6H;N^=Rst`RCu@=%>M8;f7cYXz27EG81I+YcNJ`GWfo zbGmcXw;jLx<~vnP*X(RP3Yl|R4IoF3(jqTsngmh^#ue?S%lF#V9r`U!{A;~A?4lHpRP zJEBQ3u=?me97j}vv{(9(?4z{|>Blt9&zP>Mx$l}{Avb8<$0N~sKYdQ2m7Ubc3#9?f z?X&HnahJEH4d*kSw<1Q1>k@36K^W-|7Buq0D;v=4?Hys*Uk`HcU)k8#FE0wmv1dZW z0=veLV*W+{x#KB8cWa*C6OoGMqXM|D;-I}#BQl36upRxT=qEPW>CJ`q5StMhILUk9 z7HwAc)1CD!V_Rx{Bs6|--hQqxhkZ{6>*mv%CJEiSq9A|B9rQrn)w=Et_nlPc~o zm3zc7%&F=B@;Jxx&$MxO;rJxfz+Q==w6khp0FMH!0&O z12Zo65(>f(nvYGAS3BQy=16@t9BaL2tU5O(bLzvVQkzFVJ>*SCgA^b#Iv478L`E3pV48tqua6mYR#LT86i5LlO;{s) zOQ0LqpQ0D#cCz}0Aaa($!hBZqxBQ-R=2s?U(p;vl-5PM#mLUoqD!Y?-r*zz~&5jg0SLP$+3wt(_hRhej@y* zaFC5RuyXM34K_k_XoY*YAsd`0bxNv?*)0XcW~h)sa}_Zv^RaSB6~f-8+Zx6jge4!&la{1^DvA^r=fFO2!YdDd#?nvkmy9cR}@DI{fOJc&jL z?c8=ah^%RRsxhI}{wjj<_HOk3AA}r4zd>}|$PMCHkI;uWSa4ELamN?jkH4$TLomS? znLslPMnqFJiSd~w9PkTuTbTQW)&A-!7?=$8xC{^n)0{*?6LSCIlh?qQbon1J0zjmg zHB}KY4cnqb4n2?*^`gYH7~;o$QthoFUfHtA+XP=vbee^UcFgg3B; z>oru5J)UkK*@NMt;QpYiJ;JaN9PzxL!m+pDc2)Zauad+Nu6W0#Y6^(aOUen#QbmvR z)fFb2q*D-8`szVEZ9~~9;E(XQ78bY_7!kAz0kJniGui(jt*&8sWlbp}2#q5_n8gZ@ zwpe9o{s7xYc`j73RLxYPTtf9bq6$9~O`arSCnfVq7*v<}hXF6wyFmY?Eb%t0-}O4X z`ysv7Us;TE≶ruakHo_!h6)5-R^II&4xz9ft3(4?Hh^ws2p`n`P_S6VNizeB`7o z(B>!dt5(za!~Ne$V^b#lH}l~@;*Z{vk1z6B9hH1+J4=;)spN>j63 z4h8bvyC`S*r*JHy2XYo5Gw}N;ZI+_~GLzwh24ba}Y)#6Jo~vl1#li}Im95XAP42-( z3*WFH$p2(u09n>|2Ms{teO+BxC6&G|R71Q`LO1NiI9Gu7*F77Wfx`Cxy%RIe;3r&c z@N#=PY&Hm+e$k61{Lgy-o5uN1>gDkD|3sW%ckBO62mMd3=WoWQK@mV@HA4O;A@nHx zZ*#RI3%4TDzWkrcTRLO@zp1EcyuF#u>my)_ioN@NXD)Vbu3iMQ<1+`@T770V23IM; z_ZfY+oT?O&p0ju0hSRjP#@_mz-u!){#2haK{DcjqQw>`ojUzEpn`Q(;*0p)bcL`i4O@Hp{g>V!eVZIJ7sw;rVa7m+UP0ui6b z)v0wu0H(Hi%c6y zyc-7qKguvh9;ZJdKf>F;TZMX;mC7ERF%Q(*%#FCD5?@{z4@g|r9Pxk0wM`)$*s3-C z@)>04Xg(2gbQ$sf5rTb1hwRH$s|1U;wif#LS;mg%7GD9HTyf5#NgddsX}e0^@X4dX ze8%u(Jk`Ye{D=wwDHyYkTJJ2bgX|p|Gvilq>6@cXwHPRlBPJTtoa%KYUO1`ccYb#;^|`lNYltIkBq-ah;Ci$uDd#H{l{4k3F;edca(H6Xd3nFy0y0DIT{+#oEo0o%F?>S4hUYxV z0Quvt1YfI@9OV7XGW%EaOGe z>&LLy!tU9JOgZQDi)nM-YXtZUAxhzURK^a~3;7|tHv@Pt$c2kZW8NYB3E&~v#unZmFL%}i<_Q(mSa zoH9jG6F^e4zVbto2B4c11Lv;fH7-uGnVei(rzxjt9&qpja&_qZ+%~{e6p&q;_&725 z7PbbMZQ8Axr^;NNq}y_L`(%4O{y=aIP7ZRM7|koG+I(L_G9#sK3-A8H148$-Mrap( zK?a!nZz3JB11zm;s&D@W+2s@)+@{fq@-``)+?ggSdrHfx_mmR?ZJ5Qj*eI% z%-#YY0oHuVn3LSUSk!I4HY2mp%pZj%5;N&Ip z!3y8(K^j~(le2Wa)_RN_t&fDcve+Gfy8P~Kl(^IJoyyk!wVZm1*m|`2oGK7nwt2fR z+WtCJdV55^B}7OXkoC!OMbc(63XJg@o?^hV#_moHNN`Nyh)z#aLVLIX+|Jc+yU9YwPbxP z!m^4b+)MZKMdRk$?%W2L!My?iv)|5a&wt5Q=B|sKrQ(=mxOL1PKe* zb2#&+n_n$;+1jrWqB^CJ(La+WAU;yW5hndB(En7j7vL+GpF_IZ5yccJL-lN(hnQV} z=Ja0t|MW6SjpWElPV#Vm8dKm1ozPokyrItUKSQ9g($FFa;U%%6LH?)Hzw`$=FdhL} z9vxDkg;j4WU z#6zbWrp#ai2Le4ivzw%=BH9a|FgfmhI5Wz0F6b%W=R(yZPav{hVP&}nlDk2*WDWC) zc6iRGq7y|hrYQjVobxO*(3w$ZcmLA+Mr zuIR3?EzV3>#nEBz*x0QMs^yU%VJiT}9v%DGC=6qVzAl$o2YHV#R|rV7hIWhn#`lk! z$#jx{`clJ!d>TEpTIT$C?ZAe@gZMDnQwNXrYY66g4Z(O2$o#2{?lj-V*R~3ra+!;2 zj$nwipNn|B#WoT18xA!Mg(8g)n}Q&H~e1ftKR)Q?kfKyR=2x$!XL3A zb#w**!I5jrz~D<>*oz|zo!5R%4i5G}~yB)tMZ(xj(>#ytrQW^E?&6{0=)Lc*&!= zmJ#PNL1how_Q+1v28SgxtpRb6?D}`J5AomrzWuH%S1kL4>ZH$ONz~iIH;x@5OL&}5 zZn6l*Fmg4oGeGL;K5Oipxr=ONDEljbIGFJde(PCAsyz_u%15+FGY7NOOJ{x!0iN~! zwB>F(l(h&HdipF_fo5F_e^$7X1Oj@2-3QF6s_{OjO_EE7Nf)=@L<<_zQfS_T0w2@s zRr|iDh^DRHl=;5Mt|PXWrYH!=#u6~_aC`o6b}S9*PUycZ zJcx7+iB+<;uY;y~mg_%-nR4ng#E==)k7P~Vq~1xx^q|e>rEbTPB)}jVqSfrvh|w^S z_qYR}_DwqtnN^`stN=0_L;piH`be+h=J}n@ll$vaa-@^Bu~y1+gPmGYmTr2WL5c8h z%nQgy=rcxx)%Xjw1MqQOIrLH|G{)a_v$mrknUeo)h&(Lq;RY#h&Ex7lE!)(~w;{v7zKg%d*tqajboKq1njw0g zJeh1_&&J_%BqqE3wUdJ#C2+4E?3xvf*s+Eqy)t?ZF!K*3sB;RTceY@tPZ#wcN5|yf z_IL%Abs;v#o=8Bc4?X(GRWAwhL?2XNgVq`9t>Ty4qdOw{K|`1sDp$9LyC?Y&-QgQ_ zHNCvnx|i&kHmS?^&eZFQ>Q6Es6J700W9#1XNup@Ly_PDMw)G>v3?HSYg9}q}%M_Or zWbj+Q#?>*;TRc|{$Jek(@4~f@tgv4fWsFgT{fdAOQ(y#x>-ec-G7j+UUa0>wVE*bP zqifCB*Dl~le64G|b^r39iOpyf--EWr+_U~TXv0PG)i$5cGE#DRZJ_R+vCix9#K1!w zwXZ1SfYaxiZQO2%!zv~$Aa+vhDpQCdCm>wlee9vPe1QkAAYM$TMD8!7dyQ39$yHvp zC=^Y#6^f+f_v^T|_;i#U1oD)Qqi&tq1?<9TbC-0lrrmvlPqvQIutzU5dSa@y$AVaL zV}#C5NO?5&z$6RElS-fH%Ypld4s>QWv_6hr!`=IHqSAU4T{UZRI@TSM(HoUA`({kP zX=&N+q!I+0np*&oSN8^8z5PX7ok_uye`Yvy=Pk&!<;mYIvGMsWpp7$Qk@LNKyXdhD zDa42hiGwdIp;Z)3?1KO-u2!c7{#oCDm<%+6&K2%r1g= z5XbK#ty(3j_5(nI*XFQB?!Cm%kv3Ri`H{@ReH1N0m!I_%7`WNQ=pCqF;ftpN1$Zdi zgIAj`!!V5vNnjEJM$;a!_?7RWWe+Qt0f_lj@enNyc`C*0J}^i(H6_Q?w+p5RV~LWP z-OgP~GqJ0GI`M5O;dgrar&md}Y89y8;J|;7ECwG2>GmD)`#r4%lU#;rO5YuKO;*sG z0i_M6C7ut>s9KXNo@5Phe*AiTX5wwrkP2?0KwCPI>Ud(KNz5wGSkT>yYGWr;#cC{7 zrumheq*^^w-$g_}IQq?sDNXS+>Di~BUsDg1zz9-6K@dhG93R$3`?k7V8uP;TXbUSjBhP{z@NW9dy785QV|@ij8CK^WL0KBb|s zkP!9uGIriw#h+B>FyrjsP_Y?7XB(3gie(_20mzbv897IE5!<{|pazxGp_K{Q+O_4r zn=BsEn1QF^)rs<6GQe98E1TkG)`XCg#W(^X2u!bK81fAlPmj=c3s z%>sSy56&Jdig!$|C@W+%@aBbd+|=(gOPT)R(e+2mLE}CYNE-8(FJD@-sMFr9k)o*G z`q0WH-@9=E7t3jcvT3t~t*NRPUL!>a9VSg4}&cEf)9#5p74ET_Jqcu5OIzao2 zZp(p=5PQZNkPX@SEF}MR_&CoVgPwK3btQ0RoHXWT68-qxU#u!!E`3E`+sj&4uV+s8 z$-V_mRgb<)1683CrCWn>R-b_hN=@Np^V5gGi<;0z^fOF%3y+Q9R|;g(U?c0vWCd9u z&&7GyD<3RO2X+Q5>n-7P-OlIB6zA+c>KucWQXr`mmb6aG_uDy{L@8c(z%10wzug-4 z)iVEX(7m$H%QuyTUVldD@<;x&l|)R_a>@eisZ_>ZDC%vf%c`$;{owJ9x0^pn7BEa# zBbh*=(g|DbES=0%*mx&4HaMhiJ&3`)K)J;OL8zolk)Rbrrr5tOSNe0);3WSRUa4_f zvedBdY{2;XLr?n2rr*M*4-=iyKU?rN+-XfOf1a%PAfo354@TU2d9J>rx&!$dJv>{- z=ls+fE{1~G&b^$c#(o|L<6$EOd{0Z=I)-#s_~y^GvvPdyLVD%l2K#Ij>aC4VxVgBB zCQ}k?<2=<{n+eNUX%QZ!PF{xFx0C1dX~zsvW+wMMSW?4(8#^Du8um5?LrWK%kl}%) zo};*Bp)2Q?wRst>8{;hx&Ms$}F8u<=^haJi;>;>o&S=~t-EarJfIg=?8h4LoyqPml zZAo)$_Pjy3;O3}*3*p$G^$U*yX_=s5($>^nrEL9PJG#pU_WI3yZbeSdK23{nc<_ks z#SG@6Ha@w)I>LYM*kL5dB8-DuDO=Xkear*q!jf`>vFbx8h5%d@EQZfN09v<6XTqBv z^0A;}8njU0*4t}Yv{IR_N7cJu z^#&9|rOESyvn@MG&YBexL#pci?X%uwcu==ZkeKR(^|U%v7xlcUWa>P}6SGf_F)_d3 zd&E8LEH`=N(4Bw0BM90nm6a8lUy zayg1=QTKM{!=k`^@@vhdiTT9O3i+M+eDLaEG`o#r){eZ1DT6=A53#5D^WsU3RIh>3 zh=kQ~qwlxwZl^)qGNvAt>!3Mx(4!ue+dSy-<}QTMX8Lc$=0j(rz;li6MF2s+hQ5%O z%1U$V{^LT6ihZ{aSE9C?cUJNm>Rr}GDUkamyEml5tW~Z z{A8{umc=hZ1i1nsHJaq_n;K&{eC*P1IXK@n72gMkc;fDY3;D?*Fh!&kCKz1cb8 z33NuDL7W3$y{h;wm;`#!Skqk6<)Y2OHJz55zmPR1gh(cCT5;48s36%mm+X;rD}SL z687Ff!-`+(5KXx|RYE6-^{hPLPK95=j?fY|-w^K62&br3fy6a~H5>7M?4bx`vQ!Z$ z2H(T8c&>2w$)NdZ9r3A(V@@an{hl#NUF+L2eO9g&S#L;TfRVP8>X>0}L5KtmCpTXe z)w?1uDHw}MR^NbR^COxs91?5J1WZ!OiV`pEaLYP#V>(15jA(NAzvXlmsl0lb@M(pn zrm(kV0i*$7V2>G|_=tzU*g zm2;ZTt~JC$phC=+aAv}UaPGjF;lzvjJn##RSe;wD*1w-}f2vsB6{H=BC-=bc&G$K3;HR^I`PF3I~GFS9lx`+i>}EF{zk4;DG~j(y0} zF1@JtVf(^nQk_n$_IV+JR=?N4xva*VanA*n(u(6YtW`QkH8Q~I{nL%ir)~NV6w{nHmHcg*STU6D?w#PY$D<8ufQ{X z*2AsrKO;HJuO+!XwLkq>nQ-=)n_NCDywPZ+2MeqfL?=!_T@eog>og+5L@ZoJeqn>+)1?9QYk3`|$3;%_G0^IGzZ4pmNg~#1%Ek?_{5kIg`w%o6$*6g|*ZE z6b)4GGm z%#r#A3*&vG-9aj+vzZlcJ|;#+>$wwv_;jq}Jug+uKWTntblmlkkK&sthPODHMU5V!Vzjo+KDjjT-joDn^KQNEYA20VP{Vd|9Axh3k z-egA40*rz?D^_)Px|TF~$dMhNy`^^LKC?v8q3Sbk*{y1eKU6b! z`cs1Sc5G-){zBL8b?~Tlm4GJYg$&uC zSbNTM^nH%#-dST*Q*AenQ$vW3ee>Q<`;rdmB0%xu@>9QkeT%nKFTK;tmqyo zUy4J06G^O0BKRGq<=>cx@&N$ym-(m`87r7gqmg@#t}Wzr7Z{rVNLaAL%cQIQ!6$r7 z!~A}4x7S=(e+g%0Q#_iT-z$!oH(J3GPwR0uV@iVxqu1Kg`FPE}Ev-2mB5;auXGKlk z?dY!65u;}x09gvk9N0*;7_;H;AJRjM9SO(BUog=lE&e^ri9ce;aNZi1JehbQ_j&qk z&%DO}t)K#UNC!TKUv|bQTB2=vzdQy1RDiR9ujzu^hjF_*d?+UirPNOnlm>$(Q-*=t$E8<~F>MdmBjDWp{s`4Y&%H@HMMxIgu!73V> z_fs^{{ShWNDR=gL4y744-*Zl?a|iqYQ^df%2M*cg_hYE1lwQ$+jX>6ZFu0ArkHu3M zYM}q~adqE5#yH|-JLhwsv=~*2TKAP6LphQH${LQC-)-|-g^qk2AL|>$TpqU5g6SR> z+p~A^wvLfG{S=z?5NMs}cP{W?3`3f>At z`Og;&2CNDmHRI>qdhzIiG&28xwey`(O*dP=K{O~5K|rNQ02M(|KxtA!M^wbbhbA4A zDov?EAb^N8X`-kg{hdvie9Nr= z?Ad$Io;@>r@A>VNBc%5EK9ZsK!U4d=|6Z(HAIs-PJhzUxBc~cj{`E#1*=x5dkFWTr z_}cUwL7)$|!LH{I^5%Xin^f}Q!e6`=C3@F3h(kFyF)p4VDauuASyMN$rs2$9cD?H$o6yz9TK6%u`45So+E zGu5euwI(08%SCI1{n>Pb&mP7xf=eSu6gZ_>WsOwOb>4o$?VLB#e!*tHnfg{SQTUXr z$742T1l#;}o?obT8>+OHPrh(hyL71U_xm&T+24y_OdeJ&fb?TE;NzP&^E_LA_I_3; zznLlfJ~QnjNpnl2ys%u5K1X)@-nOl~dWll(@?5NJwzSjd((PjuR#vNTqW}+In!mJE z_OT&E%)Q6MIK?Ecc|V$JV>RwJo9Jov?q_pKg{-gNfV=fXeAoMoY{ND)s#&6VBYukH%gx4aK)a{Vpa@_$`+A1VW772^j^ZWg5}u2dP@f$ zkKa3WoL5X(;>e`hgQJa+EtT&lrGQLF2R)C|tV`aw+xf(y+eW}-@FRji!bj##Vxs}% za(dwQu!!4Ix~K)Jc-;j)7ilOO3`gy6q#v}ms%(GNj8k53Gp?wwY|be6O~4uv)E1>*^ftvz7G<$-wPDWJ>`^d%e|(Rxv1B||#2ZPD-jGu&!_ z#%v_l2?46R(>&AbZ7XBo$anhcxsHIAXi!^9vZH#~1&|D-CO0GHJ9gY;@4Qv6EZ|o1 zRXADmQXPNsK6E)|8ho_C!_ngV7(_zH4WoA^QPg&PQ-iaqwj$QU&*A~)8yF{fd~%|0 z!e{o?&Gdl^EpE_#qaFXSo+12AfTKbCGOotsU`JNNj;@r6=E!knIGXi4Tlr!MP@{O| znS)5B!OKhY8v^7J#f-(mwY4e`PT=DS5fLgM;%aX*f3xMN z>Yts?Wp19?D#iPA3O{%w#_gThIWMr#IG}!fGAcXX*0>Al>M`!3w_E~KPAGvC>u*Zs z>Y$q6Uwm`Rxz`# zvTwR5?nl%)bcVv^xD*x0pJ{wPBeIaq>(6Cu;+NCeI=>B8@oSon7en z*9WC0b0c^DBULS8aiiMYN3$P{$@0~Th1wXmBh@W?W$rw*8ao?f7&-A9MX`DL36s3V+b4e~p-n&0PHEQ$=JzWLOLj0ge1acqc$@-_&_uB)O<19e)|K-cb`UHqEPE zt5j~ezF*f;d1v8^P<*cc!$EUX?vXI9!j{4obY~}Q!K%;?Dx>VI-|dks#ON9eUIm=R z0%}|PiSRRBr`Yb_-`;(wDhPVnUwKRY`RyDtQ3;v6D{1^<(ZRR)SnYh+-DV6gmL9zq zt;?%^xO;jjaN<}l%!Roqv6}e+p;ov0zJA`!XEN@vc_yfVira*Y7HCDwas)ViqqMna zW?$8sds>W|iClh1)E!XI=?%&Td2>QnGi>N}EzButT7W&H(;bt7JG2WBgS^0+kvAcMB}K^sOo;ANk z#*gND`%veb&~**B4X{K?mP8MAFhl2?fkKqqz3AfP4LNvQ&F(Wjwzlbt(XgQ0i5s(2 z4_@yxq|cM@SDrH-$5GQoQ}iVv7>wMZYf+79(jBkKRz5+`gd zAG3^G&)Pojtl71dZEWvseeVPvJ0Fr!?J@t5Bgf$vUkr?+qpZvD*6FZIwc#*lLlI?% zPoL2EZ`wB%{Oa3w7CY8G97Cy)!$F~^6k|h!sKR;@;&vHo1*?tL|@JuF21@Z zXgnb5kL$=hBCNFBg4S9^b+#HxWaqls;MpySVw?^4xE92xLuwVWjcX8dj8BNU z{+R`hcCzj|Cl>bdhoAp^?+h^IxF#9-Hhg1XEwvtpy?*hHZd@)$$Hs3(GvHOQLqgn1 zh)}|dQZbYC~|W`YRq2Xz%sCt8wSx66L`No=wRy zqIRkZkG8U-sqnd#64~l*y2sIy^I$$Caj9I9-g-3}SX4BU?=6gz);_ewMQ# z-q0`CyQPu8W`$0L5A_RKrdfU{tm^U$X0bS(HXINp6*d#5E{TyAA|@H@)$x87m8T;X zGQ?*p6?>T35FRL42mJaY!rwa#aY_ijXOLoU!E$&RQp2nPiGVIY`Y3U~0fXBf!3#B~ z)fBE8Hm4c*Jr55LpXWY4ob`FkH9#DpUTTBa$vQ9jUaP>6r|0CjZ=k1XpViq*oyEN% z3(JYmD-d9!A?-Jr?^hhN2!=j|igPp`xDTj3uP)lza>3Bf{y9p9m#ktWQESmovxJb4 z5P$t@m!62R#r66xk774|0I?sF6h%jO#|Hm(@)yZM){V3C$1J~4+pAx)CKiKna$YO7 z9CoV8yKy)b*?ySN$nsob_v@SPd7m;_R--M?3{&Kv#nID`IZ2B<0oXjjP|o_{rmc?m z;;j&gZbeejPM@x145nu3%R%;6q(SE~=$4~Gk3rfw<3T&$-Vwa!jtyQlx^B^QtT{_h zt_yMDC7eF>F)0sS9;{}iIHU2IP=3LjFXKYsUG{g}hHG)&TC3}k5mpYZ5lMh4F9=Vi zu+<$53bFNh-tfcBkYt?PmKYt0*hiMHGZ)gnyM<=-R&B zCz*69@b{hk9=m9R0!mfe@vS@&wr-{$kyD5?22uM{bqGIq!&fT~;2;I^zq6AZxE5`- zr#%@68T0Lr0zooEYOdx{O%lX0l8icQ4wd`;O!ptLxwnr|P7R*M9lRT337Y(pi^(tn ziXu7|Zf}bjm32zgF1Lq6{Tcp* zm`H&t;DYXhnmTE9YtXTQzU-h%FOzUTM}r1p1OoMramkAG6|}te?m;dUb$fYu%@sR-mi^SJAL)BDqNGzTn1+3t zn>!cy=w@wYvd288>UY#mtP(kbOZa@yX0~7q*NyY@S{85i)7d5#k!r-042x$?$DFK? zJ5%A)*t*&4YsJ`!k&}T@C>9WYdcnz|Zne_5g|a)T^YuKEQUh6Q=2tnby4?n ze*=5kbLMp&IhEe`^TniZ5HK{S5Kqbdrm~aJ`Wq4#cy)h<3;sPt6)OVupW~%L@l;b= zXO%rtIWyxFusB(mX;Z4J@}gfayAU%E1Sk{K<`=DK)hORUYERAjd2b6To($sq_Wj>^ zs?iMxs{5DsC5Z=}JN(26u7i2iJ&8c}1tbqZ3BW&HaMH0bNYsRUT(31y-Q{NF@D|9%6& z2Tvd%?jh0OCeS~n4gU8V00rG{U<~Ts)9vSLF;kz!PNy#^CPb zryD#bz1KD*s-(tW?@!e146bp(50GGH1Px_85N@kGu`{>B)v$YikBIVkJm&AO>Ygf3 zY`D5|&W}E}H;c&)9HIUE87=XEPBN}v(}4(5(;D`i_8ONeo)ZTNBU>M~t#Elg3rNIv zJwVP2?$?S`L6f?6d}T zj8Tf%3wmtn;}Cfwr|SF|fRt5(W^9$$(VkQiO|0HKfhd@47TqOx+VU~UI^`8fMO9Zb zdhfOj561T=alh%{jb#1Iu|*%Zn%PP(rBaexokAcyozaxOA5qVeLq;x%*N`=-%C+?( zH@D(DhI*UDYB6^7)N$VdY$+Afs!E;hRmly9FQrg%fm``JMygL|nlNOiq1H>2D`^f5 zTs5M7e+)`3@krG|L0M$~@+6G%3rcGf?d$Pw#!@f6md(dQlxLpzad{PIHwD4i-?`D& z746ciNEMJDK_t>aSQF@-C1`#{huH}!HKQ6(s_yHUDuCQq7I@_>a4?lvXX+1UrWEOz zyd2c>hQU{1?gIC*Tv4U*!KY66(4g-gg66j}>*ya&STnjLFe*9qIX#0qdn#yD4l<8s z?;`-)8&u>h*KRGWcVRCmdu+m1y5OxR7(2_KyH=4skDOMa*XGsnOn}qpZlq7!#AUQo`76JGj&q-_kBeN z=0+;FGXn=ls7Gm^)(#9Y^V^_tl0C`zo~g&8^-q`h`k?x4zX>+{Y0ChjJ+ViSc-^=KkQpajCwPGVu4BHSvHiK%UaQFzM_0hTCAu z713YUrE@CD6kk%nd>Ue zBR_obsG_A#rEK-##!*{pqO0ghY~mg4>^tTz>kJy>0ihOsvC}=y+#uBN{r!)!ec>*X zBrASEJC(7n#;t!*ni3-?{h4i3b$Wv>C-RF{4T37v>pxl2r*ceNV}~^mgYM;@vuBCtYiSyVU!E!ESK2Ji@QX)uelh~PcmZh)Gq|;=4wAWy)CEBmacg*@D3q#Xt08i zfBgLwWmD3wrP+Ai60D>hdB=WxK)NB(t+T=1;X9TVe}KP3S+txvIJFp1O69FRXA)7t zu-v6q#Qz$)F-#fnlOLCNQ+*m*#DjevUN>H8{?P2u{CU`9U>x`^{I?kI>^>pHZ)5o@ zCelZKDc|F}FSms2+rJL)rAjTn9_uJ^g}m@)Q%uXs>puH5m%jo$!T0Rr&ZZ^+W%X44 z(@^i)(@{Q`&W-m1Vxuv{mdZ%TnTt1j&^S>hvS33!Kd?mD1vJYh?7_^l=UTdpWqmg3+Ci$v+sjHuHOD0)J2R@&DzJnXBmT3Mb{qwU@G!%iXpAc2wi<-=3Ieln-_clcZZ?-*s{Sa6NynN3)Gz~93LDyD{DueC|UHJ9vP!$Z)aCt zr>$fVnSe)ujX|g z)FwCT=Gpa9r;O~BuiJ~!HsiJxpTTv0E4G#w_=RlK14cDL#OT~7_{j+m=t^YJ!WG>1 z%1Jxtjdp_~dnrUcDv#6#Ew^oE?vj3grV)Uky=>~;Wy^w>i{GTDYNex*y3%->oLa@K z+57N3=OG&Q)6rrrO}V0nffr|P47o?b#MS})u0g>8Gr`Vn3ofytq$TRo!7x)r#aCEB zDIqfi7Kj-MgbVLyIyXYS>;WW^<4MZtXL&PJX3mwDB7wv>6$W$c-LfN@)Yn^F?DALG zxZj$^eXN0KLPVr*(qkf@ldLj*IwqojW~Zz?L8TjwF2Mrl^7wbzeHnPS7{O&r7j0Tp zU&;co2T2t)1%vZzn8MO70Wb!f^>SS=!AvzF4!ArY~YSz$~7+) zFUX^W&%n!8sFj5?pJTX241=U>%Ne@gh#Nfe3tXj$63C7nt#eUy3u?p=6O_Ler~vO? zk3AF9Xn}eS2V2mGb{!iozs-KRXGcu5bA^6kS0fhs5c_3$Iy|xAe`z22g{eW)(@}Y4 z6NYq1kF-T%4Z#+ZV06OT>eZ6X2jzTJ71l~f_oYn7m7`AVO=lvfh|#5|FPycTiZ+9d z4Iz{2ts9&&Io!;KSV<-oE{DFZ+*Qh2zNPMn(3VDq$j?2FFLg&$OxR1#G_{?Ay6hT- zshtZmA9t=(v}q0DD6!_v;l^d}+a8)K8kz#jw`@nr^q>en4eJ!flUW+5C#8vh>b=N2c`U zO1>*Eb2y&BVtQUbv1?9>fRZ(>b$U9Pm4a$pj;w^7kNToZdhKR2xZli_a^ZHX zvAgQ=N%FGqSvTJGvBQna4?SpA`mJI(iu4Q}sb8~@31M>1M85{nZKc0e+`o%5ejCX-Yd$=v zWc;Z&UkPP`t8@XquJ{Q7-wW#V4%! zt9GWGP{QP0nZ(Y9e zxWDY9PKV&5g}qJG_Re*KpGT#SR4LI@{T`PRlEI(5j6y2!kxenc5W;07IP>&!MFHax z`FX;*dn6|X0r-N=TksD#1lF@WKcYy!D{Avmw>^x>g`Mp3RJK#Ri2AGxC4OJ(VsI^% zGAyHlDrT`L^I4IXhP)kT*`v>B0S_Qa;bcQp#iGCEY0sW+!3J2Gg5!)|qFRRC)^s*uG z9;V$LW|VBIoUuOzCMYnRx)#tawCG2pj{vzSscJHDD`M+fYd-t0SZ$Jt$cM{~(vd-C z5<6ACquBLf=S@>j!6|35m4q*7Ea$ZQ?-7s;*3hZMC1d6zVf69-Fv zws9C+Oe#Op*>zrK+{|Z4C5!AW>r>6FCcWAY)4?WADtN!37+lWbopi1yZ8G-Vb?#sr z(zE}rv>2Y=A13|$99x3UfqO5Qjd9XB|lx2o&%QC0hk6n2nJ5wg%fNWv~I;&Kh zVJ5~35@*qSdS~O%=4jiv(K3SRxCxS2Gf*n8`!H?xji`t(NV)1XC0}3XWy((F<-8vO zL#MBHf#TXNbW%+n2#SQEC@i@c95A$hb$I&5urrIk^NJZ}WCojx8x@ZiuV$VMOJU04 zRU^M!Zclrw1Zd=*bnw`f;Y1if*%AECUX48SpgnE*%At4}GRz)%w(xCRc)I{78R!#)%vBP$a`eapAW}|yZ`0G z!y$n2-;FV4@FJ3#fG@-Ul{5BXeGe9ZwiEad&wm8!3T}e`^Z%9VL?uvHa39-0$N(~6 z@N9cKyQJx8tAdIViGNB5P+z?|aex{Y_cowpUHCKP;kSJpdqzu%eaG8U-@* - + diff --git a/doc/load-balancing.md b/doc/load-balancing.md index c5e59331c2d..1071961b116 100644 --- a/doc/load-balancing.md +++ b/doc/load-balancing.md @@ -1,17 +1,25 @@ Load Balancing in gRPC -======================= +====================== -# Objective +# Scope -To design a load balancing API between a gRPC client and a Load Balancer to -instruct the client how to send load to multiple backend servers. +This document explains the design for load balancing within gRPC. # Background +## Per-Call Load Balancing + +It is worth noting that load-balancing within gRPC happens on a per-call +basis, not a per-connection basis. In other words, even if all requests +come from a single client, we still want them to be load-balanced across +all servers. + +## Approaches to Load Balancing + Prior to any gRPC specifics, we explore some usual ways to approach load balancing. -## Proxy Model +### Proxy Model Using a proxy provides a solid trustable client that can report load to the load balancing system. Proxies typically require more resources to operate since they @@ -21,7 +29,7 @@ latency to the RPCs. The proxy model was deemed inefficient when considering request heavy services like storage. -## Balancing-aware Client +### Balancing-aware Client This thicker client places more of the load balancing logic in the client. For example, the client could contain many load balancing policies (Round Robin, @@ -41,7 +49,7 @@ It would also significantly complicate the client's code: the new design hides the load balancing complexity of multiple layers and presents it as a simple list of servers to the client. -## External Load Balancing Service +### External Load Balancing Service The client load balancing code is kept simple and portable, implementing well-known algorithms (e.g., Round Robin) for server selection. @@ -104,9 +112,7 @@ works: a load balancer address, and a [service config](service_config.md) that indicates which client-side load-balancing policy to use (e.g., `round_robin` or `grpclb`). -2. The client instantiates the load balancing policy, which is then - responsible for deciding which requests will be sent to which - addresses. +2. The client instantiates the load balancing policy. - Note: If all addresses returned by the resolver are balancer addresses, then the client will use the `grpclb` policy, regardless of what load-balancing policy was requested by the service config. @@ -114,19 +120,28 @@ works: by the service config. If no load-balancing policy is requested by the service config, then the client will default to a policy that picks the first available server address. -3. In the case of the `grpclb` policy, it opens a stream to one of the - balancer addresses returned by the resolver. It asks the balancer for - the server addresses to use for the server name originally requested by - the client (i.e., the same one originally passed to the name resolver). - - Note: Currently, the `grpclb` policy ignores any non-balancer - addresses returned by the resolver. However, in the future, it may - be changed to use these addresses as a fallback in case no balancers - can be contacted. -4. The gRPC servers to which the load balancer is directing the client - may report load to the load balancers, if that information is needed - by the load balancer's configuration. -5. The load balancer returns a server list to the gRPC client. If the - server list is empty, the call will block until a non-empty one is - received. -6. The gRPC client will send RPCs to the gRPC servers contained in - the server list from the Load Balancer. +3. The load balancing policy creates a subchannel to each server address. + - For all policies *except* `grpclb`, this means one subchannel for each + address returned by the resolver. Note that these policies + ignore any balancer addresses returned by the resolver. + - In the case of the `grpclb` policy, the workflow is as follows: + a. The policy opens a stream to one of the balancer addresses returned + by the resolver. It asks the balancer for the server addresses to + use for the server name originally requested by the client (i.e., + the same one originally passed to the name resolver). + - Note: The `grpclb` policy currently ignores any non-balancer + addresses returned by the resolver. However, in the future, it + may be changed to use these addresses as a fallback in case no + balancers can be contacted. + b. The gRPC servers to which the load balancer is directing the client + may report load to the load balancers, if that information is needed + by the load balancer's configuration. + c. The load balancer returns a server list to the gRPC client's `grpclb` + policy. The `grpclb` policy will then create a subchannel to each of + server in the list. +4. For each RPC sent, the load balancing policy decides which + subchannel (i.e., which server) the RPC should be sent to. + - In the case of the `grpclb` policy, the client will send requests + to the servers in the order in which they were returned by the load + balancer. If the server list is empty, the call will block until a + non-empty one is received. diff --git a/doc/naming.md b/doc/naming.md index 588f611f163..676aa9f2980 100644 --- a/doc/naming.md +++ b/doc/naming.md @@ -20,12 +20,18 @@ uses the syntax: scheme://authority/endpoint_name ``` -Here, `scheme` indicates the name-system to be used. Example schemes to -be supported include: +Here, `scheme` indicates the name-system to be used. Currently, we +support the following schemes: -* `dns` +- `dns` -* `etcd` +- `ipv4` (IPv4 address) + +- `ipv6` (IPv6 address) + +- `unix` (path to unix domain socket -- unix systems only) + +In the future, additional schemes such as `etcd` could be added. The `authority` indicates some scheme-specific bootstrap information, e.g., for DNS, the authority may include the IP[:port] of the DNS server to @@ -38,7 +44,7 @@ syntax of the endpoint name is dictated by the scheme in use. ### Resolver Plugins -The gRPC client library will switch on the scheme to pick the right +The gRPC client library will use the specified scheme to pick the right resolver plugin and pass it the fully qualified name string. Resolvers should be able to contact the authority and get a resolution @@ -46,7 +52,7 @@ that they return back to the gRPC client library. The returned contents include: - A list of resolved addresses, each of which has three attributes: - - The address itself, in IP:port form. + - The address itself, including both IP address and port. - A boolean indicating whether the address is a backend address (i.e., the address to use to contact the server directly) or a balancer address (for cases where [external load balancing](load-balancing.md) From e860359f231cdadc9ff1c8292ef869b91b8879d4 Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Wed, 18 Jan 2017 09:22:26 -0800 Subject: [PATCH 221/261] Attempt to fix formatting. --- doc/load-balancing.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/load-balancing.md b/doc/load-balancing.md index 1071961b116..f56d2b0c73a 100644 --- a/doc/load-balancing.md +++ b/doc/load-balancing.md @@ -125,7 +125,7 @@ works: address returned by the resolver. Note that these policies ignore any balancer addresses returned by the resolver. - In the case of the `grpclb` policy, the workflow is as follows: - a. The policy opens a stream to one of the balancer addresses returned + 1. The policy opens a stream to one of the balancer addresses returned by the resolver. It asks the balancer for the server addresses to use for the server name originally requested by the client (i.e., the same one originally passed to the name resolver). @@ -133,10 +133,10 @@ works: addresses returned by the resolver. However, in the future, it may be changed to use these addresses as a fallback in case no balancers can be contacted. - b. The gRPC servers to which the load balancer is directing the client + 2. The gRPC servers to which the load balancer is directing the client may report load to the load balancers, if that information is needed by the load balancer's configuration. - c. The load balancer returns a server list to the gRPC client's `grpclb` + 3. The load balancer returns a server list to the gRPC client's `grpclb` policy. The `grpclb` policy will then create a subchannel to each of server in the list. 4. For each RPC sent, the load balancing policy decides which From d0f7bf4a76be6e0f8d8212c8ce91d054f478f29c Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Wed, 18 Jan 2017 11:49:22 -0800 Subject: [PATCH 222/261] Document new args in grpc_resolver_create --- src/core/ext/client_channel/resolver_registry.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/core/ext/client_channel/resolver_registry.h b/src/core/ext/client_channel/resolver_registry.h index 4fb16131db9..a4606463ebd 100644 --- a/src/core/ext/client_channel/resolver_registry.h +++ b/src/core/ext/client_channel/resolver_registry.h @@ -60,7 +60,9 @@ void grpc_register_resolver_type(grpc_resolver_factory *factory); return it. If a resolver factory was not found, return NULL. \a args is a set of channel arguments to be included in the result - (typically the set of arguments passed in from the client API). */ + (typically the set of arguments passed in from the client API). + \a pollset_set is used to drive IO in the name resolution process, it + should not be NULL. */ grpc_resolver *grpc_resolver_create(grpc_exec_ctx *exec_ctx, const char *target, const grpc_channel_args *args, grpc_pollset_set *pollset_set); From 5a96770fe305710ae9154779bc9bb8e603b65345 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Wed, 18 Jan 2017 13:38:32 -0800 Subject: [PATCH 223/261] Dont try to index close headers: this messes up compression tables for subsequent requests --- src/core/ext/transport/chttp2/transport/chttp2_transport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 790a567e1a5..8e213f8404f 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1634,7 +1634,7 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, compression and just write the uncompressed bytes onto the wire. */ status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); p = GRPC_SLICE_START_PTR(status_hdr); - *p++ = 0x40; /* literal header */ + *p++ = 0x00; /* literal header, not indexed */ *p++ = 11; /* len(grpc-status) */ *p++ = 'g'; *p++ = 'r'; @@ -1664,8 +1664,8 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0); message_pfx = grpc_slice_malloc(14 + msg_len_len); p = GRPC_SLICE_START_PTR(message_pfx); - *p++ = 0x40; - *p++ = 12; /* len(grpc-message) */ + *p++ = 0x00; /* literal header, not indexed */ + *p++ = 12; /* len(grpc-message) */ *p++ = 'g'; *p++ = 'r'; *p++ = 'p'; From f6d8aae8d5d480c0ebd7724b01ffac8a8d4c5e86 Mon Sep 17 00:00:00 2001 From: Yuchen Zeng Date: Wed, 18 Jan 2017 16:00:54 -0800 Subject: [PATCH 224/261] Dockerfile template update for http2_badserver_interop --- .../interoptest/grpc_interop_http2/Dockerfile.template | 2 ++ tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile | 1 + 2 files changed, 3 insertions(+) diff --git a/templates/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile.template b/templates/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile.template index 38a5ca725da..6204c3e2cb2 100644 --- a/templates/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile.template +++ b/templates/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile.template @@ -33,6 +33,8 @@ <%include file="../../go_path.include"/> <%include file="../../python_deps.include"/> + RUN pip install twisted h2 + # Define the default command. CMD ["bash"] diff --git a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile index 03ff179f718..3a5e15d21bd 100644 --- a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile @@ -46,6 +46,7 @@ RUN apt-get update && apt-get install -y \ RUN pip install pip --upgrade RUN pip install virtualenv RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 + RUN pip install twisted h2 # Define the default command. From 9c7a08d2509c6f0549d0a56690321c75cc201fec Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 17 Jan 2017 16:26:40 -0800 Subject: [PATCH 225/261] Simplify cpp stress flags --- Makefile | 8 +-- build.yaml | 3 +- test/cpp/interop/stress_test.cc | 66 ++----------------- .../generated/sources_and_headers.json | 4 +- .../test/stress_test/stress_test.vcxproj | 5 +- .../stress_test/stress_test.vcxproj.filters | 9 ++- 6 files changed, 24 insertions(+), 71 deletions(-) diff --git a/Makefile b/Makefile index 184bdaf58b5..0d7ce4d66cb 100644 --- a/Makefile +++ b/Makefile @@ -14196,10 +14196,10 @@ STRESS_TEST_SRC = \ $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc \ $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc \ - test/cpp/interop/client_helper.cc \ test/cpp/interop/interop_client.cc \ test/cpp/interop/stress_interop_client.cc \ test/cpp/interop/stress_test.cc \ + test/cpp/util/create_test_channel.cc \ test/cpp/util/metrics_server.cc \ STRESS_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STRESS_TEST_SRC)))) @@ -14239,14 +14239,14 @@ $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/metrics.o: $(LIBDIR)/$(CONFIG)/libgr $(OBJDIR)/$(CONFIG)/src/proto/grpc/testing/test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a -$(OBJDIR)/$(CONFIG)/test/cpp/interop/client_helper.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a - $(OBJDIR)/$(CONFIG)/test/cpp/interop/interop_client.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_interop_client.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a +$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a + $(OBJDIR)/$(CONFIG)/test/cpp/util/metrics_server.o: $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc++.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a deps_stress_test: $(STRESS_TEST_OBJS:.o=.dep) @@ -14256,10 +14256,10 @@ ifneq ($(NO_DEPS),true) -include $(STRESS_TEST_OBJS:.o=.dep) endif endif -$(OBJDIR)/$(CONFIG)/test/cpp/interop/client_helper.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/interop_client.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_interop_client.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/interop/stress_test.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc +$(OBJDIR)/$(CONFIG)/test/cpp/util/create_test_channel.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc $(OBJDIR)/$(CONFIG)/test/cpp/util/metrics_server.o: $(GENDIR)/src/proto/grpc/testing/empty.pb.cc $(GENDIR)/src/proto/grpc/testing/empty.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.pb.cc $(GENDIR)/src/proto/grpc/testing/messages.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.pb.cc $(GENDIR)/src/proto/grpc/testing/metrics.grpc.pb.cc $(GENDIR)/src/proto/grpc/testing/test.pb.cc $(GENDIR)/src/proto/grpc/testing/test.grpc.pb.cc diff --git a/build.yaml b/build.yaml index 1072bfcb630..f367dc7ed16 100644 --- a/build.yaml +++ b/build.yaml @@ -3648,16 +3648,17 @@ targets: - test/cpp/interop/client_helper.h - test/cpp/interop/interop_client.h - test/cpp/interop/stress_interop_client.h + - test/cpp/util/create_test_channel.h - test/cpp/util/metrics_server.h src: - src/proto/grpc/testing/empty.proto - src/proto/grpc/testing/messages.proto - src/proto/grpc/testing/metrics.proto - src/proto/grpc/testing/test.proto - - test/cpp/interop/client_helper.cc - test/cpp/interop/interop_client.cc - test/cpp/interop/stress_interop_client.cc - test/cpp/interop/stress_test.cc + - test/cpp/util/create_test_channel.cc - test/cpp/util/metrics_server.cc deps: - grpc++_test_util diff --git a/test/cpp/interop/stress_test.cc b/test/cpp/interop/stress_test.cc index 562522de779..fdc0a613f37 100644 --- a/test/cpp/interop/stress_test.cc +++ b/test/cpp/interop/stress_test.cc @@ -45,9 +45,9 @@ #include "src/proto/grpc/testing/metrics.grpc.pb.h" #include "src/proto/grpc/testing/metrics.pb.h" -#include "test/cpp/interop/client_helper.h" #include "test/cpp/interop/interop_client.h" #include "test/cpp/interop/stress_interop_client.h" +#include "test/cpp/util/create_test_channel.h" #include "test/cpp/util/metrics_server.h" #include "test/cpp/util/test_config.h" @@ -67,9 +67,7 @@ DEFINE_int32(test_duration_secs, -1, " forcefully terminated."); DEFINE_string(server_addresses, "localhost:8080", - "The list of server" - "addresses. This option is ignored if either\n" - "server_port or server_host is specified. The format is: \n" + "The list of server addresses. The format is: \n" " \":,:...:\"\n" " Note: can be servername or IP address."); @@ -80,34 +78,6 @@ DEFINE_int32(num_stubs_per_channel, 1, "indicates the max number of parallel RPC calls on each channel " "at any given time."); -DEFINE_string(test_case, "", - "Configure different test cases. Valid options are:\n\n" - "all : all test cases;\n" - "cancel_after_begin : cancel stream after starting it;\n" - "cancel_after_first_response: cancel on first response;\n" - "client_compressed_streaming : compressed request streaming with " - "client_compressed_unary : single compressed request;\n" - "client_streaming : request streaming with single response;\n" - "compute_engine_creds: large_unary with compute engine auth;\n" - "custom_metadata: server will echo custom metadata;\n" - "empty_stream : bi-di stream with no request/response;\n" - "empty_unary : empty (zero bytes) request and response;\n" - "half_duplex : half-duplex streaming;\n" - "jwt_token_creds: large_unary with JWT token auth;\n" - "large_unary : single request and (large) response;\n" - "oauth2_auth_token: raw oauth2 access token auth;\n" - "per_rpc_creds: raw oauth2 access token on a single rpc;\n" - "ping_pong : full-duplex streaming;\n" - "response streaming;\n" - "server_compressed_streaming : single request with compressed " - "server_compressed_unary : single compressed response;\n" - "server_streaming : single request with response streaming;\n" - "slow_consumer : single request with response streaming with " - "slow client consumer;\n" - "status_code_and_message: verify status code & message;\n" - "timeout_on_sleeping_server: deadline exceeds on stream;\n" - "unimplemented_method: client calls an unimplemented_method;\n"); - // TODO(sreek): Add more test cases here in future DEFINE_string(test_cases, "", "List of test cases to call along with the" @@ -147,14 +117,9 @@ DEFINE_bool(do_not_abort_on_transient_failures, true, // Options from client.cc (for compatibility with interop test). // TODO(sreek): Consolidate overlapping options DEFINE_bool(use_tls, false, "Whether to use tls."); -DEFINE_string(custom_credentials_type, "", "User provided credentials type."); DEFINE_bool(use_test_ca, false, "False to use SSL roots for google"); -DEFINE_int32(server_port, 0, "Server port."); -DEFINE_string(server_host, "127.0.0.1", "Server host to connect to"); DEFINE_string(server_host_override, "foo.test.google.fr", "Override the server host which is sent in HTTP header"); -DEFINE_string(service_account_key_file, "", - "Path to service account json key file."); using grpc::testing::kTestCaseList; using grpc::testing::MetricsService; @@ -241,8 +206,6 @@ bool ParseTestCasesString(const grpc::string& test_cases, void LogParameterInfo(const std::vector& addresses, const std::vector>& tests) { gpr_log(GPR_INFO, "server_addresses: %s", FLAGS_server_addresses.c_str()); - gpr_log(GPR_INFO, "server_host: %s", FLAGS_server_host.c_str()); - gpr_log(GPR_INFO, "server_port: %d", FLAGS_server_port); gpr_log(GPR_INFO, "test_cases : %s", FLAGS_test_cases.c_str()); gpr_log(GPR_INFO, "sleep_duration_ms: %d", FLAGS_sleep_duration_ms); gpr_log(GPR_INFO, "test_duration_secs: %d", FLAGS_test_duration_secs); @@ -286,24 +249,11 @@ int main(int argc, char** argv) { // Parse the server addresses std::vector server_addresses; - if (FLAGS_server_port != 0) { - // We are using interop_client style cmdline options. - const int host_port_buf_size = 1024; - char host_port[host_port_buf_size]; - snprintf(host_port, host_port_buf_size, "%s:%d", FLAGS_server_host.c_str(), - FLAGS_server_port); - std::string host_port_str(host_port); - ParseCommaDelimitedString(host_port_str, server_addresses); - } else { - ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); - } + ParseCommaDelimitedString(FLAGS_server_addresses, server_addresses); // Parse test cases and weights if (FLAGS_test_cases.length() == 0) { - // We are using interop_client style test_case option - FLAGS_test_cases = FLAGS_test_case + ":100"; - } else if (FLAGS_test_case != "") { - gpr_log(GPR_ERROR, "specify --test_case or --test_cases but not both."); + gpr_log(GPR_ERROR, "No test cases supplied"); return 1; } @@ -341,12 +291,8 @@ int main(int argc, char** argv) { channel_idx++) { gpr_log(GPR_INFO, "Starting test with %s channel_idx=%d..", it->c_str(), channel_idx); - std::shared_ptr channel; - if (FLAGS_use_tls) { - channel = grpc::testing::CreateChannelForTestCase(FLAGS_test_case); - } else { - channel = grpc::CreateChannel(*it, grpc::InsecureChannelCredentials()); - } + std::shared_ptr channel = grpc::CreateTestChannel( + *it, FLAGS_server_host_override, FLAGS_use_tls, !FLAGS_use_test_ca); // Create stub(s) for each channel for (int stub_idx = 0; stub_idx < FLAGS_num_stubs_per_channel; diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index 1a3345cb957..7c520c4eb12 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3370,19 +3370,21 @@ "test/cpp/interop/client_helper.h", "test/cpp/interop/interop_client.h", "test/cpp/interop/stress_interop_client.h", + "test/cpp/util/create_test_channel.h", "test/cpp/util/metrics_server.h" ], "is_filegroup": false, "language": "c++", "name": "stress_test", "src": [ - "test/cpp/interop/client_helper.cc", "test/cpp/interop/client_helper.h", "test/cpp/interop/interop_client.cc", "test/cpp/interop/interop_client.h", "test/cpp/interop/stress_interop_client.cc", "test/cpp/interop/stress_interop_client.h", "test/cpp/interop/stress_test.cc", + "test/cpp/util/create_test_channel.cc", + "test/cpp/util/create_test_channel.h", "test/cpp/util/metrics_server.cc", "test/cpp/util/metrics_server.h" ], diff --git a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj index 8e1b6bb3a66..fed916f50a9 100644 --- a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj +++ b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj @@ -163,6 +163,7 @@ + @@ -198,14 +199,14 @@ - - + + diff --git a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters index 476c04ec956..9339621c8d1 100644 --- a/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/stress_test/stress_test.vcxproj.filters @@ -13,9 +13,6 @@ src\proto\grpc\testing - - test\cpp\interop - test\cpp\interop @@ -25,6 +22,9 @@ test\cpp\interop + + test\cpp\util + test\cpp\util @@ -39,6 +39,9 @@ test\cpp\interop + + test\cpp\util + test\cpp\util From 8ebedd11df4837ec6be377f009817e3d5870cac9 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Jan 2017 19:55:42 +0100 Subject: [PATCH 226/261] Improve docs on windows building --- INSTALL.md | 74 ++++++++++++++++++-------------------- vsprojects/README.md | 85 ++++++++------------------------------------ 2 files changed, 50 insertions(+), 109 deletions(-) diff --git a/INSTALL.md b/INSTALL.md index 686145566fa..24f088ea492 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -61,49 +61,45 @@ gRPC C Core library. There are several ways to build under Windows, of varying complexity depending on experience with the tools involved. - +###msys2 (with mingw) -###msys2 +The Makefile (and source code) should support msys2's mingw32 and mingw64 +compilers. Building with msys2's native compiler is also possible, but +difficult. This approach requires having [msys2](https://msys2.github.io/) installed. + +``` +# Install prerequisites +MSYS2$ pacman -S autoconf automake gcc libtool mingw-w64-x86_64-toolchain perl pkg-config zlib +MSYS2$ pacman -S mingw-w64-x86_64-gflags +``` -- The Makefile (and source code) should support msys2's mingw32 and mingw64 - compilers. Building with msys2's native compiler is also possible, but - difficult. -- The Makefile is expecting the Windows versions of OpenSSL (see - https://slproweb.com/products/Win32OpenSSL.html). It's also possible to build - the Windows version of OpenSSL from scratch. The output should be `libeay32` - and `ssleay32`. -- If you are not installing the above files under msys2's path, you may specify - it, for instance, in the following way: - ```CPPFLAGS=”-I/c/OpenSSL-Win32/include” LDFLAGS=”-L/c/OpenSSL-Win32/lib” make static_c``` -- [protobuf3](https://github.com/google/protobuf/blob/master/src/README.md#c-installation---windows) - must be installed on the msys2 path. - -###Cmake (experimental) +``` +# From mingw shell +MINGW64$ export CPPFLAGS="-D_WIN32_WINNT=0x0600" +MINGW64$ make +``` -- Install [CMake](https://cmake.org/download/). -- Run it over [grpc's - CMakeLists.txt](https://github.com/grpc/grpc/blob/master/CMakeLists.txt) to - generate "projects" for your compiler. -- Build with your compiler of choice. The generated build files should have the - protobuf3 dependency baked in. +NOTE: While most of the make targets are buildable under Mingw, some haven't been ported to Windows yet +and may fail to build (mostly trying to include POSIX headers not available on Mingw). diff --git a/vsprojects/README.md b/vsprojects/README.md index afd6430bfe5..f1663d25485 100644 --- a/vsprojects/README.md +++ b/vsprojects/README.md @@ -1,8 +1,8 @@ -This directory contains MS Visual Studio project & solution files. +#Pre-generated MS Visual Studio project & solution files -#Supported Visual Studio versions - -Currently supported versions are Visual Studio 2013 (our primary focus). +Versions 2013 and 2015 are both supported. You can use [their respective +community +editions](https://www.visualstudio.com/en-us/downloads/download-visual-studio-vs.aspx). #Building We are using [NuGet](http://www.nuget.org) to pull zlib and openssl dependencies. @@ -16,8 +16,8 @@ download nuget.exe from the web and manually restore the NuGet packages. ``` After that, you can build the solution using one of these options: -1. open `grpc.sln` with Visual Studio and hit "Build". -2. build from commandline using `msbuild grpc.sln /p:Configuration=Debug` + 1. open `grpc.sln` with Visual Studio and hit "Build". + 2. build from commandline using `msbuild grpc.sln /p:Configuration=Debug` #C/C++ Test Dependencies * gtest isn't available as a git repo like the other dependencies. download it and add it to `/third_party/gtest/` (the folder will end up with `/build-aux/`, `/cmake/`, `/codegear/`, etc. folders in it). @@ -36,73 +36,18 @@ After that, you can build the solution using one of these options: * install [NuGet](http://www.nuget.org) * nuget should automatically bring in built versions of zlib and openssl when building grpc.sln (the versions in `/third_party/` are not used). If it doesn't work use `tools->nuget...->manage...`. The packages are put in `/vsprojects/packages/` -#C/C++ Test Solution/Project Build Steps - * A basic git version of grpc only has templates for non-test items. This checklist adds test items to grpc.sln and makes individual vs projects for them - * set up dependencies (above) - * add `"debug": true,` to the top of build.json. This is the base file for all build tracking, see [templates](https://github.com/grpc/grpc/tree/master/templates) for more information - * `"debug": true,` gets picked up by `/tools/buildgen/plugins/generate_vsprojects.py`. It tells the script to add visual studio GUIDs to all projects. Otherwise only the projects that already have GUIDs in build.json will be built - * run `/templates/vsprojects/generate_debug_projects.sh` to make debug templates/projects. This runs a regular visual studio buildgen process, which creates the `.sln` file with all of the new debug projects, then uses git diff to find the new project names from the `.sln` that need templates added. It builds the new templates based on the diff, then re-runs the visual studio buildgen, which builds the vs projects for each of the new debug targets - * copy over the `/vsprojects/` folder to your windows build setup (assuming this was built on linux in order to have easy access to python/mako and shell scripts) - * run `/templates/vsprojects/build_test_protos.sh` - * this builds all `.proto` files in `/test/` in-place. there might be a better place to put them that mirrors what happens in the linux build process (todo) - * each `.proto` file gets built into a `.grpc.pb.cc`, .`grpc.pb.h`, `.pb.cc`, and `.pb.h`. These are included in each test project in lieu of the `.proto` includes specified in `build.json`. This substitution is done by `/templates/vsprojects/vcxproj_defs.include` - * copy over the `/test/` folder in order to get the new files (assuming this was built on linux in order to have an easy protobuf+grpc plugin installation) - -#Making and running tests with `/tools/run_tests/run_tests.py` or `/vsprojects/make.bat` -`run_tests.py` and `make.bat` both rely on `/vsprojects/grpc.mak`, an NMAKE script that includes C/C++ tests in addition to the base grpc projects. It builds the base projects by calling grpc.sln, but most things are built with a command line similar to a makefile workflow. - - arguments for `/vsprojects/make.bat`: - - * no options or `all` or `buildtests`: builds all tests - * `buildtests_c`: just c tests - * `buildtests_cxx`: just c++ tests - * names of individual tests: just those tests (example: `make.bat gpr_string_test`) - -using `run_tests.py` on windows: - - * when `run_tests.py` detects that it's running on windows it calls `make.bat` to build the tests and expects to find tests in `/vsprojects/test_bins/` - -`run_tests.py` options: - - * `run_tests.py --help` - * `run_tests.py -l c`: run c language tests - * `run_tests.py -l c++`: run c++ language tests - * note: `run_tests.py` doesn't normally show build steps, so if a build fails it is best to fall back to `make.bat` - * if `make.bat` fails, it might be easier to open up the `.sln` file in the visual studio gui (see above for how to build the test projects) and build the offending test from its project file. The `.mak` and project file templates are slightly different, so it's possible that a project will build one way and not another. Please report this if it happens. - -It can be helpful to disable the firewall when running tests so that 400 connection warnings don't pop up. - -Individual tests can be run by directly running the executable in `/vsprojects/run_tests/` (this is `/bins/opt/` on linux). Many C tests have no output; they either pass or fail internally and communicate this with their exit code (`0=pass`, `nonzero=fail`) - -`run_tests.py` will fail if it can't build something, so not-building tests are disabled with a "platforms = posix" note in build.json. The buildgen tools will not add a test to a windows build unless it is marked "windows" or has no platforms identified. As tests are ported they will get this mark removed. - # Building protoc plugins For generating service stub code, gRPC relies on plugins for `protoc` (the protocol buffer compiler). The solution `grpc_protoc_plugins.sln` allows you to build Windows .exe binaries of gRPC protoc plugins. -1. Follow instructions in `third_party\protobuf\cmake\README.md` to create Visual Studio 2013 projects for protobuf. -``` -$ cd third_party/protobuf/cmake -$ mkdir build & cd build -$ mkdir solution & cd solution -$ cmake -G "Visual Studio 12 2013" -Dprotobuf_BUILD_TESTS=OFF ../.. -``` - -2. Open solution `third_party\protobuf\cmake\build\solution\protobuf.sln` and build it in Release mode. That will build libraries `libprotobuf.lib` and `libprotoc.lib` needed for the next step. +- Follow instructions in `third_party\protobuf\cmake\README.md` to create Visual Studio 2013 projects for protobuf. + ``` + $ cd third_party/protobuf/cmake + $ mkdir build & cd build + $ mkdir solution & cd solution + $ cmake -G "Visual Studio 12 2013" -Dprotobuf_BUILD_TESTS=OFF ../.. + ``` -3. Open solution `vsprojects\grpc_protoc_plugins.sln` and build it in Release mode. As a result, you should obtain a set of gRPC protoc plugin binaries (`grpc_cpp_plugin.exe`, `grpc_csharp_plugin.exe`, ...) +- Open solution `third_party\protobuf\cmake\build\solution\protobuf.sln` and build it in Release mode. That will build libraries `libprotobuf.lib` and `libprotoc.lib` needed for the next step. -#Building using CMake (with BoringSSL) -1. Install [Active State Perl](http://www.activestate.com/activeperl/) (`choco install activeperl`) -2. Install [Ninja](https://ninja-build.org/) (`choco install ninja`) -2. Install [Go](https://golang.org/dl/) (`choco install golang`) -3. Install [yasm](http://yasm.tortall.net/) and add it to `PATH` (`choco install yasm`) -4. Update boringssl sumbodule to `master` -5. Run this commads in grpc directory: -``` -> md .build -> cd .build -> call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64 -> cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -> cmake --build . -``` +- Open solution `vsprojects\grpc_protoc_plugins.sln` and build it in Release mode. As a result, you should obtain a set of gRPC protoc plugin binaries (`grpc_cpp_plugin.exe`, `grpc_csharp_plugin.exe`, ...) From 015f9b18ef5158c980f4d83edf03689b1889a057 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Jan 2017 20:27:04 +0100 Subject: [PATCH 227/261] Delete generate_debug_projects.sh --- .../vsprojects/generate_debug_projects.sh | 76 ------------------- 1 file changed, 76 deletions(-) delete mode 100755 templates/vsprojects/generate_debug_projects.sh diff --git a/templates/vsprojects/generate_debug_projects.sh b/templates/vsprojects/generate_debug_projects.sh deleted file mode 100755 index f103ebe01a9..00000000000 --- a/templates/vsprojects/generate_debug_projects.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh - -# 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. - -# To properly use this, you'll need to add: -# -# "debug": true -# -# to build.json - -cd `dirname $0`/../.. - -git add . #because we're using "git diff" to find changes to grpc.sln and then make files based on those changes, this prevents this file or other files from possibly being found in the diff - -./tools/buildgen/generate_projects-old.sh - -line_number=0 - -git diff | -grep -A2 \\+Project | #find "Project" immediately after a backslash (escaped), plus 2 additional lines to capture the "libs = ", plus 1 line of "--". matches will come from the generated grpc.sln -while read p ; do - line_number=$((line_number + 1)) - if [ "$line_number" -gt "4" ]; then - line_number=1; - fi - echo $line_number - echo $p - if [ "$line_number" -eq "1" ]; then - project_name=$(echo "$p" | cut -d\" -f 4) #sed: extract line N only; cut with delimiter: ". select only field 4 - fi - if [ "$line_number" -eq "3" ]; then - lib_setting=$(echo "$p" | cut -d\" -f 2) # - echo "project_name" - echo $project_name - echo "lib_setting" - echo $lib_setting - mkdir -p templates/vsprojects/$project_name - if [ "$lib_setting" = "True" ]; then - echo "lib: true" - echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$project_name'", libs)}' > templates/vsprojects/$project_name/$project_name.vcxproj.template - else - echo "lib: not true" - echo '<%namespace file="../vcxproj_defs.include" import="gen_project"/>${gen_project("'$project_name'", targets)}' > templates/vsprojects/$project_name/$project_name.vcxproj.template - fi - fi - # sleep .5 #for testing -done - -./tools/buildgen/generate_projects-old.sh From 2a8af018ca25fafcb19efe13ed7ecb71369c04f0 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Mon, 16 Jan 2017 20:27:53 +0100 Subject: [PATCH 228/261] Delete generate_projects-old.sh --- tools/buildgen/generate_projects-old.sh | 76 ------------------------- 1 file changed, 76 deletions(-) delete mode 100644 tools/buildgen/generate_projects-old.sh diff --git a/tools/buildgen/generate_projects-old.sh b/tools/buildgen/generate_projects-old.sh deleted file mode 100644 index 55d93d4942b..00000000000 --- a/tools/buildgen/generate_projects-old.sh +++ /dev/null @@ -1,76 +0,0 @@ -#!/bin/sh -# 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. - - -set -e - -if [ "x$TEST" = "x" ] ; then - TEST=false -fi - - -cd `dirname $0`/../.. -mako_renderer=tools/buildgen/mako_renderer.py - -if [ "x$TEST" != "x" ] ; then - tools/buildgen/build-cleaner.py build.yaml -fi - -. tools/buildgen/generate_build_additions.sh - -global_plugins=`find ./tools/buildgen/plugins -name '*.py' | - sort | grep -v __init__ | awk ' { printf "-p %s ", $0 } '` - -for dir in . ; do - local_plugins=`find $dir/templates -name '*.py' | - sort | grep -v __init__ | awk ' { printf "-p %s ", $0 } '` - - plugins="$global_plugins $local_plugins" - - find -L $dir/templates -type f -and -name *.template | while read file ; do - out=${dir}/${file#$dir/templates/} # strip templates dir prefix - out=${out%.*} # strip template extension - echo "generating file: $out" - yaml_files="build.yaml $gen_build_files" - data=`for i in $yaml_files ; do echo $i ; done | awk ' { printf "-d %s ", $0 } '` - if [ "x$TEST" = "xtrue" ] ; then - actual_out=$out - out=`mktemp /tmp/gentXXXXXX` - fi - mkdir -p `dirname $out` # make sure dest directory exist - $mako_renderer $plugins $data -o $out $file - if [ "x$TEST" = "xtrue" ] ; then - diff -q $out $actual_out - rm $out - fi - done -done - -rm $gen_build_files From b595c172bf03b5f2cab9aaba5e3dc1994a9d0f39 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 19 Jan 2017 09:50:23 +0100 Subject: [PATCH 229/261] fix sanity --- tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile index 03ff179f718..05e963d1e67 100644 --- a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile @@ -46,7 +46,6 @@ RUN apt-get update && apt-get install -y \ RUN pip install pip --upgrade RUN pip install virtualenv RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 -RUN pip install twisted h2 # Define the default command. CMD ["bash"] From 0a1701f17b47cd5187ad83e6508303920e8b888a Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Jan 2017 19:44:08 +0100 Subject: [PATCH 230/261] enable building of tests with cmake --- templates/CMakeLists.txt.template | 61 +++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 3 deletions(-) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 7868d412290..20c1b2797d7 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -65,6 +65,8 @@ deps.append("${_gRPC_ZLIB_LIBRARIES}") for d in target_dict.get('deps', []): deps.append(d) + if target_dict.build == 'test' and target_dict.language == 'c++': + deps.append("${_gRPC_GFLAGS_LIBRARIES}") return deps %> @@ -76,6 +78,9 @@ set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") project(<%text>${PACKAGE_NAME} C CXX) + + # Options + option(gRPC_BUILD_TESTS "Build tests" OFF) if (NOT MSVC) set(gRPC_INSTALL ON CACHE BOOL "Generate installation target") @@ -91,7 +96,10 @@ set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library") set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package") - + + set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library") + set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package") + set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library") if (MSVC) @@ -195,6 +203,26 @@ endif() set(_gRPC_FIND_SSL "if(NOT OpenSSL_FOUND)\n find_package(OpenSSL)\nendif()") endif() + + if("<%text>${gRPC_GFLAGS_PROVIDER}" STREQUAL "module") + if(NOT GFLAGS_ROOT_DIR) + set(GFLAGS_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}/third_party/gflags) + endif() + if(EXISTS "<%text>${GFLAGS_ROOT_DIR}/CMakeLists.txt") + add_subdirectory(<%text>${GFLAGS_ROOT_DIR} third_party/gflags) + if(TARGET gflags-static) + set(_gRPC_GFLAGS_LIBRARIES gflags-static) + endif() + else() + message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") + endif() + elseif("<%text>${gRPC_GFLAGS_PROVIDER}" STREQUAL "package") + find_package(gflags) + if(TARGET gflags::gflags) + set(_gRPC_GFLAGS_LIBRARIES gflags::gflags) + endif() + set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags)\nendif()") + endif() if(NOT MSVC) set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS} -std=c11") @@ -260,17 +288,31 @@ endfunction() % for lib in libs: - % if lib.build in ["all", "protoc", "tool"] and lib.language in ['c', 'c++']: + % if lib.build in ["all", "protoc", "tool", "test", "private"] and lib.language in ['c', 'c++']: + % if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []): + % if lib.build in ["test", "private"]: + if (gRPC_BUILD_TESTS) + ${cc_library(lib)} + endif (gRPC_BUILD_TESTS) + % else: ${cc_library(lib)} ${cc_install(lib)} % endif + % endif + % endif % endfor % for tgt in targets: - % if tgt.build in ["all", "protoc", "tool"] and tgt.language in ['c', 'c++']: + % if tgt.build in ["all", "protoc", "tool", "test", "private"] and tgt.language in ['c', 'c++']: + % if tgt.build in ["test", "private"]: + if (gRPC_BUILD_TESTS) + ${cc_binary(tgt)} + endif (gRPC_BUILD_TESTS) + % else: ${cc_binary(tgt)} ${cc_install(tgt)} % endif + % endif % endfor <%def name="cc_library(lib)"> @@ -302,6 +344,11 @@ PRIVATE <%text>${PROTOBUF_ROOT_DIR}/src PRIVATE <%text>${ZLIB_INCLUDE_DIR} PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + % if lib.build in ['test', 'private'] and lib.language == 'c++': + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + % endif % if any(proto_re.match(src) for src in lib.src): PRIVATE <%text>${_gRPC_PROTO_GENS_DIR} % endif @@ -335,6 +382,9 @@ % for src in tgt.src: ${src} % endfor + % if tgt.build == 'test' and tgt.language == 'c++': + third_party/googletest/src/gtest-all.cc + % endif ) target_include_directories(${tgt.name} @@ -344,6 +394,11 @@ PRIVATE <%text>${PROTOBUF_ROOT_DIR}/src PRIVATE <%text>${ZLIB_ROOT_DIR} PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + % if tgt.build in ['test', 'private'] and tgt.language == 'c++': + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + % endif ) % if len(get_deps(tgt)) > 0: From 1985a6273ffe00215f082fc7ef3a27005f9c434c Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 18 Jan 2017 15:21:54 +0100 Subject: [PATCH 231/261] upgrade third_party/gflags to v2.2.0 --- third_party/gflags | 2 +- tools/run_tests/sanity/check_submodules.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/third_party/gflags b/third_party/gflags index 05b155ff591..f8a0efe03aa 160000 --- a/third_party/gflags +++ b/third_party/gflags @@ -1 +1 @@ -Subproject commit 05b155ff59114735ec8cd089f669c4c3d8f59029 +Subproject commit f8a0efe03aa69b3336d8e228b37d4ccb17324b88 diff --git a/tools/run_tests/sanity/check_submodules.sh b/tools/run_tests/sanity/check_submodules.sh index 61e8185854b..a484b26716e 100755 --- a/tools/run_tests/sanity/check_submodules.sh +++ b/tools/run_tests/sanity/check_submodules.sh @@ -44,7 +44,7 @@ cat << EOF | awk '{ print $1 }' | sort > $want_submodules 44c25c892a6229b20db7cd9dc05584ea865896de third_party/benchmark (v0.1.0-343-g44c25c8) c880e42ba1c8032d4cdde2aba0541d8a9d9fa2e9 third_party/boringssl (c880e42) 886e7d75368e3f4fab3f4d0d3584e4abfc557755 third_party/boringssl-with-bazel (version_for_cocoapods_7.0-857-g886e7d7) - 05b155ff59114735ec8cd089f669c4c3d8f59029 third_party/gflags (v2.1.0-45-g05b155f) + f8a0efe03aa69b3336d8e228b37d4ccb17324b88 third_party/gflags (v2.2.0) c99458533a9b4c743ed51537e25989ea55944908 third_party/googletest (release-1.7.0) a428e42072765993ff674fda72863c9f1aa2d268 third_party/protobuf (v3.1.0-alpha-1) bcad91771b7f0bff28a1cac1981d7ef2b9bcef3c third_party/thrift (bcad917) From 87a5d655882059439e69f304488f0b29e92ff7e3 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 18 Jan 2017 16:22:40 +0100 Subject: [PATCH 232/261] gflags library target renamed in v2.2.0 --- templates/CMakeLists.txt.template | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 20c1b2797d7..a326f36fe93 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -210,8 +210,8 @@ endif() if(EXISTS "<%text>${GFLAGS_ROOT_DIR}/CMakeLists.txt") add_subdirectory(<%text>${GFLAGS_ROOT_DIR} third_party/gflags) - if(TARGET gflags-static) - set(_gRPC_GFLAGS_LIBRARIES gflags-static) + if(TARGET gflags_static) + set(_gRPC_GFLAGS_LIBRARIES gflags_static) endif() else() message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") From 36cda4c3fa446ffa8c1f09b1ff1cfd27897ff6ca Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Tue, 17 Jan 2017 20:00:12 +0100 Subject: [PATCH 233/261] regenerate --- CMakeLists.txt | 9705 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 9523 insertions(+), 182 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cce0528defe..c5a1927c92e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,9 @@ set(PACKAGE_TARNAME "${PACKAGE_NAME}-${PACKAGE_VERSION}") set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") project(${PACKAGE_NAME} C CXX) +# Options +option(gRPC_BUILD_TESTS "Build tests" OFF) + if (NOT MSVC) set(gRPC_INSTALL ON CACHE BOOL "Generate installation target") else() @@ -63,6 +66,9 @@ set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package") set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library") set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package") +set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library") +set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package") + set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library") if (MSVC) @@ -167,6 +173,26 @@ elseif("${gRPC_SSL_PROVIDER}" STREQUAL "package") set(_gRPC_FIND_SSL "if(NOT OpenSSL_FOUND)\n find_package(OpenSSL)\nendif()") endif() +if("${gRPC_GFLAGS_PROVIDER}" STREQUAL "module") + if(NOT GFLAGS_ROOT_DIR) + set(GFLAGS_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/gflags) + endif() + if(EXISTS "${GFLAGS_ROOT_DIR}/CMakeLists.txt") + add_subdirectory(${GFLAGS_ROOT_DIR} third_party/gflags) + if(TARGET gflags_static) + set(_gRPC_GFLAGS_LIBRARIES gflags_static) + endif() + else() + message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") + endif() +elseif("${gRPC_GFLAGS_PROVIDER}" STREQUAL "package") + find_package(gflags) + if(TARGET gflags::gflags) + set(_gRPC_GFLAGS_LIBRARIES gflags::gflags) + endif() + set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags)\nendif()") +endif() + if(NOT MSVC) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11") @@ -286,6 +312,7 @@ target_include_directories(gpr PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) @@ -345,6 +372,29 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(gpr_test_util + test/core/util/test_config.c +) + + +target_include_directories(gpr_test_util + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) add_library(grpc src/core/lib/surface/init.c @@ -574,6 +624,7 @@ target_include_directories(grpc PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc @@ -831,6 +882,7 @@ target_include_directories(grpc_cronet PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc_cronet @@ -887,6 +939,240 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(grpc_test_util + test/core/end2end/data/client_certs.c + test/core/end2end/data/server1_cert.c + test/core/end2end/data/server1_key.c + test/core/end2end/data/test_root_cert.c + test/core/security/oauth2_utils.c + test/core/end2end/cq_verifier.c + test/core/end2end/fake_resolver.c + test/core/end2end/fixtures/http_proxy.c + test/core/end2end/fixtures/proxy.c + test/core/iomgr/endpoint_tests.c + test/core/util/grpc_profiler.c + test/core/util/memory_counters.c + test/core/util/mock_endpoint.c + test/core/util/parse_hexstring.c + test/core/util/passthru_endpoint.c + test/core/util/port_posix.c + test/core/util/port_server_client.c + test/core/util/port_uv.c + test/core/util/port_windows.c + test/core/util/slice_splitter.c + src/core/lib/channel/channel_args.c + src/core/lib/channel/channel_stack.c + src/core/lib/channel/channel_stack_builder.c + src/core/lib/channel/compress_filter.c + src/core/lib/channel/connected_channel.c + src/core/lib/channel/deadline_filter.c + src/core/lib/channel/handshaker.c + src/core/lib/channel/handshaker_factory.c + src/core/lib/channel/handshaker_registry.c + src/core/lib/channel/http_client_filter.c + src/core/lib/channel/http_server_filter.c + src/core/lib/channel/message_size_filter.c + src/core/lib/compression/compression.c + src/core/lib/compression/message_compress.c + src/core/lib/debug/trace.c + src/core/lib/http/format_request.c + src/core/lib/http/httpcli.c + src/core/lib/http/parser.c + src/core/lib/iomgr/closure.c + src/core/lib/iomgr/combiner.c + src/core/lib/iomgr/endpoint.c + src/core/lib/iomgr/endpoint_pair_posix.c + src/core/lib/iomgr/endpoint_pair_uv.c + src/core/lib/iomgr/endpoint_pair_windows.c + src/core/lib/iomgr/error.c + src/core/lib/iomgr/ev_epoll_linux.c + src/core/lib/iomgr/ev_poll_posix.c + src/core/lib/iomgr/ev_posix.c + src/core/lib/iomgr/exec_ctx.c + src/core/lib/iomgr/executor.c + src/core/lib/iomgr/iocp_windows.c + src/core/lib/iomgr/iomgr.c + src/core/lib/iomgr/iomgr_posix.c + src/core/lib/iomgr/iomgr_uv.c + src/core/lib/iomgr/iomgr_windows.c + src/core/lib/iomgr/load_file.c + src/core/lib/iomgr/network_status_tracker.c + src/core/lib/iomgr/polling_entity.c + src/core/lib/iomgr/pollset_set_uv.c + src/core/lib/iomgr/pollset_set_windows.c + src/core/lib/iomgr/pollset_uv.c + src/core/lib/iomgr/pollset_windows.c + src/core/lib/iomgr/resolve_address_posix.c + src/core/lib/iomgr/resolve_address_uv.c + src/core/lib/iomgr/resolve_address_windows.c + src/core/lib/iomgr/resource_quota.c + src/core/lib/iomgr/sockaddr_utils.c + src/core/lib/iomgr/socket_mutator.c + src/core/lib/iomgr/socket_utils_common_posix.c + src/core/lib/iomgr/socket_utils_linux.c + src/core/lib/iomgr/socket_utils_posix.c + src/core/lib/iomgr/socket_utils_uv.c + src/core/lib/iomgr/socket_utils_windows.c + src/core/lib/iomgr/socket_windows.c + src/core/lib/iomgr/tcp_client_posix.c + src/core/lib/iomgr/tcp_client_uv.c + src/core/lib/iomgr/tcp_client_windows.c + src/core/lib/iomgr/tcp_posix.c + src/core/lib/iomgr/tcp_server_posix.c + src/core/lib/iomgr/tcp_server_uv.c + src/core/lib/iomgr/tcp_server_windows.c + src/core/lib/iomgr/tcp_uv.c + src/core/lib/iomgr/tcp_windows.c + src/core/lib/iomgr/time_averaged_stats.c + src/core/lib/iomgr/timer_generic.c + src/core/lib/iomgr/timer_heap.c + src/core/lib/iomgr/timer_uv.c + src/core/lib/iomgr/udp_server.c + src/core/lib/iomgr/unix_sockets_posix.c + src/core/lib/iomgr/unix_sockets_posix_noop.c + src/core/lib/iomgr/wakeup_fd_cv.c + src/core/lib/iomgr/wakeup_fd_eventfd.c + src/core/lib/iomgr/wakeup_fd_nospecial.c + src/core/lib/iomgr/wakeup_fd_pipe.c + src/core/lib/iomgr/wakeup_fd_posix.c + src/core/lib/iomgr/workqueue_uv.c + src/core/lib/iomgr/workqueue_windows.c + src/core/lib/json/json.c + src/core/lib/json/json_reader.c + src/core/lib/json/json_string.c + src/core/lib/json/json_writer.c + src/core/lib/slice/percent_encoding.c + src/core/lib/slice/slice.c + src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_string_helpers.c + src/core/lib/surface/alarm.c + src/core/lib/surface/api_trace.c + src/core/lib/surface/byte_buffer.c + src/core/lib/surface/byte_buffer_reader.c + src/core/lib/surface/call.c + src/core/lib/surface/call_details.c + src/core/lib/surface/call_log_batch.c + src/core/lib/surface/channel.c + src/core/lib/surface/channel_init.c + src/core/lib/surface/channel_ping.c + src/core/lib/surface/channel_stack_type.c + src/core/lib/surface/completion_queue.c + src/core/lib/surface/event_string.c + src/core/lib/surface/lame_client.c + src/core/lib/surface/metadata_array.c + src/core/lib/surface/server.c + src/core/lib/surface/validate_metadata.c + src/core/lib/surface/version.c + src/core/lib/transport/byte_stream.c + 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/pid_controller.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 + src/core/lib/transport/transport_op_string.c +) + + +target_include_directories(grpc_test_util + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_test_util + gpr_test_util + gpr + grpc +) + +foreach(_hdr + include/grpc/byte_buffer.h + include/grpc/byte_buffer_reader.h + include/grpc/compression.h + include/grpc/grpc.h + include/grpc/grpc_posix.h + include/grpc/grpc_security_constants.h + include/grpc/slice.h + include/grpc/slice_buffer.h + include/grpc/status.h + include/grpc/impl/codegen/byte_buffer_reader.h + include/grpc/impl/codegen/compression_types.h + include/grpc/impl/codegen/connectivity_state.h + include/grpc/impl/codegen/exec_ctx_fwd.h + include/grpc/impl/codegen/grpc_types.h + include/grpc/impl/codegen/propagation_bits.h + include/grpc/impl/codegen/status.h + include/grpc/impl/codegen/atm.h + include/grpc/impl/codegen/atm_gcc_atomic.h + include/grpc/impl/codegen/atm_gcc_sync.h + include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h + include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/port_platform.h + include/grpc/impl/codegen/slice.h + include/grpc/impl/codegen/sync.h + include/grpc/impl/codegen/sync_generic.h + include/grpc/impl/codegen/sync_posix.h + include/grpc/impl/codegen/sync_windows.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(grpc_test_util_unsecure + test/core/end2end/cq_verifier.c + test/core/end2end/fake_resolver.c + test/core/end2end/fixtures/http_proxy.c + test/core/end2end/fixtures/proxy.c + test/core/iomgr/endpoint_tests.c + test/core/util/grpc_profiler.c + test/core/util/memory_counters.c + test/core/util/mock_endpoint.c + test/core/util/parse_hexstring.c + test/core/util/passthru_endpoint.c + test/core/util/port_posix.c + test/core/util/port_server_client.c + test/core/util/port_uv.c + test/core/util/port_windows.c + test/core/util/slice_splitter.c +) + + +target_include_directories(grpc_test_util_unsecure + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_test_util_unsecure + gpr + gpr_test_util + grpc_unsecure + grpc +) + + +endif (gRPC_BUILD_TESTS) add_library(grpc_unsecure src/core/lib/surface/init.c @@ -1088,6 +1374,7 @@ target_include_directories(grpc_unsecure PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc_unsecure @@ -1142,6 +1429,59 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(reconnect_server + test/core/util/reconnect_server.c +) + + +target_include_directories(reconnect_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(reconnect_server + test_tcp_server + grpc_test_util + grpc + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(test_tcp_server + test/core/util/test_tcp_server.c +) + + +target_include_directories(test_tcp_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(test_tcp_server + grpc_test_util + grpc + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) add_library(grpc++ src/cpp/client/insecure_credentials.cc @@ -1191,6 +1531,7 @@ target_include_directories(grpc++ PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc++ @@ -1529,6 +1870,7 @@ target_include_directories(grpc++_cronet PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc++_cronet @@ -1655,10 +1997,10 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) -add_library(grpc++_reflection - src/cpp/ext/proto_server_reflection.cc - src/cpp/ext/proto_server_reflection_plugin.cc +add_library(grpc++_proto_reflection_desc_db + test/cpp/util/proto_reflection_descriptor_database.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.h @@ -1669,22 +2011,25 @@ protobuf_generate_grpc_cpp( src/proto/grpc/reflection/v1alpha/reflection.proto ) -target_include_directories(grpc++_reflection +target_include_directories(grpc++_proto_reflection_desc_db PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(grpc++_reflection +target_link_libraries(grpc++_proto_reflection_desc_db grpc++ ) foreach(_hdr - include/grpc++/ext/proto_server_reflection_plugin.h + include/grpc++/impl/codegen/config_protobuf.h ) string(REPLACE "include/" "" _path ${_hdr}) get_filename_component(_path ${_path} PATH) @@ -1693,15 +2038,215 @@ foreach(_hdr ) endforeach() +endif (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc++_reflection EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_library(grpc++_reflection + src/cpp/ext/proto_server_reflection.cc + src/cpp/ext/proto_server_reflection_plugin.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/reflection/v1alpha/reflection.proto +) + +target_include_directories(grpc++_reflection + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc++_reflection + grpc++ +) + +foreach(_hdr + include/grpc++/ext/proto_server_reflection_plugin.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + + +if (gRPC_INSTALL) + install(TARGETS grpc++_reflection EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_library(grpc++_test + src/cpp/test/server_context_test_spouse.cc +) + + +target_include_directories(grpc++_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(grpc++_test + grpc++ +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(grpc++_test_config + test/cpp/util/test_config_cc.cc +) + + +target_include_directories(grpc++_test_config + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(grpc++_test_util + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo_messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/echo.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/duplicate/echo_duplicate.grpc.pb.h + test/cpp/end2end/test_service_impl.cc + test/cpp/util/byte_buffer_proto_helper.cc + test/cpp/util/create_test_channel.cc + test/cpp/util/string_ref_helper.cc + test/cpp/util/subprocess.cc + test/cpp/util/test_credentials_provider.cc + src/cpp/codegen/codegen_init.cc +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/echo_messages.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/echo.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/duplicate/echo_duplicate.proto +) + +target_include_directories(grpc++_test_util + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc++_test_util + grpc++ + grpc_test_util +) + +foreach(_hdr + include/grpc++/impl/codegen/async_stream.h + include/grpc++/impl/codegen/async_unary_call.h + include/grpc++/impl/codegen/call.h + include/grpc++/impl/codegen/call_hook.h + include/grpc++/impl/codegen/channel_interface.h + include/grpc++/impl/codegen/client_context.h + include/grpc++/impl/codegen/client_unary_call.h + include/grpc++/impl/codegen/completion_queue.h + include/grpc++/impl/codegen/completion_queue_tag.h + include/grpc++/impl/codegen/config.h + include/grpc++/impl/codegen/core_codegen_interface.h + include/grpc++/impl/codegen/create_auth_context.h + include/grpc++/impl/codegen/grpc_library.h + include/grpc++/impl/codegen/method_handler_impl.h + include/grpc++/impl/codegen/rpc_method.h + include/grpc++/impl/codegen/rpc_service_method.h + include/grpc++/impl/codegen/security/auth_context.h + include/grpc++/impl/codegen/serialization_traits.h + include/grpc++/impl/codegen/server_context.h + include/grpc++/impl/codegen/server_interface.h + include/grpc++/impl/codegen/service_type.h + include/grpc++/impl/codegen/status.h + include/grpc++/impl/codegen/status_code_enum.h + include/grpc++/impl/codegen/status_helper.h + include/grpc++/impl/codegen/string_ref.h + include/grpc++/impl/codegen/stub_options.h + include/grpc++/impl/codegen/sync_stream.h + include/grpc++/impl/codegen/time.h + include/grpc/impl/codegen/byte_buffer_reader.h + include/grpc/impl/codegen/compression_types.h + include/grpc/impl/codegen/connectivity_state.h + include/grpc/impl/codegen/exec_ctx_fwd.h + include/grpc/impl/codegen/grpc_types.h + include/grpc/impl/codegen/propagation_bits.h + include/grpc/impl/codegen/status.h + include/grpc/impl/codegen/atm.h + include/grpc/impl/codegen/atm_gcc_atomic.h + include/grpc/impl/codegen/atm_gcc_sync.h + include/grpc/impl/codegen/atm_windows.h + include/grpc/impl/codegen/gpr_slice.h + include/grpc/impl/codegen/gpr_types.h + include/grpc/impl/codegen/port_platform.h + include/grpc/impl/codegen/slice.h + include/grpc/impl/codegen/sync.h + include/grpc/impl/codegen/sync_generic.h + include/grpc/impl/codegen/sync_posix.h + include/grpc/impl/codegen/sync_windows.h + include/grpc++/impl/codegen/proto_utils.h + include/grpc++/impl/codegen/config_protobuf.h + include/grpc++/impl/codegen/thrift_serializer.h + include/grpc++/impl/codegen/thrift_utils.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() +endif (gRPC_BUILD_TESTS) add_library(grpc++_unsecure src/cpp/client/insecure_credentials.cc @@ -1746,6 +2291,7 @@ target_include_directories(grpc++_unsecure PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc++_unsecure @@ -1862,6 +2408,53 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(grpc_cli_libs + test/cpp/util/cli_call.cc + test/cpp/util/cli_credentials.cc + test/cpp/util/grpc_tool.cc + test/cpp/util/proto_file_parser.cc + test/cpp/util/service_describer.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/reflection/v1alpha/reflection.grpc.pb.h +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/reflection/v1alpha/reflection.proto +) + +target_include_directories(grpc_cli_libs + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(grpc_cli_libs + grpc++_proto_reflection_desc_db + grpc++ +) + +foreach(_hdr + include/grpc++/impl/codegen/config_protobuf.h +) + string(REPLACE "include/" "" _path ${_hdr}) + get_filename_component(_path ${_path} PATH) + install(FILES ${_hdr} + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/${_path}" + ) +endforeach() + +endif (gRPC_BUILD_TESTS) add_library(grpc_plugin_support src/compiler/cpp_generator.cc @@ -1881,6 +2474,7 @@ target_include_directories(grpc_plugin_support PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) target_link_libraries(grpc_plugin_support @@ -1906,86 +2500,3273 @@ if (gRPC_INSTALL) ) endif() +if (gRPC_BUILD_TESTS) + +add_library(http2_client_main + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.h + test/cpp/interop/http2_client.cc +) - -add_executable(gen_hpack_tables - tools/codegen/core/gen_hpack_tables.c +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/empty.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/messages.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/test.proto ) -target_include_directories(gen_hpack_tables +target_include_directories(http2_client_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} ) -target_link_libraries(gen_hpack_tables - gpr +target_link_libraries(http2_client_main + grpc++_test_util + grpc_test_util + grpc++ grpc + grpc++_test_config ) -if (gRPC_INSTALL) - install(TARGETS gen_hpack_tables EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) +add_library(interop_client_helper + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.h + test/cpp/interop/client_helper.cc +) -add_executable(gen_legal_metadata_characters - tools/codegen/core/gen_legal_metadata_characters.c +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/messages.proto ) -target_include_directories(gen_legal_metadata_characters +target_include_directories(interop_client_helper PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} ) +target_link_libraries(interop_client_helper + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr +) -if (gRPC_INSTALL) - install(TARGETS gen_legal_metadata_characters EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() - +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(interop_client_main + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.h + test/cpp/interop/client.cc + test/cpp/interop/interop_client.cc +) -add_executable(gen_percent_encoding_tables - tools/codegen/core/gen_percent_encoding_tables.c +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/empty.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/messages.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/test.proto ) -target_include_directories(gen_percent_encoding_tables +target_include_directories(interop_client_main PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} ) +target_link_libraries(interop_client_main + interop_client_helper + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config +) -if (gRPC_INSTALL) - install(TARGETS gen_percent_encoding_tables EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() - +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -add_executable(grpc_create_jwt - test/core/security/create_jwt.c +add_library(interop_server_helper + test/cpp/interop/server_helper.cc +) + + +target_include_directories(interop_server_helper + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(interop_server_helper + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(interop_server_lib + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/empty.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/test.grpc.pb.h + test/cpp/interop/interop_server.cc +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/empty.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/messages.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/test.proto +) + +target_include_directories(interop_server_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(interop_server_lib + interop_server_helper + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(interop_server_main + test/cpp/interop/interop_server_bootstrap.cc +) + + +target_include_directories(interop_server_main + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(interop_server_main + interop_server_lib +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(qps + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/messages.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/payloads.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/payloads.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/payloads.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/payloads.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/stats.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/control.grpc.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/services.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/services.grpc.pb.cc + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/services.pb.h + ${_gRPC_PROTO_GENS_DIR}/src/proto/grpc/testing/services.grpc.pb.h + test/cpp/qps/client_async.cc + test/cpp/qps/client_sync.cc + test/cpp/qps/driver.cc + test/cpp/qps/parse_json.cc + test/cpp/qps/qps_worker.cc + test/cpp/qps/report.cc + test/cpp/qps/server_async.cc + test/cpp/qps/server_sync.cc + test/cpp/qps/usage_timer.cc + test/cpp/util/benchmark_config.cc +) + +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/messages.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/payloads.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/stats.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/control.proto +) +protobuf_generate_grpc_cpp( + src/proto/grpc/testing/services.proto +) + +target_include_directories(qps + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest + PRIVATE ${_gRPC_PROTO_GENS_DIR} +) + +target_link_libraries(qps + grpc_test_util + grpc++_test_util + grpc++ +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl + src/boringssl/err_data.c + third_party/boringssl/crypto/aes/aes.c + third_party/boringssl/crypto/aes/mode_wrappers.c + third_party/boringssl/crypto/asn1/a_bitstr.c + third_party/boringssl/crypto/asn1/a_bool.c + third_party/boringssl/crypto/asn1/a_bytes.c + third_party/boringssl/crypto/asn1/a_d2i_fp.c + third_party/boringssl/crypto/asn1/a_dup.c + third_party/boringssl/crypto/asn1/a_enum.c + third_party/boringssl/crypto/asn1/a_gentm.c + third_party/boringssl/crypto/asn1/a_i2d_fp.c + third_party/boringssl/crypto/asn1/a_int.c + third_party/boringssl/crypto/asn1/a_mbstr.c + third_party/boringssl/crypto/asn1/a_object.c + third_party/boringssl/crypto/asn1/a_octet.c + third_party/boringssl/crypto/asn1/a_print.c + third_party/boringssl/crypto/asn1/a_strnid.c + third_party/boringssl/crypto/asn1/a_time.c + third_party/boringssl/crypto/asn1/a_type.c + third_party/boringssl/crypto/asn1/a_utctm.c + third_party/boringssl/crypto/asn1/a_utf8.c + third_party/boringssl/crypto/asn1/asn1_lib.c + third_party/boringssl/crypto/asn1/asn1_par.c + third_party/boringssl/crypto/asn1/asn_pack.c + third_party/boringssl/crypto/asn1/bio_asn1.c + third_party/boringssl/crypto/asn1/bio_ndef.c + third_party/boringssl/crypto/asn1/f_enum.c + third_party/boringssl/crypto/asn1/f_int.c + third_party/boringssl/crypto/asn1/f_string.c + third_party/boringssl/crypto/asn1/t_bitst.c + third_party/boringssl/crypto/asn1/t_pkey.c + third_party/boringssl/crypto/asn1/tasn_dec.c + third_party/boringssl/crypto/asn1/tasn_enc.c + third_party/boringssl/crypto/asn1/tasn_fre.c + third_party/boringssl/crypto/asn1/tasn_new.c + third_party/boringssl/crypto/asn1/tasn_prn.c + third_party/boringssl/crypto/asn1/tasn_typ.c + third_party/boringssl/crypto/asn1/tasn_utl.c + third_party/boringssl/crypto/asn1/x_bignum.c + third_party/boringssl/crypto/asn1/x_long.c + third_party/boringssl/crypto/base64/base64.c + third_party/boringssl/crypto/bio/bio.c + third_party/boringssl/crypto/bio/bio_mem.c + third_party/boringssl/crypto/bio/buffer.c + third_party/boringssl/crypto/bio/connect.c + third_party/boringssl/crypto/bio/fd.c + third_party/boringssl/crypto/bio/file.c + third_party/boringssl/crypto/bio/hexdump.c + third_party/boringssl/crypto/bio/pair.c + third_party/boringssl/crypto/bio/printf.c + third_party/boringssl/crypto/bio/socket.c + third_party/boringssl/crypto/bio/socket_helper.c + third_party/boringssl/crypto/bn/add.c + third_party/boringssl/crypto/bn/asm/x86_64-gcc.c + third_party/boringssl/crypto/bn/bn.c + third_party/boringssl/crypto/bn/bn_asn1.c + third_party/boringssl/crypto/bn/cmp.c + third_party/boringssl/crypto/bn/convert.c + third_party/boringssl/crypto/bn/ctx.c + third_party/boringssl/crypto/bn/div.c + third_party/boringssl/crypto/bn/exponentiation.c + third_party/boringssl/crypto/bn/gcd.c + third_party/boringssl/crypto/bn/generic.c + third_party/boringssl/crypto/bn/kronecker.c + third_party/boringssl/crypto/bn/montgomery.c + third_party/boringssl/crypto/bn/mul.c + third_party/boringssl/crypto/bn/prime.c + third_party/boringssl/crypto/bn/random.c + third_party/boringssl/crypto/bn/rsaz_exp.c + third_party/boringssl/crypto/bn/shift.c + third_party/boringssl/crypto/bn/sqrt.c + third_party/boringssl/crypto/buf/buf.c + third_party/boringssl/crypto/bytestring/asn1_compat.c + third_party/boringssl/crypto/bytestring/ber.c + third_party/boringssl/crypto/bytestring/cbb.c + third_party/boringssl/crypto/bytestring/cbs.c + third_party/boringssl/crypto/chacha/chacha_generic.c + third_party/boringssl/crypto/chacha/chacha_vec.c + third_party/boringssl/crypto/cipher/aead.c + third_party/boringssl/crypto/cipher/cipher.c + third_party/boringssl/crypto/cipher/derive_key.c + third_party/boringssl/crypto/cipher/e_aes.c + third_party/boringssl/crypto/cipher/e_chacha20poly1305.c + third_party/boringssl/crypto/cipher/e_des.c + third_party/boringssl/crypto/cipher/e_null.c + third_party/boringssl/crypto/cipher/e_rc2.c + third_party/boringssl/crypto/cipher/e_rc4.c + third_party/boringssl/crypto/cipher/e_ssl3.c + third_party/boringssl/crypto/cipher/e_tls.c + third_party/boringssl/crypto/cipher/tls_cbc.c + third_party/boringssl/crypto/cmac/cmac.c + third_party/boringssl/crypto/conf/conf.c + third_party/boringssl/crypto/cpu-arm.c + third_party/boringssl/crypto/cpu-intel.c + third_party/boringssl/crypto/crypto.c + third_party/boringssl/crypto/curve25519/curve25519.c + third_party/boringssl/crypto/curve25519/x25519-x86_64.c + third_party/boringssl/crypto/des/des.c + third_party/boringssl/crypto/dh/check.c + third_party/boringssl/crypto/dh/dh.c + third_party/boringssl/crypto/dh/dh_asn1.c + third_party/boringssl/crypto/dh/params.c + third_party/boringssl/crypto/digest/digest.c + third_party/boringssl/crypto/digest/digests.c + third_party/boringssl/crypto/directory_posix.c + third_party/boringssl/crypto/directory_win.c + third_party/boringssl/crypto/dsa/dsa.c + third_party/boringssl/crypto/dsa/dsa_asn1.c + third_party/boringssl/crypto/ec/ec.c + third_party/boringssl/crypto/ec/ec_asn1.c + third_party/boringssl/crypto/ec/ec_key.c + third_party/boringssl/crypto/ec/ec_montgomery.c + third_party/boringssl/crypto/ec/oct.c + third_party/boringssl/crypto/ec/p224-64.c + third_party/boringssl/crypto/ec/p256-64.c + third_party/boringssl/crypto/ec/p256-x86_64.c + third_party/boringssl/crypto/ec/simple.c + third_party/boringssl/crypto/ec/util-64.c + third_party/boringssl/crypto/ec/wnaf.c + third_party/boringssl/crypto/ecdh/ecdh.c + third_party/boringssl/crypto/ecdsa/ecdsa.c + third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c + third_party/boringssl/crypto/engine/engine.c + third_party/boringssl/crypto/err/err.c + third_party/boringssl/crypto/evp/algorithm.c + third_party/boringssl/crypto/evp/digestsign.c + third_party/boringssl/crypto/evp/evp.c + third_party/boringssl/crypto/evp/evp_asn1.c + third_party/boringssl/crypto/evp/evp_ctx.c + third_party/boringssl/crypto/evp/p_dsa_asn1.c + third_party/boringssl/crypto/evp/p_ec.c + third_party/boringssl/crypto/evp/p_ec_asn1.c + third_party/boringssl/crypto/evp/p_rsa.c + third_party/boringssl/crypto/evp/p_rsa_asn1.c + third_party/boringssl/crypto/evp/pbkdf.c + third_party/boringssl/crypto/evp/sign.c + third_party/boringssl/crypto/ex_data.c + third_party/boringssl/crypto/hkdf/hkdf.c + third_party/boringssl/crypto/hmac/hmac.c + third_party/boringssl/crypto/lhash/lhash.c + third_party/boringssl/crypto/md4/md4.c + third_party/boringssl/crypto/md5/md5.c + third_party/boringssl/crypto/mem.c + third_party/boringssl/crypto/modes/cbc.c + third_party/boringssl/crypto/modes/cfb.c + third_party/boringssl/crypto/modes/ctr.c + third_party/boringssl/crypto/modes/gcm.c + third_party/boringssl/crypto/modes/ofb.c + third_party/boringssl/crypto/obj/obj.c + third_party/boringssl/crypto/obj/obj_xref.c + third_party/boringssl/crypto/pem/pem_all.c + third_party/boringssl/crypto/pem/pem_info.c + third_party/boringssl/crypto/pem/pem_lib.c + third_party/boringssl/crypto/pem/pem_oth.c + third_party/boringssl/crypto/pem/pem_pk8.c + third_party/boringssl/crypto/pem/pem_pkey.c + third_party/boringssl/crypto/pem/pem_x509.c + third_party/boringssl/crypto/pem/pem_xaux.c + third_party/boringssl/crypto/pkcs8/p5_pbe.c + third_party/boringssl/crypto/pkcs8/p5_pbev2.c + third_party/boringssl/crypto/pkcs8/p8_pkey.c + third_party/boringssl/crypto/pkcs8/pkcs8.c + third_party/boringssl/crypto/poly1305/poly1305.c + third_party/boringssl/crypto/poly1305/poly1305_arm.c + third_party/boringssl/crypto/poly1305/poly1305_vec.c + third_party/boringssl/crypto/rand/rand.c + third_party/boringssl/crypto/rand/urandom.c + third_party/boringssl/crypto/rand/windows.c + third_party/boringssl/crypto/rc4/rc4.c + third_party/boringssl/crypto/refcount_c11.c + third_party/boringssl/crypto/refcount_lock.c + third_party/boringssl/crypto/rsa/blinding.c + third_party/boringssl/crypto/rsa/padding.c + third_party/boringssl/crypto/rsa/rsa.c + third_party/boringssl/crypto/rsa/rsa_asn1.c + third_party/boringssl/crypto/rsa/rsa_impl.c + third_party/boringssl/crypto/sha/sha1.c + third_party/boringssl/crypto/sha/sha256.c + third_party/boringssl/crypto/sha/sha512.c + third_party/boringssl/crypto/stack/stack.c + third_party/boringssl/crypto/thread.c + third_party/boringssl/crypto/thread_none.c + third_party/boringssl/crypto/thread_pthread.c + third_party/boringssl/crypto/thread_win.c + third_party/boringssl/crypto/time_support.c + third_party/boringssl/crypto/x509/a_digest.c + third_party/boringssl/crypto/x509/a_sign.c + third_party/boringssl/crypto/x509/a_strex.c + third_party/boringssl/crypto/x509/a_verify.c + third_party/boringssl/crypto/x509/asn1_gen.c + third_party/boringssl/crypto/x509/by_dir.c + third_party/boringssl/crypto/x509/by_file.c + third_party/boringssl/crypto/x509/i2d_pr.c + third_party/boringssl/crypto/x509/pkcs7.c + third_party/boringssl/crypto/x509/t_crl.c + third_party/boringssl/crypto/x509/t_req.c + third_party/boringssl/crypto/x509/t_x509.c + third_party/boringssl/crypto/x509/t_x509a.c + third_party/boringssl/crypto/x509/x509.c + third_party/boringssl/crypto/x509/x509_att.c + third_party/boringssl/crypto/x509/x509_cmp.c + third_party/boringssl/crypto/x509/x509_d2.c + third_party/boringssl/crypto/x509/x509_def.c + third_party/boringssl/crypto/x509/x509_ext.c + third_party/boringssl/crypto/x509/x509_lu.c + third_party/boringssl/crypto/x509/x509_obj.c + third_party/boringssl/crypto/x509/x509_r2x.c + third_party/boringssl/crypto/x509/x509_req.c + third_party/boringssl/crypto/x509/x509_set.c + third_party/boringssl/crypto/x509/x509_trs.c + third_party/boringssl/crypto/x509/x509_txt.c + third_party/boringssl/crypto/x509/x509_v3.c + third_party/boringssl/crypto/x509/x509_vfy.c + third_party/boringssl/crypto/x509/x509_vpm.c + third_party/boringssl/crypto/x509/x509cset.c + third_party/boringssl/crypto/x509/x509name.c + third_party/boringssl/crypto/x509/x509rset.c + third_party/boringssl/crypto/x509/x509spki.c + third_party/boringssl/crypto/x509/x509type.c + third_party/boringssl/crypto/x509/x_algor.c + third_party/boringssl/crypto/x509/x_all.c + third_party/boringssl/crypto/x509/x_attrib.c + third_party/boringssl/crypto/x509/x_crl.c + third_party/boringssl/crypto/x509/x_exten.c + third_party/boringssl/crypto/x509/x_info.c + third_party/boringssl/crypto/x509/x_name.c + third_party/boringssl/crypto/x509/x_pkey.c + third_party/boringssl/crypto/x509/x_pubkey.c + third_party/boringssl/crypto/x509/x_req.c + third_party/boringssl/crypto/x509/x_sig.c + third_party/boringssl/crypto/x509/x_spki.c + third_party/boringssl/crypto/x509/x_val.c + third_party/boringssl/crypto/x509/x_x509.c + third_party/boringssl/crypto/x509/x_x509a.c + third_party/boringssl/crypto/x509v3/pcy_cache.c + third_party/boringssl/crypto/x509v3/pcy_data.c + third_party/boringssl/crypto/x509v3/pcy_lib.c + third_party/boringssl/crypto/x509v3/pcy_map.c + third_party/boringssl/crypto/x509v3/pcy_node.c + third_party/boringssl/crypto/x509v3/pcy_tree.c + third_party/boringssl/crypto/x509v3/v3_akey.c + third_party/boringssl/crypto/x509v3/v3_akeya.c + third_party/boringssl/crypto/x509v3/v3_alt.c + third_party/boringssl/crypto/x509v3/v3_bcons.c + third_party/boringssl/crypto/x509v3/v3_bitst.c + third_party/boringssl/crypto/x509v3/v3_conf.c + third_party/boringssl/crypto/x509v3/v3_cpols.c + third_party/boringssl/crypto/x509v3/v3_crld.c + third_party/boringssl/crypto/x509v3/v3_enum.c + third_party/boringssl/crypto/x509v3/v3_extku.c + third_party/boringssl/crypto/x509v3/v3_genn.c + third_party/boringssl/crypto/x509v3/v3_ia5.c + third_party/boringssl/crypto/x509v3/v3_info.c + third_party/boringssl/crypto/x509v3/v3_int.c + third_party/boringssl/crypto/x509v3/v3_lib.c + third_party/boringssl/crypto/x509v3/v3_ncons.c + third_party/boringssl/crypto/x509v3/v3_pci.c + third_party/boringssl/crypto/x509v3/v3_pcia.c + third_party/boringssl/crypto/x509v3/v3_pcons.c + third_party/boringssl/crypto/x509v3/v3_pku.c + third_party/boringssl/crypto/x509v3/v3_pmaps.c + third_party/boringssl/crypto/x509v3/v3_prn.c + third_party/boringssl/crypto/x509v3/v3_purp.c + third_party/boringssl/crypto/x509v3/v3_skey.c + third_party/boringssl/crypto/x509v3/v3_sxnet.c + third_party/boringssl/crypto/x509v3/v3_utl.c + third_party/boringssl/ssl/custom_extensions.c + third_party/boringssl/ssl/d1_both.c + third_party/boringssl/ssl/d1_clnt.c + third_party/boringssl/ssl/d1_lib.c + third_party/boringssl/ssl/d1_meth.c + third_party/boringssl/ssl/d1_pkt.c + third_party/boringssl/ssl/d1_srtp.c + third_party/boringssl/ssl/d1_srvr.c + third_party/boringssl/ssl/dtls_record.c + third_party/boringssl/ssl/pqueue/pqueue.c + third_party/boringssl/ssl/s3_both.c + third_party/boringssl/ssl/s3_clnt.c + third_party/boringssl/ssl/s3_enc.c + third_party/boringssl/ssl/s3_lib.c + third_party/boringssl/ssl/s3_meth.c + third_party/boringssl/ssl/s3_pkt.c + third_party/boringssl/ssl/s3_srvr.c + third_party/boringssl/ssl/ssl_aead_ctx.c + third_party/boringssl/ssl/ssl_asn1.c + third_party/boringssl/ssl/ssl_buffer.c + third_party/boringssl/ssl/ssl_cert.c + third_party/boringssl/ssl/ssl_cipher.c + third_party/boringssl/ssl/ssl_ecdh.c + third_party/boringssl/ssl/ssl_file.c + third_party/boringssl/ssl/ssl_lib.c + third_party/boringssl/ssl/ssl_rsa.c + third_party/boringssl/ssl/ssl_session.c + third_party/boringssl/ssl/ssl_stat.c + third_party/boringssl/ssl/t1_enc.c + third_party/boringssl/ssl/t1_lib.c + third_party/boringssl/ssl/tls_record.c +) + + +target_include_directories(boringssl + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl + ${_gRPC_SSL_LIBRARIES} +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_test_util + third_party/boringssl/crypto/test/file_test.cc + third_party/boringssl/crypto/test/malloc.cc + third_party/boringssl/crypto/test/test_util.cc +) + + +target_include_directories(boringssl_test_util + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_test_util + ${_gRPC_SSL_LIBRARIES} +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_aes_test_lib + third_party/boringssl/crypto/aes/aes_test.cc +) + + +target_include_directories(boringssl_aes_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_aes_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_asn1_test_lib + third_party/boringssl/crypto/asn1/asn1_test.cc +) + + +target_include_directories(boringssl_asn1_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_asn1_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_base64_test_lib + third_party/boringssl/crypto/base64/base64_test.cc +) + + +target_include_directories(boringssl_base64_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_base64_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_bio_test_lib + third_party/boringssl/crypto/bio/bio_test.cc +) + + +target_include_directories(boringssl_bio_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bio_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_bn_test_lib + third_party/boringssl/crypto/bn/bn_test.cc +) + + +target_include_directories(boringssl_bn_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bn_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_bytestring_test_lib + third_party/boringssl/crypto/bytestring/bytestring_test.cc +) + + +target_include_directories(boringssl_bytestring_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bytestring_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_aead_test_lib + third_party/boringssl/crypto/cipher/aead_test.cc +) + + +target_include_directories(boringssl_aead_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_aead_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_cipher_test_lib + third_party/boringssl/crypto/cipher/cipher_test.cc +) + + +target_include_directories(boringssl_cipher_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_cipher_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_cmac_test_lib + third_party/boringssl/crypto/cmac/cmac_test.cc +) + + +target_include_directories(boringssl_cmac_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_cmac_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_constant_time_test_lib + third_party/boringssl/crypto/constant_time_test.c +) + + +target_include_directories(boringssl_constant_time_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_constant_time_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ed25519_test_lib + third_party/boringssl/crypto/curve25519/ed25519_test.cc +) + + +target_include_directories(boringssl_ed25519_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ed25519_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_x25519_test_lib + third_party/boringssl/crypto/curve25519/x25519_test.cc +) + + +target_include_directories(boringssl_x25519_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_x25519_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_dh_test_lib + third_party/boringssl/crypto/dh/dh_test.cc +) + + +target_include_directories(boringssl_dh_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_dh_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_digest_test_lib + third_party/boringssl/crypto/digest/digest_test.cc +) + + +target_include_directories(boringssl_digest_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_digest_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_dsa_test_lib + third_party/boringssl/crypto/dsa/dsa_test.c +) + + +target_include_directories(boringssl_dsa_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_dsa_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ec_test_lib + third_party/boringssl/crypto/ec/ec_test.cc +) + + +target_include_directories(boringssl_ec_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ec_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_example_mul_lib + third_party/boringssl/crypto/ec/example_mul.c +) + + +target_include_directories(boringssl_example_mul_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_example_mul_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ecdsa_test_lib + third_party/boringssl/crypto/ecdsa/ecdsa_test.cc +) + + +target_include_directories(boringssl_ecdsa_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_err_test_lib + third_party/boringssl/crypto/err/err_test.cc +) + + +target_include_directories(boringssl_err_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_err_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_evp_extra_test_lib + third_party/boringssl/crypto/evp/evp_extra_test.cc +) + + +target_include_directories(boringssl_evp_extra_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_evp_extra_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_evp_test_lib + third_party/boringssl/crypto/evp/evp_test.cc +) + + +target_include_directories(boringssl_evp_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_evp_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_pbkdf_test_lib + third_party/boringssl/crypto/evp/pbkdf_test.cc +) + + +target_include_directories(boringssl_pbkdf_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pbkdf_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_hkdf_test_lib + third_party/boringssl/crypto/hkdf/hkdf_test.c +) + + +target_include_directories(boringssl_hkdf_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_hkdf_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_hmac_test_lib + third_party/boringssl/crypto/hmac/hmac_test.cc +) + + +target_include_directories(boringssl_hmac_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_hmac_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_lhash_test_lib + third_party/boringssl/crypto/lhash/lhash_test.c +) + + +target_include_directories(boringssl_lhash_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_lhash_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_gcm_test_lib + third_party/boringssl/crypto/modes/gcm_test.c +) + + +target_include_directories(boringssl_gcm_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_gcm_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_pkcs12_test_lib + third_party/boringssl/crypto/pkcs8/pkcs12_test.cc +) + + +target_include_directories(boringssl_pkcs12_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pkcs12_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_pkcs8_test_lib + third_party/boringssl/crypto/pkcs8/pkcs8_test.cc +) + + +target_include_directories(boringssl_pkcs8_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pkcs8_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_poly1305_test_lib + third_party/boringssl/crypto/poly1305/poly1305_test.cc +) + + +target_include_directories(boringssl_poly1305_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_poly1305_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_refcount_test_lib + third_party/boringssl/crypto/refcount_test.c +) + + +target_include_directories(boringssl_refcount_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_refcount_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_rsa_test_lib + third_party/boringssl/crypto/rsa/rsa_test.cc +) + + +target_include_directories(boringssl_rsa_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_rsa_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_thread_test_lib + third_party/boringssl/crypto/thread_test.c +) + + +target_include_directories(boringssl_thread_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_thread_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_pkcs7_test_lib + third_party/boringssl/crypto/x509/pkcs7_test.c +) + + +target_include_directories(boringssl_pkcs7_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_pkcs7_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_x509_test_lib + third_party/boringssl/crypto/x509/x509_test.cc +) + + +target_include_directories(boringssl_x509_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_x509_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_tab_test_lib + third_party/boringssl/crypto/x509v3/tab_test.c +) + + +target_include_directories(boringssl_tab_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_tab_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_v3name_test_lib + third_party/boringssl/crypto/x509v3/v3name_test.c +) + + +target_include_directories(boringssl_v3name_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_v3name_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_pqueue_test_lib + third_party/boringssl/ssl/pqueue/pqueue_test.c +) + + +target_include_directories(boringssl_pqueue_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(boringssl_pqueue_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ssl_test_lib + third_party/boringssl/ssl/ssl_test.cc +) + + +target_include_directories(boringssl_ssl_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ssl_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(benchmark + third_party/benchmark/src/benchmark.cc + third_party/benchmark/src/benchmark_register.cc + third_party/benchmark/src/colorprint.cc + third_party/benchmark/src/commandlineflags.cc + third_party/benchmark/src/complexity.cc + third_party/benchmark/src/console_reporter.cc + third_party/benchmark/src/csv_reporter.cc + third_party/benchmark/src/json_reporter.cc + third_party/benchmark/src/reporter.cc + third_party/benchmark/src/sleep.cc + third_party/benchmark/src/string_util.cc + third_party/benchmark/src/sysinfo.cc + third_party/benchmark/src/timers.cc +) + + +target_include_directories(benchmark + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(benchmark + ${_gRPC_SSL_LIBRARIES} +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(z + third_party/zlib/adler32.c + third_party/zlib/compress.c + third_party/zlib/crc32.c + third_party/zlib/deflate.c + third_party/zlib/gzclose.c + third_party/zlib/gzlib.c + third_party/zlib/gzread.c + third_party/zlib/gzwrite.c + third_party/zlib/infback.c + third_party/zlib/inffast.c + third_party/zlib/inflate.c + third_party/zlib/inftrees.c + third_party/zlib/trees.c + third_party/zlib/uncompr.c + third_party/zlib/zutil.c +) + + +target_include_directories(z + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(z + ${_gRPC_SSL_LIBRARIES} +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(bad_client_test + test/core/bad_client/bad_client.c +) + + +target_include_directories(bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(bad_ssl_test_server + test/core/bad_ssl/server_common.c +) + + +target_include_directories(bad_ssl_test_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bad_ssl_test_server + grpc_test_util + grpc + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(end2end_tests + test/core/end2end/end2end_tests.c + test/core/end2end/end2end_test_utils.c + test/core/end2end/tests/authority_not_supported.c + test/core/end2end/tests/bad_hostname.c + test/core/end2end/tests/binary_metadata.c + test/core/end2end/tests/call_creds.c + test/core/end2end/tests/cancel_after_accept.c + test/core/end2end/tests/cancel_after_client_done.c + test/core/end2end/tests/cancel_after_invoke.c + test/core/end2end/tests/cancel_before_invoke.c + test/core/end2end/tests/cancel_in_a_vacuum.c + test/core/end2end/tests/cancel_with_status.c + test/core/end2end/tests/compressed_payload.c + test/core/end2end/tests/connectivity.c + test/core/end2end/tests/default_host.c + test/core/end2end/tests/disappearing_server.c + test/core/end2end/tests/empty_batch.c + test/core/end2end/tests/filter_call_init_fails.c + test/core/end2end/tests/filter_causes_close.c + test/core/end2end/tests/filter_latency.c + test/core/end2end/tests/graceful_server_shutdown.c + test/core/end2end/tests/high_initial_seqno.c + test/core/end2end/tests/hpack_size.c + test/core/end2end/tests/idempotent_request.c + test/core/end2end/tests/invoke_large_request.c + test/core/end2end/tests/large_metadata.c + test/core/end2end/tests/load_reporting_hook.c + test/core/end2end/tests/max_concurrent_streams.c + test/core/end2end/tests/max_message_length.c + test/core/end2end/tests/negative_deadline.c + test/core/end2end/tests/network_status_change.c + test/core/end2end/tests/no_logging.c + test/core/end2end/tests/no_op.c + test/core/end2end/tests/payload.c + test/core/end2end/tests/ping.c + test/core/end2end/tests/ping_pong_streaming.c + test/core/end2end/tests/registered_call.c + test/core/end2end/tests/request_with_flags.c + test/core/end2end/tests/request_with_payload.c + test/core/end2end/tests/resource_quota_server.c + test/core/end2end/tests/server_finishes_request.c + test/core/end2end/tests/shutdown_finishes_calls.c + test/core/end2end/tests/shutdown_finishes_tags.c + test/core/end2end/tests/simple_cacheable_request.c + test/core/end2end/tests/simple_delayed_request.c + test/core/end2end/tests/simple_metadata.c + test/core/end2end/tests/simple_request.c + test/core/end2end/tests/streaming_error_response.c + test/core/end2end/tests/trailing_metadata.c + test/core/end2end/tests/write_buffering.c + test/core/end2end/tests/write_buffering_at_end.c +) + + +target_include_directories(end2end_tests + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(end2end_tests + ${_gRPC_SSL_LIBRARIES} + grpc_test_util + grpc + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(end2end_nosec_tests + test/core/end2end/end2end_nosec_tests.c + test/core/end2end/end2end_test_utils.c + test/core/end2end/tests/authority_not_supported.c + test/core/end2end/tests/bad_hostname.c + test/core/end2end/tests/binary_metadata.c + test/core/end2end/tests/cancel_after_accept.c + test/core/end2end/tests/cancel_after_client_done.c + test/core/end2end/tests/cancel_after_invoke.c + test/core/end2end/tests/cancel_before_invoke.c + test/core/end2end/tests/cancel_in_a_vacuum.c + test/core/end2end/tests/cancel_with_status.c + test/core/end2end/tests/compressed_payload.c + test/core/end2end/tests/connectivity.c + test/core/end2end/tests/default_host.c + test/core/end2end/tests/disappearing_server.c + test/core/end2end/tests/empty_batch.c + test/core/end2end/tests/filter_call_init_fails.c + test/core/end2end/tests/filter_causes_close.c + test/core/end2end/tests/filter_latency.c + test/core/end2end/tests/graceful_server_shutdown.c + test/core/end2end/tests/high_initial_seqno.c + test/core/end2end/tests/hpack_size.c + test/core/end2end/tests/idempotent_request.c + test/core/end2end/tests/invoke_large_request.c + test/core/end2end/tests/large_metadata.c + test/core/end2end/tests/load_reporting_hook.c + test/core/end2end/tests/max_concurrent_streams.c + test/core/end2end/tests/max_message_length.c + test/core/end2end/tests/negative_deadline.c + test/core/end2end/tests/network_status_change.c + test/core/end2end/tests/no_logging.c + test/core/end2end/tests/no_op.c + test/core/end2end/tests/payload.c + test/core/end2end/tests/ping.c + test/core/end2end/tests/ping_pong_streaming.c + test/core/end2end/tests/registered_call.c + test/core/end2end/tests/request_with_flags.c + test/core/end2end/tests/request_with_payload.c + test/core/end2end/tests/resource_quota_server.c + test/core/end2end/tests/server_finishes_request.c + test/core/end2end/tests/shutdown_finishes_calls.c + test/core/end2end/tests/shutdown_finishes_tags.c + test/core/end2end/tests/simple_cacheable_request.c + test/core/end2end/tests/simple_delayed_request.c + test/core/end2end/tests/simple_metadata.c + test/core/end2end/tests/simple_request.c + test/core/end2end/tests/streaming_error_response.c + test/core/end2end/tests/trailing_metadata.c + test/core/end2end/tests/write_buffering.c + test/core/end2end/tests/write_buffering_at_end.c +) + + +target_include_directories(end2end_nosec_tests + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + + +endif (gRPC_BUILD_TESTS) + +if (gRPC_BUILD_TESTS) + +add_executable(alarm_test + test/core/surface/alarm_test.c +) + +target_include_directories(alarm_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(alarm_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(algorithm_test + test/core/compression/algorithm_test.c +) + +target_include_directories(algorithm_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(algorithm_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(alloc_test + test/core/support/alloc_test.c +) + +target_include_directories(alloc_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(alloc_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(alpn_test + test/core/transport/chttp2/alpn_test.c +) + +target_include_directories(alpn_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(alpn_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bad_server_response_test + test/core/end2end/bad_server_response_test.c +) + +target_include_directories(bad_server_response_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bad_server_response_test + test_tcp_server + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bin_decoder_test + test/core/transport/chttp2/bin_decoder_test.c +) + +target_include_directories(bin_decoder_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bin_decoder_test + grpc_test_util + grpc +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bin_encoder_test + test/core/transport/chttp2/bin_encoder_test.c +) + +target_include_directories(bin_encoder_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bin_encoder_test + grpc_test_util + grpc +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(census_context_test + test/core/census/context_test.c +) + +target_include_directories(census_context_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(census_context_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(census_resource_test + test/core/census/resource_test.c +) + +target_include_directories(census_resource_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(census_resource_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(census_trace_context_test + test/core/census/trace_context_test.c +) + +target_include_directories(census_trace_context_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(census_trace_context_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(channel_create_test + test/core/surface/channel_create_test.c +) + +target_include_directories(channel_create_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(channel_create_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(chttp2_hpack_encoder_test + test/core/transport/chttp2/hpack_encoder_test.c +) + +target_include_directories(chttp2_hpack_encoder_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(chttp2_hpack_encoder_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(chttp2_status_conversion_test + test/core/transport/chttp2/status_conversion_test.c +) + +target_include_directories(chttp2_status_conversion_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(chttp2_status_conversion_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(chttp2_stream_map_test + test/core/transport/chttp2/stream_map_test.c +) + +target_include_directories(chttp2_stream_map_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(chttp2_stream_map_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(chttp2_varint_test + test/core/transport/chttp2/varint_test.c +) + +target_include_directories(chttp2_varint_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(chttp2_varint_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(combiner_test + test/core/iomgr/combiner_test.c +) + +target_include_directories(combiner_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(combiner_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(compression_test + test/core/compression/compression_test.c +) + +target_include_directories(compression_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(compression_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(concurrent_connectivity_test + test/core/surface/concurrent_connectivity_test.c +) + +target_include_directories(concurrent_connectivity_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(concurrent_connectivity_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(connection_refused_test + test/core/end2end/connection_refused_test.c +) + +target_include_directories(connection_refused_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(connection_refused_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(dns_resolver_connectivity_test + test/core/client_channel/resolvers/dns_resolver_connectivity_test.c +) + +target_include_directories(dns_resolver_connectivity_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(dns_resolver_connectivity_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(dns_resolver_test + test/core/client_channel/resolvers/dns_resolver_test.c +) + +target_include_directories(dns_resolver_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(dns_resolver_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(dualstack_socket_test + test/core/end2end/dualstack_socket_test.c +) + +target_include_directories(dualstack_socket_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(dualstack_socket_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(endpoint_pair_test + test/core/iomgr/endpoint_pair_test.c +) + +target_include_directories(endpoint_pair_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(endpoint_pair_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(ev_epoll_linux_test + test/core/iomgr/ev_epoll_linux_test.c +) + +target_include_directories(ev_epoll_linux_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(ev_epoll_linux_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fd_conservation_posix_test + test/core/iomgr/fd_conservation_posix_test.c +) + +target_include_directories(fd_conservation_posix_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fd_conservation_posix_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fd_posix_test + test/core/iomgr/fd_posix_test.c +) + +target_include_directories(fd_posix_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fd_posix_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fling_client + test/core/fling/client.c +) + +target_include_directories(fling_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fling_client + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fling_server + test/core/fling/server.c +) + +target_include_directories(fling_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fling_server + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fling_stream_test + test/core/fling/fling_stream_test.c +) + +target_include_directories(fling_stream_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fling_stream_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(fling_test + test/core/fling/fling_test.c +) + +target_include_directories(fling_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(fling_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) + +add_executable(gen_hpack_tables + tools/codegen/core/gen_hpack_tables.c +) + +target_include_directories(gen_hpack_tables + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gen_hpack_tables + gpr + grpc +) + + +if (gRPC_INSTALL) + install(TARGETS gen_hpack_tables EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(gen_legal_metadata_characters + tools/codegen/core/gen_legal_metadata_characters.c +) + +target_include_directories(gen_legal_metadata_characters + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + + + +if (gRPC_INSTALL) + install(TARGETS gen_legal_metadata_characters EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(gen_percent_encoding_tables + tools/codegen/core/gen_percent_encoding_tables.c +) + +target_include_directories(gen_percent_encoding_tables + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + + + +if (gRPC_INSTALL) + install(TARGETS gen_percent_encoding_tables EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_executable(goaway_server_test + test/core/end2end/goaway_server_test.c +) + +target_include_directories(goaway_server_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(goaway_server_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_avl_test + test/core/support/avl_test.c +) + +target_include_directories(gpr_avl_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_avl_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_backoff_test + test/core/support/backoff_test.c +) + +target_include_directories(gpr_backoff_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_backoff_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_cmdline_test + test/core/support/cmdline_test.c +) + +target_include_directories(gpr_cmdline_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_cmdline_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_cpu_test + test/core/support/cpu_test.c +) + +target_include_directories(gpr_cpu_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_cpu_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_env_test + test/core/support/env_test.c +) + +target_include_directories(gpr_env_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_env_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_histogram_test + test/core/support/histogram_test.c +) + +target_include_directories(gpr_histogram_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_histogram_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_host_port_test + test/core/support/host_port_test.c +) + +target_include_directories(gpr_host_port_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_host_port_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_log_test + test/core/support/log_test.c +) + +target_include_directories(gpr_log_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_log_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_mpscq_test + test/core/support/mpscq_test.c +) + +target_include_directories(gpr_mpscq_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_mpscq_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_stack_lockfree_test + test/core/support/stack_lockfree_test.c +) + +target_include_directories(gpr_stack_lockfree_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_stack_lockfree_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_string_test + test/core/support/string_test.c +) + +target_include_directories(gpr_string_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_string_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_sync_test + test/core/support/sync_test.c +) + +target_include_directories(gpr_sync_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_sync_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_thd_test + test/core/support/thd_test.c +) + +target_include_directories(gpr_thd_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_thd_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_time_test + test/core/support/time_test.c +) + +target_include_directories(gpr_time_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_time_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_tls_test + test/core/support/tls_test.c +) + +target_include_directories(gpr_tls_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_tls_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(gpr_useful_test + test/core/support/useful_test.c +) + +target_include_directories(gpr_useful_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(gpr_useful_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_auth_context_test + test/core/security/auth_context_test.c +) + +target_include_directories(grpc_auth_context_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_auth_context_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_b64_test + test/core/security/b64_test.c +) + +target_include_directories(grpc_b64_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_b64_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_byte_buffer_reader_test + test/core/surface/byte_buffer_reader_test.c +) + +target_include_directories(grpc_byte_buffer_reader_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_byte_buffer_reader_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_channel_args_test + test/core/channel/channel_args_test.c +) + +target_include_directories(grpc_channel_args_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_channel_args_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_channel_stack_test + test/core/channel/channel_stack_test.c +) + +target_include_directories(grpc_channel_stack_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_channel_stack_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_completion_queue_test + test/core/surface/completion_queue_test.c +) + +target_include_directories(grpc_completion_queue_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_completion_queue_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) + +add_executable(grpc_create_jwt + test/core/security/create_jwt.c ) target_include_directories(grpc_create_jwt @@ -1995,275 +5776,5835 @@ target_include_directories(grpc_create_jwt PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_create_jwt + ${_gRPC_SSL_LIBRARIES} + grpc + gpr +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_create_jwt EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_executable(grpc_credentials_test + test/core/security/credentials_test.c +) + +target_include_directories(grpc_credentials_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_credentials_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_fetch_oauth2 + test/core/security/fetch_oauth2.c +) + +target_include_directories(grpc_fetch_oauth2 + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_fetch_oauth2 + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_invalid_channel_args_test + test/core/surface/invalid_channel_args_test.c +) + +target_include_directories(grpc_invalid_channel_args_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_invalid_channel_args_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_json_token_test + test/core/security/json_token_test.c +) + +target_include_directories(grpc_json_token_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_json_token_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_jwt_verifier_test + test/core/security/jwt_verifier_test.c +) + +target_include_directories(grpc_jwt_verifier_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_jwt_verifier_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) + +add_executable(grpc_print_google_default_creds_token + test/core/security/print_google_default_creds_token.c +) + +target_include_directories(grpc_print_google_default_creds_token + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_print_google_default_creds_token + grpc + gpr +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_print_google_default_creds_token EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_executable(grpc_security_connector_test + test/core/security/security_connector_test.c +) + +target_include_directories(grpc_security_connector_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_security_connector_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) + +add_executable(grpc_verify_jwt + test/core/security/verify_jwt.c +) + +target_include_directories(grpc_verify_jwt + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_verify_jwt + grpc + gpr +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_verify_jwt EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_executable(handshake_client + test/core/handshake/client_ssl.c +) + +target_include_directories(handshake_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(handshake_client + ${_gRPC_SSL_LIBRARIES} + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(handshake_server + test/core/handshake/server_ssl.c +) + +target_include_directories(handshake_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(handshake_server + ${_gRPC_SSL_LIBRARIES} + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(hpack_parser_test + test/core/transport/chttp2/hpack_parser_test.c +) + +target_include_directories(hpack_parser_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(hpack_parser_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(hpack_table_test + test/core/transport/chttp2/hpack_table_test.c +) + +target_include_directories(hpack_table_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(hpack_table_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(http_parser_test + test/core/http/parser_test.c +) + +target_include_directories(http_parser_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(http_parser_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(httpcli_format_request_test + test/core/http/format_request_test.c +) + +target_include_directories(httpcli_format_request_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(httpcli_format_request_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(httpcli_test + test/core/http/httpcli_test.c +) + +target_include_directories(httpcli_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(httpcli_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(httpscli_test + test/core/http/httpscli_test.c +) + +target_include_directories(httpscli_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(httpscli_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(init_test + test/core/surface/init_test.c +) + +target_include_directories(init_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(init_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(internal_api_canary_iomgr_test + test/core/internal_api_canaries/iomgr.c +) + +target_include_directories(internal_api_canary_iomgr_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(internal_api_canary_iomgr_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(internal_api_canary_support_test + test/core/internal_api_canaries/iomgr.c +) + +target_include_directories(internal_api_canary_support_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(internal_api_canary_support_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(internal_api_canary_transport_test + test/core/internal_api_canaries/iomgr.c +) + +target_include_directories(internal_api_canary_transport_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(internal_api_canary_transport_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(invalid_call_argument_test + test/core/end2end/invalid_call_argument_test.c +) + +target_include_directories(invalid_call_argument_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(invalid_call_argument_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_rewrite + test/core/json/json_rewrite.c +) + +target_include_directories(json_rewrite + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(json_rewrite + grpc + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_rewrite_test + test/core/json/json_rewrite_test.c +) + +target_include_directories(json_rewrite_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(json_rewrite_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_stream_error_test + test/core/json/json_stream_error_test.c +) + +target_include_directories(json_stream_error_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(json_stream_error_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_test + test/core/json/json_test.c +) + +target_include_directories(json_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(json_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(lame_client_test + test/core/surface/lame_client_test.c +) + +target_include_directories(lame_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(lame_client_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(lb_policies_test + test/core/client_channel/lb_policies_test.c +) + +target_include_directories(lb_policies_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(lb_policies_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(load_file_test + test/core/iomgr/load_file_test.c +) + +target_include_directories(load_file_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(load_file_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(memory_profile_client + test/core/memory_usage/client.c +) + +target_include_directories(memory_profile_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(memory_profile_client + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(memory_profile_server + test/core/memory_usage/server.c +) + +target_include_directories(memory_profile_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(memory_profile_server + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(memory_profile_test + test/core/memory_usage/memory_usage_test.c +) + +target_include_directories(memory_profile_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(memory_profile_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(message_compress_test + test/core/compression/message_compress_test.c +) + +target_include_directories(message_compress_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(message_compress_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(mlog_test + test/core/census/mlog_test.c +) + +target_include_directories(mlog_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(mlog_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(multiple_server_queues_test + test/core/end2end/multiple_server_queues_test.c +) + +target_include_directories(multiple_server_queues_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(multiple_server_queues_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(murmur_hash_test + test/core/support/murmur_hash_test.c +) + +target_include_directories(murmur_hash_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(murmur_hash_test + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(no_server_test + test/core/end2end/no_server_test.c +) + +target_include_directories(no_server_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(no_server_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(percent_encoding_test + test/core/slice/percent_encoding_test.c +) + +target_include_directories(percent_encoding_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(percent_encoding_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(resolve_address_test + test/core/iomgr/resolve_address_test.c +) + +target_include_directories(resolve_address_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(resolve_address_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(resource_quota_test + test/core/iomgr/resource_quota_test.c +) + +target_include_directories(resource_quota_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(resource_quota_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(secure_channel_create_test + test/core/surface/secure_channel_create_test.c +) + +target_include_directories(secure_channel_create_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(secure_channel_create_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(secure_endpoint_test + test/core/security/secure_endpoint_test.c +) + +target_include_directories(secure_endpoint_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(secure_endpoint_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(sequential_connectivity_test + test/core/surface/sequential_connectivity_test.c +) + +target_include_directories(sequential_connectivity_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(sequential_connectivity_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_chttp2_test + test/core/surface/server_chttp2_test.c +) + +target_include_directories(server_chttp2_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(server_chttp2_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_test + test/core/surface/server_test.c +) + +target_include_directories(server_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(server_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(set_initial_connect_string_test + test/core/client_channel/set_initial_connect_string_test.c +) + +target_include_directories(set_initial_connect_string_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(set_initial_connect_string_test + test_tcp_server + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(slice_buffer_test + test/core/slice/slice_buffer_test.c +) + +target_include_directories(slice_buffer_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(slice_buffer_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(slice_string_helpers_test + test/core/slice/slice_string_helpers_test.c +) + +target_include_directories(slice_string_helpers_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(slice_string_helpers_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(slice_test + test/core/slice/slice_test.c +) + +target_include_directories(slice_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(slice_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(sockaddr_resolver_test + test/core/client_channel/resolvers/sockaddr_resolver_test.c +) + +target_include_directories(sockaddr_resolver_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(sockaddr_resolver_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(sockaddr_utils_test + test/core/iomgr/sockaddr_utils_test.c +) + +target_include_directories(sockaddr_utils_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(sockaddr_utils_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(socket_utils_test + test/core/iomgr/socket_utils_test.c +) + +target_include_directories(socket_utils_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(socket_utils_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(tcp_client_posix_test + test/core/iomgr/tcp_client_posix_test.c +) + +target_include_directories(tcp_client_posix_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(tcp_client_posix_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(tcp_posix_test + test/core/iomgr/tcp_posix_test.c +) + +target_include_directories(tcp_posix_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(tcp_posix_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(tcp_server_posix_test + test/core/iomgr/tcp_server_posix_test.c +) + +target_include_directories(tcp_server_posix_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(tcp_server_posix_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(time_averaged_stats_test + test/core/iomgr/time_averaged_stats_test.c +) + +target_include_directories(time_averaged_stats_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(time_averaged_stats_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(timeout_encoding_test + test/core/transport/timeout_encoding_test.c +) + +target_include_directories(timeout_encoding_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(timeout_encoding_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(timer_heap_test + test/core/iomgr/timer_heap_test.c +) + +target_include_directories(timer_heap_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(timer_heap_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(timer_list_test + test/core/iomgr/timer_list_test.c +) + +target_include_directories(timer_list_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(timer_list_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_connectivity_state_test + test/core/transport/connectivity_state_test.c +) + +target_include_directories(transport_connectivity_state_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(transport_connectivity_state_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_metadata_test + test/core/transport/metadata_test.c +) + +target_include_directories(transport_metadata_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(transport_metadata_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_pid_controller_test + test/core/transport/pid_controller_test.c +) + +target_include_directories(transport_pid_controller_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(transport_pid_controller_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(transport_security_test + test/core/tsi/transport_security_test.c +) + +target_include_directories(transport_security_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(transport_security_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(udp_server_test + test/core/iomgr/udp_server_test.c +) + +target_include_directories(udp_server_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(udp_server_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(uri_parser_test + test/core/client_channel/uri_parser_test.c +) + +target_include_directories(uri_parser_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(uri_parser_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(wakeup_fd_cv_test + test/core/iomgr/wakeup_fd_cv_test.c +) + +target_include_directories(wakeup_fd_cv_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(wakeup_fd_cv_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(alarm_cpp_test + test/cpp/common/alarm_cpp_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(alarm_cpp_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(alarm_cpp_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(async_end2end_test + test/cpp/end2end/async_end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(async_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(async_end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(auth_property_iterator_test + test/cpp/common/auth_property_iterator_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(auth_property_iterator_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(auth_property_iterator_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bm_fullstack + test/cpp/microbenchmarks/bm_fullstack.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(bm_fullstack + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(bm_fullstack + benchmark + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(channel_arguments_test + test/cpp/common/channel_arguments_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(channel_arguments_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(channel_arguments_test + grpc++ + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(channel_filter_test + test/cpp/common/channel_filter_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(channel_filter_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(channel_filter_test + grpc++ + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(cli_call_test + test/cpp/util/cli_call_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(cli_call_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(cli_call_test + grpc_cli_libs + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(client_crash_test + test/cpp/end2end/client_crash_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(client_crash_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(client_crash_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(client_crash_test_server + test/cpp/end2end/client_crash_test_server.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(client_crash_test_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(client_crash_test_server + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(codegen_test_full + src/proto/grpc/testing/control.proto + src/proto/grpc/testing/messages.proto + src/proto/grpc/testing/payloads.proto + src/proto/grpc/testing/services.proto + src/proto/grpc/testing/stats.proto + test/cpp/codegen/codegen_test_full.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(codegen_test_full + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(codegen_test_full + grpc++ + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(codegen_test_minimal + src/proto/grpc/testing/control.proto + src/proto/grpc/testing/messages.proto + src/proto/grpc/testing/payloads.proto + src/proto/grpc/testing/services.proto + src/proto/grpc/testing/stats.proto + test/cpp/codegen/codegen_test_minimal.cc + src/cpp/codegen/codegen_init.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(codegen_test_minimal + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(codegen_test_minimal + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(credentials_test + test/cpp/client/credentials_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(credentials_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(credentials_test + grpc++ + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(cxx_byte_buffer_test + test/cpp/util/byte_buffer_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(cxx_byte_buffer_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(cxx_byte_buffer_test + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(cxx_slice_test + test/cpp/util/slice_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(cxx_slice_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(cxx_slice_test + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(cxx_string_ref_test + test/cpp/util/string_ref_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(cxx_string_ref_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(cxx_string_ref_test + grpc++ + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(cxx_time_test + test/cpp/util/time_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(cxx_time_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(cxx_time_test + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(end2end_test + test/cpp/end2end/end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(filter_end2end_test + test/cpp/end2end/filter_end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(filter_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(filter_end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(generic_end2end_test + test/cpp/end2end/generic_end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(generic_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(generic_end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(golden_file_test + src/proto/grpc/testing/compiler_test.proto + test/cpp/codegen/golden_file_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(golden_file_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(golden_file_test + grpc++ + grpc + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpc_cli + test/cpp/util/grpc_cli.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(grpc_cli + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(grpc_cli + grpc_cli_libs + grpc++_proto_reflection_desc_db + grpc++ + grpc + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) + +add_executable(grpc_cpp_plugin + src/compiler/cpp_plugin.cc +) + +target_include_directories(grpc_cpp_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_cpp_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_cpp_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_csharp_plugin + src/compiler/csharp_plugin.cc +) + +target_include_directories(grpc_csharp_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_csharp_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_csharp_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_node_plugin + src/compiler/node_plugin.cc +) + +target_include_directories(grpc_node_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_node_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_node_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_objective_c_plugin + src/compiler/objective_c_plugin.cc +) + +target_include_directories(grpc_objective_c_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_objective_c_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_objective_c_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_php_plugin + src/compiler/php_plugin.cc +) + +target_include_directories(grpc_php_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_php_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_php_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_python_plugin + src/compiler/python_plugin.cc +) + +target_include_directories(grpc_python_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_python_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_python_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + + +add_executable(grpc_ruby_plugin + src/compiler/ruby_plugin.cc +) + +target_include_directories(grpc_ruby_plugin + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(grpc_ruby_plugin + ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} + grpc_plugin_support +) + + +if (gRPC_INSTALL) + install(TARGETS grpc_ruby_plugin EXPORT gRPCTargets + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + ) +endif() + +if (gRPC_BUILD_TESTS) + +add_executable(grpc_tool_test + src/proto/grpc/testing/echo.proto + src/proto/grpc/testing/echo_messages.proto + test/cpp/util/grpc_tool_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(grpc_tool_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(grpc_tool_test + grpc_cli_libs + grpc++_proto_reflection_desc_db + grpc++_reflection + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpclb_api_test + src/proto/grpc/lb/v1/load_balancer.proto + test/cpp/grpclb/grpclb_api_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(grpclb_api_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(grpclb_api_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(grpclb_test + src/proto/grpc/lb/v1/load_balancer.proto + test/cpp/grpclb/grpclb_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(grpclb_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(grpclb_test + gpr + gpr_test_util + grpc + grpc++ + grpc++_test_util + grpc_test_util + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(http2_client + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(http2_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(http2_client + http2_client_main + grpc++_test_util + grpc_test_util + grpc++ + grpc + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(hybrid_end2end_test + test/cpp/end2end/hybrid_end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(hybrid_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(hybrid_end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(interop_client + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(interop_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(interop_client + interop_client_main + interop_client_helper + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(interop_server + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(interop_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(interop_server + interop_server_main + interop_server_helper + interop_server_lib + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(interop_test + test/cpp/interop/interop_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(interop_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(interop_test + grpc_test_util + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_run_localhost + test/cpp/qps/json_run_localhost.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(json_run_localhost + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(json_run_localhost + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(metrics_client + src/proto/grpc/testing/metrics.proto + test/cpp/interop/metrics_client.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(metrics_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(metrics_client + grpc++ + grpc + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(mock_test + test/cpp/end2end/mock_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(mock_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(mock_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(noop-benchmark + test/cpp/microbenchmarks/noop-benchmark.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(noop-benchmark + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(noop-benchmark + benchmark + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(proto_server_reflection_test + test/cpp/end2end/proto_server_reflection_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(proto_server_reflection_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(proto_server_reflection_test + grpc++_proto_reflection_desc_db + grpc++_reflection + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(qps_interarrival_test + test/cpp/qps/qps_interarrival_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(qps_interarrival_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(qps_interarrival_test + qps + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(qps_json_driver + test/cpp/qps/qps_json_driver.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(qps_json_driver + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(qps_json_driver + qps + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(qps_openloop_test + test/cpp/qps/qps_openloop_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(qps_openloop_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(qps_openloop_test + qps + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(qps_worker + test/cpp/qps/worker.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(qps_worker + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(qps_worker + qps + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(reconnect_interop_client + src/proto/grpc/testing/empty.proto + src/proto/grpc/testing/messages.proto + src/proto/grpc/testing/test.proto + test/cpp/interop/reconnect_interop_client.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(reconnect_interop_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(reconnect_interop_client + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(reconnect_interop_server + src/proto/grpc/testing/empty.proto + src/proto/grpc/testing/messages.proto + src/proto/grpc/testing/test.proto + test/cpp/interop/reconnect_interop_server.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(reconnect_interop_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(reconnect_interop_server + reconnect_server + test_tcp_server + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(round_robin_end2end_test + test/cpp/end2end/round_robin_end2end_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(round_robin_end2end_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(round_robin_end2end_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(secure_auth_context_test + test/cpp/common/secure_auth_context_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(secure_auth_context_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(secure_auth_context_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(secure_sync_unary_ping_pong_test + test/cpp/qps/secure_sync_unary_ping_pong_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(secure_sync_unary_ping_pong_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(secure_sync_unary_ping_pong_test + qps + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_builder_plugin_test + test/cpp/end2end/server_builder_plugin_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(server_builder_plugin_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(server_builder_plugin_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_context_test_spouse_test + test/cpp/test/server_context_test_spouse_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(server_context_test_spouse_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(server_context_test_spouse_test + grpc_test_util + grpc++_test + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_crash_test + test/cpp/end2end/server_crash_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(server_crash_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(server_crash_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_crash_test_client + test/cpp/end2end/server_crash_test_client.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(server_crash_test_client + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(server_crash_test_client + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(shutdown_test + test/cpp/end2end/shutdown_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(shutdown_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(shutdown_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(status_test + test/cpp/util/status_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(status_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(status_test + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(streaming_throughput_test + test/cpp/end2end/streaming_throughput_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(streaming_throughput_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(streaming_throughput_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(stress_test + src/proto/grpc/testing/empty.proto + src/proto/grpc/testing/messages.proto + src/proto/grpc/testing/metrics.proto + src/proto/grpc/testing/test.proto + test/cpp/interop/client_helper.cc + test/cpp/interop/interop_client.cc + test/cpp/interop/stress_interop_client.cc + test/cpp/interop/stress_test.cc + test/cpp/util/metrics_server.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(stress_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(stress_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(thread_manager_test + test/cpp/thread_manager/thread_manager_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(thread_manager_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(thread_manager_test + grpc++ + grpc + gpr + grpc++_test_config + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(thread_stress_test + test/cpp/end2end/thread_stress_test.cc + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(thread_stress_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(thread_stress_test + grpc++_test_util + grpc_test_util + grpc++ + grpc + gpr_test_util + gpr + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_aes_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_aes_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_aes_test + ${_gRPC_SSL_LIBRARIES} + boringssl_aes_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_asn1_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_asn1_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_asn1_test + ${_gRPC_SSL_LIBRARIES} + boringssl_asn1_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_base64_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_base64_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_base64_test + ${_gRPC_SSL_LIBRARIES} + boringssl_base64_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_bio_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_bio_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bio_test + ${_gRPC_SSL_LIBRARIES} + boringssl_bio_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_bn_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_bn_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bn_test + ${_gRPC_SSL_LIBRARIES} + boringssl_bn_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_bytestring_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_bytestring_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_bytestring_test + ${_gRPC_SSL_LIBRARIES} + boringssl_bytestring_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_aead_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_aead_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_aead_test + ${_gRPC_SSL_LIBRARIES} + boringssl_aead_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_cipher_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_cipher_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_cipher_test + ${_gRPC_SSL_LIBRARIES} + boringssl_cipher_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_cmac_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_cmac_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_cmac_test + ${_gRPC_SSL_LIBRARIES} + boringssl_cmac_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_constant_time_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_constant_time_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_constant_time_test + ${_gRPC_SSL_LIBRARIES} + boringssl_constant_time_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_ed25519_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ed25519_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ed25519_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ed25519_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_x25519_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_x25519_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_x25519_test + ${_gRPC_SSL_LIBRARIES} + boringssl_x25519_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_dh_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_dh_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_dh_test + ${_gRPC_SSL_LIBRARIES} + boringssl_dh_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_digest_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_digest_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_digest_test + ${_gRPC_SSL_LIBRARIES} + boringssl_digest_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_dsa_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_dsa_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_dsa_test + ${_gRPC_SSL_LIBRARIES} + boringssl_dsa_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_ec_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ec_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ec_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_example_mul + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_example_mul + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_example_mul + ${_gRPC_SSL_LIBRARIES} + boringssl_example_mul_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_ecdsa_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ecdsa_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ecdsa_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_err_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_err_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_err_test + ${_gRPC_SSL_LIBRARIES} + boringssl_err_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_evp_extra_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_evp_extra_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_evp_extra_test + ${_gRPC_SSL_LIBRARIES} + boringssl_evp_extra_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_evp_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_evp_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_evp_test + ${_gRPC_SSL_LIBRARIES} + boringssl_evp_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_pbkdf_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_pbkdf_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pbkdf_test + ${_gRPC_SSL_LIBRARIES} + boringssl_pbkdf_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_hkdf_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_hkdf_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_hkdf_test + ${_gRPC_SSL_LIBRARIES} + boringssl_hkdf_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_hmac_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_hmac_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_hmac_test + ${_gRPC_SSL_LIBRARIES} + boringssl_hmac_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_lhash_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_lhash_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_lhash_test + ${_gRPC_SSL_LIBRARIES} + boringssl_lhash_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_gcm_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_gcm_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_gcm_test + ${_gRPC_SSL_LIBRARIES} + boringssl_gcm_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_pkcs12_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_pkcs12_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pkcs12_test + ${_gRPC_SSL_LIBRARIES} + boringssl_pkcs12_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_pkcs8_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_pkcs8_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pkcs8_test + ${_gRPC_SSL_LIBRARIES} + boringssl_pkcs8_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_poly1305_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_poly1305_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_poly1305_test + ${_gRPC_SSL_LIBRARIES} + boringssl_poly1305_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_refcount_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_refcount_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_refcount_test + ${_gRPC_SSL_LIBRARIES} + boringssl_refcount_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_rsa_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_rsa_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_rsa_test + ${_gRPC_SSL_LIBRARIES} + boringssl_rsa_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_thread_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_thread_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_thread_test + ${_gRPC_SSL_LIBRARIES} + boringssl_thread_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_pkcs7_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_pkcs7_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pkcs7_test + ${_gRPC_SSL_LIBRARIES} + boringssl_pkcs7_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_x509_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_x509_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_x509_test + ${_gRPC_SSL_LIBRARIES} + boringssl_x509_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_tab_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_tab_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_tab_test + ${_gRPC_SSL_LIBRARIES} + boringssl_tab_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_v3name_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_v3name_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_v3name_test + ${_gRPC_SSL_LIBRARIES} + boringssl_v3name_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_pqueue_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_pqueue_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_pqueue_test + ${_gRPC_SSL_LIBRARIES} + boringssl_pqueue_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_ssl_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ssl_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ssl_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ssl_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(badreq_bad_client_test + test/core/bad_client/tests/badreq.c +) + +target_include_directories(badreq_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(badreq_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(connection_prefix_bad_client_test + test/core/bad_client/tests/connection_prefix.c +) + +target_include_directories(connection_prefix_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(connection_prefix_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(head_of_line_blocking_bad_client_test + test/core/bad_client/tests/head_of_line_blocking.c +) + +target_include_directories(head_of_line_blocking_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(head_of_line_blocking_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(headers_bad_client_test + test/core/bad_client/tests/headers.c +) + +target_include_directories(headers_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(headers_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(initial_settings_frame_bad_client_test + test/core/bad_client/tests/initial_settings_frame.c +) + +target_include_directories(initial_settings_frame_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(initial_settings_frame_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(large_metadata_bad_client_test + test/core/bad_client/tests/large_metadata.c +) + +target_include_directories(large_metadata_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(large_metadata_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(server_registered_method_bad_client_test + test/core/bad_client/tests/server_registered_method.c +) + +target_include_directories(server_registered_method_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(server_registered_method_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(simple_request_bad_client_test + test/core/bad_client/tests/simple_request.c +) + +target_include_directories(simple_request_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(simple_request_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(unknown_frame_bad_client_test + test/core/bad_client/tests/unknown_frame.c +) + +target_include_directories(unknown_frame_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(unknown_frame_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(window_overflow_bad_client_test + test/core/bad_client/tests/window_overflow.c +) + +target_include_directories(window_overflow_bad_client_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(window_overflow_bad_client_test + ${_gRPC_SSL_LIBRARIES} + bad_client_test + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bad_ssl_cert_server + test/core/bad_ssl/servers/cert.c +) + +target_include_directories(bad_ssl_cert_server + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bad_ssl_cert_server + bad_ssl_test_server + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(bad_ssl_cert_test + test/core/bad_ssl/bad_ssl_test.c +) + +target_include_directories(bad_ssl_cert_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(bad_ssl_cert_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_census_test + test/core/end2end/fixtures/h2_census.c +) + +target_include_directories(h2_census_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_census_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_compress_test + test/core/end2end/fixtures/h2_compress.c +) + +target_include_directories(h2_compress_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_compress_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_fakesec_test + test/core/end2end/fixtures/h2_fakesec.c +) + +target_include_directories(h2_fakesec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_fakesec_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_fd_test + test/core/end2end/fixtures/h2_fd.c +) + +target_include_directories(h2_fd_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_fd_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full_test + test/core/end2end/fixtures/h2_full.c +) + +target_include_directories(h2_full_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full+pipe_test + test/core/end2end/fixtures/h2_full+pipe.c +) + +target_include_directories(h2_full+pipe_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full+pipe_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full+trace_test + test/core/end2end/fixtures/h2_full+trace.c +) + +target_include_directories(h2_full+trace_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full+trace_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_http_proxy_test + test/core/end2end/fixtures/h2_http_proxy.c +) + +target_include_directories(h2_http_proxy_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_http_proxy_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_load_reporting_test + test/core/end2end/fixtures/h2_load_reporting.c +) + +target_include_directories(h2_load_reporting_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_load_reporting_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_oauth2_test + test/core/end2end/fixtures/h2_oauth2.c +) + +target_include_directories(h2_oauth2_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_oauth2_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_proxy_test + test/core/end2end/fixtures/h2_proxy.c +) + +target_include_directories(h2_proxy_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_proxy_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_sockpair_test + test/core/end2end/fixtures/h2_sockpair.c +) + +target_include_directories(h2_sockpair_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_sockpair_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_sockpair+trace_test + test/core/end2end/fixtures/h2_sockpair+trace.c +) + +target_include_directories(h2_sockpair+trace_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_sockpair+trace_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_sockpair_1byte_test + test/core/end2end/fixtures/h2_sockpair_1byte.c +) + +target_include_directories(h2_sockpair_1byte_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_sockpair_1byte_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_ssl_test + test/core/end2end/fixtures/h2_ssl.c +) + +target_include_directories(h2_ssl_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_ssl_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_ssl_cert_test + test/core/end2end/fixtures/h2_ssl_cert.c +) + +target_include_directories(h2_ssl_cert_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_ssl_cert_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_ssl_proxy_test + test/core/end2end/fixtures/h2_ssl_proxy.c +) + +target_include_directories(h2_ssl_proxy_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_ssl_proxy_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_uds_test + test/core/end2end/fixtures/h2_uds.c +) + +target_include_directories(h2_uds_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_uds_test + end2end_tests + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_census_nosec_test + test/core/end2end/fixtures/h2_census.c +) + +target_include_directories(h2_census_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_census_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_compress_nosec_test + test/core/end2end/fixtures/h2_compress.c +) + +target_include_directories(h2_compress_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_compress_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_fd_nosec_test + test/core/end2end/fixtures/h2_fd.c +) + +target_include_directories(h2_fd_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_fd_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full_nosec_test + test/core/end2end/fixtures/h2_full.c +) + +target_include_directories(h2_full_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full+pipe_nosec_test + test/core/end2end/fixtures/h2_full+pipe.c +) + +target_include_directories(h2_full+pipe_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full+pipe_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_full+trace_nosec_test + test/core/end2end/fixtures/h2_full+trace.c +) + +target_include_directories(h2_full+trace_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_full+trace_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_http_proxy_nosec_test + test/core/end2end/fixtures/h2_http_proxy.c +) + +target_include_directories(h2_http_proxy_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_http_proxy_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_load_reporting_nosec_test + test/core/end2end/fixtures/h2_load_reporting.c +) + +target_include_directories(h2_load_reporting_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(h2_load_reporting_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_proxy_nosec_test + test/core/end2end/fixtures/h2_proxy.c +) + +target_include_directories(h2_proxy_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_create_jwt - ${_gRPC_SSL_LIBRARIES} - grpc +target_link_libraries(h2_proxy_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_create_jwt EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() - - -add_executable(grpc_print_google_default_creds_token - test/core/security/print_google_default_creds_token.c +add_executable(h2_sockpair_nosec_test + test/core/end2end/fixtures/h2_sockpair.c ) -target_include_directories(grpc_print_google_default_creds_token +target_include_directories(h2_sockpair_nosec_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_print_google_default_creds_token - grpc +target_link_libraries(h2_sockpair_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_print_google_default_creds_token EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() - - -add_executable(grpc_verify_jwt - test/core/security/verify_jwt.c +add_executable(h2_sockpair+trace_nosec_test + test/core/end2end/fixtures/h2_sockpair+trace.c ) -target_include_directories(grpc_verify_jwt +target_include_directories(h2_sockpair+trace_nosec_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_verify_jwt - grpc +target_link_libraries(h2_sockpair+trace_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_verify_jwt EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(h2_sockpair_1byte_nosec_test + test/core/end2end/fixtures/h2_sockpair_1byte.c +) +target_include_directories(h2_sockpair_1byte_nosec_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) -add_executable(grpc_cpp_plugin - src/compiler/cpp_plugin.cc +target_link_libraries(h2_sockpair_1byte_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr ) -target_include_directories(grpc_cpp_plugin +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(h2_uds_nosec_test + test/core/end2end/fixtures/h2_uds.c +) + +target_include_directories(h2_uds_nosec_test PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_cpp_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(h2_uds_nosec_test + end2end_nosec_tests + grpc_test_util_unsecure + grpc_unsecure + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_cpp_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(api_fuzzer_one_entry + test/core/end2end/fuzzers/api_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(api_fuzzer_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) +target_link_libraries(api_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr +) -add_executable(grpc_csharp_plugin - src/compiler/csharp_plugin.cc +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(client_fuzzer_one_entry + test/core/end2end/fuzzers/client_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c ) -target_include_directories(grpc_csharp_plugin +target_include_directories(client_fuzzer_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_csharp_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(client_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_csharp_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(hpack_parser_fuzzer_test_one_entry + test/core/transport/chttp2/hpack_parser_fuzzer_test.c + test/core/util/one_corpus_entry_fuzzer.c +) +target_include_directories(hpack_parser_fuzzer_test_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) -add_executable(grpc_node_plugin - src/compiler/node_plugin.cc +target_link_libraries(hpack_parser_fuzzer_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) -target_include_directories(grpc_node_plugin +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(http_request_fuzzer_test_one_entry + test/core/http/request_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(http_request_fuzzer_test_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_node_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(http_request_fuzzer_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_node_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(http_response_fuzzer_test_one_entry + test/core/http/response_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) +target_include_directories(http_response_fuzzer_test_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) -add_executable(grpc_objective_c_plugin - src/compiler/objective_c_plugin.cc +target_link_libraries(http_response_fuzzer_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) -target_include_directories(grpc_objective_c_plugin +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(json_fuzzer_test_one_entry + test/core/json/fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(json_fuzzer_test_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_objective_c_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(json_fuzzer_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_objective_c_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(nanopb_fuzzer_response_test_one_entry + test/core/nanopb/fuzzer_response.c + test/core/util/one_corpus_entry_fuzzer.c +) +target_include_directories(nanopb_fuzzer_response_test_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) -add_executable(grpc_php_plugin - src/compiler/php_plugin.cc +target_link_libraries(nanopb_fuzzer_response_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) -target_include_directories(grpc_php_plugin +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(nanopb_fuzzer_serverlist_test_one_entry + test/core/nanopb/fuzzer_serverlist.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(nanopb_fuzzer_serverlist_test_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_php_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(nanopb_fuzzer_serverlist_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_php_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(percent_decode_fuzzer_one_entry + test/core/slice/percent_decode_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(percent_decode_fuzzer_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) +target_link_libraries(percent_decode_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr +) -add_executable(grpc_python_plugin - src/compiler/python_plugin.cc +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(percent_encode_fuzzer_one_entry + test/core/slice/percent_encode_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c ) -target_include_directories(grpc_python_plugin +target_include_directories(percent_encode_fuzzer_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_python_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(percent_encode_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_python_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(server_fuzzer_one_entry + test/core/end2end/fuzzers/server_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) +target_include_directories(server_fuzzer_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) -add_executable(grpc_ruby_plugin - src/compiler/ruby_plugin.cc +target_link_libraries(server_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) -target_include_directories(grpc_ruby_plugin +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(ssl_server_fuzzer_one_entry + test/core/security/ssl_server_fuzzer.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(ssl_server_fuzzer_one_entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include PRIVATE ${BORINGSSL_ROOT_DIR}/include PRIVATE ${PROTOBUF_ROOT_DIR}/src PRIVATE ${ZLIB_ROOT_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include ) -target_link_libraries(grpc_ruby_plugin - ${_gRPC_PROTOBUF_PROTOC_LIBRARIES} - grpc_plugin_support +target_link_libraries(ssl_server_fuzzer_one_entry + grpc_test_util + grpc + gpr_test_util + gpr ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) -if (gRPC_INSTALL) - install(TARGETS grpc_ruby_plugin EXPORT gRPCTargets - RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} - LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} - ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} - ) -endif() +add_executable(uri_fuzzer_test_one_entry + test/core/client_channel/uri_fuzzer_test.c + test/core/util/one_corpus_entry_fuzzer.c +) + +target_include_directories(uri_fuzzer_test_one_entry + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(uri_fuzzer_test_one_entry + grpc_test_util + grpc + gpr_test_util + gpr +) +endif (gRPC_BUILD_TESTS) From c7554240502d9dcf5a308def02b0c026adffdf50 Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Thu, 19 Jan 2017 10:31:47 +0100 Subject: [PATCH 234/261] fix building protoc artifacts on windows --- tools/run_tests/artifacts/build_artifact_protoc.bat | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/artifacts/build_artifact_protoc.bat b/tools/run_tests/artifacts/build_artifact_protoc.bat index fd93318833a..b2bf86da404 100644 --- a/tools/run_tests/artifacts/build_artifact_protoc.bat +++ b/tools/run_tests/artifacts/build_artifact_protoc.bat @@ -34,7 +34,7 @@ cd third_party/protobuf/cmake mkdir build & cd build mkdir solution & cd solution -cmake -G "%generator%" -Dprotobuf_BUILD_TESTS=OFF ../../.. || goto :error +cmake -G "%generator%" -Dprotobuf_BUILD_TESTS=OFF ../.. || goto :error endlocal call vsprojects/build_plugins.bat || goto :error From f0e17783ae74427a7cdb454eefabe02a28376b5f Mon Sep 17 00:00:00 2001 From: "Mark D. Roth" Date: Thu, 19 Jan 2017 08:41:15 -0800 Subject: [PATCH 235/261] Add ChannelArguments methods for setting max send/recv message size. --- include/grpc++/support/channel_arguments.h | 4 ++++ src/cpp/common/channel_arguments.cc | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/include/grpc++/support/channel_arguments.h b/include/grpc++/support/channel_arguments.h index d43f7c61bdd..efdf7772ad7 100644 --- a/include/grpc++/support/channel_arguments.h +++ b/include/grpc++/support/channel_arguments.h @@ -88,6 +88,10 @@ class ChannelArguments { /// The given buffer pool will be attached to the constructed channel void SetResourceQuota(const ResourceQuota& resource_quota); + /// Sets the max receive and send message sizes. + void SetMaxReceiveMessageSize(int size); + void SetMaxSendMessageSize(int size); + /// Set LB policy name. /// Note that if the name resolver returns only balancer addresses, the /// grpclb LB policy will be used, regardless of what is specified here. diff --git a/src/cpp/common/channel_arguments.cc b/src/cpp/common/channel_arguments.cc index 1fdd1061303..65f32774999 100644 --- a/src/cpp/common/channel_arguments.cc +++ b/src/cpp/common/channel_arguments.cc @@ -143,6 +143,14 @@ void ChannelArguments::SetResourceQuota( grpc_resource_quota_arg_vtable()); } +void ChannelArguments::SetMaxReceiveMessageSize(int size) { + SetInt(GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH, size); +} + +void ChannelArguments::SetMaxSendMessageSize(int size) { + SetInt(GRPC_ARG_MAX_SEND_MESSAGE_LENGTH, size); +} + void ChannelArguments::SetLoadBalancingPolicyName( const grpc::string& lb_policy_name) { SetString(GRPC_ARG_LB_POLICY_NAME, lb_policy_name); From 20115614e1ebbdfb8a3711d425f6edd6cd964734 Mon Sep 17 00:00:00 2001 From: yang-g Date: Thu, 19 Jan 2017 10:57:56 -0800 Subject: [PATCH 236/261] Stop generating method name array when there is no method. --- src/compiler/cpp_generator.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/compiler/cpp_generator.cc b/src/compiler/cpp_generator.cc index a26eeb46b95..e481aaf811b 100644 --- a/src/compiler/cpp_generator.cc +++ b/src/compiler/cpp_generator.cc @@ -1218,13 +1218,15 @@ void PrintSourceService(Printer *printer, const Service *service, std::map *vars) { (*vars)["Service"] = service->name(); - printer->Print(*vars, - "static const char* $prefix$$Service$_method_names[] = {\n"); - for (int i = 0; i < service->method_count(); ++i) { - (*vars)["Method"] = service->method(i).get()->name(); - printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); + if (service->method_count() > 0) { + printer->Print(*vars, + "static const char* $prefix$$Service$_method_names[] = {\n"); + for (int i = 0; i < service->method_count(); ++i) { + (*vars)["Method"] = service->method(i).get()->name(); + printer->Print(*vars, " \"/$Package$$Service$/$Method$\",\n"); + } + printer->Print(*vars, "};\n\n"); } - printer->Print(*vars, "};\n\n"); printer->Print(*vars, "std::unique_ptr< $ns$$Service$::Stub> $ns$$Service$::NewStub(" @@ -1272,7 +1274,6 @@ void PrintSourceService(Printer *printer, const Service *service, printer->Print(*vars, "$ns$$Service$::Service::Service() {\n"); printer->Indent(); - printer->Print(*vars, "(void)$prefix$$Service$_method_names;\n"); for (int i = 0; i < service->method_count(); ++i) { auto method = service->method(i); (*vars)["Idx"] = as_string(i); From af2c01e73e265265c6e30aa2fef5f9768f6a1d9f Mon Sep 17 00:00:00 2001 From: ncteisen Date: Wed, 18 Jan 2017 17:06:24 -0800 Subject: [PATCH 237/261] Expect INTERNAL in Python negative interop client The test now expects to receive StatusCode.INTERNAL when it receives a RST_STREAM from the server in order to comply with https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md Also added wait for ready behavior on the client channel. --- ...ative_http2_client.py => negative_http2_client.py} | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) rename src/python/grpcio_tests/tests/http2/{_negative_http2_client.py => negative_http2_client.py} (94%) diff --git a/src/python/grpcio_tests/tests/http2/_negative_http2_client.py b/src/python/grpcio_tests/tests/http2/negative_http2_client.py similarity index 94% rename from src/python/grpcio_tests/tests/http2/_negative_http2_client.py rename to src/python/grpcio_tests/tests/http2/negative_http2_client.py index c192d827c40..b8adf093a56 100644 --- a/src/python/grpcio_tests/tests/http2/_negative_http2_client.py +++ b/src/python/grpcio_tests/tests/http2/negative_http2_client.py @@ -82,20 +82,22 @@ def _goaway(stub): def _rst_after_header(stub): resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNAVAILABLE, - "") + _validate_status_code_and_details(resp_future, grpc.StatusCode.INTERNAL, + "Received RST_STREAM with error code 0") def _rst_during_data(stub): resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + _validate_status_code_and_details(resp_future, grpc.StatusCode.INTERNAL, + "Received RST_STREAM with error code 0") def _rst_after_data(stub): resp_future = stub.UnaryCall.future(_SIMPLE_REQUEST) _validate_payload_type_and_length( next(resp_future), messages_pb2.COMPRESSABLE, _RESPONSE_SIZE) - _validate_status_code_and_details(resp_future, grpc.StatusCode.UNKNOWN, "") + _validate_status_code_and_details(resp_future, grpc.StatusCode.INTERNAL, + "Received RST_STREAM with error code 0") def _ping(stub): @@ -159,6 +161,7 @@ def _args(): def _stub(server_host, server_port): target = '{}:{}'.format(server_host, server_port) channel = grpc.insecure_channel(target) + grpc.channel_ready_future(channel).result() return test_pb2.TestServiceStub(channel) From d9ed84f66e165221124cefe76202f85f9a121092 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Thu, 19 Jan 2017 22:30:52 +0000 Subject: [PATCH 238/261] Doc string fix and tweaks In those places where we return an object that implements two interfaces (let's say P and Q), consistently describe it as a "P-Q" rather than once mentioning that it is a P and describing it as a "Q" for the rest of prose. --- src/python/grpcio/grpc/__init__.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/python/grpcio/grpc/__init__.py b/src/python/grpcio/grpc/__init__.py index abe14e70498..fe299717992 100644 --- a/src/python/grpcio/grpc/__init__.py +++ b/src/python/grpcio/grpc/__init__.py @@ -487,9 +487,9 @@ class UnaryUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: An object that is both a Call for the RPC and a Future. In the event of - RPC completion, the return Future's result value will be the response - message of the RPC. Should the event terminate with non-OK status, the - returned Future's exception value will be an RpcError. + RPC completion, the return Call-Future's result value will be the + response message of the RPC. Should the event terminate with non-OK + status, the returned Call-Future's exception value will be an RpcError. """ raise NotImplementedError() @@ -510,8 +510,8 @@ class UnaryStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - RpcError indicating termination of the RPC with non-OK status. + values. Drawing response values from the returned Call-iterator may + raise RpcError indicating termination of the RPC with non-OK status. """ raise NotImplementedError() @@ -535,8 +535,7 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): credentials: An optional CallCredentials for the RPC. Returns: - The response value for the RPC, and a Call for the RPC if with_call was - set to True at invocation. + The response value for the RPC. Raises: RpcError: Indicating that the RPC terminated with non-OK status. The @@ -587,9 +586,9 @@ class StreamUnaryMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: An object that is both a Call for the RPC and a Future. In the event of - RPC completion, the return Future's result value will be the response - message of the RPC. Should the event terminate with non-OK status, the - returned Future's exception value will be an RpcError. + RPC completion, the return Call-Future's result value will be the + response message of the RPC. Should the event terminate with non-OK + status, the returned Call-Future's exception value will be an RpcError. """ raise NotImplementedError() @@ -614,8 +613,8 @@ class StreamStreamMultiCallable(six.with_metaclass(abc.ABCMeta)): Returns: An object that is both a Call for the RPC and an iterator of response - values. Drawing response values from the returned iterator may raise - RpcError indicating termination of the RPC with non-OK status. + values. Drawing response values from the returned Call-iterator may + raise RpcError indicating termination of the RPC with non-OK status. """ raise NotImplementedError() From 876008493b9b48d9c70464d68460e4540d35441b Mon Sep 17 00:00:00 2001 From: ncteisen Date: Thu, 19 Jan 2017 15:40:00 -0800 Subject: [PATCH 239/261] Regenerate project --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c5a1927c92e..4fee13da043 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9080,10 +9080,10 @@ add_executable(stress_test src/proto/grpc/testing/messages.proto src/proto/grpc/testing/metrics.proto src/proto/grpc/testing/test.proto - test/cpp/interop/client_helper.cc test/cpp/interop/interop_client.cc test/cpp/interop/stress_interop_client.cc test/cpp/interop/stress_test.cc + test/cpp/util/create_test_channel.cc test/cpp/util/metrics_server.cc third_party/googletest/src/gtest-all.cc ) From c4d10dfb1b65f6e559db55ad8448ab37fc8d4fa8 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Wed, 18 Jan 2017 17:47:52 -0800 Subject: [PATCH 240/261] Fix Python memory errors ... but for real this time. --- .../grpc/_cython/_cygrpc/channel.pyx.pxi | 19 +-- .../_cython/_cygrpc/completion_queue.pyx.pxi | 10 +- .../grpc/_cython/_cygrpc/records.pxd.pxi | 24 +-- .../grpc/_cython/_cygrpc/records.pyx.pxi | 144 +++++++----------- 4 files changed, 84 insertions(+), 113 deletions(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index e4c24a83abd..246e8399bc9 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -60,24 +60,25 @@ cdef class Channel: method, host, Timespec deadline not None): if queue.is_shutting_down: raise ValueError("queue must not be shutting down or shutdown") - cdef Slice method_slice = Slice.from_bytes(method) - cdef Slice host_slice - cdef grpc_slice *host_c_slice = NULL + cdef grpc_slice method_slice = _slice_from_bytes(method) + cdef grpc_slice host_slice + cdef grpc_slice *host_slice_ptr = NULL if host is not None: - host_slice = Slice.from_bytes(host) - host_c_slice = &host_slice.c_slice - else: - host_slice = Slice() + host_slice = _slice_from_bytes(host) + host_slice_ptr = &host_slice cdef Call operation_call = Call() - operation_call.references = [self, method_slice, host_slice, queue] + operation_call.references = [self, queue] cdef grpc_call *parent_call = NULL if parent is not None: parent_call = parent.c_call with nogil: operation_call.c_call = grpc_channel_create_call( self.c_channel, parent_call, flags, - queue.c_completion_queue, method_slice.c_slice, host_c_slice, + queue.c_completion_queue, method_slice, host_slice_ptr, deadline.c_time, NULL) + grpc_slice_unref(method_slice) + if host_slice_ptr: + grpc_slice_unref(host_slice) return operation_call def check_connectivity_state(self, bint try_to_connect): diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index 2b5cce88a4f..d8df6c2ef40 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -51,6 +51,7 @@ cdef class CompletionQueue: cdef CallDetails request_call_details = None cdef Metadata request_metadata = None cdef Operations batch_operations = None + cdef Operation batch_operation = None if event.type == GRPC_QUEUE_TIMEOUT: return Event( event.type, False, None, None, None, None, False, None) @@ -69,10 +70,15 @@ cdef class CompletionQueue: user_tag = tag.user_tag operation_call = tag.operation_call request_call_details = tag.request_call_details - request_metadata = tag.request_metadata - if request_metadata is not None: + if tag.request_metadata is not None: + request_metadata = tag.request_metadata request_metadata._claim_slice_ownership() batch_operations = tag.batch_operations + if tag.batch_operations is not None: + for op in batch_operations.operations: + batch_operation = op + if batch_operation._received_metadata is not None: + batch_operation._received_metadata._claim_slice_ownership() if tag.is_new_request: # Stuff in the tag not explicitly handled by us needs to live through # the life of the call diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index e9276053845..c4a17118c0e 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -28,6 +28,11 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +cdef bytes _slice_bytes(grpc_slice slice) +cdef grpc_slice _copy_slice(grpc_slice slice) nogil +cdef grpc_slice _slice_from_bytes(bytes value) nogil + + cdef class Timespec: cdef gpr_timespec c_time @@ -70,17 +75,6 @@ cdef class Event: cdef readonly Operations batch_operations -cdef class Slice: - - cdef grpc_slice c_slice - - cdef void _assign_slice(self, grpc_slice new_slice) nogil - @staticmethod - cdef Slice from_slice(grpc_slice slice) - @staticmethod - cdef bytes bytes_from_slice(grpc_slice slice) - - cdef class ByteBuffer: cdef grpc_byte_buffer *c_byte_buffer @@ -108,17 +102,13 @@ cdef class ChannelArgs: cdef class Metadatum: cdef grpc_metadata c_metadata - cdef Slice _key, - cdef Slice _value + cdef void _copy_metadatum(self, grpc_metadata *destination) nogil cdef class Metadata: cdef grpc_metadata_array c_metadata_array - cdef bint owns_metadata_slices - cdef object metadata cdef void _claim_slice_ownership(self) - cdef void _drop_slice_ownership(self) cdef class Operation: @@ -127,7 +117,7 @@ cdef class Operation: cdef ByteBuffer _received_message cdef Metadata _received_metadata cdef grpc_status_code _received_status_code - cdef Slice _received_status_details + cdef grpc_slice _status_details cdef int _received_cancelled cdef readonly bint is_valid cdef object references diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index d7a77133325..d052b3f8bc9 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -29,6 +29,26 @@ from libc.stdint cimport intptr_t + +cdef bytes _slice_bytes(grpc_slice slice): + cdef void *start = grpc_slice_start_ptr(slice) + cdef size_t length = grpc_slice_length(slice) + return (start)[:length] + +cdef grpc_slice _copy_slice(grpc_slice slice) nogil: + cdef void *start = grpc_slice_start_ptr(slice) + cdef size_t length = grpc_slice_length(slice) + return grpc_slice_from_copied_buffer(start, length) + +cdef grpc_slice _slice_from_bytes(bytes value) nogil: + cdef const char *value_ptr + cdef size_t length + with gil: + value_ptr = value + length = len(value) + return grpc_slice_from_copied_buffer(value_ptr, length) + + class ConnectivityState: idle = GRPC_CHANNEL_IDLE connecting = GRPC_CHANNEL_CONNECTING @@ -189,11 +209,11 @@ cdef class CallDetails: @property def method(self): - return Slice.bytes_from_slice(self.c_details.method) + return _slice_bytes(self.c_details.method) @property def host(self): - return Slice.bytes_from_slice(self.c_details.host) + return _slice_bytes(self.c_details.host) @property def deadline(self): @@ -227,46 +247,6 @@ cdef class Event: self.is_new_request = is_new_request -cdef class Slice: - - def __cinit__(self): - with nogil: - grpc_init() - self.c_slice = grpc_empty_slice() - - cdef void _assign_slice(self, grpc_slice new_slice) nogil: - grpc_slice_unref(self.c_slice) - self.c_slice = new_slice - - @staticmethod - def from_bytes(bytes data): - cdef Slice self = Slice() - self._assign_slice(grpc_slice_from_copied_buffer(data, len(data))) - return self - - @staticmethod - cdef Slice from_slice(grpc_slice slice): - cdef Slice self = Slice() - grpc_slice_ref(slice) - self._assign_slice(slice) - return self - - @staticmethod - cdef bytes bytes_from_slice(grpc_slice slice): - with nogil: - pointer = grpc_slice_start_ptr(slice) - length = grpc_slice_length(slice) - return (pointer)[:length] - - def bytes(self): - return Slice.bytes_from_slice(self.c_slice) - - def __dealloc__(self): - with nogil: - grpc_slice_unref(self.c_slice) - grpc_shutdown() - - cdef class ByteBuffer: def __cinit__(self, bytes data): @@ -416,20 +396,21 @@ cdef class ChannelArgs: cdef class Metadatum: - # TODO(atash) this should just accept Slice objects. def __cinit__(self, bytes key, bytes value): - self._key = Slice.from_bytes(key) - self._value = Slice.from_bytes(value) - self.c_metadata.key = self._key.c_slice - self.c_metadata.value = self._value.c_slice + self.c_metadata.key = _slice_from_bytes(key) + self.c_metadata.value = _slice_from_bytes(value) + + cdef void _copy_metadatum(self, grpc_metadata *destination) nogil: + destination[0].key = _copy_slice(self.c_metadata.key) + destination[0].value = _copy_slice(self.c_metadata.value) @property def key(self): - return self._key.bytes() + return _slice_bytes(self.c_metadata.key) @property def value(self): - return self._value.bytes() + return _slice_bytes(self.c_metadata.value) def __len__(self): return 2 @@ -445,6 +426,9 @@ cdef class Metadatum: def __iter__(self): return iter((self.key, self.value)) + def __dealloc__(self): + grpc_slice_unref(self.c_metadata.key) + grpc_slice_unref(self.c_metadata.value) cdef class _MetadataIterator: @@ -466,34 +450,27 @@ cdef class _MetadataIterator: else: raise StopIteration -cdef grpc_slice _copy_slice(grpc_slice slice) nogil: - cdef void *start = grpc_slice_start_ptr(slice) - cdef size_t length = grpc_slice_length(slice) - return grpc_slice_from_copied_buffer(start, length) cdef class Metadata: - def __cinit__(self, metadata): + def __cinit__(self, metadata_iterable): with nogil: grpc_init() grpc_metadata_array_init(&self.c_metadata_array) - self.owns_metadata_slices = False - self.metadata = list(metadata) - for metadatum in self.metadata: + metadata = list(metadata_iterable) + for metadatum in metadata: if not isinstance(metadatum, Metadatum): raise TypeError("expected list of Metadatum") - self.c_metadata_array.count = len(self.metadata) - self.c_metadata_array.capacity = len(self.metadata) + self.c_metadata_array.count = len(metadata) + self.c_metadata_array.capacity = len(metadata) with nogil: self.c_metadata_array.metadata = gpr_malloc( self.c_metadata_array.count*sizeof(grpc_metadata) ) for i in range(self.c_metadata_array.count): - self.c_metadata_array.metadata[i] = ( - (self.metadata[i]).c_metadata) + (metadata[i])._copy_metadatum(&self.c_metadata_array.metadata[i]) def __dealloc__(self): - self._drop_slice_ownership() with nogil: # this frees the allocated memory for the grpc_metadata_array (although # it'd be nice if that were documented somewhere...) @@ -507,30 +484,26 @@ cdef class Metadata: def __getitem__(self, size_t i): if i >= self.c_metadata_array.count: raise IndexError - return Metadatum( - key=Slice.bytes_from_slice(self.c_metadata_array.metadata[i].key), - value=Slice.bytes_from_slice(self.c_metadata_array.metadata[i].value)) + key = _slice_bytes(self.c_metadata_array.metadata[i].key) + value = _slice_bytes(self.c_metadata_array.metadata[i].value) + return Metadatum(key=key, value=value) def __iter__(self): return _MetadataIterator(self) cdef void _claim_slice_ownership(self): - if self.owns_metadata_slices: - return + cdef grpc_metadata_array new_c_metadata_array + grpc_metadata_array_init(&new_c_metadata_array) + new_c_metadata_array.metadata = gpr_malloc( + self.c_metadata_array.count*sizeof(grpc_metadata)) + new_c_metadata_array.count = self.c_metadata_array.count for i in range(self.c_metadata_array.count): - self.c_metadata_array.metadata[i].key = _copy_slice( + new_c_metadata_array.metadata[i].key = _copy_slice( self.c_metadata_array.metadata[i].key) - self.c_metadata_array.metadata[i].value = _copy_slice( + new_c_metadata_array.metadata[i].value = _copy_slice( self.c_metadata_array.metadata[i].value) - self.owns_metadata_slices = True - - cdef void _drop_slice_ownership(self): - if not self.owns_metadata_slices: - return - for i in range(self.c_metadata_array.count): - grpc_slice_unref(self.c_metadata_array.metadata[i].key) - grpc_slice_unref(self.c_metadata_array.metadata[i].value) - self.owns_metadata_slices = False + grpc_metadata_array_destroy(&self.c_metadata_array) + self.c_metadata_array = new_c_metadata_array cdef class Operation: @@ -538,7 +511,7 @@ cdef class Operation: def __cinit__(self): grpc_init() self.references = [] - self._received_status_details = Slice() + self._status_details = grpc_empty_slice() self.is_valid = False @property @@ -595,13 +568,13 @@ cdef class Operation: def received_status_details(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: raise TypeError("self must be an operation receiving status details") - return self._received_status_details.bytes() + return _slice_bytes(self._status_details) @property def received_status_details_or_none(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: return None - return self._received_status_details.bytes() + return _slice_bytes(self._status_details) @property def received_cancelled(self): @@ -617,6 +590,7 @@ cdef class Operation: return False if self._received_cancelled == 0 else True def __dealloc__(self): + grpc_slice_unref(self._status_details) grpc_shutdown() def operation_send_initial_metadata(Metadata metadata, int flags): @@ -657,10 +631,10 @@ def operation_send_status_from_server( op.c_op.data.send_status_from_server.trailing_metadata = ( metadata.c_metadata_array.metadata) op.c_op.data.send_status_from_server.status = code - cdef Slice details_slice = Slice.from_bytes(details) - op.c_op.data.send_status_from_server.status_details = &details_slice.c_slice + grpc_slice_unref(op._status_details) + op._status_details = _slice_from_bytes(details) + op.c_op.data.send_status_from_server.status_details = &op._status_details op.references.append(metadata) - op.references.append(details_slice) op.is_valid = True return op @@ -696,7 +670,7 @@ def operation_receive_status_on_client(int flags): op.c_op.data.receive_status_on_client.status = ( &op._received_status_code) op.c_op.data.receive_status_on_client.status_details = ( - &op._received_status_details.c_slice) + &op._status_details) op.is_valid = True return op From 66122b2c0594b294a643f35811c0a9a0b3174d00 Mon Sep 17 00:00:00 2001 From: Matt Kwong Date: Fri, 9 Dec 2016 16:34:01 -0800 Subject: [PATCH 241/261] Add all the other fuzzer tests to internal CI --- tools/internal_ci/linux/grpc_fuzzer_api.cfg | 40 ++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_api.sh | 41 ++++++++++++++++++ .../linux/grpc_fuzzer_hpack_parser.cfg | 40 ++++++++++++++++++ .../linux/grpc_fuzzer_hpack_parser.sh | 42 +++++++++++++++++++ .../linux/grpc_fuzzer_http_request.cfg | 40 ++++++++++++++++++ .../linux/grpc_fuzzer_http_request.sh | 42 +++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_json.cfg | 40 ++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_json.sh | 42 +++++++++++++++++++ .../linux/grpc_fuzzer_nanopb_response.cfg | 40 ++++++++++++++++++ .../linux/grpc_fuzzer_nanopb_response.sh | 41 ++++++++++++++++++ .../internal_ci/linux/grpc_fuzzer_server.cfg | 40 ++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_server.sh | 41 ++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_uri.cfg | 40 ++++++++++++++++++ tools/internal_ci/linux/grpc_fuzzer_uri.sh | 41 ++++++++++++++++++ 14 files changed, 570 insertions(+) create mode 100644 tools/internal_ci/linux/grpc_fuzzer_api.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_api.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_hpack_parser.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_http_request.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_http_request.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_json.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_json.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_nanopb_response.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_server.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_server.sh create mode 100644 tools/internal_ci/linux/grpc_fuzzer_uri.cfg create mode 100755 tools/internal_ci/linux/grpc_fuzzer_uri.sh diff --git a/tools/internal_ci/linux/grpc_fuzzer_api.cfg b/tools/internal_ci/linux/grpc_fuzzer_api.cfg new file mode 100644 index 00000000000..a34fb9d47ed --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_api.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_api.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_api.sh b/tools/internal_ci/linux/grpc_fuzzer_api.sh new file mode 100755 index 00000000000..c3cf1109de4 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_api.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp runtime=86400 tools/jenkins/run_fuzzer.sh api_fuzzer diff --git a/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.cfg b/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.cfg new file mode 100644 index 00000000000..215ce2bf9c6 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh b/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh new file mode 100755 index 00000000000..d9a73a622ba --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_hpack_parser.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp tools/jenkins/run_fuzzer.sh hpack_parser_fuzzer_test + diff --git a/tools/internal_ci/linux/grpc_fuzzer_http_request.cfg b/tools/internal_ci/linux/grpc_fuzzer_http_request.cfg new file mode 100644 index 00000000000..120e8f8f760 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_http_request.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_http_request.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_http_request.sh b/tools/internal_ci/linux/grpc_fuzzer_http_request.sh new file mode 100755 index 00000000000..d412d921ba9 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_http_request.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp tools/jenkins/run_fuzzer.sh http_request_fuzzer_test + diff --git a/tools/internal_ci/linux/grpc_fuzzer_json.cfg b/tools/internal_ci/linux/grpc_fuzzer_json.cfg new file mode 100644 index 00000000000..cab4f293ed4 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_json.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_json.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_json.sh b/tools/internal_ci/linux/grpc_fuzzer_json.sh new file mode 100755 index 00000000000..d9869f6c302 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_json.sh @@ -0,0 +1,42 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp tools/jenkins/run_fuzzer.sh json_fuzzer_test + diff --git a/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.cfg b/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.cfg new file mode 100644 index 00000000000..c73aa819eee --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh b/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh new file mode 100755 index 00000000000..0a7187f8bf2 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_nanopb_response.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp tools/jenkins/run_fuzzer.sh nanopb_fuzzer_response_test diff --git a/tools/internal_ci/linux/grpc_fuzzer_server.cfg b/tools/internal_ci/linux/grpc_fuzzer_server.cfg new file mode 100644 index 00000000000..a1931cb8916 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_server.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_server.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_server.sh b/tools/internal_ci/linux/grpc_fuzzer_server.sh new file mode 100755 index 00000000000..e00e940382e --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_server.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp runtime=86400 tools/jenkins/run_fuzzer.sh server_fuzzer diff --git a/tools/internal_ci/linux/grpc_fuzzer_uri.cfg b/tools/internal_ci/linux/grpc_fuzzer_uri.cfg new file mode 100644 index 00000000000..c312ae04645 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_uri.cfg @@ -0,0 +1,40 @@ +#!/bin/bash +# 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. + +# Config file for the internal CI (in protobuf text format) + +# Location of the continuous shell script in repository. +build_file: "grpc/tools/internal_ci/linux/grpc_fuzzer_uri.sh" +timeout_mins: 1440 # 24 hours is the maximum allowed value +action { + define_artifacts { + regex: "git/grpc/fuzzer_output/**" + } +} diff --git a/tools/internal_ci/linux/grpc_fuzzer_uri.sh b/tools/internal_ci/linux/grpc_fuzzer_uri.sh new file mode 100755 index 00000000000..4137f8061c5 --- /dev/null +++ b/tools/internal_ci/linux/grpc_fuzzer_uri.sh @@ -0,0 +1,41 @@ +#!/bin/bash +# 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. + +set -ex + +# change to grpc repo root +cd $(dirname $0)/../../.. + +git submodule update --init + +# download fuzzer docker image from dockerhub +export DOCKERHUB_ORGANIZATION=grpctesting +# runtime 23 * 60 mins +config=asan-trace-cmp tools/jenkins/run_fuzzer.sh uri_fuzzer_test From f575369d054c358543ccc431d3ad84d83fc2114d Mon Sep 17 00:00:00 2001 From: Julien Boeuf Date: Thu, 19 Jan 2017 21:29:00 -0800 Subject: [PATCH 242/261] Fixing msan issue in client_ssl.c See this error (somehow triggered by a new version of boringssl): https://grpc-testing.appspot.com/job/gRPC_pull_requests_msan_c/1154/testReport/junit/(root)/c_linux_msan/bins_msan_handshake_client_GRPC_POLL_STRATEGY_poll_cv/ In the alpn callback, in_len is the size of the in buffer and not the number of alpn elements. --- test/core/handshake/client_ssl.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/core/handshake/client_ssl.c b/test/core/handshake/client_ssl.c index 24281e0b418..613251b8355 100644 --- a/test/core/handshake/client_ssl.c +++ b/test/core/handshake/client_ssl.c @@ -104,7 +104,8 @@ static int alpn_select_cb(SSL *ssl, const uint8_t **out, uint8_t *out_len, bool grpc_exp_seen = false; bool h2_seen = false; const char *inp = (const char *)in; - for (int i = 0; i < (int)in_len; ++i) { + const char *in_end = inp + in_len; + while (inp < in_end) { const size_t length = (size_t)*inp++; if (length == strlen("grpc-exp") && strncmp(inp, "grpc-exp", length) == 0) { grpc_exp_seen = true; @@ -117,6 +118,7 @@ static int alpn_select_cb(SSL *ssl, const uint8_t **out, uint8_t *out_len, inp += length; } + GPR_ASSERT(inp == in_end); GPR_ASSERT(grpc_exp_seen); GPR_ASSERT(h2_seen); From 0f5b400fa435d9fffccf2aee12acba76e7b1a9e0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Jan 2017 08:54:56 -0800 Subject: [PATCH 243/261] Fix Python test --- src/core/ext/transport/chttp2/transport/chttp2_transport.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 8e213f8404f..2004bc6437e 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -1567,6 +1567,7 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, int close_writes, grpc_error *error) { if (s->read_closed && s->write_closed) { /* already closed */ + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_ERROR_UNREF(error); return; } From b39942f06fe0b256c5053b93084216625a38938e Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 12 Jan 2017 21:31:07 -0800 Subject: [PATCH 244/261] Update boringssl to latest chromium-stable --- Makefile | 719 +++++++++- binding.gyp | 41 +- config.m4 | 43 +- grpc.gemspec | 58 +- package.xml | 58 +- src/boringssl/err_data.c | 1266 +++++++++-------- src/python/grpcio/grpc_core_dependencies.py | 41 +- third_party/boringssl | 2 +- .../generated/sources_and_headers.json | 291 +++- tools/run_tests/generated/tests.json | 248 +++- tools/run_tests/sanity/check_submodules.sh | 2 +- .../vcxproj/boringssl/boringssl.vcxproj | 93 +- .../boringssl/boringssl.vcxproj.filters | 170 +-- .../boringssl_chacha_test.vcxproj} | 10 +- .../boringssl_chacha_test.vcxproj.filters} | 0 .../boringssl_chacha_test_lib.vcxproj | 170 +++ .../boringssl_chacha_test_lib.vcxproj.filters | 24 + .../boringssl_ecdh_test.vcxproj | 198 +++ .../boringssl_ecdh_test.vcxproj.filters | 7 + .../boringssl_ecdh_test_lib.vcxproj} | 8 +- .../boringssl_ecdh_test_lib.vcxproj.filters | 24 + .../boringssl_ecdsa_sign_test.vcxproj | 198 +++ .../boringssl_ecdsa_sign_test.vcxproj.filters | 7 + .../boringssl_ecdsa_sign_test_lib.vcxproj | 170 +++ ...ingssl_ecdsa_sign_test_lib.vcxproj.filters | 24 + .../boringssl_ecdsa_verify_test.vcxproj | 198 +++ ...oringssl_ecdsa_verify_test.vcxproj.filters | 7 + .../boringssl_ecdsa_verify_test_lib.vcxproj | 170 +++ ...gssl_ecdsa_verify_test_lib.vcxproj.filters | 24 + .../boringssl_gcm_test_lib.vcxproj | 2 +- .../boringssl_gcm_test_lib.vcxproj.filters | 2 +- ...boringssl_newhope_statistical_test.vcxproj | 198 +++ ...l_newhope_statistical_test.vcxproj.filters | 7 + ...ngssl_newhope_statistical_test_lib.vcxproj | 170 +++ ...whope_statistical_test_lib.vcxproj.filters | 24 + .../boringssl_newhope_test.vcxproj | 198 +++ .../boringssl_newhope_test.vcxproj.filters | 7 + .../boringssl_newhope_test_lib.vcxproj | 170 +++ ...boringssl_newhope_test_lib.vcxproj.filters | 24 + .../boringssl_newhope_vectors_test.vcxproj | 198 +++ ...ngssl_newhope_vectors_test.vcxproj.filters | 7 + ...boringssl_newhope_vectors_test_lib.vcxproj | 170 +++ ...l_newhope_vectors_test_lib.vcxproj.filters | 24 + .../boringssl_obj_test.vcxproj | 198 +++ .../boringssl_obj_test.vcxproj.filters | 7 + .../boringssl_obj_test_lib.vcxproj | 170 +++ .../boringssl_obj_test_lib.vcxproj.filters} | 16 +- .../boringssl_spake25519_test.vcxproj | 198 +++ .../boringssl_spake25519_test.vcxproj.filters | 7 + .../boringssl_spake25519_test_lib.vcxproj | 170 +++ ...ingssl_spake25519_test_lib.vcxproj.filters | 24 + 51 files changed, 5192 insertions(+), 1070 deletions(-) rename vsprojects/vcxproj/test/boringssl/{boringssl_pqueue_test/boringssl_pqueue_test.vcxproj => boringssl_chacha_test/boringssl_chacha_test.vcxproj} (97%) rename vsprojects/vcxproj/test/boringssl/{boringssl_pqueue_test/boringssl_pqueue_test.vcxproj.filters => boringssl_chacha_test/boringssl_chacha_test.vcxproj.filters} (100%) create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj.filters rename vsprojects/vcxproj/test/boringssl/{boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj => boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj} (97%) create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj rename vsprojects/vcxproj/test/boringssl/{boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj.filters => boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj.filters} (52%) create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj.filters create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj create mode 100644 vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj.filters diff --git a/Makefile b/Makefile index 5af7d4e45a8..50e4411bb79 100644 --- a/Makefile +++ b/Makefile @@ -1134,18 +1134,23 @@ boringssl_base64_test: $(BINDIR)/$(CONFIG)/boringssl_base64_test boringssl_bio_test: $(BINDIR)/$(CONFIG)/boringssl_bio_test boringssl_bn_test: $(BINDIR)/$(CONFIG)/boringssl_bn_test boringssl_bytestring_test: $(BINDIR)/$(CONFIG)/boringssl_bytestring_test +boringssl_chacha_test: $(BINDIR)/$(CONFIG)/boringssl_chacha_test boringssl_aead_test: $(BINDIR)/$(CONFIG)/boringssl_aead_test boringssl_cipher_test: $(BINDIR)/$(CONFIG)/boringssl_cipher_test boringssl_cmac_test: $(BINDIR)/$(CONFIG)/boringssl_cmac_test boringssl_constant_time_test: $(BINDIR)/$(CONFIG)/boringssl_constant_time_test boringssl_ed25519_test: $(BINDIR)/$(CONFIG)/boringssl_ed25519_test +boringssl_spake25519_test: $(BINDIR)/$(CONFIG)/boringssl_spake25519_test boringssl_x25519_test: $(BINDIR)/$(CONFIG)/boringssl_x25519_test boringssl_dh_test: $(BINDIR)/$(CONFIG)/boringssl_dh_test boringssl_digest_test: $(BINDIR)/$(CONFIG)/boringssl_digest_test boringssl_dsa_test: $(BINDIR)/$(CONFIG)/boringssl_dsa_test boringssl_ec_test: $(BINDIR)/$(CONFIG)/boringssl_ec_test boringssl_example_mul: $(BINDIR)/$(CONFIG)/boringssl_example_mul +boringssl_ecdh_test: $(BINDIR)/$(CONFIG)/boringssl_ecdh_test +boringssl_ecdsa_sign_test: $(BINDIR)/$(CONFIG)/boringssl_ecdsa_sign_test boringssl_ecdsa_test: $(BINDIR)/$(CONFIG)/boringssl_ecdsa_test +boringssl_ecdsa_verify_test: $(BINDIR)/$(CONFIG)/boringssl_ecdsa_verify_test boringssl_err_test: $(BINDIR)/$(CONFIG)/boringssl_err_test boringssl_evp_extra_test: $(BINDIR)/$(CONFIG)/boringssl_evp_extra_test boringssl_evp_test: $(BINDIR)/$(CONFIG)/boringssl_evp_test @@ -1154,6 +1159,10 @@ boringssl_hkdf_test: $(BINDIR)/$(CONFIG)/boringssl_hkdf_test boringssl_hmac_test: $(BINDIR)/$(CONFIG)/boringssl_hmac_test boringssl_lhash_test: $(BINDIR)/$(CONFIG)/boringssl_lhash_test boringssl_gcm_test: $(BINDIR)/$(CONFIG)/boringssl_gcm_test +boringssl_newhope_statistical_test: $(BINDIR)/$(CONFIG)/boringssl_newhope_statistical_test +boringssl_newhope_test: $(BINDIR)/$(CONFIG)/boringssl_newhope_test +boringssl_newhope_vectors_test: $(BINDIR)/$(CONFIG)/boringssl_newhope_vectors_test +boringssl_obj_test: $(BINDIR)/$(CONFIG)/boringssl_obj_test boringssl_pkcs12_test: $(BINDIR)/$(CONFIG)/boringssl_pkcs12_test boringssl_pkcs8_test: $(BINDIR)/$(CONFIG)/boringssl_pkcs8_test boringssl_poly1305_test: $(BINDIR)/$(CONFIG)/boringssl_poly1305_test @@ -1164,7 +1173,6 @@ boringssl_pkcs7_test: $(BINDIR)/$(CONFIG)/boringssl_pkcs7_test boringssl_x509_test: $(BINDIR)/$(CONFIG)/boringssl_x509_test boringssl_tab_test: $(BINDIR)/$(CONFIG)/boringssl_tab_test boringssl_v3name_test: $(BINDIR)/$(CONFIG)/boringssl_v3name_test -boringssl_pqueue_test: $(BINDIR)/$(CONFIG)/boringssl_pqueue_test boringssl_ssl_test: $(BINDIR)/$(CONFIG)/boringssl_ssl_test badreq_bad_client_test: $(BINDIR)/$(CONFIG)/badreq_bad_client_test connection_prefix_bad_client_test: $(BINDIR)/$(CONFIG)/connection_prefix_bad_client_test @@ -1274,7 +1282,7 @@ pc_cxx: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++.pc pc_cxx_unsecure: $(LIBDIR)/$(CONFIG)/pkgconfig/grpc++_unsecure.pc ifeq ($(EMBED_OPENSSL),true) -privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl_aes_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_asn1_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_base64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bio_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bn_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bytestring_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_aead_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cipher_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ed25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_dh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_digest_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ec_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_err_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_extra_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pbkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs12_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs8_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_poly1305_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_rsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x509_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ssl_test_lib.a $(LIBDIR)/$(CONFIG)/libbenchmark.a +privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl_aes_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_asn1_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_base64_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bio_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bn_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_bytestring_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_aead_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cipher_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_cmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ed25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_dh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_digest_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ec_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_err_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_extra_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_evp_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pbkdf_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_hmac_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs12_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_pkcs8_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_poly1305_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_rsa_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_x509_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_ssl_test_lib.a $(LIBDIR)/$(CONFIG)/libbenchmark.a else privatelibs_cxx: $(LIBDIR)/$(CONFIG)/libgrpc++_proto_reflection_desc_db.a $(LIBDIR)/$(CONFIG)/libgrpc++_test.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_config.a $(LIBDIR)/$(CONFIG)/libgrpc++_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc_cli_libs.a $(LIBDIR)/$(CONFIG)/libhttp2_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_client_helper.a $(LIBDIR)/$(CONFIG)/libinterop_client_main.a $(LIBDIR)/$(CONFIG)/libinterop_server_helper.a $(LIBDIR)/$(CONFIG)/libinterop_server_lib.a $(LIBDIR)/$(CONFIG)/libinterop_server_main.a $(LIBDIR)/$(CONFIG)/libqps.a $(LIBDIR)/$(CONFIG)/libbenchmark.a endif @@ -1519,18 +1527,23 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/boringssl_bio_test \ $(BINDIR)/$(CONFIG)/boringssl_bn_test \ $(BINDIR)/$(CONFIG)/boringssl_bytestring_test \ + $(BINDIR)/$(CONFIG)/boringssl_chacha_test \ $(BINDIR)/$(CONFIG)/boringssl_aead_test \ $(BINDIR)/$(CONFIG)/boringssl_cipher_test \ $(BINDIR)/$(CONFIG)/boringssl_cmac_test \ $(BINDIR)/$(CONFIG)/boringssl_constant_time_test \ $(BINDIR)/$(CONFIG)/boringssl_ed25519_test \ + $(BINDIR)/$(CONFIG)/boringssl_spake25519_test \ $(BINDIR)/$(CONFIG)/boringssl_x25519_test \ $(BINDIR)/$(CONFIG)/boringssl_dh_test \ $(BINDIR)/$(CONFIG)/boringssl_digest_test \ $(BINDIR)/$(CONFIG)/boringssl_dsa_test \ $(BINDIR)/$(CONFIG)/boringssl_ec_test \ $(BINDIR)/$(CONFIG)/boringssl_example_mul \ + $(BINDIR)/$(CONFIG)/boringssl_ecdh_test \ + $(BINDIR)/$(CONFIG)/boringssl_ecdsa_sign_test \ $(BINDIR)/$(CONFIG)/boringssl_ecdsa_test \ + $(BINDIR)/$(CONFIG)/boringssl_ecdsa_verify_test \ $(BINDIR)/$(CONFIG)/boringssl_err_test \ $(BINDIR)/$(CONFIG)/boringssl_evp_extra_test \ $(BINDIR)/$(CONFIG)/boringssl_evp_test \ @@ -1539,6 +1552,10 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/boringssl_hmac_test \ $(BINDIR)/$(CONFIG)/boringssl_lhash_test \ $(BINDIR)/$(CONFIG)/boringssl_gcm_test \ + $(BINDIR)/$(CONFIG)/boringssl_newhope_statistical_test \ + $(BINDIR)/$(CONFIG)/boringssl_newhope_test \ + $(BINDIR)/$(CONFIG)/boringssl_newhope_vectors_test \ + $(BINDIR)/$(CONFIG)/boringssl_obj_test \ $(BINDIR)/$(CONFIG)/boringssl_pkcs12_test \ $(BINDIR)/$(CONFIG)/boringssl_pkcs8_test \ $(BINDIR)/$(CONFIG)/boringssl_poly1305_test \ @@ -1549,7 +1566,6 @@ buildtests_cxx: privatelibs_cxx \ $(BINDIR)/$(CONFIG)/boringssl_x509_test \ $(BINDIR)/$(CONFIG)/boringssl_tab_test \ $(BINDIR)/$(CONFIG)/boringssl_v3name_test \ - $(BINDIR)/$(CONFIG)/boringssl_pqueue_test \ $(BINDIR)/$(CONFIG)/boringssl_ssl_test \ else @@ -5424,7 +5440,6 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/aes/mode_wrappers.c \ third_party/boringssl/crypto/asn1/a_bitstr.c \ third_party/boringssl/crypto/asn1/a_bool.c \ - third_party/boringssl/crypto/asn1/a_bytes.c \ third_party/boringssl/crypto/asn1/a_d2i_fp.c \ third_party/boringssl/crypto/asn1/a_dup.c \ third_party/boringssl/crypto/asn1/a_enum.c \ @@ -5443,18 +5458,14 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/asn1/asn1_lib.c \ third_party/boringssl/crypto/asn1/asn1_par.c \ third_party/boringssl/crypto/asn1/asn_pack.c \ - third_party/boringssl/crypto/asn1/bio_asn1.c \ - third_party/boringssl/crypto/asn1/bio_ndef.c \ third_party/boringssl/crypto/asn1/f_enum.c \ third_party/boringssl/crypto/asn1/f_int.c \ third_party/boringssl/crypto/asn1/f_string.c \ third_party/boringssl/crypto/asn1/t_bitst.c \ - third_party/boringssl/crypto/asn1/t_pkey.c \ third_party/boringssl/crypto/asn1/tasn_dec.c \ third_party/boringssl/crypto/asn1/tasn_enc.c \ third_party/boringssl/crypto/asn1/tasn_fre.c \ third_party/boringssl/crypto/asn1/tasn_new.c \ - third_party/boringssl/crypto/asn1/tasn_prn.c \ third_party/boringssl/crypto/asn1/tasn_typ.c \ third_party/boringssl/crypto/asn1/tasn_utl.c \ third_party/boringssl/crypto/asn1/x_bignum.c \ @@ -5484,6 +5495,7 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/bn/generic.c \ third_party/boringssl/crypto/bn/kronecker.c \ third_party/boringssl/crypto/bn/montgomery.c \ + third_party/boringssl/crypto/bn/montgomery_inv.c \ third_party/boringssl/crypto/bn/mul.c \ third_party/boringssl/crypto/bn/prime.c \ third_party/boringssl/crypto/bn/random.c \ @@ -5495,8 +5507,7 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/bytestring/ber.c \ third_party/boringssl/crypto/bytestring/cbb.c \ third_party/boringssl/crypto/bytestring/cbs.c \ - third_party/boringssl/crypto/chacha/chacha_generic.c \ - third_party/boringssl/crypto/chacha/chacha_vec.c \ + third_party/boringssl/crypto/chacha/chacha.c \ third_party/boringssl/crypto/cipher/aead.c \ third_party/boringssl/crypto/cipher/cipher.c \ third_party/boringssl/crypto/cipher/derive_key.c \ @@ -5511,10 +5522,14 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/cipher/tls_cbc.c \ third_party/boringssl/crypto/cmac/cmac.c \ third_party/boringssl/crypto/conf/conf.c \ + third_party/boringssl/crypto/cpu-aarch64-linux.c \ + third_party/boringssl/crypto/cpu-arm-linux.c \ third_party/boringssl/crypto/cpu-arm.c \ third_party/boringssl/crypto/cpu-intel.c \ + third_party/boringssl/crypto/cpu-ppc64le.c \ third_party/boringssl/crypto/crypto.c \ third_party/boringssl/crypto/curve25519/curve25519.c \ + third_party/boringssl/crypto/curve25519/spake25519.c \ third_party/boringssl/crypto/curve25519/x25519-x86_64.c \ third_party/boringssl/crypto/des/des.c \ third_party/boringssl/crypto/dh/check.c \ @@ -5523,8 +5538,6 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/dh/params.c \ third_party/boringssl/crypto/digest/digest.c \ third_party/boringssl/crypto/digest/digests.c \ - third_party/boringssl/crypto/directory_posix.c \ - third_party/boringssl/crypto/directory_win.c \ third_party/boringssl/crypto/dsa/dsa.c \ third_party/boringssl/crypto/dsa/dsa_asn1.c \ third_party/boringssl/crypto/ec/ec.c \ @@ -5543,7 +5556,6 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c \ third_party/boringssl/crypto/engine/engine.c \ third_party/boringssl/crypto/err/err.c \ - third_party/boringssl/crypto/evp/algorithm.c \ third_party/boringssl/crypto/evp/digestsign.c \ third_party/boringssl/crypto/evp/evp.c \ third_party/boringssl/crypto/evp/evp_asn1.c \ @@ -5554,6 +5566,7 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/evp/p_rsa.c \ third_party/boringssl/crypto/evp/p_rsa_asn1.c \ third_party/boringssl/crypto/evp/pbkdf.c \ + third_party/boringssl/crypto/evp/print.c \ third_party/boringssl/crypto/evp/sign.c \ third_party/boringssl/crypto/ex_data.c \ third_party/boringssl/crypto/hkdf/hkdf.c \ @@ -5567,6 +5580,12 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/modes/ctr.c \ third_party/boringssl/crypto/modes/gcm.c \ third_party/boringssl/crypto/modes/ofb.c \ + third_party/boringssl/crypto/newhope/error_correction.c \ + third_party/boringssl/crypto/newhope/newhope.c \ + third_party/boringssl/crypto/newhope/ntt.c \ + third_party/boringssl/crypto/newhope/poly.c \ + third_party/boringssl/crypto/newhope/precomp.c \ + third_party/boringssl/crypto/newhope/reduce.c \ third_party/boringssl/crypto/obj/obj.c \ third_party/boringssl/crypto/obj/obj_xref.c \ third_party/boringssl/crypto/pem/pem_all.c \ @@ -5584,6 +5603,7 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/poly1305/poly1305.c \ third_party/boringssl/crypto/poly1305/poly1305_arm.c \ third_party/boringssl/crypto/poly1305/poly1305_vec.c \ + third_party/boringssl/crypto/rand/deterministic.c \ third_party/boringssl/crypto/rand/rand.c \ third_party/boringssl/crypto/rand/urandom.c \ third_party/boringssl/crypto/rand/windows.c \ @@ -5608,11 +5628,13 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/x509/a_sign.c \ third_party/boringssl/crypto/x509/a_strex.c \ third_party/boringssl/crypto/x509/a_verify.c \ + third_party/boringssl/crypto/x509/algorithm.c \ third_party/boringssl/crypto/x509/asn1_gen.c \ third_party/boringssl/crypto/x509/by_dir.c \ third_party/boringssl/crypto/x509/by_file.c \ third_party/boringssl/crypto/x509/i2d_pr.c \ third_party/boringssl/crypto/x509/pkcs7.c \ + third_party/boringssl/crypto/x509/rsa_pss.c \ third_party/boringssl/crypto/x509/t_crl.c \ third_party/boringssl/crypto/x509/t_req.c \ third_party/boringssl/crypto/x509/t_x509.c \ @@ -5687,21 +5709,17 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/crypto/x509v3/v3_utl.c \ third_party/boringssl/ssl/custom_extensions.c \ third_party/boringssl/ssl/d1_both.c \ - third_party/boringssl/ssl/d1_clnt.c \ third_party/boringssl/ssl/d1_lib.c \ - third_party/boringssl/ssl/d1_meth.c \ third_party/boringssl/ssl/d1_pkt.c \ third_party/boringssl/ssl/d1_srtp.c \ - third_party/boringssl/ssl/d1_srvr.c \ + third_party/boringssl/ssl/dtls_method.c \ third_party/boringssl/ssl/dtls_record.c \ - third_party/boringssl/ssl/pqueue/pqueue.c \ + third_party/boringssl/ssl/handshake_client.c \ + third_party/boringssl/ssl/handshake_server.c \ third_party/boringssl/ssl/s3_both.c \ - third_party/boringssl/ssl/s3_clnt.c \ third_party/boringssl/ssl/s3_enc.c \ third_party/boringssl/ssl/s3_lib.c \ - third_party/boringssl/ssl/s3_meth.c \ third_party/boringssl/ssl/s3_pkt.c \ - third_party/boringssl/ssl/s3_srvr.c \ third_party/boringssl/ssl/ssl_aead_ctx.c \ third_party/boringssl/ssl/ssl_asn1.c \ third_party/boringssl/ssl/ssl_buffer.c \ @@ -5715,6 +5733,11 @@ LIBBORINGSSL_SRC = \ third_party/boringssl/ssl/ssl_stat.c \ third_party/boringssl/ssl/t1_enc.c \ third_party/boringssl/ssl/t1_lib.c \ + third_party/boringssl/ssl/tls13_both.c \ + third_party/boringssl/ssl/tls13_client.c \ + third_party/boringssl/ssl/tls13_enc.c \ + third_party/boringssl/ssl/tls13_server.c \ + third_party/boringssl/ssl/tls_method.c \ third_party/boringssl/ssl/tls_record.c \ PUBLIC_HEADERS_C += \ @@ -6009,6 +6032,44 @@ ifneq ($(NO_DEPS),true) endif +LIBBORINGSSL_CHACHA_TEST_LIB_SRC = \ + third_party/boringssl/crypto/chacha/chacha_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_CHACHA_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_CHACHA_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_CHACHA_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_CHACHA_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_CHACHA_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a $(LIBBORINGSSL_CHACHA_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_CHACHA_TEST_LIB_OBJS:.o=.dep) +endif + + LIBBORINGSSL_AEAD_TEST_LIB_SRC = \ third_party/boringssl/crypto/cipher/aead_test.cc \ @@ -6188,6 +6249,44 @@ ifneq ($(NO_DEPS),true) endif +LIBBORINGSSL_SPAKE25519_TEST_LIB_SRC = \ + third_party/boringssl/crypto/curve25519/spake25519_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_SPAKE25519_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_SPAKE25519_TEST_LIB_OBJS:.o=.dep) +endif + + LIBBORINGSSL_X25519_TEST_LIB_SRC = \ third_party/boringssl/crypto/curve25519/x25519_test.cc \ @@ -6394,6 +6493,82 @@ ifneq ($(NO_DEPS),true) endif +LIBBORINGSSL_ECDH_TEST_LIB_SRC = \ + third_party/boringssl/crypto/ecdh/ecdh_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_ECDH_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_ECDH_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_ECDH_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_ECDH_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_ECDH_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBBORINGSSL_ECDH_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_ECDH_TEST_LIB_OBJS:.o=.dep) +endif + + +LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_SRC = \ + third_party/boringssl/crypto/ecdsa/ecdsa_sign_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_ECDSA_SIGN_TEST_LIB_OBJS:.o=.dep) +endif + + LIBBORINGSSL_ECDSA_TEST_LIB_SRC = \ third_party/boringssl/crypto/ecdsa/ecdsa_test.cc \ @@ -6432,6 +6607,44 @@ ifneq ($(NO_DEPS),true) endif +LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_SRC = \ + third_party/boringssl/crypto/ecdsa/ecdsa_verify_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_ECDSA_VERIFY_TEST_LIB_OBJS:.o=.dep) +endif + + LIBBORINGSSL_ERR_TEST_LIB_SRC = \ third_party/boringssl/crypto/err/err_test.cc \ @@ -6677,16 +6890,25 @@ endif LIBBORINGSSL_GCM_TEST_LIB_SRC = \ - third_party/boringssl/crypto/modes/gcm_test.c \ + third_party/boringssl/crypto/modes/gcm_test.cc \ -PUBLIC_HEADERS_C += \ +PUBLIC_HEADERS_CXX += \ LIBBORINGSSL_GCM_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_GCM_TEST_LIB_SRC)))) $(LIBBORINGSSL_GCM_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX $(LIBBORINGSSL_GCM_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) -$(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a: $(ZLIB_DEP) $(LIBBORINGSSL_GCM_TEST_LIB_OBJS) +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_GCM_TEST_LIB_OBJS) $(E) "[AR] Creating $@" $(Q) mkdir -p `dirname $@` $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_gcm_test_lib.a @@ -6698,11 +6920,165 @@ endif +endif + ifneq ($(NO_DEPS),true) -include $(LIBBORINGSSL_GCM_TEST_LIB_OBJS:.o=.dep) endif +LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_SRC = \ + third_party/boringssl/crypto/newhope/newhope_statistical_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a $(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_NEWHOPE_STATISTICAL_TEST_LIB_OBJS:.o=.dep) +endif + + +LIBBORINGSSL_NEWHOPE_TEST_LIB_SRC = \ + third_party/boringssl/crypto/newhope/newhope_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_NEWHOPE_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a $(LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_NEWHOPE_TEST_LIB_OBJS:.o=.dep) +endif + + +LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_SRC = \ + third_party/boringssl/crypto/newhope/newhope_vectors_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a $(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_NEWHOPE_VECTORS_TEST_LIB_OBJS:.o=.dep) +endif + + +LIBBORINGSSL_OBJ_TEST_LIB_SRC = \ + third_party/boringssl/crypto/obj/obj_test.cc \ + +PUBLIC_HEADERS_CXX += \ + +LIBBORINGSSL_OBJ_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_OBJ_TEST_LIB_SRC)))) + +$(LIBBORINGSSL_OBJ_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX +$(LIBBORINGSSL_OBJ_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) + +ifeq ($(NO_PROTOBUF),true) + +# You can't build a C++ library if you don't have protobuf - a bit overreached, but still okay. + +$(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a: protobuf_dep_error + + +else + +$(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a: $(ZLIB_DEP) $(PROTOBUF_DEP) $(LIBBORINGSSL_OBJ_TEST_LIB_OBJS) + $(E) "[AR] Creating $@" + $(Q) mkdir -p `dirname $@` + $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a + $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBBORINGSSL_OBJ_TEST_LIB_OBJS) +ifeq ($(SYSTEM),Darwin) + $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a +endif + + + + +endif + +ifneq ($(NO_DEPS),true) +-include $(LIBBORINGSSL_OBJ_TEST_LIB_OBJS:.o=.dep) +endif + + LIBBORINGSSL_PKCS12_TEST_LIB_SRC = \ third_party/boringssl/crypto/pkcs8/pkcs12_test.cc \ @@ -7028,33 +7404,6 @@ ifneq ($(NO_DEPS),true) endif -LIBBORINGSSL_PQUEUE_TEST_LIB_SRC = \ - third_party/boringssl/ssl/pqueue/pqueue_test.c \ - -PUBLIC_HEADERS_C += \ - -LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(LIBBORINGSSL_PQUEUE_TEST_LIB_SRC)))) - -$(LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS): CPPFLAGS += -Ithird_party/boringssl/include -fvisibility=hidden -DOPENSSL_NO_ASM -D_GNU_SOURCE -DWIN32_LEAN_AND_MEAN -D_HAS_EXCEPTIONS=0 -DNOMINMAX -$(LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS): CFLAGS += -Wno-sign-conversion -Wno-conversion -Wno-unused-value -Wno-unknown-pragmas -Wno-implicit-function-declaration -Wno-unused-variable -Wno-sign-compare $(NO_W_EXTRA_SEMI) - -$(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a: $(ZLIB_DEP) $(LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS) - $(E) "[AR] Creating $@" - $(Q) mkdir -p `dirname $@` - $(Q) rm -f $(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a - $(Q) $(AR) $(AROPTS) $(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a $(LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS) -ifeq ($(SYSTEM),Darwin) - $(Q) ranlib -no_warning_for_no_symbols $(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a -endif - - - - -ifneq ($(NO_DEPS),true) --include $(LIBBORINGSSL_PQUEUE_TEST_LIB_OBJS:.o=.dep) -endif - - LIBBORINGSSL_SSL_TEST_LIB_SRC = \ third_party/boringssl/ssl/ssl_test.cc \ @@ -14546,6 +14895,33 @@ endif +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_CHACHA_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_CHACHA_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_CHACHA_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_chacha_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_chacha_test: $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_chacha_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_chacha_test + +endif + + + + + # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment @@ -14681,6 +15057,33 @@ endif +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_SPAKE25519_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_SPAKE25519_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_SPAKE25519_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_spake25519_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_spake25519_test: $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_spake25519_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_spake25519_test + +endif + + + + + # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment @@ -14843,6 +15246,60 @@ endif +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_ECDH_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_ECDH_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_ECDH_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_ecdh_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_ecdh_test: $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdh_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_ecdh_test + +endif + + + + + +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_ECDSA_SIGN_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_ECDSA_SIGN_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_ECDSA_SIGN_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_ecdsa_sign_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_ecdsa_sign_test: $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_sign_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_ecdsa_sign_test + +endif + + + + + # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment @@ -14870,6 +15327,33 @@ endif +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_ECDSA_VERIFY_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_ECDSA_VERIFY_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_ECDSA_VERIFY_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_ecdsa_verify_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_ecdsa_verify_test: $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_ecdsa_verify_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_ecdsa_verify_test + +endif + + + + + # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment @@ -15086,6 +15570,114 @@ endif +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_NEWHOPE_STATISTICAL_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_NEWHOPE_STATISTICAL_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_NEWHOPE_STATISTICAL_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_newhope_statistical_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_newhope_statistical_test: $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_statistical_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_newhope_statistical_test + +endif + + + + + +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_NEWHOPE_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_NEWHOPE_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_NEWHOPE_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_newhope_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_newhope_test: $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_newhope_test + +endif + + + + + +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_NEWHOPE_VECTORS_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_NEWHOPE_VECTORS_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_NEWHOPE_VECTORS_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_newhope_vectors_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_newhope_vectors_test: $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_newhope_vectors_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_newhope_vectors_test + +endif + + + + + +# boringssl needs an override to ensure that it does not include +# system openssl headers regardless of other configuration +# we do so here with a target specific variable assignment +$(BORINGSSL_OBJ_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) +$(BORINGSSL_OBJ_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) +$(BORINGSSL_OBJ_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE + + +ifeq ($(NO_PROTOBUF),true) + +# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. + +$(BINDIR)/$(CONFIG)/boringssl_obj_test: protobuf_dep_error + +else + +$(BINDIR)/$(CONFIG)/boringssl_obj_test: $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_obj_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_obj_test + +endif + + + + + # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment @@ -15356,33 +15948,6 @@ endif -# boringssl needs an override to ensure that it does not include -# system openssl headers regardless of other configuration -# we do so here with a target specific variable assignment -$(BORINGSSL_PQUEUE_TEST_OBJS): CFLAGS := -Ithird_party/boringssl/include $(CFLAGS) -Wno-sign-conversion -Wno-conversion -Wno-unused-value $(NO_W_EXTRA_SEMI) -$(BORINGSSL_PQUEUE_TEST_OBJS): CXXFLAGS := -Ithird_party/boringssl/include $(CXXFLAGS) -$(BORINGSSL_PQUEUE_TEST_OBJS): CPPFLAGS += -DOPENSSL_NO_ASM -D_GNU_SOURCE - - -ifeq ($(NO_PROTOBUF),true) - -# You can't build the protoc plugins or protobuf-enabled targets if you don't have protobuf 3.0.0+. - -$(BINDIR)/$(CONFIG)/boringssl_pqueue_test: protobuf_dep_error - -else - -$(BINDIR)/$(CONFIG)/boringssl_pqueue_test: $(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LDXX) $(LDFLAGS) $(LIBDIR)/$(CONFIG)/libboringssl_pqueue_test_lib.a $(LIBDIR)/$(CONFIG)/libboringssl_test_util.a $(LIBDIR)/$(CONFIG)/libboringssl.a $(LDLIBSXX) $(LDLIBS_PROTOBUF) $(LDLIBS) $(GTEST_LIB) -o $(BINDIR)/$(CONFIG)/boringssl_pqueue_test - -endif - - - - - # boringssl needs an override to ensure that it does not include # system openssl headers regardless of other configuration # we do so here with a target specific variable assignment diff --git a/binding.gyp b/binding.gyp index 479403ed218..6c82028dbd3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -161,7 +161,6 @@ 'third_party/boringssl/crypto/aes/mode_wrappers.c', 'third_party/boringssl/crypto/asn1/a_bitstr.c', 'third_party/boringssl/crypto/asn1/a_bool.c', - 'third_party/boringssl/crypto/asn1/a_bytes.c', 'third_party/boringssl/crypto/asn1/a_d2i_fp.c', 'third_party/boringssl/crypto/asn1/a_dup.c', 'third_party/boringssl/crypto/asn1/a_enum.c', @@ -180,18 +179,14 @@ 'third_party/boringssl/crypto/asn1/asn1_lib.c', 'third_party/boringssl/crypto/asn1/asn1_par.c', 'third_party/boringssl/crypto/asn1/asn_pack.c', - 'third_party/boringssl/crypto/asn1/bio_asn1.c', - 'third_party/boringssl/crypto/asn1/bio_ndef.c', 'third_party/boringssl/crypto/asn1/f_enum.c', 'third_party/boringssl/crypto/asn1/f_int.c', 'third_party/boringssl/crypto/asn1/f_string.c', 'third_party/boringssl/crypto/asn1/t_bitst.c', - 'third_party/boringssl/crypto/asn1/t_pkey.c', 'third_party/boringssl/crypto/asn1/tasn_dec.c', 'third_party/boringssl/crypto/asn1/tasn_enc.c', 'third_party/boringssl/crypto/asn1/tasn_fre.c', 'third_party/boringssl/crypto/asn1/tasn_new.c', - 'third_party/boringssl/crypto/asn1/tasn_prn.c', 'third_party/boringssl/crypto/asn1/tasn_typ.c', 'third_party/boringssl/crypto/asn1/tasn_utl.c', 'third_party/boringssl/crypto/asn1/x_bignum.c', @@ -221,6 +216,7 @@ 'third_party/boringssl/crypto/bn/generic.c', 'third_party/boringssl/crypto/bn/kronecker.c', 'third_party/boringssl/crypto/bn/montgomery.c', + 'third_party/boringssl/crypto/bn/montgomery_inv.c', 'third_party/boringssl/crypto/bn/mul.c', 'third_party/boringssl/crypto/bn/prime.c', 'third_party/boringssl/crypto/bn/random.c', @@ -232,8 +228,7 @@ 'third_party/boringssl/crypto/bytestring/ber.c', 'third_party/boringssl/crypto/bytestring/cbb.c', 'third_party/boringssl/crypto/bytestring/cbs.c', - 'third_party/boringssl/crypto/chacha/chacha_generic.c', - 'third_party/boringssl/crypto/chacha/chacha_vec.c', + 'third_party/boringssl/crypto/chacha/chacha.c', 'third_party/boringssl/crypto/cipher/aead.c', 'third_party/boringssl/crypto/cipher/cipher.c', 'third_party/boringssl/crypto/cipher/derive_key.c', @@ -248,10 +243,14 @@ 'third_party/boringssl/crypto/cipher/tls_cbc.c', 'third_party/boringssl/crypto/cmac/cmac.c', 'third_party/boringssl/crypto/conf/conf.c', + 'third_party/boringssl/crypto/cpu-aarch64-linux.c', + 'third_party/boringssl/crypto/cpu-arm-linux.c', 'third_party/boringssl/crypto/cpu-arm.c', 'third_party/boringssl/crypto/cpu-intel.c', + 'third_party/boringssl/crypto/cpu-ppc64le.c', 'third_party/boringssl/crypto/crypto.c', 'third_party/boringssl/crypto/curve25519/curve25519.c', + 'third_party/boringssl/crypto/curve25519/spake25519.c', 'third_party/boringssl/crypto/curve25519/x25519-x86_64.c', 'third_party/boringssl/crypto/des/des.c', 'third_party/boringssl/crypto/dh/check.c', @@ -260,8 +259,6 @@ 'third_party/boringssl/crypto/dh/params.c', 'third_party/boringssl/crypto/digest/digest.c', 'third_party/boringssl/crypto/digest/digests.c', - 'third_party/boringssl/crypto/directory_posix.c', - 'third_party/boringssl/crypto/directory_win.c', 'third_party/boringssl/crypto/dsa/dsa.c', 'third_party/boringssl/crypto/dsa/dsa_asn1.c', 'third_party/boringssl/crypto/ec/ec.c', @@ -280,7 +277,6 @@ 'third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c', 'third_party/boringssl/crypto/engine/engine.c', 'third_party/boringssl/crypto/err/err.c', - 'third_party/boringssl/crypto/evp/algorithm.c', 'third_party/boringssl/crypto/evp/digestsign.c', 'third_party/boringssl/crypto/evp/evp.c', 'third_party/boringssl/crypto/evp/evp_asn1.c', @@ -291,6 +287,7 @@ 'third_party/boringssl/crypto/evp/p_rsa.c', 'third_party/boringssl/crypto/evp/p_rsa_asn1.c', 'third_party/boringssl/crypto/evp/pbkdf.c', + 'third_party/boringssl/crypto/evp/print.c', 'third_party/boringssl/crypto/evp/sign.c', 'third_party/boringssl/crypto/ex_data.c', 'third_party/boringssl/crypto/hkdf/hkdf.c', @@ -304,6 +301,12 @@ 'third_party/boringssl/crypto/modes/ctr.c', 'third_party/boringssl/crypto/modes/gcm.c', 'third_party/boringssl/crypto/modes/ofb.c', + 'third_party/boringssl/crypto/newhope/error_correction.c', + 'third_party/boringssl/crypto/newhope/newhope.c', + 'third_party/boringssl/crypto/newhope/ntt.c', + 'third_party/boringssl/crypto/newhope/poly.c', + 'third_party/boringssl/crypto/newhope/precomp.c', + 'third_party/boringssl/crypto/newhope/reduce.c', 'third_party/boringssl/crypto/obj/obj.c', 'third_party/boringssl/crypto/obj/obj_xref.c', 'third_party/boringssl/crypto/pem/pem_all.c', @@ -321,6 +324,7 @@ 'third_party/boringssl/crypto/poly1305/poly1305.c', 'third_party/boringssl/crypto/poly1305/poly1305_arm.c', 'third_party/boringssl/crypto/poly1305/poly1305_vec.c', + 'third_party/boringssl/crypto/rand/deterministic.c', 'third_party/boringssl/crypto/rand/rand.c', 'third_party/boringssl/crypto/rand/urandom.c', 'third_party/boringssl/crypto/rand/windows.c', @@ -345,11 +349,13 @@ 'third_party/boringssl/crypto/x509/a_sign.c', 'third_party/boringssl/crypto/x509/a_strex.c', 'third_party/boringssl/crypto/x509/a_verify.c', + 'third_party/boringssl/crypto/x509/algorithm.c', 'third_party/boringssl/crypto/x509/asn1_gen.c', 'third_party/boringssl/crypto/x509/by_dir.c', 'third_party/boringssl/crypto/x509/by_file.c', 'third_party/boringssl/crypto/x509/i2d_pr.c', 'third_party/boringssl/crypto/x509/pkcs7.c', + 'third_party/boringssl/crypto/x509/rsa_pss.c', 'third_party/boringssl/crypto/x509/t_crl.c', 'third_party/boringssl/crypto/x509/t_req.c', 'third_party/boringssl/crypto/x509/t_x509.c', @@ -424,21 +430,17 @@ 'third_party/boringssl/crypto/x509v3/v3_utl.c', 'third_party/boringssl/ssl/custom_extensions.c', 'third_party/boringssl/ssl/d1_both.c', - 'third_party/boringssl/ssl/d1_clnt.c', 'third_party/boringssl/ssl/d1_lib.c', - 'third_party/boringssl/ssl/d1_meth.c', 'third_party/boringssl/ssl/d1_pkt.c', 'third_party/boringssl/ssl/d1_srtp.c', - 'third_party/boringssl/ssl/d1_srvr.c', + 'third_party/boringssl/ssl/dtls_method.c', 'third_party/boringssl/ssl/dtls_record.c', - 'third_party/boringssl/ssl/pqueue/pqueue.c', + 'third_party/boringssl/ssl/handshake_client.c', + 'third_party/boringssl/ssl/handshake_server.c', 'third_party/boringssl/ssl/s3_both.c', - 'third_party/boringssl/ssl/s3_clnt.c', 'third_party/boringssl/ssl/s3_enc.c', 'third_party/boringssl/ssl/s3_lib.c', - 'third_party/boringssl/ssl/s3_meth.c', 'third_party/boringssl/ssl/s3_pkt.c', - 'third_party/boringssl/ssl/s3_srvr.c', 'third_party/boringssl/ssl/ssl_aead_ctx.c', 'third_party/boringssl/ssl/ssl_asn1.c', 'third_party/boringssl/ssl/ssl_buffer.c', @@ -452,6 +454,11 @@ 'third_party/boringssl/ssl/ssl_stat.c', 'third_party/boringssl/ssl/t1_enc.c', 'third_party/boringssl/ssl/t1_lib.c', + 'third_party/boringssl/ssl/tls13_both.c', + 'third_party/boringssl/ssl/tls13_client.c', + 'third_party/boringssl/ssl/tls13_enc.c', + 'third_party/boringssl/ssl/tls13_server.c', + 'third_party/boringssl/ssl/tls_method.c', 'third_party/boringssl/ssl/tls_record.c', ] }, diff --git a/config.m4 b/config.m4 index 85549e5f427..621bbb36d5d 100644 --- a/config.m4 +++ b/config.m4 @@ -302,7 +302,6 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/aes/mode_wrappers.c \ third_party/boringssl/crypto/asn1/a_bitstr.c \ third_party/boringssl/crypto/asn1/a_bool.c \ - third_party/boringssl/crypto/asn1/a_bytes.c \ third_party/boringssl/crypto/asn1/a_d2i_fp.c \ third_party/boringssl/crypto/asn1/a_dup.c \ third_party/boringssl/crypto/asn1/a_enum.c \ @@ -321,18 +320,14 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/asn1/asn1_lib.c \ third_party/boringssl/crypto/asn1/asn1_par.c \ third_party/boringssl/crypto/asn1/asn_pack.c \ - third_party/boringssl/crypto/asn1/bio_asn1.c \ - third_party/boringssl/crypto/asn1/bio_ndef.c \ third_party/boringssl/crypto/asn1/f_enum.c \ third_party/boringssl/crypto/asn1/f_int.c \ third_party/boringssl/crypto/asn1/f_string.c \ third_party/boringssl/crypto/asn1/t_bitst.c \ - third_party/boringssl/crypto/asn1/t_pkey.c \ third_party/boringssl/crypto/asn1/tasn_dec.c \ third_party/boringssl/crypto/asn1/tasn_enc.c \ third_party/boringssl/crypto/asn1/tasn_fre.c \ third_party/boringssl/crypto/asn1/tasn_new.c \ - third_party/boringssl/crypto/asn1/tasn_prn.c \ third_party/boringssl/crypto/asn1/tasn_typ.c \ third_party/boringssl/crypto/asn1/tasn_utl.c \ third_party/boringssl/crypto/asn1/x_bignum.c \ @@ -362,6 +357,7 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/bn/generic.c \ third_party/boringssl/crypto/bn/kronecker.c \ third_party/boringssl/crypto/bn/montgomery.c \ + third_party/boringssl/crypto/bn/montgomery_inv.c \ third_party/boringssl/crypto/bn/mul.c \ third_party/boringssl/crypto/bn/prime.c \ third_party/boringssl/crypto/bn/random.c \ @@ -373,8 +369,7 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/bytestring/ber.c \ third_party/boringssl/crypto/bytestring/cbb.c \ third_party/boringssl/crypto/bytestring/cbs.c \ - third_party/boringssl/crypto/chacha/chacha_generic.c \ - third_party/boringssl/crypto/chacha/chacha_vec.c \ + third_party/boringssl/crypto/chacha/chacha.c \ third_party/boringssl/crypto/cipher/aead.c \ third_party/boringssl/crypto/cipher/cipher.c \ third_party/boringssl/crypto/cipher/derive_key.c \ @@ -389,10 +384,14 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/cipher/tls_cbc.c \ third_party/boringssl/crypto/cmac/cmac.c \ third_party/boringssl/crypto/conf/conf.c \ + third_party/boringssl/crypto/cpu-aarch64-linux.c \ + third_party/boringssl/crypto/cpu-arm-linux.c \ third_party/boringssl/crypto/cpu-arm.c \ third_party/boringssl/crypto/cpu-intel.c \ + third_party/boringssl/crypto/cpu-ppc64le.c \ third_party/boringssl/crypto/crypto.c \ third_party/boringssl/crypto/curve25519/curve25519.c \ + third_party/boringssl/crypto/curve25519/spake25519.c \ third_party/boringssl/crypto/curve25519/x25519-x86_64.c \ third_party/boringssl/crypto/des/des.c \ third_party/boringssl/crypto/dh/check.c \ @@ -401,8 +400,6 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/dh/params.c \ third_party/boringssl/crypto/digest/digest.c \ third_party/boringssl/crypto/digest/digests.c \ - third_party/boringssl/crypto/directory_posix.c \ - third_party/boringssl/crypto/directory_win.c \ third_party/boringssl/crypto/dsa/dsa.c \ third_party/boringssl/crypto/dsa/dsa_asn1.c \ third_party/boringssl/crypto/ec/ec.c \ @@ -421,7 +418,6 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c \ third_party/boringssl/crypto/engine/engine.c \ third_party/boringssl/crypto/err/err.c \ - third_party/boringssl/crypto/evp/algorithm.c \ third_party/boringssl/crypto/evp/digestsign.c \ third_party/boringssl/crypto/evp/evp.c \ third_party/boringssl/crypto/evp/evp_asn1.c \ @@ -432,6 +428,7 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/evp/p_rsa.c \ third_party/boringssl/crypto/evp/p_rsa_asn1.c \ third_party/boringssl/crypto/evp/pbkdf.c \ + third_party/boringssl/crypto/evp/print.c \ third_party/boringssl/crypto/evp/sign.c \ third_party/boringssl/crypto/ex_data.c \ third_party/boringssl/crypto/hkdf/hkdf.c \ @@ -445,6 +442,12 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/modes/ctr.c \ third_party/boringssl/crypto/modes/gcm.c \ third_party/boringssl/crypto/modes/ofb.c \ + third_party/boringssl/crypto/newhope/error_correction.c \ + third_party/boringssl/crypto/newhope/newhope.c \ + third_party/boringssl/crypto/newhope/ntt.c \ + third_party/boringssl/crypto/newhope/poly.c \ + third_party/boringssl/crypto/newhope/precomp.c \ + third_party/boringssl/crypto/newhope/reduce.c \ third_party/boringssl/crypto/obj/obj.c \ third_party/boringssl/crypto/obj/obj_xref.c \ third_party/boringssl/crypto/pem/pem_all.c \ @@ -462,6 +465,7 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/poly1305/poly1305.c \ third_party/boringssl/crypto/poly1305/poly1305_arm.c \ third_party/boringssl/crypto/poly1305/poly1305_vec.c \ + third_party/boringssl/crypto/rand/deterministic.c \ third_party/boringssl/crypto/rand/rand.c \ third_party/boringssl/crypto/rand/urandom.c \ third_party/boringssl/crypto/rand/windows.c \ @@ -486,11 +490,13 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/x509/a_sign.c \ third_party/boringssl/crypto/x509/a_strex.c \ third_party/boringssl/crypto/x509/a_verify.c \ + third_party/boringssl/crypto/x509/algorithm.c \ third_party/boringssl/crypto/x509/asn1_gen.c \ third_party/boringssl/crypto/x509/by_dir.c \ third_party/boringssl/crypto/x509/by_file.c \ third_party/boringssl/crypto/x509/i2d_pr.c \ third_party/boringssl/crypto/x509/pkcs7.c \ + third_party/boringssl/crypto/x509/rsa_pss.c \ third_party/boringssl/crypto/x509/t_crl.c \ third_party/boringssl/crypto/x509/t_req.c \ third_party/boringssl/crypto/x509/t_x509.c \ @@ -565,21 +571,17 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/crypto/x509v3/v3_utl.c \ third_party/boringssl/ssl/custom_extensions.c \ third_party/boringssl/ssl/d1_both.c \ - third_party/boringssl/ssl/d1_clnt.c \ third_party/boringssl/ssl/d1_lib.c \ - third_party/boringssl/ssl/d1_meth.c \ third_party/boringssl/ssl/d1_pkt.c \ third_party/boringssl/ssl/d1_srtp.c \ - third_party/boringssl/ssl/d1_srvr.c \ + third_party/boringssl/ssl/dtls_method.c \ third_party/boringssl/ssl/dtls_record.c \ - third_party/boringssl/ssl/pqueue/pqueue.c \ + third_party/boringssl/ssl/handshake_client.c \ + third_party/boringssl/ssl/handshake_server.c \ third_party/boringssl/ssl/s3_both.c \ - third_party/boringssl/ssl/s3_clnt.c \ third_party/boringssl/ssl/s3_enc.c \ third_party/boringssl/ssl/s3_lib.c \ - third_party/boringssl/ssl/s3_meth.c \ third_party/boringssl/ssl/s3_pkt.c \ - third_party/boringssl/ssl/s3_srvr.c \ third_party/boringssl/ssl/ssl_aead_ctx.c \ third_party/boringssl/ssl/ssl_asn1.c \ third_party/boringssl/ssl/ssl_buffer.c \ @@ -593,6 +595,11 @@ if test "$PHP_GRPC" != "no"; then third_party/boringssl/ssl/ssl_stat.c \ third_party/boringssl/ssl/t1_enc.c \ third_party/boringssl/ssl/t1_lib.c \ + third_party/boringssl/ssl/tls13_both.c \ + third_party/boringssl/ssl/tls13_client.c \ + third_party/boringssl/ssl/tls13_enc.c \ + third_party/boringssl/ssl/tls13_server.c \ + third_party/boringssl/ssl/tls_method.c \ third_party/boringssl/ssl/tls_record.c \ , $ext_shared, , -Wall -Werror \ -Wno-parentheses-equality -Wno-unused-value -std=c11 \ @@ -675,6 +682,7 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/md4) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/md5) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/modes) + PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/newhope) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/obj) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/pem) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/pkcs8) @@ -687,6 +695,5 @@ if test "$PHP_GRPC" != "no"; then PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/x509) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/crypto/x509v3) PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/ssl) - PHP_ADD_BUILD_DIR($ext_builddir/third_party/boringssl/ssl/pqueue) PHP_ADD_BUILD_DIR($ext_builddir/third_party/nanopb) fi diff --git a/grpc.gemspec b/grpc.gemspec index cfc0c35aa3e..356851521d2 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -577,23 +577,22 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/conf/internal.h ) s.files += %w( third_party/boringssl/crypto/curve25519/internal.h ) s.files += %w( third_party/boringssl/crypto/des/internal.h ) - s.files += %w( third_party/boringssl/crypto/dh/internal.h ) s.files += %w( third_party/boringssl/crypto/digest/internal.h ) s.files += %w( third_party/boringssl/crypto/digest/md32_common.h ) - s.files += %w( third_party/boringssl/crypto/directory.h ) s.files += %w( third_party/boringssl/crypto/ec/internal.h ) s.files += %w( third_party/boringssl/crypto/ec/p256-x86_64-table.h ) s.files += %w( third_party/boringssl/crypto/evp/internal.h ) s.files += %w( third_party/boringssl/crypto/internal.h ) s.files += %w( third_party/boringssl/crypto/modes/internal.h ) + s.files += %w( third_party/boringssl/crypto/newhope/internal.h ) s.files += %w( third_party/boringssl/crypto/obj/obj_dat.h ) s.files += %w( third_party/boringssl/crypto/obj/obj_xref.h ) s.files += %w( third_party/boringssl/crypto/pkcs8/internal.h ) + s.files += %w( third_party/boringssl/crypto/poly1305/internal.h ) s.files += %w( third_party/boringssl/crypto/rand/internal.h ) s.files += %w( third_party/boringssl/crypto/rsa/internal.h ) - s.files += %w( third_party/boringssl/crypto/test/scoped_types.h ) - s.files += %w( third_party/boringssl/crypto/test/test_util.h ) s.files += %w( third_party/boringssl/crypto/x509/charmap.h ) + s.files += %w( third_party/boringssl/crypto/x509/internal.h ) s.files += %w( third_party/boringssl/crypto/x509/vpm_int.h ) s.files += %w( third_party/boringssl/crypto/x509v3/ext_dat.h ) s.files += %w( third_party/boringssl/crypto/x509v3/pcy_int.h ) @@ -639,10 +638,12 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/include/openssl/md4.h ) s.files += %w( third_party/boringssl/include/openssl/md5.h ) s.files += %w( third_party/boringssl/include/openssl/mem.h ) + s.files += %w( third_party/boringssl/include/openssl/newhope.h ) + s.files += %w( third_party/boringssl/include/openssl/nid.h ) s.files += %w( third_party/boringssl/include/openssl/obj.h ) s.files += %w( third_party/boringssl/include/openssl/obj_mac.h ) s.files += %w( third_party/boringssl/include/openssl/objects.h ) - s.files += %w( third_party/boringssl/include/openssl/opensslfeatures.h ) + s.files += %w( third_party/boringssl/include/openssl/opensslconf.h ) s.files += %w( third_party/boringssl/include/openssl/opensslv.h ) s.files += %w( third_party/boringssl/include/openssl/ossl_typ.h ) s.files += %w( third_party/boringssl/include/openssl/pem.h ) @@ -650,9 +651,9 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/include/openssl/pkcs7.h ) s.files += %w( third_party/boringssl/include/openssl/pkcs8.h ) s.files += %w( third_party/boringssl/include/openssl/poly1305.h ) - s.files += %w( third_party/boringssl/include/openssl/pqueue.h ) s.files += %w( third_party/boringssl/include/openssl/rand.h ) s.files += %w( third_party/boringssl/include/openssl/rc4.h ) + s.files += %w( third_party/boringssl/include/openssl/ripemd.h ) s.files += %w( third_party/boringssl/include/openssl/rsa.h ) s.files += %w( third_party/boringssl/include/openssl/safestack.h ) s.files += %w( third_party/boringssl/include/openssl/sha.h ) @@ -669,16 +670,11 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/include/openssl/x509_vfy.h ) s.files += %w( third_party/boringssl/include/openssl/x509v3.h ) s.files += %w( third_party/boringssl/ssl/internal.h ) - s.files += %w( third_party/boringssl/ssl/test/async_bio.h ) - s.files += %w( third_party/boringssl/ssl/test/packeted_bio.h ) - s.files += %w( third_party/boringssl/ssl/test/scoped_types.h ) - s.files += %w( third_party/boringssl/ssl/test/test_config.h ) s.files += %w( src/boringssl/err_data.c ) s.files += %w( third_party/boringssl/crypto/aes/aes.c ) s.files += %w( third_party/boringssl/crypto/aes/mode_wrappers.c ) s.files += %w( third_party/boringssl/crypto/asn1/a_bitstr.c ) s.files += %w( third_party/boringssl/crypto/asn1/a_bool.c ) - s.files += %w( third_party/boringssl/crypto/asn1/a_bytes.c ) s.files += %w( third_party/boringssl/crypto/asn1/a_d2i_fp.c ) s.files += %w( third_party/boringssl/crypto/asn1/a_dup.c ) s.files += %w( third_party/boringssl/crypto/asn1/a_enum.c ) @@ -697,18 +693,14 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/asn1/asn1_lib.c ) s.files += %w( third_party/boringssl/crypto/asn1/asn1_par.c ) s.files += %w( third_party/boringssl/crypto/asn1/asn_pack.c ) - s.files += %w( third_party/boringssl/crypto/asn1/bio_asn1.c ) - s.files += %w( third_party/boringssl/crypto/asn1/bio_ndef.c ) s.files += %w( third_party/boringssl/crypto/asn1/f_enum.c ) s.files += %w( third_party/boringssl/crypto/asn1/f_int.c ) s.files += %w( third_party/boringssl/crypto/asn1/f_string.c ) s.files += %w( third_party/boringssl/crypto/asn1/t_bitst.c ) - s.files += %w( third_party/boringssl/crypto/asn1/t_pkey.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_dec.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_enc.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_fre.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_new.c ) - s.files += %w( third_party/boringssl/crypto/asn1/tasn_prn.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_typ.c ) s.files += %w( third_party/boringssl/crypto/asn1/tasn_utl.c ) s.files += %w( third_party/boringssl/crypto/asn1/x_bignum.c ) @@ -738,6 +730,7 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/bn/generic.c ) s.files += %w( third_party/boringssl/crypto/bn/kronecker.c ) s.files += %w( third_party/boringssl/crypto/bn/montgomery.c ) + s.files += %w( third_party/boringssl/crypto/bn/montgomery_inv.c ) s.files += %w( third_party/boringssl/crypto/bn/mul.c ) s.files += %w( third_party/boringssl/crypto/bn/prime.c ) s.files += %w( third_party/boringssl/crypto/bn/random.c ) @@ -749,8 +742,7 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/bytestring/ber.c ) s.files += %w( third_party/boringssl/crypto/bytestring/cbb.c ) s.files += %w( third_party/boringssl/crypto/bytestring/cbs.c ) - s.files += %w( third_party/boringssl/crypto/chacha/chacha_generic.c ) - s.files += %w( third_party/boringssl/crypto/chacha/chacha_vec.c ) + s.files += %w( third_party/boringssl/crypto/chacha/chacha.c ) s.files += %w( third_party/boringssl/crypto/cipher/aead.c ) s.files += %w( third_party/boringssl/crypto/cipher/cipher.c ) s.files += %w( third_party/boringssl/crypto/cipher/derive_key.c ) @@ -765,10 +757,14 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/cipher/tls_cbc.c ) s.files += %w( third_party/boringssl/crypto/cmac/cmac.c ) s.files += %w( third_party/boringssl/crypto/conf/conf.c ) + s.files += %w( third_party/boringssl/crypto/cpu-aarch64-linux.c ) + s.files += %w( third_party/boringssl/crypto/cpu-arm-linux.c ) s.files += %w( third_party/boringssl/crypto/cpu-arm.c ) s.files += %w( third_party/boringssl/crypto/cpu-intel.c ) + s.files += %w( third_party/boringssl/crypto/cpu-ppc64le.c ) s.files += %w( third_party/boringssl/crypto/crypto.c ) s.files += %w( third_party/boringssl/crypto/curve25519/curve25519.c ) + s.files += %w( third_party/boringssl/crypto/curve25519/spake25519.c ) s.files += %w( third_party/boringssl/crypto/curve25519/x25519-x86_64.c ) s.files += %w( third_party/boringssl/crypto/des/des.c ) s.files += %w( third_party/boringssl/crypto/dh/check.c ) @@ -777,8 +773,6 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/dh/params.c ) s.files += %w( third_party/boringssl/crypto/digest/digest.c ) s.files += %w( third_party/boringssl/crypto/digest/digests.c ) - s.files += %w( third_party/boringssl/crypto/directory_posix.c ) - s.files += %w( third_party/boringssl/crypto/directory_win.c ) s.files += %w( third_party/boringssl/crypto/dsa/dsa.c ) s.files += %w( third_party/boringssl/crypto/dsa/dsa_asn1.c ) s.files += %w( third_party/boringssl/crypto/ec/ec.c ) @@ -797,7 +791,6 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c ) s.files += %w( third_party/boringssl/crypto/engine/engine.c ) s.files += %w( third_party/boringssl/crypto/err/err.c ) - s.files += %w( third_party/boringssl/crypto/evp/algorithm.c ) s.files += %w( third_party/boringssl/crypto/evp/digestsign.c ) s.files += %w( third_party/boringssl/crypto/evp/evp.c ) s.files += %w( third_party/boringssl/crypto/evp/evp_asn1.c ) @@ -808,6 +801,7 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/evp/p_rsa.c ) s.files += %w( third_party/boringssl/crypto/evp/p_rsa_asn1.c ) s.files += %w( third_party/boringssl/crypto/evp/pbkdf.c ) + s.files += %w( third_party/boringssl/crypto/evp/print.c ) s.files += %w( third_party/boringssl/crypto/evp/sign.c ) s.files += %w( third_party/boringssl/crypto/ex_data.c ) s.files += %w( third_party/boringssl/crypto/hkdf/hkdf.c ) @@ -821,6 +815,12 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/modes/ctr.c ) s.files += %w( third_party/boringssl/crypto/modes/gcm.c ) s.files += %w( third_party/boringssl/crypto/modes/ofb.c ) + s.files += %w( third_party/boringssl/crypto/newhope/error_correction.c ) + s.files += %w( third_party/boringssl/crypto/newhope/newhope.c ) + s.files += %w( third_party/boringssl/crypto/newhope/ntt.c ) + s.files += %w( third_party/boringssl/crypto/newhope/poly.c ) + s.files += %w( third_party/boringssl/crypto/newhope/precomp.c ) + s.files += %w( third_party/boringssl/crypto/newhope/reduce.c ) s.files += %w( third_party/boringssl/crypto/obj/obj.c ) s.files += %w( third_party/boringssl/crypto/obj/obj_xref.c ) s.files += %w( third_party/boringssl/crypto/pem/pem_all.c ) @@ -838,6 +838,7 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/poly1305/poly1305.c ) s.files += %w( third_party/boringssl/crypto/poly1305/poly1305_arm.c ) s.files += %w( third_party/boringssl/crypto/poly1305/poly1305_vec.c ) + s.files += %w( third_party/boringssl/crypto/rand/deterministic.c ) s.files += %w( third_party/boringssl/crypto/rand/rand.c ) s.files += %w( third_party/boringssl/crypto/rand/urandom.c ) s.files += %w( third_party/boringssl/crypto/rand/windows.c ) @@ -862,11 +863,13 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/x509/a_sign.c ) s.files += %w( third_party/boringssl/crypto/x509/a_strex.c ) s.files += %w( third_party/boringssl/crypto/x509/a_verify.c ) + s.files += %w( third_party/boringssl/crypto/x509/algorithm.c ) s.files += %w( third_party/boringssl/crypto/x509/asn1_gen.c ) s.files += %w( third_party/boringssl/crypto/x509/by_dir.c ) s.files += %w( third_party/boringssl/crypto/x509/by_file.c ) s.files += %w( third_party/boringssl/crypto/x509/i2d_pr.c ) s.files += %w( third_party/boringssl/crypto/x509/pkcs7.c ) + s.files += %w( third_party/boringssl/crypto/x509/rsa_pss.c ) s.files += %w( third_party/boringssl/crypto/x509/t_crl.c ) s.files += %w( third_party/boringssl/crypto/x509/t_req.c ) s.files += %w( third_party/boringssl/crypto/x509/t_x509.c ) @@ -941,21 +944,17 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/crypto/x509v3/v3_utl.c ) s.files += %w( third_party/boringssl/ssl/custom_extensions.c ) s.files += %w( third_party/boringssl/ssl/d1_both.c ) - s.files += %w( third_party/boringssl/ssl/d1_clnt.c ) s.files += %w( third_party/boringssl/ssl/d1_lib.c ) - s.files += %w( third_party/boringssl/ssl/d1_meth.c ) s.files += %w( third_party/boringssl/ssl/d1_pkt.c ) s.files += %w( third_party/boringssl/ssl/d1_srtp.c ) - s.files += %w( third_party/boringssl/ssl/d1_srvr.c ) + s.files += %w( third_party/boringssl/ssl/dtls_method.c ) s.files += %w( third_party/boringssl/ssl/dtls_record.c ) - s.files += %w( third_party/boringssl/ssl/pqueue/pqueue.c ) + s.files += %w( third_party/boringssl/ssl/handshake_client.c ) + s.files += %w( third_party/boringssl/ssl/handshake_server.c ) s.files += %w( third_party/boringssl/ssl/s3_both.c ) - s.files += %w( third_party/boringssl/ssl/s3_clnt.c ) s.files += %w( third_party/boringssl/ssl/s3_enc.c ) s.files += %w( third_party/boringssl/ssl/s3_lib.c ) - s.files += %w( third_party/boringssl/ssl/s3_meth.c ) s.files += %w( third_party/boringssl/ssl/s3_pkt.c ) - s.files += %w( third_party/boringssl/ssl/s3_srvr.c ) s.files += %w( third_party/boringssl/ssl/ssl_aead_ctx.c ) s.files += %w( third_party/boringssl/ssl/ssl_asn1.c ) s.files += %w( third_party/boringssl/ssl/ssl_buffer.c ) @@ -969,6 +968,11 @@ Gem::Specification.new do |s| s.files += %w( third_party/boringssl/ssl/ssl_stat.c ) s.files += %w( third_party/boringssl/ssl/t1_enc.c ) s.files += %w( third_party/boringssl/ssl/t1_lib.c ) + s.files += %w( third_party/boringssl/ssl/tls13_both.c ) + s.files += %w( third_party/boringssl/ssl/tls13_client.c ) + s.files += %w( third_party/boringssl/ssl/tls13_enc.c ) + s.files += %w( third_party/boringssl/ssl/tls13_server.c ) + s.files += %w( third_party/boringssl/ssl/tls_method.c ) s.files += %w( third_party/boringssl/ssl/tls_record.c ) s.files += %w( third_party/zlib/crc32.h ) s.files += %w( third_party/zlib/deflate.h ) diff --git a/package.xml b/package.xml index aa1894f4086..69fa8711d88 100644 --- a/package.xml +++ b/package.xml @@ -586,23 +586,22 @@ - - + + - - + @@ -648,10 +647,12 @@ + + - + @@ -659,9 +660,9 @@ - + @@ -678,16 +679,11 @@ - - - - - @@ -706,18 +702,14 @@ - - - - @@ -747,6 +739,7 @@ + @@ -758,8 +751,7 @@ - - + @@ -774,10 +766,14 @@ + + + + @@ -786,8 +782,6 @@ - - @@ -806,7 +800,6 @@ - @@ -817,6 +810,7 @@ + @@ -830,6 +824,12 @@ + + + + + + @@ -847,6 +847,7 @@ + @@ -871,11 +872,13 @@ + + @@ -950,21 +953,17 @@ - - - + - + + - - - @@ -978,6 +977,11 @@ + + + + + diff --git a/src/boringssl/err_data.c b/src/boringssl/err_data.c index d4cc08bd99c..c1257cdc787 100644 --- a/src/boringssl/err_data.c +++ b/src/boringssl/err_data.c @@ -54,182 +54,166 @@ OPENSSL_COMPILE_ASSERT(ERR_LIB_USER == 32, library_values_changed_32); OPENSSL_COMPILE_ASSERT(ERR_NUM_LIBS == 33, library_values_changed_num); const uint32_t kOpenSSLReasonValues[] = { - 0xc3207ab, - 0xc3287c5, - 0xc3307d4, - 0xc3387e4, - 0xc3407f3, - 0xc34880c, - 0xc350818, - 0xc358835, - 0xc360847, - 0xc368855, - 0xc370865, - 0xc378872, - 0xc380882, - 0xc38888d, - 0xc3908a3, - 0xc3988b2, - 0xc3a08c6, - 0xc3a87b8, - 0xc3b00b0, - 0x10321484, - 0x10329490, - 0x103314a9, - 0x103394bc, - 0x10340ded, - 0x103494cf, - 0x103514e4, - 0x10359516, - 0x1036152f, - 0x10369544, - 0x10371562, - 0x10379571, - 0x1038158d, - 0x103895a8, - 0x103915b7, - 0x103995d3, - 0x103a15ee, - 0x103a9605, - 0x103b1616, - 0x103b962a, - 0x103c1649, - 0x103c9658, - 0x103d166f, - 0x103d9682, - 0x103e0b5d, - 0x103e96b3, - 0x103f16c6, - 0x103f96e0, - 0x104016f0, - 0x10409704, - 0x1041171a, - 0x10419732, - 0x10421747, - 0x1042975b, - 0x1043176d, - 0x104385c1, - 0x104408b2, - 0x10449782, - 0x10451799, - 0x104597ae, - 0x104617bc, - 0x10469695, - 0x104714f7, - 0x104787b8, - 0x104800b0, - 0x10488b8c, - 0x14320b40, - 0x14328b4e, - 0x14330b5d, - 0x14338b6f, + 0xc320838, + 0xc328852, + 0xc330861, + 0xc338871, + 0xc340880, + 0xc348899, + 0xc3508a5, + 0xc3588c2, + 0xc3608d4, + 0xc3688e2, + 0xc3708f2, + 0xc3788ff, + 0xc38090f, + 0xc38891a, + 0xc390930, + 0xc39893f, + 0xc3a0953, + 0xc3a8845, + 0xc3b00ea, + 0x10320845, + 0x103293ab, + 0x103313b7, + 0x103393d0, + 0x103413e3, + 0x10348e8b, + 0x10350c19, + 0x103593f6, + 0x1036140b, + 0x1036941e, + 0x1037143d, + 0x10379456, + 0x1038146b, + 0x10389489, + 0x10391498, + 0x103994b4, + 0x103a14cf, + 0x103a94de, + 0x103b14fa, + 0x103b9515, + 0x103c152c, + 0x103c80ea, + 0x103d153d, + 0x103d9551, + 0x103e1570, + 0x103e957f, + 0x103f1596, + 0x103f95a9, + 0x10400bea, + 0x104095bc, + 0x104115da, + 0x104195ed, + 0x10421607, + 0x10429617, + 0x1043162b, + 0x10439641, + 0x10441659, + 0x1044966e, + 0x10451682, + 0x10459694, + 0x104605fb, + 0x1046893f, + 0x104716a9, + 0x104796c0, + 0x104816d5, + 0x104896e3, + 0x14320bcd, + 0x14328bdb, + 0x14330bea, + 0x14338bfc, + 0x143400ac, + 0x143480ea, 0x18320083, - 0x18328e53, - 0x18340e81, - 0x18348e95, - 0x18358ecc, - 0x18368ef9, - 0x18370f0c, - 0x18378f20, - 0x18380f44, - 0x18388f52, - 0x18390f68, - 0x18398f7c, - 0x183a0f8c, - 0x183b0f9c, - 0x183b8fb1, - 0x183c8fdc, - 0x183d0ff0, - 0x183d9000, - 0x183e0b98, - 0x183e900d, - 0x183f101f, - 0x183f902a, - 0x1840103a, - 0x1840904b, - 0x1841105c, - 0x1841906e, - 0x18421097, - 0x184290c9, - 0x184310d8, - 0x18451141, - 0x18459157, - 0x18461172, - 0x18468ee4, - 0x184709ca, - 0x18478094, - 0x18480fc8, - 0x1848910d, - 0x18490e69, - 0x18498eaa, - 0x184a11a8, - 0x184a9125, - 0x184b10ec, - 0x184b8e43, - 0x184c10b0, - 0x184c865c, - 0x184d118d, - 0x184d80b0, - 0x203211cf, - 0x243211db, - 0x243288f8, - 0x243311ed, - 0x243391fa, - 0x24341207, - 0x24349219, - 0x24351228, - 0x24359245, - 0x24361252, - 0x24369260, - 0x2437126e, - 0x2437927c, - 0x24381285, - 0x24389292, - 0x243912a5, - 0x28320b80, - 0x28328b98, - 0x28330b5d, - 0x28338bab, - 0x28340b8c, - 0x28348094, - 0x283500b0, - 0x2c32281d, - 0x2c32a82b, - 0x2c33283d, - 0x2c33a84f, - 0x2c342863, - 0x2c34a875, - 0x2c352890, - 0x2c35a8a2, - 0x2c3628b5, - 0x2c3682f3, - 0x2c3728c2, - 0x2c37a8d4, - 0x2c3828e7, - 0x2c38a8f5, - 0x2c392905, - 0x2c39a917, - 0x2c3a292b, - 0x2c3aa93c, - 0x2c3b1365, - 0x2c3ba94d, - 0x2c3c2961, - 0x2c3ca977, - 0x2c3d2990, - 0x2c3da9be, - 0x2c3e29cc, - 0x2c3ea9e4, - 0x2c3f29fc, - 0x2c3faa09, - 0x2c402a2c, - 0x2c40aa4b, - 0x2c4111cf, - 0x2c41aa5c, - 0x2c422a6f, - 0x2c429141, - 0x2c432a80, - 0x2c438693, - 0x2c4429ad, + 0x18328ee1, + 0x183300ac, + 0x18338ef7, + 0x18340f0b, + 0x183480ea, + 0x18350f20, + 0x18358f38, + 0x18360f4d, + 0x18368f61, + 0x18370f85, + 0x18378f9b, + 0x18380faf, + 0x18388fbf, + 0x18390a57, + 0x18398fcf, + 0x183a0fe4, + 0x183a8ff8, + 0x183b0c25, + 0x183b9005, + 0x183c1017, + 0x183c9022, + 0x183d1032, + 0x183d9043, + 0x183e1054, + 0x183e9066, + 0x183f108f, + 0x183f90a8, + 0x184010c0, + 0x184086d3, + 0x203210e7, + 0x243210f3, + 0x24328985, + 0x24331105, + 0x24339112, + 0x2434111f, + 0x24349131, + 0x24351140, + 0x2435915d, + 0x2436116a, + 0x24369178, + 0x24371186, + 0x24379194, + 0x2438119d, + 0x243891aa, + 0x243911bd, + 0x28320c0d, + 0x28328c25, + 0x28330bea, + 0x28338c38, + 0x28340c19, + 0x283480ac, + 0x283500ea, + 0x2c3228ca, + 0x2c32a8d8, + 0x2c3328ea, + 0x2c33a8fc, + 0x2c342910, + 0x2c34a922, + 0x2c35293d, + 0x2c35a94f, + 0x2c362962, + 0x2c36832d, + 0x2c37296f, + 0x2c37a981, + 0x2c382994, + 0x2c38a9ab, + 0x2c3929b9, + 0x2c39a9c9, + 0x2c3a29db, + 0x2c3aa9ef, + 0x2c3b2a00, + 0x2c3baa1f, + 0x2c3c2a33, + 0x2c3caa49, + 0x2c3d2a62, + 0x2c3daa7f, + 0x2c3e2a90, + 0x2c3eaa9e, + 0x2c3f2ab6, + 0x2c3faace, + 0x2c402adb, + 0x2c4090e7, + 0x2c412aec, + 0x2c41aaff, + 0x2c4210c0, + 0x2c42ab10, + 0x2c430720, + 0x2c43aa11, 0x30320000, 0x30328015, 0x3033001f, @@ -239,443 +223,465 @@ const uint32_t kOpenSSLReasonValues[] = { 0x3035006b, 0x30358083, 0x30360094, - 0x303680a1, - 0x303700b0, - 0x303780bd, - 0x303800d0, - 0x303880eb, - 0x30390100, - 0x30398114, - 0x303a0128, - 0x303a8139, - 0x303b0152, - 0x303b816f, - 0x303c017d, - 0x303c8191, - 0x303d01a1, - 0x303d81ba, - 0x303e01ca, - 0x303e81dd, - 0x303f01ec, - 0x303f81f8, - 0x3040020d, - 0x3040821d, - 0x30410234, - 0x30418241, - 0x30420254, - 0x30428263, - 0x30430278, - 0x30438299, - 0x304402ac, - 0x304482bf, - 0x304502d8, - 0x304582f3, - 0x30460310, - 0x30468329, - 0x30470337, - 0x30478348, - 0x30480357, - 0x3048836f, - 0x30490381, - 0x30498395, - 0x304a03b4, - 0x304a83c7, - 0x304b03d2, - 0x304b83e3, - 0x304c03ef, - 0x304c8405, - 0x304d0413, - 0x304d8429, - 0x304e043b, - 0x304e844d, - 0x304f0460, - 0x304f8473, - 0x30500484, - 0x30508494, - 0x305104ac, - 0x305184c1, - 0x305204d9, - 0x305284ed, - 0x30530505, - 0x3053851e, - 0x30540537, - 0x30548554, - 0x3055055f, - 0x30558577, - 0x30560587, - 0x30568598, - 0x305705ab, - 0x305785c1, - 0x305805ca, - 0x305885df, - 0x305905f2, - 0x30598601, - 0x305a0621, - 0x305a8630, - 0x305b063c, - 0x305b865c, - 0x305c0678, - 0x305c8689, - 0x305d0693, - 0x34320aba, - 0x34328ace, - 0x34330aeb, - 0x34338afe, - 0x34340b0d, - 0x34348b2a, + 0x303680ac, + 0x303700b9, + 0x303780c8, + 0x303800ea, + 0x303880f7, + 0x3039010a, + 0x30398125, + 0x303a013a, + 0x303a814e, + 0x303b0162, + 0x303b8173, + 0x303c018c, + 0x303c81a9, + 0x303d01b7, + 0x303d81cb, + 0x303e01db, + 0x303e81f4, + 0x303f0204, + 0x303f8217, + 0x30400226, + 0x30408232, + 0x30410247, + 0x30418257, + 0x3042026e, + 0x3042827b, + 0x3043028e, + 0x3043829d, + 0x304402b2, + 0x304482d3, + 0x304502e6, + 0x304582f9, + 0x30460312, + 0x3046832d, + 0x3047034a, + 0x30478363, + 0x30480371, + 0x30488382, + 0x30490391, + 0x304983a9, + 0x304a03bb, + 0x304a83cf, + 0x304b03ee, + 0x304b8401, + 0x304c040c, + 0x304c841d, + 0x304d0429, + 0x304d843f, + 0x304e044d, + 0x304e8463, + 0x304f0475, + 0x304f8487, + 0x3050049a, + 0x305084ad, + 0x305104be, + 0x305184ce, + 0x305204e6, + 0x305284fb, + 0x30530513, + 0x30538527, + 0x3054053f, + 0x30548558, + 0x30550571, + 0x3055858e, + 0x30560599, + 0x305685b1, + 0x305705c1, + 0x305785d2, + 0x305805e5, + 0x305885fb, + 0x30590604, + 0x30598619, + 0x305a062c, + 0x305a863b, + 0x305b065b, + 0x305b866a, + 0x305c068b, + 0x305c86a7, + 0x305d06b3, + 0x305d86d3, + 0x305e06ef, + 0x305e8700, + 0x305f0716, + 0x305f8720, + 0x34320b47, + 0x34328b5b, + 0x34330b78, + 0x34338b8b, + 0x34340b9a, + 0x34348bb7, 0x3c320083, - 0x3c328bd5, - 0x3c330bee, - 0x3c338c09, - 0x3c340c26, - 0x3c348c50, - 0x3c350c6b, - 0x3c358c80, - 0x3c360c99, - 0x3c368cb1, - 0x3c370cc2, - 0x3c378cd0, - 0x3c380cdd, - 0x3c388cf1, - 0x3c390b98, - 0x3c398d05, - 0x3c3a0d19, - 0x3c3a8872, - 0x3c3b0d29, - 0x3c3b8d44, - 0x3c3c0d56, - 0x3c3c8d6c, - 0x3c3d0d76, - 0x3c3d8d8a, - 0x3c3e0d98, - 0x3c3e8dbd, - 0x3c3f0bc1, - 0x3c3f8da6, - 0x3c400094, - 0x3c4080b0, - 0x3c410c41, - 0x403217d3, - 0x403297e9, - 0x40331817, - 0x40339821, - 0x40341838, - 0x40349856, - 0x40351866, - 0x40359878, - 0x40361885, - 0x40369891, - 0x403718a6, - 0x403798b8, - 0x403818c3, - 0x403898d5, - 0x40390ded, - 0x403998e5, - 0x403a18f8, - 0x403a9919, - 0x403b192a, - 0x403b993a, + 0x3c328c62, + 0x3c330c7b, + 0x3c338c96, + 0x3c340cb3, + 0x3c348cdd, + 0x3c350cf8, + 0x3c358d1e, + 0x3c360d37, + 0x3c368d4f, + 0x3c370d60, + 0x3c378d6e, + 0x3c380d7b, + 0x3c388d8f, + 0x3c390c25, + 0x3c398da3, + 0x3c3a0db7, + 0x3c3a88ff, + 0x3c3b0dc7, + 0x3c3b8de2, + 0x3c3c0df4, + 0x3c3c8e0a, + 0x3c3d0e14, + 0x3c3d8e28, + 0x3c3e0e36, + 0x3c3e8e5b, + 0x3c3f0c4e, + 0x3c3f8e44, + 0x3c4000ac, + 0x3c4080ea, + 0x3c410cce, + 0x3c418d0d, + 0x403216fa, + 0x40329710, + 0x4033173e, + 0x40339748, + 0x4034175f, + 0x4034977d, + 0x4035178d, + 0x4035979f, + 0x403617ac, + 0x403697b8, + 0x403717cd, + 0x403797df, + 0x403817ea, + 0x403897fc, + 0x40390e8b, + 0x4039980c, + 0x403a181f, + 0x403a9840, + 0x403b1851, + 0x403b9861, 0x403c0064, 0x403c8083, - 0x403d1946, - 0x403d995c, - 0x403e196b, - 0x403e997e, - 0x403f1998, - 0x403f99a6, - 0x404019bb, - 0x404099cf, - 0x404119ec, - 0x40419a07, - 0x40421a20, - 0x40429a33, - 0x40431a47, - 0x40439a5f, - 0x40441a76, - 0x40448094, - 0x40451a8b, - 0x40459a9d, - 0x40461ac1, - 0x40469ae1, - 0x40471aef, - 0x40479b03, - 0x40481b18, - 0x40489b31, - 0x40491b48, - 0x40499b62, - 0x404a1b79, - 0x404a9b97, - 0x404b1baf, - 0x404b9bc6, - 0x404c1bdc, - 0x404c9bee, - 0x404d1c0f, - 0x404d9c31, - 0x404e1c45, - 0x404e9c52, - 0x404f1c69, - 0x404f9c79, - 0x40501c89, - 0x40509c9d, - 0x40511cb8, - 0x40519cc8, - 0x40521cdf, - 0x40529cf1, - 0x40531d09, - 0x40539d1c, - 0x40541d31, - 0x40549d54, - 0x40551d62, - 0x40559d7f, - 0x40561d8c, - 0x40569da5, - 0x40571dbd, - 0x40579dd0, - 0x40581de5, - 0x40589df7, - 0x40591e07, - 0x40599e20, - 0x405a1e34, - 0x405a9e44, - 0x405b1e5c, - 0x405b9e6d, - 0x405c1e80, - 0x405c9e91, - 0x405d1e9e, - 0x405d9eb5, - 0x405e1ed5, - 0x405e8a08, - 0x405f1ef6, - 0x405f9f03, - 0x40601f11, - 0x40609f33, - 0x40611f5b, - 0x40619f70, - 0x40621f87, - 0x40629f98, - 0x40631fa9, - 0x40639fbe, - 0x40641fd5, - 0x40649fe6, - 0x40652001, - 0x4065a018, - 0x40662030, - 0x4066a05a, - 0x40672085, - 0x4067a0a6, - 0x406820b9, - 0x4068a0da, - 0x406920f5, - 0x4069a123, - 0x406a2144, - 0x406aa164, - 0x406b22ec, - 0x406ba30f, - 0x406c2325, - 0x406ca551, - 0x406d2580, - 0x406da5a8, - 0x406e25c1, - 0x406ea5d9, - 0x406f25f8, - 0x406fa60d, - 0x40702620, - 0x4070a63d, - 0x40710773, - 0x4071a64f, - 0x40722662, - 0x4072a67b, - 0x40732693, - 0x407390c9, - 0x407426a7, - 0x4074a6c1, - 0x407526d2, - 0x4075a6e6, - 0x407626f4, - 0x40769292, - 0x40772719, - 0x4077a73b, - 0x40782756, - 0x4078a76b, - 0x40792782, - 0x4079a798, - 0x407a27a4, - 0x407aa7b7, - 0x407b27cc, - 0x407ba7de, - 0x407c27f3, - 0x407ca7fc, - 0x41f42217, - 0x41f922a9, - 0x41fe219c, - 0x41fea378, - 0x41ff2469, - 0x42032230, - 0x42082252, - 0x4208a28e, - 0x42092180, - 0x4209a2c8, - 0x420a21d7, - 0x420aa1b7, - 0x420b21f7, - 0x420ba270, - 0x420c2485, - 0x420ca345, - 0x420d235f, - 0x420da396, - 0x421223b0, - 0x4217244c, - 0x4217a3f2, - 0x421c2414, - 0x421f23cf, - 0x4221249c, - 0x4226242f, - 0x422b2535, - 0x422ba4fe, - 0x422c251d, - 0x422ca4d8, - 0x422d24b7, - 0x4432069e, - 0x443286ad, - 0x443306b9, - 0x443386c7, - 0x443406da, - 0x443486eb, - 0x443506f2, - 0x443586fc, - 0x4436070f, - 0x44368725, - 0x44370737, - 0x44378744, - 0x44380753, - 0x4438875b, - 0x44390773, - 0x44398781, - 0x443a0794, - 0x4c3212bc, - 0x4c3292cc, - 0x4c3312df, - 0x4c3392ff, - 0x4c340094, - 0x4c3480b0, - 0x4c35130b, - 0x4c359319, - 0x4c361335, - 0x4c369348, - 0x4c371357, - 0x4c379365, - 0x4c38137a, - 0x4c389386, - 0x4c3913a6, - 0x4c3993d0, - 0x4c3a13e9, - 0x4c3a9402, - 0x4c3b05c1, - 0x4c3b941b, - 0x4c3c142d, - 0x4c3c943c, - 0x4c3d10c9, - 0x4c3d9455, - 0x4c3e1462, - 0x50322a92, - 0x5032aaa1, - 0x50332aac, - 0x5033aabc, - 0x50342ad5, - 0x5034aaef, - 0x50352afd, - 0x5035ab13, - 0x50362b25, - 0x5036ab3b, - 0x50372b54, - 0x5037ab67, - 0x50382b7f, - 0x5038ab90, - 0x50392ba5, - 0x5039abb9, - 0x503a2bd9, - 0x503aabef, - 0x503b2c07, - 0x503bac19, - 0x503c2c35, - 0x503cac4c, - 0x503d2c65, - 0x503dac7b, - 0x503e2c88, - 0x503eac9e, - 0x503f2cb0, - 0x503f8348, - 0x50402cc3, - 0x5040acd3, - 0x50412ced, - 0x5041acfc, - 0x50422d16, - 0x5042ad33, - 0x50432d43, - 0x5043ad53, - 0x50442d62, - 0x50448405, - 0x50452d76, - 0x5045ad94, - 0x50462da7, - 0x5046adbd, - 0x50472dcf, - 0x5047ade4, - 0x50482e0a, - 0x5048ae18, - 0x50492e2b, - 0x5049ae40, - 0x504a2e56, - 0x504aae66, - 0x504b2e86, - 0x504bae99, - 0x504c2ebc, - 0x504caeea, - 0x504d2efc, - 0x504daf19, - 0x504e2f34, - 0x504eaf50, - 0x504f2f62, - 0x504faf79, - 0x50502f88, - 0x50508678, - 0x50512f9b, - 0x58320e2b, - 0x68320ded, - 0x68328b98, - 0x68330bab, - 0x68338dfb, - 0x68340e0b, - 0x683480b0, - 0x6c320dc9, - 0x6c328b6f, - 0x6c330dd4, - 0x7432097e, - 0x783208e3, - 0x783288f8, - 0x78330904, + 0x403d18aa, + 0x403d98c0, + 0x403e18cf, + 0x403e98e2, + 0x403f18fc, + 0x403f990a, + 0x4040191f, + 0x40409933, + 0x40411950, + 0x4041996b, + 0x40421984, + 0x40429997, + 0x404319ab, + 0x404399c3, + 0x404419da, + 0x404480ac, + 0x404519ef, + 0x40459a01, + 0x40461a25, + 0x40469a45, + 0x40471a53, + 0x40479a7a, + 0x40481ab7, + 0x40489ad0, + 0x40491ae7, + 0x40499b01, + 0x404a1b18, + 0x404a9b36, + 0x404b1b4e, + 0x404b9b65, + 0x404c1b7b, + 0x404c9b8d, + 0x404d1bae, + 0x404d9bd0, + 0x404e1be4, + 0x404e9bf1, + 0x404f1c1e, + 0x404f9c47, + 0x40501c71, + 0x40509c85, + 0x40511ca0, + 0x40519cb0, + 0x40521cc7, + 0x40529ceb, + 0x40531d03, + 0x40539d16, + 0x40541d2b, + 0x40549d4e, + 0x40551d5c, + 0x40559d79, + 0x40561d86, + 0x40569d9f, + 0x40571db7, + 0x40579dca, + 0x40581ddf, + 0x40589e06, + 0x40591e35, + 0x40599e62, + 0x405a1e76, + 0x405a9e86, + 0x405b1e9e, + 0x405b9eaf, + 0x405c1ec2, + 0x405c9ed3, + 0x405d1ee0, + 0x405d9ef7, + 0x405e1f17, + 0x405e8a95, + 0x405f1f38, + 0x405f9f45, + 0x40601f53, + 0x40609f75, + 0x40611f9d, + 0x40619fb2, + 0x40621fc9, + 0x40629fda, + 0x40631feb, + 0x4063a000, + 0x40642017, + 0x4064a043, + 0x4065205e, + 0x4065a075, + 0x4066208d, + 0x4066a0b7, + 0x406720e2, + 0x4067a103, + 0x40682116, + 0x4068a137, + 0x40692169, + 0x4069a197, + 0x406a21b8, + 0x406aa1d8, + 0x406b2360, + 0x406ba383, + 0x406c2399, + 0x406ca5c5, + 0x406d25f4, + 0x406da61c, + 0x406e264a, + 0x406ea662, + 0x406f2681, + 0x406fa696, + 0x407026a9, + 0x4070a6c6, + 0x40710800, + 0x4071a6d8, + 0x407226eb, + 0x4072a704, + 0x4073271c, + 0x4073936d, + 0x40742730, + 0x4074a74a, + 0x4075275b, + 0x4075a76f, + 0x4076277d, + 0x407691aa, + 0x407727a2, + 0x4077a7c4, + 0x407827df, + 0x4078a818, + 0x4079282f, + 0x4079a845, + 0x407a2851, + 0x407aa864, + 0x407b2879, + 0x407ba88b, + 0x407c28a0, + 0x407ca8a9, + 0x407d2152, + 0x407d9c57, + 0x407e27f4, + 0x407e9e16, + 0x407f1a67, + 0x407f9887, + 0x40801c2e, + 0x40809a8f, + 0x40811cd9, + 0x40819c08, + 0x40822635, + 0x4082986d, + 0x40831df1, + 0x4083a028, + 0x40841aa3, + 0x40849e4e, + 0x41f4228b, + 0x41f9231d, + 0x41fe2210, + 0x41fea3ec, + 0x41ff24dd, + 0x420322a4, + 0x420822c6, + 0x4208a302, + 0x420921f4, + 0x4209a33c, + 0x420a224b, + 0x420aa22b, + 0x420b226b, + 0x420ba2e4, + 0x420c24f9, + 0x420ca3b9, + 0x420d23d3, + 0x420da40a, + 0x42122424, + 0x421724c0, + 0x4217a466, + 0x421c2488, + 0x421f2443, + 0x42212510, + 0x422624a3, + 0x422b25a9, + 0x422ba572, + 0x422c2591, + 0x422ca54c, + 0x422d252b, + 0x4432072b, + 0x4432873a, + 0x44330746, + 0x44338754, + 0x44340767, + 0x44348778, + 0x4435077f, + 0x44358789, + 0x4436079c, + 0x443687b2, + 0x443707c4, + 0x443787d1, + 0x443807e0, + 0x443887e8, + 0x44390800, + 0x4439880e, + 0x443a0821, + 0x4c3211d4, + 0x4c3291e4, + 0x4c3311f7, + 0x4c339217, + 0x4c3400ac, + 0x4c3480ea, + 0x4c351223, + 0x4c359231, + 0x4c36124d, + 0x4c369260, + 0x4c37126f, + 0x4c37927d, + 0x4c381292, + 0x4c38929e, + 0x4c3912be, + 0x4c3992e8, + 0x4c3a1301, + 0x4c3a931a, + 0x4c3b05fb, + 0x4c3b9333, + 0x4c3c1345, + 0x4c3c9354, + 0x4c3d136d, + 0x4c3d937c, + 0x4c3e1389, + 0x50322b22, + 0x5032ab31, + 0x50332b3c, + 0x5033ab4c, + 0x50342b65, + 0x5034ab7f, + 0x50352b8d, + 0x5035aba3, + 0x50362bb5, + 0x5036abcb, + 0x50372be4, + 0x5037abf7, + 0x50382c0f, + 0x5038ac20, + 0x50392c35, + 0x5039ac49, + 0x503a2c69, + 0x503aac7f, + 0x503b2c97, + 0x503baca9, + 0x503c2cc5, + 0x503cacdc, + 0x503d2cf5, + 0x503dad0b, + 0x503e2d18, + 0x503ead2e, + 0x503f2d40, + 0x503f8382, + 0x50402d53, + 0x5040ad63, + 0x50412d7d, + 0x5041ad8c, + 0x50422da6, + 0x5042adc3, + 0x50432dd3, + 0x5043ade3, + 0x50442df2, + 0x5044843f, + 0x50452e06, + 0x5045ae24, + 0x50462e37, + 0x5046ae4d, + 0x50472e5f, + 0x5047ae74, + 0x50482e9a, + 0x5048aea8, + 0x50492ebb, + 0x5049aed0, + 0x504a2ee6, + 0x504aaef6, + 0x504b2f16, + 0x504baf29, + 0x504c2f4c, + 0x504caf7a, + 0x504d2f8c, + 0x504dafa9, + 0x504e2fc4, + 0x504eafe0, + 0x504f2ff2, + 0x504fb009, + 0x50503018, + 0x505086ef, + 0x5051302b, + 0x58320ec9, + 0x68320e8b, + 0x68328c25, + 0x68330c38, + 0x68338e99, + 0x68340ea9, + 0x683480ea, + 0x6c320e67, + 0x6c328bfc, + 0x6c330e72, + 0x74320a0b, + 0x78320970, + 0x78328985, + 0x78330991, 0x78338083, - 0x78340913, - 0x78348928, - 0x78350947, - 0x78358969, - 0x7836097e, - 0x78368994, - 0x783709a4, - 0x783789b7, - 0x783809ca, - 0x783889dc, - 0x783909e9, - 0x78398a08, - 0x783a0a1d, - 0x783a8a2b, - 0x783b0a35, - 0x783b8a49, - 0x783c0a60, - 0x783c8a75, - 0x783d0a8c, - 0x783d8aa1, - 0x783e09f7, - 0x7c3211be, + 0x783409a0, + 0x783489b5, + 0x783509d4, + 0x783589f6, + 0x78360a0b, + 0x78368a21, + 0x78370a31, + 0x78378a44, + 0x78380a57, + 0x78388a69, + 0x78390a76, + 0x78398a95, + 0x783a0aaa, + 0x783a8ab8, + 0x783b0ac2, + 0x783b8ad6, + 0x783c0aed, + 0x783c8b02, + 0x783d0b19, + 0x783d8b2e, + 0x783e0a84, + 0x7c3210d6, }; const size_t kOpenSSLReasonValuesLen = sizeof(kOpenSSLReasonValues) / sizeof(kOpenSSLReasonValues[0]); @@ -689,8 +695,10 @@ const char kOpenSSLReasonStringData[] = "BN_LIB\0" "BOOLEAN_IS_WRONG_LENGTH\0" "BUFFER_TOO_SMALL\0" + "CONTEXT_NOT_INITIALISED\0" "DECODE_ERROR\0" "DEPTH_EXCEEDED\0" + "DIGEST_AND_KEY_TYPE_NOT_SUPPORTED\0" "ENCODE_ERROR\0" "ERROR_GETTING_TIME\0" "EXPECTING_AN_ASN1_SEQUENCE\0" @@ -762,10 +770,13 @@ const char kOpenSSLReasonStringData[] = "UNEXPECTED_EOC\0" "UNIVERSALSTRING_IS_WRONG_LENGTH\0" "UNKNOWN_FORMAT\0" + "UNKNOWN_MESSAGE_DIGEST_ALGORITHM\0" + "UNKNOWN_SIGNATURE_ALGORITHM\0" "UNKNOWN_TAG\0" "UNSUPPORTED_ANY_DEFINED_BY_TYPE\0" "UNSUPPORTED_PUBLIC_KEY_TYPE\0" "UNSUPPORTED_TYPE\0" + "WRONG_PUBLIC_KEY_TYPE\0" "WRONG_TAG\0" "WRONG_TYPE\0" "BAD_FOPEN_MODE\0" @@ -849,6 +860,7 @@ const char kOpenSSLReasonStringData[] = "GROUP_MISMATCH\0" "I2D_ECPKPARAMETERS_FAILURE\0" "INCOMPATIBLE_OBJECTS\0" + "INVALID_COFACTOR\0" "INVALID_COMPRESSED_POINT\0" "INVALID_COMPRESSION_BIT\0" "INVALID_ENCODING\0" @@ -873,27 +885,19 @@ const char kOpenSSLReasonStringData[] = "NOT_IMPLEMENTED\0" "RANDOM_NUMBER_GENERATION_FAILED\0" "OPERATION_NOT_SUPPORTED\0" - "BN_DECODE_ERROR\0" "COMMAND_NOT_SUPPORTED\0" - "CONTEXT_NOT_INITIALISED\0" "DIFFERENT_KEY_TYPES\0" "DIFFERENT_PARAMETERS\0" - "DIGEST_AND_KEY_TYPE_NOT_SUPPORTED\0" "EXPECTING_AN_EC_KEY_KEY\0" "EXPECTING_AN_RSA_KEY\0" - "EXPECTING_A_DH_KEY\0" "EXPECTING_A_DSA_KEY\0" "ILLEGAL_OR_UNSUPPORTED_PADDING_MODE\0" - "INVALID_CURVE\0" "INVALID_DIGEST_LENGTH\0" "INVALID_DIGEST_TYPE\0" "INVALID_KEYBITS\0" "INVALID_MGF1_MD\0" "INVALID_PADDING_MODE\0" - "INVALID_PSS_PARAMETERS\0" "INVALID_PSS_SALTLEN\0" - "INVALID_SALT_LENGTH\0" - "INVALID_TRAILER\0" "KEYS_NOT_SET\0" "NO_DEFAULT_DIGEST\0" "NO_KEY_SET\0" @@ -903,17 +907,8 @@ const char kOpenSSLReasonStringData[] = "NO_PARAMETERS_SET\0" "OPERATION_NOT_SUPPORTED_FOR_THIS_KEYTYPE\0" "OPERATON_NOT_INITIALIZED\0" - "PARAMETER_ENCODING_ERROR\0" - "UNKNOWN_DIGEST\0" - "UNKNOWN_MASK_DIGEST\0" - "UNKNOWN_MESSAGE_DIGEST_ALGORITHM\0" "UNKNOWN_PUBLIC_KEY_TYPE\0" - "UNKNOWN_SIGNATURE_ALGORITHM\0" "UNSUPPORTED_ALGORITHM\0" - "UNSUPPORTED_MASK_ALGORITHM\0" - "UNSUPPORTED_MASK_PARAMETER\0" - "UNSUPPORTED_SIGNATURE_TYPE\0" - "WRONG_PUBLIC_KEY_TYPE\0" "OUTPUT_TOO_LARGE\0" "UNKNOWN_NID\0" "BAD_BASE64_DECODE\0" @@ -949,6 +944,7 @@ const char kOpenSSLReasonStringData[] = "UNKNOWN_ALGORITHM\0" "UNKNOWN_CIPHER\0" "UNKNOWN_CIPHER_ALGORITHM\0" + "UNKNOWN_DIGEST\0" "UNKNOWN_HASH\0" "UNSUPPORTED_PRIVATE_KEY_ALGORITHM\0" "BAD_E_VALUE\0" @@ -1009,6 +1005,8 @@ const char kOpenSSLReasonStringData[] = "BAD_SSL_FILETYPE\0" "BAD_WRITE_RETRY\0" "BIO_NOT_SET\0" + "BLOCK_CIPHER_PAD_IS_WRONG\0" + "BUFFERED_MESSAGES_ON_CIPHER_CHANGE\0" "CA_DN_LENGTH_MISMATCH\0" "CA_DN_TOO_LONG\0" "CCS_RECEIVED_EARLY\0" @@ -1029,7 +1027,10 @@ const char kOpenSSLReasonStringData[] = "DH_PUBLIC_VALUE_LENGTH_IS_WRONG\0" "DH_P_TOO_LONG\0" "DIGEST_CHECK_FAILED\0" + "DOWNGRADE_DETECTED\0" "DTLS_MESSAGE_TOO_BIG\0" + "DUPLICATE_EXTENSION\0" + "DUPLICATE_KEY_SHARE\0" "ECC_CERT_NOT_FOR_SIGNING\0" "EMS_STATE_INCONSISTENT\0" "ENCRYPTED_LENGTH_TOO_LONG\0" @@ -1044,13 +1045,17 @@ const char kOpenSSLReasonStringData[] = "HTTPS_PROXY_REQUEST\0" "HTTP_REQUEST\0" "INAPPROPRIATE_FALLBACK\0" + "INVALID_ALPN_PROTOCOL\0" "INVALID_COMMAND\0" + "INVALID_COMPRESSION_LIST\0" "INVALID_MESSAGE\0" + "INVALID_OUTER_RECORD_TYPE\0" "INVALID_SSL_SESSION\0" "INVALID_TICKET_KEYS_LENGTH\0" "LENGTH_MISMATCH\0" "LIBRARY_HAS_NO_CIPHERS\0" "MISSING_EXTENSION\0" + "MISSING_KEY_SHARE\0" "MISSING_RSA_CERTIFICATE\0" "MISSING_TMP_DH_KEY\0" "MISSING_TMP_ECDH_KEY\0" @@ -1063,8 +1068,11 @@ const char kOpenSSLReasonStringData[] = "NO_CERTIFICATE_SET\0" "NO_CIPHERS_AVAILABLE\0" "NO_CIPHERS_PASSED\0" + "NO_CIPHERS_SPECIFIED\0" "NO_CIPHER_MATCH\0" + "NO_COMMON_SIGNATURE_ALGORITHMS\0" "NO_COMPRESSION_SPECIFIED\0" + "NO_GROUPS_SPECIFIED\0" "NO_METHOD_SPECIFIED\0" "NO_P256_SUPPORT\0" "NO_PRIVATE_KEY_ASSIGNED\0" @@ -1086,6 +1094,7 @@ const char kOpenSSLReasonStringData[] = "READ_TIMEOUT_EXPIRED\0" "RECORD_LENGTH_MISMATCH\0" "RECORD_TOO_LARGE\0" + "RENEGOTIATION_EMS_MISMATCH\0" "RENEGOTIATION_ENCODING_ERR\0" "RENEGOTIATION_MISMATCH\0" "REQUIRED_CIPHER_MISSING\0" @@ -1095,6 +1104,7 @@ const char kOpenSSLReasonStringData[] = "SERVERHELLO_TLSEXT\0" "SESSION_ID_CONTEXT_UNINITIALIZED\0" "SESSION_MAY_NOT_BE_CREATED\0" + "SHUTDOWN_WHILE_IN_INIT\0" "SIGNATURE_ALGORITHMS_EXTENSION_SENT_BY_SERVER\0" "SRTP_COULD_NOT_ALLOCATE_PROFILES\0" "SRTP_UNKNOWN_PROTECTION_PROFILE\0" @@ -1135,6 +1145,7 @@ const char kOpenSSLReasonStringData[] = "TLS_PEER_DID_NOT_RESPOND_WITH_CERTIFICATE_LIST\0" "TLS_RSA_ENCRYPTED_VALUE_LENGTH_IS_WRONG\0" "TOO_MANY_EMPTY_FRAGMENTS\0" + "TOO_MANY_KEY_UPDATES\0" "TOO_MANY_WARNING_ALERTS\0" "UNABLE_TO_FIND_ECDH_PARAMETERS\0" "UNEXPECTED_EXTENSION\0" @@ -1153,6 +1164,7 @@ const char kOpenSSLReasonStringData[] = "UNSUPPORTED_COMPRESSION_ALGORITHM\0" "UNSUPPORTED_ELLIPTIC_CURVE\0" "UNSUPPORTED_PROTOCOL\0" + "UNSUPPORTED_PROTOCOL_FOR_CUSTOM_KEY\0" "WRONG_CERTIFICATE_TYPE\0" "WRONG_CIPHER_RETURNED\0" "WRONG_CURVE\0" @@ -1173,12 +1185,14 @@ const char kOpenSSLReasonStringData[] = "IDP_MISMATCH\0" "INVALID_DIRECTORY\0" "INVALID_FIELD_NAME\0" + "INVALID_PSS_PARAMETERS\0" "INVALID_TRUST\0" "ISSUER_MISMATCH\0" "KEY_TYPE_MISMATCH\0" "KEY_VALUES_MISMATCH\0" "LOADING_CERT_DIR\0" "LOADING_DEFAULTS\0" + "NAME_TOO_LONG\0" "NEWER_CRL_NOT_NEWER\0" "NOT_PKCS7_SIGNED_DATA\0" "NO_CERTIFICATES_INCLUDED\0" @@ -1188,8 +1202,6 @@ const char kOpenSSLReasonStringData[] = "PUBLIC_KEY_DECODE_ERROR\0" "PUBLIC_KEY_ENCODE_ERROR\0" "SHOULD_RETRY\0" - "UNABLE_TO_FIND_PARAMETERS_IN_CHAIN\0" - "UNABLE_TO_GET_CERTS_PUBLIC_KEY\0" "UNKNOWN_KEY_TYPE\0" "UNKNOWN_PURPOSE_ID\0" "UNKNOWN_TRUST_ID\0" diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index e27e9e181d5..ba641748634 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -296,7 +296,6 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/aes/mode_wrappers.c', 'third_party/boringssl/crypto/asn1/a_bitstr.c', 'third_party/boringssl/crypto/asn1/a_bool.c', - 'third_party/boringssl/crypto/asn1/a_bytes.c', 'third_party/boringssl/crypto/asn1/a_d2i_fp.c', 'third_party/boringssl/crypto/asn1/a_dup.c', 'third_party/boringssl/crypto/asn1/a_enum.c', @@ -315,18 +314,14 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/asn1/asn1_lib.c', 'third_party/boringssl/crypto/asn1/asn1_par.c', 'third_party/boringssl/crypto/asn1/asn_pack.c', - 'third_party/boringssl/crypto/asn1/bio_asn1.c', - 'third_party/boringssl/crypto/asn1/bio_ndef.c', 'third_party/boringssl/crypto/asn1/f_enum.c', 'third_party/boringssl/crypto/asn1/f_int.c', 'third_party/boringssl/crypto/asn1/f_string.c', 'third_party/boringssl/crypto/asn1/t_bitst.c', - 'third_party/boringssl/crypto/asn1/t_pkey.c', 'third_party/boringssl/crypto/asn1/tasn_dec.c', 'third_party/boringssl/crypto/asn1/tasn_enc.c', 'third_party/boringssl/crypto/asn1/tasn_fre.c', 'third_party/boringssl/crypto/asn1/tasn_new.c', - 'third_party/boringssl/crypto/asn1/tasn_prn.c', 'third_party/boringssl/crypto/asn1/tasn_typ.c', 'third_party/boringssl/crypto/asn1/tasn_utl.c', 'third_party/boringssl/crypto/asn1/x_bignum.c', @@ -356,6 +351,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/bn/generic.c', 'third_party/boringssl/crypto/bn/kronecker.c', 'third_party/boringssl/crypto/bn/montgomery.c', + 'third_party/boringssl/crypto/bn/montgomery_inv.c', 'third_party/boringssl/crypto/bn/mul.c', 'third_party/boringssl/crypto/bn/prime.c', 'third_party/boringssl/crypto/bn/random.c', @@ -367,8 +363,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/bytestring/ber.c', 'third_party/boringssl/crypto/bytestring/cbb.c', 'third_party/boringssl/crypto/bytestring/cbs.c', - 'third_party/boringssl/crypto/chacha/chacha_generic.c', - 'third_party/boringssl/crypto/chacha/chacha_vec.c', + 'third_party/boringssl/crypto/chacha/chacha.c', 'third_party/boringssl/crypto/cipher/aead.c', 'third_party/boringssl/crypto/cipher/cipher.c', 'third_party/boringssl/crypto/cipher/derive_key.c', @@ -383,10 +378,14 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/cipher/tls_cbc.c', 'third_party/boringssl/crypto/cmac/cmac.c', 'third_party/boringssl/crypto/conf/conf.c', + 'third_party/boringssl/crypto/cpu-aarch64-linux.c', + 'third_party/boringssl/crypto/cpu-arm-linux.c', 'third_party/boringssl/crypto/cpu-arm.c', 'third_party/boringssl/crypto/cpu-intel.c', + 'third_party/boringssl/crypto/cpu-ppc64le.c', 'third_party/boringssl/crypto/crypto.c', 'third_party/boringssl/crypto/curve25519/curve25519.c', + 'third_party/boringssl/crypto/curve25519/spake25519.c', 'third_party/boringssl/crypto/curve25519/x25519-x86_64.c', 'third_party/boringssl/crypto/des/des.c', 'third_party/boringssl/crypto/dh/check.c', @@ -395,8 +394,6 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/dh/params.c', 'third_party/boringssl/crypto/digest/digest.c', 'third_party/boringssl/crypto/digest/digests.c', - 'third_party/boringssl/crypto/directory_posix.c', - 'third_party/boringssl/crypto/directory_win.c', 'third_party/boringssl/crypto/dsa/dsa.c', 'third_party/boringssl/crypto/dsa/dsa_asn1.c', 'third_party/boringssl/crypto/ec/ec.c', @@ -415,7 +412,6 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c', 'third_party/boringssl/crypto/engine/engine.c', 'third_party/boringssl/crypto/err/err.c', - 'third_party/boringssl/crypto/evp/algorithm.c', 'third_party/boringssl/crypto/evp/digestsign.c', 'third_party/boringssl/crypto/evp/evp.c', 'third_party/boringssl/crypto/evp/evp_asn1.c', @@ -426,6 +422,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/evp/p_rsa.c', 'third_party/boringssl/crypto/evp/p_rsa_asn1.c', 'third_party/boringssl/crypto/evp/pbkdf.c', + 'third_party/boringssl/crypto/evp/print.c', 'third_party/boringssl/crypto/evp/sign.c', 'third_party/boringssl/crypto/ex_data.c', 'third_party/boringssl/crypto/hkdf/hkdf.c', @@ -439,6 +436,12 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/modes/ctr.c', 'third_party/boringssl/crypto/modes/gcm.c', 'third_party/boringssl/crypto/modes/ofb.c', + 'third_party/boringssl/crypto/newhope/error_correction.c', + 'third_party/boringssl/crypto/newhope/newhope.c', + 'third_party/boringssl/crypto/newhope/ntt.c', + 'third_party/boringssl/crypto/newhope/poly.c', + 'third_party/boringssl/crypto/newhope/precomp.c', + 'third_party/boringssl/crypto/newhope/reduce.c', 'third_party/boringssl/crypto/obj/obj.c', 'third_party/boringssl/crypto/obj/obj_xref.c', 'third_party/boringssl/crypto/pem/pem_all.c', @@ -456,6 +459,7 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/poly1305/poly1305.c', 'third_party/boringssl/crypto/poly1305/poly1305_arm.c', 'third_party/boringssl/crypto/poly1305/poly1305_vec.c', + 'third_party/boringssl/crypto/rand/deterministic.c', 'third_party/boringssl/crypto/rand/rand.c', 'third_party/boringssl/crypto/rand/urandom.c', 'third_party/boringssl/crypto/rand/windows.c', @@ -480,11 +484,13 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/x509/a_sign.c', 'third_party/boringssl/crypto/x509/a_strex.c', 'third_party/boringssl/crypto/x509/a_verify.c', + 'third_party/boringssl/crypto/x509/algorithm.c', 'third_party/boringssl/crypto/x509/asn1_gen.c', 'third_party/boringssl/crypto/x509/by_dir.c', 'third_party/boringssl/crypto/x509/by_file.c', 'third_party/boringssl/crypto/x509/i2d_pr.c', 'third_party/boringssl/crypto/x509/pkcs7.c', + 'third_party/boringssl/crypto/x509/rsa_pss.c', 'third_party/boringssl/crypto/x509/t_crl.c', 'third_party/boringssl/crypto/x509/t_req.c', 'third_party/boringssl/crypto/x509/t_x509.c', @@ -559,21 +565,17 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/crypto/x509v3/v3_utl.c', 'third_party/boringssl/ssl/custom_extensions.c', 'third_party/boringssl/ssl/d1_both.c', - 'third_party/boringssl/ssl/d1_clnt.c', 'third_party/boringssl/ssl/d1_lib.c', - 'third_party/boringssl/ssl/d1_meth.c', 'third_party/boringssl/ssl/d1_pkt.c', 'third_party/boringssl/ssl/d1_srtp.c', - 'third_party/boringssl/ssl/d1_srvr.c', + 'third_party/boringssl/ssl/dtls_method.c', 'third_party/boringssl/ssl/dtls_record.c', - 'third_party/boringssl/ssl/pqueue/pqueue.c', + 'third_party/boringssl/ssl/handshake_client.c', + 'third_party/boringssl/ssl/handshake_server.c', 'third_party/boringssl/ssl/s3_both.c', - 'third_party/boringssl/ssl/s3_clnt.c', 'third_party/boringssl/ssl/s3_enc.c', 'third_party/boringssl/ssl/s3_lib.c', - 'third_party/boringssl/ssl/s3_meth.c', 'third_party/boringssl/ssl/s3_pkt.c', - 'third_party/boringssl/ssl/s3_srvr.c', 'third_party/boringssl/ssl/ssl_aead_ctx.c', 'third_party/boringssl/ssl/ssl_asn1.c', 'third_party/boringssl/ssl/ssl_buffer.c', @@ -587,6 +589,11 @@ CORE_SOURCE_FILES = [ 'third_party/boringssl/ssl/ssl_stat.c', 'third_party/boringssl/ssl/t1_enc.c', 'third_party/boringssl/ssl/t1_lib.c', + 'third_party/boringssl/ssl/tls13_both.c', + 'third_party/boringssl/ssl/tls13_client.c', + 'third_party/boringssl/ssl/tls13_enc.c', + 'third_party/boringssl/ssl/tls13_server.c', + 'third_party/boringssl/ssl/tls_method.c', 'third_party/boringssl/ssl/tls_record.c', 'third_party/zlib/adler32.c', 'third_party/zlib/compress.c', diff --git a/third_party/boringssl b/third_party/boringssl index c880e42ba1c..78684e5b222 160000 --- a/third_party/boringssl +++ b/third_party/boringssl @@ -1 +1 @@ -Subproject commit c880e42ba1c8032d4cdde2aba0541d8a9d9fa2e9 +Subproject commit 78684e5b222645828ca302e56b40b9daff2b2d27 diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index c95957d22bb..9bc82486d2b 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -3526,6 +3526,20 @@ "third_party": true, "type": "target" }, + { + "deps": [ + "boringssl", + "boringssl_chacha_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_chacha_test", + "src": [], + "third_party": true, + "type": "target" + }, { "deps": [ "boringssl", @@ -3596,6 +3610,20 @@ "third_party": true, "type": "target" }, + { + "deps": [ + "boringssl", + "boringssl_spake25519_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_spake25519_test", + "src": [], + "third_party": true, + "type": "target" + }, { "deps": [ "boringssl", @@ -3680,6 +3708,34 @@ "third_party": true, "type": "target" }, + { + "deps": [ + "boringssl", + "boringssl_ecdh_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdh_test", + "src": [], + "third_party": true, + "type": "target" + }, + { + "deps": [ + "boringssl", + "boringssl_ecdsa_sign_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdsa_sign_test", + "src": [], + "third_party": true, + "type": "target" + }, { "deps": [ "boringssl", @@ -3694,6 +3750,20 @@ "third_party": true, "type": "target" }, + { + "deps": [ + "boringssl", + "boringssl_ecdsa_verify_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdsa_verify_test", + "src": [], + "third_party": true, + "type": "target" + }, { "deps": [ "boringssl", @@ -3806,6 +3876,62 @@ "third_party": true, "type": "target" }, + { + "deps": [ + "boringssl", + "boringssl_newhope_statistical_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_newhope_statistical_test", + "src": [], + "third_party": true, + "type": "target" + }, + { + "deps": [ + "boringssl", + "boringssl_newhope_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_newhope_test", + "src": [], + "third_party": true, + "type": "target" + }, + { + "deps": [ + "boringssl", + "boringssl_newhope_vectors_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_newhope_vectors_test", + "src": [], + "third_party": true, + "type": "target" + }, + { + "deps": [ + "boringssl", + "boringssl_obj_test_lib", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_obj_test", + "src": [], + "third_party": true, + "type": "target" + }, { "deps": [ "boringssl", @@ -3946,20 +4072,6 @@ "third_party": true, "type": "target" }, - { - "deps": [ - "boringssl", - "boringssl_pqueue_test_lib", - "boringssl_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c++", - "name": "boringssl_pqueue_test", - "src": [], - "third_party": true, - "type": "target" - }, { "deps": [ "boringssl", @@ -5689,23 +5801,22 @@ "third_party/boringssl/crypto/conf/internal.h", "third_party/boringssl/crypto/curve25519/internal.h", "third_party/boringssl/crypto/des/internal.h", - "third_party/boringssl/crypto/dh/internal.h", "third_party/boringssl/crypto/digest/internal.h", "third_party/boringssl/crypto/digest/md32_common.h", - "third_party/boringssl/crypto/directory.h", "third_party/boringssl/crypto/ec/internal.h", "third_party/boringssl/crypto/ec/p256-x86_64-table.h", "third_party/boringssl/crypto/evp/internal.h", "third_party/boringssl/crypto/internal.h", "third_party/boringssl/crypto/modes/internal.h", + "third_party/boringssl/crypto/newhope/internal.h", "third_party/boringssl/crypto/obj/obj_dat.h", "third_party/boringssl/crypto/obj/obj_xref.h", "third_party/boringssl/crypto/pkcs8/internal.h", + "third_party/boringssl/crypto/poly1305/internal.h", "third_party/boringssl/crypto/rand/internal.h", "third_party/boringssl/crypto/rsa/internal.h", - "third_party/boringssl/crypto/test/scoped_types.h", - "third_party/boringssl/crypto/test/test_util.h", "third_party/boringssl/crypto/x509/charmap.h", + "third_party/boringssl/crypto/x509/internal.h", "third_party/boringssl/crypto/x509/vpm_int.h", "third_party/boringssl/crypto/x509v3/ext_dat.h", "third_party/boringssl/crypto/x509v3/pcy_int.h", @@ -5751,10 +5862,12 @@ "third_party/boringssl/include/openssl/md4.h", "third_party/boringssl/include/openssl/md5.h", "third_party/boringssl/include/openssl/mem.h", + "third_party/boringssl/include/openssl/newhope.h", + "third_party/boringssl/include/openssl/nid.h", "third_party/boringssl/include/openssl/obj.h", "third_party/boringssl/include/openssl/obj_mac.h", "third_party/boringssl/include/openssl/objects.h", - "third_party/boringssl/include/openssl/opensslfeatures.h", + "third_party/boringssl/include/openssl/opensslconf.h", "third_party/boringssl/include/openssl/opensslv.h", "third_party/boringssl/include/openssl/ossl_typ.h", "third_party/boringssl/include/openssl/pem.h", @@ -5762,9 +5875,9 @@ "third_party/boringssl/include/openssl/pkcs7.h", "third_party/boringssl/include/openssl/pkcs8.h", "third_party/boringssl/include/openssl/poly1305.h", - "third_party/boringssl/include/openssl/pqueue.h", "third_party/boringssl/include/openssl/rand.h", "third_party/boringssl/include/openssl/rc4.h", + "third_party/boringssl/include/openssl/ripemd.h", "third_party/boringssl/include/openssl/rsa.h", "third_party/boringssl/include/openssl/safestack.h", "third_party/boringssl/include/openssl/sha.h", @@ -5780,11 +5893,7 @@ "third_party/boringssl/include/openssl/x509.h", "third_party/boringssl/include/openssl/x509_vfy.h", "third_party/boringssl/include/openssl/x509v3.h", - "third_party/boringssl/ssl/internal.h", - "third_party/boringssl/ssl/test/async_bio.h", - "third_party/boringssl/ssl/test/packeted_bio.h", - "third_party/boringssl/ssl/test/scoped_types.h", - "third_party/boringssl/ssl/test/test_config.h" + "third_party/boringssl/ssl/internal.h" ], "is_filegroup": false, "language": "c", @@ -5883,6 +5992,19 @@ "third_party": true, "type": "lib" }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_chacha_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, { "deps": [ "boringssl", @@ -5948,6 +6070,19 @@ "third_party": true, "type": "lib" }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_spake25519_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, { "deps": [ "boringssl", @@ -6026,6 +6161,32 @@ "third_party": true, "type": "lib" }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdh_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdsa_sign_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, { "deps": [ "boringssl", @@ -6039,6 +6200,19 @@ "third_party": true, "type": "lib" }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_ecdsa_verify_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, { "deps": [ "boringssl", @@ -6137,7 +6311,7 @@ ], "headers": [], "is_filegroup": false, - "language": "c", + "language": "c++", "name": "boringssl_gcm_test_lib", "src": [], "third_party": true, @@ -6151,7 +6325,7 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "boringssl_pkcs12_test_lib", + "name": "boringssl_newhope_statistical_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6164,7 +6338,7 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "boringssl_pkcs8_test_lib", + "name": "boringssl_newhope_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6177,7 +6351,7 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "boringssl_poly1305_test_lib", + "name": "boringssl_newhope_vectors_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6189,8 +6363,8 @@ ], "headers": [], "is_filegroup": false, - "language": "c", - "name": "boringssl_refcount_test_lib", + "language": "c++", + "name": "boringssl_obj_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6203,7 +6377,7 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "boringssl_rsa_test_lib", + "name": "boringssl_pkcs12_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6215,8 +6389,21 @@ ], "headers": [], "is_filegroup": false, - "language": "c", - "name": "boringssl_thread_test_lib", + "language": "c++", + "name": "boringssl_pkcs8_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_poly1305_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6229,7 +6416,7 @@ "headers": [], "is_filegroup": false, "language": "c", - "name": "boringssl_pkcs7_test_lib", + "name": "boringssl_refcount_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6242,7 +6429,7 @@ "headers": [], "is_filegroup": false, "language": "c++", - "name": "boringssl_x509_test_lib", + "name": "boringssl_rsa_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6255,7 +6442,7 @@ "headers": [], "is_filegroup": false, "language": "c", - "name": "boringssl_tab_test_lib", + "name": "boringssl_thread_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6268,7 +6455,20 @@ "headers": [], "is_filegroup": false, "language": "c", - "name": "boringssl_v3name_test_lib", + "name": "boringssl_pkcs7_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c++", + "name": "boringssl_x509_test_lib", "src": [], "third_party": true, "type": "lib" @@ -6281,7 +6481,20 @@ "headers": [], "is_filegroup": false, "language": "c", - "name": "boringssl_pqueue_test_lib", + "name": "boringssl_tab_test_lib", + "src": [], + "third_party": true, + "type": "lib" + }, + { + "deps": [ + "boringssl", + "boringssl_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "boringssl_v3name_test_lib", "src": [], "third_party": true, "type": "lib" diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index 8014f68f6c8..2c7b0a6c822 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -3568,7 +3568,9 @@ ] }, { - "args": [], + "args": [ + "third_party/boringssl/crypto/bn/bn_tests.txt" + ], "boringssl": true, "ci_platforms": [ "linux", @@ -3615,6 +3617,30 @@ "windows" ] }, + { + "args": [], + "boringssl": true, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "defaults": "boringssl", + "exclude_configs": [ + "asan" + ], + "flaky": false, + "language": "c++", + "name": "boringssl_chacha_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [ "aes-128-gcm", @@ -3779,8 +3805,8 @@ }, { "args": [ - "rc4-md5-tls", - "third_party/boringssl/crypto/cipher/test/rc4_md5_tls_tests.txt" + "aes-128-cbc-sha1-tls", + "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3806,8 +3832,8 @@ }, { "args": [ - "rc4-sha1-tls", - "third_party/boringssl/crypto/cipher/test/rc4_sha1_tls_tests.txt" + "aes-128-cbc-sha1-tls-implicit-iv", + "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_tls_implicit_iv_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3833,8 +3859,8 @@ }, { "args": [ - "aes-128-cbc-sha1-tls", - "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_tls_tests.txt" + "aes-128-cbc-sha256-tls", + "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha256_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3860,8 +3886,8 @@ }, { "args": [ - "aes-128-cbc-sha1-tls-implicit-iv", - "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_tls_implicit_iv_tests.txt" + "aes-256-cbc-sha1-tls", + "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3887,8 +3913,8 @@ }, { "args": [ - "aes-128-cbc-sha256-tls", - "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha256_tls_tests.txt" + "aes-256-cbc-sha1-tls-implicit-iv", + "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_tls_implicit_iv_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3914,8 +3940,8 @@ }, { "args": [ - "aes-256-cbc-sha1-tls", - "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_tls_tests.txt" + "aes-256-cbc-sha256-tls", + "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha256_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3941,8 +3967,8 @@ }, { "args": [ - "aes-256-cbc-sha1-tls-implicit-iv", - "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_tls_implicit_iv_tests.txt" + "aes-256-cbc-sha384-tls", + "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha384_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3968,8 +3994,8 @@ }, { "args": [ - "aes-256-cbc-sha256-tls", - "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha256_tls_tests.txt" + "des-ede3-cbc-sha1-tls", + "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_tls_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -3995,8 +4021,8 @@ }, { "args": [ - "aes-256-cbc-sha384-tls", - "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha384_tls_tests.txt" + "des-ede3-cbc-sha1-tls-implicit-iv", + "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_tls_implicit_iv_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4022,8 +4048,8 @@ }, { "args": [ - "des-ede3-cbc-sha1-tls", - "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_tls_tests.txt" + "aes-128-cbc-sha1-ssl3", + "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_ssl3_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4049,8 +4075,8 @@ }, { "args": [ - "des-ede3-cbc-sha1-tls-implicit-iv", - "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_tls_implicit_iv_tests.txt" + "aes-256-cbc-sha1-ssl3", + "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_ssl3_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4076,8 +4102,8 @@ }, { "args": [ - "rc4-md5-ssl3", - "third_party/boringssl/crypto/cipher/test/rc4_md5_ssl3_tests.txt" + "des-ede3-cbc-sha1-ssl3", + "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_ssl3_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4103,8 +4129,8 @@ }, { "args": [ - "rc4-sha1-ssl3", - "third_party/boringssl/crypto/cipher/test/rc4_sha1_ssl3_tests.txt" + "aes-128-ctr-hmac-sha256", + "third_party/boringssl/crypto/cipher/test/aes_128_ctr_hmac_sha256.txt" ], "boringssl": true, "ci_platforms": [ @@ -4130,8 +4156,8 @@ }, { "args": [ - "aes-128-cbc-sha1-ssl3", - "third_party/boringssl/crypto/cipher/test/aes_128_cbc_sha1_ssl3_tests.txt" + "aes-256-ctr-hmac-sha256", + "third_party/boringssl/crypto/cipher/test/aes_256_ctr_hmac_sha256.txt" ], "boringssl": true, "ci_platforms": [ @@ -4157,8 +4183,7 @@ }, { "args": [ - "aes-256-cbc-sha1-ssl3", - "third_party/boringssl/crypto/cipher/test/aes_256_cbc_sha1_ssl3_tests.txt" + "third_party/boringssl/crypto/cipher/test/cipher_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4174,7 +4199,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_aead_test", + "name": "boringssl_cipher_test", "platforms": [ "linux", "mac", @@ -4183,10 +4208,7 @@ ] }, { - "args": [ - "des-ede3-cbc-sha1-ssl3", - "third_party/boringssl/crypto/cipher/test/des_ede3_cbc_sha1_ssl3_tests.txt" - ], + "args": [], "boringssl": true, "ci_platforms": [ "linux", @@ -4201,7 +4223,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_aead_test", + "name": "boringssl_cmac_test", "platforms": [ "linux", "mac", @@ -4210,10 +4232,7 @@ ] }, { - "args": [ - "aes-128-ctr-hmac-sha256", - "third_party/boringssl/crypto/cipher/test/aes_128_ctr_hmac_sha256.txt" - ], + "args": [], "boringssl": true, "ci_platforms": [ "linux", @@ -4228,7 +4247,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_aead_test", + "name": "boringssl_constant_time_test", "platforms": [ "linux", "mac", @@ -4238,8 +4257,7 @@ }, { "args": [ - "aes-256-ctr-hmac-sha256", - "third_party/boringssl/crypto/cipher/test/aes_256_ctr_hmac_sha256.txt" + "third_party/boringssl/crypto/curve25519/ed25519_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4255,7 +4273,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_aead_test", + "name": "boringssl_ed25519_test", "platforms": [ "linux", "mac", @@ -4264,9 +4282,7 @@ ] }, { - "args": [ - "third_party/boringssl/crypto/cipher/test/cipher_test.txt" - ], + "args": [], "boringssl": true, "ci_platforms": [ "linux", @@ -4281,7 +4297,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_cipher_test", + "name": "boringssl_x25519_test", "platforms": [ "linux", "mac", @@ -4305,7 +4321,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_cmac_test", + "name": "boringssl_spake25519_test", "platforms": [ "linux", "mac", @@ -4329,7 +4345,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_constant_time_test", + "name": "boringssl_dh_test", "platforms": [ "linux", "mac", @@ -4338,9 +4354,7 @@ ] }, { - "args": [ - "third_party/boringssl/crypto/curve25519/ed25519_tests.txt" - ], + "args": [], "boringssl": true, "ci_platforms": [ "linux", @@ -4355,7 +4369,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_ed25519_test", + "name": "boringssl_digest_test", "platforms": [ "linux", "mac", @@ -4379,7 +4393,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_x25519_test", + "name": "boringssl_dsa_test", "platforms": [ "linux", "mac", @@ -4403,7 +4417,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_dh_test", + "name": "boringssl_ec_test", "platforms": [ "linux", "mac", @@ -4427,7 +4441,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_digest_test", + "name": "boringssl_example_mul", "platforms": [ "linux", "mac", @@ -4436,7 +4450,9 @@ ] }, { - "args": [], + "args": [ + "third_party/boringssl/crypto/ecdh/ecdh_tests.txt" + ], "boringssl": true, "ci_platforms": [ "linux", @@ -4451,7 +4467,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_dsa_test", + "name": "boringssl_ecdh_test", "platforms": [ "linux", "mac", @@ -4460,7 +4476,9 @@ ] }, { - "args": [], + "args": [ + "third_party/boringssl/crypto/ecdsa/ecdsa_sign_tests.txt" + ], "boringssl": true, "ci_platforms": [ "linux", @@ -4475,7 +4493,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_ec_test", + "name": "boringssl_ecdsa_sign_test", "platforms": [ "linux", "mac", @@ -4499,7 +4517,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_example_mul", + "name": "boringssl_ecdsa_test", "platforms": [ "linux", "mac", @@ -4508,7 +4526,9 @@ ] }, { - "args": [], + "args": [ + "third_party/boringssl/crypto/ecdsa/ecdsa_verify_tests.txt" + ], "boringssl": true, "ci_platforms": [ "linux", @@ -4523,7 +4543,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_ecdsa_test", + "name": "boringssl_ecdsa_verify_test", "platforms": [ "linux", "mac", @@ -4743,7 +4763,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_pkcs8_test", + "name": "boringssl_newhope_test", "platforms": [ "linux", "mac", @@ -4767,7 +4787,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_pkcs12_test", + "name": "boringssl_newhope_statistical_test", "platforms": [ "linux", "mac", @@ -4777,7 +4797,7 @@ }, { "args": [ - "third_party/boringssl/crypto/poly1305/poly1305_test.txt" + "third_party/boringssl/crypto/newhope/newhope_tests.txt" ], "boringssl": true, "ci_platforms": [ @@ -4793,7 +4813,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_poly1305_test", + "name": "boringssl_newhope_vectors_test", "platforms": [ "linux", "mac", @@ -4817,7 +4837,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_refcount_test", + "name": "boringssl_obj_test", "platforms": [ "linux", "mac", @@ -4841,7 +4861,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_rsa_test", + "name": "boringssl_pkcs12_test", "platforms": [ "linux", "mac", @@ -4865,7 +4885,33 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_thread_test", + "name": "boringssl_pkcs8_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, + { + "args": [ + "third_party/boringssl/crypto/poly1305/poly1305_tests.txt" + ], + "boringssl": true, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "defaults": "boringssl", + "exclude_configs": [ + "asan" + ], + "flaky": false, + "language": "c++", + "name": "boringssl_poly1305_test", "platforms": [ "linux", "mac", @@ -4889,7 +4935,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_pkcs7_test", + "name": "boringssl_refcount_test", "platforms": [ "linux", "mac", @@ -4913,7 +4959,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_x509_test", + "name": "boringssl_rsa_test", "platforms": [ "linux", "mac", @@ -4937,7 +4983,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_tab_test", + "name": "boringssl_thread_test", "platforms": [ "linux", "mac", @@ -4961,7 +5007,7 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_v3name_test", + "name": "boringssl_pkcs7_test", "platforms": [ "linux", "mac", @@ -4985,7 +5031,55 @@ ], "flaky": false, "language": "c++", - "name": "boringssl_pqueue_test", + "name": "boringssl_x509_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, + { + "args": [], + "boringssl": true, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "defaults": "boringssl", + "exclude_configs": [ + "asan" + ], + "flaky": false, + "language": "c++", + "name": "boringssl_tab_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, + { + "args": [], + "boringssl": true, + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "defaults": "boringssl", + "exclude_configs": [ + "asan" + ], + "flaky": false, + "language": "c++", + "name": "boringssl_v3name_test", "platforms": [ "linux", "mac", diff --git a/tools/run_tests/sanity/check_submodules.sh b/tools/run_tests/sanity/check_submodules.sh index a484b26716e..0b68319d290 100755 --- a/tools/run_tests/sanity/check_submodules.sh +++ b/tools/run_tests/sanity/check_submodules.sh @@ -42,7 +42,7 @@ want_submodules=`mktemp /tmp/submXXXXXX` git submodule | awk '{ print $1 }' | sort > $submodules cat << EOF | awk '{ print $1 }' | sort > $want_submodules 44c25c892a6229b20db7cd9dc05584ea865896de third_party/benchmark (v0.1.0-343-g44c25c8) - c880e42ba1c8032d4cdde2aba0541d8a9d9fa2e9 third_party/boringssl (c880e42) + 78684e5b222645828ca302e56b40b9daff2b2d27 third_party/boringssl (78684e5) 886e7d75368e3f4fab3f4d0d3584e4abfc557755 third_party/boringssl-with-bazel (version_for_cocoapods_7.0-857-g886e7d7) f8a0efe03aa69b3336d8e228b37d4ccb17324b88 third_party/gflags (v2.2.0) c99458533a9b4c743ed51537e25989ea55944908 third_party/googletest (release-1.7.0) diff --git a/vsprojects/vcxproj/boringssl/boringssl.vcxproj b/vsprojects/vcxproj/boringssl/boringssl.vcxproj index 59db775d799..a67b2c3a5d8 100644 --- a/vsprojects/vcxproj/boringssl/boringssl.vcxproj +++ b/vsprojects/vcxproj/boringssl/boringssl.vcxproj @@ -158,23 +158,22 @@ - - + + - - + @@ -220,10 +219,12 @@ + + - + @@ -231,9 +232,9 @@ - + @@ -250,10 +251,6 @@ - - - - @@ -266,8 +263,6 @@ - - @@ -304,10 +299,6 @@ - - - - @@ -316,8 +307,6 @@ - - @@ -326,8 +315,6 @@ - - @@ -386,6 +373,8 @@ + + @@ -408,9 +397,7 @@ - - - + @@ -440,14 +427,22 @@ + + + + + + + + @@ -464,10 +459,6 @@ - - - - @@ -504,8 +495,6 @@ - - @@ -526,6 +515,8 @@ + + @@ -552,6 +543,18 @@ + + + + + + + + + + + + @@ -586,6 +589,8 @@ + + @@ -634,6 +639,8 @@ + + @@ -644,6 +651,8 @@ + + @@ -792,36 +801,28 @@ - - - - - + - + - + - + - - - - @@ -848,6 +849,16 @@ + + + + + + + + + + diff --git a/vsprojects/vcxproj/boringssl/boringssl.vcxproj.filters b/vsprojects/vcxproj/boringssl/boringssl.vcxproj.filters index bd996bdc445..09aa067f785 100644 --- a/vsprojects/vcxproj/boringssl/boringssl.vcxproj.filters +++ b/vsprojects/vcxproj/boringssl/boringssl.vcxproj.filters @@ -16,9 +16,6 @@ third_party\boringssl\crypto\asn1 - - third_party\boringssl\crypto\asn1 - third_party\boringssl\crypto\asn1 @@ -73,12 +70,6 @@ third_party\boringssl\crypto\asn1 - - third_party\boringssl\crypto\asn1 - - - third_party\boringssl\crypto\asn1 - third_party\boringssl\crypto\asn1 @@ -91,9 +82,6 @@ third_party\boringssl\crypto\asn1 - - third_party\boringssl\crypto\asn1 - third_party\boringssl\crypto\asn1 @@ -106,9 +94,6 @@ third_party\boringssl\crypto\asn1 - - third_party\boringssl\crypto\asn1 - third_party\boringssl\crypto\asn1 @@ -196,6 +181,9 @@ third_party\boringssl\crypto\bn + + third_party\boringssl\crypto\bn + third_party\boringssl\crypto\bn @@ -229,10 +217,7 @@ third_party\boringssl\crypto\bytestring - - third_party\boringssl\crypto\chacha - - + third_party\boringssl\crypto\chacha @@ -277,18 +262,30 @@ third_party\boringssl\crypto\conf + + third_party\boringssl\crypto + + + third_party\boringssl\crypto + third_party\boringssl\crypto third_party\boringssl\crypto + + third_party\boringssl\crypto + third_party\boringssl\crypto third_party\boringssl\crypto\curve25519 + + third_party\boringssl\crypto\curve25519 + third_party\boringssl\crypto\curve25519 @@ -313,12 +310,6 @@ third_party\boringssl\crypto\digest - - third_party\boringssl\crypto - - - third_party\boringssl\crypto - third_party\boringssl\crypto\dsa @@ -373,9 +364,6 @@ third_party\boringssl\crypto\err - - third_party\boringssl\crypto\evp - third_party\boringssl\crypto\evp @@ -406,6 +394,9 @@ third_party\boringssl\crypto\evp + + third_party\boringssl\crypto\evp + third_party\boringssl\crypto\evp @@ -445,6 +436,24 @@ third_party\boringssl\crypto\modes + + third_party\boringssl\crypto\newhope + + + third_party\boringssl\crypto\newhope + + + third_party\boringssl\crypto\newhope + + + third_party\boringssl\crypto\newhope + + + third_party\boringssl\crypto\newhope + + + third_party\boringssl\crypto\newhope + third_party\boringssl\crypto\obj @@ -496,6 +505,9 @@ third_party\boringssl\crypto\poly1305 + + third_party\boringssl\crypto\rand + third_party\boringssl\crypto\rand @@ -568,6 +580,9 @@ third_party\boringssl\crypto\x509 + + third_party\boringssl\crypto\x509 + third_party\boringssl\crypto\x509 @@ -583,6 +598,9 @@ third_party\boringssl\crypto\x509 + + third_party\boringssl\crypto\x509 + third_party\boringssl\crypto\x509 @@ -805,34 +823,28 @@ third_party\boringssl\ssl - - third_party\boringssl\ssl - third_party\boringssl\ssl - - third_party\boringssl\ssl - third_party\boringssl\ssl third_party\boringssl\ssl - + third_party\boringssl\ssl third_party\boringssl\ssl - - third_party\boringssl\ssl\pqueue + + third_party\boringssl\ssl - + third_party\boringssl\ssl - + third_party\boringssl\ssl @@ -841,15 +853,9 @@ third_party\boringssl\ssl - - third_party\boringssl\ssl - third_party\boringssl\ssl - - third_party\boringssl\ssl - third_party\boringssl\ssl @@ -889,6 +895,21 @@ third_party\boringssl\ssl + + third_party\boringssl\ssl + + + third_party\boringssl\ssl + + + third_party\boringssl\ssl + + + third_party\boringssl\ssl + + + third_party\boringssl\ssl + third_party\boringssl\ssl @@ -927,18 +948,12 @@ third_party\boringssl\crypto\des - - third_party\boringssl\crypto\dh - third_party\boringssl\crypto\digest third_party\boringssl\crypto\digest - - third_party\boringssl\crypto - third_party\boringssl\crypto\ec @@ -954,6 +969,9 @@ third_party\boringssl\crypto\modes + + third_party\boringssl\crypto\newhope + third_party\boringssl\crypto\obj @@ -963,21 +981,21 @@ third_party\boringssl\crypto\pkcs8 + + third_party\boringssl\crypto\poly1305 + third_party\boringssl\crypto\rand third_party\boringssl\crypto\rsa - - third_party\boringssl\crypto\test - - - third_party\boringssl\crypto\test - third_party\boringssl\crypto\x509 + + third_party\boringssl\crypto\x509 + third_party\boringssl\crypto\x509 @@ -1113,6 +1131,12 @@ third_party\boringssl\include\openssl + + third_party\boringssl\include\openssl + + + third_party\boringssl\include\openssl + third_party\boringssl\include\openssl @@ -1122,7 +1146,7 @@ third_party\boringssl\include\openssl - + third_party\boringssl\include\openssl @@ -1146,15 +1170,15 @@ third_party\boringssl\include\openssl - - third_party\boringssl\include\openssl - third_party\boringssl\include\openssl third_party\boringssl\include\openssl + + third_party\boringssl\include\openssl + third_party\boringssl\include\openssl @@ -1203,18 +1227,6 @@ third_party\boringssl\ssl - - third_party\boringssl\ssl\test - - - third_party\boringssl\ssl\test - - - third_party\boringssl\ssl\test - - - third_party\boringssl\ssl\test - @@ -1320,6 +1332,9 @@ {63ca8fcd-7644-61d6-4357-5a0bcfdc395b} + + {2a39f7c3-62df-5021-0825-36f18f10ad12} + {59349deb-4276-df4c-f4cd-e2cf707c3b4c} @@ -1347,9 +1362,6 @@ {7b1c1e89-c813-5ccd-fa2a-dd1b187f8da9} - - {eec8fd39-7429-3d4d-be78-028791b4b927} - {74c9e47d-193b-84c0-95d9-4b33703b7890} @@ -1365,12 +1377,6 @@ {e6e8c0c0-1755-4978-209e-5429ee3a2f5f} - - {89eb7fc9-98ec-dee5-ea8c-f7d23760aa94} - - - {8dda7bd5-b246-84a4-20c9-c92101caeb48} - diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test/boringssl_pqueue_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test/boringssl_chacha_test.vcxproj similarity index 97% rename from vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test/boringssl_pqueue_test.vcxproj rename to vsprojects/vcxproj/test/boringssl/boringssl_chacha_test/boringssl_chacha_test.vcxproj index 7c0189b6271..f8932983672 100644 --- a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test/boringssl_pqueue_test.vcxproj +++ b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test/boringssl_chacha_test.vcxproj @@ -20,7 +20,7 @@ - {CCAA2ACD-B171-6011-0646-93010DCF8BC5} + {0F12358C-9F7A-E3B5-23EC-250C29C9D3A2} true $(SolutionDir)IntDir\$(MSBuildProjectName)\ @@ -62,14 +62,14 @@ - boringssl_pqueue_test + boringssl_chacha_test static Debug static Debug - boringssl_pqueue_test + boringssl_chacha_test static Release static @@ -164,8 +164,8 @@ - - {D03600F9-540A-2691-69F6-3A1DC2874D24} + + {D15F1CF5-EC88-FDD5-55A0-CBE5DC8A9F29} {427037B1-B51B-D6F1-5025-AD12B200266A} diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test/boringssl_pqueue_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test/boringssl_chacha_test.vcxproj.filters similarity index 100% rename from vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test/boringssl_pqueue_test.vcxproj.filters rename to vsprojects/vcxproj/test/boringssl/boringssl_chacha_test/boringssl_chacha_test.vcxproj.filters diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj new file mode 100644 index 00000000000..3c4c382c56d --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {D15F1CF5-EC88-FDD5-55A0-CBE5DC8A9F29} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_chacha_test_lib + + + boringssl_chacha_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj.filters new file mode 100644 index 00000000000..5fb3e2fc495 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_chacha_test_lib/boringssl_chacha_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\chacha + + + + + + {4b736811-6554-6004-024b-74e526459c17} + + + {256ad378-581e-bc4f-e018-f4a4e4098091} + + + {7e6857c0-cc2b-da3a-bdf7-cf9f82aba586} + + + {02432684-f62e-6b57-5847-af2e296fbbab} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj new file mode 100644 index 00000000000..cb85dd53829 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8B7A464C-BC82-53A0-656A-0215D2BCE85D} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_ecdh_test + static + Debug + static + Debug + + + boringssl_ecdh_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {04FA7804-13C6-D0E4-144D-BD3736334565} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test/boringssl_ecdh_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj similarity index 97% rename from vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj rename to vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj index 12198c11495..22c033c57b2 100644 --- a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj @@ -19,7 +19,7 @@ - {D03600F9-540A-2691-69F6-3A1DC2874D24} + {04FA7804-13C6-D0E4-144D-BD3736334565} true $(SolutionDir)IntDir\$(MSBuildProjectName)\ @@ -57,10 +57,10 @@ - boringssl_pqueue_test_lib + boringssl_ecdh_test_lib - boringssl_pqueue_test_lib + boringssl_ecdh_test_lib @@ -147,7 +147,7 @@ - + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj.filters new file mode 100644 index 00000000000..51393f51907 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdh_test_lib/boringssl_ecdh_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\ecdh + + + + + + {100930cd-7241-d92b-da6a-a84ea68e24bd} + + + {2f0bb152-1c3a-5f3a-7512-ca92fef36751} + + + {c004f731-666a-9d7d-c448-96a16069cbc4} + + + {74176a90-7b93-c871-7de7-0048a1a55076} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj new file mode 100644 index 00000000000..db7fc98af66 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B9368314-B4D2-DEB2-A448-26D327059447} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_ecdsa_sign_test + static + Debug + static + Debug + + + boringssl_ecdsa_sign_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {8F0F763A-31D1-6710-6286-FD91EAC75EDB} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test/boringssl_ecdsa_sign_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj new file mode 100644 index 00000000000..947dcddd949 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {8F0F763A-31D1-6710-6286-FD91EAC75EDB} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_ecdsa_sign_test_lib + + + boringssl_ecdsa_sign_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj.filters new file mode 100644 index 00000000000..69fb20cc1bd --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_sign_test_lib/boringssl_ecdsa_sign_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\ecdsa + + + + + + {2407663e-0b17-cfb0-0aaa-fe639ecda00a} + + + {9ad9cf54-8113-a6e1-0689-09b051b5acf9} + + + {8057866a-62e2-5309-70fa-f98800b682a8} + + + {76196bab-7843-c0ca-4f97-32c3336af99b} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj new file mode 100644 index 00000000000..ddf4b0c0227 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {BF550763-A8E9-1C98-89C5-7A4A00364E06} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_ecdsa_verify_test + static + Debug + static + Debug + + + boringssl_ecdsa_verify_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {3F79C89D-E5CA-4C28-DE1C-27E0E1BFCA43} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test/boringssl_ecdsa_verify_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj new file mode 100644 index 00000000000..5287bbec92b --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {3F79C89D-E5CA-4C28-DE1C-27E0E1BFCA43} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_ecdsa_verify_test_lib + + + boringssl_ecdsa_verify_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj.filters new file mode 100644 index 00000000000..01169e3656b --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_ecdsa_verify_test_lib/boringssl_ecdsa_verify_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\ecdsa + + + + + + {62c752a3-7d35-4a52-4e3e-af92d1ef7ae0} + + + {cf981be6-06c7-d75e-bb01-bdcf6cbac573} + + + {f4955fa6-0694-bb47-d2e7-59ee77f72e37} + + + {bc349ef0-99fd-5724-06c0-0c6f6e1f7b69} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj index 7b5ffa1ca10..8b3f5f49bc6 100644 --- a/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj +++ b/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj @@ -147,7 +147,7 @@ - + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj.filters index 7260136bd81..fbc3a077ecf 100644 --- a/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj.filters +++ b/vsprojects/vcxproj/test/boringssl/boringssl_gcm_test_lib/boringssl_gcm_test_lib.vcxproj.filters @@ -1,7 +1,7 @@ - + third_party\boringssl\crypto\modes diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj new file mode 100644 index 00000000000..f3dde154ade --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2DFF4B39-A402-0C88-ACE5-58BD7E5F7686} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_newhope_statistical_test + static + Debug + static + Debug + + + boringssl_newhope_statistical_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {95B2444A-04E1-7F0A-049C-30099AA62E84} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test/boringssl_newhope_statistical_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj new file mode 100644 index 00000000000..c9cb80a4306 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {95B2444A-04E1-7F0A-049C-30099AA62E84} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_newhope_statistical_test_lib + + + boringssl_newhope_statistical_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj.filters new file mode 100644 index 00000000000..95945c24671 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_statistical_test_lib/boringssl_newhope_statistical_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\newhope + + + + + + {25a9ae19-5707-441e-6d97-13ff38322368} + + + {e6e1e1f9-31eb-463f-a882-01c72cbe7a6e} + + + {37a6d595-952d-a224-060b-ea246359d76a} + + + {e0473499-9b3e-c3c3-5463-4706bd005f6c} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj new file mode 100644 index 00000000000..7a085b638f1 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {105DF9D7-2B9F-501B-9FC4-C98BF16FC9D3} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_newhope_test + static + Debug + static + Debug + + + boringssl_newhope_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {2E791A00-9907-8B9A-D201-4E0C357A6BB3} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test/boringssl_newhope_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj new file mode 100644 index 00000000000..55046360614 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {2E791A00-9907-8B9A-D201-4E0C357A6BB3} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_newhope_test_lib + + + boringssl_newhope_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj.filters new file mode 100644 index 00000000000..f2dc0e6a5bb --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_test_lib/boringssl_newhope_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\newhope + + + + + + {f6eddde4-4559-9adb-797f-897631281a89} + + + {81b307de-7498-3465-2ad4-7b634bf4788a} + + + {af9d3e32-2f0f-f0f3-f63f-4a8bd7f07c46} + + + {ea48f773-5060-8693-62ef-f257ccd47b21} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj new file mode 100644 index 00000000000..505f7cf33a8 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {E4C140A1-B7A3-0D00-A02F-CC90C9972F00} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_newhope_vectors_test + static + Debug + static + Debug + + + boringssl_newhope_vectors_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {0993166D-33B9-2E51-B0A9-5035A9086A2E} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test/boringssl_newhope_vectors_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj new file mode 100644 index 00000000000..4f01ec4b706 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {0993166D-33B9-2E51-B0A9-5035A9086A2E} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_newhope_vectors_test_lib + + + boringssl_newhope_vectors_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj.filters new file mode 100644 index 00000000000..27b208d3507 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_newhope_vectors_test_lib/boringssl_newhope_vectors_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\newhope + + + + + + {678cf897-2d02-4bb5-1872-b6d6d61c528f} + + + {3cc5b2df-8409-e2e8-9504-748004a314f3} + + + {2a4fb92f-e756-007b-f6fc-d8f55fee6096} + + + {09155346-c8e7-ffdb-7791-4f623ac5d521} + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj new file mode 100644 index 00000000000..188663cd253 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {CAF4E45E-3BA1-0EFD-2551-F16B4E43D0AB} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_obj_test + static + Debug + static + Debug + + + boringssl_obj_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {9C5FF985-A7D0-185E-4982-8166BC8267EF} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test/boringssl_obj_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj new file mode 100644 index 00000000000..5cff5dc611a --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {9C5FF985-A7D0-185E-4982-8166BC8267EF} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_obj_test_lib + + + boringssl_obj_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj.filters similarity index 52% rename from vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj.filters rename to vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj.filters index 50a19355fc4..e860a95a150 100644 --- a/vsprojects/vcxproj/test/boringssl/boringssl_pqueue_test_lib/boringssl_pqueue_test_lib.vcxproj.filters +++ b/vsprojects/vcxproj/test/boringssl/boringssl_obj_test_lib/boringssl_obj_test_lib.vcxproj.filters @@ -1,23 +1,23 @@ - - third_party\boringssl\ssl\pqueue + + third_party\boringssl\crypto\obj - {5abc2e4b-4b3e-76f3-af5b-32b49bed5734} + {1e65df99-429c-84ab-e85c-2a74292dff99} - {ba7fa262-1d79-278b-6d33-494ef09bc0b0} + {f67c8934-df62-47c5-ab21-f2670e0624d4} - - {bbe38f66-e869-8d99-4ef8-a477041fda28} + + {a1c37911-be8c-bf36-9263-c4db89aa11dc} - - {c6deeb40-d424-ed7a-bcf9-8b33d62d603d} + + {26163139-0b8e-2ee1-11ac-7be64498bbab} diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj new file mode 100644 index 00000000000..dd9022b2ac1 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj @@ -0,0 +1,198 @@ + + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {6E1688D7-E3F2-8F4A-0748-8DEB832397A6} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + Application + true + Unicode + + + Application + false + true + Unicode + + + + + + + + + + + + + + + + boringssl_spake25519_test + static + Debug + static + Debug + + + boringssl_spake25519_test + static + Release + static + Release + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Console + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Console + true + false + true + true + + + + + + + + + + {B5EDD577-C90C-F122-313E-6D9803E91FEB} + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj.filters new file mode 100644 index 00000000000..00e4276f1d4 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test/boringssl_spake25519_test.vcxproj.filters @@ -0,0 +1,7 @@ + + + + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj new file mode 100644 index 00000000000..f0347a48932 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj @@ -0,0 +1,170 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {B5EDD577-C90C-F122-313E-6D9803E91FEB} + true + $(SolutionDir)IntDir\$(MSBuildProjectName)\ + + + + v100 + + + v110 + + + v120 + + + v140 + + + StaticLibrary + true + Unicode + + + StaticLibrary + false + true + Unicode + + + + + + + + + + + + boringssl_spake25519_test_lib + + + boringssl_spake25519_test_lib + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + Disabled + WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions) + true + MultiThreadedDebug + false + None + false + + + Windows + true + false + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + NotUsing + Level3 + MaxSpeed + WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions) + true + true + true + MultiThreaded + false + None + false + + + Windows + true + false + true + true + + + + + + + + + + {427037B1-B51B-D6F1-5025-AD12B200266A} + + + {9FD9A3EF-C4A3-8390-D8F4-6F86C22A58CE} + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + diff --git a/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj.filters b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj.filters new file mode 100644 index 00000000000..a94780cf898 --- /dev/null +++ b/vsprojects/vcxproj/test/boringssl/boringssl_spake25519_test_lib/boringssl_spake25519_test_lib.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + third_party\boringssl\crypto\curve25519 + + + + + + {88324f4e-8e00-0e8c-b6ab-d9406be0cccf} + + + {067bed6d-c308-8eee-2225-771546a4eb5c} + + + {08b844f4-9df6-ff01-d951-1c944f9e5b6b} + + + {2f6416cc-d016-dedd-4e2f-d0ebd4d78fdb} + + + + From 7201fdc0d8c4aaf8cb673933e19a76a7ffc165c1 Mon Sep 17 00:00:00 2001 From: Stanley Cheung Date: Thu, 19 Jan 2017 21:56:41 -0800 Subject: [PATCH 245/261] re-run generate-project.sh after rebase --- CMakeLists.txt | 583 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 513 insertions(+), 70 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fee13da043..2ca0b805429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2831,7 +2831,6 @@ add_library(boringssl third_party/boringssl/crypto/aes/mode_wrappers.c third_party/boringssl/crypto/asn1/a_bitstr.c third_party/boringssl/crypto/asn1/a_bool.c - third_party/boringssl/crypto/asn1/a_bytes.c third_party/boringssl/crypto/asn1/a_d2i_fp.c third_party/boringssl/crypto/asn1/a_dup.c third_party/boringssl/crypto/asn1/a_enum.c @@ -2850,18 +2849,14 @@ add_library(boringssl third_party/boringssl/crypto/asn1/asn1_lib.c third_party/boringssl/crypto/asn1/asn1_par.c third_party/boringssl/crypto/asn1/asn_pack.c - third_party/boringssl/crypto/asn1/bio_asn1.c - third_party/boringssl/crypto/asn1/bio_ndef.c third_party/boringssl/crypto/asn1/f_enum.c third_party/boringssl/crypto/asn1/f_int.c third_party/boringssl/crypto/asn1/f_string.c third_party/boringssl/crypto/asn1/t_bitst.c - third_party/boringssl/crypto/asn1/t_pkey.c third_party/boringssl/crypto/asn1/tasn_dec.c third_party/boringssl/crypto/asn1/tasn_enc.c third_party/boringssl/crypto/asn1/tasn_fre.c third_party/boringssl/crypto/asn1/tasn_new.c - third_party/boringssl/crypto/asn1/tasn_prn.c third_party/boringssl/crypto/asn1/tasn_typ.c third_party/boringssl/crypto/asn1/tasn_utl.c third_party/boringssl/crypto/asn1/x_bignum.c @@ -2891,6 +2886,7 @@ add_library(boringssl third_party/boringssl/crypto/bn/generic.c third_party/boringssl/crypto/bn/kronecker.c third_party/boringssl/crypto/bn/montgomery.c + third_party/boringssl/crypto/bn/montgomery_inv.c third_party/boringssl/crypto/bn/mul.c third_party/boringssl/crypto/bn/prime.c third_party/boringssl/crypto/bn/random.c @@ -2902,8 +2898,7 @@ add_library(boringssl third_party/boringssl/crypto/bytestring/ber.c third_party/boringssl/crypto/bytestring/cbb.c third_party/boringssl/crypto/bytestring/cbs.c - third_party/boringssl/crypto/chacha/chacha_generic.c - third_party/boringssl/crypto/chacha/chacha_vec.c + third_party/boringssl/crypto/chacha/chacha.c third_party/boringssl/crypto/cipher/aead.c third_party/boringssl/crypto/cipher/cipher.c third_party/boringssl/crypto/cipher/derive_key.c @@ -2918,10 +2913,14 @@ add_library(boringssl third_party/boringssl/crypto/cipher/tls_cbc.c third_party/boringssl/crypto/cmac/cmac.c third_party/boringssl/crypto/conf/conf.c + third_party/boringssl/crypto/cpu-aarch64-linux.c + third_party/boringssl/crypto/cpu-arm-linux.c third_party/boringssl/crypto/cpu-arm.c third_party/boringssl/crypto/cpu-intel.c + third_party/boringssl/crypto/cpu-ppc64le.c third_party/boringssl/crypto/crypto.c third_party/boringssl/crypto/curve25519/curve25519.c + third_party/boringssl/crypto/curve25519/spake25519.c third_party/boringssl/crypto/curve25519/x25519-x86_64.c third_party/boringssl/crypto/des/des.c third_party/boringssl/crypto/dh/check.c @@ -2930,8 +2929,6 @@ add_library(boringssl third_party/boringssl/crypto/dh/params.c third_party/boringssl/crypto/digest/digest.c third_party/boringssl/crypto/digest/digests.c - third_party/boringssl/crypto/directory_posix.c - third_party/boringssl/crypto/directory_win.c third_party/boringssl/crypto/dsa/dsa.c third_party/boringssl/crypto/dsa/dsa_asn1.c third_party/boringssl/crypto/ec/ec.c @@ -2950,7 +2947,6 @@ add_library(boringssl third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c third_party/boringssl/crypto/engine/engine.c third_party/boringssl/crypto/err/err.c - third_party/boringssl/crypto/evp/algorithm.c third_party/boringssl/crypto/evp/digestsign.c third_party/boringssl/crypto/evp/evp.c third_party/boringssl/crypto/evp/evp_asn1.c @@ -2961,6 +2957,7 @@ add_library(boringssl third_party/boringssl/crypto/evp/p_rsa.c third_party/boringssl/crypto/evp/p_rsa_asn1.c third_party/boringssl/crypto/evp/pbkdf.c + third_party/boringssl/crypto/evp/print.c third_party/boringssl/crypto/evp/sign.c third_party/boringssl/crypto/ex_data.c third_party/boringssl/crypto/hkdf/hkdf.c @@ -2974,6 +2971,12 @@ add_library(boringssl third_party/boringssl/crypto/modes/ctr.c third_party/boringssl/crypto/modes/gcm.c third_party/boringssl/crypto/modes/ofb.c + third_party/boringssl/crypto/newhope/error_correction.c + third_party/boringssl/crypto/newhope/newhope.c + third_party/boringssl/crypto/newhope/ntt.c + third_party/boringssl/crypto/newhope/poly.c + third_party/boringssl/crypto/newhope/precomp.c + third_party/boringssl/crypto/newhope/reduce.c third_party/boringssl/crypto/obj/obj.c third_party/boringssl/crypto/obj/obj_xref.c third_party/boringssl/crypto/pem/pem_all.c @@ -2991,6 +2994,7 @@ add_library(boringssl third_party/boringssl/crypto/poly1305/poly1305.c third_party/boringssl/crypto/poly1305/poly1305_arm.c third_party/boringssl/crypto/poly1305/poly1305_vec.c + third_party/boringssl/crypto/rand/deterministic.c third_party/boringssl/crypto/rand/rand.c third_party/boringssl/crypto/rand/urandom.c third_party/boringssl/crypto/rand/windows.c @@ -3015,11 +3019,13 @@ add_library(boringssl third_party/boringssl/crypto/x509/a_sign.c third_party/boringssl/crypto/x509/a_strex.c third_party/boringssl/crypto/x509/a_verify.c + third_party/boringssl/crypto/x509/algorithm.c third_party/boringssl/crypto/x509/asn1_gen.c third_party/boringssl/crypto/x509/by_dir.c third_party/boringssl/crypto/x509/by_file.c third_party/boringssl/crypto/x509/i2d_pr.c third_party/boringssl/crypto/x509/pkcs7.c + third_party/boringssl/crypto/x509/rsa_pss.c third_party/boringssl/crypto/x509/t_crl.c third_party/boringssl/crypto/x509/t_req.c third_party/boringssl/crypto/x509/t_x509.c @@ -3094,21 +3100,17 @@ add_library(boringssl third_party/boringssl/crypto/x509v3/v3_utl.c third_party/boringssl/ssl/custom_extensions.c third_party/boringssl/ssl/d1_both.c - third_party/boringssl/ssl/d1_clnt.c third_party/boringssl/ssl/d1_lib.c - third_party/boringssl/ssl/d1_meth.c third_party/boringssl/ssl/d1_pkt.c third_party/boringssl/ssl/d1_srtp.c - third_party/boringssl/ssl/d1_srvr.c + third_party/boringssl/ssl/dtls_method.c third_party/boringssl/ssl/dtls_record.c - third_party/boringssl/ssl/pqueue/pqueue.c + third_party/boringssl/ssl/handshake_client.c + third_party/boringssl/ssl/handshake_server.c third_party/boringssl/ssl/s3_both.c - third_party/boringssl/ssl/s3_clnt.c third_party/boringssl/ssl/s3_enc.c third_party/boringssl/ssl/s3_lib.c - third_party/boringssl/ssl/s3_meth.c third_party/boringssl/ssl/s3_pkt.c - third_party/boringssl/ssl/s3_srvr.c third_party/boringssl/ssl/ssl_aead_ctx.c third_party/boringssl/ssl/ssl_asn1.c third_party/boringssl/ssl/ssl_buffer.c @@ -3122,6 +3124,11 @@ add_library(boringssl third_party/boringssl/ssl/ssl_stat.c third_party/boringssl/ssl/t1_enc.c third_party/boringssl/ssl/t1_lib.c + third_party/boringssl/ssl/tls13_both.c + third_party/boringssl/ssl/tls13_client.c + third_party/boringssl/ssl/tls13_enc.c + third_party/boringssl/ssl/tls13_server.c + third_party/boringssl/ssl/tls_method.c third_party/boringssl/ssl/tls_record.c ) @@ -3330,6 +3337,33 @@ target_link_libraries(boringssl_bytestring_test_lib ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_chacha_test_lib + third_party/boringssl/crypto/chacha/chacha_test.cc +) + + +target_include_directories(boringssl_chacha_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_chacha_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -3463,6 +3497,33 @@ target_link_libraries(boringssl_ed25519_test_lib ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_spake25519_test_lib + third_party/boringssl/crypto/curve25519/spake25519_test.cc +) + + +target_include_directories(boringssl_spake25519_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_spake25519_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -3621,6 +3682,60 @@ target_link_libraries(boringssl_example_mul_lib ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ecdh_test_lib + third_party/boringssl/crypto/ecdh/ecdh_test.cc +) + + +target_include_directories(boringssl_ecdh_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdh_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ecdsa_sign_test_lib + third_party/boringssl/crypto/ecdsa/ecdsa_sign_test.cc +) + + +target_include_directories(boringssl_ecdsa_sign_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_sign_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -3648,6 +3763,33 @@ target_link_libraries(boringssl_ecdsa_test_lib ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_ecdsa_verify_test_lib + third_party/boringssl/crypto/ecdsa/ecdsa_verify_test.cc +) + + +target_include_directories(boringssl_ecdsa_verify_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_verify_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -3837,7 +3979,7 @@ endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) add_library(boringssl_gcm_test_lib - third_party/boringssl/crypto/modes/gcm_test.c + third_party/boringssl/crypto/modes/gcm_test.cc ) @@ -3849,6 +3991,8 @@ target_include_directories(boringssl_gcm_test_lib PRIVATE ${ZLIB_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest ) target_link_libraries(boringssl_gcm_test_lib @@ -3858,6 +4002,114 @@ target_link_libraries(boringssl_gcm_test_lib ) +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_newhope_statistical_test_lib + third_party/boringssl/crypto/newhope/newhope_statistical_test.cc +) + + +target_include_directories(boringssl_newhope_statistical_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_statistical_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_newhope_test_lib + third_party/boringssl/crypto/newhope/newhope_test.cc +) + + +target_include_directories(boringssl_newhope_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_newhope_vectors_test_lib + third_party/boringssl/crypto/newhope/newhope_vectors_test.cc +) + + +target_include_directories(boringssl_newhope_vectors_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_vectors_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_library(boringssl_obj_test_lib + third_party/boringssl/crypto/obj/obj_test.cc +) + + +target_include_directories(boringssl_obj_test_lib + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_INCLUDE_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_obj_test_lib + ${_gRPC_SSL_LIBRARIES} + boringssl_test_util + boringssl +) + + endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -4118,31 +4370,6 @@ target_link_libraries(boringssl_v3name_test_lib ) -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - -add_library(boringssl_pqueue_test_lib - third_party/boringssl/ssl/pqueue/pqueue_test.c -) - - -target_include_directories(boringssl_pqueue_test_lib - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${BORINGSSL_ROOT_DIR}/include - PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_INCLUDE_DIR} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include -) - -target_link_libraries(boringssl_pqueue_test_lib - ${_gRPC_SSL_LIBRARIES} - boringssl_test_util - boringssl -) - - endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) @@ -9334,6 +9561,33 @@ target_link_libraries(boringssl_bytestring_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(boringssl_chacha_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_chacha_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_chacha_test + ${_gRPC_SSL_LIBRARIES} + boringssl_chacha_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(boringssl_aead_test third_party/googletest/src/gtest-all.cc ) @@ -9469,6 +9723,33 @@ target_link_libraries(boringssl_ed25519_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(boringssl_spake25519_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_spake25519_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_spake25519_test + ${_gRPC_SSL_LIBRARIES} + boringssl_spake25519_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(boringssl_x25519_test third_party/googletest/src/gtest-all.cc ) @@ -9631,6 +9912,60 @@ target_link_libraries(boringssl_example_mul endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(boringssl_ecdh_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ecdh_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdh_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ecdh_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_ecdsa_sign_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ecdsa_sign_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_sign_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ecdsa_sign_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(boringssl_ecdsa_test third_party/googletest/src/gtest-all.cc ) @@ -9658,6 +9993,33 @@ target_link_libraries(boringssl_ecdsa_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(boringssl_ecdsa_verify_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_ecdsa_verify_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_ecdsa_verify_test + ${_gRPC_SSL_LIBRARIES} + boringssl_ecdsa_verify_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(boringssl_err_test third_party/googletest/src/gtest-all.cc ) @@ -9874,6 +10236,114 @@ target_link_libraries(boringssl_gcm_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(boringssl_newhope_statistical_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_newhope_statistical_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_statistical_test + ${_gRPC_SSL_LIBRARIES} + boringssl_newhope_statistical_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_newhope_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_newhope_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_test + ${_gRPC_SSL_LIBRARIES} + boringssl_newhope_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_newhope_vectors_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_newhope_vectors_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_newhope_vectors_test + ${_gRPC_SSL_LIBRARIES} + boringssl_newhope_vectors_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + +add_executable(boringssl_obj_test + third_party/googletest/src/gtest-all.cc +) + +target_include_directories(boringssl_obj_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include + PRIVATE third_party/googletest/include + PRIVATE third_party/googletest +) + +target_link_libraries(boringssl_obj_test + ${_gRPC_SSL_LIBRARIES} + boringssl_obj_test_lib + boringssl_test_util + boringssl + ${_gRPC_GFLAGS_LIBRARIES} +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(boringssl_pkcs12_test third_party/googletest/src/gtest-all.cc ) @@ -10144,33 +10614,6 @@ target_link_libraries(boringssl_v3name_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(boringssl_pqueue_test - third_party/googletest/src/gtest-all.cc -) - -target_include_directories(boringssl_pqueue_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${BORINGSSL_ROOT_DIR}/include - PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include - PRIVATE third_party/googletest/include - PRIVATE third_party/googletest -) - -target_link_libraries(boringssl_pqueue_test - ${_gRPC_SSL_LIBRARIES} - boringssl_pqueue_test_lib - boringssl_test_util - boringssl - ${_gRPC_GFLAGS_LIBRARIES} -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(boringssl_ssl_test third_party/googletest/src/gtest-all.cc ) From 4e51140789dadc437ab34f805b722f9a4d10cb5b Mon Sep 17 00:00:00 2001 From: Eric Gribkoff Date: Fri, 20 Jan 2017 11:07:59 -0800 Subject: [PATCH 246/261] Update path to http2 Java test client --- tools/run_tests/run_interop_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index b2dac7d1a87..e18ca775f01 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -170,7 +170,7 @@ class JavaLanguage: return ['./run-test-client.sh'] + args def client_cmd_http2interop(self, args): - return ['./run-http2-client.sh'] + args + return ['./interop-testing/build/install/grpc-interop-testing/bin/http2-client'] + args def cloud_to_prod_env(self): return {} From 4906d2c4b1d86a881d86e53f1d6be400f4421e5f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Jan 2017 11:24:35 -0800 Subject: [PATCH 247/261] Update projects --- tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile | 1 - 1 file changed, 1 deletion(-) diff --git a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile index 03ff179f718..05e963d1e67 100644 --- a/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile +++ b/tools/dockerfile/interoptest/grpc_interop_http2/Dockerfile @@ -46,7 +46,6 @@ RUN apt-get update && apt-get install -y \ RUN pip install pip --upgrade RUN pip install virtualenv RUN pip install futures==2.2.0 enum34==1.0.4 protobuf==3.0.0a2 six==1.10.0 -RUN pip install twisted h2 # Define the default command. CMD ["bash"] From daa9f45f0e8963c4dd3fa4bc23bd28fbdb54becb Mon Sep 17 00:00:00 2001 From: Harvey Tuch Date: Mon, 21 Nov 2016 15:42:49 -0500 Subject: [PATCH 248/261] Fix workqueue_move_items_to_parent() invocation bug in polling_island_merge()[ev_epoll_linux.c]. This bug resulted in workqueue items failing to merge correctly and consequently queued closures would fail to execute. --- src/core/lib/iomgr/ev_epoll_linux.c | 2 +- test/core/iomgr/ev_epoll_linux_test.c | 128 +++++++++++++++++++++----- 2 files changed, 104 insertions(+), 26 deletions(-) diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index d6664aead2e..715d057c517 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -796,7 +796,7 @@ static polling_island *polling_island_merge(polling_island *p, gpr_atm_rel_store(&p->merged_to, (gpr_atm)q); PI_ADD_REF(q, "pi_merge"); /* To account for the new incoming ref from p */ - workqueue_move_items_to_parent(q); + workqueue_move_items_to_parent(p); } /* else if p == q, nothing needs to be done */ diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c index 40ae91bc6de..d95d5527731 100644 --- a/test/core/iomgr/ev_epoll_linux_test.c +++ b/test/core/iomgr/ev_epoll_linux_test.c @@ -45,6 +45,7 @@ #include #include "src/core/lib/iomgr/iomgr.h" +#include "src/core/lib/iomgr/workqueue.h" #include "test/core/util/test_config.h" typedef struct test_pollset { @@ -60,6 +61,22 @@ typedef struct test_fd { /* num_fds should be an even number */ static void test_fd_init(test_fd *tfds, int *fds, int num_fds) { int i; + int r; + + /* Create some dummy file descriptors. Currently using pipe file descriptors + * for this test but we could use any other type of file descriptors. Also, + * since pipe() used in this test creates two fds in each call, num_fds should + * be an even number */ + GPR_ASSERT((num_fds % 2) == 0); + for (i = 0; i < num_fds; i = i + 2) { + r = pipe(fds + i); + if (r != 0) { + gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno, + strerror(errno)); + return; + } + } + for (i = 0; i < num_fds; i++) { tfds[i].inner_fd = fds[i]; tfds[i].fd = grpc_fd_create(fds[i], "test_fd"); @@ -111,8 +128,80 @@ static void test_pollset_cleanup(grpc_exec_ctx *exec_ctx, } } -#define NUM_FDS 8 -#define NUM_POLLSETS 4 +static void increment(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + ++*(int *)arg; +} + +/* + * Validate that merging two workqueues preserves the closures in each queue. + * This is a regression test for a bug in + * polling_island_merge()[ev_epoll_linux.c], where the parent relationship was + * inverted. + */ +static void test_pollset_queue_merge_items() { + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + const int num_fds = 2; + const int num_pollsets = 2; + const int num_closures = 4; + test_fd tfds[num_fds]; + int fds[num_fds]; + test_pollset pollsets[num_pollsets]; + grpc_closure closures[num_closures]; + int i; + int result = 0; + + test_fd_init(tfds, fds, num_fds); + test_pollset_init(pollsets, num_pollsets); + + /* Two distinct polling islands, each with their own FD and pollset. */ + for (i = 0; i < num_fds; i++) { + grpc_pollset_add_fd(&exec_ctx, pollsets[i].pollset, tfds[i].fd); + grpc_exec_ctx_flush(&exec_ctx); + } + + /* Enqeue the closures, 3 to polling island 0 and 1 to polling island 1. */ + grpc_closure_init( + closures, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 1, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 2, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[0].fd))); + grpc_closure_init( + closures + 3, increment, &result, + grpc_workqueue_scheduler(grpc_fd_get_polling_island(tfds[1].fd))); + for (i = 0; i < num_closures; ++i) { + grpc_closure_sched(&exec_ctx, closures + i, GRPC_ERROR_NONE); + } + + /* Merge the two polling islands. */ + grpc_pollset_add_fd(&exec_ctx, pollsets[0].pollset, tfds[1].fd); + grpc_exec_ctx_flush(&exec_ctx); + + /* + * Execute the closures, verify we see each one execute when executing work on + * the merged polling island. + */ + grpc_pollset_worker *worker = NULL; + for (i = 0; i < num_closures; ++i) { + const gpr_timespec deadline = gpr_time_add( + gpr_now(GPR_CLOCK_MONOTONIC), gpr_time_from_seconds(2, GPR_TIMESPAN)); + gpr_mu_lock(pollsets[1].mu); + GRPC_LOG_IF_ERROR( + "grpc_pollset_work", + grpc_pollset_work(&exec_ctx, pollsets[1].pollset, &worker, + gpr_now(GPR_CLOCK_MONOTONIC), deadline)); + gpr_mu_unlock(pollsets[1].mu); + } + GPR_ASSERT(result == num_closures); + + test_fd_cleanup(&exec_ctx, tfds, num_fds); + test_pollset_cleanup(&exec_ctx, pollsets, num_pollsets); + grpc_exec_ctx_finish(&exec_ctx); +} + /* * Cases to test: * case 1) Polling islands of both fd and pollset are NULL @@ -125,28 +214,16 @@ static void test_pollset_cleanup(grpc_exec_ctx *exec_ctx, * */ static void test_add_fd_to_pollset() { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - test_fd tfds[NUM_FDS]; - int fds[NUM_FDS]; - test_pollset pollsets[NUM_POLLSETS]; + const int num_fds = 8; + const int num_pollsets = 4; + test_fd tfds[num_fds]; + int fds[num_fds]; + test_pollset pollsets[num_pollsets]; void *expected_pi = NULL; int i; - int r; - /* Create some dummy file descriptors. Currently using pipe file descriptors - * for this test but we could use any other type of file descriptors. Also, - * since pipe() used in this test creates two fds in each call, NUM_FDS should - * be an even number */ - for (i = 0; i < NUM_FDS; i = i + 2) { - r = pipe(fds + i); - if (r != 0) { - gpr_log(GPR_ERROR, "Error in creating pipe. %d (%s)", errno, - strerror(errno)); - return; - } - } - - test_fd_init(tfds, fds, NUM_FDS); - test_pollset_init(pollsets, NUM_POLLSETS); + test_fd_init(tfds, fds, num_fds); + test_pollset_init(pollsets, num_pollsets); /*Step 1. * Create three polling islands (This will exercise test case 1 and 2) with @@ -207,19 +284,19 @@ static void test_add_fd_to_pollset() { /* Compare Fd:0's polling island with that of all other Fds */ expected_pi = grpc_fd_get_polling_island(tfds[0].fd); - for (i = 1; i < NUM_FDS; i++) { + for (i = 1; i < num_fds; i++) { GPR_ASSERT(grpc_are_polling_islands_equal( expected_pi, grpc_fd_get_polling_island(tfds[i].fd))); } /* Compare Fd:0's polling island with that of all other pollsets */ - for (i = 0; i < NUM_POLLSETS; i++) { + for (i = 0; i < num_pollsets; i++) { GPR_ASSERT(grpc_are_polling_islands_equal( expected_pi, grpc_pollset_get_polling_island(pollsets[i].pollset))); } - test_fd_cleanup(&exec_ctx, tfds, NUM_FDS); - test_pollset_cleanup(&exec_ctx, pollsets, NUM_POLLSETS); + test_fd_cleanup(&exec_ctx, tfds, num_fds); + test_pollset_cleanup(&exec_ctx, pollsets, num_pollsets); grpc_exec_ctx_finish(&exec_ctx); } @@ -231,6 +308,7 @@ int main(int argc, char **argv) { poll_strategy = grpc_get_poll_strategy_name(); if (poll_strategy != NULL && strcmp(poll_strategy, "epoll") == 0) { test_add_fd_to_pollset(); + test_pollset_queue_merge_items(); } else { gpr_log(GPR_INFO, "Skipping the test. The test is only relevant for 'epoll' " From 4a08147513b67006f360fa02f61280e9edf04fac Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Jan 2017 13:33:11 -0800 Subject: [PATCH 249/261] Fix test under MSVC Optimizer was spotting that src1 and src2 would be identical and merging them. --- test/core/slice/slice_test.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index 75bef28dec4..f68a9532619 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -259,8 +259,8 @@ static void test_slice_interning(void) { LOG_TEST_NAME("test_slice_interning"); grpc_init(); - grpc_slice src1 = grpc_slice_from_copied_string("hello"); - grpc_slice src2 = grpc_slice_from_copied_string("hello"); + grpc_slice src1 = grpc_slice_from_copied_string("hello123456789123456789"); + grpc_slice src2 = grpc_slice_from_copied_string("hello123456789123456789"); GPR_ASSERT(GRPC_SLICE_START_PTR(src1) != GRPC_SLICE_START_PTR(src2)); grpc_slice interned1 = grpc_slice_intern(src1); grpc_slice interned2 = grpc_slice_intern(src2); From 55fe0db764089474a5b4bd4276b65419fbea11f0 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Jan 2017 13:35:45 -0800 Subject: [PATCH 250/261] Update projects --- CMakeLists.txt | 54 +++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 86856485bd3..7d34ef36f3d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1050,6 +1050,8 @@ add_library(grpc_test_util src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c + src/core/lib/slice/slice_hash_table.c + src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -1071,12 +1073,13 @@ add_library(grpc_test_util src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/mdstr_hash_table.c + src/core/lib/transport/error_utils.c src/core/lib/transport/metadata.c src/core/lib/transport/metadata_batch.c src/core/lib/transport/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c + src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -2218,6 +2221,7 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h + include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -4746,30 +4750,6 @@ target_link_libraries(chttp2_hpack_encoder_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(chttp2_status_conversion_test - test/core/transport/chttp2/status_conversion_test.c -) - -target_include_directories(chttp2_status_conversion_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${BORINGSSL_ROOT_DIR}/include - PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include -) - -target_link_libraries(chttp2_status_conversion_test - grpc_test_util - grpc - gpr_test_util - gpr -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(chttp2_stream_map_test test/core/transport/chttp2/stream_map_test.c ) @@ -7040,6 +7020,30 @@ target_link_libraries(socket_utils_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(status_conversion_test + test/core/transport/status_conversion_test.c +) + +target_include_directories(status_conversion_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(status_conversion_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(tcp_client_posix_test test/core/iomgr/tcp_client_posix_test.c ) From 7d561a6328caedaf7404af8d9015e465d3630810 Mon Sep 17 00:00:00 2001 From: Nathaniel Manista Date: Fri, 20 Jan 2017 21:05:47 +0000 Subject: [PATCH 251/261] Fix grpc._server._Context.time_remaining A weak test is included; proper test coverage will come later. --- src/python/grpcio/grpc/_server.py | 5 +++-- src/python/grpcio_tests/tests/unit/_rpc_test.py | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index 158cdf8b0e6..cbbe2dcbf5d 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -233,8 +233,9 @@ class _Context(grpc.ServicerContext): return self._state.client is not _CANCELLED and not self._state.statused def time_remaining(self): - return max(self._rpc_event.request_call_details.deadline - time.time(), - 0) + return max( + float(self._rpc_event.request_call_details.deadline) - time.time(), + 0) def cancel(self): self._rpc_event.operation_call.cancel() diff --git a/src/python/grpcio_tests/tests/unit/_rpc_test.py b/src/python/grpcio_tests/tests/unit/_rpc_test.py index 2cf6dfea620..2b1c85a82d2 100644 --- a/src/python/grpcio_tests/tests/unit/_rpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_rpc_test.py @@ -81,6 +81,11 @@ class _Handler(object): servicer_context.set_trailing_metadata((( 'testkey', 'testvalue',),)) + # TODO(https://github.com/grpc/grpc/issues/8483): test the values + # returned by these methods rather than only "smoke" testing that + # the return after having been called. + servicer_context.is_active() + servicer_context.time_remaining() return request def handle_unary_stream(self, request, servicer_context): From a66dad5db6339b81e0dd0891881855b916c8e216 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Fri, 20 Jan 2017 18:13:26 -0500 Subject: [PATCH 252/261] Add __richcmp__ to cygrpc.Timespec --- .../grpc/_cython/_cygrpc/records.pyx.pxi | 19 +++++++++++++++++++ .../tests/unit/_cython/cygrpc_test.py | 14 ++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index d052b3f8bc9..a9163c75bfd 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -194,6 +194,25 @@ cdef class Timespec: def infinite_past(): return Timespec(float("-inf")) + def __richcmp__(Timespec self not None, Timespec other not None, int op): + cdef gpr_timespec self_c_time = self.c_time + cdef gpr_timespec other_c_time = other.c_time + cdef int result = gpr_time_cmp(self_c_time, other_c_time) + if op == 0: # < + return result < 0 + elif op == 2: # == + return result == 0 + elif op == 4: # > + return result > 0 + elif op == 1: # <= + return result <= 0 + elif op == 3: # != + return result != 0 + elif op == 5: # >= + return result >= 0 + else: + raise ValueError('__richcmp__ `op` contract violated') + cdef class CallDetails: diff --git a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py index 7aec316b95d..a4d5015aa41 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py @@ -95,8 +95,18 @@ class TypeSmokeTest(unittest.TestCase): def testTimespec(self): now = time.time() - timespec = cygrpc.Timespec(now) - self.assertAlmostEqual(now, float(timespec), places=8) + now_timespec_a = cygrpc.Timespec(now) + now_timespec_b = cygrpc.Timespec(now) + self.assertAlmostEqual(now, float(now_timespec_a), places=8) + self.assertEqual(now_timespec_a, now_timespec_b) + self.assertLess(cygrpc.Timespec(now - 1), cygrpc.Timespec(now)) + self.assertGreater(cygrpc.Timespec(now + 1), cygrpc.Timespec(now)) + self.assertGreaterEqual(cygrpc.Timespec(now + 1), cygrpc.Timespec(now)) + self.assertGreaterEqual(cygrpc.Timespec(now), cygrpc.Timespec(now)) + self.assertLessEqual(cygrpc.Timespec(now - 1), cygrpc.Timespec(now)) + self.assertLessEqual(cygrpc.Timespec(now), cygrpc.Timespec(now)) + self.assertNotEqual(cygrpc.Timespec(now - 1), cygrpc.Timespec(now)) + self.assertNotEqual(cygrpc.Timespec(now + 1), cygrpc.Timespec(now)) def testCompletionQueueUpDown(self): completion_queue = cygrpc.CompletionQueue() From 459c93f147663b8f57f7ae3876104fcba138b26f Mon Sep 17 00:00:00 2001 From: ncteisen Date: Fri, 20 Jan 2017 15:42:07 -0800 Subject: [PATCH 253/261] Update name of Python negative interop test --- tools/run_tests/run_interop_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/run_interop_tests.py b/tools/run_tests/run_interop_tests.py index e18ca775f01..53df3347a0c 100755 --- a/tools/run_tests/run_interop_tests.py +++ b/tools/run_tests/run_interop_tests.py @@ -406,7 +406,7 @@ class PythonLanguage: def client_cmd_http2interop(self, args): return [ 'py27/bin/python', - 'src/python/grpcio_tests/tests/http2/_negative_http2_client.py', + 'src/python/grpcio_tests/tests/http2/negative_http2_client.py', ] + args def cloud_to_prod_env(self): From aa7089a549566cb2af45e6cbca0e9da3f22e988a Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Fri, 20 Jan 2017 18:33:13 -0500 Subject: [PATCH 254/261] Be more verbose when generating Python documentation --- tools/distrib/python/docgen.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/distrib/python/docgen.py b/tools/distrib/python/docgen.py index 38ffcd6e0e3..fddaa2ba3e0 100755 --- a/tools/distrib/python/docgen.py +++ b/tools/distrib/python/docgen.py @@ -28,11 +28,14 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from __future__ import print_function + import argparse import os import os.path import shutil import subprocess +import sys import tempfile parser = argparse.ArgumentParser() @@ -99,6 +102,7 @@ if args.submit: python_doc_dir = os.path.join(repo_dir, 'python') doc_branch = args.doc_branch + print('Cloning your repository...') subprocess.check_call([ 'git', 'clone', 'https://{}@github.com/{}/grpc'.format( github_user, github_repository_owner) @@ -110,13 +114,20 @@ if args.submit: subprocess.check_call([ 'git', 'checkout', 'upstream/gh-pages', '-b', doc_branch ], cwd=repo_dir) + print('Updating documentation...') shutil.rmtree(python_doc_dir, ignore_errors=True) shutil.copytree(DOC_PATH, python_doc_dir) - subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir) - subprocess.check_call([ - 'git', 'commit', '-m', 'Auto-update Python documentation' - ], cwd=repo_dir) - subprocess.check_call([ - 'git', 'push', '--set-upstream', 'origin', doc_branch - ], cwd=repo_dir) + print('Attempting to push documentation...') + try: + subprocess.check_call(['git', 'add', '--all'], cwd=repo_dir) + subprocess.check_call([ + 'git', 'commit', '-m', 'Auto-update Python documentation' + ], cwd=repo_dir) + subprocess.check_call([ + 'git', 'push', '--set-upstream', 'origin', doc_branch + ], cwd=repo_dir) + except subprocess.CalledProcessError: + print('Failed to push documentation. Examine this directory and push ' + 'manually: {}'.format(repo_parent_dir)) + sys.exit(1) shutil.rmtree(repo_parent_dir) From 5e01e2ac977655aa074faf7fde0a74298f5e4c55 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 20 Jan 2017 18:11:52 -0800 Subject: [PATCH 255/261] Revert "Metadata handling rewrite" --- .gitignore | 5 +- BUILD | 15 +- CMakeLists.txt | 81 +- Makefile | 283 ++--- binding.gyp | 7 +- build.yaml | 68 +- config.m4 | 6 +- gRPC-Core.podspec | 24 +- grpc.def | 15 +- grpc.gemspec | 15 +- include/grpc++/impl/codegen/call.h | 68 +- include/grpc++/impl/codegen/client_context.h | 10 +- .../grpc++/impl/codegen/client_unary_call.h | 9 +- include/grpc++/impl/codegen/core_codegen.h | 8 +- .../impl/codegen/core_codegen_interface.h | 17 +- include/grpc++/impl/codegen/metadata_map.h | 71 -- include/grpc++/impl/codegen/server_context.h | 5 +- .../grpc++/impl/codegen/server_interface.h | 1 + include/grpc++/impl/codegen/slice.h | 65 - include/grpc/compression.h | 8 +- include/grpc/grpc.h | 10 +- include/grpc/impl/codegen/grpc_types.h | 42 +- include/grpc/impl/codegen/slice.h | 21 +- include/grpc/slice.h | 38 +- package.xml | 15 +- src/core/ext/census/gen/census.pb.h | 2 +- src/core/ext/census/gen/trace_context.pb.h | 2 +- src/core/ext/census/grpc_filter.c | 4 +- src/core/ext/client_channel/client_channel.c | 29 +- src/core/ext/client_channel/subchannel.c | 10 +- src/core/ext/client_channel/subchannel.h | 2 +- src/core/ext/lb_policy/grpclb/grpclb.c | 66 +- .../load_reporting/load_reporting_filter.c | 84 +- .../ext/resolver/dns/native/dns_resolver.c | 5 +- .../ext/resolver/sockaddr/sockaddr_resolver.c | 2 +- .../transport/chttp2/server/chttp2_server.c | 4 +- .../chttp2/server/insecure/server_chttp2.c | 2 +- .../server/secure/server_secure_chttp2.c | 2 +- .../transport/chttp2/transport/bin_decoder.c | 14 +- .../transport/chttp2/transport/bin_encoder.c | 3 +- .../transport/chttp2/transport/bin_encoder.h | 3 +- .../chttp2/transport/chttp2_plugin.c | 3 + .../chttp2/transport/chttp2_transport.c | 372 +++--- .../chttp2/transport/frame_rst_stream.c | 13 +- .../chttp2/transport/frame_settings.c | 16 +- .../chttp2/transport/hpack_encoder.c | 152 +-- .../chttp2/transport/hpack_encoder.h | 4 +- .../transport/chttp2/transport/hpack_parser.c | 196 ++- .../transport/chttp2/transport/hpack_parser.h | 20 +- .../transport/chttp2/transport/hpack_table.c | 41 +- .../transport/chttp2/transport/hpack_table.h | 12 +- .../chttp2}/transport/http2_errors.h | 36 +- .../chttp2/transport/incoming_metadata.c | 34 +- .../chttp2/transport/incoming_metadata.h | 8 +- .../ext/transport/chttp2/transport/internal.h | 3 +- .../ext/transport/chttp2/transport/parsing.c | 69 +- .../chttp2}/transport/status_conversion.c | 38 +- .../chttp2}/transport/status_conversion.h | 19 +- .../ext/transport/chttp2/transport/writing.c | 6 +- .../cronet/transport/cronet_transport.c | 49 +- src/core/lib/channel/channel_stack.c | 43 +- src/core/lib/channel/channel_stack.h | 19 +- src/core/lib/channel/compress_filter.c | 94 +- src/core/lib/channel/deadline_filter.c | 15 +- src/core/lib/channel/http_client_filter.c | 246 ++-- src/core/lib/channel/http_server_filter.c | 296 +++-- src/core/lib/channel/message_size_filter.c | 14 +- src/core/lib/compression/algorithm_metadata.h | 8 +- src/core/lib/compression/compression.c | 40 +- .../lib/http/httpcli_security_connector.c | 2 +- src/core/lib/iomgr/closure.c | 1 - src/core/lib/iomgr/closure.h | 1 - src/core/lib/iomgr/combiner.c | 12 +- src/core/lib/iomgr/error.c | 154 ++- src/core/lib/iomgr/error.h | 13 +- src/core/lib/iomgr/error_internal.h | 54 - src/core/lib/iomgr/ev_epoll_linux.c | 2 +- src/core/lib/iomgr/ev_posix.c | 2 - src/core/lib/iomgr/exec_ctx.c | 17 +- src/core/lib/iomgr/exec_ctx.h | 25 +- src/core/lib/iomgr/executor.c | 4 +- src/core/lib/iomgr/load_file.c | 2 +- src/core/lib/iomgr/resource_quota.c | 8 +- src/core/lib/iomgr/tcp_client_posix.c | 2 + src/core/lib/iomgr/tcp_posix.c | 4 +- src/core/lib/iomgr/tcp_server_windows.c | 2 +- src/core/lib/iomgr/tcp_uv.c | 3 +- .../google_default_credentials.c | 2 +- .../credentials/plugin/plugin_credentials.c | 22 +- .../security/transport/client_auth_filter.c | 115 +- .../security/transport/security_connector.c | 2 +- .../security/transport/security_handshaker.c | 2 +- .../security/transport/server_auth_filter.c | 69 +- src/core/lib/security/util/b64.c | 2 +- src/core/lib/slice/slice.c | 130 +- src/core/lib/slice/slice_intern.c | 344 ------ src/core/lib/slice/slice_internal.h | 15 - src/core/lib/slice/slice_string_helpers.c | 5 - src/core/lib/slice/slice_string_helpers.h | 5 - src/core/lib/slice/slice_traits.h | 44 - src/core/lib/surface/call.c | 1072 +++++++++-------- src/core/lib/surface/call.h | 2 +- src/core/lib/surface/call_details.c | 10 +- src/core/lib/surface/call_log_batch.c | 23 +- src/core/lib/surface/channel.c | 106 +- src/core/lib/surface/channel.h | 11 +- src/core/lib/surface/completion_queue.c | 15 +- src/core/lib/surface/init.c | 3 - src/core/lib/surface/lame_client.c | 16 +- src/core/lib/surface/server.c | 142 +-- src/core/lib/surface/validate_metadata.c | 61 +- src/core/lib/surface/validate_metadata.h | 43 - src/core/lib/transport/connectivity_state.c | 1 + src/core/lib/transport/error_utils.c | 124 -- src/core/lib/transport/error_utils.h | 56 - .../mdstr_hash_table.c} | 69 +- .../mdstr_hash_table.h} | 42 +- src/core/lib/transport/metadata.c | 760 ++++++++---- src/core/lib/transport/metadata.h | 137 ++- src/core/lib/transport/metadata_batch.c | 242 +--- src/core/lib/transport/metadata_batch.h | 76 +- src/core/lib/transport/method_config.c | 347 ++++++ src/core/lib/transport/method_config.h | 139 +++ src/core/lib/transport/service_config.c | 39 +- src/core/lib/transport/service_config.h | 10 +- src/core/lib/transport/static_metadata.c | 870 ++----------- src/core/lib/transport/static_metadata.h | 672 ++++------- src/core/lib/transport/timeout_encoding.c | 20 +- src/core/lib/transport/timeout_encoding.h | 4 +- src/core/lib/transport/transport.c | 99 +- src/core/lib/transport/transport.h | 34 +- src/core/lib/transport/transport_op_string.c | 26 +- src/cpp/client/channel_cc.cc | 18 +- src/cpp/client/secure_credentials.cc | 9 +- src/cpp/client/secure_credentials.h | 2 +- src/cpp/common/channel_filter.cc | 8 +- src/cpp/common/channel_filter.h | 6 +- src/cpp/common/core_codegen.cc | 17 +- src/cpp/server/dynamic_thread_pool.cc | 5 +- src/cpp/server/secure_server_credentials.cc | 19 +- src/cpp/server/server_cc.cc | 26 +- src/cpp/server/server_context.cc | 7 +- src/cpp/test/server_context_test_spouse.cc | 7 +- src/cpp/util/slice_cc.cc | 2 +- .../Internal/BatchContextSafeHandle.cs | 4 +- .../Internal/MetadataArraySafeHandle.cs | 10 +- .../Grpc.Core/Internal/NativeMethods.cs | 13 +- .../Internal/RequestCallContextSafeHandle.cs | 10 +- src/csharp/ext/grpc_csharp_ext.c | 73 +- src/node/ext/byte_buffer.cc | 6 +- src/node/ext/call.cc | 130 +- src/node/ext/call.h | 17 +- src/node/ext/call_credentials.cc | 3 +- src/node/ext/channel.cc | 3 +- src/node/ext/node_grpc.cc | 16 +- src/node/ext/server.cc | 19 +- src/node/ext/slice.cc | 102 -- src/node/ext/slice.h | 52 - .../GRPCClient/private/GRPCChannel.m | 2 +- .../GRPCClient/private/GRPCWrappedCall.m | 19 +- .../GRPCClient/private/NSDictionary+GRPC.m | 20 +- src/php/ext/grpc/call.c | 47 +- src/php/ext/grpc/server.c | 10 +- .../grpc/_cython/_cygrpc/channel.pyx.pxi | 15 +- .../_cython/_cygrpc/completion_queue.pyx.pxi | 14 +- .../grpcio/grpc/_cython/_cygrpc/grpc.pxi | 35 +- .../grpc/_cython/_cygrpc/records.pxd.pxi | 12 +- .../grpc/_cython/_cygrpc/records.pyx.pxi | 129 +- src/python/grpcio/grpc/_server.py | 2 - src/python/grpcio/grpc_core_dependencies.py | 6 +- src/ruby/ext/grpc/rb_byte_buffer.c | 7 - src/ruby/ext/grpc/rb_byte_buffer.h | 3 - src/ruby/ext/grpc/rb_call.c | 93 +- src/ruby/ext/grpc/rb_channel.c | 27 +- src/ruby/ext/grpc/rb_compression_options.c | 15 +- src/ruby/ext/grpc/rb_grpc_imports.generated.c | 30 +- src/ruby/ext/grpc/rb_grpc_imports.generated.h | 55 +- src/ruby/ext/grpc/rb_server.c | 10 +- test/core/bad_client/tests/large_metadata.c | 59 +- test/core/bad_client/tests/simple_request.c | 4 +- test/core/bad_ssl/bad_ssl_test.c | 11 +- test/core/channel/channel_stack_test.c | 5 +- test/core/client_channel/lb_policies_test.c | 31 +- .../set_initial_connect_string_test.c | 9 +- test/core/compression/algorithm_test.c | 42 +- test/core/compression/compression_test.c | 4 +- test/core/compression/message_compress_test.c | 2 +- test/core/end2end/bad_server_response_test.c | 16 +- test/core/end2end/connection_refused_test.c | 14 +- test/core/end2end/cq_verifier.c | 20 +- test/core/end2end/cq_verifier.h | 2 - test/core/end2end/dualstack_socket_test.c | 22 +- test/core/end2end/end2end_test_utils.c | 22 +- test/core/end2end/end2end_tests.h | 6 +- test/core/end2end/fake_resolver.c | 2 +- test/core/end2end/fixtures/h2_oauth2.c | 10 +- test/core/end2end/fixtures/h2_ssl_cert.c | 5 +- test/core/end2end/fixtures/http_proxy.c | 2 +- test/core/end2end/fixtures/proxy.c | 15 +- test/core/end2end/fuzzers/api_fuzzer.c | 111 +- test/core/end2end/fuzzers/client_fuzzer.c | 16 +- test/core/end2end/fuzzers/hpack.dictionary | 153 ++- test/core/end2end/fuzzers/server_fuzzer.c | 3 +- test/core/end2end/goaway_server_test.c | 27 +- .../core/end2end/invalid_call_argument_test.c | 44 +- test/core/end2end/no_server_test.c | 10 +- .../end2end/tests/authority_not_supported.c | 21 +- test/core/end2end/tests/bad_hostname.c | 10 +- test/core/end2end/tests/binary_metadata.c | 77 +- test/core/end2end/tests/call_creds.c | 29 +- test/core/end2end/tests/cancel_after_accept.c | 12 +- .../end2end/tests/cancel_after_client_done.c | 11 +- test/core/end2end/tests/cancel_after_invoke.c | 11 +- .../core/end2end/tests/cancel_before_invoke.c | 11 +- test/core/end2end/tests/cancel_in_a_vacuum.c | 5 +- test/core/end2end/tests/cancel_with_status.c | 13 +- test/core/end2end/tests/compressed_payload.c | 47 +- test/core/end2end/tests/default_host.c | 18 +- test/core/end2end/tests/disappearing_server.c | 18 +- test/core/end2end/tests/empty_batch.c | 5 +- .../end2end/tests/filter_call_init_fails.c | 13 +- test/core/end2end/tests/filter_causes_close.c | 28 +- test/core/end2end/tests/filter_latency.c | 17 +- .../end2end/tests/graceful_server_shutdown.c | 16 +- test/core/end2end/tests/high_initial_seqno.c | 18 +- test/core/end2end/tests/hpack_size.c | 36 +- test/core/end2end/tests/idempotent_request.c | 18 +- .../core/end2end/tests/invoke_large_request.c | 18 +- test/core/end2end/tests/large_metadata.c | 32 +- test/core/end2end/tests/load_reporting_hook.c | 24 +- .../end2end/tests/max_concurrent_streams.c | 47 +- test/core/end2end/tests/max_message_length.c | 54 +- test/core/end2end/tests/negative_deadline.c | 11 +- .../end2end/tests/network_status_change.c | 16 +- test/core/end2end/tests/no_logging.c | 18 +- test/core/end2end/tests/payload.c | 18 +- test/core/end2end/tests/ping_pong_streaming.c | 14 +- test/core/end2end/tests/registered_call.c | 13 +- test/core/end2end/tests/request_with_flags.c | 11 +- .../core/end2end/tests/request_with_payload.c | 18 +- .../end2end/tests/resource_quota_server.c | 23 +- .../end2end/tests/server_finishes_request.c | 18 +- .../end2end/tests/shutdown_finishes_calls.c | 13 +- .../end2end/tests/simple_cacheable_request.c | 40 +- .../end2end/tests/simple_delayed_request.c | 18 +- test/core/end2end/tests/simple_metadata.c | 40 +- test/core/end2end/tests/simple_request.c | 18 +- .../end2end/tests/streaming_error_response.c | 19 +- test/core/end2end/tests/trailing_metadata.c | 51 +- test/core/end2end/tests/write_buffering.c | 18 +- .../end2end/tests/write_buffering_at_end.c | 18 +- test/core/fling/client.c | 20 +- test/core/fling/server.c | 8 +- test/core/iomgr/ev_epoll_linux_test.c | 1 - test/core/memory_usage/client.c | 51 +- test/core/memory_usage/server.c | 28 +- test/core/security/credentials_test.c | 9 +- .../print_google_default_creds_token.c | 2 +- test/core/security/secure_endpoint_test.c | 2 +- test/core/security/security_connector_test.c | 6 +- test/core/slice/percent_encode_fuzzer.c | 4 +- test/core/slice/percent_encoding_test.c | 10 +- test/core/slice/slice_test.c | 62 +- test/core/surface/lame_client_test.c | 9 +- test/core/transport/chttp2/bin_decoder_test.c | 2 +- test/core/transport/chttp2/bin_encoder_test.c | 8 +- .../transport/chttp2/hpack_encoder_test.c | 14 +- .../chttp2/hpack_parser_fuzzer_test.c | 9 +- .../core/transport/chttp2/hpack_parser_test.c | 11 +- test/core/transport/chttp2/hpack_table_test.c | 37 +- .../{ => chttp2}/status_conversion_test.c | 98 +- test/core/transport/chttp2/varint_test.c | 2 +- test/core/transport/metadata_test.c | 325 ++--- test/core/transport/timeout_encoding_test.c | 28 +- test/core/util/port_server_client.c | 2 +- test/cpp/end2end/async_end2end_test.cc | 21 +- test/cpp/end2end/end2end_test.cc | 21 +- test/cpp/grpclb/grpclb_test.cc | 19 +- test/cpp/interop/client.cc | 180 +-- test/cpp/interop/interop_client.cc | 9 +- test/cpp/interop/interop_client.h | 1 - test/cpp/interop/interop_server.cc | 4 +- test/cpp/microbenchmarks/bm_fullstack.cc | 2 - .../test/server_context_test_spouse_test.cc | 3 - tools/codegen/core/gen_static_metadata.py | 215 +--- tools/doxygen/Doxyfile.c++ | 1 - tools/doxygen/Doxyfile.c++.internal | 1 - tools/doxygen/Doxyfile.core.internal | 15 +- tools/run_tests/generated/configs.json | 72 +- .../generated/sources_and_headers.json | 60 +- tools/run_tests/generated/tests.json | 146 ++- vsprojects/buildtests_c.sln | 54 +- vsprojects/vcxproj/grpc++/grpc++.vcxproj | 1 - .../vcxproj/grpc++/grpc++.vcxproj.filters | 3 - .../grpc++_test_util/grpc++_test_util.vcxproj | 1 - .../grpc++_test_util.vcxproj.filters | 3 - .../grpc++_unsecure/grpc++_unsecure.vcxproj | 1 - .../grpc++_unsecure.vcxproj.filters | 3 - vsprojects/vcxproj/grpc/grpc.vcxproj | 19 +- vsprojects/vcxproj/grpc/grpc.vcxproj.filters | 37 +- .../grpc_test_util/grpc_test_util.vcxproj | 15 +- .../grpc_test_util.vcxproj.filters | 28 +- .../grpc_unsecure/grpc_unsecure.vcxproj | 19 +- .../grpc_unsecure.vcxproj.filters | 37 +- .../chttp2_status_conversion_test.vcxproj} | 8 +- ...tp2_status_conversion_test.vcxproj.filters | 24 + .../codegen_test_full.vcxproj | 1 - .../codegen_test_full.vcxproj.filters | 3 - .../codegen_test_minimal.vcxproj | 1 - .../codegen_test_minimal.vcxproj.filters | 3 - .../grpc_tool_test/grpc_tool_test.vcxproj | 1 - .../grpc_tool_test.vcxproj.filters | 3 - .../status_conversion_test.vcxproj.filters | 21 - 313 files changed, 6042 insertions(+), 7911 deletions(-) delete mode 100644 include/grpc++/impl/codegen/metadata_map.h delete mode 100644 include/grpc++/impl/codegen/slice.h rename src/core/{lib => ext/transport/chttp2}/transport/http2_errors.h (69%) rename src/core/{lib => ext/transport/chttp2}/transport/status_conversion.c (78%) rename src/core/{lib => ext/transport/chttp2}/transport/status_conversion.h (73%) delete mode 100644 src/core/lib/iomgr/error_internal.h delete mode 100644 src/core/lib/slice/slice_intern.c delete mode 100644 src/core/lib/slice/slice_traits.h delete mode 100644 src/core/lib/surface/validate_metadata.h delete mode 100644 src/core/lib/transport/error_utils.c delete mode 100644 src/core/lib/transport/error_utils.h rename src/core/lib/{slice/slice_hash_table.c => transport/mdstr_hash_table.c} (61%) rename src/core/lib/{slice/slice_hash_table.h => transport/mdstr_hash_table.h} (67%) create mode 100644 src/core/lib/transport/method_config.c create mode 100644 src/core/lib/transport/method_config.h delete mode 100644 src/node/ext/slice.cc delete mode 100644 src/node/ext/slice.h rename test/core/transport/{ => chttp2}/status_conversion_test.c (65%) rename vsprojects/vcxproj/test/{status_conversion_test/status_conversion_test.vcxproj => chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj} (97%) create mode 100644 vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters delete mode 100644 vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters diff --git a/.gitignore b/.gitignore index 4098106e760..618c9ba5ae1 100644 --- a/.gitignore +++ b/.gitignore @@ -32,7 +32,7 @@ coverage # python compiled objects *.pyc -# eclipse project files +#eclipse project files .cproject .project .settings @@ -111,6 +111,3 @@ bazel-genfiles bazel-grpc bazel-out bazel-testlogs - -# Debug output -gdb.txt diff --git a/BUILD b/BUILD index a134d28a562..54192514cc7 100644 --- a/BUILD +++ b/BUILD @@ -499,8 +499,6 @@ grpc_cc_library( "src/core/lib/slice/percent_encoding.c", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", - "src/core/lib/slice/slice_hash_table.c", - "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/surface/alarm.c", "src/core/lib/surface/api_trace.c", @@ -522,13 +520,12 @@ grpc_cc_library( "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/connectivity_state.c", - "src/core/lib/transport/error_utils.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/pid_controller.c", "src/core/lib/transport/service_config.c", "src/core/lib/transport/static_metadata.c", - "src/core/lib/transport/status_conversion.c", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/transport.c", "src/core/lib/transport/transport_op_string.c", @@ -558,7 +555,6 @@ grpc_cc_library( "src/core/lib/iomgr/endpoint.h", "src/core/lib/iomgr/endpoint_pair.h", "src/core/lib/iomgr/error.h", - "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.h", "src/core/lib/iomgr/ev_posix.h", @@ -611,7 +607,6 @@ grpc_cc_library( "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", - "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_internal.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", @@ -623,19 +618,16 @@ grpc_cc_library( "src/core/lib/surface/completion_queue.h", "src/core/lib/surface/event_string.h", "src/core/lib/surface/init.h", - "src/core/lib/surface/validate_metadata.h", "src/core/lib/surface/lame_client.h", "src/core/lib/surface/server.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/error_utils.h", - "src/core/lib/transport/http2_errors.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/pid_controller.h", "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", - "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", "src/core/lib/transport/transport_impl.h", @@ -888,6 +880,7 @@ grpc_cc_library( "src/core/ext/transport/chttp2/transport/huffsyms.c", "src/core/ext/transport/chttp2/transport/incoming_metadata.c", "src/core/ext/transport/chttp2/transport/parsing.c", + "src/core/ext/transport/chttp2/transport/status_conversion.c", "src/core/ext/transport/chttp2/transport/stream_lists.c", "src/core/ext/transport/chttp2/transport/stream_map.c", "src/core/ext/transport/chttp2/transport/varint.c", @@ -907,9 +900,11 @@ grpc_cc_library( "src/core/ext/transport/chttp2/transport/hpack_encoder.h", "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.h", + "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", + "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h", ], diff --git a/CMakeLists.txt b/CMakeLists.txt index 23c5f7bdd79..2ca0b805429 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -482,8 +482,6 @@ add_library(grpc src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -505,13 +503,12 @@ add_library(grpc src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/error_utils.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/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c - src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -532,6 +529,7 @@ add_library(grpc src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c + src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -771,8 +769,6 @@ add_library(grpc_cronet src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -794,13 +790,12 @@ add_library(grpc_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/error_utils.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/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c - src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -824,6 +819,7 @@ add_library(grpc_cronet src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c + src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -1050,8 +1046,6 @@ add_library(grpc_test_util src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -1073,13 +1067,12 @@ add_library(grpc_test_util src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/error_utils.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/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c - src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -1268,8 +1261,6 @@ add_library(grpc_unsecure src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -1291,13 +1282,12 @@ add_library(grpc_unsecure src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/error_utils.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/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c - src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -1319,6 +1309,7 @@ add_library(grpc_unsecure src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c + src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -1614,7 +1605,6 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h - include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -1712,6 +1702,7 @@ add_library(grpc++_cronet src/core/ext/transport/chttp2/transport/huffsyms.c src/core/ext/transport/chttp2/transport/incoming_metadata.c src/core/ext/transport/chttp2/transport/parsing.c + src/core/ext/transport/chttp2/transport/status_conversion.c src/core/ext/transport/chttp2/transport/stream_lists.c src/core/ext/transport/chttp2/transport/stream_map.c src/core/ext/transport/chttp2/transport/varint.c @@ -1800,8 +1791,6 @@ add_library(grpc++_cronet src/core/lib/slice/percent_encoding.c src/core/lib/slice/slice.c src/core/lib/slice/slice_buffer.c - src/core/lib/slice/slice_hash_table.c - src/core/lib/slice/slice_intern.c src/core/lib/slice/slice_string_helpers.c src/core/lib/surface/alarm.c src/core/lib/surface/api_trace.c @@ -1823,13 +1812,12 @@ add_library(grpc++_cronet src/core/lib/surface/version.c src/core/lib/transport/byte_stream.c src/core/lib/transport/connectivity_state.c - src/core/lib/transport/error_utils.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/pid_controller.c src/core/lib/transport/service_config.c src/core/lib/transport/static_metadata.c - src/core/lib/transport/status_conversion.c src/core/lib/transport/timeout_encoding.c src/core/lib/transport/transport.c src/core/lib/transport/transport_op_string.c @@ -1956,7 +1944,6 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h - include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -2221,7 +2208,6 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h - include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -2379,7 +2365,6 @@ foreach(_hdr include/grpc++/impl/codegen/server_context.h include/grpc++/impl/codegen/server_interface.h include/grpc++/impl/codegen/service_type.h - include/grpc++/impl/codegen/slice.h include/grpc++/impl/codegen/status.h include/grpc++/impl/codegen/status_code_enum.h include/grpc++/impl/codegen/status_helper.h @@ -4977,6 +4962,30 @@ target_link_libraries(chttp2_hpack_encoder_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) +add_executable(chttp2_status_conversion_test + test/core/transport/chttp2/status_conversion_test.c +) + +target_include_directories(chttp2_status_conversion_test + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include + PRIVATE ${BORINGSSL_ROOT_DIR}/include + PRIVATE ${PROTOBUF_ROOT_DIR}/src + PRIVATE ${ZLIB_ROOT_DIR} + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib + PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include +) + +target_link_libraries(chttp2_status_conversion_test + grpc_test_util + grpc + gpr_test_util + gpr +) + +endif (gRPC_BUILD_TESTS) +if (gRPC_BUILD_TESTS) + add_executable(chttp2_stream_map_test test/core/transport/chttp2/stream_map_test.c ) @@ -7247,30 +7256,6 @@ target_link_libraries(socket_utils_test endif (gRPC_BUILD_TESTS) if (gRPC_BUILD_TESTS) -add_executable(status_conversion_test - test/core/transport/status_conversion_test.c -) - -target_include_directories(status_conversion_test - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} - PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/include - PRIVATE ${BORINGSSL_ROOT_DIR}/include - PRIVATE ${PROTOBUF_ROOT_DIR}/src - PRIVATE ${ZLIB_ROOT_DIR} - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib - PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include -) - -target_link_libraries(status_conversion_test - grpc_test_util - grpc - gpr_test_util - gpr -) - -endif (gRPC_BUILD_TESTS) -if (gRPC_BUILD_TESTS) - add_executable(tcp_client_posix_test test/core/iomgr/tcp_client_posix_test.c ) diff --git a/Makefile b/Makefile index f903d273f0a..50e4411bb79 100644 --- a/Makefile +++ b/Makefile @@ -95,34 +95,6 @@ LDXX_opt = $(DEFAULT_CXX) CPPFLAGS_opt = -O2 DEFINES_opt = NDEBUG -VALID_CONFIG_basicprof = 1 -CC_basicprof = $(DEFAULT_CC) -CXX_basicprof = $(DEFAULT_CXX) -LD_basicprof = $(DEFAULT_CC) -LDXX_basicprof = $(DEFAULT_CXX) -CPPFLAGS_basicprof = -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC -DEFINES_basicprof = NDEBUG - -VALID_CONFIG_helgrind = 1 -CC_helgrind = $(DEFAULT_CC) -CXX_helgrind = $(DEFAULT_CXX) -LD_helgrind = $(DEFAULT_CC) -LDXX_helgrind = $(DEFAULT_CXX) -CPPFLAGS_helgrind = -O0 -LDFLAGS_helgrind = -rdynamic -DEFINES_helgrind = _DEBUG DEBUG -DEFINES_helgrind += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 - -VALID_CONFIG_asan-noleaks = 1 -REQUIRE_CUSTOM_LIBRARIES_asan-noleaks = 1 -CC_asan-noleaks = clang -CXX_asan-noleaks = clang++ -LD_asan-noleaks = clang -LDXX_asan-noleaks = clang++ -CPPFLAGS_asan-noleaks = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_asan-noleaks = -fsanitize=address -DEFINES_asan-noleaks += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 - VALID_CONFIG_asan-trace-cmp = 1 REQUIRE_CUSTOM_LIBRARIES_asan-trace-cmp = 1 CC_asan-trace-cmp = clang @@ -141,32 +113,16 @@ LDXX_dbg = $(DEFAULT_CXX) CPPFLAGS_dbg = -O0 DEFINES_dbg = _DEBUG DEBUG -VALID_CONFIG_stapprof = 1 -CC_stapprof = $(DEFAULT_CC) -CXX_stapprof = $(DEFAULT_CXX) -LD_stapprof = $(DEFAULT_CC) -LDXX_stapprof = $(DEFAULT_CXX) -CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER -DEFINES_stapprof = NDEBUG - -VALID_CONFIG_gcov = 1 -CC_gcov = gcc -CXX_gcov = g++ -LD_gcov = gcc -LDXX_gcov = g++ -CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type -LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic -DEFINES_gcov = _DEBUG DEBUG GPR_GCOV - -VALID_CONFIG_memcheck = 1 -CC_memcheck = $(DEFAULT_CC) -CXX_memcheck = $(DEFAULT_CXX) -LD_memcheck = $(DEFAULT_CC) -LDXX_memcheck = $(DEFAULT_CXX) -CPPFLAGS_memcheck = -O0 -LDFLAGS_memcheck = -rdynamic -DEFINES_memcheck = _DEBUG DEBUG -DEFINES_memcheck += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 +VALID_CONFIG_easan = 1 +REQUIRE_CUSTOM_LIBRARIES_easan = 1 +CC_easan = clang +CXX_easan = clang++ +LD_easan = clang +LDXX_easan = clang++ +CPPFLAGS_easan = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_easan = -fsanitize=address +DEFINES_easan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER +DEFINES_easan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 VALID_CONFIG_asan = 1 REQUIRE_CUSTOM_LIBRARIES_asan = 1 @@ -178,16 +134,52 @@ CPPFLAGS_asan = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame- LDFLAGS_asan = -fsanitize=address DEFINES_asan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 -VALID_CONFIG_tsan = 1 -REQUIRE_CUSTOM_LIBRARIES_tsan = 1 -CC_tsan = clang -CXX_tsan = clang++ -LD_tsan = clang -LDXX_tsan = clang++ -CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_tsan = -fsanitize=thread -DEFINES_tsan = GRPC_TSAN -DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 +VALID_CONFIG_msan = 1 +REQUIRE_CUSTOM_LIBRARIES_msan = 1 +CC_msan = clang +CXX_msan = clang++ +LD_msan = clang +LDXX_msan = clang++ +CPPFLAGS_msan = -O0 -fsanitize-coverage=edge -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +DEFINES_msan = NDEBUG +DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 + +VALID_CONFIG_basicprof = 1 +CC_basicprof = $(DEFAULT_CC) +CXX_basicprof = $(DEFAULT_CXX) +LD_basicprof = $(DEFAULT_CC) +LDXX_basicprof = $(DEFAULT_CXX) +CPPFLAGS_basicprof = -O2 -DGRPC_BASIC_PROFILER -DGRPC_TIMERS_RDTSC +DEFINES_basicprof = NDEBUG + +VALID_CONFIG_helgrind = 1 +CC_helgrind = $(DEFAULT_CC) +CXX_helgrind = $(DEFAULT_CXX) +LD_helgrind = $(DEFAULT_CC) +LDXX_helgrind = $(DEFAULT_CXX) +CPPFLAGS_helgrind = -O0 +LDFLAGS_helgrind = -rdynamic +DEFINES_helgrind = _DEBUG DEBUG +DEFINES_helgrind += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=20 + +VALID_CONFIG_asan-noleaks = 1 +REQUIRE_CUSTOM_LIBRARIES_asan-noleaks = 1 +CC_asan-noleaks = clang +CXX_asan-noleaks = clang++ +LD_asan-noleaks = clang +LDXX_asan-noleaks = clang++ +CPPFLAGS_asan-noleaks = -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_asan-noleaks = -fsanitize=address +DEFINES_asan-noleaks += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=3 + +VALID_CONFIG_edbg = 1 +CC_edbg = $(DEFAULT_CC) +CXX_edbg = $(DEFAULT_CXX) +LD_edbg = $(DEFAULT_CC) +LDXX_edbg = $(DEFAULT_CXX) +CPPFLAGS_edbg = -O0 +DEFINES_edbg = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER VALID_CONFIG_ubsan = 1 REQUIRE_CUSTOM_LIBRARIES_ubsan = 1 @@ -200,16 +192,24 @@ LDFLAGS_ubsan = -fsanitize=undefined,unsigned-integer-overflow DEFINES_ubsan = NDEBUG DEFINES_ubsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=1.5 -VALID_CONFIG_msan = 1 -REQUIRE_CUSTOM_LIBRARIES_msan = 1 -CC_msan = clang -CXX_msan = clang++ -LD_msan = clang -LDXX_msan = clang++ -CPPFLAGS_msan = -O0 -fsanitize-coverage=edge -fsanitize=memory -fsanitize-memory-track-origins -fno-omit-frame-pointer -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_msan = -fsanitize=memory -DGTEST_HAS_TR1_TUPLE=0 -DGTEST_USE_OWN_TR1_TUPLE=1 -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) -DEFINES_msan = NDEBUG -DEFINES_msan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=4 +VALID_CONFIG_tsan = 1 +REQUIRE_CUSTOM_LIBRARIES_tsan = 1 +CC_tsan = clang +CXX_tsan = clang++ +LD_tsan = clang +LDXX_tsan = clang++ +CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_tsan = -fsanitize=thread +DEFINES_tsan = GRPC_TSAN +DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 + +VALID_CONFIG_stapprof = 1 +CC_stapprof = $(DEFAULT_CC) +CXX_stapprof = $(DEFAULT_CXX) +LD_stapprof = $(DEFAULT_CC) +LDXX_stapprof = $(DEFAULT_CXX) +CPPFLAGS_stapprof = -O2 -DGRPC_STAP_PROFILER +DEFINES_stapprof = NDEBUG VALID_CONFIG_mutrace = 1 CC_mutrace = $(DEFAULT_CC) @@ -220,6 +220,36 @@ CPPFLAGS_mutrace = -O3 -fno-omit-frame-pointer LDFLAGS_mutrace = -rdynamic DEFINES_mutrace = NDEBUG +VALID_CONFIG_memcheck = 1 +CC_memcheck = $(DEFAULT_CC) +CXX_memcheck = $(DEFAULT_CXX) +LD_memcheck = $(DEFAULT_CC) +LDXX_memcheck = $(DEFAULT_CXX) +CPPFLAGS_memcheck = -O0 +LDFLAGS_memcheck = -rdynamic +DEFINES_memcheck = _DEBUG DEBUG +DEFINES_memcheck += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=10 + +VALID_CONFIG_etsan = 1 +REQUIRE_CUSTOM_LIBRARIES_etsan = 1 +CC_etsan = clang +CXX_etsan = clang++ +LD_etsan = clang +LDXX_etsan = clang++ +CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_etsan = -fsanitize=thread +DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER +DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 + +VALID_CONFIG_gcov = 1 +CC_gcov = gcc +CXX_gcov = g++ +LD_gcov = gcc +LDXX_gcov = g++ +CPPFLAGS_gcov = -O0 -fprofile-arcs -ftest-coverage -Wno-return-type +LDFLAGS_gcov = -fprofile-arcs -ftest-coverage -rdynamic +DEFINES_gcov = _DEBUG DEBUG GPR_GCOV + # General settings. @@ -914,6 +944,7 @@ census_resource_test: $(BINDIR)/$(CONFIG)/census_resource_test census_trace_context_test: $(BINDIR)/$(CONFIG)/census_trace_context_test channel_create_test: $(BINDIR)/$(CONFIG)/channel_create_test chttp2_hpack_encoder_test: $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test +chttp2_status_conversion_test: $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test chttp2_stream_map_test: $(BINDIR)/$(CONFIG)/chttp2_stream_map_test chttp2_varint_test: $(BINDIR)/$(CONFIG)/chttp2_varint_test client_fuzzer: $(BINDIR)/$(CONFIG)/client_fuzzer @@ -1021,7 +1052,6 @@ sockaddr_resolver_test: $(BINDIR)/$(CONFIG)/sockaddr_resolver_test sockaddr_utils_test: $(BINDIR)/$(CONFIG)/sockaddr_utils_test socket_utils_test: $(BINDIR)/$(CONFIG)/socket_utils_test ssl_server_fuzzer: $(BINDIR)/$(CONFIG)/ssl_server_fuzzer -status_conversion_test: $(BINDIR)/$(CONFIG)/status_conversion_test tcp_client_posix_test: $(BINDIR)/$(CONFIG)/tcp_client_posix_test tcp_posix_test: $(BINDIR)/$(CONFIG)/tcp_posix_test tcp_server_posix_test: $(BINDIR)/$(CONFIG)/tcp_server_posix_test @@ -1273,6 +1303,7 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/census_trace_context_test \ $(BINDIR)/$(CONFIG)/channel_create_test \ $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test \ + $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test \ $(BINDIR)/$(CONFIG)/chttp2_stream_map_test \ $(BINDIR)/$(CONFIG)/chttp2_varint_test \ $(BINDIR)/$(CONFIG)/combiner_test \ @@ -1362,7 +1393,6 @@ buildtests_c: privatelibs_c \ $(BINDIR)/$(CONFIG)/sockaddr_resolver_test \ $(BINDIR)/$(CONFIG)/sockaddr_utils_test \ $(BINDIR)/$(CONFIG)/socket_utils_test \ - $(BINDIR)/$(CONFIG)/status_conversion_test \ $(BINDIR)/$(CONFIG)/tcp_client_posix_test \ $(BINDIR)/$(CONFIG)/tcp_posix_test \ $(BINDIR)/$(CONFIG)/tcp_server_posix_test \ @@ -1626,6 +1656,8 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/channel_create_test || ( echo test channel_create_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_hpack_encoder_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_hpack_encoder_test || ( echo test chttp2_hpack_encoder_test failed ; exit 1 ) + $(E) "[RUN] Testing chttp2_status_conversion_test" + $(Q) $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test || ( echo test chttp2_status_conversion_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_stream_map_test" $(Q) $(BINDIR)/$(CONFIG)/chttp2_stream_map_test || ( echo test chttp2_stream_map_test failed ; exit 1 ) $(E) "[RUN] Testing chttp2_varint_test" @@ -1782,8 +1814,6 @@ test_c: buildtests_c $(Q) $(BINDIR)/$(CONFIG)/sockaddr_utils_test || ( echo test sockaddr_utils_test failed ; exit 1 ) $(E) "[RUN] Testing socket_utils_test" $(Q) $(BINDIR)/$(CONFIG)/socket_utils_test || ( echo test socket_utils_test failed ; exit 1 ) - $(E) "[RUN] Testing status_conversion_test" - $(Q) $(BINDIR)/$(CONFIG)/status_conversion_test || ( echo test status_conversion_test failed ; exit 1 ) $(E) "[RUN] Testing tcp_client_posix_test" $(Q) $(BINDIR)/$(CONFIG)/tcp_client_posix_test || ( echo test tcp_client_posix_test failed ; exit 1 ) $(E) "[RUN] Testing tcp_posix_test" @@ -2712,8 +2742,6 @@ LIBGRPC_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -2735,13 +2763,12 @@ LIBGRPC_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -2762,6 +2789,7 @@ LIBGRPC_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ + src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -3017,8 +3045,6 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -3040,13 +3066,12 @@ LIBGRPC_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3070,6 +3095,7 @@ LIBGRPC_CRONET_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ + src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -3312,8 +3338,6 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -3335,13 +3359,12 @@ LIBGRPC_TEST_UTIL_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3536,8 +3559,6 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -3559,13 +3580,12 @@ LIBGRPC_UNSECURE_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -3587,6 +3607,7 @@ LIBGRPC_UNSECURE_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ + src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -3891,7 +3912,6 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ - include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4035,6 +4055,7 @@ LIBGRPC++_CRONET_SRC = \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ + src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ @@ -4123,8 +4144,6 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -4146,13 +4165,12 @@ LIBGRPC++_CRONET_SRC = \ src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -4260,7 +4278,6 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ - include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4618,7 +4635,6 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ - include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -4799,7 +4815,6 @@ PUBLIC_HEADERS_CXX += \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ - include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ @@ -8177,6 +8192,38 @@ endif endif +CHTTP2_STATUS_CONVERSION_TEST_SRC = \ + test/core/transport/chttp2/status_conversion_test.c \ + +CHTTP2_STATUS_CONVERSION_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(CHTTP2_STATUS_CONVERSION_TEST_SRC)))) +ifeq ($(NO_SECURE),true) + +# You can't build secure targets if you don't have OpenSSL. + +$(BINDIR)/$(CONFIG)/chttp2_status_conversion_test: openssl_dep_error + +else + + + +$(BINDIR)/$(CONFIG)/chttp2_status_conversion_test: $(CHTTP2_STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + $(E) "[LD] Linking $@" + $(Q) mkdir -p `dirname $@` + $(Q) $(LD) $(LDFLAGS) $(CHTTP2_STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/chttp2_status_conversion_test + +endif + +$(OBJDIR)/$(CONFIG)/test/core/transport/chttp2/status_conversion_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a + +deps_chttp2_status_conversion_test: $(CHTTP2_STATUS_CONVERSION_TEST_OBJS:.o=.dep) + +ifneq ($(NO_SECURE),true) +ifneq ($(NO_DEPS),true) +-include $(CHTTP2_STATUS_CONVERSION_TEST_OBJS:.o=.dep) +endif +endif + + CHTTP2_STREAM_MAP_TEST_SRC = \ test/core/transport/chttp2/stream_map_test.c \ @@ -11601,38 +11648,6 @@ endif endif -STATUS_CONVERSION_TEST_SRC = \ - test/core/transport/status_conversion_test.c \ - -STATUS_CONVERSION_TEST_OBJS = $(addprefix $(OBJDIR)/$(CONFIG)/, $(addsuffix .o, $(basename $(STATUS_CONVERSION_TEST_SRC)))) -ifeq ($(NO_SECURE),true) - -# You can't build secure targets if you don't have OpenSSL. - -$(BINDIR)/$(CONFIG)/status_conversion_test: openssl_dep_error - -else - - - -$(BINDIR)/$(CONFIG)/status_conversion_test: $(STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - $(E) "[LD] Linking $@" - $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) $(STATUS_CONVERSION_TEST_OBJS) $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a $(LDLIBS) $(LDLIBS_SECURE) -o $(BINDIR)/$(CONFIG)/status_conversion_test - -endif - -$(OBJDIR)/$(CONFIG)/test/core/transport/status_conversion_test.o: $(LIBDIR)/$(CONFIG)/libgrpc_test_util.a $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr_test_util.a $(LIBDIR)/$(CONFIG)/libgpr.a - -deps_status_conversion_test: $(STATUS_CONVERSION_TEST_OBJS:.o=.dep) - -ifneq ($(NO_SECURE),true) -ifneq ($(NO_DEPS),true) --include $(STATUS_CONVERSION_TEST_OBJS:.o=.dep) -endif -endif - - TCP_CLIENT_POSIX_TEST_SRC = \ test/core/iomgr/tcp_client_posix_test.c \ diff --git a/binding.gyp b/binding.gyp index 54958dbf4fa..6c82028dbd3 100644 --- a/binding.gyp +++ b/binding.gyp @@ -686,8 +686,6 @@ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', - 'src/core/lib/slice/slice_hash_table.c', - 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', @@ -709,13 +707,12 @@ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/error_utils.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/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', - 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -736,6 +733,7 @@ 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', + 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', @@ -883,7 +881,6 @@ "src/node/ext/node_grpc.cc", "src/node/ext/server.cc", "src/node/ext/server_credentials.cc", - "src/node/ext/slice.cc", "src/node/ext/timeval.cc", ], "dependencies": [ diff --git a/build.yaml b/build.yaml index 7b3e64e9bb4..23e2659ea1e 100644 --- a/build.yaml +++ b/build.yaml @@ -188,7 +188,6 @@ filegroups: - src/core/lib/iomgr/endpoint.h - src/core/lib/iomgr/endpoint_pair.h - src/core/lib/iomgr/error.h - - src/core/lib/iomgr/error_internal.h - src/core/lib/iomgr/ev_epoll_linux.h - src/core/lib/iomgr/ev_poll_posix.h - src/core/lib/iomgr/ev_posix.h @@ -241,7 +240,6 @@ filegroups: - src/core/lib/json/json_reader.h - src/core/lib/json/json_writer.h - src/core/lib/slice/percent_encoding.h - - src/core/lib/slice/slice_hash_table.h - src/core/lib/slice/slice_internal.h - src/core/lib/slice/slice_string_helpers.h - src/core/lib/surface/api_trace.h @@ -255,17 +253,14 @@ filegroups: - src/core/lib/surface/init.h - src/core/lib/surface/lame_client.h - src/core/lib/surface/server.h - - src/core/lib/surface/validate_metadata.h - src/core/lib/transport/byte_stream.h - src/core/lib/transport/connectivity_state.h - - src/core/lib/transport/error_utils.h - - src/core/lib/transport/http2_errors.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/pid_controller.h - src/core/lib/transport/service_config.h - src/core/lib/transport/static_metadata.h - - src/core/lib/transport/status_conversion.h - src/core/lib/transport/timeout_encoding.h - src/core/lib/transport/transport.h - src/core/lib/transport/transport_impl.h @@ -354,8 +349,6 @@ filegroups: - src/core/lib/slice/percent_encoding.c - src/core/lib/slice/slice.c - src/core/lib/slice/slice_buffer.c - - src/core/lib/slice/slice_hash_table.c - - src/core/lib/slice/slice_intern.c - src/core/lib/slice/slice_string_helpers.c - src/core/lib/surface/alarm.c - src/core/lib/surface/api_trace.c @@ -377,13 +370,12 @@ filegroups: - src/core/lib/surface/version.c - src/core/lib/transport/byte_stream.c - src/core/lib/transport/connectivity_state.c - - src/core/lib/transport/error_utils.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/pid_controller.c - src/core/lib/transport/service_config.c - src/core/lib/transport/static_metadata.c - - src/core/lib/transport/status_conversion.c - src/core/lib/transport/timeout_encoding.c - src/core/lib/transport/transport.c - src/core/lib/transport/transport_op_string.c @@ -596,9 +588,11 @@ filegroups: - src/core/ext/transport/chttp2/transport/hpack_encoder.h - src/core/ext/transport/chttp2/transport/hpack_parser.h - src/core/ext/transport/chttp2/transport/hpack_table.h + - src/core/ext/transport/chttp2/transport/http2_errors.h - src/core/ext/transport/chttp2/transport/huffsyms.h - src/core/ext/transport/chttp2/transport/incoming_metadata.h - src/core/ext/transport/chttp2/transport/internal.h + - src/core/ext/transport/chttp2/transport/status_conversion.h - src/core/ext/transport/chttp2/transport/stream_map.h - src/core/ext/transport/chttp2/transport/varint.h src: @@ -618,6 +612,7 @@ filegroups: - src/core/ext/transport/chttp2/transport/huffsyms.c - src/core/ext/transport/chttp2/transport/incoming_metadata.c - src/core/ext/transport/chttp2/transport/parsing.c + - src/core/ext/transport/chttp2/transport/status_conversion.c - src/core/ext/transport/chttp2/transport/stream_lists.c - src/core/ext/transport/chttp2/transport/stream_map.c - src/core/ext/transport/chttp2/transport/varint.c @@ -827,7 +822,6 @@ filegroups: - include/grpc++/impl/codegen/server_context.h - include/grpc++/impl/codegen/server_interface.h - include/grpc++/impl/codegen/service_type.h - - include/grpc++/impl/codegen/slice.h - include/grpc++/impl/codegen/status.h - include/grpc++/impl/codegen/status_code_enum.h - include/grpc++/impl/codegen/status_helper.h @@ -1499,6 +1493,16 @@ targets: - grpc - gpr_test_util - gpr +- name: chttp2_status_conversion_test + build: test + language: c + src: + - test/core/transport/chttp2/status_conversion_test.c + deps: + - grpc_test_util + - grpc + - gpr_test_util + - gpr - name: chttp2_stream_map_test build: test language: c @@ -2667,16 +2671,6 @@ targets: corpus_dirs: - test/core/security/corpus/ssl_server_corpus maxlen: 2048 -- name: status_conversion_test - build: test - language: c - src: - - test/core/transport/status_conversion_test.c - deps: - - grpc_test_util - - grpc - - gpr_test_util - - gpr - name: tcp_client_posix_test cpu_cost: 0.5 build: test @@ -3768,6 +3762,36 @@ configs: dbg: CPPFLAGS: -O0 DEFINES: _DEBUG DEBUG + easan: + CC: clang + CPPFLAGS: -O0 -fsanitize-coverage=edge -fsanitize=address -fno-omit-frame-pointer + -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS + CXX: clang++ + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + LD: clang + LDFLAGS: -fsanitize=address + LDXX: clang++ + compile_the_world: true + test_environ: + ASAN_OPTIONS: detect_leaks=1:color=always + LSAN_OPTIONS: suppressions=tools/lsan_suppressions.txt:report_objects=1 + timeout_multiplier: 3 + edbg: + CPPFLAGS: -O0 + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + etsan: + CC: clang + CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument + -DGPR_NO_DIRECT_SYSCALLS + CXX: clang++ + DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER + LD: clang + LDFLAGS: -fsanitize=thread + LDXX: clang++ + compile_the_world: true + test_environ: + TSAN_OPTIONS: suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1 + timeout_multiplier: 5 gcov: CC: gcc CPPFLAGS: -O0 -fprofile-arcs -ftest-coverage -Wno-return-type @@ -3866,7 +3890,6 @@ node_modules: - src/node/ext/completion_queue.h - src/node/ext/server.h - src/node/ext/server_credentials.h - - src/node/ext/slice.h - src/node/ext/timeval.h js: - src/node/index.js @@ -3888,7 +3911,6 @@ node_modules: - src/node/ext/node_grpc.cc - src/node/ext/server.cc - src/node/ext/server_credentials.cc - - src/node/ext/slice.cc - src/node/ext/timeval.cc openssl_fallback: base_uri: https://openssl.org/source/old/1.0.2/ diff --git a/config.m4 b/config.m4 index e9f02523cdf..621bbb36d5d 100644 --- a/config.m4 +++ b/config.m4 @@ -165,8 +165,6 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ - src/core/lib/slice/slice_hash_table.c \ - src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/surface/alarm.c \ src/core/lib/surface/api_trace.c \ @@ -188,13 +186,12 @@ if test "$PHP_GRPC" != "no"; then src/core/lib/surface/version.c \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/connectivity_state.c \ - src/core/lib/transport/error_utils.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/pid_controller.c \ src/core/lib/transport/service_config.c \ src/core/lib/transport/static_metadata.c \ - src/core/lib/transport/status_conversion.c \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/transport.c \ src/core/lib/transport/transport_op_string.c \ @@ -215,6 +212,7 @@ if test "$PHP_GRPC" != "no"; then src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/parsing.c \ + src/core/ext/transport/chttp2/transport/status_conversion.c \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/varint.c \ diff --git a/gRPC-Core.podspec b/gRPC-Core.podspec index f15fcc77823..1eb178931dc 100644 --- a/gRPC-Core.podspec +++ b/gRPC-Core.podspec @@ -274,7 +274,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/endpoint.h', 'src/core/lib/iomgr/endpoint_pair.h', 'src/core/lib/iomgr/error.h', - 'src/core/lib/iomgr/error_internal.h', 'src/core/lib/iomgr/ev_epoll_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', @@ -327,7 +326,6 @@ Pod::Spec.new do |s| 'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_writer.h', 'src/core/lib/slice/percent_encoding.h', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/surface/api_trace.h', @@ -341,17 +339,14 @@ Pod::Spec.new do |s| 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', - 'src/core/lib/surface/validate_metadata.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', - 'src/core/lib/transport/error_utils.h', - 'src/core/lib/transport/http2_errors.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/pid_controller.h', 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', - 'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', @@ -368,9 +363,11 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/hpack_encoder.h', 'src/core/ext/transport/chttp2/transport/hpack_parser.h', 'src/core/ext/transport/chttp2/transport/hpack_table.h', + 'src/core/ext/transport/chttp2/transport/http2_errors.h', 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/incoming_metadata.h', 'src/core/ext/transport/chttp2/transport/internal.h', + 'src/core/ext/transport/chttp2/transport/status_conversion.h', 'src/core/ext/transport/chttp2/transport/stream_map.h', 'src/core/ext/transport/chttp2/transport/varint.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', @@ -520,8 +517,6 @@ Pod::Spec.new do |s| 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', - 'src/core/lib/slice/slice_hash_table.c', - 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', @@ -543,13 +538,12 @@ Pod::Spec.new do |s| 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/error_utils.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/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', - 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -570,6 +564,7 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', + 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', @@ -691,7 +686,6 @@ Pod::Spec.new do |s| 'src/core/lib/iomgr/endpoint.h', 'src/core/lib/iomgr/endpoint_pair.h', 'src/core/lib/iomgr/error.h', - 'src/core/lib/iomgr/error_internal.h', 'src/core/lib/iomgr/ev_epoll_linux.h', 'src/core/lib/iomgr/ev_poll_posix.h', 'src/core/lib/iomgr/ev_posix.h', @@ -744,7 +738,6 @@ Pod::Spec.new do |s| 'src/core/lib/json/json_reader.h', 'src/core/lib/json/json_writer.h', 'src/core/lib/slice/percent_encoding.h', - 'src/core/lib/slice/slice_hash_table.h', 'src/core/lib/slice/slice_internal.h', 'src/core/lib/slice/slice_string_helpers.h', 'src/core/lib/surface/api_trace.h', @@ -758,17 +751,14 @@ Pod::Spec.new do |s| 'src/core/lib/surface/init.h', 'src/core/lib/surface/lame_client.h', 'src/core/lib/surface/server.h', - 'src/core/lib/surface/validate_metadata.h', 'src/core/lib/transport/byte_stream.h', 'src/core/lib/transport/connectivity_state.h', - 'src/core/lib/transport/error_utils.h', - 'src/core/lib/transport/http2_errors.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/pid_controller.h', 'src/core/lib/transport/service_config.h', 'src/core/lib/transport/static_metadata.h', - 'src/core/lib/transport/status_conversion.h', 'src/core/lib/transport/timeout_encoding.h', 'src/core/lib/transport/transport.h', 'src/core/lib/transport/transport_impl.h', @@ -785,9 +775,11 @@ Pod::Spec.new do |s| 'src/core/ext/transport/chttp2/transport/hpack_encoder.h', 'src/core/ext/transport/chttp2/transport/hpack_parser.h', 'src/core/ext/transport/chttp2/transport/hpack_table.h', + 'src/core/ext/transport/chttp2/transport/http2_errors.h', 'src/core/ext/transport/chttp2/transport/huffsyms.h', 'src/core/ext/transport/chttp2/transport/incoming_metadata.h', 'src/core/ext/transport/chttp2/transport/internal.h', + 'src/core/ext/transport/chttp2/transport/status_conversion.h', 'src/core/ext/transport/chttp2/transport/stream_map.h', 'src/core/ext/transport/chttp2/transport/varint.h', 'src/core/ext/transport/chttp2/alpn/alpn.h', diff --git a/grpc.def b/grpc.def index 5b2b679708a..01628638ef5 100644 --- a/grpc.def +++ b/grpc.def @@ -141,30 +141,17 @@ EXPORTS grpc_slice_new_with_user_data grpc_slice_new_with_len grpc_slice_malloc - grpc_slice_intern grpc_slice_from_copied_string grpc_slice_from_copied_buffer grpc_slice_from_static_string - grpc_slice_from_static_buffer grpc_slice_sub grpc_slice_sub_no_ref grpc_slice_split_tail grpc_slice_split_head - grpc_empty_slice - grpc_slice_default_hash_impl - grpc_slice_default_eq_impl - grpc_slice_eq + gpr_empty_slice grpc_slice_cmp grpc_slice_str_cmp - grpc_slice_buf_cmp - grpc_slice_buf_start_eq - grpc_slice_rchr - grpc_slice_chr - grpc_slice_slice - grpc_slice_hash grpc_slice_is_equivalent - grpc_slice_dup - grpc_slice_to_c_string grpc_slice_buffer_init grpc_slice_buffer_destroy grpc_slice_buffer_add diff --git a/grpc.gemspec b/grpc.gemspec index a85be4e7850..356851521d2 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -191,7 +191,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/iomgr/endpoint.h ) s.files += %w( src/core/lib/iomgr/endpoint_pair.h ) s.files += %w( src/core/lib/iomgr/error.h ) - s.files += %w( src/core/lib/iomgr/error_internal.h ) s.files += %w( src/core/lib/iomgr/ev_epoll_linux.h ) s.files += %w( src/core/lib/iomgr/ev_poll_posix.h ) s.files += %w( src/core/lib/iomgr/ev_posix.h ) @@ -244,7 +243,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/json/json_reader.h ) s.files += %w( src/core/lib/json/json_writer.h ) s.files += %w( src/core/lib/slice/percent_encoding.h ) - s.files += %w( src/core/lib/slice/slice_hash_table.h ) s.files += %w( src/core/lib/slice/slice_internal.h ) s.files += %w( src/core/lib/slice/slice_string_helpers.h ) s.files += %w( src/core/lib/surface/api_trace.h ) @@ -258,17 +256,14 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/init.h ) s.files += %w( src/core/lib/surface/lame_client.h ) s.files += %w( src/core/lib/surface/server.h ) - s.files += %w( src/core/lib/surface/validate_metadata.h ) s.files += %w( src/core/lib/transport/byte_stream.h ) s.files += %w( src/core/lib/transport/connectivity_state.h ) - s.files += %w( src/core/lib/transport/error_utils.h ) - s.files += %w( src/core/lib/transport/http2_errors.h ) + 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/pid_controller.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/status_conversion.h ) s.files += %w( src/core/lib/transport/timeout_encoding.h ) s.files += %w( src/core/lib/transport/transport.h ) s.files += %w( src/core/lib/transport/transport_impl.h ) @@ -285,9 +280,11 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/transport/hpack_encoder.h ) s.files += %w( src/core/ext/transport/chttp2/transport/hpack_parser.h ) s.files += %w( src/core/ext/transport/chttp2/transport/hpack_table.h ) + s.files += %w( src/core/ext/transport/chttp2/transport/http2_errors.h ) s.files += %w( src/core/ext/transport/chttp2/transport/huffsyms.h ) s.files += %w( src/core/ext/transport/chttp2/transport/incoming_metadata.h ) s.files += %w( src/core/ext/transport/chttp2/transport/internal.h ) + s.files += %w( src/core/ext/transport/chttp2/transport/status_conversion.h ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_map.h ) s.files += %w( src/core/ext/transport/chttp2/transport/varint.h ) s.files += %w( src/core/ext/transport/chttp2/alpn/alpn.h ) @@ -437,8 +434,6 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/slice/percent_encoding.c ) s.files += %w( src/core/lib/slice/slice.c ) s.files += %w( src/core/lib/slice/slice_buffer.c ) - s.files += %w( src/core/lib/slice/slice_hash_table.c ) - s.files += %w( src/core/lib/slice/slice_intern.c ) s.files += %w( src/core/lib/slice/slice_string_helpers.c ) s.files += %w( src/core/lib/surface/alarm.c ) s.files += %w( src/core/lib/surface/api_trace.c ) @@ -460,13 +455,12 @@ Gem::Specification.new do |s| s.files += %w( src/core/lib/surface/version.c ) s.files += %w( src/core/lib/transport/byte_stream.c ) s.files += %w( src/core/lib/transport/connectivity_state.c ) - s.files += %w( src/core/lib/transport/error_utils.c ) + 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/pid_controller.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/status_conversion.c ) s.files += %w( src/core/lib/transport/timeout_encoding.c ) s.files += %w( src/core/lib/transport/transport.c ) s.files += %w( src/core/lib/transport/transport_op_string.c ) @@ -487,6 +481,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/ext/transport/chttp2/transport/huffsyms.c ) s.files += %w( src/core/ext/transport/chttp2/transport/incoming_metadata.c ) s.files += %w( src/core/ext/transport/chttp2/transport/parsing.c ) + s.files += %w( src/core/ext/transport/chttp2/transport/status_conversion.c ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_lists.c ) s.files += %w( src/core/ext/transport/chttp2/transport/stream_map.c ) s.files += %w( src/core/ext/transport/chttp2/transport/varint.c ) diff --git a/include/grpc++/impl/codegen/call.h b/include/grpc++/impl/codegen/call.h index dd6c83a14ae..6ab00612f6e 100644 --- a/include/grpc++/impl/codegen/call.h +++ b/include/grpc++/impl/codegen/call.h @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -63,6 +62,19 @@ class CallHook; class CompletionQueue; extern CoreCodegenInterface* g_core_codegen_interface; +inline void FillMetadataMap( + grpc_metadata_array* arr, + std::multimap* metadata) { + for (size_t i = 0; i < arr->count; i++) { + // TODO(yangg) handle duplicates? + metadata->insert(std::pair( + arr->metadata[i].key, grpc::string_ref(arr->metadata[i].value, + arr->metadata[i].value_length))); + } + g_core_codegen_interface->grpc_metadata_array_destroy(arr); + g_core_codegen_interface->grpc_metadata_array_init(arr); +} + // TODO(yangg) if the map is changed before we send, the pointers will be a // mess. Make sure it does not happen. inline grpc_metadata* FillMetadataArray( @@ -75,8 +87,9 @@ inline grpc_metadata* FillMetadataArray( metadata.size() * sizeof(grpc_metadata))); size_t i = 0; for (auto iter = metadata.cbegin(); iter != metadata.cend(); ++iter, ++i) { - metadata_array[i].key = SliceReferencingString(iter->first); - metadata_array[i].value = SliceReferencingString(iter->second); + metadata_array[i].key = iter->first.c_str(); + metadata_array[i].value = iter->second.c_str(); + metadata_array[i].value_length = iter->second.size(); } return metadata_array; } @@ -438,9 +451,8 @@ class CallOpServerSendStatus { trailing_metadata_count_; op->data.send_status_from_server.trailing_metadata = trailing_metadata_; op->data.send_status_from_server.status = send_status_code_; - status_details_slice_ = SliceReferencingString(send_status_details_); op->data.send_status_from_server.status_details = - send_status_details_.empty() ? nullptr : &status_details_slice_; + send_status_details_.empty() ? nullptr : send_status_details_.c_str(); op->flags = 0; op->reserved = NULL; } @@ -457,35 +469,36 @@ class CallOpServerSendStatus { grpc::string send_status_details_; size_t trailing_metadata_count_; grpc_metadata* trailing_metadata_; - grpc_slice status_details_slice_; }; class CallOpRecvInitialMetadata { public: - CallOpRecvInitialMetadata() : metadata_map_(nullptr) {} + CallOpRecvInitialMetadata() : recv_initial_metadata_(nullptr) {} void RecvInitialMetadata(ClientContext* context) { context->initial_metadata_received_ = true; - metadata_map_ = &context->recv_initial_metadata_; + recv_initial_metadata_ = &context->recv_initial_metadata_; } protected: void AddOp(grpc_op* ops, size_t* nops) { - if (metadata_map_ == nullptr) return; + if (!recv_initial_metadata_) return; + memset(&recv_initial_metadata_arr_, 0, sizeof(recv_initial_metadata_arr_)); grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_INITIAL_METADATA; - op->data.recv_initial_metadata = metadata_map_->arr(); + op->data.recv_initial_metadata = &recv_initial_metadata_arr_; op->flags = 0; op->reserved = NULL; } void FinishOp(bool* status, int max_receive_message_size) { - if (metadata_map_ == nullptr) return; - metadata_map_->FillMap(); - metadata_map_ = nullptr; + if (recv_initial_metadata_ == nullptr) return; + FillMetadataMap(&recv_initial_metadata_arr_, recv_initial_metadata_); + recv_initial_metadata_ = nullptr; } private: - MetadataMap* metadata_map_; + std::multimap* recv_initial_metadata_; + grpc_metadata_array recv_initial_metadata_arr_; }; class CallOpClientRecvStatus { @@ -493,37 +506,46 @@ class CallOpClientRecvStatus { CallOpClientRecvStatus() : recv_status_(nullptr) {} void ClientRecvStatus(ClientContext* context, Status* status) { - metadata_map_ = &context->trailing_metadata_; + recv_trailing_metadata_ = &context->trailing_metadata_; recv_status_ = status; } protected: void AddOp(grpc_op* ops, size_t* nops) { if (recv_status_ == nullptr) return; + memset(&recv_trailing_metadata_arr_, 0, + sizeof(recv_trailing_metadata_arr_)); + status_details_ = nullptr; + status_details_capacity_ = 0; grpc_op* op = &ops[(*nops)++]; op->op = GRPC_OP_RECV_STATUS_ON_CLIENT; - op->data.recv_status_on_client.trailing_metadata = metadata_map_->arr(); + op->data.recv_status_on_client.trailing_metadata = + &recv_trailing_metadata_arr_; op->data.recv_status_on_client.status = &status_code_; op->data.recv_status_on_client.status_details = &status_details_; + op->data.recv_status_on_client.status_details_capacity = + &status_details_capacity_; op->flags = 0; op->reserved = NULL; } void FinishOp(bool* status, int max_receive_message_size) { if (recv_status_ == nullptr) return; - metadata_map_->FillMap(); - *recv_status_ = Status(static_cast(status_code_), - grpc::string(GRPC_SLICE_START_PTR(status_details_), - GRPC_SLICE_END_PTR(status_details_))); - g_core_codegen_interface->grpc_slice_unref(status_details_); + FillMetadataMap(&recv_trailing_metadata_arr_, recv_trailing_metadata_); + *recv_status_ = Status( + static_cast(status_code_), + status_details_ ? grpc::string(status_details_) : grpc::string()); + g_core_codegen_interface->gpr_free(status_details_); recv_status_ = nullptr; } private: - MetadataMap* metadata_map_; + std::multimap* recv_trailing_metadata_; Status* recv_status_; + grpc_metadata_array recv_trailing_metadata_arr_; grpc_status_code status_code_; - grpc_slice status_details_; + char* status_details_; + size_t status_details_capacity_; }; /// An abstract collection of CallOpSet's, to be used whenever diff --git a/include/grpc++/impl/codegen/client_context.h b/include/grpc++/impl/codegen/client_context.h index b91c7f65d43..777b2f8847f 100644 --- a/include/grpc++/impl/codegen/client_context.h +++ b/include/grpc++/impl/codegen/client_context.h @@ -57,9 +57,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -195,7 +193,7 @@ class ClientContext { const std::multimap& GetServerInitialMetadata() const { GPR_CODEGEN_ASSERT(initial_metadata_received_); - return *recv_initial_metadata_.map(); + return recv_initial_metadata_; } /// Return a collection of trailing metadata key-value pairs. Note that keys @@ -207,7 +205,7 @@ class ClientContext { const std::multimap& GetServerTrailingMetadata() const { // TODO(yangg) check finished - return *trailing_metadata_.map(); + return trailing_metadata_; } /// Set the deadline for the client call. @@ -377,8 +375,8 @@ class ClientContext { mutable std::shared_ptr auth_context_; struct census_context* census_context_; std::multimap send_initial_metadata_; - MetadataMap recv_initial_metadata_; - MetadataMap trailing_metadata_; + std::multimap recv_initial_metadata_; + std::multimap trailing_metadata_; grpc_call* propagate_from_call_; PropagationOptions propagation_options_; diff --git a/include/grpc++/impl/codegen/client_unary_call.h b/include/grpc++/impl/codegen/client_unary_call.h index 201e52ae073..70d65549c80 100644 --- a/include/grpc++/impl/codegen/client_unary_call.h +++ b/include/grpc++/impl/codegen/client_unary_call.h @@ -69,14 +69,7 @@ Status BlockingUnaryCall(ChannelInterface* channel, const RpcMethod& method, ops.ClientSendClose(); ops.ClientRecvStatus(context, &status); call.PerformOps(&ops); - if (cq.Pluck(&ops)) { - if (!ops.got_message && status.ok()) { - return Status(StatusCode::UNIMPLEMENTED, - "No message returned for unary request"); - } - } else { - GPR_CODEGEN_ASSERT(!status.ok()); - } + GPR_CODEGEN_ASSERT((cq.Pluck(&ops) && ops.got_message) || !status.ok()); return status; } diff --git a/include/grpc++/impl/codegen/core_codegen.h b/include/grpc++/impl/codegen/core_codegen.h index 754bf14b259..6b5e637e4e2 100644 --- a/include/grpc++/impl/codegen/core_codegen.h +++ b/include/grpc++/impl/codegen/core_codegen.h @@ -81,10 +81,7 @@ class CoreCodegen : public CoreCodegenInterface { grpc_slice grpc_slice_split_tail(grpc_slice* s, size_t split) override; void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) override; void grpc_slice_buffer_pop(grpc_slice_buffer* sb) override; - grpc_slice grpc_slice_from_static_buffer(const void* buffer, - size_t length) override; - grpc_slice grpc_slice_from_copied_buffer(const void* buffer, - size_t length) override; + void grpc_metadata_array_init(grpc_metadata_array* array) override; void grpc_metadata_array_destroy(grpc_metadata_array* array) override; @@ -94,8 +91,7 @@ class CoreCodegen : public CoreCodegenInterface { virtual const Status& ok() override; virtual const Status& cancelled() override; - void assert_fail(const char* failed_assertion, const char* file, - int line) override; + void assert_fail(const char* failed_assertion) override; }; } // namespace grpc diff --git a/include/grpc++/impl/codegen/core_codegen_interface.h b/include/grpc++/impl/codegen/core_codegen_interface.h index 45ea0403031..4783a43454f 100644 --- a/include/grpc++/impl/codegen/core_codegen_interface.h +++ b/include/grpc++/impl/codegen/core_codegen_interface.h @@ -56,8 +56,7 @@ namespace grpc { class CoreCodegenInterface { public: /// Upon a failed assertion, log the error. - virtual void assert_fail(const char* failed_assertion, const char* file, - int line) = 0; + virtual void assert_fail(const char* failed_assertion) = 0; virtual grpc_completion_queue* grpc_completion_queue_create( void* reserved) = 0; @@ -100,10 +99,6 @@ class CoreCodegenInterface { virtual void grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) = 0; virtual void grpc_slice_buffer_pop(grpc_slice_buffer* sb) = 0; - virtual grpc_slice grpc_slice_from_static_buffer(const void* buffer, - size_t length) = 0; - virtual grpc_slice grpc_slice_from_copied_buffer(const void* buffer, - size_t length) = 0; virtual void grpc_metadata_array_init(grpc_metadata_array* array) = 0; virtual void grpc_metadata_array_destroy(grpc_metadata_array* array) = 0; @@ -118,11 +113,11 @@ class CoreCodegenInterface { extern CoreCodegenInterface* g_core_codegen_interface; /// Codegen specific version of \a GPR_ASSERT. -#define GPR_CODEGEN_ASSERT(x) \ - do { \ - if (!(x)) { \ - grpc::g_core_codegen_interface->assert_fail(#x, __FILE__, __LINE__); \ - } \ +#define GPR_CODEGEN_ASSERT(x) \ + do { \ + if (!(x)) { \ + grpc::g_core_codegen_interface->assert_fail(#x); \ + } \ } while (0) } // namespace grpc diff --git a/include/grpc++/impl/codegen/metadata_map.h b/include/grpc++/impl/codegen/metadata_map.h deleted file mode 100644 index 53b9d62f9f9..00000000000 --- a/include/grpc++/impl/codegen/metadata_map.h +++ /dev/null @@ -1,71 +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. -* -*/ - -#ifndef GRPCXX_IMPL_CODEGEN_METADATA_MAP_H -#define GRPCXX_IMPL_CODEGEN_METADATA_MAP_H - -#include - -namespace grpc { - -class MetadataMap { - public: - MetadataMap() { memset(&arr_, 0, sizeof(arr_)); } - - ~MetadataMap() { - g_core_codegen_interface->grpc_metadata_array_destroy(&arr_); - } - - void FillMap() { - for (size_t i = 0; i < arr_.count; i++) { - // TODO(yangg) handle duplicates? - map_.insert(std::pair( - StringRefFromSlice(&arr_.metadata[i].key), - StringRefFromSlice(&arr_.metadata[i].value))); - } - } - - std::multimap *map() { return &map_; } - const std::multimap *map() const { - return &map_; - } - grpc_metadata_array *arr() { return &arr_; } - - private: - grpc_metadata_array arr_; - std::multimap map_; -}; - -} // namespace grpc - -#endif // GRPCXX_IMPL_CODEGEN_METADATA_MAP_H diff --git a/include/grpc++/impl/codegen/server_context.h b/include/grpc++/impl/codegen/server_context.h index 8c7fe0809ea..dd305763796 100644 --- a/include/grpc++/impl/codegen/server_context.h +++ b/include/grpc++/impl/codegen/server_context.h @@ -39,7 +39,6 @@ #include #include -#include #include #include #include @@ -124,7 +123,7 @@ class ServerContext { const std::multimap& client_metadata() const { - return *client_metadata_.map(); + return client_metadata_; } grpc_compression_level compression_level() const { @@ -224,7 +223,7 @@ class ServerContext { CompletionQueue* cq_; bool sent_initial_metadata_; mutable std::shared_ptr auth_context_; - MetadataMap client_metadata_; + std::multimap client_metadata_; std::multimap initial_metadata_; std::multimap trailing_metadata_; diff --git a/include/grpc++/impl/codegen/server_interface.h b/include/grpc++/impl/codegen/server_interface.h index af1bf6fa6f7..666b9ff66eb 100644 --- a/include/grpc++/impl/codegen/server_interface.h +++ b/include/grpc++/impl/codegen/server_interface.h @@ -152,6 +152,7 @@ class ServerInterface : public CallHook { void* const tag_; const bool delete_on_finalize_; grpc_call* call_; + grpc_metadata_array initial_metadata_array_; }; class RegisteredAsyncRequest : public BaseAsyncRequest { diff --git a/include/grpc++/impl/codegen/slice.h b/include/grpc++/impl/codegen/slice.h deleted file mode 100644 index 04b2f9af016..00000000000 --- a/include/grpc++/impl/codegen/slice.h +++ /dev/null @@ -1,65 +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. - * - */ - -#ifndef GRPCXX_IMPL_CODEGEN_SLICE_H -#define GRPCXX_IMPL_CODEGEN_SLICE_H - -#include -#include - -namespace grpc { - -inline grpc::string_ref StringRefFromSlice(const grpc_slice* slice) { - return grpc::string_ref( - reinterpret_cast(GRPC_SLICE_START_PTR(*slice)), - GRPC_SLICE_LENGTH(*slice)); -} - -inline grpc::string StringFromCopiedSlice(grpc_slice slice) { - return grpc::string(reinterpret_cast(GRPC_SLICE_START_PTR(slice)), - GRPC_SLICE_LENGTH(slice)); -} - -inline grpc_slice SliceReferencingString(const grpc::string& str) { - return g_core_codegen_interface->grpc_slice_from_static_buffer(str.data(), - str.length()); -} - -inline grpc_slice SliceFromCopiedString(const grpc::string& str) { - return g_core_codegen_interface->grpc_slice_from_copied_buffer(str.data(), - str.length()); -} - -} // namespace grpc - -#endif // GRPCXX_IMPL_CODEGEN_SLICE_H diff --git a/include/grpc/compression.h b/include/grpc/compression.h index 659d6fe7582..5f285cdcdf4 100644 --- a/include/grpc/compression.h +++ b/include/grpc/compression.h @@ -34,12 +34,11 @@ #ifndef GRPC_COMPRESSION_H #define GRPC_COMPRESSION_H -#include - #include +#include + #include -#include #ifdef __cplusplus extern "C" { @@ -49,7 +48,8 @@ extern "C" { * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon * success, 0 otherwise. */ GRPCAPI int grpc_compression_algorithm_parse( - grpc_slice value, grpc_compression_algorithm *algorithm); + const char *name, size_t name_length, + grpc_compression_algorithm *algorithm); /** Updates \a name with the encoding name corresponding to a valid \a * algorithm. Note that \a name is statically allocated and must *not* be freed. diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 37b823ae1e9..898f4d533bc 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -178,8 +178,8 @@ GRPCAPI void grpc_channel_watch_connectivity_state( possible values). */ GRPCAPI grpc_call *grpc_channel_create_call( grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_completion_queue *completion_queue, grpc_slice method, - const grpc_slice *host, gpr_timespec deadline, void *reserved); + grpc_completion_queue *completion_queue, const char *method, + const char *host, gpr_timespec deadline, void *reserved); /** Ping the channels peer (load balanced channels will select one sub-channel to ping); if the channel is not connected, posts a failed. */ @@ -402,14 +402,14 @@ GRPCAPI void grpc_server_destroy(grpc_server *server); GRPCAPI int grpc_tracer_set_enabled(const char *name, int enabled); /** Check whether a metadata key is legal (will be accepted by core) */ -GRPCAPI int grpc_header_key_is_legal(grpc_slice slice); +GRPCAPI int grpc_header_key_is_legal(const char *key, size_t length); /** Check whether a non-binary metadata value is legal (will be accepted by core) */ -GRPCAPI int grpc_header_nonbin_value_is_legal(grpc_slice slice); +GRPCAPI int grpc_header_nonbin_value_is_legal(const char *value, size_t length); /** Check whether a metadata key corresponds to a binary value */ -GRPCAPI int grpc_is_binary_header(grpc_slice slice); +GRPCAPI int grpc_is_binary_header(const char *key, size_t length); /** Convert grpc_call_error values to a string */ GRPCAPI const char *grpc_call_error_to_string(grpc_call_error error); diff --git a/include/grpc/impl/codegen/grpc_types.h b/include/grpc/impl/codegen/grpc_types.h index 8efd570bad9..ee8101aab8d 100644 --- a/include/grpc/impl/codegen/grpc_types.h +++ b/include/grpc/impl/codegen/grpc_types.h @@ -294,11 +294,9 @@ typedef enum grpc_call_error { /** A single metadata element */ typedef struct grpc_metadata { - /* the key, value values are expected to line up with grpc_mdelem: if changing - them, update metadata.h at the same time. */ - grpc_slice key; - grpc_slice value; - + const char *key; + const char *value; + size_t value_length; uint32_t flags; /** The following fields are reserved for grpc internal use. @@ -340,8 +338,10 @@ typedef struct { } grpc_metadata_array; typedef struct { - grpc_slice method; - grpc_slice host; + char *method; + size_t method_capacity; + char *host; + size_t host_capacity; gpr_timespec deadline; uint32_t flags; void *reserved; @@ -423,10 +423,7 @@ typedef struct grpc_op { size_t trailing_metadata_count; grpc_metadata *trailing_metadata; grpc_status_code status; - /* optional: set to NULL if no details need sending, non-NULL if they do - * pointer will not be retained past the start_batch call - */ - grpc_slice *status_details; + const char *status_details; } send_status_from_server; /** ownership of the array is with the caller, but ownership of the elements stays with the call object (ie key, value members are owned by the call @@ -447,7 +444,28 @@ typedef struct grpc_op { value, or reuse it in a future op. */ grpc_metadata_array *trailing_metadata; grpc_status_code *status; - grpc_slice *status_details; + /** status_details is a buffer owned by the application before the op + completes and after the op has completed. During the operation + status_details may be reallocated to a size larger than + *status_details_capacity, in which case *status_details_capacity will + be updated with the new array capacity. + + Pre-allocating space: + size_t my_capacity = 8; + char *my_details = gpr_malloc(my_capacity); + x.status_details = &my_details; + x.status_details_capacity = &my_capacity; + + Not pre-allocating space: + size_t my_capacity = 0; + char *my_details = NULL; + x.status_details = &my_details; + x.status_details_capacity = &my_capacity; + + After the call: + gpr_free(my_details); */ + char **status_details; + size_t *status_details_capacity; } recv_status_on_client; struct { /** out argument, set to 1 if the call failed in any way (seen as a diff --git a/include/grpc/impl/codegen/slice.h b/include/grpc/impl/codegen/slice.h index 3c9c7b02855..00781bb76bd 100644 --- a/include/grpc/impl/codegen/slice.h +++ b/include/grpc/impl/codegen/slice.h @@ -40,8 +40,6 @@ #include #include -typedef struct grpc_slice grpc_slice; - /* Slice API A slice represents a contiguous reference counted array of bytes. @@ -55,25 +53,14 @@ typedef struct grpc_slice grpc_slice; reference ownership semantics (who should call unref?) and mutability constraints (is the callee allowed to modify the slice?) */ -typedef struct grpc_slice_refcount_vtable { - void (*ref)(void *); - void (*unref)(grpc_exec_ctx *exec_ctx, void *); - int (*eq)(grpc_slice a, grpc_slice b); - uint32_t (*hash)(grpc_slice slice); -} grpc_slice_refcount_vtable; - /* Reference count container for grpc_slice. Contains function pointers to increment and decrement reference counts. Implementations should cleanup when the reference count drops to zero. Typically client code should not touch this, and use grpc_slice_malloc, grpc_slice_new, or grpc_slice_new_with_len instead. */ typedef struct grpc_slice_refcount { - const grpc_slice_refcount_vtable *vtable; - /* If a subset of this slice is taken, use this pointer for the refcount. - Typically points back to the refcount itself, however iterning - implementations can use this to avoid a verification step on each hash - or equality check */ - struct grpc_slice_refcount *sub_refcount; + void (*ref)(void *); + void (*unref)(grpc_exec_ctx *exec_ctx, void *); } grpc_slice_refcount; #define GRPC_SLICE_INLINED_SIZE (sizeof(size_t) + sizeof(uint8_t *) - 1) @@ -87,7 +74,7 @@ typedef struct grpc_slice_refcount { If the slice does not have a refcount, it represents an inlined small piece of data that is copied by value. */ -struct grpc_slice { +typedef struct grpc_slice { struct grpc_slice_refcount *refcount; union { struct { @@ -99,7 +86,7 @@ struct grpc_slice { uint8_t bytes[GRPC_SLICE_INLINED_SIZE]; } inlined; } data; -}; +} grpc_slice; #define GRPC_SLICE_BUFFER_INLINE_ELEMENTS 8 diff --git a/include/grpc/slice.h b/include/grpc/slice.h index ea66e094e98..1f181aae16a 100644 --- a/include/grpc/slice.h +++ b/include/grpc/slice.h @@ -76,12 +76,6 @@ GPRAPI grpc_slice grpc_slice_new_with_len(void *p, size_t len, Aborts if malloc() fails. */ GPRAPI grpc_slice grpc_slice_malloc(size_t length); -/* Intern a slice: - - The return value for two invocations of this function with the same sequence - of bytes is a slice which points to the same memory. */ -GPRAPI grpc_slice grpc_slice_intern(grpc_slice slice); - /* Create a slice by copying a string. Does not preserve null terminators. Equivalent to: @@ -99,9 +93,6 @@ GPRAPI grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t len); /* Create a slice pointing to constant memory */ GPRAPI grpc_slice grpc_slice_from_static_string(const char *source); -/* Create a slice pointing to constant memory */ -GPRAPI grpc_slice grpc_slice_from_static_buffer(const void *source, size_t len); - /* Return a result slice derived from s, which shares a ref count with s, where result.data==s.data+begin, and result.length==end-begin. The ref count of s is increased by one. @@ -122,45 +113,18 @@ GPRAPI grpc_slice grpc_slice_split_tail(grpc_slice *s, size_t split); Requires s intialized, split <= s.length */ GPRAPI grpc_slice grpc_slice_split_head(grpc_slice *s, size_t split); -GPRAPI grpc_slice grpc_empty_slice(void); - -GPRAPI uint32_t grpc_slice_default_hash_impl(grpc_slice s); -GPRAPI int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b); - -GPRAPI int grpc_slice_eq(grpc_slice a, grpc_slice b); +GPRAPI grpc_slice gpr_empty_slice(void); /* Returns <0 if a < b, ==0 if a == b, >0 if a > b The order is arbitrary, and is not guaranteed to be stable across different versions of the API. */ GPRAPI int grpc_slice_cmp(grpc_slice a, grpc_slice b); GPRAPI int grpc_slice_str_cmp(grpc_slice a, const char *b); -GPRAPI int grpc_slice_buf_cmp(grpc_slice a, const void *b, size_t blen); - -/* return non-zero if the first blen bytes of a are equal to b */ -GPRAPI int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t blen); - -/* return the index of the last instance of \a c in \a s, or -1 if not found */ -GPRAPI int grpc_slice_rchr(grpc_slice s, char c); -GPRAPI int grpc_slice_chr(grpc_slice s, char c); - -/* return the index of the first occurance of \a needle in \a haystack, or -1 if - * it's not found */ -GPRAPI int grpc_slice_slice(grpc_slice haystack, grpc_slice needle); - -GPRAPI uint32_t grpc_slice_hash(grpc_slice s); /* Do two slices point at the same memory, with the same length If a or b is inlined, actually compares data */ GPRAPI int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b); -/* Return a slice pointing to newly allocated memory that has the same contents - * as \a s */ -GPRAPI grpc_slice grpc_slice_dup(grpc_slice a); - -/* Return a copy of slice as a C string. Offers no protection against embedded - NULL's. Returned string must be freed with gpr_free. */ -GPRAPI char *grpc_slice_to_c_string(grpc_slice s); - #ifdef __cplusplus } #endif diff --git a/package.xml b/package.xml index 70384de6a0e..69fa8711d88 100644 --- a/package.xml +++ b/package.xml @@ -200,7 +200,6 @@ - @@ -253,7 +252,6 @@ - @@ -267,17 +265,14 @@ - - - + - @@ -294,9 +289,11 @@ + + @@ -446,8 +443,6 @@ - - @@ -469,13 +464,12 @@ - + - @@ -496,6 +490,7 @@ + diff --git a/src/core/ext/census/gen/census.pb.h b/src/core/ext/census/gen/census.pb.h index c8546eac2e3..dae583f33d3 100644 --- a/src/core/ext/census/gen/census.pb.h +++ b/src/core/ext/census/gen/census.pb.h @@ -292,4 +292,4 @@ extern const pb_field_t google_census_Metric_fields[5]; } /* extern "C" */ #endif -#endif /* GRPC_CORE_EXT_CENSUS_GEN_CENSUS_PB_H */ +#endif diff --git a/src/core/ext/census/gen/trace_context.pb.h b/src/core/ext/census/gen/trace_context.pb.h index cfb2f04ccd2..263c4c58cbf 100644 --- a/src/core/ext/census/gen/trace_context.pb.h +++ b/src/core/ext/census/gen/trace_context.pb.h @@ -96,4 +96,4 @@ extern const pb_field_t google_trace_TraceContext_fields[4]; } /* extern "C" */ #endif -#endif /* GRPC_CORE_EXT_CENSUS_GEN_TRACE_CONTEXT_PB_H */ +#endif diff --git a/src/core/ext/census/grpc_filter.c b/src/core/ext/census/grpc_filter.c index 65cfe1fa902..8e4d4732b82 100644 --- a/src/core/ext/census/grpc_filter.c +++ b/src/core/ext/census/grpc_filter.c @@ -67,7 +67,9 @@ static void extract_and_annotate_method_tag(grpc_metadata_batch *md, channel_data *chand) { grpc_linked_mdelem *m; for (m = md->list.head; m != NULL; m = m->next) { - if (grpc_slice_eq(GRPC_MDKEY(m->md), GRPC_MDSTR_PATH)) { + if (m->md->key == GRPC_MDSTR_PATH) { + gpr_log(GPR_DEBUG, "%s", + (const char *)GRPC_SLICE_START_PTR(m->md->value->slice)); /* Add method tag here */ } } diff --git a/src/core/ext/client_channel/client_channel.c b/src/core/ext/client_channel/client_channel.c index 74350d9feea..2f25fef9a74 100644 --- a/src/core/ext/client_channel/client_channel.c +++ b/src/core/ext/client_channel/client_channel.c @@ -52,7 +52,6 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/polling_entity.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/connectivity_state.h" @@ -88,7 +87,7 @@ static void method_parameters_free(grpc_exec_ctx *exec_ctx, void *p) { gpr_free(p); } -static const grpc_slice_hash_table_vtable method_parameters_vtable = { +static const grpc_mdstr_hash_table_vtable method_parameters_vtable = { method_parameters_free, method_parameters_copy}; static void *method_parameters_create_from_json(const grpc_json *json) { @@ -166,7 +165,7 @@ typedef struct client_channel_channel_data { /** service config in JSON form */ char *service_config_json; /** maps method names to method_parameters structs */ - grpc_slice_hash_table *method_params_table; + grpc_mdstr_hash_table *method_params_table; /** incoming resolver result - set by resolver.next() */ grpc_channel_args *resolver_result; /** a list of closures that are all waiting for config to come in */ @@ -268,7 +267,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, char *lb_policy_name = NULL; grpc_lb_policy *lb_policy = NULL; grpc_lb_policy *old_lb_policy; - grpc_slice_hash_table *method_params_table = NULL; + grpc_mdstr_hash_table *method_params_table = NULL; grpc_connectivity_state state = GRPC_CHANNEL_TRANSIENT_FAILURE; bool exit_idle = false; grpc_error *state_error = GRPC_ERROR_CREATE("No load balancing policy"); @@ -363,7 +362,7 @@ static void on_resolver_result_changed(grpc_exec_ctx *exec_ctx, void *arg, chand->service_config_json = service_config_json; } if (chand->method_params_table != NULL) { - grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table); } chand->method_params_table = method_params_table; if (lb_policy != NULL) { @@ -559,7 +558,7 @@ static void cc_destroy_channel_elem(grpc_exec_ctx *exec_ctx, gpr_free(chand->lb_policy_name); gpr_free(chand->service_config_json); if (chand->method_params_table != NULL) { - grpc_slice_hash_table_unref(exec_ctx, chand->method_params_table); + grpc_mdstr_hash_table_unref(exec_ctx, chand->method_params_table); } grpc_connectivity_state_destroy(exec_ctx, &chand->state_tracker); grpc_pollset_set_destroy(chand->interested_parties); @@ -594,7 +593,7 @@ typedef struct client_channel_call_data { // to avoid this without breaking the grpc_deadline_state abstraction. grpc_deadline_state deadline_state; - grpc_slice path; // Request path. + grpc_mdstr *path; // Request path. gpr_timespec call_start_time; gpr_timespec deadline; wait_for_ready_value wait_for_ready_from_service_config; @@ -998,10 +997,10 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg, if (error == GRPC_ERROR_NONE) { // Get the method config table from channel data. gpr_mu_lock(&chand->mu); - grpc_slice_hash_table *method_params_table = NULL; + grpc_mdstr_hash_table *method_params_table = NULL; if (chand->method_params_table != NULL) { method_params_table = - grpc_slice_hash_table_ref(chand->method_params_table); + grpc_mdstr_hash_table_ref(chand->method_params_table); } gpr_mu_unlock(&chand->mu); // If the method config table was present, use it. @@ -1030,7 +1029,7 @@ static void read_service_config(grpc_exec_ctx *exec_ctx, void *arg, gpr_mu_unlock(&calld->mu); } } - grpc_slice_hash_table_unref(exec_ctx, method_params_table); + grpc_mdstr_hash_table_unref(exec_ctx, method_params_table); } } GRPC_CALL_STACK_UNREF(exec_ctx, calld->owning_call, "read_service_config"); @@ -1044,7 +1043,7 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, call_data *calld = elem->call_data; // Initialize data members. grpc_deadline_state_init(exec_ctx, elem, args->call_stack); - calld->path = grpc_slice_ref_internal(args->path); + calld->path = GRPC_MDSTR_REF(args->path); calld->call_start_time = args->start_time; calld->deadline = gpr_convert_clock_type(args->deadline, GPR_CLOCK_MONOTONIC); calld->wait_for_ready_from_service_config = WAIT_FOR_READY_UNSET; @@ -1068,8 +1067,8 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, if (chand->lb_policy != NULL) { // We already have a resolver result, so check for service config. if (chand->method_params_table != NULL) { - grpc_slice_hash_table *method_params_table = - grpc_slice_hash_table_ref(chand->method_params_table); + grpc_mdstr_hash_table *method_params_table = + grpc_mdstr_hash_table_ref(chand->method_params_table); gpr_mu_unlock(&chand->mu); method_parameters *method_params = grpc_method_config_table_get( exec_ctx, method_params_table, args->path); @@ -1085,7 +1084,7 @@ static grpc_error *cc_init_call_elem(grpc_exec_ctx *exec_ctx, method_params->wait_for_ready; } } - grpc_slice_hash_table_unref(exec_ctx, method_params_table); + grpc_mdstr_hash_table_unref(exec_ctx, method_params_table); } else { gpr_mu_unlock(&chand->mu); } @@ -1114,7 +1113,7 @@ static void cc_destroy_call_elem(grpc_exec_ctx *exec_ctx, void *and_free_memory) { call_data *calld = elem->call_data; grpc_deadline_state_destroy(exec_ctx, elem); - grpc_slice_unref_internal(exec_ctx, calld->path); + GRPC_MDSTR_UNREF(exec_ctx, calld->path); GRPC_ERROR_UNREF(calld->cancel_error); grpc_subchannel_call *call = GET_CALL(calld); if (call != NULL && call != CANCELLED_CALL) { diff --git a/src/core/ext/client_channel/subchannel.c b/src/core/ext/client_channel/subchannel.c index b7379b30b3a..8bd284507d2 100644 --- a/src/core/ext/client_channel/subchannel.c +++ b/src/core/ext/client_channel/subchannel.c @@ -625,8 +625,9 @@ static void publish_transport_locked(grpc_exec_ctx *exec_ctx, grpc_error *error = grpc_channel_stack_builder_finish( exec_ctx, builder, 0, 1, connection_destroy, NULL, (void **)&con); if (error != GRPC_ERROR_NONE) { - gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", - grpc_error_string(error)); + const char *msg = grpc_error_string(error); + gpr_log(GPR_ERROR, "error initializing subchannel stack: %s", msg); + grpc_error_free_string(msg); GRPC_ERROR_UNREF(error); abort(); /* TODO(ctiller): what to do here? */ } @@ -691,6 +692,7 @@ static void subchannel_connected(grpc_exec_ctx *exec_ctx, void *arg, const char *errmsg = grpc_error_string(error); gpr_log(GPR_INFO, "Connect failed: %s", errmsg); + grpc_error_free_string(errmsg); maybe_start_connecting_locked(exec_ctx, c); GRPC_SUBCHANNEL_WEAK_UNREF(exec_ctx, c, "connecting"); @@ -749,7 +751,7 @@ grpc_connected_subchannel *grpc_subchannel_get_connected_subchannel( grpc_error *grpc_connected_subchannel_create_call( grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *con, - grpc_polling_entity *pollent, grpc_slice path, gpr_timespec start_time, + grpc_polling_entity *pollent, grpc_mdstr *path, gpr_timespec start_time, gpr_timespec deadline, grpc_subchannel_call **call) { grpc_channel_stack *chanstk = CHANNEL_STACK_FROM_CONNECTION(con); *call = gpr_malloc(sizeof(grpc_subchannel_call) + chanstk->call_stack_size); @@ -761,7 +763,7 @@ grpc_error *grpc_connected_subchannel_create_call( if (error != GRPC_ERROR_NONE) { const char *error_string = grpc_error_string(error); gpr_log(GPR_ERROR, "error: %s", error_string); - + grpc_error_free_string(error_string); gpr_free(*call); return error; } diff --git a/src/core/ext/client_channel/subchannel.h b/src/core/ext/client_channel/subchannel.h index 9bd35a77049..684675eb37d 100644 --- a/src/core/ext/client_channel/subchannel.h +++ b/src/core/ext/client_channel/subchannel.h @@ -114,7 +114,7 @@ void grpc_subchannel_call_unref(grpc_exec_ctx *exec_ctx, /** construct a subchannel call */ grpc_error *grpc_connected_subchannel_create_call( grpc_exec_ctx *exec_ctx, grpc_connected_subchannel *connected_subchannel, - grpc_polling_entity *pollent, grpc_slice path, gpr_timespec start_time, + grpc_polling_entity *pollent, grpc_mdstr *path, gpr_timespec start_time, gpr_timespec deadline, grpc_subchannel_call **subchannel_call); /** process a transport level op */ diff --git a/src/core/ext/lb_policy/grpclb/grpclb.c b/src/core/ext/lb_policy/grpclb/grpclb.c index ded457f64a8..97f98df03af 100644 --- a/src/core/ext/lb_policy/grpclb/grpclb.c +++ b/src/core/ext/lb_policy/grpclb/grpclb.c @@ -135,13 +135,13 @@ int grpc_lb_glb_trace = 0; /* add lb_token of selected subchannel (address) to the call's initial * metadata */ -static grpc_error *initial_metadata_add_lb_token( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *initial_metadata, - grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem lb_token) { +static void initial_metadata_add_lb_token( + grpc_metadata_batch *initial_metadata, + grpc_linked_mdelem *lb_token_mdelem_storage, grpc_mdelem *lb_token) { GPR_ASSERT(lb_token_mdelem_storage != NULL); - GPR_ASSERT(!GRPC_MDISNULL(lb_token)); - return grpc_metadata_batch_add_tail(exec_ctx, initial_metadata, - lb_token_mdelem_storage, lb_token); + GPR_ASSERT(lb_token != NULL); + grpc_metadata_batch_add_tail(initial_metadata, lb_token_mdelem_storage, + lb_token); } typedef struct wrapped_rr_closure_arg { @@ -161,7 +161,7 @@ typedef struct wrapped_rr_closure_arg { grpc_connected_subchannel **target; /* the LB token associated with the pick */ - grpc_mdelem lb_token; + grpc_mdelem *lb_token; /* storage for the lb token initial metadata mdelem */ grpc_linked_mdelem *lb_token_mdelem_storage; @@ -188,8 +188,8 @@ static void wrapped_rr_closure(grpc_exec_ctx *exec_ctx, void *arg, * addresses failed to connect). There won't be any user_data/token * available */ if (*wc_arg->target != NULL) { - if (!GRPC_MDISNULL(wc_arg->lb_token)) { - initial_metadata_add_lb_token(exec_ctx, wc_arg->initial_metadata, + if (wc_arg->lb_token != NULL) { + initial_metadata_add_lb_token(wc_arg->initial_metadata, wc_arg->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); } else { @@ -345,7 +345,8 @@ typedef struct glb_lb_policy { /* call status code and details, set in lb_on_server_status_received() */ grpc_status_code lb_call_status; - grpc_slice lb_call_status_details; + char *lb_call_status_details; + size_t lb_call_status_details_capacity; /** LB call retry backoff state */ gpr_backoff lb_call_backoff_state; @@ -387,14 +388,10 @@ static bool is_server_valid(const grpc_grpclb_server *server, size_t idx, /* vtable for LB tokens in grpc_lb_addresses. */ static void *lb_token_copy(void *token) { - return token == NULL - ? NULL - : (void *)GRPC_MDELEM_REF((grpc_mdelem){(uintptr_t)token}).payload; + return token == NULL ? NULL : GRPC_MDELEM_REF(token); } static void lb_token_destroy(grpc_exec_ctx *exec_ctx, void *token) { - if (token != NULL) { - GRPC_MDELEM_UNREF(exec_ctx, (grpc_mdelem){(uintptr_t)token}); - } + if (token != NULL) GRPC_MDELEM_UNREF(exec_ctx, token); } static int lb_token_cmp(void *token1, void *token2) { if (token1 > token2) return 1; @@ -462,11 +459,10 @@ static grpc_lb_addresses *process_serverlist_locked( GPR_ARRAY_SIZE(server->load_balance_token); const size_t lb_token_length = strnlen(server->load_balance_token, lb_token_max_length); - grpc_slice lb_token_mdstr = grpc_slice_from_copied_buffer( - server->load_balance_token, lb_token_length); - user_data = (void *)grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_LB_TOKEN, - lb_token_mdstr) - .payload; + grpc_mdstr *lb_token_mdstr = grpc_mdstr_from_buffer( + (uint8_t *)server->load_balance_token, lb_token_length); + user_data = grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_LB_TOKEN, lb_token_mdstr); } else { char *uri = grpc_sockaddr_to_uri(&addr); gpr_log(GPR_INFO, @@ -474,7 +470,7 @@ static grpc_lb_addresses *process_serverlist_locked( "be used instead", uri); gpr_free(uri); - user_data = (void *)GRPC_MDELEM_LB_TOKEN_EMPTY.payload; + user_data = GRPC_MDELEM_LB_TOKEN_EMPTY; } grpc_lb_addresses_set_address(lb_addresses, addr_idx, &addr.addr, addr.len, @@ -568,7 +564,7 @@ static bool pick_from_internal_rr_locked( GRPC_LB_POLICY_UNREF(exec_ctx, wc_arg->rr_policy, "glb_pick_sync"); /* add the load reporting initial metadata */ - initial_metadata_add_lb_token(exec_ctx, pick_args->initial_metadata, + initial_metadata_add_lb_token(pick_args->initial_metadata, pick_args->lb_token_mdelem_storage, GRPC_MDELEM_REF(wc_arg->lb_token)); @@ -1107,12 +1103,11 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, /* Note the following LB call progresses every time there's activity in \a * glb_policy->base.interested_parties, which is comprised of the polling * entities from \a client_channel. */ - grpc_slice host = grpc_slice_from_copied_string(glb_policy->server_name); glb_policy->lb_call = grpc_channel_create_pollset_set_call( exec_ctx, glb_policy->lb_channel, NULL, GRPC_PROPAGATE_DEFAULTS, glb_policy->base.interested_parties, - GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD, - &host, glb_policy->deadline, NULL); + "/grpc.lb.v1.LoadBalancer/BalanceLoad", glb_policy->server_name, + glb_policy->deadline, NULL); grpc_metadata_array_init(&glb_policy->lb_initial_metadata_recv); grpc_metadata_array_init(&glb_policy->lb_trailing_metadata_recv); @@ -1125,6 +1120,9 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, grpc_slice_unref_internal(exec_ctx, request_payload_slice); grpc_grpclb_request_destroy(request); + glb_policy->lb_call_status_details = NULL; + glb_policy->lb_call_status_details_capacity = 0; + grpc_closure_init(&glb_policy->lb_on_server_status_received, lb_on_server_status_received, glb_policy, grpc_schedule_on_exec_ctx); @@ -1140,8 +1138,7 @@ static void lb_call_init_locked(grpc_exec_ctx *exec_ctx, GRPC_GRPCLB_RECONNECT_MAX_BACKOFF_SECONDS * 1000); } -static void lb_call_destroy_locked(grpc_exec_ctx *exec_ctx, - glb_lb_policy *glb_policy) { +static void lb_call_destroy_locked(glb_lb_policy *glb_policy) { GPR_ASSERT(glb_policy->lb_call != NULL); grpc_call_destroy(glb_policy->lb_call); glb_policy->lb_call = NULL; @@ -1150,7 +1147,7 @@ static void lb_call_destroy_locked(grpc_exec_ctx *exec_ctx, grpc_metadata_array_destroy(&glb_policy->lb_trailing_metadata_recv); grpc_byte_buffer_destroy(glb_policy->lb_request_payload); - grpc_slice_unref_internal(exec_ctx, glb_policy->lb_call_status_details); + gpr_free(glb_policy->lb_call_status_details); } /* @@ -1199,6 +1196,8 @@ static void query_for_backends_locked(grpc_exec_ctx *exec_ctx, op->data.recv_status_on_client.status = &glb_policy->lb_call_status; op->data.recv_status_on_client.status_details = &glb_policy->lb_call_status_details; + op->data.recv_status_on_client.status_details_capacity = + &glb_policy->lb_call_status_details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -1341,18 +1340,15 @@ static void lb_on_server_status_received(grpc_exec_ctx *exec_ctx, void *arg, GPR_ASSERT(glb_policy->lb_call != NULL); if (grpc_lb_glb_trace) { - char *status_details = - grpc_slice_to_c_string(glb_policy->lb_call_status_details); gpr_log(GPR_DEBUG, "Status from LB server received. Status = %d, Details = '%s', " "(call: %p)", - glb_policy->lb_call_status, status_details, + glb_policy->lb_call_status, glb_policy->lb_call_status_details, (void *)glb_policy->lb_call); - gpr_free(status_details); } - /* We need to perform cleanups no matter what. */ - lb_call_destroy_locked(exec_ctx, glb_policy); + /* We need to performe cleanups no matter what. */ + lb_call_destroy_locked(glb_policy); if (!glb_policy->shutting_down) { /* if we aren't shutting down, restart the LB client call after some time */ diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 8af6191c3b8..07ef10e6a83 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -41,17 +41,13 @@ #include "src/core/ext/load_reporting/load_reporting_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/static_metadata.h" typedef struct call_data { intptr_t id; /**< an id unique to the call */ - bool have_trailing_md_string; - grpc_slice trailing_md_string; - bool have_initial_md_string; - grpc_slice initial_md_string; - bool have_service_method; - grpc_slice service_method; + char *trailing_md_string; + char *initial_md_string; + const char *service_method; /* stores the recv_initial_metadata op's ready closure, which we wrap with our * own (on_initial_md_ready) in order to capture the incoming initial metadata @@ -67,28 +63,42 @@ typedef struct channel_data { intptr_t id; /**< an id unique to the channel */ } channel_data; +typedef struct { + grpc_call_element *elem; + grpc_exec_ctx *exec_ctx; +} recv_md_filter_args; + +static grpc_mdelem *recv_md_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { + recv_md_filter_args *a = user_data; + grpc_call_element *elem = a->elem; + call_data *calld = elem->call_data; + + if (md->key == GRPC_MDSTR_PATH) { + calld->service_method = grpc_mdstr_as_c_string(md->value); + } else if (md->key == GRPC_MDSTR_LB_TOKEN) { + calld->initial_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); + return NULL; + } + + return md; +} + static void on_initial_md_ready(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *err) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (err == GRPC_ERROR_NONE) { - if (calld->recv_initial_metadata->idx.named.path != NULL) { - calld->service_method = grpc_slice_ref_internal( - GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); - calld->have_service_method = true; - } else { + recv_md_filter_args a; + a.elem = elem; + a.exec_ctx = exec_ctx; + grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, + recv_md_filter, &a); + if (calld->service_method == NULL) { err = grpc_error_add_child(err, GRPC_ERROR_CREATE("Missing :path header")); } - if (calld->recv_initial_metadata->idx.named.lb_token != NULL) { - calld->initial_md_string = grpc_slice_ref_internal( - GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.lb_token->md)); - calld->have_initial_md_string = true; - grpc_metadata_batch_remove( - exec_ctx, calld->recv_initial_metadata, - calld->recv_initial_metadata->idx.named.lb_token); - } } else { GRPC_ERROR_REF(err); } @@ -139,15 +149,8 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, calld->service_method}; */ - if (calld->have_initial_md_string) { - grpc_slice_unref_internal(exec_ctx, calld->initial_md_string); - } - if (calld->have_trailing_md_string) { - grpc_slice_unref_internal(exec_ctx, calld->trailing_md_string); - } - if (calld->have_service_method) { - grpc_slice_unref_internal(exec_ctx, calld->service_method); - } + gpr_free(calld->initial_md_string); + gpr_free(calld->trailing_md_string); } /* Constructor for channel_data */ @@ -190,6 +193,19 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, */ } +static grpc_mdelem *lr_trailing_md_filter(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem *md) { + grpc_call_element *elem = user_data; + call_data *calld = elem->call_data; + + if (md->key == GRPC_MDSTR_LB_COST_BIN) { + calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); + return NULL; + } + + return md; +} + static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_transport_stream_op *op) { @@ -202,14 +218,8 @@ static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, calld->ops_recv_initial_metadata_ready = op->recv_initial_metadata_ready; op->recv_initial_metadata_ready = &calld->on_initial_md_ready; } else if (op->send_trailing_metadata) { - if (op->send_trailing_metadata->idx.named.lb_cost_bin != NULL) { - calld->trailing_md_string = grpc_slice_ref_internal( - GRPC_MDVALUE(op->send_trailing_metadata->idx.named.lb_cost_bin->md)); - calld->have_trailing_md_string = true; - grpc_metadata_batch_remove( - exec_ctx, op->send_trailing_metadata, - op->send_trailing_metadata->idx.named.lb_cost_bin); - } + grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata, + lr_trailing_md_filter, elem); } grpc_call_next_op(exec_ctx, elem, op); diff --git a/src/core/ext/resolver/dns/native/dns_resolver.c b/src/core/ext/resolver/dns/native/dns_resolver.c index 58fe9d39852..655d9dc586c 100644 --- a/src/core/ext/resolver/dns/native/dns_resolver.c +++ b/src/core/ext/resolver/dns/native/dns_resolver.c @@ -188,8 +188,9 @@ static void dns_on_resolved(grpc_exec_ctx *exec_ctx, void *arg, gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC); gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now); gpr_timespec timeout = gpr_time_sub(next_try, now); - gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", - grpc_error_string(error)); + const char *msg = grpc_error_string(error); + gpr_log(GPR_INFO, "dns resolution failed (will retry): %s", msg); + grpc_error_free_string(msg); GPR_ASSERT(!r->have_retry_timer); r->have_retry_timer = true; GRPC_RESOLVER_REF(&r->base, "retry-timer"); diff --git a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c index a1365f64656..c146a627cb5 100644 --- a/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +++ b/src/core/ext/resolver/sockaddr/sockaddr_resolver.c @@ -182,7 +182,7 @@ static grpc_resolver *sockaddr_create(grpc_exec_ctx *exec_ctx, bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; - char *part_str = grpc_slice_to_c_string(path_parts.slices[i]); + char *part_str = grpc_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII); ith_uri.path = part_str; if (!parse(&ith_uri, &addresses->addresses[i].address)) { errors_found = true; /* GPR_TRUE */ diff --git a/src/core/ext/transport/chttp2/server/chttp2_server.c b/src/core/ext/transport/chttp2/server/chttp2_server.c index 56a1a0de9b3..574d1a77101 100644 --- a/src/core/ext/transport/chttp2/server/chttp2_server.c +++ b/src/core/ext/transport/chttp2/server/chttp2_server.c @@ -121,7 +121,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE || connection_state->server_state->shutdown) { const char *error_str = grpc_error_string(error); gpr_log(GPR_ERROR, "Handshaking failed: %s", error_str); - + grpc_error_free_string(error_str); if (error == GRPC_ERROR_NONE && args->endpoint != NULL) { // We were shut down after handshaking completed successfully, so // destroy the endpoint here. @@ -307,7 +307,7 @@ grpc_error *grpc_chttp2_server_add_port(grpc_exec_ctx *exec_ctx, const char *warning_message = grpc_error_string(err); gpr_log(GPR_INFO, "WARNING: %s", warning_message); - + grpc_error_free_string(warning_message); /* we managed to bind some addresses: continue */ } grpc_resolved_addresses_destroy(resolved); diff --git a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c index c219a7d85ff..bf5026bea64 100644 --- a/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +++ b/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c @@ -51,7 +51,7 @@ int grpc_server_add_insecure_http2_port(grpc_server *server, const char *addr) { if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - + grpc_error_free_string(msg); GRPC_ERROR_UNREF(err); } grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c index cb2b3f5502c..395c79a71d1 100644 --- a/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +++ b/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c @@ -94,7 +94,7 @@ done: if (err != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); - + grpc_error_free_string(msg); GRPC_ERROR_UNREF(err); } return port_num; diff --git a/src/core/ext/transport/chttp2/transport/bin_decoder.c b/src/core/ext/transport/chttp2/transport/bin_decoder.c index 8c87de112eb..8db36e4a7f0 100644 --- a/src/core/ext/transport/chttp2/transport/bin_decoder.c +++ b/src/core/ext/transport/chttp2/transport/bin_decoder.c @@ -157,7 +157,7 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, "grpc_chttp2_base64_decode has a length of %d, which is not a " "multiple of 4.\n", (int)input_length); - return grpc_empty_slice(); + return gpr_empty_slice(); } if (input_length > 0) { @@ -178,11 +178,11 @@ grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, ctx.contains_tail = false; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_slice_to_c_string(input); + char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); - return grpc_empty_slice(); + return gpr_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.input_cur == GRPC_SLICE_END_PTR(input)); @@ -204,7 +204,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, "has a tail of 1 byte.\n", (int)input_length); grpc_slice_unref_internal(exec_ctx, output); - return grpc_empty_slice(); + return gpr_empty_slice(); } if (output_length > input_length / 4 * 3 + tail_xtra[input_length % 4]) { @@ -214,7 +214,7 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, (int)output_length, (int)(input_length / 4 * 3 + tail_xtra[input_length % 4])); grpc_slice_unref_internal(exec_ctx, output); - return grpc_empty_slice(); + return gpr_empty_slice(); } ctx.input_cur = GRPC_SLICE_START_PTR(input); @@ -224,11 +224,11 @@ grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx, ctx.contains_tail = true; if (!grpc_base64_decode_partial(&ctx)) { - char *s = grpc_slice_to_c_string(input); + char *s = grpc_dump_slice(input, GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "Base64 decoding failed, input string:\n%s\n", s); gpr_free(s); grpc_slice_unref_internal(exec_ctx, output); - return grpc_empty_slice(); + return gpr_empty_slice(); } GPR_ASSERT(ctx.output_cur == GRPC_SLICE_END_PTR(output)); GPR_ASSERT(ctx.input_cur <= GRPC_SLICE_END_PTR(input)); diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.c b/src/core/ext/transport/chttp2/transport/bin_encoder.c index e301c073f37..af25a4352ac 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.c +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.c @@ -177,7 +177,8 @@ static void enc_add1(huff_out *out, uint8_t a) { enc_flush_some(out); } -grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) { +grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl( + grpc_slice input) { size_t input_length = GRPC_SLICE_LENGTH(input); size_t input_triplets = input_length / 3; size_t tail_case = input_length % 3; diff --git a/src/core/ext/transport/chttp2/transport/bin_encoder.h b/src/core/ext/transport/chttp2/transport/bin_encoder.h index 0f899c8e343..477559d0e25 100644 --- a/src/core/ext/transport/chttp2/transport/bin_encoder.h +++ b/src/core/ext/transport/chttp2/transport/bin_encoder.h @@ -49,6 +49,7 @@ grpc_slice grpc_chttp2_huffman_compress(grpc_slice input); grpc_slice y = grpc_chttp2_huffman_compress(x); grpc_slice_unref_internal(exec_ctx, x); return y; */ -grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input); +grpc_slice grpc_chttp2_base64_encode_and_huffman_compress_impl( + grpc_slice input); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_ENCODER_H */ diff --git a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c index 59b21e3330d..bd87253ed32 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_plugin.c @@ -31,11 +31,14 @@ * */ +#include "src/core/ext/transport/chttp2/transport/bin_encoder.h" #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/lib/debug/trace.h" #include "src/core/lib/transport/metadata.h" void grpc_chttp2_plugin_init(void) { + grpc_chttp2_base64_encode_and_huffman_compress = + grpc_chttp2_base64_encode_and_huffman_compress_impl; grpc_register_tracer("http", &grpc_http_trace); grpc_register_tracer("flowctl", &grpc_flowctl_trace); } diff --git a/src/core/ext/transport/chttp2/transport/chttp2_transport.c b/src/core/ext/transport/chttp2/transport/chttp2_transport.c index 2004bc6437e..68a6a2155dd 100644 --- a/src/core/ext/transport/chttp2/transport/chttp2_transport.c +++ b/src/core/ext/transport/chttp2/transport/chttp2_transport.c @@ -44,7 +44,9 @@ #include #include +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/ext/transport/chttp2/transport/internal.h" +#include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/http/parser.h" @@ -53,10 +55,7 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" -#include "src/core/lib/transport/error_utils.h" -#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/static_metadata.h" -#include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" #include "src/core/lib/transport/transport_impl.h" @@ -410,7 +409,7 @@ static void close_transport_locked(grpc_exec_ctx *exec_ctx, grpc_error_add_child(t->close_transport_on_writes_finished, error); return; } - if (!grpc_error_has_clear_grpc_status(error)) { + if (!grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); } @@ -867,6 +866,7 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, (int)(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT), (int)(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT), desc, errstr); + grpc_error_free_string(errstr); } if (error != GRPC_ERROR_NONE) { if (closure->error_data.error == GRPC_ERROR_NONE) { @@ -895,9 +895,12 @@ void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx, } static bool contains_non_ok_status(grpc_metadata_batch *batch) { - if (batch->idx.named.grpc_status != NULL) { - return !grpc_mdelem_eq(batch->idx.named.grpc_status->md, - GRPC_MDELEM_GRPC_STATUS_0); + grpc_linked_mdelem *l; + for (l = batch->list.head; l; l = l->next) { + if (l->md->key == GRPC_MDSTR_GRPC_STATUS && + l->md != GRPC_MDELEM_GRPC_STATUS_0) { + return true; + } } return false; } @@ -977,12 +980,9 @@ static void log_metadata(const grpc_metadata_batch *md_batch, uint32_t id, bool is_client, bool is_initial) { for (grpc_linked_mdelem *md = md_batch->list.head; md != md_batch->list.tail; md = md->next) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md->md)); - char *value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md)); gpr_log(GPR_INFO, "HTTP:%d:%s:%s: %s: %s", id, is_initial ? "HDR" : "TRL", - is_client ? "CLI" : "SVR", key, value); - gpr_free(key); - gpr_free(value); + is_client ? "CLI" : "SVR", grpc_mdstr_as_c_string(md->md->key), + grpc_mdstr_as_c_string(md->md->value)); } } @@ -1025,7 +1025,11 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, } if (op->cancel_error != GRPC_ERROR_NONE) { - grpc_chttp2_cancel_stream(exec_ctx, t, s, op->cancel_error); + grpc_chttp2_cancel_stream(exec_ctx, t, s, GRPC_ERROR_REF(op->cancel_error)); + } + + if (op->close_error != GRPC_ERROR_NONE) { + close_from_api(exec_ctx, t, s, GRPC_ERROR_REF(op->close_error)); } if (op->send_initial_metadata != NULL) { @@ -1076,9 +1080,8 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, s->send_initial_metadata = NULL; grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->send_initial_metadata_finished, - GRPC_ERROR_CREATE_REFERENCING( - "Attempt to send initial metadata after stream was closed", - &s->write_closed_error, 1), + GRPC_ERROR_CREATE( + "Attempt to send initial metadata after stream was closed"), "send_initial_metadata_finished"); } } @@ -1090,9 +1093,7 @@ static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op, if (s->write_closed) { grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->fetching_send_message_finished, - GRPC_ERROR_CREATE_REFERENCING( - "Attempt to send message after stream was closed", - &s->write_closed_error, 1), + GRPC_ERROR_CREATE("Attempt to send message after stream was closed"), "fetching_send_message_finished"); } else { GPR_ASSERT(s->fetching_send_message == NULL); @@ -1264,16 +1265,11 @@ void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, } static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_error *error) { + grpc_chttp2_error_code error, grpc_slice data) { t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED; - grpc_http2_error_code http_error; - const char *msg; - grpc_error_get_status(error, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL, &msg, - &http_error); - grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error, - grpc_slice_from_copied_string(msg), &t->qbuf); + grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)error, data, + &t->qbuf); grpc_chttp2_initiate_write(exec_ctx, t, false, "goaway_sent"); - GRPC_ERROR_UNREF(error); } static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, @@ -1289,8 +1285,10 @@ static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx, op->on_connectivity_state_change); } - if (op->goaway_error) { - send_goaway(exec_ctx, t, op->goaway_error); + if (op->send_goaway) { + send_goaway(exec_ctx, t, + grpc_chttp2_grpc_status_to_http2_error(op->goaway_status), + grpc_slice_ref_internal(*op->goaway_message)); } if (op->set_accept_stream) { @@ -1350,8 +1348,8 @@ void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx, incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE); } } - grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &s->metadata_buffer[0], s->recv_initial_metadata); + grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[0], + s->recv_initial_metadata); null_then_run_closure(exec_ctx, &s->recv_initial_metadata_ready, GRPC_ERROR_NONE); } @@ -1394,8 +1392,8 @@ void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, } if (s->all_incoming_byte_streams_finished && s->recv_trailing_metadata_finished != NULL) { - grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata); + grpc_chttp2_incoming_metadata_buffer_publish(&s->metadata_buffer[1], + s->recv_trailing_metadata); grpc_chttp2_complete_closure_step( exec_ctx, t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE, "recv_trailing_metadata_finished"); @@ -1443,37 +1441,70 @@ static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, maybe_start_some_streams(exec_ctx, t); } +static void status_codes_from_error(grpc_error *error, gpr_timespec deadline, + grpc_chttp2_error_code *http2_error, + grpc_status_code *grpc_status) { + intptr_t ip_http; + intptr_t ip_grpc; + bool have_http = + grpc_error_get_int(error, GRPC_ERROR_INT_HTTP2_ERROR, &ip_http); + bool have_grpc = + grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &ip_grpc); + if (have_http) { + *http2_error = (grpc_chttp2_error_code)ip_http; + } else if (have_grpc) { + *http2_error = + grpc_chttp2_grpc_status_to_http2_error((grpc_status_code)ip_grpc); + } else { + *http2_error = GRPC_CHTTP2_INTERNAL_ERROR; + } + if (have_grpc) { + *grpc_status = (grpc_status_code)ip_grpc; + } else if (have_http) { + *grpc_status = grpc_chttp2_http2_error_to_grpc_status( + (grpc_chttp2_error_code)ip_http, deadline); + } else { + *grpc_status = GRPC_STATUS_INTERNAL; + } +} + void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, grpc_error *due_to_error) { - if (!t->is_client && !s->sent_trailing_metadata && - grpc_error_has_clear_grpc_status(due_to_error)) { - close_from_api(exec_ctx, t, s, due_to_error); - return; - } - if (!s->read_closed || !s->write_closed) { + grpc_status_code grpc_status; + grpc_chttp2_error_code http_error; + status_codes_from_error(due_to_error, s->deadline, &http_error, + &grpc_status); + if (s->id != 0) { - grpc_http2_error_code http_error; - grpc_error_get_status(due_to_error, s->deadline, NULL, NULL, &http_error); grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error, &s->stats.outgoing)); grpc_chttp2_initiate_write(exec_ctx, t, false, "rst_stream"); } + + const char *msg = + grpc_error_get_str(due_to_error, GRPC_ERROR_STR_GRPC_MESSAGE); + bool free_msg = false; + if (msg == NULL) { + free_msg = true; + msg = grpc_error_string(due_to_error); + } + grpc_slice msg_slice = grpc_slice_from_copied_string(msg); + grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, &msg_slice); + if (free_msg) grpc_error_free_string(msg); } if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) { s->seen_error = true; + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error); } void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *s, grpc_error *error) { - grpc_status_code status; - const char *msg; - grpc_error_get_status(error, s->deadline, &status, &msg, NULL); - + grpc_chttp2_stream *s, grpc_status_code status, + grpc_slice *slice) { if (status != GRPC_STATUS_OK) { s->seen_error = true; } @@ -1487,21 +1518,24 @@ void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, s->recv_trailing_metadata_finished != NULL) { char status_string[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(status, status_string); - grpc_chttp2_incoming_metadata_buffer_replace_or_add( - exec_ctx, &s->metadata_buffer[1], - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, - grpc_slice_from_copied_string(status_string))); - if (msg != NULL) { - grpc_chttp2_incoming_metadata_buffer_replace_or_add( - exec_ctx, &s->metadata_buffer[1], - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_slice_from_copied_string(msg))); + grpc_chttp2_incoming_metadata_buffer_add( + &s->metadata_buffer[1], grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_STATUS, + grpc_mdstr_from_string(status_string))); + if (slice) { + grpc_chttp2_incoming_metadata_buffer_add( + &s->metadata_buffer[1], + grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_mdstr_from_slice(exec_ctx, + grpc_slice_ref_internal(*slice)))); } s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE; grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } - - GRPC_ERROR_UNREF(error); + if (slice) { + grpc_slice_unref_internal(exec_ctx, *slice); + } } static void add_error(grpc_error *error, grpc_error **refs, size_t *nrefs) { @@ -1567,48 +1601,36 @@ void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, int close_writes, grpc_error *error) { if (s->read_closed && s->write_closed) { /* already closed */ - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_ERROR_UNREF(error); return; } - bool closed_read = false; - bool became_closed = false; if (close_reads && !s->read_closed) { s->read_closed_error = GRPC_ERROR_REF(error); s->read_closed = true; - closed_read = true; + for (int i = 0; i < 2; i++) { + if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) { + s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; + } + } + decrement_active_streams_locked(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } if (close_writes && !s->write_closed) { s->write_closed_error = GRPC_ERROR_REF(error); s->write_closed = true; grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error)); + grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); } if (s->read_closed && s->write_closed) { - became_closed = true; - grpc_error *overall_error = - removal_error(GRPC_ERROR_REF(error), s, "Stream removed"); if (s->id != 0) { - remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error)); + remove_stream(exec_ctx, t, s->id, + removal_error(GRPC_ERROR_REF(error), s, "Stream removed")); } else { /* Purge streams waiting on concurrency still waiting for id assignment */ grpc_chttp2_list_remove_waiting_for_concurrency(t, s); } - if (overall_error != GRPC_ERROR_NONE) { - grpc_chttp2_fake_status(exec_ctx, t, s, overall_error); - } - } - if (closed_read) { - for (int i = 0; i < 2; i++) { - if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) { - s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE; - } - } - decrement_active_streams_locked(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s); - grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s); - } - if (became_closed) { - grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s); GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2"); } GRPC_ERROR_UNREF(error); @@ -1622,92 +1644,112 @@ static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, uint8_t *p; uint32_t len = 0; grpc_status_code grpc_status; - const char *msg; - grpc_error_get_status(error, s->deadline, &grpc_status, &msg, NULL); + grpc_chttp2_error_code http_error; + status_codes_from_error(error, s->deadline, &http_error, &grpc_status); GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100); - /* Hand roll a header block. - This is unnecessarily ugly - at some point we should find a more - elegant solution. - It's complicated by the fact that our send machinery would be dead by - the time we got around to sending this, so instead we ignore HPACK - compression and just write the uncompressed bytes onto the wire. */ - status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); - p = GRPC_SLICE_START_PTR(status_hdr); - *p++ = 0x00; /* literal header, not indexed */ - *p++ = 11; /* len(grpc-status) */ - *p++ = 'g'; - *p++ = 'r'; - *p++ = 'p'; - *p++ = 'c'; - *p++ = '-'; - *p++ = 's'; - *p++ = 't'; - *p++ = 'a'; - *p++ = 't'; - *p++ = 'u'; - *p++ = 's'; - if (grpc_status < 10) { - *p++ = 1; - *p++ = (uint8_t)('0' + grpc_status); - } else { - *p++ = 2; - *p++ = (uint8_t)('0' + (grpc_status / 10)); - *p++ = (uint8_t)('0' + (grpc_status % 10)); - } - GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); - len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); - - if (msg != NULL) { - size_t msg_len = strlen(msg); - GPR_ASSERT(msg_len <= UINT32_MAX); - uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0); - message_pfx = grpc_slice_malloc(14 + msg_len_len); - p = GRPC_SLICE_START_PTR(message_pfx); - *p++ = 0x00; /* literal header, not indexed */ - *p++ = 12; /* len(grpc-message) */ + if (s->id != 0 && !t->is_client) { + /* Hand roll a header block. + This is unnecessarily ugly - at some point we should find a more + elegant + solution. + It's complicated by the fact that our send machinery would be dead by + the + time we got around to sending this, so instead we ignore HPACK + compression + and just write the uncompressed bytes onto the wire. */ + status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10)); + p = GRPC_SLICE_START_PTR(status_hdr); + *p++ = 0x40; /* literal header */ + *p++ = 11; /* len(grpc-status) */ *p++ = 'g'; *p++ = 'r'; *p++ = 'p'; *p++ = 'c'; *p++ = '-'; - *p++ = 'm'; - *p++ = 'e'; - *p++ = 's'; *p++ = 's'; + *p++ = 't'; *p++ = 'a'; - *p++ = 'g'; - *p++ = 'e'; - GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 0, 0, p, (uint32_t)msg_len_len); - p += msg_len_len; - GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); - len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); - len += (uint32_t)msg_len; - } - - hdr = grpc_slice_malloc(9); - p = GRPC_SLICE_START_PTR(hdr); - *p++ = (uint8_t)(len >> 16); - *p++ = (uint8_t)(len >> 8); - *p++ = (uint8_t)(len); - *p++ = GRPC_CHTTP2_FRAME_HEADER; - *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; - *p++ = (uint8_t)(s->id >> 24); - *p++ = (uint8_t)(s->id >> 16); - *p++ = (uint8_t)(s->id >> 8); - *p++ = (uint8_t)(s->id); - GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); - - grpc_slice_buffer_add(&t->qbuf, hdr); - grpc_slice_buffer_add(&t->qbuf, status_hdr); - if (msg != NULL) { - grpc_slice_buffer_add(&t->qbuf, message_pfx); - grpc_slice_buffer_add(&t->qbuf, grpc_slice_from_copied_string(msg)); - } - grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, - &s->stats.outgoing)); + *p++ = 't'; + *p++ = 'u'; + *p++ = 's'; + if (grpc_status < 10) { + *p++ = 1; + *p++ = (uint8_t)('0' + grpc_status); + } else { + *p++ = 2; + *p++ = (uint8_t)('0' + (grpc_status / 10)); + *p++ = (uint8_t)('0' + (grpc_status % 10)); + } + GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr)); + len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr); + + const char *optional_message = + grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE); + + if (optional_message != NULL) { + size_t msg_len = strlen(optional_message); + GPR_ASSERT(msg_len <= UINT32_MAX); + uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 0); + message_pfx = grpc_slice_malloc(14 + msg_len_len); + p = GRPC_SLICE_START_PTR(message_pfx); + *p++ = 0x40; + *p++ = 12; /* len(grpc-message) */ + *p++ = 'g'; + *p++ = 'r'; + *p++ = 'p'; + *p++ = 'c'; + *p++ = '-'; + *p++ = 'm'; + *p++ = 'e'; + *p++ = 's'; + *p++ = 's'; + *p++ = 'a'; + *p++ = 'g'; + *p++ = 'e'; + GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 0, 0, p, + (uint32_t)msg_len_len); + p += msg_len_len; + GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx)); + len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx); + len += (uint32_t)msg_len; + } + + hdr = grpc_slice_malloc(9); + p = GRPC_SLICE_START_PTR(hdr); + *p++ = (uint8_t)(len >> 16); + *p++ = (uint8_t)(len >> 8); + *p++ = (uint8_t)(len); + *p++ = GRPC_CHTTP2_FRAME_HEADER; + *p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS; + *p++ = (uint8_t)(s->id >> 24); + *p++ = (uint8_t)(s->id >> 16); + *p++ = (uint8_t)(s->id >> 8); + *p++ = (uint8_t)(s->id); + GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr)); + + grpc_slice_buffer_add(&t->qbuf, hdr); + grpc_slice_buffer_add(&t->qbuf, status_hdr); + if (optional_message) { + grpc_slice_buffer_add(&t->qbuf, message_pfx); + grpc_slice_buffer_add(&t->qbuf, + grpc_slice_from_copied_string(optional_message)); + } + grpc_slice_buffer_add( + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, + &s->stats.outgoing)); + } + + const char *msg = grpc_error_get_str(error, GRPC_ERROR_STR_GRPC_MESSAGE); + bool free_msg = false; + if (msg == NULL) { + free_msg = true; + msg = grpc_error_string(error); + } + grpc_slice msg_slice = grpc_slice_from_copied_string(msg); + grpc_chttp2_fake_status(exec_ctx, t, s, grpc_status, &msg_slice); + if (free_msg) grpc_error_free_string(msg); grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error); grpc_chttp2_initiate_write(exec_ctx, t, false, "close_from_api"); @@ -1785,10 +1827,8 @@ static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx, if (parse_error == GRPC_ERROR_NONE && (parse_error = grpc_http_parser_eof(&parser)) == GRPC_ERROR_NONE) { error = grpc_error_set_int( - grpc_error_set_int( - GRPC_ERROR_CREATE("Trying to connect an http1.x server"), - GRPC_ERROR_INT_HTTP_STATUS, response.status), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE); + GRPC_ERROR_CREATE("Trying to connect an http1.x server"), + GRPC_ERROR_INT_HTTP_STATUS, response.status); } GRPC_ERROR_UNREF(parse_error); @@ -2049,8 +2089,6 @@ static void incoming_byte_stream_publish_error( grpc_closure_sched(exec_ctx, bs->on_next, GRPC_ERROR_REF(error)); bs->on_next = NULL; GRPC_ERROR_UNREF(bs->error); - grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream, - GRPC_ERROR_REF(error)); bs->error = error; } @@ -2159,10 +2197,8 @@ static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory", t->peer_string); } - send_goaway(exec_ctx, t, - grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), - GRPC_ERROR_INT_HTTP2_ERROR, - GRPC_HTTP2_ENHANCE_YOUR_CALM)); + send_goaway(exec_ctx, t, GRPC_CHTTP2_ENHANCE_YOUR_CALM, + grpc_slice_from_static_string("Buffers full")); } else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace) { gpr_log(GPR_DEBUG, "HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR @@ -2191,7 +2227,7 @@ static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg, grpc_chttp2_cancel_stream( exec_ctx, t, s, grpc_error_set_int(GRPC_ERROR_CREATE("Buffers full"), GRPC_ERROR_INT_HTTP2_ERROR, - GRPC_HTTP2_ENHANCE_YOUR_CALM)); + GRPC_CHTTP2_ENHANCE_YOUR_CALM)); if (n > 1) { /* Since we cancel one stream per destructive reclamation, if there are more streams left, we can immediately post a new diff --git a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c index 7d5beed09dd..20043f5fbf4 100644 --- a/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +++ b/src/core/ext/transport/chttp2/transport/frame_rst_stream.c @@ -39,7 +39,8 @@ #include #include "src/core/ext/transport/chttp2/transport/frame.h" -#include "src/core/lib/transport/http2_errors.h" +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" +#include "src/core/ext/transport/chttp2/transport/status_conversion.h" grpc_slice grpc_chttp2_rst_stream_create(uint32_t id, uint32_t code, grpc_transport_one_way_stats *stats) { @@ -108,9 +109,17 @@ grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx, (((uint32_t)p->reason_bytes[2]) << 8) | (((uint32_t)p->reason_bytes[3])); grpc_error *error = GRPC_ERROR_NONE; - if (reason != GRPC_HTTP2_NO_ERROR || s->header_frames_received < 2) { + if (reason != GRPC_CHTTP2_NO_ERROR || s->header_frames_received < 2) { error = grpc_error_set_int(GRPC_ERROR_CREATE("RST_STREAM"), GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason); + grpc_status_code status_code = grpc_chttp2_http2_error_to_grpc_status( + (grpc_chttp2_error_code)reason, s->deadline); + char *status_details; + gpr_asprintf(&status_details, "Received RST_STREAM with error code %d", + reason); + grpc_slice slice_details = grpc_slice_from_copied_string(status_details); + gpr_free(status_details); + grpc_chttp2_fake_status(exec_ctx, t, s, status_code, &slice_details); } grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, error); } diff --git a/src/core/ext/transport/chttp2/transport/frame_settings.c b/src/core/ext/transport/chttp2/transport/frame_settings.c index be9b663ac14..98facae87fe 100644 --- a/src/core/ext/transport/chttp2/transport/frame_settings.c +++ b/src/core/ext/transport/chttp2/transport/frame_settings.c @@ -43,8 +43,8 @@ #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" #include "src/core/ext/transport/chttp2/transport/frame.h" +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/debug/trace.h" -#include "src/core/lib/transport/http2_errors.h" #define MAX_MAX_HEADER_LIST_SIZE (1024 * 1024 * 1024) @@ -52,21 +52,21 @@ const grpc_chttp2_setting_parameters grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = { {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_PROTOCOL_ERROR}, {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff, - GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_PROTOCOL_ERROR}, {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, {"INITIAL_WINDOW_SIZE", 65535, 0, 0x7fffffffu, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, - GRPC_HTTP2_FLOW_CONTROL_ERROR}, + GRPC_CHTTP2_FLOW_CONTROL_ERROR}, {"MAX_FRAME_SIZE", 16384, 16384, 16777215, - GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_CHTTP2_PROTOCOL_ERROR}, {"MAX_HEADER_LIST_SIZE", MAX_MAX_HEADER_LIST_SIZE, 0, MAX_MAX_HEADER_LIST_SIZE, GRPC_CHTTP2_CLAMP_INVALID_VALUE, - GRPC_HTTP2_PROTOCOL_ERROR}, + GRPC_CHTTP2_PROTOCOL_ERROR}, }; static uint8_t *fill_header(uint8_t *out, uint32_t length, uint8_t flags) { diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.c b/src/core/ext/transport/chttp2/transport/hpack_encoder.c index 63df8e135f8..49a8326f627 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.c +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.c @@ -49,7 +49,6 @@ #include "src/core/ext/transport/chttp2/transport/hpack_table.h" #include "src/core/ext/transport/chttp2/transport/varint.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/timeout_encoding.h" @@ -65,10 +64,6 @@ /* don't consider adding anything bigger than this to the hpack table */ #define MAX_DECODER_SPACE_USAGE 512 -static grpc_slice_refcount terminal_slice_refcount = {NULL, NULL}; -static const grpc_slice terminal_slice = {&terminal_slice_refcount, - .data.refcounted = {0, 0}}; - extern int grpc_http_trace; typedef struct { @@ -190,12 +185,9 @@ static void evict_entry(grpc_chttp2_hpack_compressor *c) { /* add an element to the decoder table */ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, - grpc_mdelem elem) { - GPR_ASSERT(GRPC_MDELEM_IS_INTERNED(elem)); - - uint32_t key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); - uint32_t value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); - uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); + grpc_mdelem *elem) { + uint32_t key_hash = elem->key->hash; + uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); uint32_t new_index = c->tail_remote_index + c->table_elems + 1; size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); @@ -220,18 +212,17 @@ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, c->table_elems++; /* Store this element into {entries,indices}_elem */ - if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem)) { + if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem) { /* already there: update with new index */ c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; - } else if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)], - elem)) { + } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem) { /* already there (cuckoo): update with new index */ c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; - } else if (GRPC_MDISNULL(c->entries_elems[HASH_FRAGMENT_2(elem_hash)])) { + } else if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == NULL) { /* not there, but a free element: add */ c->entries_elems[HASH_FRAGMENT_2(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_2(elem_hash)] = new_index; - } else if (GRPC_MDISNULL(c->entries_elems[HASH_FRAGMENT_3(elem_hash)])) { + } else if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == NULL) { /* not there (cuckoo), but a free element: add */ c->entries_elems[HASH_FRAGMENT_3(elem_hash)] = GRPC_MDELEM_REF(elem); c->indices_elems[HASH_FRAGMENT_3(elem_hash)] = new_index; @@ -250,34 +241,24 @@ static void add_elem(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* do exactly the same for the key (so we can find by that again too) */ - if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)], - GRPC_MDKEY(elem))) { + if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key) { c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)], - GRPC_MDKEY(elem))) { + } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key) { c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)].refcount == - &terminal_slice_refcount) { - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = - grpc_slice_ref_internal(GRPC_MDKEY(elem)); + } else if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == NULL) { + c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; - } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)].refcount == - &terminal_slice_refcount) { - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = - grpc_slice_ref_internal(GRPC_MDKEY(elem)); + } else if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == NULL) { + c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } else if (c->indices_keys[HASH_FRAGMENT_2(key_hash)] < c->indices_keys[HASH_FRAGMENT_3(key_hash)]) { - grpc_slice_unref_internal(exec_ctx, - c->entries_keys[HASH_FRAGMENT_2(key_hash)]); - c->entries_keys[HASH_FRAGMENT_2(key_hash)] = - grpc_slice_ref_internal(GRPC_MDKEY(elem)); + GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_2(key_hash)]); + c->entries_keys[HASH_FRAGMENT_2(key_hash)] = GRPC_MDSTR_REF(elem->key); c->indices_keys[HASH_FRAGMENT_2(key_hash)] = new_index; } else { - grpc_slice_unref_internal(exec_ctx, - c->entries_keys[HASH_FRAGMENT_3(key_hash)]); - c->entries_keys[HASH_FRAGMENT_3(key_hash)] = - grpc_slice_ref_internal(GRPC_MDKEY(elem)); + GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[HASH_FRAGMENT_3(key_hash)]); + c->entries_keys[HASH_FRAGMENT_3(key_hash)] = GRPC_MDSTR_REF(elem->key); c->indices_keys[HASH_FRAGMENT_3(key_hash)] = new_index; } } @@ -289,18 +270,20 @@ static void emit_indexed(grpc_chttp2_hpack_compressor *c, uint32_t elem_index, len); } -static grpc_slice get_wire_value(grpc_mdelem elem, uint8_t *huffman_prefix) { - if (grpc_is_binary_header(GRPC_MDKEY(elem))) { +static grpc_slice get_wire_value(grpc_mdelem *elem, uint8_t *huffman_prefix) { + if (grpc_is_binary_header( + (const char *)GRPC_SLICE_START_PTR(elem->key->slice), + GRPC_SLICE_LENGTH(elem->key->slice))) { *huffman_prefix = 0x80; - return grpc_chttp2_base64_encode_and_huffman_compress(GRPC_MDVALUE(elem)); + return grpc_mdstr_as_base64_encoded_and_huffman_compressed(elem->value); } /* TODO(ctiller): opportunistically compress non-binary headers */ *huffman_prefix = 0x00; - return grpc_slice_ref_internal(GRPC_MDVALUE(elem)); + return elem->value->slice; } static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, - uint32_t key_index, grpc_mdelem elem, + uint32_t key_index, grpc_mdelem *elem, framer_state *st) { uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2); uint8_t huffman_prefix; @@ -313,11 +296,11 @@ static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, value_slice); + add_header_data(st, grpc_slice_ref_internal(value_slice)); } static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, - uint32_t key_index, grpc_mdelem elem, + uint32_t key_index, grpc_mdelem *elem, framer_state *st) { uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4); uint8_t huffman_prefix; @@ -330,12 +313,12 @@ static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c, add_tiny_header_data(st, len_pfx), len_pfx); GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, value_slice); + add_header_data(st, grpc_slice_ref_internal(value_slice)); } static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem elem, framer_state *st) { - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + grpc_mdelem *elem, framer_state *st) { + uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key->slice); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice); @@ -346,15 +329,15 @@ static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c, *add_tiny_header_data(st, 1) = 0x40; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, grpc_slice_ref_internal(GRPC_MDKEY(elem))); + add_header_data(st, grpc_slice_ref_internal(elem->key->slice)); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, value_slice); + add_header_data(st, grpc_slice_ref_internal(value_slice)); } static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, - grpc_mdelem elem, framer_state *st) { - uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); + grpc_mdelem *elem, framer_state *st) { + uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(elem->key->slice); uint8_t huffman_prefix; grpc_slice value_slice = get_wire_value(elem, &huffman_prefix); uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice); @@ -365,10 +348,10 @@ static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c, *add_tiny_header_data(st, 1) = 0x00; GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00, add_tiny_header_data(st, len_key_len), len_key_len); - add_header_data(st, grpc_slice_ref_internal(GRPC_MDKEY(elem))); + add_header_data(st, grpc_slice_ref_internal(elem->key->slice)); GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix, add_tiny_header_data(st, len_val_len), len_val_len); - add_header_data(st, value_slice); + add_header_data(st, grpc_slice_ref_internal(value_slice)); } static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c, @@ -386,9 +369,15 @@ static uint32_t dynidx(grpc_chttp2_hpack_compressor *c, uint32_t elem_index) { /* encode an mdelem */ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, - grpc_mdelem elem, framer_state *st) { - GPR_ASSERT(GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)) > 0); - if (GRPC_SLICE_START_PTR(GRPC_MDKEY(elem))[0] != ':') { /* regular header */ + grpc_mdelem *elem, framer_state *st) { + uint32_t key_hash = elem->key->hash; + uint32_t elem_hash = GRPC_MDSTR_KV_HASH(key_hash, elem->value->hash); + size_t decoder_space_usage; + uint32_t indices_key; + int should_add_elem; + + GPR_ASSERT(GRPC_SLICE_LENGTH(elem->key->slice) > 0); + if (GRPC_SLICE_START_PTR(elem->key->slice)[0] != ':') { /* regular header */ st->seen_regular_header = 1; } else { GPR_ASSERT( @@ -396,39 +385,11 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, "Reserved header (colon-prefixed) happening after regular ones."); } - if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(elem)) { - char *k = grpc_slice_to_c_string(GRPC_MDKEY(elem)); - char *v = grpc_slice_to_c_string(GRPC_MDVALUE(elem)); - gpr_log( - GPR_DEBUG, - "Encode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", - k, v, GRPC_MDELEM_IS_INTERNED(elem), GRPC_MDELEM_STORAGE(elem), - grpc_slice_is_interned(GRPC_MDKEY(elem)), - grpc_slice_is_interned(GRPC_MDVALUE(elem))); - gpr_free(k); - gpr_free(v); - } - if (!GRPC_MDELEM_IS_INTERNED(elem)) { - emit_lithdr_noidx_v(c, elem, st); - return; - } - - uint32_t key_hash; - uint32_t value_hash; - uint32_t elem_hash; - size_t decoder_space_usage; - uint32_t indices_key; - int should_add_elem; - - key_hash = grpc_slice_hash(GRPC_MDKEY(elem)); - value_hash = grpc_slice_hash(GRPC_MDVALUE(elem)); - elem_hash = GRPC_MDSTR_KV_HASH(key_hash, value_hash); - inc_filter(HASH_FRAGMENT_1(elem_hash), &c->filter_elems_sum, c->filter_elems); /* is this elem currently in the decoders table? */ - if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_2(elem_hash)], elem) && + if (c->entries_elems[HASH_FRAGMENT_2(elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_2(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (first cuckoo hash) */ emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_2(elem_hash)]), @@ -436,7 +397,7 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, return; } - if (grpc_mdelem_eq(c->entries_elems[HASH_FRAGMENT_3(elem_hash)], elem) && + if (c->entries_elems[HASH_FRAGMENT_3(elem_hash)] == elem && c->indices_elems[HASH_FRAGMENT_3(elem_hash)] > c->tail_remote_index) { /* HIT: complete element (second cuckoo hash) */ emit_indexed(c, dynidx(c, c->indices_elems[HASH_FRAGMENT_3(elem_hash)]), @@ -453,8 +414,7 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, /* no hits for the elem... maybe there's a key? */ indices_key = c->indices_keys[HASH_FRAGMENT_2(key_hash)]; - if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_2(key_hash)], - GRPC_MDKEY(elem)) && + if (c->entries_keys[HASH_FRAGMENT_2(key_hash)] == elem->key && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { @@ -469,8 +429,7 @@ static void hpack_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, } indices_key = c->indices_keys[HASH_FRAGMENT_3(key_hash)]; - if (grpc_slice_eq(c->entries_keys[HASH_FRAGMENT_3(key_hash)], - GRPC_MDKEY(elem)) && + if (c->entries_keys[HASH_FRAGMENT_3(key_hash)] == elem->key && indices_key > c->tail_remote_index) { /* HIT: key (first cuckoo hash) */ if (should_add_elem) { @@ -504,11 +463,11 @@ static void deadline_enc(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c, gpr_timespec deadline, framer_state *st) { char timeout_str[GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE]; - grpc_mdelem mdelem; + grpc_mdelem *mdelem; grpc_http2_encode_timeout( gpr_time_sub(deadline, gpr_now(deadline.clock_type)), timeout_str); - mdelem = grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, - grpc_slice_from_copied_string(timeout_str)); + mdelem = grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_TIMEOUT, grpc_mdstr_from_string(timeout_str)); hpack_enc(exec_ctx, c, mdelem, st); GRPC_MDELEM_UNREF(exec_ctx, mdelem); } @@ -525,19 +484,14 @@ void grpc_chttp2_hpack_compressor_init(grpc_chttp2_hpack_compressor *c) { gpr_malloc(sizeof(*c->table_elem_size) * c->cap_table_elems); memset(c->table_elem_size, 0, sizeof(*c->table_elem_size) * c->cap_table_elems); - for (size_t i = 0; i < GPR_ARRAY_SIZE(c->entries_keys); i++) { - c->entries_keys[i] = terminal_slice; - } } void grpc_chttp2_hpack_compressor_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_compressor *c) { int i; for (i = 0; i < GRPC_CHTTP2_HPACKC_NUM_VALUES; i++) { - if (c->entries_keys[i].refcount != &terminal_slice_refcount) { - grpc_slice_unref_internal(exec_ctx, c->entries_keys[i]); - } - GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); + if (c->entries_keys[i]) GRPC_MDSTR_UNREF(exec_ctx, c->entries_keys[i]); + if (c->entries_elems[i]) GRPC_MDELEM_UNREF(exec_ctx, c->entries_elems[i]); } gpr_free(c->table_elem_size); } diff --git a/src/core/ext/transport/chttp2/transport/hpack_encoder.h b/src/core/ext/transport/chttp2/transport/hpack_encoder.h index 83ba5b1b3e0..3a35496ec8a 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_encoder.h +++ b/src/core/ext/transport/chttp2/transport/hpack_encoder.h @@ -74,8 +74,8 @@ typedef struct { /* entry tables for keys & elems: these tables track values that have been seen and *may* be in the decompressor table */ - grpc_slice entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; - grpc_mdelem entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; + grpc_mdstr *entries_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; + grpc_mdelem *entries_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_keys[GRPC_CHTTP2_HPACKC_NUM_VALUES]; uint32_t indices_elems[GRPC_CHTTP2_HPACKC_NUM_VALUES]; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.c b/src/core/ext/transport/chttp2/transport/hpack_parser.c index 40f5120308c..8b91cc760b8 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.c +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.c @@ -50,13 +50,9 @@ #include #include "src/core/ext/transport/chttp2/transport/bin_encoder.h" +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" -#include "src/core/lib/transport/http2_errors.h" - -/* TODO(ctiller): remove before submission */ -#include "src/core/lib/slice/slice_string_helpers.h" extern int grpc_http_trace; @@ -672,22 +668,8 @@ static const uint8_t inverse_base64[256] = { /* emission helpers */ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_mdelem md, int add_to_table) { - if (grpc_http_trace && !GRPC_MDELEM_IS_INTERNED(md)) { - char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - gpr_log( - GPR_DEBUG, - "Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d", - k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md), - grpc_slice_is_interned(GRPC_MDKEY(md)), - grpc_slice_is_interned(GRPC_MDVALUE(md))); - gpr_free(k); - gpr_free(v); - } + grpc_mdelem *md, int add_to_table) { if (add_to_table) { - GPR_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED || - GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC); grpc_error *err = grpc_chttp2_hptbl_add(exec_ctx, &p->table, md); if (err != GRPC_ERROR_NONE) return err; } @@ -699,28 +681,10 @@ static grpc_error *on_hdr(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, return GRPC_ERROR_NONE; } -static grpc_slice take_string(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hpack_parser *p, - grpc_chttp2_hpack_parser_string *str, - bool intern) { - grpc_slice s; - if (!str->copied) { - if (intern) { - s = grpc_slice_intern(str->data.referenced); - grpc_slice_unref_internal(exec_ctx, str->data.referenced); - } else { - s = str->data.referenced; - } - str->copied = true; - str->data.referenced = grpc_empty_slice(); - } else if (intern) { - s = grpc_slice_intern(grpc_slice_from_static_buffer( - str->data.copied.str, str->data.copied.length)); - } else { - s = grpc_slice_from_copied_buffer(str->data.copied.str, - str->data.copied.length); - } - str->data.copied.length = 0; +static grpc_mdstr *take_string(grpc_chttp2_hpack_parser *p, + grpc_chttp2_hpack_parser_string *str) { + grpc_mdstr *s = grpc_mdstr_from_buffer((uint8_t *)str->str, str->length); + str->length = 0; return s; } @@ -807,8 +771,8 @@ static grpc_error *finish_indexed_field(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - if (GRPC_MDISNULL(md)) { + grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + if (md == NULL) { return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Invalid HPACK index received"), GRPC_ERROR_INT_INDEX, (intptr_t)p->index), @@ -849,13 +813,12 @@ static grpc_error *finish_lithdr_incidx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, true)), - 1); + grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + GPR_ASSERT(md != NULL); /* handled in string parsing */ + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_REF(md->key), + take_string(p, &p->value)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -865,11 +828,10 @@ static grpc_error *finish_lithdr_incidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, true)), - 1); + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 1); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -919,13 +881,12 @@ static grpc_error *finish_lithdr_notidx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, false)), - 0); + grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + GPR_ASSERT(md != NULL); /* handled in string parsing */ + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_REF(md->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -935,11 +896,10 @@ static grpc_error *finish_lithdr_notidx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, false)), - 0); + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -989,13 +949,12 @@ static grpc_error *finish_lithdr_nvridx(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_mdelem md = grpc_chttp2_hptbl_lookup(&p->table, p->index); - GPR_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */ - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(md)), - take_string(exec_ctx, p, &p->value, false)), - 0); + grpc_mdelem *md = grpc_chttp2_hptbl_lookup(&p->table, p->index); + GPR_ASSERT(md != NULL); /* handled in string parsing */ + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_REF(md->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -1005,11 +964,10 @@ static grpc_error *finish_lithdr_nvridx_v(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { - grpc_error *err = on_hdr( - exec_ctx, p, - grpc_mdelem_from_slices(exec_ctx, take_string(exec_ctx, p, &p->key, true), - take_string(exec_ctx, p, &p->value, false)), - 0); + grpc_error *err = on_hdr(exec_ctx, p, grpc_mdelem_from_metadata_strings( + exec_ctx, take_string(p, &p->key), + take_string(p, &p->value)), + 0); if (err != GRPC_ERROR_NONE) return parse_error(exec_ctx, p, cur, end, err); return parse_begin(exec_ctx, p, cur, end); } @@ -1303,15 +1261,14 @@ static grpc_error *parse_string_prefix(grpc_exec_ctx *exec_ctx, static void append_bytes(grpc_chttp2_hpack_parser_string *str, const uint8_t *data, size_t length) { if (length == 0) return; - if (length + str->data.copied.length > str->data.copied.capacity) { - GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX); - str->data.copied.capacity = (uint32_t)(str->data.copied.length + length); - str->data.copied.str = - gpr_realloc(str->data.copied.str, str->data.copied.capacity); + if (length + str->length > str->capacity) { + GPR_ASSERT(str->length + length <= UINT32_MAX); + str->capacity = (uint32_t)(str->length + length); + str->str = gpr_realloc(str->str, str->capacity); } - memcpy(str->data.copied.str + str->data.copied.length, data, length); - GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length); - str->data.copied.length += (uint32_t)length; + memcpy(str->str + str->length, data, length); + GPR_ASSERT(length <= UINT32_MAX - str->length); + str->length += (uint32_t)length; } static grpc_error *append_string(grpc_exec_ctx *exec_ctx, @@ -1394,9 +1351,11 @@ static grpc_error *append_string(grpc_exec_ctx *exec_ctx, exec_ctx, p, cur, end, GRPC_ERROR_CREATE("Should never reach here"))); } +/* append a null terminator to a string */ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, const uint8_t *cur, const uint8_t *end) { + uint8_t terminator = 0; uint8_t decoded[2]; uint32_t bits; grpc_chttp2_hpack_parser_string *str = p->parsing.str; @@ -1437,6 +1396,8 @@ static grpc_error *finish_str(grpc_exec_ctx *exec_ctx, append_bytes(str, decoded, 2); break; } + append_bytes(str, &terminator, 1); + p->parsing.str->length--; /* don't actually count the null terminator */ return GRPC_ERROR_NONE; } @@ -1511,18 +1472,8 @@ static grpc_error *begin_parse_string(grpc_exec_ctx *exec_ctx, const uint8_t *cur, const uint8_t *end, uint8_t binary, grpc_chttp2_hpack_parser_string *str) { - if (!p->huff && binary == NOT_BINARY && (end - cur) >= (intptr_t)p->strlen && - p->current_slice_refcount != NULL) { - str->copied = false; - str->data.referenced.refcount = p->current_slice_refcount; - str->data.referenced.data.refcounted.bytes = (uint8_t *)cur; - str->data.referenced.data.refcounted.length = p->strlen; - grpc_slice_ref_internal(str->data.referenced); - return parse_next(exec_ctx, p, cur + p->strlen, end); - } p->strgot = 0; - str->copied = true; - str->data.copied.length = 0; + str->length = 0; p->parsing.str = str; p->huff_state = 0; p->binary = binary; @@ -1539,22 +1490,21 @@ static grpc_error *parse_key_string(grpc_exec_ctx *exec_ctx, /* check if a key represents a binary header or not */ static bool is_binary_literal_header(grpc_chttp2_hpack_parser *p) { - return grpc_is_binary_header( - p->key.copied ? grpc_slice_from_static_buffer(p->key.data.copied.str, - p->key.data.copied.length) - : p->key.data.referenced); + return grpc_is_binary_header(p->key.str, p->key.length); } static grpc_error *is_binary_indexed_header(grpc_chttp2_hpack_parser *p, bool *is) { - grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); - if (GRPC_MDISNULL(elem)) { + grpc_mdelem *elem = grpc_chttp2_hptbl_lookup(&p->table, p->index); + if (!elem) { return grpc_error_set_int( grpc_error_set_int(GRPC_ERROR_CREATE("Invalid HPACK index received"), GRPC_ERROR_INT_INDEX, (intptr_t)p->index), GRPC_ERROR_INT_SIZE, (intptr_t)p->table.num_ents); } - *is = grpc_is_binary_header(GRPC_MDKEY(elem)); + *is = grpc_is_binary_header( + (const char *)GRPC_SLICE_START_PTR(elem->key->slice), + GRPC_SLICE_LENGTH(elem->key->slice)); return GRPC_ERROR_NONE; } @@ -1589,14 +1539,12 @@ void grpc_chttp2_hpack_parser_init(grpc_exec_ctx *exec_ctx, p->on_header = NULL; p->on_header_user_data = NULL; p->state = parse_begin; - p->key.data.referenced = grpc_empty_slice(); - p->key.data.copied.str = NULL; - p->key.data.copied.capacity = 0; - p->key.data.copied.length = 0; - p->value.data.referenced = grpc_empty_slice(); - p->value.data.copied.str = NULL; - p->value.data.copied.capacity = 0; - p->value.data.copied.length = 0; + p->key.str = NULL; + p->key.capacity = 0; + p->key.length = 0; + p->value.str = NULL; + p->value.capacity = 0; + p->value.length = 0; p->dynamic_table_update_allowed = 2; p->last_error = GRPC_ERROR_NONE; grpc_chttp2_hptbl_init(exec_ctx, &p->table); @@ -1611,24 +1559,19 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p) { grpc_chttp2_hptbl_destroy(exec_ctx, &p->table); GRPC_ERROR_UNREF(p->last_error); - grpc_slice_unref_internal(exec_ctx, p->key.data.referenced); - grpc_slice_unref_internal(exec_ctx, p->value.data.referenced); - gpr_free(p->key.data.copied.str); - gpr_free(p->value.data.copied.str); + gpr_free(p->key.str); + gpr_free(p->value.str); } grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice slice) { + const uint8_t *beg, + const uint8_t *end) { /* TODO(ctiller): limit the distance of end from beg, and perform multiple steps in the event of a large chunk of data to limit stack space usage when no tail call optimization is available */ - p->current_slice_refcount = slice.refcount; - grpc_error *error = p->state(exec_ctx, p, GRPC_SLICE_START_PTR(slice), - GRPC_SLICE_END_PTR(slice)); - p->current_slice_refcount = NULL; - return error; + return p->state(exec_ctx, p, beg, end); } typedef void (*maybe_complete_func_type)(grpc_exec_ctx *exec_ctx, @@ -1644,7 +1587,7 @@ static void force_client_rst_stream(grpc_exec_ctx *exec_ctx, void *sp, grpc_chttp2_transport *t = s->t; if (!s->write_closed) { grpc_slice_buffer_add( - &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR, + &t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_CHTTP2_NO_ERROR, &s->stats.outgoing)); grpc_chttp2_initiate_write(exec_ctx, t, false, "force_rst_stream"); grpc_chttp2_mark_stream_closed(exec_ctx, t, s, true, true, GRPC_ERROR_NONE); @@ -1662,7 +1605,8 @@ grpc_error *grpc_chttp2_header_parser_parse(grpc_exec_ctx *exec_ctx, if (s != NULL) { s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice); } - grpc_error *error = grpc_chttp2_hpack_parser_parse(exec_ctx, parser, slice); + grpc_error *error = grpc_chttp2_hpack_parser_parse( + exec_ctx, parser, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_END_PTR(slice)); if (error != GRPC_ERROR_NONE) { GPR_TIMER_END("grpc_chttp2_hpack_parser_parse", 0); return error; diff --git a/src/core/ext/transport/chttp2/transport/hpack_parser.h b/src/core/ext/transport/chttp2/transport/hpack_parser.h index a817183eb5b..52ccf1e7a73 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_parser.h +++ b/src/core/ext/transport/chttp2/transport/hpack_parser.h @@ -49,20 +49,14 @@ typedef grpc_error *(*grpc_chttp2_hpack_parser_state)( const uint8_t *end); typedef struct { - bool copied; - struct { - grpc_slice referenced; - struct { - char *str; - uint32_t length; - uint32_t capacity; - } copied; - } data; + char *str; + uint32_t length; + uint32_t capacity; } grpc_chttp2_hpack_parser_string; struct grpc_chttp2_hpack_parser { /* user specified callback for each header output */ - void (*on_header)(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem md); + void (*on_header)(grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem *md); void *on_header_user_data; grpc_error *last_error; @@ -73,8 +67,6 @@ struct grpc_chttp2_hpack_parser { const grpc_chttp2_hpack_parser_state *next_state; /* what to do after skipping prioritization data */ grpc_chttp2_hpack_parser_state after_prioritization; - /* the refcount of the slice that we're currently parsing */ - grpc_slice_refcount *current_slice_refcount; /* the value we're currently parsing */ union { uint32_t *value; @@ -114,9 +106,11 @@ void grpc_chttp2_hpack_parser_destroy(grpc_exec_ctx *exec_ctx, void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser *p); +/* returns 1 on success, 0 on error */ grpc_error *grpc_chttp2_hpack_parser_parse(grpc_exec_ctx *exec_ctx, grpc_chttp2_hpack_parser *p, - grpc_slice slice); + const uint8_t *beg, + const uint8_t *end); /* wraps grpc_chttp2_hpack_parser_parse to provide a frame level parser for the transport */ diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.c b/src/core/ext/transport/chttp2/transport/hpack_table.c index 62dd1b8cab4..26d4036d49f 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.c +++ b/src/core/ext/transport/chttp2/transport/hpack_table.c @@ -190,11 +190,8 @@ void grpc_chttp2_hptbl_init(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { tbl->ents = gpr_malloc(sizeof(*tbl->ents) * tbl->cap_entries); memset(tbl->ents, 0, sizeof(*tbl->ents) * tbl->cap_entries); for (i = 1; i <= GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - tbl->static_ents[i - 1] = grpc_mdelem_from_slices( - exec_ctx, - grpc_slice_intern(grpc_slice_from_static_string(static_table[i].key)), - grpc_slice_intern( - grpc_slice_from_static_string(static_table[i].value))); + tbl->static_ents[i - 1] = grpc_mdelem_from_strings( + exec_ctx, static_table[i].key, static_table[i].value); } } @@ -211,8 +208,8 @@ void grpc_chttp2_hptbl_destroy(grpc_exec_ctx *exec_ctx, gpr_free(tbl->ents); } -grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, - uint32_t tbl_index) { +grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, + uint32_t tbl_index) { /* Static table comes first, just return an entry from it */ if (tbl_index <= GRPC_CHTTP2_LAST_STATIC_ENTRY) { return tbl->static_ents[tbl_index - 1]; @@ -225,14 +222,14 @@ grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, return tbl->ents[offset]; } /* Invalid entry: return error */ - return GRPC_MDNULL; + return NULL; } /* Evict one element from the table */ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { - grpc_mdelem first_ent = tbl->ents[tbl->first_ent]; - size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(first_ent)) + - GRPC_SLICE_LENGTH(GRPC_MDVALUE(first_ent)) + + grpc_mdelem *first_ent = tbl->ents[tbl->first_ent]; + size_t elem_bytes = GRPC_SLICE_LENGTH(first_ent->key->slice) + + GRPC_SLICE_LENGTH(first_ent->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; GPR_ASSERT(elem_bytes <= tbl->mem_used); tbl->mem_used -= (uint32_t)elem_bytes; @@ -242,7 +239,7 @@ static void evict1(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl) { } static void rebuild_ents(grpc_chttp2_hptbl *tbl, uint32_t new_cap) { - grpc_mdelem *ents = gpr_malloc(sizeof(*ents) * new_cap); + grpc_mdelem **ents = gpr_malloc(sizeof(*ents) * new_cap); uint32_t i; for (i = 0; i < tbl->num_ents; i++) { @@ -304,10 +301,10 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, } grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, - grpc_chttp2_hptbl *tbl, grpc_mdelem md) { + grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { /* determine how many bytes of buffer this entry represents */ - size_t elem_bytes = GRPC_SLICE_LENGTH(GRPC_MDKEY(md)) + - GRPC_SLICE_LENGTH(GRPC_MDVALUE(md)) + + size_t elem_bytes = GRPC_SLICE_LENGTH(md->key->slice) + + GRPC_SLICE_LENGTH(md->value->slice) + GRPC_CHTTP2_HPACK_ENTRY_OVERHEAD; if (tbl->current_table_bytes > tbl->max_bytes) { @@ -355,16 +352,16 @@ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, } grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem md) { + const grpc_chttp2_hptbl *tbl, grpc_mdelem *md) { grpc_chttp2_hptbl_find_result r = {0, 0}; uint32_t i; /* See if the string is in the static table */ for (i = 0; i < GRPC_CHTTP2_LAST_STATIC_ENTRY; i++) { - grpc_mdelem ent = tbl->static_ents[i]; - if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; + grpc_mdelem *ent = tbl->static_ents[i]; + if (md->key != ent->key) continue; r.index = i + 1u; - r.has_value = grpc_slice_eq(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)); + r.has_value = md->value == ent->value; if (r.has_value) return r; } @@ -372,10 +369,10 @@ grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( for (i = 0; i < tbl->num_ents; i++) { uint32_t idx = (uint32_t)(tbl->num_ents - i + GRPC_CHTTP2_LAST_STATIC_ENTRY); - grpc_mdelem ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; - if (!grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDKEY(ent))) continue; + grpc_mdelem *ent = tbl->ents[(tbl->first_ent + i) % tbl->cap_entries]; + if (md->key != ent->key) continue; r.index = idx; - r.has_value = grpc_slice_eq(GRPC_MDVALUE(md), GRPC_MDVALUE(ent)); + r.has_value = md->value == ent->value; if (r.has_value) return r; } diff --git a/src/core/ext/transport/chttp2/transport/hpack_table.h b/src/core/ext/transport/chttp2/transport/hpack_table.h index 32a0380e009..144574ef06e 100644 --- a/src/core/ext/transport/chttp2/transport/hpack_table.h +++ b/src/core/ext/transport/chttp2/transport/hpack_table.h @@ -79,8 +79,8 @@ typedef struct { /* a circular buffer of headers - this is stored in the opposite order to what hpack specifies, in order to simplify table management a little... meaning lookups need to SUBTRACT from the end position */ - grpc_mdelem *ents; - grpc_mdelem static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY]; + grpc_mdelem **ents; + grpc_mdelem *static_ents[GRPC_CHTTP2_LAST_STATIC_ENTRY]; } grpc_chttp2_hptbl; /* initialize a hpack table */ @@ -94,12 +94,12 @@ grpc_error *grpc_chttp2_hptbl_set_current_table_size(grpc_exec_ctx *exec_ctx, uint32_t bytes); /* lookup a table entry based on its hpack index */ -grpc_mdelem grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, - uint32_t index); +grpc_mdelem *grpc_chttp2_hptbl_lookup(const grpc_chttp2_hptbl *tbl, + uint32_t index); /* add a table entry to the index */ grpc_error *grpc_chttp2_hptbl_add(grpc_exec_ctx *exec_ctx, grpc_chttp2_hptbl *tbl, - grpc_mdelem md) GRPC_MUST_USE_RESULT; + grpc_mdelem *md) GRPC_MUST_USE_RESULT; /* Find a key/value pair in the table... returns the index in the table of the most similar entry, or 0 if the value was not found */ typedef struct { @@ -107,6 +107,6 @@ typedef struct { int has_value; } grpc_chttp2_hptbl_find_result; grpc_chttp2_hptbl_find_result grpc_chttp2_hptbl_find( - const grpc_chttp2_hptbl *tbl, grpc_mdelem md); + const grpc_chttp2_hptbl *tbl, grpc_mdelem *md); #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HPACK_TABLE_H */ diff --git a/src/core/lib/transport/http2_errors.h b/src/core/ext/transport/chttp2/transport/http2_errors.h similarity index 69% rename from src/core/lib/transport/http2_errors.h rename to src/core/ext/transport/chttp2/transport/http2_errors.h index 330bc987f6e..deab2b7e3e8 100644 --- a/src/core/lib/transport/http2_errors.h +++ b/src/core/ext/transport/chttp2/transport/http2_errors.h @@ -31,26 +31,26 @@ * */ -#ifndef GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H -#define GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H +#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H +#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H /* error codes for RST_STREAM from http2 draft 14 section 7 */ typedef enum { - GRPC_HTTP2_NO_ERROR = 0x0, - GRPC_HTTP2_PROTOCOL_ERROR = 0x1, - GRPC_HTTP2_INTERNAL_ERROR = 0x2, - GRPC_HTTP2_FLOW_CONTROL_ERROR = 0x3, - GRPC_HTTP2_SETTINGS_TIMEOUT = 0x4, - GRPC_HTTP2_STREAM_CLOSED = 0x5, - GRPC_HTTP2_FRAME_SIZE_ERROR = 0x6, - GRPC_HTTP2_REFUSED_STREAM = 0x7, - GRPC_HTTP2_CANCEL = 0x8, - GRPC_HTTP2_COMPRESSION_ERROR = 0x9, - GRPC_HTTP2_CONNECT_ERROR = 0xa, - GRPC_HTTP2_ENHANCE_YOUR_CALM = 0xb, - GRPC_HTTP2_INADEQUATE_SECURITY = 0xc, + GRPC_CHTTP2_NO_ERROR = 0x0, + GRPC_CHTTP2_PROTOCOL_ERROR = 0x1, + GRPC_CHTTP2_INTERNAL_ERROR = 0x2, + GRPC_CHTTP2_FLOW_CONTROL_ERROR = 0x3, + GRPC_CHTTP2_SETTINGS_TIMEOUT = 0x4, + GRPC_CHTTP2_STREAM_CLOSED = 0x5, + GRPC_CHTTP2_FRAME_SIZE_ERROR = 0x6, + GRPC_CHTTP2_REFUSED_STREAM = 0x7, + GRPC_CHTTP2_CANCEL = 0x8, + GRPC_CHTTP2_COMPRESSION_ERROR = 0x9, + GRPC_CHTTP2_CONNECT_ERROR = 0xa, + GRPC_CHTTP2_ENHANCE_YOUR_CALM = 0xb, + GRPC_CHTTP2_INADEQUATE_SECURITY = 0xc, /* force use of a default clause */ - GRPC_HTTP2__ERROR_DO_NOT_USE = -1 -} grpc_http2_error_code; + GRPC_CHTTP2__ERROR_DO_NOT_USE = -1 +} grpc_chttp2_error_code; -#endif /* GRPC_CORE_LIB_TRANSPORT_HTTP2_ERRORS_H */ +#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_HTTP2_ERRORS_H */ diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.c b/src/core/ext/transport/chttp2/transport/incoming_metadata.c index c91b019aa05..5d1094999cb 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.c +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.c @@ -57,7 +57,7 @@ void grpc_chttp2_incoming_metadata_buffer_destroy( } void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem) { + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem) { GPR_ASSERT(!buffer->published); if (buffer->capacity == buffer->count) { buffer->capacity = GPR_MAX(8, 2 * buffer->capacity); @@ -68,19 +68,6 @@ void grpc_chttp2_incoming_metadata_buffer_add( buffer->size += GRPC_MDELEM_LENGTH(elem); } -void grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_mdelem elem) { - for (size_t i = 0; i < buffer->count; i++) { - if (grpc_slice_eq(GRPC_MDKEY(buffer->elems[i].md), GRPC_MDKEY(elem))) { - GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md); - buffer->elems[i].md = elem; - return; - } - } - grpc_chttp2_incoming_metadata_buffer_add(buffer, elem); -} - void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline) { GPR_ASSERT(!buffer->published); @@ -88,20 +75,21 @@ void grpc_chttp2_incoming_metadata_buffer_set_deadline( } void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_metadata_batch *batch) { + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch) { GPR_ASSERT(!buffer->published); buffer->published = 1; if (buffer->count > 0) { size_t i; - for (i = 0; i < buffer->count; i++) { - /* TODO(ctiller): do something better here */ - if (!GRPC_LOG_IF_ERROR("grpc_chttp2_incoming_metadata_buffer_publish", - grpc_metadata_batch_link_tail( - exec_ctx, batch, &buffer->elems[i]))) { - GRPC_MDELEM_UNREF(exec_ctx, buffer->elems[i].md); - } + for (i = 1; i < buffer->count; i++) { + buffer->elems[i].prev = &buffer->elems[i - 1]; + } + for (i = 0; i < buffer->count - 1; i++) { + buffer->elems[i].next = &buffer->elems[i + 1]; } + buffer->elems[0].prev = NULL; + buffer->elems[buffer->count - 1].next = NULL; + batch->list.head = &buffer->elems[0]; + batch->list.tail = &buffer->elems[buffer->count - 1]; } else { batch->list.head = batch->list.tail = NULL; } diff --git a/src/core/ext/transport/chttp2/transport/incoming_metadata.h b/src/core/ext/transport/chttp2/transport/incoming_metadata.h index 1eac6fc1504..7a0c4da15f3 100644 --- a/src/core/ext/transport/chttp2/transport/incoming_metadata.h +++ b/src/core/ext/transport/chttp2/transport/incoming_metadata.h @@ -51,14 +51,10 @@ void grpc_chttp2_incoming_metadata_buffer_init( void grpc_chttp2_incoming_metadata_buffer_destroy( grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer); void grpc_chttp2_incoming_metadata_buffer_publish( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_metadata_batch *batch); + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_metadata_batch *batch); void grpc_chttp2_incoming_metadata_buffer_add( - grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem elem); -void grpc_chttp2_incoming_metadata_buffer_replace_or_add( - grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_metadata_buffer *buffer, - grpc_mdelem elem); + grpc_chttp2_incoming_metadata_buffer *buffer, grpc_mdelem *elem); void grpc_chttp2_incoming_metadata_buffer_set_deadline( grpc_chttp2_incoming_metadata_buffer *buffer, gpr_timespec deadline); diff --git a/src/core/ext/transport/chttp2/transport/internal.h b/src/core/ext/transport/chttp2/transport/internal.h index ee5edc92dfa..ea7beb4c2b6 100644 --- a/src/core/ext/transport/chttp2/transport/internal.h +++ b/src/core/ext/transport/chttp2/transport/internal.h @@ -618,7 +618,8 @@ void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase, uint32_t stream_id, int64_t val1, int64_t val2); void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, - grpc_chttp2_stream *stream, grpc_error *error); + grpc_chttp2_stream *stream, + grpc_status_code status, grpc_slice *details); void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s, int close_reads, diff --git a/src/core/ext/transport/chttp2/transport/parsing.c b/src/core/ext/transport/chttp2/transport/parsing.c index f58cd696f9b..4fb5dc7bd2b 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.c +++ b/src/core/ext/transport/chttp2/transport/parsing.c @@ -39,11 +39,10 @@ #include #include +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" +#include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/transport/http2_errors.h" #include "src/core/lib/transport/static_metadata.h" -#include "src/core/lib/transport/status_conversion.h" #include "src/core/lib/transport/timeout_encoding.h" static grpc_error *init_frame_parser(grpc_exec_ctx *exec_ctx, @@ -201,7 +200,7 @@ grpc_error *grpc_chttp2_perform_read(grpc_exec_ctx *exec_ctx, return err; } if (t->incoming_frame_size == 0) { - err = parse_frame_slice(exec_ctx, t, grpc_empty_slice(), 1); + err = parse_frame_slice(exec_ctx, t, gpr_empty_slice(), 1); if (err != GRPC_ERROR_NONE) { return err; } @@ -336,7 +335,7 @@ static grpc_error *skip_parser(grpc_exec_ctx *exec_ctx, void *parser, return GRPC_ERROR_NONE; } -static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem md) { +static void skip_header(grpc_exec_ctx *exec_ctx, void *tp, grpc_mdelem *md) { GRPC_MDELEM_UNREF(exec_ctx, md); } @@ -433,7 +432,7 @@ error_handler: } grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, - GRPC_HTTP2_PROTOCOL_ERROR, + GRPC_CHTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); return init_skip_frame_parser(exec_ctx, t, 0); } else { @@ -444,7 +443,7 @@ error_handler: static void free_timeout(void *p) { gpr_free(p); } static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, - grpc_mdelem md) { + grpc_mdelem *md) { grpc_chttp2_transport *t = tp; grpc_chttp2_stream *s = t->incoming_stream; @@ -452,42 +451,32 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); - if (grpc_http_trace) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *value = - grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, - t->is_client ? "CLI" : "SVR", key, value); - gpr_free(key); - gpr_free(value); - } + GRPC_CHTTP2_IF_TRACING(gpr_log( + GPR_INFO, "HTTP:%d:HDR:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", + grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value))); - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) && - !grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) { + if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; } - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_TIMEOUT)) { + if (md->key == GRPC_MDSTR_GRPC_TIMEOUT) { gpr_timespec *cached_timeout = grpc_mdelem_get_user_data(md, free_timeout); - gpr_timespec timeout; - if (cached_timeout == NULL) { + if (!cached_timeout) { /* not already parsed: parse it now, and store the result away */ cached_timeout = gpr_malloc(sizeof(gpr_timespec)); - if (!grpc_http2_decode_timeout(GRPC_MDVALUE(md), cached_timeout)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", val); - gpr_free(val); + if (!grpc_http2_decode_timeout(grpc_mdstr_as_c_string(md->value), + cached_timeout)) { + gpr_log(GPR_ERROR, "Ignoring bad timeout value '%s'", + grpc_mdstr_as_c_string(md->value)); *cached_timeout = gpr_inf_future(GPR_TIMESPAN); } - timeout = *cached_timeout; - grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); - } else { - timeout = *cached_timeout; + cached_timeout = + grpc_mdelem_set_user_data(md, free_timeout, cached_timeout); } grpc_chttp2_incoming_metadata_buffer_set_deadline( &s->metadata_buffer[0], - gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), timeout)); + gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), *cached_timeout)); GRPC_MDELEM_UNREF(exec_ctx, md); } else { const size_t new_size = s->metadata_buffer[0].size + GRPC_MDELEM_LENGTH(md); @@ -516,7 +505,7 @@ static void on_initial_header(grpc_exec_ctx *exec_ctx, void *tp, } static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, - grpc_mdelem md) { + grpc_mdelem *md) { grpc_chttp2_transport *t = tp; grpc_chttp2_stream *s = t->incoming_stream; @@ -524,18 +513,11 @@ static void on_trailing_header(grpc_exec_ctx *exec_ctx, void *tp, GPR_ASSERT(s != NULL); - if (grpc_http_trace) { - char *key = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *value = - grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, - t->is_client ? "CLI" : "SVR", key, value); - gpr_free(key); - gpr_free(value); - } + GRPC_CHTTP2_IF_TRACING(gpr_log( + GPR_INFO, "HTTP:%d:TRL:%s: %s: %s", s->id, t->is_client ? "CLI" : "SVR", + grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value))); - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_GRPC_STATUS) && - !grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) { + if (md->key == GRPC_MDSTR_GRPC_STATUS && md != GRPC_MDELEM_GRPC_STATUS_0) { /* TODO(ctiller): check for a status like " 0" */ s->seen_error = true; } @@ -751,13 +733,14 @@ static grpc_error *parse_frame_slice(grpc_exec_ctx *exec_ctx, if (grpc_http_trace) { const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "%s", msg); + grpc_error_free_string(msg); } grpc_chttp2_parsing_become_skip_parser(exec_ctx, t); if (s) { s->forced_close_error = err; grpc_slice_buffer_add( &t->qbuf, grpc_chttp2_rst_stream_create(t->incoming_stream_id, - GRPC_HTTP2_PROTOCOL_ERROR, + GRPC_CHTTP2_PROTOCOL_ERROR, &s->stats.outgoing)); } else { GRPC_ERROR_UNREF(err); diff --git a/src/core/lib/transport/status_conversion.c b/src/core/ext/transport/chttp2/transport/status_conversion.c similarity index 78% rename from src/core/lib/transport/status_conversion.c rename to src/core/ext/transport/chttp2/transport/status_conversion.c index af0ac89db75..5dce2f2d0cc 100644 --- a/src/core/lib/transport/status_conversion.c +++ b/src/core/ext/transport/chttp2/transport/status_conversion.c @@ -31,51 +31,51 @@ * */ -#include "src/core/lib/transport/status_conversion.h" +#include "src/core/ext/transport/chttp2/transport/status_conversion.h" -int grpc_status_to_http2_error(grpc_status_code status) { +int grpc_chttp2_grpc_status_to_http2_error(grpc_status_code status) { switch (status) { case GRPC_STATUS_OK: - return GRPC_HTTP2_NO_ERROR; + return GRPC_CHTTP2_NO_ERROR; case GRPC_STATUS_CANCELLED: - return GRPC_HTTP2_CANCEL; + return GRPC_CHTTP2_CANCEL; case GRPC_STATUS_DEADLINE_EXCEEDED: - return GRPC_HTTP2_CANCEL; + return GRPC_CHTTP2_CANCEL; case GRPC_STATUS_RESOURCE_EXHAUSTED: - return GRPC_HTTP2_ENHANCE_YOUR_CALM; + return GRPC_CHTTP2_ENHANCE_YOUR_CALM; case GRPC_STATUS_PERMISSION_DENIED: - return GRPC_HTTP2_INADEQUATE_SECURITY; + return GRPC_CHTTP2_INADEQUATE_SECURITY; case GRPC_STATUS_UNAVAILABLE: - return GRPC_HTTP2_REFUSED_STREAM; + return GRPC_CHTTP2_REFUSED_STREAM; default: - return GRPC_HTTP2_INTERNAL_ERROR; + return GRPC_CHTTP2_INTERNAL_ERROR; } } -grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, - gpr_timespec deadline) { +grpc_status_code grpc_chttp2_http2_error_to_grpc_status( + grpc_chttp2_error_code error, gpr_timespec deadline) { switch (error) { - case GRPC_HTTP2_NO_ERROR: + case GRPC_CHTTP2_NO_ERROR: /* should never be received */ return GRPC_STATUS_INTERNAL; - case GRPC_HTTP2_CANCEL: + case GRPC_CHTTP2_CANCEL: /* http2 cancel translates to STATUS_CANCELLED iff deadline hasn't been * exceeded */ return gpr_time_cmp(gpr_now(deadline.clock_type), deadline) >= 0 ? GRPC_STATUS_DEADLINE_EXCEEDED : GRPC_STATUS_CANCELLED; - case GRPC_HTTP2_ENHANCE_YOUR_CALM: + case GRPC_CHTTP2_ENHANCE_YOUR_CALM: return GRPC_STATUS_RESOURCE_EXHAUSTED; - case GRPC_HTTP2_INADEQUATE_SECURITY: + case GRPC_CHTTP2_INADEQUATE_SECURITY: return GRPC_STATUS_PERMISSION_DENIED; - case GRPC_HTTP2_REFUSED_STREAM: + case GRPC_CHTTP2_REFUSED_STREAM: return GRPC_STATUS_UNAVAILABLE; default: return GRPC_STATUS_INTERNAL; } } -grpc_status_code grpc_http2_status_to_grpc_status(int status) { +grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status) { switch (status) { /* these HTTP2 status codes are called out explicitly in status.proto */ case 200: @@ -110,4 +110,6 @@ grpc_status_code grpc_http2_status_to_grpc_status(int status) { } } -int grpc_status_to_http2_status(grpc_status_code status) { return 200; } +int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status) { + return 200; +} diff --git a/src/core/lib/transport/status_conversion.h b/src/core/ext/transport/chttp2/transport/status_conversion.h similarity index 73% rename from src/core/lib/transport/status_conversion.h rename to src/core/ext/transport/chttp2/transport/status_conversion.h index e6a23a606b4..953bc9f1e1f 100644 --- a/src/core/lib/transport/status_conversion.h +++ b/src/core/ext/transport/chttp2/transport/status_conversion.h @@ -31,19 +31,20 @@ * */ -#ifndef GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H -#define GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H +#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H +#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H #include -#include "src/core/lib/transport/http2_errors.h" +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" /* Conversion of grpc status codes to http2 error codes (for RST_STREAM) */ -grpc_http2_error_code grpc_status_to_http2_error(grpc_status_code status); -grpc_status_code grpc_http2_error_to_grpc_status(grpc_http2_error_code error, - gpr_timespec deadline); +grpc_chttp2_error_code grpc_chttp2_grpc_status_to_http2_error( + grpc_status_code status); +grpc_status_code grpc_chttp2_http2_error_to_grpc_status( + grpc_chttp2_error_code error, gpr_timespec deadline); /* Conversion of HTTP status codes (:status) to grpc status codes */ -grpc_status_code grpc_http2_status_to_grpc_status(int status); -int grpc_status_to_http2_status(grpc_status_code status); +grpc_status_code grpc_chttp2_http2_status_to_grpc_status(int status); +int grpc_chttp2_grpc_status_to_http2_status(grpc_status_code status); -#endif /* GRPC_CORE_LIB_TRANSPORT_STATUS_CONVERSION_H */ +#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_STATUS_CONVERSION_H */ diff --git a/src/core/ext/transport/chttp2/transport/writing.c b/src/core/ext/transport/chttp2/transport/writing.c index 182aff1e3ff..ef2010af7b9 100644 --- a/src/core/ext/transport/chttp2/transport/writing.c +++ b/src/core/ext/transport/chttp2/transport/writing.c @@ -37,9 +37,9 @@ #include +#include "src/core/ext/transport/chttp2/transport/http2_errors.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/transport/http2_errors.h" static void add_to_write_list(grpc_chttp2_write_cb **list, grpc_chttp2_write_cb *cb) { @@ -164,7 +164,7 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, s->sent_trailing_metadata = true; if (!t->is_client && !s->read_closed) { grpc_slice_buffer_add(&t->outbuf, grpc_chttp2_rst_stream_create( - s->id, GRPC_HTTP2_NO_ERROR, + s->id, GRPC_CHTTP2_NO_ERROR, &s->stats.outgoing)); } } @@ -197,7 +197,7 @@ bool grpc_chttp2_begin_write(grpc_exec_ctx *exec_ctx, if (!t->is_client && !s->read_closed) { grpc_slice_buffer_add( &t->outbuf, grpc_chttp2_rst_stream_create( - s->id, GRPC_HTTP2_NO_ERROR, &s->stats.outgoing)); + s->id, GRPC_CHTTP2_NO_ERROR, &s->stats.outgoing)); } now_writing = true; } diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 2683abf47cd..b080408565f 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -44,8 +44,6 @@ #include "src/core/ext/transport/chttp2/transport/incoming_metadata.h" #include "src/core/lib/iomgr/endpoint.h" #include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/metadata_batch.h" @@ -439,11 +437,9 @@ static void on_response_headers_received( for (size_t i = 0; i < headers->count; i++) { grpc_chttp2_incoming_metadata_buffer_add( &s->state.rs.initial_metadata, - grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( - headers->headers[i].key)), - grpc_slice_intern( - grpc_slice_from_static_string(headers->headers[i].value)))); + grpc_mdelem_from_metadata_strings( + &exec_ctx, grpc_mdstr_from_string(headers->headers[i].key), + grpc_mdstr_from_string(headers->headers[i].value))); } s->state.state_callback_received[OP_RECV_INITIAL_METADATA] = true; if (!(s->state.state_op_done[OP_CANCEL_ERROR] || @@ -538,11 +534,9 @@ static void on_response_trailers_received( trailers->headers[i].value); grpc_chttp2_incoming_metadata_buffer_add( &s->state.rs.trailing_metadata, - grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string( - trailers->headers[i].key)), - grpc_slice_intern( - grpc_slice_from_static_string(trailers->headers[i].value)))); + grpc_mdelem_from_metadata_strings( + &exec_ctx, grpc_mdstr_from_string(trailers->headers[i].key), + grpc_mdstr_from_string(trailers->headers[i].value))); s->state.rs.trailing_metadata_valid = true; if (0 == strcmp(trailers->headers[i].key, "grpc-status") && 0 != strcmp(trailers->headers[i].value, "0")) { @@ -622,41 +616,33 @@ static void convert_metadata_to_cronet_headers( curr = head; size_t num_headers = 0; while (num_headers < num_headers_available) { - grpc_mdelem mdelem = curr->md; + grpc_mdelem *mdelem = curr->md; curr = curr->next; - char *key = grpc_slice_to_c_string(GRPC_MDKEY(mdelem)); - char *value = grpc_slice_to_c_string(GRPC_MDVALUE(mdelem)); - if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_SCHEME) || - grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_AUTHORITY)) { + const char *key = grpc_mdstr_as_c_string(mdelem->key); + const char *value = grpc_mdstr_as_c_string(mdelem->value); + if (mdelem->key == GRPC_MDSTR_SCHEME || + mdelem->key == GRPC_MDSTR_AUTHORITY) { /* Cronet populates these fields on its own */ - gpr_free(key); - gpr_free(value); continue; } - if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_METHOD)) { - if (grpc_slice_eq(GRPC_MDVALUE(mdelem), GRPC_MDSTR_PUT)) { + if (mdelem->key == GRPC_MDSTR_METHOD) { + if (mdelem->value == GRPC_MDSTR_PUT) { *method = "PUT"; } else { /* POST method in default*/ *method = "POST"; } - gpr_free(key); - gpr_free(value); continue; } - if (grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_PATH)) { + if (mdelem->key == GRPC_MDSTR_PATH) { /* Create URL by appending :path value to the hostname */ gpr_asprintf(pp_url, "https://%s%s", host, value); - gpr_free(key); - gpr_free(value); continue; } CRONET_LOG(GPR_DEBUG, "header %s = %s", key, value); headers[num_headers].key = key; headers[num_headers].value = value; num_headers++; - gpr_free(key); - gpr_free(value); if (curr == NULL) { break; } @@ -676,7 +662,7 @@ static int parse_grpc_header(const uint8_t *data) { static bool header_has_authority(grpc_linked_mdelem *head) { while (head != NULL) { - if (grpc_slice_eq(GRPC_MDKEY(head->md), GRPC_MDSTR_AUTHORITY)) { + if (head->md->key == GRPC_MDSTR_AUTHORITY) { return true; } head = head->next; @@ -872,8 +858,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, make_error_with_desc(GRPC_STATUS_UNAVAILABLE, "Unavailable.")); } else { grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &oas->s->state.rs.initial_metadata, - stream_op->recv_initial_metadata); + &oas->s->state.rs.initial_metadata, stream_op->recv_initial_metadata); grpc_closure_sched(exec_ctx, stream_op->recv_initial_metadata_ready, GRPC_ERROR_NONE); } @@ -1030,7 +1015,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, CRONET_LOG(GPR_DEBUG, "running: %p OP_RECV_TRAILING_METADATA", oas); if (oas->s->state.rs.trailing_metadata_valid) { grpc_chttp2_incoming_metadata_buffer_publish( - exec_ctx, &oas->s->state.rs.trailing_metadata, + &oas->s->state.rs.trailing_metadata, stream_op->recv_trailing_metadata); stream_state->rs.trailing_metadata_valid = false; } diff --git a/src/core/lib/channel/channel_stack.c b/src/core/lib/channel/channel_stack.c index ec973d4e7f8..8f08b427fb3 100644 --- a/src/core/lib/channel/channel_stack.c +++ b/src/core/lib/channel/channel_stack.c @@ -170,7 +170,7 @@ grpc_error *grpc_call_stack_init( grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, grpc_call_context_element *context, const void *transport_server_data, - grpc_slice path, gpr_timespec start_time, gpr_timespec deadline, + grpc_mdstr *path, gpr_timespec start_time, gpr_timespec deadline, grpc_call_stack *call_stack) { grpc_channel_element *channel_elems = CHANNEL_ELEMS_FROM_STACK(channel_stack); grpc_call_element_args args; @@ -288,10 +288,41 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem) { sizeof(grpc_call_stack))); } -void grpc_call_element_signal_error(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_error *error) { - grpc_transport_stream_op *op = grpc_make_transport_stream_op(NULL); - op->cancel_error = error; +static void destroy_op(grpc_exec_ctx *exec_ctx, void *op, grpc_error *error) { + gpr_free(op); +} + +void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem) { + grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); + memset(op, 0, sizeof(*op)); + op->cancel_error = GRPC_ERROR_CANCELLED; + op->on_complete = + grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); + elem->filter->start_transport_stream_op(exec_ctx, elem, op); +} + +void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_status_code status, + grpc_slice *optional_message) { + grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); + memset(op, 0, sizeof(*op)); + op->on_complete = + grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); + grpc_transport_stream_op_add_cancellation_with_message(exec_ctx, op, status, + optional_message); + elem->filter->start_transport_stream_op(exec_ctx, elem, op); +} + +void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_status_code status, + grpc_slice *optional_message) { + grpc_transport_stream_op *op = gpr_malloc(sizeof(*op)); + memset(op, 0, sizeof(*op)); + op->on_complete = + grpc_closure_create(destroy_op, op, grpc_schedule_on_exec_ctx); + grpc_transport_stream_op_add_close(exec_ctx, op, status, optional_message); elem->filter->start_transport_stream_op(exec_ctx, elem, op); } diff --git a/src/core/lib/channel/channel_stack.h b/src/core/lib/channel/channel_stack.h index 1cf07d43c24..d9d3a852335 100644 --- a/src/core/lib/channel/channel_stack.h +++ b/src/core/lib/channel/channel_stack.h @@ -81,7 +81,7 @@ typedef struct { grpc_call_stack *call_stack; const void *server_transport_data; grpc_call_context_element *context; - grpc_slice path; + grpc_mdstr *path; gpr_timespec start_time; gpr_timespec deadline; } grpc_call_element_args; @@ -238,7 +238,7 @@ grpc_error *grpc_call_stack_init( grpc_exec_ctx *exec_ctx, grpc_channel_stack *channel_stack, int initial_refs, grpc_iomgr_cb_func destroy, void *destroy_arg, grpc_call_context_element *context, const void *transport_server_data, - grpc_slice path, gpr_timespec start_time, gpr_timespec deadline, + grpc_mdstr *path, gpr_timespec start_time, gpr_timespec deadline, grpc_call_stack *call_stack); /* Set a pollset or a pollset_set for a call stack: must occur before the first * op is started */ @@ -299,9 +299,18 @@ grpc_call_stack *grpc_call_stack_from_top_element(grpc_call_element *elem); void grpc_call_log_op(char *file, int line, gpr_log_severity severity, grpc_call_element *elem, grpc_transport_stream_op *op); -void grpc_call_element_signal_error(grpc_exec_ctx *exec_ctx, - grpc_call_element *cur_elem, - grpc_error *error); +void grpc_call_element_send_cancel(grpc_exec_ctx *exec_ctx, + grpc_call_element *cur_elem); + +void grpc_call_element_send_cancel_with_message(grpc_exec_ctx *exec_ctx, + grpc_call_element *cur_elem, + grpc_status_code status, + grpc_slice *optional_message); + +void grpc_call_element_send_close_with_message(grpc_exec_ctx *exec_ctx, + grpc_call_element *cur_elem, + grpc_status_code status, + grpc_slice *optional_message); extern int grpc_trace_channel; diff --git a/src/core/lib/channel/compress_filter.c b/src/core/lib/channel/compress_filter.c index c860d60d881..337c194b798 100644 --- a/src/core/lib/channel/compress_filter.c +++ b/src/core/lib/channel/compress_filter.c @@ -45,7 +45,6 @@ #include "src/core/lib/compression/message_compress.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" @@ -81,6 +80,39 @@ typedef struct channel_data { uint32_t supported_compression_algorithms; } channel_data; +/** For each \a md element from the incoming metadata, filter out the entry for + * "grpc-encoding", using its value to populate the call data's + * compression_algorithm field. */ +static grpc_mdelem *compression_md_filter(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem *md) { + grpc_call_element *elem = user_data; + call_data *calld = elem->call_data; + channel_data *channeld = elem->channel_data; + + if (md->key == GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST) { + const char *md_c_str = grpc_mdstr_as_c_string(md->value); + if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str), + &calld->compression_algorithm)) { + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (unknown). Ignoring.", + md_c_str); + calld->compression_algorithm = GRPC_COMPRESS_NONE; + } + if (!GPR_BITGET(channeld->enabled_algorithms_bitset, + calld->compression_algorithm)) { + gpr_log(GPR_ERROR, + "Invalid compression algorithm: '%s' (previously disabled). " + "Ignoring.", + md_c_str); + calld->compression_algorithm = GRPC_COMPRESS_NONE; + } + calld->has_compression_algorithm = 1; + return NULL; + } + + return md; +} + static int skip_compression(grpc_call_element *elem, uint32_t flags) { call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; @@ -99,65 +131,32 @@ static int skip_compression(grpc_call_element *elem, uint32_t flags) { } /** Filter initial metadata */ -static grpc_error *process_send_initial_metadata( - grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_metadata_batch *initial_metadata) GRPC_MUST_USE_RESULT; -static grpc_error *process_send_initial_metadata( +static void process_send_initial_metadata( grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_metadata_batch *initial_metadata) { - grpc_error *error; call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; /* Parse incoming request for compression. If any, it'll be available * at calld->compression_algorithm */ - if (initial_metadata->idx.named.grpc_internal_encoding_request != NULL) { - grpc_mdelem md = - initial_metadata->idx.named.grpc_internal_encoding_request->md; - if (!grpc_compression_algorithm_parse(GRPC_MDVALUE(md), - &calld->compression_algorithm)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (unknown). Ignoring.", val); - gpr_free(val); - calld->compression_algorithm = GRPC_COMPRESS_NONE; - } - if (!GPR_BITGET(channeld->enabled_algorithms_bitset, - calld->compression_algorithm)) { - char *val = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - gpr_log(GPR_ERROR, - "Invalid compression algorithm: '%s' (previously disabled). " - "Ignoring.", - val); - gpr_free(val); - calld->compression_algorithm = GRPC_COMPRESS_NONE; - } - calld->has_compression_algorithm = 1; - - grpc_metadata_batch_remove( - exec_ctx, initial_metadata, - initial_metadata->idx.named.grpc_internal_encoding_request); - } else { + grpc_metadata_batch_filter(exec_ctx, initial_metadata, compression_md_filter, + elem); + if (!calld->has_compression_algorithm) { /* If no algorithm was found in the metadata and we aren't * exceptionally skipping compression, fall back to the channel * default */ calld->compression_algorithm = channeld->default_compression_algorithm; calld->has_compression_algorithm = 1; /* GPR_TRUE */ } - /* hint compression algorithm */ - error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, &calld->compression_algorithm_storage, + grpc_metadata_batch_add_tail( + initial_metadata, &calld->compression_algorithm_storage, grpc_compression_encoding_mdelem(calld->compression_algorithm)); - if (error != GRPC_ERROR_NONE) return error; - /* convey supported compression algorithms */ - error = grpc_metadata_batch_add_tail( - exec_ctx, initial_metadata, &calld->accept_encoding_storage, - GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( - channeld->supported_compression_algorithms)); - - return error; + grpc_metadata_batch_add_tail(initial_metadata, + &calld->accept_encoding_storage, + GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( + channeld->supported_compression_algorithms)); } static void continue_send_message(grpc_exec_ctx *exec_ctx, @@ -248,12 +247,7 @@ static void compress_start_transport_stream_op(grpc_exec_ctx *exec_ctx, GPR_TIMER_BEGIN("compress_start_transport_stream_op", 0); if (op->send_initial_metadata) { - grpc_error *error = process_send_initial_metadata( - exec_ctx, elem, op->send_initial_metadata); - if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); - return; - } + process_send_initial_metadata(exec_ctx, elem, op->send_initial_metadata); } if (op->send_message != NULL && !skip_compression(elem, op->send_message->flags)) { diff --git a/src/core/lib/channel/deadline_filter.c b/src/core/lib/channel/deadline_filter.c index bc9a2effc28..a45a4d4b820 100644 --- a/src/core/lib/channel/deadline_filter.c +++ b/src/core/lib/channel/deadline_filter.c @@ -56,11 +56,10 @@ static void timer_callback(grpc_exec_ctx* exec_ctx, void* arg, deadline_state->timer_pending = false; gpr_mu_unlock(&deadline_state->timer_mu); if (error != GRPC_ERROR_CANCELLED) { - grpc_call_element_signal_error( - exec_ctx, elem, - grpc_error_set_int(GRPC_ERROR_CREATE("Deadline Exceeded"), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_DEADLINE_EXCEEDED)); + grpc_slice msg = grpc_slice_from_static_string("Deadline Exceeded"); + grpc_call_element_send_cancel_with_message( + exec_ctx, elem, GRPC_STATUS_DEADLINE_EXCEEDED, &msg); + grpc_slice_unref_internal(exec_ctx, msg); } GRPC_CALL_STACK_UNREF(exec_ctx, deadline_state->call_stack, "deadline_timer"); } @@ -197,7 +196,8 @@ void grpc_deadline_state_client_start_transport_stream_op( grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op* op) { grpc_deadline_state* deadline_state = elem->call_data; - if (op->cancel_error != GRPC_ERROR_NONE) { + if (op->cancel_error != GRPC_ERROR_NONE || + op->close_error != GRPC_ERROR_NONE) { cancel_timer_if_needed(exec_ctx, deadline_state); } else { // Make sure we know when the call is complete, so that we can cancel @@ -285,7 +285,8 @@ static void server_start_transport_stream_op(grpc_exec_ctx* exec_ctx, grpc_call_element* elem, grpc_transport_stream_op* op) { server_call_data* calld = elem->call_data; - if (op->cancel_error != GRPC_ERROR_NONE) { + if (op->cancel_error != GRPC_ERROR_NONE || + op->close_error != GRPC_ERROR_NONE) { cancel_timer_if_needed(exec_ctx, &calld->base.deadline_state); } else { // If we're receiving initial metadata, we need to get the deadline diff --git a/src/core/lib/channel/http_client_filter.c b/src/core/lib/channel/http_client_filter.c index 49a2a980e0d..d1544509888 100644 --- a/src/core/lib/channel/http_client_filter.c +++ b/src/core/lib/channel/http_client_filter.c @@ -38,7 +38,6 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/percent_encoding.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/transport_impl.h" @@ -89,104 +88,77 @@ typedef struct call_data { } call_data; typedef struct channel_data { - grpc_mdelem static_scheme; - grpc_mdelem user_agent; + grpc_mdelem *static_scheme; + grpc_mdelem *user_agent; size_t max_payload_size_for_get; } channel_data; -static grpc_error *client_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { - if (b->idx.named.status != NULL) { - if (grpc_mdelem_eq(b->idx.named.status->md, GRPC_MDELEM_STATUS_200)) { - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.status); - } else { - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.status->md), - GPR_DUMP_ASCII); - char *msg; - gpr_asprintf(&msg, "Received http2 header with status: %s", val); - grpc_error *e = grpc_error_set_str( - grpc_error_set_int( - grpc_error_set_str( - GRPC_ERROR_CREATE( - "Received http2 :status header with non-200 OK status"), - GRPC_ERROR_STR_VALUE, val), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_CANCELLED), - GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(val); - gpr_free(msg); - return e; - } - } - - if (b->idx.named.grpc_message != NULL) { - grpc_slice pct_decoded_msg = grpc_permissive_percent_decode_slice( - GRPC_MDVALUE(b->idx.named.grpc_message->md)); - if (grpc_slice_is_equivalent(pct_decoded_msg, - GRPC_MDVALUE(b->idx.named.grpc_message->md))) { +static grpc_mdelem *client_recv_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { + grpc_call_element *elem = user_data; + if (md == GRPC_MDELEM_STATUS_200) { + return NULL; + } else if (md->key == GRPC_MDSTR_STATUS) { + char *message_string; + gpr_asprintf(&message_string, "Received http2 header with status: %s", + grpc_mdstr_as_c_string(md->value)); + grpc_slice message = grpc_slice_from_copied_string(message_string); + gpr_free(message_string); + grpc_call_element_send_close_with_message(exec_ctx, elem, + GRPC_STATUS_CANCELLED, &message); + return NULL; + } else if (md->key == GRPC_MDSTR_GRPC_MESSAGE) { + grpc_slice pct_decoded_msg = + grpc_permissive_percent_decode_slice(md->value->slice); + if (grpc_slice_is_equivalent(pct_decoded_msg, md->value->slice)) { grpc_slice_unref_internal(exec_ctx, pct_decoded_msg); + return md; } else { - grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, - pct_decoded_msg); + return grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_mdstr_from_slice(exec_ctx, pct_decoded_msg)); } - } - - if (b->idx.named.content_type != NULL) { - if (!grpc_mdelem_eq(b->idx.named.content_type->md, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { - if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), - EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(GRPC_MDVALUE( - b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == - '+' || - GRPC_SLICE_START_PTR(GRPC_MDVALUE( - b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == - ';')) { - /* Although the C implementation doesn't (currently) generate them, - any custom +-suffix is explicitly valid. */ - /* TODO(klempner): We should consider preallocating common values such - as +proto or +json, or at least stashing them if we see them. */ - /* TODO(klempner): Should we be surfacing this to application code? */ - } else { - /* TODO(klempner): We're currently allowing this, but we shouldn't - see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), - GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); - gpr_free(val); - } + } else if (md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { + return NULL; + } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { + const char *value_str = grpc_mdstr_as_c_string(md->value); + if (strncmp(value_str, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) == 0 && + (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { + /* Although the C implementation doesn't (currently) generate them, + any custom +-suffix is explicitly valid. */ + /* TODO(klempner): We should consider preallocating common values such + as +proto or +json, or at least stashing them if we see them. */ + /* TODO(klempner): Should we be surfacing this to application code? */ + } else { + /* TODO(klempner): We're currently allowing this, but we shouldn't + see it without a proxy so log for now. */ + gpr_log(GPR_INFO, "Unexpected content-type '%s'", value_str); } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); + return NULL; } - - return GRPC_ERROR_NONE; + return md; } static void hc_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (error == GRPC_ERROR_NONE) { - error = client_filter_incoming_metadata(exec_ctx, elem, - calld->recv_initial_metadata); - } else { - GRPC_ERROR_REF(error); - } - grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error); + grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, + client_recv_filter, elem); + grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, + GRPC_ERROR_REF(error)); } static void hc_on_recv_trailing_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_error *error) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - if (error == GRPC_ERROR_NONE) { - error = client_filter_incoming_metadata(exec_ctx, elem, - calld->recv_trailing_metadata); - } else { - GRPC_ERROR_REF(error); - } - grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, error); + grpc_metadata_batch_filter(exec_ctx, calld->recv_trailing_metadata, + client_recv_filter, elem); + grpc_closure_run(exec_ctx, calld->on_done_recv_trailing_metadata, + GRPC_ERROR_REF(error)); } static void hc_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, @@ -207,12 +179,15 @@ static void send_done(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { calld->post_send->cb(exec_ctx, calld->post_send->cb_arg, error); } -static void remove_if_present(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_metadata_batch_callouts_index idx) { - if (batch->idx.array[idx] != NULL) { - grpc_metadata_batch_remove(exec_ctx, batch, batch->idx.array[idx]); - } +static grpc_mdelem *client_strip_filter(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem *md) { + /* eat the things we'd like to set ourselves */ + if (md->key == GRPC_MDSTR_METHOD) return NULL; + if (md->key == GRPC_MDSTR_SCHEME) return NULL; + if (md->key == GRPC_MDSTR_TE) return NULL; + if (md->key == GRPC_MDSTR_CONTENT_TYPE) return NULL; + if (md->key == GRPC_MDSTR_USER_AGENT) return NULL; + return md; } static void continue_send_message(grpc_exec_ctx *exec_ctx, @@ -251,20 +226,18 @@ static void got_slice(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) { } } -static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_transport_stream_op *op) { +static void hc_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_transport_stream_op *op) { /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; channel_data *channeld = elem->channel_data; - grpc_error *error; if (op->send_initial_metadata != NULL) { /* Decide which HTTP VERB to use. We use GET if the request is marked cacheable, and the operation contains both initial metadata and send message, and the payload is below the size threshold, and all the data for this request is immediately available. */ - grpc_mdelem method = GRPC_MDELEM_METHOD_POST; + grpc_mdelem *method = GRPC_MDELEM_METHOD_POST; if ((op->send_initial_metadata_flags & GRPC_INITIAL_METADATA_CACHEABLE_REQUEST) && op->send_message != NULL && @@ -281,7 +254,7 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, } /* Attempt to read the data from send_message and create a header field. */ - if (grpc_mdelem_eq(method, GRPC_MDELEM_METHOD_GET)) { + if (method == GRPC_MDELEM_METHOD_GET) { /* allocate memory to hold the entire payload */ calld->payload_bytes = gpr_malloc(op->send_message->length); @@ -294,14 +267,12 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, if (calld->send_message_blocked == false) { /* when all the send_message data is available, then create a MDELEM and append to headers */ - grpc_mdelem payload_bin = grpc_mdelem_from_slices( + grpc_mdelem *payload_bin = grpc_mdelem_from_metadata_strings( exec_ctx, GRPC_MDSTR_GRPC_PAYLOAD_BIN, - grpc_slice_from_copied_buffer((const char *)calld->payload_bytes, - op->send_message->length)); - error = - grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, - &calld->payload_bin, payload_bin); - if (error != GRPC_ERROR_NONE) return error; + grpc_mdstr_from_buffer(calld->payload_bytes, + op->send_message->length)); + grpc_metadata_batch_add_tail(op->send_initial_metadata, + &calld->payload_bin, payload_bin); calld->on_complete = op->on_complete; op->on_complete = &calld->hc_on_complete; op->send_message = NULL; @@ -314,35 +285,21 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, } } - remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_METHOD); - remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_SCHEME); - remove_if_present(exec_ctx, op->send_initial_metadata, GRPC_BATCH_TE); - remove_if_present(exec_ctx, op->send_initial_metadata, - GRPC_BATCH_CONTENT_TYPE); - remove_if_present(exec_ctx, op->send_initial_metadata, - GRPC_BATCH_USER_AGENT); - + grpc_metadata_batch_filter(exec_ctx, op->send_initial_metadata, + client_strip_filter, elem); /* Send : prefixed headers, which have to be before any application layer headers. */ - error = grpc_metadata_batch_add_head(exec_ctx, op->send_initial_metadata, - &calld->method, method); - if (error != GRPC_ERROR_NONE) return error; - error = - grpc_metadata_batch_add_head(exec_ctx, op->send_initial_metadata, - &calld->scheme, channeld->static_scheme); - if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, - &calld->te_trailers, - GRPC_MDELEM_TE_TRAILERS); - if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_tail( - exec_ctx, op->send_initial_metadata, &calld->content_type, + grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->method, + method); + grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->scheme, + channeld->static_scheme); + grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->te_trailers, + GRPC_MDELEM_TE_TRAILERS); + grpc_metadata_batch_add_tail( + op->send_initial_metadata, &calld->content_type, GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); - if (error != GRPC_ERROR_NONE) return error; - error = grpc_metadata_batch_add_tail(exec_ctx, op->send_initial_metadata, - &calld->user_agent, - GRPC_MDELEM_REF(channeld->user_agent)); - if (error != GRPC_ERROR_NONE) return error; + grpc_metadata_batch_add_tail(op->send_initial_metadata, &calld->user_agent, + GRPC_MDELEM_REF(channeld->user_agent)); } if (op->recv_initial_metadata != NULL) { @@ -358,8 +315,6 @@ static grpc_error *hc_mutate_op(grpc_exec_ctx *exec_ctx, calld->on_done_recv_trailing_metadata = op->on_complete; op->on_complete = &calld->hc_on_recv_trailing_metadata; } - - return GRPC_ERROR_NONE; } static void hc_start_transport_op(grpc_exec_ctx *exec_ctx, @@ -367,20 +322,15 @@ static void hc_start_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op) { GPR_TIMER_BEGIN("hc_start_transport_op", 0); GRPC_CALL_LOG_OP(GPR_INFO, elem, op); - grpc_error *error = hc_mutate_op(exec_ctx, elem, op); - if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + hc_mutate_op(exec_ctx, elem, op); + GPR_TIMER_END("hc_start_transport_op", 0); + call_data *calld = elem->call_data; + if (op->send_message != NULL && calld->send_message_blocked) { + /* Don't forward the op. send_message contains slices that aren't ready + yet. The call will be forwarded by the op_complete of slice read call. */ } else { - call_data *calld = elem->call_data; - if (op->send_message != NULL && calld->send_message_blocked) { - /* Don't forward the op. send_message contains slices that aren't ready - yet. The call will be forwarded by the op_complete of slice read call. - */ - } else { - grpc_call_next_op(exec_ctx, elem, op); - } + grpc_call_next_op(exec_ctx, elem, op); } - GPR_TIMER_END("hc_start_transport_op", 0); } /* Constructor for call_data */ @@ -417,18 +367,18 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices); } -static grpc_mdelem scheme_from_args(const grpc_channel_args *args) { +static grpc_mdelem *scheme_from_args(const grpc_channel_args *args) { unsigned i; size_t j; - grpc_mdelem valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, - GRPC_MDELEM_SCHEME_HTTPS}; + grpc_mdelem *valid_schemes[] = {GRPC_MDELEM_SCHEME_HTTP, + GRPC_MDELEM_SCHEME_HTTPS}; if (args != NULL) { for (i = 0; i < args->num_args; ++i) { if (args->args[i].type == GRPC_ARG_STRING && strcmp(args->args[i].key, GRPC_ARG_HTTP2_SCHEME) == 0) { for (j = 0; j < GPR_ARRAY_SIZE(valid_schemes); j++) { - if (0 == grpc_slice_str_cmp(GRPC_MDVALUE(valid_schemes[j]), - args->args[i].value.string)) { + if (0 == strcmp(grpc_mdstr_as_c_string(valid_schemes[j]->value), + args->args[i].value.string)) { return valid_schemes[j]; } } @@ -454,13 +404,13 @@ static size_t max_payload_size_from_args(const grpc_channel_args *args) { return kMaxPayloadSizeForGet; } -static grpc_slice user_agent_from_args(const grpc_channel_args *args, - const char *transport_name) { +static grpc_mdstr *user_agent_from_args(const grpc_channel_args *args, + const char *transport_name) { gpr_strvec v; size_t i; int is_first = 1; char *tmp; - grpc_slice result; + grpc_mdstr *result; gpr_strvec_init(&v); @@ -498,7 +448,7 @@ static grpc_slice user_agent_from_args(const grpc_channel_args *args, tmp = gpr_strvec_flatten(&v, NULL); gpr_strvec_destroy(&v); - result = grpc_slice_intern(grpc_slice_from_static_string(tmp)); + result = grpc_mdstr_from_string(tmp); gpr_free(tmp); return result; @@ -514,7 +464,7 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx, chand->static_scheme = scheme_from_args(args->channel_args); chand->max_payload_size_for_get = max_payload_size_from_args(args->channel_args); - chand->user_agent = grpc_mdelem_from_slices( + chand->user_agent = grpc_mdelem_from_metadata_strings( exec_ctx, GRPC_MDSTR_USER_AGENT, user_agent_from_args(args->channel_args, args->optional_transport->vtable->name)); diff --git a/src/core/lib/channel/http_server_filter.c b/src/core/lib/channel/http_server_filter.c index 3f992977c08..f5082312383 100644 --- a/src/core/lib/channel/http_server_filter.c +++ b/src/core/lib/channel/http_server_filter.c @@ -39,7 +39,6 @@ #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/percent_encoding.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/transport/static_metadata.h" #define EXPECTED_CONTENT_TYPE "application/grpc" @@ -48,13 +47,18 @@ extern int grpc_http_trace; typedef struct call_data { + uint8_t seen_path; + uint8_t seen_method; + uint8_t sent_status; + uint8_t seen_scheme; + uint8_t seen_te_trailers; + uint8_t seen_authority; + uint8_t seen_payload_bin; grpc_linked_mdelem status; grpc_linked_mdelem content_type; - /* did this request come with payload-bin */ - bool seen_payload_bin; /* flag to ensure payload_bin is delivered only once */ - bool payload_bin_delivered; + uint8_t payload_bin_delivered; grpc_metadata_batch *recv_initial_metadata; bool *recv_idempotent_request; @@ -79,152 +83,109 @@ typedef struct call_data { typedef struct channel_data { uint8_t unused; } channel_data; -static grpc_error *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { - if (b->idx.named.grpc_message != NULL) { +static grpc_mdelem *server_filter_outgoing_metadata(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem *md) { + if (md->key == GRPC_MDSTR_GRPC_MESSAGE) { grpc_slice pct_encoded_msg = grpc_percent_encode_slice( - GRPC_MDVALUE(b->idx.named.grpc_message->md), - grpc_compatible_percent_encoding_unreserved_bytes); - if (grpc_slice_is_equivalent(pct_encoded_msg, - GRPC_MDVALUE(b->idx.named.grpc_message->md))) { + md->value->slice, grpc_compatible_percent_encoding_unreserved_bytes); + if (grpc_slice_is_equivalent(pct_encoded_msg, md->value->slice)) { grpc_slice_unref_internal(exec_ctx, pct_encoded_msg); + return md; } else { - grpc_metadata_batch_set_value(exec_ctx, b->idx.named.grpc_message, - pct_encoded_msg); + return grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_mdstr_from_slice(exec_ctx, pct_encoded_msg)); } + } else { + return md; } - return GRPC_ERROR_NONE; -} - -static void add_error(const char *error_name, grpc_error **cumulative, - grpc_error *new) { - if (new == GRPC_ERROR_NONE) return; - if (*cumulative == GRPC_ERROR_NONE) { - *cumulative = GRPC_ERROR_CREATE(error_name); - } - *cumulative = grpc_error_add_child(*cumulative, new); } -static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx, - grpc_call_element *elem, - grpc_metadata_batch *b) { +static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { + grpc_call_element *elem = user_data; call_data *calld = elem->call_data; - grpc_error *error = GRPC_ERROR_NONE; - static const char *error_name = "Failed processing incoming headers"; - if (b->idx.named.method != NULL) { - if (grpc_mdelem_eq(b->idx.named.method->md, GRPC_MDELEM_METHOD_POST)) { + /* Check if it is one of the headers we care about. */ + if (md == GRPC_MDELEM_TE_TRAILERS || md == GRPC_MDELEM_METHOD_POST || + md == GRPC_MDELEM_METHOD_PUT || md == GRPC_MDELEM_METHOD_GET || + md == GRPC_MDELEM_SCHEME_HTTP || md == GRPC_MDELEM_SCHEME_HTTPS || + md == GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC) { + /* swallow it */ + if (md == GRPC_MDELEM_METHOD_POST) { + calld->seen_method = 1; *calld->recv_idempotent_request = false; *calld->recv_cacheable_request = false; - } else if (grpc_mdelem_eq(b->idx.named.method->md, - GRPC_MDELEM_METHOD_PUT)) { + } else if (md == GRPC_MDELEM_METHOD_PUT) { + calld->seen_method = 1; *calld->recv_idempotent_request = true; - } else if (grpc_mdelem_eq(b->idx.named.method->md, - GRPC_MDELEM_METHOD_GET)) { + } else if (md == GRPC_MDELEM_METHOD_GET) { + calld->seen_method = 1; *calld->recv_cacheable_request = true; - } else { - add_error(error_name, &error, - grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), - b->idx.named.method->md)); - } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.method); - } else { - add_error(error_name, &error, - grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), - GRPC_ERROR_STR_KEY, ":method")); - } - - if (b->idx.named.te != NULL) { - if (!grpc_mdelem_eq(b->idx.named.te->md, GRPC_MDELEM_TE_TRAILERS)) { - add_error(error_name, &error, - grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), - b->idx.named.te->md)); + } else if (md->key == GRPC_MDSTR_SCHEME) { + calld->seen_scheme = 1; + } else if (md == GRPC_MDELEM_TE_TRAILERS) { + calld->seen_te_trailers = 1; } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.te); - } else { - add_error(error_name, &error, - grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), - GRPC_ERROR_STR_KEY, "te")); - } - - if (b->idx.named.scheme != NULL) { - if (!grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTP) && - !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_HTTPS) && - !grpc_mdelem_eq(b->idx.named.scheme->md, GRPC_MDELEM_SCHEME_GRPC)) { - add_error(error_name, &error, - grpc_attach_md_to_error(GRPC_ERROR_CREATE("Bad header"), - b->idx.named.scheme->md)); + /* TODO(klempner): Track that we've seen all the headers we should + require */ + return NULL; + } else if (md->key == GRPC_MDSTR_CONTENT_TYPE) { + const char *value_str = grpc_mdstr_as_c_string(md->value); + if (strncmp(value_str, EXPECTED_CONTENT_TYPE, + EXPECTED_CONTENT_TYPE_LENGTH) == 0 && + (value_str[EXPECTED_CONTENT_TYPE_LENGTH] == '+' || + value_str[EXPECTED_CONTENT_TYPE_LENGTH] == ';')) { + /* Although the C implementation doesn't (currently) generate them, + any custom +-suffix is explicitly valid. */ + /* TODO(klempner): We should consider preallocating common values such + as +proto or +json, or at least stashing them if we see them. */ + /* TODO(klempner): Should we be surfacing this to application code? */ + } else { + /* TODO(klempner): We're currently allowing this, but we shouldn't + see it without a proxy so log for now. */ + gpr_log(GPR_INFO, "Unexpected content-type '%s'", value_str); } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.scheme); - } else { - add_error(error_name, &error, - grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), - GRPC_ERROR_STR_KEY, ":scheme")); - } - - if (b->idx.named.content_type != NULL) { - if (!grpc_mdelem_eq(b->idx.named.content_type->md, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)) { - if (grpc_slice_buf_start_eq(GRPC_MDVALUE(b->idx.named.content_type->md), - EXPECTED_CONTENT_TYPE, - EXPECTED_CONTENT_TYPE_LENGTH) && - (GRPC_SLICE_START_PTR(GRPC_MDVALUE( - b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == - '+' || - GRPC_SLICE_START_PTR(GRPC_MDVALUE( - b->idx.named.content_type->md))[EXPECTED_CONTENT_TYPE_LENGTH] == - ';')) { - /* Although the C implementation doesn't (currently) generate them, - any custom +-suffix is explicitly valid. */ - /* TODO(klempner): We should consider preallocating common values such - as +proto or +json, or at least stashing them if we see them. */ - /* TODO(klempner): Should we be surfacing this to application code? */ - } else { - /* TODO(klempner): We're currently allowing this, but we shouldn't - see it without a proxy so log for now. */ - char *val = grpc_dump_slice(GRPC_MDVALUE(b->idx.named.content_type->md), - GPR_DUMP_ASCII); - gpr_log(GPR_INFO, "Unexpected content-type '%s'", val); - gpr_free(val); - } + return NULL; + } else if (md->key == GRPC_MDSTR_TE || md->key == GRPC_MDSTR_METHOD || + md->key == GRPC_MDSTR_SCHEME) { + gpr_log(GPR_ERROR, "Invalid %s: header: '%s'", + grpc_mdstr_as_c_string(md->key), grpc_mdstr_as_c_string(md->value)); + /* swallow it and error everything out. */ + /* TODO(klempner): We ought to generate more descriptive error messages + on the wire here. */ + grpc_call_element_send_cancel(exec_ctx, elem); + return NULL; + } else if (md->key == GRPC_MDSTR_PATH) { + if (calld->seen_path) { + gpr_log(GPR_ERROR, "Received :path twice"); + return NULL; } - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.content_type); - } - - if (b->idx.named.path == NULL) { - add_error(error_name, &error, - grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), - GRPC_ERROR_STR_KEY, ":path")); - } - - if (b->idx.named.host != NULL) { - add_error( - error_name, &error, - grpc_metadata_batch_substitute( - exec_ctx, b, b->idx.named.host, - grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref_internal(GRPC_MDVALUE(b->idx.named.host->md))))); - } - - if (b->idx.named.authority == NULL) { - add_error(error_name, &error, - grpc_error_set_str(GRPC_ERROR_CREATE("Missing header"), - GRPC_ERROR_STR_KEY, ":authority")); - } - - if (b->idx.named.grpc_payload_bin != NULL) { - calld->seen_payload_bin = true; + calld->seen_path = 1; + return md; + } else if (md->key == GRPC_MDSTR_AUTHORITY) { + calld->seen_authority = 1; + return md; + } else if (md->key == GRPC_MDSTR_HOST) { + /* translate host to :authority since :authority may be + omitted */ + grpc_mdelem *authority = grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_AUTHORITY, GRPC_MDSTR_REF(md->value)); + calld->seen_authority = 1; + return authority; + } else if (md->key == GRPC_MDSTR_GRPC_PAYLOAD_BIN) { + /* Retrieve the payload from the value of the 'grpc-internal-payload-bin' + header field */ + calld->seen_payload_bin = 1; grpc_slice_buffer_add(&calld->read_slice_buffer, - grpc_slice_ref_internal( - GRPC_MDVALUE(b->idx.named.grpc_payload_bin->md))); + grpc_slice_ref_internal(md->value->slice)); grpc_slice_buffer_stream_init(&calld->read_stream, &calld->read_slice_buffer, 0); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_payload_bin); + return NULL; + } else { + return md; } - - return error; } static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, @@ -232,12 +193,49 @@ static void hs_on_recv(grpc_exec_ctx *exec_ctx, void *user_data, grpc_call_element *elem = user_data; call_data *calld = elem->call_data; if (err == GRPC_ERROR_NONE) { - err = server_filter_incoming_metadata(exec_ctx, elem, - calld->recv_initial_metadata); + grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, + server_filter, elem); + /* Have we seen the required http2 transport headers? + (:method, :scheme, content-type, with :path and :authority covered + at the channel level right now) */ + if (calld->seen_method && calld->seen_scheme && calld->seen_te_trailers && + calld->seen_path && calld->seen_authority) { + /* do nothing */ + } else { + err = GRPC_ERROR_CREATE("Bad incoming HTTP headers"); + if (!calld->seen_path) { + err = grpc_error_add_child(err, + GRPC_ERROR_CREATE("Missing :path header")); + } + if (!calld->seen_authority) { + err = grpc_error_add_child( + err, GRPC_ERROR_CREATE("Missing :authority header")); + } + if (!calld->seen_method) { + err = grpc_error_add_child(err, + GRPC_ERROR_CREATE("Missing :method header")); + } + if (!calld->seen_scheme) { + err = grpc_error_add_child(err, + GRPC_ERROR_CREATE("Missing :scheme header")); + } + if (!calld->seen_te_trailers) { + err = grpc_error_add_child( + err, GRPC_ERROR_CREATE("Missing te: trailers header")); + } + /* Error this call out */ + if (grpc_http_trace) { + const char *error_str = grpc_error_string(err); + gpr_log(GPR_ERROR, "Invalid http2 headers: %s", error_str); + grpc_error_free_string(error_str); + } + grpc_call_element_send_cancel(exec_ctx, elem); + } } else { GRPC_ERROR_REF(err); } - grpc_closure_run(exec_ctx, calld->on_done_recv, err); + calld->on_done_recv->cb(exec_ctx, calld->on_done_recv->cb_arg, err); + GRPC_ERROR_UNREF(err); } static void hs_on_complete(grpc_exec_ctx *exec_ctx, void *user_data, @@ -275,23 +273,13 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, /* grab pointers to our data from the call element */ call_data *calld = elem->call_data; - if (op->send_initial_metadata != NULL) { - grpc_error *error = GRPC_ERROR_NONE; - static const char *error_name = "Failed sending initial metadata"; - add_error(error_name, &error, grpc_metadata_batch_add_head( - exec_ctx, op->send_initial_metadata, - &calld->status, GRPC_MDELEM_STATUS_200)); - add_error(error_name, &error, - grpc_metadata_batch_add_tail( - exec_ctx, op->send_initial_metadata, &calld->content_type, - GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC)); - add_error(error_name, &error, - server_filter_outgoing_metadata(exec_ctx, elem, - op->send_initial_metadata)); - if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); - return; - } + if (op->send_initial_metadata != NULL && !calld->sent_status) { + calld->sent_status = 1; + grpc_metadata_batch_add_head(op->send_initial_metadata, &calld->status, + GRPC_MDELEM_STATUS_200); + grpc_metadata_batch_add_tail( + op->send_initial_metadata, &calld->content_type, + GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC); } if (op->recv_initial_metadata) { @@ -318,12 +306,8 @@ static void hs_mutate_op(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, } if (op->send_trailing_metadata) { - grpc_error *error = server_filter_outgoing_metadata( - exec_ctx, elem, op->send_trailing_metadata); - if (error != GRPC_ERROR_NONE) { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); - return; - } + grpc_metadata_batch_filter(exec_ctx, op->send_trailing_metadata, + server_filter_outgoing_metadata, elem); } } diff --git a/src/core/lib/channel/message_size_filter.c b/src/core/lib/channel/message_size_filter.c index d9862c5252b..862090b371c 100644 --- a/src/core/lib/channel/message_size_filter.c +++ b/src/core/lib/channel/message_size_filter.c @@ -58,7 +58,7 @@ static void message_size_limits_free(grpc_exec_ctx* exec_ctx, void* value) { gpr_free(value); } -static const grpc_slice_hash_table_vtable message_size_limits_vtable = { +static const grpc_mdstr_hash_table_vtable message_size_limits_vtable = { message_size_limits_free, message_size_limits_copy}; static void* message_size_limits_create_from_json(const grpc_json* json) { @@ -101,7 +101,7 @@ typedef struct channel_data { int max_send_size; int max_recv_size; // Maps path names to message_size_limits structs. - grpc_slice_hash_table* method_limit_table; + grpc_mdstr_hash_table* method_limit_table; } channel_data; // Callback invoked when we receive a message. Here we check the max @@ -142,12 +142,10 @@ static void start_transport_stream_op(grpc_exec_ctx* exec_ctx, char* message_string; gpr_asprintf(&message_string, "Sent message larger than max (%u vs. %d)", op->send_message->length, calld->max_send_size); - grpc_transport_stream_op_finish_with_failure( - exec_ctx, op, grpc_error_set_int(GRPC_ERROR_CREATE(message_string), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_INVALID_ARGUMENT)); + grpc_slice message = grpc_slice_from_copied_string(message_string); gpr_free(message_string); - return; + grpc_call_element_send_close_with_message( + exec_ctx, elem, GRPC_STATUS_INVALID_ARGUMENT, &message); } // Inject callback for receiving a message. if (op->recv_message_ready != NULL) { @@ -245,7 +243,7 @@ static grpc_error* init_channel_elem(grpc_exec_ctx* exec_ctx, static void destroy_channel_elem(grpc_exec_ctx* exec_ctx, grpc_channel_element* elem) { channel_data* chand = elem->channel_data; - grpc_slice_hash_table_unref(exec_ctx, chand->method_limit_table); + grpc_mdstr_hash_table_unref(exec_ctx, chand->method_limit_table); } const grpc_channel_filter grpc_message_size_filter = { diff --git a/src/core/lib/compression/algorithm_metadata.h b/src/core/lib/compression/algorithm_metadata.h index 58dfe628b49..1f9cc15f230 100644 --- a/src/core/lib/compression/algorithm_metadata.h +++ b/src/core/lib/compression/algorithm_metadata.h @@ -38,16 +38,16 @@ #include "src/core/lib/transport/metadata.h" /** Return compression algorithm based metadata value */ -grpc_slice grpc_compression_algorithm_slice( +grpc_mdstr *grpc_compression_algorithm_mdstr( grpc_compression_algorithm algorithm); /** Return compression algorithm based metadata element (grpc-encoding: xxx) */ -grpc_mdelem grpc_compression_encoding_mdelem( +grpc_mdelem *grpc_compression_encoding_mdelem( grpc_compression_algorithm algorithm); /** Find compression algorithm based on passed in mdstr - returns * GRPC_COMPRESS_ALGORITHM_COUNT on failure */ -grpc_compression_algorithm grpc_compression_algorithm_from_slice( - grpc_slice str); +grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( + grpc_mdstr *str); #endif /* GRPC_CORE_LIB_COMPRESSION_ALGORITHM_METADATA_H */ diff --git a/src/core/lib/compression/compression.c b/src/core/lib/compression/compression.c index ce4f597af56..54efb5e855c 100644 --- a/src/core/lib/compression/compression.c +++ b/src/core/lib/compression/compression.c @@ -41,24 +41,30 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/transport/static_metadata.h" -int grpc_compression_algorithm_parse(grpc_slice name, +int grpc_compression_algorithm_parse(const char *name, size_t name_length, grpc_compression_algorithm *algorithm) { /* we use strncmp not only because it's safer (even though in this case it * doesn't matter, given that we are comparing against string literals, but * because this way we needn't have "name" nil-terminated (useful for slice * data, for example) */ - if (grpc_slice_eq(name, GRPC_MDSTR_IDENTITY)) { + GRPC_API_TRACE( + "grpc_compression_algorithm_parse(" + "name=%*.*s, name_length=%lu, algorithm=%p)", + 5, ((int)name_length, (int)name_length, name, (unsigned long)name_length, + algorithm)); + if (name_length == 0) { + return 0; + } + if (strncmp(name, "identity", name_length) == 0) { *algorithm = GRPC_COMPRESS_NONE; - return 1; - } else if (grpc_slice_eq(name, GRPC_MDSTR_GZIP)) { + } else if (strncmp(name, "gzip", name_length) == 0) { *algorithm = GRPC_COMPRESS_GZIP; - return 1; - } else if (grpc_slice_eq(name, GRPC_MDSTR_DEFLATE)) { + } else if (strncmp(name, "deflate", name_length) == 0) { *algorithm = GRPC_COMPRESS_DEFLATE; - return 1; } else { return 0; } + return 1; } int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, @@ -81,15 +87,15 @@ int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, return 0; } -grpc_compression_algorithm grpc_compression_algorithm_from_slice( - grpc_slice str) { - if (grpc_slice_eq(str, GRPC_MDSTR_IDENTITY)) return GRPC_COMPRESS_NONE; - if (grpc_slice_eq(str, GRPC_MDSTR_DEFLATE)) return GRPC_COMPRESS_DEFLATE; - if (grpc_slice_eq(str, GRPC_MDSTR_GZIP)) return GRPC_COMPRESS_GZIP; +grpc_compression_algorithm grpc_compression_algorithm_from_mdstr( + grpc_mdstr *str) { + if (str == GRPC_MDSTR_IDENTITY) return GRPC_COMPRESS_NONE; + if (str == GRPC_MDSTR_DEFLATE) return GRPC_COMPRESS_DEFLATE; + if (str == GRPC_MDSTR_GZIP) return GRPC_COMPRESS_GZIP; return GRPC_COMPRESS_ALGORITHMS_COUNT; } -grpc_slice grpc_compression_algorithm_slice( +grpc_mdstr *grpc_compression_algorithm_mdstr( grpc_compression_algorithm algorithm) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -99,12 +105,12 @@ grpc_slice grpc_compression_algorithm_slice( case GRPC_COMPRESS_GZIP: return GRPC_MDSTR_GZIP; case GRPC_COMPRESS_ALGORITHMS_COUNT: - return grpc_empty_slice(); + return NULL; } - return grpc_empty_slice(); + return NULL; } -grpc_mdelem grpc_compression_encoding_mdelem( +grpc_mdelem *grpc_compression_encoding_mdelem( grpc_compression_algorithm algorithm) { switch (algorithm) { case GRPC_COMPRESS_NONE: @@ -116,7 +122,7 @@ grpc_mdelem grpc_compression_encoding_mdelem( default: break; } - return GRPC_MDNULL; + return NULL; } void grpc_compression_options_init(grpc_compression_options *opts) { diff --git a/src/core/lib/http/httpcli_security_connector.c b/src/core/lib/http/httpcli_security_connector.c index f4f6f3c27aa..440817c5a6b 100644 --- a/src/core/lib/http/httpcli_security_connector.c +++ b/src/core/lib/http/httpcli_security_connector.c @@ -156,7 +156,7 @@ static void on_handshake_done(grpc_exec_ctx *exec_ctx, void *arg, if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_ERROR, "Secure transport setup failed: %s", msg); - + grpc_error_free_string(msg); c->func(exec_ctx, c->arg, NULL); } else { grpc_channel_args_destroy(exec_ctx, args->args); diff --git a/src/core/lib/iomgr/closure.c b/src/core/lib/iomgr/closure.c index 8e4efd3370d..da0ec878a39 100644 --- a/src/core/lib/iomgr/closure.c +++ b/src/core/lib/iomgr/closure.c @@ -34,7 +34,6 @@ #include "src/core/lib/iomgr/closure.h" #include -#include #include "src/core/lib/profiling/timers.h" diff --git a/src/core/lib/iomgr/closure.h b/src/core/lib/iomgr/closure.h index 6748b21e59c..ee386fbc767 100644 --- a/src/core/lib/iomgr/closure.h +++ b/src/core/lib/iomgr/closure.h @@ -66,7 +66,6 @@ typedef struct grpc_closure_scheduler_vtable { grpc_error *error); void (*sched)(grpc_exec_ctx *exec_ctx, grpc_closure *closure, grpc_error *error); - const char *name; } grpc_closure_scheduler_vtable; /** Abstract type that can schedule closures for execution */ diff --git a/src/core/lib/iomgr/combiner.c b/src/core/lib/iomgr/combiner.c index ba6c7087a92..c26a73b2b71 100644 --- a/src/core/lib/iomgr/combiner.c +++ b/src/core/lib/iomgr/combiner.c @@ -86,17 +86,13 @@ static void combiner_finally_exec_covered(grpc_exec_ctx *exec_ctx, grpc_error *error); static const grpc_closure_scheduler_vtable scheduler_uncovered = { - combiner_exec_uncovered, combiner_exec_uncovered, - "combiner:immediately:uncovered"}; + combiner_exec_uncovered, combiner_exec_uncovered}; static const grpc_closure_scheduler_vtable scheduler_covered = { - combiner_exec_covered, combiner_exec_covered, - "combiner:immediately:covered"}; + combiner_exec_covered, combiner_exec_covered}; static const grpc_closure_scheduler_vtable finally_scheduler_uncovered = { - combiner_finally_exec_uncovered, combiner_finally_exec_uncovered, - "combiner:finally:uncovered"}; + combiner_finally_exec_uncovered, combiner_finally_exec_uncovered}; static const grpc_closure_scheduler_vtable finally_scheduler_covered = { - combiner_finally_exec_covered, combiner_finally_exec_covered, - "combiner:finally:covered"}; + combiner_finally_exec_covered, combiner_finally_exec_covered}; static void offload(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error); diff --git a/src/core/lib/iomgr/error.c b/src/core/lib/iomgr/error.c index dbe5b139f91..f6bb3a04779 100644 --- a/src/core/lib/iomgr/error.c +++ b/src/core/lib/iomgr/error.c @@ -33,10 +33,13 @@ #include "src/core/lib/iomgr/error.h" +#include +#include #include #include #include +#include #include #include #include @@ -45,7 +48,6 @@ #include #endif -#include "src/core/lib/iomgr/error_internal.h" #include "src/core/lib/profiling/timers.h" static void destroy_integer(void *key) {} @@ -126,10 +128,6 @@ static const char *error_int_name(grpc_error_ints key) { static const char *error_str_name(grpc_error_strs key) { switch (key) { - case GRPC_ERROR_STR_KEY: - return "key"; - case GRPC_ERROR_STR_VALUE: - return "value"; case GRPC_ERROR_STR_DESCRIPTION: return "description"; case GRPC_ERROR_STR_OS_ERROR: @@ -162,7 +160,16 @@ static const char *error_time_name(grpc_error_times key) { GPR_UNREACHABLE_CODE(return "unknown"); } -bool grpc_error_is_special(grpc_error *err) { +struct grpc_error { + gpr_refcount refs; + gpr_avl ints; + gpr_avl strs; + gpr_avl times; + gpr_avl errs; + uintptr_t next_err; +}; + +static bool is_special(grpc_error *err) { return err == GRPC_ERROR_NONE || err == GRPC_ERROR_OOM || err == GRPC_ERROR_CANCELLED; } @@ -170,7 +177,7 @@ bool grpc_error_is_special(grpc_error *err) { #ifdef GRPC_ERROR_REFCOUNT_DEBUG grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, const char *func) { - if (grpc_error_is_special(err)) return err; + if (is_special(err)) return err; gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, err->refs.count, err->refs.count + 1, file, line, func); gpr_ref(&err->refs); @@ -178,26 +185,25 @@ grpc_error *grpc_error_ref(grpc_error *err, const char *file, int line, } #else grpc_error *grpc_error_ref(grpc_error *err) { - if (grpc_error_is_special(err)) return err; + if (is_special(err)) return err; gpr_ref(&err->refs); return err; } #endif static void error_destroy(grpc_error *err) { - GPR_ASSERT(!grpc_error_is_special(err)); + GPR_ASSERT(!is_special(err)); gpr_avl_unref(err->ints); gpr_avl_unref(err->strs); gpr_avl_unref(err->errs); gpr_avl_unref(err->times); - gpr_free((void *)gpr_atm_acq_load(&err->error_string)); gpr_free(err); } #ifdef GRPC_ERROR_REFCOUNT_DEBUG void grpc_error_unref(grpc_error *err, const char *file, int line, const char *func) { - if (grpc_error_is_special(err)) return; + if (is_special(err)) return; gpr_log(GPR_DEBUG, "%p: %" PRIdPTR " -> %" PRIdPTR " [%s:%d %s]", err, err->refs.count, err->refs.count - 1, file, line, func); if (gpr_unref(&err->refs)) { @@ -206,7 +212,7 @@ void grpc_error_unref(grpc_error *err, const char *file, int line, } #else void grpc_error_unref(grpc_error *err) { - if (grpc_error_is_special(err)) return; + if (is_special(err)) return; if (gpr_unref(&err->refs)) { error_destroy(err); } @@ -241,7 +247,6 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, err->times = gpr_avl_add(gpr_avl_create(&avl_vtable_times), (void *)(uintptr_t)GRPC_ERROR_TIME_CREATED, box_time(gpr_now(GPR_CLOCK_REALTIME))); - gpr_atm_no_barrier_store(&err->error_string, 0); gpr_ref_init(&err->refs, 1); GPR_TIMER_END("grpc_error_create", 0); return err; @@ -250,10 +255,9 @@ grpc_error *grpc_error_create(const char *file, int line, const char *desc, static grpc_error *copy_error_and_unref(grpc_error *in) { GPR_TIMER_BEGIN("copy_error_and_unref", 0); grpc_error *out; - if (grpc_error_is_special(in)) { + if (is_special(in)) { if (in == GRPC_ERROR_NONE) - out = grpc_error_set_int(GRPC_ERROR_CREATE("no error"), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK); + out = GRPC_ERROR_CREATE("no error"); else if (in == GRPC_ERROR_OOM) out = GRPC_ERROR_CREATE("oom"); else if (in == GRPC_ERROR_CANCELLED) @@ -271,7 +275,6 @@ static grpc_error *copy_error_and_unref(grpc_error *in) { out->strs = gpr_avl_ref(in->strs); out->errs = gpr_avl_ref(in->errs); out->times = gpr_avl_ref(in->times); - gpr_atm_no_barrier_store(&out->error_string, 0); out->next_err = in->next_err; gpr_ref_init(&out->refs, 1); GRPC_ERROR_UNREF(in); @@ -289,29 +292,14 @@ grpc_error *grpc_error_set_int(grpc_error *src, grpc_error_ints which, return new; } -typedef struct { - grpc_error *error; - grpc_status_code code; - const char *msg; -} special_error_status_map; -static special_error_status_map error_status_map[] = { - {GRPC_ERROR_NONE, GRPC_STATUS_OK, NULL}, - {GRPC_ERROR_CANCELLED, GRPC_STATUS_CANCELLED, "Cancelled"}, - {GRPC_ERROR_OOM, GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory"}, -}; - bool grpc_error_get_int(grpc_error *err, grpc_error_ints which, intptr_t *p) { GPR_TIMER_BEGIN("grpc_error_get_int", 0); void *pp; - if (grpc_error_is_special(err)) { - if (which == GRPC_ERROR_INT_GRPC_STATUS) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) { - if (error_status_map[i].error == err) { - if (p != NULL) *p = error_status_map[i].code; - GPR_TIMER_END("grpc_error_get_int", 0); - return true; - } - } + if (is_special(err)) { + if (err == GRPC_ERROR_CANCELLED && which == GRPC_ERROR_INT_GRPC_STATUS) { + *p = GRPC_STATUS_CANCELLED; + GPR_TIMER_END("grpc_error_get_int", 0); + return true; } GPR_TIMER_END("grpc_error_get_int", 0); return false; @@ -336,17 +324,66 @@ grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, } const char *grpc_error_get_str(grpc_error *err, grpc_error_strs which) { - if (grpc_error_is_special(err)) { - if (which == GRPC_ERROR_STR_GRPC_MESSAGE) { - for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); i++) { - if (error_status_map[i].error == err) { - return error_status_map[i].msg; - } - } + if (is_special(err)) return NULL; + return gpr_avl_get(err->strs, (void *)(uintptr_t)which); +} + +typedef struct { + grpc_error *error; + grpc_status_code code; + const char *msg; +} special_error_status_map; +static special_error_status_map error_status_map[] = { + {GRPC_ERROR_NONE, GRPC_STATUS_OK, ""}, + {GRPC_ERROR_CANCELLED, GRPC_STATUS_CANCELLED, "RPC cancelled"}, + {GRPC_ERROR_OOM, GRPC_STATUS_RESOURCE_EXHAUSTED, "Out of memory"}, +}; + +static grpc_error *recursively_find_error_with_status(grpc_error *error, + intptr_t *status) { + // If the error itself has a status code, return it. + if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, status)) { + return error; + } + // Otherwise, search through its children. + intptr_t key = 0; + while (true) { + grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); + if (child_error == NULL) break; + grpc_error *result = + recursively_find_error_with_status(child_error, status); + if (result != NULL) return result; + } + return NULL; +} + +void grpc_error_get_status(grpc_error *error, grpc_status_code *code, + const char **msg) { + // Handle special errors via the static map. + for (size_t i = 0; i < GPR_ARRAY_SIZE(error_status_map); ++i) { + if (error == error_status_map[i].error) { + *code = error_status_map[i].code; + *msg = error_status_map[i].msg; + return; } - return NULL; } - return gpr_avl_get(err->strs, (void *)(uintptr_t)which); + // Populate code. + // Start with the parent error and recurse through the tree of children + // until we find the first one that has a status code. + intptr_t status = GRPC_STATUS_UNKNOWN; // Default in case we don't find one. + grpc_error *found_error = recursively_find_error_with_status(error, &status); + *code = (grpc_status_code)status; + // Now populate msg. + // If we found an error with a status code above, use that; otherwise, + // fall back to using the parent error. + if (found_error == NULL) found_error = error; + // If the error has a status message, use it. Otherwise, fall back to + // the error description. + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); + if (*msg == NULL) { + *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); + if (*msg == NULL) *msg = "uknown error"; // Just in case. + } } grpc_error *grpc_error_add_child(grpc_error *src, grpc_error *child) { @@ -498,6 +535,7 @@ static void add_errs(gpr_avl_node *n, char **s, size_t *sz, size_t *cap, *first = false; const char *e = grpc_error_string(n->value); append_str(e, s, sz, cap); + grpc_error_free_string(e); add_errs(n->right, s, sz, cap, first); } @@ -519,7 +557,7 @@ static int cmp_kvs(const void *a, const void *b) { return strcmp(ka->key, kb->key); } -static char *finish_kvs(kv_pairs *kvs) { +static const char *finish_kvs(kv_pairs *kvs) { char *s = NULL; size_t sz = 0; size_t cap = 0; @@ -540,18 +578,19 @@ static char *finish_kvs(kv_pairs *kvs) { return s; } +void grpc_error_free_string(const char *str) { + if (str == no_error_string) return; + if (str == oom_error_string) return; + if (str == cancelled_error_string) return; + gpr_free((char *)str); +} + const char *grpc_error_string(grpc_error *err) { GPR_TIMER_BEGIN("grpc_error_string", 0); if (err == GRPC_ERROR_NONE) return no_error_string; if (err == GRPC_ERROR_OOM) return oom_error_string; if (err == GRPC_ERROR_CANCELLED) return cancelled_error_string; - void *p = (void *)gpr_atm_acq_load(&err->error_string); - if (p != NULL) { - GPR_TIMER_END("grpc_error_string", 0); - return p; - } - kv_pairs kvs; memset(&kvs, 0, sizeof(kvs)); @@ -564,13 +603,7 @@ const char *grpc_error_string(grpc_error *err) { qsort(kvs.kvs, kvs.num_kvs, sizeof(kv_pair), cmp_kvs); - char *out = finish_kvs(&kvs); - - if (!gpr_atm_rel_cas(&err->error_string, 0, (gpr_atm)out)) { - gpr_free(out); - out = (char *)gpr_atm_no_barrier_load(&err->error_string); - } - + const char *out = finish_kvs(&kvs); GPR_TIMER_END("grpc_error_string", 0); return out; } @@ -605,6 +638,7 @@ bool grpc_log_if_error(const char *what, grpc_error *error, const char *file, if (error == GRPC_ERROR_NONE) return true; const char *msg = grpc_error_string(error); gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "%s: %s", what, msg); + grpc_error_free_string(msg); GRPC_ERROR_UNREF(error); return false; } diff --git a/src/core/lib/iomgr/error.h b/src/core/lib/iomgr/error.h index ffacdac3934..f3f3b80a092 100644 --- a/src/core/lib/iomgr/error.h +++ b/src/core/lib/iomgr/error.h @@ -124,11 +124,7 @@ typedef enum { /// filename that we were trying to read/write when this error occurred GRPC_ERROR_STR_FILENAME, /// which data was queued for writing when the error occurred - GRPC_ERROR_STR_QUEUED_BUFFERS, - /// key associated with the error - GRPC_ERROR_STR_KEY, - /// value associated with the error - GRPC_ERROR_STR_VALUE, + GRPC_ERROR_STR_QUEUED_BUFFERS } grpc_error_strs; typedef enum { @@ -145,6 +141,7 @@ typedef enum { #define GRPC_ERROR_CANCELLED ((grpc_error *)4) const char *grpc_error_string(grpc_error *error); +void grpc_error_free_string(const char *str); /// Create an error - but use GRPC_ERROR_CREATE instead grpc_error *grpc_error_create(const char *file, int line, const char *desc, @@ -192,6 +189,12 @@ grpc_error *grpc_error_set_str(grpc_error *src, grpc_error_strs which, /// Caller does NOT own return value. const char *grpc_error_get_str(grpc_error *error, grpc_error_strs which); +/// A utility function to get the status code and message to be returned +/// to the application. If not set in the top-level message, looks +/// through child errors until it finds the first one with these attributes. +void grpc_error_get_status(grpc_error *error, grpc_status_code *code, + const char **msg); + /// Add a child error: an error that is believed to have contributed to this /// error occurring. Allows root causing high level errors from lower level /// errors that contributed to them. diff --git a/src/core/lib/iomgr/error_internal.h b/src/core/lib/iomgr/error_internal.h deleted file mode 100644 index 1c89ead4ed6..00000000000 --- a/src/core/lib/iomgr/error_internal.h +++ /dev/null @@ -1,54 +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_IOMGR_ERROR_INTERNAL_H -#define GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H - -#include -#include - -#include - -struct grpc_error { - gpr_refcount refs; - gpr_avl ints; - gpr_avl strs; - gpr_avl times; - gpr_avl errs; - uintptr_t next_err; - gpr_atm error_string; -}; - -bool grpc_error_is_special(grpc_error *err); - -#endif /* GRPC_CORE_LIB_IOMGR_ERROR_INTERNAL_H */ diff --git a/src/core/lib/iomgr/ev_epoll_linux.c b/src/core/lib/iomgr/ev_epoll_linux.c index 39b5c0032e8..d6664aead2e 100644 --- a/src/core/lib/iomgr/ev_epoll_linux.c +++ b/src/core/lib/iomgr/ev_epoll_linux.c @@ -321,7 +321,7 @@ gpr_atm g_epoll_sync; #endif /* defined(GRPC_TSAN) */ static const grpc_closure_scheduler_vtable workqueue_scheduler_vtable = { - workqueue_enqueue, workqueue_enqueue, "workqueue"}; + workqueue_enqueue, workqueue_enqueue}; static void pi_add_ref(polling_island *pi); static void pi_unref(grpc_exec_ctx *exec_ctx, polling_island *pi); diff --git a/src/core/lib/iomgr/ev_posix.c b/src/core/lib/iomgr/ev_posix.c index c106ba54006..2975d619e18 100644 --- a/src/core/lib/iomgr/ev_posix.c +++ b/src/core/lib/iomgr/ev_posix.c @@ -52,8 +52,6 @@ * tests */ grpc_poll_function_type grpc_poll_function = poll; -grpc_wakeup_fd grpc_global_wakeup_fd; - static const grpc_event_engine_vtable *g_event_engine; static const char *g_poll_strategy_name = NULL; diff --git a/src/core/lib/iomgr/exec_ctx.c b/src/core/lib/iomgr/exec_ctx.c index 83bb436bd0a..6aa788f8e5f 100644 --- a/src/core/lib/iomgr/exec_ctx.c +++ b/src/core/lib/iomgr/exec_ctx.c @@ -42,16 +42,11 @@ #include "src/core/lib/profiling/timers.h" bool grpc_exec_ctx_ready_to_finish(grpc_exec_ctx *exec_ctx) { - if ((exec_ctx->flags & GRPC_EXEC_CTX_FLAG_IS_FINISHED) == 0) { - if (exec_ctx->check_ready_to_finish(exec_ctx, - exec_ctx->check_ready_to_finish_arg)) { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; - return true; - } - return false; - } else { - return true; + if (!exec_ctx->cached_ready_to_finish) { + exec_ctx->cached_ready_to_finish = exec_ctx->check_ready_to_finish( + exec_ctx, exec_ctx->check_ready_to_finish_arg); } + return exec_ctx->cached_ready_to_finish; } bool grpc_never_ready_to_finish(grpc_exec_ctx *exec_ctx, void *arg_ignored) { @@ -87,7 +82,7 @@ bool grpc_exec_ctx_flush(grpc_exec_ctx *exec_ctx) { } void grpc_exec_ctx_finish(grpc_exec_ctx *exec_ctx) { - exec_ctx->flags |= GRPC_EXEC_CTX_FLAG_IS_FINISHED; + exec_ctx->cached_ready_to_finish = true; grpc_exec_ctx_flush(exec_ctx); } @@ -106,6 +101,6 @@ void grpc_exec_ctx_global_init(void) {} void grpc_exec_ctx_global_shutdown(void) {} static const grpc_closure_scheduler_vtable exec_ctx_scheduler_vtable = { - exec_ctx_run, exec_ctx_sched, "exec_ctx"}; + exec_ctx_run, exec_ctx_sched}; static grpc_closure_scheduler exec_ctx_scheduler = {&exec_ctx_scheduler_vtable}; grpc_closure_scheduler *grpc_schedule_on_exec_ctx = &exec_ctx_scheduler; diff --git a/src/core/lib/iomgr/exec_ctx.h b/src/core/lib/iomgr/exec_ctx.h index f99a0fee5fc..e566f1b3e89 100644 --- a/src/core/lib/iomgr/exec_ctx.h +++ b/src/core/lib/iomgr/exec_ctx.h @@ -43,13 +43,6 @@ typedef struct grpc_workqueue grpc_workqueue; typedef struct grpc_combiner grpc_combiner; -/* This exec_ctx is ready to return: either pre-populated, or cached as soon as - the finish_check returns true */ -#define GRPC_EXEC_CTX_FLAG_IS_FINISHED 1 -/* The exec_ctx's thread is (potentially) owned by a call or channel: care - should be given to not delete said call/channel from this exec_ctx */ -#define GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP 2 - /** Execution context. * A bag of data that collects information along a callstack. * Generally created at public API entry points, and passed down as @@ -70,26 +63,36 @@ typedef struct grpc_combiner grpc_combiner; * - Instances are always passed as the first argument to a function that * takes it, and always as a pointer (grpc_exec_ctx is never copied). */ +#ifndef GRPC_EXECUTION_CONTEXT_SANITIZER struct grpc_exec_ctx { grpc_closure_list closure_list; /** currently active combiner: updated only via combiner.c */ grpc_combiner *active_combiner; /** last active combiner in the active combiner list */ grpc_combiner *last_combiner; - uintptr_t flags; + bool cached_ready_to_finish; void *check_ready_to_finish_arg; bool (*check_ready_to_finish)(grpc_exec_ctx *exec_ctx, void *arg); }; /* initializer for grpc_exec_ctx: prefer to use GRPC_EXEC_CTX_INIT whenever possible */ -#define GRPC_EXEC_CTX_INITIALIZER(flags, finish_check, finish_check_arg) \ - { GRPC_CLOSURE_LIST_INIT, NULL, NULL, flags, finish_check_arg, finish_check } +#define GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(finish_check, finish_check_arg) \ + { GRPC_CLOSURE_LIST_INIT, NULL, NULL, false, finish_check_arg, finish_check } +#else +struct grpc_exec_ctx { + bool cached_ready_to_finish; + void *check_ready_to_finish_arg; + bool (*check_ready_to_finish)(grpc_exec_ctx *exec_ctx, void *arg); +}; +#define GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(finish_check, finish_check_arg) \ + { false, finish_check_arg, finish_check } +#endif /* initialize an execution context at the top level of an API call into grpc (this is safe to use elsewhere, though possibly not as efficient) */ #define GRPC_EXEC_CTX_INIT \ - GRPC_EXEC_CTX_INITIALIZER(GRPC_EXEC_CTX_FLAG_IS_FINISHED, NULL, NULL) + GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK(grpc_always_ready_to_finish, NULL) extern grpc_closure_scheduler *grpc_schedule_on_exec_ctx; diff --git a/src/core/lib/iomgr/executor.c b/src/core/lib/iomgr/executor.c index a5b62aa8888..852775564f6 100644 --- a/src/core/lib/iomgr/executor.c +++ b/src/core/lib/iomgr/executor.c @@ -158,7 +158,7 @@ void grpc_executor_shutdown(grpc_exec_ctx *exec_ctx) { gpr_mu_destroy(&g_executor.mu); } -static const grpc_closure_scheduler_vtable executor_vtable = { - executor_push, executor_push, "executor"}; +static const grpc_closure_scheduler_vtable executor_vtable = {executor_push, + executor_push}; static grpc_closure_scheduler executor_scheduler = {&executor_vtable}; grpc_closure_scheduler *grpc_executor_scheduler = &executor_scheduler; diff --git a/src/core/lib/iomgr/load_file.c b/src/core/lib/iomgr/load_file.c index f40c8b28ccd..217bc5da594 100644 --- a/src/core/lib/iomgr/load_file.c +++ b/src/core/lib/iomgr/load_file.c @@ -47,7 +47,7 @@ grpc_error *grpc_load_file(const char *filename, int add_null_terminator, grpc_slice *output) { unsigned char *contents = NULL; size_t contents_size = 0; - grpc_slice result = grpc_empty_slice(); + grpc_slice result = gpr_empty_slice(); FILE *file; size_t bytes_read = 0; grpc_error *error = GRPC_ERROR_NONE; diff --git a/src/core/lib/iomgr/resource_quota.c b/src/core/lib/iomgr/resource_quota.c index 41ea609c73b..31590cd53b7 100644 --- a/src/core/lib/iomgr/resource_quota.c +++ b/src/core/lib/iomgr/resource_quota.c @@ -378,15 +378,11 @@ static void ru_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } -static const grpc_slice_refcount_vtable ru_slice_vtable = { - ru_slice_ref, ru_slice_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; - static grpc_slice ru_slice_create(grpc_resource_user *resource_user, size_t size) { ru_slice_refcount *rc = gpr_malloc(sizeof(ru_slice_refcount) + size); - rc->base.vtable = &ru_slice_vtable; - rc->base.sub_refcount = &rc->base; + rc->base.ref = ru_slice_ref; + rc->base.unref = ru_slice_unref; gpr_ref_init(&rc->refs, 1); rc->resource_user = resource_user; rc->size = size; diff --git a/src/core/lib/iomgr/tcp_client_posix.c b/src/core/lib/iomgr/tcp_client_posix.c index 16b0f4e73c1..9a77c92016b 100644 --- a/src/core/lib/iomgr/tcp_client_posix.c +++ b/src/core/lib/iomgr/tcp_client_posix.c @@ -118,6 +118,7 @@ static void tc_on_alarm(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_alarm: error=%s", ac->addr_str, str); + grpc_error_free_string(str); } gpr_mu_lock(&ac->mu); if (ac->fd != NULL) { @@ -177,6 +178,7 @@ static void on_writable(grpc_exec_ctx *exec_ctx, void *acp, grpc_error *error) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "CLIENT_CONNECT: %s: on_writable: error=%s", ac->addr_str, str); + grpc_error_free_string(str); } gpr_mu_lock(&ac->mu); diff --git a/src/core/lib/iomgr/tcp_posix.c b/src/core/lib/iomgr/tcp_posix.c index a33e63e845c..ece44978b0f 100644 --- a/src/core/lib/iomgr/tcp_posix.c +++ b/src/core/lib/iomgr/tcp_posix.c @@ -181,7 +181,7 @@ static void call_read_cb(grpc_exec_ctx *exec_ctx, grpc_tcp *tcp, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - + grpc_error_free_string(str); for (i = 0; i < tcp->incoming_buffer->count; i++) { char *dump = grpc_dump_slice(tcp->incoming_buffer->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -435,6 +435,7 @@ static void tcp_handle_write(grpc_exec_ctx *exec_ctx, void *arg /* grpc_tcp */, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); + grpc_error_free_string(str); } grpc_closure_run(exec_ctx, cb, error); @@ -484,6 +485,7 @@ static void tcp_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *ep, if (grpc_tcp_trace) { const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "write: %s", str); + grpc_error_free_string(str); } grpc_closure_sched(exec_ctx, cb, error); } diff --git a/src/core/lib/iomgr/tcp_server_windows.c b/src/core/lib/iomgr/tcp_server_windows.c index bd4b9b2df11..dafe851ce8b 100644 --- a/src/core/lib/iomgr/tcp_server_windows.c +++ b/src/core/lib/iomgr/tcp_server_windows.c @@ -343,7 +343,7 @@ static void on_accept(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { if (error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Skipping on_accept due to error: %s", msg); - + grpc_error_free_string(msg); gpr_mu_unlock(&sp->server->mu); return; } diff --git a/src/core/lib/iomgr/tcp_uv.c b/src/core/lib/iomgr/tcp_uv.c index 7f4ea49a1ce..3ddc79706be 100644 --- a/src/core/lib/iomgr/tcp_uv.c +++ b/src/core/lib/iomgr/tcp_uv.c @@ -48,7 +48,6 @@ #include "src/core/lib/iomgr/network_status_tracker.h" #include "src/core/lib/iomgr/resource_quota.h" #include "src/core/lib/iomgr/tcp_uv.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" @@ -157,7 +156,7 @@ static void read_callback(uv_stream_t *stream, ssize_t nread, size_t i; const char *str = grpc_error_string(error); gpr_log(GPR_DEBUG, "read: error=%s", str); - + grpc_error_free_string(str); for (i = 0; i < tcp->read_slices->count; i++) { char *dump = grpc_dump_slice(tcp->read_slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII); diff --git a/src/core/lib/security/credentials/google_default/google_default_credentials.c b/src/core/lib/security/credentials/google_default/google_default_credentials.c index a098741b707..d6e1fe3dcfc 100644 --- a/src/core/lib/security/credentials/google_default/google_default_credentials.c +++ b/src/core/lib/security/credentials/google_default/google_default_credentials.c @@ -177,7 +177,7 @@ static grpc_error *create_default_creds_from_path( grpc_auth_json_key key; grpc_auth_refresh_token token; grpc_call_credentials *result = NULL; - grpc_slice creds_data = grpc_empty_slice(); + grpc_slice creds_data = gpr_empty_slice(); grpc_error *error = GRPC_ERROR_NONE; if (creds_path == NULL) { error = GRPC_ERROR_CREATE("creds_path unset"); diff --git a/src/core/lib/security/credentials/plugin/plugin_credentials.c b/src/core/lib/security/credentials/plugin/plugin_credentials.c index 7bc5dfb4035..f90d7dce83f 100644 --- a/src/core/lib/security/credentials/plugin/plugin_credentials.c +++ b/src/core/lib/security/credentials/plugin/plugin_credentials.c @@ -42,9 +42,7 @@ #include #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/surface/api_trace.h" -#include "src/core/lib/surface/validate_metadata.h" typedef struct { void *user_data; @@ -65,9 +63,7 @@ static void plugin_md_request_metadata_ready(void *request, grpc_status_code status, const char *error_details) { /* called from application code */ - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INITIALIZER( - GRPC_EXEC_CTX_FLAG_IS_FINISHED | GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP, - NULL, NULL); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_metadata_plugin_request *r = (grpc_metadata_plugin_request *)request; if (status != GRPC_STATUS_OK) { if (error_details != NULL) { @@ -81,14 +77,13 @@ static void plugin_md_request_metadata_ready(void *request, bool seen_illegal_header = false; grpc_credentials_md *md_array = NULL; for (i = 0; i < num_md; i++) { - if (!GRPC_LOG_IF_ERROR("validate_metadata_from_plugin", - grpc_validate_header_key_is_legal(md[i].key))) { + if (!grpc_header_key_is_legal(md[i].key, strlen(md[i].key))) { + gpr_log(GPR_ERROR, "Plugin added invalid metadata key: %s", md[i].key); seen_illegal_header = true; break; - } else if (!grpc_is_binary_header(md[i].key) && - !GRPC_LOG_IF_ERROR( - "validate_metadata_from_plugin", - grpc_validate_header_nonbin_value_is_legal(md[i].value))) { + } else if (!grpc_is_binary_header(md[i].key, strlen(md[i].key)) && + !grpc_header_nonbin_value_is_legal(md[i].value, + md[i].value_length)) { gpr_log(GPR_ERROR, "Plugin added invalid metadata value."); seen_illegal_header = true; break; @@ -100,8 +95,9 @@ static void plugin_md_request_metadata_ready(void *request, } else if (num_md > 0) { md_array = gpr_malloc(num_md * sizeof(grpc_credentials_md)); for (i = 0; i < num_md; i++) { - md_array[i].key = grpc_slice_ref_internal(md[i].key); - md_array[i].value = grpc_slice_ref_internal(md[i].value); + md_array[i].key = grpc_slice_from_copied_string(md[i].key); + md_array[i].value = + grpc_slice_from_copied_buffer(md[i].value, md[i].value_length); } r->cb(&exec_ctx, r->user_data, md_array, num_md, GRPC_CREDENTIALS_OK, NULL); diff --git a/src/core/lib/security/transport/client_auth_filter.c b/src/core/lib/security/transport/client_auth_filter.c index cf056e80080..b7f6fd23e30 100644 --- a/src/core/lib/security/transport/client_auth_filter.c +++ b/src/core/lib/security/transport/client_auth_filter.c @@ -45,7 +45,6 @@ #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/transport/security_connector.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/transport/static_metadata.h" @@ -55,10 +54,8 @@ /* We can have a per-call credentials. */ typedef struct { grpc_call_credentials *creds; - bool have_host; - bool have_method; - grpc_slice host; - grpc_slice method; + grpc_mdstr *host; + grpc_mdstr *method; /* pollset{_set} bound to this call; if we need to make external network requests, they should be done under a pollset added to this pollset_set so that work can progress when this call wants work to progress @@ -92,12 +89,14 @@ static void reset_auth_metadata_context( auth_md_context->channel_auth_context = NULL; } -static void add_error(grpc_error **combined, grpc_error *error) { - if (error == GRPC_ERROR_NONE) return; - if (*combined == GRPC_ERROR_NONE) { - *combined = GRPC_ERROR_CREATE("Client auth metadata plugin error"); - } - *combined = grpc_error_add_child(*combined, error); +static void bubble_up_error(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, + grpc_status_code status, const char *error_msg) { + call_data *calld = elem->call_data; + gpr_log(GPR_ERROR, "Client side authentication failure: %s", error_msg); + grpc_slice error_slice = grpc_slice_from_copied_string(error_msg); + grpc_transport_stream_op_add_close(exec_ctx, &calld->op, status, + &error_slice); + grpc_call_next_op(exec_ctx, elem, &calld->op); } static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, @@ -111,37 +110,30 @@ static void on_credentials_metadata(grpc_exec_ctx *exec_ctx, void *user_data, grpc_metadata_batch *mdb; size_t i; reset_auth_metadata_context(&calld->auth_md_context); - grpc_error *error = GRPC_ERROR_NONE; if (status != GRPC_CREDENTIALS_OK) { - error = grpc_error_set_int( - GRPC_ERROR_CREATE(error_details != NULL && strlen(error_details) > 0 - ? error_details - : "Credentials failed to get metadata."), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED); - } else { - GPR_ASSERT(num_md <= MAX_CREDENTIALS_METADATA_COUNT); - GPR_ASSERT(op->send_initial_metadata != NULL); - mdb = op->send_initial_metadata; - for (i = 0; i < num_md; i++) { - add_error(&error, - grpc_metadata_batch_add_tail( - exec_ctx, mdb, &calld->md_links[i], - grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(md_elems[i].key), - grpc_slice_ref_internal(md_elems[i].value)))); - } + bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, + (error_details != NULL && strlen(error_details) > 0) + ? error_details + : "Credentials failed to get metadata."); + return; } - if (error == GRPC_ERROR_NONE) { - grpc_call_next_op(exec_ctx, elem, op); - } else { - grpc_transport_stream_op_finish_with_failure(exec_ctx, op, error); + GPR_ASSERT(num_md <= MAX_CREDENTIALS_METADATA_COUNT); + GPR_ASSERT(op->send_initial_metadata != NULL); + mdb = op->send_initial_metadata; + for (i = 0; i < num_md; i++) { + grpc_metadata_batch_add_tail( + mdb, &calld->md_links[i], + grpc_mdelem_from_slices(exec_ctx, + grpc_slice_ref_internal(md_elems[i].key), + grpc_slice_ref_internal(md_elems[i].value))); } + grpc_call_next_op(exec_ctx, elem, op); } void build_auth_metadata_context(grpc_security_connector *sc, grpc_auth_context *auth_context, call_data *calld) { - char *service = grpc_slice_to_c_string(calld->method); + char *service = gpr_strdup(grpc_mdstr_as_c_string(calld->method)); char *last_slash = strrchr(service, '/'); char *method_name = NULL; char *service_url = NULL; @@ -157,15 +149,14 @@ void build_auth_metadata_context(grpc_security_connector *sc, method_name = gpr_strdup(last_slash + 1); } if (method_name == NULL) method_name = gpr_strdup(""); - char *host = grpc_slice_to_c_string(calld->host); gpr_asprintf(&service_url, "%s://%s%s", - sc->url_scheme == NULL ? "" : sc->url_scheme, host, service); + sc->url_scheme == NULL ? "" : sc->url_scheme, + grpc_mdstr_as_c_string(calld->host), service); calld->auth_md_context.service_url = service_url; calld->auth_md_context.method_name = method_name; calld->auth_md_context.channel_auth_context = GRPC_AUTH_CONTEXT_REF(auth_context, "grpc_auth_metadata_context"); gpr_free(service); - gpr_free(host); } static void send_security_metadata(grpc_exec_ctx *exec_ctx, @@ -189,12 +180,8 @@ static void send_security_metadata(grpc_exec_ctx *exec_ctx, calld->creds = grpc_composite_call_credentials_create(channel_call_creds, ctx->creds, NULL); if (calld->creds == NULL) { - grpc_transport_stream_op_finish_with_failure( - exec_ctx, op, - grpc_error_set_int( - GRPC_ERROR_CREATE( - "Incompatible credentials set on channel and call."), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAUTHENTICATED)); + bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, + "Incompatible credentials set on channel and call."); return; } } else { @@ -220,14 +207,9 @@ static void on_host_checked(grpc_exec_ctx *exec_ctx, void *user_data, send_security_metadata(exec_ctx, elem, &calld->op); } else { char *error_msg; - char *host = grpc_slice_to_c_string(calld->host); gpr_asprintf(&error_msg, "Invalid host %s set in :authority metadata.", - host); - gpr_free(host); - grpc_call_element_signal_error( - exec_ctx, elem, grpc_error_set_int(GRPC_ERROR_CREATE(error_msg), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_UNAUTHENTICATED)); + grpc_mdstr_as_c_string(calld->host)); + bubble_up_error(exec_ctx, elem, GRPC_STATUS_UNAUTHENTICATED, error_msg); gpr_free(error_msg); } } @@ -265,30 +247,23 @@ static void auth_start_transport_op(grpc_exec_ctx *exec_ctx, if (op->send_initial_metadata != NULL) { for (l = op->send_initial_metadata->list.head; l != NULL; l = l->next) { - grpc_mdelem md = l->md; + grpc_mdelem *md = l->md; /* Pointer comparison is OK for md_elems created from the same context. */ - if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_AUTHORITY)) { - if (calld->have_host) { - grpc_slice_unref_internal(exec_ctx, calld->host); - } - calld->host = grpc_slice_ref_internal(GRPC_MDVALUE(md)); - calld->have_host = true; - } else if (grpc_slice_eq(GRPC_MDKEY(md), GRPC_MDSTR_PATH)) { - if (calld->have_method) { - grpc_slice_unref_internal(exec_ctx, calld->method); - } - calld->method = grpc_slice_ref_internal(GRPC_MDVALUE(md)); - calld->have_method = true; + if (md->key == GRPC_MDSTR_AUTHORITY) { + if (calld->host != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->host); + calld->host = GRPC_MDSTR_REF(md->value); + } else if (md->key == GRPC_MDSTR_PATH) { + if (calld->method != NULL) GRPC_MDSTR_UNREF(exec_ctx, calld->method); + calld->method = GRPC_MDSTR_REF(md->value); } } - if (calld->have_host) { - char *call_host = grpc_slice_to_c_string(calld->host); + if (calld->host != NULL) { + const char *call_host = grpc_mdstr_as_c_string(calld->host); calld->op = *op; /* Copy op (originates from the caller's stack). */ grpc_channel_security_connector_check_call_host( exec_ctx, chand->security_connector, call_host, chand->auth_context, on_host_checked, elem); - gpr_free(call_host); GPR_TIMER_END("auth_start_transport_op", 0); return; /* early exit */ } @@ -321,11 +296,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, void *ignored) { call_data *calld = elem->call_data; grpc_call_credentials_unref(exec_ctx, calld->creds); - if (calld->have_host) { - grpc_slice_unref_internal(exec_ctx, calld->host); + if (calld->host != NULL) { + GRPC_MDSTR_UNREF(exec_ctx, calld->host); } - if (calld->have_method) { - grpc_slice_unref_internal(exec_ctx, calld->method); + if (calld->method != NULL) { + GRPC_MDSTR_UNREF(exec_ctx, calld->method); } reset_auth_metadata_context(&calld->auth_md_context); } diff --git a/src/core/lib/security/transport/security_connector.c b/src/core/lib/security/transport/security_connector.c index b09127811b0..5aa26e05771 100644 --- a/src/core/lib/security/transport/security_connector.c +++ b/src/core/lib/security/transport/security_connector.c @@ -601,7 +601,7 @@ static grpc_security_connector_vtable ssl_server_vtable = { ssl_server_destroy, ssl_server_check_peer}; static grpc_slice compute_default_pem_root_certs_once(void) { - grpc_slice result = grpc_empty_slice(); + grpc_slice result = gpr_empty_slice(); /* First try to load the roots from the environment. */ char *default_root_certs_path = diff --git a/src/core/lib/security/transport/security_handshaker.c b/src/core/lib/security/transport/security_handshaker.c index 37d57d759b3..5e75856c7a4 100644 --- a/src/core/lib/security/transport/security_handshaker.c +++ b/src/core/lib/security/transport/security_handshaker.c @@ -124,7 +124,7 @@ static void security_handshake_failed_locked(grpc_exec_ctx *exec_ctx, } const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "Security handshake failed: %s", msg); - + grpc_error_free_string(msg); if (!h->shutdown) { // TODO(ctiller): It is currently necessary to shutdown endpoints // before destroying them, even if we know that there are no diff --git a/src/core/lib/security/transport/server_auth_filter.c b/src/core/lib/security/transport/server_auth_filter.c index 36e81d6501c..5e98ba895dc 100644 --- a/src/core/lib/security/transport/server_auth_filter.c +++ b/src/core/lib/security/transport/server_auth_filter.c @@ -33,13 +33,12 @@ #include -#include -#include - #include "src/core/lib/security/context/security_context.h" #include "src/core/lib/security/credentials/credentials.h" #include "src/core/lib/security/transport/auth_filters.h" -#include "src/core/lib/slice/slice_internal.h" + +#include +#include typedef struct call_data { grpc_metadata_batch *recv_initial_metadata; @@ -68,34 +67,48 @@ static grpc_metadata_array metadata_batch_to_md_array( grpc_metadata_array_init(&result); for (l = batch->list.head; l != NULL; l = l->next) { grpc_metadata *usr_md = NULL; - grpc_mdelem md = l->md; - grpc_slice key = GRPC_MDKEY(md); - grpc_slice value = GRPC_MDVALUE(md); + grpc_mdelem *md = l->md; + grpc_mdstr *key = md->key; + grpc_mdstr *value = md->value; if (result.count == result.capacity) { result.capacity = GPR_MAX(result.capacity + 8, result.capacity * 2); result.metadata = gpr_realloc(result.metadata, result.capacity * sizeof(grpc_metadata)); } usr_md = &result.metadata[result.count++]; - usr_md->key = grpc_slice_ref_internal(key); - usr_md->value = grpc_slice_ref_internal(value); + usr_md->key = grpc_mdstr_as_c_string(key); + usr_md->value = grpc_mdstr_as_c_string(value); + usr_md->value_length = GRPC_SLICE_LENGTH(value->slice); } return result; } -static grpc_filtered_mdelem remove_consumed_md(grpc_exec_ctx *exec_ctx, - void *user_data, - grpc_mdelem md) { +static grpc_mdelem *remove_consumed_md(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { grpc_call_element *elem = user_data; call_data *calld = elem->call_data; size_t i; for (i = 0; i < calld->num_consumed_md; i++) { const grpc_metadata *consumed_md = &calld->consumed_md[i]; - if (grpc_slice_eq(GRPC_MDKEY(md), consumed_md->key) && - grpc_slice_eq(GRPC_MDVALUE(md), consumed_md->value)) - return GRPC_FILTERED_REMOVE(); + /* Maybe we could do a pointer comparison but we do not have any guarantee + that the metadata processor used the same pointers for consumed_md in the + callback. */ + if (GRPC_SLICE_LENGTH(md->key->slice) != strlen(consumed_md->key) || + GRPC_SLICE_LENGTH(md->value->slice) != consumed_md->value_length) { + continue; + } + if (memcmp(GRPC_SLICE_START_PTR(md->key->slice), consumed_md->key, + GRPC_SLICE_LENGTH(md->key->slice)) == 0 && + memcmp(GRPC_SLICE_START_PTR(md->value->slice), consumed_md->value, + GRPC_SLICE_LENGTH(md->value->slice)) == 0) { + return NULL; /* Delete. */ + } } - return GRPC_FILTERED_MDELEM(md); + return md; +} + +static void destroy_op(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { + gpr_free(arg); } /* called from application code */ @@ -117,33 +130,29 @@ static void on_md_processing_done( if (status == GRPC_STATUS_OK) { calld->consumed_md = consumed_md; calld->num_consumed_md = num_consumed_md; - /* TODO(ctiller): propagate error */ - GRPC_LOG_IF_ERROR( - "grpc_metadata_batch_filter", - grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, - remove_consumed_md, elem, - "Response metadata filtering error")); - for (size_t i = 0; i < calld->md.count; i++) { - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); - } + grpc_metadata_batch_filter(&exec_ctx, calld->recv_initial_metadata, + remove_consumed_md, elem); grpc_metadata_array_destroy(&calld->md); grpc_closure_sched(&exec_ctx, calld->on_done_recv, GRPC_ERROR_NONE); } else { - for (size_t i = 0; i < calld->md.count; i++) { - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].key); - grpc_slice_unref_internal(&exec_ctx, calld->md.metadata[i].value); - } + grpc_slice message; + grpc_transport_stream_op *close_op = gpr_malloc(sizeof(*close_op)); + memset(close_op, 0, sizeof(*close_op)); grpc_metadata_array_destroy(&calld->md); error_details = error_details != NULL ? error_details : "Authentication metadata processing failed."; + message = grpc_slice_from_copied_string(error_details); calld->transport_op->send_initial_metadata = NULL; if (calld->transport_op->send_message != NULL) { grpc_byte_stream_destroy(&exec_ctx, calld->transport_op->send_message); calld->transport_op->send_message = NULL; } calld->transport_op->send_trailing_metadata = NULL; + close_op->on_complete = + grpc_closure_create(destroy_op, close_op, grpc_schedule_on_exec_ctx); + grpc_transport_stream_op_add_close(&exec_ctx, close_op, status, &message); + grpc_call_next_op(&exec_ctx, elem, close_op); grpc_closure_sched(&exec_ctx, calld->on_done_recv, grpc_error_set_int(GRPC_ERROR_CREATE(error_details), GRPC_ERROR_INT_GRPC_STATUS, status)); diff --git a/src/core/lib/security/util/b64.c b/src/core/lib/security/util/b64.c index 09c82131316..bbd7e335a67 100644 --- a/src/core/lib/security/util/b64.c +++ b/src/core/lib/security/util/b64.c @@ -232,5 +232,5 @@ grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64, fail: grpc_slice_unref_internal(exec_ctx, result); - return grpc_empty_slice(); + return gpr_empty_slice(); } diff --git a/src/core/lib/slice/slice.c b/src/core/lib/slice/slice.c index 1cddf062cd4..76118102ece 100644 --- a/src/core/lib/slice/slice.c +++ b/src/core/lib/slice/slice.c @@ -41,30 +41,23 @@ #include "src/core/lib/iomgr/exec_ctx.h" -char *grpc_slice_to_c_string(grpc_slice slice) { - char *out = gpr_malloc(GRPC_SLICE_LENGTH(slice) + 1); - memcpy(out, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); - out[GRPC_SLICE_LENGTH(slice)] = 0; - return out; -} - -grpc_slice grpc_empty_slice(void) { +grpc_slice gpr_empty_slice(void) { grpc_slice out; - out.refcount = NULL; + out.refcount = 0; out.data.inlined.length = 0; return out; } grpc_slice grpc_slice_ref_internal(grpc_slice slice) { if (slice.refcount) { - slice.refcount->vtable->ref(slice.refcount); + slice.refcount->ref(slice.refcount); } return slice; } void grpc_slice_unref_internal(grpc_exec_ctx *exec_ctx, grpc_slice slice) { if (slice.refcount) { - slice.refcount->vtable->unref(exec_ctx, slice.refcount); + slice.refcount->unref(exec_ctx, slice.refcount); } } @@ -85,24 +78,16 @@ void grpc_slice_unref(grpc_slice slice) { static void noop_ref(void *unused) {} static void noop_unref(grpc_exec_ctx *exec_ctx, void *unused) {} -static const grpc_slice_refcount_vtable noop_refcount_vtable = { - noop_ref, noop_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; -static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable, - &noop_refcount}; +static grpc_slice_refcount noop_refcount = {noop_ref, noop_unref}; -grpc_slice grpc_slice_from_static_buffer(const void *s, size_t len) { +grpc_slice grpc_slice_from_static_string(const char *s) { grpc_slice slice; slice.refcount = &noop_refcount; slice.data.refcounted.bytes = (uint8_t *)s; - slice.data.refcounted.length = len; + slice.data.refcounted.length = strlen(s); return slice; } -grpc_slice grpc_slice_from_static_string(const char *s) { - return grpc_slice_from_static_buffer(s, strlen(s)); -} - /* grpc_slice_new support structures - we create a refcount object extended with the user provided data pointer & destroy function */ typedef struct new_slice_refcount { @@ -125,18 +110,14 @@ static void new_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { } } -static const grpc_slice_refcount_vtable new_slice_vtable = { - new_slice_ref, new_slice_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; - grpc_slice grpc_slice_new_with_user_data(void *p, size_t len, void (*destroy)(void *), void *user_data) { grpc_slice slice; new_slice_refcount *rc = gpr_malloc(sizeof(new_slice_refcount)); gpr_ref_init(&rc->refs, 1); - rc->rc.vtable = &new_slice_vtable; - rc->rc.sub_refcount = &rc->rc; + rc->rc.ref = new_slice_ref; + rc->rc.unref = new_slice_unref; rc->user_destroy = destroy; rc->user_data = user_data; @@ -174,18 +155,14 @@ static void new_with_len_unref(grpc_exec_ctx *exec_ctx, void *p) { } } -static const grpc_slice_refcount_vtable new_with_len_vtable = { - new_with_len_ref, new_with_len_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; - grpc_slice grpc_slice_new_with_len(void *p, size_t len, void (*destroy)(void *, size_t)) { grpc_slice slice; new_with_len_slice_refcount *rc = gpr_malloc(sizeof(new_with_len_slice_refcount)); gpr_ref_init(&rc->refs, 1); - rc->rc.vtable = &new_with_len_vtable; - rc->rc.sub_refcount = &rc->rc; + rc->rc.ref = new_with_len_ref; + rc->rc.unref = new_with_len_unref; rc->user_destroy = destroy; rc->user_data = p; rc->user_length = len; @@ -223,10 +200,6 @@ static void malloc_unref(grpc_exec_ctx *exec_ctx, void *p) { } } -static const grpc_slice_refcount_vtable malloc_vtable = { - malloc_ref, malloc_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; - grpc_slice grpc_slice_malloc(size_t length) { grpc_slice slice; @@ -246,8 +219,8 @@ grpc_slice grpc_slice_malloc(size_t length) { this reference. */ gpr_ref_init(&rc->refs, 1); - rc->base.vtable = &malloc_vtable; - rc->base.sub_refcount = &rc->base; + rc->base.ref = malloc_ref; + rc->base.unref = malloc_unref; /* Build up the slice to be returned. */ /* The slices refcount points back to the allocated block. */ @@ -274,7 +247,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) { GPR_ASSERT(source.data.refcounted.length >= end); /* Build the result */ - subset.refcount = source.refcount->sub_refcount; + subset.refcount = source.refcount; /* Point into the source array */ subset.data.refcounted.bytes = source.data.refcounted.bytes + begin; subset.data.refcounted.length = end - begin; @@ -300,7 +273,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) { } else { subset = grpc_slice_sub_no_ref(source, begin, end); /* Bump the refcount */ - subset.refcount->vtable->ref(subset.refcount); + subset.refcount->ref(subset.refcount); } return subset; } @@ -327,14 +300,13 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) { tail_length); } else { /* Build the result */ - tail.refcount = source->refcount->sub_refcount; + tail.refcount = source->refcount; /* Bump the refcount */ - tail.refcount->vtable->ref(tail.refcount); + tail.refcount->ref(tail.refcount); /* Point into the source array */ tail.data.refcounted.bytes = source->data.refcounted.bytes + split; tail.data.refcounted.length = tail_length; } - source->refcount = source->refcount->sub_refcount; source->data.refcounted.length = split; } @@ -360,20 +332,18 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { head.refcount = NULL; head.data.inlined.length = (uint8_t)split; memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split); - source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; source->data.refcounted.length -= split; } else { GPR_ASSERT(source->data.refcounted.length >= split); /* Build the result */ - head.refcount = source->refcount->sub_refcount; + head.refcount = source->refcount; /* Bump the refcount */ - head.refcount->vtable->ref(head.refcount); + head.refcount->ref(head.refcount); /* Point into the source array */ head.data.refcounted.bytes = source->data.refcounted.bytes; head.data.refcounted.length = split; - source->refcount = source->refcount->sub_refcount; source->data.refcounted.bytes += split; source->data.refcounted.length -= split; } @@ -381,19 +351,6 @@ grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) { return head; } -int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b) { - return GRPC_SLICE_LENGTH(a) == GRPC_SLICE_LENGTH(b) && - 0 == memcmp(GRPC_SLICE_START_PTR(a), GRPC_SLICE_START_PTR(b), - GRPC_SLICE_LENGTH(a)); -} - -int grpc_slice_eq(grpc_slice a, grpc_slice b) { - if (a.refcount && b.refcount && a.refcount->vtable == b.refcount->vtable) { - return a.refcount->vtable->eq(a, b); - } - return grpc_slice_default_eq_impl(a, b); -} - int grpc_slice_cmp(grpc_slice a, grpc_slice b) { int d = (int)(GRPC_SLICE_LENGTH(a) - GRPC_SLICE_LENGTH(b)); if (d != 0) return d; @@ -410,55 +367,8 @@ int grpc_slice_str_cmp(grpc_slice a, const char *b) { int grpc_slice_is_equivalent(grpc_slice a, grpc_slice b) { if (a.refcount == NULL || b.refcount == NULL) { - return grpc_slice_eq(a, b); + return grpc_slice_cmp(a, b) == 0; } return a.data.refcounted.length == b.data.refcounted.length && a.data.refcounted.bytes == b.data.refcounted.bytes; } - -int grpc_slice_buf_start_eq(grpc_slice a, const void *b, size_t len) { - if (GRPC_SLICE_LENGTH(a) < len) return 0; - return 0 == memcmp(GRPC_SLICE_START_PTR(a), b, len); -} - -int grpc_slice_rchr(grpc_slice s, char c) { - const char *b = (const char *)GRPC_SLICE_START_PTR(s); - int i; - for (i = (int)GRPC_SLICE_LENGTH(s) - 1; i != -1 && b[i] != c; i--) - ; - return i; -} - -int grpc_slice_chr(grpc_slice s, char c) { - const char *b = (const char *)GRPC_SLICE_START_PTR(s); - const char *p = memchr(b, c, GRPC_SLICE_LENGTH(s)); - return p == NULL ? -1 : (int)(p - b); -} - -int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) { - size_t haystack_len = GRPC_SLICE_LENGTH(haystack); - const uint8_t *haystack_bytes = GRPC_SLICE_START_PTR(haystack); - size_t needle_len = GRPC_SLICE_LENGTH(needle); - const uint8_t *needle_bytes = GRPC_SLICE_START_PTR(needle); - - if (haystack_len == 0 || needle_len == 0) return -1; - if (haystack_len < needle_len) return -1; - if (haystack_len == needle_len) - return grpc_slice_eq(haystack, needle) ? 0 : -1; - if (needle_len == 1) return grpc_slice_chr(haystack, (char)*needle_bytes); - - const uint8_t *last = haystack_bytes + haystack_len - needle_len; - for (const uint8_t *cur = haystack_bytes; cur != last; ++cur) { - if (0 == memcmp(cur, needle_bytes, needle_len)) { - return (int)(cur - haystack_bytes); - } - } - return -1; -} - -grpc_slice grpc_slice_dup(grpc_slice a) { - grpc_slice copy = grpc_slice_malloc(GRPC_SLICE_LENGTH(a)); - memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a), - GRPC_SLICE_LENGTH(a)); - return copy; -} diff --git a/src/core/lib/slice/slice_intern.c b/src/core/lib/slice/slice_intern.c deleted file mode 100644 index 7cbd17bffd8..00000000000 --- a/src/core/lib/slice/slice_intern.c +++ /dev/null @@ -1,344 +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. - * - */ - -#include "src/core/lib/slice/slice_internal.h" - -#include - -#include -#include - -#include "src/core/lib/iomgr/iomgr_internal.h" /* for iomgr_abort_on_leaks() */ -#include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_string_helpers.h" -#include "src/core/lib/support/murmur_hash.h" -#include "src/core/lib/transport/static_metadata.h" - -#define LOG2_SHARD_COUNT 5 -#define SHARD_COUNT (1 << LOG2_SHARD_COUNT) -#define INITIAL_SHARD_CAPACITY 8 - -#define TABLE_IDX(hash, capacity) (((hash) >> LOG2_SHARD_COUNT) % (capacity)) -#define SHARD_IDX(hash) ((hash) & ((1 << LOG2_SHARD_COUNT) - 1)) - -typedef struct interned_slice_refcount { - grpc_slice_refcount base; - grpc_slice_refcount sub; - size_t length; - gpr_atm refcnt; - uint32_t hash; - struct interned_slice_refcount *bucket_next; -} interned_slice_refcount; - -typedef struct slice_shard { - gpr_mu mu; - interned_slice_refcount **strs; - size_t count; - size_t capacity; -} slice_shard; - -/* hash seed: decided at initialization time */ -static uint32_t g_hash_seed; -static int g_forced_hash_seed = 0; - -static slice_shard g_shards[SHARD_COUNT]; - -typedef struct { - uint32_t hash; - uint32_t idx; -} static_metadata_hash_ent; - -static static_metadata_hash_ent - static_metadata_hash[4 * GRPC_STATIC_MDSTR_COUNT]; -static uint32_t max_static_metadata_hash_probe; -static uint32_t static_metadata_hash_values[GRPC_STATIC_MDSTR_COUNT]; - -static void interned_slice_ref(void *p) { - interned_slice_refcount *s = p; - GPR_ASSERT(gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) > 0); -} - -static void interned_slice_destroy(interned_slice_refcount *s) { - slice_shard *shard = &g_shards[SHARD_IDX(s->hash)]; - gpr_mu_lock(&shard->mu); - GPR_ASSERT(0 == gpr_atm_no_barrier_load(&s->refcnt)); - interned_slice_refcount **prev_next; - interned_slice_refcount *cur; - for (prev_next = &shard->strs[TABLE_IDX(s->hash, shard->capacity)], - cur = *prev_next; - cur != s; prev_next = &cur->bucket_next, cur = cur->bucket_next) - ; - *prev_next = cur->bucket_next; - shard->count--; - gpr_free(s); - gpr_mu_unlock(&shard->mu); -} - -static void interned_slice_unref(grpc_exec_ctx *exec_ctx, void *p) { - interned_slice_refcount *s = p; - if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { - interned_slice_destroy(s); - } -} - -static void interned_slice_sub_ref(void *p) { - interned_slice_ref(((char *)p) - offsetof(interned_slice_refcount, sub)); -} - -static void interned_slice_sub_unref(grpc_exec_ctx *exec_ctx, void *p) { - interned_slice_unref(exec_ctx, - ((char *)p) - offsetof(interned_slice_refcount, sub)); -} - -static uint32_t interned_slice_hash(grpc_slice slice) { - interned_slice_refcount *s = (interned_slice_refcount *)slice.refcount; - return s->hash; -} - -static int interned_slice_eq(grpc_slice a, grpc_slice b) { - return a.refcount == b.refcount; -} - -static const grpc_slice_refcount_vtable interned_slice_vtable = { - interned_slice_ref, interned_slice_unref, interned_slice_eq, - interned_slice_hash}; -static const grpc_slice_refcount_vtable interned_slice_sub_vtable = { - interned_slice_sub_ref, interned_slice_sub_unref, - grpc_slice_default_eq_impl, grpc_slice_default_hash_impl}; - -static void grow_shard(slice_shard *shard) { - size_t capacity = shard->capacity * 2; - size_t i; - interned_slice_refcount **strtab; - interned_slice_refcount *s, *next; - - GPR_TIMER_BEGIN("grow_strtab", 0); - - strtab = gpr_malloc(sizeof(interned_slice_refcount *) * capacity); - memset(strtab, 0, sizeof(interned_slice_refcount *) * capacity); - - for (i = 0; i < shard->capacity; i++) { - for (s = shard->strs[i]; s; s = next) { - size_t idx = TABLE_IDX(s->hash, capacity); - next = s->bucket_next; - s->bucket_next = strtab[idx]; - strtab[idx] = s; - } - } - - gpr_free(shard->strs); - shard->strs = strtab; - shard->capacity = capacity; - - GPR_TIMER_END("grow_strtab", 0); -} - -static grpc_slice materialize(interned_slice_refcount *s) { - grpc_slice slice; - slice.refcount = &s->base; - slice.data.refcounted.bytes = (uint8_t *)(s + 1); - slice.data.refcounted.length = s->length; - return slice; -} - -uint32_t grpc_slice_default_hash_impl(grpc_slice s) { - return gpr_murmur_hash3(GRPC_SLICE_START_PTR(s), GRPC_SLICE_LENGTH(s), - g_hash_seed); -} - -uint32_t grpc_static_slice_hash(grpc_slice s) { - return static_metadata_hash_values[GRPC_STATIC_METADATA_INDEX(s)]; -} - -int grpc_static_slice_eq(grpc_slice a, grpc_slice b) { - return GRPC_STATIC_METADATA_INDEX(a) == GRPC_STATIC_METADATA_INDEX(b); -} - -uint32_t grpc_slice_hash(grpc_slice s) { - return s.refcount == NULL ? grpc_slice_default_hash_impl(s) - : s.refcount->vtable->hash(s); -} - -grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, - bool *returned_slice_is_different) { - if (GRPC_IS_STATIC_METADATA_STRING(slice)) { - return slice; - } - - uint32_t hash = grpc_slice_hash(slice); - for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { - static_metadata_hash_ent ent = - static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; - if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - grpc_slice_eq(grpc_static_slice_table[ent.idx], slice)) { - *returned_slice_is_different = true; - return grpc_static_slice_table[ent.idx]; - } - } - - return slice; -} - -bool grpc_slice_is_interned(grpc_slice slice) { - return (slice.refcount && slice.refcount->vtable == &interned_slice_vtable) || - GRPC_IS_STATIC_METADATA_STRING(slice); -} - -grpc_slice grpc_slice_intern(grpc_slice slice) { - if (GRPC_IS_STATIC_METADATA_STRING(slice)) { - return slice; - } - - uint32_t hash = grpc_slice_hash(slice); - for (uint32_t i = 0; i <= max_static_metadata_hash_probe; i++) { - static_metadata_hash_ent ent = - static_metadata_hash[(hash + i) % GPR_ARRAY_SIZE(static_metadata_hash)]; - if (ent.hash == hash && ent.idx < GRPC_STATIC_MDSTR_COUNT && - grpc_slice_eq(grpc_static_slice_table[ent.idx], slice)) { - return grpc_static_slice_table[ent.idx]; - } - } - - interned_slice_refcount *s; - slice_shard *shard = &g_shards[SHARD_IDX(hash)]; - - gpr_mu_lock(&shard->mu); - - /* search for an existing string */ - size_t idx = TABLE_IDX(hash, shard->capacity); - for (s = shard->strs[idx]; s; s = s->bucket_next) { - if (s->hash == hash && grpc_slice_eq(slice, materialize(s))) { - if (gpr_atm_no_barrier_fetch_add(&s->refcnt, 1) == 0) { - /* If we get here, we've added a ref to something that was about to - * die - drop it immediately. - * The *only* possible path here (given the shard mutex) should be to - * drop from one ref back to zero - assert that with a CAS */ - GPR_ASSERT(gpr_atm_rel_cas(&s->refcnt, 1, 0)); - /* and treat this as if we were never here... sshhh */ - } else { - gpr_mu_unlock(&shard->mu); - GPR_TIMER_END("grpc_mdstr_from_buffer", 0); - return materialize(s); - } - } - } - - /* not found: create a new string */ - /* string data goes after the internal_string header */ - s = gpr_malloc(sizeof(*s) + GRPC_SLICE_LENGTH(slice)); - gpr_atm_rel_store(&s->refcnt, 1); - s->length = GRPC_SLICE_LENGTH(slice); - s->hash = hash; - s->base.vtable = &interned_slice_vtable; - s->base.sub_refcount = &s->sub; - s->sub.vtable = &interned_slice_sub_vtable; - s->sub.sub_refcount = &s->sub; - s->bucket_next = shard->strs[idx]; - shard->strs[idx] = s; - memcpy(s + 1, GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); - - shard->count++; - - if (shard->count > shard->capacity * 2) { - grow_shard(shard); - } - - gpr_mu_unlock(&shard->mu); - - return materialize(s); -} - -void grpc_test_only_set_slice_hash_seed(uint32_t seed) { - g_hash_seed = seed; - g_forced_hash_seed = 1; -} - -void grpc_slice_intern_init(void) { - if (!g_forced_hash_seed) { - g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; - } - for (size_t i = 0; i < SHARD_COUNT; i++) { - slice_shard *shard = &g_shards[i]; - gpr_mu_init(&shard->mu); - shard->count = 0; - shard->capacity = INITIAL_SHARD_CAPACITY; - shard->strs = gpr_malloc(sizeof(*shard->strs) * shard->capacity); - memset(shard->strs, 0, sizeof(*shard->strs) * shard->capacity); - } - for (size_t i = 0; i < GPR_ARRAY_SIZE(static_metadata_hash); i++) { - static_metadata_hash[i].hash = 0; - static_metadata_hash[i].idx = GRPC_STATIC_MDSTR_COUNT; - } - max_static_metadata_hash_probe = 0; - for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - static_metadata_hash_values[i] = - grpc_slice_default_hash_impl(grpc_static_slice_table[i]); - for (size_t j = 0; j < GPR_ARRAY_SIZE(static_metadata_hash); j++) { - size_t slot = (static_metadata_hash_values[i] + j) % - GPR_ARRAY_SIZE(static_metadata_hash); - if (static_metadata_hash[slot].idx == GRPC_STATIC_MDSTR_COUNT) { - static_metadata_hash[slot].hash = static_metadata_hash_values[i]; - static_metadata_hash[slot].idx = (uint32_t)i; - if (j > max_static_metadata_hash_probe) { - max_static_metadata_hash_probe = (uint32_t)j; - } - break; - } - } - } -} - -void grpc_slice_intern_shutdown(void) { - for (size_t i = 0; i < SHARD_COUNT; i++) { - slice_shard *shard = &g_shards[i]; - gpr_mu_destroy(&shard->mu); - /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ - if (shard->count != 0) { - gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata strings were leaked", - shard->count); - for (size_t j = 0; j < shard->capacity; j++) { - for (interned_slice_refcount *s = shard->strs[j]; s; - s = s->bucket_next) { - char *text = - grpc_dump_slice(materialize(s), GPR_DUMP_HEX | GPR_DUMP_ASCII); - gpr_log(GPR_DEBUG, "LEAKED: %s", text); - gpr_free(text); - } - } - if (grpc_iomgr_abort_on_leaks()) { - abort(); - } - } - gpr_free(shard->strs); - } -} diff --git a/src/core/lib/slice/slice_internal.h b/src/core/lib/slice/slice_internal.h index 6467b0a8d63..6185333ca72 100644 --- a/src/core/lib/slice/slice_internal.h +++ b/src/core/lib/slice/slice_internal.h @@ -46,19 +46,4 @@ void grpc_slice_buffer_reset_and_unref_internal(grpc_exec_ctx *exec_ctx, void grpc_slice_buffer_destroy_internal(grpc_exec_ctx *exec_ctx, grpc_slice_buffer *sb); -/* Check if a slice is interned */ -bool grpc_slice_is_interned(grpc_slice slice); - -void grpc_slice_intern_init(void); -void grpc_slice_intern_shutdown(void); -void grpc_test_only_set_slice_hash_seed(uint32_t key); -// if slice matches a static slice, returns the static slice -// otherwise returns the passed in slice (without reffing it) -// used for surface boundaries where we might receive an un-interned static -// string -grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, - bool *returned_slice_is_different); -uint32_t grpc_static_slice_hash(grpc_slice s); -int grpc_static_slice_eq(grpc_slice a, grpc_slice b); - #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */ diff --git a/src/core/lib/slice/slice_string_helpers.c b/src/core/lib/slice/slice_string_helpers.c index 99695007cca..839c366b32d 100644 --- a/src/core/lib/slice/slice_string_helpers.c +++ b/src/core/lib/slice/slice_string_helpers.c @@ -88,8 +88,3 @@ void grpc_slice_split(grpc_slice str, const char *sep, grpc_slice_buffer *dst) { grpc_slice_buffer_add_indexed(dst, grpc_slice_ref_internal(str)); } } - -bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t *result) { - return gpr_parse_bytes_to_uint32((const char *)GRPC_SLICE_START_PTR(str), - GRPC_SLICE_LENGTH(str), result) != 0; -} diff --git a/src/core/lib/slice/slice_string_helpers.h b/src/core/lib/slice/slice_string_helpers.h index 4a4deec6e54..151c720777b 100644 --- a/src/core/lib/slice/slice_string_helpers.h +++ b/src/core/lib/slice/slice_string_helpers.h @@ -34,15 +34,12 @@ #ifndef GRPC_CORE_LIB_SLICE_SLICE_STRING_HELPERS_H #define GRPC_CORE_LIB_SLICE_SLICE_STRING_HELPERS_H -#include #include #include #include #include -#include "src/core/lib/support/string.h" - #ifdef __cplusplus extern "C" { #endif @@ -54,8 +51,6 @@ char *grpc_dump_slice(grpc_slice slice, uint32_t flags); * should be a properly initialized instance. */ void grpc_slice_split(grpc_slice str, const char *sep, grpc_slice_buffer *dst); -bool grpc_parse_slice_to_uint32(grpc_slice str, uint32_t *result); - #ifdef __cplusplus } #endif diff --git a/src/core/lib/slice/slice_traits.h b/src/core/lib/slice/slice_traits.h deleted file mode 100644 index 8a283dc65c4..00000000000 --- a/src/core/lib/slice/slice_traits.h +++ /dev/null @@ -1,44 +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_SLICE_SLICE_TRAITS_H -#define GRPC_CORE_LIB_SLICE_SLICE_TRAITS_H - -#include -#include - -bool grpc_slice_is_legal_header(grpc_slice s); -bool grpc_slice_is_legal_nonbin_header(grpc_slice s); -bool grpc_slice_is_bin_suffixed(grpc_slice s); - -#endif /* GRPC_CORE_LIB_SLICE_SLICE_TRAITS_H */ diff --git a/src/core/lib/surface/call.c b/src/core/lib/surface/call.c index 63b0683df56..899e8fab3f6 100644 --- a/src/core/lib/surface/call.c +++ b/src/core/lib/surface/call.c @@ -56,15 +56,13 @@ #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/surface/completion_queue.h" -#include "src/core/lib/surface/validate_metadata.h" -#include "src/core/lib/transport/error_utils.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/static_metadata.h" #include "src/core/lib/transport/transport.h" /** The maximum number of concurrent batches possible. Based upon the maximum number of individually queueable ops in the batch - api: + api: - initial metadata send - message send - status/close send (depending on client/server) @@ -94,21 +92,18 @@ typedef enum { } status_source; typedef struct { - bool is_set; - grpc_error *error; + uint8_t is_set; + grpc_status_code code; + grpc_mdstr *details; } received_status; -#define MAX_ERRORS_PER_BATCH 3 - typedef struct batch_control { grpc_call *call; grpc_cq_completion cq_completion; grpc_closure finish_batch; void *notify_tag; gpr_refcount steps_to_complete; - - grpc_error *errors[MAX_ERRORS_PER_BATCH]; - gpr_atm num_errors; + grpc_error *error; uint8_t send_initial_metadata; uint8_t send_message; @@ -190,7 +185,6 @@ struct grpc_call { grpc_call *sibling_prev; grpc_slice_buffer_stream sending_stream; - grpc_byte_stream *receiving_stream; grpc_byte_buffer **receiving_buffer; grpc_slice receiving_slice; @@ -202,7 +196,8 @@ struct grpc_call { union { struct { grpc_status_code *status; - grpc_slice *status_details; + char **status_details; + size_t *status_details_capacity; } client; struct { int *cancelled; @@ -224,23 +219,13 @@ static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, grpc_status_code status, const char *description); -static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_error *error); +static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description); static void destroy_call(grpc_exec_ctx *exec_ctx, void *call_stack, grpc_error *error); static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error); -static void get_final_status(grpc_call *call, - void (*set_value)(grpc_status_code code, - void *user_data), - void *set_value_user_data, grpc_slice *details); -static void set_status_value_directly(grpc_status_code status, void *dest); -static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, - status_source source, grpc_error *error); -static void process_data_after_md(grpc_exec_ctx *exec_ctx, batch_control *bctl); -static void post_batch_completion(grpc_exec_ctx *exec_ctx, batch_control *bctl); -static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, - grpc_error *error); grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, const grpc_call_create_args *args, @@ -261,16 +246,14 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, /* Always support no compression */ GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); call->is_client = args->server_transport_data == NULL; - grpc_slice path = grpc_empty_slice(); + grpc_mdstr *path = NULL; if (call->is_client) { GPR_ASSERT(args->add_initial_metadata_count < MAX_SEND_EXTRA_METADATA_COUNT); for (i = 0; i < args->add_initial_metadata_count; i++) { call->send_extra_metadata[i].md = args->add_initial_metadata[i]; - if (grpc_slice_eq(GRPC_MDKEY(args->add_initial_metadata[i]), - GRPC_MDSTR_PATH)) { - path = grpc_slice_ref_internal( - GRPC_MDVALUE(args->add_initial_metadata[i])); + if (args->add_initial_metadata[i]->key == GRPC_MDSTR_PATH) { + path = GRPC_MDSTR_REF(args->add_initial_metadata[i]->value); } } call->send_extra_metadata_count = (int)args->add_initial_metadata_count; @@ -337,7 +320,10 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, args->server_transport_data, path, call->start_time, send_deadline, CALL_STACK_FROM_CALL(call)); if (error != GRPC_ERROR_NONE) { - cancel_with_error(exec_ctx, call, GRPC_ERROR_REF(error)); + grpc_status_code status; + const char *error_str; + grpc_error_get_status(error, &status, &error_str); + close_with_status(exec_ctx, call, status, error_str); } if (args->cq != NULL) { GPR_ASSERT( @@ -356,7 +342,7 @@ grpc_error *grpc_call_create(grpc_exec_ctx *exec_ctx, exec_ctx, CALL_STACK_FROM_CALL(call), &call->pollent); } - grpc_slice_unref_internal(exec_ctx, path); + if (path != NULL) GRPC_MDSTR_UNREF(exec_ctx, path); GPR_TIMER_END("grpc_call_create", 0); return error; @@ -391,6 +377,24 @@ void grpc_call_internal_unref(grpc_exec_ctx *exec_ctx, grpc_call *c REF_ARG) { GRPC_CALL_STACK_UNREF(exec_ctx, CALL_STACK_FROM_CALL(c), REF_REASON); } +static void get_final_status(grpc_call *call, + void (*set_value)(grpc_status_code code, + void *user_data), + void *set_value_user_data) { + int i; + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + if (call->status[i].is_set) { + set_value(call->status[i].code, set_value_user_data); + return; + } + } + if (call->is_client) { + set_value(GRPC_STATUS_UNKNOWN, set_value_user_data); + } else { + set_value(GRPC_STATUS_OK, set_value_user_data); + } +} + static void set_status_value_directly(grpc_status_code status, void *dest); static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, grpc_error *error) { @@ -406,6 +410,11 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, grpc_byte_stream_destroy(exec_ctx, c->receiving_stream); } gpr_mu_destroy(&c->mu); + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + if (c->status[i].details) { + GRPC_MDSTR_UNREF(exec_ctx, c->status[i].details); + } + } for (ii = 0; ii < c->send_extra_metadata_count; ii++) { GRPC_MDELEM_UNREF(exec_ctx, c->send_extra_metadata[ii].md); } @@ -419,20 +428,285 @@ static void destroy_call(grpc_exec_ctx *exec_ctx, void *call, } grpc_channel *channel = c->channel; - get_final_status(call, set_status_value_directly, &c->final_info.final_status, - NULL); + get_final_status(call, set_status_value_directly, + &c->final_info.final_status); c->final_info.stats.latency = gpr_time_sub(gpr_now(GPR_CLOCK_MONOTONIC), c->start_time); - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - GRPC_ERROR_UNREF(c->status[i].error); - } - grpc_call_stack_destroy(exec_ctx, CALL_STACK_FROM_CALL(c), &c->final_info, c); GRPC_CHANNEL_INTERNAL_UNREF(exec_ctx, channel, "call"); GPR_TIMER_END("destroy_call", 0); } +static void set_status_code(grpc_call *call, status_source source, + uint32_t status) { + if (call->status[source].is_set) return; + + call->status[source].is_set = 1; + call->status[source].code = (grpc_status_code)status; +} + +static void set_status_details(grpc_exec_ctx *exec_ctx, grpc_call *call, + status_source source, grpc_mdstr *status) { + if (call->status[source].details != NULL) { + GRPC_MDSTR_UNREF(exec_ctx, status); + } else { + call->status[source].details = status; + } +} + +static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, + status_source source, grpc_error *error) { + grpc_status_code status; + const char *msg; + grpc_error_get_status(error, &status, &msg); + set_status_code(call, source, (uint32_t)status); + set_status_details(exec_ctx, call, source, grpc_mdstr_from_string(msg)); +} + +static void set_incoming_compression_algorithm( + grpc_call *call, grpc_compression_algorithm algo) { + GPR_ASSERT(algo < GRPC_COMPRESS_ALGORITHMS_COUNT); + call->incoming_compression_algorithm = algo; +} + +grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( + grpc_call *call) { + grpc_compression_algorithm algorithm; + gpr_mu_lock(&call->mu); + algorithm = call->incoming_compression_algorithm; + gpr_mu_unlock(&call->mu); + return algorithm; +} + +static grpc_compression_algorithm compression_algorithm_for_level_locked( + grpc_call *call, grpc_compression_level level) { + return grpc_compression_algorithm_for_level(level, + call->encodings_accepted_by_peer); +} + +uint32_t grpc_call_test_only_get_message_flags(grpc_call *call) { + uint32_t flags; + gpr_mu_lock(&call->mu); + flags = call->test_only_last_message_flags; + gpr_mu_unlock(&call->mu); + return flags; +} + +static void destroy_encodings_accepted_by_peer(void *p) { return; } + +static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, + grpc_call *call, grpc_mdelem *mdel) { + size_t i; + grpc_compression_algorithm algorithm; + grpc_slice_buffer accept_encoding_parts; + grpc_slice accept_encoding_slice; + void *accepted_user_data; + + accepted_user_data = + grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); + if (accepted_user_data != NULL) { + call->encodings_accepted_by_peer = + (uint32_t)(((uintptr_t)accepted_user_data) - 1); + return; + } + + accept_encoding_slice = mdel->value->slice; + grpc_slice_buffer_init(&accept_encoding_parts); + grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); + + /* No need to zero call->encodings_accepted_by_peer: grpc_call_create already + * zeroes the whole grpc_call */ + /* Always support no compression */ + GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); + for (i = 0; i < accept_encoding_parts.count; i++) { + const grpc_slice *accept_encoding_entry_slice = + &accept_encoding_parts.slices[i]; + if (grpc_compression_algorithm_parse( + (const char *)GRPC_SLICE_START_PTR(*accept_encoding_entry_slice), + GRPC_SLICE_LENGTH(*accept_encoding_entry_slice), &algorithm)) { + GPR_BITSET(&call->encodings_accepted_by_peer, algorithm); + } else { + char *accept_encoding_entry_str = + grpc_dump_slice(*accept_encoding_entry_slice, GPR_DUMP_ASCII); + gpr_log(GPR_ERROR, + "Invalid entry in accept encoding metadata: '%s'. Ignoring.", + accept_encoding_entry_str); + gpr_free(accept_encoding_entry_str); + } + } + + grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); + + grpc_mdelem_set_user_data( + mdel, destroy_encodings_accepted_by_peer, + (void *)(((uintptr_t)call->encodings_accepted_by_peer) + 1)); +} + +uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { + uint32_t encodings_accepted_by_peer; + gpr_mu_lock(&call->mu); + encodings_accepted_by_peer = call->encodings_accepted_by_peer; + gpr_mu_unlock(&call->mu); + return encodings_accepted_by_peer; +} + +static void get_final_details(grpc_call *call, char **out_details, + size_t *out_details_capacity) { + int i; + for (i = 0; i < STATUS_SOURCE_COUNT; i++) { + if (call->status[i].is_set) { + if (call->status[i].details) { + grpc_slice details = call->status[i].details->slice; + size_t len = GRPC_SLICE_LENGTH(details); + if (len + 1 > *out_details_capacity) { + *out_details_capacity = + GPR_MAX(len + 1, *out_details_capacity * 3 / 2); + *out_details = gpr_realloc(*out_details, *out_details_capacity); + } + memcpy(*out_details, GRPC_SLICE_START_PTR(details), len); + (*out_details)[len] = 0; + } else { + goto no_details; + } + return; + } + } + +no_details: + if (0 == *out_details_capacity) { + *out_details_capacity = 8; + *out_details = gpr_malloc(*out_details_capacity); + } + **out_details = 0; +} + +static grpc_linked_mdelem *linked_from_md(grpc_metadata *md) { + return (grpc_linked_mdelem *)&md->internal_data; +} + +static grpc_metadata *get_md_elem(grpc_metadata *metadata, + grpc_metadata *additional_metadata, int i, + int count) { + grpc_metadata *res = + i < count ? &metadata[i] : &additional_metadata[i - count]; + GPR_ASSERT(res); + return res; +} + +static int prepare_application_metadata( + grpc_exec_ctx *exec_ctx, grpc_call *call, int count, + grpc_metadata *metadata, int is_trailing, int prepend_extra_metadata, + grpc_metadata *additional_metadata, int additional_metadata_count) { + int total_count = count + additional_metadata_count; + int i; + grpc_metadata_batch *batch = + &call->metadata_batch[0 /* is_receiving */][is_trailing]; + for (i = 0; i < total_count; i++) { + const grpc_metadata *md = + get_md_elem(metadata, additional_metadata, i, count); + grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; + GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); + l->md = grpc_mdelem_from_string_and_buffer( + exec_ctx, md->key, (const uint8_t *)md->value, md->value_length); + if (!grpc_header_key_is_legal(grpc_mdstr_as_c_string(l->md->key), + GRPC_MDSTR_LENGTH(l->md->key))) { + gpr_log(GPR_ERROR, "attempt to send invalid metadata key: %s", + grpc_mdstr_as_c_string(l->md->key)); + break; + } else if (!grpc_is_binary_header(grpc_mdstr_as_c_string(l->md->key), + GRPC_MDSTR_LENGTH(l->md->key)) && + !grpc_header_nonbin_value_is_legal( + grpc_mdstr_as_c_string(l->md->value), + GRPC_MDSTR_LENGTH(l->md->value))) { + gpr_log(GPR_ERROR, "attempt to send invalid metadata value"); + break; + } + } + if (i != total_count) { + for (int j = 0; j <= i; j++) { + const grpc_metadata *md = + get_md_elem(metadata, additional_metadata, j, count); + grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; + GRPC_MDELEM_UNREF(exec_ctx, l->md); + } + return 0; + } + if (prepend_extra_metadata) { + if (call->send_extra_metadata_count == 0) { + prepend_extra_metadata = 0; + } else { + for (i = 1; i < call->send_extra_metadata_count; i++) { + call->send_extra_metadata[i].prev = &call->send_extra_metadata[i - 1]; + } + for (i = 0; i < call->send_extra_metadata_count - 1; i++) { + call->send_extra_metadata[i].next = &call->send_extra_metadata[i + 1]; + } + } + } + for (i = 1; i < total_count; i++) { + grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); + grpc_metadata *prev_md = + get_md_elem(metadata, additional_metadata, i - 1, count); + linked_from_md(md)->prev = linked_from_md(prev_md); + } + for (i = 0; i < total_count - 1; i++) { + grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); + grpc_metadata *next_md = + get_md_elem(metadata, additional_metadata, i + 1, count); + linked_from_md(md)->next = linked_from_md(next_md); + } + + switch (prepend_extra_metadata * 2 + (total_count != 0)) { + case 0: + /* no prepend, no metadata => nothing to do */ + batch->list.head = batch->list.tail = NULL; + break; + case 1: { + /* metadata, but no prepend */ + grpc_metadata *first_md = + get_md_elem(metadata, additional_metadata, 0, count); + grpc_metadata *last_md = + get_md_elem(metadata, additional_metadata, total_count - 1, count); + batch->list.head = linked_from_md(first_md); + batch->list.tail = linked_from_md(last_md); + batch->list.head->prev = NULL; + batch->list.tail->next = NULL; + break; + } + case 2: + /* prepend, but no md */ + batch->list.head = &call->send_extra_metadata[0]; + batch->list.tail = + &call->send_extra_metadata[call->send_extra_metadata_count - 1]; + batch->list.head->prev = NULL; + batch->list.tail->next = NULL; + call->send_extra_metadata_count = 0; + break; + case 3: { + /* prepend AND md */ + grpc_metadata *first_md = + get_md_elem(metadata, additional_metadata, 0, count); + grpc_metadata *last_md = + get_md_elem(metadata, additional_metadata, total_count - 1, count); + batch->list.head = &call->send_extra_metadata[0]; + call->send_extra_metadata[call->send_extra_metadata_count - 1].next = + linked_from_md(first_md); + linked_from_md(first_md)->prev = + &call->send_extra_metadata[call->send_extra_metadata_count - 1]; + batch->list.tail = linked_from_md(last_md); + batch->list.head->prev = NULL; + batch->list.tail->next = NULL; + call->send_extra_metadata_count = 0; + break; + } + default: + GPR_UNREACHABLE_CODE(return 0); + } + + return 1; +} + void grpc_call_destroy(grpc_call *c) { int cancel; grpc_call *parent = c->parent; @@ -473,41 +747,6 @@ grpc_call_error grpc_call_cancel(grpc_call *call, void *reserved) { NULL); } -static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_transport_stream_op *op) { - grpc_call_element *elem; - - GPR_TIMER_BEGIN("execute_op", 0); - elem = CALL_ELEM_FROM_CALL(call, 0); - op->context = call->context; - elem->filter->start_transport_stream_op(exec_ctx, elem, op); - GPR_TIMER_END("execute_op", 0); -} - -char *grpc_call_get_peer(grpc_call *call) { - grpc_call_element *elem = CALL_ELEM_FROM_CALL(call, 0); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - char *result; - GRPC_API_TRACE("grpc_call_get_peer(%p)", 1, (call)); - result = elem->filter->get_peer(&exec_ctx, elem); - if (result == NULL) { - result = grpc_channel_get_target(call->channel); - } - if (result == NULL) { - result = gpr_strdup("unknown"); - } - grpc_exec_ctx_finish(&exec_ctx); - return result; -} - -grpc_call *grpc_call_from_top_element(grpc_call_element *elem) { - return CALL_FROM_TOP_ELEM(elem); -} - -/******************************************************************************* - * CANCELLATION - */ - grpc_call_error grpc_call_cancel_with_status(grpc_call *c, grpc_status_code status, const char *description, @@ -530,18 +769,26 @@ typedef struct termination_closure { grpc_closure closure; grpc_call *call; grpc_error *error; + enum { TC_CANCEL, TC_CLOSE } type; grpc_transport_stream_op op; } termination_closure; static void done_termination(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { termination_closure *tc = tcp; - GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "termination"); + switch (tc->type) { + case TC_CANCEL: + GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "cancel"); + break; + case TC_CLOSE: + GRPC_CALL_INTERNAL_UNREF(exec_ctx, tc->call, "close"); + break; + } + GRPC_ERROR_UNREF(tc->error); gpr_free(tc); } -static void send_termination(grpc_exec_ctx *exec_ctx, void *tcp, - grpc_error *error) { +static void send_cancel(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { termination_closure *tc = tcp; memset(&tc->op, 0, sizeof(tc->op)); tc->op.cancel_error = tc->error; @@ -552,263 +799,94 @@ static void send_termination(grpc_exec_ctx *exec_ctx, void *tcp, execute_op(exec_ctx, tc->call, &tc->op); } -static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, - termination_closure *tc) { - set_status_from_error(exec_ctx, tc->call, STATUS_FROM_API_OVERRIDE, - GRPC_ERROR_REF(tc->error)); - grpc_closure_init(&tc->closure, send_termination, tc, +static void send_close(grpc_exec_ctx *exec_ctx, void *tcp, grpc_error *error) { + termination_closure *tc = tcp; + memset(&tc->op, 0, sizeof(tc->op)); + tc->op.close_error = tc->error; + /* reuse closure to catch completion */ + grpc_closure_init(&tc->closure, done_termination, tc, grpc_schedule_on_exec_ctx); - GRPC_CALL_INTERNAL_REF(tc->call, "termination"); - grpc_closure_sched(exec_ctx, &tc->closure, GRPC_ERROR_NONE); - return GRPC_CALL_OK; -} - -static grpc_call_error terminate_with_error(grpc_exec_ctx *exec_ctx, - grpc_call *c, grpc_error *error) { - termination_closure *tc = gpr_malloc(sizeof(*tc)); - memset(tc, 0, sizeof(*tc)); - tc->call = c; - tc->error = error; - return terminate_with_status(exec_ctx, tc); -} - -static void cancel_with_error(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_error *error) { - terminate_with_error(exec_ctx, c, error); -} - -static grpc_error *error_from_status(grpc_status_code status, - const char *description) { - return grpc_error_set_int( - grpc_error_set_str(GRPC_ERROR_CREATE(description), - GRPC_ERROR_STR_GRPC_MESSAGE, description), - GRPC_ERROR_INT_GRPC_STATUS, status); -} - -static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, - grpc_status_code status, - const char *description) { - return terminate_with_error(exec_ctx, c, - error_from_status(status, description)); -} - -/******************************************************************************* - * FINAL STATUS CODE MANIPULATION - */ - -static void get_final_status_from(grpc_call *call, status_source from_source, - void (*set_value)(grpc_status_code code, - void *user_data), - void *set_value_user_data, - grpc_slice *details) { - grpc_status_code code; - const char *msg = NULL; - grpc_error_get_status(call->status[from_source].error, call->send_deadline, - &code, &msg, NULL); - - set_value(code, set_value_user_data); - if (details != NULL) { - *details = - msg == NULL ? grpc_empty_slice() : grpc_slice_from_copied_string(msg); - } -} - -static void get_final_status(grpc_call *call, - void (*set_value)(grpc_status_code code, - void *user_data), - void *set_value_user_data, grpc_slice *details) { - int i; - /* search for the best status we can present: ideally the error we use has a - clearly defined grpc-status, and we'll prefer that. */ - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_set && - grpc_error_has_clear_grpc_status(call->status[i].error)) { - get_final_status_from(call, (status_source)i, set_value, - set_value_user_data, details); - return; - } - } - /* If no clearly defined status exists, search for 'anything' */ - for (i = 0; i < STATUS_SOURCE_COUNT; i++) { - if (call->status[i].is_set) { - get_final_status_from(call, (status_source)i, set_value, - set_value_user_data, details); - return; - } - } - /* If nothing exists, set some default */ - if (call->is_client) { - set_value(GRPC_STATUS_UNKNOWN, set_value_user_data); - } else { - set_value(GRPC_STATUS_OK, set_value_user_data); - } -} - -static void set_status_from_error(grpc_exec_ctx *exec_ctx, grpc_call *call, - status_source source, grpc_error *error) { - if (call->status[source].is_set) { - GRPC_ERROR_UNREF(error); - return; - } - call->status[source].is_set = true; - call->status[source].error = error; -} - -/******************************************************************************* - * COMPRESSION - */ - -static void set_incoming_compression_algorithm( - grpc_call *call, grpc_compression_algorithm algo) { - GPR_ASSERT(algo < GRPC_COMPRESS_ALGORITHMS_COUNT); - call->incoming_compression_algorithm = algo; -} - -grpc_compression_algorithm grpc_call_test_only_get_compression_algorithm( - grpc_call *call) { - grpc_compression_algorithm algorithm; - gpr_mu_lock(&call->mu); - algorithm = call->incoming_compression_algorithm; - gpr_mu_unlock(&call->mu); - return algorithm; -} - -static grpc_compression_algorithm compression_algorithm_for_level_locked( - grpc_call *call, grpc_compression_level level) { - return grpc_compression_algorithm_for_level(level, - call->encodings_accepted_by_peer); -} - -uint32_t grpc_call_test_only_get_message_flags(grpc_call *call) { - uint32_t flags; - gpr_mu_lock(&call->mu); - flags = call->test_only_last_message_flags; - gpr_mu_unlock(&call->mu); - return flags; -} - -static void destroy_encodings_accepted_by_peer(void *p) { return; } - -static void set_encodings_accepted_by_peer(grpc_exec_ctx *exec_ctx, - grpc_call *call, grpc_mdelem mdel) { - size_t i; - grpc_compression_algorithm algorithm; - grpc_slice_buffer accept_encoding_parts; - grpc_slice accept_encoding_slice; - void *accepted_user_data; - - accepted_user_data = - grpc_mdelem_get_user_data(mdel, destroy_encodings_accepted_by_peer); - if (accepted_user_data != NULL) { - call->encodings_accepted_by_peer = - (uint32_t)(((uintptr_t)accepted_user_data) - 1); - return; - } + tc->op.on_complete = &tc->closure; + execute_op(exec_ctx, tc->call, &tc->op); +} - accept_encoding_slice = GRPC_MDVALUE(mdel); - grpc_slice_buffer_init(&accept_encoding_parts); - grpc_slice_split(accept_encoding_slice, ",", &accept_encoding_parts); +static grpc_call_error terminate_with_status(grpc_exec_ctx *exec_ctx, + termination_closure *tc) { + set_status_from_error(exec_ctx, tc->call, STATUS_FROM_API_OVERRIDE, + tc->error); - /* No need to zero call->encodings_accepted_by_peer: grpc_call_create already - * zeroes the whole grpc_call */ - /* Always support no compression */ - GPR_BITSET(&call->encodings_accepted_by_peer, GRPC_COMPRESS_NONE); - for (i = 0; i < accept_encoding_parts.count; i++) { - grpc_slice accept_encoding_entry_slice = accept_encoding_parts.slices[i]; - if (grpc_compression_algorithm_parse(accept_encoding_entry_slice, - &algorithm)) { - GPR_BITSET(&call->encodings_accepted_by_peer, algorithm); - } else { - char *accept_encoding_entry_str = - grpc_slice_to_c_string(accept_encoding_entry_slice); - gpr_log(GPR_ERROR, - "Invalid entry in accept encoding metadata: '%s'. Ignoring.", - accept_encoding_entry_str); - gpr_free(accept_encoding_entry_str); - } + if (tc->type == TC_CANCEL) { + grpc_closure_init(&tc->closure, send_cancel, tc, grpc_schedule_on_exec_ctx); + GRPC_CALL_INTERNAL_REF(tc->call, "cancel"); + } else if (tc->type == TC_CLOSE) { + grpc_closure_init(&tc->closure, send_close, tc, grpc_schedule_on_exec_ctx); + GRPC_CALL_INTERNAL_REF(tc->call, "close"); } + grpc_closure_sched(exec_ctx, &tc->closure, GRPC_ERROR_NONE); + return GRPC_CALL_OK; +} - grpc_slice_buffer_destroy_internal(exec_ctx, &accept_encoding_parts); +static grpc_call_error cancel_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description) { + GPR_ASSERT(status != GRPC_STATUS_OK); + termination_closure *tc = gpr_malloc(sizeof(*tc)); + memset(tc, 0, sizeof(termination_closure)); + tc->type = TC_CANCEL; + tc->call = c; + tc->error = grpc_error_set_int( + grpc_error_set_str(GRPC_ERROR_CREATE(description), + GRPC_ERROR_STR_GRPC_MESSAGE, description), + GRPC_ERROR_INT_GRPC_STATUS, status); - grpc_mdelem_set_user_data( - mdel, destroy_encodings_accepted_by_peer, - (void *)(((uintptr_t)call->encodings_accepted_by_peer) + 1)); + return terminate_with_status(exec_ctx, tc); } -uint32_t grpc_call_test_only_get_encodings_accepted_by_peer(grpc_call *call) { - uint32_t encodings_accepted_by_peer; - gpr_mu_lock(&call->mu); - encodings_accepted_by_peer = call->encodings_accepted_by_peer; - gpr_mu_unlock(&call->mu); - return encodings_accepted_by_peer; -} +static grpc_call_error close_with_status(grpc_exec_ctx *exec_ctx, grpc_call *c, + grpc_status_code status, + const char *description) { + GPR_ASSERT(status != GRPC_STATUS_OK); + termination_closure *tc = gpr_malloc(sizeof(*tc)); + memset(tc, 0, sizeof(termination_closure)); + tc->type = TC_CLOSE; + tc->call = c; + tc->error = grpc_error_set_int( + grpc_error_set_str(GRPC_ERROR_CREATE(description), + GRPC_ERROR_STR_GRPC_MESSAGE, description), + GRPC_ERROR_INT_GRPC_STATUS, status); -static grpc_linked_mdelem *linked_from_md(grpc_metadata *md) { - return (grpc_linked_mdelem *)&md->internal_data; + return terminate_with_status(exec_ctx, tc); } -static grpc_metadata *get_md_elem(grpc_metadata *metadata, - grpc_metadata *additional_metadata, int i, - int count) { - grpc_metadata *res = - i < count ? &metadata[i] : &additional_metadata[i - count]; - GPR_ASSERT(res); - return res; +static void execute_op(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_transport_stream_op *op) { + grpc_call_element *elem; + + GPR_TIMER_BEGIN("execute_op", 0); + elem = CALL_ELEM_FROM_CALL(call, 0); + op->context = call->context; + elem->filter->start_transport_stream_op(exec_ctx, elem, op); + GPR_TIMER_END("execute_op", 0); } -static int prepare_application_metadata( - grpc_exec_ctx *exec_ctx, grpc_call *call, int count, - grpc_metadata *metadata, int is_trailing, int prepend_extra_metadata, - grpc_metadata *additional_metadata, int additional_metadata_count) { - int total_count = count + additional_metadata_count; - int i; - grpc_metadata_batch *batch = - &call->metadata_batch[0 /* is_receiving */][is_trailing]; - for (i = 0; i < total_count; i++) { - const grpc_metadata *md = - get_md_elem(metadata, additional_metadata, i, count); - grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; - GPR_ASSERT(sizeof(grpc_linked_mdelem) == sizeof(md->internal_data)); - if (!GRPC_LOG_IF_ERROR("validate_metadata", - grpc_validate_header_key_is_legal(md->key))) { - break; - } else if (!grpc_is_binary_header(md->key) && - !GRPC_LOG_IF_ERROR( - "validate_metadata", - grpc_validate_header_nonbin_value_is_legal(md->value))) { - break; - } - l->md = grpc_mdelem_from_grpc_metadata(exec_ctx, (grpc_metadata *)md); - } - if (i != total_count) { - for (int j = 0; j < i; j++) { - const grpc_metadata *md = - get_md_elem(metadata, additional_metadata, j, count); - grpc_linked_mdelem *l = (grpc_linked_mdelem *)&md->internal_data; - GRPC_MDELEM_UNREF(exec_ctx, l->md); - } - return 0; - } - if (prepend_extra_metadata) { - if (call->send_extra_metadata_count == 0) { - prepend_extra_metadata = 0; - } else { - for (i = 0; i < call->send_extra_metadata_count; i++) { - GRPC_LOG_IF_ERROR("prepare_application_metadata", - grpc_metadata_batch_link_tail( - exec_ctx, batch, &call->send_extra_metadata[i])); - } - } +char *grpc_call_get_peer(grpc_call *call) { + grpc_call_element *elem = CALL_ELEM_FROM_CALL(call, 0); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + char *result; + GRPC_API_TRACE("grpc_call_get_peer(%p)", 1, (call)); + result = elem->filter->get_peer(&exec_ctx, elem); + if (result == NULL) { + result = grpc_channel_get_target(call->channel); } - for (i = 0; i < total_count; i++) { - grpc_metadata *md = get_md_elem(metadata, additional_metadata, i, count); - GRPC_LOG_IF_ERROR( - "prepare_application_metadata", - grpc_metadata_batch_link_tail(exec_ctx, batch, linked_from_md(md))); + if (result == NULL) { + result = gpr_strdup("unknown"); } - call->send_extra_metadata_count = 0; + grpc_exec_ctx_finish(&exec_ctx); + return result; +} - return 1; +grpc_call *grpc_call_from_top_element(grpc_call_element *elem) { + return CALL_FROM_TOP_ELEM(elem); } /* we offset status by a small amount when storing it into transport metadata @@ -817,17 +895,19 @@ static int prepare_application_metadata( #define STATUS_OFFSET 1 static void destroy_status(void *ignored) {} -static uint32_t decode_status(grpc_mdelem md) { +static uint32_t decode_status(grpc_mdelem *md) { uint32_t status; void *user_data; - if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_0)) return 0; - if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_1)) return 1; - if (grpc_mdelem_eq(md, GRPC_MDELEM_GRPC_STATUS_2)) return 2; + if (md == GRPC_MDELEM_GRPC_STATUS_0) return 0; + if (md == GRPC_MDELEM_GRPC_STATUS_1) return 1; + if (md == GRPC_MDELEM_GRPC_STATUS_2) return 2; user_data = grpc_mdelem_get_user_data(md, destroy_status); if (user_data != NULL) { status = ((uint32_t)(intptr_t)user_data) - STATUS_OFFSET; } else { - if (!grpc_parse_slice_to_uint32(GRPC_MDVALUE(md), &status)) { + if (!gpr_parse_bytes_to_uint32(grpc_mdstr_as_c_string(md->value), + GRPC_SLICE_LENGTH(md->value->slice), + &status)) { status = GRPC_STATUS_UNKNOWN; /* could not parse status code */ } grpc_mdelem_set_user_data(md, destroy_status, @@ -836,104 +916,93 @@ static uint32_t decode_status(grpc_mdelem md) { return status; } -static grpc_compression_algorithm decode_compression(grpc_mdelem md) { +static grpc_compression_algorithm decode_compression(grpc_mdelem *md) { grpc_compression_algorithm algorithm = - grpc_compression_algorithm_from_slice(GRPC_MDVALUE(md)); + grpc_compression_algorithm_from_mdstr(md->value); if (algorithm == GRPC_COMPRESS_ALGORITHMS_COUNT) { - char *md_c_str = grpc_slice_to_c_string(GRPC_MDVALUE(md)); + const char *md_c_str = grpc_mdstr_as_c_string(md->value); gpr_log(GPR_ERROR, "Invalid incoming compression algorithm: '%s'. Interpreting " "incoming data as uncompressed.", md_c_str); - gpr_free(md_c_str); return GRPC_COMPRESS_NONE; } return algorithm; } -static void recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_metadata_batch *b) { - if (b->idx.named.grpc_status != NULL) { - uint32_t status_code = decode_status(b->idx.named.grpc_status->md); - grpc_error *error = - status_code == GRPC_STATUS_OK - ? GRPC_ERROR_NONE - : grpc_error_set_int(GRPC_ERROR_CREATE("Error received from peer"), - GRPC_ERROR_INT_GRPC_STATUS, - (intptr_t)status_code); - - if (b->idx.named.grpc_message != NULL) { - char *msg = - grpc_slice_to_c_string(GRPC_MDVALUE(b->idx.named.grpc_message->md)); - error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(msg); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_message); - } else { - error = grpc_error_set_str(error, GRPC_ERROR_STR_GRPC_MESSAGE, ""); - } - - set_status_from_error(exec_ctx, call, STATUS_FROM_WIRE, error); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_status); - } +static grpc_mdelem *recv_common_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, + grpc_mdelem *elem) { + if (elem->key == GRPC_MDSTR_GRPC_STATUS) { + GPR_TIMER_BEGIN("status", 0); + set_status_code(call, STATUS_FROM_WIRE, decode_status(elem)); + GPR_TIMER_END("status", 0); + return NULL; + } else if (elem->key == GRPC_MDSTR_GRPC_MESSAGE) { + GPR_TIMER_BEGIN("status-details", 0); + set_status_details(exec_ctx, call, STATUS_FROM_WIRE, + GRPC_MDSTR_REF(elem->value)); + GPR_TIMER_END("status-details", 0); + return NULL; + } + return elem; } -static void publish_app_metadata(grpc_call *call, grpc_metadata_batch *b, - int is_trailing) { - if (b->list.count == 0) return; - GPR_TIMER_BEGIN("publish_app_metadata", 0); +static grpc_mdelem *publish_app_metadata(grpc_call *call, grpc_mdelem *elem, + int is_trailing) { grpc_metadata_array *dest; grpc_metadata *mdusr; + GPR_TIMER_BEGIN("publish_app_metadata", 0); dest = call->buffered_metadata[is_trailing]; - if (dest->count + b->list.count > dest->capacity) { - dest->capacity = - GPR_MAX(dest->capacity + b->list.count, dest->capacity * 3 / 2); + if (dest->count == dest->capacity) { + dest->capacity = GPR_MAX(dest->capacity + 8, dest->capacity * 2); dest->metadata = gpr_realloc(dest->metadata, sizeof(grpc_metadata) * dest->capacity); } - for (grpc_linked_mdelem *l = b->list.head; l != NULL; l = l->next) { - mdusr = &dest->metadata[dest->count++]; - /* we pass back borrowed slices that are valid whilst the call is valid */ - mdusr->key = GRPC_MDKEY(l->md); - mdusr->value = GRPC_MDVALUE(l->md); - } + mdusr = &dest->metadata[dest->count++]; + mdusr->key = grpc_mdstr_as_c_string(elem->key); + mdusr->value = grpc_mdstr_as_c_string(elem->value); + mdusr->value_length = GRPC_SLICE_LENGTH(elem->value->slice); GPR_TIMER_END("publish_app_metadata", 0); + return elem; } -static void recv_initial_filter(grpc_exec_ctx *exec_ctx, grpc_call *call, - grpc_metadata_batch *b) { - recv_common_filter(exec_ctx, call, b); - - if (b->idx.named.grpc_encoding != NULL) { +static grpc_mdelem *recv_initial_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem *elem) { + grpc_call *call = args; + elem = recv_common_filter(exec_ctx, call, elem); + if (elem == NULL) { + return NULL; + } else if (elem->key == GRPC_MDSTR_GRPC_ENCODING) { GPR_TIMER_BEGIN("incoming_compression_algorithm", 0); - set_incoming_compression_algorithm( - call, decode_compression(b->idx.named.grpc_encoding->md)); + set_incoming_compression_algorithm(call, decode_compression(elem)); GPR_TIMER_END("incoming_compression_algorithm", 0); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_encoding); - } - - if (b->idx.named.grpc_accept_encoding != NULL) { + return NULL; + } else if (elem->key == GRPC_MDSTR_GRPC_ACCEPT_ENCODING) { GPR_TIMER_BEGIN("encodings_accepted_by_peer", 0); - set_encodings_accepted_by_peer(exec_ctx, call, - b->idx.named.grpc_accept_encoding->md); - grpc_metadata_batch_remove(exec_ctx, b, b->idx.named.grpc_accept_encoding); + set_encodings_accepted_by_peer(exec_ctx, call, elem); GPR_TIMER_END("encodings_accepted_by_peer", 0); + return NULL; + } else { + return publish_app_metadata(call, elem, 0); } - - publish_app_metadata(call, b, false); } -static void recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, - grpc_metadata_batch *b) { +static grpc_mdelem *recv_trailing_filter(grpc_exec_ctx *exec_ctx, void *args, + grpc_mdelem *elem) { grpc_call *call = args; - recv_common_filter(exec_ctx, call, b); - publish_app_metadata(call, b, true); + elem = recv_common_filter(exec_ctx, call, elem); + if (elem == NULL) { + return NULL; + } else { + return publish_app_metadata(call, elem, 1); + } } grpc_call_stack *grpc_call_get_call_stack(grpc_call *call) { return CALL_STACK_FROM_CALL(call); } -/******************************************************************************* +/* * BATCH API IMPLEMENTATION */ @@ -984,83 +1053,14 @@ static void finish_batch_completion(grpc_exec_ctx *exec_ctx, void *user_data, GRPC_CALL_INTERNAL_UNREF(exec_ctx, call, "completion"); } -static grpc_error *consolidate_batch_errors(batch_control *bctl) { - size_t n = (size_t)gpr_atm_no_barrier_load(&bctl->num_errors); - if (n == 0) { - return GRPC_ERROR_NONE; - } else if (n == 1) { - return bctl->errors[0]; - } else { - grpc_error *error = - GRPC_ERROR_CREATE_REFERENCING("Call batch failed", bctl->errors, n); - for (size_t i = 0; i < n; i++) { - GRPC_ERROR_UNREF(bctl->errors[i]); - } - return error; - } -} - static void post_batch_completion(grpc_exec_ctx *exec_ctx, batch_control *bctl) { - grpc_call *child_call; - grpc_call *next_child_call; grpc_call *call = bctl->call; - grpc_error *error = consolidate_batch_errors(bctl); - - gpr_mu_lock(&call->mu); - - if (error != GRPC_ERROR_NONE) { - set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, - GRPC_ERROR_REF(error)); - } - - if (bctl->send_initial_metadata) { - grpc_metadata_batch_destroy( - exec_ctx, - &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); - } - if (bctl->send_message) { - call->sending_message = false; - } - if (bctl->send_final_op) { - grpc_metadata_batch_destroy( - exec_ctx, - &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); - } + grpc_error *error = bctl->error; if (bctl->recv_final_op) { - grpc_metadata_batch *md = - &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; - recv_trailing_filter(exec_ctx, call, md); - - call->received_final_op = true; - /* propagate cancellation to any interested children */ - child_call = call->first_child; - if (child_call != NULL) { - do { - next_child_call = child_call->sibling_next; - if (child_call->cancellation_is_inherited) { - GRPC_CALL_INTERNAL_REF(child_call, "propagate_cancel"); - grpc_call_cancel(child_call, NULL); - GRPC_CALL_INTERNAL_UNREF(exec_ctx, child_call, "propagate_cancel"); - } - child_call = next_child_call; - } while (child_call != call->first_child); - } - - if (call->is_client) { - get_final_status(call, set_status_value_directly, - call->final_op.client.status, - call->final_op.client.status_details); - } else { - get_final_status(call, set_cancelled_value, - call->final_op.server.cancelled, NULL); - } - GRPC_ERROR_UNREF(error); error = GRPC_ERROR_NONE; } - gpr_mu_unlock(&call->mu); - if (bctl->is_notify_tag_closure) { /* unrefs bctl->error */ grpc_closure_run(exec_ctx, bctl->notify_tag, error); @@ -1077,12 +1077,6 @@ static void post_batch_completion(grpc_exec_ctx *exec_ctx, } } -static void finish_batch_step(grpc_exec_ctx *exec_ctx, batch_control *bctl) { - if (gpr_unref(&bctl->steps_to_complete)) { - post_batch_completion(exec_ctx, bctl); - } -} - static void continue_receiving_slices(grpc_exec_ctx *exec_ctx, batch_control *bctl) { grpc_call *call = bctl->call; @@ -1093,7 +1087,9 @@ static void continue_receiving_slices(grpc_exec_ctx *exec_ctx, call->receiving_message = 0; grpc_byte_stream_destroy(exec_ctx, call->receiving_stream); call->receiving_stream = NULL; - finish_batch_step(exec_ctx, bctl); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } return; } if (grpc_byte_stream_next(exec_ctx, call->receiving_stream, @@ -1124,7 +1120,9 @@ static void receiving_slice_ready(grpc_exec_ctx *exec_ctx, void *bctlp, call->receiving_stream = NULL; grpc_byte_buffer_destroy(*call->receiving_buffer); *call->receiving_buffer = NULL; - finish_batch_step(exec_ctx, bctl); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } } } @@ -1134,7 +1132,9 @@ static void process_data_after_md(grpc_exec_ctx *exec_ctx, if (call->receiving_stream == NULL) { *call->receiving_buffer = NULL; call->receiving_message = 0; - finish_batch_step(exec_ctx, bctl); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } } else { call->test_only_last_message_flags = call->receiving_stream->flags; if ((call->receiving_stream->flags & GRPC_WRITE_INTERNAL_COMPRESS) && @@ -1154,11 +1154,14 @@ static void receiving_stream_ready(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error) { batch_control *bctl = bctlp; grpc_call *call = bctl->call; - gpr_mu_lock(&bctl->call->mu); if (error != GRPC_ERROR_NONE) { - cancel_with_error(exec_ctx, call, GRPC_ERROR_REF(error)); + grpc_status_code status; + const char *msg; + grpc_error_get_status(error, &status, &msg); + close_with_status(exec_ctx, call, status, msg); } - if (call->has_initial_md_been_received || error != GRPC_ERROR_NONE || + gpr_mu_lock(&bctl->call->mu); + if (bctl->call->has_initial_md_been_received || error != GRPC_ERROR_NONE || call->receiving_stream == NULL) { gpr_mu_unlock(&bctl->call->mu); process_data_after_md(exec_ctx, bctlp); @@ -1183,7 +1186,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, gpr_asprintf(&error_msg, "Invalid compression algorithm value '%d'.", algo); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); + close_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); } else if (grpc_compression_options_is_algorithm_enabled( &compression_options, algo) == 0) { /* check if algorithm is supported by current channel config */ @@ -1192,7 +1195,7 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, gpr_asprintf(&error_msg, "Compression algorithm '%s' is disabled.", algo_name); gpr_log(GPR_ERROR, "%s", error_msg); - cancel_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); + close_with_status(exec_ctx, call, GRPC_STATUS_UNIMPLEMENTED, error_msg); } else { call->incoming_compression_algorithm = algo; } @@ -1218,12 +1221,12 @@ static void validate_filtered_metadata(grpc_exec_ctx *exec_ctx, } } -static void add_batch_error(grpc_exec_ctx *exec_ctx, batch_control *bctl, - grpc_error *error) { +static void add_batch_error(batch_control *bctl, grpc_error *error) { if (error == GRPC_ERROR_NONE) return; - cancel_with_error(exec_ctx, bctl->call, GRPC_ERROR_REF(error)); - int idx = (int)gpr_atm_no_barrier_fetch_add(&bctl->num_errors, 1); - bctl->errors[idx] = error; + if (bctl->error == GRPC_ERROR_NONE) { + bctl->error = GRPC_ERROR_CREATE("Call batch operation failed"); + } + bctl->error = grpc_error_add_child(bctl->error, error); } static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, @@ -1233,13 +1236,12 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, gpr_mu_lock(&call->mu); - add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); + add_batch_error(bctl, GRPC_ERROR_REF(error)); if (error == GRPC_ERROR_NONE) { grpc_metadata_batch *md = &call->metadata_batch[1 /* is_receiving */][0 /* is_trailing */]; - recv_initial_filter(exec_ctx, call, md); + grpc_metadata_batch_filter(exec_ctx, md, recv_initial_filter, call); - /* TODO(ctiller): this could be moved into recv_initial_filter now */ GPR_TIMER_BEGIN("validate_filtered_metadata", 0); validate_filtered_metadata(exec_ctx, bctl); GPR_TIMER_END("validate_filtered_metadata", 0); @@ -1263,15 +1265,85 @@ static void receiving_initial_metadata_ready(grpc_exec_ctx *exec_ctx, gpr_mu_unlock(&call->mu); - finish_batch_step(exec_ctx, bctl); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } } static void finish_batch(grpc_exec_ctx *exec_ctx, void *bctlp, grpc_error *error) { batch_control *bctl = bctlp; + grpc_call *call = bctl->call; + grpc_call *child_call; + grpc_call *next_child_call; + + GRPC_ERROR_REF(error); + + gpr_mu_lock(&call->mu); + + // If the error has an associated status code, set the call's status. + intptr_t status; + if (error != GRPC_ERROR_NONE && + grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, &status)) { + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); + } + + if (bctl->send_initial_metadata) { + if (error != GRPC_ERROR_NONE) { + set_status_from_error(exec_ctx, call, STATUS_FROM_CORE, error); + } + grpc_metadata_batch_destroy( + exec_ctx, + &call->metadata_batch[0 /* is_receiving */][0 /* is_trailing */]); + } + if (bctl->send_message) { + call->sending_message = 0; + } + if (bctl->send_final_op) { + grpc_metadata_batch_destroy( + exec_ctx, + &call->metadata_batch[0 /* is_receiving */][1 /* is_trailing */]); + } + if (bctl->recv_final_op) { + grpc_metadata_batch *md = + &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; + grpc_metadata_batch_filter(exec_ctx, md, recv_trailing_filter, call); - add_batch_error(exec_ctx, bctl, GRPC_ERROR_REF(error)); - finish_batch_step(exec_ctx, bctl); + call->received_final_op = true; + /* propagate cancellation to any interested children */ + child_call = call->first_child; + if (child_call != NULL) { + do { + next_child_call = child_call->sibling_next; + if (child_call->cancellation_is_inherited) { + GRPC_CALL_INTERNAL_REF(child_call, "propagate_cancel"); + grpc_call_cancel(child_call, NULL); + GRPC_CALL_INTERNAL_UNREF(exec_ctx, child_call, "propagate_cancel"); + } + child_call = next_child_call; + } while (child_call != call->first_child); + } + + if (call->is_client) { + get_final_status(call, set_status_value_directly, + call->final_op.client.status); + get_final_details(call, call->final_op.client.status_details, + call->final_op.client.status_details_capacity); + } else { + get_final_status(call, set_cancelled_value, + call->final_op.server.cancelled); + } + + GRPC_ERROR_UNREF(error); + error = GRPC_ERROR_NONE; + } + add_batch_error(bctl, GRPC_ERROR_REF(error)); + gpr_mu_unlock(&call->mu); + if (gpr_unref(&bctl->steps_to_complete)) { + post_batch_completion(exec_ctx, bctl); + } + + GRPC_ERROR_UNREF(error); } static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, @@ -1305,6 +1377,7 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, if (nops == 0) { GRPC_CALL_INTERNAL_REF(call, "completion"); + bctl->error = GRPC_ERROR_NONE; if (!is_notify_tag_closure) { grpc_cq_begin_op(call->cq, notify_tag); } @@ -1353,10 +1426,13 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, const grpc_compression_algorithm calgo = compression_algorithm_for_level_locked( call, effective_compression_level); + char *calgo_name = NULL; + grpc_compression_algorithm_name(calgo, &calgo_name); // the following will be picked up by the compress filter and used as // the call's compression algorithm. - compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; - compression_md.value = grpc_compression_algorithm_slice(calgo); + compression_md.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; + compression_md.value = calgo_name; + compression_md.value_length = strlen(calgo_name); additional_metadata_count++; } @@ -1449,25 +1525,19 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->send_extra_metadata_count = 1; call->send_extra_metadata[0].md = grpc_channel_get_reffed_status_elem( exec_ctx, call->channel, op->data.send_status_from_server.status); - { - grpc_error *override_error = GRPC_ERROR_NONE; - if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { - override_error = GRPC_ERROR_CREATE("Error from server send status"); - } - if (op->data.send_status_from_server.status_details != NULL) { - call->send_extra_metadata[1].md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_slice_ref_internal( - *op->data.send_status_from_server.status_details)); - call->send_extra_metadata_count++; - char *msg = grpc_slice_to_c_string( - GRPC_MDVALUE(call->send_extra_metadata[1].md)); - override_error = grpc_error_set_str( - override_error, GRPC_ERROR_STR_GRPC_MESSAGE, msg); - gpr_free(msg); - } - set_status_from_error(exec_ctx, call, STATUS_FROM_API_OVERRIDE, - override_error); + if (op->data.send_status_from_server.status_details != NULL) { + call->send_extra_metadata[1].md = grpc_mdelem_from_metadata_strings( + exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, + grpc_mdstr_from_string( + op->data.send_status_from_server.status_details)); + call->send_extra_metadata_count++; + set_status_details( + exec_ctx, call, STATUS_FROM_API_OVERRIDE, + GRPC_MDSTR_REF(call->send_extra_metadata[1].md->value)); + } + if (op->data.send_status_from_server.status != GRPC_STATUS_OK) { + set_status_code(call, STATUS_FROM_API_OVERRIDE, + (uint32_t)op->data.send_status_from_server.status); } if (!prepare_application_metadata( exec_ctx, call, @@ -1545,6 +1615,8 @@ static grpc_call_error call_start_batch(grpc_exec_ctx *exec_ctx, call->final_op.client.status = op->data.recv_status_on_client.status; call->final_op.client.status_details = op->data.recv_status_on_client.status_details; + call->final_op.client.status_details_capacity = + op->data.recv_status_on_client.status_details_capacity; bctl->recv_final_op = 1; stream_op->recv_trailing_metadata = &call->metadata_batch[1 /* is_receiving */][1 /* is_trailing */]; diff --git a/src/core/lib/surface/call.h b/src/core/lib/surface/call.h index 8c46a83d427..233340c3298 100644 --- a/src/core/lib/surface/call.h +++ b/src/core/lib/surface/call.h @@ -61,7 +61,7 @@ typedef struct grpc_call_create_args { const void *server_transport_data; - grpc_mdelem *add_initial_metadata; + grpc_mdelem **add_initial_metadata; size_t add_initial_metadata_count; gpr_timespec send_deadline; diff --git a/src/core/lib/surface/call_details.c b/src/core/lib/surface/call_details.c index d0f88e19690..fe73da3f552 100644 --- a/src/core/lib/surface/call_details.c +++ b/src/core/lib/surface/call_details.c @@ -36,21 +36,15 @@ #include -#include "src/core/lib/iomgr/exec_ctx.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" void grpc_call_details_init(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_init(cd=%p)", 1, (cd)); memset(cd, 0, sizeof(*cd)); - cd->method = grpc_empty_slice(); - cd->host = grpc_empty_slice(); } void grpc_call_details_destroy(grpc_call_details* cd) { GRPC_API_TRACE("grpc_call_details_destroy(cd=%p)", 1, (cd)); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice_unref_internal(&exec_ctx, cd->method); - grpc_slice_unref_internal(&exec_ctx, cd->host); - grpc_exec_ctx_finish(&exec_ctx); + gpr_free(cd->method); + gpr_free(cd->host); } diff --git a/src/core/lib/surface/call_log_batch.c b/src/core/lib/surface/call_log_batch.c index 7fc58e19c29..31c074f15dc 100644 --- a/src/core/lib/surface/call_log_batch.c +++ b/src/core/lib/surface/call_log_batch.c @@ -35,22 +35,17 @@ #include #include -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" static void add_metadata(gpr_strvec *b, const grpc_metadata *md, size_t count) { size_t i; - if (md == NULL) { - gpr_strvec_add(b, gpr_strdup("(nil)")); - return; - } for (i = 0; i < count; i++) { gpr_strvec_add(b, gpr_strdup("\nkey=")); - gpr_strvec_add(b, grpc_slice_to_c_string(md[i].key)); + gpr_strvec_add(b, gpr_strdup(md[i].key)); gpr_strvec_add(b, gpr_strdup(" value=")); - gpr_strvec_add(b, - grpc_dump_slice(md[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII)); + gpr_strvec_add(b, gpr_dump(md[i].value, md[i].value_length, + GPR_DUMP_HEX | GPR_DUMP_ASCII)); } } @@ -75,16 +70,10 @@ char *grpc_op_string(const grpc_op *op) { gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT")); break; case GRPC_OP_SEND_STATUS_FROM_SERVER: - gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=", - op->data.send_status_from_server.status); + gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=%s", + op->data.send_status_from_server.status, + op->data.send_status_from_server.status_details); gpr_strvec_add(&b, tmp); - if (op->data.send_status_from_server.status_details != NULL) { - gpr_strvec_add(&b, grpc_dump_slice( - *op->data.send_status_from_server.status_details, - GPR_DUMP_ASCII)); - } else { - gpr_strvec_add(&b, gpr_strdup("(null)")); - } add_metadata(&b, op->data.send_status_from_server.trailing_metadata, op->data.send_status_from_server.trailing_metadata_count); break; diff --git a/src/core/lib/surface/channel.c b/src/core/lib/surface/channel.c index 429dbad7c77..b87295786e5 100644 --- a/src/core/lib/surface/channel.c +++ b/src/core/lib/surface/channel.c @@ -43,7 +43,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/iomgr/iomgr.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/support/string.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" @@ -58,15 +57,15 @@ #define NUM_CACHED_STATUS_ELEMS 3 typedef struct registered_call { - grpc_mdelem path; - grpc_mdelem authority; + grpc_mdelem *path; + grpc_mdelem *authority; struct registered_call *next; } registered_call; struct grpc_channel { int is_client; grpc_compression_options compression_options; - grpc_mdelem default_authority; + grpc_mdelem *default_authority; gpr_mu registered_call_mu; registered_call *registered_calls; @@ -103,8 +102,9 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, exec_ctx, builder, sizeof(grpc_channel), 1, destroy_channel, NULL, (void **)&channel); if (error != GRPC_ERROR_NONE) { - gpr_log(GPR_ERROR, "channel stack builder failed: %s", - grpc_error_string(error)); + const char *msg = grpc_error_string(error); + gpr_log(GPR_ERROR, "channel stack builder failed: %s", msg); + grpc_error_free_string(msg); GRPC_ERROR_UNREF(error); goto done; } @@ -116,19 +116,19 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, channel->registered_calls = NULL; grpc_compression_options_init(&channel->compression_options); + for (size_t i = 0; i < args->num_args; i++) { if (0 == strcmp(args->args[i].key, GRPC_ARG_DEFAULT_AUTHORITY)) { if (args->args[i].type != GRPC_ARG_STRING) { gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_ARG_DEFAULT_AUTHORITY); } else { - if (!GRPC_MDISNULL(channel->default_authority)) { + if (channel->default_authority) { /* setting this takes precedence over anything else */ GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); } - channel->default_authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_from_copied_string(args->args[i].value.string)); + channel->default_authority = grpc_mdelem_from_strings( + exec_ctx, ":authority", args->args[i].value.string); } } else if (0 == strcmp(args->args[i].key, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG)) { @@ -136,15 +136,14 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, gpr_log(GPR_ERROR, "%s ignored: it must be a string", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - if (!GRPC_MDISNULL(channel->default_authority)) { + if (channel->default_authority) { /* other ways of setting this (notably ssl) take precedence */ gpr_log(GPR_ERROR, "%s ignored: default host already set some other way", GRPC_SSL_TARGET_NAME_OVERRIDE_ARG); } else { - channel->default_authority = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_from_copied_string(args->args[i].value.string)); + channel->default_authority = grpc_mdelem_from_strings( + exec_ctx, ":authority", args->args[i].value.string); } } } else if (0 == strcmp(args->args[i].key, @@ -192,18 +191,18 @@ void grpc_channel_get_info(grpc_channel *channel, static grpc_call *grpc_channel_create_call_internal( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *cq, - grpc_pollset_set *pollset_set_alternative, grpc_mdelem path_mdelem, - grpc_mdelem authority_mdelem, gpr_timespec deadline) { - grpc_mdelem send_metadata[2]; + grpc_pollset_set *pollset_set_alternative, grpc_mdelem *path_mdelem, + grpc_mdelem *authority_mdelem, gpr_timespec deadline) { + grpc_mdelem *send_metadata[2]; size_t num_metadata = 0; GPR_ASSERT(channel->is_client); GPR_ASSERT(!(cq != NULL && pollset_set_alternative != NULL)); send_metadata[num_metadata++] = path_mdelem; - if (!GRPC_MDISNULL(authority_mdelem)) { + if (authority_mdelem != NULL) { send_metadata[num_metadata++] = authority_mdelem; - } else if (!GRPC_MDISNULL(channel->default_authority)) { + } else if (channel->default_authority != NULL) { send_metadata[num_metadata++] = GRPC_MDELEM_REF(channel->default_authority); } @@ -228,17 +227,27 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *cq, - grpc_slice method, const grpc_slice *host, + const char *method, const char *host, gpr_timespec deadline, void *reserved) { + GRPC_API_TRACE( + "grpc_channel_create_call(" + "channel=%p, parent_call=%p, propagation_mask=%x, cq=%p, method=%s, " + "host=%s, " + "deadline=gpr_timespec { tv_sec: %" PRId64 + ", tv_nsec: %d, clock_type: %d }, " + "reserved=%p)", + 10, + (channel, parent_call, (unsigned)propagation_mask, cq, method, host, + deadline.tv_sec, deadline.tv_nsec, (int)deadline.clock_type, reserved)); GPR_ASSERT(!reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, cq, NULL, - grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref_internal(method)), - host != NULL ? grpc_mdelem_from_slices(&exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref_internal(*host)) - : GRPC_MDNULL, + grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, + grpc_mdstr_from_string(method)), + host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdstr_from_string(host)) + : NULL, deadline); grpc_exec_ctx_finish(&exec_ctx); return call; @@ -246,16 +255,17 @@ grpc_call *grpc_channel_create_call(grpc_channel *channel, grpc_call *grpc_channel_create_pollset_set_call( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, - uint32_t propagation_mask, grpc_pollset_set *pollset_set, grpc_slice method, - const grpc_slice *host, gpr_timespec deadline, void *reserved) { + uint32_t propagation_mask, grpc_pollset_set *pollset_set, + const char *method, const char *host, gpr_timespec deadline, + void *reserved) { GPR_ASSERT(!reserved); return grpc_channel_create_call_internal( exec_ctx, channel, parent_call, propagation_mask, NULL, pollset_set, - grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_ref_internal(method)), - host != NULL ? grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_ref_internal(*host)) - : GRPC_MDNULL, + grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_PATH, + grpc_mdstr_from_string(method)), + host ? grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdstr_from_string(host)) + : NULL, deadline); } @@ -267,15 +277,12 @@ void *grpc_channel_register_call(grpc_channel *channel, const char *method, 4, (channel, method, host, reserved)); GPR_ASSERT(!reserved); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - rc->path = grpc_mdelem_from_slices( - &exec_ctx, GRPC_MDSTR_PATH, - grpc_slice_intern(grpc_slice_from_static_string(method))); + rc->path = grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_PATH, + grpc_mdstr_from_string(method)); rc->authority = - host ? grpc_mdelem_from_slices( - &exec_ctx, GRPC_MDSTR_AUTHORITY, - grpc_slice_intern(grpc_slice_from_static_string(host))) - : GRPC_MDNULL; + host ? grpc_mdelem_from_metadata_strings(&exec_ctx, GRPC_MDSTR_AUTHORITY, + grpc_mdstr_from_string(host)) + : NULL; gpr_mu_lock(&channel->registered_call_mu); rc->next = channel->registered_calls; channel->registered_calls = rc; @@ -303,7 +310,8 @@ grpc_call *grpc_channel_create_registered_call( grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_call *call = grpc_channel_create_call_internal( &exec_ctx, channel, parent_call, propagation_mask, completion_queue, NULL, - GRPC_MDELEM_REF(rc->path), GRPC_MDELEM_REF(rc->authority), deadline); + GRPC_MDELEM_REF(rc->path), + rc->authority ? GRPC_MDELEM_REF(rc->authority) : NULL, deadline); grpc_exec_ctx_finish(&exec_ctx); return call; } @@ -332,10 +340,14 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, void *arg, registered_call *rc = channel->registered_calls; channel->registered_calls = rc->next; GRPC_MDELEM_UNREF(exec_ctx, rc->path); - GRPC_MDELEM_UNREF(exec_ctx, rc->authority); + if (rc->authority) { + GRPC_MDELEM_UNREF(exec_ctx, rc->authority); + } gpr_free(rc); } - GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); + if (channel->default_authority != NULL) { + GRPC_MDELEM_UNREF(exec_ctx, channel->default_authority); + } gpr_mu_destroy(&channel->registered_call_mu); gpr_free(channel->target); gpr_free(channel); @@ -364,8 +376,8 @@ grpc_compression_options grpc_channel_compression_options( return channel->compression_options; } -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, - grpc_channel *channel, int i) { +grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, + grpc_channel *channel, int i) { char tmp[GPR_LTOA_MIN_BUFSIZE]; switch (i) { case 0: @@ -376,6 +388,6 @@ grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, return GRPC_MDELEM_GRPC_STATUS_2; } gpr_ltoa(i, tmp); - return grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_STATUS, - grpc_slice_from_copied_string(tmp)); + return grpc_mdelem_from_metadata_strings(exec_ctx, GRPC_MDSTR_GRPC_STATUS, + grpc_mdstr_from_string(tmp)); } diff --git a/src/core/lib/surface/channel.h b/src/core/lib/surface/channel.h index 3a441d7adde..2ebadb7a150 100644 --- a/src/core/lib/surface/channel.h +++ b/src/core/lib/surface/channel.h @@ -52,8 +52,9 @@ grpc_channel *grpc_channel_create(grpc_exec_ctx *exec_ctx, const char *target, value of \a propagation_mask (see propagation_bits.h for possible values) */ grpc_call *grpc_channel_create_pollset_set_call( grpc_exec_ctx *exec_ctx, grpc_channel *channel, grpc_call *parent_call, - uint32_t propagation_mask, grpc_pollset_set *pollset_set, grpc_slice method, - const grpc_slice *host, gpr_timespec deadline, void *reserved); + uint32_t propagation_mask, grpc_pollset_set *pollset_set, + const char *method, const char *host, gpr_timespec deadline, + void *reserved); /** Get a (borrowed) pointer to this channels underlying channel stack */ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); @@ -62,9 +63,9 @@ grpc_channel_stack *grpc_channel_get_channel_stack(grpc_channel *channel); status_code. The returned elem is owned by the caller. */ -grpc_mdelem grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, - grpc_channel *channel, - int status_code); +grpc_mdelem *grpc_channel_get_reffed_status_elem(grpc_exec_ctx *exec_ctx, + grpc_channel *channel, + int status_code); #ifdef GRPC_STREAM_REFCOUNT_DEBUG void grpc_channel_internal_ref(grpc_channel *channel, const char *reason); diff --git a/src/core/lib/surface/completion_queue.c b/src/core/lib/surface/completion_queue.c index 1830842d00b..4613c9021ee 100644 --- a/src/core/lib/surface/completion_queue.c +++ b/src/core/lib/surface/completion_queue.c @@ -253,6 +253,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (grpc_trace_operation_failures && error != GRPC_ERROR_NONE) { gpr_log(GPR_ERROR, "Operation failed: tag=%p, error=%s", tag, errmsg); } + grpc_error_free_string(errmsg); } storage->tag = tag; @@ -293,7 +294,7 @@ void grpc_cq_end_op(grpc_exec_ctx *exec_ctx, grpc_completion_queue *cc, if (kick_error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(kick_error); gpr_log(GPR_ERROR, "Kick failed: %s", msg); - + grpc_error_free_string(msg); GRPC_ERROR_UNREF(kick_error); } } else { @@ -402,8 +403,8 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, .stolen_completion = NULL, .tag = NULL, .first_loop = true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_next_finished, &is_finished_arg); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK( + cq_is_next_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cc->mu); @@ -460,7 +461,7 @@ grpc_event grpc_completion_queue_next(grpc_completion_queue *cc, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - + grpc_error_free_string(msg); GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; @@ -571,8 +572,8 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, .stolen_completion = NULL, .tag = tag, .first_loop = true}; - grpc_exec_ctx exec_ctx = - GRPC_EXEC_CTX_INITIALIZER(0, cq_is_pluck_finished, &is_finished_arg); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT_WITH_FINISH_CHECK( + cq_is_pluck_finished, &is_finished_arg); for (;;) { if (is_finished_arg.stolen_completion != NULL) { gpr_mu_unlock(cc->mu); @@ -646,7 +647,7 @@ grpc_event grpc_completion_queue_pluck(grpc_completion_queue *cc, void *tag, gpr_mu_unlock(cc->mu); const char *msg = grpc_error_string(err); gpr_log(GPR_ERROR, "Completion queue next failed: %s", msg); - + grpc_error_free_string(msg); GRPC_ERROR_UNREF(err); memset(&ret, 0, sizeof(ret)); ret.type = GRPC_QUEUE_TIMEOUT; diff --git a/src/core/lib/surface/init.c b/src/core/lib/surface/init.c index cfa1882775f..f61bf1582e5 100644 --- a/src/core/lib/surface/init.c +++ b/src/core/lib/surface/init.c @@ -55,7 +55,6 @@ #include "src/core/lib/iomgr/iomgr.h" #include "src/core/lib/iomgr/resource_quota.h" #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel_init.h" @@ -179,7 +178,6 @@ void grpc_init(void) { gpr_mu_lock(&g_init_mu); if (++g_initializations == 1) { gpr_time_init(); - grpc_slice_intern_init(); grpc_mdctx_global_init(); grpc_channel_init_init(); grpc_register_tracer("api", &grpc_api_trace); @@ -244,7 +242,6 @@ void grpc_shutdown(void) { } grpc_mdctx_global_shutdown(&exec_ctx); grpc_handshaker_factory_registry_shutdown(&exec_ctx); - grpc_slice_intern_shutdown(); } gpr_mu_unlock(&g_init_mu); grpc_exec_ctx_finish(&exec_ctx); diff --git a/src/core/lib/surface/lame_client.c b/src/core/lib/surface/lame_client.c index 48de0e1d5bd..ae1eac09a96 100644 --- a/src/core/lib/surface/lame_client.c +++ b/src/core/lib/surface/lame_client.c @@ -44,12 +44,10 @@ #include "src/core/lib/surface/api_trace.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/channel.h" -#include "src/core/lib/transport/static_metadata.h" typedef struct { grpc_linked_mdelem status; grpc_linked_mdelem details; - gpr_atm filled_metadata; } call_data; typedef struct { @@ -60,23 +58,17 @@ typedef struct { static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_metadata_batch *mdb) { call_data *calld = elem->call_data; - if (!gpr_atm_no_barrier_cas(&calld->filled_metadata, 0, 1)) { - return; - } channel_data *chand = elem->channel_data; char tmp[GPR_LTOA_MIN_BUFSIZE]; gpr_ltoa(chand->error_code, tmp); - calld->status.md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp)); - calld->details.md = grpc_mdelem_from_slices( - exec_ctx, GRPC_MDSTR_GRPC_MESSAGE, - grpc_slice_from_copied_string(chand->error_message)); + calld->status.md = grpc_mdelem_from_strings(exec_ctx, "grpc-status", tmp); + calld->details.md = + grpc_mdelem_from_strings(exec_ctx, "grpc-message", chand->error_message); calld->status.prev = calld->details.next = NULL; calld->status.next = &calld->details; calld->details.prev = &calld->status; mdb->list.head = &calld->status; mdb->list.tail = &calld->details; - mdb->list.count = 2; mdb->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } @@ -123,8 +115,6 @@ static void lame_start_transport_op(grpc_exec_ctx *exec_ctx, static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, grpc_call_element_args *args) { - call_data *calld = elem->call_data; - gpr_atm_no_barrier_store(&calld->filled_metadata, 0); return GRPC_ERROR_NONE; } diff --git a/src/core/lib/surface/server.c b/src/core/lib/surface/server.c index 3782b491226..addb7c4fbc0 100644 --- a/src/core/lib/surface/server.c +++ b/src/core/lib/surface/server.c @@ -98,9 +98,8 @@ typedef struct requested_call { typedef struct channel_registered_method { registered_method *server_registered_method; uint32_t flags; - bool has_host; - grpc_slice method; - grpc_slice host; + grpc_mdstr *method; + grpc_mdstr *host; } channel_registered_method; struct channel_data { @@ -145,10 +144,8 @@ struct call_data { /** the current state of a call - see call_state */ call_state state; - bool path_set; - bool host_set; - grpc_slice path; - grpc_slice host; + grpc_mdstr *path; + grpc_mdstr *host; gpr_timespec deadline; grpc_completion_queue *cq_new; @@ -280,20 +277,18 @@ static void shutdown_cleanup(grpc_exec_ctx *exec_ctx, void *arg, } static void send_shutdown(grpc_exec_ctx *exec_ctx, grpc_channel *channel, - bool send_goaway, grpc_error *send_disconnect) { + int send_goaway, grpc_error *send_disconnect) { struct shutdown_cleanup_args *sc = gpr_malloc(sizeof(*sc)); grpc_closure_init(&sc->closure, shutdown_cleanup, sc, grpc_schedule_on_exec_ctx); grpc_transport_op *op = grpc_make_transport_op(&sc->closure); grpc_channel_element *elem; - op->goaway_error = - send_goaway - ? grpc_error_set_int(GRPC_ERROR_CREATE("Server shutdown"), - GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK) - : GRPC_ERROR_NONE; + op->send_goaway = send_goaway; op->set_accept_stream = true; sc->slice = grpc_slice_from_copied_string("Server shutdown"); + op->goaway_message = &sc->slice; + op->goaway_status = GRPC_STATUS_OK; op->disconnect_with_error = send_disconnect; elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0); @@ -453,6 +448,7 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) { const char *msg = grpc_error_string(error); gpr_log(GPR_INFO, "Disconnected client: %s", msg); + grpc_error_free_string(msg); } GRPC_ERROR_UNREF(error); @@ -465,6 +461,17 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand, op); } +static void cpstr(char **dest, size_t *capacity, grpc_mdstr *value) { + grpc_slice slice = value->slice; + size_t len = GRPC_SLICE_LENGTH(slice); + + if (len + 1 > *capacity) { + *capacity = GPR_MAX(len + 1, *capacity * 2); + *dest = gpr_realloc(*dest, *capacity); + } + memcpy(*dest, grpc_mdstr_as_c_string(value), len + 1); +} + static void done_request_event(grpc_exec_ctx *exec_ctx, void *req, grpc_cq_completion *c) { requested_call *rc = req; @@ -493,10 +500,12 @@ static void publish_call(grpc_exec_ctx *exec_ctx, grpc_server *server, GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata); switch (rc->type) { case BATCH_CALL: - GPR_ASSERT(calld->host_set); - GPR_ASSERT(calld->path_set); - rc->data.batch.details->host = grpc_slice_ref_internal(calld->host); - rc->data.batch.details->method = grpc_slice_ref_internal(calld->path); + GPR_ASSERT(calld->host != NULL); + GPR_ASSERT(calld->path != NULL); + cpstr(&rc->data.batch.details->host, + &rc->data.batch.details->host_capacity, calld->host); + cpstr(&rc->data.batch.details->method, + &rc->data.batch.details->method_capacity, calld->path); rc->data.batch.details->deadline = calld->deadline; rc->data.batch.details->flags = (calld->recv_idempotent_request @@ -618,39 +627,35 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) { uint32_t hash; channel_registered_method *rm; - if (chand->registered_methods && calld->path_set && calld->host_set) { + if (chand->registered_methods && calld->path && calld->host) { /* TODO(ctiller): unify these two searches */ /* check for an exact match with host */ - hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(calld->host), - grpc_slice_hash(calld->path)); + hash = GRPC_MDSTR_KV_HASH(calld->host->hash, calld->path->hash); for (i = 0; i <= chand->registered_method_max_probes; i++) { rm = &chand->registered_methods[(hash + i) % chand->registered_method_slots]; if (!rm) break; - if (!rm->has_host) continue; - if (!grpc_slice_eq(rm->host, calld->host)) continue; - if (!grpc_slice_eq(rm->method, calld->path)) continue; + if (rm->host != calld->host) continue; + if (rm->method != calld->path) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && - !calld->recv_idempotent_request) { + !calld->recv_idempotent_request) continue; - } finish_start_new_rpc(exec_ctx, server, elem, &rm->server_registered_method->request_matcher, rm->server_registered_method->payload_handling); return; } /* check for a wildcard method definition (no host set) */ - hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash(calld->path)); + hash = GRPC_MDSTR_KV_HASH(0, calld->path->hash); for (i = 0; i <= chand->registered_method_max_probes; i++) { rm = &chand->registered_methods[(hash + i) % chand->registered_method_slots]; if (!rm) break; - if (rm->has_host) continue; - if (!grpc_slice_eq(rm->method, calld->path)) continue; + if (rm->host != NULL) continue; + if (rm->method != calld->path) continue; if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) && - !calld->recv_idempotent_request) { + !calld->recv_idempotent_request) continue; - } finish_start_new_rpc(exec_ctx, server, elem, &rm->server_registered_method->request_matcher, rm->server_registered_method->payload_handling); @@ -739,40 +744,43 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx, } } +static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data, + grpc_mdelem *md) { + grpc_call_element *elem = user_data; + call_data *calld = elem->call_data; + if (md->key == GRPC_MDSTR_PATH) { + if (calld->path == NULL) { + calld->path = GRPC_MDSTR_REF(md->value); + } + return NULL; + } else if (md->key == GRPC_MDSTR_AUTHORITY) { + if (calld->host == NULL) { + calld->host = GRPC_MDSTR_REF(md->value); + } + return NULL; + } + return md; +} + static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr, grpc_error *error) { grpc_call_element *elem = ptr; call_data *calld = elem->call_data; gpr_timespec op_deadline; - if (error == GRPC_ERROR_NONE) { - GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != NULL); - GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != NULL); - calld->path = grpc_slice_ref_internal( - GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md)); - calld->host = grpc_slice_ref_internal( - GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md)); - calld->path_set = true; - calld->host_set = true; - grpc_metadata_batch_remove(exec_ctx, calld->recv_initial_metadata, - calld->recv_initial_metadata->idx.named.path); - grpc_metadata_batch_remove( - exec_ctx, calld->recv_initial_metadata, - calld->recv_initial_metadata->idx.named.authority); - } else { - GRPC_ERROR_REF(error); - } + GRPC_ERROR_REF(error); + grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata, + server_filter, elem); op_deadline = calld->recv_initial_metadata->deadline; if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) { calld->deadline = op_deadline; } - if (calld->host_set && calld->path_set) { + if (calld->host && calld->path) { /* do nothing */ } else { - grpc_error *src_error = error; + GRPC_ERROR_UNREF(error); error = GRPC_ERROR_CREATE_REFERENCING("Missing :authority or :path", &error, 1); - GRPC_ERROR_UNREF(src_error); } grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error); @@ -902,11 +910,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, GPR_ASSERT(calld->state != PENDING); - if (calld->host_set) { - grpc_slice_unref_internal(exec_ctx, calld->host); + if (calld->host) { + GRPC_MDSTR_UNREF(exec_ctx, calld->host); } - if (calld->path_set) { - grpc_slice_unref_internal(exec_ctx, calld->path); + if (calld->path) { + GRPC_MDSTR_UNREF(exec_ctx, calld->path); } grpc_metadata_array_destroy(&calld->initial_metadata); @@ -938,9 +946,11 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, channel_data *chand = elem->channel_data; if (chand->registered_methods) { for (i = 0; i < chand->registered_method_slots; i++) { - grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].method); - if (chand->registered_methods[i].has_host) { - grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].host); + if (chand->registered_methods[i].method) { + GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].method); + } + if (chand->registered_methods[i].host) { + GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].host); } } gpr_free(chand->registered_methods); @@ -1138,6 +1148,8 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, channel_registered_method *crm; grpc_channel *channel; channel_data *chand; + grpc_mdstr *host; + grpc_mdstr *method; uint32_t hash; size_t slots; uint32_t probes; @@ -1176,18 +1188,9 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, chand->registered_methods = gpr_malloc(alloc); memset(chand->registered_methods, 0, alloc); for (rm = s->registered_methods; rm; rm = rm->next) { - grpc_slice host; - bool has_host; - grpc_slice method; - if (rm->host != NULL) { - host = grpc_slice_intern(grpc_slice_from_static_string(rm->host)); - has_host = true; - } else { - has_host = false; - } - method = grpc_slice_intern(grpc_slice_from_static_string(rm->method)); - hash = GRPC_MDSTR_KV_HASH(has_host ? grpc_slice_hash(host) : 0, - grpc_slice_hash(method)); + host = rm->host ? grpc_mdstr_from_string(rm->host) : NULL; + method = grpc_mdstr_from_string(rm->method); + hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash); for (probes = 0; chand->registered_methods[(hash + probes) % slots] .server_registered_method != NULL; probes++) @@ -1196,7 +1199,6 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s, crm = &chand->registered_methods[(hash + probes) % slots]; crm->server_registered_method = rm; crm->flags = rm->flags; - crm->has_host = has_host; crm->host = host; crm->method = method; } diff --git a/src/core/lib/surface/validate_metadata.c b/src/core/lib/surface/validate_metadata.c index 7ec9137265d..f49dd8584b0 100644 --- a/src/core/lib/surface/validate_metadata.c +++ b/src/core/lib/surface/validate_metadata.c @@ -34,71 +34,40 @@ #include #include -#include -#include #include -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/slice/slice_string_helpers.h" - -static grpc_error *conforms_to(grpc_slice slice, const uint8_t *legal_bits, - const char *err_desc) { - const uint8_t *p = GRPC_SLICE_START_PTR(slice); - const uint8_t *e = GRPC_SLICE_END_PTR(slice); +static int conforms_to(const char *s, size_t len, const uint8_t *legal_bits) { + const char *p = s; + const char *e = s + len; for (; p != e; p++) { - int idx = *p; + int idx = (uint8_t)*p; int byte = idx / 8; int bit = idx % 8; - if ((legal_bits[byte] & (1 << bit)) == 0) { - char *dump = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); - grpc_error *error = grpc_error_set_str( - grpc_error_set_int(GRPC_ERROR_CREATE(err_desc), GRPC_ERROR_INT_OFFSET, - p - GRPC_SLICE_START_PTR(slice)), - GRPC_ERROR_STR_RAW_BYTES, dump); - gpr_free(dump); - return error; - } + if ((legal_bits[byte] & (1 << bit)) == 0) return 0; } - return GRPC_ERROR_NONE; -} - -static int error2int(grpc_error *error) { - int r = (error == GRPC_ERROR_NONE); - GRPC_ERROR_UNREF(error); - return r; + return 1; } -grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice) { +int grpc_header_key_is_legal(const char *key, size_t length) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00, 0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - if (GRPC_SLICE_LENGTH(slice) == 0) { - return GRPC_ERROR_CREATE("Metadata keys cannot be zero length"); - } - if (GRPC_SLICE_START_PTR(slice)[0] == ':') { - return GRPC_ERROR_CREATE("Metadata keys cannot start with :"); + if (length == 0 || key[0] == ':') { + return 0; } - return conforms_to(slice, legal_header_bits, "Illegal header key"); + return conforms_to(key, length, legal_header_bits); } -int grpc_header_key_is_legal(grpc_slice slice) { - return error2int(grpc_validate_header_key_is_legal(slice)); -} - -grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice) { +int grpc_header_nonbin_value_is_legal(const char *value, size_t length) { static const uint8_t legal_header_bits[256 / 8] = { 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - return conforms_to(slice, legal_header_bits, "Illegal header value"); -} - -int grpc_header_nonbin_value_is_legal(grpc_slice slice) { - return error2int(grpc_validate_header_nonbin_value_is_legal(slice)); + return conforms_to(value, length, legal_header_bits); } -int grpc_is_binary_header(grpc_slice slice) { - if (GRPC_SLICE_LENGTH(slice) < 5) return 0; - return 0 == memcmp(GRPC_SLICE_END_PTR(slice) - 4, "-bin", 4); +int grpc_is_binary_header(const char *key, size_t length) { + if (length < 5) return 0; + return 0 == memcmp(key + length - 4, "-bin", 4); } diff --git a/src/core/lib/surface/validate_metadata.h b/src/core/lib/surface/validate_metadata.h deleted file mode 100644 index 2b800d25a43..00000000000 --- a/src/core/lib/surface/validate_metadata.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * - * Copyright 2017, 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_SURFACE_VALIDATE_METADATA_H -#define GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H - -#include -#include "src/core/lib/iomgr/error.h" - -grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice); -grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice); - -#endif /* GRPC_CORE_LIB_SURFACE_VALIDATE_METADATA_H */ diff --git a/src/core/lib/transport/connectivity_state.c b/src/core/lib/transport/connectivity_state.c index 8fc5bf3e9a6..c656d93740e 100644 --- a/src/core/lib/transport/connectivity_state.c +++ b/src/core/lib/transport/connectivity_state.c @@ -163,6 +163,7 @@ void grpc_connectivity_state_set(grpc_exec_ctx *exec_ctx, gpr_log(GPR_DEBUG, "SET: %p %s: %s --> %s [%s] error=%p %s", tracker, tracker->name, grpc_connectivity_state_name(tracker->current_state), grpc_connectivity_state_name(state), reason, error, error_string); + grpc_error_free_string(error_string); } switch (state) { case GRPC_CHANNEL_INIT: diff --git a/src/core/lib/transport/error_utils.c b/src/core/lib/transport/error_utils.c deleted file mode 100644 index da77828d9c1..00000000000 --- a/src/core/lib/transport/error_utils.c +++ /dev/null @@ -1,124 +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. - * - */ - -#include "src/core/lib/transport/error_utils.h" - -#include "src/core/lib/iomgr/error_internal.h" -#include "src/core/lib/transport/status_conversion.h" - -static grpc_error *recursively_find_error_with_field(grpc_error *error, - grpc_error_ints which) { - // If the error itself has a status code, return it. - if (grpc_error_get_int(error, which, NULL)) { - return error; - } - if (grpc_error_is_special(error)) return NULL; - // Otherwise, search through its children. - intptr_t key = 0; - while (true) { - grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); - if (child_error == NULL) break; - grpc_error *result = recursively_find_error_with_field(child_error, which); - if (result != NULL) return result; - } - return NULL; -} - -void grpc_error_get_status(grpc_error *error, gpr_timespec deadline, - grpc_status_code *code, const char **msg, - grpc_http2_error_code *http_error) { - // Start with the parent error and recurse through the tree of children - // until we find the first one that has a status code. - grpc_error *found_error = - recursively_find_error_with_field(error, GRPC_ERROR_INT_GRPC_STATUS); - if (found_error == NULL) { - /// If no grpc-status exists, retry through the tree to find a http2 error - /// code - found_error = - recursively_find_error_with_field(error, GRPC_ERROR_INT_HTTP2_ERROR); - } - - // If we found an error with a status code above, use that; otherwise, - // fall back to using the parent error. - if (found_error == NULL) found_error = error; - - grpc_status_code status = GRPC_STATUS_UNKNOWN; - intptr_t integer; - if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, &integer)) { - status = (grpc_status_code)integer; - } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, - &integer)) { - status = grpc_http2_error_to_grpc_status((grpc_http2_error_code)integer, - deadline); - } - if (code != NULL) *code = status; - - if (http_error != NULL) { - if (grpc_error_get_int(found_error, GRPC_ERROR_INT_HTTP2_ERROR, &integer)) { - *http_error = (grpc_http2_error_code)integer; - } else if (grpc_error_get_int(found_error, GRPC_ERROR_INT_GRPC_STATUS, - &integer)) { - *http_error = grpc_status_to_http2_error((grpc_status_code)integer); - } else { - *http_error = found_error == GRPC_ERROR_NONE ? GRPC_HTTP2_NO_ERROR - : GRPC_HTTP2_INTERNAL_ERROR; - } - } - - // If the error has a status message, use it. Otherwise, fall back to - // the error description. - if (msg != NULL) { - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_GRPC_MESSAGE); - if (*msg == NULL && error != GRPC_ERROR_NONE) { - *msg = grpc_error_get_str(found_error, GRPC_ERROR_STR_DESCRIPTION); - if (*msg == NULL) *msg = "unknown error"; // Just in case. - } - } - - if (found_error == NULL) found_error = error; -} - -bool grpc_error_has_clear_grpc_status(grpc_error *error) { - if (grpc_error_get_int(error, GRPC_ERROR_INT_GRPC_STATUS, NULL)) { - return true; - } - intptr_t key = 0; - while (true) { - grpc_error *child_error = gpr_avl_get(error->errs, (void *)key++); - if (child_error == NULL) break; - if (grpc_error_has_clear_grpc_status(child_error)) { - return true; - } - } - return false; -} diff --git a/src/core/lib/transport/error_utils.h b/src/core/lib/transport/error_utils.h deleted file mode 100644 index 105338880ac..00000000000 --- a/src/core/lib/transport/error_utils.h +++ /dev/null @@ -1,56 +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_ERROR_UTILS_H -#define GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H - -#include "src/core/lib/iomgr/error.h" -#include "src/core/lib/transport/http2_errors.h" - -/// A utility function to get the status code and message to be returned -/// to the application. If not set in the top-level message, looks -/// through child errors until it finds the first one with these attributes. -/// All attributes are pulled from the same child error. If any of the -/// attributes (code, msg, http_status) are unneeded, they can be passed as -/// NULL. -void grpc_error_get_status(grpc_error *error, gpr_timespec deadline, - grpc_status_code *code, const char **msg, - grpc_http2_error_code *http_status); - -/// A utility function to check whether there is a clear status code that -/// doesn't need to be guessed in \a error. This means that \a error or some -/// child has GRPC_ERROR_INT_GRPC_STATUS set, or that it is GRPC_ERROR_NONE or -/// GRPC_ERROR_CANCELLED -bool grpc_error_has_clear_grpc_status(grpc_error *error); - -#endif /* GRPC_CORE_LIB_TRANSPORT_ERROR_UTILS_H */ diff --git a/src/core/lib/slice/slice_hash_table.c b/src/core/lib/transport/mdstr_hash_table.c similarity index 61% rename from src/core/lib/slice/slice_hash_table.c rename to src/core/lib/transport/mdstr_hash_table.c index 46f807f4a52..2791bf653b8 100644 --- a/src/core/lib/slice/slice_hash_table.c +++ b/src/core/lib/transport/mdstr_hash_table.c @@ -29,7 +29,7 @@ // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // -#include "src/core/lib/slice/slice_hash_table.h" +#include "src/core/lib/transport/mdstr_hash_table.h" #include #include @@ -37,79 +37,70 @@ #include #include -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" -struct grpc_slice_hash_table { +struct grpc_mdstr_hash_table { gpr_refcount refs; size_t size; - grpc_slice_hash_table_entry* entries; + grpc_mdstr_hash_table_entry* entries; }; -static bool is_empty(grpc_slice_hash_table_entry* entry) { - return entry->vtable == NULL; -} - // Helper function for insert and get operations that performs quadratic // probing (https://en.wikipedia.org/wiki/Quadratic_probing). -static size_t grpc_slice_hash_table_find_index( - const grpc_slice_hash_table* table, const grpc_slice key, bool find_empty) { - size_t hash = grpc_slice_hash(key); +static size_t grpc_mdstr_hash_table_find_index( + const grpc_mdstr_hash_table* table, const grpc_mdstr* key, + bool find_empty) { for (size_t i = 0; i < table->size; ++i) { - const size_t idx = (hash + i * i) % table->size; - if (is_empty(&table->entries[idx])) { - return find_empty ? idx : table->size; - } - if (grpc_slice_eq(table->entries[idx].key, key)) { - return idx; - } + const size_t idx = (key->hash + i * i) % table->size; + if (table->entries[idx].key == NULL) return find_empty ? idx : table->size; + if (table->entries[idx].key == key) return idx; } return table->size; // Not found. } -static void grpc_slice_hash_table_add( - grpc_slice_hash_table* table, grpc_slice key, void* value, - const grpc_slice_hash_table_vtable* vtable) { +static void grpc_mdstr_hash_table_add( + grpc_mdstr_hash_table* table, grpc_mdstr* key, void* value, + const grpc_mdstr_hash_table_vtable* vtable) { GPR_ASSERT(value != NULL); const size_t idx = - grpc_slice_hash_table_find_index(table, key, true /* find_empty */); + grpc_mdstr_hash_table_find_index(table, key, true /* find_empty */); GPR_ASSERT(idx != table->size); // Table should never be full. - grpc_slice_hash_table_entry* entry = &table->entries[idx]; - entry->key = grpc_slice_ref_internal(key); + grpc_mdstr_hash_table_entry* entry = &table->entries[idx]; + entry->key = GRPC_MDSTR_REF(key); entry->value = vtable->copy_value(value); entry->vtable = vtable; } -grpc_slice_hash_table* grpc_slice_hash_table_create( - size_t num_entries, grpc_slice_hash_table_entry* entries) { - grpc_slice_hash_table* table = gpr_malloc(sizeof(*table)); +grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( + size_t num_entries, grpc_mdstr_hash_table_entry* entries) { + grpc_mdstr_hash_table* table = gpr_malloc(sizeof(*table)); memset(table, 0, sizeof(*table)); gpr_ref_init(&table->refs, 1); // Quadratic probing gets best performance when the table is no more // than half full. table->size = num_entries * 2; - const size_t entry_size = sizeof(grpc_slice_hash_table_entry) * table->size; + const size_t entry_size = sizeof(grpc_mdstr_hash_table_entry) * table->size; table->entries = gpr_malloc(entry_size); memset(table->entries, 0, entry_size); for (size_t i = 0; i < num_entries; ++i) { - grpc_slice_hash_table_entry* entry = &entries[i]; - grpc_slice_hash_table_add(table, entry->key, entry->value, entry->vtable); + grpc_mdstr_hash_table_entry* entry = &entries[i]; + grpc_mdstr_hash_table_add(table, entry->key, entry->value, entry->vtable); } return table; } -grpc_slice_hash_table* grpc_slice_hash_table_ref(grpc_slice_hash_table* table) { +grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table) { if (table != NULL) gpr_ref(&table->refs); return table; } -void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, - grpc_slice_hash_table* table) { +void grpc_mdstr_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_mdstr_hash_table* table) { if (table != NULL && gpr_unref(&table->refs)) { for (size_t i = 0; i < table->size; ++i) { - grpc_slice_hash_table_entry* entry = &table->entries[i]; - if (!is_empty(entry)) { - grpc_slice_unref_internal(exec_ctx, entry->key); + grpc_mdstr_hash_table_entry* entry = &table->entries[i]; + if (entry->key != NULL) { + GRPC_MDSTR_UNREF(exec_ctx, entry->key); entry->vtable->destroy_value(exec_ctx, entry->value); } } @@ -118,10 +109,10 @@ void grpc_slice_hash_table_unref(grpc_exec_ctx* exec_ctx, } } -void* grpc_slice_hash_table_get(const grpc_slice_hash_table* table, - const grpc_slice key) { +void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* key) { const size_t idx = - grpc_slice_hash_table_find_index(table, key, false /* find_empty */); + grpc_mdstr_hash_table_find_index(table, key, false /* find_empty */); if (idx == table->size) return NULL; // Not found. return table->entries[idx].value; } diff --git a/src/core/lib/slice/slice_hash_table.h b/src/core/lib/transport/mdstr_hash_table.h similarity index 67% rename from src/core/lib/slice/slice_hash_table.h rename to src/core/lib/transport/mdstr_hash_table.h index d0c27122d7f..57f497ee278 100644 --- a/src/core/lib/slice/slice_hash_table.h +++ b/src/core/lib/transport/mdstr_hash_table.h @@ -29,8 +29,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H -#define GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H +#ifndef GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H +#define GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H #include "src/core/lib/transport/metadata.h" @@ -40,38 +40,38 @@ * (https://en.wikipedia.org/wiki/Open_addressing) with quadratic * probing (https://en.wikipedia.org/wiki/Quadratic_probing). * - * The keys are \a grpc_slice objects. The values are arbitrary pointers + * The keys are \a grpc_mdstr objects. The values are arbitrary pointers * with a common vtable. * * Hash tables are intentionally immutable, to avoid the need for locking. */ -typedef struct grpc_slice_hash_table grpc_slice_hash_table; +typedef struct grpc_mdstr_hash_table grpc_mdstr_hash_table; -typedef struct grpc_slice_hash_table_vtable { - void (*destroy_value)(grpc_exec_ctx *exec_ctx, void *value); - void *(*copy_value)(void *value); -} grpc_slice_hash_table_vtable; +typedef struct grpc_mdstr_hash_table_vtable { + void (*destroy_value)(grpc_exec_ctx* exec_ctx, void* value); + void* (*copy_value)(void* value); +} grpc_mdstr_hash_table_vtable; -typedef struct grpc_slice_hash_table_entry { - grpc_slice key; - void *value; /* Must not be NULL. */ - const grpc_slice_hash_table_vtable *vtable; -} grpc_slice_hash_table_entry; +typedef struct grpc_mdstr_hash_table_entry { + grpc_mdstr* key; + void* value; /* Must not be NULL. */ + const grpc_mdstr_hash_table_vtable* vtable; +} grpc_mdstr_hash_table_entry; /** Creates a new hash table of containing \a entries, which is an array of length \a num_entries. Creates its own copy of all keys and values from \a entries. */ -grpc_slice_hash_table *grpc_slice_hash_table_create( - size_t num_entries, grpc_slice_hash_table_entry *entries); +grpc_mdstr_hash_table* grpc_mdstr_hash_table_create( + size_t num_entries, grpc_mdstr_hash_table_entry* entries); -grpc_slice_hash_table *grpc_slice_hash_table_ref(grpc_slice_hash_table *table); -void grpc_slice_hash_table_unref(grpc_exec_ctx *exec_ctx, - grpc_slice_hash_table *table); +grpc_mdstr_hash_table* grpc_mdstr_hash_table_ref(grpc_mdstr_hash_table* table); +void grpc_mdstr_hash_table_unref(grpc_exec_ctx* exec_ctx, + grpc_mdstr_hash_table* table); /** Returns the value from \a table associated with \a key. Returns NULL if \a key is not found. */ -void *grpc_slice_hash_table_get(const grpc_slice_hash_table *table, - const grpc_slice key); +void* grpc_mdstr_hash_table_get(const grpc_mdstr_hash_table* table, + const grpc_mdstr* key); -#endif /* GRPC_CORE_LIB_SLICE_SLICE_HASH_TABLE_H */ +#endif /* GRPC_CORE_LIB_TRANSPORT_MDSTR_HASH_TABLE_H */ diff --git a/src/core/lib/transport/metadata.c b/src/core/lib/transport/metadata.c index 489c20cbc82..54c39df6a7f 100644 --- a/src/core/lib/transport/metadata.c +++ b/src/core/lib/transport/metadata.c @@ -48,11 +48,12 @@ #include "src/core/lib/iomgr/iomgr_internal.h" #include "src/core/lib/profiling/timers.h" #include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/murmur_hash.h" #include "src/core/lib/support/string.h" #include "src/core/lib/transport/static_metadata.h" +grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)(grpc_slice input); + /* There are two kinds of mdelem and mdstr instances. * Static instances are declared in static_metadata.{h,c} and * are initialized by grpc_mdctx_global_init(). @@ -62,6 +63,9 @@ * used to determine which kind of element a pointer refers to. */ +#define INITIAL_STRTAB_CAPACITY 4 +#define INITIAL_MDTAB_CAPACITY 4 + #ifdef GRPC_METADATA_REFCOUNT_DEBUG #define DEBUG_ARGS , const char *file, int line #define FWD_DEBUG_ARGS , file, line @@ -72,44 +76,58 @@ #define REF_MD_LOCKED(shard, s) ref_md_locked((shard), (s)) #endif -#define INITIAL_SHARD_CAPACITY 8 -#define LOG2_SHARD_COUNT 4 -#define SHARD_COUNT ((size_t)(1 << LOG2_SHARD_COUNT)) - -#define TABLE_IDX(hash, capacity) (((hash) >> (LOG2_SHARD_COUNT)) % (capacity)) -#define SHARD_IDX(hash) ((hash) & ((1 << (LOG2_SHARD_COUNT)) - 1)) +#define TABLE_IDX(hash, log2_shards, capacity) \ + (((hash) >> (log2_shards)) % (capacity)) +#define SHARD_IDX(hash, log2_shards) ((hash) & ((1 << (log2_shards)) - 1)) typedef void (*destroy_user_data_func)(void *user_data); -/* Shadow structure for grpc_mdelem_data for interned elements */ -typedef struct interned_metadata { - /* must be byte compatible with grpc_mdelem_data */ - grpc_slice key; - grpc_slice value; +#define SIZE_IN_DECODER_TABLE_NOT_SET -1 +/* Shadow structure for grpc_mdstr for non-static values */ +typedef struct internal_string { + /* must be byte compatible with grpc_mdstr */ + grpc_slice slice; + uint32_t hash; /* private only data */ gpr_atm refcnt; - gpr_mu mu_user_data; - gpr_atm destroy_user_data; - gpr_atm user_data; + uint8_t has_base64_and_huffman_encoded; + grpc_slice_refcount refcount; + + grpc_slice base64_and_huffman; - struct interned_metadata *bucket_next; -} interned_metadata; + gpr_atm size_in_decoder_table; -/* Shadow structure for grpc_mdelem_data for allocated elements */ -typedef struct allocated_metadata { - /* must be byte compatible with grpc_mdelem_data */ - grpc_slice key; - grpc_slice value; + struct internal_string *bucket_next; +} internal_string; + +/* Shadow structure for grpc_mdelem for non-static elements */ +typedef struct internal_metadata { + /* must be byte compatible with grpc_mdelem */ + internal_string *key; + internal_string *value; /* private only data */ gpr_atm refcnt; -} allocated_metadata; + + gpr_mu mu_user_data; + gpr_atm destroy_user_data; + gpr_atm user_data; + + struct internal_metadata *bucket_next; +} internal_metadata; + +typedef struct strtab_shard { + gpr_mu mu; + internal_string **strs; + size_t count; + size_t capacity; +} strtab_shard; typedef struct mdtab_shard { gpr_mu mu; - interned_metadata **elems; + internal_metadata **elems; size_t count; size_t capacity; /** Estimate of the number of unreferenced mdelems in the hash table. @@ -118,26 +136,102 @@ typedef struct mdtab_shard { gpr_atm free_estimate; } mdtab_shard; -static mdtab_shard g_shards[SHARD_COUNT]; +#define LOG2_STRTAB_SHARD_COUNT 5 +#define LOG2_MDTAB_SHARD_COUNT 4 +#define STRTAB_SHARD_COUNT ((size_t)(1 << LOG2_STRTAB_SHARD_COUNT)) +#define MDTAB_SHARD_COUNT ((size_t)(1 << LOG2_MDTAB_SHARD_COUNT)) + +/* hash seed: decided at initialization time */ +static uint32_t g_hash_seed; +static int g_forced_hash_seed = 0; + +/* linearly probed hash tables for static element lookup */ +static grpc_mdstr *g_static_strtab[GRPC_STATIC_MDSTR_COUNT * 2]; +static grpc_mdelem *g_static_mdtab[GRPC_STATIC_MDELEM_COUNT * 2]; +static size_t g_static_strtab_maxprobe; +static size_t g_static_mdtab_maxprobe; + +static strtab_shard g_strtab_shard[STRTAB_SHARD_COUNT]; +static mdtab_shard g_mdtab_shard[MDTAB_SHARD_COUNT]; static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard); +void grpc_test_only_set_metadata_hash_seed(uint32_t seed) { + g_hash_seed = seed; + g_forced_hash_seed = 1; +} + void grpc_mdctx_global_init(void) { + size_t i, j; + if (!g_forced_hash_seed) { + g_hash_seed = (uint32_t)gpr_now(GPR_CLOCK_REALTIME).tv_nsec; + } + g_static_strtab_maxprobe = 0; + g_static_mdtab_maxprobe = 0; + /* build static tables */ + memset(g_static_mdtab, 0, sizeof(g_static_mdtab)); + memset(g_static_strtab, 0, sizeof(g_static_strtab)); + for (i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { + grpc_mdstr *elem = &grpc_static_mdstr_table[i]; + const char *str = grpc_static_metadata_strings[i]; + uint32_t hash = gpr_murmur_hash3(str, strlen(str), g_hash_seed); + *(grpc_slice *)&elem->slice = grpc_slice_from_static_string(str); + *(uint32_t *)&elem->hash = hash; + for (j = 0;; j++) { + size_t idx = (hash + j) % GPR_ARRAY_SIZE(g_static_strtab); + if (g_static_strtab[idx] == NULL) { + g_static_strtab[idx] = &grpc_static_mdstr_table[i]; + break; + } + } + if (j > g_static_strtab_maxprobe) { + g_static_strtab_maxprobe = j; + } + } + for (i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { + grpc_mdelem *elem = &grpc_static_mdelem_table[i]; + grpc_mdstr *key = + &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 0]]; + grpc_mdstr *value = + &grpc_static_mdstr_table[grpc_static_metadata_elem_indices[2 * i + 1]]; + uint32_t hash = GRPC_MDSTR_KV_HASH(key->hash, value->hash); + *(grpc_mdstr **)&elem->key = key; + *(grpc_mdstr **)&elem->value = value; + for (j = 0;; j++) { + size_t idx = (hash + j) % GPR_ARRAY_SIZE(g_static_mdtab); + if (g_static_mdtab[idx] == NULL) { + g_static_mdtab[idx] = elem; + break; + } + } + if (j > g_static_mdtab_maxprobe) { + g_static_mdtab_maxprobe = j; + } + } /* initialize shards */ - for (size_t i = 0; i < SHARD_COUNT; i++) { - mdtab_shard *shard = &g_shards[i]; + for (i = 0; i < STRTAB_SHARD_COUNT; i++) { + strtab_shard *shard = &g_strtab_shard[i]; + gpr_mu_init(&shard->mu); + shard->count = 0; + shard->capacity = INITIAL_STRTAB_CAPACITY; + shard->strs = gpr_malloc(sizeof(*shard->strs) * shard->capacity); + memset(shard->strs, 0, sizeof(*shard->strs) * shard->capacity); + } + for (i = 0; i < MDTAB_SHARD_COUNT; i++) { + mdtab_shard *shard = &g_mdtab_shard[i]; gpr_mu_init(&shard->mu); shard->count = 0; gpr_atm_no_barrier_store(&shard->free_estimate, 0); - shard->capacity = INITIAL_SHARD_CAPACITY; + shard->capacity = INITIAL_MDTAB_CAPACITY; shard->elems = gpr_malloc(sizeof(*shard->elems) * shard->capacity); memset(shard->elems, 0, sizeof(*shard->elems) * shard->capacity); } } void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { - for (size_t i = 0; i < SHARD_COUNT; i++) { - mdtab_shard *shard = &g_shards[i]; + size_t i; + for (i = 0; i < MDTAB_SHARD_COUNT; i++) { + mdtab_shard *shard = &g_mdtab_shard[i]; gpr_mu_destroy(&shard->mu); gc_mdtab(exec_ctx, shard); /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ @@ -150,35 +244,212 @@ void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx) { } gpr_free(shard->elems); } + for (i = 0; i < STRTAB_SHARD_COUNT; i++) { + strtab_shard *shard = &g_strtab_shard[i]; + gpr_mu_destroy(&shard->mu); + /* TODO(ctiller): GPR_ASSERT(shard->count == 0); */ + if (shard->count != 0) { + gpr_log(GPR_DEBUG, "WARNING: %" PRIuPTR " metadata strings were leaked", + shard->count); + for (size_t j = 0; j < shard->capacity; j++) { + for (internal_string *s = shard->strs[j]; s; s = s->bucket_next) { + gpr_log(GPR_DEBUG, "LEAKED: %s", + grpc_mdstr_as_c_string((grpc_mdstr *)s)); + } + } + if (grpc_iomgr_abort_on_leaks()) { + abort(); + } + } + gpr_free(shard->strs); + } } -static int is_mdelem_static(grpc_mdelem e) { - return GRPC_MDELEM_DATA(e) >= &grpc_static_mdelem_table[0] && - GRPC_MDELEM_DATA(e) < - &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; +static int is_mdstr_static(grpc_mdstr *s) { + return s >= &grpc_static_mdstr_table[0] && + s < &grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; +} + +static int is_mdelem_static(grpc_mdelem *e) { + return e >= &grpc_static_mdelem_table[0] && + e < &grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; } static void ref_md_locked(mdtab_shard *shard, - interned_metadata *md DEBUG_ARGS) { + internal_metadata *md DEBUG_ARGS) { #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_atm_no_barrier_load(&md->refcnt) + 1, + grpc_mdstr_as_c_string((grpc_mdstr *)md->key), + grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); #endif if (0 == gpr_atm_no_barrier_fetch_add(&md->refcnt, 1)) { gpr_atm_no_barrier_fetch_add(&shard->free_estimate, -1); } } +static void grow_strtab(strtab_shard *shard) { + size_t capacity = shard->capacity * 2; + size_t i; + internal_string **strtab; + internal_string *s, *next; + + GPR_TIMER_BEGIN("grow_strtab", 0); + + strtab = gpr_malloc(sizeof(internal_string *) * capacity); + memset(strtab, 0, sizeof(internal_string *) * capacity); + + for (i = 0; i < shard->capacity; i++) { + for (s = shard->strs[i]; s; s = next) { + size_t idx = TABLE_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT, capacity); + next = s->bucket_next; + s->bucket_next = strtab[idx]; + strtab[idx] = s; + } + } + + gpr_free(shard->strs); + shard->strs = strtab; + shard->capacity = capacity; + + GPR_TIMER_END("grow_strtab", 0); +} + +static void internal_destroy_string(grpc_exec_ctx *exec_ctx, + strtab_shard *shard, internal_string *is) { + internal_string **prev_next; + internal_string *cur; + GPR_TIMER_BEGIN("internal_destroy_string", 0); + if (is->has_base64_and_huffman_encoded) { + grpc_slice_unref_internal(exec_ctx, is->base64_and_huffman); + } + for (prev_next = &shard->strs[TABLE_IDX(is->hash, LOG2_STRTAB_SHARD_COUNT, + shard->capacity)], + cur = *prev_next; + cur != is; prev_next = &cur->bucket_next, cur = cur->bucket_next) + ; + *prev_next = cur->bucket_next; + shard->count--; + gpr_free(is); + GPR_TIMER_END("internal_destroy_string", 0); +} + +static void slice_ref(void *p) { + internal_string *is = + (internal_string *)((char *)p - offsetof(internal_string, refcount)); + GRPC_MDSTR_REF((grpc_mdstr *)(is)); +} + +static void slice_unref(grpc_exec_ctx *exec_ctx, void *p) { + internal_string *is = + (internal_string *)((char *)p - offsetof(internal_string, refcount)); + GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)(is)); +} + +grpc_mdstr *grpc_mdstr_from_string(const char *str) { + return grpc_mdstr_from_buffer((const uint8_t *)str, strlen(str)); +} + +grpc_mdstr *grpc_mdstr_from_slice(grpc_exec_ctx *exec_ctx, grpc_slice slice) { + grpc_mdstr *result = grpc_mdstr_from_buffer(GRPC_SLICE_START_PTR(slice), + GRPC_SLICE_LENGTH(slice)); + grpc_slice_unref_internal(exec_ctx, slice); + return result; +} + +grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *buf, size_t length) { + uint32_t hash = gpr_murmur_hash3(buf, length, g_hash_seed); + internal_string *s; + strtab_shard *shard = + &g_strtab_shard[SHARD_IDX(hash, LOG2_STRTAB_SHARD_COUNT)]; + size_t i; + size_t idx; + + GPR_TIMER_BEGIN("grpc_mdstr_from_buffer", 0); + + /* search for a static string */ + for (i = 0; i <= g_static_strtab_maxprobe; i++) { + grpc_mdstr *ss; + idx = (hash + i) % GPR_ARRAY_SIZE(g_static_strtab); + ss = g_static_strtab[idx]; + if (ss == NULL) break; + if (ss->hash == hash && GRPC_SLICE_LENGTH(ss->slice) == length && + (length == 0 || + 0 == memcmp(buf, GRPC_SLICE_START_PTR(ss->slice), length))) { + GPR_TIMER_END("grpc_mdstr_from_buffer", 0); + return ss; + } + } + + gpr_mu_lock(&shard->mu); + + /* search for an existing string */ + idx = TABLE_IDX(hash, LOG2_STRTAB_SHARD_COUNT, shard->capacity); + for (s = shard->strs[idx]; s; s = s->bucket_next) { + if (s->hash == hash && GRPC_SLICE_LENGTH(s->slice) == length && + 0 == memcmp(buf, GRPC_SLICE_START_PTR(s->slice), length)) { + if (gpr_atm_full_fetch_add(&s->refcnt, 1) == 0) { + /* If we get here, we've added a ref to something that was about to + * die - drop it immediately. + * The *only* possible path here (given the shard mutex) should be to + * drop from one ref back to zero - assert that with a CAS */ + GPR_ASSERT(gpr_atm_rel_cas(&s->refcnt, 1, 0)); + /* and treat this as if we were never here... sshhh */ + } else { + gpr_mu_unlock(&shard->mu); + GPR_TIMER_END("grpc_mdstr_from_buffer", 0); + return (grpc_mdstr *)s; + } + } + } + + /* not found: create a new string */ + if (length + 1 < GRPC_SLICE_INLINED_SIZE) { + /* string data goes directly into the slice */ + s = gpr_malloc(sizeof(internal_string)); + gpr_atm_rel_store(&s->refcnt, 1); + s->slice.refcount = NULL; + memcpy(s->slice.data.inlined.bytes, buf, length); + s->slice.data.inlined.bytes[length] = 0; + s->slice.data.inlined.length = (uint8_t)length; + } else { + /* string data goes after the internal_string header, and we +1 for null + terminator */ + s = gpr_malloc(sizeof(internal_string) + length + 1); + gpr_atm_rel_store(&s->refcnt, 1); + s->refcount.ref = slice_ref; + s->refcount.unref = slice_unref; + s->slice.refcount = &s->refcount; + s->slice.data.refcounted.bytes = (uint8_t *)(s + 1); + s->slice.data.refcounted.length = length; + memcpy(s->slice.data.refcounted.bytes, buf, length); + /* add a null terminator for cheap c string conversion when desired */ + s->slice.data.refcounted.bytes[length] = 0; + } + s->has_base64_and_huffman_encoded = 0; + s->hash = hash; + s->size_in_decoder_table = SIZE_IN_DECODER_TABLE_NOT_SET; + s->bucket_next = shard->strs[idx]; + shard->strs[idx] = s; + + shard->count++; + + if (shard->count > shard->capacity * 2) { + grow_strtab(shard); + } + + gpr_mu_unlock(&shard->mu); + GPR_TIMER_END("grpc_mdstr_from_buffer", 0); + + return (grpc_mdstr *)s; +} + static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { size_t i; - interned_metadata **prev_next; - interned_metadata *md, *next; + internal_metadata **prev_next; + internal_metadata *md, *next; gpr_atm num_freed = 0; GPR_TIMER_BEGIN("gc_mdtab", 0); @@ -188,8 +459,8 @@ static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { void *user_data = (void *)gpr_atm_no_barrier_load(&md->user_data); next = md->bucket_next; if (gpr_atm_acq_load(&md->refcnt) == 0) { - grpc_slice_unref_internal(exec_ctx, md->key); - grpc_slice_unref_internal(exec_ctx, md->value); + GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)md->key); + GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)md->value); if (md->user_data) { ((destroy_user_data_func)gpr_atm_no_barrier_load( &md->destroy_user_data))(user_data); @@ -210,22 +481,21 @@ static void gc_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { static void grow_mdtab(mdtab_shard *shard) { size_t capacity = shard->capacity * 2; size_t i; - interned_metadata **mdtab; - interned_metadata *md, *next; + internal_metadata **mdtab; + internal_metadata *md, *next; uint32_t hash; GPR_TIMER_BEGIN("grow_mdtab", 0); - mdtab = gpr_malloc(sizeof(interned_metadata *) * capacity); - memset(mdtab, 0, sizeof(interned_metadata *) * capacity); + mdtab = gpr_malloc(sizeof(internal_metadata *) * capacity); + memset(mdtab, 0, sizeof(internal_metadata *) * capacity); for (i = 0; i < shard->capacity; i++) { for (md = shard->elems[i]; md; md = next) { size_t idx; - hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), - grpc_slice_hash(md->value)); + hash = GRPC_MDSTR_KV_HASH(md->key->hash, md->value->hash); next = md->bucket_next; - idx = TABLE_IDX(hash, capacity); + idx = TABLE_IDX(hash, LOG2_MDTAB_SHARD_COUNT, capacity); md->bucket_next = mdtab[idx]; mdtab[idx] = md; } @@ -247,77 +517,62 @@ static void rehash_mdtab(grpc_exec_ctx *exec_ctx, mdtab_shard *shard) { } } -grpc_mdelem grpc_mdelem_create( - grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value, - grpc_mdelem_data *compatible_external_backing_store) { - if (!grpc_slice_is_interned(key) || !grpc_slice_is_interned(value)) { - if (compatible_external_backing_store != NULL) { - return GRPC_MAKE_MDELEM(compatible_external_backing_store, - GRPC_MDELEM_STORAGE_EXTERNAL); - } +grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, + grpc_mdstr *mkey, + grpc_mdstr *mvalue) { + internal_string *key = (internal_string *)mkey; + internal_string *value = (internal_string *)mvalue; + uint32_t hash = GRPC_MDSTR_KV_HASH(mkey->hash, mvalue->hash); + internal_metadata *md; + mdtab_shard *shard = &g_mdtab_shard[SHARD_IDX(hash, LOG2_MDTAB_SHARD_COUNT)]; + size_t i; + size_t idx; - allocated_metadata *allocated = gpr_malloc(sizeof(*allocated)); - allocated->key = grpc_slice_ref_internal(key); - allocated->value = grpc_slice_ref_internal(value); - gpr_atm_rel_store(&allocated->refcnt, 1); -#ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(allocated->key); - char *value_str = grpc_slice_to_c_string(allocated->value); - gpr_log(GPR_DEBUG, "ELM ALLOC:%p:%zu: '%s' = '%s'", (void *)allocated, - gpr_atm_no_barrier_load(&allocated->refcnt), key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); -#endif - return GRPC_MAKE_MDELEM(allocated, GRPC_MDELEM_STORAGE_ALLOCATED); - } + GPR_TIMER_BEGIN("grpc_mdelem_from_metadata_strings", 0); - if (GRPC_IS_STATIC_METADATA_STRING(key) && - GRPC_IS_STATIC_METADATA_STRING(value)) { - grpc_mdelem static_elem = grpc_static_mdelem_for_static_strings( - GRPC_STATIC_METADATA_INDEX(key), GRPC_STATIC_METADATA_INDEX(value)); - if (!GRPC_MDISNULL(static_elem)) { - return static_elem; + if (is_mdstr_static(mkey) && is_mdstr_static(mvalue)) { + for (i = 0; i <= g_static_mdtab_maxprobe; i++) { + grpc_mdelem *smd; + idx = (hash + i) % GPR_ARRAY_SIZE(g_static_mdtab); + smd = g_static_mdtab[idx]; + if (smd == NULL) break; + if (smd->key == mkey && smd->value == mvalue) { + GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); + return smd; + } } } - uint32_t hash = - GRPC_MDSTR_KV_HASH(grpc_slice_hash(key), grpc_slice_hash(value)); - interned_metadata *md; - mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; - size_t idx; - - GPR_TIMER_BEGIN("grpc_mdelem_from_metadata_strings", 0); - gpr_mu_lock(&shard->mu); - idx = TABLE_IDX(hash, shard->capacity); + idx = TABLE_IDX(hash, LOG2_MDTAB_SHARD_COUNT, shard->capacity); /* search for an existing pair */ for (md = shard->elems[idx]; md; md = md->bucket_next) { - if (grpc_slice_eq(key, md->key) && grpc_slice_eq(value, md->value)) { + if (md->key == key && md->value == value) { REF_MD_LOCKED(shard, md); + GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)key); + GRPC_MDSTR_UNREF(exec_ctx, (grpc_mdstr *)value); gpr_mu_unlock(&shard->mu); GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); + return (grpc_mdelem *)md; } } /* not found: create a new pair */ - md = gpr_malloc(sizeof(interned_metadata)); + md = gpr_malloc(sizeof(internal_metadata)); gpr_atm_rel_store(&md->refcnt, 1); - md->key = grpc_slice_ref_internal(key); - md->value = grpc_slice_ref_internal(value); + md->key = key; + md->value = value; md->user_data = 0; md->destroy_user_data = 0; md->bucket_next = shard->elems[idx]; shard->elems[idx] = md; gpr_mu_init(&md->mu_user_data); #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); gpr_log(GPR_DEBUG, "ELM NEW:%p:%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_atm_no_barrier_load(&md->refcnt), + grpc_mdstr_as_c_string((grpc_mdstr *)md->key), + grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); #endif shard->count++; @@ -329,26 +584,29 @@ grpc_mdelem grpc_mdelem_create( GPR_TIMER_END("grpc_mdelem_from_metadata_strings", 0); - return GRPC_MAKE_MDELEM(md, GRPC_MDELEM_STORAGE_INTERNED); + return (grpc_mdelem *)md; +} + +grpc_mdelem *grpc_mdelem_from_strings(grpc_exec_ctx *exec_ctx, const char *key, + const char *value) { + return grpc_mdelem_from_metadata_strings( + exec_ctx, grpc_mdstr_from_string(key), grpc_mdstr_from_string(value)); } -grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value) { - grpc_mdelem out = grpc_mdelem_create(exec_ctx, key, value, NULL); - grpc_slice_unref_internal(exec_ctx, key); - grpc_slice_unref_internal(exec_ctx, value); - return out; +grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value) { + return grpc_mdelem_from_metadata_strings( + exec_ctx, grpc_mdstr_from_slice(exec_ctx, key), + grpc_mdstr_from_slice(exec_ctx, value)); } -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx *exec_ctx, - grpc_metadata *metadata) { - bool changed = false; - grpc_slice key_slice = - grpc_slice_maybe_static_intern(metadata->key, &changed); - grpc_slice value_slice = - grpc_slice_maybe_static_intern(metadata->value, &changed); - return grpc_mdelem_create(exec_ctx, key_slice, value_slice, - changed ? NULL : (grpc_mdelem_data *)metadata); +grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_exec_ctx *exec_ctx, + const char *key, + const uint8_t *value, + size_t value_length) { + return grpc_mdelem_from_metadata_strings( + exec_ctx, grpc_mdstr_from_string(key), + grpc_mdstr_from_buffer(value, value_length)); } static size_t get_base64_encoded_size(size_t raw_length) { @@ -356,176 +614,160 @@ static size_t get_base64_encoded_size(size_t raw_length) { return raw_length / 3 * 4 + tail_xtra[raw_length % 3]; } -size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem) { - size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(GRPC_MDKEY(elem)); - size_t value_len = GRPC_SLICE_LENGTH(GRPC_MDVALUE(elem)); - if (grpc_is_binary_header(GRPC_MDKEY(elem))) { - return overhead_and_key + get_base64_encoded_size(value_len); +size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem) { + size_t overhead_and_key = 32 + GRPC_SLICE_LENGTH(elem->key->slice); + size_t value_len = GRPC_SLICE_LENGTH(elem->value->slice); + if (is_mdstr_static(elem->value)) { + if (grpc_is_binary_header( + (const char *)GRPC_SLICE_START_PTR(elem->key->slice), + GRPC_SLICE_LENGTH(elem->key->slice))) { + return overhead_and_key + get_base64_encoded_size(value_len); + } else { + return overhead_and_key + value_len; + } } else { - return overhead_and_key + value_len; + internal_string *is = (internal_string *)elem->value; + gpr_atm current_size = gpr_atm_acq_load(&is->size_in_decoder_table); + if (current_size == SIZE_IN_DECODER_TABLE_NOT_SET) { + if (grpc_is_binary_header( + (const char *)GRPC_SLICE_START_PTR(elem->key->slice), + GRPC_SLICE_LENGTH(elem->key->slice))) { + current_size = (gpr_atm)get_base64_encoded_size(value_len); + } else { + current_size = (gpr_atm)value_len; + } + gpr_atm_rel_store(&is->size_in_decoder_table, current_size); + } + return overhead_and_key + (size_t)current_size; } } -grpc_mdelem grpc_mdelem_ref(grpc_mdelem gmd DEBUG_ARGS) { - switch (GRPC_MDELEM_STORAGE(gmd)) { - case GRPC_MDELEM_STORAGE_EXTERNAL: - case GRPC_MDELEM_STORAGE_STATIC: - break; - case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); +grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *gmd DEBUG_ARGS) { + internal_metadata *md = (internal_metadata *)gmd; + if (is_mdelem_static(gmd)) return gmd; #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) + 1, + grpc_mdstr_as_c_string((grpc_mdstr *)md->key), + grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); #endif - /* we can assume the ref count is >= 1 as the application is calling - this function - meaning that no adjustment to mdtab_free is necessary, - simplifying the logic here to be just an atomic increment */ - /* use C assert to have this removed in opt builds */ - GPR_ASSERT(gpr_atm_no_barrier_load(&md->refcnt) >= 1); - gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); - break; - } - case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); + /* we can assume the ref count is >= 1 as the application is calling + this function - meaning that no adjustment to mdtab_free is necessary, + simplifying the logic here to be just an atomic increment */ + /* use C assert to have this removed in opt builds */ + GPR_ASSERT(gpr_atm_no_barrier_load(&md->refcnt) >= 1); + gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); + return gmd; +} + +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *gmd DEBUG_ARGS) { + internal_metadata *md = (internal_metadata *)gmd; + if (!md) return; + if (is_mdelem_static(gmd)) return; #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM REF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) + 1, key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, + "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, + gpr_atm_no_barrier_load(&md->refcnt), + gpr_atm_no_barrier_load(&md->refcnt) - 1, + grpc_mdstr_as_c_string((grpc_mdstr *)md->key), + grpc_mdstr_as_c_string((grpc_mdstr *)md->value)); #endif - /* we can assume the ref count is >= 1 as the application is calling - this function - meaning that no adjustment to mdtab_free is necessary, - simplifying the logic here to be just an atomic increment */ - /* use C assert to have this removed in opt builds */ - gpr_atm_no_barrier_fetch_add(&md->refcnt, 1); - break; - } + uint32_t hash = GRPC_MDSTR_KV_HASH(md->key->hash, md->value->hash); + const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); + GPR_ASSERT(prev_refcount >= 1); + if (1 == prev_refcount) { + /* once the refcount hits zero, some other thread can come along and + free md at any time: it's unsafe from this point on to access it */ + mdtab_shard *shard = + &g_mdtab_shard[SHARD_IDX(hash, LOG2_MDTAB_SHARD_COUNT)]; + gpr_atm_no_barrier_fetch_add(&shard->free_estimate, 1); } - return gmd; } -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem gmd DEBUG_ARGS) { - switch (GRPC_MDELEM_STORAGE(gmd)) { - case GRPC_MDELEM_STORAGE_EXTERNAL: - case GRPC_MDELEM_STORAGE_STATIC: - break; - case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata *md = (interned_metadata *)GRPC_MDELEM_DATA(gmd); +const char *grpc_mdstr_as_c_string(const grpc_mdstr *s) { + return (const char *)GRPC_SLICE_START_PTR(s->slice); +} + +size_t grpc_mdstr_length(const grpc_mdstr *s) { return GRPC_MDSTR_LENGTH(s); } + +grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *gs DEBUG_ARGS) { + internal_string *s = (internal_string *)gs; + if (is_mdstr_static(gs)) return gs; #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) - 1, key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR REF:%p:%zu->%zu: '%s'", + (void *)s, gpr_atm_no_barrier_load(&s->refcnt), + gpr_atm_no_barrier_load(&s->refcnt) + 1, grpc_mdstr_as_c_string(gs)); #endif - uint32_t hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(md->key), - grpc_slice_hash(md->value)); - const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); - GPR_ASSERT(prev_refcount >= 1); - if (1 == prev_refcount) { - /* once the refcount hits zero, some other thread can come along and - free md at any time: it's unsafe from this point on to access it */ - mdtab_shard *shard = &g_shards[SHARD_IDX(hash)]; - gpr_atm_no_barrier_fetch_add(&shard->free_estimate, 1); - } - break; - } - case GRPC_MDELEM_STORAGE_ALLOCATED: { - allocated_metadata *md = (allocated_metadata *)GRPC_MDELEM_DATA(gmd); + GPR_ASSERT(gpr_atm_full_fetch_add(&s->refcnt, 1) > 0); + return gs; +} + +void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *gs DEBUG_ARGS) { + internal_string *s = (internal_string *)gs; + if (is_mdstr_static(gs)) return; #ifdef GRPC_METADATA_REFCOUNT_DEBUG - char *key_str = grpc_slice_to_c_string(md->key); - char *value_str = grpc_slice_to_c_string(md->value); - gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, - "ELM UNREF:%p:%zu->%zu: '%s' = '%s'", (void *)md, - gpr_atm_no_barrier_load(&md->refcnt), - gpr_atm_no_barrier_load(&md->refcnt) - 1, key_str, value_str); - gpr_free(key_str); - gpr_free(value_str); + gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG, "STR UNREF:%p:%zu->%zu: '%s'", + (void *)s, gpr_atm_no_barrier_load(&s->refcnt), + gpr_atm_no_barrier_load(&s->refcnt) - 1, grpc_mdstr_as_c_string(gs)); #endif - const gpr_atm prev_refcount = gpr_atm_full_fetch_add(&md->refcnt, -1); - GPR_ASSERT(prev_refcount >= 1); - if (1 == prev_refcount) { - grpc_slice_unref_internal(exec_ctx, md->key); - grpc_slice_unref_internal(exec_ctx, md->value); - gpr_free(md); - } - break; - } + if (1 == gpr_atm_full_fetch_add(&s->refcnt, -1)) { + strtab_shard *shard = + &g_strtab_shard[SHARD_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT)]; + gpr_mu_lock(&shard->mu); + GPR_ASSERT(0 == gpr_atm_no_barrier_load(&s->refcnt)); + internal_destroy_string(exec_ctx, shard, s); + gpr_mu_unlock(&shard->mu); } } -void *grpc_mdelem_get_user_data(grpc_mdelem md, void (*destroy_func)(void *)) { - switch (GRPC_MDELEM_STORAGE(md)) { - case GRPC_MDELEM_STORAGE_EXTERNAL: - case GRPC_MDELEM_STORAGE_ALLOCATED: - return NULL; - case GRPC_MDELEM_STORAGE_STATIC: - return (void *)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - - grpc_static_mdelem_table]; - case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata *im = (interned_metadata *)GRPC_MDELEM_DATA(md); - void *result; - if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { - return (void *)gpr_atm_no_barrier_load(&im->user_data); - } else { - return NULL; - } - return result; - } +void *grpc_mdelem_get_user_data(grpc_mdelem *md, void (*destroy_func)(void *)) { + internal_metadata *im = (internal_metadata *)md; + void *result; + if (is_mdelem_static(md)) { + return (void *)grpc_static_mdelem_user_data[md - grpc_static_mdelem_table]; + } + if (gpr_atm_acq_load(&im->destroy_user_data) == (gpr_atm)destroy_func) { + return (void *)gpr_atm_no_barrier_load(&im->user_data); + } else { + return NULL; } - GPR_UNREACHABLE_CODE(return NULL); + return result; } -void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), +void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), void *user_data) { - switch (GRPC_MDELEM_STORAGE(md)) { - case GRPC_MDELEM_STORAGE_EXTERNAL: - case GRPC_MDELEM_STORAGE_ALLOCATED: + internal_metadata *im = (internal_metadata *)md; + GPR_ASSERT(!is_mdelem_static(md)); + GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); + gpr_mu_lock(&im->mu_user_data); + if (gpr_atm_no_barrier_load(&im->destroy_user_data)) { + /* user data can only be set once */ + gpr_mu_unlock(&im->mu_user_data); + if (destroy_func != NULL) { destroy_func(user_data); - return NULL; - case GRPC_MDELEM_STORAGE_STATIC: - destroy_func(user_data); - return (void *)grpc_static_mdelem_user_data[GRPC_MDELEM_DATA(md) - - grpc_static_mdelem_table]; - case GRPC_MDELEM_STORAGE_INTERNED: { - interned_metadata *im = (interned_metadata *)GRPC_MDELEM_DATA(md); - GPR_ASSERT(!is_mdelem_static(md)); - GPR_ASSERT((user_data == NULL) == (destroy_func == NULL)); - gpr_mu_lock(&im->mu_user_data); - if (gpr_atm_no_barrier_load(&im->destroy_user_data)) { - /* user data can only be set once */ - gpr_mu_unlock(&im->mu_user_data); - if (destroy_func != NULL) { - destroy_func(user_data); - } - return (void *)gpr_atm_no_barrier_load(&im->user_data); - } - gpr_atm_no_barrier_store(&im->user_data, (gpr_atm)user_data); - gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func); - gpr_mu_unlock(&im->mu_user_data); - return user_data; } + return (void *)gpr_atm_no_barrier_load(&im->user_data); } - GPR_UNREACHABLE_CODE(return NULL); + gpr_atm_no_barrier_store(&im->user_data, (gpr_atm)user_data); + gpr_atm_rel_store(&im->destroy_user_data, (gpr_atm)destroy_func); + gpr_mu_unlock(&im->mu_user_data); + return user_data; } -bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b) { - if (a.payload == b.payload) return true; - if (GRPC_MDELEM_IS_INTERNED(a) && GRPC_MDELEM_IS_INTERNED(b)) return false; - if (GRPC_MDISNULL(a) || GRPC_MDISNULL(b)) return false; - return grpc_slice_eq(GRPC_MDKEY(a), GRPC_MDKEY(b)) && - grpc_slice_eq(GRPC_MDVALUE(a), GRPC_MDVALUE(b)); +grpc_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *gs) { + internal_string *s = (internal_string *)gs; + grpc_slice slice; + strtab_shard *shard = + &g_strtab_shard[SHARD_IDX(s->hash, LOG2_STRTAB_SHARD_COUNT)]; + gpr_mu_lock(&shard->mu); + if (!s->has_base64_and_huffman_encoded) { + s->base64_and_huffman = + grpc_chttp2_base64_encode_and_huffman_compress(s->slice); + s->has_base64_and_huffman_encoded = 1; + } + slice = s->base64_and_huffman; + gpr_mu_unlock(&shard->mu); + return slice; } diff --git a/src/core/lib/transport/metadata.h b/src/core/lib/transport/metadata.h index f4ba86c854b..991eee96f1c 100644 --- a/src/core/lib/transport/metadata.h +++ b/src/core/lib/transport/metadata.h @@ -34,7 +34,6 @@ #ifndef GRPC_CORE_LIB_TRANSPORT_METADATA_H #define GRPC_CORE_LIB_TRANSPORT_METADATA_H -#include #include #include @@ -75,110 +74,110 @@ extern "C" { declared here - in which case those functions are effectively no-ops. */ /* Forward declarations */ +typedef struct grpc_mdstr grpc_mdstr; typedef struct grpc_mdelem grpc_mdelem; -/* if changing this, make identical changes in: - - interned_metadata, allocated_metadata in metadata.c - - grpc_metadata in grpc_types.h */ -typedef struct grpc_mdelem_data { - const grpc_slice key; - const grpc_slice value; +/* if changing this, make identical changes in internal_string in metadata.c */ +struct grpc_mdstr { + const grpc_slice slice; + const uint32_t hash; /* there is a private part to this in metadata.c */ -} grpc_mdelem_data; - -/* GRPC_MDELEM_STORAGE_* enum values that can be treated as interned always have - this bit set in their integer value */ -#define GRPC_MDELEM_STORAGE_INTERNED_BIT 1 - -typedef enum { - /* memory pointed to by grpc_mdelem::payload is owned by an external system */ - GRPC_MDELEM_STORAGE_EXTERNAL = 0, - /* memory pointed to by grpc_mdelem::payload is interned by the metadata - system */ - GRPC_MDELEM_STORAGE_INTERNED = GRPC_MDELEM_STORAGE_INTERNED_BIT, - /* memory pointed to by grpc_mdelem::payload is allocated by the metadata - system */ - GRPC_MDELEM_STORAGE_ALLOCATED = 2, - /* memory is in the static metadata table */ - GRPC_MDELEM_STORAGE_STATIC = 2 | GRPC_MDELEM_STORAGE_INTERNED_BIT, -} grpc_mdelem_data_storage; +}; +/* if changing this, make identical changes in internal_metadata in + metadata.c */ struct grpc_mdelem { - /* a grpc_mdelem_data* generally, with the two lower bits signalling memory - ownership as per grpc_mdelem_data_storage */ - uintptr_t payload; + grpc_mdstr *const key; + grpc_mdstr *const value; + /* there is a private part to this in metadata.c */ }; -#define GRPC_MDELEM_DATA(md) \ - ((grpc_mdelem_data *)((md).payload & ~(uintptr_t)3)) -#define GRPC_MDELEM_STORAGE(md) \ - ((grpc_mdelem_data_storage)((md).payload & (uintptr_t)3)) -#define GRPC_MAKE_MDELEM(data, storage) \ - ((grpc_mdelem){((uintptr_t)(data)) | ((uintptr_t)storage)}) -#define GRPC_MDELEM_IS_INTERNED(md) \ - ((grpc_mdelem_data_storage)((md).payload & \ - (uintptr_t)GRPC_MDELEM_STORAGE_INTERNED_BIT)) - +void grpc_test_only_set_metadata_hash_seed(uint32_t seed); + +/* Constructors for grpc_mdstr instances; take a variety of data types that + clients may have handy */ +grpc_mdstr *grpc_mdstr_from_string(const char *str); +/* Unrefs the slice. */ +grpc_mdstr *grpc_mdstr_from_slice(grpc_exec_ctx *exec_ctx, grpc_slice slice); +grpc_mdstr *grpc_mdstr_from_buffer(const uint8_t *str, size_t length); + +/* Returns a borrowed slice from the mdstr with its contents base64 encoded + and huffman compressed */ +grpc_slice grpc_mdstr_as_base64_encoded_and_huffman_compressed(grpc_mdstr *str); + +/* Constructors for grpc_mdelem instances; take a variety of data types that + clients may have handy */ +grpc_mdelem *grpc_mdelem_from_metadata_strings(grpc_exec_ctx *exec_ctx, + grpc_mdstr *key, + grpc_mdstr *value); +grpc_mdelem *grpc_mdelem_from_strings(grpc_exec_ctx *exec_ctx, const char *key, + const char *value); /* Unrefs the slices. */ -grpc_mdelem grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, - grpc_slice value); - -/* Cheaply convert a grpc_metadata to a grpc_mdelem; may use the grpc_metadata - object as backing storage (so lifetimes should align) */ -grpc_mdelem grpc_mdelem_from_grpc_metadata(grpc_exec_ctx *exec_ctx, - grpc_metadata *metadata); +grpc_mdelem *grpc_mdelem_from_slices(grpc_exec_ctx *exec_ctx, grpc_slice key, + grpc_slice value); +grpc_mdelem *grpc_mdelem_from_string_and_buffer(grpc_exec_ctx *exec_ctx, + const char *key, + const uint8_t *value, + size_t value_length); -/* Does not unref the slices; if a new non-interned mdelem is needed, allocates - one if compatible_external_backing_store is NULL, or uses - compatible_external_backing_store if it is non-NULL (in which case it's the - users responsibility to ensure that it outlives usage) */ -grpc_mdelem grpc_mdelem_create( - grpc_exec_ctx *exec_ctx, grpc_slice key, grpc_slice value, - grpc_mdelem_data *compatible_external_backing_store); - -bool grpc_mdelem_eq(grpc_mdelem a, grpc_mdelem b); - -size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem elem); +size_t grpc_mdelem_get_size_in_hpack_table(grpc_mdelem *elem); /* Mutator and accessor for grpc_mdelem user data. The destructor function is used as a type tag and is checked during user_data fetch. */ -void *grpc_mdelem_get_user_data(grpc_mdelem md, +void *grpc_mdelem_get_user_data(grpc_mdelem *md, void (*if_destroy_func)(void *)); -void *grpc_mdelem_set_user_data(grpc_mdelem md, void (*destroy_func)(void *), +void *grpc_mdelem_set_user_data(grpc_mdelem *md, void (*destroy_func)(void *), void *user_data); /* Reference counting */ //#define GRPC_METADATA_REFCOUNT_DEBUG #ifdef GRPC_METADATA_REFCOUNT_DEBUG +#define GRPC_MDSTR_REF(s) grpc_mdstr_ref((s), __FILE__, __LINE__) +#define GRPC_MDSTR_UNREF(exec_ctx, s) \ + grpc_mdstr_unref((exec_ctx), (s), __FILE__, __LINE__) #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s), __FILE__, __LINE__) #define GRPC_MDELEM_UNREF(exec_ctx, s) \ grpc_mdelem_unref((exec_ctx), (s), __FILE__, __LINE__) -grpc_mdelem grpc_mdelem_ref(grpc_mdelem md, const char *file, int line); -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md, +grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s, const char *file, int line); +void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *s, const char *file, + int line); +grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md, const char *file, int line); +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md, const char *file, int line); #else +#define GRPC_MDSTR_REF(s) grpc_mdstr_ref((s)) +#define GRPC_MDSTR_UNREF(exec_ctx, s) grpc_mdstr_unref((exec_ctx), (s)) #define GRPC_MDELEM_REF(s) grpc_mdelem_ref((s)) #define GRPC_MDELEM_UNREF(exec_ctx, s) grpc_mdelem_unref((exec_ctx), (s)) -grpc_mdelem grpc_mdelem_ref(grpc_mdelem md); -void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem md); +grpc_mdstr *grpc_mdstr_ref(grpc_mdstr *s); +void grpc_mdstr_unref(grpc_exec_ctx *exec_ctx, grpc_mdstr *s); +grpc_mdelem *grpc_mdelem_ref(grpc_mdelem *md); +void grpc_mdelem_unref(grpc_exec_ctx *exec_ctx, grpc_mdelem *md); #endif -#define GRPC_MDKEY(md) (GRPC_MDELEM_DATA(md)->key) -#define GRPC_MDVALUE(md) (GRPC_MDELEM_DATA(md)->value) +/* Recover a char* from a grpc_mdstr. The returned string is null terminated. + Does not promise that the returned string has no embedded nulls however. */ +const char *grpc_mdstr_as_c_string(const grpc_mdstr *s); -#define GRPC_MDNULL GRPC_MAKE_MDELEM(NULL, GRPC_MDELEM_STORAGE_EXTERNAL) -#define GRPC_MDISNULL(md) (GRPC_MDELEM_DATA(md) == NULL) +#define GRPC_MDSTR_LENGTH(s) (GRPC_SLICE_LENGTH(s->slice)) /* We add 32 bytes of padding as per RFC-7540 section 6.5.2. */ -#define GRPC_MDELEM_LENGTH(e) \ - (GRPC_SLICE_LENGTH(GRPC_MDKEY((e))) + GRPC_SLICE_LENGTH(GRPC_MDVALUE((e))) + \ - 32) +#define GRPC_MDELEM_LENGTH(e) \ + (GRPC_MDSTR_LENGTH((e)->key) + GRPC_MDSTR_LENGTH((e)->value) + 32) + +int grpc_mdstr_is_legal_header(grpc_mdstr *s); +int grpc_mdstr_is_legal_nonbin_header(grpc_mdstr *s); +int grpc_mdstr_is_bin_suffixed(grpc_mdstr *s); #define GRPC_MDSTR_KV_HASH(k_hash, v_hash) (GPR_ROTL((k_hash), 2) ^ (v_hash)) void grpc_mdctx_global_init(void); void grpc_mdctx_global_shutdown(grpc_exec_ctx *exec_ctx); +/* Implementation provided by chttp2_transport */ +extern grpc_slice (*grpc_chttp2_base64_encode_and_huffman_compress)( + grpc_slice input); + #ifdef __cplusplus } #endif diff --git a/src/core/lib/transport/metadata_batch.c b/src/core/lib/transport/metadata_batch.c index 95b71d33d77..b62ecc3aa6f 100644 --- a/src/core/lib/transport/metadata_batch.c +++ b/src/core/lib/transport/metadata_batch.c @@ -40,8 +40,6 @@ #include #include "src/core/lib/profiling/timers.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" static void assert_valid_list(grpc_mdelem_list *list) { #ifndef NDEBUG @@ -53,34 +51,16 @@ static void assert_valid_list(grpc_mdelem_list *list) { GPR_ASSERT(list->tail->next == NULL); GPR_ASSERT((list->head == list->tail) == (list->head->next == NULL)); - size_t verified_count = 0; for (l = list->head; l; l = l->next) { - GPR_ASSERT(!GRPC_MDISNULL(l->md)); + GPR_ASSERT(l->md); GPR_ASSERT((l->prev == NULL) == (l == list->head)); GPR_ASSERT((l->next == NULL) == (l == list->tail)); if (l->next) GPR_ASSERT(l->next->prev == l); if (l->prev) GPR_ASSERT(l->prev->next == l); - verified_count++; } - GPR_ASSERT(list->count == verified_count); #endif /* NDEBUG */ } -static void assert_valid_callouts(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch) { -#ifndef NDEBUG - for (grpc_linked_mdelem *l = batch->list.head; l != NULL; l = l->next) { - grpc_slice key_interned = grpc_slice_intern(GRPC_MDKEY(l->md)); - grpc_metadata_batch_callouts_index callout_idx = - GRPC_BATCH_INDEX_OF(key_interned); - if (callout_idx != GRPC_BATCH_CALLOUTS_COUNT) { - GPR_ASSERT(batch->idx.array[callout_idx] == l); - } - grpc_slice_unref_internal(exec_ctx, key_interned); - } -#endif -} - #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) { assert_valid_list(&batch->list); @@ -88,7 +68,7 @@ void grpc_metadata_batch_assert_ok(grpc_metadata_batch *batch) { #endif /* NDEBUG */ void grpc_metadata_batch_init(grpc_metadata_batch *batch) { - memset(batch, 0, sizeof(*batch)); + batch->list.head = batch->list.tail = NULL; batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); } @@ -100,58 +80,17 @@ void grpc_metadata_batch_destroy(grpc_exec_ctx *exec_ctx, } } -grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md) { - char *k = grpc_slice_to_c_string(GRPC_MDKEY(md)); - char *v = grpc_slice_to_c_string(GRPC_MDVALUE(md)); - grpc_error *out = grpc_error_set_str( - grpc_error_set_str(src, GRPC_ERROR_STR_KEY, k), GRPC_ERROR_STR_VALUE, v); - gpr_free(k); - gpr_free(v); - return out; -} - -static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) - GRPC_MUST_USE_RESULT; - -static grpc_error *maybe_link_callout(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { - grpc_metadata_batch_callouts_index idx = - GRPC_BATCH_INDEX_OF(GRPC_MDKEY(storage->md)); - if (idx == GRPC_BATCH_CALLOUTS_COUNT) { - return GRPC_ERROR_NONE; - } - if (batch->idx.array[idx] == NULL) { - batch->idx.array[idx] = storage; - return GRPC_ERROR_NONE; - } - return grpc_attach_md_to_error( - GRPC_ERROR_CREATE("Unallowed duplicate metadata"), storage->md); -} - -static void maybe_unlink_callout(grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { - grpc_metadata_batch_callouts_index idx = - GRPC_BATCH_INDEX_OF(GRPC_MDKEY(storage->md)); - if (idx == GRPC_BATCH_CALLOUTS_COUNT) { - return; - } - GPR_ASSERT(batch->idx.array[idx] != NULL); - batch->idx.array[idx] = NULL; -} - -grpc_error *grpc_metadata_batch_add_head(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) { - GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); +void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem *elem_to_add) { + GPR_ASSERT(elem_to_add); storage->md = elem_to_add; - return grpc_metadata_batch_link_head(exec_ctx, batch, storage); + grpc_metadata_batch_link_head(batch, storage); } static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(!GRPC_MDISNULL(storage->md)); + GPR_ASSERT(storage->md); storage->prev = NULL; storage->next = list->head; if (list->head != NULL) { @@ -160,36 +99,25 @@ static void link_head(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { list->tail = storage; } list->head = storage; - list->count++; assert_valid_list(list); } -grpc_error *grpc_metadata_batch_link_head(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { - assert_valid_callouts(exec_ctx, batch); - grpc_error *err = maybe_link_callout(batch, storage); - if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(exec_ctx, batch); - return err; - } +void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { link_head(&batch->list, storage); - assert_valid_callouts(exec_ctx, batch); - return GRPC_ERROR_NONE; } -grpc_error *grpc_metadata_batch_add_tail(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem elem_to_add) { - GPR_ASSERT(!GRPC_MDISNULL(elem_to_add)); +void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem *elem_to_add) { + GPR_ASSERT(elem_to_add); storage->md = elem_to_add; - return grpc_metadata_batch_link_tail(exec_ctx, batch, storage); + grpc_metadata_batch_link_tail(batch, storage); } static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { assert_valid_list(list); - GPR_ASSERT(!GRPC_MDISNULL(storage->md)); + GPR_ASSERT(storage->md); storage->prev = list->tail; storage->next = NULL; storage->reserved = NULL; @@ -199,82 +127,70 @@ static void link_tail(grpc_mdelem_list *list, grpc_linked_mdelem *storage) { list->head = storage; } list->tail = storage; - list->count++; assert_valid_list(list); } -grpc_error *grpc_metadata_batch_link_tail(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { - assert_valid_callouts(exec_ctx, batch); - grpc_error *err = maybe_link_callout(batch, storage); - if (err != GRPC_ERROR_NONE) { - assert_valid_callouts(exec_ctx, batch); - return err; - } +void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage) { link_tail(&batch->list, storage); - assert_valid_callouts(exec_ctx, batch); - return GRPC_ERROR_NONE; } -static void unlink_storage(grpc_mdelem_list *list, - grpc_linked_mdelem *storage) { - assert_valid_list(list); - if (storage->prev != NULL) { - storage->prev->next = storage->next; - } else { - list->head = storage->next; - } - if (storage->next != NULL) { - storage->next->prev = storage->prev; - } else { - list->tail = storage->prev; - } - list->count--; - assert_valid_list(list); +void grpc_metadata_batch_move(grpc_metadata_batch *dst, + grpc_metadata_batch *src) { + *dst = *src; + memset(src, 0, sizeof(grpc_metadata_batch)); } -void grpc_metadata_batch_remove(grpc_exec_ctx *exec_ctx, +void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) { - assert_valid_callouts(exec_ctx, batch); - maybe_unlink_callout(batch, storage); - unlink_storage(&batch->list, storage); - GRPC_MDELEM_UNREF(exec_ctx, storage->md); - assert_valid_callouts(exec_ctx, batch); -} + grpc_mdelem *(*filter)(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem *elem), + void *user_data) { + grpc_linked_mdelem *l; + grpc_linked_mdelem *next; -void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, - grpc_linked_mdelem *storage, - grpc_slice value) { - grpc_mdelem old = storage->md; - grpc_mdelem new = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_ref_internal(GRPC_MDKEY(old)), value); - storage->md = new; - GRPC_MDELEM_UNREF(exec_ctx, old); -} + GPR_TIMER_BEGIN("grpc_metadata_batch_filter", 0); -grpc_error *grpc_metadata_batch_substitute(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem new) { - grpc_error *error = GRPC_ERROR_NONE; - grpc_mdelem old = storage->md; - if (!grpc_slice_eq(GRPC_MDKEY(new), GRPC_MDKEY(old))) { - maybe_unlink_callout(batch, storage); - storage->md = new; - error = maybe_link_callout(batch, storage); - } else { - storage->md = new; + assert_valid_list(&batch->list); + for (l = batch->list.head; l; l = next) { + grpc_mdelem *orig = l->md; + grpc_mdelem *filt = filter(exec_ctx, user_data, orig); + next = l->next; + if (filt == NULL) { + if (l->prev) { + l->prev->next = l->next; + } + if (l->next) { + l->next->prev = l->prev; + } + if (batch->list.head == l) { + batch->list.head = l->next; + } + if (batch->list.tail == l) { + batch->list.tail = l->prev; + } + assert_valid_list(&batch->list); + GRPC_MDELEM_UNREF(exec_ctx, l->md); + } else if (filt != orig) { + GRPC_MDELEM_UNREF(exec_ctx, orig); + l->md = filt; + } } - GRPC_MDELEM_UNREF(exec_ctx, old); - return error; + assert_valid_list(&batch->list); + + GPR_TIMER_END("grpc_metadata_batch_filter", 0); +} + +static grpc_mdelem *no_metadata_for_you(grpc_exec_ctx *exec_ctx, + void *user_data, grpc_mdelem *elem) { + return NULL; } void grpc_metadata_batch_clear(grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch) { - grpc_metadata_batch_destroy(exec_ctx, batch); - grpc_metadata_batch_init(batch); + batch->deadline = gpr_inf_future(GPR_CLOCK_REALTIME); + grpc_metadata_batch_filter(exec_ctx, batch, no_metadata_for_you, NULL); } bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch) { @@ -291,33 +207,3 @@ size_t grpc_metadata_batch_size(grpc_metadata_batch *batch) { } return size; } - -static void add_error(grpc_error **composite, grpc_error *error, - const char *composite_error_string) { - if (error == GRPC_ERROR_NONE) return; - if (*composite == GRPC_ERROR_NONE) { - *composite = GRPC_ERROR_CREATE(composite_error_string); - } - *composite = grpc_error_add_child(*composite, error); -} - -grpc_error *grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_metadata_batch_filter_func func, - void *user_data, - const char *composite_error_string) { - grpc_linked_mdelem *l = batch->list.head; - grpc_error *error = GRPC_ERROR_NONE; - while (l) { - grpc_linked_mdelem *next = l->next; - grpc_filtered_mdelem new = func(exec_ctx, user_data, l->md); - add_error(&error, new.error, composite_error_string); - if (GRPC_MDISNULL(new.md)) { - grpc_metadata_batch_remove(exec_ctx, batch, l); - } else if (new.md.payload != l->md.payload) { - grpc_metadata_batch_substitute(exec_ctx, batch, l, new.md); - } - l = next; - } - return error; -} diff --git a/src/core/lib/transport/metadata_batch.h b/src/core/lib/transport/metadata_batch.h index 5471539e824..c0bd5174abb 100644 --- a/src/core/lib/transport/metadata_batch.h +++ b/src/core/lib/transport/metadata_batch.h @@ -41,21 +41,19 @@ #include #include #include "src/core/lib/transport/metadata.h" -#include "src/core/lib/transport/static_metadata.h" #ifdef __cplusplus extern "C" { #endif typedef struct grpc_linked_mdelem { - grpc_mdelem md; + grpc_mdelem *md; struct grpc_linked_mdelem *next; struct grpc_linked_mdelem *prev; void *reserved; } grpc_linked_mdelem; typedef struct grpc_mdelem_list { - size_t count; grpc_linked_mdelem *head; grpc_linked_mdelem *tail; } grpc_mdelem_list; @@ -63,7 +61,6 @@ typedef struct grpc_mdelem_list { typedef struct grpc_metadata_batch { /** Metadata elements in this batch */ grpc_mdelem_list list; - grpc_metadata_batch_callouts idx; /** Used to calculate grpc-timeout at the point of sending, or gpr_inf_future if this batch does not need to send a grpc-timeout */ @@ -80,37 +77,25 @@ bool grpc_metadata_batch_is_empty(grpc_metadata_batch *batch); /* Returns the transport size of the batch. */ size_t grpc_metadata_batch_size(grpc_metadata_batch *batch); -/** Remove \a storage from the batch, unreffing the mdelem contained */ -void grpc_metadata_batch_remove(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage); - -/** Substitute a new mdelem for an old value */ -grpc_error *grpc_metadata_batch_substitute(grpc_exec_ctx *exec_ctx, - grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, - grpc_mdelem new_value); - -void grpc_metadata_batch_set_value(grpc_exec_ctx *exec_ctx, - grpc_linked_mdelem *storage, - grpc_slice value); +/** Moves the metadata information from \a src to \a dst. Upon return, \a src is + * zeroed. */ +void grpc_metadata_batch_move(grpc_metadata_batch *dst, + grpc_metadata_batch *src); /** Add \a storage to the beginning of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error *grpc_metadata_batch_link_head( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) GRPC_MUST_USE_RESULT; +void grpc_metadata_batch_link_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage); /** Add \a storage to the end of \a batch. storage->md is assumed to be valid. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. */ -grpc_error *grpc_metadata_batch_link_tail( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_linked_mdelem *storage) GRPC_MUST_USE_RESULT; +void grpc_metadata_batch_link_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage); /** Add \a elem_to_add as the first element in \a batch, using \a storage as backing storage for the linked list element. @@ -118,38 +103,29 @@ grpc_error *grpc_metadata_batch_link_tail( lifetime of batch. This usually means it should be around for the lifetime of the call. Takes ownership of \a elem_to_add */ -grpc_error *grpc_metadata_batch_add_head( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; +void grpc_metadata_batch_add_head(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem *elem_to_add); /** Add \a elem_to_add as the last element in \a batch, using \a storage as backing storage for the linked list element. \a storage is owned by the caller and must survive for the lifetime of batch. This usually means it should be around for the lifetime of the call. Takes ownership of \a elem_to_add */ -grpc_error *grpc_metadata_batch_add_tail( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_linked_mdelem *storage, grpc_mdelem elem_to_add) GRPC_MUST_USE_RESULT; - -grpc_error *grpc_attach_md_to_error(grpc_error *src, grpc_mdelem md); - -typedef struct { - grpc_error *error; - grpc_mdelem md; -} grpc_filtered_mdelem; - -#define GRPC_FILTERED_ERROR(error) \ - ((grpc_filtered_mdelem){(error), GRPC_MDNULL}) -#define GRPC_FILTERED_MDELEM(md) ((grpc_filtered_mdelem){GRPC_ERROR_NONE, (md)}) -#define GRPC_FILTERED_REMOVE() \ - ((grpc_filtered_mdelem){GRPC_ERROR_NONE, GRPC_MDNULL}) - -typedef grpc_filtered_mdelem (*grpc_metadata_batch_filter_func)( - grpc_exec_ctx *exec_ctx, void *user_data, grpc_mdelem elem); -grpc_error *grpc_metadata_batch_filter( - grpc_exec_ctx *exec_ctx, grpc_metadata_batch *batch, - grpc_metadata_batch_filter_func func, void *user_data, - const char *composite_error_string) GRPC_MUST_USE_RESULT; +void grpc_metadata_batch_add_tail(grpc_metadata_batch *batch, + grpc_linked_mdelem *storage, + grpc_mdelem *elem_to_add); + +/** For each element in \a batch, execute \a filter. + The return value from \a filter will be substituted for the + grpc_mdelem passed to \a filter. If \a filter returns NULL, + the element will be moved to the garbage list. */ +void grpc_metadata_batch_filter(grpc_exec_ctx *exec_ctx, + grpc_metadata_batch *batch, + grpc_mdelem *(*filter)(grpc_exec_ctx *exec_ctx, + void *user_data, + grpc_mdelem *elem), + void *user_data); #ifndef NDEBUG void grpc_metadata_batch_assert_ok(grpc_metadata_batch *comd); diff --git a/src/core/lib/transport/method_config.c b/src/core/lib/transport/method_config.c new file mode 100644 index 00000000000..25fb54b37db --- /dev/null +++ b/src/core/lib/transport/method_config.c @@ -0,0 +1,347 @@ +// +// 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 + +#include "src/core/lib/transport/mdstr_hash_table.h" +#include "src/core/lib/transport/metadata.h" + +// +// grpc_method_config +// + +// bool vtable + +static void* bool_copy(void* valuep) { + bool value = *(bool*)valuep; + bool* new_value = gpr_malloc(sizeof(bool)); + *new_value = value; + return new_value; +} + +static int bool_cmp(void* v1, void* v2) { + bool b1 = *(bool*)v1; + bool b2 = *(bool*)v2; + if (!b1 && b2) return -1; + if (b1 && !b2) return 1; + return 0; +} + +static void free_mem(grpc_exec_ctx* exec_ctx, void* p) { gpr_free(p); } + +static grpc_mdstr_hash_table_vtable bool_vtable = {free_mem, bool_copy, + bool_cmp}; + +// timespec vtable + +static void* timespec_copy(void* valuep) { + gpr_timespec value = *(gpr_timespec*)valuep; + gpr_timespec* new_value = gpr_malloc(sizeof(gpr_timespec)); + *new_value = value; + return new_value; +} + +static int timespec_cmp(void* v1, void* v2) { + return gpr_time_cmp(*(gpr_timespec*)v1, *(gpr_timespec*)v2); +} + +static grpc_mdstr_hash_table_vtable timespec_vtable = {free_mem, timespec_copy, + timespec_cmp}; + +// int32 vtable + +static void* int32_copy(void* valuep) { + int32_t value = *(int32_t*)valuep; + int32_t* new_value = gpr_malloc(sizeof(int32_t)); + *new_value = value; + return new_value; +} + +static int int32_cmp(void* v1, void* v2) { + int32_t i1 = *(int32_t*)v1; + int32_t i2 = *(int32_t*)v2; + if (i1 < i2) return -1; + if (i1 > i2) return 1; + return 0; +} + +static grpc_mdstr_hash_table_vtable int32_vtable = {free_mem, int32_copy, + int32_cmp}; + +// Hash table keys. +#define GRPC_METHOD_CONFIG_WAIT_FOR_READY "grpc.wait_for_ready" // bool +#define GRPC_METHOD_CONFIG_TIMEOUT "grpc.timeout" // gpr_timespec +#define GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES \ + "grpc.max_request_message_bytes" // int32 +#define GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES \ + "grpc.max_response_message_bytes" // int32 + +struct grpc_method_config { + grpc_mdstr_hash_table* table; + grpc_mdstr* wait_for_ready_key; + grpc_mdstr* timeout_key; + grpc_mdstr* max_request_message_bytes_key; + grpc_mdstr* max_response_message_bytes_key; +}; + +grpc_method_config* grpc_method_config_create( + bool* wait_for_ready, gpr_timespec* timeout, + int32_t* max_request_message_bytes, int32_t* max_response_message_bytes) { + grpc_method_config* method_config = gpr_malloc(sizeof(grpc_method_config)); + memset(method_config, 0, sizeof(grpc_method_config)); + method_config->wait_for_ready_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_WAIT_FOR_READY); + method_config->timeout_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_TIMEOUT); + method_config->max_request_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_REQUEST_MESSAGE_BYTES); + method_config->max_response_message_bytes_key = + grpc_mdstr_from_string(GRPC_METHOD_CONFIG_MAX_RESPONSE_MESSAGE_BYTES); + grpc_mdstr_hash_table_entry entries[4]; + size_t num_entries = 0; + if (wait_for_ready != NULL) { + entries[num_entries].key = method_config->wait_for_ready_key; + entries[num_entries].value = wait_for_ready; + entries[num_entries].vtable = &bool_vtable; + ++num_entries; + } + if (timeout != NULL) { + entries[num_entries].key = method_config->timeout_key; + entries[num_entries].value = timeout; + entries[num_entries].vtable = ×pec_vtable; + ++num_entries; + } + if (max_request_message_bytes != NULL) { + entries[num_entries].key = method_config->max_request_message_bytes_key; + entries[num_entries].value = max_request_message_bytes; + entries[num_entries].vtable = &int32_vtable; + ++num_entries; + } + if (max_response_message_bytes != NULL) { + entries[num_entries].key = method_config->max_response_message_bytes_key; + entries[num_entries].value = max_response_message_bytes; + entries[num_entries].vtable = &int32_vtable; + ++num_entries; + } + method_config->table = grpc_mdstr_hash_table_create(num_entries, entries); + return method_config; +} + +grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config) { + grpc_mdstr_hash_table_ref(method_config->table); + return method_config; +} + +void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, + grpc_method_config* method_config) { + if (grpc_mdstr_hash_table_unref(exec_ctx, method_config->table)) { + GRPC_MDSTR_UNREF(exec_ctx, method_config->wait_for_ready_key); + GRPC_MDSTR_UNREF(exec_ctx, method_config->timeout_key); + GRPC_MDSTR_UNREF(exec_ctx, method_config->max_request_message_bytes_key); + GRPC_MDSTR_UNREF(exec_ctx, method_config->max_response_message_bytes_key); + gpr_free(method_config); + } +} + +int grpc_method_config_cmp(const grpc_method_config* method_config1, + const grpc_method_config* method_config2) { + return grpc_mdstr_hash_table_cmp(method_config1->table, + method_config2->table); +} + +const bool* grpc_method_config_get_wait_for_ready( + const grpc_method_config* method_config) { + return grpc_mdstr_hash_table_get(method_config->table, + method_config->wait_for_ready_key); +} + +const gpr_timespec* grpc_method_config_get_timeout( + const grpc_method_config* method_config) { + return grpc_mdstr_hash_table_get(method_config->table, + method_config->timeout_key); +} + +const int32_t* grpc_method_config_get_max_request_message_bytes( + const grpc_method_config* method_config) { + return grpc_mdstr_hash_table_get( + method_config->table, method_config->max_request_message_bytes_key); +} + +const int32_t* grpc_method_config_get_max_response_message_bytes( + const grpc_method_config* method_config) { + return grpc_mdstr_hash_table_get( + method_config->table, method_config->max_response_message_bytes_key); +} + +// +// grpc_method_config_table +// + +static void method_config_unref(grpc_exec_ctx* exec_ctx, void* valuep) { + grpc_method_config_unref(exec_ctx, valuep); +} + +static void* method_config_ref(void* valuep) { + return grpc_method_config_ref(valuep); +} + +static int method_config_cmp(void* valuep1, void* valuep2) { + return grpc_method_config_cmp(valuep1, valuep2); +} + +static const grpc_mdstr_hash_table_vtable method_config_table_vtable = { + method_config_unref, method_config_ref, method_config_cmp}; + +grpc_method_config_table* grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry* entries) { + grpc_mdstr_hash_table_entry* hash_table_entries = + gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * num_entries); + for (size_t i = 0; i < num_entries; ++i) { + hash_table_entries[i].key = entries[i].method_name; + hash_table_entries[i].value = entries[i].method_config; + hash_table_entries[i].vtable = &method_config_table_vtable; + } + grpc_method_config_table* method_config_table = + grpc_mdstr_hash_table_create(num_entries, hash_table_entries); + gpr_free(hash_table_entries); + return method_config_table; +} + +grpc_method_config_table* grpc_method_config_table_ref( + grpc_method_config_table* table) { + return grpc_mdstr_hash_table_ref(table); +} + +void grpc_method_config_table_unref(grpc_exec_ctx* exec_ctx, + grpc_method_config_table* table) { + grpc_mdstr_hash_table_unref(exec_ctx, table); +} + +int grpc_method_config_table_cmp(const grpc_method_config_table* table1, + const grpc_method_config_table* table2) { + return grpc_mdstr_hash_table_cmp(table1, table2); +} + +void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, + 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(exec_ctx, wildcard_path); + } + return value; +} + +static void* copy_arg(void* p) { return grpc_method_config_table_ref(p); } + +static void destroy_arg(grpc_exec_ctx* exec_ctx, void* p) { + grpc_method_config_table_unref(exec_ctx, p); +} + +static int cmp_arg(void* p1, void* p2) { + return grpc_method_config_table_cmp(p1, p2); +} + +static grpc_arg_pointer_vtable arg_vtable = {copy_arg, destroy_arg, cmp_arg}; + +grpc_arg grpc_method_config_table_create_channel_arg( + grpc_method_config_table* table) { + grpc_arg arg; + arg.type = GRPC_ARG_POINTER; + arg.key = GRPC_ARG_SERVICE_CONFIG; + arg.value.pointer.p = table; + arg.value.pointer.vtable = &arg_vtable; + return arg; +} + +// State used by convert_entry() below. +typedef struct conversion_state { + void* (*convert_value)(const grpc_method_config* method_config); + const grpc_mdstr_hash_table_vtable* vtable; + size_t num_entries; + grpc_mdstr_hash_table_entry* entries; +} conversion_state; + +// A function to be passed to grpc_mdstr_hash_table_iterate() to create +// a copy of the entries. +static void convert_entry(const grpc_mdstr_hash_table_entry* entry, + void* user_data) { + conversion_state* state = user_data; + state->entries[state->num_entries].key = GRPC_MDSTR_REF(entry->key); + state->entries[state->num_entries].value = state->convert_value(entry->value); + state->entries[state->num_entries].vtable = state->vtable; + ++state->num_entries; +} + +grpc_mdstr_hash_table* grpc_method_config_table_convert( + grpc_exec_ctx* exec_ctx, const grpc_method_config_table* table, + void* (*convert_value)(const grpc_method_config* method_config), + const grpc_mdstr_hash_table_vtable* vtable) { + // Create an array of the entries in the table with converted values. + conversion_state state; + state.convert_value = convert_value; + state.vtable = vtable; + state.num_entries = 0; + state.entries = gpr_malloc(sizeof(grpc_mdstr_hash_table_entry) * + grpc_mdstr_hash_table_num_entries(table)); + grpc_mdstr_hash_table_iterate(table, convert_entry, &state); + // Create a new table based on the array we just constructed. + grpc_mdstr_hash_table* new_table = + grpc_mdstr_hash_table_create(state.num_entries, state.entries); + // Clean up the array. + for (size_t i = 0; i < state.num_entries; ++i) { + GRPC_MDSTR_UNREF(exec_ctx, state.entries[i].key); + vtable->destroy_value(exec_ctx, state.entries[i].value); + } + gpr_free(state.entries); + // Return the new table. + return new_table; +} diff --git a/src/core/lib/transport/method_config.h b/src/core/lib/transport/method_config.h new file mode 100644 index 00000000000..d17a493fd4d --- /dev/null +++ b/src/core/lib/transport/method_config.h @@ -0,0 +1,139 @@ +// +// 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 +#include + +#include "src/core/lib/transport/mdstr_hash_table.h" +#include "src/core/lib/transport/metadata.h" + +/// Per-method configuration. +typedef struct grpc_method_config grpc_method_config; + +/// Creates a grpc_method_config with the specified parameters. +/// Any parameter may be NULL to indicate that the value is unset. +/// +/// \a wait_for_ready indicates whether the client should wait until the +/// request deadline for the channel to become ready, even if there is a +/// temporary failure before the deadline while attempting to connect. +/// +/// \a timeout indicates the timeout for calls. +/// +/// \a max_request_message_bytes and \a max_response_message_bytes +/// indicate the maximum sizes of the request (checked when sending) and +/// response (checked when receiving) messages. +grpc_method_config* grpc_method_config_create( + bool* wait_for_ready, gpr_timespec* timeout, + int32_t* max_request_message_bytes, int32_t* max_response_message_bytes); + +grpc_method_config* grpc_method_config_ref(grpc_method_config* method_config); +void grpc_method_config_unref(grpc_exec_ctx* exec_ctx, + grpc_method_config* method_config); + +/// Compares two grpc_method_configs. +/// The sort order is stable but undefined. +int grpc_method_config_cmp(const grpc_method_config* method_config1, + const grpc_method_config* method_config2); + +/// These methods return NULL if the requested field is unset. +/// The caller does NOT take ownership of the result. +const bool* grpc_method_config_get_wait_for_ready( + const grpc_method_config* method_config); +const gpr_timespec* grpc_method_config_get_timeout( + const grpc_method_config* method_config); +const int32_t* grpc_method_config_get_max_request_message_bytes( + const grpc_method_config* method_config); +const int32_t* grpc_method_config_get_max_response_message_bytes( + const grpc_method_config* method_config); + +/// A table of method configs. +typedef grpc_mdstr_hash_table grpc_method_config_table; + +typedef struct grpc_method_config_table_entry { + /// The name is of one of the following forms: + /// service/method -- specifies exact service and method name + /// service/* -- matches all methods for the specified service + grpc_mdstr* method_name; + grpc_method_config* method_config; +} grpc_method_config_table_entry; + +/// Takes new references to all keys and values in \a entries. +grpc_method_config_table* grpc_method_config_table_create( + size_t num_entries, grpc_method_config_table_entry* entries); + +grpc_method_config_table* grpc_method_config_table_ref( + grpc_method_config_table* table); +void grpc_method_config_table_unref(grpc_exec_ctx* exec_ctx, + grpc_method_config_table* table); + +/// Compares two grpc_method_config_tables. +/// The sort order is stable but undefined. +int grpc_method_config_table_cmp(const grpc_method_config_table* table1, + const grpc_method_config_table* table2); + +/// 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. +/// +/// Note: This returns a void* instead of a grpc_method_config* so that +/// it can also be used for tables constructed via +/// grpc_method_config_table_convert(). +void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, + const grpc_mdstr_hash_table* table, + const grpc_mdstr* path); + +/// Returns a channel arg containing \a table. +grpc_arg grpc_method_config_table_create_channel_arg( + grpc_method_config_table* table); + +/// Generates a new table from \a table whose values are converted to a +/// new form via the \a convert_value function. The new table will use +/// \a vtable for its values. +/// +/// This is generally used to convert the table's value type from +/// grpc_method_config to a simple struct containing only the parameters +/// relevant to a particular filter, thus avoiding the need for a hash +/// table lookup on the fast path. In that scenario, \a convert_value +/// will return a new instance of the struct containing the values from +/// the grpc_method_config, and \a vtable provides the methods for +/// operating on the struct type. +grpc_mdstr_hash_table* grpc_method_config_table_convert( + grpc_exec_ctx* exec_ctx, const grpc_method_config_table* table, + void* (*convert_value)(const grpc_method_config* method_config), + const grpc_mdstr_hash_table_vtable* vtable); + +#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 index 12da2a88feb..552d3ec8568 100644 --- a/src/core/lib/transport/service_config.c +++ b/src/core/lib/transport/service_config.c @@ -39,10 +39,8 @@ #include #include "src/core/lib/json/json.h" -#include "src/core/lib/slice/slice_hash_table.h" -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" +#include "src/core/lib/transport/mdstr_hash_table.h" // The main purpose of the code here is to parse the service config in // JSON form, which will look like this: @@ -150,8 +148,8 @@ static char* parse_json_method_name(grpc_json* json) { static bool parse_json_method_config( grpc_exec_ctx* exec_ctx, grpc_json* json, void* (*create_value)(const grpc_json* method_config_json), - const grpc_slice_hash_table_vtable* vtable, - grpc_slice_hash_table_entry* entries, size_t* idx) { + 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 false; @@ -172,7 +170,7 @@ static bool parse_json_method_config( 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_slice_from_copied_string(paths.strs[i]); + entries[*idx].key = grpc_mdstr_from_string(paths.strs[i]); entries[*idx].value = vtable->copy_value(method_config); entries[*idx].vtable = vtable; ++*idx; @@ -184,15 +182,15 @@ done: return success; } -grpc_slice_hash_table* grpc_service_config_create_method_config_table( +grpc_mdstr_hash_table* grpc_service_config_create_method_config_table( grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - const grpc_slice_hash_table_vtable* vtable) { + const grpc_mdstr_hash_table_vtable* vtable) { const grpc_json* json = service_config->json_tree; // Traverse parsed JSON tree. if (json->type != GRPC_JSON_OBJECT || json->key != NULL) return NULL; size_t num_entries = 0; - grpc_slice_hash_table_entry* entries = NULL; + 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, "methodConfig") == 0) { @@ -204,7 +202,7 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( num_entries += count_names_in_method_config_json(method); } // Populate method config table entries. - entries = gpr_malloc(num_entries * sizeof(grpc_slice_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) { @@ -217,12 +215,12 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( } } // Instantiate method config table. - grpc_slice_hash_table* method_config_table = NULL; + grpc_mdstr_hash_table* method_config_table = NULL; if (entries != NULL) { - method_config_table = grpc_slice_hash_table_create(num_entries, entries); + method_config_table = grpc_mdstr_hash_table_create(num_entries, entries); // Clean up. for (size_t i = 0; i < num_entries; ++i) { - grpc_slice_unref_internal(exec_ctx, entries[i].key); + GRPC_MDSTR_UNREF(exec_ctx, entries[i].key); vtable->destroy_value(exec_ctx, entries[i].value); } gpr_free(entries); @@ -231,24 +229,23 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( } void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_slice_hash_table* table, - grpc_slice path) { - void* value = grpc_slice_hash_table_get(table, path); + 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) { - char* path_str = grpc_slice_to_c_string(path); + 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_slice wildcard_path = grpc_slice_from_copied_string(buf); + grpc_mdstr* wildcard_path = grpc_mdstr_from_string(buf); gpr_free(buf); - value = grpc_slice_hash_table_get(table, wildcard_path); - grpc_slice_unref_internal(exec_ctx, wildcard_path); - gpr_free(path_str); + value = grpc_mdstr_hash_table_get(table, wildcard_path); + GRPC_MDSTR_UNREF(exec_ctx, wildcard_path); } return value; } diff --git a/src/core/lib/transport/service_config.h b/src/core/lib/transport/service_config.h index cd739a593c2..f0897170fa6 100644 --- a/src/core/lib/transport/service_config.h +++ b/src/core/lib/transport/service_config.h @@ -35,7 +35,7 @@ #include #include "src/core/lib/json/json.h" -#include "src/core/lib/slice/slice_hash_table.h" +#include "src/core/lib/transport/mdstr_hash_table.h" typedef struct grpc_service_config grpc_service_config; @@ -53,10 +53,10 @@ const char* grpc_service_config_get_lb_policy_name( /// 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_slice_hash_table* grpc_service_config_create_method_config_table( +grpc_mdstr_hash_table* grpc_service_config_create_method_config_table( grpc_exec_ctx* exec_ctx, const grpc_service_config* service_config, void* (*create_value)(const grpc_json* method_config_json), - const grpc_slice_hash_table_vtable* vtable); + const grpc_mdstr_hash_table_vtable* vtable); /// A helper function for looking up values in the table returned by /// \a grpc_service_config_create_method_config_table(). @@ -65,7 +65,7 @@ grpc_slice_hash_table* grpc_service_config_create_method_config_table( /// Returns NULL if the method has no config. /// Caller does NOT own a reference to the result. void* grpc_method_config_table_get(grpc_exec_ctx* exec_ctx, - const grpc_slice_hash_table* table, - grpc_slice path); + const grpc_mdstr_hash_table* table, + const grpc_mdstr* path); #endif /* GRPC_CORE_LIB_TRANSPORT_SERVICE_CONFIG_H */ diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 5adc3216c98..8b22592b45d 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -41,770 +41,120 @@ #include "src/core/lib/transport/static_metadata.h" -#include "src/core/lib/slice/slice_internal.h" - -static uint8_t g_bytes[] = { - 58, 112, 97, 116, 104, 58, 109, 101, 116, 104, 111, 100, 58, 115, 116, - 97, 116, 117, 115, 58, 97, 117, 116, 104, 111, 114, 105, 116, 121, 58, - 115, 99, 104, 101, 109, 101, 116, 101, 103, 114, 112, 99, 45, 109, 101, - 115, 115, 97, 103, 101, 103, 114, 112, 99, 45, 115, 116, 97, 116, 117, - 115, 103, 114, 112, 99, 45, 112, 97, 121, 108, 111, 97, 100, 45, 98, - 105, 110, 103, 114, 112, 99, 45, 101, 110, 99, 111, 100, 105, 110, 103, - 103, 114, 112, 99, 45, 97, 99, 99, 101, 112, 116, 45, 101, 110, 99, - 111, 100, 105, 110, 103, 99, 111, 110, 116, 101, 110, 116, 45, 116, 121, - 112, 101, 103, 114, 112, 99, 45, 105, 110, 116, 101, 114, 110, 97, 108, - 45, 101, 110, 99, 111, 100, 105, 110, 103, 45, 114, 101, 113, 117, 101, - 115, 116, 117, 115, 101, 114, 45, 97, 103, 101, 110, 116, 104, 111, 115, - 116, 108, 98, 45, 116, 111, 107, 101, 110, 108, 98, 45, 99, 111, 115, - 116, 45, 98, 105, 110, 103, 114, 112, 99, 45, 116, 105, 109, 101, 111, - 117, 116, 103, 114, 112, 99, 45, 116, 114, 97, 99, 105, 110, 103, 45, - 98, 105, 110, 103, 114, 112, 99, 45, 115, 116, 97, 116, 115, 45, 98, - 105, 110, 103, 114, 112, 99, 46, 119, 97, 105, 116, 95, 102, 111, 114, - 95, 114, 101, 97, 100, 121, 103, 114, 112, 99, 46, 116, 105, 109, 101, - 111, 117, 116, 103, 114, 112, 99, 46, 109, 97, 120, 95, 114, 101, 113, - 117, 101, 115, 116, 95, 109, 101, 115, 115, 97, 103, 101, 95, 98, 121, - 116, 101, 115, 103, 114, 112, 99, 46, 109, 97, 120, 95, 114, 101, 115, - 112, 111, 110, 115, 101, 95, 109, 101, 115, 115, 97, 103, 101, 95, 98, - 121, 116, 101, 115, 47, 103, 114, 112, 99, 46, 108, 98, 46, 118, 49, - 46, 76, 111, 97, 100, 66, 97, 108, 97, 110, 99, 101, 114, 47, 66, - 97, 108, 97, 110, 99, 101, 76, 111, 97, 100, 48, 49, 50, 105, 100, - 101, 110, 116, 105, 116, 121, 103, 122, 105, 112, 100, 101, 102, 108, 97, - 116, 101, 116, 114, 97, 105, 108, 101, 114, 115, 97, 112, 112, 108, 105, - 99, 97, 116, 105, 111, 110, 47, 103, 114, 112, 99, 80, 79, 83, 84, - 50, 48, 48, 52, 48, 52, 104, 116, 116, 112, 104, 116, 116, 112, 115, - 103, 114, 112, 99, 71, 69, 84, 80, 85, 84, 47, 47, 105, 110, 100, - 101, 120, 46, 104, 116, 109, 108, 50, 48, 52, 50, 48, 54, 51, 48, - 52, 52, 48, 48, 53, 48, 48, 97, 99, 99, 101, 112, 116, 45, 99, - 104, 97, 114, 115, 101, 116, 97, 99, 99, 101, 112, 116, 45, 101, 110, - 99, 111, 100, 105, 110, 103, 103, 122, 105, 112, 44, 32, 100, 101, 102, - 108, 97, 116, 101, 97, 99, 99, 101, 112, 116, 45, 108, 97, 110, 103, - 117, 97, 103, 101, 97, 99, 99, 101, 112, 116, 45, 114, 97, 110, 103, - 101, 115, 97, 99, 99, 101, 112, 116, 97, 99, 99, 101, 115, 115, 45, - 99, 111, 110, 116, 114, 111, 108, 45, 97, 108, 108, 111, 119, 45, 111, - 114, 105, 103, 105, 110, 97, 103, 101, 97, 108, 108, 111, 119, 97, 117, - 116, 104, 111, 114, 105, 122, 97, 116, 105, 111, 110, 99, 97, 99, 104, - 101, 45, 99, 111, 110, 116, 114, 111, 108, 99, 111, 110, 116, 101, 110, - 116, 45, 100, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 99, 111, - 110, 116, 101, 110, 116, 45, 101, 110, 99, 111, 100, 105, 110, 103, 99, - 111, 110, 116, 101, 110, 116, 45, 108, 97, 110, 103, 117, 97, 103, 101, - 99, 111, 110, 116, 101, 110, 116, 45, 108, 101, 110, 103, 116, 104, 99, - 111, 110, 116, 101, 110, 116, 45, 108, 111, 99, 97, 116, 105, 111, 110, - 99, 111, 110, 116, 101, 110, 116, 45, 114, 97, 110, 103, 101, 99, 111, - 111, 107, 105, 101, 100, 97, 116, 101, 101, 116, 97, 103, 101, 120, 112, - 101, 99, 116, 101, 120, 112, 105, 114, 101, 115, 102, 114, 111, 109, 105, - 102, 45, 109, 97, 116, 99, 104, 105, 102, 45, 109, 111, 100, 105, 102, - 105, 101, 100, 45, 115, 105, 110, 99, 101, 105, 102, 45, 110, 111, 110, - 101, 45, 109, 97, 116, 99, 104, 105, 102, 45, 114, 97, 110, 103, 101, - 105, 102, 45, 117, 110, 109, 111, 100, 105, 102, 105, 101, 100, 45, 115, - 105, 110, 99, 101, 108, 97, 115, 116, 45, 109, 111, 100, 105, 102, 105, - 101, 100, 108, 105, 110, 107, 108, 111, 99, 97, 116, 105, 111, 110, 109, - 97, 120, 45, 102, 111, 114, 119, 97, 114, 100, 115, 112, 114, 111, 120, - 121, 45, 97, 117, 116, 104, 101, 110, 116, 105, 99, 97, 116, 101, 112, - 114, 111, 120, 121, 45, 97, 117, 116, 104, 111, 114, 105, 122, 97, 116, - 105, 111, 110, 114, 97, 110, 103, 101, 114, 101, 102, 101, 114, 101, 114, - 114, 101, 102, 114, 101, 115, 104, 114, 101, 116, 114, 121, 45, 97, 102, - 116, 101, 114, 115, 101, 114, 118, 101, 114, 115, 101, 116, 45, 99, 111, - 111, 107, 105, 101, 115, 116, 114, 105, 99, 116, 45, 116, 114, 97, 110, - 115, 112, 111, 114, 116, 45, 115, 101, 99, 117, 114, 105, 116, 121, 116, - 114, 97, 110, 115, 102, 101, 114, 45, 101, 110, 99, 111, 100, 105, 110, - 103, 118, 97, 114, 121, 118, 105, 97, 119, 119, 119, 45, 97, 117, 116, - 104, 101, 110, 116, 105, 99, 97, 116, 101, 105, 100, 101, 110, 116, 105, - 116, 121, 44, 100, 101, 102, 108, 97, 116, 101, 105, 100, 101, 110, 116, - 105, 116, 121, 44, 103, 122, 105, 112, 100, 101, 102, 108, 97, 116, 101, - 44, 103, 122, 105, 112, 105, 100, 101, 110, 116, 105, 116, 121, 44, 100, - 101, 102, 108, 97, 116, 101, 44, 103, 122, 105, 112}; - -static void static_ref(void *unused) {} -static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {} -static const grpc_slice_refcount_vtable static_sub_vtable = { - static_ref, static_unref, grpc_slice_default_eq_impl, - grpc_slice_default_hash_impl}; -const grpc_slice_refcount_vtable grpc_static_metadata_vtable = { - static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash}; -static grpc_slice_refcount static_sub_refcnt = {&static_sub_vtable, - &static_sub_refcnt}; -grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = { - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, - {&grpc_static_metadata_vtable, &static_sub_refcnt}, -}; - -const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = { - {.refcount = &grpc_static_metadata_refcounts[0], - .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &grpc_static_metadata_refcounts[1], - .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[3], - .data.refcounted = {g_bytes + 19, 10}}, - {.refcount = &grpc_static_metadata_refcounts[4], - .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &grpc_static_metadata_refcounts[5], - .data.refcounted = {g_bytes + 36, 2}}, - {.refcount = &grpc_static_metadata_refcounts[6], - .data.refcounted = {g_bytes + 38, 12}}, - {.refcount = &grpc_static_metadata_refcounts[7], - .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &grpc_static_metadata_refcounts[8], - .data.refcounted = {g_bytes + 61, 16}}, - {.refcount = &grpc_static_metadata_refcounts[9], - .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[11], - .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &grpc_static_metadata_refcounts[12], - .data.refcounted = {g_bytes + 122, 30}}, - {.refcount = &grpc_static_metadata_refcounts[13], - .data.refcounted = {g_bytes + 152, 10}}, - {.refcount = &grpc_static_metadata_refcounts[14], - .data.refcounted = {g_bytes + 162, 4}}, - {.refcount = &grpc_static_metadata_refcounts[15], - .data.refcounted = {g_bytes + 166, 8}}, - {.refcount = &grpc_static_metadata_refcounts[16], - .data.refcounted = {g_bytes + 174, 11}}, - {.refcount = &grpc_static_metadata_refcounts[17], - .data.refcounted = {g_bytes + 185, 12}}, - {.refcount = &grpc_static_metadata_refcounts[18], - .data.refcounted = {g_bytes + 197, 16}}, - {.refcount = &grpc_static_metadata_refcounts[19], - .data.refcounted = {g_bytes + 213, 14}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}, - {.refcount = &grpc_static_metadata_refcounts[21], - .data.refcounted = {g_bytes + 227, 19}}, - {.refcount = &grpc_static_metadata_refcounts[22], - .data.refcounted = {g_bytes + 246, 12}}, - {.refcount = &grpc_static_metadata_refcounts[23], - .data.refcounted = {g_bytes + 258, 30}}, - {.refcount = &grpc_static_metadata_refcounts[24], - .data.refcounted = {g_bytes + 288, 31}}, - {.refcount = &grpc_static_metadata_refcounts[25], - .data.refcounted = {g_bytes + 319, 36}}, - {.refcount = &grpc_static_metadata_refcounts[26], - .data.refcounted = {g_bytes + 355, 1}}, - {.refcount = &grpc_static_metadata_refcounts[27], - .data.refcounted = {g_bytes + 356, 1}}, - {.refcount = &grpc_static_metadata_refcounts[28], - .data.refcounted = {g_bytes + 357, 1}}, - {.refcount = &grpc_static_metadata_refcounts[29], - .data.refcounted = {g_bytes + 358, 8}}, - {.refcount = &grpc_static_metadata_refcounts[30], - .data.refcounted = {g_bytes + 366, 4}}, - {.refcount = &grpc_static_metadata_refcounts[31], - .data.refcounted = {g_bytes + 370, 7}}, - {.refcount = &grpc_static_metadata_refcounts[32], - .data.refcounted = {g_bytes + 377, 8}}, - {.refcount = &grpc_static_metadata_refcounts[33], - .data.refcounted = {g_bytes + 385, 16}}, - {.refcount = &grpc_static_metadata_refcounts[34], - .data.refcounted = {g_bytes + 401, 4}}, - {.refcount = &grpc_static_metadata_refcounts[35], - .data.refcounted = {g_bytes + 405, 3}}, - {.refcount = &grpc_static_metadata_refcounts[36], - .data.refcounted = {g_bytes + 408, 3}}, - {.refcount = &grpc_static_metadata_refcounts[37], - .data.refcounted = {g_bytes + 411, 4}}, - {.refcount = &grpc_static_metadata_refcounts[38], - .data.refcounted = {g_bytes + 415, 5}}, - {.refcount = &grpc_static_metadata_refcounts[39], - .data.refcounted = {g_bytes + 420, 4}}, - {.refcount = &grpc_static_metadata_refcounts[40], - .data.refcounted = {g_bytes + 424, 3}}, - {.refcount = &grpc_static_metadata_refcounts[41], - .data.refcounted = {g_bytes + 427, 3}}, - {.refcount = &grpc_static_metadata_refcounts[42], - .data.refcounted = {g_bytes + 430, 1}}, - {.refcount = &grpc_static_metadata_refcounts[43], - .data.refcounted = {g_bytes + 431, 11}}, - {.refcount = &grpc_static_metadata_refcounts[44], - .data.refcounted = {g_bytes + 442, 3}}, - {.refcount = &grpc_static_metadata_refcounts[45], - .data.refcounted = {g_bytes + 445, 3}}, - {.refcount = &grpc_static_metadata_refcounts[46], - .data.refcounted = {g_bytes + 448, 3}}, - {.refcount = &grpc_static_metadata_refcounts[47], - .data.refcounted = {g_bytes + 451, 3}}, - {.refcount = &grpc_static_metadata_refcounts[48], - .data.refcounted = {g_bytes + 454, 3}}, - {.refcount = &grpc_static_metadata_refcounts[49], - .data.refcounted = {g_bytes + 457, 14}}, - {.refcount = &grpc_static_metadata_refcounts[50], - .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &grpc_static_metadata_refcounts[51], - .data.refcounted = {g_bytes + 486, 13}}, - {.refcount = &grpc_static_metadata_refcounts[52], - .data.refcounted = {g_bytes + 499, 15}}, - {.refcount = &grpc_static_metadata_refcounts[53], - .data.refcounted = {g_bytes + 514, 13}}, - {.refcount = &grpc_static_metadata_refcounts[54], - .data.refcounted = {g_bytes + 527, 6}}, - {.refcount = &grpc_static_metadata_refcounts[55], - .data.refcounted = {g_bytes + 533, 27}}, - {.refcount = &grpc_static_metadata_refcounts[56], - .data.refcounted = {g_bytes + 560, 3}}, - {.refcount = &grpc_static_metadata_refcounts[57], - .data.refcounted = {g_bytes + 563, 5}}, - {.refcount = &grpc_static_metadata_refcounts[58], - .data.refcounted = {g_bytes + 568, 13}}, - {.refcount = &grpc_static_metadata_refcounts[59], - .data.refcounted = {g_bytes + 581, 13}}, - {.refcount = &grpc_static_metadata_refcounts[60], - .data.refcounted = {g_bytes + 594, 19}}, - {.refcount = &grpc_static_metadata_refcounts[61], - .data.refcounted = {g_bytes + 613, 16}}, - {.refcount = &grpc_static_metadata_refcounts[62], - .data.refcounted = {g_bytes + 629, 16}}, - {.refcount = &grpc_static_metadata_refcounts[63], - .data.refcounted = {g_bytes + 645, 14}}, - {.refcount = &grpc_static_metadata_refcounts[64], - .data.refcounted = {g_bytes + 659, 16}}, - {.refcount = &grpc_static_metadata_refcounts[65], - .data.refcounted = {g_bytes + 675, 13}}, - {.refcount = &grpc_static_metadata_refcounts[66], - .data.refcounted = {g_bytes + 688, 6}}, - {.refcount = &grpc_static_metadata_refcounts[67], - .data.refcounted = {g_bytes + 694, 4}}, - {.refcount = &grpc_static_metadata_refcounts[68], - .data.refcounted = {g_bytes + 698, 4}}, - {.refcount = &grpc_static_metadata_refcounts[69], - .data.refcounted = {g_bytes + 702, 6}}, - {.refcount = &grpc_static_metadata_refcounts[70], - .data.refcounted = {g_bytes + 708, 7}}, - {.refcount = &grpc_static_metadata_refcounts[71], - .data.refcounted = {g_bytes + 715, 4}}, - {.refcount = &grpc_static_metadata_refcounts[72], - .data.refcounted = {g_bytes + 719, 8}}, - {.refcount = &grpc_static_metadata_refcounts[73], - .data.refcounted = {g_bytes + 727, 17}}, - {.refcount = &grpc_static_metadata_refcounts[74], - .data.refcounted = {g_bytes + 744, 13}}, - {.refcount = &grpc_static_metadata_refcounts[75], - .data.refcounted = {g_bytes + 757, 8}}, - {.refcount = &grpc_static_metadata_refcounts[76], - .data.refcounted = {g_bytes + 765, 19}}, - {.refcount = &grpc_static_metadata_refcounts[77], - .data.refcounted = {g_bytes + 784, 13}}, - {.refcount = &grpc_static_metadata_refcounts[78], - .data.refcounted = {g_bytes + 797, 4}}, - {.refcount = &grpc_static_metadata_refcounts[79], - .data.refcounted = {g_bytes + 801, 8}}, - {.refcount = &grpc_static_metadata_refcounts[80], - .data.refcounted = {g_bytes + 809, 12}}, - {.refcount = &grpc_static_metadata_refcounts[81], - .data.refcounted = {g_bytes + 821, 18}}, - {.refcount = &grpc_static_metadata_refcounts[82], - .data.refcounted = {g_bytes + 839, 19}}, - {.refcount = &grpc_static_metadata_refcounts[83], - .data.refcounted = {g_bytes + 858, 5}}, - {.refcount = &grpc_static_metadata_refcounts[84], - .data.refcounted = {g_bytes + 863, 7}}, - {.refcount = &grpc_static_metadata_refcounts[85], - .data.refcounted = {g_bytes + 870, 7}}, - {.refcount = &grpc_static_metadata_refcounts[86], - .data.refcounted = {g_bytes + 877, 11}}, - {.refcount = &grpc_static_metadata_refcounts[87], - .data.refcounted = {g_bytes + 888, 6}}, - {.refcount = &grpc_static_metadata_refcounts[88], - .data.refcounted = {g_bytes + 894, 10}}, - {.refcount = &grpc_static_metadata_refcounts[89], - .data.refcounted = {g_bytes + 904, 25}}, - {.refcount = &grpc_static_metadata_refcounts[90], - .data.refcounted = {g_bytes + 929, 17}}, - {.refcount = &grpc_static_metadata_refcounts[91], - .data.refcounted = {g_bytes + 946, 4}}, - {.refcount = &grpc_static_metadata_refcounts[92], - .data.refcounted = {g_bytes + 950, 3}}, - {.refcount = &grpc_static_metadata_refcounts[93], - .data.refcounted = {g_bytes + 953, 16}}, - {.refcount = &grpc_static_metadata_refcounts[94], - .data.refcounted = {g_bytes + 969, 16}}, - {.refcount = &grpc_static_metadata_refcounts[95], - .data.refcounted = {g_bytes + 985, 13}}, - {.refcount = &grpc_static_metadata_refcounts[96], - .data.refcounted = {g_bytes + 998, 12}}, - {.refcount = &grpc_static_metadata_refcounts[97], - .data.refcounted = {g_bytes + 1010, 21}}, -}; +grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; +grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 4, 8, 6, 2, 4, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 4, 6, 6, 8, 8}; - -static const int8_t elems_r[] = { - 10, 8, -3, 0, 9, 21, -76, 22, 0, 10, -7, 20, 0, 19, 18, 17, - 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, -49, -50, 16, -52, -53, -54, -54, -55, -56, -57, 0, 38, 37, 36, 35, - 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, - 18, 17, 16, 15, 14, 13, 12, 15, 14, 13, 12, 11, 10, 9, 8, 0}; -static uint32_t elems_phash(uint32_t i) { - i -= 42; - uint32_t x = i % 96; - uint32_t y = i / 96; - uint32_t h = x; - if (y < GPR_ARRAY_SIZE(elems_r)) { - uint32_t delta = (uint32_t)elems_r[y]; - h += delta; - } - return h; -} + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; -static const uint16_t elem_keys[] = { - 1009, 1010, 1011, 240, 241, 242, 243, 244, 138, 139, 42, 43, - 429, 430, 431, 911, 912, 913, 712, 713, 1098, 522, 714, 1294, - 1392, 1490, 1588, 4822, 4920, 4951, 5116, 5214, 5312, 1111, 5410, 5508, - 5606, 5704, 5802, 5900, 5998, 6096, 6194, 6292, 6390, 6488, 6586, 6684, - 6782, 6880, 6978, 7076, 7174, 7272, 7370, 7468, 7566, 7664, 7762, 7860, - 7958, 8056, 8154, 8252, 8350, 1074, 1075, 1076, 1077, 8448, 8546, 8644, - 8742, 8840, 8938, 9036, 9134, 314, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 132, 231, 232, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0}; -static const uint8_t elem_idxs[] = { - 74, 77, 75, 19, 20, 21, 22, 23, 15, 16, 17, 18, 11, 12, 13, - 3, 4, 5, 0, 1, 41, 6, 2, 70, 48, 55, 56, 24, 25, 26, - 27, 28, 29, 7, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 57, 58, 59, - 60, 61, 62, 63, 64, 76, 78, 79, 80, 65, 66, 67, 68, 69, 71, - 72, 73, 14, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 8, 9, 10}; +const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = + {11, 33, 10, 33, 12, 33, 12, 50, 13, 33, 14, 33, 15, 33, 16, 33, 17, 33, + 19, 33, 20, 33, 21, 33, 22, 33, 23, 33, 24, 33, 25, 33, 26, 33, 27, 33, + 28, 18, 28, 33, 29, 33, 30, 33, 34, 33, 35, 33, 36, 33, 37, 33, 40, 31, + 40, 32, 40, 49, 40, 54, 40, 55, 40, 56, 40, 57, 41, 31, 41, 49, 41, 54, + 46, 0, 46, 1, 46, 2, 51, 33, 58, 33, 59, 33, 60, 33, 61, 33, 62, 33, + 63, 33, 64, 33, 65, 33, 66, 33, 67, 33, 68, 33, 69, 38, 69, 71, 69, 74, + 70, 82, 70, 83, 72, 33, 73, 33, 75, 33, 76, 33, 77, 33, 78, 33, 79, 39, + 79, 52, 79, 53, 80, 33, 81, 33, 84, 3, 84, 4, 84, 5, 84, 6, 84, 7, + 84, 8, 84, 9, 85, 33, 86, 87, 88, 33, 89, 33, 90, 33, 91, 33, 92, 33}; -grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) { - if (a == -1 || b == -1) return GRPC_MDNULL; - uint32_t k = (uint32_t)(a * 98 + b); - uint32_t h = elems_phash(k); - return elem_keys[h] == k - ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]], - GRPC_MDELEM_STORAGE_STATIC) - : GRPC_MDNULL; -} +const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { + "0", + "1", + "2", + "200", + "204", + "206", + "304", + "400", + "404", + "500", + "accept", + "accept-charset", + "accept-encoding", + "accept-language", + "accept-ranges", + "access-control-allow-origin", + "age", + "allow", + "application/grpc", + ":authority", + "authorization", + "cache-control", + "content-disposition", + "content-encoding", + "content-language", + "content-length", + "content-location", + "content-range", + "content-type", + "cookie", + "date", + "deflate", + "deflate,gzip", + "", + "etag", + "expect", + "expires", + "from", + "GET", + "grpc", + "grpc-accept-encoding", + "grpc-encoding", + "grpc-internal-encoding-request", + "grpc-message", + "grpc-payload-bin", + "grpc-stats-bin", + "grpc-status", + "grpc-timeout", + "grpc-tracing-bin", + "gzip", + "gzip, deflate", + "host", + "http", + "https", + "identity", + "identity,deflate", + "identity,deflate,gzip", + "identity,gzip", + "if-match", + "if-modified-since", + "if-none-match", + "if-range", + "if-unmodified-since", + "last-modified", + "lb-cost-bin", + "lb-token", + "link", + "location", + "max-forwards", + ":method", + ":path", + "POST", + "proxy-authenticate", + "proxy-authorization", + "PUT", + "range", + "referer", + "refresh", + "retry-after", + ":scheme", + "server", + "set-cookie", + "/", + "/index.html", + ":status", + "strict-transport-security", + "te", + "trailers", + "transfer-encoding", + "user-agent", + "vary", + "via", + "www-authenticate"}; -grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = { - {{.refcount = &grpc_static_metadata_refcounts[7], - .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &grpc_static_metadata_refcounts[26], - .data.refcounted = {g_bytes + 355, 1}}}, - {{.refcount = &grpc_static_metadata_refcounts[7], - .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &grpc_static_metadata_refcounts[27], - .data.refcounted = {g_bytes + 356, 1}}}, - {{.refcount = &grpc_static_metadata_refcounts[7], - .data.refcounted = {g_bytes + 50, 11}}, - {.refcount = &grpc_static_metadata_refcounts[28], - .data.refcounted = {g_bytes + 357, 1}}}, - {{.refcount = &grpc_static_metadata_refcounts[9], - .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &grpc_static_metadata_refcounts[29], - .data.refcounted = {g_bytes + 358, 8}}}, - {{.refcount = &grpc_static_metadata_refcounts[9], - .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &grpc_static_metadata_refcounts[30], - .data.refcounted = {g_bytes + 366, 4}}}, - {{.refcount = &grpc_static_metadata_refcounts[9], - .data.refcounted = {g_bytes + 77, 13}}, - {.refcount = &grpc_static_metadata_refcounts[31], - .data.refcounted = {g_bytes + 370, 7}}}, - {{.refcount = &grpc_static_metadata_refcounts[5], - .data.refcounted = {g_bytes + 36, 2}}, - {.refcount = &grpc_static_metadata_refcounts[32], - .data.refcounted = {g_bytes + 377, 8}}}, - {{.refcount = &grpc_static_metadata_refcounts[11], - .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &grpc_static_metadata_refcounts[33], - .data.refcounted = {g_bytes + 385, 16}}}, - {{.refcount = &grpc_static_metadata_refcounts[1], - .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &grpc_static_metadata_refcounts[34], - .data.refcounted = {g_bytes + 401, 4}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[35], - .data.refcounted = {g_bytes + 405, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[36], - .data.refcounted = {g_bytes + 408, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[4], - .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &grpc_static_metadata_refcounts[37], - .data.refcounted = {g_bytes + 411, 4}}}, - {{.refcount = &grpc_static_metadata_refcounts[4], - .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &grpc_static_metadata_refcounts[38], - .data.refcounted = {g_bytes + 415, 5}}}, - {{.refcount = &grpc_static_metadata_refcounts[4], - .data.refcounted = {g_bytes + 29, 7}}, - {.refcount = &grpc_static_metadata_refcounts[39], - .data.refcounted = {g_bytes + 420, 4}}}, - {{.refcount = &grpc_static_metadata_refcounts[3], - .data.refcounted = {g_bytes + 19, 10}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[1], - .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &grpc_static_metadata_refcounts[40], - .data.refcounted = {g_bytes + 424, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[1], - .data.refcounted = {g_bytes + 5, 7}}, - {.refcount = &grpc_static_metadata_refcounts[41], - .data.refcounted = {g_bytes + 427, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[0], - .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &grpc_static_metadata_refcounts[42], - .data.refcounted = {g_bytes + 430, 1}}}, - {{.refcount = &grpc_static_metadata_refcounts[0], - .data.refcounted = {g_bytes + 0, 5}}, - {.refcount = &grpc_static_metadata_refcounts[43], - .data.refcounted = {g_bytes + 431, 11}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[44], - .data.refcounted = {g_bytes + 442, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[45], - .data.refcounted = {g_bytes + 445, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[46], - .data.refcounted = {g_bytes + 448, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[47], - .data.refcounted = {g_bytes + 451, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[2], - .data.refcounted = {g_bytes + 12, 7}}, - {.refcount = &grpc_static_metadata_refcounts[48], - .data.refcounted = {g_bytes + 454, 3}}}, - {{.refcount = &grpc_static_metadata_refcounts[49], - .data.refcounted = {g_bytes + 457, 14}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[50], - .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[50], - .data.refcounted = {g_bytes + 471, 15}}, - {.refcount = &grpc_static_metadata_refcounts[51], - .data.refcounted = {g_bytes + 486, 13}}}, - {{.refcount = &grpc_static_metadata_refcounts[52], - .data.refcounted = {g_bytes + 499, 15}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[53], - .data.refcounted = {g_bytes + 514, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[54], - .data.refcounted = {g_bytes + 527, 6}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[55], - .data.refcounted = {g_bytes + 533, 27}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[56], - .data.refcounted = {g_bytes + 560, 3}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[57], - .data.refcounted = {g_bytes + 563, 5}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[58], - .data.refcounted = {g_bytes + 568, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[59], - .data.refcounted = {g_bytes + 581, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[60], - .data.refcounted = {g_bytes + 594, 19}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[61], - .data.refcounted = {g_bytes + 613, 16}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[62], - .data.refcounted = {g_bytes + 629, 16}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[63], - .data.refcounted = {g_bytes + 645, 14}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[64], - .data.refcounted = {g_bytes + 659, 16}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[65], - .data.refcounted = {g_bytes + 675, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[11], - .data.refcounted = {g_bytes + 110, 12}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[66], - .data.refcounted = {g_bytes + 688, 6}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[67], - .data.refcounted = {g_bytes + 694, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[68], - .data.refcounted = {g_bytes + 698, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[69], - .data.refcounted = {g_bytes + 702, 6}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[70], - .data.refcounted = {g_bytes + 708, 7}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[71], - .data.refcounted = {g_bytes + 715, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[14], - .data.refcounted = {g_bytes + 162, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[72], - .data.refcounted = {g_bytes + 719, 8}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[73], - .data.refcounted = {g_bytes + 727, 17}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[74], - .data.refcounted = {g_bytes + 744, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[75], - .data.refcounted = {g_bytes + 757, 8}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[76], - .data.refcounted = {g_bytes + 765, 19}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[77], - .data.refcounted = {g_bytes + 784, 13}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[15], - .data.refcounted = {g_bytes + 166, 8}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[16], - .data.refcounted = {g_bytes + 174, 11}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[78], - .data.refcounted = {g_bytes + 797, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[79], - .data.refcounted = {g_bytes + 801, 8}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[80], - .data.refcounted = {g_bytes + 809, 12}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[81], - .data.refcounted = {g_bytes + 821, 18}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[82], - .data.refcounted = {g_bytes + 839, 19}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[83], - .data.refcounted = {g_bytes + 858, 5}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[84], - .data.refcounted = {g_bytes + 863, 7}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[85], - .data.refcounted = {g_bytes + 870, 7}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[86], - .data.refcounted = {g_bytes + 877, 11}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[87], - .data.refcounted = {g_bytes + 888, 6}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[88], - .data.refcounted = {g_bytes + 894, 10}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[89], - .data.refcounted = {g_bytes + 904, 25}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[90], - .data.refcounted = {g_bytes + 929, 17}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[13], - .data.refcounted = {g_bytes + 152, 10}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[91], - .data.refcounted = {g_bytes + 946, 4}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[92], - .data.refcounted = {g_bytes + 950, 3}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[93], - .data.refcounted = {g_bytes + 953, 16}}, - {.refcount = &grpc_static_metadata_refcounts[20], - .data.refcounted = {g_bytes + 227, 0}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[29], - .data.refcounted = {g_bytes + 358, 8}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[31], - .data.refcounted = {g_bytes + 370, 7}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[94], - .data.refcounted = {g_bytes + 969, 16}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[30], - .data.refcounted = {g_bytes + 366, 4}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[95], - .data.refcounted = {g_bytes + 985, 13}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[96], - .data.refcounted = {g_bytes + 998, 12}}}, - {{.refcount = &grpc_static_metadata_refcounts[10], - .data.refcounted = {g_bytes + 90, 20}}, - {.refcount = &grpc_static_metadata_refcounts[97], - .data.refcounted = {g_bytes + 1010, 21}}}, -}; -const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 74, 75, 76, - 77, 78, 79, 80}; +const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 29, 26, 30, + 28, 32, 27, 31}; diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index 7649ccd5d2d..28ad6f2961a 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -44,521 +44,375 @@ #include "src/core/lib/transport/metadata.h" -#define GRPC_STATIC_MDSTR_COUNT 98 -extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT]; -/* ":path" */ -#define GRPC_MDSTR_PATH (grpc_static_slice_table[0]) -/* ":method" */ -#define GRPC_MDSTR_METHOD (grpc_static_slice_table[1]) -/* ":status" */ -#define GRPC_MDSTR_STATUS (grpc_static_slice_table[2]) -/* ":authority" */ -#define GRPC_MDSTR_AUTHORITY (grpc_static_slice_table[3]) -/* ":scheme" */ -#define GRPC_MDSTR_SCHEME (grpc_static_slice_table[4]) -/* "te" */ -#define GRPC_MDSTR_TE (grpc_static_slice_table[5]) -/* "grpc-message" */ -#define GRPC_MDSTR_GRPC_MESSAGE (grpc_static_slice_table[6]) -/* "grpc-status" */ -#define GRPC_MDSTR_GRPC_STATUS (grpc_static_slice_table[7]) -/* "grpc-payload-bin" */ -#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (grpc_static_slice_table[8]) -/* "grpc-encoding" */ -#define GRPC_MDSTR_GRPC_ENCODING (grpc_static_slice_table[9]) -/* "grpc-accept-encoding" */ -#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (grpc_static_slice_table[10]) -/* "content-type" */ -#define GRPC_MDSTR_CONTENT_TYPE (grpc_static_slice_table[11]) -/* "grpc-internal-encoding-request" */ -#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (grpc_static_slice_table[12]) -/* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (grpc_static_slice_table[13]) -/* "host" */ -#define GRPC_MDSTR_HOST (grpc_static_slice_table[14]) -/* "lb-token" */ -#define GRPC_MDSTR_LB_TOKEN (grpc_static_slice_table[15]) -/* "lb-cost-bin" */ -#define GRPC_MDSTR_LB_COST_BIN (grpc_static_slice_table[16]) -/* "grpc-timeout" */ -#define GRPC_MDSTR_GRPC_TIMEOUT (grpc_static_slice_table[17]) -/* "grpc-tracing-bin" */ -#define GRPC_MDSTR_GRPC_TRACING_BIN (grpc_static_slice_table[18]) -/* "grpc-stats-bin" */ -#define GRPC_MDSTR_GRPC_STATS_BIN (grpc_static_slice_table[19]) -/* "" */ -#define GRPC_MDSTR_EMPTY (grpc_static_slice_table[20]) -/* "grpc.wait_for_ready" */ -#define GRPC_MDSTR_GRPC_DOT_WAIT_FOR_READY (grpc_static_slice_table[21]) -/* "grpc.timeout" */ -#define GRPC_MDSTR_GRPC_DOT_TIMEOUT (grpc_static_slice_table[22]) -/* "grpc.max_request_message_bytes" */ -#define GRPC_MDSTR_GRPC_DOT_MAX_REQUEST_MESSAGE_BYTES \ - (grpc_static_slice_table[23]) -/* "grpc.max_response_message_bytes" */ -#define GRPC_MDSTR_GRPC_DOT_MAX_RESPONSE_MESSAGE_BYTES \ - (grpc_static_slice_table[24]) -/* "/grpc.lb.v1.LoadBalancer/BalanceLoad" */ -#define GRPC_MDSTR_SLASH_GRPC_DOT_LB_DOT_V1_DOT_LOADBALANCER_SLASH_BALANCELOAD \ - (grpc_static_slice_table[25]) +#define GRPC_STATIC_MDSTR_COUNT 93 +extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ -#define GRPC_MDSTR_0 (grpc_static_slice_table[26]) +#define GRPC_MDSTR_0 (&grpc_static_mdstr_table[0]) /* "1" */ -#define GRPC_MDSTR_1 (grpc_static_slice_table[27]) +#define GRPC_MDSTR_1 (&grpc_static_mdstr_table[1]) /* "2" */ -#define GRPC_MDSTR_2 (grpc_static_slice_table[28]) -/* "identity" */ -#define GRPC_MDSTR_IDENTITY (grpc_static_slice_table[29]) -/* "gzip" */ -#define GRPC_MDSTR_GZIP (grpc_static_slice_table[30]) -/* "deflate" */ -#define GRPC_MDSTR_DEFLATE (grpc_static_slice_table[31]) -/* "trailers" */ -#define GRPC_MDSTR_TRAILERS (grpc_static_slice_table[32]) -/* "application/grpc" */ -#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (grpc_static_slice_table[33]) -/* "POST" */ -#define GRPC_MDSTR_POST (grpc_static_slice_table[34]) +#define GRPC_MDSTR_2 (&grpc_static_mdstr_table[2]) /* "200" */ -#define GRPC_MDSTR_200 (grpc_static_slice_table[35]) -/* "404" */ -#define GRPC_MDSTR_404 (grpc_static_slice_table[36]) -/* "http" */ -#define GRPC_MDSTR_HTTP (grpc_static_slice_table[37]) -/* "https" */ -#define GRPC_MDSTR_HTTPS (grpc_static_slice_table[38]) -/* "grpc" */ -#define GRPC_MDSTR_GRPC (grpc_static_slice_table[39]) -/* "GET" */ -#define GRPC_MDSTR_GET (grpc_static_slice_table[40]) -/* "PUT" */ -#define GRPC_MDSTR_PUT (grpc_static_slice_table[41]) -/* "/" */ -#define GRPC_MDSTR_SLASH (grpc_static_slice_table[42]) -/* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (grpc_static_slice_table[43]) +#define GRPC_MDSTR_200 (&grpc_static_mdstr_table[3]) /* "204" */ -#define GRPC_MDSTR_204 (grpc_static_slice_table[44]) +#define GRPC_MDSTR_204 (&grpc_static_mdstr_table[4]) /* "206" */ -#define GRPC_MDSTR_206 (grpc_static_slice_table[45]) +#define GRPC_MDSTR_206 (&grpc_static_mdstr_table[5]) /* "304" */ -#define GRPC_MDSTR_304 (grpc_static_slice_table[46]) +#define GRPC_MDSTR_304 (&grpc_static_mdstr_table[6]) /* "400" */ -#define GRPC_MDSTR_400 (grpc_static_slice_table[47]) +#define GRPC_MDSTR_400 (&grpc_static_mdstr_table[7]) +/* "404" */ +#define GRPC_MDSTR_404 (&grpc_static_mdstr_table[8]) /* "500" */ -#define GRPC_MDSTR_500 (grpc_static_slice_table[48]) +#define GRPC_MDSTR_500 (&grpc_static_mdstr_table[9]) +/* "accept" */ +#define GRPC_MDSTR_ACCEPT (&grpc_static_mdstr_table[10]) /* "accept-charset" */ -#define GRPC_MDSTR_ACCEPT_CHARSET (grpc_static_slice_table[49]) +#define GRPC_MDSTR_ACCEPT_CHARSET (&grpc_static_mdstr_table[11]) /* "accept-encoding" */ -#define GRPC_MDSTR_ACCEPT_ENCODING (grpc_static_slice_table[50]) -/* "gzip, deflate" */ -#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (grpc_static_slice_table[51]) +#define GRPC_MDSTR_ACCEPT_ENCODING (&grpc_static_mdstr_table[12]) /* "accept-language" */ -#define GRPC_MDSTR_ACCEPT_LANGUAGE (grpc_static_slice_table[52]) +#define GRPC_MDSTR_ACCEPT_LANGUAGE (&grpc_static_mdstr_table[13]) /* "accept-ranges" */ -#define GRPC_MDSTR_ACCEPT_RANGES (grpc_static_slice_table[53]) -/* "accept" */ -#define GRPC_MDSTR_ACCEPT (grpc_static_slice_table[54]) +#define GRPC_MDSTR_ACCEPT_RANGES (&grpc_static_mdstr_table[14]) /* "access-control-allow-origin" */ -#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (grpc_static_slice_table[55]) +#define GRPC_MDSTR_ACCESS_CONTROL_ALLOW_ORIGIN (&grpc_static_mdstr_table[15]) /* "age" */ -#define GRPC_MDSTR_AGE (grpc_static_slice_table[56]) +#define GRPC_MDSTR_AGE (&grpc_static_mdstr_table[16]) /* "allow" */ -#define GRPC_MDSTR_ALLOW (grpc_static_slice_table[57]) +#define GRPC_MDSTR_ALLOW (&grpc_static_mdstr_table[17]) +/* "application/grpc" */ +#define GRPC_MDSTR_APPLICATION_SLASH_GRPC (&grpc_static_mdstr_table[18]) +/* ":authority" */ +#define GRPC_MDSTR_AUTHORITY (&grpc_static_mdstr_table[19]) /* "authorization" */ -#define GRPC_MDSTR_AUTHORIZATION (grpc_static_slice_table[58]) +#define GRPC_MDSTR_AUTHORIZATION (&grpc_static_mdstr_table[20]) /* "cache-control" */ -#define GRPC_MDSTR_CACHE_CONTROL (grpc_static_slice_table[59]) +#define GRPC_MDSTR_CACHE_CONTROL (&grpc_static_mdstr_table[21]) /* "content-disposition" */ -#define GRPC_MDSTR_CONTENT_DISPOSITION (grpc_static_slice_table[60]) +#define GRPC_MDSTR_CONTENT_DISPOSITION (&grpc_static_mdstr_table[22]) /* "content-encoding" */ -#define GRPC_MDSTR_CONTENT_ENCODING (grpc_static_slice_table[61]) +#define GRPC_MDSTR_CONTENT_ENCODING (&grpc_static_mdstr_table[23]) /* "content-language" */ -#define GRPC_MDSTR_CONTENT_LANGUAGE (grpc_static_slice_table[62]) +#define GRPC_MDSTR_CONTENT_LANGUAGE (&grpc_static_mdstr_table[24]) /* "content-length" */ -#define GRPC_MDSTR_CONTENT_LENGTH (grpc_static_slice_table[63]) +#define GRPC_MDSTR_CONTENT_LENGTH (&grpc_static_mdstr_table[25]) /* "content-location" */ -#define GRPC_MDSTR_CONTENT_LOCATION (grpc_static_slice_table[64]) +#define GRPC_MDSTR_CONTENT_LOCATION (&grpc_static_mdstr_table[26]) /* "content-range" */ -#define GRPC_MDSTR_CONTENT_RANGE (grpc_static_slice_table[65]) +#define GRPC_MDSTR_CONTENT_RANGE (&grpc_static_mdstr_table[27]) +/* "content-type" */ +#define GRPC_MDSTR_CONTENT_TYPE (&grpc_static_mdstr_table[28]) /* "cookie" */ -#define GRPC_MDSTR_COOKIE (grpc_static_slice_table[66]) +#define GRPC_MDSTR_COOKIE (&grpc_static_mdstr_table[29]) /* "date" */ -#define GRPC_MDSTR_DATE (grpc_static_slice_table[67]) +#define GRPC_MDSTR_DATE (&grpc_static_mdstr_table[30]) +/* "deflate" */ +#define GRPC_MDSTR_DEFLATE (&grpc_static_mdstr_table[31]) +/* "deflate,gzip" */ +#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (&grpc_static_mdstr_table[32]) +/* "" */ +#define GRPC_MDSTR_EMPTY (&grpc_static_mdstr_table[33]) /* "etag" */ -#define GRPC_MDSTR_ETAG (grpc_static_slice_table[68]) +#define GRPC_MDSTR_ETAG (&grpc_static_mdstr_table[34]) /* "expect" */ -#define GRPC_MDSTR_EXPECT (grpc_static_slice_table[69]) +#define GRPC_MDSTR_EXPECT (&grpc_static_mdstr_table[35]) /* "expires" */ -#define GRPC_MDSTR_EXPIRES (grpc_static_slice_table[70]) +#define GRPC_MDSTR_EXPIRES (&grpc_static_mdstr_table[36]) /* "from" */ -#define GRPC_MDSTR_FROM (grpc_static_slice_table[71]) +#define GRPC_MDSTR_FROM (&grpc_static_mdstr_table[37]) +/* "GET" */ +#define GRPC_MDSTR_GET (&grpc_static_mdstr_table[38]) +/* "grpc" */ +#define GRPC_MDSTR_GRPC (&grpc_static_mdstr_table[39]) +/* "grpc-accept-encoding" */ +#define GRPC_MDSTR_GRPC_ACCEPT_ENCODING (&grpc_static_mdstr_table[40]) +/* "grpc-encoding" */ +#define GRPC_MDSTR_GRPC_ENCODING (&grpc_static_mdstr_table[41]) +/* "grpc-internal-encoding-request" */ +#define GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST (&grpc_static_mdstr_table[42]) +/* "grpc-message" */ +#define GRPC_MDSTR_GRPC_MESSAGE (&grpc_static_mdstr_table[43]) +/* "grpc-payload-bin" */ +#define GRPC_MDSTR_GRPC_PAYLOAD_BIN (&grpc_static_mdstr_table[44]) +/* "grpc-stats-bin" */ +#define GRPC_MDSTR_GRPC_STATS_BIN (&grpc_static_mdstr_table[45]) +/* "grpc-status" */ +#define GRPC_MDSTR_GRPC_STATUS (&grpc_static_mdstr_table[46]) +/* "grpc-timeout" */ +#define GRPC_MDSTR_GRPC_TIMEOUT (&grpc_static_mdstr_table[47]) +/* "grpc-tracing-bin" */ +#define GRPC_MDSTR_GRPC_TRACING_BIN (&grpc_static_mdstr_table[48]) +/* "gzip" */ +#define GRPC_MDSTR_GZIP (&grpc_static_mdstr_table[49]) +/* "gzip, deflate" */ +#define GRPC_MDSTR_GZIP_COMMA_DEFLATE (&grpc_static_mdstr_table[50]) +/* "host" */ +#define GRPC_MDSTR_HOST (&grpc_static_mdstr_table[51]) +/* "http" */ +#define GRPC_MDSTR_HTTP (&grpc_static_mdstr_table[52]) +/* "https" */ +#define GRPC_MDSTR_HTTPS (&grpc_static_mdstr_table[53]) +/* "identity" */ +#define GRPC_MDSTR_IDENTITY (&grpc_static_mdstr_table[54]) +/* "identity,deflate" */ +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (&grpc_static_mdstr_table[55]) +/* "identity,deflate,gzip" */ +#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ + (&grpc_static_mdstr_table[56]) +/* "identity,gzip" */ +#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (&grpc_static_mdstr_table[57]) /* "if-match" */ -#define GRPC_MDSTR_IF_MATCH (grpc_static_slice_table[72]) +#define GRPC_MDSTR_IF_MATCH (&grpc_static_mdstr_table[58]) /* "if-modified-since" */ -#define GRPC_MDSTR_IF_MODIFIED_SINCE (grpc_static_slice_table[73]) +#define GRPC_MDSTR_IF_MODIFIED_SINCE (&grpc_static_mdstr_table[59]) /* "if-none-match" */ -#define GRPC_MDSTR_IF_NONE_MATCH (grpc_static_slice_table[74]) +#define GRPC_MDSTR_IF_NONE_MATCH (&grpc_static_mdstr_table[60]) /* "if-range" */ -#define GRPC_MDSTR_IF_RANGE (grpc_static_slice_table[75]) +#define GRPC_MDSTR_IF_RANGE (&grpc_static_mdstr_table[61]) /* "if-unmodified-since" */ -#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (grpc_static_slice_table[76]) +#define GRPC_MDSTR_IF_UNMODIFIED_SINCE (&grpc_static_mdstr_table[62]) /* "last-modified" */ -#define GRPC_MDSTR_LAST_MODIFIED (grpc_static_slice_table[77]) +#define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_mdstr_table[63]) +/* "lb-cost-bin" */ +#define GRPC_MDSTR_LB_COST_BIN (&grpc_static_mdstr_table[64]) +/* "lb-token" */ +#define GRPC_MDSTR_LB_TOKEN (&grpc_static_mdstr_table[65]) /* "link" */ -#define GRPC_MDSTR_LINK (grpc_static_slice_table[78]) +#define GRPC_MDSTR_LINK (&grpc_static_mdstr_table[66]) /* "location" */ -#define GRPC_MDSTR_LOCATION (grpc_static_slice_table[79]) +#define GRPC_MDSTR_LOCATION (&grpc_static_mdstr_table[67]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (grpc_static_slice_table[80]) +#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_mdstr_table[68]) +/* ":method" */ +#define GRPC_MDSTR_METHOD (&grpc_static_mdstr_table[69]) +/* ":path" */ +#define GRPC_MDSTR_PATH (&grpc_static_mdstr_table[70]) +/* "POST" */ +#define GRPC_MDSTR_POST (&grpc_static_mdstr_table[71]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (grpc_static_slice_table[81]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_mdstr_table[72]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (grpc_static_slice_table[82]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_mdstr_table[73]) +/* "PUT" */ +#define GRPC_MDSTR_PUT (&grpc_static_mdstr_table[74]) /* "range" */ -#define GRPC_MDSTR_RANGE (grpc_static_slice_table[83]) +#define GRPC_MDSTR_RANGE (&grpc_static_mdstr_table[75]) /* "referer" */ -#define GRPC_MDSTR_REFERER (grpc_static_slice_table[84]) +#define GRPC_MDSTR_REFERER (&grpc_static_mdstr_table[76]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (grpc_static_slice_table[85]) +#define GRPC_MDSTR_REFRESH (&grpc_static_mdstr_table[77]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (grpc_static_slice_table[86]) +#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_mdstr_table[78]) +/* ":scheme" */ +#define GRPC_MDSTR_SCHEME (&grpc_static_mdstr_table[79]) /* "server" */ -#define GRPC_MDSTR_SERVER (grpc_static_slice_table[87]) +#define GRPC_MDSTR_SERVER (&grpc_static_mdstr_table[80]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (grpc_static_slice_table[88]) +#define GRPC_MDSTR_SET_COOKIE (&grpc_static_mdstr_table[81]) +/* "/" */ +#define GRPC_MDSTR_SLASH (&grpc_static_mdstr_table[82]) +/* "/index.html" */ +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_mdstr_table[83]) +/* ":status" */ +#define GRPC_MDSTR_STATUS (&grpc_static_mdstr_table[84]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (grpc_static_slice_table[89]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_mdstr_table[85]) +/* "te" */ +#define GRPC_MDSTR_TE (&grpc_static_mdstr_table[86]) +/* "trailers" */ +#define GRPC_MDSTR_TRAILERS (&grpc_static_mdstr_table[87]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (grpc_static_slice_table[90]) +#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_mdstr_table[88]) +/* "user-agent" */ +#define GRPC_MDSTR_USER_AGENT (&grpc_static_mdstr_table[89]) /* "vary" */ -#define GRPC_MDSTR_VARY (grpc_static_slice_table[91]) +#define GRPC_MDSTR_VARY (&grpc_static_mdstr_table[90]) /* "via" */ -#define GRPC_MDSTR_VIA (grpc_static_slice_table[92]) +#define GRPC_MDSTR_VIA (&grpc_static_mdstr_table[91]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (grpc_static_slice_table[93]) -/* "identity,deflate" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE (grpc_static_slice_table[94]) -/* "identity,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_GZIP (grpc_static_slice_table[95]) -/* "deflate,gzip" */ -#define GRPC_MDSTR_DEFLATE_COMMA_GZIP (grpc_static_slice_table[96]) -/* "identity,deflate,gzip" */ -#define GRPC_MDSTR_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (grpc_static_slice_table[97]) - -extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable; -extern grpc_slice_refcount - grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT]; -#define GRPC_IS_STATIC_METADATA_STRING(slice) \ - ((slice).refcount != NULL && \ - (slice).refcount->vtable == &grpc_static_metadata_vtable) - -#define GRPC_STATIC_METADATA_INDEX(static_slice) \ - ((int)((static_slice).refcount - grpc_static_metadata_refcounts)) +#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_mdstr_table[92]) #define GRPC_STATIC_MDELEM_COUNT 81 -extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; +extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; -/* "grpc-status": "0" */ -#define GRPC_MDELEM_GRPC_STATUS_0 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[0], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-status": "1" */ -#define GRPC_MDELEM_GRPC_STATUS_1 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[1], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-status": "2" */ -#define GRPC_MDELEM_GRPC_STATUS_2 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[2], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[3], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ENCODING_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[4], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[5], GRPC_MDELEM_STORAGE_STATIC)) -/* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[6], GRPC_MDELEM_STORAGE_STATIC)) -/* "content-type": "application/grpc" */ -#define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[7], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[8], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[9], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[10], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[11], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[12], GRPC_MDELEM_STORAGE_STATIC)) -/* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[13], GRPC_MDELEM_STORAGE_STATIC)) -/* ":authority": "" */ -#define GRPC_MDELEM_AUTHORITY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[14], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[15], GRPC_MDELEM_STORAGE_STATIC)) -/* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[16], GRPC_MDELEM_STORAGE_STATIC)) -/* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[17], GRPC_MDELEM_STORAGE_STATIC)) -/* ":path": "/index.html" */ -#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[18], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[19], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[20], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[21], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[22], GRPC_MDELEM_STORAGE_STATIC)) -/* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[23], GRPC_MDELEM_STORAGE_STATIC)) /* "accept-charset": "" */ -#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[24], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_CHARSET_EMPTY (&grpc_static_mdelem_table[0]) +/* "accept": "" */ +#define GRPC_MDELEM_ACCEPT_EMPTY (&grpc_static_mdelem_table[1]) /* "accept-encoding": "" */ -#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[25], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_ENCODING_EMPTY (&grpc_static_mdelem_table[2]) /* "accept-encoding": "gzip, deflate" */ #define GRPC_MDELEM_ACCEPT_ENCODING_GZIP_COMMA_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[26], GRPC_MDELEM_STORAGE_STATIC)) + (&grpc_static_mdelem_table[3]) /* "accept-language": "" */ -#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[27], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[4]) /* "accept-ranges": "" */ -#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[28], GRPC_MDELEM_STORAGE_STATIC)) -/* "accept": "" */ -#define GRPC_MDELEM_ACCEPT_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[29], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_RANGES_EMPTY (&grpc_static_mdelem_table[5]) /* "access-control-allow-origin": "" */ #define GRPC_MDELEM_ACCESS_CONTROL_ALLOW_ORIGIN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[30], GRPC_MDELEM_STORAGE_STATIC)) + (&grpc_static_mdelem_table[6]) /* "age": "" */ -#define GRPC_MDELEM_AGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[31], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_AGE_EMPTY (&grpc_static_mdelem_table[7]) /* "allow": "" */ -#define GRPC_MDELEM_ALLOW_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[32], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ALLOW_EMPTY (&grpc_static_mdelem_table[8]) +/* ":authority": "" */ +#define GRPC_MDELEM_AUTHORITY_EMPTY (&grpc_static_mdelem_table[9]) /* "authorization": "" */ -#define GRPC_MDELEM_AUTHORIZATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[33], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[10]) /* "cache-control": "" */ -#define GRPC_MDELEM_CACHE_CONTROL_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[34], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CACHE_CONTROL_EMPTY (&grpc_static_mdelem_table[11]) /* "content-disposition": "" */ -#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[35], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_DISPOSITION_EMPTY (&grpc_static_mdelem_table[12]) /* "content-encoding": "" */ -#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[36], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_ENCODING_EMPTY (&grpc_static_mdelem_table[13]) /* "content-language": "" */ -#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[37], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_LANGUAGE_EMPTY (&grpc_static_mdelem_table[14]) /* "content-length": "" */ -#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[38], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_LENGTH_EMPTY (&grpc_static_mdelem_table[15]) /* "content-location": "" */ -#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[39], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_LOCATION_EMPTY (&grpc_static_mdelem_table[16]) /* "content-range": "" */ -#define GRPC_MDELEM_CONTENT_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[40], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_RANGE_EMPTY (&grpc_static_mdelem_table[17]) +/* "content-type": "application/grpc" */ +#define GRPC_MDELEM_CONTENT_TYPE_APPLICATION_SLASH_GRPC \ + (&grpc_static_mdelem_table[18]) /* "content-type": "" */ -#define GRPC_MDELEM_CONTENT_TYPE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[41], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_CONTENT_TYPE_EMPTY (&grpc_static_mdelem_table[19]) /* "cookie": "" */ -#define GRPC_MDELEM_COOKIE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[42], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_COOKIE_EMPTY (&grpc_static_mdelem_table[20]) /* "date": "" */ -#define GRPC_MDELEM_DATE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[43], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_DATE_EMPTY (&grpc_static_mdelem_table[21]) /* "etag": "" */ -#define GRPC_MDELEM_ETAG_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[44], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ETAG_EMPTY (&grpc_static_mdelem_table[22]) /* "expect": "" */ -#define GRPC_MDELEM_EXPECT_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[45], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_EXPECT_EMPTY (&grpc_static_mdelem_table[23]) /* "expires": "" */ -#define GRPC_MDELEM_EXPIRES_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[46], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_EXPIRES_EMPTY (&grpc_static_mdelem_table[24]) /* "from": "" */ -#define GRPC_MDELEM_FROM_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[47], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_FROM_EMPTY (&grpc_static_mdelem_table[25]) +/* "grpc-accept-encoding": "deflate" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE (&grpc_static_mdelem_table[26]) +/* "grpc-accept-encoding": "deflate,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ + (&grpc_static_mdelem_table[27]) +/* "grpc-accept-encoding": "gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP (&grpc_static_mdelem_table[28]) +/* "grpc-accept-encoding": "identity" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ + (&grpc_static_mdelem_table[29]) +/* "grpc-accept-encoding": "identity,deflate" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ + (&grpc_static_mdelem_table[30]) +/* "grpc-accept-encoding": "identity,deflate,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ + (&grpc_static_mdelem_table[31]) +/* "grpc-accept-encoding": "identity,gzip" */ +#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ + (&grpc_static_mdelem_table[32]) +/* "grpc-encoding": "deflate" */ +#define GRPC_MDELEM_GRPC_ENCODING_DEFLATE (&grpc_static_mdelem_table[33]) +/* "grpc-encoding": "gzip" */ +#define GRPC_MDELEM_GRPC_ENCODING_GZIP (&grpc_static_mdelem_table[34]) +/* "grpc-encoding": "identity" */ +#define GRPC_MDELEM_GRPC_ENCODING_IDENTITY (&grpc_static_mdelem_table[35]) +/* "grpc-status": "0" */ +#define GRPC_MDELEM_GRPC_STATUS_0 (&grpc_static_mdelem_table[36]) +/* "grpc-status": "1" */ +#define GRPC_MDELEM_GRPC_STATUS_1 (&grpc_static_mdelem_table[37]) +/* "grpc-status": "2" */ +#define GRPC_MDELEM_GRPC_STATUS_2 (&grpc_static_mdelem_table[38]) /* "host": "" */ -#define GRPC_MDELEM_HOST_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[48], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_HOST_EMPTY (&grpc_static_mdelem_table[39]) /* "if-match": "" */ -#define GRPC_MDELEM_IF_MATCH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[49], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_IF_MATCH_EMPTY (&grpc_static_mdelem_table[40]) /* "if-modified-since": "" */ -#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[50], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_IF_MODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[41]) /* "if-none-match": "" */ -#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[51], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_IF_NONE_MATCH_EMPTY (&grpc_static_mdelem_table[42]) /* "if-range": "" */ -#define GRPC_MDELEM_IF_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[52], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_IF_RANGE_EMPTY (&grpc_static_mdelem_table[43]) /* "if-unmodified-since": "" */ -#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[53], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_IF_UNMODIFIED_SINCE_EMPTY (&grpc_static_mdelem_table[44]) /* "last-modified": "" */ -#define GRPC_MDELEM_LAST_MODIFIED_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[54], GRPC_MDELEM_STORAGE_STATIC)) -/* "lb-token": "" */ -#define GRPC_MDELEM_LB_TOKEN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[55], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_LAST_MODIFIED_EMPTY (&grpc_static_mdelem_table[45]) /* "lb-cost-bin": "" */ -#define GRPC_MDELEM_LB_COST_BIN_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[56], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_LB_COST_BIN_EMPTY (&grpc_static_mdelem_table[46]) +/* "lb-token": "" */ +#define GRPC_MDELEM_LB_TOKEN_EMPTY (&grpc_static_mdelem_table[47]) /* "link": "" */ -#define GRPC_MDELEM_LINK_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[57], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_LINK_EMPTY (&grpc_static_mdelem_table[48]) /* "location": "" */ -#define GRPC_MDELEM_LOCATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[58], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_LOCATION_EMPTY (&grpc_static_mdelem_table[49]) /* "max-forwards": "" */ -#define GRPC_MDELEM_MAX_FORWARDS_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[59], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (&grpc_static_mdelem_table[50]) +/* ":method": "GET" */ +#define GRPC_MDELEM_METHOD_GET (&grpc_static_mdelem_table[51]) +/* ":method": "POST" */ +#define GRPC_MDELEM_METHOD_POST (&grpc_static_mdelem_table[52]) +/* ":method": "PUT" */ +#define GRPC_MDELEM_METHOD_PUT (&grpc_static_mdelem_table[53]) +/* ":path": "/" */ +#define GRPC_MDELEM_PATH_SLASH (&grpc_static_mdelem_table[54]) +/* ":path": "/index.html" */ +#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (&grpc_static_mdelem_table[55]) /* "proxy-authenticate": "" */ -#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[60], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[56]) /* "proxy-authorization": "" */ -#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[61], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[57]) /* "range": "" */ -#define GRPC_MDELEM_RANGE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[62], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_RANGE_EMPTY (&grpc_static_mdelem_table[58]) /* "referer": "" */ -#define GRPC_MDELEM_REFERER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[63], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_REFERER_EMPTY (&grpc_static_mdelem_table[59]) /* "refresh": "" */ -#define GRPC_MDELEM_REFRESH_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[64], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_REFRESH_EMPTY (&grpc_static_mdelem_table[60]) /* "retry-after": "" */ -#define GRPC_MDELEM_RETRY_AFTER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[65], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_RETRY_AFTER_EMPTY (&grpc_static_mdelem_table[61]) +/* ":scheme": "grpc" */ +#define GRPC_MDELEM_SCHEME_GRPC (&grpc_static_mdelem_table[62]) +/* ":scheme": "http" */ +#define GRPC_MDELEM_SCHEME_HTTP (&grpc_static_mdelem_table[63]) +/* ":scheme": "https" */ +#define GRPC_MDELEM_SCHEME_HTTPS (&grpc_static_mdelem_table[64]) /* "server": "" */ -#define GRPC_MDELEM_SERVER_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[66], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_SERVER_EMPTY (&grpc_static_mdelem_table[65]) /* "set-cookie": "" */ -#define GRPC_MDELEM_SET_COOKIE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[67], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_SET_COOKIE_EMPTY (&grpc_static_mdelem_table[66]) +/* ":status": "200" */ +#define GRPC_MDELEM_STATUS_200 (&grpc_static_mdelem_table[67]) +/* ":status": "204" */ +#define GRPC_MDELEM_STATUS_204 (&grpc_static_mdelem_table[68]) +/* ":status": "206" */ +#define GRPC_MDELEM_STATUS_206 (&grpc_static_mdelem_table[69]) +/* ":status": "304" */ +#define GRPC_MDELEM_STATUS_304 (&grpc_static_mdelem_table[70]) +/* ":status": "400" */ +#define GRPC_MDELEM_STATUS_400 (&grpc_static_mdelem_table[71]) +/* ":status": "404" */ +#define GRPC_MDELEM_STATUS_404 (&grpc_static_mdelem_table[72]) +/* ":status": "500" */ +#define GRPC_MDELEM_STATUS_500 (&grpc_static_mdelem_table[73]) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[68], GRPC_MDELEM_STORAGE_STATIC)) + (&grpc_static_mdelem_table[74]) +/* "te": "trailers" */ +#define GRPC_MDELEM_TE_TRAILERS (&grpc_static_mdelem_table[75]) /* "transfer-encoding": "" */ -#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[69], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (&grpc_static_mdelem_table[76]) /* "user-agent": "" */ -#define GRPC_MDELEM_USER_AGENT_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[70], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_USER_AGENT_EMPTY (&grpc_static_mdelem_table[77]) /* "vary": "" */ -#define GRPC_MDELEM_VARY_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[71], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_VARY_EMPTY (&grpc_static_mdelem_table[78]) /* "via": "" */ -#define GRPC_MDELEM_VIA_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[72], GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_VIA_EMPTY (&grpc_static_mdelem_table[79]) /* "www-authenticate": "" */ -#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[73], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[74], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "deflate" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[75], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,deflate" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[76], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[77], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[78], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "deflate,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_DEFLATE_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[79], GRPC_MDELEM_STORAGE_STATIC)) -/* "grpc-accept-encoding": "identity,deflate,gzip" */ -#define GRPC_MDELEM_GRPC_ACCEPT_ENCODING_IDENTITY_COMMA_DEFLATE_COMMA_GZIP \ - (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[80], GRPC_MDELEM_STORAGE_STATIC)) - -grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b); -typedef enum { - GRPC_BATCH_PATH, - GRPC_BATCH_METHOD, - GRPC_BATCH_STATUS, - GRPC_BATCH_AUTHORITY, - GRPC_BATCH_SCHEME, - GRPC_BATCH_TE, - GRPC_BATCH_GRPC_MESSAGE, - GRPC_BATCH_GRPC_STATUS, - GRPC_BATCH_GRPC_PAYLOAD_BIN, - GRPC_BATCH_GRPC_ENCODING, - GRPC_BATCH_GRPC_ACCEPT_ENCODING, - GRPC_BATCH_CONTENT_TYPE, - GRPC_BATCH_GRPC_INTERNAL_ENCODING_REQUEST, - GRPC_BATCH_USER_AGENT, - GRPC_BATCH_HOST, - GRPC_BATCH_LB_TOKEN, - GRPC_BATCH_LB_COST_BIN, - GRPC_BATCH_CALLOUTS_COUNT -} grpc_metadata_batch_callouts_index; - -typedef union { - struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT]; - struct { - struct grpc_linked_mdelem *path; - struct grpc_linked_mdelem *method; - struct grpc_linked_mdelem *status; - struct grpc_linked_mdelem *authority; - struct grpc_linked_mdelem *scheme; - struct grpc_linked_mdelem *te; - struct grpc_linked_mdelem *grpc_message; - struct grpc_linked_mdelem *grpc_status; - struct grpc_linked_mdelem *grpc_payload_bin; - struct grpc_linked_mdelem *grpc_encoding; - struct grpc_linked_mdelem *grpc_accept_encoding; - struct grpc_linked_mdelem *content_type; - struct grpc_linked_mdelem *grpc_internal_encoding_request; - struct grpc_linked_mdelem *user_agent; - struct grpc_linked_mdelem *host; - struct grpc_linked_mdelem *lb_token; - struct grpc_linked_mdelem *lb_cost_bin; - } named; -} grpc_metadata_batch_callouts; - -#define GRPC_BATCH_INDEX_OF(slice) \ - (GRPC_IS_STATIC_METADATA_STRING((slice)) \ - ? (grpc_metadata_batch_callouts_index)GPR_CLAMP( \ - GRPC_STATIC_METADATA_INDEX((slice)), 0, \ - GRPC_BATCH_CALLOUTS_COUNT) \ - : GRPC_BATCH_CALLOUTS_COUNT) +#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[80]) +extern const uint8_t + grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2]; +extern const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT]; extern const uint8_t grpc_static_accept_encoding_metadata[8]; -#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ - (GRPC_MAKE_MDELEM( \ - &grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]], \ - GRPC_MDELEM_STORAGE_STATIC)) +#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ + (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]]) #endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */ diff --git a/src/core/lib/transport/timeout_encoding.c b/src/core/lib/transport/timeout_encoding.c index 0d4d7e5a7e3..b58ebbd0a8f 100644 --- a/src/core/lib/transport/timeout_encoding.c +++ b/src/core/lib/transport/timeout_encoding.c @@ -131,21 +131,20 @@ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer) { } } -static int is_all_whitespace(const char *p, const char *end) { - while (p != end && *p == ' ') p++; - return p == end; +static int is_all_whitespace(const char *p) { + while (*p == ' ') p++; + return *p == 0; } -int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) { +int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout) { int32_t x = 0; - const uint8_t *p = GRPC_SLICE_START_PTR(text); - const uint8_t *end = GRPC_SLICE_END_PTR(text); + const uint8_t *p = (const uint8_t *)buffer; int have_digit = 0; /* skip whitespace */ - for (; p != end && *p == ' '; p++) + for (; *p == ' '; p++) ; /* decode numeric part */ - for (; p != end && *p >= '0' && *p <= '9'; p++) { + for (; *p >= '0' && *p <= '9'; p++) { int32_t digit = (int32_t)(*p - (uint8_t)'0'); have_digit = 1; /* spec allows max. 8 digits, but we allow values up to 1,000,000,000 */ @@ -159,9 +158,8 @@ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) { } if (!have_digit) return 0; /* skip whitespace */ - for (; p != end && *p == ' '; p++) + for (; *p == ' '; p++) ; - if (p == end) return 0; /* decode unit specifier */ switch (*p) { case 'n': @@ -186,5 +184,5 @@ int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout) { return 0; } p++; - return is_all_whitespace((const char *)p, (const char *)end); + return is_all_whitespace((const char *)p); } diff --git a/src/core/lib/transport/timeout_encoding.h b/src/core/lib/transport/timeout_encoding.h index 4c8025d800f..92f02f6ecd1 100644 --- a/src/core/lib/transport/timeout_encoding.h +++ b/src/core/lib/transport/timeout_encoding.h @@ -34,9 +34,7 @@ #ifndef GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H #define GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H -#include #include - #include "src/core/lib/support/string.h" #define GRPC_HTTP2_TIMEOUT_ENCODE_MIN_BUFSIZE (GPR_LTOA_MIN_BUFSIZE + 1) @@ -44,6 +42,6 @@ /* Encode/decode timeouts to the GRPC over HTTP/2 format; encoding may round up arbitrarily */ void grpc_http2_encode_timeout(gpr_timespec timeout, char *buffer); -int grpc_http2_decode_timeout(grpc_slice text, gpr_timespec *timeout); +int grpc_http2_decode_timeout(const char *buffer, gpr_timespec *timeout); #endif /* GRPC_CORE_LIB_TRANSPORT_TIMEOUT_ENCODING_H */ diff --git a/src/core/lib/transport/transport.c b/src/core/lib/transport/transport.c index 004e748f251..055edbb39fc 100644 --- a/src/core/lib/transport/transport.c +++ b/src/core/lib/transport/transport.c @@ -40,7 +40,6 @@ #include #include -#include "src/core/lib/iomgr/executor.h" #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/slice/slice_string_helpers.h" #include "src/core/lib/support/string.h" @@ -70,16 +69,6 @@ void grpc_stream_unref(grpc_exec_ctx *exec_ctx, grpc_stream_refcount *refcount) { #endif if (gpr_unref(&refcount->refs)) { - if (exec_ctx->flags & GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP) { - /* Ick. - The thread we're running on MAY be owned (indirectly) by a call-stack. - If that's the case, destroying the call-stack MAY try to destroy the - thread, which is a tangled mess that we just don't want to ever have to - cope with. - Throw this over to the executor (on a core-owned thread) and process it - there. */ - refcount->destroy.scheduler = grpc_executor_scheduler; - } grpc_closure_sched(exec_ctx, &refcount->destroy, GRPC_ERROR_NONE); } } @@ -184,7 +173,93 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, grpc_closure_sched(exec_ctx, op->recv_initial_metadata_ready, GRPC_ERROR_REF(error)); grpc_closure_sched(exec_ctx, op->on_complete, error); - GRPC_ERROR_UNREF(op->cancel_error); +} + +typedef struct { + grpc_error *error; + grpc_closure *then_call; + grpc_closure closure; +} close_message_data; + +static void free_message(grpc_exec_ctx *exec_ctx, void *p, grpc_error *error) { + close_message_data *cmd = p; + GRPC_ERROR_UNREF(cmd->error); + if (cmd->then_call != NULL) { + cmd->then_call->cb(exec_ctx, cmd->then_call->cb_arg, error); + } + gpr_free(cmd); +} + +static void add_error(grpc_transport_stream_op *op, grpc_error **which, + grpc_error *error) { + close_message_data *cmd; + cmd = gpr_malloc(sizeof(*cmd)); + cmd->error = error; + cmd->then_call = op->on_complete; + grpc_closure_init(&cmd->closure, free_message, cmd, + grpc_schedule_on_exec_ctx); + op->on_complete = &cmd->closure; + *which = error; +} + +void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, + grpc_status_code status) { + GPR_ASSERT(status != GRPC_STATUS_OK); + if (op->cancel_error == GRPC_ERROR_NONE) { + op->cancel_error = grpc_error_set_int(GRPC_ERROR_CANCELLED, + GRPC_ERROR_INT_GRPC_STATUS, status); + op->close_error = GRPC_ERROR_NONE; + } +} + +void grpc_transport_stream_op_add_cancellation_with_message( + grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, + grpc_status_code status, grpc_slice *optional_message) { + GPR_ASSERT(status != GRPC_STATUS_OK); + if (op->cancel_error != GRPC_ERROR_NONE) { + if (optional_message) { + grpc_slice_unref_internal(exec_ctx, *optional_message); + } + return; + } + grpc_error *error; + if (optional_message != NULL) { + char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII); + error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), + GRPC_ERROR_STR_GRPC_MESSAGE, msg); + gpr_free(msg); + grpc_slice_unref_internal(exec_ctx, *optional_message); + } else { + error = GRPC_ERROR_CREATE("Call cancelled"); + } + error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status); + add_error(op, &op->cancel_error, error); +} + +void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx, + grpc_transport_stream_op *op, + grpc_status_code status, + grpc_slice *optional_message) { + GPR_ASSERT(status != GRPC_STATUS_OK); + if (op->cancel_error != GRPC_ERROR_NONE || + op->close_error != GRPC_ERROR_NONE) { + if (optional_message) { + grpc_slice_unref_internal(exec_ctx, *optional_message); + } + return; + } + grpc_error *error; + if (optional_message != NULL) { + char *msg = grpc_dump_slice(*optional_message, GPR_DUMP_ASCII); + error = grpc_error_set_str(GRPC_ERROR_CREATE(msg), + GRPC_ERROR_STR_GRPC_MESSAGE, msg); + gpr_free(msg); + grpc_slice_unref_internal(exec_ctx, *optional_message); + } else { + error = GRPC_ERROR_CREATE("Call force closed"); + } + error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS, status); + add_error(op, &op->close_error, error); } typedef struct { diff --git a/src/core/lib/transport/transport.h b/src/core/lib/transport/transport.h index 9a0abe1ca46..d1281830aa0 100644 --- a/src/core/lib/transport/transport.h +++ b/src/core/lib/transport/transport.h @@ -150,18 +150,13 @@ typedef struct grpc_transport_stream_op { /** Collect any stats into provided buffer, zero internal stat counters */ grpc_transport_stream_stats *collect_stats; - /** If != GRPC_ERROR_NONE, forcefully close this stream. - The HTTP2 semantics should be: - - server side: if cancel_error has GRPC_ERROR_INT_GRPC_STATUS, and - trailing metadata has not been sent, send trailing metadata with status - and message from cancel_error (use grpc_error_get_status) followed by - a RST_STREAM with error=GRPC_CHTTP2_NO_ERROR to force a full close - - at all other times: use grpc_error_get_status to get a status code, and - convert to a HTTP2 error code using - grpc_chttp2_grpc_status_to_http2_error. Send a RST_STREAM with this - error. */ + /** If != GRPC_ERROR_NONE, cancel this stream */ grpc_error *cancel_error; + /** If != GRPC_ERROR_NONE, send grpc-status, grpc-message, and close this + stream for both reading and writing */ + grpc_error *close_error; + /* Indexes correspond to grpc_context_index enum values */ grpc_call_context_element *context; @@ -181,8 +176,13 @@ typedef struct grpc_transport_op { grpc_connectivity_state *connectivity_state; /** should the transport be disconnected */ grpc_error *disconnect_with_error; + /** should we send a goaway? + after a goaway is sent, once there are no more active calls on + the transport, the transport should disconnect */ + bool send_goaway; /** what should the goaway contain? */ - grpc_error *goaway_error; + grpc_status_code goaway_status; + grpc_slice *goaway_message; /** set the callback for accepting new streams; this is a permanent callback, unlike the other one-shot closures. If true, the callback is set to set_accept_stream_fn, with its @@ -245,6 +245,18 @@ void grpc_transport_stream_op_finish_with_failure(grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, grpc_error *error); +void grpc_transport_stream_op_add_cancellation(grpc_transport_stream_op *op, + grpc_status_code status); + +void grpc_transport_stream_op_add_cancellation_with_message( + grpc_exec_ctx *exec_ctx, grpc_transport_stream_op *op, + grpc_status_code status, grpc_slice *optional_message); + +void grpc_transport_stream_op_add_close(grpc_exec_ctx *exec_ctx, + grpc_transport_stream_op *op, + grpc_status_code status, + grpc_slice *optional_message); + char *grpc_transport_stream_op_string(grpc_transport_stream_op *op); char *grpc_transport_op_string(grpc_transport_op *op); diff --git a/src/core/lib/transport/transport_op_string.c b/src/core/lib/transport/transport_op_string.c index 28360e37840..58d6ad508e3 100644 --- a/src/core/lib/transport/transport_op_string.c +++ b/src/core/lib/transport/transport_op_string.c @@ -47,14 +47,14 @@ /* These routines are here to facilitate debugging - they produce string representations of various transport data structures */ -static void put_metadata(gpr_strvec *b, grpc_mdelem md) { +static void put_metadata(gpr_strvec *b, grpc_mdelem *md) { gpr_strvec_add(b, gpr_strdup("key=")); gpr_strvec_add( - b, grpc_dump_slice(GRPC_MDKEY(md), GPR_DUMP_HEX | GPR_DUMP_ASCII)); + b, grpc_dump_slice(md->key->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII)); gpr_strvec_add(b, gpr_strdup(" value=")); gpr_strvec_add( - b, grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX | GPR_DUMP_ASCII)); + b, grpc_dump_slice(md->value->slice, GPR_DUMP_HEX | GPR_DUMP_ASCII)); } static void put_metadata_list(gpr_strvec *b, grpc_metadata_batch md) { @@ -121,7 +121,15 @@ char *grpc_transport_stream_op_string(grpc_transport_stream_op *op) { gpr_strvec_add(&b, gpr_strdup(" ")); const char *msg = grpc_error_string(op->cancel_error); gpr_asprintf(&tmp, "CANCEL:%s", msg); + grpc_error_free_string(msg); + gpr_strvec_add(&b, tmp); + } + if (op->close_error != GRPC_ERROR_NONE) { + gpr_strvec_add(&b, gpr_strdup(" ")); + const char *msg = grpc_error_string(op->close_error); + gpr_asprintf(&tmp, "CLOSE:%s", msg); + grpc_error_free_string(msg); gpr_strvec_add(&b, tmp); } @@ -160,14 +168,18 @@ char *grpc_transport_op_string(grpc_transport_op *op) { const char *err = grpc_error_string(op->disconnect_with_error); gpr_asprintf(&tmp, "DISCONNECT:%s", err); gpr_strvec_add(&b, tmp); + grpc_error_free_string(err); } - if (op->goaway_error) { + if (op->send_goaway) { if (!first) gpr_strvec_add(&b, gpr_strdup(" ")); first = false; - const char *msg = grpc_error_string(op->goaway_error); - gpr_asprintf(&tmp, "SEND_GOAWAY:%s", msg); - + char *msg = op->goaway_message == NULL + ? "null" + : grpc_dump_slice(*op->goaway_message, + GPR_DUMP_ASCII | GPR_DUMP_HEX); + gpr_asprintf(&tmp, "SEND_GOAWAY:status=%d:msg=%s", op->goaway_status, msg); + if (op->goaway_message != NULL) gpr_free(msg); gpr_strvec_add(&b, tmp); } diff --git a/src/cpp/client/channel_cc.cc b/src/cpp/client/channel_cc.cc index c985183ae76..357d8317adf 100644 --- a/src/cpp/client/channel_cc.cc +++ b/src/cpp/client/channel_cc.cc @@ -107,20 +107,10 @@ Call Channel::CreateCall(const RpcMethod& method, ClientContext* context, } else if (!host_.empty()) { host_str = host_.c_str(); } - grpc_slice method_slice = SliceFromCopiedString(method.name()); - grpc_slice host_slice; - if (host_str != nullptr) { - host_slice = SliceFromCopiedString(host_str); - } - c_call = grpc_channel_create_call( - c_channel_, context->propagate_from_call_, - context->propagation_options_.c_bitmask(), cq->cq(), method_slice, - host_str == nullptr ? nullptr : &host_slice, context->raw_deadline(), - nullptr); - grpc_slice_unref(method_slice); - if (host_str != nullptr) { - grpc_slice_unref(host_slice); - } + c_call = grpc_channel_create_call(c_channel_, context->propagate_from_call_, + context->propagation_options_.c_bitmask(), + cq->cq(), method.name(), host_str, + context->raw_deadline(), nullptr); } grpc_census_call_set_context(c_call, context->census_context()); context->set_call(c_call, shared_from_this()); diff --git a/src/cpp/client/secure_credentials.cc b/src/cpp/client/secure_credentials.cc index 25f6bab7f25..269c523bba1 100644 --- a/src/cpp/client/secure_credentials.cc +++ b/src/cpp/client/secure_credentials.cc @@ -206,18 +206,15 @@ void MetadataCredentialsPluginWrapper::InvokePlugin( std::vector md; for (auto it = metadata.begin(); it != metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceFromCopiedString(it->first); - md_entry.value = SliceFromCopiedString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); md_entry.flags = 0; md.push_back(md_entry); } cb(user_data, md.empty() ? nullptr : &md[0], md.size(), static_cast(status.error_code()), status.error_message().c_str()); - for (auto it = md.begin(); it != md.end(); ++it) { - grpc_slice_unref(it->key); - grpc_slice_unref(it->value); - } } MetadataCredentialsPluginWrapper::MetadataCredentialsPluginWrapper( diff --git a/src/cpp/client/secure_credentials.h b/src/cpp/client/secure_credentials.h index 713654ad5ba..281db17e983 100644 --- a/src/cpp/client/secure_credentials.h +++ b/src/cpp/client/secure_credentials.h @@ -70,7 +70,7 @@ class SecureCallCredentials final : public CallCredentials { grpc_call_credentials* const c_creds_; }; -class MetadataCredentialsPluginWrapper final : private GrpcLibraryCodegen { +class MetadataCredentialsPluginWrapper final { public: static void Destroy(void* wrapper); static void GetMetadata(void* wrapper, grpc_auth_metadata_context context, diff --git a/src/cpp/common/channel_filter.cc b/src/cpp/common/channel_filter.cc index 253614ca9b4..c0dc9dd63e5 100644 --- a/src/cpp/common/channel_filter.cc +++ b/src/cpp/common/channel_filter.cc @@ -36,8 +36,6 @@ #include "src/core/lib/channel/channel_stack.h" #include "src/cpp/common/channel_filter.h" -#include - namespace grpc { // MetadataBatch @@ -47,10 +45,8 @@ grpc_linked_mdelem *MetadataBatch::AddMetadata(grpc_exec_ctx *exec_ctx, const string &value) { grpc_linked_mdelem *storage = new grpc_linked_mdelem; memset(storage, 0, sizeof(grpc_linked_mdelem)); - storage->md = grpc_mdelem_from_slices(exec_ctx, SliceFromCopiedString(key), - SliceFromCopiedString(value)); - GRPC_LOG_IF_ERROR("MetadataBatch::AddMetadata", - grpc_metadata_batch_link_head(exec_ctx, batch_, storage)); + storage->md = grpc_mdelem_from_strings(exec_ctx, key.c_str(), value.c_str()); + grpc_metadata_batch_link_head(batch_, storage); return storage; } diff --git a/src/cpp/common/channel_filter.h b/src/cpp/common/channel_filter.h index 5f9fd8790b5..5de8f5e4631 100644 --- a/src/cpp/common/channel_filter.h +++ b/src/cpp/common/channel_filter.h @@ -76,8 +76,8 @@ class MetadataBatch { class const_iterator : public std::iterator { public: - const grpc_mdelem &operator*() const { return elem_->md; } - const grpc_mdelem operator->() const { return elem_->md; } + const grpc_mdelem &operator*() const { return *elem_->md; } + const grpc_mdelem *operator->() const { return elem_->md; } const_iterator &operator++() { elem_ = elem_->next; @@ -133,7 +133,7 @@ class TransportOp { grpc_error *disconnect_with_error() const { return op_->disconnect_with_error; } - bool send_goaway() const { return op_->goaway_error != GRPC_ERROR_NONE; } + bool send_goaway() const { return op_->send_goaway; } // TODO(roth): Add methods for additional fields as needed. diff --git a/src/cpp/common/core_codegen.cc b/src/cpp/common/core_codegen.cc index 36e4c893540..a07ad543769 100644 --- a/src/cpp/common/core_codegen.cc +++ b/src/cpp/common/core_codegen.cc @@ -123,17 +123,6 @@ grpc_slice CoreCodegen::grpc_slice_split_tail(grpc_slice* s, size_t split) { return ::grpc_slice_split_tail(s, split); } -grpc_slice CoreCodegen::grpc_slice_from_static_buffer(const void* buffer, - size_t length) { - return ::grpc_slice_from_static_buffer(buffer, length); -} - -grpc_slice CoreCodegen::grpc_slice_from_copied_buffer(const void* buffer, - size_t length) { - return ::grpc_slice_from_copied_buffer(static_cast(buffer), - length); -} - void CoreCodegen::grpc_slice_buffer_add(grpc_slice_buffer* sb, grpc_slice slice) { ::grpc_slice_buffer_add(sb, slice); @@ -163,10 +152,8 @@ gpr_timespec CoreCodegen::gpr_time_0(gpr_clock_type type) { return ::gpr_time_0(type); } -void CoreCodegen::assert_fail(const char* failed_assertion, const char* file, - int line) { - gpr_log(file, line, GPR_LOG_SEVERITY_ERROR, "assertion failed: %s", - failed_assertion); +void CoreCodegen::assert_fail(const char* failed_assertion) { + gpr_log(GPR_ERROR, "assertion failed: %s", failed_assertion); abort(); } diff --git a/src/cpp/server/dynamic_thread_pool.cc b/src/cpp/server/dynamic_thread_pool.cc index afb5beaadec..1fdc2edb259 100644 --- a/src/cpp/server/dynamic_thread_pool.cc +++ b/src/cpp/server/dynamic_thread_pool.cc @@ -31,15 +31,12 @@ * */ -#include "src/cpp/server/dynamic_thread_pool.h" - #include #include -#include +#include "src/cpp/server/dynamic_thread_pool.h" namespace grpc { - DynamicThreadPool::DynamicThread::DynamicThread(DynamicThreadPool* pool) : pool_(pool), thd_(new std::thread(&DynamicThreadPool::DynamicThread::ThreadFunc, diff --git a/src/cpp/server/secure_server_credentials.cc b/src/cpp/server/secure_server_credentials.cc index 10f662c77df..33bdc2a1f4f 100644 --- a/src/cpp/server/secure_server_credentials.cc +++ b/src/cpp/server/secure_server_credentials.cc @@ -35,12 +35,11 @@ #include #include -#include -#include - #include "src/cpp/common/secure_auth_context.h" #include "src/cpp/server/secure_server_credentials.h" +#include + namespace grpc { void AuthMetadataProcessorAyncWrapper::Destroy(void* wrapper) { @@ -72,8 +71,8 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( grpc_process_auth_metadata_done_cb cb, void* user_data) { AuthMetadataProcessor::InputMetadata metadata; for (size_t i = 0; i < num_md; i++) { - metadata.insert(std::make_pair(StringRefFromSlice(&md[i].key), - StringRefFromSlice(&md[i].value))); + metadata.insert(std::make_pair( + md[i].key, grpc::string_ref(md[i].value, md[i].value_length))); } SecureAuthContext context(ctx, false); AuthMetadataProcessor::OutputMetadata consumed_metadata; @@ -86,8 +85,9 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = consumed_metadata.begin(); it != consumed_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceReferencingString(it->first); - md_entry.value = SliceReferencingString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); md_entry.flags = 0; consumed_md.push_back(md_entry); } @@ -95,8 +95,9 @@ void AuthMetadataProcessorAyncWrapper::InvokeProcessor( for (auto it = response_metadata.begin(); it != response_metadata.end(); ++it) { grpc_metadata md_entry; - md_entry.key = SliceReferencingString(it->first); - md_entry.value = SliceReferencingString(it->second); + md_entry.key = it->first.c_str(); + md_entry.value = it->second.data(); + md_entry.value_length = it->second.size(); md_entry.flags = 0; response_md.push_back(md_entry); } diff --git a/src/cpp/server/server_cc.cc b/src/cpp/server/server_cc.cc index dcc56eecbce..817d85a81ca 100644 --- a/src/cpp/server/server_cc.cc +++ b/src/cpp/server/server_cc.cc @@ -576,6 +576,7 @@ ServerInterface::BaseAsyncRequest::BaseAsyncRequest( delete_on_finalize_(delete_on_finalize), call_(nullptr) { call_cq_->RegisterAvalanching(); // This op will trigger more ops + memset(&initial_metadata_array_, 0, sizeof(initial_metadata_array_)); } ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { @@ -585,8 +586,16 @@ ServerInterface::BaseAsyncRequest::~BaseAsyncRequest() { bool ServerInterface::BaseAsyncRequest::FinalizeResult(void** tag, bool* status) { if (*status) { - context_->client_metadata_.FillMap(); + for (size_t i = 0; i < initial_metadata_array_.count; i++) { + context_->client_metadata_.insert( + std::pair( + initial_metadata_array_.metadata[i].key, + grpc::string_ref( + initial_metadata_array_.metadata[i].value, + initial_metadata_array_.metadata[i].value_length))); + } } + grpc_metadata_array_destroy(&initial_metadata_array_); context_->set_call(call_); context_->cq_ = call_cq_; Call call(call_, server_, call_cq_, server_->max_receive_message_size()); @@ -612,8 +621,8 @@ void ServerInterface::RegisteredAsyncRequest::IssueRequest( ServerCompletionQueue* notification_cq) { grpc_server_request_registered_call( server_->server(), registered_method, &call_, &context_->deadline_, - context_->client_metadata_.arr(), payload, call_cq_->cq(), - notification_cq->cq(), this); + &initial_metadata_array_, payload, call_cq_->cq(), notification_cq->cq(), + this); } ServerInterface::GenericAsyncRequest::GenericAsyncRequest( @@ -626,7 +635,7 @@ ServerInterface::GenericAsyncRequest::GenericAsyncRequest( GPR_ASSERT(notification_cq); GPR_ASSERT(call_cq); grpc_server_request_call(server->server(), &call_, &call_details_, - context->client_metadata_.arr(), call_cq->cq(), + &initial_metadata_array_, call_cq->cq(), notification_cq->cq(), this); } @@ -635,12 +644,11 @@ bool ServerInterface::GenericAsyncRequest::FinalizeResult(void** tag, // TODO(yangg) remove the copy here. if (*status) { static_cast(context_)->method_ = - StringFromCopiedSlice(call_details_.method); - static_cast(context_)->host_ = - StringFromCopiedSlice(call_details_.host); + call_details_.method; + static_cast(context_)->host_ = call_details_.host; } - grpc_slice_unref(call_details_.method); - grpc_slice_unref(call_details_.host); + gpr_free(call_details_.method); + gpr_free(call_details_.host); return BaseAsyncRequest::FinalizeResult(tag, status); } diff --git a/src/cpp/server/server_context.cc b/src/cpp/server/server_context.cc index a7aaa255724..a66ec4ac841 100644 --- a/src/cpp/server/server_context.cc +++ b/src/cpp/server/server_context.cc @@ -144,10 +144,9 @@ ServerContext::ServerContext(gpr_timespec deadline, grpc_metadata* metadata, sent_initial_metadata_(false), compression_level_set_(false) { for (size_t i = 0; i < metadata_count; i++) { - client_metadata_.map()->insert( - std::pair( - StringRefFromSlice(&metadata[i].key), - StringRefFromSlice(&metadata[i].value))); + client_metadata_.insert(std::pair( + metadata[i].key, + grpc::string_ref(metadata[i].value, metadata[i].value_length))); } } diff --git a/src/cpp/test/server_context_test_spouse.cc b/src/cpp/test/server_context_test_spouse.cc index b812d169a52..b93152eea0e 100644 --- a/src/cpp/test/server_context_test_spouse.cc +++ b/src/cpp/test/server_context_test_spouse.cc @@ -40,12 +40,11 @@ void ServerContextTestSpouse::AddClientMetadata(const grpc::string& key, const grpc::string& value) { client_metadata_storage_.insert( std::pair(key, value)); - ctx_->client_metadata_.map()->clear(); + ctx_->client_metadata_.clear(); for (auto iter = client_metadata_storage_.begin(); iter != client_metadata_storage_.end(); ++iter) { - ctx_->client_metadata_.map()->insert( - std::pair(iter->first.c_str(), - iter->second.c_str())); + ctx_->client_metadata_.insert(std::pair( + iter->first.c_str(), iter->second.c_str())); } } diff --git a/src/cpp/util/slice_cc.cc b/src/cpp/util/slice_cc.cc index 6efb68e1232..c05f1cf1240 100644 --- a/src/cpp/util/slice_cc.cc +++ b/src/cpp/util/slice_cc.cc @@ -35,7 +35,7 @@ namespace grpc { -Slice::Slice() : slice_(grpc_empty_slice()) {} +Slice::Slice() : slice_(gpr_empty_slice()) {} Slice::~Slice() { grpc_slice_unref(slice_); } diff --git a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs index 0e4a77be81a..26449ee5393 100644 --- a/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/BatchContextSafeHandle.cs @@ -71,9 +71,7 @@ namespace Grpc.Core.Internal // Gets data of recv_status_on_client completion. public ClientSideStatus GetReceivedStatusOnClient() { - UIntPtr detailsLength; - IntPtr detailsPtr = Native.grpcsharp_batch_context_recv_status_on_client_details(this, out detailsLength); - string details = Marshal.PtrToStringAnsi(detailsPtr, (int) detailsLength.ToUInt32()); + string details = Marshal.PtrToStringAnsi(Native.grpcsharp_batch_context_recv_status_on_client_details(this)); var status = new Status(Native.grpcsharp_batch_context_recv_status_on_client_status(this), details); IntPtr metadataArrayPtr = Native.grpcsharp_batch_context_recv_status_on_client_trailing_metadata(this); diff --git a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs index d5b87a6c945..05dda5b1486 100644 --- a/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/MetadataArraySafeHandle.cs @@ -79,13 +79,9 @@ namespace Grpc.Core.Internal for (ulong i = 0; i < count; i++) { var index = new UIntPtr(i); - UIntPtr keyLen; - IntPtr keyPtr = Native.grpcsharp_metadata_array_get_key(metadataArray, index, out keyLen); - string key = Marshal.PtrToStringAnsi(keyPtr, (int)keyLen.ToUInt32()); - UIntPtr valueLen; - IntPtr valuePtr = Native.grpcsharp_metadata_array_get_value(metadataArray, index, out valueLen); - var bytes = new byte[valueLen.ToUInt64()]; - Marshal.Copy(valuePtr, bytes, 0, bytes.Length); + string key = Marshal.PtrToStringAnsi(Native.grpcsharp_metadata_array_get_key(metadataArray, index)); + var bytes = new byte[Native.grpcsharp_metadata_array_get_value_length(metadataArray, index).ToUInt64()]; + Marshal.Copy(Native.grpcsharp_metadata_array_get_value(metadataArray, index), bytes, 0, bytes.Length); metadata.Add(Metadata.Entry.CreateUnsafe(key, bytes)); } return metadata; diff --git a/src/csharp/Grpc.Core/Internal/NativeMethods.cs b/src/csharp/Grpc.Core/Internal/NativeMethods.cs index 2f377071f79..ce38e370936 100644 --- a/src/csharp/Grpc.Core/Internal/NativeMethods.cs +++ b/src/csharp/Grpc.Core/Internal/NativeMethods.cs @@ -128,6 +128,7 @@ namespace Grpc.Core.Internal public readonly Delegates.grpcsharp_metadata_array_count_delegate grpcsharp_metadata_array_count; public readonly Delegates.grpcsharp_metadata_array_get_key_delegate grpcsharp_metadata_array_get_key; public readonly Delegates.grpcsharp_metadata_array_get_value_delegate grpcsharp_metadata_array_get_value; + public readonly Delegates.grpcsharp_metadata_array_get_value_length_delegate grpcsharp_metadata_array_get_value_length; public readonly Delegates.grpcsharp_metadata_array_destroy_full_delegate grpcsharp_metadata_array_destroy_full; public readonly Delegates.grpcsharp_redirect_log_delegate grpcsharp_redirect_log; @@ -236,6 +237,7 @@ namespace Grpc.Core.Internal this.grpcsharp_metadata_array_count = GetMethodDelegate(library); this.grpcsharp_metadata_array_get_key = GetMethodDelegate(library); this.grpcsharp_metadata_array_get_value = GetMethodDelegate(library); + this.grpcsharp_metadata_array_get_value_length = GetMethodDelegate(library); this.grpcsharp_metadata_array_destroy_full = GetMethodDelegate(library); this.grpcsharp_redirect_log = GetMethodDelegate(library); @@ -304,15 +306,15 @@ namespace Grpc.Core.Internal public delegate IntPtr grpcsharp_batch_context_recv_message_length_delegate(BatchContextSafeHandle ctx); public delegate void grpcsharp_batch_context_recv_message_to_buffer_delegate(BatchContextSafeHandle ctx, byte[] buffer, UIntPtr bufferLen); public delegate StatusCode grpcsharp_batch_context_recv_status_on_client_status_delegate(BatchContextSafeHandle ctx); - public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate(BatchContextSafeHandle ctx, out UIntPtr detailsLength); + public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_details_delegate(BatchContextSafeHandle ctx); // returns const char* public delegate IntPtr grpcsharp_batch_context_recv_status_on_client_trailing_metadata_delegate(BatchContextSafeHandle ctx); public delegate int grpcsharp_batch_context_recv_close_on_server_cancelled_delegate(BatchContextSafeHandle ctx); public delegate void grpcsharp_batch_context_destroy_delegate(IntPtr ctx); public delegate RequestCallContextSafeHandle grpcsharp_request_call_context_create_delegate(); public delegate CallSafeHandle grpcsharp_request_call_context_call_delegate(RequestCallContextSafeHandle ctx); - public delegate IntPtr grpcsharp_request_call_context_method_delegate(RequestCallContextSafeHandle ctx, out UIntPtr methodLength); - public delegate IntPtr grpcsharp_request_call_context_host_delegate(RequestCallContextSafeHandle ctx, out UIntPtr hostLength); + public delegate IntPtr grpcsharp_request_call_context_method_delegate(RequestCallContextSafeHandle ctx); // returns const char* + public delegate IntPtr grpcsharp_request_call_context_host_delegate(RequestCallContextSafeHandle ctx); // returns const char* public delegate Timespec grpcsharp_request_call_context_deadline_delegate(RequestCallContextSafeHandle ctx); public delegate IntPtr grpcsharp_request_call_context_request_metadata_delegate(RequestCallContextSafeHandle ctx); public delegate void grpcsharp_request_call_context_destroy_delegate(IntPtr ctx); @@ -382,8 +384,9 @@ namespace Grpc.Core.Internal public delegate MetadataArraySafeHandle grpcsharp_metadata_array_create_delegate(UIntPtr capacity); public delegate void grpcsharp_metadata_array_add_delegate(MetadataArraySafeHandle array, string key, byte[] value, UIntPtr valueLength); public delegate UIntPtr grpcsharp_metadata_array_count_delegate(IntPtr metadataArray); - public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(IntPtr metadataArray, UIntPtr index, out UIntPtr keyLength); - public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(IntPtr metadataArray, UIntPtr index, out UIntPtr valueLength); + public delegate IntPtr grpcsharp_metadata_array_get_key_delegate(IntPtr metadataArray, UIntPtr index); + public delegate IntPtr grpcsharp_metadata_array_get_value_delegate(IntPtr metadataArray, UIntPtr index); + public delegate UIntPtr grpcsharp_metadata_array_get_value_length_delegate(IntPtr metadataArray, UIntPtr index); public delegate void grpcsharp_metadata_array_destroy_full_delegate(IntPtr array); public delegate void grpcsharp_redirect_log_delegate(GprLogDelegate callback); diff --git a/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs b/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs index c1560bc8bf4..ea7819d7b1f 100644 --- a/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs +++ b/src/csharp/Grpc.Core/Internal/RequestCallContextSafeHandle.cs @@ -66,14 +66,8 @@ namespace Grpc.Core.Internal { var call = Native.grpcsharp_request_call_context_call(this); - UIntPtr methodLen; - IntPtr methodPtr = Native.grpcsharp_request_call_context_method(this, out methodLen); - var method = Marshal.PtrToStringAnsi(methodPtr, (int) methodLen.ToUInt32()); - - UIntPtr hostLen; - IntPtr hostPtr = Native.grpcsharp_request_call_context_host(this, out hostLen); - var host = Marshal.PtrToStringAnsi(hostPtr, (int) hostLen.ToUInt32()); - + var method = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_method(this)); + var host = Marshal.PtrToStringAnsi(Native.grpcsharp_request_call_context_host(this)); var deadline = Native.grpcsharp_request_call_context_deadline(this); IntPtr metadataArrayPtr = Native.grpcsharp_request_call_context_request_metadata(this); diff --git a/src/csharp/ext/grpc_csharp_ext.c b/src/csharp/ext/grpc_csharp_ext.c index 12c747b8008..946f5872c0e 100644 --- a/src/csharp/ext/grpc_csharp_ext.c +++ b/src/csharp/ext/grpc_csharp_ext.c @@ -73,13 +73,15 @@ typedef struct grpcsharp_batch_context { grpc_byte_buffer *send_message; struct { grpc_metadata_array trailing_metadata; + char *status_details; } send_status_from_server; grpc_metadata_array recv_initial_metadata; grpc_byte_buffer *recv_message; struct { grpc_metadata_array trailing_metadata; grpc_status_code status; - grpc_slice status_details; + char *status_details; + size_t status_details_capacity; } recv_status_on_client; int recv_close_on_server_cancelled; } grpcsharp_batch_context; @@ -120,8 +122,8 @@ void grpcsharp_metadata_array_destroy_metadata_including_entries( size_t i; if (array->metadata) { for (i = 0; i < array->count; i++) { - grpc_slice_unref(array->metadata[i].key); - grpc_slice_unref(array->metadata[i].value); + gpr_free((void *)array->metadata[i].key); + gpr_free((void *)array->metadata[i].value); } } gpr_free(array->metadata); @@ -165,8 +167,10 @@ grpcsharp_metadata_array_add(grpc_metadata_array *array, const char *key, const char *value, size_t value_length) { size_t i = array->count; GPR_ASSERT(array->count < array->capacity); - array->metadata[i].key = grpc_slice_from_copied_string(key); - array->metadata[i].value = grpc_slice_from_copied_buffer(value, value_length); + array->metadata[i].key = gpr_strdup(key); + array->metadata[i].value = (char *)gpr_malloc(value_length); + memcpy((void *)array->metadata[i].value, value, value_length); + array->metadata[i].value_length = value_length; array->count++; } @@ -176,17 +180,21 @@ grpcsharp_metadata_array_count(grpc_metadata_array *array) { } GPR_EXPORT const char *GPR_CALLTYPE -grpcsharp_metadata_array_get_key(grpc_metadata_array *array, size_t index, size_t *key_length) { +grpcsharp_metadata_array_get_key(grpc_metadata_array *array, size_t index) { GPR_ASSERT(index < array->count); - *key_length = GRPC_SLICE_LENGTH(array->metadata[index].key); - return (char *)GRPC_SLICE_START_PTR(array->metadata[index].key); + return array->metadata[index].key; } GPR_EXPORT const char *GPR_CALLTYPE -grpcsharp_metadata_array_get_value(grpc_metadata_array *array, size_t index, size_t *value_length) { +grpcsharp_metadata_array_get_value(grpc_metadata_array *array, size_t index) { GPR_ASSERT(index < array->count); - *value_length = GRPC_SLICE_LENGTH(array->metadata[index].value); - return (char *)GRPC_SLICE_START_PTR(array->metadata[index].value); + return array->metadata[index].value; +} + +GPR_EXPORT intptr_t GPR_CALLTYPE grpcsharp_metadata_array_get_value_length( + grpc_metadata_array *array, size_t index) { + GPR_ASSERT(index < array->count); + return (intptr_t)array->metadata[index].value_length; } /* Move contents of metadata array */ @@ -219,6 +227,7 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_batch_context_destroy(grpcsharp_batch_con grpcsharp_metadata_array_destroy_metadata_including_entries( &(ctx->send_status_from_server.trailing_metadata)); + gpr_free(ctx->send_status_from_server.status_details); grpcsharp_metadata_array_destroy_metadata_only(&(ctx->recv_initial_metadata)); @@ -226,7 +235,7 @@ GPR_EXPORT void GPR_CALLTYPE grpcsharp_batch_context_destroy(grpcsharp_batch_con grpcsharp_metadata_array_destroy_metadata_only( &(ctx->recv_status_on_client.trailing_metadata)); - grpc_slice_unref(ctx->recv_status_on_client.status_details); + gpr_free((void *)ctx->recv_status_on_client.status_details); gpr_free(ctx); } @@ -298,9 +307,8 @@ grpcsharp_batch_context_recv_status_on_client_status( GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_batch_context_recv_status_on_client_details( - const grpcsharp_batch_context *ctx, size_t *details_length) { - *details_length = GRPC_SLICE_LENGTH(ctx->recv_status_on_client.status_details); - return (char *)GRPC_SLICE_START_PTR(ctx->recv_status_on_client.status_details); + const grpcsharp_batch_context *ctx) { + return ctx->recv_status_on_client.status_details; } GPR_EXPORT const grpc_metadata_array *GPR_CALLTYPE @@ -316,15 +324,13 @@ GPR_EXPORT grpc_call *GPR_CALLTYPE grpcsharp_request_call_context_call( GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_request_call_context_method( - const grpcsharp_request_call_context *ctx, size_t *method_length) { - *method_length = GRPC_SLICE_LENGTH(ctx->call_details.method); - return (char *)GRPC_SLICE_START_PTR(ctx->call_details.method); + const grpcsharp_request_call_context *ctx) { + return ctx->call_details.method; } GPR_EXPORT const char *GPR_CALLTYPE grpcsharp_request_call_context_host( - const grpcsharp_request_call_context *ctx, size_t *host_length) { - *host_length = GRPC_SLICE_LENGTH(ctx->call_details.host); - return (char *)GRPC_SLICE_START_PTR(ctx->call_details.host); + const grpcsharp_request_call_context *ctx) { + return ctx->call_details.host; } GPR_EXPORT gpr_timespec GPR_CALLTYPE @@ -398,15 +404,8 @@ grpcsharp_channel_create_call(grpc_channel *channel, grpc_call *parent_call, grpc_completion_queue *cq, const char *method, const char *host, gpr_timespec deadline) { - grpc_slice method_slice = grpc_slice_from_copied_string(method); - grpc_slice *host_slice_ptr = NULL; - grpc_slice host_slice; - if (host != NULL) { - host_slice = grpc_slice_from_copied_string(host); - host_slice_ptr = &host_slice; - } return grpc_channel_create_call(channel, parent_call, propagation_mask, cq, - method_slice, host_slice_ptr, deadline, NULL); + method, host, deadline, NULL); } GPR_EXPORT grpc_connectivity_state GPR_CALLTYPE @@ -561,8 +560,11 @@ grpcsharp_call_start_unary(grpc_call *call, grpcsharp_batch_context *ctx, &(ctx->recv_status_on_client.trailing_metadata); ops[5].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); + /* not using preallocation for status_details */ ops[5].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); + ops[5].data.recv_status_on_client.status_details_capacity = + &(ctx->recv_status_on_client.status_details_capacity); ops[5].flags = 0; ops[5].reserved = NULL; @@ -602,8 +604,11 @@ grpcsharp_call_start_client_streaming(grpc_call *call, &(ctx->recv_status_on_client.trailing_metadata); ops[3].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); + /* not using preallocation for status_details */ ops[3].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); + ops[3].data.recv_status_on_client.status_details_capacity = + &(ctx->recv_status_on_client.status_details_capacity); ops[3].flags = 0; ops[3].reserved = NULL; @@ -642,8 +647,11 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_start_server_streaming( &(ctx->recv_status_on_client.trailing_metadata); ops[3].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); + /* not using preallocation for status_details */ ops[3].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); + ops[3].data.recv_status_on_client.status_details_capacity = + &(ctx->recv_status_on_client.status_details_capacity); ops[3].flags = 0; ops[3].reserved = NULL; @@ -673,8 +681,11 @@ grpcsharp_call_start_duplex_streaming(grpc_call *call, &(ctx->recv_status_on_client.trailing_metadata); ops[1].data.recv_status_on_client.status = &(ctx->recv_status_on_client.status); + /* not using preallocation for status_details */ ops[1].data.recv_status_on_client.status_details = &(ctx->recv_status_on_client.status_details); + ops[1].data.recv_status_on_client.status_details_capacity = + &(ctx->recv_status_on_client.status_details_capacity); ops[1].flags = 0; ops[1].reserved = NULL; @@ -738,10 +749,10 @@ GPR_EXPORT grpc_call_error GPR_CALLTYPE grpcsharp_call_send_status_from_server( grpc_op ops[3]; memset(ops, 0, sizeof(ops)); size_t nops = 1; - grpc_slice status_details_slice = grpc_slice_from_copied_string(status_details); ops[0].op = GRPC_OP_SEND_STATUS_FROM_SERVER; ops[0].data.send_status_from_server.status = status_code; - ops[0].data.send_status_from_server.status_details = &status_details_slice; + ops[0].data.send_status_from_server.status_details = + gpr_strdup(status_details); grpcsharp_metadata_array_move( &(ctx->send_status_from_server.trailing_metadata), trailing_metadata); ops[0].data.send_status_from_server.trailing_metadata_count = diff --git a/src/node/ext/byte_buffer.cc b/src/node/ext/byte_buffer.cc index 7d6fb198603..fc339fc4629 100644 --- a/src/node/ext/byte_buffer.cc +++ b/src/node/ext/byte_buffer.cc @@ -40,7 +40,6 @@ #include "grpc/slice.h" #include "byte_buffer.h" -#include "slice.h" namespace grpc { namespace node { @@ -55,7 +54,10 @@ using v8::Value; grpc_byte_buffer *BufferToByteBuffer(Local buffer) { Nan::HandleScope scope; - grpc_slice slice = CreateSliceFromBuffer(buffer); + int length = ::node::Buffer::Length(buffer); + char *data = ::node::Buffer::Data(buffer); + grpc_slice slice = grpc_slice_malloc(length); + memcpy(GRPC_SLICE_START_PTR(slice), data, length); grpc_byte_buffer *byte_buffer(grpc_raw_byte_buffer_create(&slice, 1)); grpc_slice_unref(slice); return byte_buffer; diff --git a/src/node/ext/call.cc b/src/node/ext/call.cc index 9213d5e87d3..191e763e0e7 100644 --- a/src/node/ext/call.cc +++ b/src/node/ext/call.cc @@ -48,7 +48,6 @@ #include "completion_queue.h" #include "completion_queue_async_worker.h" #include "call_credentials.h" -#include "slice.h" #include "timeval.h" using std::unique_ptr; @@ -97,7 +96,8 @@ Local nanErrorWithCode(const char *msg, grpc_call_error code) { return scope.Escape(err); } -bool CreateMetadataArray(Local metadata, grpc_metadata_array *array) { +bool CreateMetadataArray(Local metadata, grpc_metadata_array *array, + shared_ptr resources) { HandleScope scope; grpc_metadata_array_init(array); Local keys = Nan::GetOwnPropertyNames(metadata).ToLocalChecked(); @@ -113,25 +113,32 @@ bool CreateMetadataArray(Local metadata, grpc_metadata_array *array) { array->metadata = reinterpret_cast( gpr_malloc(array->capacity * sizeof(grpc_metadata))); for (unsigned int i = 0; i < keys->Length(); i++) { - Local current_key(Nan::To(keys->Get(i)).ToLocalChecked()); + Local current_key(keys->Get(i)->ToString()); + Utf8String *utf8_key = new Utf8String(current_key); + resources->strings.push_back(unique_ptr(utf8_key)); Local values = Local::Cast( Nan::Get(metadata, current_key).ToLocalChecked()); - grpc_slice key_slice = grpc_slice_intern(CreateSliceFromString(current_key)); for (unsigned int j = 0; j < values->Length(); j++) { Local value = Nan::Get(values, j).ToLocalChecked(); grpc_metadata *current = &array->metadata[array->count]; - current->key = key_slice; + current->key = **utf8_key; // Only allow binary headers for "-bin" keys - if (grpc_is_binary_header(key_slice)) { + if (grpc_is_binary_header(current->key, strlen(current->key))) { if (::node::Buffer::HasInstance(value)) { - current->value = CreateSliceFromBuffer(value); + current->value = ::node::Buffer::Data(value); + current->value_length = ::node::Buffer::Length(value); + PersistentValue *handle = new PersistentValue(value); + resources->handles.push_back(unique_ptr(handle)); } else { return false; } } else { if (value->IsString()) { Local string_value = Nan::To(value).ToLocalChecked(); - current->value = CreateSliceFromString(string_value); + Utf8String *utf8_value = new Utf8String(string_value); + resources->strings.push_back(unique_ptr(utf8_value)); + current->value = **utf8_value; + current->value_length = string_value->Length(); } else { return false; } @@ -146,25 +153,40 @@ Local ParseMetadata(const grpc_metadata_array *metadata_array) { EscapableHandleScope scope; grpc_metadata *metadata_elements = metadata_array->metadata; size_t length = metadata_array->count; + std::map size_map; + std::map index_map; + + for (unsigned int i = 0; i < length; i++) { + const char *key = metadata_elements[i].key; + if (size_map.count(key)) { + size_map[key] += 1; + } else { + size_map[key] = 1; + } + index_map[key] = 0; + } Local metadata_object = Nan::New(); for (unsigned int i = 0; i < length; i++) { grpc_metadata* elem = &metadata_elements[i]; - // TODO(murgatroid99): Use zero-copy string construction instead - Local key_string = CopyStringFromSlice(elem->key); + Local key_string = Nan::New(elem->key).ToLocalChecked(); Local array; MaybeLocal maybe_array = Nan::Get(metadata_object, key_string); if (maybe_array.IsEmpty() || !maybe_array.ToLocalChecked()->IsArray()) { - array = Nan::New(0); + array = Nan::New(size_map[elem->key]); Nan::Set(metadata_object, key_string, array); } else { array = Local::Cast(maybe_array.ToLocalChecked()); } - if (grpc_is_binary_header(elem->key)) { - Nan::Set(array, array->Length(), CreateBufferFromSlice(elem->value)); + if (grpc_is_binary_header(elem->key, strlen(elem->key))) { + Nan::Set(array, index_map[elem->key], + MakeFastBuffer( + Nan::CopyBuffer(elem->value, + elem->value_length).ToLocalChecked())); } else { - // TODO(murgatroid99): Use zero-copy string construction instead - Nan::Set(array, array->Length(), CopyStringFromSlice(elem->value)); + Nan::Set(array, index_map[elem->key], + Nan::New(elem->value).ToLocalChecked()); } + index_map[elem->key] += 1; } return scope.Escape(metadata_object); } @@ -183,7 +205,8 @@ class SendMetadataOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { if (!value->IsObject()) { return false; } @@ -193,7 +216,7 @@ class SendMetadataOp : public Op { return false; } if (!CreateMetadataArray(maybe_metadata.ToLocalChecked(), - &array)) { + &array, resources)) { return false; } out->data.send_initial_metadata.count = array.count; @@ -223,7 +246,8 @@ class SendMessageOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { if (!::node::Buffer::HasInstance(value)) { return false; } @@ -239,6 +263,8 @@ class SendMessageOp : public Op { } send_message = BufferToByteBuffer(value); out->data.send_message = send_message; + PersistentValue *handle = new PersistentValue(value); + resources->handles.push_back(unique_ptr(handle)); return true; } bool IsFinalOp() { @@ -258,7 +284,8 @@ class SendClientCloseOp : public Op { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { return true; } bool IsFinalOp() { @@ -272,14 +299,12 @@ class SendClientCloseOp : public Op { class SendServerStatusOp : public Op { public: - ~SendServerStatusOp() { - grpc_slice_unref(details); - } Local GetNodeValue() const { EscapableHandleScope scope; return scope.Escape(Nan::True()); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { if (!value->IsObject()) { return false; } @@ -314,15 +339,16 @@ class SendServerStatusOp : public Op { Local details = Nan::To( maybe_details.ToLocalChecked()).ToLocalChecked(); grpc_metadata_array array; - if (!CreateMetadataArray(metadata, &array)) { + if (!CreateMetadataArray(metadata, &array, resources)) { return false; } out->data.send_status_from_server.trailing_metadata_count = array.count; out->data.send_status_from_server.trailing_metadata = array.metadata; out->data.send_status_from_server.status = static_cast(code); - this->details = CreateSliceFromString(details); - out->data.send_status_from_server.status_details = &this->details; + Utf8String *str = new Utf8String(details); + resources->strings.push_back(unique_ptr(str)); + out->data.send_status_from_server.status_details = **str; return true; } bool IsFinalOp() { @@ -332,9 +358,6 @@ class SendServerStatusOp : public Op { std::string GetTypeString() const { return "send_status"; } - - private: - grpc_slice details; }; class GetMetadataOp : public Op { @@ -352,7 +375,8 @@ class GetMetadataOp : public Op { return scope.Escape(ParseMetadata(&recv_metadata)); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { out->data.recv_initial_metadata = &recv_metadata; return true; } @@ -384,7 +408,8 @@ class ReadMessageOp : public Op { return scope.Escape(ByteBufferToBuffer(recv_message)); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { out->data.recv_message = &recv_message; return true; } @@ -405,16 +430,21 @@ class ClientStatusOp : public Op { public: ClientStatusOp() { grpc_metadata_array_init(&metadata_array); + status_details = NULL; + details_capacity = 0; } ~ClientStatusOp() { grpc_metadata_array_destroy(&metadata_array); + gpr_free(status_details); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { out->data.recv_status_on_client.trailing_metadata = &metadata_array; out->data.recv_status_on_client.status = &status; out->data.recv_status_on_client.status_details = &status_details; + out->data.recv_status_on_client.status_details_capacity = &details_capacity; return true; } @@ -423,8 +453,10 @@ class ClientStatusOp : public Op { Local status_obj = Nan::New(); Nan::Set(status_obj, Nan::New("code").ToLocalChecked(), Nan::New(status)); - Nan::Set(status_obj, Nan::New("details").ToLocalChecked(), - CopyStringFromSlice(status_details)); + if (status_details != NULL) { + Nan::Set(status_obj, Nan::New("details").ToLocalChecked(), + Nan::New(status_details).ToLocalChecked()); + } Nan::Set(status_obj, Nan::New("metadata").ToLocalChecked(), ParseMetadata(&metadata_array)); return scope.Escape(status_obj); @@ -439,7 +471,8 @@ class ClientStatusOp : public Op { private: grpc_metadata_array metadata_array; grpc_status_code status; - grpc_slice status_details; + char *status_details; + size_t details_capacity; }; class ServerCloseResponseOp : public Op { @@ -449,7 +482,8 @@ class ServerCloseResponseOp : public Op { return scope.Escape(Nan::New(cancelled)); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { out->data.recv_close_on_server.cancelled = &cancelled; return true; } @@ -466,8 +500,9 @@ class ServerCloseResponseOp : public Op { int cancelled; }; -tag::tag(Callback *callback, OpVec *ops, Call *call) : - callback(callback), ops(ops), call(call){ +tag::tag(Callback *callback, OpVec *ops, + shared_ptr resources, Call *call) : + callback(callback), ops(ops), resources(resources), call(call){ } tag::~tag() { @@ -615,24 +650,20 @@ NAN_METHOD(Call::New) { if (channel->GetWrappedChannel() == NULL) { return Nan::ThrowError("Call cannot be created from a closed channel"); } + Utf8String method(info[1]); double deadline = Nan::To(info[2]).FromJust(); grpc_channel *wrapped_channel = channel->GetWrappedChannel(); grpc_call *wrapped_call; if (info[3]->IsString()) { - grpc_slice *host = new grpc_slice; - *host = CreateSliceFromString( - Nan::To(info[3]).ToLocalChecked()); + Utf8String host_override(info[3]); wrapped_call = grpc_channel_create_call( wrapped_channel, parent_call, propagate_flags, - GetCompletionQueue(), CreateSliceFromString( - Nan::To(info[1]).ToLocalChecked()), - host, MillisecondsToTimespec(deadline), NULL); - delete host; + GetCompletionQueue(), *method, + *host_override, MillisecondsToTimespec(deadline), NULL); } else if (info[3]->IsUndefined() || info[3]->IsNull()) { wrapped_call = grpc_channel_create_call( wrapped_channel, parent_call, propagate_flags, - GetCompletionQueue(), CreateSliceFromString( - Nan::To(info[1]).ToLocalChecked()), + GetCompletionQueue(), *method, NULL, MillisecondsToTimespec(deadline), NULL); } else { return Nan::ThrowTypeError("Call's fourth argument must be a string"); @@ -669,6 +700,7 @@ NAN_METHOD(Call::StartBatch) { } Local callback_func = info[1].As(); Call *call = ObjectWrap::Unwrap(info.This()); + shared_ptr resources(new Resources); Local obj = Nan::To(info[0]).ToLocalChecked(); Local keys = Nan::GetOwnPropertyNames(obj).ToLocalChecked(); size_t nops = keys->Length(); @@ -713,7 +745,7 @@ NAN_METHOD(Call::StartBatch) { default: return Nan::ThrowError("Argument object had an unrecognized key"); } - if (!op->ParseOp(obj->Get(type), &ops[i])) { + if (!op->ParseOp(obj->Get(type), &ops[i], resources)) { return Nan::ThrowTypeError("Incorrectly typed arguments to startBatch"); } op_vector->push_back(std::move(op)); @@ -721,7 +753,7 @@ NAN_METHOD(Call::StartBatch) { Callback *callback = new Callback(callback_func); grpc_call_error error = grpc_call_start_batch( call->wrapped_call, &ops[0], nops, new struct tag( - callback, op_vector.release(), call), NULL); + callback, op_vector.release(), resources, call), NULL); if (error != GRPC_CALL_OK) { return Nan::ThrowError(nanErrorWithCode("startBatch failed", error)); } diff --git a/src/node/ext/call.h b/src/node/ext/call.h index cffff00fce4..31c6566d145 100644 --- a/src/node/ext/call.h +++ b/src/node/ext/call.h @@ -51,12 +51,20 @@ namespace node { using std::unique_ptr; using std::shared_ptr; +typedef Nan::Persistent> PersistentValue; + v8::Local nanErrorWithCode(const char *msg, grpc_call_error code); v8::Local ParseMetadata(const grpc_metadata_array *metadata_array); +struct Resources { + std::vector > strings; + std::vector > handles; +}; + bool CreateMetadataArray(v8::Local metadata, - grpc_metadata_array *array); + grpc_metadata_array *array, + shared_ptr resources); /* Wrapper class for grpc_call structs. */ class Call : public Nan::ObjectWrap { @@ -98,7 +106,8 @@ class Call : public Nan::ObjectWrap { class Op { public: virtual v8::Local GetNodeValue() const = 0; - virtual bool ParseOp(v8::Local value, grpc_op *out) = 0; + virtual bool ParseOp(v8::Local value, grpc_op *out, + shared_ptr resources) = 0; virtual ~Op(); v8::Local GetOpType() const; virtual bool IsFinalOp() = 0; @@ -109,10 +118,12 @@ class Op { typedef std::vector> OpVec; struct tag { - tag(Nan::Callback *callback, OpVec *ops, Call *call); + tag(Nan::Callback *callback, OpVec *ops, + shared_ptr resources, Call *call); ~tag(); Nan::Callback *callback; OpVec *ops; + shared_ptr resources; Call *call; }; diff --git a/src/node/ext/call_credentials.cc b/src/node/ext/call_credentials.cc index 4d172d4ddfd..81fc552fd10 100644 --- a/src/node/ext/call_credentials.cc +++ b/src/node/ext/call_credentials.cc @@ -206,6 +206,7 @@ NAN_METHOD(PluginCallback) { return Nan::ThrowTypeError( "The callback's fourth argument must be an object"); } + shared_ptr resources(new Resources); grpc_status_code code = static_cast( Nan::To(info[0]).FromJust()); Utf8String details_utf8_str(info[1]); @@ -213,7 +214,7 @@ NAN_METHOD(PluginCallback) { grpc_metadata_array array; Local callback_data = Nan::To(info[3]).ToLocalChecked(); if (!CreateMetadataArray(Nan::To(info[2]).ToLocalChecked(), - &array)){ + &array, resources)){ return Nan::ThrowError("Failed to parse metadata"); } grpc_credentials_plugin_metadata_cb cb = diff --git a/src/node/ext/channel.cc b/src/node/ext/channel.cc index c795ff7f42f..5bc58b9b324 100644 --- a/src/node/ext/channel.cc +++ b/src/node/ext/channel.cc @@ -280,7 +280,8 @@ NAN_METHOD(Channel::WatchConnectivityState) { channel->wrapped_channel, last_state, MillisecondsToTimespec(deadline), GetCompletionQueue(), new struct tag(callback, - ops.release(), NULL)); + ops.release(), + shared_ptr(nullptr), NULL)); CompletionQueueNext(); } diff --git a/src/node/ext/node_grpc.cc b/src/node/ext/node_grpc.cc index 682af0e5add..9b9eee85b79 100644 --- a/src/node/ext/node_grpc.cc +++ b/src/node/ext/node_grpc.cc @@ -56,12 +56,9 @@ extern "C" { #include "server.h" #include "completion_queue_async_worker.h" #include "server_credentials.h" -#include "slice.h" #include "timeval.h" #include "completion_queue.h" -using grpc::node::CreateSliceFromString; - using v8::FunctionTemplate; using v8::Local; using v8::Value; @@ -286,8 +283,10 @@ NAN_METHOD(MetadataKeyIsLegal) { "headerKeyIsLegal's argument must be a string"); } Local key = Nan::To(info[0]).ToLocalChecked(); + Nan::Utf8String key_utf8_str(key); + char *key_str = *key_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_header_key_is_legal(CreateSliceFromString(key)))); + grpc_header_key_is_legal(key_str, static_cast(key->Length())))); } NAN_METHOD(MetadataNonbinValueIsLegal) { @@ -296,8 +295,11 @@ NAN_METHOD(MetadataNonbinValueIsLegal) { "metadataNonbinValueIsLegal's argument must be a string"); } Local value = Nan::To(info[0]).ToLocalChecked(); + Nan::Utf8String value_utf8_str(value); + char *value_str = *value_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_header_nonbin_value_is_legal(CreateSliceFromString(value)))); + grpc_header_nonbin_value_is_legal( + value_str, static_cast(value->Length())))); } NAN_METHOD(MetadataKeyIsBinary) { @@ -306,8 +308,10 @@ NAN_METHOD(MetadataKeyIsBinary) { "metadataKeyIsLegal's argument must be a string"); } Local key = Nan::To(info[0]).ToLocalChecked(); + Nan::Utf8String key_utf8_str(key); + char *key_str = *key_utf8_str; info.GetReturnValue().Set(static_cast( - grpc_is_binary_header(CreateSliceFromString(key)))); + grpc_is_binary_header(key_str, static_cast(key->Length())))); } static grpc_ssl_roots_override_result get_ssl_roots_override( diff --git a/src/node/ext/server.cc b/src/node/ext/server.cc index 4761b2867db..70d5b96f397 100644 --- a/src/node/ext/server.cc +++ b/src/node/ext/server.cc @@ -46,7 +46,6 @@ #include "grpc/grpc_security.h" #include "grpc/support/log.h" #include "server_credentials.h" -#include "slice.h" #include "timeval.h" namespace grpc { @@ -100,11 +99,10 @@ class NewCallOp : public Op { } Local obj = Nan::New(); Nan::Set(obj, Nan::New("call").ToLocalChecked(), Call::WrapStruct(call)); - // TODO(murgatroid99): Use zero-copy string construction instead Nan::Set(obj, Nan::New("method").ToLocalChecked(), - CopyStringFromSlice(details.method)); + Nan::New(details.method).ToLocalChecked()); Nan::Set(obj, Nan::New("host").ToLocalChecked(), - CopyStringFromSlice(details.host)); + Nan::New(details.host).ToLocalChecked()); Nan::Set(obj, Nan::New("deadline").ToLocalChecked(), Nan::New(TimespecToMilliseconds(details.deadline)) .ToLocalChecked()); @@ -113,7 +111,8 @@ class NewCallOp : public Op { return scope.Escape(obj); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { return true; } bool IsFinalOp() { @@ -140,7 +139,8 @@ class ServerShutdownOp : public Op { return Nan::New(reinterpret_cast(server)); } - bool ParseOp(Local value, grpc_op *out) { + bool ParseOp(Local value, grpc_op *out, + shared_ptr resources) { return true; } bool IsFinalOp() { @@ -207,7 +207,8 @@ void Server::ShutdownServer() { grpc_server_shutdown_and_notify( this->wrapped_server, GetCompletionQueue(), - new struct tag(new Callback(**shutdown_callback), ops.release(), NULL)); + new struct tag(new Callback(**shutdown_callback), ops.release(), + shared_ptr(nullptr), NULL)); grpc_server_cancel_all_calls(this->wrapped_server); CompletionQueueNext(); this->wrapped_server = NULL; @@ -260,7 +261,7 @@ NAN_METHOD(Server::RequestCall) { GetCompletionQueue(), GetCompletionQueue(), new struct tag(new Callback(info[0].As()), ops.release(), - NULL)); + shared_ptr(nullptr), NULL)); if (error != GRPC_CALL_OK) { return Nan::ThrowError(nanErrorWithCode("requestCall failed", error)); } @@ -313,7 +314,7 @@ NAN_METHOD(Server::TryShutdown) { grpc_server_shutdown_and_notify( server->wrapped_server, GetCompletionQueue(), new struct tag(new Nan::Callback(info[0].As()), ops.release(), - NULL)); + shared_ptr(nullptr), NULL)); CompletionQueueNext(); } diff --git a/src/node/ext/slice.cc b/src/node/ext/slice.cc deleted file mode 100644 index 98a80b3d2f9..00000000000 --- a/src/node/ext/slice.cc +++ /dev/null @@ -1,102 +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. - * - */ - -#include -#include -#include -#include - -#include "slice.h" -#include "byte_buffer.h" - -namespace grpc { -namespace node { - -using Nan::Persistent; - -using v8::Local; -using v8::String; -using v8::Value; - -namespace { -void SliceFreeCallback(char *data, void *hint) { - grpc_slice *slice = reinterpret_cast(hint); - grpc_slice_unref(*slice); - delete slice; -} - -void string_destroy_func(void *user_data) { - delete reinterpret_cast(user_data); -} - -void buffer_destroy_func(void *user_data) { - delete reinterpret_cast(user_data); -} -} // namespace - -grpc_slice CreateSliceFromString(const Local source) { - Nan::HandleScope scope; - Nan::Utf8String *utf8_value = new Nan::Utf8String(source); - return grpc_slice_new_with_user_data(**utf8_value, source->Length(), - string_destroy_func, utf8_value); -} - -grpc_slice CreateSliceFromBuffer(const Local source) { - // Prerequisite: ::node::Buffer::HasInstance(source) - Nan::HandleScope scope; - return grpc_slice_new_with_user_data(::node::Buffer::Data(source), - ::node::Buffer::Length(source), - buffer_destroy_func, - new PersistentValue(source)); -} -Local CopyStringFromSlice(const grpc_slice slice) { - Nan::EscapableHandleScope scope; - if (GRPC_SLICE_LENGTH(slice) == 0) { - return scope.Escape(Nan::EmptyString()); - } - return scope.Escape(Nan::New( - const_cast(reinterpret_cast(GRPC_SLICE_START_PTR(slice))), - GRPC_SLICE_LENGTH(slice)).ToLocalChecked()); -} - -Local CreateBufferFromSlice(const grpc_slice slice) { - Nan::EscapableHandleScope scope; - grpc_slice *slice_ptr = new grpc_slice; - *slice_ptr = grpc_slice_ref(slice); - return scope.Escape(MakeFastBuffer(Nan::NewBuffer( - const_cast(reinterpret_cast(GRPC_SLICE_START_PTR(*slice_ptr))), - GRPC_SLICE_LENGTH(*slice_ptr), SliceFreeCallback, slice_ptr).ToLocalChecked())); -} - -} // namespace node -} // namespace grpc diff --git a/src/node/ext/slice.h b/src/node/ext/slice.h deleted file mode 100644 index 7dcb1bd45a8..00000000000 --- a/src/node/ext/slice.h +++ /dev/null @@ -1,52 +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. - * - */ - -#include -#include -#include - -namespace grpc { -namespace node { - -typedef Nan::Persistent> PersistentValue; - -grpc_slice CreateSliceFromString(const v8::Local source); - -grpc_slice CreateSliceFromBuffer(const v8::Local source); - -v8::Local CopyStringFromSlice(const grpc_slice slice); - -v8::Local CreateBufferFromSlice(const grpc_slice slice); - -} // namespace node -} // namespace grpc diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.m b/src/objective-c/GRPCClient/private/GRPCChannel.m index c533c5ae711..2397c929f70 100644 --- a/src/objective-c/GRPCClient/private/GRPCChannel.m +++ b/src/objective-c/GRPCClient/private/GRPCChannel.m @@ -200,7 +200,7 @@ static grpc_channel_args *BuildChannelArgs(NSDictionary *dictionary) { return grpc_channel_create_call(_unmanagedChannel, NULL, GRPC_PROPAGATE_DEFAULTS, queue.unmanagedQueue, - grpc_slice_from_copied_string(path.UTF8String), + path.UTF8String, NULL, // Passing NULL for host gpr_inf_future(GPR_CLOCK_REALTIME), NULL); } diff --git a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m index 43c564552bf..38fcae0299d 100644 --- a/src/objective-c/GRPCClient/private/GRPCWrappedCall.m +++ b/src/objective-c/GRPCClient/private/GRPCWrappedCall.m @@ -194,7 +194,7 @@ @implementation GRPCOpRecvStatus{ grpc_status_code _statusCode; - grpc_slice _details; + char *_details; size_t _detailsCapacity; grpc_metadata_array _trailers; } @@ -208,6 +208,7 @@ _op.op = GRPC_OP_RECV_STATUS_ON_CLIENT; _op.data.recv_status_on_client.status = &_statusCode; _op.data.recv_status_on_client.status_details = &_details; + _op.data.recv_status_on_client.status_details_capacity = &_detailsCapacity; grpc_metadata_array_init(&_trailers); _op.data.recv_status_on_client.trailing_metadata = &_trailers; if (handler) { @@ -215,15 +216,11 @@ __weak typeof(self) weakSelf = self; _handler = ^{ __strong typeof(self) strongSelf = weakSelf; - if (strongSelf) { - char *details = grpc_slice_to_c_string(strongSelf->_details); - NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode - details:details]; - NSDictionary *trailers = [NSDictionary - grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; - handler(error, trailers); - gpr_free(details); - } + NSError *error = [NSError grpc_errorFromStatusCode:strongSelf->_statusCode + details:strongSelf->_details]; + NSDictionary *trailers = [NSDictionary + grpc_dictionaryFromMetadataArray:strongSelf->_trailers]; + handler(error, trailers); }; } } @@ -232,7 +229,7 @@ - (void)dealloc { grpc_metadata_array_destroy(&_trailers); - grpc_slice_unref(_details); + gpr_free(_details); } @end diff --git a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m index feb2bb5ed8f..7477da7619e 100644 --- a/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m +++ b/src/objective-c/GRPCClient/private/NSDictionary+GRPC.m @@ -47,12 +47,12 @@ @implementation NSData (GRPCMetadata) + (instancetype)grpc_dataFromMetadataValue:(grpc_metadata *)metadata { // TODO(jcanizales): Should we use a non-copy constructor? - return [self dataWithBytes:GRPC_SLICE_START_PTR(metadata->value) - length:GRPC_SLICE_LENGTH(metadata->value)]; + return [self dataWithBytes:metadata->value length:metadata->value_length]; } - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = grpc_slice_from_copied_buffer(self.bytes, self.length); + metadata->value = self.bytes; + metadata->value_length = self.length; } @end @@ -67,14 +67,15 @@ @implementation NSString (GRPCMetadata) + (instancetype)grpc_stringFromMetadataValue:(grpc_metadata *)metadata { - return [[self alloc] initWithBytes:GRPC_SLICE_START_PTR(metadata->value) - length:GRPC_SLICE_LENGTH(metadata->value) + return [[self alloc] initWithBytes:metadata->value + length:metadata->value_length encoding:NSASCIIStringEncoding]; } // Precondition: This object contains only ASCII characters. - (void)grpc_initMetadata:(grpc_metadata *)metadata { - metadata->value = grpc_slice_from_copied_string(self.UTF8String); + metadata->value = self.UTF8String; + metadata->value_length = self.length; } @end @@ -88,10 +89,7 @@ + (instancetype)grpc_dictionaryFromMetadata:(grpc_metadata *)entries count:(size_t)count { NSMutableDictionary *metadata = [NSMutableDictionary dictionaryWithCapacity:count]; for (grpc_metadata *entry = entries; entry < entries + count; entry++) { - char *key = grpc_slice_to_c_string(entry->key); - NSString *name = [NSString stringWithCString:key - encoding:NSASCIIStringEncoding]; - gpr_free(key); + NSString *name = [NSString stringWithCString:entry->key encoding:NSASCIIStringEncoding]; if (!name || metadata[name]) { // Log if name is nil? continue; @@ -114,7 +112,7 @@ grpc_metadata *current = metadata; for (NSString* key in self) { id value = self[key]; - current->key = grpc_slice_from_copied_string(key.UTF8String); + current->key = key.UTF8String; if ([value respondsToSelector:@selector(grpc_initMetadata:)]) { [value grpc_initMetadata:current]; } else { diff --git a/src/php/ext/grpc/call.c b/src/php/ext/grpc/call.c index 8a2070481e8..64b1137c2a4 100644 --- a/src/php/ext/grpc/call.c +++ b/src/php/ext/grpc/call.c @@ -100,11 +100,11 @@ zval *grpc_parse_metadata_array(grpc_metadata_array grpc_metadata *elem; for (i = 0; i < count; i++) { elem = &elements[i]; - key_len = GRPC_SLICE_LENGTH(elem->key); + key_len = strlen(elem->key); str_key = ecalloc(key_len + 1, sizeof(char)); - memcpy(str_key, GRPC_SLICE_START_PTR(elem->key), key_len); - str_val = ecalloc(GRPC_SLICE_LENGTH(elem->value) + 1, sizeof(char)); - memcpy(str_val, GRPC_SLICE_START_PTR(elem->value), GRPC_SLICE_LENGTH(elem->value)); + memcpy(str_key, elem->key, key_len); + str_val = ecalloc(elem->value_length + 1, sizeof(char)); + memcpy(str_val, elem->value, elem->value_length); if (php_grpc_zend_hash_find(array_hash, str_key, key_len, (void **)&data) == SUCCESS) { if (Z_TYPE_P(data) != IS_ARRAY) { @@ -115,13 +115,13 @@ zval *grpc_parse_metadata_array(grpc_metadata_array efree(str_val); return NULL; } - php_grpc_add_next_index_stringl(data, str_val, GRPC_SLICE_LENGTH(elem->value), + php_grpc_add_next_index_stringl(data, str_val, elem->value_length, false); } else { PHP_GRPC_MAKE_STD_ZVAL(inner_array); array_init(inner_array); php_grpc_add_next_index_stringl(inner_array, str_val, - GRPC_SLICE_LENGTH(elem->value), false); + elem->value_length, false); add_assoc_zval(array, str_key, inner_array); } } @@ -164,7 +164,7 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { if (key_type1 != HASH_KEY_IS_STRING) { return false; } - if (!grpc_header_key_is_legal(grpc_slice_from_static_string(key1))) { + if (!grpc_header_key_is_legal(key1, strlen(key1))) { return false; } inner_array_hash = Z_ARRVAL_P(inner_array); @@ -172,8 +172,9 @@ bool create_metadata_array(zval *array, grpc_metadata_array *metadata) { if (Z_TYPE_P(value) != IS_STRING) { return false; } - metadata->metadata[metadata->count].key = grpc_slice_from_copied_string(key1); - metadata->metadata[metadata->count].value = grpc_slice_from_copied_buffer(Z_STRVAL_P(value), Z_STRLEN_P(value)); + metadata->metadata[metadata->count].key = key1; + metadata->metadata[metadata->count].value = Z_STRVAL_P(value); + metadata->metadata[metadata->count].value_length = Z_STRLEN_P(value); metadata->count += 1; PHP_GRPC_HASH_FOREACH_END() PHP_GRPC_HASH_FOREACH_END() @@ -228,15 +229,10 @@ PHP_METHOD(Call, __construct) { } add_property_zval(getThis(), "channel", channel_obj); wrapped_grpc_timeval *deadline = Z_WRAPPED_GRPC_TIMEVAL_P(deadline_obj); - grpc_slice method_slice = grpc_slice_from_copied_string(method); - grpc_slice host_slice = host_override != NULL ? - grpc_slice_from_copied_string(host_override) : grpc_empty_slice(); call->wrapped = grpc_channel_create_call(channel->wrapped, NULL, GRPC_PROPAGATE_DEFAULTS, - completion_queue, method_slice, host_override != NULL ? &host_slice : NULL, + completion_queue, method, host_override, deadline->wrapped, NULL); - grpc_slice_unref(method_slice); - grpc_slice_unref(host_slice); call->owned = true; } @@ -271,8 +267,8 @@ PHP_METHOD(Call, startBatch) { grpc_metadata_array recv_metadata; grpc_metadata_array recv_trailing_metadata; grpc_status_code status; - grpc_slice recv_status_details = grpc_empty_slice(); - grpc_slice send_status_details = grpc_empty_slice(); + char *status_details = NULL; + size_t status_details_capacity = 0; grpc_byte_buffer *message; int cancelled; grpc_call_error error; @@ -384,8 +380,8 @@ PHP_METHOD(Call, startBatch) { 1 TSRMLS_CC); goto cleanup; } - send_status_details = grpc_slice_from_copied_string(Z_STRVAL_P(inner_value)); - ops[op_num].data.send_status_from_server.status_details = &send_status_details; + ops[op_num].data.send_status_from_server.status_details = + Z_STRVAL_P(inner_value); } else { zend_throw_exception(spl_ce_InvalidArgumentException, "String status details is required", @@ -404,7 +400,9 @@ PHP_METHOD(Call, startBatch) { &recv_trailing_metadata; ops[op_num].data.recv_status_on_client.status = &status; ops[op_num].data.recv_status_on_client.status_details = - &recv_status_details; + &status_details; + ops[op_num].data.recv_status_on_client.status_details_capacity = + &status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: ops[op_num].data.recv_close_on_server.cancelled = &cancelled; @@ -476,10 +474,8 @@ PHP_METHOD(Call, startBatch) { #endif PHP_GRPC_DELREF(array); add_property_long(recv_status, "code", status); - char *status_details_text = grpc_slice_to_c_string(recv_status_details); - php_grpc_add_property_string(recv_status, "details", status_details_text, + php_grpc_add_property_string(recv_status, "details", status_details, true); - gpr_free(status_details_text); add_property_zval(result, "status", recv_status); PHP_GRPC_DELREF(recv_status); PHP_GRPC_FREE_STD_ZVAL(recv_status); @@ -497,8 +493,9 @@ cleanup: grpc_metadata_array_destroy(&trailing_metadata); grpc_metadata_array_destroy(&recv_metadata); grpc_metadata_array_destroy(&recv_trailing_metadata); - grpc_slice_unref(recv_status_details); - grpc_slice_unref(send_status_details); + if (status_details != NULL) { + gpr_free(status_details); + } for (int i = 0; i < op_num; i++) { if (ops[i].op == GRPC_OP_SEND_MESSAGE) { grpc_byte_buffer_destroy(ops[i].data.send_message); diff --git a/src/php/ext/grpc/server.c b/src/php/ext/grpc/server.c index 9ac5d2a3c39..2217a4f9a81 100644 --- a/src/php/ext/grpc/server.c +++ b/src/php/ext/grpc/server.c @@ -49,8 +49,6 @@ #include #include -#include -#include #include "completion_queue.h" #include "server.h" @@ -151,12 +149,8 @@ PHP_METHOD(Server, requestCall) { 1 TSRMLS_CC); goto cleanup; } - char *method_text = grpc_slice_to_c_string(details.method); - char *host_text = grpc_slice_to_c_string(details.host); - php_grpc_add_property_string(result, "method", method_text, true); - php_grpc_add_property_string(result, "host", host_text, true); - gpr_free(method_text); - gpr_free(host_text); + php_grpc_add_property_string(result, "method", details.method, true); + php_grpc_add_property_string(result, "host", details.host, true); #if PHP_MAJOR_VERSION < 7 add_property_zval(result, "call", grpc_php_wrap_call(call, true TSRMLS_CC)); add_property_zval(result, "absolute_deadline", diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi index 246e8399bc9..73d1ff7b97d 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/channel.pyx.pxi @@ -60,25 +60,20 @@ cdef class Channel: method, host, Timespec deadline not None): if queue.is_shutting_down: raise ValueError("queue must not be shutting down or shutdown") - cdef grpc_slice method_slice = _slice_from_bytes(method) - cdef grpc_slice host_slice - cdef grpc_slice *host_slice_ptr = NULL + cdef char *method_c_string = method + cdef char *host_c_string = NULL if host is not None: - host_slice = _slice_from_bytes(host) - host_slice_ptr = &host_slice + host_c_string = host cdef Call operation_call = Call() - operation_call.references = [self, queue] + operation_call.references = [self, method, host, queue] cdef grpc_call *parent_call = NULL if parent is not None: parent_call = parent.c_call with nogil: operation_call.c_call = grpc_channel_create_call( self.c_channel, parent_call, flags, - queue.c_completion_queue, method_slice, host_slice_ptr, + queue.c_completion_queue, method_c_string, host_c_string, deadline.c_time, NULL) - grpc_slice_unref(method_slice) - if host_slice_ptr: - grpc_slice_unref(host_slice) return operation_call def check_connectivity_state(self, bint try_to_connect): diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi index d8df6c2ef40..a258ba40639 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/completion_queue.pyx.pxi @@ -51,7 +51,6 @@ cdef class CompletionQueue: cdef CallDetails request_call_details = None cdef Metadata request_metadata = None cdef Operations batch_operations = None - cdef Operation batch_operation = None if event.type == GRPC_QUEUE_TIMEOUT: return Event( event.type, False, None, None, None, None, False, None) @@ -70,15 +69,8 @@ cdef class CompletionQueue: user_tag = tag.user_tag operation_call = tag.operation_call request_call_details = tag.request_call_details - if tag.request_metadata is not None: - request_metadata = tag.request_metadata - request_metadata._claim_slice_ownership() + request_metadata = tag.request_metadata batch_operations = tag.batch_operations - if tag.batch_operations is not None: - for op in batch_operations.operations: - batch_operation = op - if batch_operation._received_metadata is not None: - batch_operation._received_metadata._claim_slice_ownership() if tag.is_new_request: # Stuff in the tag not explicitly handled by us needs to live through # the life of the call @@ -99,7 +91,7 @@ cdef class CompletionQueue: c_deadline = gpr_inf_future(GPR_CLOCK_REALTIME) if deadline is not None: c_deadline = deadline.c_time - + while True: c_timeout = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), c_increment) if gpr_time_cmp(c_timeout, c_deadline) > 0: @@ -108,7 +100,7 @@ cdef class CompletionQueue: self.c_completion_queue, c_timeout, NULL) if event.type != GRPC_QUEUE_TIMEOUT or gpr_time_cmp(c_timeout, c_deadline) == 0: break; - + # Handle any signals with gil: cpython.PyErr_CheckSignals() diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi index 141580b82ad..ad766186bd1 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/grpc.pxi @@ -51,13 +51,6 @@ cdef extern from "grpc/byte_buffer_reader.h": pass -cdef extern from "grpc/impl/codegen/exec_ctx_fwd.h": - - struct grpc_exec_ctx: - # We don't care about the internals - pass - - cdef extern from "grpc/grpc.h": ctypedef struct grpc_slice: @@ -67,7 +60,6 @@ cdef extern from "grpc/grpc.h": grpc_slice grpc_slice_ref(grpc_slice s) nogil void grpc_slice_unref(grpc_slice s) nogil - grpc_slice grpc_empty_slice() nogil grpc_slice grpc_slice_new(void *p, size_t len, void (*destroy)(void *)) nogil grpc_slice grpc_slice_new_with_len( void *p, size_t len, void (*destroy)(void *, size_t)) nogil @@ -183,7 +175,7 @@ cdef extern from "grpc/grpc.h": ctypedef struct grpc_arg_pointer_vtable: void *(*copy)(void *) - void (*destroy)(grpc_exec_ctx *, void *) + void (*destroy)(void *) int (*cmp)(void *, void *) ctypedef struct grpc_arg_value_pointer: @@ -225,8 +217,9 @@ cdef extern from "grpc/grpc.h": GRPC_CHANNEL_SHUTDOWN ctypedef struct grpc_metadata: - grpc_slice key - grpc_slice value + const char *key + const char *value + size_t value_length # ignore the 'internal_data.obfuscated' fields. ctypedef enum grpc_completion_type: @@ -248,8 +241,10 @@ cdef extern from "grpc/grpc.h": void grpc_metadata_array_destroy(grpc_metadata_array *array) nogil ctypedef struct grpc_call_details: - grpc_slice method - grpc_slice host + char *method + size_t method_capacity + char *host + size_t host_capacity gpr_timespec deadline void grpc_call_details_init(grpc_call_details *details) nogil @@ -273,12 +268,13 @@ cdef extern from "grpc/grpc.h": size_t trailing_metadata_count grpc_metadata *trailing_metadata grpc_status_code status - grpc_slice *status_details + const char *status_details ctypedef struct grpc_op_data_recv_status_on_client: grpc_metadata_array *trailing_metadata grpc_status_code *status - grpc_slice *status_details + char **status_details + size_t *status_details_capacity ctypedef struct grpc_op_data_recv_close_on_server: int *cancelled @@ -325,9 +321,9 @@ cdef extern from "grpc/grpc.h": const grpc_channel_args *args, void *reserved) nogil grpc_call *grpc_channel_create_call( - grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, - grpc_completion_queue *completion_queue, grpc_slice method, - const grpc_slice *host, gpr_timespec deadline, void *reserved) nogil + grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, + grpc_completion_queue *completion_queue, const char *method, + const char *host, gpr_timespec deadline, void *reserved) nogil grpc_connectivity_state grpc_channel_check_connectivity_state( grpc_channel *channel, int try_to_connect) nogil void grpc_channel_watch_connectivity_state( @@ -477,7 +473,8 @@ cdef extern from "grpc/compression.h": grpc_compression_algorithm default_compression_algorithm int grpc_compression_algorithm_parse( - grpc_slice value, grpc_compression_algorithm *algorithm) nogil + const char *name, size_t name_length, + grpc_compression_algorithm *algorithm) nogil int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, char **name) nogil grpc_compression_algorithm grpc_compression_algorithm_for_level( diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi index c4a17118c0e..00ec91b131e 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pxd.pxi @@ -28,11 +28,6 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -cdef bytes _slice_bytes(grpc_slice slice) -cdef grpc_slice _copy_slice(grpc_slice slice) nogil -cdef grpc_slice _slice_from_bytes(bytes value) nogil - - cdef class Timespec: cdef gpr_timespec c_time @@ -102,13 +97,13 @@ cdef class ChannelArgs: cdef class Metadatum: cdef grpc_metadata c_metadata - cdef void _copy_metadatum(self, grpc_metadata *destination) nogil + cdef object _key, _value cdef class Metadata: cdef grpc_metadata_array c_metadata_array - cdef void _claim_slice_ownership(self) + cdef object metadata cdef class Operation: @@ -117,7 +112,8 @@ cdef class Operation: cdef ByteBuffer _received_message cdef Metadata _received_metadata cdef grpc_status_code _received_status_code - cdef grpc_slice _status_details + cdef char *_received_status_details + cdef size_t _received_status_details_capacity cdef int _received_cancelled cdef readonly bint is_valid cdef object references diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi index d052b3f8bc9..cadfce6ee6b 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/records.pyx.pxi @@ -29,26 +29,6 @@ from libc.stdint cimport intptr_t - -cdef bytes _slice_bytes(grpc_slice slice): - cdef void *start = grpc_slice_start_ptr(slice) - cdef size_t length = grpc_slice_length(slice) - return (start)[:length] - -cdef grpc_slice _copy_slice(grpc_slice slice) nogil: - cdef void *start = grpc_slice_start_ptr(slice) - cdef size_t length = grpc_slice_length(slice) - return grpc_slice_from_copied_buffer(start, length) - -cdef grpc_slice _slice_from_bytes(bytes value) nogil: - cdef const char *value_ptr - cdef size_t length - with gil: - value_ptr = value - length = len(value) - return grpc_slice_from_copied_buffer(value_ptr, length) - - class ConnectivityState: idle = GRPC_CHANNEL_IDLE connecting = GRPC_CHANNEL_CONNECTING @@ -209,11 +189,17 @@ cdef class CallDetails: @property def method(self): - return _slice_bytes(self.c_details.method) + if self.c_details.method != NULL: + return self.c_details.method + else: + return None @property def host(self): - return _slice_bytes(self.c_details.host) + if self.c_details.host != NULL: + return self.c_details.host + else: + return None @property def deadline(self): @@ -324,7 +310,7 @@ cdef void* copy_ptr(void* ptr): return ptr -cdef void destroy_ptr(grpc_exec_ctx* ctx, void* ptr): +cdef void destroy_ptr(void* ptr): pass @@ -397,20 +383,19 @@ cdef class ChannelArgs: cdef class Metadatum: def __cinit__(self, bytes key, bytes value): - self.c_metadata.key = _slice_from_bytes(key) - self.c_metadata.value = _slice_from_bytes(value) - - cdef void _copy_metadatum(self, grpc_metadata *destination) nogil: - destination[0].key = _copy_slice(self.c_metadata.key) - destination[0].value = _copy_slice(self.c_metadata.value) + self._key = key + self._value = value + self.c_metadata.key = self._key + self.c_metadata.value = self._value + self.c_metadata.value_length = len(self._value) @property def key(self): - return _slice_bytes(self.c_metadata.key) + return self.c_metadata.key @property def value(self): - return _slice_bytes(self.c_metadata.value) + return self.c_metadata.value[:self.c_metadata.value_length] def __len__(self): return 2 @@ -426,9 +411,6 @@ cdef class Metadatum: def __iter__(self): return iter((self.key, self.value)) - def __dealloc__(self): - grpc_slice_unref(self.c_metadata.key) - grpc_slice_unref(self.c_metadata.value) cdef class _MetadataIterator: @@ -453,65 +435,51 @@ cdef class _MetadataIterator: cdef class Metadata: - def __cinit__(self, metadata_iterable): - with nogil: - grpc_init() - grpc_metadata_array_init(&self.c_metadata_array) - metadata = list(metadata_iterable) + def __cinit__(self, metadata): + grpc_init() + self.metadata = list(metadata) for metadatum in metadata: if not isinstance(metadatum, Metadatum): raise TypeError("expected list of Metadatum") - self.c_metadata_array.count = len(metadata) - self.c_metadata_array.capacity = len(metadata) + with nogil: + grpc_metadata_array_init(&self.c_metadata_array) + self.c_metadata_array.count = len(self.metadata) + self.c_metadata_array.capacity = len(self.metadata) with nogil: self.c_metadata_array.metadata = gpr_malloc( self.c_metadata_array.count*sizeof(grpc_metadata) ) for i in range(self.c_metadata_array.count): - (metadata[i])._copy_metadatum(&self.c_metadata_array.metadata[i]) + self.c_metadata_array.metadata[i] = ( + (self.metadata[i]).c_metadata) def __dealloc__(self): - with nogil: - # this frees the allocated memory for the grpc_metadata_array (although - # it'd be nice if that were documented somewhere...) - # TODO(atash): document this in the C core - grpc_metadata_array_destroy(&self.c_metadata_array) - grpc_shutdown() + # this frees the allocated memory for the grpc_metadata_array (although + # it'd be nice if that were documented somewhere...) + # TODO(atash): document this in the C core + grpc_metadata_array_destroy(&self.c_metadata_array) + grpc_shutdown() def __len__(self): return self.c_metadata_array.count def __getitem__(self, size_t i): - if i >= self.c_metadata_array.count: - raise IndexError - key = _slice_bytes(self.c_metadata_array.metadata[i].key) - value = _slice_bytes(self.c_metadata_array.metadata[i].value) - return Metadatum(key=key, value=value) + return Metadatum( + key=self.c_metadata_array.metadata[i].key, + value=self.c_metadata_array.metadata[i].value[ + :self.c_metadata_array.metadata[i].value_length]) def __iter__(self): return _MetadataIterator(self) - cdef void _claim_slice_ownership(self): - cdef grpc_metadata_array new_c_metadata_array - grpc_metadata_array_init(&new_c_metadata_array) - new_c_metadata_array.metadata = gpr_malloc( - self.c_metadata_array.count*sizeof(grpc_metadata)) - new_c_metadata_array.count = self.c_metadata_array.count - for i in range(self.c_metadata_array.count): - new_c_metadata_array.metadata[i].key = _copy_slice( - self.c_metadata_array.metadata[i].key) - new_c_metadata_array.metadata[i].value = _copy_slice( - self.c_metadata_array.metadata[i].value) - grpc_metadata_array_destroy(&self.c_metadata_array) - self.c_metadata_array = new_c_metadata_array - cdef class Operation: def __cinit__(self): grpc_init() self.references = [] - self._status_details = grpc_empty_slice() + self._received_status_details = NULL + self._received_status_details_capacity = 0 self.is_valid = False @property @@ -568,13 +536,19 @@ cdef class Operation: def received_status_details(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: raise TypeError("self must be an operation receiving status details") - return _slice_bytes(self._status_details) + if self._received_status_details: + return self._received_status_details + else: + return None @property def received_status_details_or_none(self): if self.c_op.type != GRPC_OP_RECV_STATUS_ON_CLIENT: return None - return _slice_bytes(self._status_details) + if self._received_status_details: + return self._received_status_details + else: + return None @property def received_cancelled(self): @@ -590,7 +564,11 @@ cdef class Operation: return False if self._received_cancelled == 0 else True def __dealloc__(self): - grpc_slice_unref(self._status_details) + # We *almost* don't need to do anything; most of the objects are handled by + # Python. The remaining one(s) are primitive fields filled in by GRPC core. + # This means that we need to clean up after receive_status_on_client. + if self.c_op.type == GRPC_OP_RECV_STATUS_ON_CLIENT: + gpr_free(self._received_status_details) grpc_shutdown() def operation_send_initial_metadata(Metadata metadata, int flags): @@ -631,10 +609,9 @@ def operation_send_status_from_server( op.c_op.data.send_status_from_server.trailing_metadata = ( metadata.c_metadata_array.metadata) op.c_op.data.send_status_from_server.status = code - grpc_slice_unref(op._status_details) - op._status_details = _slice_from_bytes(details) - op.c_op.data.send_status_from_server.status_details = &op._status_details + op.c_op.data.send_status_from_server.status_details = details op.references.append(metadata) + op.references.append(details) op.is_valid = True return op @@ -670,7 +647,9 @@ def operation_receive_status_on_client(int flags): op.c_op.data.receive_status_on_client.status = ( &op._received_status_code) op.c_op.data.receive_status_on_client.status_details = ( - &op._status_details) + &op._received_status_details) + op.c_op.data.receive_status_on_client.status_details_capacity = ( + &op._received_status_details_capacity) op.is_valid = True return op diff --git a/src/python/grpcio/grpc/_server.py b/src/python/grpcio/grpc/_server.py index 31551e0f1bd..cbbe2dcbf5d 100644 --- a/src/python/grpcio/grpc/_server.py +++ b/src/python/grpcio/grpc/_server.py @@ -592,8 +592,6 @@ def _handle_with_method_handler(rpc_event, method_handler, thread_pool): def _handle_call(rpc_event, generic_handlers, thread_pool): - if not rpc_event.success: - return None if rpc_event.request_call_details.method is not None: method_handler = _find_method_handler(rpc_event, generic_handlers) if method_handler is None: diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 0b86661db87..ba641748634 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -159,8 +159,6 @@ CORE_SOURCE_FILES = [ 'src/core/lib/slice/percent_encoding.c', 'src/core/lib/slice/slice.c', 'src/core/lib/slice/slice_buffer.c', - 'src/core/lib/slice/slice_hash_table.c', - 'src/core/lib/slice/slice_intern.c', 'src/core/lib/slice/slice_string_helpers.c', 'src/core/lib/surface/alarm.c', 'src/core/lib/surface/api_trace.c', @@ -182,13 +180,12 @@ CORE_SOURCE_FILES = [ 'src/core/lib/surface/version.c', 'src/core/lib/transport/byte_stream.c', 'src/core/lib/transport/connectivity_state.c', - 'src/core/lib/transport/error_utils.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/pid_controller.c', 'src/core/lib/transport/service_config.c', 'src/core/lib/transport/static_metadata.c', - 'src/core/lib/transport/status_conversion.c', 'src/core/lib/transport/timeout_encoding.c', 'src/core/lib/transport/transport.c', 'src/core/lib/transport/transport_op_string.c', @@ -209,6 +206,7 @@ CORE_SOURCE_FILES = [ 'src/core/ext/transport/chttp2/transport/huffsyms.c', 'src/core/ext/transport/chttp2/transport/incoming_metadata.c', 'src/core/ext/transport/chttp2/transport/parsing.c', + 'src/core/ext/transport/chttp2/transport/status_conversion.c', 'src/core/ext/transport/chttp2/transport/stream_lists.c', 'src/core/ext/transport/chttp2/transport/stream_map.c', 'src/core/ext/transport/chttp2/transport/varint.c', diff --git a/src/ruby/ext/grpc/rb_byte_buffer.c b/src/ruby/ext/grpc/rb_byte_buffer.c index 65fa2f2cf62..47fd6d91200 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.c +++ b/src/ruby/ext/grpc/rb_byte_buffer.c @@ -68,10 +68,3 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) { grpc_byte_buffer_reader_destroy(&reader); return rb_string; } - -VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice) { - if (GRPC_SLICE_START_PTR(slice) == NULL) { - rb_raise(rb_eRuntimeError, "attempt to convert uninitialized grpc_slice to ruby string"); - } - return rb_str_new((char*)GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice)); -} diff --git a/src/ruby/ext/grpc/rb_byte_buffer.h b/src/ruby/ext/grpc/rb_byte_buffer.h index fac68fe6a00..c7ddd764890 100644 --- a/src/ruby/ext/grpc/rb_byte_buffer.h +++ b/src/ruby/ext/grpc/rb_byte_buffer.h @@ -44,7 +44,4 @@ grpc_byte_buffer *grpc_rb_s_to_byte_buffer(char *string, size_t length); /* Converts a grpc_byte_buffer to a ruby string */ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer); -/* Converts a grpc_slice to a ruby string */ -VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice); - #endif /* GRPC_RB_BYTE_BUFFER_H_ */ diff --git a/src/ruby/ext/grpc/rb_call.c b/src/ruby/ext/grpc/rb_call.c index 0179bd9e9b2..67a42af619b 100644 --- a/src/ruby/ext/grpc/rb_call.c +++ b/src/ruby/ext/grpc/rb_call.c @@ -121,8 +121,8 @@ static size_t md_ary_datasize(const void *p) { size_t i, datasize = sizeof(grpc_metadata_array); for (i = 0; i < ary->count; ++i) { const grpc_metadata *const md = &ary->metadata[i]; - datasize += GRPC_SLICE_LENGTH(md->key); - datasize += GRPC_SLICE_LENGTH(md->value); + datasize += strlen(md->key); + datasize += md->value_length; } datasize += ary->capacity * sizeof(grpc_metadata); return datasize; @@ -386,23 +386,23 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { grpc_metadata_array *md_ary = NULL; long array_length; long i; - grpc_slice key_slice; - grpc_slice value_slice; - char* tmp_str; + char *key_str; + size_t key_len; + char *value_str; + size_t value_len; if (TYPE(key) == T_SYMBOL) { - key_slice = grpc_slice_from_static_string(rb_id2name(SYM2ID(key))); - } else if (TYPE(key) == T_STRING) { - key_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(key), RSTRING_LEN(key)); - } else { - rb_raise(rb_eTypeError, "grpc_rb_md_ary_fill_hash_cb: bad type for key parameter"); + key_str = (char *)rb_id2name(SYM2ID(key)); + key_len = strlen(key_str); + } else { /* StringValueCStr does all other type exclusions for us */ + key_str = StringValueCStr(key); + key_len = RSTRING_LEN(key); } - if (!grpc_header_key_is_legal(key_slice)) { - tmp_str = grpc_slice_to_c_string(key_slice); + if (!grpc_header_key_is_legal(key_str, key_len)) { rb_raise(rb_eArgError, "'%s' is an invalid header key, must match [a-z0-9-_.]+", - tmp_str); + key_str); return ST_STOP; } @@ -414,31 +414,33 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) { array_length = RARRAY_LEN(val); /* If the value is an array, add capacity for each value in the array */ for (i = 0; i < array_length; i++) { - value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(rb_ary_entry(val, i)), RSTRING_LEN(rb_ary_entry(val, i))); - if (!grpc_is_binary_header(key_slice) && - !grpc_header_nonbin_value_is_legal(value_slice)) { + value_str = RSTRING_PTR(rb_ary_entry(val, i)); + value_len = RSTRING_LEN(rb_ary_entry(val, i)); + if (!grpc_is_binary_header(key_str, key_len) && + !grpc_header_nonbin_value_is_legal(value_str, value_len)) { // The value has invalid characters - tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", tmp_str); + "Header value '%s' has invalid characters", value_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_slice; - md_ary->metadata[md_ary->count].value = value_slice; + md_ary->metadata[md_ary->count].key = key_str; + md_ary->metadata[md_ary->count].value = value_str; + md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; } } else if (TYPE(val) == T_STRING) { - value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(val), RSTRING_LEN(val)); - if (!grpc_is_binary_header(key_slice) && - !grpc_header_nonbin_value_is_legal(value_slice)) { + value_str = RSTRING_PTR(val); + value_len = RSTRING_LEN(val); + if (!grpc_is_binary_header(key_str, key_len) && + !grpc_header_nonbin_value_is_legal(value_str, value_len)) { // The value has invalid characters - tmp_str = grpc_slice_to_c_string(value_slice); rb_raise(rb_eArgError, - "Header value '%s' has invalid characters", tmp_str); + "Header value '%s' has invalid characters", value_str); return ST_STOP; } - md_ary->metadata[md_ary->count].key = key_slice; - md_ary->metadata[md_ary->count].value = value_slice; + md_ary->metadata[md_ary->count].key = key_str; + md_ary->metadata[md_ary->count].value = value_str; + md_ary->metadata[md_ary->count].value_length = value_len; md_ary->count += 1; } else { rb_raise(rb_eArgError, @@ -504,19 +506,22 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary) { size_t i; for (i = 0; i < md_ary->count; i++) { - key = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].key); + key = rb_str_new2(md_ary->metadata[i].key); value = rb_hash_aref(result, key); if (value == Qnil) { - value = grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value); + value = rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length); rb_hash_aset(result, key, value); } else if (TYPE(value) == T_ARRAY) { /* Add the string to the returned array */ - rb_ary_push(value, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); + rb_ary_push(value, rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length)); } else { /* Add the current value with this key and the new one to an array */ new_ary = rb_ary_new(); rb_ary_push(new_ary, value); - rb_ary_push(new_ary, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value)); + rb_ary_push(new_ary, rb_str_new(md_ary->metadata[i].value, + md_ary->metadata[i].value_length)); rb_hash_aset(result, key, new_ary); } } @@ -558,7 +563,6 @@ static int grpc_rb_call_check_op_keys_hash_cb(VALUE key, VALUE val, */ static void grpc_rb_op_update_status_from_server(grpc_op *op, grpc_metadata_array *md_ary, - grpc_slice *send_status_details, VALUE status) { VALUE code = rb_struct_aref(status, sym_code); VALUE details = rb_struct_aref(status, sym_details); @@ -575,11 +579,8 @@ static void grpc_rb_op_update_status_from_server(grpc_op *op, rb_obj_classname(code)); return; } - - *send_status_details = grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details)); - op->data.send_status_from_server.status = NUM2INT(code); - op->data.send_status_from_server.status_details = send_status_details; + op->data.send_status_from_server.status_details = StringValueCStr(details); grpc_rb_md_ary_convert(metadata_hash, md_ary); op->data.send_status_from_server.trailing_metadata_count = md_ary->count; op->data.send_status_from_server.trailing_metadata = md_ary->metadata; @@ -602,9 +603,9 @@ typedef struct run_batch_stack { grpc_metadata_array recv_trailing_metadata; int recv_cancelled; grpc_status_code recv_status; - grpc_slice recv_status_details; + char *recv_status_details; + size_t recv_status_details_capacity; unsigned write_flag; - grpc_slice send_status_details; } run_batch_stack; /* grpc_run_batch_stack_init ensures the run_batch_stack is properly @@ -630,12 +631,8 @@ static void grpc_run_batch_stack_cleanup(run_batch_stack *st) { grpc_metadata_array_destroy(&st->recv_metadata); grpc_metadata_array_destroy(&st->recv_trailing_metadata); - if (GRPC_SLICE_START_PTR(st->send_status_details) != NULL) { - grpc_slice_unref(st->send_status_details); - } - - if (GRPC_SLICE_START_PTR(st->recv_status_details) != NULL) { - grpc_slice_unref(st->recv_status_details); + if (st->recv_status_details != NULL) { + gpr_free(st->recv_status_details); } if (st->recv_message != NULL) { @@ -686,7 +683,7 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { /* N.B. later there is no need to explicitly delete the metadata keys * and values, they are references to data in ruby objects. */ grpc_rb_op_update_status_from_server( - &st->ops[st->op_num], &st->send_trailing_metadata, &st->send_status_details, this_value); + &st->ops[st->op_num], &st->send_trailing_metadata, this_value); break; case GRPC_OP_RECV_INITIAL_METADATA: st->ops[st->op_num].data.recv_initial_metadata = &st->recv_metadata; @@ -701,6 +698,8 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) { &st->recv_status; st->ops[st->op_num].data.recv_status_on_client.status_details = &st->recv_status_details; + st->ops[st->op_num].data.recv_status_on_client.status_details_capacity = + &st->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: st->ops[st->op_num].data.recv_close_on_server.cancelled = @@ -748,9 +747,9 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) { rb_struct_aset( result, sym_status, rb_struct_new(grpc_rb_sStatus, UINT2NUM(st->recv_status), - (GRPC_SLICE_START_PTR(st->recv_status_details) == NULL + (st->recv_status_details == NULL ? Qnil - : grpc_rb_slice_to_ruby_string(st->recv_status_details)), + : rb_str_new2(st->recv_status_details)), grpc_rb_md_ary_to_h(&st->recv_trailing_metadata), NULL)); break; diff --git a/src/ruby/ext/grpc/rb_channel.c b/src/ruby/ext/grpc/rb_channel.c index 84e43d3f7bf..3b2b88eb774 100644 --- a/src/ruby/ext/grpc/rb_channel.c +++ b/src/ruby/ext/grpc/rb_channel.c @@ -35,7 +35,6 @@ #include "rb_grpc_imports.generated.h" #include "rb_channel.h" -#include "rb_byte_buffer.h" #include #include @@ -253,14 +252,10 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, grpc_channel *ch = NULL; grpc_completion_queue *cq = NULL; int flags = GRPC_PROPAGATE_DEFAULTS; - grpc_slice method_slice; - grpc_slice host_slice; - grpc_slice *host_slice_ptr = NULL; - char* tmp_str = NULL; - + char *method_chars = StringValueCStr(method); + char *host_chars = NULL; if (host != Qnil) { - host_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(host), RSTRING_LEN(host)); - host_slice_ptr = &host_slice; + host_chars = StringValueCStr(host); } if (mask != Qnil) { flags = NUM2UINT(mask); @@ -277,25 +272,15 @@ static VALUE grpc_rb_channel_create_call(VALUE self, VALUE parent, return Qnil; } - method_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(method), RSTRING_LEN(method)); - - call = grpc_channel_create_call(ch, parent_call, flags, cq, method_slice, - host_slice_ptr, grpc_rb_time_timeval( + call = grpc_channel_create_call(ch, parent_call, flags, cq, method_chars, + host_chars, grpc_rb_time_timeval( deadline, /* absolute time */ 0), NULL); - if (call == NULL) { - tmp_str = grpc_slice_to_c_string(method_slice); rb_raise(rb_eRuntimeError, "cannot create call with method %s", - tmp_str); + method_chars); return Qnil; } - - grpc_slice_unref(method_slice); - if (host_slice_ptr != NULL) { - grpc_slice_unref(host_slice); - } - res = grpc_rb_wrap_call(call, cq); /* Make this channel an instance attribute of the call so that it is not GCed diff --git a/src/ruby/ext/grpc/rb_compression_options.c b/src/ruby/ext/grpc/rb_compression_options.c index 6b2467ee461..6200dbafeb8 100644 --- a/src/ruby/ext/grpc/rb_compression_options.c +++ b/src/ruby/ext/grpc/rb_compression_options.c @@ -34,7 +34,6 @@ #include #include "rb_compression_options.h" -#include "rb_byte_buffer.h" #include "rb_grpc_imports.generated.h" #include @@ -169,9 +168,9 @@ void grpc_rb_compression_options_set_default_level( * Raises an error if the name of the algorithm passed in is invalid. */ void grpc_rb_compression_options_algorithm_name_to_value_internal( grpc_compression_algorithm *algorithm_value, VALUE algorithm_name) { - grpc_slice name_slice; + char *name_str = NULL; + long name_len = 0; VALUE algorithm_name_as_string = Qnil; - char *tmp_str = NULL; Check_Type(algorithm_name, T_SYMBOL); @@ -179,18 +178,16 @@ void grpc_rb_compression_options_algorithm_name_to_value_internal( * correct C string out of it. */ algorithm_name_as_string = rb_funcall(algorithm_name, rb_intern("to_s"), 0); - name_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(algorithm_name_as_string), RSTRING_LEN(algorithm_name_as_string)); + name_str = RSTRING_PTR(algorithm_name_as_string); + name_len = RSTRING_LEN(algorithm_name_as_string); /* Raise an error if the name isn't recognized as a compression algorithm by * the algorithm parse function * in GRPC core. */ - if(!grpc_compression_algorithm_parse(name_slice, algorithm_value)) { - tmp_str = grpc_slice_to_c_string(name_slice); + if (!grpc_compression_algorithm_parse(name_str, name_len, algorithm_value)) { rb_raise(rb_eNameError, "Invalid compression algorithm name: %s", - tmp_str); + StringValueCStr(algorithm_name_as_string)); } - - grpc_slice_unref(name_slice); } /* Indicates whether a given algorithm is enabled on this instance, given the diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.c b/src/ruby/ext/grpc/rb_grpc_imports.generated.c index 230682e72d9..6c36df9113e 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.c +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.c @@ -179,30 +179,17 @@ grpc_slice_new_type grpc_slice_new_import; grpc_slice_new_with_user_data_type grpc_slice_new_with_user_data_import; grpc_slice_new_with_len_type grpc_slice_new_with_len_import; grpc_slice_malloc_type grpc_slice_malloc_import; -grpc_slice_intern_type grpc_slice_intern_import; grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; grpc_slice_from_static_string_type grpc_slice_from_static_string_import; -grpc_slice_from_static_buffer_type grpc_slice_from_static_buffer_import; grpc_slice_sub_type grpc_slice_sub_import; grpc_slice_sub_no_ref_type grpc_slice_sub_no_ref_import; grpc_slice_split_tail_type grpc_slice_split_tail_import; grpc_slice_split_head_type grpc_slice_split_head_import; -grpc_empty_slice_type grpc_empty_slice_import; -grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; -grpc_slice_default_eq_impl_type grpc_slice_default_eq_impl_import; -grpc_slice_eq_type grpc_slice_eq_import; +gpr_empty_slice_type gpr_empty_slice_import; grpc_slice_cmp_type grpc_slice_cmp_import; grpc_slice_str_cmp_type grpc_slice_str_cmp_import; -grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; -grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; -grpc_slice_rchr_type grpc_slice_rchr_import; -grpc_slice_chr_type grpc_slice_chr_import; -grpc_slice_slice_type grpc_slice_slice_import; -grpc_slice_hash_type grpc_slice_hash_import; grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; -grpc_slice_dup_type grpc_slice_dup_import; -grpc_slice_to_c_string_type grpc_slice_to_c_string_import; grpc_slice_buffer_init_type grpc_slice_buffer_init_import; grpc_slice_buffer_destroy_type grpc_slice_buffer_destroy_import; grpc_slice_buffer_add_type grpc_slice_buffer_add_import; @@ -468,30 +455,17 @@ void grpc_rb_load_imports(HMODULE library) { grpc_slice_new_with_user_data_import = (grpc_slice_new_with_user_data_type) GetProcAddress(library, "grpc_slice_new_with_user_data"); grpc_slice_new_with_len_import = (grpc_slice_new_with_len_type) GetProcAddress(library, "grpc_slice_new_with_len"); grpc_slice_malloc_import = (grpc_slice_malloc_type) GetProcAddress(library, "grpc_slice_malloc"); - grpc_slice_intern_import = (grpc_slice_intern_type) GetProcAddress(library, "grpc_slice_intern"); grpc_slice_from_copied_string_import = (grpc_slice_from_copied_string_type) GetProcAddress(library, "grpc_slice_from_copied_string"); grpc_slice_from_copied_buffer_import = (grpc_slice_from_copied_buffer_type) GetProcAddress(library, "grpc_slice_from_copied_buffer"); grpc_slice_from_static_string_import = (grpc_slice_from_static_string_type) GetProcAddress(library, "grpc_slice_from_static_string"); - grpc_slice_from_static_buffer_import = (grpc_slice_from_static_buffer_type) GetProcAddress(library, "grpc_slice_from_static_buffer"); grpc_slice_sub_import = (grpc_slice_sub_type) GetProcAddress(library, "grpc_slice_sub"); grpc_slice_sub_no_ref_import = (grpc_slice_sub_no_ref_type) GetProcAddress(library, "grpc_slice_sub_no_ref"); grpc_slice_split_tail_import = (grpc_slice_split_tail_type) GetProcAddress(library, "grpc_slice_split_tail"); grpc_slice_split_head_import = (grpc_slice_split_head_type) GetProcAddress(library, "grpc_slice_split_head"); - grpc_empty_slice_import = (grpc_empty_slice_type) GetProcAddress(library, "grpc_empty_slice"); - grpc_slice_default_hash_impl_import = (grpc_slice_default_hash_impl_type) GetProcAddress(library, "grpc_slice_default_hash_impl"); - grpc_slice_default_eq_impl_import = (grpc_slice_default_eq_impl_type) GetProcAddress(library, "grpc_slice_default_eq_impl"); - grpc_slice_eq_import = (grpc_slice_eq_type) GetProcAddress(library, "grpc_slice_eq"); + gpr_empty_slice_import = (gpr_empty_slice_type) GetProcAddress(library, "gpr_empty_slice"); grpc_slice_cmp_import = (grpc_slice_cmp_type) GetProcAddress(library, "grpc_slice_cmp"); grpc_slice_str_cmp_import = (grpc_slice_str_cmp_type) GetProcAddress(library, "grpc_slice_str_cmp"); - grpc_slice_buf_cmp_import = (grpc_slice_buf_cmp_type) GetProcAddress(library, "grpc_slice_buf_cmp"); - grpc_slice_buf_start_eq_import = (grpc_slice_buf_start_eq_type) GetProcAddress(library, "grpc_slice_buf_start_eq"); - grpc_slice_rchr_import = (grpc_slice_rchr_type) GetProcAddress(library, "grpc_slice_rchr"); - grpc_slice_chr_import = (grpc_slice_chr_type) GetProcAddress(library, "grpc_slice_chr"); - grpc_slice_slice_import = (grpc_slice_slice_type) GetProcAddress(library, "grpc_slice_slice"); - grpc_slice_hash_import = (grpc_slice_hash_type) GetProcAddress(library, "grpc_slice_hash"); grpc_slice_is_equivalent_import = (grpc_slice_is_equivalent_type) GetProcAddress(library, "grpc_slice_is_equivalent"); - grpc_slice_dup_import = (grpc_slice_dup_type) GetProcAddress(library, "grpc_slice_dup"); - grpc_slice_to_c_string_import = (grpc_slice_to_c_string_type) GetProcAddress(library, "grpc_slice_to_c_string"); grpc_slice_buffer_init_import = (grpc_slice_buffer_init_type) GetProcAddress(library, "grpc_slice_buffer_init"); grpc_slice_buffer_destroy_import = (grpc_slice_buffer_destroy_type) GetProcAddress(library, "grpc_slice_buffer_destroy"); grpc_slice_buffer_add_import = (grpc_slice_buffer_add_type) GetProcAddress(library, "grpc_slice_buffer_add"); diff --git a/src/ruby/ext/grpc/rb_grpc_imports.generated.h b/src/ruby/ext/grpc/rb_grpc_imports.generated.h index 4c4f655b861..5745686adf3 100644 --- a/src/ruby/ext/grpc/rb_grpc_imports.generated.h +++ b/src/ruby/ext/grpc/rb_grpc_imports.generated.h @@ -176,7 +176,7 @@ extern census_resource_id_type census_resource_id_import; typedef void(*census_record_values_type)(census_context *context, census_value *values, size_t nvalues); extern census_record_values_type census_record_values_import; #define census_record_values census_record_values_import -typedef int(*grpc_compression_algorithm_parse_type)(grpc_slice value, grpc_compression_algorithm *algorithm); +typedef int(*grpc_compression_algorithm_parse_type)(const char *name, size_t name_length, grpc_compression_algorithm *algorithm); extern grpc_compression_algorithm_parse_type grpc_compression_algorithm_parse_import; #define grpc_compression_algorithm_parse grpc_compression_algorithm_parse_import typedef int(*grpc_compression_algorithm_name_type)(grpc_compression_algorithm algorithm, char **name); @@ -254,7 +254,7 @@ extern grpc_channel_check_connectivity_state_type grpc_channel_check_connectivit typedef void(*grpc_channel_watch_connectivity_state_type)(grpc_channel *channel, grpc_connectivity_state last_observed_state, gpr_timespec deadline, grpc_completion_queue *cq, void *tag); extern grpc_channel_watch_connectivity_state_type grpc_channel_watch_connectivity_state_import; #define grpc_channel_watch_connectivity_state grpc_channel_watch_connectivity_state_import -typedef grpc_call *(*grpc_channel_create_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, grpc_slice method, const grpc_slice *host, gpr_timespec deadline, void *reserved); +typedef grpc_call *(*grpc_channel_create_call_type)(grpc_channel *channel, grpc_call *parent_call, uint32_t propagation_mask, grpc_completion_queue *completion_queue, const char *method, const char *host, gpr_timespec deadline, void *reserved); extern grpc_channel_create_call_type grpc_channel_create_call_import; #define grpc_channel_create_call grpc_channel_create_call_import typedef void(*grpc_channel_ping_type)(grpc_channel *channel, grpc_completion_queue *cq, void *tag, void *reserved); @@ -338,13 +338,13 @@ extern grpc_server_destroy_type grpc_server_destroy_import; typedef int(*grpc_tracer_set_enabled_type)(const char *name, int enabled); extern grpc_tracer_set_enabled_type grpc_tracer_set_enabled_import; #define grpc_tracer_set_enabled grpc_tracer_set_enabled_import -typedef int(*grpc_header_key_is_legal_type)(grpc_slice slice); +typedef int(*grpc_header_key_is_legal_type)(const char *key, size_t length); extern grpc_header_key_is_legal_type grpc_header_key_is_legal_import; #define grpc_header_key_is_legal grpc_header_key_is_legal_import -typedef int(*grpc_header_nonbin_value_is_legal_type)(grpc_slice slice); +typedef int(*grpc_header_nonbin_value_is_legal_type)(const char *value, size_t length); extern grpc_header_nonbin_value_is_legal_type grpc_header_nonbin_value_is_legal_import; #define grpc_header_nonbin_value_is_legal grpc_header_nonbin_value_is_legal_import -typedef int(*grpc_is_binary_header_type)(grpc_slice slice); +typedef int(*grpc_is_binary_header_type)(const char *key, size_t length); extern grpc_is_binary_header_type grpc_is_binary_header_import; #define grpc_is_binary_header grpc_is_binary_header_import typedef const char *(*grpc_call_error_to_string_type)(grpc_call_error error); @@ -488,9 +488,6 @@ extern grpc_slice_new_with_len_type grpc_slice_new_with_len_import; typedef grpc_slice(*grpc_slice_malloc_type)(size_t length); extern grpc_slice_malloc_type grpc_slice_malloc_import; #define grpc_slice_malloc grpc_slice_malloc_import -typedef grpc_slice(*grpc_slice_intern_type)(grpc_slice slice); -extern grpc_slice_intern_type grpc_slice_intern_import; -#define grpc_slice_intern grpc_slice_intern_import typedef grpc_slice(*grpc_slice_from_copied_string_type)(const char *source); extern grpc_slice_from_copied_string_type grpc_slice_from_copied_string_import; #define grpc_slice_from_copied_string grpc_slice_from_copied_string_import @@ -500,9 +497,6 @@ extern grpc_slice_from_copied_buffer_type grpc_slice_from_copied_buffer_import; typedef grpc_slice(*grpc_slice_from_static_string_type)(const char *source); extern grpc_slice_from_static_string_type grpc_slice_from_static_string_import; #define grpc_slice_from_static_string grpc_slice_from_static_string_import -typedef grpc_slice(*grpc_slice_from_static_buffer_type)(const void *source, size_t len); -extern grpc_slice_from_static_buffer_type grpc_slice_from_static_buffer_import; -#define grpc_slice_from_static_buffer grpc_slice_from_static_buffer_import typedef grpc_slice(*grpc_slice_sub_type)(grpc_slice s, size_t begin, size_t end); extern grpc_slice_sub_type grpc_slice_sub_import; #define grpc_slice_sub grpc_slice_sub_import @@ -515,51 +509,18 @@ extern grpc_slice_split_tail_type grpc_slice_split_tail_import; typedef grpc_slice(*grpc_slice_split_head_type)(grpc_slice *s, size_t split); extern grpc_slice_split_head_type grpc_slice_split_head_import; #define grpc_slice_split_head grpc_slice_split_head_import -typedef grpc_slice(*grpc_empty_slice_type)(void); -extern grpc_empty_slice_type grpc_empty_slice_import; -#define grpc_empty_slice grpc_empty_slice_import -typedef uint32_t(*grpc_slice_default_hash_impl_type)(grpc_slice s); -extern grpc_slice_default_hash_impl_type grpc_slice_default_hash_impl_import; -#define grpc_slice_default_hash_impl grpc_slice_default_hash_impl_import -typedef int(*grpc_slice_default_eq_impl_type)(grpc_slice a, grpc_slice b); -extern grpc_slice_default_eq_impl_type grpc_slice_default_eq_impl_import; -#define grpc_slice_default_eq_impl grpc_slice_default_eq_impl_import -typedef int(*grpc_slice_eq_type)(grpc_slice a, grpc_slice b); -extern grpc_slice_eq_type grpc_slice_eq_import; -#define grpc_slice_eq grpc_slice_eq_import +typedef grpc_slice(*gpr_empty_slice_type)(void); +extern gpr_empty_slice_type gpr_empty_slice_import; +#define gpr_empty_slice gpr_empty_slice_import typedef int(*grpc_slice_cmp_type)(grpc_slice a, grpc_slice b); extern grpc_slice_cmp_type grpc_slice_cmp_import; #define grpc_slice_cmp grpc_slice_cmp_import typedef int(*grpc_slice_str_cmp_type)(grpc_slice a, const char *b); extern grpc_slice_str_cmp_type grpc_slice_str_cmp_import; #define grpc_slice_str_cmp grpc_slice_str_cmp_import -typedef int(*grpc_slice_buf_cmp_type)(grpc_slice a, const void *b, size_t blen); -extern grpc_slice_buf_cmp_type grpc_slice_buf_cmp_import; -#define grpc_slice_buf_cmp grpc_slice_buf_cmp_import -typedef int(*grpc_slice_buf_start_eq_type)(grpc_slice a, const void *b, size_t blen); -extern grpc_slice_buf_start_eq_type grpc_slice_buf_start_eq_import; -#define grpc_slice_buf_start_eq grpc_slice_buf_start_eq_import -typedef int(*grpc_slice_rchr_type)(grpc_slice s, char c); -extern grpc_slice_rchr_type grpc_slice_rchr_import; -#define grpc_slice_rchr grpc_slice_rchr_import -typedef int(*grpc_slice_chr_type)(grpc_slice s, char c); -extern grpc_slice_chr_type grpc_slice_chr_import; -#define grpc_slice_chr grpc_slice_chr_import -typedef int(*grpc_slice_slice_type)(grpc_slice haystack, grpc_slice needle); -extern grpc_slice_slice_type grpc_slice_slice_import; -#define grpc_slice_slice grpc_slice_slice_import -typedef uint32_t(*grpc_slice_hash_type)(grpc_slice s); -extern grpc_slice_hash_type grpc_slice_hash_import; -#define grpc_slice_hash grpc_slice_hash_import typedef int(*grpc_slice_is_equivalent_type)(grpc_slice a, grpc_slice b); extern grpc_slice_is_equivalent_type grpc_slice_is_equivalent_import; #define grpc_slice_is_equivalent grpc_slice_is_equivalent_import -typedef grpc_slice(*grpc_slice_dup_type)(grpc_slice a); -extern grpc_slice_dup_type grpc_slice_dup_import; -#define grpc_slice_dup grpc_slice_dup_import -typedef char *(*grpc_slice_to_c_string_type)(grpc_slice s); -extern grpc_slice_to_c_string_type grpc_slice_to_c_string_import; -#define grpc_slice_to_c_string grpc_slice_to_c_string_import typedef void(*grpc_slice_buffer_init_type)(grpc_slice_buffer *sb); extern grpc_slice_buffer_init_type grpc_slice_buffer_init_import; #define grpc_slice_buffer_init grpc_slice_buffer_init_import diff --git a/src/ruby/ext/grpc/rb_server.c b/src/ruby/ext/grpc/rb_server.c index 7b2f5774aa1..c7b112c94b4 100644 --- a/src/ruby/ext/grpc/rb_server.c +++ b/src/ruby/ext/grpc/rb_server.c @@ -44,7 +44,6 @@ #include "rb_channel_args.h" #include "rb_completion_queue.h" #include "rb_server_credentials.h" -#include "rb_byte_buffer.h" #include "rb_grpc.h" /* grpc_rb_cServer is the ruby class that proxies grpc_server. */ @@ -167,6 +166,8 @@ static void grpc_request_call_stack_init(request_call_stack* st) { MEMZERO(st, request_call_stack, 1); grpc_metadata_array_init(&st->md_ary); grpc_call_details_init(&st->details); + st->details.method = NULL; + st->details.host = NULL; } /* grpc_request_call_stack_cleanup ensures the request_call_stack is properly @@ -190,7 +191,6 @@ static VALUE grpc_rb_server_request_call(VALUE self) { void *tag = (void*)&st; grpc_completion_queue *call_queue = grpc_completion_queue_create(NULL); gpr_timespec deadline; - TypedData_Get_Struct(self, grpc_rb_server, &grpc_rb_server_data_type, s); if (s->wrapped == NULL) { rb_raise(rb_eRuntimeError, "destroyed!"); @@ -218,13 +218,11 @@ static VALUE grpc_rb_server_request_call(VALUE self) { return Qnil; } - - /* build the NewServerRpc struct result */ deadline = gpr_convert_clock_type(st.details.deadline, GPR_CLOCK_REALTIME); result = rb_struct_new( - grpc_rb_sNewServerRpc, grpc_rb_slice_to_ruby_string(st.details.method), - grpc_rb_slice_to_ruby_string(st.details.host), + grpc_rb_sNewServerRpc, rb_str_new2(st.details.method), + rb_str_new2(st.details.host), rb_funcall(rb_cTime, id_at, 2, INT2NUM(deadline.tv_sec), INT2NUM(deadline.tv_nsec / 1000)), grpc_rb_md_ary_to_h(&st.md_ary), grpc_rb_wrap_call(call, call_queue), diff --git a/test/core/bad_client/tests/large_metadata.c b/test/core/bad_client/tests/large_metadata.c index f672776a9fb..9c804e78c10 100644 --- a/test/core/bad_client/tests/large_metadata.c +++ b/test/core/bad_client/tests/large_metadata.c @@ -126,8 +126,8 @@ static void server_verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); @@ -153,14 +153,16 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); const size_t metadata_value_size = 16 * 1024; grpc_metadata meta; - meta.key = grpc_slice_from_static_string("key"); - meta.value = grpc_slice_malloc(metadata_value_size); - memset(GRPC_SLICE_START_PTR(meta.value), 'a', metadata_value_size); + meta.key = "key"; + meta.value = gpr_malloc(metadata_value_size + 1); + memset((char *)meta.value, 'a', metadata_value_size); + ((char *)meta.value)[metadata_value_size] = 0; + meta.value_length = metadata_value_size; grpc_op op; memset(&op, 0, sizeof(op)); @@ -174,7 +176,7 @@ static void server_verifier_sends_too_much_metadata(grpc_server *server, CQ_EXPECT_COMPLETION(cqv, tag(102), 0); // Operation fails. cq_verify(cqv); - grpc_slice_unref(meta.value); + gpr_free((char *)meta.value); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); grpc_call_destroy(s); @@ -188,26 +190,29 @@ static void client_validator(grpc_slice_buffer *incoming) { grpc_slice_buffer_trim_end(incoming, 13, &last_frame_buffer); GPR_ASSERT(last_frame_buffer.count == 1); grpc_slice last_frame = last_frame_buffer.slices[0]; - const uint8_t *p = GRPC_SLICE_START_PTR(last_frame); - // Length = 4 - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 4); - // Frame type (RST_STREAM) - GPR_ASSERT(*p++ == 3); - // Flags - GPR_ASSERT(*p++ == 0); + // Construct expected frame. + grpc_slice expected = grpc_slice_malloc(13); + uint8_t *p = GRPC_SLICE_START_PTR(expected); + // Length. + *p++ = 0; + *p++ = 0; + *p++ = 4; + // Frame type (RST_STREAM). + *p++ = 3; + // Flags. + *p++ = 0; // Stream ID. - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 1); - // Payload (error code) - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p++ == 0); - GPR_ASSERT(*p == 0 || *p == 11); - + *p++ = 0; + *p++ = 0; + *p++ = 0; + *p++ = 1; + // Payload (error code). + *p++ = 0; + *p++ = 0; + *p++ = 0; + *p++ = 11; + // Compare actual and expected. + GPR_ASSERT(grpc_slice_cmp(last_frame, expected) == 0); grpc_slice_buffer_destroy(&last_frame_buffer); } diff --git a/test/core/bad_client/tests/simple_request.c b/test/core/bad_client/tests/simple_request.c index db31ba6fb3c..c08aa40a0a7 100644 --- a/test/core/bad_client/tests/simple_request.c +++ b/test/core/bad_client/tests/simple_request.c @@ -117,8 +117,8 @@ static void verifier(grpc_server *server, grpc_completion_queue *cq, CQ_EXPECT_COMPLETION(cqv, tag(101), 1); cq_verify(cqv); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.host, "localhost")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo/bar")); + GPR_ASSERT(0 == strcmp(call_details.host, "localhost")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo/bar")); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); diff --git a/test/core/bad_ssl/bad_ssl_test.c b/test/core/bad_ssl/bad_ssl_test.c index 9cce77e71ab..f8a9fe6caca 100644 --- a/test/core/bad_ssl/bad_ssl_test.c +++ b/test/core/bad_ssl/bad_ssl_test.c @@ -57,7 +57,8 @@ static void run_test(const char *target, size_t nops) { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_status_code status; grpc_call_error error; gpr_timespec deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5); @@ -79,10 +80,9 @@ static void run_test(const char *target, size_t nops) { grpc_metadata_array_init(&trailing_metadata_recv); channel = grpc_secure_channel_create(ssl_creds, target, &args, NULL); - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); + "/foo", "foo.test.google.fr:1234", deadline, + NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -95,6 +95,7 @@ static void run_test(const char *target, size_t nops) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -116,7 +117,7 @@ static void run_test(const char *target, size_t nops) { GPR_ASSERT(status != GRPC_STATUS_OK); grpc_call_destroy(c); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/channel/channel_stack_test.c b/test/core/channel/channel_stack_test.c index dd9c5445243..080c56f1349 100644 --- a/test/core/channel/channel_stack_test.c +++ b/test/core/channel/channel_stack_test.c @@ -39,7 +39,6 @@ #include #include -#include "src/core/lib/slice/slice_internal.h" #include "test/core/util/test_config.h" static grpc_error *channel_init_func(grpc_exec_ctx *exec_ctx, @@ -121,7 +120,7 @@ static void test_create_channel_stack(void) { int *channel_data; int *call_data; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice path = grpc_slice_from_static_string("/service/method"); + grpc_mdstr *path = grpc_mdstr_from_string("/service/method"); arg.type = GRPC_ARG_INTEGER; arg.key = "test_key"; @@ -158,7 +157,7 @@ static void test_create_channel_stack(void) { GRPC_CHANNEL_STACK_UNREF(&exec_ctx, channel_stack, "done"); - grpc_slice_unref_internal(&exec_ctx, path); + GRPC_MDSTR_UNREF(&exec_ctx, path); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/client_channel/lb_policies_test.c b/test/core/client_channel/lb_policies_test.c index d7b1a785bea..f46982a3879 100644 --- a/test/core/client_channel/lb_policies_test.c +++ b/test/core/client_channel/lb_policies_test.c @@ -157,7 +157,8 @@ static void kill_server(const servers_fixture *f, size_t i) { typedef struct request_data { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; - grpc_slice details; + char *details; + size_t details_capacity; grpc_status_code status; grpc_call_details *call_details; } request_data; @@ -271,6 +272,8 @@ static request_sequences perform_request(servers_fixture *f, for (iter_num = 0; iter_num < spec->num_iters; iter_num++) { cq_verifier *cqv = cq_verifier_create(f->cq); + rdata->details = NULL; + rdata->details_capacity = 0; was_cancelled = 2; for (i = 0; i < f->num_servers; i++) { @@ -291,9 +294,8 @@ static request_sequences perform_request(servers_fixture *f, } memset(s_valid, 0, f->num_servers * sizeof(int)); - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - grpc_slice_from_static_string("/foo"), &host, + "/foo", "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); completed_client = 0; @@ -319,6 +321,8 @@ static request_sequences perform_request(servers_fixture *f, &rdata->trailing_metadata_recv; op->data.recv_status_on_client.status = &rdata->status; op->data.recv_status_on_client.status_details = &rdata->details; + op->data.recv_status_on_client.status_details_capacity = + &rdata->details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -361,8 +365,7 @@ static request_sequences perform_request(servers_fixture *f, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -381,12 +384,12 @@ static request_sequences perform_request(servers_fixture *f, } cq_verify(cqv); + gpr_log(GPR_DEBUG, "status=%d; %s", rdata->status, rdata->details); GPR_ASSERT(rdata->status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(rdata->details, "xyz")); + GPR_ASSERT(0 == strcmp(rdata->details, "xyz")); + GPR_ASSERT(0 == strcmp(rdata->call_details[s_idx].method, "/foo")); GPR_ASSERT(0 == - grpc_slice_str_cmp(rdata->call_details[s_idx].method, "/foo")); - GPR_ASSERT(0 == grpc_slice_str_cmp(rdata->call_details[s_idx].host, - "foo.test.google.fr")); + strcmp(rdata->call_details[s_idx].host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 1); grpc_call_destroy(f->server_calls[s_idx]); @@ -419,7 +422,7 @@ static request_sequences perform_request(servers_fixture *f, for (i = 0; i < f->num_servers; i++) { grpc_call_details_destroy(&rdata->call_details[i]); } - grpc_slice_unref(rdata->details); + gpr_free(rdata->details); } gpr_free(s_valid); @@ -451,12 +454,10 @@ static grpc_call **perform_multirequest(servers_fixture *f, op->flags = 0; op->reserved = NULL; - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); for (i = 0; i < concurrent_calls; i++) { - calls[i] = - grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - grpc_slice_from_static_string("/foo"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + calls[i] = grpc_channel_create_call( + client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", + "foo.test.google.fr", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(calls[i]); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[i], ops, (size_t)(op - ops), tag(1), diff --git a/test/core/client_channel/set_initial_connect_string_test.c b/test/core/client_channel/set_initial_connect_string_test.c index fc0aca0434f..b78ba98e0a9 100644 --- a/test/core/client_channel/set_initial_connect_string_test.c +++ b/test/core/client_channel/set_initial_connect_string_test.c @@ -141,11 +141,9 @@ static void start_rpc(int use_creds, int target_port) { } else { state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); } - grpc_slice host = grpc_slice_from_static_string("localhost"); state.call = grpc_channel_create_call( - state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, - grpc_slice_from_static_string("/Service/Method"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); memset(&state.op, 0, sizeof(state.op)); state.op.op = GRPC_OP_SEND_INITIAL_METADATA; state.op.data.send_initial_metadata.count = 0; @@ -209,7 +207,8 @@ static void match_initial_magic_string(grpc_slice_buffer *buffer) { size_t magic_length = strlen(magic_connect_string); GPR_ASSERT(buffer->length >= magic_length); for (i = 0, j = 0; i < state.incoming_buffer.count && j < magic_length; i++) { - char *dump = grpc_slice_to_c_string(state.incoming_buffer.slices[i]); + char *dump = + grpc_dump_slice(state.incoming_buffer.slices[i], GPR_DUMP_ASCII); cmp_length = GPR_MIN(strlen(dump), magic_length - j); GPR_ASSERT(strncmp(dump, magic_connect_string + j, cmp_length) == 0); j += cmp_length; diff --git a/test/core/compression/algorithm_test.c b/test/core/compression/algorithm_test.c index 37397ced8df..ff17667b945 100644 --- a/test/core/compression/algorithm_test.c +++ b/test/core/compression/algorithm_test.c @@ -40,7 +40,6 @@ #include #include -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" @@ -52,33 +51,32 @@ static void test_algorithm_mesh(void) { for (i = 0; i < GRPC_COMPRESS_ALGORITHMS_COUNT; i++) { char *name; grpc_compression_algorithm parsed; - grpc_slice mdstr; - grpc_mdelem mdelem; + grpc_mdstr *mdstr; + grpc_mdelem *mdelem; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; GPR_ASSERT( grpc_compression_algorithm_name((grpc_compression_algorithm)i, &name)); - GPR_ASSERT(grpc_compression_algorithm_parse( - grpc_slice_from_static_string(name), &parsed)); + GPR_ASSERT(grpc_compression_algorithm_parse(name, strlen(name), &parsed)); GPR_ASSERT((int)parsed == i); - mdstr = grpc_slice_from_copied_string(name); - GPR_ASSERT(grpc_slice_eq(mdstr, grpc_compression_algorithm_slice(parsed))); - GPR_ASSERT(parsed == grpc_compression_algorithm_from_slice(mdstr)); + mdstr = grpc_mdstr_from_string(name); + GPR_ASSERT(mdstr == grpc_compression_algorithm_mdstr(parsed)); + GPR_ASSERT(parsed == grpc_compression_algorithm_from_mdstr(mdstr)); mdelem = grpc_compression_encoding_mdelem(parsed); - GPR_ASSERT(grpc_slice_eq(GRPC_MDVALUE(mdelem), mdstr)); - GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(mdelem), GRPC_MDSTR_GRPC_ENCODING)); - grpc_slice_unref_internal(&exec_ctx, mdstr); + GPR_ASSERT(mdelem->value == mdstr); + GPR_ASSERT(mdelem->key == GRPC_MDSTR_GRPC_ENCODING); + GRPC_MDSTR_UNREF(&exec_ctx, mdstr); GRPC_MDELEM_UNREF(&exec_ctx, mdelem); grpc_exec_ctx_finish(&exec_ctx); } /* test failure */ - GPR_ASSERT(GRPC_MDISNULL( - grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT))); + GPR_ASSERT(NULL == + grpc_compression_encoding_mdelem(GRPC_COMPRESS_ALGORITHMS_COUNT)); } static void test_algorithm_failure(void) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_slice mdstr; + grpc_mdstr *mdstr; gpr_log(GPR_DEBUG, "test_algorithm_failure"); @@ -86,16 +84,14 @@ static void test_algorithm_failure(void) { NULL) == 0); GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT + 1, NULL) == 0); - mdstr = grpc_slice_from_static_string("this-is-an-invalid-algorithm"); - GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) == + mdstr = grpc_mdstr_from_string("this-is-an-invalid-algorithm"); + GPR_ASSERT(grpc_compression_algorithm_from_mdstr(mdstr) == GRPC_COMPRESS_ALGORITHMS_COUNT); - GPR_ASSERT(grpc_slice_eq( - grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT), - grpc_empty_slice())); - GPR_ASSERT(grpc_slice_eq( - grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT + 1), - grpc_empty_slice())); - grpc_slice_unref_internal(&exec_ctx, mdstr); + GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT) == + NULL); + GPR_ASSERT(grpc_compression_algorithm_mdstr(GRPC_COMPRESS_ALGORITHMS_COUNT + + 1) == NULL); + GRPC_MDSTR_UNREF(&exec_ctx, mdstr); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/compression/compression_test.c b/test/core/compression/compression_test.c index 7b2e56dc018..4c43746e335 100644 --- a/test/core/compression/compression_test.c +++ b/test/core/compression/compression_test.c @@ -54,7 +54,7 @@ static void test_compression_algorithm_parse(void) { const char *valid_name = valid_names[i]; grpc_compression_algorithm algorithm; const int success = grpc_compression_algorithm_parse( - grpc_slice_from_static_string(valid_name), &algorithm); + valid_name, strlen(valid_name), &algorithm); GPR_ASSERT(success != 0); GPR_ASSERT(algorithm == valid_algorithms[i]); } @@ -64,7 +64,7 @@ static void test_compression_algorithm_parse(void) { grpc_compression_algorithm algorithm; int success; success = grpc_compression_algorithm_parse( - grpc_slice_from_static_string(invalid_name), &algorithm); + invalid_name, strlen(invalid_name), &algorithm); GPR_ASSERT(success == 0); /* the value of "algorithm" is undefined upon failure */ } diff --git a/test/core/compression/message_compress_test.c b/test/core/compression/message_compress_test.c index 246a2b3a713..2432ca768ad 100644 --- a/test/core/compression/message_compress_test.c +++ b/test/core/compression/message_compress_test.c @@ -114,7 +114,7 @@ static void assert_passthrough(grpc_slice value, } final = grpc_slice_merge(output.slices, output.count); - GPR_ASSERT(grpc_slice_eq(value, final)); + GPR_ASSERT(0 == grpc_slice_cmp(value, final)); grpc_slice_buffer_destroy(&input); grpc_slice_buffer_destroy(&compressed); diff --git a/test/core/end2end/bad_server_response_test.c b/test/core/end2end/bad_server_response_test.c index 12db8a13f2b..a0520168830 100644 --- a/test/core/end2end/bad_server_response_test.c +++ b/test/core/end2end/bad_server_response_test.c @@ -172,17 +172,16 @@ static void start_rpc(int target_port, grpc_status_code expected_status, grpc_status_code status; grpc_call_error error; cq_verifier *cqv; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; state.cq = grpc_completion_queue_create(NULL); cqv = cq_verifier_create(state.cq); gpr_join_host_port(&state.target, "127.0.0.1", target_port); state.channel = grpc_insecure_channel_create(state.target, NULL, NULL); - grpc_slice host = grpc_slice_from_static_string("localhost"); state.call = grpc_channel_create_call( - state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, - grpc_slice_from_static_string("/Service/Method"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + state.channel, NULL, GRPC_PROPAGATE_DEFAULTS, state.cq, "/Service/Method", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -207,6 +206,7 @@ static void start_rpc(int target_port, grpc_status_code expected_status, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -218,13 +218,13 @@ static void start_rpc(int target_port, grpc_status_code expected_status, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); + gpr_log(GPR_DEBUG, "Rpc status: %d, details: %s", status, details); GPR_ASSERT(status == expected_status); - GPR_ASSERT(-1 != grpc_slice_slice(details, grpc_slice_from_static_string( - expected_detail))); + GPR_ASSERT(NULL != strstr(details, expected_detail)); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); + gpr_free(details); cq_verifier_destroy(cqv); } diff --git a/test/core/end2end/connection_refused_test.c b/test/core/end2end/connection_refused_test.c index 81a6b8720d4..44308043608 100644 --- a/test/core/end2end/connection_refused_test.c +++ b/test/core/end2end/connection_refused_test.c @@ -40,7 +40,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/service_config.h" @@ -60,7 +59,8 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_op *op; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; gpr_log(GPR_INFO, "TEST: wait_for_ready=%d use_service_config=%d", wait_for_ready, use_service_config); @@ -97,10 +97,9 @@ static void run_test(bool wait_for_ready, bool use_service_config) { gpr_join_host_port(&addr, "127.0.0.1", port); gpr_log(GPR_INFO, "server: %s", addr); chan = grpc_insecure_channel_create(addr, args, NULL); - grpc_slice host = grpc_slice_from_static_string("nonexistant"); - call = grpc_channel_create_call( - chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/service/method"), &host, deadline, NULL); + call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + "/service/method", "nonexistant", deadline, + NULL); gpr_free(addr); @@ -117,6 +116,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -142,7 +142,7 @@ static void run_test(bool wait_for_ready, bool use_service_config) { grpc_channel_destroy(chan); cq_verifier_destroy(cqv); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&trailing_metadata_recv); { diff --git a/test/core/end2end/cq_verifier.c b/test/core/end2end/cq_verifier.c index bc2d5888f0d..57373970c42 100644 --- a/test/core/end2end/cq_verifier.c +++ b/test/core/end2end/cq_verifier.c @@ -92,8 +92,8 @@ static int has_metadata(const grpc_metadata *md, size_t count, const char *key, const char *value) { size_t i; for (i = 0; i < count; i++) { - if (0 == grpc_slice_str_cmp(md[i].key, key) && - 0 == grpc_slice_str_cmp(md[i].value, value)) { + if (0 == strcmp(key, md[i].key) && strlen(value) == md[i].value_length && + 0 == memcmp(md[i].value, value, md[i].value_length)) { return 1; } } @@ -105,22 +105,6 @@ int contains_metadata(grpc_metadata_array *array, const char *key, return has_metadata(array->metadata, array->count, key, value); } -static int has_metadata_slices(const grpc_metadata *md, size_t count, - grpc_slice key, grpc_slice value) { - size_t i; - for (i = 0; i < count; i++) { - if (grpc_slice_eq(md[i].key, key) && grpc_slice_eq(md[i].value, value)) { - return 1; - } - } - return 0; -} - -int contains_metadata_slices(grpc_metadata_array *array, grpc_slice key, - grpc_slice value) { - return has_metadata_slices(array->metadata, array->count, key, value); -} - static grpc_slice merge_slices(grpc_slice *slices, size_t nslices) { size_t i; size_t len = 0; diff --git a/test/core/end2end/cq_verifier.h b/test/core/end2end/cq_verifier.h index 035aa270e4a..b754de9bbe7 100644 --- a/test/core/end2end/cq_verifier.h +++ b/test/core/end2end/cq_verifier.h @@ -71,7 +71,5 @@ int byte_buffer_eq_slice(grpc_byte_buffer *bb, grpc_slice b); int byte_buffer_eq_string(grpc_byte_buffer *byte_buffer, const char *string); int contains_metadata(grpc_metadata_array *array, const char *key, const char *value); -int contains_metadata_slices(grpc_metadata_array *array, grpc_slice key, - grpc_slice value); #endif /* GRPC_TEST_CORE_END2END_CQ_VERIFIER_H */ diff --git a/test/core/end2end/dualstack_socket_test.c b/test/core/end2end/dualstack_socket_test.c index 9cd07071746..11e8604f56a 100644 --- a/test/core/end2end/dualstack_socket_test.c +++ b/test/core/end2end/dualstack_socket_test.c @@ -88,7 +88,8 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_metadata_array request_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; grpc_call_details call_details; char *peer; @@ -134,7 +135,7 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_slice_split(uri_slice, ",", &uri_parts); hosts_with_port = gpr_malloc(sizeof(char *) * uri_parts.count); for (i = 0; i < uri_parts.count; i++) { - char *uri_part_str = grpc_slice_to_c_string(uri_parts.slices[i]); + char *uri_part_str = grpc_dump_slice(uri_parts.slices[i], GPR_DUMP_ASCII); gpr_asprintf(&hosts_with_port[i], "%s:%d", uri_part_str, port); gpr_free(uri_part_str); } @@ -167,10 +168,8 @@ void test_connect(const char *server_host, const char *client_host, int port, } /* Send a trivial request. */ - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(client, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); + "/foo", "foo.test.google.fr", deadline, NULL); GPR_ASSERT(c); memset(ops, 0, sizeof(ops)); @@ -193,6 +192,7 @@ void test_connect(const char *server_host, const char *client_host, int port, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -216,8 +216,7 @@ void test_connect(const char *server_host, const char *client_host, int port, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; @@ -236,10 +235,9 @@ void test_connect(const char *server_host, const char *client_host, int port, gpr_free(peer); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); - GPR_ASSERT(0 == - grpc_slice_str_cmp(call_details.host, "foo.test.google.fr")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr")); GPR_ASSERT(was_cancelled == 1); grpc_call_destroy(s); @@ -273,7 +271,7 @@ void test_connect(const char *server_host, const char *client_host, int port, grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); - grpc_slice_unref(details); + gpr_free(details); if (picked_port) { grpc_recycle_unused_port(port); } diff --git a/test/core/end2end/end2end_test_utils.c b/test/core/end2end/end2end_test_utils.c index 8783d8451b6..46fb4ec1aff 100644 --- a/test/core/end2end/end2end_test_utils.c +++ b/test/core/end2end/end2end_test_utils.c @@ -39,27 +39,13 @@ const char *get_host_override_string(const char *str, grpc_end2end_test_config config) { - if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) { - return str; - } else { - return NULL; - } -} - -const grpc_slice *get_host_override_slice(const char *str, - grpc_end2end_test_config config) { - const char *r = get_host_override_string(str, config); - if (r != NULL) { - static grpc_slice ret; - ret = grpc_slice_from_static_string(r); - return &ret; - } - return NULL; + return (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER ? str + : NULL); } -void validate_host_override_string(const char *pattern, grpc_slice str, +void validate_host_override_string(const char *pattern, const char *str, grpc_end2end_test_config config) { if (config.feature_mask & FEATURE_MASK_SUPPORTS_AUTHORITY_HEADER) { - GPR_ASSERT(0 == grpc_slice_str_cmp(str, pattern)); + GPR_ASSERT(0 == strcmp(str, pattern)); } } diff --git a/test/core/end2end/end2end_tests.h b/test/core/end2end/end2end_tests.h index cb0afd9cd99..f25e90b5f61 100644 --- a/test/core/end2end/end2end_tests.h +++ b/test/core/end2end/end2end_tests.h @@ -72,12 +72,8 @@ void grpc_end2end_tests(int argc, char **argv, grpc_end2end_test_config config); const char *get_host_override_string(const char *str, grpc_end2end_test_config config); -/* Returns a pointer to a statically allocated slice: future invocations - overwrite past invocations, not threadsafe, etc... */ -const grpc_slice *get_host_override_slice(const char *str, - grpc_end2end_test_config config); -void validate_host_override_string(const char *pattern, grpc_slice str, +void validate_host_override_string(const char *pattern, const char *str, grpc_end2end_test_config config); #endif /* GRPC_TEST_CORE_END2END_END2END_TESTS_H */ diff --git a/test/core/end2end/fake_resolver.c b/test/core/end2end/fake_resolver.c index 8e711c6b419..966642f403c 100644 --- a/test/core/end2end/fake_resolver.c +++ b/test/core/end2end/fake_resolver.c @@ -165,7 +165,7 @@ static grpc_resolver* fake_resolver_create(grpc_exec_ctx* exec_ctx, bool errors_found = false; for (size_t i = 0; i < addresses->num_addresses; i++) { grpc_uri ith_uri = *args->uri; - char* part_str = grpc_slice_to_c_string(path_parts.slices[i]); + char* part_str = grpc_dump_slice(path_parts.slices[i], GPR_DUMP_ASCII); ith_uri.path = part_str; if (!parse_ipv4(&ith_uri, &addresses->addresses[i].address)) { errors_found = true; diff --git a/test/core/end2end/fixtures/h2_oauth2.c b/test/core/end2end/fixtures/h2_oauth2.c index 33516528586..83f759ce2dd 100644 --- a/test/core/end2end/fixtures/h2_oauth2.c +++ b/test/core/end2end/fixtures/h2_oauth2.c @@ -59,8 +59,8 @@ static const grpc_metadata *find_metadata(const grpc_metadata *md, const char *value) { size_t i; for (i = 0; i < md_count; i++) { - if (grpc_slice_str_cmp(md[i].key, key) == 0 && - grpc_slice_str_cmp(md[i].value, value) == 0) { + if (strcmp(key, md[i].key) == 0 && strlen(value) == md[i].value_length && + memcmp(md[i].value, value, md[i].value_length) == 0) { return &md[i]; } } @@ -74,7 +74,7 @@ static void process_oauth2_success(void *state, grpc_auth_context *ctx, grpc_process_auth_metadata_done_cb cb, void *user_data) { const grpc_metadata *oauth2 = - find_metadata(md, md_count, "authorization", oauth2_md); + find_metadata(md, md_count, "Authorization", oauth2_md); test_processor_state *s; GPR_ASSERT(state != NULL); @@ -93,7 +93,7 @@ static void process_oauth2_failure(void *state, grpc_auth_context *ctx, grpc_process_auth_metadata_done_cb cb, void *user_data) { const grpc_metadata *oauth2 = - find_metadata(md, md_count, "authorization", oauth2_md); + find_metadata(md, md_count, "Authorization", oauth2_md); test_processor_state *s; GPR_ASSERT(state != NULL); s = (test_processor_state *)state; @@ -154,7 +154,7 @@ static void chttp2_init_client_simple_ssl_with_oauth2_secure_fullstack( grpc_channel_credentials *ssl_creds = grpc_ssl_credentials_create(test_root_cert, NULL, NULL); grpc_call_credentials *oauth2_creds = - grpc_md_only_test_credentials_create("authorization", oauth2_md, 1); + grpc_md_only_test_credentials_create("Authorization", oauth2_md, 1); grpc_channel_credentials *ssl_oauth2_creds = grpc_composite_channel_credentials_create(ssl_creds, oauth2_creds, NULL); grpc_arg ssl_name_override = {GRPC_ARG_STRING, diff --git a/test/core/end2end/fixtures/h2_ssl_cert.c b/test/core/end2end/fixtures/h2_ssl_cert.c index 844e93396df..ae49cc859af 100644 --- a/test/core/end2end/fixtures/h2_ssl_cert.c +++ b/test/core/end2end/fixtures/h2_ssl_cert.c @@ -321,10 +321,9 @@ static void simple_request_body(grpc_end2end_test_fixture f, grpc_op *op; grpc_call_error error; - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); + "/foo", "foo.test.google.fr:1234", deadline, + NULL); GPR_ASSERT(c); memset(ops, 0, sizeof(ops)); diff --git a/test/core/end2end/fixtures/http_proxy.c b/test/core/end2end/fixtures/http_proxy.c index dac9baf3cec..b62082c6fb1 100644 --- a/test/core/end2end/fixtures/http_proxy.c +++ b/test/core/end2end/fixtures/http_proxy.c @@ -132,7 +132,7 @@ static void proxy_connection_failed(grpc_exec_ctx* exec_ctx, const char* prefix, grpc_error* error) { const char* msg = grpc_error_string(error); gpr_log(GPR_INFO, "%s: %s", prefix, msg); - + grpc_error_free_string(msg); grpc_endpoint_shutdown(exec_ctx, conn->client_endpoint); if (conn->server_endpoint != NULL) grpc_endpoint_shutdown(exec_ctx, conn->server_endpoint); diff --git a/test/core/end2end/fixtures/proxy.c b/test/core/end2end/fixtures/proxy.c index 30bb9ff1b34..beed80df819 100644 --- a/test/core/end2end/fixtures/proxy.c +++ b/test/core/end2end/fixtures/proxy.c @@ -80,7 +80,8 @@ typedef struct { grpc_metadata_array p2s_trailing_metadata; grpc_status_code p2s_status; - grpc_slice p2s_status_details; + char *p2s_status_details; + size_t p2s_status_details_capacity; int c2p_server_cancelled; } proxy_call; @@ -111,7 +112,6 @@ grpc_end2end_proxy *grpc_end2end_proxy_create(const grpc_end2end_proxy_def *def, grpc_server_register_completion_queue(proxy->server, proxy->cq, NULL); grpc_server_start(proxy->server); - grpc_call_details_init(&proxy->new_call_details); gpr_thd_options_set_joinable(&opt); GPR_ASSERT(gpr_thd_new(&proxy->thd, thread_main, proxy, &opt)); @@ -153,7 +153,7 @@ static void unrefpc(proxy_call *pc, const char *reason) { grpc_metadata_array_destroy(&pc->c2p_initial_metadata); grpc_metadata_array_destroy(&pc->p2s_initial_metadata); grpc_metadata_array_destroy(&pc->p2s_trailing_metadata); - grpc_slice_unref(pc->p2s_status_details); + gpr_free(pc->p2s_status_details); gpr_free(pc); } } @@ -309,7 +309,7 @@ static void on_p2s_status(void *arg, int success) { op.data.send_status_from_server.trailing_metadata = pc->p2s_trailing_metadata.metadata; op.data.send_status_from_server.status = pc->p2s_status; - op.data.send_status_from_server.status_details = &pc->p2s_status_details; + op.data.send_status_from_server.status_details = pc->p2s_status_details; refpc(pc, "on_c2p_sent_status"); err = grpc_call_start_batch(pc->c2p, &op, 1, new_closure(on_c2p_sent_status, pc), NULL); @@ -339,7 +339,7 @@ static void on_new_call(void *arg, int success) { pc->c2p = proxy->new_call; pc->p2s = grpc_channel_create_call( proxy->client, pc->c2p, GRPC_PROPAGATE_DEFAULTS, proxy->cq, - proxy->new_call_details.method, &proxy->new_call_details.host, + proxy->new_call_details.method, proxy->new_call_details.host, proxy->new_call_details.deadline, NULL); gpr_ref_init(&pc->refs, 1); @@ -384,6 +384,8 @@ static void on_new_call(void *arg, int success) { &pc->p2s_trailing_metadata; op.data.recv_status_on_client.status = &pc->p2s_status; op.data.recv_status_on_client.status_details = &pc->p2s_status_details; + op.data.recv_status_on_client.status_details_capacity = + &pc->p2s_status_details_capacity; refpc(pc, "on_p2s_status"); err = grpc_call_start_batch(pc->p2s, &op, 1, new_closure(on_p2s_status, pc), NULL); @@ -399,9 +401,6 @@ static void on_new_call(void *arg, int success) { request_call(proxy); - grpc_call_details_destroy(&proxy->new_call_details); - grpc_call_details_init(&proxy->new_call_details); - unrefpc(pc, "init"); } else { GPR_ASSERT(proxy->new_call == NULL); diff --git a/test/core/end2end/fuzzers/api_fuzzer.c b/test/core/end2end/fuzzers/api_fuzzer.c index 30d814b01bb..200a51858a0 100644 --- a/test/core/end2end/fuzzers/api_fuzzer.c +++ b/test/core/end2end/fuzzers/api_fuzzer.c @@ -44,7 +44,6 @@ #include "src/core/lib/iomgr/resolve_address.h" #include "src/core/lib/iomgr/tcp_client.h" #include "src/core/lib/iomgr/timer.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/server.h" #include "src/core/lib/transport/metadata.h" #include "test/core/end2end/data/ssl_test_data.h" @@ -91,7 +90,7 @@ static uint8_t next_byte(input_stream *inp) { static void end(input_stream *inp) { inp->cur = inp->end; } -static char *read_string(input_stream *inp, bool *special) { +static char *read_string(input_stream *inp) { char *str = NULL; size_t cap = 0; size_t sz = 0; @@ -103,56 +102,18 @@ static char *read_string(input_stream *inp, bool *special) { } c = (char)next_byte(inp); str[sz++] = c; - } while (c != 0 && c != 1); - if (special != NULL) { - *special = (c == 1); - } - if (c == 1) { - str[sz - 1] = 0; - } + } while (c != 0); return str; } -static void read_buffer(input_stream *inp, char **buffer, size_t *length, - bool *special) { +static void read_buffer(input_stream *inp, char **buffer, size_t *length) { *length = next_byte(inp); - if (*length == 255) { - if (special != NULL) *special = true; - *length = next_byte(inp); - } else { - if (special != NULL) *special = false; - } *buffer = gpr_malloc(*length); for (size_t i = 0; i < *length; i++) { (*buffer)[i] = (char)next_byte(inp); } } -static grpc_slice maybe_intern(grpc_slice s, bool intern) { - grpc_slice r = intern ? grpc_slice_intern(s) : grpc_slice_ref(s); - grpc_slice_unref(s); - return r; -} - -static grpc_slice read_string_like_slice(input_stream *inp) { - bool special; - char *s = read_string(inp, &special); - grpc_slice r = maybe_intern(grpc_slice_from_copied_string(s), special); - gpr_free(s); - return r; -} - -static grpc_slice read_buffer_like_slice(input_stream *inp) { - char *buffer; - size_t length; - bool special; - read_buffer(inp, &buffer, &length, &special); - grpc_slice r = - maybe_intern(grpc_slice_from_copied_buffer(buffer, length), special); - gpr_free(buffer); - return r; -} - static uint32_t read_uint22(input_stream *inp) { uint8_t b = next_byte(inp); uint32_t x = b & 0x7f; @@ -209,12 +170,12 @@ static grpc_channel_args *read_args(input_stream *inp) { switch (next_byte(inp)) { case 1: args[i].type = GRPC_ARG_STRING; - args[i].key = read_string(inp, NULL); - args[i].value.string = read_string(inp, NULL); + args[i].key = read_string(inp); + args[i].value.string = read_string(inp); break; case 2: args[i].type = GRPC_ARG_INTEGER; - args[i].key = read_string(inp, NULL); + args[i].key = read_string(inp); args[i].value.integer = read_int(inp); break; case 3: @@ -256,7 +217,7 @@ static const char *read_cred_artifact(cred_artifact_ctx *ctx, input_stream *inp, size_t num_builtins) { uint8_t b = next_byte(inp); if (b == 0) return NULL; - if (b == 1) return ctx->release[ctx->num_release++] = read_string(inp, NULL); + if (b == 1) return ctx->release[ctx->num_release++] = read_string(inp); if (b >= num_builtins + 1) { end(inp); return NULL; @@ -547,7 +508,8 @@ typedef struct call_state { grpc_status_code status; grpc_metadata_array recv_initial_metadata; grpc_metadata_array recv_trailing_metadata; - grpc_slice recv_status_details; + char *recv_status_details; + size_t recv_status_details_capacity; int cancelled; int pending_ops; grpc_call_details call_details; @@ -561,11 +523,6 @@ typedef struct call_state { size_t cap_to_free; void **to_free; - // array of slices to unref - size_t num_slices_to_unref; - size_t cap_slices_to_unref; - grpc_slice *slices_to_unref; - struct call_state *next; struct call_state *prev; } call_state; @@ -601,15 +558,12 @@ static call_state *maybe_delete_call_state(call_state *call) { call->next->prev = call->prev; grpc_metadata_array_destroy(&call->recv_initial_metadata); grpc_metadata_array_destroy(&call->recv_trailing_metadata); - grpc_slice_unref(call->recv_status_details); + gpr_free(call->recv_status_details); grpc_call_details_destroy(&call->call_details); for (size_t i = 0; i < call->num_to_free; i++) { gpr_free(call->to_free[i]); } - for (size_t i = 0; i < call->num_slices_to_unref; i++) { - grpc_slice_unref(call->slices_to_unref[i]); - } gpr_free(call->to_free); gpr_free(call); @@ -626,17 +580,6 @@ static void add_to_free(call_state *call, void *p) { call->to_free[call->num_to_free++] = p; } -static grpc_slice *add_to_slice_unref(call_state *call, grpc_slice s) { - if (call->num_slices_to_unref == call->cap_slices_to_unref) { - call->cap_slices_to_unref = GPR_MAX(8, 2 * call->cap_slices_to_unref); - call->slices_to_unref = - gpr_realloc(call->slices_to_unref, - sizeof(*call->slices_to_unref) * call->cap_slices_to_unref); - } - call->slices_to_unref[call->num_to_free++] = s; - return &call->slices_to_unref[call->num_to_free - 1]; -} - static void read_metadata(input_stream *inp, size_t *count, grpc_metadata **metadata, call_state *cs) { *count = next_byte(inp); @@ -644,11 +587,12 @@ static void read_metadata(input_stream *inp, size_t *count, *metadata = gpr_malloc(*count * sizeof(**metadata)); memset(*metadata, 0, *count * sizeof(**metadata)); for (size_t i = 0; i < *count; i++) { - (*metadata)[i].key = read_string_like_slice(inp); - (*metadata)[i].value = read_buffer_like_slice(inp); + (*metadata)[i].key = read_string(inp); + read_buffer(inp, (char **)&(*metadata)[i].value, + &(*metadata)[i].value_length); (*metadata)[i].flags = read_uint32(inp); - add_to_slice_unref(cs, (*metadata)[i].key); - add_to_slice_unref(cs, (*metadata)[i].value); + add_to_free(cs, (void *)(*metadata)[i].key); + add_to_free(cs, (void *)(*metadata)[i].value); } } else { *metadata = gpr_malloc(1); @@ -712,7 +656,7 @@ static validator *make_finished_batch_validator(call_state *cs, } int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_slice_hash_seed(0); + grpc_test_only_set_metadata_hash_seed(0); if (squelch) gpr_set_log_function(dont_log); input_stream inp = {data, data + size}; grpc_resolve_address = my_resolve_address; @@ -798,7 +742,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // create an insecure channel case 2: { if (g_channel == NULL) { - char *target = read_string(&inp, NULL); + char *target = read_string(&inp); char *target_uri; gpr_asprintf(&target_uri, "dns:%s", target); grpc_channel_args *args = read_args(&inp); @@ -927,8 +871,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { parent_call = g_active_call->call; } uint32_t propagation_mask = read_uint32(&inp); - grpc_slice method = read_string_like_slice(&inp); - grpc_slice host = read_string_like_slice(&inp); + char *method = read_string(&inp); + char *host = read_string(&inp); gpr_timespec deadline = gpr_time_add(gpr_now(GPR_CLOCK_REALTIME), gpr_time_from_micros(read_uint32(&inp), GPR_TIMESPAN)); @@ -937,12 +881,12 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { call_state *cs = new_call(g_active_call, CLIENT); cs->call = grpc_channel_create_call(g_channel, parent_call, propagation_mask, - cq, method, &host, deadline, NULL); + cq, method, host, deadline, NULL); } else { end(&inp); } - grpc_slice_unref(method); - grpc_slice_unref(host); + gpr_free(method); + gpr_free(host); break; } // switch the 'current' call @@ -1007,8 +951,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { g_active_call); op->data.send_status_from_server.status = next_byte(&inp); op->data.send_status_from_server.status_details = - add_to_slice_unref(g_active_call, - read_buffer_like_slice(&inp)); + read_string(&inp); break; case GRPC_OP_RECV_INITIAL_METADATA: op->op = GRPC_OP_RECV_INITIAL_METADATA; @@ -1028,6 +971,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { &g_active_call->recv_trailing_metadata; op->data.recv_status_on_client.status_details = &g_active_call->recv_status_details; + op->data.recv_status_on_client.status_details_capacity = + &g_active_call->recv_status_details_capacity; break; case GRPC_OP_RECV_CLOSE_ON_SERVER: op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; @@ -1115,14 +1060,14 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { } // enable a tracer case 17: { - char *tracer = read_string(&inp, NULL); + char *tracer = read_string(&inp); grpc_tracer_set_enabled(tracer, 1); gpr_free(tracer); break; } // disable a tracer case 18: { - char *tracer = read_string(&inp, NULL); + char *tracer = read_string(&inp); grpc_tracer_set_enabled(tracer, 0); gpr_free(tracer); break; @@ -1164,7 +1109,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { // create a secure channel case 22: { if (g_channel == NULL) { - char *target = read_string(&inp, NULL); + char *target = read_string(&inp); char *target_uri; gpr_asprintf(&target_uri, "dns:%s", target); grpc_channel_args *args = read_args(&inp); diff --git a/test/core/end2end/fuzzers/client_fuzzer.c b/test/core/end2end/fuzzers/client_fuzzer.c index 1fdc86356c6..26b520885bb 100644 --- a/test/core/end2end/fuzzers/client_fuzzer.c +++ b/test/core/end2end/fuzzers/client_fuzzer.c @@ -37,7 +37,6 @@ #include #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/channel.h" #include "test/core/util/memory_counters.h" #include "test/core/util/mock_endpoint.h" @@ -52,7 +51,7 @@ static void *tag(int n) { return (void *)(uintptr_t)n; } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_slice_hash_seed(0); + grpc_test_only_set_metadata_hash_seed(0); struct grpc_memory_counters counters; if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); @@ -72,10 +71,9 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_channel *channel = grpc_channel_create( &exec_ctx, "test-target", NULL, GRPC_CLIENT_DIRECT_CHANNEL, transport); - grpc_slice host = grpc_slice_from_static_string("localhost"); - grpc_call *call = grpc_channel_create_call( - channel, NULL, 0, cq, grpc_slice_from_static_string("/foo"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + grpc_call *call = + grpc_channel_create_call(channel, NULL, 0, cq, "/foo", "localhost", + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array initial_metadata_recv; grpc_metadata_array_init(&initial_metadata_recv); @@ -83,7 +81,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { grpc_metadata_array trailing_metadata_recv; grpc_metadata_array_init(&trailing_metadata_recv); grpc_status_code status; - grpc_slice details = grpc_empty_slice(); + char *details = NULL; + size_t details_capacity = 0; grpc_op ops[6]; memset(ops, 0, sizeof(ops)); @@ -111,6 +110,7 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -155,7 +155,7 @@ done: grpc_completion_queue_destroy(cq); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_channel_destroy(channel); if (response_payload_recv != NULL) { grpc_byte_buffer_destroy(response_payload_recv); diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index 81a2419d120..12db0ff0248 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -1,62 +1,24 @@ # hpack fuzzing dictionary -"\x05:path" -"\x07:method" -"\x07:status" -"\x0A:authority" -"\x07:scheme" -"\x02te" -"\x0Cgrpc-message" -"\x0Bgrpc-status" -"\x10grpc-payload-bin" -"\x0Dgrpc-encoding" -"\x14grpc-accept-encoding" -"\x0Ccontent-type" -"\x1Egrpc-internal-encoding-request" -"\x0Auser-agent" -"\x04host" -"\x08lb-token" -"\x0Blb-cost-bin" -"\x0Cgrpc-timeout" -"\x10grpc-tracing-bin" -"\x0Egrpc-stats-bin" -"\x00" -"\x13grpc.wait_for_ready" -"\x0Cgrpc.timeout" -"\x1Egrpc.max_request_message_bytes" -"\x1Fgrpc.max_response_message_bytes" -"$/grpc.lb.v1.LoadBalancer/BalanceLoad" "\x010" "\x011" "\x012" -"\x08identity" -"\x04gzip" -"\x07deflate" -"\x08trailers" -"\x10application/grpc" -"\x04POST" "\x03200" -"\x03404" -"\x04http" -"\x05https" -"\x04grpc" -"\x03GET" -"\x03PUT" -"\x01/" -"\x0B/index.html" "\x03204" "\x03206" "\x03304" "\x03400" +"\x03404" "\x03500" +"\x06accept" "\x0Eaccept-charset" "\x0Faccept-encoding" -"\x0Dgzip, deflate" "\x0Faccept-language" "\x0Daccept-ranges" -"\x06accept" "\x1Baccess-control-allow-origin" "\x03age" "\x05allow" +"\x10application/grpc" +"\x0A:authority" "\x0Dauthorization" "\x0Dcache-control" "\x13content-disposition" @@ -65,71 +27,81 @@ "\x0Econtent-length" "\x10content-location" "\x0Dcontent-range" +"\x0Ccontent-type" "\x06cookie" "\x04date" +"\x07deflate" +"\x0Cdeflate,gzip" +"\x00" "\x04etag" "\x06expect" "\x07expires" "\x04from" +"\x03GET" +"\x04grpc" +"\x14grpc-accept-encoding" +"\x0Dgrpc-encoding" +"\x1Egrpc-internal-encoding-request" +"\x0Cgrpc-message" +"\x10grpc-payload-bin" +"\x0Egrpc-stats-bin" +"\x0Bgrpc-status" +"\x0Cgrpc-timeout" +"\x10grpc-tracing-bin" +"\x04gzip" +"\x0Dgzip, deflate" +"\x04host" +"\x04http" +"\x05https" +"\x08identity" +"\x10identity,deflate" +"\x15identity,deflate,gzip" +"\x0Didentity,gzip" "\x08if-match" "\x11if-modified-since" "\x0Dif-none-match" "\x08if-range" "\x13if-unmodified-since" "\x0Dlast-modified" +"\x0Blb-cost-bin" +"\x08lb-token" "\x04link" "\x08location" "\x0Cmax-forwards" +"\x07:method" +"\x05:path" +"\x04POST" "\x12proxy-authenticate" "\x13proxy-authorization" +"\x03PUT" "\x05range" "\x07referer" "\x07refresh" "\x0Bretry-after" +"\x07:scheme" "\x06server" "\x0Aset-cookie" +"\x01/" +"\x0B/index.html" +"\x07:status" "\x19strict-transport-security" +"\x02te" +"\x08trailers" "\x11transfer-encoding" +"\x0Auser-agent" "\x04vary" "\x03via" "\x10www-authenticate" -"\x10identity,deflate" -"\x0Didentity,gzip" -"\x0Cdeflate,gzip" -"\x15identity,deflate,gzip" -"\x00\x0Bgrpc-status\x010" -"\x00\x0Bgrpc-status\x011" -"\x00\x0Bgrpc-status\x012" -"\x00\x0Dgrpc-encoding\x08identity" -"\x00\x0Dgrpc-encoding\x04gzip" -"\x00\x0Dgrpc-encoding\x07deflate" -"\x00\x02te\x08trailers" -"\x00\x0Ccontent-type\x10application/grpc" -"\x00\x07:method\x04POST" -"\x00\x07:status\x03200" -"\x00\x07:status\x03404" -"\x00\x07:scheme\x04http" -"\x00\x07:scheme\x05https" -"\x00\x07:scheme\x04grpc" -"\x00\x0A:authority\x00" -"\x00\x07:method\x03GET" -"\x00\x07:method\x03PUT" -"\x00\x05:path\x01/" -"\x00\x05:path\x0B/index.html" -"\x00\x07:status\x03204" -"\x00\x07:status\x03206" -"\x00\x07:status\x03304" -"\x00\x07:status\x03400" -"\x00\x07:status\x03500" "\x00\x0Eaccept-charset\x00" +"\x00\x06accept\x00" "\x00\x0Faccept-encoding\x00" "\x00\x0Faccept-encoding\x0Dgzip, deflate" "\x00\x0Faccept-language\x00" "\x00\x0Daccept-ranges\x00" -"\x00\x06accept\x00" "\x00\x1Baccess-control-allow-origin\x00" "\x00\x03age\x00" "\x00\x05allow\x00" +"\x00\x0A:authority\x00" "\x00\x0Dauthorization\x00" "\x00\x0Dcache-control\x00" "\x00\x13content-disposition\x00" @@ -138,6 +110,7 @@ "\x00\x0Econtent-length\x00" "\x00\x10content-location\x00" "\x00\x0Dcontent-range\x00" +"\x00\x0Ccontent-type\x10application/grpc" "\x00\x0Ccontent-type\x00" "\x00\x06cookie\x00" "\x00\x04date\x00" @@ -145,6 +118,19 @@ "\x00\x06expect\x00" "\x00\x07expires\x00" "\x00\x04from\x00" +"\x00\x14grpc-accept-encoding\x07deflate" +"\x00\x14grpc-accept-encoding\x0Cdeflate,gzip" +"\x00\x14grpc-accept-encoding\x04gzip" +"\x00\x14grpc-accept-encoding\x08identity" +"\x00\x14grpc-accept-encoding\x10identity,deflate" +"\x00\x14grpc-accept-encoding\x15identity,deflate,gzip" +"\x00\x14grpc-accept-encoding\x0Didentity,gzip" +"\x00\x0Dgrpc-encoding\x07deflate" +"\x00\x0Dgrpc-encoding\x04gzip" +"\x00\x0Dgrpc-encoding\x08identity" +"\x00\x0Bgrpc-status\x010" +"\x00\x0Bgrpc-status\x011" +"\x00\x0Bgrpc-status\x012" "\x00\x04host\x00" "\x00\x08if-match\x00" "\x00\x11if-modified-since\x00" @@ -152,29 +138,38 @@ "\x00\x08if-range\x00" "\x00\x13if-unmodified-since\x00" "\x00\x0Dlast-modified\x00" -"\x00\x08lb-token\x00" "\x00\x0Blb-cost-bin\x00" +"\x00\x08lb-token\x00" "\x00\x04link\x00" "\x00\x08location\x00" "\x00\x0Cmax-forwards\x00" +"\x00\x07:method\x03GET" +"\x00\x07:method\x04POST" +"\x00\x07:method\x03PUT" +"\x00\x05:path\x01/" +"\x00\x05:path\x0B/index.html" "\x00\x12proxy-authenticate\x00" "\x00\x13proxy-authorization\x00" "\x00\x05range\x00" "\x00\x07referer\x00" "\x00\x07refresh\x00" "\x00\x0Bretry-after\x00" +"\x00\x07:scheme\x04grpc" +"\x00\x07:scheme\x04http" +"\x00\x07:scheme\x05https" "\x00\x06server\x00" "\x00\x0Aset-cookie\x00" +"\x00\x07:status\x03200" +"\x00\x07:status\x03204" +"\x00\x07:status\x03206" +"\x00\x07:status\x03304" +"\x00\x07:status\x03400" +"\x00\x07:status\x03404" +"\x00\x07:status\x03500" "\x00\x19strict-transport-security\x00" +"\x00\x02te\x08trailers" "\x00\x11transfer-encoding\x00" "\x00\x0Auser-agent\x00" "\x00\x04vary\x00" "\x00\x03via\x00" "\x00\x10www-authenticate\x00" -"\x00\x14grpc-accept-encoding\x08identity" -"\x00\x14grpc-accept-encoding\x07deflate" -"\x00\x14grpc-accept-encoding\x10identity,deflate" -"\x00\x14grpc-accept-encoding\x04gzip" -"\x00\x14grpc-accept-encoding\x0Didentity,gzip" -"\x00\x14grpc-accept-encoding\x0Cdeflate,gzip" -"\x00\x14grpc-accept-encoding\x15identity,deflate,gzip" diff --git a/test/core/end2end/fuzzers/server_fuzzer.c b/test/core/end2end/fuzzers/server_fuzzer.c index 186542d4b2d..115fb069252 100644 --- a/test/core/end2end/fuzzers/server_fuzzer.c +++ b/test/core/end2end/fuzzers/server_fuzzer.c @@ -34,7 +34,6 @@ #include #include "src/core/ext/transport/chttp2/transport/chttp2_transport.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/server.h" #include "test/core/util/memory_counters.h" #include "test/core/util/mock_endpoint.h" @@ -50,7 +49,7 @@ static int detag(void *p) { return (int)(uintptr_t)p; } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_slice_hash_seed(0); + grpc_test_only_set_metadata_hash_seed(0); struct grpc_memory_counters counters; if (squelch) gpr_set_log_function(dont_log); if (leak_check) grpc_memory_counters_init(); diff --git a/test/core/end2end/goaway_server_test.c b/test/core/end2end/goaway_server_test.c index 65fcb957816..cd68b390bbb 100644 --- a/test/core/end2end/goaway_server_test.c +++ b/test/core/end2end/goaway_server_test.c @@ -101,7 +101,8 @@ int main(int argc, char **argv) { grpc_metadata_array request_metadata1; grpc_call_details request_details1; grpc_status_code status1; - grpc_slice details1; + char *details1 = NULL; + size_t details_capacity1 = 0; grpc_metadata_array_init(&trailing_metadata_recv1); grpc_metadata_array_init(&request_metadata1); grpc_call_details_init(&request_details1); @@ -110,7 +111,8 @@ int main(int argc, char **argv) { grpc_metadata_array request_metadata2; grpc_call_details request_details2; grpc_status_code status2; - grpc_slice details2; + char *details2 = NULL; + size_t details_capacity2 = 0; grpc_metadata_array_init(&trailing_metadata_recv2); grpc_metadata_array_init(&request_metadata2); grpc_call_details_init(&request_details2); @@ -135,11 +137,9 @@ int main(int argc, char **argv) { /* create a channel that picks first amongst the servers */ grpc_channel *chan = grpc_insecure_channel_create("test", &client_args, NULL); /* and an initial call to them */ - grpc_slice host = grpc_slice_from_static_string("127.0.0.1"); - grpc_call *call1 = - grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/foo"), &host, - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); + grpc_call *call1 = grpc_channel_create_call( + chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1", + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); /* send initial metadata to probe connectivity */ memset(ops, 0, sizeof(ops)); op = ops; @@ -158,6 +158,7 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1; op->data.recv_status_on_client.status = &status1; op->data.recv_status_on_client.status_details = &details1; + op->data.recv_status_on_client.status_details_capacity = &details_capacity1; op->flags = 0; op->reserved = NULL; op++; @@ -212,10 +213,9 @@ int main(int argc, char **argv) { cq_verify_empty(cqv); /* and a new call: should go through to server2 when we start it */ - grpc_call *call2 = - grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/foo"), &host, - GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); + grpc_call *call2 = grpc_channel_create_call( + chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/foo", "127.0.0.1", + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(20), NULL); /* send initial metadata to probe connectivity */ memset(ops, 0, sizeof(ops)); op = ops; @@ -234,6 +234,7 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2; op->data.recv_status_on_client.status = &status2; op->data.recv_status_on_client.status_details = &details2; + op->data.recv_status_on_client.status_details_capacity = &details_capacity2; op->flags = 0; op->reserved = NULL; op++; @@ -299,11 +300,11 @@ int main(int argc, char **argv) { grpc_metadata_array_destroy(&trailing_metadata_recv1); grpc_metadata_array_destroy(&request_metadata1); grpc_call_details_destroy(&request_details1); - grpc_slice_unref(details1); + gpr_free(details1); grpc_metadata_array_destroy(&trailing_metadata_recv2); grpc_metadata_array_destroy(&request_metadata2); grpc_call_details_destroy(&request_details2); - grpc_slice_unref(details2); + gpr_free(details2); cq_verifier_destroy(cqv); grpc_completion_queue_destroy(cq); diff --git a/test/core/end2end/invalid_call_argument_test.c b/test/core/end2end/invalid_call_argument_test.c index a9d0287952e..d974d2c8ff9 100644 --- a/test/core/end2end/invalid_call_argument_test.c +++ b/test/core/end2end/invalid_call_argument_test.c @@ -56,7 +56,8 @@ struct test_state { grpc_metadata_array initial_metadata_recv; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - grpc_slice details; + char *details; + size_t details_capacity; grpc_call *server_call; grpc_server *server; grpc_metadata_array server_initial_metadata_recv; @@ -75,17 +76,17 @@ static void prepare_test(int is_client) { g_state.deadline = GRPC_TIMEOUT_SECONDS_TO_DEADLINE(2); g_state.cq = grpc_completion_queue_create(NULL); g_state.cqv = cq_verifier_create(g_state.cq); - g_state.details = grpc_empty_slice(); + g_state.details = NULL; + g_state.details_capacity = 0; memset(g_state.ops, 0, sizeof(g_state.ops)); if (is_client) { /* create a call, channel to a non existant server */ g_state.chan = grpc_insecure_channel_create("nonexistant:54321", NULL, NULL); - grpc_slice host = grpc_slice_from_static_string("nonexistant"); g_state.call = grpc_channel_create_call( - g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, - grpc_slice_from_static_string("/Foo"), &host, g_state.deadline, NULL); + g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, "/Foo", + "nonexistant", g_state.deadline, NULL); } else { g_state.server = grpc_server_create(NULL, NULL); grpc_server_register_completion_queue(g_state.server, g_state.cq, NULL); @@ -96,10 +97,9 @@ static void prepare_test(int is_client) { gpr_join_host_port(&server_hostport, "localhost", port); g_state.chan = grpc_insecure_channel_create(server_hostport, NULL, NULL); gpr_free(server_hostport); - grpc_slice host = grpc_slice_from_static_string("bar"); g_state.call = grpc_channel_create_call( - g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, - grpc_slice_from_static_string("/Foo"), &host, g_state.deadline, NULL); + g_state.chan, NULL, GRPC_PROPAGATE_DEFAULTS, g_state.cq, "/Foo", "bar", + g_state.deadline, NULL); grpc_metadata_array_init(&g_state.server_initial_metadata_recv); grpc_call_details_init(&g_state.call_details); op = g_state.ops; @@ -126,7 +126,7 @@ static void cleanup_test() { grpc_call_destroy(g_state.call); cq_verifier_destroy(g_state.cqv); grpc_channel_destroy(g_state.chan); - grpc_slice_unref(g_state.details); + gpr_free(g_state.details); grpc_metadata_array_destroy(&g_state.initial_metadata_recv); grpc_metadata_array_destroy(&g_state.trailing_metadata_recv); @@ -289,8 +289,7 @@ static void test_send_server_status_from_client() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -399,6 +398,8 @@ static void test_recv_status_on_client_twice() { &g_state.trailing_metadata_recv; op->data.recv_status_on_client.status = &g_state.status; op->data.recv_status_on_client.status_details = &g_state.details; + op->data.recv_status_on_client.status_details_capacity = + &g_state.details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -413,6 +414,7 @@ static void test_recv_status_on_client_twice() { op->data.recv_status_on_client.trailing_metadata = NULL; op->data.recv_status_on_client.status = NULL; op->data.recv_status_on_client.status_details = NULL; + op->data.recv_status_on_client.status_details_capacity = NULL; op->flags = 0; op->reserved = NULL; op++; @@ -451,6 +453,8 @@ static void test_recv_status_on_client_from_server() { &g_state.trailing_metadata_recv; op->data.recv_status_on_client.status = &g_state.status; op->data.recv_status_on_client.status_details = &g_state.details; + op->data.recv_status_on_client.status_details_capacity = + &g_state.details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -470,8 +474,7 @@ static void test_send_status_from_server_with_invalid_flags() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 1; op->reserved = NULL; op++; @@ -492,8 +495,7 @@ static void test_too_many_trailing_metadata() { op->data.send_status_from_server.trailing_metadata_count = (size_t)INT_MAX + 1; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -513,15 +515,14 @@ static void test_send_server_status_twice() { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -576,8 +577,9 @@ static void test_invalid_initial_metadata_reserved_key() { gpr_log(GPR_INFO, "test_invalid_initial_metadata_reserved_key"); grpc_metadata metadata; - metadata.key = grpc_slice_from_static_string(":start_with_colon"); - metadata.value = grpc_slice_from_static_string("value"); + metadata.key = ":start_with_colon"; + metadata.value = "value"; + metadata.value_length = 6; grpc_op *op; prepare_test(1); @@ -597,7 +599,6 @@ static void test_invalid_initial_metadata_reserved_key() { int main(int argc, char **argv) { grpc_test_init(argc, argv); grpc_init(); - test_invalid_initial_metadata_reserved_key(); test_non_null_reserved_on_start_batch(); test_non_null_reserved_on_op(); test_send_initial_metadata_more_than_once(); @@ -617,6 +618,7 @@ int main(int argc, char **argv) { test_send_server_status_twice(); test_recv_close_on_server_with_invalid_flags(); test_recv_close_on_server_twice(); + test_invalid_initial_metadata_reserved_key(); grpc_shutdown(); return 0; diff --git a/test/core/end2end/no_server_test.c b/test/core/end2end/no_server_test.c index 5c0f7a0f488..03ff70a1881 100644 --- a/test/core/end2end/no_server_test.c +++ b/test/core/end2end/no_server_test.c @@ -52,7 +52,8 @@ int main(int argc, char **argv) { grpc_op *op; grpc_metadata_array trailing_metadata_recv; grpc_status_code status; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_test_init(argc, argv); grpc_init(); @@ -64,10 +65,8 @@ int main(int argc, char **argv) { /* create a call, channel to a non existant server */ chan = grpc_insecure_channel_create("nonexistant:54321", NULL, NULL); - grpc_slice host = grpc_slice_from_static_string("nonexistant"); call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/Foo"), &host, - deadline, NULL); + "/Foo", "nonexistant", deadline, NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -80,6 +79,7 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -101,7 +101,7 @@ int main(int argc, char **argv) { grpc_channel_destroy(chan); cq_verifier_destroy(cqv); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_shutdown(); diff --git a/test/core/end2end/tests/authority_not_supported.c b/test/core/end2end/tests/authority_not_supported.c index 40d217e6195..705970f6cab 100644 --- a/test/core/end2end/tests/authority_not_supported.c +++ b/test/core/end2end/tests/authority_not_supported.c @@ -103,14 +103,9 @@ static void test_with_authority_header(grpc_end2end_test_config config) { grpc_byte_buffer *request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), - grpc_slice_from_static_string("val1"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key2"), - grpc_slice_from_static_string("val2"), - 0, - {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = { + {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test(config, "test_with_authority_header", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -121,12 +116,11 @@ static void test_with_authority_header(grpc_end2end_test_config config) { grpc_byte_buffer *response_payload_recv = NULL; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); + "/foo", "foo.test.google.fr", deadline, NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -163,6 +157,7 @@ static void test_with_authority_header(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -174,7 +169,7 @@ static void test_with_authority_header(grpc_end2end_test_config config) { GPR_ASSERT(status == GRPC_STATUS_CANCELLED); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/bad_hostname.c b/test/core/end2end/tests/bad_hostname.c index f18abc78f0c..e0c7ac7c021 100644 --- a/test/core/end2end/tests/bad_hostname.c +++ b/test/core/end2end/tests/bad_hostname.c @@ -109,12 +109,11 @@ static void simple_request_body(grpc_end2end_test_fixture f) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; - grpc_slice host = grpc_slice_from_static_string("slartibartfast.local"); c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), &host, - deadline, NULL); + "/foo", "slartibartfast.local", deadline, NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -142,6 +141,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -153,7 +153,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { GPR_ASSERT(status == GRPC_STATUS_INTERNAL); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/binary_metadata.c b/test/core/end2end/tests/binary_metadata.c index 004cc9e2af4..dd7a8a9ad38 100644 --- a/test/core/end2end/tests/binary_metadata.c +++ b/test/core/end2end/tests/binary_metadata.c @@ -110,25 +110,25 @@ static void test_request_response_with_metadata_and_payload( grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); grpc_metadata meta_c[2] = { - {grpc_slice_from_static_string("key1-bin"), - grpc_slice_from_static_string( - "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc"), + {"key1-bin", + "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc", + 13, 0, {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key2-bin"), - grpc_slice_from_static_string( - "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d"), + {"key2-bin", + "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d", + 14, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_metadata meta_s[2] = { - {grpc_slice_from_static_string("key3-bin"), - grpc_slice_from_static_string( - "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee"), + {"key3-bin", + "\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee", + 15, 0, {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key4-bin"), - grpc_slice_from_static_string( - "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff"), + {"key4-bin", + "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff", + 16, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( @@ -144,13 +144,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -190,6 +190,7 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -237,7 +238,7 @@ static void test_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_string = grpc_slice_from_static_string( + op->data.send_status_from_server.status_details = "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12" "\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20\x21\x22\x23\x24" "\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30\x31\x32\x33\x34\x35\x36" @@ -252,8 +253,7 @@ static void test_request_response_with_metadata_and_payload( "\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8" "\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea" "\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc" - "\xfd\xfe\xff"); - op->data.send_status_from_server.status_details = &status_string; + "\xfd\xfe\xff"; op->flags = 0; op->reserved = NULL; op++; @@ -267,25 +267,24 @@ static void test_request_response_with_metadata_and_payload( GPR_ASSERT(status == GRPC_STATUS_OK); GPR_ASSERT( 0 == - grpc_slice_str_cmp( - details, - "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" - "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20" - "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30" - "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40" - "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50" - "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60" - "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70" - "\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80" - "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" - "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0" - "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0" - "\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0" - "\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0" - "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" - "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0" - "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + strcmp(details, + "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10" + "\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f\x20" + "\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2a\x2b\x2c\x2d\x2e\x2f\x30" + "\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3a\x3b\x3c\x3d\x3e\x3f\x40" + "\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4a\x4b\x4c\x4d\x4e\x4f\x50" + "\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5a\x5b\x5c\x5d\x5e\x5f\x60" + "\x61\x62\x63\x64\x65\x66\x67\x68\x69\x6a\x6b\x6c\x6d\x6e\x6f\x70" + "\x71\x72\x73\x74\x75\x76\x77\x78\x79\x7a\x7b\x7c\x7d\x7e\x7f\x80" + "\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90" + "\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0" + "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0" + "\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0" + "\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0" + "\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0" + "\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0" + "\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -304,7 +303,7 @@ static void test_request_response_with_metadata_and_payload( &initial_metadata_recv, "key4-bin", "\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/call_creds.c b/test/core/end2end/tests/call_creds.c index ebc854606b1..606938fff64 100644 --- a/test/core/end2end/tests/call_creds.c +++ b/test/core/end2end/tests/call_creds.c @@ -156,7 +156,8 @@ static void request_response_with_payload_and_call_creds( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; grpc_call_credentials *creds = NULL; grpc_auth_context *s_auth_context = NULL; @@ -166,9 +167,8 @@ static void request_response_with_payload_and_call_creds( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); creds = grpc_google_iam_credentials_create(iam_token, iam_selector, NULL); @@ -225,6 +225,7 @@ static void request_response_with_payload_and_call_creds( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -283,8 +284,7 @@ static void request_response_with_payload_and_call_creds( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -296,8 +296,8 @@ static void request_response_with_payload_and_call_creds( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -337,7 +337,7 @@ static void request_response_with_payload_and_call_creds( break; } - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -391,7 +391,8 @@ static void test_request_with_server_rejecting_client_creds( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -403,9 +404,8 @@ static void test_request_with_server_rejecting_client_creds( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -425,6 +425,7 @@ static void test_request_with_server_rejecting_client_creds( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -467,7 +468,7 @@ static void test_request_with_server_rejecting_client_creds( grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_after_accept.c b/test/core/end2end/tests/cancel_after_accept.c index a0bec34ec9f..a8e310c6835 100644 --- a/test/core/end2end/tests/cancel_after_accept.c +++ b/test/core/end2end/tests/cancel_after_accept.c @@ -43,7 +43,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/service_config.h" @@ -119,7 +118,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = @@ -154,9 +154,8 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, cq_verifier *cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/service/method"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/service/method", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -171,6 +170,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -246,7 +246,7 @@ static void test_cancel_after_accept(grpc_end2end_test_config config, grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_call_destroy(c); grpc_call_destroy(s); diff --git a/test/core/end2end/tests/cancel_after_client_done.c b/test/core/end2end/tests/cancel_after_client_done.c index 63b8150cb63..7742f9d1798 100644 --- a/test/core/end2end/tests/cancel_after_client_done.c +++ b/test/core/end2end/tests/cancel_after_client_done.c @@ -113,7 +113,8 @@ static void test_cancel_after_accept_and_writes_closed( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *request_payload_recv = NULL; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = @@ -127,9 +128,8 @@ static void test_cancel_after_accept_and_writes_closed( int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -144,6 +144,7 @@ static void test_cancel_after_accept_and_writes_closed( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -223,7 +224,7 @@ static void test_cancel_after_accept_and_writes_closed( grpc_byte_buffer_destroy(response_payload); grpc_byte_buffer_destroy(request_payload_recv); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_call_destroy(c); grpc_call_destroy(s); diff --git a/test/core/end2end/tests/cancel_after_invoke.c b/test/core/end2end/tests/cancel_after_invoke.c index 216c3637609..c3c5418f207 100644 --- a/test/core/end2end/tests/cancel_after_invoke.c +++ b/test/core/end2end/tests/cancel_after_invoke.c @@ -113,7 +113,8 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -121,9 +122,8 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_raw_byte_buffer_create(&request_payload_slice, 1); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -138,6 +138,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -182,7 +183,7 @@ static void test_cancel_after_invoke(grpc_end2end_test_config config, grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_before_invoke.c b/test/core/end2end/tests/cancel_before_invoke.c index c198fd1713e..d4842829c0a 100644 --- a/test/core/end2end/tests/cancel_before_invoke.c +++ b/test/core/end2end/tests/cancel_before_invoke.c @@ -111,7 +111,8 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *response_payload_recv = NULL; grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); @@ -119,9 +120,8 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_raw_byte_buffer_create(&request_payload_slice, 1); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -138,6 +138,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -180,7 +181,7 @@ static void test_cancel_before_invoke(grpc_end2end_test_config config, grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_call_destroy(c); diff --git a/test/core/end2end/tests/cancel_in_a_vacuum.c b/test/core/end2end/tests/cancel_in_a_vacuum.c index af919805c7a..5be850b6ea9 100644 --- a/test/core/end2end/tests/cancel_in_a_vacuum.c +++ b/test/core/end2end/tests/cancel_in_a_vacuum.c @@ -106,9 +106,8 @@ static void test_cancel_in_a_vacuum(grpc_end2end_test_config config, cq_verifier *v_client = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); diff --git a/test/core/end2end/tests/cancel_with_status.c b/test/core/end2end/tests/cancel_with_status.c index 38f8c612d14..3aecaf71598 100644 --- a/test/core/end2end/tests/cancel_with_status.c +++ b/test/core/end2end/tests/cancel_with_status.c @@ -108,14 +108,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,6 +128,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -155,9 +156,9 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(details, "xyz")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/compressed_payload.c b/test/core/end2end/tests/compressed_payload.c index 847bc1a8c96..d7efe7747bf 100644 --- a/test/core/end2end/tests/compressed_payload.c +++ b/test/core/end2end/tests/compressed_payload.c @@ -48,7 +48,6 @@ #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/surface/call.h" #include "src/core/lib/surface/call_test_only.h" -#include "src/core/lib/transport/static_metadata.h" #include "test/core/end2end/cq_verifier.h" static void *tag(intptr_t t) { return (void *)t; } @@ -126,7 +125,8 @@ static void request_for_disabled_algorithm( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; cq_verifier *cqv; char str[1024]; @@ -151,9 +151,8 @@ static void request_for_disabled_algorithm( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -192,6 +191,7 @@ static void request_for_disabled_algorithm( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -245,13 +245,13 @@ static void request_for_disabled_algorithm( gpr_asprintf(&expected_details, "Compression algorithm '%s' is disabled.", algo_name); /* and we expect a specific reason for it */ - GPR_ASSERT(0 == grpc_slice_str_cmp(details, expected_details)); + GPR_ASSERT(0 == strcmp(details, expected_details)); gpr_free(expected_details); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -305,7 +305,8 @@ static void request_with_payload_template( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; cq_verifier *cqv; char request_str[1024]; @@ -330,9 +331,8 @@ static void request_with_payload_template( cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -362,6 +362,7 @@ static void request_with_payload_template( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -488,8 +489,7 @@ static void request_with_payload_template( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -503,13 +503,13 @@ static void request_with_payload_template( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -569,14 +569,17 @@ static void test_invoke_request_with_compressed_payload_md_override( grpc_metadata gzip_compression_override; grpc_metadata identity_compression_override; - gzip_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; - gzip_compression_override.value = grpc_slice_from_static_string("gzip"); + gzip_compression_override.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; + gzip_compression_override.value = "gzip"; + gzip_compression_override.value_length = + strlen(gzip_compression_override.value); memset(&gzip_compression_override.internal_data, 0, sizeof(gzip_compression_override.internal_data)); - identity_compression_override.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; - identity_compression_override.value = - grpc_slice_from_static_string("identity"); + identity_compression_override.key = GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY; + identity_compression_override.value = "identity"; + identity_compression_override.value_length = + strlen(identity_compression_override.value); memset(&identity_compression_override.internal_data, 0, sizeof(identity_compression_override.internal_data)); diff --git a/test/core/end2end/tests/default_host.c b/test/core/end2end/tests/default_host.c index 0c39957fa78..208e31697e6 100644 --- a/test/core/end2end/tests/default_host.c +++ b/test/core/end2end/tests/default_host.c @@ -110,13 +110,13 @@ static void simple_request_body(grpc_end2end_test_fixture f) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; char *peer; c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), NULL, - deadline, NULL); + "/foo", NULL, deadline, NULL); GPR_ASSERT(c); peer = grpc_call_get_peer(c); @@ -149,6 +149,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -181,8 +182,7 @@ static void simple_request_body(grpc_end2end_test_fixture f) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -199,12 +199,12 @@ static void simple_request_body(grpc_end2end_test_fixture f) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); - GPR_ASSERT(grpc_slice_buf_start_eq(call_details.host, "localhost", 9)); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strncmp(call_details.host, "localhost", 9)); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/disappearing_server.c b/test/core/end2end/tests/disappearing_server.c index a01372144c0..8ebf7e643e0 100644 --- a/test/core/end2end/tests/disappearing_server.c +++ b/test/core/end2end/tests/disappearing_server.c @@ -93,13 +93,13 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,6 +128,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -155,8 +156,7 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -174,13 +174,13 @@ static void do_request_and_shutdown_server(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/empty_batch.c b/test/core/end2end/tests/empty_batch.c index 1b420ad4cbc..dc8e52a60f0 100644 --- a/test/core/end2end/tests/empty_batch.c +++ b/test/core/end2end/tests/empty_batch.c @@ -106,9 +106,8 @@ static void empty_batch_body(grpc_end2end_test_config config, grpc_op *op = NULL; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); diff --git a/test/core/end2end/tests/filter_call_init_fails.c b/test/core/end2end/tests/filter_call_init_fails.c index e91c8aa54fb..ac9d2dd2fe8 100644 --- a/test/core/end2end/tests/filter_call_init_fails.c +++ b/test/core/end2end/tests/filter_call_init_fails.c @@ -125,12 +125,12 @@ static void test_request(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -165,6 +165,7 @@ static void test_request(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -180,9 +181,9 @@ static void test_request(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "access denied")); + GPR_ASSERT(0 == strcmp(details, "access denied")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/filter_causes_close.c b/test/core/end2end/tests/filter_causes_close.c index a1f7d1b6a79..45f623c5c7b 100644 --- a/test/core/end2end/tests/filter_causes_close.c +++ b/test/core/end2end/tests/filter_causes_close.c @@ -121,12 +121,12 @@ static void test_request(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -161,6 +161,7 @@ static void test_request(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -176,10 +177,9 @@ static void test_request(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_PERMISSION_DENIED); - GPR_ASSERT(0 == - grpc_slice_str_cmp(details, "Failure that's not preventable.")); + GPR_ASSERT(0 == strcmp(details, "Failure that's not preventable.")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -208,12 +208,18 @@ static void recv_im_ready(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) { grpc_call_element *elem = arg; call_data *calld = elem->call_data; + if (error == GRPC_ERROR_NONE) { + // close the stream with an error. + grpc_slice message = + grpc_slice_from_copied_string("Failure that's not preventable."); + grpc_transport_stream_op *op = grpc_make_transport_stream_op(NULL); + grpc_transport_stream_op_add_close(exec_ctx, op, + GRPC_STATUS_PERMISSION_DENIED, &message); + grpc_call_next_op(exec_ctx, elem, op); + } grpc_closure_sched( exec_ctx, calld->recv_im_ready, - grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING( - "Failure that's not preventable.", &error, 1), - GRPC_ERROR_INT_GRPC_STATUS, - GRPC_STATUS_PERMISSION_DENIED)); + GRPC_ERROR_CREATE_REFERENCING("Forced call to close", &error, 1)); } static void start_transport_stream_op(grpc_exec_ctx *exec_ctx, diff --git a/test/core/end2end/tests/filter_latency.c b/test/core/end2end/tests/filter_latency.c index 7f37c461374..dbb5c8dcd9d 100644 --- a/test/core/end2end/tests/filter_latency.c +++ b/test/core/end2end/tests/filter_latency.c @@ -128,7 +128,8 @@ static void test_request(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; gpr_mu_lock(&g_mu); @@ -137,10 +138,8 @@ static void test_request(grpc_end2end_test_config config) { gpr_mu_unlock(&g_mu); const gpr_timespec start_time = gpr_now(GPR_CLOCK_MONOTONIC); - c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr", config), deadline, NULL); + c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + "/foo", "foo.test.google.fr", deadline, NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -174,6 +173,7 @@ static void test_request(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -198,8 +198,7 @@ static void test_request(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_string = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_string; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -216,9 +215,9 @@ static void test_request(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(details, "xyz")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/graceful_server_shutdown.c b/test/core/end2end/tests/graceful_server_shutdown.c index 08af25dd282..5fecadbe441 100644 --- a/test/core/end2end/tests/graceful_server_shutdown.c +++ b/test/core/end2end/tests/graceful_server_shutdown.c @@ -107,13 +107,13 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -143,6 +143,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -170,8 +171,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -191,12 +191,12 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_destroy(s); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/high_initial_seqno.c b/test/core/end2end/tests/high_initial_seqno.c index 217ca2bb726..01a4909ccdb 100644 --- a/test/core/end2end/tests/high_initial_seqno.c +++ b/test/core/end2end/tests/high_initial_seqno.c @@ -113,13 +113,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -148,6 +148,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -171,8 +172,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -189,13 +189,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/hpack_size.c b/test/core/end2end/tests/hpack_size.c index 9aedc9c1436..cec8b2faae1 100644 --- a/test/core/end2end/tests/hpack_size.c +++ b/test/core/end2end/tests/hpack_size.c @@ -254,24 +254,24 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_status_code status; grpc_call_error error; grpc_metadata extra_metadata[3]; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; memset(extra_metadata, 0, sizeof(extra_metadata)); - extra_metadata[0].key = grpc_slice_from_static_string("hobbit-first-name"); - extra_metadata[0].value = grpc_slice_from_static_string( - hobbits[index % GPR_ARRAY_SIZE(hobbits)][0]); - extra_metadata[1].key = grpc_slice_from_static_string("hobbit-second-name"); - extra_metadata[1].value = grpc_slice_from_static_string( - hobbits[index % GPR_ARRAY_SIZE(hobbits)][1]); - extra_metadata[2].key = grpc_slice_from_static_string("dragon"); - extra_metadata[2].value = - grpc_slice_from_static_string(dragons[index % GPR_ARRAY_SIZE(dragons)]); + extra_metadata[0].key = "hobbit-first-name"; + extra_metadata[0].value = hobbits[index % GPR_ARRAY_SIZE(hobbits)][0]; + extra_metadata[0].value_length = strlen(extra_metadata[0].value); + extra_metadata[1].key = "hobbit-second-name"; + extra_metadata[1].value = hobbits[index % GPR_ARRAY_SIZE(hobbits)][1]; + extra_metadata[1].value_length = strlen(extra_metadata[1].value); + extra_metadata[2].key = "dragon"; + extra_metadata[2].value = dragons[index % GPR_ARRAY_SIZE(dragons)]; + extra_metadata[2].value_length = strlen(extra_metadata[2].value); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -301,6 +301,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -324,8 +325,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -342,13 +342,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/idempotent_request.c b/test/core/end2end/tests/idempotent_request.c index 2db7accaaa4..4f6d3bb808c 100644 --- a/test/core/end2end/tests/idempotent_request.c +++ b/test/core/end2end/tests/idempotent_request.c @@ -111,14 +111,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,6 +152,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -184,8 +185,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -202,14 +202,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST == call_details.flags); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/invoke_large_request.c b/test/core/end2end/tests/invoke_large_request.c index e18953a6410..24abfa2ea0d 100644 --- a/test/core/end2end/tests/invoke_large_request.c +++ b/test/core/end2end/tests/invoke_large_request.c @@ -140,13 +140,13 @@ static void test_invoke_large_request(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -185,6 +185,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -231,8 +232,7 @@ static void test_invoke_large_request(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -244,13 +244,13 @@ static void test_invoke_large_request(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/large_metadata.c b/test/core/end2end/tests/large_metadata.c index b45ceb26643..69b4b24b061 100644 --- a/test/core/end2end/tests/large_metadata.c +++ b/test/core/end2end/tests/large_metadata.c @@ -122,19 +122,21 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); - meta.key = grpc_slice_from_static_string("key"); - meta.value = grpc_slice_malloc(large_size); - memset(GRPC_SLICE_START_PTR(meta.value), 'a', large_size); + meta.key = "key"; + meta.value = gpr_malloc(large_size + 1); + memset((char *)meta.value, 'a', large_size); + ((char *)meta.value)[large_size] = 0; + meta.value_length = large_size; grpc_metadata_array_init(&initial_metadata_recv); grpc_metadata_array_init(&trailing_metadata_recv); @@ -168,6 +170,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -213,8 +216,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -226,17 +228,15 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); - GPR_ASSERT(contains_metadata_slices(&request_metadata_recv, - grpc_slice_from_static_string("key"), - meta.value)); + GPR_ASSERT(contains_metadata(&request_metadata_recv, "key", meta.value)); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -250,7 +250,7 @@ static void test_request_with_large_metadata(grpc_end2end_test_config config) { grpc_byte_buffer_destroy(request_payload); grpc_byte_buffer_destroy(request_payload_recv); - grpc_slice_unref(meta.value); + gpr_free((char *)meta.value); end_test(&f); config.tear_down_data(&f); diff --git a/test/core/end2end/tests/load_reporting_hook.c b/test/core/end2end/tests/load_reporting_hook.c index edc42511191..ae5c2706299 100644 --- a/test/core/end2end/tests/load_reporting_hook.c +++ b/test/core/end2end/tests/load_reporting_hook.c @@ -146,13 +146,13 @@ static void request_response_with_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string(method_name), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, method_name, + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -193,6 +193,7 @@ static void request_response_with_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -241,8 +242,7 @@ static void request_response_with_payload( op->data.send_status_from_server.trailing_metadata_count = 1; op->data.send_status_from_server.trailing_metadata = trailing_lr_metadata; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -255,7 +255,7 @@ static void request_response_with_payload( GPR_ASSERT(status == GRPC_STATUS_OK); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -295,13 +295,15 @@ static void test_load_reporting_hook(grpc_end2end_test_config config) { grpc_metadata initial_lr_metadata; grpc_metadata trailing_lr_metadata; - initial_lr_metadata.key = GRPC_MDSTR_LB_TOKEN; - initial_lr_metadata.value = grpc_slice_from_static_string("client-token"); + initial_lr_metadata.key = GRPC_LB_TOKEN_MD_KEY; + initial_lr_metadata.value = "client-token"; + initial_lr_metadata.value_length = strlen(initial_lr_metadata.value); memset(&initial_lr_metadata.internal_data, 0, sizeof(initial_lr_metadata.internal_data)); - trailing_lr_metadata.key = GRPC_MDSTR_LB_COST_BIN; - trailing_lr_metadata.value = grpc_slice_from_static_string("server-token"); + trailing_lr_metadata.key = GRPC_LB_COST_MD_KEY; + trailing_lr_metadata.value = "server-token"; + trailing_lr_metadata.value_length = strlen(trailing_lr_metadata.value); memset(&trailing_lr_metadata.internal_data, 0, sizeof(trailing_lr_metadata.internal_data)); diff --git a/test/core/end2end/tests/max_concurrent_streams.c b/test/core/end2end/tests/max_concurrent_streams.c index b34ea40f1b3..9338bc5f0d7 100644 --- a/test/core/end2end/tests/max_concurrent_streams.c +++ b/test/core/end2end/tests/max_concurrent_streams.c @@ -109,13 +109,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -144,6 +144,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -167,8 +168,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -185,13 +185,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -223,9 +223,11 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { grpc_metadata_array trailing_metadata_recv2; grpc_status_code status1; grpc_call_error error; - grpc_slice details1; + char *details1 = NULL; + size_t details_capacity1 = 0; grpc_status_code status2; - grpc_slice details2; + char *details2 = NULL; + size_t details_capacity2 = 0; grpc_op ops[6]; grpc_op *op; int was_cancelled; @@ -259,15 +261,13 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { the first completes */ deadline = n_seconds_time(1000); c1 = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/alpha"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/alpha", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c1); c2 = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/beta"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/beta", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c2); @@ -295,6 +295,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv1; op->data.recv_status_on_client.status = &status1; op->data.recv_status_on_client.status_details = &details1; + op->data.recv_status_on_client.status_details_capacity = &details_capacity1; op->flags = 0; op->reserved = NULL; op++; @@ -326,6 +327,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv2; op->data.recv_status_on_client.status = &status2; op->data.recv_status_on_client.status_details = &details2; + op->data.recv_status_on_client.status_details_capacity = &details_capacity2; op->flags = 0; op->reserved = NULL; op++; @@ -376,8 +378,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -391,8 +392,6 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { CQ_EXPECT_COMPLETION(cqv, tag(live_call + 1), 1); cq_verify(cqv); - grpc_call_details_destroy(&call_details); - GPR_ASSERT(GRPC_CALL_OK == grpc_server_request_call( f.server, &s2, &call_details, &request_metadata_recv, f.cq, f.cq, tag(201))); @@ -414,7 +413,7 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -432,8 +431,8 @@ static void test_max_concurrent_streams(grpc_end2end_test_config config) { grpc_call_destroy(c2); grpc_call_destroy(s2); - grpc_slice_unref(details1); - grpc_slice_unref(details2); + gpr_free(details1); + gpr_free(details2); grpc_metadata_array_destroy(&initial_metadata_recv1); grpc_metadata_array_destroy(&trailing_metadata_recv1); grpc_metadata_array_destroy(&initial_metadata_recv2); diff --git a/test/core/end2end/tests/max_message_length.c b/test/core/end2end/tests/max_message_length.c index 4140df9aade..4a6ef44bb32 100644 --- a/test/core/end2end/tests/max_message_length.c +++ b/test/core/end2end/tests/max_message_length.c @@ -43,7 +43,6 @@ #include #include "src/core/lib/channel/channel_args.h" -#include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/transport/metadata.h" #include "src/core/lib/transport/service_config.h" @@ -130,7 +129,8 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; grpc_channel_args *client_args = NULL; @@ -178,9 +178,8 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, cqv = cq_verifier_create(f.cq); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/service/method"), - get_host_override_slice("foo.test.google.fr:1234", config), + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/service/method", + get_host_override_string("foo.test.google.fr:1234", config), gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); @@ -214,6 +213,7 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -252,20 +252,19 @@ static void test_max_message_length_on_request(grpc_end2end_test_config config, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method")); + GPR_ASSERT(0 == strcmp(call_details.method, "/service/method")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); done: GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT); - GPR_ASSERT( - grpc_slice_str_cmp( - details, send_limit - ? "Sent message larger than max (11 vs. 5)" - : "Received message larger than max (11 vs. 5)") == 0); + GPR_ASSERT(strcmp(details, + send_limit + ? "Sent message larger than max (11 vs. 5)" + : "Received message larger than max (11 vs. 5)") == 0); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); @@ -308,7 +307,8 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; grpc_channel_args *client_args = NULL; @@ -354,11 +354,9 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, } cqv = cq_verifier_create(f.cq); - c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/service/method"), - get_host_override_slice("foo.test.google.fr:1234", config), - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + c = grpc_channel_create_call(f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, + "/service/method", "foo.test.google.fr:1234", + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(c); grpc_metadata_array_init(&initial_metadata_recv); @@ -391,6 +389,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -424,8 +423,7 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -436,18 +434,16 @@ static void test_max_message_length_on_response(grpc_end2end_test_config config, CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/service/method")); - GPR_ASSERT(0 == - grpc_slice_str_cmp(call_details.host, "foo.test.google.fr:1234")); + GPR_ASSERT(0 == strcmp(call_details.method, "/service/method")); + GPR_ASSERT(0 == strcmp(call_details.host, "foo.test.google.fr:1234")); GPR_ASSERT(status == GRPC_STATUS_INVALID_ARGUMENT); - GPR_ASSERT( - grpc_slice_str_cmp( - details, send_limit - ? "Sent message larger than max (11 vs. 5)" - : "Received message larger than max (11 vs. 5)") == 0); + GPR_ASSERT(strcmp(details, + send_limit + ? "Sent message larger than max (11 vs. 5)" + : "Received message larger than max (11 vs. 5)") == 0); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/negative_deadline.c b/test/core/end2end/tests/negative_deadline.c index 403386b5e75..929777d39ef 100644 --- a/test/core/end2end/tests/negative_deadline.c +++ b/test/core/end2end/tests/negative_deadline.c @@ -108,14 +108,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; gpr_log(GPR_DEBUG, "test with %" PRIuPTR " ops", num_ops); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -128,6 +128,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -154,7 +155,7 @@ static void simple_request_body(grpc_end2end_test_config config, GPR_ASSERT(status == GRPC_STATUS_DEADLINE_EXCEEDED); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); diff --git a/test/core/end2end/tests/network_status_change.c b/test/core/end2end/tests/network_status_change.c index 6cfeaa851a2..2ebda2ccb85 100644 --- a/test/core/end2end/tests/network_status_change.c +++ b/test/core/end2end/tests/network_status_change.c @@ -119,13 +119,13 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -159,6 +159,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -200,8 +201,7 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -214,11 +214,11 @@ static void test_invoke_network_status_change(grpc_end2end_test_config config) { // Expected behavior of a RPC when network is lost. GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/no_logging.c b/test/core/end2end/tests/no_logging.c index 5c22631badb..54614cb0291 100644 --- a/test/core/end2end/tests/no_logging.c +++ b/test/core/end2end/tests/no_logging.c @@ -139,14 +139,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -179,6 +179,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -209,8 +210,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -227,14 +227,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(0 == call_details.flags); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/payload.c b/test/core/end2end/tests/payload.c index af0c819e382..4a88c5f2a81 100644 --- a/test/core/end2end/tests/payload.c +++ b/test/core/end2end/tests/payload.c @@ -138,13 +138,13 @@ static void request_response_with_payload(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -183,6 +183,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -229,8 +230,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -242,8 +242,8 @@ static void request_response_with_payload(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -251,7 +251,7 @@ static void request_response_with_payload(grpc_end2end_test_config config, GPR_ASSERT( byte_buffer_eq_slice(response_payload_recv, response_payload_slice)); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/ping_pong_streaming.c b/test/core/end2end/tests/ping_pong_streaming.c index b69b7f27a66..0a1566e9c25 100644 --- a/test/core/end2end/tests/ping_pong_streaming.c +++ b/test/core/end2end/tests/ping_pong_streaming.c @@ -112,7 +112,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; grpc_byte_buffer *request_payload; grpc_byte_buffer *request_payload_recv; @@ -125,9 +126,8 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_slice_from_copied_string("hello you"); c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,6 +152,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -247,8 +248,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -270,7 +270,7 @@ static void test_pingpong_streaming(grpc_end2end_test_config config, grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); grpc_call_details_destroy(&call_details); - grpc_slice_unref(details); + gpr_free(details); end_test(&f); config.tear_down_data(&f); diff --git a/test/core/end2end/tests/registered_call.c b/test/core/end2end/tests/registered_call.c index e0716737a3a..6594b420b9d 100644 --- a/test/core/end2end/tests/registered_call.c +++ b/test/core/end2end/tests/registered_call.c @@ -111,7 +111,8 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_registered_call( @@ -143,6 +144,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -166,8 +168,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -184,13 +185,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/request_with_flags.c b/test/core/end2end/tests/request_with_flags.c index 1328a7e891f..9c18e155f32 100644 --- a/test/core/end2end/tests/request_with_flags.c +++ b/test/core/end2end/tests/request_with_flags.c @@ -117,13 +117,13 @@ static void test_invoke_request_with_flags( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_call_error expectation; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -157,6 +157,7 @@ static void test_invoke_request_with_flags( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = flags_for_op[op->op]; op->reserved = NULL; op++; @@ -167,9 +168,9 @@ static void test_invoke_request_with_flags( if (expectation == GRPC_CALL_OK) { CQ_EXPECT_COMPLETION(cqv, tag(1), 1); cq_verify(cqv); - grpc_slice_unref(details); } + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/request_with_payload.c b/test/core/end2end/tests/request_with_payload.c index 3258c0451b3..c84e3ac5b50 100644 --- a/test/core/end2end/tests/request_with_payload.c +++ b/test/core/end2end/tests/request_with_payload.c @@ -116,13 +116,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -156,6 +156,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -196,8 +197,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -209,14 +209,14 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/resource_quota_server.c b/test/core/end2end/tests/resource_quota_server.c index f65d60327ca..c919faea89f 100644 --- a/test/core/end2end/tests/resource_quota_server.c +++ b/test/core/end2end/tests/resource_quota_server.c @@ -149,7 +149,8 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_call_details *call_details = malloc(sizeof(grpc_call_details) * NUM_CALLS); grpc_status_code *status = malloc(sizeof(grpc_status_code) * NUM_CALLS); - grpc_slice *details = malloc(sizeof(grpc_slice) * NUM_CALLS); + char **details = malloc(sizeof(char *) * NUM_CALLS); + size_t *details_capacity = malloc(sizeof(size_t) * NUM_CALLS); grpc_byte_buffer **request_payload_recv = malloc(sizeof(grpc_byte_buffer *) * NUM_CALLS); int *was_cancelled = malloc(sizeof(int) * NUM_CALLS); @@ -172,6 +173,8 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_init(&trailing_metadata_recv[i]); grpc_metadata_array_init(&request_metadata_recv[i]); grpc_call_details_init(&call_details[i]); + details[i] = NULL; + details_capacity[i] = 0; request_payload_recv[i] = NULL; was_cancelled[i] = 0; } @@ -187,10 +190,8 @@ void resource_quota_server(grpc_end2end_test_config config) { for (int i = 0; i < NUM_CALLS; i++) { client_calls[i] = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr", config), - n_seconds_time(60), NULL); + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + "foo.test.google.fr", n_seconds_time(60), NULL); memset(ops, 0, sizeof(ops)); op = ops; @@ -218,6 +219,8 @@ void resource_quota_server(grpc_end2end_test_config config) { &trailing_metadata_recv[i]; op->data.recv_status_on_client.status = &status[i]; op->data.recv_status_on_client.status_details = &details[i]; + op->data.recv_status_on_client.status_details_capacity = + &details_capacity[i]; op->flags = 0; op->reserved = NULL; op++; @@ -257,7 +260,7 @@ void resource_quota_server(grpc_end2end_test_config config) { grpc_metadata_array_destroy(&initial_metadata_recv[call_id]); grpc_metadata_array_destroy(&trailing_metadata_recv[call_id]); grpc_call_destroy(client_calls[call_id]); - grpc_slice_unref(details[call_id]); + gpr_free(details[call_id]); pending_client_calls--; } else if (ev_tag < SERVER_RECV_BASE_TAG) { @@ -314,8 +317,7 @@ void resource_quota_server(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -351,6 +353,10 @@ void resource_quota_server(grpc_end2end_test_config config) { * the client has received it. This means that we should see strictly more * failures on the client than on the server. */ GPR_ASSERT(cancelled_calls_on_client >= cancelled_calls_on_server); + /* However, we shouldn't see radically more... 0.9 is a guessed bound on what + * we'd want that ratio to be... to at least trigger some investigation should + * that ratio become much higher. */ + GPR_ASSERT(cancelled_calls_on_server >= 0.9 * cancelled_calls_on_client); grpc_byte_buffer_destroy(request_payload); grpc_slice_unref(request_payload_slice); @@ -364,6 +370,7 @@ void resource_quota_server(grpc_end2end_test_config config) { free(call_details); free(status); free(details); + free(details_capacity); free(request_payload_recv); free(was_cancelled); diff --git a/test/core/end2end/tests/server_finishes_request.c b/test/core/end2end/tests/server_finishes_request.c index ee18c6817b7..3bb25fd9242 100644 --- a/test/core/end2end/tests/server_finishes_request.c +++ b/test/core/end2end/tests/server_finishes_request.c @@ -111,13 +111,13 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -142,6 +142,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -165,8 +166,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -183,13 +183,13 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/shutdown_finishes_calls.c b/test/core/end2end/tests/shutdown_finishes_calls.c index 0be53153604..b80a2e35f23 100644 --- a/test/core/end2end/tests/shutdown_finishes_calls.c +++ b/test/core/end2end/tests/shutdown_finishes_calls.c @@ -100,13 +100,13 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -136,6 +136,7 @@ static void test_early_server_shutdown_finishes_inflight_calls( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -171,12 +172,12 @@ static void test_early_server_shutdown_finishes_inflight_calls( grpc_server_destroy(f.server); GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_cacheable_request.c b/test/core/end2end/tests/simple_cacheable_request.c index ea916e7b3a5..2c229b08fe9 100644 --- a/test/core/end2end/tests/simple_cacheable_request.c +++ b/test/core/end2end/tests/simple_cacheable_request.c @@ -111,22 +111,12 @@ static void test_cacheable_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), - grpc_slice_from_static_string("val1"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key2"), - grpc_slice_from_static_string("val2"), - 0, - {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), - grpc_slice_from_static_string("val3"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key4"), - grpc_slice_from_static_string("val4"), - 0, - {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = { + {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = { + {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_cacheable_request_response_with_metadata_and_payload", NULL, NULL); @@ -141,13 +131,13 @@ static void test_cacheable_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -187,6 +177,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -234,8 +225,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -247,8 +237,8 @@ static void test_cacheable_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); if (config.feature_mask & FEATURE_MASK_SUPPORTS_REQUEST_PROXYING) { @@ -264,7 +254,7 @@ static void test_cacheable_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3")); GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_delayed_request.c b/test/core/end2end/tests/simple_delayed_request.c index b0c98c51abc..414a03d98bb 100644 --- a/test/core/end2end/tests/simple_delayed_request.c +++ b/test/core/end2end/tests/simple_delayed_request.c @@ -100,15 +100,15 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; config.init_client(f, client_args); c = grpc_channel_create_call( - f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f->client, NULL, GRPC_PROPAGATE_DEFAULTS, f->cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -137,6 +137,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -162,8 +163,7 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -180,13 +180,13 @@ static void simple_delayed_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_metadata.c b/test/core/end2end/tests/simple_metadata.c index 162c89c6180..5490cc2b75f 100644 --- a/test/core/end2end/tests/simple_metadata.c +++ b/test/core/end2end/tests/simple_metadata.c @@ -109,22 +109,12 @@ static void test_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), - grpc_slice_from_static_string("val1"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key2"), - grpc_slice_from_static_string("val2"), - 0, - {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), - grpc_slice_from_static_string("val3"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key4"), - grpc_slice_from_static_string("val4"), - 0, - {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = { + {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = { + {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_request_response_with_metadata_and_payload", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -138,13 +128,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -184,6 +174,7 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -231,8 +222,7 @@ static void test_request_response_with_metadata_and_payload( op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -244,8 +234,8 @@ static void test_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); @@ -256,7 +246,7 @@ static void test_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key3", "val3")); GPR_ASSERT(contains_metadata(&initial_metadata_recv, "key4", "val4")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/simple_request.c b/test/core/end2end/tests/simple_request.c index e0a69826c4c..2dea5d6af2e 100644 --- a/test/core/end2end/tests/simple_request.c +++ b/test/core/end2end/tests/simple_request.c @@ -111,14 +111,14 @@ static void simple_request_body(grpc_end2end_test_config config, grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; char *peer; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -152,6 +152,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -184,8 +185,7 @@ static void simple_request_body(grpc_end2end_test_config config, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_UNIMPLEMENTED; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -202,14 +202,14 @@ static void simple_request_body(grpc_end2end_test_config config, cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_UNIMPLEMENTED); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(0 == call_details.flags); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/streaming_error_response.c b/test/core/end2end/tests/streaming_error_response.c index 05012523a73..583bc9268f4 100644 --- a/test/core/end2end/tests/streaming_error_response.c +++ b/test/core/end2end/tests/streaming_error_response.c @@ -121,13 +121,13 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -154,6 +154,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; } error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(1), NULL); @@ -201,8 +202,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_FAILED_PRECONDITION; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op++; error = grpc_call_start_batch(s, ops, (size_t)(op - ops), tag(104), NULL); GPR_ASSERT(GRPC_CALL_OK == error); @@ -232,6 +232,7 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; error = grpc_call_start_batch(c, ops, (size_t)(op - ops), tag(3), NULL); GPR_ASSERT(GRPC_CALL_OK == error); @@ -244,13 +245,13 @@ static void test(grpc_end2end_test_config config, bool request_status_early) { } GPR_ASSERT(status == GRPC_STATUS_FAILED_PRECONDITION); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 1); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/trailing_metadata.c b/test/core/end2end/tests/trailing_metadata.c index b6741dbf3d0..9fd4fbc052f 100644 --- a/test/core/end2end/tests/trailing_metadata.c +++ b/test/core/end2end/tests/trailing_metadata.c @@ -109,30 +109,15 @@ static void test_request_response_with_metadata_and_payload( grpc_byte_buffer *response_payload = grpc_raw_byte_buffer_create(&response_payload_slice, 1); gpr_timespec deadline = five_seconds_time(); - grpc_metadata meta_c[2] = {{grpc_slice_from_static_string("key1"), - grpc_slice_from_static_string("val1"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key2"), - grpc_slice_from_static_string("val2"), - 0, - {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_s[2] = {{grpc_slice_from_static_string("key3"), - grpc_slice_from_static_string("val3"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key4"), - grpc_slice_from_static_string("val4"), - 0, - {{NULL, NULL, NULL, NULL}}}}; - grpc_metadata meta_t[2] = {{grpc_slice_from_static_string("key5"), - grpc_slice_from_static_string("val5"), - 0, - {{NULL, NULL, NULL, NULL}}}, - {grpc_slice_from_static_string("key6"), - grpc_slice_from_static_string("val6"), - 0, - {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_c[2] = { + {"key1", "val1", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key2", "val2", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_s[2] = { + {"key3", "val3", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key4", "val4", 4, 0, {{NULL, NULL, NULL, NULL}}}}; + grpc_metadata meta_t[2] = { + {"key5", "val5", 4, 0, {{NULL, NULL, NULL, NULL}}}, + {"key6", "val6", 4, 0, {{NULL, NULL, NULL, NULL}}}}; grpc_end2end_test_fixture f = begin_test( config, "test_request_response_with_metadata_and_payload", NULL, NULL); cq_verifier *cqv = cq_verifier_create(f.cq); @@ -146,13 +131,13 @@ static void test_request_response_with_metadata_and_payload( grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -192,6 +177,7 @@ static void test_request_response_with_metadata_and_payload( op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -240,8 +226,7 @@ static void test_request_response_with_metadata_and_payload( op->data.send_status_from_server.trailing_metadata_count = 2; op->data.send_status_from_server.trailing_metadata = meta_t; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -253,8 +238,8 @@ static void test_request_response_with_metadata_and_payload( cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv, "hello world")); @@ -266,7 +251,7 @@ static void test_request_response_with_metadata_and_payload( GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key5", "val5")); GPR_ASSERT(contains_metadata(&trailing_metadata_recv, "key6", "val6")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/write_buffering.c b/test/core/end2end/tests/write_buffering.c index fc175595a55..856e9f0306f 100644 --- a/test/core/end2end/tests/write_buffering.c +++ b/test/core/end2end/tests/write_buffering.c @@ -120,13 +120,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details = grpc_empty_slice(); + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -228,6 +228,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -243,8 +244,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -256,15 +256,15 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv2, "abc123")); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/end2end/tests/write_buffering_at_end.c b/test/core/end2end/tests/write_buffering_at_end.c index 6b9a4c58f15..43aefcbdbcc 100644 --- a/test/core/end2end/tests/write_buffering_at_end.c +++ b/test/core/end2end/tests/write_buffering_at_end.c @@ -117,13 +117,13 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { grpc_call_details call_details; grpc_status_code status; grpc_call_error error; - grpc_slice details = grpc_empty_slice(); + char *details = NULL; + size_t details_capacity = 0; int was_cancelled = 2; c = grpc_channel_create_call( - f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, - grpc_slice_from_static_string("/foo"), - get_host_override_slice("foo.test.google.fr:1234", config), deadline, + f.client, NULL, GRPC_PROPAGATE_DEFAULTS, f.cq, "/foo", + get_host_override_string("foo.test.google.fr:1234", config), deadline, NULL); GPR_ASSERT(c); @@ -219,6 +219,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -234,8 +235,7 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -247,15 +247,15 @@ static void test_invoke_request_with_payload(grpc_end2end_test_config config) { cq_verify(cqv); GPR_ASSERT(status == GRPC_STATUS_OK); - GPR_ASSERT(0 == grpc_slice_str_cmp(details, "xyz")); - GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo")); + GPR_ASSERT(0 == strcmp(details, "xyz")); + GPR_ASSERT(0 == strcmp(call_details.method, "/foo")); validate_host_override_string("foo.test.google.fr:1234", call_details.host, config); GPR_ASSERT(was_cancelled == 0); GPR_ASSERT(byte_buffer_eq_string(request_payload_recv1, "hello world")); GPR_ASSERT(request_payload_recv2 == NULL); - grpc_slice_unref(details); + gpr_free(details); grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); grpc_metadata_array_destroy(&request_metadata_recv); diff --git a/test/core/fling/client.c b/test/core/fling/client.c index bb44320f34b..e717b7f7fed 100644 --- a/test/core/fling/client.c +++ b/test/core/fling/client.c @@ -57,7 +57,8 @@ static grpc_metadata_array initial_metadata_recv; static grpc_metadata_array trailing_metadata_recv; static grpc_byte_buffer *response_payload_recv = NULL; static grpc_status_code status; -static grpc_slice details; +static char *details = NULL; +static size_t details_capacity = 0; static grpc_op *op; static void init_ping_pong_request(void) { @@ -85,16 +86,15 @@ static void init_ping_pong_request(void) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op++; } static void step_ping_pong_request(void) { GPR_TIMER_BEGIN("ping_pong", 1); - grpc_slice host = grpc_slice_from_static_string("localhost"); - call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/Reflector/reflectUnary"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + call = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + "/Reflector/reflectUnary", "localhost", + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(call, ops, (size_t)(op - ops), (void *)1, NULL)); @@ -109,11 +109,9 @@ static void init_ping_pong_stream(void) { grpc_metadata_array_init(&initial_metadata_recv); grpc_call_error error; - grpc_slice host = grpc_slice_from_static_string("localhost"); - call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/Reflector/reflectStream"), &host, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + call = grpc_channel_create_call(channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, + "/Reflector/reflectStream", "localhost", + gpr_inf_future(GPR_CLOCK_REALTIME), NULL); stream_init_ops[0].op = GRPC_OP_SEND_INITIAL_METADATA; stream_init_ops[0].data.send_initial_metadata.count = 0; stream_init_ops[1].op = GRPC_OP_RECV_INITIAL_METADATA; diff --git a/test/core/fling/server.c b/test/core/fling/server.c index d4849e3bbe9..fd446f1128e 100644 --- a/test/core/fling/server.c +++ b/test/core/fling/server.c @@ -118,7 +118,7 @@ static void handle_unary_method(void) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.status = GRPC_STATUS_OK; op->data.send_status_from_server.trailing_metadata_count = 0; - op->data.send_status_from_server.status_details = NULL; + op->data.send_status_from_server.status_details = ""; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; @@ -168,7 +168,7 @@ static void start_send_status(void) { status_op[0].op = GRPC_OP_SEND_STATUS_FROM_SERVER; status_op[0].data.send_status_from_server.status = GRPC_STATUS_OK; status_op[0].data.send_status_from_server.trailing_metadata_count = 0; - status_op[0].data.send_status_from_server.status_details = NULL; + status_op[0].data.send_status_from_server.status_details = ""; status_op[1].op = GRPC_OP_RECV_CLOSE_ON_SERVER; status_op[1].data.recv_close_on_server.cancelled = &was_cancelled; @@ -259,8 +259,8 @@ int main(int argc, char **argv) { switch ((intptr_t)s) { case FLING_SERVER_NEW_REQUEST: if (call != NULL) { - if (0 == grpc_slice_str_cmp(call_details.method, - "/Reflector/reflectStream")) { + if (0 == + strcmp(call_details.method, "/Reflector/reflectStream")) { /* Received streaming call. Send metadata here. */ start_read_op(FLING_SERVER_READ_FOR_STREAMING); send_initial_metadata(); diff --git a/test/core/iomgr/ev_epoll_linux_test.c b/test/core/iomgr/ev_epoll_linux_test.c index 0d06f647955..40ae91bc6de 100644 --- a/test/core/iomgr/ev_epoll_linux_test.c +++ b/test/core/iomgr/ev_epoll_linux_test.c @@ -237,7 +237,6 @@ int main(int argc, char **argv) { "strategy. and the current strategy is: '%s'", poll_strategy); } - { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_iomgr_shutdown(&exec_ctx); diff --git a/test/core/memory_usage/client.c b/test/core/memory_usage/client.c index 0cab872014a..f4432bf5727 100644 --- a/test/core/memory_usage/client.c +++ b/test/core/memory_usage/client.c @@ -58,7 +58,8 @@ typedef struct { grpc_call *call; grpc_metadata_array initial_metadata_recv; grpc_status_code status; - grpc_slice details; + char *details; + size_t details_capacity; grpc_metadata_array trailing_metadata_recv; } fling_call; @@ -84,11 +85,9 @@ static void init_ping_pong_request(int call_idx) { op->data.recv_initial_metadata = &calls[call_idx].initial_metadata_recv; op++; - grpc_slice hostname = grpc_slice_from_static_string("localhost"); calls[call_idx].call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/Reflector/reflectUnary"), &hostname, - gpr_inf_future(GPR_CLOCK_REALTIME), NULL); + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, "/Reflector/reflectUnary", + "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, metadata_ops, @@ -108,6 +107,8 @@ static void finish_ping_pong_request(int call_idx) { &calls[call_idx].trailing_metadata_recv; op->data.recv_status_on_client.status = &calls[call_idx].status; op->data.recv_status_on_client.status_details = &calls[call_idx].details; + op->data.recv_status_on_client.status_details_capacity = + &calls[call_idx].details_capacity; op++; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch(calls[call_idx].call, @@ -117,13 +118,13 @@ static void finish_ping_pong_request(int call_idx) { grpc_completion_queue_next(cq, gpr_inf_future(GPR_CLOCK_REALTIME), NULL); grpc_metadata_array_destroy(&calls[call_idx].initial_metadata_recv); grpc_metadata_array_destroy(&calls[call_idx].trailing_metadata_recv); - grpc_slice_unref(calls[call_idx].details); + gpr_free(calls[call_idx].details); grpc_call_destroy(calls[call_idx].call); calls[call_idx].call = NULL; } -static struct grpc_memory_counters send_snapshot_request(int call_idx, - grpc_slice call_type) { +static struct grpc_memory_counters send_snapshot_request( + int call_idx, const char *call_type) { grpc_metadata_array_init(&calls[call_idx].initial_metadata_recv); grpc_metadata_array_init(&calls[call_idx].trailing_metadata_recv); @@ -148,11 +149,12 @@ static struct grpc_memory_counters send_snapshot_request(int call_idx, &calls[call_idx].trailing_metadata_recv; op->data.recv_status_on_client.status = &calls[call_idx].status; op->data.recv_status_on_client.status_details = &calls[call_idx].details; + op->data.recv_status_on_client.status_details_capacity = + &calls[call_idx].details_capacity; op++; - grpc_slice hostname = grpc_slice_from_static_string("localhost"); calls[call_idx].call = grpc_channel_create_call( - channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, &hostname, + channel, NULL, GRPC_PROPAGATE_DEFAULTS, cq, call_type, "localhost", gpr_inf_future(GPR_CLOCK_REALTIME), NULL); GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch( calls[call_idx].call, snapshot_ops, @@ -182,8 +184,9 @@ static struct grpc_memory_counters send_snapshot_request(int call_idx, grpc_slice_unref(response); grpc_byte_buffer_reader_destroy(&reader); grpc_byte_buffer_destroy(response_payload_recv); - grpc_slice_unref(calls[call_idx].details); - calls[call_idx].details = grpc_empty_slice(); + gpr_free(calls[call_idx].details); + calls[call_idx].details = NULL; + calls[call_idx].details_capacity = 0; grpc_call_destroy(calls[call_idx].call); calls[call_idx].call = NULL; @@ -216,8 +219,9 @@ int main(int argc, char **argv) { gpr_cmdline_parse(cl, argc, argv); gpr_cmdline_destroy(cl); - for (size_t k = 0; k < GPR_ARRAY_SIZE(calls); k++) { - calls[k].details = grpc_empty_slice(); + for (int k = 0; k < (int)(sizeof(calls) / sizeof(fling_call)); k++) { + calls[k].details = NULL; + calls[k].details_capacity = 0; } cq = grpc_completion_queue_create(NULL); @@ -228,10 +232,10 @@ int main(int argc, char **argv) { int call_idx = 0; - struct grpc_memory_counters before_server_create = send_snapshot_request( - 0, grpc_slice_from_static_string("Reflector/GetBeforeSvrCreation")); - struct grpc_memory_counters after_server_create = send_snapshot_request( - 0, grpc_slice_from_static_string("Reflector/GetAfterSvrCreation")); + struct grpc_memory_counters before_server_create = + send_snapshot_request(0, "Reflector/GetBeforeSvrCreation"); + struct grpc_memory_counters after_server_create = + send_snapshot_request(0, "Reflector/GetAfterSvrCreation"); // warmup period for (call_idx = 0; call_idx < warmup_iterations; ++call_idx) { @@ -239,8 +243,7 @@ int main(int argc, char **argv) { } struct grpc_memory_counters server_benchmark_calls_start = - send_snapshot_request( - 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot")); + send_snapshot_request(0, "Reflector/SimpleSnapshot"); struct grpc_memory_counters client_benchmark_calls_start = grpc_memory_counters_snapshot(); @@ -253,8 +256,8 @@ int main(int argc, char **argv) { struct grpc_memory_counters client_calls_inflight = grpc_memory_counters_snapshot(); - struct grpc_memory_counters server_calls_inflight = send_snapshot_request( - 0, grpc_slice_from_static_string("Reflector/DestroyCalls")); + struct grpc_memory_counters server_calls_inflight = + send_snapshot_request(0, "Reflector/DestroyCalls"); do { event = grpc_completion_queue_next( @@ -269,8 +272,8 @@ int main(int argc, char **argv) { finish_ping_pong_request(call_idx + 1); } - struct grpc_memory_counters server_calls_end = send_snapshot_request( - 0, grpc_slice_from_static_string("Reflector/SimpleSnapshot")); + struct grpc_memory_counters server_calls_end = + send_snapshot_request(0, "Reflector/SimpleSnapshot"); struct grpc_memory_counters client_channel_end = grpc_memory_counters_snapshot(); diff --git a/test/core/memory_usage/server.c b/test/core/memory_usage/server.c index e8774bd9769..c0710930b07 100644 --- a/test/core/memory_usage/server.c +++ b/test/core/memory_usage/server.c @@ -110,8 +110,7 @@ static void send_status(void *tag) { status_op.op = GRPC_OP_SEND_STATUS_FROM_SERVER; status_op.data.send_status_from_server.status = GRPC_STATUS_OK; status_op.data.send_status_from_server.trailing_metadata_count = 0; - grpc_slice details = grpc_slice_from_static_string(""); - status_op.data.send_status_from_server.status_details = &details; + status_op.data.send_status_from_server.status_details = ""; GPR_ASSERT(GRPC_CALL_OK == grpc_call_start_batch((*(fling_call *)tag).call, &status_op, 1, tag, NULL)); @@ -141,8 +140,7 @@ static void send_snapshot(void *tag, struct grpc_memory_counters *snapshot) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.status = GRPC_STATUS_OK; op->data.send_status_from_server.trailing_metadata_count = 0; - grpc_slice details = grpc_slice_from_static_string(""); - op->data.send_status_from_server.status_details = &details; + op->data.send_status_from_server.status_details = ""; op++; op->op = GRPC_OP_RECV_CLOSE_ON_SERVER; op->data.recv_close_on_server.cancelled = &was_cancelled; @@ -247,27 +245,25 @@ int main(int argc, char **argv) { switch (s->state) { case FLING_SERVER_NEW_REQUEST: request_call_unary(++next_call_idx); - if (0 == grpc_slice_str_cmp(s->call_details.method, - "/Reflector/reflectUnary")) { + if (0 == + strcmp(s->call_details.method, "/Reflector/reflectUnary")) { s->state = FLING_SERVER_SEND_INIT_METADATA; send_initial_metadata_unary(s); - } else if (0 == - grpc_slice_str_cmp(s->call_details.method, - "Reflector/GetBeforeSvrCreation")) { + } else if (0 == strcmp(s->call_details.method, + "Reflector/GetBeforeSvrCreation")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; send_snapshot(s, &before_server_create); - } else if (0 == - grpc_slice_str_cmp(s->call_details.method, - "Reflector/GetAfterSvrCreation")) { + } else if (0 == strcmp(s->call_details.method, + "Reflector/GetAfterSvrCreation")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; send_snapshot(s, &after_server_create); - } else if (0 == grpc_slice_str_cmp(s->call_details.method, - "Reflector/SimpleSnapshot")) { + } else if (0 == strcmp(s->call_details.method, + "Reflector/SimpleSnapshot")) { s->state = FLING_SERVER_SEND_STATUS_SNAPSHOT; current_snapshot = grpc_memory_counters_snapshot(); send_snapshot(s, ¤t_snapshot); - } else if (0 == grpc_slice_str_cmp(s->call_details.method, - "Reflector/DestroyCalls")) { + } else if (0 == strcmp(s->call_details.method, + "Reflector/DestroyCalls")) { s->state = FLING_SERVER_BATCH_SEND_STATUS_FLING_CALL; current_snapshot = grpc_memory_counters_snapshot(); send_snapshot(s, ¤t_snapshot); diff --git a/test/core/security/credentials_test.c b/test/core/security/credentials_test.c index c0933c64a68..0a79292b5b9 100644 --- a/test/core/security/credentials_test.c +++ b/test/core/security/credentials_test.c @@ -196,8 +196,8 @@ static void test_add_to_empty_md_store(void) { grpc_slice value = grpc_slice_from_copied_string(value_str); grpc_credentials_md_store_add(store, key, value); GPR_ASSERT(store->num_entries == 1); - GPR_ASSERT(grpc_slice_eq(key, store->entries[0].key)); - GPR_ASSERT(grpc_slice_eq(value, store->entries[0].value)); + GPR_ASSERT(grpc_slice_cmp(key, store->entries[0].key) == 0); + GPR_ASSERT(grpc_slice_cmp(value, store->entries[0].value) == 0); grpc_slice_unref(key); grpc_slice_unref(value); grpc_credentials_md_store_unref(&exec_ctx, store); @@ -1065,8 +1065,9 @@ static void plugin_get_metadata_success(void *state, *s = PLUGIN_GET_METADATA_CALLED_STATE; for (i = 0; i < GPR_ARRAY_SIZE(plugin_md); i++) { memset(&md[i], 0, sizeof(grpc_metadata)); - md[i].key = grpc_slice_from_copied_string(plugin_md[i].key); - md[i].value = grpc_slice_from_copied_string(plugin_md[i].value); + md[i].key = plugin_md[i].key; + md[i].value = plugin_md[i].value; + md[i].value_length = strlen(plugin_md[i].value); } cb(user_data, md, GPR_ARRAY_SIZE(md), GRPC_STATUS_OK, NULL); } diff --git a/test/core/security/print_google_default_creds_token.c b/test/core/security/print_google_default_creds_token.c index ea136fbdcf6..2b74690bc3f 100644 --- a/test/core/security/print_google_default_creds_token.c +++ b/test/core/security/print_google_default_creds_token.c @@ -63,7 +63,7 @@ static void on_metadata_response(grpc_exec_ctx *exec_ctx, void *user_data, } else { char *token; GPR_ASSERT(num_md == 1); - token = grpc_slice_to_c_string(md_elems[0].value); + token = grpc_dump_slice(md_elems[0].value, GPR_DUMP_ASCII); printf("\nGot token: %s\n\n", token); gpr_free(token); } diff --git a/test/core/security/secure_endpoint_test.c b/test/core/security/secure_endpoint_test.c index bcc50d0bb0e..e1d6ff9691f 100644 --- a/test/core/security/secure_endpoint_test.c +++ b/test/core/security/secure_endpoint_test.c @@ -164,7 +164,7 @@ static void test_leftover(grpc_endpoint_test_config config, size_t slice_size) { grpc_exec_ctx_finish(&exec_ctx); GPR_ASSERT(n == 1); GPR_ASSERT(incoming.count == 1); - GPR_ASSERT(grpc_slice_eq(s, incoming.slices[0])); + GPR_ASSERT(0 == grpc_slice_cmp(s, incoming.slices[0])); grpc_endpoint_shutdown(&exec_ctx, f.client_ep); grpc_endpoint_shutdown(&exec_ctx, f.server_ep); diff --git a/test/core/security/security_connector_test.c b/test/core/security/security_connector_test.c index 4219b134f25..8872cbe278f 100644 --- a/test/core/security/security_connector_test.c +++ b/test/core/security/security_connector_test.c @@ -370,7 +370,7 @@ static void test_default_ssl_roots(void) { gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); grpc_set_ssl_roots_override_callback(override_roots_success); grpc_slice roots = grpc_get_default_ssl_roots_for_testing(); - char *roots_contents = grpc_slice_to_c_string(roots); + char *roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); gpr_free(roots_contents); @@ -379,7 +379,7 @@ static void test_default_ssl_roots(void) { instead. */ gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, roots_env_var_file_path); roots = grpc_get_default_ssl_roots_for_testing(); - roots_contents = grpc_slice_to_c_string(roots); + roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_env_var) == 0); gpr_free(roots_contents); @@ -388,7 +388,7 @@ static void test_default_ssl_roots(void) { the api. */ gpr_setenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR, ""); roots = grpc_get_default_ssl_roots_for_testing(); - roots_contents = grpc_slice_to_c_string(roots); + roots_contents = grpc_dump_slice(roots, GPR_DUMP_ASCII); grpc_slice_unref(roots); GPR_ASSERT(strcmp(roots_contents, roots_for_override_api) == 0); gpr_free(roots_contents); diff --git a/test/core/slice/percent_encode_fuzzer.c b/test/core/slice/percent_encode_fuzzer.c index 0d440c5bb2b..9698e796b48 100644 --- a/test/core/slice/percent_encode_fuzzer.c +++ b/test/core/slice/percent_encode_fuzzer.c @@ -55,8 +55,8 @@ static void test(const uint8_t *data, size_t size, const uint8_t *dict) { grpc_slice permissive_decoded_output = grpc_permissive_percent_decode_slice(output); // and decoded output must always match the input - GPR_ASSERT(grpc_slice_eq(input, decoded_output)); - GPR_ASSERT(grpc_slice_eq(input, permissive_decoded_output)); + GPR_ASSERT(grpc_slice_cmp(input, decoded_output) == 0); + GPR_ASSERT(grpc_slice_cmp(input, permissive_decoded_output) == 0); grpc_slice_unref(input); grpc_slice_unref(output); grpc_slice_unref(decoded_output); diff --git a/test/core/slice/percent_encoding_test.c b/test/core/slice/percent_encoding_test.c index 222e695fd42..d71c99f54c5 100644 --- a/test/core/slice/percent_encoding_test.c +++ b/test/core/slice/percent_encoding_test.c @@ -81,9 +81,9 @@ static void test_vector(const char *raw, size_t raw_length, const char *encoded, gpr_free(encoded2raw_msg); gpr_free(encoded2raw_permissive_msg); - GPR_ASSERT(grpc_slice_eq(raw_slice, encoded2raw_slice)); - GPR_ASSERT(grpc_slice_eq(raw_slice, encoded2raw_permissive_slice)); - GPR_ASSERT(grpc_slice_eq(encoded_slice, raw2encoded_slice)); + GPR_ASSERT(0 == grpc_slice_cmp(raw_slice, encoded2raw_slice)); + GPR_ASSERT(0 == grpc_slice_cmp(raw_slice, encoded2raw_permissive_slice)); + GPR_ASSERT(0 == grpc_slice_cmp(encoded_slice, raw2encoded_slice)); grpc_slice_unref(encoded2raw_slice); grpc_slice_unref(encoded2raw_permissive_slice); @@ -123,8 +123,8 @@ static void test_nonconformant_vector(const char *encoded, encoded2raw_permissive_msg); gpr_free(encoded2raw_permissive_msg); - GPR_ASSERT( - grpc_slice_eq(permissive_unencoded_slice, encoded2raw_permissive_slice)); + GPR_ASSERT(0 == grpc_slice_cmp(permissive_unencoded_slice, + encoded2raw_permissive_slice)); grpc_slice_unref(permissive_unencoded_slice); grpc_slice_unref(encoded2raw_permissive_slice); diff --git a/test/core/slice/slice_test.c b/test/core/slice/slice_test.c index f68a9532619..ca44becfd09 100644 --- a/test/core/slice/slice_test.c +++ b/test/core/slice/slice_test.c @@ -35,12 +35,8 @@ #include -#include #include #include - -#include "src/core/lib/slice/slice_internal.h" -#include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" #define LOG_TEST_NAME(x) gpr_log(GPR_INFO, "%s", x); @@ -65,10 +61,8 @@ static void test_slice_malloc_returns_something_sensible(void) { GPR_ASSERT(GRPC_SLICE_LENGTH(slice) == length); /* If the slice has a refcount, it must be destroyable. */ if (slice.refcount) { - GPR_ASSERT(slice.refcount->vtable != NULL); - GPR_ASSERT(slice.refcount->vtable->ref != NULL); - GPR_ASSERT(slice.refcount->vtable->unref != NULL); - GPR_ASSERT(slice.refcount->vtable->hash != NULL); + GPR_ASSERT(slice.refcount->ref != NULL); + GPR_ASSERT(slice.refcount->unref != NULL); } /* We must be able to write to every byte of the data */ for (i = 0; i < length; i++) { @@ -255,55 +249,6 @@ static void test_slice_from_copied_string_works(void) { grpc_slice_unref(slice); } -static void test_slice_interning(void) { - LOG_TEST_NAME("test_slice_interning"); - - grpc_init(); - grpc_slice src1 = grpc_slice_from_copied_string("hello123456789123456789"); - grpc_slice src2 = grpc_slice_from_copied_string("hello123456789123456789"); - GPR_ASSERT(GRPC_SLICE_START_PTR(src1) != GRPC_SLICE_START_PTR(src2)); - grpc_slice interned1 = grpc_slice_intern(src1); - grpc_slice interned2 = grpc_slice_intern(src2); - GPR_ASSERT(GRPC_SLICE_START_PTR(interned1) == - GRPC_SLICE_START_PTR(interned2)); - GPR_ASSERT(GRPC_SLICE_START_PTR(interned1) != GRPC_SLICE_START_PTR(src1)); - GPR_ASSERT(GRPC_SLICE_START_PTR(interned2) != GRPC_SLICE_START_PTR(src2)); - grpc_slice_unref(src1); - grpc_slice_unref(src2); - grpc_slice_unref(interned1); - grpc_slice_unref(interned2); - grpc_shutdown(); -} - -static void test_static_slice_interning(void) { - LOG_TEST_NAME("test_static_slice_interning"); - - // grpc_init/grpc_shutdown deliberately omitted: they should not be necessary - // to intern a static slice - - for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - GPR_ASSERT(grpc_slice_is_equivalent( - grpc_static_slice_table[i], - grpc_slice_intern(grpc_static_slice_table[i]))); - } -} - -static void test_static_slice_copy_interning(void) { - LOG_TEST_NAME("test_static_slice_copy_interning"); - - grpc_init(); - - for (size_t i = 0; i < GRPC_STATIC_MDSTR_COUNT; i++) { - grpc_slice copy = grpc_slice_dup(grpc_static_slice_table[i]); - GPR_ASSERT(grpc_static_slice_table[i].refcount != copy.refcount); - GPR_ASSERT(grpc_static_slice_table[i].refcount == - grpc_slice_intern(copy).refcount); - grpc_slice_unref(copy); - } - - grpc_shutdown(); -} - int main(int argc, char **argv) { unsigned length; grpc_test_init(argc, argv); @@ -317,8 +262,5 @@ int main(int argc, char **argv) { test_slice_split_tail_works(length); } test_slice_from_copied_string_works(); - test_slice_interning(); - test_static_slice_interning(); - test_static_slice_copy_interning(); return 0; } diff --git a/test/core/surface/lame_client_test.c b/test/core/surface/lame_client_test.c index a2e103073ad..b6db6a6b084 100644 --- a/test/core/surface/lame_client_test.c +++ b/test/core/surface/lame_client_test.c @@ -90,7 +90,8 @@ int main(int argc, char **argv) { grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; char *peer; grpc_test_init(argc, argv); @@ -110,9 +111,8 @@ int main(int argc, char **argv) { cq = grpc_completion_queue_create(NULL); - grpc_slice host = grpc_slice_from_static_string("anywhere"); call = grpc_channel_create_call(chan, NULL, GRPC_PROPAGATE_DEFAULTS, cq, - grpc_slice_from_static_string("/Foo"), &host, + "/Foo", "anywhere", GRPC_TIMEOUT_SECONDS_TO_DEADLINE(100), NULL); GPR_ASSERT(call); cqv = cq_verifier_create(cq); @@ -142,6 +142,7 @@ int main(int argc, char **argv) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -163,7 +164,7 @@ int main(int argc, char **argv) { grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); + gpr_free(details); grpc_shutdown(); diff --git a/test/core/transport/chttp2/bin_decoder_test.c b/test/core/transport/chttp2/bin_decoder_test.c index a8b0a751378..221112ab21b 100644 --- a/test/core/transport/chttp2/bin_decoder_test.c +++ b/test/core/transport/chttp2/bin_decoder_test.c @@ -46,7 +46,7 @@ static int all_ok = 1; static void expect_slice_eq(grpc_exec_ctx *exec_ctx, grpc_slice expected, grpc_slice slice, char *debug, int line) { - if (!grpc_slice_eq(slice, expected)) { + if (0 != grpc_slice_cmp(slice, expected)) { char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, diff --git a/test/core/transport/chttp2/bin_encoder_test.c b/test/core/transport/chttp2/bin_encoder_test.c index bd10a1e2116..53b55a301e2 100644 --- a/test/core/transport/chttp2/bin_encoder_test.c +++ b/test/core/transport/chttp2/bin_encoder_test.c @@ -48,7 +48,7 @@ static int all_ok = 1; static void expect_slice_eq(grpc_slice expected, grpc_slice slice, char *debug, int line) { - if (!grpc_slice_eq(slice, expected)) { + if (0 != grpc_slice_cmp(slice, expected)) { char *hs = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *he = grpc_dump_slice(expected, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "FAILED:%d: %s\ngot: %s\nwant: %s", line, debug, hs, @@ -84,8 +84,8 @@ static void expect_combined_equiv(const char *s, size_t len, int line) { grpc_slice input = grpc_slice_from_copied_buffer(s, len); grpc_slice base64 = grpc_chttp2_base64_encode(input); grpc_slice expect = grpc_chttp2_huffman_compress(base64); - grpc_slice got = grpc_chttp2_base64_encode_and_huffman_compress(input); - if (!grpc_slice_eq(expect, got)) { + grpc_slice got = grpc_chttp2_base64_encode_and_huffman_compress_impl(input); + if (0 != grpc_slice_cmp(expect, got)) { char *t = grpc_dump_slice(input, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *e = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *g = grpc_dump_slice(got, GPR_DUMP_HEX | GPR_DUMP_ASCII); @@ -106,7 +106,7 @@ static void expect_combined_equiv(const char *s, size_t len, int line) { expect_combined_equiv(x, sizeof(x) - 1, __LINE__) static void expect_binary_header(const char *hdr, int binary) { - if (grpc_is_binary_header(grpc_slice_from_static_string(hdr)) != binary) { + if (grpc_is_binary_header(hdr, strlen(hdr)) != binary) { gpr_log(GPR_ERROR, "FAILED: expected header '%s' to be %s", hdr, binary ? "binary" : "not binary"); all_ok = 0; diff --git a/test/core/transport/chttp2/hpack_encoder_test.c b/test/core/transport/chttp2/hpack_encoder_test.c index d572d79a7ff..1fd2540d652 100644 --- a/test/core/transport/chttp2/hpack_encoder_test.c +++ b/test/core/transport/chttp2/hpack_encoder_test.c @@ -81,9 +81,7 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, e[i - 1].next = &e[i]; e[i].prev = &e[i - 1]; } - e[i].md = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - grpc_slice_intern(grpc_slice_from_static_string(value))); + e[i].md = grpc_mdelem_from_strings(exec_ctx, key, value); } e[0].prev = NULL; e[nheaders - 1].next = NULL; @@ -91,7 +89,6 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, b.list.head = &e[0]; b.list.tail = &e[nheaders - 1]; - b.list.count = nheaders; if (cap_to_delete == num_to_delete) { cap_to_delete = GPR_MAX(2 * cap_to_delete, 1000); @@ -109,7 +106,7 @@ static void verify(grpc_exec_ctx *exec_ctx, size_t window_available, int eof, grpc_slice_buffer_destroy_internal(exec_ctx, &output); grpc_metadata_batch_destroy(exec_ctx, &b); - if (!grpc_slice_eq(merged, expect)) { + if (0 != grpc_slice_cmp(merged, expect)) { char *expect_str = grpc_dump_slice(expect, GPR_DUMP_HEX | GPR_DUMP_ASCII); char *got_str = grpc_dump_slice(merged, GPR_DUMP_HEX | GPR_DUMP_ASCII); gpr_log(GPR_ERROR, "mismatched output for %s", expected); @@ -196,9 +193,7 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, const char *key, const char *value) { grpc_slice_buffer output; - grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, grpc_slice_intern(grpc_slice_from_static_string(key)), - grpc_slice_intern(grpc_slice_from_static_string(value))); + grpc_mdelem *elem = grpc_mdelem_from_strings(exec_ctx, key, value); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t initial_table_size = g_compressor.table_size; grpc_linked_mdelem *e = gpr_malloc(sizeof(*e)); @@ -209,7 +204,6 @@ static void verify_table_size_change_match_elem_size(grpc_exec_ctx *exec_ctx, e[0].next = NULL; b.list.head = &e[0]; b.list.tail = &e[0]; - b.list.count = 1; grpc_slice_buffer_init(&output); grpc_transport_one_way_stats stats; @@ -239,7 +233,7 @@ static void run_test(void (*test)(grpc_exec_ctx *exec_ctx), const char *name) { int main(int argc, char **argv) { size_t i; - grpc_test_only_set_slice_hash_seed(0); + grpc_test_only_set_metadata_hash_seed(0); grpc_test_init(argc, argv); grpc_init(); TEST(test_basic_headers); diff --git a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c index e9ac16df2de..4e00f49b664 100644 --- a/test/core/transport/chttp2/hpack_parser_fuzzer_test.c +++ b/test/core/transport/chttp2/hpack_parser_fuzzer_test.c @@ -39,26 +39,25 @@ #include #include "src/core/ext/transport/chttp2/transport/hpack_parser.h" -#include "src/core/lib/slice/slice_internal.h" bool squelch = true; bool leak_check = true; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { +static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { GRPC_MDELEM_UNREF(exec_ctx, md); } static void dont_log(gpr_log_func_args *args) {} int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - grpc_test_only_set_slice_hash_seed(0); + grpc_test_only_set_metadata_hash_seed(0); if (squelch) gpr_set_log_function(dont_log); grpc_init(); grpc_chttp2_hpack_parser parser; grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; grpc_chttp2_hpack_parser_init(&exec_ctx, &parser); parser.on_header = onhdr; - GRPC_ERROR_UNREF(grpc_chttp2_hpack_parser_parse( - &exec_ctx, &parser, grpc_slice_from_static_buffer(data, size))); + GRPC_ERROR_UNREF( + grpc_chttp2_hpack_parser_parse(&exec_ctx, &parser, data, data + size)); grpc_chttp2_hpack_parser_destroy(&exec_ctx, &parser); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); diff --git a/test/core/transport/chttp2/hpack_parser_test.c b/test/core/transport/chttp2/hpack_parser_test.c index 01789c4fb40..8f48849c974 100644 --- a/test/core/transport/chttp2/hpack_parser_test.c +++ b/test/core/transport/chttp2/hpack_parser_test.c @@ -45,15 +45,15 @@ typedef struct { va_list args; } test_checker; -static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem md) { +static void onhdr(grpc_exec_ctx *exec_ctx, void *ud, grpc_mdelem *md) { const char *ekey, *evalue; test_checker *chk = ud; ekey = va_arg(chk->args, char *); GPR_ASSERT(ekey); evalue = va_arg(chk->args, char *); GPR_ASSERT(evalue); - GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(md), ekey) == 0); - GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(md), evalue) == 0); + GPR_ASSERT(grpc_slice_str_cmp(md->key->slice, ekey) == 0); + GPR_ASSERT(grpc_slice_str_cmp(md->value->slice, evalue) == 0); GRPC_MDELEM_UNREF(exec_ctx, md); } @@ -76,8 +76,9 @@ static void test_vector(grpc_chttp2_hpack_parser *parser, for (i = 0; i < nslices; i++) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - GPR_ASSERT(grpc_chttp2_hpack_parser_parse(&exec_ctx, parser, slices[i]) == - GRPC_ERROR_NONE); + GPR_ASSERT(grpc_chttp2_hpack_parser_parse( + &exec_ctx, parser, GRPC_SLICE_START_PTR(slices[i]), + GRPC_SLICE_END_PTR(slices[i])) == GRPC_ERROR_NONE); grpc_exec_ctx_finish(&exec_ctx); } diff --git a/test/core/transport/chttp2/hpack_table_test.c b/test/core/transport/chttp2/hpack_table_test.c index d2f6d5dc5bc..ef2ad66b5ca 100644 --- a/test/core/transport/chttp2/hpack_table_test.c +++ b/test/core/transport/chttp2/hpack_table_test.c @@ -46,16 +46,16 @@ #define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) -static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_slice mdstr, +static void assert_str(const grpc_chttp2_hptbl *tbl, grpc_mdstr *mdstr, const char *str) { - GPR_ASSERT(grpc_slice_str_cmp(mdstr, str) == 0); + GPR_ASSERT(grpc_slice_str_cmp(mdstr->slice, str) == 0); } static void assert_index(const grpc_chttp2_hptbl *tbl, uint32_t idx, const char *key, const char *value) { - grpc_mdelem md = grpc_chttp2_hptbl_lookup(tbl, idx); - assert_str(tbl, GRPC_MDKEY(md), key); - assert_str(tbl, GRPC_MDVALUE(md), value); + grpc_mdelem *md = grpc_chttp2_hptbl_lookup(tbl, idx); + assert_str(tbl, md->key, key); + assert_str(tbl, md->value, value); } static void test_static_lookup(void) { @@ -143,12 +143,10 @@ static void test_many_additions(void) { grpc_chttp2_hptbl_init(&exec_ctx, &tbl); for (i = 0; i < 100000; i++) { - grpc_mdelem elem; + grpc_mdelem *elem; gpr_asprintf(&key, "K:%d", i); gpr_asprintf(&value, "VALUE:%d", i); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + elem = grpc_mdelem_from_strings(&exec_ctx, key, value); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); assert_index(&tbl, 1 + GRPC_CHTTP2_LAST_STATIC_ENTRY, key, value); @@ -171,9 +169,7 @@ static grpc_chttp2_hptbl_find_result find_simple(grpc_chttp2_hptbl *tbl, const char *key, const char *value) { grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem md = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_copied_string(key), - grpc_slice_from_copied_string(value)); + grpc_mdelem *md = grpc_mdelem_from_strings(&exec_ctx, key, value); grpc_chttp2_hptbl_find_result r = grpc_chttp2_hptbl_find(tbl, md); GRPC_MDELEM_UNREF(&exec_ctx, md); grpc_exec_ctx_finish(&exec_ctx); @@ -185,24 +181,19 @@ static void test_find(void) { grpc_chttp2_hptbl tbl; uint32_t i; char buffer[32]; - grpc_mdelem elem; + grpc_mdelem *elem; grpc_chttp2_hptbl_find_result r; LOG_TEST("test_find"); grpc_chttp2_hptbl_init(&exec_ctx, &tbl); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("xyz")); + elem = grpc_mdelem_from_strings(&exec_ctx, "abc", "xyz"); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = - grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("abc"), - grpc_slice_from_static_string("123")); + elem = grpc_mdelem_from_strings(&exec_ctx, "abc", "123"); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); - elem = grpc_mdelem_from_slices(&exec_ctx, grpc_slice_from_static_string("x"), - grpc_slice_from_static_string("1")); + elem = grpc_mdelem_from_strings(&exec_ctx, "x", "1"); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); @@ -253,9 +244,7 @@ static void test_find(void) { /* overflow the string buffer, check find still works */ for (i = 0; i < 10000; i++) { int64_ttoa(i, buffer); - elem = grpc_mdelem_from_slices(&exec_ctx, - grpc_slice_from_static_string("test"), - grpc_slice_from_copied_string(buffer)); + elem = grpc_mdelem_from_strings(&exec_ctx, "test", buffer); GPR_ASSERT(grpc_chttp2_hptbl_add(&exec_ctx, &tbl, elem) == GRPC_ERROR_NONE); GRPC_MDELEM_UNREF(&exec_ctx, elem); } diff --git a/test/core/transport/status_conversion_test.c b/test/core/transport/chttp2/status_conversion_test.c similarity index 65% rename from test/core/transport/status_conversion_test.c rename to test/core/transport/chttp2/status_conversion_test.c index 65f840b1e26..f5a5cd1395b 100644 --- a/test/core/transport/status_conversion_test.c +++ b/test/core/transport/chttp2/status_conversion_test.c @@ -31,50 +31,50 @@ * */ -#include "src/core/lib/transport/status_conversion.h" +#include "src/core/ext/transport/chttp2/transport/status_conversion.h" #include #include "test/core/util/test_config.h" #define GRPC_STATUS_TO_HTTP2_ERROR(a, b) \ - GPR_ASSERT(grpc_status_to_http2_error(a) == (b)) + GPR_ASSERT(grpc_chttp2_grpc_status_to_http2_error(a) == (b)) #define HTTP2_ERROR_TO_GRPC_STATUS(a, deadline, b) \ - GPR_ASSERT(grpc_http2_error_to_grpc_status(a, deadline) == (b)) + GPR_ASSERT(grpc_chttp2_http2_error_to_grpc_status(a, deadline) == (b)) #define GRPC_STATUS_TO_HTTP2_STATUS(a, b) \ - GPR_ASSERT(grpc_status_to_http2_status(a) == (b)) + GPR_ASSERT(grpc_chttp2_grpc_status_to_http2_status(a) == (b)) #define HTTP2_STATUS_TO_GRPC_STATUS(a, b) \ - GPR_ASSERT(grpc_http2_status_to_grpc_status(a) == (b)) + GPR_ASSERT(grpc_chttp2_http2_status_to_grpc_status(a) == (b)) int main(int argc, char **argv) { int i; grpc_test_init(argc, argv); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OK, GRPC_HTTP2_NO_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_CANCELLED, GRPC_HTTP2_CANCEL); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNKNOWN, GRPC_HTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OK, GRPC_CHTTP2_NO_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_CANCELLED, GRPC_CHTTP2_CANCEL); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNKNOWN, GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INVALID_ARGUMENT, - GRPC_HTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DEADLINE_EXCEEDED, GRPC_HTTP2_CANCEL); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_NOT_FOUND, GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DEADLINE_EXCEEDED, GRPC_CHTTP2_CANCEL); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_NOT_FOUND, GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ALREADY_EXISTS, - GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_PERMISSION_DENIED, - GRPC_HTTP2_INADEQUATE_SECURITY); + GRPC_CHTTP2_INADEQUATE_SECURITY); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNAUTHENTICATED, - GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_RESOURCE_EXHAUSTED, - GRPC_HTTP2_ENHANCE_YOUR_CALM); + GRPC_CHTTP2_ENHANCE_YOUR_CALM); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_FAILED_PRECONDITION, - GRPC_HTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ABORTED, GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_ABORTED, GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_OUT_OF_RANGE, - GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNIMPLEMENTED, - GRPC_HTTP2_INTERNAL_ERROR); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INTERNAL, GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_INTERNAL_ERROR); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_INTERNAL, GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_UNAVAILABLE, - GRPC_HTTP2_REFUSED_STREAM); - GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DATA_LOSS, GRPC_HTTP2_INTERNAL_ERROR); + GRPC_CHTTP2_REFUSED_STREAM); + GRPC_STATUS_TO_HTTP2_ERROR(GRPC_STATUS_DATA_LOSS, GRPC_CHTTP2_INTERNAL_ERROR); GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_OK, 200); GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_CANCELLED, 200); @@ -95,59 +95,59 @@ int main(int argc, char **argv) { GRPC_STATUS_TO_HTTP2_STATUS(GRPC_STATUS_DATA_LOSS, 200); const gpr_timespec before_deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_NO_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_PROTOCOL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INTERNAL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INTERNAL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FLOW_CONTROL_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FLOW_CONTROL_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_SETTINGS_TIMEOUT, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_SETTINGS_TIMEOUT, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_STREAM_CLOSED, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_STREAM_CLOSED, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FRAME_SIZE_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FRAME_SIZE_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_REFUSED_STREAM, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_REFUSED_STREAM, before_deadline, GRPC_STATUS_UNAVAILABLE); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CANCEL, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CANCEL, before_deadline, GRPC_STATUS_CANCELLED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_COMPRESSION_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_COMPRESSION_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CONNECT_ERROR, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CONNECT_ERROR, before_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_ENHANCE_YOUR_CALM, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_ENHANCE_YOUR_CALM, before_deadline, GRPC_STATUS_RESOURCE_EXHAUSTED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, before_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INADEQUATE_SECURITY, before_deadline, GRPC_STATUS_PERMISSION_DENIED); const gpr_timespec after_deadline = gpr_inf_past(GPR_CLOCK_MONOTONIC); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_NO_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_NO_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_PROTOCOL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_PROTOCOL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INTERNAL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INTERNAL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FLOW_CONTROL_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FLOW_CONTROL_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_SETTINGS_TIMEOUT, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_SETTINGS_TIMEOUT, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_STREAM_CLOSED, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_STREAM_CLOSED, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_FRAME_SIZE_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_FRAME_SIZE_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_REFUSED_STREAM, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_REFUSED_STREAM, after_deadline, GRPC_STATUS_UNAVAILABLE); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CANCEL, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CANCEL, after_deadline, GRPC_STATUS_DEADLINE_EXCEEDED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_COMPRESSION_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_COMPRESSION_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_CONNECT_ERROR, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_CONNECT_ERROR, after_deadline, GRPC_STATUS_INTERNAL); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_ENHANCE_YOUR_CALM, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_ENHANCE_YOUR_CALM, after_deadline, GRPC_STATUS_RESOURCE_EXHAUSTED); - HTTP2_ERROR_TO_GRPC_STATUS(GRPC_HTTP2_INADEQUATE_SECURITY, after_deadline, + HTTP2_ERROR_TO_GRPC_STATUS(GRPC_CHTTP2_INADEQUATE_SECURITY, after_deadline, GRPC_STATUS_PERMISSION_DENIED); HTTP2_STATUS_TO_GRPC_STATUS(200, GRPC_STATUS_OK); @@ -165,7 +165,7 @@ int main(int argc, char **argv) { /* check all status values can be converted */ for (i = 0; i <= 999; i++) { - grpc_http2_status_to_grpc_status(i); + grpc_chttp2_http2_status_to_grpc_status(i); } return 0; diff --git a/test/core/transport/chttp2/varint_test.c b/test/core/transport/chttp2/varint_test.c index f12c340a4be..e29be4b056f 100644 --- a/test/core/transport/chttp2/varint_test.c +++ b/test/core/transport/chttp2/varint_test.c @@ -49,7 +49,7 @@ static void test_varint(uint32_t value, uint32_t prefix_bits, uint8_t prefix_or, slice = grpc_slice_malloc(nbytes); GRPC_CHTTP2_WRITE_VARINT(value, prefix_bits, prefix_or, GRPC_SLICE_START_PTR(slice), nbytes); - GPR_ASSERT(grpc_slice_eq(expect, slice)); + GPR_ASSERT(grpc_slice_cmp(expect, slice) == 0); grpc_slice_unref(expect); grpc_slice_unref(slice); } diff --git a/test/core/transport/metadata_test.c b/test/core/transport/metadata_test.c index 92e58f23751..3625043d077 100644 --- a/test/core/transport/metadata_test.c +++ b/test/core/transport/metadata_test.c @@ -47,51 +47,55 @@ #include "src/core/lib/transport/static_metadata.h" #include "test/core/util/test_config.h" +#define LOG_TEST(x) gpr_log(GPR_INFO, "%s", x) + /* a large number */ #define MANY 10000 static void test_no_op(void) { - gpr_log(GPR_INFO, "test_no_op"); + LOG_TEST("test_no_op"); grpc_init(); grpc_shutdown(); } -static grpc_slice maybe_intern(grpc_slice in, bool intern) { - grpc_slice out = intern ? grpc_slice_intern(in) : grpc_slice_ref(in); - grpc_slice_unref(in); - return out; -} +static void test_create_string(void) { + grpc_mdstr *s1, *s2, *s3; + + LOG_TEST("test_create_string"); -static grpc_slice maybe_dup(grpc_slice in, bool dup) { - grpc_slice out = dup ? grpc_slice_dup(in) : grpc_slice_ref(in); - grpc_slice_unref(in); - return out; + grpc_init(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + s1 = grpc_mdstr_from_string("hello"); + s2 = grpc_mdstr_from_string("hello"); + s3 = grpc_mdstr_from_string("very much not hello"); + GPR_ASSERT(s1 == s2); + GPR_ASSERT(s3 != s1); + GPR_ASSERT(grpc_slice_str_cmp(s1->slice, "hello") == 0); + GPR_ASSERT(grpc_slice_str_cmp(s3->slice, "very much not hello") == 0); + GRPC_MDSTR_UNREF(&exec_ctx, s1); + GRPC_MDSTR_UNREF(&exec_ctx, s2); + GRPC_MDSTR_UNREF(&exec_ctx, s3); + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); } -static void test_create_metadata(bool intern_keys, bool intern_values) { - grpc_mdelem m1, m2, m3; +static void test_create_metadata(void) { + grpc_mdelem *m1, *m2, *m3; - gpr_log(GPR_INFO, "test_create_metadata: intern_keys=%d intern_values=%d", - intern_keys, intern_values); + LOG_TEST("test_create_metadata"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - m1 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values)); - m2 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values)); - m3 = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("c"), intern_values)); - GPR_ASSERT(grpc_mdelem_eq(m1, m2)); - GPR_ASSERT(!grpc_mdelem_eq(m3, m1)); - GPR_ASSERT(grpc_slice_eq(GRPC_MDKEY(m3), GRPC_MDKEY(m1))); - GPR_ASSERT(!grpc_slice_eq(GRPC_MDVALUE(m3), GRPC_MDVALUE(m1))); - GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDKEY(m1), "a") == 0); - GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m1), "b") == 0); - GPR_ASSERT(grpc_slice_str_cmp(GRPC_MDVALUE(m3), "c") == 0); + m1 = grpc_mdelem_from_strings(&exec_ctx, "a", "b"); + m2 = grpc_mdelem_from_strings(&exec_ctx, "a", "b"); + m3 = grpc_mdelem_from_strings(&exec_ctx, "a", "c"); + GPR_ASSERT(m1 == m2); + GPR_ASSERT(m3 != m1); + GPR_ASSERT(m3->key == m1->key); + GPR_ASSERT(m3->value != m1->value); + GPR_ASSERT(grpc_slice_str_cmp(m1->key->slice, "a") == 0); + GPR_ASSERT(grpc_slice_str_cmp(m1->value->slice, "b") == 0); + GPR_ASSERT(grpc_slice_str_cmp(m3->value->slice, "c") == 0); GRPC_MDELEM_UNREF(&exec_ctx, m1); GRPC_MDELEM_UNREF(&exec_ctx, m2); GRPC_MDELEM_UNREF(&exec_ctx, m3); @@ -99,28 +103,19 @@ static void test_create_metadata(bool intern_keys, bool intern_values) { grpc_shutdown(); } -static void test_create_many_ephemeral_metadata(bool intern_keys, - bool intern_values) { +static void test_create_many_ephemeral_metadata(void) { char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; - gpr_log( - GPR_INFO, - "test_create_many_ephemeral_metadata: intern_keys=%d intern_values=%d", - intern_keys, intern_values); + LOG_TEST("test_create_many_ephemeral_metadata"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add, and immediately delete a bunch of different elements */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - GRPC_MDELEM_UNREF( - &exec_ctx, - grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_copied_string(buffer), - intern_values))); + GRPC_MDELEM_UNREF(&exec_ctx, + grpc_mdelem_from_strings(&exec_ctx, "a", buffer)); } grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); @@ -129,27 +124,23 @@ static void test_create_many_ephemeral_metadata(bool intern_keys, static void test_create_many_persistant_metadata(void) { char buffer[GPR_LTOA_MIN_BUFSIZE]; long i; - grpc_mdelem *created = gpr_malloc(sizeof(grpc_mdelem) * MANY); - grpc_mdelem md; + grpc_mdelem **created = gpr_malloc(sizeof(grpc_mdelem *) * MANY); + grpc_mdelem *md; - gpr_log(GPR_INFO, "test_create_many_persistant_metadata"); + LOG_TEST("test_create_many_persistant_metadata"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; /* add phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - created[i] = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), - grpc_slice_intern(grpc_slice_from_static_string(buffer))); + created[i] = grpc_mdelem_from_strings(&exec_ctx, "a", buffer); } /* verify phase */ for (i = 0; i < MANY; i++) { gpr_ltoa(i, buffer); - md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("a")), - grpc_slice_intern(grpc_slice_from_static_string(buffer))); - GPR_ASSERT(grpc_mdelem_eq(md, created[i])); + md = grpc_mdelem_from_strings(&exec_ctx, "a", buffer); + GPR_ASSERT(md == created[i]); GRPC_MDELEM_UNREF(&exec_ctx, md); } /* cleanup phase */ @@ -162,77 +153,14 @@ static void test_create_many_persistant_metadata(void) { gpr_free(created); } -static void test_spin_creating_the_same_thing(bool intern_keys, - bool intern_values) { - gpr_log(GPR_INFO, - "test_spin_creating_the_same_thing: intern_keys=%d intern_values=%d", - intern_keys, intern_values); - - grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem a, b, c; - GRPC_MDELEM_UNREF( - &exec_ctx, - a = grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values))); - GRPC_MDELEM_UNREF( - &exec_ctx, - b = grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values))); - GRPC_MDELEM_UNREF( - &exec_ctx, - c = grpc_mdelem_from_slices( - &exec_ctx, - maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values))); - if (intern_keys && intern_values) { - GPR_ASSERT(a.payload == b.payload); - GPR_ASSERT(a.payload == c.payload); - } - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); -} - -static void test_identity_laws(bool intern_keys, bool intern_values) { - gpr_log(GPR_INFO, "test_identity_laws: intern_keys=%d intern_values=%d", - intern_keys, intern_values); +static void test_spin_creating_the_same_thing(void) { + LOG_TEST("test_spin_creating_the_same_thing"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - grpc_mdelem a, b, c; - a = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values)); - b = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values)); - c = grpc_mdelem_from_slices( - &exec_ctx, maybe_intern(grpc_slice_from_static_string("a"), intern_keys), - maybe_intern(grpc_slice_from_static_string("b"), intern_values)); - GPR_ASSERT(grpc_mdelem_eq(a, a)); - GPR_ASSERT(grpc_mdelem_eq(b, b)); - GPR_ASSERT(grpc_mdelem_eq(c, c)); - GPR_ASSERT(grpc_mdelem_eq(a, b)); - GPR_ASSERT(grpc_mdelem_eq(b, c)); - GPR_ASSERT(grpc_mdelem_eq(a, c)); - GPR_ASSERT(grpc_mdelem_eq(b, a)); - GPR_ASSERT(grpc_mdelem_eq(c, b)); - GPR_ASSERT(grpc_mdelem_eq(c, a)); - if (intern_keys && intern_values) { - GPR_ASSERT(a.payload == b.payload); - GPR_ASSERT(a.payload == c.payload); - } else { - GPR_ASSERT(a.payload != b.payload); - GPR_ASSERT(a.payload != c.payload); - GPR_ASSERT(b.payload != c.payload); - } - GRPC_MDELEM_UNREF(&exec_ctx, a); - GRPC_MDELEM_UNREF(&exec_ctx, b); - GRPC_MDELEM_UNREF(&exec_ctx, c); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); + GRPC_MDELEM_UNREF(&exec_ctx, grpc_mdelem_from_strings(&exec_ctx, "a", "b")); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); } @@ -241,25 +169,25 @@ static void test_things_stick_around(void) { size_t i, j; char *buffer; size_t nstrs = 1000; - grpc_slice *strs = gpr_malloc(sizeof(grpc_slice) * nstrs); + grpc_mdstr **strs = gpr_malloc(sizeof(grpc_mdstr *) * nstrs); size_t *shuf = gpr_malloc(sizeof(size_t) * nstrs); - grpc_slice test; + grpc_mdstr *test; - gpr_log(GPR_INFO, "test_things_stick_around"); + LOG_TEST("test_things_stick_around"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; for (i = 0; i < nstrs; i++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", i); - strs[i] = grpc_slice_intern(grpc_slice_from_static_string(buffer)); + strs[i] = grpc_mdstr_from_string(buffer); shuf[i] = i; gpr_free(buffer); } for (i = 0; i < nstrs; i++) { - grpc_slice_ref_internal(strs[i]); - grpc_slice_unref_internal(&exec_ctx, strs[i]); + GRPC_MDSTR_REF(strs[i]); + GRPC_MDSTR_UNREF(&exec_ctx, strs[i]); } for (i = 0; i < nstrs; i++) { @@ -271,13 +199,13 @@ static void test_things_stick_around(void) { } for (i = 0; i < nstrs; i++) { - grpc_slice_unref_internal(&exec_ctx, strs[shuf[i]]); + GRPC_MDSTR_UNREF(&exec_ctx, strs[shuf[i]]); for (j = i + 1; j < nstrs; j++) { gpr_asprintf(&buffer, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx%" PRIuPTR "x", shuf[j]); - test = grpc_slice_intern(grpc_slice_from_static_string(buffer)); - GPR_ASSERT(grpc_slice_is_equivalent(test, strs[shuf[j]])); - grpc_slice_unref_internal(&exec_ctx, test); + test = grpc_mdstr_from_string(buffer); + GPR_ASSERT(test == strs[shuf[j]]); + GRPC_MDSTR_UNREF(&exec_ctx, test); gpr_free(buffer); } } @@ -288,11 +216,57 @@ static void test_things_stick_around(void) { gpr_free(shuf); } +static void test_slices_work(void) { + /* ensure no memory leaks when switching representation from mdstr to slice */ + grpc_mdstr *str; + grpc_slice slice; + + LOG_TEST("test_slices_work"); + + grpc_init(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + + str = grpc_mdstr_from_string( + "123456789012345678901234567890123456789012345678901234567890"); + slice = grpc_slice_ref(str->slice); + GRPC_MDSTR_UNREF(&exec_ctx, str); + grpc_slice_unref_internal(&exec_ctx, slice); + + str = grpc_mdstr_from_string( + "123456789012345678901234567890123456789012345678901234567890"); + slice = grpc_slice_ref(str->slice); + grpc_slice_unref_internal(&exec_ctx, slice); + GRPC_MDSTR_UNREF(&exec_ctx, str); + + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); +} + +static void test_base64_and_huffman_works(void) { + grpc_mdstr *str; + grpc_slice slice1; + grpc_slice slice2; + + LOG_TEST("test_base64_and_huffman_works"); + + grpc_init(); + grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; + str = grpc_mdstr_from_string("abcdefg"); + slice1 = grpc_mdstr_as_base64_encoded_and_huffman_compressed(str); + slice2 = grpc_chttp2_base64_encode_and_huffman_compress(str->slice); + GPR_ASSERT(0 == grpc_slice_cmp(slice1, slice2)); + + grpc_slice_unref_internal(&exec_ctx, slice2); + GRPC_MDSTR_UNREF(&exec_ctx, str); + grpc_exec_ctx_finish(&exec_ctx); + grpc_shutdown(); +} + static void test_user_data_works(void) { int *ud1; int *ud2; - grpc_mdelem md; - gpr_log(GPR_INFO, "test_user_data_works"); + grpc_mdelem *md; + LOG_TEST("test_user_data_works"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -300,9 +274,7 @@ static void test_user_data_works(void) { *ud1 = 1; ud2 = gpr_malloc(sizeof(int)); *ud2 = 2; - md = grpc_mdelem_from_slices( - &exec_ctx, grpc_slice_intern(grpc_slice_from_static_string("abc")), - grpc_slice_intern(grpc_slice_from_static_string("123"))); + md = grpc_mdelem_from_strings(&exec_ctx, "abc", "123"); grpc_mdelem_set_user_data(md, gpr_free, ud1); grpc_mdelem_set_user_data(md, gpr_free, ud2); GPR_ASSERT(grpc_mdelem_get_user_data(md, gpr_free) == ud1); @@ -312,11 +284,8 @@ static void test_user_data_works(void) { } static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, - const char *value, bool intern_key, - bool intern_value) { - grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), - maybe_intern(grpc_slice_from_static_string(value), intern_value)); + const char *value) { + grpc_mdelem *elem = grpc_mdelem_from_strings(exec_ctx, key, value); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); size_t expected_size = 32 + strlen(key) + strlen(value); GPR_ASSERT(expected_size == elem_size); @@ -324,13 +293,10 @@ static void verify_ascii_header_size(grpc_exec_ctx *exec_ctx, const char *key, } static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, - const uint8_t *value, size_t value_len, - bool intern_key, bool intern_value) { - grpc_mdelem elem = grpc_mdelem_from_slices( - exec_ctx, maybe_intern(grpc_slice_from_static_string(key), intern_key), - maybe_intern(grpc_slice_from_static_buffer(value, value_len), - intern_value)); - GPR_ASSERT(grpc_is_binary_header(GRPC_MDKEY(elem))); + const uint8_t *value, size_t value_len) { + grpc_mdelem *elem = + grpc_mdelem_from_string_and_buffer(exec_ctx, key, value, value_len); + GPR_ASSERT(grpc_is_binary_header(key, strlen(key))); size_t elem_size = grpc_mdelem_get_size_in_hpack_table(elem); grpc_slice value_slice = grpc_slice_from_copied_buffer((const char *)value, value_len); @@ -343,9 +309,8 @@ static void verify_binary_header_size(grpc_exec_ctx *exec_ctx, const char *key, } #define BUFFER_SIZE 64 -static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { - gpr_log(GPR_INFO, "test_mdelem_size: intern_key=%d intern_value=%d", - intern_key, intern_value); +static void test_mdelem_sizes_in_hpack(void) { + LOG_TEST("test_mdelem_size"); grpc_init(); grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; @@ -354,44 +319,19 @@ static void test_mdelem_sizes_in_hpack(bool intern_key, bool intern_value) { binary_value[i] = i; } - verify_ascii_header_size(&exec_ctx, "hello", "world", intern_key, - intern_value); + verify_ascii_header_size(&exec_ctx, "hello", "world"); verify_ascii_header_size(&exec_ctx, "hello", - "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", intern_key, - intern_value); - verify_ascii_header_size(&exec_ctx, ":scheme", "http", intern_key, - intern_value); + "worldxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + verify_ascii_header_size(&exec_ctx, ":scheme", "http"); for (uint8_t i = 0; i < BUFFER_SIZE; i++) { - verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i, - intern_key, intern_value); + verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, i); } - grpc_exec_ctx_finish(&exec_ctx); - grpc_shutdown(); -} - -static void test_copied_static_metadata(bool dup_key, bool dup_value) { - gpr_log(GPR_INFO, "test_static_metadata: dup_key=%d dup_value=%d", dup_key, - dup_value); - grpc_init(); - grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT; - - for (size_t i = 0; i < GRPC_STATIC_MDELEM_COUNT; i++) { - grpc_mdelem p = GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[i], - GRPC_MDELEM_STORAGE_STATIC); - grpc_mdelem q = - grpc_mdelem_from_slices(&exec_ctx, maybe_dup(GRPC_MDKEY(p), dup_key), - maybe_dup(GRPC_MDVALUE(p), dup_value)); - GPR_ASSERT(grpc_mdelem_eq(p, q)); - if (dup_key || dup_value) { - GPR_ASSERT(p.payload != q.payload); - } else { - GPR_ASSERT(p.payload == q.payload); - } - GRPC_MDELEM_UNREF(&exec_ctx, p); - GRPC_MDELEM_UNREF(&exec_ctx, q); - } + const char *static_metadata = grpc_static_metadata_strings[0]; + memcpy(binary_value, static_metadata, strlen(static_metadata)); + verify_binary_header_size(&exec_ctx, "hello-bin", binary_value, + strlen(static_metadata)); grpc_exec_ctx_finish(&exec_ctx); grpc_shutdown(); @@ -400,18 +340,15 @@ static void test_copied_static_metadata(bool dup_key, bool dup_value) { int main(int argc, char **argv) { grpc_test_init(argc, argv); test_no_op(); - for (int k = 0; k <= 1; k++) { - for (int v = 0; v <= 1; v++) { - test_create_metadata(k, v); - test_create_many_ephemeral_metadata(k, v); - test_identity_laws(k, v); - test_spin_creating_the_same_thing(k, v); - test_mdelem_sizes_in_hpack(k, v); - test_copied_static_metadata(k, v); - } - } + test_create_string(); + test_create_metadata(); + test_create_many_ephemeral_metadata(); test_create_many_persistant_metadata(); + test_spin_creating_the_same_thing(); test_things_stick_around(); + test_slices_work(); + test_base64_and_huffman_works(); test_user_data_works(); + test_mdelem_sizes_in_hpack(); return 0; } diff --git a/test/core/transport/timeout_encoding_test.c b/test/core/transport/timeout_encoding_test.c index 10e18049955..b6004af7b47 100644 --- a/test/core/transport/timeout_encoding_test.c +++ b/test/core/transport/timeout_encoding_test.c @@ -88,8 +88,7 @@ void test_encoding(void) { static void assert_decodes_as(const char *buffer, gpr_timespec expected) { gpr_timespec got; gpr_log(GPR_INFO, "check decoding '%s'", buffer); - GPR_ASSERT(1 == grpc_http2_decode_timeout( - grpc_slice_from_static_string(buffer), &got)); + GPR_ASSERT(1 == grpc_http2_decode_timeout(buffer, &got)); GPR_ASSERT(0 == gpr_time_cmp(got, expected)); } @@ -135,23 +134,18 @@ void test_decoding(void) { assert_decodes_as("9999999999S", gpr_inf_future(GPR_TIMESPAN)); } -static void assert_decoding_fails(const char *s) { - gpr_timespec x; - GPR_ASSERT(0 == - grpc_http2_decode_timeout(grpc_slice_from_static_string(s), &x)); -} - void test_decoding_fails(void) { + gpr_timespec x; LOG_TEST("test_decoding_fails"); - assert_decoding_fails(""); - assert_decoding_fails(" "); - assert_decoding_fails("x"); - assert_decoding_fails("1"); - assert_decoding_fails("1x"); - assert_decoding_fails("1ux"); - assert_decoding_fails("!"); - assert_decoding_fails("n1"); - assert_decoding_fails("-1u"); + GPR_ASSERT(0 == grpc_http2_decode_timeout("", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout(" ", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("x", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("1", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("1x", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("1ux", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("!", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("n1", &x)); + GPR_ASSERT(0 == grpc_http2_decode_timeout("-1u", &x)); } int main(int argc, char **argv) { diff --git a/test/core/util/port_server_client.c b/test/core/util/port_server_client.c index 118708d419c..4baf63dcd7c 100644 --- a/test/core/util/port_server_client.c +++ b/test/core/util/port_server_client.c @@ -152,7 +152,7 @@ static void got_port_from_server(grpc_exec_ctx *exec_ctx, void *arg, failed = 1; const char *msg = grpc_error_string(error); gpr_log(GPR_DEBUG, "failed port pick from server: retrying [%s]", msg); - + grpc_error_free_string(msg); } else if (response->status != 200) { failed = 1; gpr_log(GPR_DEBUG, "failed port pick from server: status=%d", diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc index f53601297c8..2ce3f2f7bd9 100644 --- a/test/cpp/end2end/async_end2end_test.cc +++ b/test/cpp/end2end/async_end2end_test.cc @@ -228,7 +228,12 @@ class TestScenario { : disable_blocking(non_block), credentials_type(creds_type), message_content(content) {} - void Log() const; + void Log() const { + gpr_log( + GPR_INFO, + "Scenario: disable_blocking %d, credentials %s, message size %" PRIuPTR, + disable_blocking, credentials_type.c_str(), message_content.size()); + } bool disable_blocking; // Although the below grpc::string's are logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -237,20 +242,6 @@ class TestScenario { grpc::string message_content; }; -static std::ostream& operator<<(std::ostream& out, - const TestScenario& scenario) { - return out << "TestScenario{disable_blocking=" - << (scenario.disable_blocking ? "true" : "false") - << ", credentials='" << scenario.credentials_type - << "', message_size=" << scenario.message_content.size() << "}"; -} - -void TestScenario::Log() const { - std::ostringstream out; - out << *this; - gpr_log(GPR_DEBUG, "%s", out.str().c_str()); -} - class AsyncEnd2endTest : public ::testing::TestWithParam { protected: AsyncEnd2endTest() { GetParam().Log(); } diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc index d2c7edc64b9..1a1a94e87c7 100644 --- a/test/cpp/end2end/end2end_test.cc +++ b/test/cpp/end2end/end2end_test.cc @@ -209,7 +209,10 @@ class TestScenario { public: TestScenario(bool proxy, const grpc::string& creds_type) : use_proxy(proxy), credentials_type(creds_type) {} - void Log() const; + void Log() const { + gpr_log(GPR_INFO, "Scenario: proxy %d, credentials %s", use_proxy, + credentials_type.c_str()); + } bool use_proxy; // Although the below grpc::string is logically const, we can't declare // them const because of a limitation in the way old compilers (e.g., gcc-4.4) @@ -217,19 +220,6 @@ class TestScenario { grpc::string credentials_type; }; -static std::ostream& operator<<(std::ostream& out, - const TestScenario& scenario) { - return out << "TestScenario{use_proxy=" - << (scenario.use_proxy ? "true" : "false") << ", credentials='" - << scenario.credentials_type << "'}"; -} - -void TestScenario::Log() const { - std::ostringstream out; - out << *this; - gpr_log(GPR_DEBUG, "%s", out.str().c_str()); -} - class End2endTest : public ::testing::TestWithParam { protected: End2endTest() @@ -646,7 +636,7 @@ TEST_P(End2endServerTryCancelTest, BidiStreamServerCancelAfter) { TestBidiStreamServerCancel(CANCEL_AFTER_PROCESSING, 5); } -TEST_P(End2endTest, SimpleRpcWithCustomUserAgentPrefix) { +TEST_P(End2endTest, SimpleRpcWithCustomeUserAgentPrefix) { user_agent_prefix_ = "custom_prefix"; ResetStub(); EchoRequest request; @@ -1303,7 +1293,6 @@ TEST_P(SecureEnd2endTest, BlockingAuthMetadataPluginAndProcessorFailure) { EXPECT_FALSE(s.ok()); EXPECT_EQ(s.error_code(), StatusCode::UNAUTHENTICATED); } - TEST_P(SecureEnd2endTest, SetPerCallCredentials) { ResetStub(); EchoRequest request; diff --git a/test/cpp/grpclb/grpclb_test.cc b/test/cpp/grpclb/grpclb_test.cc index 07db474b873..de304b9f89c 100644 --- a/test/cpp/grpclb/grpclb_test.cc +++ b/test/cpp/grpclb/grpclb_test.cc @@ -288,8 +288,7 @@ static void start_lb_server(server_fixture *sf, int *ports, size_t nports, op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = grpc_slice_from_static_string("xyz"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "xyz"; op->flags = 0; op->reserved = NULL; op++; @@ -434,9 +433,7 @@ static void start_backend_server(server_fixture *sf) { op->op = GRPC_OP_SEND_STATUS_FROM_SERVER; op->data.send_status_from_server.trailing_metadata_count = 0; op->data.send_status_from_server.status = GRPC_STATUS_OK; - grpc_slice status_details = - grpc_slice_from_static_string("Backend server out a-ok"); - op->data.send_status_from_server.status_details = &status_details; + op->data.send_status_from_server.status_details = "Backend server out a-ok"; op->flags = 0; op->reserved = NULL; op++; @@ -465,7 +462,8 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array trailing_metadata_recv; grpc_status_code status; grpc_call_error error; - grpc_slice details; + char *details = NULL; + size_t details_capacity = 0; grpc_byte_buffer *request_payload; grpc_byte_buffer *response_payload_recv; int i; @@ -474,11 +472,9 @@ static void perform_request(client_fixture *cf) { grpc_slice request_payload_slice = grpc_slice_from_copied_string("hello world"); - grpc_slice host = grpc_slice_from_static_string("foo.test.google.fr:1234"); c = grpc_channel_create_call(cf->client, NULL, GRPC_PROPAGATE_DEFAULTS, - cf->cq, grpc_slice_from_static_string("/foo"), - &host, GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), - NULL); + cf->cq, "/foo", "foo.test.google.fr:1234", + GRPC_TIMEOUT_SECONDS_TO_DEADLINE(5), NULL); gpr_log(GPR_INFO, "Call 0x%" PRIxPTR " created", (intptr_t)c); GPR_ASSERT(c); char *peer; @@ -501,6 +497,7 @@ static void perform_request(client_fixture *cf) { op->data.recv_status_on_client.trailing_metadata = &trailing_metadata_recv; op->data.recv_status_on_client.status = &status; op->data.recv_status_on_client.status_details = &details; + op->data.recv_status_on_client.status_details_capacity = &details_capacity; op->flags = 0; op->reserved = NULL; op++; @@ -556,7 +553,7 @@ static void perform_request(client_fixture *cf) { grpc_metadata_array_destroy(&initial_metadata_recv); grpc_metadata_array_destroy(&trailing_metadata_recv); - grpc_slice_unref(details); + gpr_free(details); gpr_log(GPR_INFO, "Client call (peer %s) DESTROYED.", peer); gpr_free(peer); } diff --git a/test/cpp/interop/client.cc b/test/cpp/interop/client.cc index 1df2fc83206..3265554444b 100644 --- a/test/cpp/interop/client.cc +++ b/test/cpp/interop/client.cc @@ -32,7 +32,6 @@ */ #include -#include #include @@ -109,78 +108,119 @@ int main(int argc, char** argv) { grpc::testing::InteropClient client(CreateChannelForTestCase(FLAGS_test_case), true, FLAGS_do_not_abort_on_transient_failures); - - std::unordered_map> actions; - actions["empty_unary"] = - std::bind(&grpc::testing::InteropClient::DoEmpty, &client); - actions["large_unary"] = - std::bind(&grpc::testing::InteropClient::DoLargeUnary, &client); - actions["server_compressed_unary"] = std::bind( - &grpc::testing::InteropClient::DoServerCompressedUnary, &client); - actions["client_compressed_unary"] = std::bind( - &grpc::testing::InteropClient::DoClientCompressedUnary, &client); - actions["client_streaming"] = - std::bind(&grpc::testing::InteropClient::DoRequestStreaming, &client); - actions["server_streaming"] = - std::bind(&grpc::testing::InteropClient::DoResponseStreaming, &client); - actions["server_compressed_streaming"] = std::bind( - &grpc::testing::InteropClient::DoServerCompressedStreaming, &client); - actions["client_compressed_streaming"] = std::bind( - &grpc::testing::InteropClient::DoClientCompressedStreaming, &client); - actions["slow_consumer"] = std::bind( - &grpc::testing::InteropClient::DoResponseStreamingWithSlowConsumer, - &client); - actions["half_duplex"] = - std::bind(&grpc::testing::InteropClient::DoHalfDuplex, &client); - actions["ping_pong"] = - std::bind(&grpc::testing::InteropClient::DoPingPong, &client); - actions["cancel_after_begin"] = - std::bind(&grpc::testing::InteropClient::DoCancelAfterBegin, &client); - actions["cancel_after_first_response"] = std::bind( - &grpc::testing::InteropClient::DoCancelAfterFirstResponse, &client); - actions["timeout_on_sleeping_server"] = std::bind( - &grpc::testing::InteropClient::DoTimeoutOnSleepingServer, &client); - actions["empty_stream"] = - std::bind(&grpc::testing::InteropClient::DoEmptyStream, &client); - if (FLAGS_use_tls) { - actions["compute_engine_creds"] = - std::bind(&grpc::testing::InteropClient::DoComputeEngineCreds, &client, - FLAGS_default_service_account, FLAGS_oauth_scope); - actions["jwt_token_creds"] = - std::bind(&grpc::testing::InteropClient::DoJwtTokenCreds, &client, - GetServiceAccountJsonKey()); - actions["oauth2_auth_token"] = - std::bind(&grpc::testing::InteropClient::DoOauth2AuthToken, &client, - FLAGS_default_service_account, FLAGS_oauth_scope); - actions["per_rpc_creds"] = - std::bind(&grpc::testing::InteropClient::DoPerRpcCreds, &client, - GetServiceAccountJsonKey()); - } - actions["status_code_and_message"] = - std::bind(&grpc::testing::InteropClient::DoStatusWithMessage, &client); - actions["custom_metadata"] = - std::bind(&grpc::testing::InteropClient::DoCustomMetadata, &client); - actions["unimplemented_method"] = - std::bind(&grpc::testing::InteropClient::DoUnimplementedMethod, &client); - actions["unimplemented_service"] = - std::bind(&grpc::testing::InteropClient::DoUnimplementedService, &client); - // actions["cacheable_unary"] = - // std::bind(&grpc::testing::InteropClient::DoCacheableUnary, &client); - - if (FLAGS_test_case == "all") { - for (const auto& action : actions) { - action.second(); + if (FLAGS_test_case == "empty_unary") { + client.DoEmpty(); + } else if (FLAGS_test_case == "large_unary") { + client.DoLargeUnary(); + } else if (FLAGS_test_case == "server_compressed_unary") { + client.DoServerCompressedUnary(); + } else if (FLAGS_test_case == "client_compressed_unary") { + client.DoClientCompressedUnary(); + } else if (FLAGS_test_case == "client_streaming") { + client.DoRequestStreaming(); + } else if (FLAGS_test_case == "server_streaming") { + client.DoResponseStreaming(); + } else if (FLAGS_test_case == "server_compressed_streaming") { + client.DoServerCompressedStreaming(); + } else if (FLAGS_test_case == "client_compressed_streaming") { + client.DoClientCompressedStreaming(); + } else if (FLAGS_test_case == "slow_consumer") { + client.DoResponseStreamingWithSlowConsumer(); + } else if (FLAGS_test_case == "half_duplex") { + client.DoHalfDuplex(); + } else if (FLAGS_test_case == "ping_pong") { + client.DoPingPong(); + } else if (FLAGS_test_case == "cancel_after_begin") { + client.DoCancelAfterBegin(); + } else if (FLAGS_test_case == "cancel_after_first_response") { + client.DoCancelAfterFirstResponse(); + } else if (FLAGS_test_case == "timeout_on_sleeping_server") { + client.DoTimeoutOnSleepingServer(); + } else if (FLAGS_test_case == "empty_stream") { + client.DoEmptyStream(); + } else if (FLAGS_test_case == "compute_engine_creds") { + client.DoComputeEngineCreds(FLAGS_default_service_account, + FLAGS_oauth_scope); + } else if (FLAGS_test_case == "jwt_token_creds") { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoJwtTokenCreds(json_key); + } else if (FLAGS_test_case == "oauth2_auth_token") { + client.DoOauth2AuthToken(FLAGS_default_service_account, FLAGS_oauth_scope); + } else if (FLAGS_test_case == "per_rpc_creds") { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoPerRpcCreds(json_key); + } else if (FLAGS_test_case == "status_code_and_message") { + client.DoStatusWithMessage(); + } else if (FLAGS_test_case == "custom_metadata") { + client.DoCustomMetadata(); + } else if (FLAGS_test_case == "unimplemented_method") { + client.DoUnimplementedMethod(); + } else if (FLAGS_test_case == "unimplemented_service") { + client.DoUnimplementedService(); + } else if (FLAGS_test_case == "cacheable_unary") { + client.DoCacheableUnary(); + } else if (FLAGS_test_case == "all") { + client.DoEmpty(); + client.DoLargeUnary(); + client.DoClientCompressedUnary(); + client.DoServerCompressedUnary(); + client.DoRequestStreaming(); + client.DoResponseStreaming(); + client.DoClientCompressedStreaming(); + client.DoServerCompressedStreaming(); + client.DoHalfDuplex(); + client.DoPingPong(); + client.DoCancelAfterBegin(); + client.DoCancelAfterFirstResponse(); + client.DoTimeoutOnSleepingServer(); + client.DoEmptyStream(); + client.DoStatusWithMessage(); + client.DoCustomMetadata(); + client.DoUnimplementedMethod(); + client.DoUnimplementedService(); + client.DoCacheableUnary(); + // service_account_creds and jwt_token_creds can only run with ssl. + if (FLAGS_use_tls) { + grpc::string json_key = GetServiceAccountJsonKey(); + client.DoJwtTokenCreds(json_key); + client.DoOauth2AuthToken(FLAGS_default_service_account, + FLAGS_oauth_scope); + client.DoPerRpcCreds(json_key); } - } else if (actions.find(FLAGS_test_case) != actions.end()) { - actions.find(FLAGS_test_case)->second(); + // compute_engine_creds only runs in GCE. } else { - grpc::string test_cases; - for (const auto& action : actions) { - if (!test_cases.empty()) test_cases += "\n"; - test_cases += action.first; - } + const char* testcases[] = {"all", + "cacheable_unary", + "cancel_after_begin", + "cancel_after_first_response", + "client_compressed_streaming", + "client_compressed_unary", + "client_streaming", + "compute_engine_creds", + "custom_metadata", + "empty_stream", + "empty_unary", + "half_duplex", + "jwt_token_creds", + "large_unary", + "oauth2_auth_token", + "oauth2_auth_token", + "per_rpc_creds", + "per_rpc_creds", + "ping_pong", + "server_compressed_streaming", + "server_compressed_unary", + "server_streaming", + "status_code_and_message", + "timeout_on_sleeping_server", + "unimplemented_method", + "unimplemented_service"}; + char* joined_testcases = + gpr_strjoin_sep(testcases, GPR_ARRAY_SIZE(testcases), "\n", NULL); + gpr_log(GPR_ERROR, "Unsupported test case %s. Valid options are\n%s", - FLAGS_test_case.c_str(), test_cases.c_str()); + FLAGS_test_case.c_str(), joined_testcases); + gpr_free(joined_testcases); ret = 1; } diff --git a/test/cpp/interop/interop_client.cc b/test/cpp/interop/interop_client.cc index aa34d94f61f..d1242627ef3 100644 --- a/test/cpp/interop/interop_client.cc +++ b/test/cpp/interop/interop_client.cc @@ -109,10 +109,7 @@ TestService::Stub* InteropClient::ServiceStub::Get() { UnimplementedService::Stub* InteropClient::ServiceStub::GetUnimplementedServiceStub() { - if (unimplemented_service_stub_ == nullptr) { - unimplemented_service_stub_ = UnimplementedService::NewStub(channel_); - } - return unimplemented_service_stub_.get(); + return UnimplementedService::NewStub(channel_).get(); } void InteropClient::ServiceStub::Reset(std::shared_ptr channel) { @@ -946,7 +943,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second == kInitialMetadataValue); + GPR_ASSERT(iter->second.data() == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); @@ -997,7 +994,7 @@ bool InteropClient::DoCustomMetadata() { const auto& server_initial_metadata = context.GetServerInitialMetadata(); auto iter = server_initial_metadata.find(kEchoInitialMetadataKey); GPR_ASSERT(iter != server_initial_metadata.end()); - GPR_ASSERT(iter->second == kInitialMetadataValue); + GPR_ASSERT(iter->second.data() == kInitialMetadataValue); const auto& server_trailing_metadata = context.GetServerTrailingMetadata(); iter = server_trailing_metadata.find(kEchoTrailingBinMetadataKey); GPR_ASSERT(iter != server_trailing_metadata.end()); diff --git a/test/cpp/interop/interop_client.h b/test/cpp/interop/interop_client.h index 74f4db6b789..7ec7ebee209 100644 --- a/test/cpp/interop/interop_client.h +++ b/test/cpp/interop/interop_client.h @@ -107,7 +107,6 @@ class InteropClient { private: std::unique_ptr stub_; - std::unique_ptr unimplemented_service_stub_; std::shared_ptr channel_; bool new_stub_every_call_; // If true, a new stub is returned by every // Get() call diff --git a/test/cpp/interop/interop_server.cc b/test/cpp/interop/interop_server.cc index 1810cd076f9..956840ba709 100644 --- a/test/cpp/interop/interop_server.cc +++ b/test/cpp/interop/interop_server.cc @@ -91,9 +91,7 @@ void MaybeEchoMetadata(ServerContext* context) { auto iter = client_metadata.find(kEchoInitialMetadataKey); if (iter != client_metadata.end()) { - context->AddInitialMetadata( - kEchoInitialMetadataKey, - grpc::string(iter->second.begin(), iter->second.end())); + context->AddInitialMetadata(kEchoInitialMetadataKey, iter->second.data()); } iter = client_metadata.find(kEchoTrailingBinMetadataKey); if (iter != client_metadata.end()) { diff --git a/test/cpp/microbenchmarks/bm_fullstack.cc b/test/cpp/microbenchmarks/bm_fullstack.cc index bd158db5221..6c0bf804885 100644 --- a/test/cpp/microbenchmarks/bm_fullstack.cc +++ b/test/cpp/microbenchmarks/bm_fullstack.cc @@ -443,8 +443,6 @@ BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, Server_AddInitialMetadata, 1>); BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, Server_AddInitialMetadata, 1>); -BENCHMARK_TEMPLATE(BM_UnaryPingPong, InProcessCHTTP2, NoOpMutator, - Server_AddInitialMetadata, 100>); } // namespace testing } // namespace grpc diff --git a/test/cpp/test/server_context_test_spouse_test.cc b/test/cpp/test/server_context_test_spouse_test.cc index eb279e2401b..e0d6a2ff67a 100644 --- a/test/cpp/test/server_context_test_spouse_test.cc +++ b/test/cpp/test/server_context_test_spouse_test.cc @@ -36,14 +36,11 @@ #include #include -#include #include namespace grpc { namespace testing { -static internal::GrpcLibraryInitializer g_initializer; - const char key1[] = "metadata-key1"; const char key2[] = "metadata-key2"; const char val1[] = "metadata-val1"; diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index 0374cf75a1a..cf3762dbb8d 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -31,12 +31,8 @@ import hashlib import itertools -import collections import os import sys -import subprocess -import re -import perfection # configuration: a list of either strings or 2-tuples of strings # a single string represents a static grpc_mdstr @@ -44,8 +40,6 @@ import perfection # also be created) CONFIG = [ - # metadata strings - 'host', 'grpc-timeout', 'grpc-internal-encoding-request', 'grpc-payload-bin', @@ -54,19 +48,12 @@ CONFIG = [ 'grpc-accept-encoding', 'user-agent', ':authority', + 'host', 'grpc-message', 'grpc-status', 'grpc-tracing-bin', 'grpc-stats-bin', '', - # channel arg keys - 'grpc.wait_for_ready', - 'grpc.timeout', - 'grpc.max_request_message_bytes', - 'grpc.max_response_message_bytes', - # well known method names - '/grpc.lb.v1.LoadBalancer/BalanceLoad', - # metadata elements ('grpc-status', '0'), ('grpc-status', '1'), ('grpc-status', '2'), @@ -143,26 +130,6 @@ CONFIG = [ ('www-authenticate', ''), ] -METADATA_BATCH_CALLOUTS = [ - ':path', - ':method', - ':status', - ':authority', - ':scheme', - 'te', - 'grpc-message', - 'grpc-status', - 'grpc-payload-bin', - 'grpc-encoding', - 'grpc-accept-encoding', - 'content-type', - 'grpc-internal-encoding-request', - 'user-agent', - 'host', - 'lb-token', - 'lb-cost-bin', -] - COMPRESSION_ALGORITHMS = [ 'identity', 'deflate', @@ -170,7 +137,7 @@ COMPRESSION_ALGORITHMS = [ ] # utility: mangle the name of a config -def mangle(elem, name=None): +def mangle(elem): xl = { '-': '_', ':': '', @@ -195,14 +162,10 @@ def mangle(elem, name=None): r += put if r[-1] == '_': r = r[:-1] return r - def n(default, name=name): - if name is None: return 'grpc_%s_' % default - if name == '': return '' - return 'grpc_%s_' % name if isinstance(elem, tuple): - return '%s%s_%s' % (n('mdelem'), m0(elem[0]), m0(elem[1])) + return 'grpc_mdelem_%s_%s' % (m0(elem[0]), m0(elem[1])) else: - return '%s%s' % (n('mdstr'), m0(elem)) + return 'grpc_mdstr_%s' % (m0(elem)) # utility: generate some hash value for a string def fake_hash(elem): @@ -218,37 +181,28 @@ def put_banner(files, banner): print >>f # build a list of all the strings we need -all_strs = list() -all_elems = list() +all_strs = set() +all_elems = set() static_userdata = {} -# put metadata batch callouts first, to make the check of if a static metadata -# string is a callout trivial -for elem in METADATA_BATCH_CALLOUTS: - if elem not in all_strs: - all_strs.append(elem) for elem in CONFIG: if isinstance(elem, tuple): - if elem[0] not in all_strs: - all_strs.append(elem[0]) - if elem[1] not in all_strs: - all_strs.append(elem[1]) - if elem not in all_elems: - all_elems.append(elem) + all_strs.add(elem[0]) + all_strs.add(elem[1]) + all_elems.add(elem) else: - if elem not in all_strs: - all_strs.append(elem) + all_strs.add(elem) compression_elems = [] for mask in range(1, 1<>H print >>C, '#include "src/core/lib/transport/static_metadata.h"' print >>C -print >>C, '#include "src/core/lib/slice/slice_internal.h"' -print >>C - -str_ofs = 0 -id2strofs = {} -for i, elem in enumerate(all_strs): - id2strofs[i] = str_ofs - str_ofs += len(elem); -def slice_def(i): - return '{.refcount = &grpc_static_metadata_refcounts[%d], .data.refcounted = {g_bytes+%d, %d}}' % (i, id2strofs[i], len(all_strs[i])) - -# validate configuration -for elem in METADATA_BATCH_CALLOUTS: - assert elem in all_strs print >>H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) -print >>H, 'extern const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT];' +print >>H, 'extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];' for i, elem in enumerate(all_strs): print >>H, '/* "%s" */' % elem - print >>H, '#define %s (grpc_static_slice_table[%d])' % (mangle(elem).upper(), i) -print >>H -print >>C, 'static uint8_t g_bytes[] = {%s};' % (','.join('%d' % ord(c) for c in ''.join(all_strs))) -print >>C -print >>C, 'static void static_ref(void *unused) {}' -print >>C, 'static void static_unref(grpc_exec_ctx *exec_ctx, void *unused) {}' -print >>C, 'static const grpc_slice_refcount_vtable static_sub_vtable = {static_ref, static_unref, grpc_slice_default_eq_impl, grpc_slice_default_hash_impl};'; -print >>H, 'extern const grpc_slice_refcount_vtable grpc_static_metadata_vtable;'; -print >>C, 'const grpc_slice_refcount_vtable grpc_static_metadata_vtable = {static_ref, static_unref, grpc_static_slice_eq, grpc_static_slice_hash};'; -print >>C, 'static grpc_slice_refcount static_sub_refcnt = {&static_sub_vtable, &static_sub_refcnt};'; -print >>H, 'extern grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT];' -print >>C, 'grpc_slice_refcount grpc_static_metadata_refcounts[GRPC_STATIC_MDSTR_COUNT] = {' -for i, elem in enumerate(all_strs): - print >>C, ' {&grpc_static_metadata_vtable, &static_sub_refcnt},' -print >>C, '};' -print >>C -print >>H, '#define GRPC_IS_STATIC_METADATA_STRING(slice) \\' -print >>H, ' ((slice).refcount != NULL && (slice).refcount->vtable == &grpc_static_metadata_vtable)' + print >>H, '#define %s (&grpc_static_mdstr_table[%d])' % (mangle(elem).upper(), i) print >>H -print >>C, 'const grpc_slice grpc_static_slice_table[GRPC_STATIC_MDSTR_COUNT] = {' -for i, elem in enumerate(all_strs): - print >>C, slice_def(i) + ',' -print >>C, '};' +print >>C, 'grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT];' print >>C -print >>H, '#define GRPC_STATIC_METADATA_INDEX(static_slice) \\' -print >>H, ' ((int)((static_slice).refcount - grpc_static_metadata_refcounts))' -print >>H print >>D, '# hpack fuzzing dictionary' for i, elem in enumerate(all_strs): @@ -380,12 +297,13 @@ for i, elem in enumerate(all_elems): [len(elem[1])] + [ord(c) for c in elem[1]])) print >>H, '#define GRPC_STATIC_MDELEM_COUNT %d' % len(all_elems) -print >>H, 'extern grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' +print >>H, 'extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' print >>H, 'extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT];' for i, elem in enumerate(all_elems): print >>H, '/* "%s": "%s" */' % elem - print >>H, '#define %s (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[%d], GRPC_MDELEM_STORAGE_STATIC))' % (mangle(elem).upper(), i) + print >>H, '#define %s (&grpc_static_mdelem_table[%d])' % (mangle(elem).upper(), i) print >>H +print >>C, 'grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT];' print >>C, 'uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = {' print >>C, ' %s' % ','.join('%d' % static_userdata.get(elem, 0) for elem in all_elems) print >>C, '};' @@ -401,92 +319,17 @@ def md_idx(m): if m == m2: return i -def offset_trials(mink): - yield 0 - for i in range(1, 100): - for mul in [-1, 1]: - yield mul * i - -def perfect_hash(keys, name): - p = perfection.hash_parameters(keys) - def f(i, p=p): - i += p.offset - x = i % p.t - y = i / p.t - return x + p.r[y] - return { - 'PHASHRANGE': p.t - 1 + max(p.r), - 'PHASHNKEYS': len(p.slots), - 'pyfunc': f, - 'code': """ -static const int8_t %(name)s_r[] = {%(r)s}; -static uint32_t %(name)s_phash(uint32_t i) { - i %(offset_sign)s= %(offset)d; - uint32_t x = i %% %(t)d; - uint32_t y = i / %(t)d; - uint32_t h = x; - if (y < GPR_ARRAY_SIZE(%(name)s_r)) { - uint32_t delta = (uint32_t)%(name)s_r[y]; - h += delta; - } - return h; -} - """ % { - 'name': name, - 'r': ','.join('%d' % (r if r is not None else 0) for r in p.r), - 't': p.t, - 'offset': abs(p.offset), - 'offset_sign': '+' if p.offset > 0 else '-' - } - } - - -elem_keys = [str_idx(elem[0]) * len(all_strs) + str_idx(elem[1]) for elem in all_elems] -elem_hash = perfect_hash(elem_keys, "elems") -print >>C, elem_hash['code'] - -keys = [0] * int(elem_hash['PHASHRANGE']) -idxs = [255] * int(elem_hash['PHASHNKEYS']) -for i, k in enumerate(elem_keys): - h = elem_hash['pyfunc'](k) - assert keys[h] == 0 - keys[h] = k - idxs[h] = i -print >>C, 'static const uint16_t elem_keys[] = {%s};' % ','.join('%d' % k for k in keys) -print >>C, 'static const uint8_t elem_idxs[] = {%s};' % ','.join('%d' % i for i in idxs) -print >>C - -print >>H, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b);' -print >>C, 'grpc_mdelem grpc_static_mdelem_for_static_strings(int a, int b) {' -print >>C, ' if (a == -1 || b == -1) return GRPC_MDNULL;' -print >>C, ' uint32_t k = (uint32_t)(a * %d + b);' % len(all_strs) -print >>C, ' uint32_t h = elems_phash(k);' -print >>C, ' return elem_keys[h] == k ? GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[elem_idxs[h]], GRPC_MDELEM_STORAGE_STATIC) : GRPC_MDNULL;' -print >>C, '}' +print >>H, 'extern const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2];' +print >>C, 'const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT*2] = {' +print >>C, ','.join('%d' % str_idx(x) for x in itertools.chain.from_iterable([a,b] for a, b in all_elems)) +print >>C, '};' print >>C -print >>C, 'grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {' -for a, b in all_elems: - print >>C, '{%s,%s},' % (slice_def(str_idx(a)), slice_def(str_idx(b))) +print >>H, 'extern const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT];' +print >>C, 'const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = {' +print >>C, '%s' % ',\n'.join(' "%s"' % s for s in all_strs) print >>C, '};' - -print >>H, 'typedef enum {' -for elem in METADATA_BATCH_CALLOUTS: - print >>H, ' %s,' % mangle(elem, 'batch').upper() -print >>H, ' GRPC_BATCH_CALLOUTS_COUNT' -print >>H, '} grpc_metadata_batch_callouts_index;' -print >>H -print >>H, 'typedef union {' -print >>H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];' -print >>H, ' struct {' -for elem in METADATA_BATCH_CALLOUTS: - print >>H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower() -print >>H, ' } named;' -print >>H, '} grpc_metadata_batch_callouts;' -print >>H -print >>H, '#define GRPC_BATCH_INDEX_OF(slice) \\' -print >>H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' -print >>H +print >>C print >>H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (1 << len(COMPRESSION_ALGORITHMS)) print >>C, 'const uint8_t grpc_static_accept_encoding_metadata[%d] = {' % (1 << len(COMPRESSION_ALGORITHMS)) @@ -494,7 +337,7 @@ print >>C, '0,%s' % ','.join('%d' % md_idx(elem) for elem in compression_elems) print >>C, '};' print >>C -print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (GRPC_MAKE_MDELEM(&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]], GRPC_MDELEM_STORAGE_STATIC))' +print >>H, '#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) (&grpc_static_mdelem_table[grpc_static_accept_encoding_metadata[(algs)]])' print >>H, '#endif /* GRPC_CORE_LIB_TRANSPORT_STATIC_METADATA_H */' diff --git a/tools/doxygen/Doxyfile.c++ b/tools/doxygen/Doxyfile.c++ index 128a409df40..af844d661be 100644 --- a/tools/doxygen/Doxyfile.c++ +++ b/tools/doxygen/Doxyfile.c++ @@ -822,7 +822,6 @@ include/grpc++/impl/codegen/serialization_traits.h \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ -include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ diff --git a/tools/doxygen/Doxyfile.c++.internal b/tools/doxygen/Doxyfile.c++.internal index 5bd4323f3a4..2b2d8a3fe1f 100644 --- a/tools/doxygen/Doxyfile.c++.internal +++ b/tools/doxygen/Doxyfile.c++.internal @@ -823,7 +823,6 @@ include/grpc++/impl/codegen/serialization_traits.h \ include/grpc++/impl/codegen/server_context.h \ include/grpc++/impl/codegen/server_interface.h \ include/grpc++/impl/codegen/service_type.h \ -include/grpc++/impl/codegen/slice.h \ include/grpc++/impl/codegen/status.h \ include/grpc++/impl/codegen/status_code_enum.h \ include/grpc++/impl/codegen/status_helper.h \ diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index 9fa2916ca91..ffe83a2ddb3 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -981,12 +981,15 @@ src/core/ext/transport/chttp2/transport/hpack_parser.c \ src/core/ext/transport/chttp2/transport/hpack_parser.h \ src/core/ext/transport/chttp2/transport/hpack_table.c \ src/core/ext/transport/chttp2/transport/hpack_table.h \ +src/core/ext/transport/chttp2/transport/http2_errors.h \ src/core/ext/transport/chttp2/transport/huffsyms.c \ src/core/ext/transport/chttp2/transport/huffsyms.h \ src/core/ext/transport/chttp2/transport/incoming_metadata.c \ src/core/ext/transport/chttp2/transport/incoming_metadata.h \ src/core/ext/transport/chttp2/transport/internal.h \ src/core/ext/transport/chttp2/transport/parsing.c \ +src/core/ext/transport/chttp2/transport/status_conversion.c \ +src/core/ext/transport/chttp2/transport/status_conversion.h \ src/core/ext/transport/chttp2/transport/stream_lists.c \ src/core/ext/transport/chttp2/transport/stream_map.c \ src/core/ext/transport/chttp2/transport/stream_map.h \ @@ -1046,7 +1049,6 @@ src/core/lib/iomgr/endpoint_pair_uv.c \ src/core/lib/iomgr/endpoint_pair_windows.c \ src/core/lib/iomgr/error.c \ src/core/lib/iomgr/error.h \ -src/core/lib/iomgr/error_internal.h \ src/core/lib/iomgr/ev_epoll_linux.c \ src/core/lib/iomgr/ev_epoll_linux.h \ src/core/lib/iomgr/ev_poll_posix.c \ @@ -1202,9 +1204,6 @@ src/core/lib/slice/percent_encoding.c \ src/core/lib/slice/percent_encoding.h \ src/core/lib/slice/slice.c \ src/core/lib/slice/slice_buffer.c \ -src/core/lib/slice/slice_hash_table.c \ -src/core/lib/slice/slice_hash_table.h \ -src/core/lib/slice/slice_intern.c \ src/core/lib/slice/slice_internal.h \ src/core/lib/slice/slice_string_helpers.c \ src/core/lib/slice/slice_string_helpers.h \ @@ -1292,16 +1291,14 @@ src/core/lib/surface/metadata_array.c \ src/core/lib/surface/server.c \ src/core/lib/surface/server.h \ src/core/lib/surface/validate_metadata.c \ -src/core/lib/surface/validate_metadata.h \ src/core/lib/surface/version.c \ src/core/lib/transport/README.md \ src/core/lib/transport/byte_stream.c \ src/core/lib/transport/byte_stream.h \ src/core/lib/transport/connectivity_state.c \ src/core/lib/transport/connectivity_state.h \ -src/core/lib/transport/error_utils.c \ -src/core/lib/transport/error_utils.h \ -src/core/lib/transport/http2_errors.h \ +src/core/lib/transport/mdstr_hash_table.c \ +src/core/lib/transport/mdstr_hash_table.h \ src/core/lib/transport/metadata.c \ src/core/lib/transport/metadata.h \ src/core/lib/transport/metadata_batch.c \ @@ -1312,8 +1309,6 @@ 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/status_conversion.c \ -src/core/lib/transport/status_conversion.h \ src/core/lib/transport/timeout_encoding.c \ src/core/lib/transport/timeout_encoding.h \ src/core/lib/transport/transport.c \ diff --git a/tools/run_tests/generated/configs.json b/tools/run_tests/generated/configs.json index f2c110766b2..b0839ef026a 100644 --- a/tools/run_tests/generated/configs.json +++ b/tools/run_tests/generated/configs.json @@ -2,6 +2,37 @@ { "config": "opt" }, + { + "config": "asan-trace-cmp", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "dbg" + }, + { + "config": "easan", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "asan", + "environ": { + "ASAN_OPTIONS": "detect_leaks=1:color=always", + "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + }, + "timeout_multiplier": 3 + }, + { + "config": "msan", + "timeout_multiplier": 4 + }, { "config": "basicprof" }, @@ -21,21 +52,27 @@ "timeout_multiplier": 3 }, { - "config": "asan-trace-cmp", + "config": "edbg" + }, + { + "config": "ubsan", "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" + "UBSAN_OPTIONS": "halt_on_error=1:print_stacktrace=1" }, - "timeout_multiplier": 3 + "timeout_multiplier": 1.5 }, { - "config": "dbg" + "config": "tsan", + "environ": { + "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" + }, + "timeout_multiplier": 5 }, { "config": "stapprof" }, { - "config": "gcov" + "config": "mutrace" }, { "config": "memcheck", @@ -47,32 +84,13 @@ ] }, { - "config": "asan", - "environ": { - "ASAN_OPTIONS": "detect_leaks=1:color=always", - "LSAN_OPTIONS": "suppressions=tools/lsan_suppressions.txt:report_objects=1" - }, - "timeout_multiplier": 3 - }, - { - "config": "tsan", + "config": "etsan", "environ": { "TSAN_OPTIONS": "suppressions=tools/tsan_suppressions.txt:halt_on_error=1:second_deadlock_stack=1" }, "timeout_multiplier": 5 }, { - "config": "ubsan", - "environ": { - "UBSAN_OPTIONS": "halt_on_error=1:print_stacktrace=1" - }, - "timeout_multiplier": 1.5 - }, - { - "config": "msan", - "timeout_multiplier": 4 - }, - { - "config": "mutrace" + "config": "gcov" } ] diff --git a/tools/run_tests/generated/sources_and_headers.json b/tools/run_tests/generated/sources_and_headers.json index e392a42949a..9bc82486d2b 100644 --- a/tools/run_tests/generated/sources_and_headers.json +++ b/tools/run_tests/generated/sources_and_headers.json @@ -217,6 +217,23 @@ "third_party": false, "type": "target" }, + { + "deps": [ + "gpr", + "gpr_test_util", + "grpc", + "grpc_test_util" + ], + "headers": [], + "is_filegroup": false, + "language": "c", + "name": "chttp2_status_conversion_test", + "src": [ + "test/core/transport/chttp2/status_conversion_test.c" + ], + "third_party": false, + "type": "target" + }, { "deps": [ "gpr", @@ -1983,23 +2000,6 @@ "third_party": false, "type": "target" }, - { - "deps": [ - "gpr", - "gpr_test_util", - "grpc", - "grpc_test_util" - ], - "headers": [], - "is_filegroup": false, - "language": "c", - "name": "status_conversion_test", - "src": [ - "test/core/transport/status_conversion_test.c" - ], - "third_party": false, - "type": "target" - }, { "deps": [ "gpr", @@ -7011,7 +7011,6 @@ "src/core/lib/iomgr/endpoint.h", "src/core/lib/iomgr/endpoint_pair.h", "src/core/lib/iomgr/error.h", - "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.h", "src/core/lib/iomgr/ev_posix.h", @@ -7064,7 +7063,6 @@ "src/core/lib/json/json_reader.h", "src/core/lib/json/json_writer.h", "src/core/lib/slice/percent_encoding.h", - "src/core/lib/slice/slice_hash_table.h", "src/core/lib/slice/slice_internal.h", "src/core/lib/slice/slice_string_helpers.h", "src/core/lib/surface/api_trace.h", @@ -7078,17 +7076,14 @@ "src/core/lib/surface/init.h", "src/core/lib/surface/lame_client.h", "src/core/lib/surface/server.h", - "src/core/lib/surface/validate_metadata.h", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/error_utils.h", - "src/core/lib/transport/http2_errors.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/pid_controller.h", "src/core/lib/transport/service_config.h", "src/core/lib/transport/static_metadata.h", - "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.h", "src/core/lib/transport/transport_impl.h" @@ -7155,7 +7150,6 @@ "src/core/lib/iomgr/endpoint_pair_windows.c", "src/core/lib/iomgr/error.c", "src/core/lib/iomgr/error.h", - "src/core/lib/iomgr/error_internal.h", "src/core/lib/iomgr/ev_epoll_linux.c", "src/core/lib/iomgr/ev_epoll_linux.h", "src/core/lib/iomgr/ev_poll_posix.c", @@ -7267,9 +7261,6 @@ "src/core/lib/slice/percent_encoding.h", "src/core/lib/slice/slice.c", "src/core/lib/slice/slice_buffer.c", - "src/core/lib/slice/slice_hash_table.c", - "src/core/lib/slice/slice_hash_table.h", - "src/core/lib/slice/slice_intern.c", "src/core/lib/slice/slice_internal.h", "src/core/lib/slice/slice_string_helpers.c", "src/core/lib/slice/slice_string_helpers.h", @@ -7301,15 +7292,13 @@ "src/core/lib/surface/server.c", "src/core/lib/surface/server.h", "src/core/lib/surface/validate_metadata.c", - "src/core/lib/surface/validate_metadata.h", "src/core/lib/surface/version.c", "src/core/lib/transport/byte_stream.c", "src/core/lib/transport/byte_stream.h", "src/core/lib/transport/connectivity_state.c", "src/core/lib/transport/connectivity_state.h", - "src/core/lib/transport/error_utils.c", - "src/core/lib/transport/error_utils.h", - "src/core/lib/transport/http2_errors.h", + "src/core/lib/transport/mdstr_hash_table.c", + "src/core/lib/transport/mdstr_hash_table.h", "src/core/lib/transport/metadata.c", "src/core/lib/transport/metadata.h", "src/core/lib/transport/metadata_batch.c", @@ -7320,8 +7309,6 @@ "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/status_conversion.c", - "src/core/lib/transport/status_conversion.h", "src/core/lib/transport/timeout_encoding.c", "src/core/lib/transport/timeout_encoding.h", "src/core/lib/transport/transport.c", @@ -7691,9 +7678,11 @@ "src/core/ext/transport/chttp2/transport/hpack_encoder.h", "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.h", + "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", + "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_map.h", "src/core/ext/transport/chttp2/transport/varint.h" ], @@ -7727,12 +7716,15 @@ "src/core/ext/transport/chttp2/transport/hpack_parser.h", "src/core/ext/transport/chttp2/transport/hpack_table.c", "src/core/ext/transport/chttp2/transport/hpack_table.h", + "src/core/ext/transport/chttp2/transport/http2_errors.h", "src/core/ext/transport/chttp2/transport/huffsyms.c", "src/core/ext/transport/chttp2/transport/huffsyms.h", "src/core/ext/transport/chttp2/transport/incoming_metadata.c", "src/core/ext/transport/chttp2/transport/incoming_metadata.h", "src/core/ext/transport/chttp2/transport/internal.h", "src/core/ext/transport/chttp2/transport/parsing.c", + "src/core/ext/transport/chttp2/transport/status_conversion.c", + "src/core/ext/transport/chttp2/transport/status_conversion.h", "src/core/ext/transport/chttp2/transport/stream_lists.c", "src/core/ext/transport/chttp2/transport/stream_map.c", "src/core/ext/transport/chttp2/transport/stream_map.h", @@ -8101,7 +8093,6 @@ "include/grpc++/impl/codegen/server_context.h", "include/grpc++/impl/codegen/server_interface.h", "include/grpc++/impl/codegen/service_type.h", - "include/grpc++/impl/codegen/slice.h", "include/grpc++/impl/codegen/status.h", "include/grpc++/impl/codegen/status_code_enum.h", "include/grpc++/impl/codegen/status_helper.h", @@ -8135,7 +8126,6 @@ "include/grpc++/impl/codegen/server_context.h", "include/grpc++/impl/codegen/server_interface.h", "include/grpc++/impl/codegen/service_type.h", - "include/grpc++/impl/codegen/slice.h", "include/grpc++/impl/codegen/status.h", "include/grpc++/impl/codegen/status_code_enum.h", "include/grpc++/impl/codegen/status_helper.h", diff --git a/tools/run_tests/generated/tests.json b/tools/run_tests/generated/tests.json index c5a308a4c59..2c7b0a6c822 100644 --- a/tools/run_tests/generated/tests.json +++ b/tools/run_tests/generated/tests.json @@ -267,6 +267,28 @@ "windows" ] }, + { + "args": [], + "ci_platforms": [ + "linux", + "mac", + "posix", + "windows" + ], + "cpu_cost": 1.0, + "exclude_configs": [], + "exclude_iomgrs": [], + "flaky": false, + "gtest": false, + "language": "c", + "name": "chttp2_status_conversion_test", + "platforms": [ + "linux", + "mac", + "posix", + "windows" + ] + }, { "args": [], "ci_platforms": [ @@ -2011,28 +2033,6 @@ "posix" ] }, - { - "args": [], - "ci_platforms": [ - "linux", - "mac", - "posix", - "windows" - ], - "cpu_cost": 1.0, - "exclude_configs": [], - "exclude_iomgrs": [], - "flaky": false, - "gtest": false, - "language": "c", - "name": "status_conversion_test", - "platforms": [ - "linux", - "mac", - "posix", - "windows" - ] - }, { "args": [], "ci_platforms": [ @@ -39139,6 +39139,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39173,6 +39176,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39207,6 +39213,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39241,6 +39250,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39275,6 +39287,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39309,6 +39324,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39343,6 +39361,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39377,6 +39398,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39411,6 +39435,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39445,6 +39472,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39479,6 +39509,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39513,6 +39546,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39547,6 +39583,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39581,6 +39620,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39615,6 +39657,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39649,6 +39694,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39683,6 +39731,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39717,6 +39768,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39751,6 +39805,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39785,6 +39842,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39819,6 +39879,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39853,6 +39916,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39887,6 +39953,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39921,6 +39990,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39955,6 +40027,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -39989,6 +40064,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40023,6 +40101,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40057,6 +40138,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40091,6 +40175,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40125,6 +40212,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40159,6 +40249,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40193,6 +40286,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40227,6 +40323,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", @@ -40261,6 +40360,9 @@ "asan-trace-cmp", "basicprof", "dbg", + "easan", + "edbg", + "etsan", "gcov", "helgrind", "memcheck", diff --git a/vsprojects/buildtests_c.sln b/vsprojects/buildtests_c.sln index aa382154eb0..f484f29a4b2 100644 --- a/vsprojects/buildtests_c.sln +++ b/vsprojects/buildtests_c.sln @@ -153,6 +153,17 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_hpack_encoder_test", {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_status_conversion_test", "vcxproj\test\chttp2_status_conversion_test\chttp2_status_conversion_test.vcxproj", "{ABAD3D2C-078C-7850-B413-3352A07C6176}" + ProjectSection(myProperties) = preProject + lib = "False" + EndProjectSection + ProjectSection(ProjectDependencies) = postProject + {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} + {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} + {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} + {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} + EndProjectSection +EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "chttp2_stream_map_test", "vcxproj\test\chttp2_stream_map_test\chttp2_stream_map_test.vcxproj", "{12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}" ProjectSection(myProperties) = preProject lib = "False" @@ -1445,17 +1456,6 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sockaddr_utils_test", "vcxp {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} EndProjectSection EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "status_conversion_test", "vcxproj\test\status_conversion_test\status_conversion_test.vcxproj", "{21E2A241-9D48-02CD-92E4-4EEC98424CF5}" - ProjectSection(myProperties) = preProject - lib = "False" - EndProjectSection - ProjectSection(ProjectDependencies) = postProject - {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} = {17BCAFC0-5FDC-4C94-AEB9-95F3E220614B} - {29D16885-7228-4C31-81ED-5F9187C7F2A9} = {29D16885-7228-4C31-81ED-5F9187C7F2A9} - {EAB0A629-17A9-44DB-B5FF-E91A721FE037} = {EAB0A629-17A9-44DB-B5FF-E91A721FE037} - {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} = {B23D3D1A-9438-4EDA-BEB6-9A0A03D17792} - EndProjectSection -EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_tcp_server", "vcxproj\.\test_tcp_server\test_tcp_server.vcxproj", "{E3110C46-A148-FF65-08FD-3324829BE7FE}" ProjectSection(myProperties) = preProject lib = "True" @@ -1815,6 +1815,22 @@ Global {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|Win32.Build.0 = Release|Win32 {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|x64.ActiveCfg = Release|x64 {19F92966-3B0E-4FF8-CD7C-435D353E079E}.Release-DLL|x64.Build.0 = Release|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|Win32.ActiveCfg = Debug|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|x64.ActiveCfg = Debug|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|Win32.ActiveCfg = Release|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|x64.ActiveCfg = Release|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|Win32.Build.0 = Debug|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug|x64.Build.0 = Debug|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|Win32.Build.0 = Release|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release|x64.Build.0 = Release|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|Win32.Build.0 = Debug|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|x64.ActiveCfg = Debug|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Debug-DLL|x64.Build.0 = Debug|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|Win32.ActiveCfg = Release|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|Win32.Build.0 = Release|Win32 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|x64.ActiveCfg = Release|x64 + {ABAD3D2C-078C-7850-B413-3352A07C6176}.Release-DLL|x64.Build.0 = Release|x64 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Debug|Win32.ActiveCfg = Debug|Win32 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Debug|x64.ActiveCfg = Debug|x64 {12F9C5F8-1BDA-305F-5A0B-B0F9CC7AA7A4}.Release|Win32.ActiveCfg = Release|Win32 @@ -3751,22 +3767,6 @@ Global {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|Win32.Build.0 = Release|Win32 {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|x64.ActiveCfg = Release|x64 {529771F0-10B0-9B1A-1E7E-8A8E01870348}.Release-DLL|x64.Build.0 = Release|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|Win32.ActiveCfg = Debug|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|x64.ActiveCfg = Debug|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|Win32.ActiveCfg = Release|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|x64.ActiveCfg = Release|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|Win32.Build.0 = Debug|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug|x64.Build.0 = Debug|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|Win32.Build.0 = Release|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release|x64.Build.0 = Release|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|Win32.ActiveCfg = Debug|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|Win32.Build.0 = Debug|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|x64.ActiveCfg = Debug|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Debug-DLL|x64.Build.0 = Debug|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|Win32.ActiveCfg = Release|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|Win32.Build.0 = Release|Win32 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|x64.ActiveCfg = Release|x64 - {21E2A241-9D48-02CD-92E4-4EEC98424CF5}.Release-DLL|x64.Build.0 = Release|x64 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Debug|Win32.ActiveCfg = Debug|Win32 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Debug|x64.ActiveCfg = Debug|x64 {E3110C46-A148-FF65-08FD-3324829BE7FE}.Release|Win32.ActiveCfg = Release|Win32 diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj b/vsprojects/vcxproj/grpc++/grpc++.vcxproj index 86c2fe3641d..bd9c5467d8e 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj @@ -321,7 +321,6 @@ - diff --git a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters index dffc70f4c9a..93d8274dc0f 100644 --- a/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++/grpc++.vcxproj.filters @@ -303,9 +303,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj index 58b87ef73e1..7eba5c52ab2 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj @@ -168,7 +168,6 @@ - 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 aabb45dc6af..9a10e07056a 100644 --- a/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_test_util/grpc++_test_util.vcxproj.filters @@ -96,9 +96,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj index 33a74ba01e7..7f2e815f200 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj @@ -321,7 +321,6 @@ - diff --git a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters index b87d789abe2..df62384b1e2 100644 --- a/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc++_unsecure/grpc++_unsecure.vcxproj.filters @@ -288,9 +288,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj b/vsprojects/vcxproj/grpc/grpc.vcxproj index 2d79ffebb49..c159db63f55 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj @@ -323,7 +323,6 @@ - @@ -376,7 +375,6 @@ - @@ -390,17 +388,14 @@ - - - + - @@ -417,9 +412,11 @@ + + @@ -656,10 +653,6 @@ - - - - @@ -702,7 +695,7 @@ - + @@ -714,8 +707,6 @@ - - @@ -756,6 +747,8 @@ + + diff --git a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters index 04493499835..1e099f3285e 100644 --- a/vsprojects/vcxproj/grpc/grpc.vcxproj.filters +++ b/vsprojects/vcxproj/grpc/grpc.vcxproj.filters @@ -256,12 +256,6 @@ src\core\lib\slice - - src\core\lib\slice - - - src\core\lib\slice - src\core\lib\slice @@ -325,7 +319,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -343,9 +337,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -406,6 +397,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport @@ -824,9 +818,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -983,9 +974,6 @@ src\core\lib\slice - - src\core\lib\slice - src\core\lib\slice @@ -1025,19 +1013,13 @@ src\core\lib\surface - - src\core\lib\surface - src\core\lib\transport src\core\lib\transport - - src\core\lib\transport - - + src\core\lib\transport @@ -1055,9 +1037,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -1106,6 +1085,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport @@ -1115,6 +1097,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport diff --git a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj index 7d6685d4bf1..230c3eb3dfb 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj @@ -216,7 +216,6 @@ - @@ -269,7 +268,6 @@ - @@ -283,17 +281,14 @@ - - - + - @@ -507,10 +502,6 @@ - - - - @@ -553,7 +544,7 @@ - + @@ -565,8 +556,6 @@ - - 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 1c21ff301c2..46a38156ea7 100644 --- a/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_test_util/grpc_test_util.vcxproj.filters @@ -313,12 +313,6 @@ src\core\lib\slice - - src\core\lib\slice - - - src\core\lib\slice - src\core\lib\slice @@ -382,7 +376,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -400,9 +394,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -617,9 +608,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -776,9 +764,6 @@ src\core\lib\slice - - src\core\lib\slice - src\core\lib\slice @@ -818,19 +803,13 @@ src\core\lib\surface - - src\core\lib\surface - src\core\lib\transport src\core\lib\transport - - src\core\lib\transport - - + src\core\lib\transport @@ -848,9 +827,6 @@ src\core\lib\transport - - 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 20a47cda8c7..dcb943a3a11 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj @@ -313,7 +313,6 @@ - @@ -366,7 +365,6 @@ - @@ -380,17 +378,14 @@ - - - + - @@ -407,9 +402,11 @@ + + @@ -624,10 +621,6 @@ - - - - @@ -670,7 +663,7 @@ - + @@ -682,8 +675,6 @@ - - @@ -726,6 +717,8 @@ + + diff --git a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters index 8490ac7dfe5..ac84e0188c8 100644 --- a/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters +++ b/vsprojects/vcxproj/grpc_unsecure/grpc_unsecure.vcxproj.filters @@ -259,12 +259,6 @@ src\core\lib\slice - - src\core\lib\slice - - - src\core\lib\slice - src\core\lib\slice @@ -328,7 +322,7 @@ src\core\lib\transport - + src\core\lib\transport @@ -346,9 +340,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -412,6 +403,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport @@ -737,9 +731,6 @@ src\core\lib\iomgr - - src\core\lib\iomgr - src\core\lib\iomgr @@ -896,9 +887,6 @@ src\core\lib\slice - - src\core\lib\slice - src\core\lib\slice @@ -938,19 +926,13 @@ src\core\lib\surface - - src\core\lib\surface - src\core\lib\transport src\core\lib\transport - - src\core\lib\transport - - + src\core\lib\transport @@ -968,9 +950,6 @@ src\core\lib\transport - - src\core\lib\transport - src\core\lib\transport @@ -1019,6 +998,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport @@ -1028,6 +1010,9 @@ src\core\ext\transport\chttp2\transport + + src\core\ext\transport\chttp2\transport + src\core\ext\transport\chttp2\transport diff --git a/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj b/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj similarity index 97% rename from vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj rename to vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj index ab1e3a7a9fb..f5b8838cdf9 100644 --- a/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj +++ b/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj @@ -20,7 +20,7 @@ - {21E2A241-9D48-02CD-92E4-4EEC98424CF5} + {ABAD3D2C-078C-7850-B413-3352A07C6176} true $(SolutionDir)IntDir\$(MSBuildProjectName)\ @@ -60,14 +60,14 @@ - status_conversion_test + chttp2_status_conversion_test static Debug static Debug - status_conversion_test + chttp2_status_conversion_test static Release static @@ -158,7 +158,7 @@ - + diff --git a/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters b/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters new file mode 100644 index 00000000000..d94af50254a --- /dev/null +++ b/vsprojects/vcxproj/test/chttp2_status_conversion_test/chttp2_status_conversion_test.vcxproj.filters @@ -0,0 +1,24 @@ + + + + + test\core\transport\chttp2 + + + + + + {29690dfb-a808-84b3-d82e-deadb5d04103} + + + {d17e51ca-73ac-6f31-d02c-631ac849c194} + + + {3f03cd74-998e-23ed-a372-a1b706d35bf4} + + + {b65a9b0c-fa3d-1919-b70f-9d2d5cc28077} + + + + diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj index d8d4a76ebfb..ad6865a9344 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj @@ -181,7 +181,6 @@ - diff --git a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters index d79f2287e5c..1b367b1869b 100644 --- a/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_full/codegen_test_full.vcxproj.filters @@ -84,9 +84,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj index 595e6730fa1..9df67022403 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj @@ -181,7 +181,6 @@ - diff --git a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters index 78de9501b03..c8f62ff93ab 100644 --- a/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters +++ b/vsprojects/vcxproj/test/codegen_test_minimal/codegen_test_minimal.vcxproj.filters @@ -87,9 +87,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj index 5381be52d3f..88e4bf63f82 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj @@ -182,7 +182,6 @@ - diff --git a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters index 0526a0721bf..fece7f3ad80 100644 --- a/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters +++ b/vsprojects/vcxproj/test/grpc_tool_test/grpc_tool_test.vcxproj.filters @@ -78,9 +78,6 @@ include\grpc++\impl\codegen - - include\grpc++\impl\codegen - include\grpc++\impl\codegen diff --git a/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters b/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters deleted file mode 100644 index 72ebef552d2..00000000000 --- a/vsprojects/vcxproj/test/status_conversion_test/status_conversion_test.vcxproj.filters +++ /dev/null @@ -1,21 +0,0 @@ - - - - - test\core\transport - - - - - - {4702a9eb-d239-c799-0712-b7af210665bd} - - - {2f2eed07-7d0f-4b4a-67c0-96e860bb6b16} - - - {269c6750-9126-9b6a-4196-b7cbe492ee9f} - - - - From 289f0fed89eabf019eee4f92fc838c86d943de01 Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 20 Jan 2017 18:38:41 -0800 Subject: [PATCH 256/261] Fix cronet header memory free --- src/core/ext/transport/cronet/transport/cronet_transport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 2683abf47cd..b7c33b7b66d 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -655,8 +655,6 @@ static void convert_metadata_to_cronet_headers( headers[num_headers].key = key; headers[num_headers].value = value; num_headers++; - gpr_free(key); - gpr_free(value); if (curr == NULL) { break; } @@ -857,6 +855,11 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, s->header_array.capacity = s->header_array.count; CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, false); + int header_index; + for (header_index = 0; header_index < s->header_array.count; header_index++) { + gpr_free((void*)s->header_array.headers[header_index].key); + gpr_free((void*)s->header_array.headers[header_index].value); + } stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; result = ACTION_TAKEN_WITH_CALLBACK; } else if (stream_op->recv_initial_metadata && From e0016e2dc6fbcc090fac0a1597c06680be018e9f Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 20 Jan 2017 18:57:50 -0800 Subject: [PATCH 257/261] clang-format --- src/core/ext/transport/cronet/transport/cronet_transport.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index b7c33b7b66d..d4daf5fcb9b 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -856,9 +856,10 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, false); int header_index; - for (header_index = 0; header_index < s->header_array.count; header_index++) { - gpr_free((void*)s->header_array.headers[header_index].key); - gpr_free((void*)s->header_array.headers[header_index].value); + for (header_index = 0; header_index < s->header_array.count; + header_index++) { + gpr_free((void *)s->header_array.headers[header_index].key); + gpr_free((void *)s->header_array.headers[header_index].value); } stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; result = ACTION_TAKEN_WITH_CALLBACK; From 607413f62315363ecc2452bedb7e840cb4e3f2dc Mon Sep 17 00:00:00 2001 From: Muxi Yan Date: Fri, 20 Jan 2017 20:45:19 -0800 Subject: [PATCH 258/261] fix the test error --- src/core/ext/transport/cronet/transport/cronet_transport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index d4daf5fcb9b..02e5a4a3d27 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -855,7 +855,7 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, s->header_array.capacity = s->header_array.count; CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, false); - int header_index; + unsigned int header_index; for (header_index = 0; header_index < s->header_array.count; header_index++) { gpr_free((void *)s->header_array.headers[header_index].key); From 2e36be09af75e69b363da783a8df181b4a446699 Mon Sep 17 00:00:00 2001 From: "David G. Quintas" Date: Mon, 23 Jan 2017 09:24:11 -0800 Subject: [PATCH 259/261] Revert "Fix cronet header memory free" --- .../ext/transport/cronet/transport/cronet_transport.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/core/ext/transport/cronet/transport/cronet_transport.c b/src/core/ext/transport/cronet/transport/cronet_transport.c index 419bfb7b7db..025ae30df2e 100644 --- a/src/core/ext/transport/cronet/transport/cronet_transport.c +++ b/src/core/ext/transport/cronet/transport/cronet_transport.c @@ -655,6 +655,8 @@ static void convert_metadata_to_cronet_headers( headers[num_headers].key = key; headers[num_headers].value = value; num_headers++; + gpr_free(key); + gpr_free(value); if (curr == NULL) { break; } @@ -855,12 +857,6 @@ static enum e_op_result execute_stream_op(grpc_exec_ctx *exec_ctx, s->header_array.capacity = s->header_array.count; CRONET_LOG(GPR_DEBUG, "bidirectional_stream_start(%p, %s)", s->cbs, url); bidirectional_stream_start(s->cbs, url, 0, method, &s->header_array, false); - unsigned int header_index; - for (header_index = 0; header_index < s->header_array.count; - header_index++) { - gpr_free((void *)s->header_array.headers[header_index].key); - gpr_free((void *)s->header_array.headers[header_index].value); - } stream_state->state_op_done[OP_SEND_INITIAL_METADATA] = true; result = ACTION_TAKEN_WITH_CALLBACK; } else if (stream_op->recv_initial_metadata && From 0b1bb2d418d5782c8e527d2f2034dee9143b0bfb Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Thu, 15 Dec 2016 11:16:50 -0800 Subject: [PATCH 260/261] Don't leak Py exceptions without calling gRPC core --- .../grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi index 04872b9c09a..4d988192df3 100644 --- a/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi +++ b/src/python/grpcio/grpc/_cython/_cygrpc/credentials.pyx.pxi @@ -29,6 +29,8 @@ cimport cpython +import traceback + cdef class ChannelCredentials: @@ -138,15 +140,22 @@ cdef class AuthMetadataContext: cdef void plugin_get_metadata( void *state, grpc_auth_metadata_context context, grpc_credentials_plugin_metadata_cb cb, void *user_data) with gil: + called_flag = [False] def python_callback( Metadata metadata, grpc_status_code status, bytes error_details): cb(user_data, metadata.c_metadata_array.metadata, metadata.c_metadata_array.count, status, error_details) + called_flag[0] = True cdef CredentialsMetadataPlugin self = state cdef AuthMetadataContext cy_context = AuthMetadataContext() cy_context.context = context - self.plugin_callback(cy_context, python_callback) + try: + self.plugin_callback(cy_context, python_callback) + except Exception as error: + if not called_flag[0]: + cb(user_data, Metadata([]).c_metadata_array.metadata, + 0, StatusCode.unknown, traceback.format_exc().encode()) cdef void plugin_destroy_c_plugin_state(void *state) with gil: cpython.Py_DECREF(state) From 6b890d1dd350789a28a3fbedb4a929156e88a3b1 Mon Sep 17 00:00:00 2001 From: Masood Malekghassemi Date: Mon, 23 Jan 2017 12:02:08 -0500 Subject: [PATCH 261/261] Run yapf over Python code --- src/python/grpcio/commands.py | 12 ++++++------ src/python/grpcio/grpc/_channel.py | 4 ++-- src/python/grpcio_tests/commands.py | 4 ++-- src/python/grpcio_tests/tests/_loader.py | 4 ++-- src/python/grpcio_tests/tests/_runner.py | 4 ++-- src/python/grpcio_tests/tests/interop/methods.py | 15 +++++++-------- .../grpcio_tests/tests/qps/worker_server.py | 8 ++++---- .../tests/unit/_cython/cygrpc_test.py | 4 ++-- .../tests/unit/_empty_message_test.py | 8 ++++---- 9 files changed, 31 insertions(+), 32 deletions(-) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index e09f9225912..d813df5f448 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -271,12 +271,12 @@ class BuildExt(build_ext.build_ext): compiler = self.compiler.compiler_type if compiler in BuildExt.C_OPTIONS: for extension in self.extensions: - extension.extra_compile_args += list(BuildExt.C_OPTIONS[ - compiler]) + extension.extra_compile_args += list( + BuildExt.C_OPTIONS[compiler]) if compiler in BuildExt.LINK_OPTIONS: for extension in self.extensions: - extension.extra_link_args += list(BuildExt.LINK_OPTIONS[ - compiler]) + extension.extra_link_args += list( + BuildExt.LINK_OPTIONS[compiler]) if not check_and_update_cythonization(self.extensions): self.extensions = try_cythonize(self.extensions) try: @@ -284,8 +284,8 @@ class BuildExt(build_ext.build_ext): except Exception as error: formatted_exception = traceback.format_exc() support.diagnose_build_ext_error(self, error, formatted_exception) - raise CommandError("Failed `build_ext` step:\n{}".format( - formatted_exception)) + raise CommandError( + "Failed `build_ext` step:\n{}".format(formatted_exception)) class Gather(setuptools.Command): diff --git a/src/python/grpcio/grpc/_channel.py b/src/python/grpcio/grpc/_channel.py index 77412236cc6..5a8a3d487ae 100644 --- a/src/python/grpcio/grpc/_channel.py +++ b/src/python/grpcio/grpc/_channel.py @@ -842,8 +842,8 @@ def _poll_connectivity(state, channel, initial_try_to_connect): connectivity = channel.check_connectivity_state(try_to_connect) with state.lock: state.connectivity = ( - _common.CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[ - connectivity]) + _common. + CYGRPC_CONNECTIVITY_STATE_TO_CHANNEL_CONNECTIVITY[connectivity]) callbacks = tuple(callback for callback, unused_but_known_to_be_none_connectivity in state.callbacks_and_connectivities) diff --git a/src/python/grpcio_tests/commands.py b/src/python/grpcio_tests/commands.py index 845b7f598c0..af0ffe34750 100644 --- a/src/python/grpcio_tests/commands.py +++ b/src/python/grpcio_tests/commands.py @@ -121,8 +121,8 @@ class BuildProtoModules(setuptools.Command): '--grpc_python_out={}'.format(PROTO_STEM), ] + [path] if protoc.main(command) != 0: - sys.stderr.write('warning: Command:\n{}\nFailed'.format( - command)) + sys.stderr.write( + 'warning: Command:\n{}\nFailed'.format(command)) # Generated proto directories dont include __init__.py, but # these are needed for python package resolution diff --git a/src/python/grpcio_tests/tests/_loader.py b/src/python/grpcio_tests/tests/_loader.py index 42cf9ab4cac..165bc53fb7b 100644 --- a/src/python/grpcio_tests/tests/_loader.py +++ b/src/python/grpcio_tests/tests/_loader.py @@ -116,5 +116,5 @@ def iterate_suite_cases(suite): elif isinstance(item, unittest.TestCase): yield item else: - raise ValueError('unexpected suite item of type {}'.format( - type(item))) + raise ValueError( + 'unexpected suite item of type {}'.format(type(item))) diff --git a/src/python/grpcio_tests/tests/_runner.py b/src/python/grpcio_tests/tests/_runner.py index 59964b271c7..1138a2279da 100644 --- a/src/python/grpcio_tests/tests/_runner.py +++ b/src/python/grpcio_tests/tests/_runner.py @@ -196,8 +196,8 @@ class Runner(object): # Run the tests result.startTestRun() for augmented_case in augmented_cases: - sys.stdout.write('Running {}\n'.format(augmented_case.case.id( - ))) + sys.stdout.write( + 'Running {}\n'.format(augmented_case.case.id())) sys.stdout.flush() case_thread = threading.Thread( target=augmented_case.case.run, args=(result,)) diff --git a/src/python/grpcio_tests/tests/interop/methods.py b/src/python/grpcio_tests/tests/interop/methods.py index e1f87221686..bdb258591e7 100644 --- a/src/python/grpcio_tests/tests/interop/methods.py +++ b/src/python/grpcio_tests/tests/interop/methods.py @@ -428,8 +428,8 @@ def _compute_engine_creds(stub, args): def _oauth2_auth_token(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + json_key_filename = os.environ[oauth2client_client. + GOOGLE_APPLICATION_CREDENTIALS] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] response = _large_unary_common_behavior(stub, True, True, None) if wanted_email != response.username: @@ -441,8 +441,8 @@ def _oauth2_auth_token(stub, args): def _jwt_token_creds(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + json_key_filename = os.environ[oauth2client_client. + GOOGLE_APPLICATION_CREDENTIALS] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] response = _large_unary_common_behavior(stub, True, False, None) if wanted_email != response.username: @@ -451,11 +451,10 @@ def _jwt_token_creds(stub, args): def _per_rpc_creds(stub, args): - json_key_filename = os.environ[ - oauth2client_client.GOOGLE_APPLICATION_CREDENTIALS] + json_key_filename = os.environ[oauth2client_client. + GOOGLE_APPLICATION_CREDENTIALS] wanted_email = json.load(open(json_key_filename, 'rb'))['client_email'] - credentials = oauth2client_client.GoogleCredentials.get_application_default( - ) + credentials = oauth2client_client.GoogleCredentials.get_application_default() scoped_credentials = credentials.create_scoped([args.oauth_scope]) # TODO(https://github.com/grpc/grpc/issues/6799): Eliminate this last # remaining use of the Beta API. diff --git a/src/python/grpcio_tests/tests/qps/worker_server.py b/src/python/grpcio_tests/tests/qps/worker_server.py index 1deb7ed698c..ca1a777611c 100644 --- a/src/python/grpcio_tests/tests/qps/worker_server.py +++ b/src/python/grpcio_tests/tests/qps/worker_server.py @@ -102,8 +102,8 @@ class WorkerServer(services_pb2.WorkerServiceServicer): 'grpc.testing.BenchmarkService', method_implementations) server.add_generic_rpc_handlers((handler,)) else: - raise Exception('Unsupported server type {}'.format( - config.server_type)) + raise Exception( + 'Unsupported server type {}'.format(config.server_type)) if config.HasField('security_params'): # Use SSL server_creds = grpc.ssl_server_credentials(( @@ -171,8 +171,8 @@ class WorkerServer(services_pb2.WorkerServiceServicer): else: raise Exception('Async streaming client not supported') else: - raise Exception('Unsupported client type {}'.format( - config.client_type)) + raise Exception( + 'Unsupported client type {}'.format(config.client_type)) # In multi-channel tests, we split the load across all channels load_factor = float(config.client_channels) diff --git a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py index 7aec316b95d..6377164f0cb 100644 --- a/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py +++ b/src/python/grpcio_tests/tests/unit/_cython/cygrpc_test.py @@ -204,8 +204,8 @@ class ServerClientMixin(object): self.assertTrue(event.success) self.assertIs(tag, event.tag) except Exception as error: - raise Exception("Error in '{}': {}".format(description, - error.message)) + raise Exception( + "Error in '{}': {}".format(description, error.message)) return event return test_utilities.SimpleFuture(performer) diff --git a/src/python/grpcio_tests/tests/unit/_empty_message_test.py b/src/python/grpcio_tests/tests/unit/_empty_message_test.py index 4588688ea60..155173807ff 100644 --- a/src/python/grpcio_tests/tests/unit/_empty_message_test.py +++ b/src/python/grpcio_tests/tests/unit/_empty_message_test.py @@ -122,13 +122,13 @@ class EmptyMessageTest(unittest.TestCase): list(response_iterator)) def testStreamUnary(self): - response = self._channel.stream_unary(_STREAM_UNARY)(iter( - [_REQUEST] * test_constants.STREAM_LENGTH)) + response = self._channel.stream_unary(_STREAM_UNARY)( + iter([_REQUEST] * test_constants.STREAM_LENGTH)) self.assertEqual(_RESPONSE, response) def testStreamStream(self): - response_iterator = self._channel.stream_stream(_STREAM_STREAM)(iter( - [_REQUEST] * test_constants.STREAM_LENGTH)) + response_iterator = self._channel.stream_stream(_STREAM_STREAM)( + iter([_REQUEST] * test_constants.STREAM_LENGTH)) self.assertSequenceEqual([_RESPONSE] * test_constants.STREAM_LENGTH, list(response_iterator))