grpc 1.60.0 → 1.61.0.pre2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Makefile +208 -165
- data/include/grpc/event_engine/event_engine.h +59 -12
- data/include/grpc/event_engine/internal/memory_allocator_impl.h +6 -0
- data/include/grpc/event_engine/internal/slice_cast.h +12 -0
- data/include/grpc/event_engine/memory_allocator.h +3 -1
- data/include/grpc/event_engine/slice.h +5 -0
- data/include/grpc/grpc_security.h +22 -1
- data/include/grpc/impl/call.h +29 -0
- data/include/grpc/impl/channel_arg_names.h +12 -1
- data/include/grpc/impl/slice_type.h +1 -1
- data/include/grpc/module.modulemap +1 -0
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.cc +54 -7
- data/src/core/ext/filters/backend_metrics/backend_metric_filter.h +20 -6
- data/src/core/ext/filters/channel_idle/channel_idle_filter.cc +10 -13
- data/src/core/ext/filters/channel_idle/channel_idle_filter.h +18 -10
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +326 -0
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.h +143 -0
- data/src/core/ext/filters/client_channel/backend_metric.cc +2 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +32 -6
- data/src/core/ext/filters/client_channel/client_channel_internal.h +2 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.cc +54 -21
- data/src/core/ext/filters/client_channel/lb_policy/address_filtering.h +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/endpoint_list.cc +12 -15
- data/src/core/ext/filters/client_channel/lb_policy/endpoint_list.h +8 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +139 -92
- data/src/core/ext/filters/client_channel/lb_policy/health_check_client.cc +9 -4
- data/src/core/ext/filters/client_channel/lb_policy/oob_backend_metric.cc +9 -4
- data/src/core/ext/filters/client_channel/lb_policy/outlier_detection/outlier_detection.cc +10 -11
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +94 -93
- data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +5 -3
- data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +12 -15
- data/src/core/ext/filters/client_channel/lb_policy/rls/rls.cc +38 -16
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +25 -28
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +10 -10
- data/src/core/ext/filters/client_channel/lb_policy/weighted_round_robin/weighted_round_robin.cc +37 -35
- data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +11 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +504 -461
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +232 -122
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +8 -6
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.cc +642 -251
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_override_host.h +2 -6
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_wrr_locality.cc +7 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/event_engine/event_engine_client_channel_resolver.cc +3 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/polling_resolver.cc +6 -8
- data/src/core/ext/filters/client_channel/resolver/xds/xds_dependency_manager.cc +1031 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_dependency_manager.h +277 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +128 -270
- data/src/core/ext/filters/client_channel/resolver/xds/{xds_resolver.h → xds_resolver_attributes.h} +5 -4
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver_trace.cc +25 -0
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver_trace.h +30 -0
- data/src/core/ext/filters/client_channel/retry_filter.cc +1 -0
- data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +35 -17
- data/src/core/ext/filters/deadline/deadline_filter.cc +12 -0
- data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +17 -13
- data/src/core/ext/filters/fault_injection/fault_injection_filter.h +13 -4
- data/src/core/ext/filters/http/client/http_client_filter.cc +23 -32
- data/src/core/ext/filters/http/client/http_client_filter.h +10 -5
- data/src/core/ext/filters/http/client_authority_filter.cc +14 -14
- data/src/core/ext/filters/http/client_authority_filter.h +12 -4
- data/src/core/ext/filters/http/http_filters_plugin.cc +42 -20
- data/src/core/ext/filters/http/message_compress/compression_filter.cc +55 -80
- data/src/core/ext/filters/http/message_compress/compression_filter.h +54 -12
- data/src/core/ext/filters/http/message_compress/legacy_compression_filter.cc +325 -0
- data/src/core/ext/filters/http/message_compress/legacy_compression_filter.h +139 -0
- data/src/core/ext/filters/http/server/http_server_filter.cc +41 -41
- data/src/core/ext/filters/http/server/http_server_filter.h +11 -4
- data/src/core/ext/filters/message_size/message_size_filter.cc +56 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +35 -23
- data/src/core/ext/filters/rbac/rbac_filter.cc +15 -11
- data/src/core/ext/filters/rbac/rbac_filter.h +11 -4
- data/src/core/ext/filters/server_config_selector/server_config_selector_filter.cc +25 -13
- data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +47 -50
- data/src/core/ext/filters/stateful_session/stateful_session_filter.h +21 -4
- data/src/core/ext/transport/chttp2/alpn/alpn.cc +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -2
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +11 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +67 -145
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -3
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +21 -82
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -8
- data/src/core/ext/transport/chttp2/transport/frame.cc +506 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +214 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +33 -79
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +4 -7
- data/src/core/ext/transport/chttp2/transport/http2_settings.cc +122 -32
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +142 -37
- data/src/core/ext/transport/chttp2/transport/internal.h +1 -22
- data/src/core/ext/transport/chttp2/transport/parsing.cc +23 -37
- data/src/core/ext/transport/chttp2/transport/writing.cc +26 -58
- data/src/core/ext/transport/inproc/inproc_transport.cc +172 -13
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb.h +712 -0
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.c +151 -0
- data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.h +33 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.c +133 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.h +50 -0
- data/src/core/ext/xds/certificate_provider_store.cc +2 -1
- data/src/core/ext/xds/certificate_provider_store.h +0 -5
- data/src/core/ext/xds/xds_api.cc +31 -18
- data/src/core/ext/xds/xds_api.h +2 -2
- data/src/core/ext/xds/xds_bootstrap.h +3 -0
- data/src/core/ext/xds/xds_certificate_provider.cc +88 -287
- data/src/core/ext/xds/xds_certificate_provider.h +44 -111
- data/src/core/ext/xds/xds_client.cc +420 -414
- data/src/core/ext/xds/xds_client.h +31 -22
- data/src/core/ext/xds/xds_client_grpc.cc +3 -1
- data/src/core/ext/xds/xds_cluster.cc +104 -11
- data/src/core/ext/xds/xds_cluster.h +9 -1
- data/src/core/ext/xds/xds_cluster_specifier_plugin.cc +9 -5
- data/src/core/ext/xds/xds_common_types.cc +14 -10
- data/src/core/ext/xds/xds_endpoint.cc +9 -4
- data/src/core/ext/xds/xds_endpoint.h +5 -1
- data/src/core/ext/xds/xds_health_status.cc +12 -2
- data/src/core/ext/xds/xds_health_status.h +4 -2
- data/src/core/ext/xds/xds_http_rbac_filter.cc +5 -3
- data/src/core/ext/xds/xds_listener.cc +14 -8
- data/src/core/ext/xds/xds_resource_type_impl.h +6 -4
- data/src/core/ext/xds/xds_route_config.cc +34 -22
- data/src/core/ext/xds/xds_route_config.h +1 -0
- data/src/core/ext/xds/xds_server_config_fetcher.cc +61 -57
- data/src/core/ext/xds/xds_transport.h +3 -0
- data/src/core/ext/xds/xds_transport_grpc.cc +47 -50
- data/src/core/ext/xds/xds_transport_grpc.h +4 -0
- data/src/core/lib/channel/call_tracer.cc +12 -0
- data/src/core/lib/channel/call_tracer.h +17 -3
- data/src/core/lib/channel/channel_args.cc +24 -14
- data/src/core/lib/channel/channel_args.h +74 -13
- data/src/core/lib/channel/channel_stack.cc +27 -0
- data/src/core/lib/channel/channel_stack.h +10 -10
- data/src/core/lib/channel/connected_channel.cc +64 -18
- data/src/core/lib/channel/promise_based_filter.h +1041 -1
- data/src/core/lib/channel/server_call_tracer_filter.cc +43 -35
- data/src/core/lib/compression/compression_internal.cc +0 -3
- data/src/core/lib/event_engine/ares_resolver.cc +35 -14
- data/src/core/lib/event_engine/ares_resolver.h +9 -10
- data/src/core/lib/event_engine/cf_engine/dns_service_resolver.cc +8 -1
- data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.cc +132 -0
- data/src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h +61 -0
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +52 -36
- data/src/core/lib/event_engine/posix_engine/posix_engine.h +4 -9
- data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +11 -3
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +9 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +7 -0
- data/src/core/lib/event_engine/posix_engine/timer_manager.cc +17 -27
- data/src/core/lib/event_engine/posix_engine/timer_manager.h +0 -3
- data/src/core/lib/event_engine/ref_counted_dns_resolver_interface.h +55 -0
- data/src/core/lib/event_engine/windows/native_windows_dns_resolver.cc +114 -0
- data/src/core/lib/event_engine/windows/native_windows_dns_resolver.h +51 -0
- data/src/core/lib/event_engine/windows/windows_engine.cc +7 -7
- data/src/core/lib/experiments/config.cc +13 -0
- data/src/core/lib/experiments/config.h +3 -0
- data/src/core/lib/experiments/experiments.cc +245 -366
- data/src/core/lib/experiments/experiments.h +50 -156
- data/src/core/lib/gprpp/debug_location.h +13 -0
- data/src/core/lib/gprpp/dual_ref_counted.h +36 -7
- data/src/core/lib/gprpp/orphanable.h +27 -0
- data/src/core/lib/gprpp/ref_counted.h +63 -22
- data/src/core/lib/gprpp/ref_counted_ptr.h +70 -27
- data/src/core/lib/gprpp/ref_counted_string.h +13 -0
- data/src/core/lib/gprpp/status_helper.cc +1 -2
- data/src/core/lib/iomgr/combiner.cc +15 -51
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +31 -0
- data/src/core/lib/iomgr/event_engine_shims/endpoint.h +16 -0
- data/src/core/lib/iomgr/tcp_client_posix.cc +4 -3
- data/src/core/lib/load_balancing/lb_policy.h +1 -1
- data/src/core/lib/promise/activity.cc +17 -2
- data/src/core/lib/promise/activity.h +5 -4
- data/src/core/lib/promise/all_ok.h +80 -0
- data/src/core/lib/promise/detail/join_state.h +2077 -0
- data/src/core/lib/promise/detail/promise_factory.h +1 -0
- data/src/core/lib/promise/detail/promise_like.h +8 -1
- data/src/core/lib/promise/detail/seq_state.h +3458 -150
- data/src/core/lib/promise/detail/status.h +42 -5
- data/src/core/lib/promise/for_each.h +13 -1
- data/src/core/lib/promise/if.h +4 -0
- data/src/core/lib/promise/latch.h +6 -3
- data/src/core/lib/promise/party.cc +33 -31
- data/src/core/lib/promise/party.h +142 -6
- data/src/core/lib/promise/poll.h +39 -13
- data/src/core/lib/promise/promise.h +4 -0
- data/src/core/lib/promise/seq.h +107 -7
- data/src/core/lib/promise/status_flag.h +196 -0
- data/src/core/lib/promise/try_join.h +132 -0
- data/src/core/lib/promise/try_seq.h +132 -10
- data/src/core/lib/resolver/endpoint_addresses.cc +0 -1
- data/src/core/lib/resolver/endpoint_addresses.h +48 -0
- data/src/core/lib/resource_quota/arena.h +2 -2
- data/src/core/lib/resource_quota/memory_quota.cc +57 -8
- data/src/core/lib/resource_quota/memory_quota.h +6 -0
- data/src/core/lib/security/authorization/grpc_server_authz_filter.cc +14 -11
- data/src/core/lib/security/authorization/grpc_server_authz_filter.h +14 -5
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/external_account_credentials.cc +28 -20
- data/src/core/lib/security/credentials/external/external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/file_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +4 -0
- data/src/core/lib/security/credentials/external/url_external_account_credentials.h +4 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +0 -3
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +12 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_crl_provider.cc +22 -5
- data/src/core/lib/security/credentials/tls/grpc_tls_crl_provider.h +1 -5
- data/src/core/lib/security/credentials/tls/tls_credentials.cc +16 -0
- data/src/core/lib/security/credentials/xds/xds_credentials.cc +21 -28
- data/src/core/lib/security/credentials/xds/xds_credentials.h +2 -4
- data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +4 -3
- data/src/core/lib/security/transport/auth_filters.h +71 -4
- data/src/core/lib/security/transport/client_auth_filter.cc +2 -4
- data/src/core/lib/security/transport/legacy_server_auth_filter.cc +244 -0
- data/src/core/lib/security/transport/server_auth_filter.cc +70 -90
- data/src/core/lib/slice/slice_buffer.h +3 -0
- data/src/core/lib/surface/builtins.cc +1 -1
- data/src/core/lib/surface/call.cc +683 -196
- data/src/core/lib/surface/call.h +26 -13
- data/src/core/lib/surface/call_trace.cc +42 -1
- data/src/core/lib/surface/channel.cc +0 -1
- data/src/core/lib/surface/channel.h +0 -6
- data/src/core/lib/surface/channel_init.h +26 -0
- data/src/core/lib/surface/init.cc +14 -8
- data/src/core/lib/surface/server.cc +256 -237
- data/src/core/lib/surface/server.h +26 -54
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/surface/wait_for_cq_end_op.h +94 -0
- data/src/core/lib/transport/call_final_info.cc +38 -0
- data/src/core/lib/transport/call_final_info.h +54 -0
- data/src/core/lib/transport/connectivity_state.cc +3 -2
- data/src/core/lib/transport/connectivity_state.h +4 -0
- data/src/core/lib/transport/metadata_batch.h +4 -4
- data/src/core/lib/transport/transport.cc +70 -19
- data/src/core/lib/transport/transport.h +395 -25
- data/src/core/plugin_registry/grpc_plugin_registry.cc +3 -0
- data/src/core/plugin_registry/grpc_plugin_registry_extra.cc +0 -3
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +1 -1
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +65 -43
- data/src/ruby/ext/grpc/rb_channel_args.c +3 -1
- data/src/ruby/ext/grpc/rb_grpc.c +0 -1
- data/src/ruby/ext/grpc/rb_grpc.h +0 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/upb/upb/reflection/def_pool.h +2 -2
- data/third_party/zlib/adler32.c +5 -27
- data/third_party/zlib/compress.c +5 -16
- data/third_party/zlib/crc32.c +86 -162
- data/third_party/zlib/deflate.c +233 -336
- data/third_party/zlib/deflate.h +8 -8
- data/third_party/zlib/gzguts.h +11 -12
- data/third_party/zlib/infback.c +7 -23
- data/third_party/zlib/inffast.c +1 -4
- data/third_party/zlib/inffast.h +1 -1
- data/third_party/zlib/inflate.c +30 -99
- data/third_party/zlib/inftrees.c +6 -11
- data/third_party/zlib/inftrees.h +3 -3
- data/third_party/zlib/trees.c +224 -302
- data/third_party/zlib/uncompr.c +4 -12
- data/third_party/zlib/zconf.h +6 -2
- data/third_party/zlib/zlib.h +191 -188
- data/third_party/zlib/zutil.c +16 -44
- data/third_party/zlib/zutil.h +10 -10
- metadata +35 -13
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +0 -1173
- data/src/core/lib/event_engine/memory_allocator.cc +0 -74
- data/src/core/lib/transport/pid_controller.cc +0 -51
- data/src/core/lib/transport/pid_controller.h +0 -116
- data/third_party/upb/upb/collections/array.h +0 -17
- data/third_party/upb/upb/collections/map.h +0 -17
- data/third_party/upb/upb/upb.hpp +0 -18
@@ -56,6 +56,11 @@
|
|
56
56
|
|
57
57
|
namespace grpc_core {
|
58
58
|
|
59
|
+
const NoInterceptor ServerCompressionFilter::Call::OnServerTrailingMetadata;
|
60
|
+
const NoInterceptor ServerCompressionFilter::Call::OnFinalize;
|
61
|
+
const NoInterceptor ClientCompressionFilter::Call::OnServerTrailingMetadata;
|
62
|
+
const NoInterceptor ClientCompressionFilter::Call::OnFinalize;
|
63
|
+
|
59
64
|
const grpc_channel_filter ClientCompressionFilter::kFilter =
|
60
65
|
MakePromiseBasedFilter<ClientCompressionFilter, FilterEndpoint::kClient,
|
61
66
|
kFilterExaminesServerInitialMetadata |
|
@@ -77,7 +82,7 @@ absl::StatusOr<ServerCompressionFilter> ServerCompressionFilter::Create(
|
|
77
82
|
return ServerCompressionFilter(args);
|
78
83
|
}
|
79
84
|
|
80
|
-
|
85
|
+
ChannelCompression::ChannelCompression(const ChannelArgs& args)
|
81
86
|
: max_recv_size_(GetMaxRecvSizeFromChannelArgs(args)),
|
82
87
|
message_size_service_config_parser_index_(
|
83
88
|
MessageSizeParser::ParserIndex()),
|
@@ -105,7 +110,7 @@ CompressionFilter::CompressionFilter(const ChannelArgs& args)
|
|
105
110
|
}
|
106
111
|
}
|
107
112
|
|
108
|
-
MessageHandle
|
113
|
+
MessageHandle ChannelCompression::CompressMessage(
|
109
114
|
MessageHandle message, grpc_compression_algorithm algorithm) const {
|
110
115
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
111
116
|
gpr_log(GPR_INFO, "CompressMessage: len=%" PRIdPTR " alg=%d flags=%d",
|
@@ -163,7 +168,7 @@ MessageHandle CompressionFilter::CompressMessage(
|
|
163
168
|
return message;
|
164
169
|
}
|
165
170
|
|
166
|
-
absl::StatusOr<MessageHandle>
|
171
|
+
absl::StatusOr<MessageHandle> ChannelCompression::DecompressMessage(
|
167
172
|
MessageHandle message, DecompressArgs args) const {
|
168
173
|
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
169
174
|
gpr_log(GPR_INFO, "DecompressMessage: len=%" PRIdPTR " max=%d alg=%d",
|
@@ -208,7 +213,7 @@ absl::StatusOr<MessageHandle> CompressionFilter::DecompressMessage(
|
|
208
213
|
return std::move(message);
|
209
214
|
}
|
210
215
|
|
211
|
-
grpc_compression_algorithm
|
216
|
+
grpc_compression_algorithm ChannelCompression::HandleOutgoingMetadata(
|
212
217
|
grpc_metadata_batch& outgoing_metadata) {
|
213
218
|
const auto algorithm = outgoing_metadata.Take(GrpcInternalEncodingRequest())
|
214
219
|
.value_or(default_compression_algorithm());
|
@@ -221,7 +226,7 @@ grpc_compression_algorithm CompressionFilter::HandleOutgoingMetadata(
|
|
221
226
|
return algorithm;
|
222
227
|
}
|
223
228
|
|
224
|
-
|
229
|
+
ChannelCompression::DecompressArgs ChannelCompression::HandleIncomingMetadata(
|
225
230
|
const grpc_metadata_batch& incoming_metadata) {
|
226
231
|
// Configure max receive size.
|
227
232
|
auto max_recv_message_length = max_recv_size_;
|
@@ -232,89 +237,59 @@ CompressionFilter::DecompressArgs CompressionFilter::HandleIncomingMetadata(
|
|
232
237
|
if (limits != nullptr && limits->max_recv_size().has_value() &&
|
233
238
|
(!max_recv_message_length.has_value() ||
|
234
239
|
*limits->max_recv_size() < *max_recv_message_length)) {
|
235
|
-
max_recv_message_length =
|
240
|
+
max_recv_message_length = limits->max_recv_size();
|
236
241
|
}
|
237
242
|
return DecompressArgs{incoming_metadata.get(GrpcEncodingMetadata())
|
238
243
|
.value_or(GRPC_COMPRESS_NONE),
|
239
244
|
max_recv_message_length};
|
240
245
|
}
|
241
246
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
HandleOutgoingMetadata(
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
247
|
+
void ClientCompressionFilter::Call::OnClientInitialMetadata(
|
248
|
+
ClientMetadata& md, ClientCompressionFilter* filter) {
|
249
|
+
compression_algorithm_ =
|
250
|
+
filter->compression_engine_.HandleOutgoingMetadata(md);
|
251
|
+
}
|
252
|
+
|
253
|
+
MessageHandle ClientCompressionFilter::Call::OnClientToServerMessage(
|
254
|
+
MessageHandle message, ClientCompressionFilter* filter) {
|
255
|
+
return filter->compression_engine_.CompressMessage(std::move(message),
|
256
|
+
compression_algorithm_);
|
257
|
+
}
|
258
|
+
|
259
|
+
void ClientCompressionFilter::Call::OnServerInitialMetadata(
|
260
|
+
ServerMetadata& md, ClientCompressionFilter* filter) {
|
261
|
+
decompress_args_ = filter->compression_engine_.HandleIncomingMetadata(md);
|
262
|
+
}
|
263
|
+
|
264
|
+
absl::StatusOr<MessageHandle>
|
265
|
+
ClientCompressionFilter::Call::OnServerToClientMessage(
|
266
|
+
MessageHandle message, ClientCompressionFilter* filter) {
|
267
|
+
return filter->compression_engine_.DecompressMessage(std::move(message),
|
268
|
+
decompress_args_);
|
269
|
+
}
|
270
|
+
|
271
|
+
void ServerCompressionFilter::Call::OnClientInitialMetadata(
|
272
|
+
ClientMetadata& md, ServerCompressionFilter* filter) {
|
273
|
+
decompress_args_ = filter->compression_engine_.HandleIncomingMetadata(md);
|
274
|
+
}
|
275
|
+
|
276
|
+
absl::StatusOr<MessageHandle>
|
277
|
+
ServerCompressionFilter::Call::OnClientToServerMessage(
|
278
|
+
MessageHandle message, ServerCompressionFilter* filter) {
|
279
|
+
return filter->compression_engine_.DecompressMessage(std::move(message),
|
280
|
+
decompress_args_);
|
281
|
+
}
|
282
|
+
|
283
|
+
void ServerCompressionFilter::Call::OnServerInitialMetadata(
|
284
|
+
ServerMetadata& md, ServerCompressionFilter* filter) {
|
285
|
+
compression_algorithm_ =
|
286
|
+
filter->compression_engine_.HandleOutgoingMetadata(md);
|
275
287
|
}
|
276
288
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
auto* decompress_err =
|
282
|
-
GetContext<Arena>()->New<Latch<ServerMetadataHandle>>();
|
283
|
-
call_args.client_to_server_messages->InterceptAndMap(
|
284
|
-
[decompress_err, decompress_args,
|
285
|
-
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
286
|
-
auto r = DecompressMessage(std::move(message), decompress_args);
|
287
|
-
if (grpc_call_trace.enabled()) {
|
288
|
-
gpr_log(GPR_DEBUG, "%s[compression] DecompressMessage returned %s",
|
289
|
-
Activity::current()->DebugTag().c_str(),
|
290
|
-
r.status().ToString().c_str());
|
291
|
-
}
|
292
|
-
if (!r.ok()) {
|
293
|
-
decompress_err->Set(ServerMetadataFromStatus(r.status()));
|
294
|
-
return absl::nullopt;
|
295
|
-
}
|
296
|
-
return std::move(*r);
|
297
|
-
});
|
298
|
-
auto* compression_algorithm =
|
299
|
-
GetContext<Arena>()->New<grpc_compression_algorithm>();
|
300
|
-
call_args.server_initial_metadata->InterceptAndMap(
|
301
|
-
[this, compression_algorithm](ServerMetadataHandle md) {
|
302
|
-
if (grpc_call_trace.enabled()) {
|
303
|
-
gpr_log(GPR_INFO, "%s[compression] Write metadata",
|
304
|
-
Activity::current()->DebugTag().c_str());
|
305
|
-
}
|
306
|
-
// Find the compression algorithm.
|
307
|
-
*compression_algorithm = HandleOutgoingMetadata(*md);
|
308
|
-
return md;
|
309
|
-
});
|
310
|
-
call_args.server_to_client_messages->InterceptAndMap(
|
311
|
-
[compression_algorithm,
|
312
|
-
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
313
|
-
return CompressMessage(std::move(message), *compression_algorithm);
|
314
|
-
});
|
315
|
-
// Run the next filter, and race it with getting an error from decompression.
|
316
|
-
return PrioritizedRace(decompress_err->Wait(),
|
317
|
-
next_promise_factory(std::move(call_args)));
|
289
|
+
MessageHandle ServerCompressionFilter::Call::OnServerToClientMessage(
|
290
|
+
MessageHandle message, ServerCompressionFilter* filter) {
|
291
|
+
return filter->compression_engine_.CompressMessage(std::move(message),
|
292
|
+
compression_algorithm_);
|
318
293
|
}
|
319
294
|
|
320
295
|
} // namespace grpc_core
|
@@ -61,15 +61,15 @@ namespace grpc_core {
|
|
61
61
|
/// the aforementioned 'grpc-encoding' metadata value, data will pass through
|
62
62
|
/// uncompressed.
|
63
63
|
|
64
|
-
class
|
65
|
-
|
64
|
+
class ChannelCompression {
|
65
|
+
public:
|
66
|
+
explicit ChannelCompression(const ChannelArgs& args);
|
67
|
+
|
66
68
|
struct DecompressArgs {
|
67
69
|
grpc_compression_algorithm algorithm;
|
68
70
|
absl::optional<uint32_t> max_recv_message_length;
|
69
71
|
};
|
70
72
|
|
71
|
-
explicit CompressionFilter(const ChannelArgs& args);
|
72
|
-
|
73
73
|
grpc_compression_algorithm default_compression_algorithm() const {
|
74
74
|
return default_compression_algorithm_;
|
75
75
|
}
|
@@ -104,7 +104,8 @@ class CompressionFilter : public ChannelFilter {
|
|
104
104
|
bool enable_decompression_;
|
105
105
|
};
|
106
106
|
|
107
|
-
class ClientCompressionFilter final
|
107
|
+
class ClientCompressionFilter final
|
108
|
+
: public ImplementChannelFilter<ClientCompressionFilter> {
|
108
109
|
public:
|
109
110
|
static const grpc_channel_filter kFilter;
|
110
111
|
|
@@ -112,14 +113,35 @@ class ClientCompressionFilter final : public CompressionFilter {
|
|
112
113
|
const ChannelArgs& args, ChannelFilter::Args filter_args);
|
113
114
|
|
114
115
|
// Construct a promise for one call.
|
115
|
-
|
116
|
-
|
116
|
+
class Call {
|
117
|
+
public:
|
118
|
+
void OnClientInitialMetadata(ClientMetadata& md,
|
119
|
+
ClientCompressionFilter* filter);
|
120
|
+
MessageHandle OnClientToServerMessage(MessageHandle message,
|
121
|
+
ClientCompressionFilter* filter);
|
122
|
+
|
123
|
+
void OnServerInitialMetadata(ServerMetadata& md,
|
124
|
+
ClientCompressionFilter* filter);
|
125
|
+
absl::StatusOr<MessageHandle> OnServerToClientMessage(
|
126
|
+
MessageHandle message, ClientCompressionFilter* filter);
|
127
|
+
|
128
|
+
static const NoInterceptor OnServerTrailingMetadata;
|
129
|
+
static const NoInterceptor OnFinalize;
|
130
|
+
|
131
|
+
private:
|
132
|
+
grpc_compression_algorithm compression_algorithm_;
|
133
|
+
ChannelCompression::DecompressArgs decompress_args_;
|
134
|
+
};
|
117
135
|
|
118
136
|
private:
|
119
|
-
|
137
|
+
explicit ClientCompressionFilter(const ChannelArgs& args)
|
138
|
+
: compression_engine_(args) {}
|
139
|
+
|
140
|
+
ChannelCompression compression_engine_;
|
120
141
|
};
|
121
142
|
|
122
|
-
class ServerCompressionFilter final
|
143
|
+
class ServerCompressionFilter final
|
144
|
+
: public ImplementChannelFilter<ServerCompressionFilter> {
|
123
145
|
public:
|
124
146
|
static const grpc_channel_filter kFilter;
|
125
147
|
|
@@ -127,11 +149,31 @@ class ServerCompressionFilter final : public CompressionFilter {
|
|
127
149
|
const ChannelArgs& args, ChannelFilter::Args filter_args);
|
128
150
|
|
129
151
|
// Construct a promise for one call.
|
130
|
-
|
131
|
-
|
152
|
+
class Call {
|
153
|
+
public:
|
154
|
+
void OnClientInitialMetadata(ClientMetadata& md,
|
155
|
+
ServerCompressionFilter* filter);
|
156
|
+
absl::StatusOr<MessageHandle> OnClientToServerMessage(
|
157
|
+
MessageHandle message, ServerCompressionFilter* filter);
|
158
|
+
|
159
|
+
void OnServerInitialMetadata(ServerMetadata& md,
|
160
|
+
ServerCompressionFilter* filter);
|
161
|
+
MessageHandle OnServerToClientMessage(MessageHandle message,
|
162
|
+
ServerCompressionFilter* filter);
|
163
|
+
|
164
|
+
static const NoInterceptor OnServerTrailingMetadata;
|
165
|
+
static const NoInterceptor OnFinalize;
|
166
|
+
|
167
|
+
private:
|
168
|
+
ChannelCompression::DecompressArgs decompress_args_;
|
169
|
+
grpc_compression_algorithm compression_algorithm_;
|
170
|
+
};
|
132
171
|
|
133
172
|
private:
|
134
|
-
|
173
|
+
explicit ServerCompressionFilter(const ChannelArgs& args)
|
174
|
+
: compression_engine_(args) {}
|
175
|
+
|
176
|
+
ChannelCompression compression_engine_;
|
135
177
|
};
|
136
178
|
|
137
179
|
} // namespace grpc_core
|
@@ -0,0 +1,325 @@
|
|
1
|
+
// Copyright 2022 gRPC authors.
|
2
|
+
//
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
// you may not use this file except in compliance with the License.
|
5
|
+
// You may obtain a copy of the License at
|
6
|
+
//
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
//
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
// See the License for the specific language governing permissions and
|
13
|
+
// limitations under the License.
|
14
|
+
|
15
|
+
#include <grpc/support/port_platform.h>
|
16
|
+
|
17
|
+
#include "src/core/ext/filters/http/message_compress/legacy_compression_filter.h"
|
18
|
+
|
19
|
+
#include <inttypes.h>
|
20
|
+
|
21
|
+
#include <functional>
|
22
|
+
#include <memory>
|
23
|
+
#include <utility>
|
24
|
+
|
25
|
+
#include "absl/status/status.h"
|
26
|
+
#include "absl/strings/str_cat.h"
|
27
|
+
#include "absl/strings/str_format.h"
|
28
|
+
#include "absl/types/optional.h"
|
29
|
+
|
30
|
+
#include <grpc/compression.h>
|
31
|
+
#include <grpc/grpc.h>
|
32
|
+
#include <grpc/impl/channel_arg_names.h>
|
33
|
+
#include <grpc/impl/compression_types.h>
|
34
|
+
#include <grpc/support/log.h>
|
35
|
+
|
36
|
+
#include "src/core/ext/filters/message_size/message_size_filter.h"
|
37
|
+
#include "src/core/lib/channel/call_tracer.h"
|
38
|
+
#include "src/core/lib/channel/channel_args.h"
|
39
|
+
#include "src/core/lib/channel/channel_stack.h"
|
40
|
+
#include "src/core/lib/channel/context.h"
|
41
|
+
#include "src/core/lib/channel/promise_based_filter.h"
|
42
|
+
#include "src/core/lib/compression/compression_internal.h"
|
43
|
+
#include "src/core/lib/compression/message_compress.h"
|
44
|
+
#include "src/core/lib/debug/trace.h"
|
45
|
+
#include "src/core/lib/promise/activity.h"
|
46
|
+
#include "src/core/lib/promise/context.h"
|
47
|
+
#include "src/core/lib/promise/latch.h"
|
48
|
+
#include "src/core/lib/promise/pipe.h"
|
49
|
+
#include "src/core/lib/promise/prioritized_race.h"
|
50
|
+
#include "src/core/lib/resource_quota/arena.h"
|
51
|
+
#include "src/core/lib/slice/slice_buffer.h"
|
52
|
+
#include "src/core/lib/surface/call.h"
|
53
|
+
#include "src/core/lib/surface/call_trace.h"
|
54
|
+
#include "src/core/lib/transport/metadata_batch.h"
|
55
|
+
#include "src/core/lib/transport/transport.h"
|
56
|
+
|
57
|
+
namespace grpc_core {
|
58
|
+
|
59
|
+
const grpc_channel_filter LegacyClientCompressionFilter::kFilter =
|
60
|
+
MakePromiseBasedFilter<
|
61
|
+
LegacyClientCompressionFilter, FilterEndpoint::kClient,
|
62
|
+
kFilterExaminesServerInitialMetadata | kFilterExaminesInboundMessages |
|
63
|
+
kFilterExaminesOutboundMessages>("compression");
|
64
|
+
const grpc_channel_filter LegacyServerCompressionFilter::kFilter =
|
65
|
+
MakePromiseBasedFilter<
|
66
|
+
LegacyServerCompressionFilter, FilterEndpoint::kServer,
|
67
|
+
kFilterExaminesServerInitialMetadata | kFilterExaminesInboundMessages |
|
68
|
+
kFilterExaminesOutboundMessages>("compression");
|
69
|
+
|
70
|
+
absl::StatusOr<LegacyClientCompressionFilter>
|
71
|
+
LegacyClientCompressionFilter::Create(const ChannelArgs& args,
|
72
|
+
ChannelFilter::Args) {
|
73
|
+
return LegacyClientCompressionFilter(args);
|
74
|
+
}
|
75
|
+
|
76
|
+
absl::StatusOr<LegacyServerCompressionFilter>
|
77
|
+
LegacyServerCompressionFilter::Create(const ChannelArgs& args,
|
78
|
+
ChannelFilter::Args) {
|
79
|
+
return LegacyServerCompressionFilter(args);
|
80
|
+
}
|
81
|
+
|
82
|
+
LegacyCompressionFilter::LegacyCompressionFilter(const ChannelArgs& args)
|
83
|
+
: max_recv_size_(GetMaxRecvSizeFromChannelArgs(args)),
|
84
|
+
message_size_service_config_parser_index_(
|
85
|
+
MessageSizeParser::ParserIndex()),
|
86
|
+
default_compression_algorithm_(
|
87
|
+
DefaultCompressionAlgorithmFromChannelArgs(args).value_or(
|
88
|
+
GRPC_COMPRESS_NONE)),
|
89
|
+
enabled_compression_algorithms_(
|
90
|
+
CompressionAlgorithmSet::FromChannelArgs(args)),
|
91
|
+
enable_compression_(
|
92
|
+
args.GetBool(GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION).value_or(true)),
|
93
|
+
enable_decompression_(
|
94
|
+
args.GetBool(GRPC_ARG_ENABLE_PER_MESSAGE_DECOMPRESSION)
|
95
|
+
.value_or(true)) {
|
96
|
+
// Make sure the default is enabled.
|
97
|
+
if (!enabled_compression_algorithms_.IsSet(default_compression_algorithm_)) {
|
98
|
+
const char* name;
|
99
|
+
if (!grpc_compression_algorithm_name(default_compression_algorithm_,
|
100
|
+
&name)) {
|
101
|
+
name = "<unknown>";
|
102
|
+
}
|
103
|
+
gpr_log(GPR_ERROR,
|
104
|
+
"default compression algorithm %s not enabled: switching to none",
|
105
|
+
name);
|
106
|
+
default_compression_algorithm_ = GRPC_COMPRESS_NONE;
|
107
|
+
}
|
108
|
+
}
|
109
|
+
|
110
|
+
MessageHandle LegacyCompressionFilter::CompressMessage(
|
111
|
+
MessageHandle message, grpc_compression_algorithm algorithm) const {
|
112
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
113
|
+
gpr_log(GPR_INFO, "CompressMessage: len=%" PRIdPTR " alg=%d flags=%d",
|
114
|
+
message->payload()->Length(), algorithm, message->flags());
|
115
|
+
}
|
116
|
+
auto* call_context = GetContext<grpc_call_context_element>();
|
117
|
+
auto* call_tracer = static_cast<CallTracerInterface*>(
|
118
|
+
call_context[GRPC_CONTEXT_CALL_TRACER].value);
|
119
|
+
if (call_tracer != nullptr) {
|
120
|
+
call_tracer->RecordSendMessage(*message->payload());
|
121
|
+
}
|
122
|
+
// Check if we're allowed to compress this message
|
123
|
+
// (apps might want to disable compression for certain messages to avoid
|
124
|
+
// crime/beast like vulns).
|
125
|
+
uint32_t& flags = message->mutable_flags();
|
126
|
+
if (algorithm == GRPC_COMPRESS_NONE || !enable_compression_ ||
|
127
|
+
(flags & (GRPC_WRITE_NO_COMPRESS | GRPC_WRITE_INTERNAL_COMPRESS))) {
|
128
|
+
return message;
|
129
|
+
}
|
130
|
+
// Try to compress the payload.
|
131
|
+
SliceBuffer tmp;
|
132
|
+
SliceBuffer* payload = message->payload();
|
133
|
+
bool did_compress = grpc_msg_compress(algorithm, payload->c_slice_buffer(),
|
134
|
+
tmp.c_slice_buffer());
|
135
|
+
// If we achieved compression send it as compressed, otherwise send it as (to
|
136
|
+
// avoid spending cycles on the receiver decompressing).
|
137
|
+
if (did_compress) {
|
138
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
139
|
+
const char* algo_name;
|
140
|
+
const size_t before_size = payload->Length();
|
141
|
+
const size_t after_size = tmp.Length();
|
142
|
+
const float savings_ratio = 1.0f - static_cast<float>(after_size) /
|
143
|
+
static_cast<float>(before_size);
|
144
|
+
GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name));
|
145
|
+
gpr_log(GPR_INFO,
|
146
|
+
"Compressed[%s] %" PRIuPTR " bytes vs. %" PRIuPTR
|
147
|
+
" bytes (%.2f%% savings)",
|
148
|
+
algo_name, before_size, after_size, 100 * savings_ratio);
|
149
|
+
}
|
150
|
+
tmp.Swap(payload);
|
151
|
+
flags |= GRPC_WRITE_INTERNAL_COMPRESS;
|
152
|
+
if (call_tracer != nullptr) {
|
153
|
+
call_tracer->RecordSendCompressedMessage(*message->payload());
|
154
|
+
}
|
155
|
+
} else {
|
156
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
157
|
+
const char* algo_name;
|
158
|
+
GPR_ASSERT(grpc_compression_algorithm_name(algorithm, &algo_name));
|
159
|
+
gpr_log(GPR_INFO,
|
160
|
+
"Algorithm '%s' enabled but decided not to compress. Input size: "
|
161
|
+
"%" PRIuPTR,
|
162
|
+
algo_name, payload->Length());
|
163
|
+
}
|
164
|
+
}
|
165
|
+
return message;
|
166
|
+
}
|
167
|
+
|
168
|
+
absl::StatusOr<MessageHandle> LegacyCompressionFilter::DecompressMessage(
|
169
|
+
MessageHandle message, DecompressArgs args) const {
|
170
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_compression_trace)) {
|
171
|
+
gpr_log(GPR_INFO, "DecompressMessage: len=%" PRIdPTR " max=%d alg=%d",
|
172
|
+
message->payload()->Length(),
|
173
|
+
args.max_recv_message_length.value_or(-1), args.algorithm);
|
174
|
+
}
|
175
|
+
auto* call_context = GetContext<grpc_call_context_element>();
|
176
|
+
auto* call_tracer = static_cast<CallTracerInterface*>(
|
177
|
+
call_context[GRPC_CONTEXT_CALL_TRACER].value);
|
178
|
+
if (call_tracer != nullptr) {
|
179
|
+
call_tracer->RecordReceivedMessage(*message->payload());
|
180
|
+
}
|
181
|
+
// Check max message length.
|
182
|
+
if (args.max_recv_message_length.has_value() &&
|
183
|
+
message->payload()->Length() >
|
184
|
+
static_cast<size_t>(*args.max_recv_message_length)) {
|
185
|
+
return absl::ResourceExhaustedError(absl::StrFormat(
|
186
|
+
"Received message larger than max (%u vs. %d)",
|
187
|
+
message->payload()->Length(), *args.max_recv_message_length));
|
188
|
+
}
|
189
|
+
// Check if decompression is enabled (if not, we can just pass the message
|
190
|
+
// up).
|
191
|
+
if (!enable_decompression_ ||
|
192
|
+
(message->flags() & GRPC_WRITE_INTERNAL_COMPRESS) == 0) {
|
193
|
+
return std::move(message);
|
194
|
+
}
|
195
|
+
// Try to decompress the payload.
|
196
|
+
SliceBuffer decompressed_slices;
|
197
|
+
if (grpc_msg_decompress(args.algorithm, message->payload()->c_slice_buffer(),
|
198
|
+
decompressed_slices.c_slice_buffer()) == 0) {
|
199
|
+
return absl::InternalError(
|
200
|
+
absl::StrCat("Unexpected error decompressing data for algorithm ",
|
201
|
+
CompressionAlgorithmAsString(args.algorithm)));
|
202
|
+
}
|
203
|
+
// Swap the decompressed slices into the message.
|
204
|
+
message->payload()->Swap(&decompressed_slices);
|
205
|
+
message->mutable_flags() &= ~GRPC_WRITE_INTERNAL_COMPRESS;
|
206
|
+
message->mutable_flags() |= GRPC_WRITE_INTERNAL_TEST_ONLY_WAS_COMPRESSED;
|
207
|
+
if (call_tracer != nullptr) {
|
208
|
+
call_tracer->RecordReceivedDecompressedMessage(*message->payload());
|
209
|
+
}
|
210
|
+
return std::move(message);
|
211
|
+
}
|
212
|
+
|
213
|
+
grpc_compression_algorithm LegacyCompressionFilter::HandleOutgoingMetadata(
|
214
|
+
grpc_metadata_batch& outgoing_metadata) {
|
215
|
+
const auto algorithm = outgoing_metadata.Take(GrpcInternalEncodingRequest())
|
216
|
+
.value_or(default_compression_algorithm());
|
217
|
+
// Convey supported compression algorithms.
|
218
|
+
outgoing_metadata.Set(GrpcAcceptEncodingMetadata(),
|
219
|
+
enabled_compression_algorithms());
|
220
|
+
if (algorithm != GRPC_COMPRESS_NONE) {
|
221
|
+
outgoing_metadata.Set(GrpcEncodingMetadata(), algorithm);
|
222
|
+
}
|
223
|
+
return algorithm;
|
224
|
+
}
|
225
|
+
|
226
|
+
LegacyCompressionFilter::DecompressArgs
|
227
|
+
LegacyCompressionFilter::HandleIncomingMetadata(
|
228
|
+
const grpc_metadata_batch& incoming_metadata) {
|
229
|
+
// Configure max receive size.
|
230
|
+
auto max_recv_message_length = max_recv_size_;
|
231
|
+
const MessageSizeParsedConfig* limits =
|
232
|
+
MessageSizeParsedConfig::GetFromCallContext(
|
233
|
+
GetContext<grpc_call_context_element>(),
|
234
|
+
message_size_service_config_parser_index_);
|
235
|
+
if (limits != nullptr && limits->max_recv_size().has_value() &&
|
236
|
+
(!max_recv_message_length.has_value() ||
|
237
|
+
*limits->max_recv_size() < *max_recv_message_length)) {
|
238
|
+
max_recv_message_length = *limits->max_recv_size();
|
239
|
+
}
|
240
|
+
return DecompressArgs{incoming_metadata.get(GrpcEncodingMetadata())
|
241
|
+
.value_or(GRPC_COMPRESS_NONE),
|
242
|
+
max_recv_message_length};
|
243
|
+
}
|
244
|
+
|
245
|
+
ArenaPromise<ServerMetadataHandle>
|
246
|
+
LegacyClientCompressionFilter::MakeCallPromise(
|
247
|
+
CallArgs call_args, NextPromiseFactory next_promise_factory) {
|
248
|
+
auto compression_algorithm =
|
249
|
+
HandleOutgoingMetadata(*call_args.client_initial_metadata);
|
250
|
+
call_args.client_to_server_messages->InterceptAndMap(
|
251
|
+
[compression_algorithm,
|
252
|
+
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
253
|
+
return CompressMessage(std::move(message), compression_algorithm);
|
254
|
+
});
|
255
|
+
auto* decompress_args = GetContext<Arena>()->New<DecompressArgs>(
|
256
|
+
DecompressArgs{GRPC_COMPRESS_ALGORITHMS_COUNT, absl::nullopt});
|
257
|
+
auto* decompress_err =
|
258
|
+
GetContext<Arena>()->New<Latch<ServerMetadataHandle>>();
|
259
|
+
call_args.server_initial_metadata->InterceptAndMap(
|
260
|
+
[decompress_args, this](ServerMetadataHandle server_initial_metadata)
|
261
|
+
-> absl::optional<ServerMetadataHandle> {
|
262
|
+
if (server_initial_metadata == nullptr) return absl::nullopt;
|
263
|
+
*decompress_args = HandleIncomingMetadata(*server_initial_metadata);
|
264
|
+
return std::move(server_initial_metadata);
|
265
|
+
});
|
266
|
+
call_args.server_to_client_messages->InterceptAndMap(
|
267
|
+
[decompress_err, decompress_args,
|
268
|
+
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
269
|
+
auto r = DecompressMessage(std::move(message), *decompress_args);
|
270
|
+
if (!r.ok()) {
|
271
|
+
decompress_err->Set(ServerMetadataFromStatus(r.status()));
|
272
|
+
return absl::nullopt;
|
273
|
+
}
|
274
|
+
return std::move(*r);
|
275
|
+
});
|
276
|
+
// Run the next filter, and race it with getting an error from decompression.
|
277
|
+
return PrioritizedRace(decompress_err->Wait(),
|
278
|
+
next_promise_factory(std::move(call_args)));
|
279
|
+
}
|
280
|
+
|
281
|
+
ArenaPromise<ServerMetadataHandle>
|
282
|
+
LegacyServerCompressionFilter::MakeCallPromise(
|
283
|
+
CallArgs call_args, NextPromiseFactory next_promise_factory) {
|
284
|
+
auto decompress_args =
|
285
|
+
HandleIncomingMetadata(*call_args.client_initial_metadata);
|
286
|
+
auto* decompress_err =
|
287
|
+
GetContext<Arena>()->New<Latch<ServerMetadataHandle>>();
|
288
|
+
call_args.client_to_server_messages->InterceptAndMap(
|
289
|
+
[decompress_err, decompress_args,
|
290
|
+
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
291
|
+
auto r = DecompressMessage(std::move(message), decompress_args);
|
292
|
+
if (grpc_call_trace.enabled()) {
|
293
|
+
gpr_log(GPR_DEBUG, "%s[compression] DecompressMessage returned %s",
|
294
|
+
Activity::current()->DebugTag().c_str(),
|
295
|
+
r.status().ToString().c_str());
|
296
|
+
}
|
297
|
+
if (!r.ok()) {
|
298
|
+
decompress_err->Set(ServerMetadataFromStatus(r.status()));
|
299
|
+
return absl::nullopt;
|
300
|
+
}
|
301
|
+
return std::move(*r);
|
302
|
+
});
|
303
|
+
auto* compression_algorithm =
|
304
|
+
GetContext<Arena>()->New<grpc_compression_algorithm>();
|
305
|
+
call_args.server_initial_metadata->InterceptAndMap(
|
306
|
+
[this, compression_algorithm](ServerMetadataHandle md) {
|
307
|
+
if (grpc_call_trace.enabled()) {
|
308
|
+
gpr_log(GPR_INFO, "%s[compression] Write metadata",
|
309
|
+
Activity::current()->DebugTag().c_str());
|
310
|
+
}
|
311
|
+
// Find the compression algorithm.
|
312
|
+
*compression_algorithm = HandleOutgoingMetadata(*md);
|
313
|
+
return md;
|
314
|
+
});
|
315
|
+
call_args.server_to_client_messages->InterceptAndMap(
|
316
|
+
[compression_algorithm,
|
317
|
+
this](MessageHandle message) -> absl::optional<MessageHandle> {
|
318
|
+
return CompressMessage(std::move(message), *compression_algorithm);
|
319
|
+
});
|
320
|
+
// Run the next filter, and race it with getting an error from decompression.
|
321
|
+
return PrioritizedRace(decompress_err->Wait(),
|
322
|
+
next_promise_factory(std::move(call_args)));
|
323
|
+
}
|
324
|
+
|
325
|
+
} // namespace grpc_core
|