From 67e6b03e92626bc8c8f236b90bfa676ae7eadbc4 Mon Sep 17 00:00:00 2001 From: Juanli Shen Date: Wed, 19 Jun 2019 11:34:01 -0700 Subject: [PATCH] Fix compression algorithm parsing --- .../message_compress_filter.cc | 254 ++++++++---------- src/core/lib/compression/compression.cc | 3 +- src/core/lib/compression/compression_args.cc | 19 +- src/core/lib/compression/compression_args.h | 5 +- .../lib/compression/compression_internal.cc | 2 +- src/core/lib/surface/call.cc | 11 +- test/core/compression/algorithm_test.cc | 15 +- test/core/compression/compression_test.cc | 4 +- test/core/end2end/fixtures/h2_compress.cc | 10 +- test/core/end2end/tests/compressed_payload.cc | 10 +- .../stream_compression_compressed_payload.cc | 12 +- .../tests/stream_compression_payload.cc | 10 +- .../stream_compression_ping_pong_streaming.cc | 10 +- .../tests/workaround_cronet_compression.cc | 4 +- 14 files changed, 178 insertions(+), 191 deletions(-) diff --git a/src/core/ext/filters/http/message_compress/message_compress_filter.cc b/src/core/ext/filters/http/message_compress/message_compress_filter.cc index d2b1f6794cd..3ce79b305df 100644 --- a/src/core/ext/filters/http/message_compress/message_compress_filter.cc +++ b/src/core/ext/filters/http/message_compress/message_compress_filter.cc @@ -45,18 +45,30 @@ static void send_message_on_complete(void* arg, grpc_error* error); static void on_send_message_next_done(void* arg, grpc_error* error); namespace { -enum initial_metadata_state { - // Initial metadata not yet seen. - INITIAL_METADATA_UNSEEN = 0, - // Initial metadata seen; compression algorithm set. - HAS_COMPRESSION_ALGORITHM, - // Initial metadata seen; no compression algorithm set. - NO_COMPRESSION_ALGORITHM, + +struct channel_data { + /** The default, channel-level, compression algorithm */ + grpc_compression_algorithm default_compression_algorithm; + /** Bitset of enabled compression algorithms */ + uint32_t enabled_compression_algorithms_bitset; + /** Bitset of enabled message compression algorithms */ + uint32_t enabled_message_compression_algorithms_bitset; + /** Bitset of enabled stream compression algorithms */ + uint32_t enabled_stream_compression_algorithms_bitset; }; struct call_data { call_data(grpc_call_element* elem, const grpc_call_element_args& args) : call_combiner(args.call_combiner) { + channel_data* channeld = static_cast(elem->channel_data); + // The call's message compression algorithm is set to channel's default + // setting. It can be overridden later by initial metadata. + if (GPR_LIKELY(GPR_BITGET(channeld->enabled_compression_algorithms_bitset, + channeld->default_compression_algorithm))) { + message_compression_algorithm = + grpc_compression_algorithm_to_message_compression_algorithm( + channeld->default_compression_algorithm); + } GRPC_CLOSURE_INIT(&start_send_message_batch_in_call_combiner, start_send_message_batch, elem, grpc_schedule_on_exec_ctx); @@ -73,15 +85,13 @@ struct call_data { } grpc_core::CallCombiner* call_combiner; - grpc_linked_mdelem compression_algorithm_storage; + grpc_linked_mdelem message_compression_algorithm_storage; grpc_linked_mdelem stream_compression_algorithm_storage; grpc_linked_mdelem accept_encoding_storage; grpc_linked_mdelem accept_stream_encoding_storage; - /** Compression algorithm we'll try to use. It may be given by incoming - * metadata, or by the channel's default compression settings. */ grpc_message_compression_algorithm message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; - initial_metadata_state send_initial_metadata_state = INITIAL_METADATA_UNSEEN; + bool seen_initial_metadata = false; grpc_error* cancel_error = GRPC_ERROR_NONE; grpc_closure start_send_message_batch_in_call_combiner; grpc_transport_stream_op_batch* send_message_batch = nullptr; @@ -93,130 +103,104 @@ struct call_data { grpc_closure on_send_message_next_done; }; -struct channel_data { - /** The default, channel-level, compression algorithm */ - grpc_compression_algorithm default_compression_algorithm; - /** Bitset of enabled compression algorithms */ - uint32_t enabled_algorithms_bitset; - /** Supported compression algorithms */ - uint32_t supported_message_compression_algorithms; - /** Supported stream compression algorithms */ - uint32_t supported_stream_compression_algorithms; -}; } // namespace -static bool skip_compression(grpc_call_element* elem, uint32_t flags, - bool has_compression_algorithm) { +// Returns true if we should skip message compression for the current message. +static bool skip_message_compression(grpc_call_element* elem) { call_data* calld = static_cast(elem->call_data); - channel_data* channeld = static_cast(elem->channel_data); - + // If the flags of this message indicate that it shouldn't be compressed, we + // skip message compression. + uint32_t flags = + calld->send_message_batch->payload->send_message.send_message->flags(); if (flags & (GRPC_WRITE_NO_COMPRESS | GRPC_WRITE_INTERNAL_COMPRESS)) { return true; } - if (has_compression_algorithm) { - if (calld->message_compression_algorithm == GRPC_MESSAGE_COMPRESS_NONE) { - return true; - } - return false; /* we have an actual call-specific algorithm */ + // If this call doesn't have any message compression algorithm set, skip + // message compression. + return calld->message_compression_algorithm == GRPC_MESSAGE_COMPRESS_NONE; +} + +// Determines the compression algorithm from the initial metadata and the +// channel's default setting. +static grpc_compression_algorithm find_compression_algorithm( + grpc_metadata_batch* initial_metadata, channel_data* channeld) { + if (initial_metadata->idx.named.grpc_internal_encoding_request == nullptr) { + return channeld->default_compression_algorithm; } - /* no per-call compression override */ - return channeld->default_compression_algorithm == GRPC_COMPRESS_NONE; + grpc_compression_algorithm compression_algorithm; + // Parse the compression algorithm from the initial metadata. + grpc_mdelem md = + initial_metadata->idx.named.grpc_internal_encoding_request->md; + GPR_ASSERT(grpc_compression_algorithm_parse(GRPC_MDVALUE(md), + &compression_algorithm)); + // Remove this metadata since it's an internal one (i.e., it won't be + // transmitted out). + grpc_metadata_batch_remove( + initial_metadata, + initial_metadata->idx.named.grpc_internal_encoding_request); + // Check if that algorithm is enabled. Note that GRPC_COMPRESS_NONE is always + // enabled. + // TODO(juanlishen): Maybe use channel default or abort() if the algorithm + // from the initial metadata is disabled. + if (GPR_LIKELY(GPR_BITGET(channeld->enabled_compression_algorithms_bitset, + compression_algorithm))) { + return compression_algorithm; + } + const char* algorithm_name; + GPR_ASSERT( + grpc_compression_algorithm_name(compression_algorithm, &algorithm_name)); + gpr_log(GPR_ERROR, + "Invalid compression algorithm from initial metadata: '%s' " + "(previously disabled). " + "Will not compress.", + algorithm_name); + return GRPC_COMPRESS_NONE; } -/** Filter initial metadata */ static grpc_error* process_send_initial_metadata( - grpc_call_element* elem, grpc_metadata_batch* initial_metadata, - bool* has_compression_algorithm) GRPC_MUST_USE_RESULT; + grpc_call_element* elem, + grpc_metadata_batch* initial_metadata) GRPC_MUST_USE_RESULT; static grpc_error* process_send_initial_metadata( - grpc_call_element* elem, grpc_metadata_batch* initial_metadata, - bool* has_compression_algorithm) { + grpc_call_element* elem, grpc_metadata_batch* initial_metadata) { call_data* calld = static_cast(elem->call_data); channel_data* channeld = static_cast(elem->channel_data); - *has_compression_algorithm = false; - grpc_compression_algorithm compression_algorithm; + // Find the compression algorithm. + grpc_compression_algorithm compression_algorithm = + find_compression_algorithm(initial_metadata, channeld); + // Note that at most one of the following algorithms can be set. + calld->message_compression_algorithm = + grpc_compression_algorithm_to_message_compression_algorithm( + compression_algorithm); grpc_stream_compression_algorithm stream_compression_algorithm = - GRPC_STREAM_COMPRESS_NONE; - if (initial_metadata->idx.named.grpc_internal_encoding_request != nullptr) { - grpc_mdelem md = - initial_metadata->idx.named.grpc_internal_encoding_request->md; - if (GPR_UNLIKELY(!grpc_compression_algorithm_parse( - GRPC_MDVALUE(md), &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->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; - stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; - } - if (GPR_UNLIKELY(!GPR_BITGET(channeld->enabled_algorithms_bitset, - 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->message_compression_algorithm = GRPC_MESSAGE_COMPRESS_NONE; - stream_compression_algorithm = GRPC_STREAM_COMPRESS_NONE; - } - *has_compression_algorithm = true; - grpc_metadata_batch_remove( - initial_metadata, - initial_metadata->idx.named.grpc_internal_encoding_request); - calld->message_compression_algorithm = - grpc_compression_algorithm_to_message_compression_algorithm( - compression_algorithm); - stream_compression_algorithm = - grpc_compression_algorithm_to_stream_compression_algorithm( - compression_algorithm); - } else { - /* If no algorithm was found in the metadata and we aren't - * exceptionally skipping compression, fall back to the channel - * default */ - if (channeld->default_compression_algorithm != GRPC_COMPRESS_NONE) { - calld->message_compression_algorithm = - grpc_compression_algorithm_to_message_compression_algorithm( - channeld->default_compression_algorithm); - stream_compression_algorithm = - grpc_compression_algorithm_to_stream_compression_algorithm( - channeld->default_compression_algorithm); - } - *has_compression_algorithm = true; - } - + grpc_compression_algorithm_to_stream_compression_algorithm( + compression_algorithm); + // Hint compression algorithm. grpc_error* error = GRPC_ERROR_NONE; - /* hint compression algorithm */ - if (stream_compression_algorithm != GRPC_STREAM_COMPRESS_NONE) { + if (calld->message_compression_algorithm != GRPC_MESSAGE_COMPRESS_NONE) { error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->stream_compression_algorithm_storage, - grpc_stream_compression_encoding_mdelem(stream_compression_algorithm)); - } else if (calld->message_compression_algorithm != - GRPC_MESSAGE_COMPRESS_NONE) { - error = grpc_metadata_batch_add_tail( - initial_metadata, &calld->compression_algorithm_storage, + initial_metadata, &calld->message_compression_algorithm_storage, grpc_message_compression_encoding_mdelem( calld->message_compression_algorithm)); + } else if (stream_compression_algorithm != GRPC_STREAM_COMPRESS_NONE) { + error = grpc_metadata_batch_add_tail( + initial_metadata, &calld->stream_compression_algorithm_storage, + grpc_stream_compression_encoding_mdelem(stream_compression_algorithm)); } - if (error != GRPC_ERROR_NONE) return error; - - /* convey supported compression algorithms */ + // Convey supported compression algorithms. error = grpc_metadata_batch_add_tail( initial_metadata, &calld->accept_encoding_storage, GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS( - channeld->supported_message_compression_algorithms)); - + channeld->enabled_message_compression_algorithms_bitset)); if (error != GRPC_ERROR_NONE) return error; - - /* Do not overwrite accept-encoding header if it already presents (e.g. added - * by some proxy). */ + // Do not overwrite accept-encoding header if it already presents (e.g., added + // by some proxy). if (!initial_metadata->idx.named.accept_encoding) { error = grpc_metadata_batch_add_tail( initial_metadata, &calld->accept_stream_encoding_storage, GRPC_MDELEM_ACCEPT_STREAM_ENCODING_FOR_ALGORITHMS( - channeld->supported_stream_compression_algorithms)); + channeld->enabled_stream_compression_algorithms_bitset)); } - return error; } @@ -358,12 +342,7 @@ static void on_send_message_next_done(void* arg, grpc_error* error) { static void start_send_message_batch(void* arg, grpc_error* unused) { grpc_call_element* elem = static_cast(arg); - call_data* calld = static_cast(elem->call_data); - if (skip_compression( - elem, - calld->send_message_batch->payload->send_message.send_message - ->flags(), - calld->send_initial_metadata_state == HAS_COMPRESSION_ALGORITHM)) { + if (skip_message_compression(elem)) { send_message_batch_continue(elem); } else { continue_reading_send_message(elem); @@ -380,7 +359,7 @@ static void compress_start_transport_stream_op_batch( calld->cancel_error = GRPC_ERROR_REF(batch->payload->cancel_stream.cancel_error); if (calld->send_message_batch != nullptr) { - if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { + if (!calld->seen_initial_metadata) { GRPC_CALL_COMBINER_START( calld->call_combiner, GRPC_CLOSURE_CREATE(fail_send_message_batch_in_call_combiner, calld, @@ -398,19 +377,15 @@ static void compress_start_transport_stream_op_batch( } // Handle send_initial_metadata. if (batch->send_initial_metadata) { - GPR_ASSERT(calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN); - bool has_compression_algorithm; + GPR_ASSERT(!calld->seen_initial_metadata); grpc_error* error = process_send_initial_metadata( - elem, batch->payload->send_initial_metadata.send_initial_metadata, - &has_compression_algorithm); + elem, batch->payload->send_initial_metadata.send_initial_metadata); if (error != GRPC_ERROR_NONE) { grpc_transport_stream_op_batch_finish_with_failure(batch, error, calld->call_combiner); return; } - calld->send_initial_metadata_state = has_compression_algorithm - ? HAS_COMPRESSION_ALGORITHM - : NO_COMPRESSION_ALGORITHM; + calld->seen_initial_metadata = true; // If we had previously received a batch containing a send_message op, // handle it now. Note that we need to re-enter the call combiner // for this, since we can't send two batches down while holding the @@ -431,7 +406,7 @@ static void compress_start_transport_stream_op_batch( // wait. We save the batch in calld and then drop the call // combiner, which we'll have to pick up again later when we get // send_initial_metadata. - if (calld->send_initial_metadata_state == INITIAL_METADATA_UNSEEN) { + if (!calld->seen_initial_metadata) { GRPC_CALL_COMBINER_STOP( calld->call_combiner, "send_message batch pending send_initial_metadata"); @@ -463,34 +438,29 @@ static void destroy_call_elem(grpc_call_element* elem, static grpc_error* init_channel_elem(grpc_channel_element* elem, grpc_channel_element_args* args) { channel_data* channeld = static_cast(elem->channel_data); - - channeld->enabled_algorithms_bitset = + // Get the enabled and the default algorithms from channel args. + channeld->enabled_compression_algorithms_bitset = grpc_channel_args_compression_algorithm_get_states(args->channel_args); channeld->default_compression_algorithm = - grpc_channel_args_get_compression_algorithm(args->channel_args); - - /* Make sure the default isn't disabled. */ - if (!GPR_BITGET(channeld->enabled_algorithms_bitset, + grpc_channel_args_get_channel_default_compression_algorithm( + args->channel_args); + // Make sure the default is enabled. + if (!GPR_BITGET(channeld->enabled_compression_algorithms_bitset, channeld->default_compression_algorithm)) { - gpr_log(GPR_DEBUG, - "compression algorithm %d not enabled: switching to none", - channeld->default_compression_algorithm); + const char* name; + GPR_ASSERT(grpc_compression_algorithm_name( + channeld->default_compression_algorithm, &name) == 1); + gpr_log(GPR_ERROR, + "default compression algorithm %s not enabled: switching to none", + name); channeld->default_compression_algorithm = GRPC_COMPRESS_NONE; } - - uint32_t supported_compression_algorithms = - (((1u << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1) & - channeld->enabled_algorithms_bitset) | - 1u; - - channeld->supported_message_compression_algorithms = + channeld->enabled_message_compression_algorithms_bitset = grpc_compression_bitset_to_message_bitset( - supported_compression_algorithms); - - channeld->supported_stream_compression_algorithms = + channeld->enabled_compression_algorithms_bitset); + channeld->enabled_stream_compression_algorithms_bitset = grpc_compression_bitset_to_stream_bitset( - supported_compression_algorithms); - + channeld->enabled_compression_algorithms_bitset); GPR_ASSERT(!args->is_last); return GRPC_ERROR_NONE; } diff --git a/src/core/lib/compression/compression.cc b/src/core/lib/compression/compression.cc index a3a069d9266..2f35e5fa03f 100644 --- a/src/core/lib/compression/compression.cc +++ b/src/core/lib/compression/compression.cc @@ -59,12 +59,11 @@ int grpc_compression_algorithm_parse(grpc_slice name, } else { return 0; } - return 0; } int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm, const char** name) { - GRPC_API_TRACE("grpc_compression_algorithm_parse(algorithm=%d, name=%p)", 2, + GRPC_API_TRACE("grpc_compression_algorithm_name(algorithm=%d, name=%p)", 2, ((int)algorithm, name)); switch (algorithm) { case GRPC_COMPRESS_NONE: diff --git a/src/core/lib/compression/compression_args.cc b/src/core/lib/compression/compression_args.cc index 6a8232dc033..6bbda64e263 100644 --- a/src/core/lib/compression/compression_args.cc +++ b/src/core/lib/compression/compression_args.cc @@ -32,21 +32,25 @@ #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" -grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( +grpc_compression_algorithm +grpc_channel_args_get_channel_default_compression_algorithm( const grpc_channel_args* a) { size_t i; if (a == nullptr) return GRPC_COMPRESS_NONE; for (i = 0; i < a->num_args; ++i) { if (a->args[i].type == GRPC_ARG_INTEGER && !strcmp(GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM, a->args[i].key)) { - return static_cast(a->args[i].value.integer); - break; + grpc_compression_algorithm default_algorithm = + static_cast(a->args[i].value.integer); + return default_algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT + ? default_algorithm + : GRPC_COMPRESS_NONE; } } return GRPC_COMPRESS_NONE; } -grpc_channel_args* grpc_channel_args_set_compression_algorithm( +grpc_channel_args* grpc_channel_args_set_channel_default_compression_algorithm( grpc_channel_args* a, grpc_compression_algorithm algorithm) { GPR_ASSERT(algorithm < GRPC_COMPRESS_ALGORITHMS_COUNT); grpc_arg tmp; @@ -68,7 +72,9 @@ static int find_compression_algorithm_states_bitset(const grpc_channel_args* a, !strcmp(GRPC_COMPRESSION_CHANNEL_ENABLED_ALGORITHMS_BITSET, a->args[i].key)) { *states_arg = &a->args[i].value.integer; - **states_arg |= 0x1; /* forcefully enable support for no compression */ + **states_arg = + (**states_arg & ((1 << GRPC_COMPRESS_ALGORITHMS_COUNT) - 1)) | + 0x1; /* forcefully enable support for no compression */ return 1; } } @@ -83,7 +89,8 @@ grpc_channel_args* grpc_channel_args_compression_algorithm_set_state( const int states_arg_found = find_compression_algorithm_states_bitset(*a, &states_arg); - if (grpc_channel_args_get_compression_algorithm(*a) == algorithm && + if (grpc_channel_args_get_channel_default_compression_algorithm(*a) == + algorithm && state == 0) { const char* algo_name = nullptr; GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name) != 0); diff --git a/src/core/lib/compression/compression_args.h b/src/core/lib/compression/compression_args.h index 407d6e2b8ca..f1abc122cea 100644 --- a/src/core/lib/compression/compression_args.h +++ b/src/core/lib/compression/compression_args.h @@ -25,13 +25,14 @@ #include /** Returns the compression algorithm set in \a a. */ -grpc_compression_algorithm grpc_channel_args_get_compression_algorithm( +grpc_compression_algorithm +grpc_channel_args_get_channel_default_compression_algorithm( const grpc_channel_args* a); /** Returns a channel arg instance with compression enabled. If \a a is * non-NULL, its args are copied. N.B. GRPC_COMPRESS_NONE disables compression * for the channel. */ -grpc_channel_args* grpc_channel_args_set_compression_algorithm( +grpc_channel_args* grpc_channel_args_set_channel_default_compression_algorithm( grpc_channel_args* a, grpc_compression_algorithm algorithm); /** Sets the support for the given compression algorithm. By default, all diff --git a/src/core/lib/compression/compression_internal.cc b/src/core/lib/compression/compression_internal.cc index e0d73ef6d83..e0cf6d45194 100644 --- a/src/core/lib/compression/compression_internal.cc +++ b/src/core/lib/compression/compression_internal.cc @@ -171,7 +171,7 @@ int grpc_compression_algorithm_from_message_stream_compression_algorithm( int grpc_message_compression_algorithm_name( grpc_message_compression_algorithm algorithm, const char** name) { GRPC_API_TRACE( - "grpc_message_compression_algorithm_parse(algorithm=%d, name=%p)", 2, + "grpc_message_compression_algorithm_name(algorithm=%d, name=%p)", 2, ((int)algorithm, name)); switch (algorithm) { case GRPC_MESSAGE_COMPRESS_NONE: diff --git a/src/core/lib/surface/call.cc b/src/core/lib/surface/call.cc index 2ccd3355594..13b1d126393 100644 --- a/src/core/lib/surface/call.cc +++ b/src/core/lib/surface/call.cc @@ -1568,6 +1568,10 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, error = GRPC_CALL_ERROR_TOO_MANY_OPERATIONS; goto done_with_error; } + // TODO(juanlishen): If the user has already specified a compression + // algorithm by setting the initial metadata with key of + // GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY, we shouldn't override that + // with the compression algorithm mapped from compression level. /* process compression level */ grpc_metadata& compression_md = call->compression_md; compression_md.key = grpc_empty_slice(); @@ -1589,17 +1593,18 @@ static grpc_call_error call_start_batch(grpc_call* call, const grpc_op* ops, effective_compression_level = copts.default_level.level; } } + // Currently, only server side supports compression level setting. if (level_set && !call->is_client) { const grpc_compression_algorithm calgo = compression_algorithm_for_level_locked( call, effective_compression_level); - /* the following will be picked up by the compress filter and used - * as the call's compression algorithm. */ + // The following metadata will be checked and removed by the message + // compression filter. It will be used as the call's compression + // algorithm. compression_md.key = GRPC_MDSTR_GRPC_INTERNAL_ENCODING_REQUEST; compression_md.value = grpc_compression_algorithm_slice(calgo); additional_metadata_count++; } - if (op->data.send_initial_metadata.count + additional_metadata_count > INT_MAX) { error = GRPC_CALL_ERROR_INVALID_METADATA; diff --git a/test/core/compression/algorithm_test.cc b/test/core/compression/algorithm_test.cc index 24fe83774b8..c32820f08f4 100644 --- a/test/core/compression/algorithm_test.cc +++ b/test/core/compression/algorithm_test.cc @@ -80,20 +80,20 @@ static void test_algorithm_mesh(void) { } static void test_algorithm_failure(void) { - grpc_core::ExecCtx exec_ctx; - grpc_slice mdstr; - gpr_log(GPR_DEBUG, "test_algorithm_failure"); - + // Test invalid algorithm name + grpc_slice mdstr = + grpc_slice_from_static_string("this-is-an-invalid-algorithm"); + GPR_ASSERT(grpc_compression_algorithm_from_slice(mdstr) == + GRPC_COMPRESS_ALGORITHMS_COUNT); + grpc_slice_unref_internal(mdstr); + // Test invalid algorithm enum entry. GPR_ASSERT(grpc_compression_algorithm_name(GRPC_COMPRESS_ALGORITHMS_COUNT, nullptr) == 0); GPR_ASSERT( grpc_compression_algorithm_name(static_cast( GRPC_COMPRESS_ALGORITHMS_COUNT + 1), nullptr) == 0); - 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_slice_eq( grpc_compression_algorithm_slice(GRPC_COMPRESS_ALGORITHMS_COUNT), grpc_empty_slice())); @@ -101,7 +101,6 @@ static void test_algorithm_failure(void) { grpc_compression_algorithm_slice(static_cast( static_cast(GRPC_COMPRESS_ALGORITHMS_COUNT) + 1)), grpc_empty_slice())); - grpc_slice_unref_internal(mdstr); } int main(int argc, char** argv) { diff --git a/test/core/compression/compression_test.cc b/test/core/compression/compression_test.cc index cf6d18847e6..aa54241135c 100644 --- a/test/core/compression/compression_test.cc +++ b/test/core/compression/compression_test.cc @@ -265,8 +265,8 @@ static void test_channel_args_set_compression_algorithm(void) { grpc_core::ExecCtx exec_ctx; grpc_channel_args* ch_args; - ch_args = - grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_GZIP); + ch_args = grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_GZIP); GPR_ASSERT(ch_args->num_args == 1); GPR_ASSERT(strcmp(ch_args->args[0].key, GRPC_COMPRESSION_CHANNEL_DEFAULT_ALGORITHM) == 0); diff --git a/test/core/end2end/fixtures/h2_compress.cc b/test/core/end2end/fixtures/h2_compress.cc index f97192fecaa..01e5ae1b7b5 100644 --- a/test/core/end2end/fixtures/h2_compress.cc +++ b/test/core/end2end/fixtures/h2_compress.cc @@ -69,8 +69,9 @@ void chttp2_init_client_fullstack_compression(grpc_end2end_test_fixture* f, grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(ffd->client_args_compression); } - ffd->client_args_compression = grpc_channel_args_set_compression_algorithm( - client_args, GRPC_COMPRESS_GZIP); + ffd->client_args_compression = + grpc_channel_args_set_channel_default_compression_algorithm( + client_args, GRPC_COMPRESS_GZIP); f->client = grpc_insecure_channel_create( ffd->localaddr, ffd->client_args_compression, nullptr); } @@ -83,8 +84,9 @@ void chttp2_init_server_fullstack_compression(grpc_end2end_test_fixture* f, grpc_core::ExecCtx exec_ctx; grpc_channel_args_destroy(ffd->server_args_compression); } - ffd->server_args_compression = grpc_channel_args_set_compression_algorithm( - server_args, GRPC_COMPRESS_GZIP); + ffd->server_args_compression = + grpc_channel_args_set_channel_default_compression_algorithm( + server_args, GRPC_COMPRESS_GZIP); if (f->server) { grpc_server_destroy(f->server); } diff --git a/test/core/end2end/tests/compressed_payload.cc b/test/core/end2end/tests/compressed_payload.cc index 2b9ab5d642a..81e6bfccd10 100644 --- a/test/core/end2end/tests/compressed_payload.cc +++ b/test/core/end2end/tests/compressed_payload.cc @@ -124,10 +124,10 @@ static void request_for_disabled_algorithm( request_payload_slice = grpc_slice_from_copied_string(str); request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - client_args = grpc_channel_args_set_compression_algorithm( + client_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, requested_client_compression_algorithm); - server_args = - grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); + server_args = grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_NONE); { grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( @@ -308,9 +308,9 @@ static void request_with_payload_template( grpc_slice response_payload_slice = grpc_slice_from_copied_string(response_str); - client_args = grpc_channel_args_set_compression_algorithm( + client_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_client_channel_compression_algorithm); - server_args = grpc_channel_args_set_compression_algorithm( + server_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_server_channel_compression_algorithm); f = begin_test(config, test_name, client_args, server_args); diff --git a/test/core/end2end/tests/stream_compression_compressed_payload.cc b/test/core/end2end/tests/stream_compression_compressed_payload.cc index 39f95b85baa..9f40da100b4 100644 --- a/test/core/end2end/tests/stream_compression_compressed_payload.cc +++ b/test/core/end2end/tests/stream_compression_compressed_payload.cc @@ -124,10 +124,10 @@ static void request_for_disabled_algorithm( request_payload_slice = grpc_slice_from_copied_string(str); request_payload = grpc_raw_byte_buffer_create(&request_payload_slice, 1); - client_args = grpc_channel_args_set_compression_algorithm( + client_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, requested_client_compression_algorithm); - server_args = - grpc_channel_args_set_compression_algorithm(nullptr, GRPC_COMPRESS_NONE); + server_args = grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_NONE); { grpc_core::ExecCtx exec_ctx; server_args = grpc_channel_args_compression_algorithm_set_state( @@ -310,13 +310,13 @@ static void request_with_payload_template( grpc_slice response_payload_slice = grpc_slice_from_copied_string(response_str); - client_args = grpc_channel_args_set_compression_algorithm( + client_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_client_channel_compression_algorithm); if (set_default_server_message_compression_algorithm) { - server_args = grpc_channel_args_set_compression_algorithm( + server_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_server_message_compression_algorithm); } else { - server_args = grpc_channel_args_set_compression_algorithm( + server_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_server_channel_compression_algorithm); } diff --git a/test/core/end2end/tests/stream_compression_payload.cc b/test/core/end2end/tests/stream_compression_payload.cc index 5f6b9a7f199..ba0557facac 100644 --- a/test/core/end2end/tests/stream_compression_payload.cc +++ b/test/core/end2end/tests/stream_compression_payload.cc @@ -263,10 +263,12 @@ static void request_response_with_payload(grpc_end2end_test_config config, payload and status. */ static void test_invoke_request_response_with_payload( grpc_end2end_test_config config) { - grpc_channel_args* client_args = grpc_channel_args_set_compression_algorithm( - nullptr, GRPC_COMPRESS_STREAM_GZIP); - grpc_channel_args* server_args = grpc_channel_args_set_compression_algorithm( - nullptr, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args* client_args = + grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args* server_args = + grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_STREAM_GZIP); grpc_end2end_test_fixture f = begin_test(config, "test_invoke_request_response_with_payload", client_args, server_args); diff --git a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc index 6e96f7d2938..39698bde442 100644 --- a/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc +++ b/test/core/end2end/tests/stream_compression_ping_pong_streaming.cc @@ -91,10 +91,12 @@ static void end_test(grpc_end2end_test_fixture* f) { /* Client pings and server pongs. Repeat messages rounds before finishing. */ static void test_pingpong_streaming(grpc_end2end_test_config config, int messages) { - grpc_channel_args* client_args = grpc_channel_args_set_compression_algorithm( - nullptr, GRPC_COMPRESS_STREAM_GZIP); - grpc_channel_args* server_args = grpc_channel_args_set_compression_algorithm( - nullptr, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args* client_args = + grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_STREAM_GZIP); + grpc_channel_args* server_args = + grpc_channel_args_set_channel_default_compression_algorithm( + nullptr, GRPC_COMPRESS_STREAM_GZIP); grpc_end2end_test_fixture f = begin_test(config, "test_pingpong_streaming", client_args, server_args); grpc_call* c; diff --git a/test/core/end2end/tests/workaround_cronet_compression.cc b/test/core/end2end/tests/workaround_cronet_compression.cc index d79b2a9be3b..1a47244b68d 100644 --- a/test/core/end2end/tests/workaround_cronet_compression.cc +++ b/test/core/end2end/tests/workaround_cronet_compression.cc @@ -136,9 +136,9 @@ static void request_with_payload_template( grpc_slice response_payload_slice = grpc_slice_from_copied_string(response_str); - client_args = grpc_channel_args_set_compression_algorithm( + client_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_client_channel_compression_algorithm); - server_args = grpc_channel_args_set_compression_algorithm( + server_args = grpc_channel_args_set_channel_default_compression_algorithm( nullptr, default_server_channel_compression_algorithm); if (user_agent_override) {