grpc 1.60.2 → 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 +68 -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/hpack_parser.cc +27 -36
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +0 -2
- 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
@@ -42,19 +42,55 @@ namespace grpc_core {
|
|
42
42
|
|
43
43
|
namespace {
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
class ServerCallTracerFilter : public ChannelFilter {
|
45
|
+
class ServerCallTracerFilter
|
46
|
+
: public ImplementChannelFilter<ServerCallTracerFilter> {
|
48
47
|
public:
|
49
48
|
static const grpc_channel_filter kFilter;
|
50
49
|
|
51
50
|
static absl::StatusOr<ServerCallTracerFilter> Create(
|
52
51
|
const ChannelArgs& /*args*/, ChannelFilter::Args /*filter_args*/);
|
53
52
|
|
54
|
-
|
55
|
-
|
53
|
+
class Call {
|
54
|
+
public:
|
55
|
+
void OnClientInitialMetadata(ClientMetadata& client_initial_metadata) {
|
56
|
+
auto* call_tracer = CallTracer();
|
57
|
+
if (call_tracer == nullptr) return;
|
58
|
+
call_tracer->RecordReceivedInitialMetadata(&client_initial_metadata);
|
59
|
+
}
|
60
|
+
|
61
|
+
void OnServerInitialMetadata(ServerMetadata& server_initial_metadata) {
|
62
|
+
auto* call_tracer = CallTracer();
|
63
|
+
if (call_tracer == nullptr) return;
|
64
|
+
call_tracer->RecordSendInitialMetadata(&server_initial_metadata);
|
65
|
+
}
|
66
|
+
|
67
|
+
void OnFinalize(const grpc_call_final_info* final_info) {
|
68
|
+
auto* call_tracer = CallTracer();
|
69
|
+
if (call_tracer == nullptr) return;
|
70
|
+
call_tracer->RecordEnd(final_info);
|
71
|
+
}
|
72
|
+
|
73
|
+
void OnServerTrailingMetadata(ServerMetadata& server_trailing_metadata) {
|
74
|
+
auto* call_tracer = CallTracer();
|
75
|
+
if (call_tracer == nullptr) return;
|
76
|
+
call_tracer->RecordSendTrailingMetadata(&server_trailing_metadata);
|
77
|
+
}
|
78
|
+
|
79
|
+
static const NoInterceptor OnClientToServerMessage;
|
80
|
+
static const NoInterceptor OnServerToClientMessage;
|
81
|
+
|
82
|
+
private:
|
83
|
+
static ServerCallTracer* CallTracer() {
|
84
|
+
auto* call_context = GetContext<grpc_call_context_element>();
|
85
|
+
return static_cast<ServerCallTracer*>(
|
86
|
+
call_context[GRPC_CONTEXT_CALL_TRACER].value);
|
87
|
+
}
|
88
|
+
};
|
56
89
|
};
|
57
90
|
|
91
|
+
const NoInterceptor ServerCallTracerFilter::Call::OnClientToServerMessage;
|
92
|
+
const NoInterceptor ServerCallTracerFilter::Call::OnServerToClientMessage;
|
93
|
+
|
58
94
|
const grpc_channel_filter ServerCallTracerFilter::kFilter =
|
59
95
|
MakePromiseBasedFilter<ServerCallTracerFilter, FilterEndpoint::kServer,
|
60
96
|
kFilterExaminesServerInitialMetadata>(
|
@@ -65,39 +101,11 @@ absl::StatusOr<ServerCallTracerFilter> ServerCallTracerFilter::Create(
|
|
65
101
|
return ServerCallTracerFilter();
|
66
102
|
}
|
67
103
|
|
68
|
-
ArenaPromise<ServerMetadataHandle> ServerCallTracerFilter::MakeCallPromise(
|
69
|
-
CallArgs call_args, NextPromiseFactory next_promise_factory) {
|
70
|
-
auto* call_context = GetContext<grpc_call_context_element>();
|
71
|
-
auto* call_tracer = static_cast<ServerCallTracer*>(
|
72
|
-
call_context[GRPC_CONTEXT_CALL_TRACER].value);
|
73
|
-
if (call_tracer == nullptr) {
|
74
|
-
return next_promise_factory(std::move(call_args));
|
75
|
-
}
|
76
|
-
call_tracer->RecordReceivedInitialMetadata(
|
77
|
-
call_args.client_initial_metadata.get());
|
78
|
-
call_args.server_initial_metadata->InterceptAndMap(
|
79
|
-
[call_tracer](ServerMetadataHandle metadata) {
|
80
|
-
call_tracer->RecordSendInitialMetadata(metadata.get());
|
81
|
-
return metadata;
|
82
|
-
});
|
83
|
-
GetContext<CallFinalization>()->Add(
|
84
|
-
[call_tracer](const grpc_call_final_info* final_info) {
|
85
|
-
call_tracer->RecordEnd(final_info);
|
86
|
-
});
|
87
|
-
return OnCancel(
|
88
|
-
Map(next_promise_factory(std::move(call_args)),
|
89
|
-
[call_tracer](ServerMetadataHandle md) {
|
90
|
-
call_tracer->RecordSendTrailingMetadata(md.get());
|
91
|
-
return md;
|
92
|
-
}),
|
93
|
-
[call_tracer]() { call_tracer->RecordCancel(absl::CancelledError()); });
|
94
|
-
}
|
95
|
-
|
96
104
|
} // namespace
|
97
105
|
|
98
106
|
void RegisterServerCallTracerFilter(CoreConfiguration::Builder* builder) {
|
99
|
-
builder->channel_init()->RegisterFilter(
|
100
|
-
|
107
|
+
builder->channel_init()->RegisterFilter<ServerCallTracerFilter>(
|
108
|
+
GRPC_SERVER_CHANNEL);
|
101
109
|
}
|
102
110
|
|
103
111
|
} // namespace grpc_core
|
@@ -36,7 +36,6 @@
|
|
36
36
|
#include "src/core/lib/gprpp/crash.h"
|
37
37
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
38
38
|
#include "src/core/lib/gprpp/ref_counted_string.h"
|
39
|
-
#include "src/core/lib/surface/api_trace.h"
|
40
39
|
|
41
40
|
namespace grpc_core {
|
42
41
|
|
@@ -112,8 +111,6 @@ absl::optional<grpc_compression_algorithm> ParseCompressionAlgorithm(
|
|
112
111
|
grpc_compression_algorithm
|
113
112
|
CompressionAlgorithmSet::CompressionAlgorithmForLevel(
|
114
113
|
grpc_compression_level level) const {
|
115
|
-
GRPC_API_TRACE("grpc_message_compression_algorithm_for_level(level=%d)", 1,
|
116
|
-
((int)level));
|
117
114
|
if (level > GRPC_COMPRESS_LEVEL_HIGH) {
|
118
115
|
Crash(absl::StrFormat("Unknown message compression level %d.",
|
119
116
|
static_cast<int>(level)));
|
@@ -193,7 +193,7 @@ AresResolver::CreateAresResolver(
|
|
193
193
|
AresResolver::AresResolver(
|
194
194
|
std::unique_ptr<GrpcPolledFdFactory> polled_fd_factory,
|
195
195
|
std::shared_ptr<EventEngine> event_engine, ares_channel channel)
|
196
|
-
:
|
196
|
+
: RefCountedDNSResolverInterface(
|
197
197
|
GRPC_TRACE_FLAG_ENABLED(grpc_trace_ares_resolver) ? "AresResolver"
|
198
198
|
: nullptr),
|
199
199
|
channel_(channel),
|
@@ -230,8 +230,8 @@ void AresResolver::Orphan() {
|
|
230
230
|
}
|
231
231
|
|
232
232
|
void AresResolver::LookupHostname(
|
233
|
-
|
234
|
-
|
233
|
+
EventEngine::DNSResolver::LookupHostnameCallback callback,
|
234
|
+
absl::string_view name, absl::string_view default_port) {
|
235
235
|
absl::string_view host;
|
236
236
|
absl::string_view port_string;
|
237
237
|
if (!grpc_core::SplitHostPort(name, &host, &port_string)) {
|
@@ -241,7 +241,13 @@ void AresResolver::LookupHostname(
|
|
241
241
|
"Unparseable name: ", name))]() mutable { callback(status); });
|
242
242
|
return;
|
243
243
|
}
|
244
|
-
|
244
|
+
if (host.empty()) {
|
245
|
+
event_engine_->Run([callback = std::move(callback),
|
246
|
+
status = absl::InvalidArgumentError(absl::StrCat(
|
247
|
+
"host must not be empty in name: ",
|
248
|
+
name))]() mutable { callback(status); });
|
249
|
+
return;
|
250
|
+
}
|
245
251
|
if (port_string.empty()) {
|
246
252
|
if (default_port.empty()) {
|
247
253
|
event_engine_->Run([callback = std::move(callback),
|
@@ -296,8 +302,8 @@ void AresResolver::LookupHostname(
|
|
296
302
|
}
|
297
303
|
|
298
304
|
void AresResolver::LookupSRV(
|
299
|
-
|
300
|
-
|
305
|
+
EventEngine::DNSResolver::LookupSRVCallback callback,
|
306
|
+
absl::string_view name) {
|
301
307
|
absl::string_view host;
|
302
308
|
absl::string_view port;
|
303
309
|
if (!grpc_core::SplitHostPort(name, &host, &port)) {
|
@@ -307,7 +313,13 @@ void AresResolver::LookupSRV(
|
|
307
313
|
"Unparseable name: ", name))]() mutable { callback(status); });
|
308
314
|
return;
|
309
315
|
}
|
310
|
-
|
316
|
+
if (host.empty()) {
|
317
|
+
event_engine_->Run([callback = std::move(callback),
|
318
|
+
status = absl::InvalidArgumentError(absl::StrCat(
|
319
|
+
"host must not be empty in name: ",
|
320
|
+
name))]() mutable { callback(status); });
|
321
|
+
return;
|
322
|
+
}
|
311
323
|
// Don't query for SRV records if the target is "localhost"
|
312
324
|
if (absl::EqualsIgnoreCase(host, "localhost")) {
|
313
325
|
event_engine_->Run([callback = std::move(callback)]() mutable {
|
@@ -325,8 +337,8 @@ void AresResolver::LookupSRV(
|
|
325
337
|
}
|
326
338
|
|
327
339
|
void AresResolver::LookupTXT(
|
328
|
-
|
329
|
-
|
340
|
+
EventEngine::DNSResolver::LookupTXTCallback callback,
|
341
|
+
absl::string_view name) {
|
330
342
|
absl::string_view host;
|
331
343
|
absl::string_view port;
|
332
344
|
if (!grpc_core::SplitHostPort(name, &host, &port)) {
|
@@ -336,7 +348,13 @@ void AresResolver::LookupTXT(
|
|
336
348
|
"Unparseable name: ", name))]() mutable { callback(status); });
|
337
349
|
return;
|
338
350
|
}
|
339
|
-
|
351
|
+
if (host.empty()) {
|
352
|
+
event_engine_->Run([callback = std::move(callback),
|
353
|
+
status = absl::InvalidArgumentError(absl::StrCat(
|
354
|
+
"host must not be empty in name: ",
|
355
|
+
name))]() mutable { callback(status); });
|
356
|
+
return;
|
357
|
+
}
|
340
358
|
// Don't query for TXT records if the target is "localhost"
|
341
359
|
if (absl::EqualsIgnoreCase(host, "localhost")) {
|
342
360
|
event_engine_->Run([callback = std::move(callback)]() mutable {
|
@@ -387,7 +405,8 @@ void AresResolver::CheckSocketsLocked() {
|
|
387
405
|
event_engine_->Run(
|
388
406
|
[self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"),
|
389
407
|
fd_node]() mutable {
|
390
|
-
self
|
408
|
+
static_cast<AresResolver*>(self.get())
|
409
|
+
->OnReadable(fd_node, absl::OkStatus());
|
391
410
|
});
|
392
411
|
} else {
|
393
412
|
// Otherwise register with the poller for readable event.
|
@@ -396,7 +415,8 @@ void AresResolver::CheckSocketsLocked() {
|
|
396
415
|
fd_node->polled_fd->RegisterForOnReadableLocked(
|
397
416
|
[self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"),
|
398
417
|
fd_node](absl::Status status) mutable {
|
399
|
-
self
|
418
|
+
static_cast<AresResolver*>(self.get())
|
419
|
+
->OnReadable(fd_node, status);
|
400
420
|
});
|
401
421
|
}
|
402
422
|
}
|
@@ -410,7 +430,8 @@ void AresResolver::CheckSocketsLocked() {
|
|
410
430
|
fd_node->polled_fd->RegisterForOnWriteableLocked(
|
411
431
|
[self = Ref(DEBUG_LOCATION, "CheckSocketsLocked"),
|
412
432
|
fd_node](absl::Status status) mutable {
|
413
|
-
self
|
433
|
+
static_cast<AresResolver*>(self.get())
|
434
|
+
->OnWritable(fd_node, status);
|
414
435
|
});
|
415
436
|
}
|
416
437
|
}
|
@@ -453,7 +474,7 @@ void AresResolver::MaybeStartTimerLocked() {
|
|
453
474
|
ares_backup_poll_alarm_handle_ = event_engine_->RunAfter(
|
454
475
|
kAresBackupPollAlarmDuration,
|
455
476
|
[self = Ref(DEBUG_LOCATION, "MaybeStartTimerLocked")]() {
|
456
|
-
self->OnAresBackupPollAlarm();
|
477
|
+
static_cast<AresResolver*>(self.get())->OnAresBackupPollAlarm();
|
457
478
|
});
|
458
479
|
}
|
459
480
|
|
@@ -39,6 +39,7 @@
|
|
39
39
|
#include <grpc/support/log.h>
|
40
40
|
|
41
41
|
#include "src/core/lib/event_engine/grpc_polled_fd.h"
|
42
|
+
#include "src/core/lib/event_engine/ref_counted_dns_resolver_interface.h"
|
42
43
|
#include "src/core/lib/gprpp/orphanable.h"
|
43
44
|
#include "src/core/lib/gprpp/sync.h"
|
44
45
|
|
@@ -54,7 +55,7 @@ extern grpc_core::TraceFlag grpc_trace_ares_resolver;
|
|
54
55
|
} \
|
55
56
|
} while (0)
|
56
57
|
|
57
|
-
class AresResolver : public
|
58
|
+
class AresResolver : public RefCountedDNSResolverInterface {
|
58
59
|
public:
|
59
60
|
static absl::StatusOr<grpc_core::OrphanablePtr<AresResolver>>
|
60
61
|
CreateAresResolver(absl::string_view dns_server,
|
@@ -67,15 +68,13 @@ class AresResolver : public grpc_core::InternallyRefCounted<AresResolver> {
|
|
67
68
|
~AresResolver() override;
|
68
69
|
void Orphan() override ABSL_LOCKS_EXCLUDED(mutex_);
|
69
70
|
|
70
|
-
void LookupHostname(
|
71
|
-
|
72
|
-
ABSL_LOCKS_EXCLUDED(mutex_);
|
73
|
-
void LookupSRV(
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
EventEngine::DNSResolver::LookupTXTCallback callback)
|
78
|
-
ABSL_LOCKS_EXCLUDED(mutex_);
|
71
|
+
void LookupHostname(EventEngine::DNSResolver::LookupHostnameCallback callback,
|
72
|
+
absl::string_view name, absl::string_view default_port)
|
73
|
+
ABSL_LOCKS_EXCLUDED(mutex_) override;
|
74
|
+
void LookupSRV(EventEngine::DNSResolver::LookupSRVCallback callback,
|
75
|
+
absl::string_view name) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
76
|
+
void LookupTXT(EventEngine::DNSResolver::LookupTXTCallback callback,
|
77
|
+
absl::string_view name) ABSL_LOCKS_EXCLUDED(mutex_) override;
|
79
78
|
|
80
79
|
private:
|
81
80
|
// A FdNode saves (not owns) a live socket/fd which c-ares creates, and owns a
|
@@ -50,7 +50,14 @@ void DNSServiceResolverImpl::LookupHostname(
|
|
50
50
|
});
|
51
51
|
return;
|
52
52
|
}
|
53
|
-
|
53
|
+
if (host.empty()) {
|
54
|
+
engine_->Run([on_resolve = std::move(on_resolve),
|
55
|
+
status = absl::InvalidArgumentError(absl::StrCat(
|
56
|
+
"host must not be empty in name: ", name))]() mutable {
|
57
|
+
on_resolve(status);
|
58
|
+
});
|
59
|
+
return;
|
60
|
+
}
|
54
61
|
if (port_string.empty()) {
|
55
62
|
if (default_port.empty()) {
|
56
63
|
engine_->Run([on_resolve = std::move(on_resolve),
|
@@ -0,0 +1,132 @@
|
|
1
|
+
// Copyright 2023 The 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/lib/iomgr/port.h"
|
18
|
+
|
19
|
+
#ifdef GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
20
|
+
|
21
|
+
#include <netdb.h>
|
22
|
+
#include <string.h>
|
23
|
+
#include <sys/socket.h>
|
24
|
+
|
25
|
+
#include <string>
|
26
|
+
#include <type_traits>
|
27
|
+
#include <utility>
|
28
|
+
#include <vector>
|
29
|
+
|
30
|
+
#include "absl/functional/any_invocable.h"
|
31
|
+
#include "absl/status/status.h"
|
32
|
+
#include "absl/status/statusor.h"
|
33
|
+
#include "absl/strings/str_cat.h"
|
34
|
+
#include "absl/strings/str_format.h"
|
35
|
+
|
36
|
+
#include "src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h"
|
37
|
+
#include "src/core/lib/gpr/useful.h"
|
38
|
+
#include "src/core/lib/gprpp/host_port.h"
|
39
|
+
|
40
|
+
namespace grpc_event_engine {
|
41
|
+
namespace experimental {
|
42
|
+
namespace {
|
43
|
+
|
44
|
+
absl::StatusOr<std::vector<EventEngine::ResolvedAddress>>
|
45
|
+
LookupHostnameBlocking(absl::string_view name, absl::string_view default_port) {
|
46
|
+
struct addrinfo hints;
|
47
|
+
struct addrinfo *result = nullptr, *resp;
|
48
|
+
std::string host;
|
49
|
+
std::string port;
|
50
|
+
// parse name, splitting it into host and port parts
|
51
|
+
grpc_core::SplitHostPort(name, &host, &port);
|
52
|
+
if (host.empty()) {
|
53
|
+
return absl::InvalidArgumentError(absl::StrCat("Unparseable name: ", name));
|
54
|
+
}
|
55
|
+
if (port.empty()) {
|
56
|
+
if (default_port.empty()) {
|
57
|
+
return absl::InvalidArgumentError(
|
58
|
+
absl::StrFormat("No port in name %s or default_port argument", name));
|
59
|
+
}
|
60
|
+
port = std::string(default_port);
|
61
|
+
}
|
62
|
+
// Call getaddrinfo
|
63
|
+
memset(&hints, 0, sizeof(hints));
|
64
|
+
hints.ai_family = AF_UNSPEC; // ipv4 or ipv6
|
65
|
+
hints.ai_socktype = SOCK_STREAM; // stream socket
|
66
|
+
hints.ai_flags = AI_PASSIVE; // for wildcard IP address
|
67
|
+
int s = getaddrinfo(host.c_str(), port.c_str(), &hints, &result);
|
68
|
+
if (s != 0) {
|
69
|
+
// Retry if well-known service name is recognized
|
70
|
+
const char* svc[][2] = {{"http", "80"}, {"https", "443"}};
|
71
|
+
for (size_t i = 0; i < GPR_ARRAY_SIZE(svc); i++) {
|
72
|
+
if (port == svc[i][0]) {
|
73
|
+
s = getaddrinfo(host.c_str(), svc[i][1], &hints, &result);
|
74
|
+
break;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
}
|
78
|
+
if (s != 0) {
|
79
|
+
return absl::UnknownError(absl::StrFormat(
|
80
|
+
"Address lookup failed for %s os_error: %s syscall: getaddrinfo", name,
|
81
|
+
gai_strerror(s)));
|
82
|
+
}
|
83
|
+
// Success path: fill in addrs
|
84
|
+
std::vector<EventEngine::ResolvedAddress> addresses;
|
85
|
+
for (resp = result; resp != nullptr; resp = resp->ai_next) {
|
86
|
+
addresses.emplace_back(resp->ai_addr, resp->ai_addrlen);
|
87
|
+
}
|
88
|
+
if (result) {
|
89
|
+
freeaddrinfo(result);
|
90
|
+
}
|
91
|
+
return addresses;
|
92
|
+
}
|
93
|
+
|
94
|
+
} // namespace
|
95
|
+
|
96
|
+
NativePosixDNSResolver::NativePosixDNSResolver(
|
97
|
+
std::shared_ptr<EventEngine> event_engine)
|
98
|
+
: event_engine_(std::move(event_engine)) {}
|
99
|
+
|
100
|
+
void NativePosixDNSResolver::LookupHostname(
|
101
|
+
EventEngine::DNSResolver::LookupHostnameCallback on_resolved,
|
102
|
+
absl::string_view name, absl::string_view default_port) {
|
103
|
+
event_engine_->Run(
|
104
|
+
[name, default_port, on_resolved = std::move(on_resolved)]() mutable {
|
105
|
+
on_resolved(LookupHostnameBlocking(name, default_port));
|
106
|
+
});
|
107
|
+
}
|
108
|
+
|
109
|
+
void NativePosixDNSResolver::LookupSRV(
|
110
|
+
EventEngine::DNSResolver::LookupSRVCallback on_resolved,
|
111
|
+
absl::string_view /* name */) {
|
112
|
+
// Not supported
|
113
|
+
event_engine_->Run([on_resolved = std::move(on_resolved)]() mutable {
|
114
|
+
on_resolved(absl::UnimplementedError(
|
115
|
+
"The Native resolver does not support looking up SRV records"));
|
116
|
+
});
|
117
|
+
}
|
118
|
+
|
119
|
+
void NativePosixDNSResolver::LookupTXT(
|
120
|
+
EventEngine::DNSResolver::LookupTXTCallback on_resolved,
|
121
|
+
absl::string_view /* name */) {
|
122
|
+
// Not supported
|
123
|
+
event_engine_->Run([on_resolved = std::move(on_resolved)]() mutable {
|
124
|
+
on_resolved(absl::UnimplementedError(
|
125
|
+
"The Native resolver does not support looking up TXT records"));
|
126
|
+
});
|
127
|
+
}
|
128
|
+
|
129
|
+
} // namespace experimental
|
130
|
+
} // namespace grpc_event_engine
|
131
|
+
|
132
|
+
#endif // GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
@@ -0,0 +1,61 @@
|
|
1
|
+
// Copyright 2023 The 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
|
+
#ifndef GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_NATIVE_POSIX_DNS_RESOLVER_H
|
16
|
+
#define GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_NATIVE_POSIX_DNS_RESOLVER_H
|
17
|
+
|
18
|
+
#include <grpc/support/port_platform.h>
|
19
|
+
|
20
|
+
#include <memory>
|
21
|
+
|
22
|
+
#include "absl/strings/string_view.h"
|
23
|
+
|
24
|
+
#include "src/core/lib/iomgr/port.h"
|
25
|
+
|
26
|
+
#ifdef GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
27
|
+
|
28
|
+
#include <grpc/event_engine/event_engine.h>
|
29
|
+
|
30
|
+
#include "src/core/lib/event_engine/ref_counted_dns_resolver_interface.h"
|
31
|
+
|
32
|
+
namespace grpc_event_engine {
|
33
|
+
namespace experimental {
|
34
|
+
|
35
|
+
// An asynchronous DNS resolver which uses the native platform's getaddrinfo
|
36
|
+
// API. Only supports A/AAAA records.
|
37
|
+
class NativePosixDNSResolver : public RefCountedDNSResolverInterface {
|
38
|
+
public:
|
39
|
+
explicit NativePosixDNSResolver(std::shared_ptr<EventEngine> event_engine);
|
40
|
+
|
41
|
+
void LookupHostname(
|
42
|
+
EventEngine::DNSResolver::LookupHostnameCallback on_resolved,
|
43
|
+
absl::string_view name, absl::string_view default_port) override;
|
44
|
+
|
45
|
+
void LookupSRV(EventEngine::DNSResolver::LookupSRVCallback on_resolved,
|
46
|
+
absl::string_view name) override;
|
47
|
+
|
48
|
+
void LookupTXT(EventEngine::DNSResolver::LookupTXTCallback on_resolved,
|
49
|
+
absl::string_view name) override;
|
50
|
+
|
51
|
+
void Orphan() override { delete this; }
|
52
|
+
|
53
|
+
private:
|
54
|
+
std::shared_ptr<EventEngine> event_engine_;
|
55
|
+
};
|
56
|
+
|
57
|
+
} // namespace experimental
|
58
|
+
} // namespace grpc_event_engine
|
59
|
+
|
60
|
+
#endif // GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
61
|
+
#endif // GRPC_SRC_CORE_LIB_EVENT_ENGINE_POSIX_ENGINE_NATIVE_POSIX_DNS_RESOLVER_H
|
@@ -28,6 +28,7 @@
|
|
28
28
|
#include "absl/cleanup/cleanup.h"
|
29
29
|
#include "absl/functional/any_invocable.h"
|
30
30
|
#include "absl/status/status.h"
|
31
|
+
#include "absl/strings/match.h"
|
31
32
|
#include "absl/strings/str_cat.h"
|
32
33
|
|
33
34
|
#include <grpc/event_engine/event_engine.h>
|
@@ -36,12 +37,15 @@
|
|
36
37
|
#include <grpc/support/cpu.h>
|
37
38
|
#include <grpc/support/log.h>
|
38
39
|
|
40
|
+
#include "src/core/lib/config/config_vars.h"
|
39
41
|
#include "src/core/lib/debug/trace.h"
|
42
|
+
#include "src/core/lib/event_engine/ares_resolver.h"
|
40
43
|
#include "src/core/lib/event_engine/forkable.h"
|
41
44
|
#include "src/core/lib/event_engine/grpc_polled_fd.h"
|
42
45
|
#include "src/core/lib/event_engine/poller.h"
|
43
46
|
#include "src/core/lib/event_engine/posix.h"
|
44
47
|
#include "src/core/lib/event_engine/posix_engine/grpc_polled_fd_posix.h"
|
48
|
+
#include "src/core/lib/event_engine/posix_engine/native_posix_dns_resolver.h"
|
45
49
|
#include "src/core/lib/event_engine/posix_engine/tcp_socket_utils.h"
|
46
50
|
#include "src/core/lib/event_engine/posix_engine/timer.h"
|
47
51
|
#include "src/core/lib/event_engine/tcp_socket_utils.h"
|
@@ -90,6 +94,15 @@ class TimerForkCallbackMethods {
|
|
90
94
|
static void PostforkChild() { g_timer_fork_manager->PostforkChild(); }
|
91
95
|
};
|
92
96
|
|
97
|
+
bool ShouldUseAresDnsResolver() {
|
98
|
+
#if GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_ARES_EV_DRIVER)
|
99
|
+
auto resolver_env = grpc_core::ConfigVars::Get().DnsResolver();
|
100
|
+
return resolver_env.empty() || absl::EqualsIgnoreCase(resolver_env, "ares");
|
101
|
+
#else // GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_ARES_EV_DRIVER)
|
102
|
+
return false;
|
103
|
+
#endif // GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_ARES_EV_DRIVER)
|
104
|
+
}
|
105
|
+
|
93
106
|
} // namespace
|
94
107
|
|
95
108
|
#ifdef GRPC_POSIX_SOCKET_TCP
|
@@ -242,11 +255,11 @@ EventEngine::ConnectionHandle PosixEventEngine::ConnectInternal(
|
|
242
255
|
MemoryAllocator&& allocator, const PosixTcpOptions& options,
|
243
256
|
Duration timeout) {
|
244
257
|
int err;
|
245
|
-
int
|
258
|
+
int connect_errno;
|
246
259
|
do {
|
247
260
|
err = connect(sock.Fd(), addr.address(), addr.size());
|
248
261
|
} while (err < 0 && errno == EINTR);
|
249
|
-
|
262
|
+
connect_errno = (err < 0) ? errno : 0;
|
250
263
|
|
251
264
|
auto addr_uri = ResolvedAddressToURI(addr);
|
252
265
|
if (!addr_uri.ok()) {
|
@@ -261,13 +274,8 @@ EventEngine::ConnectionHandle PosixEventEngine::ConnectInternal(
|
|
261
274
|
PosixEventPoller* poller = poller_manager_->Poller();
|
262
275
|
EventHandle* handle =
|
263
276
|
poller->CreateHandle(sock.Fd(), name, poller->CanTrackErrors());
|
264
|
-
int64_t connection_id = 0;
|
265
|
-
if (saved_errno == EWOULDBLOCK || saved_errno == EINPROGRESS) {
|
266
|
-
// Connection is still in progress.
|
267
|
-
connection_id = last_connection_id_.fetch_add(1, std::memory_order_acq_rel);
|
268
|
-
}
|
269
277
|
|
270
|
-
if (
|
278
|
+
if (connect_errno == 0) {
|
271
279
|
// Connection already succeded. Return 0 to discourage any cancellation
|
272
280
|
// attempts.
|
273
281
|
Run([on_connect = std::move(on_connect),
|
@@ -277,18 +285,21 @@ EventEngine::ConnectionHandle PosixEventEngine::ConnectInternal(
|
|
277
285
|
});
|
278
286
|
return EventEngine::ConnectionHandle::kInvalid;
|
279
287
|
}
|
280
|
-
if (
|
288
|
+
if (connect_errno != EWOULDBLOCK && connect_errno != EINPROGRESS) {
|
281
289
|
// Connection already failed. Return 0 to discourage any cancellation
|
282
290
|
// attempts.
|
283
291
|
handle->OrphanHandle(nullptr, nullptr, "tcp_client_connect_error");
|
284
292
|
Run([on_connect = std::move(on_connect),
|
285
|
-
ep = absl::FailedPreconditionError(
|
286
|
-
|
287
|
-
|
293
|
+
ep = absl::FailedPreconditionError(absl::StrCat(
|
294
|
+
"connect failed: ", "addr: ", addr_uri.value(),
|
295
|
+
" error: ", std::strerror(connect_errno)))]() mutable {
|
288
296
|
on_connect(std::move(ep));
|
289
297
|
});
|
290
298
|
return EventEngine::ConnectionHandle::kInvalid;
|
291
299
|
}
|
300
|
+
// Connection is still in progress.
|
301
|
+
int64_t connection_id =
|
302
|
+
last_connection_id_.fetch_add(1, std::memory_order_acq_rel);
|
292
303
|
AsyncConnect* ac = new AsyncConnect(
|
293
304
|
std::move(on_connect), shared_from_this(), executor_.get(), handle,
|
294
305
|
std::move(allocator), options, addr_uri.value(), connection_id);
|
@@ -517,49 +528,54 @@ EventEngine::TaskHandle PosixEventEngine::RunAfterInternal(
|
|
517
528
|
return handle;
|
518
529
|
}
|
519
530
|
|
520
|
-
#if GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_TCP)
|
521
|
-
|
522
531
|
PosixEventEngine::PosixDNSResolver::PosixDNSResolver(
|
523
|
-
grpc_core::OrphanablePtr<
|
524
|
-
:
|
532
|
+
grpc_core::OrphanablePtr<RefCountedDNSResolverInterface> dns_resolver)
|
533
|
+
: dns_resolver_(std::move(dns_resolver)) {}
|
525
534
|
|
526
535
|
void PosixEventEngine::PosixDNSResolver::LookupHostname(
|
527
536
|
LookupHostnameCallback on_resolve, absl::string_view name,
|
528
537
|
absl::string_view default_port) {
|
529
|
-
|
538
|
+
dns_resolver_->LookupHostname(std::move(on_resolve), name, default_port);
|
530
539
|
}
|
531
540
|
|
532
541
|
void PosixEventEngine::PosixDNSResolver::LookupSRV(LookupSRVCallback on_resolve,
|
533
542
|
absl::string_view name) {
|
534
|
-
|
543
|
+
dns_resolver_->LookupSRV(std::move(on_resolve), name);
|
535
544
|
}
|
536
545
|
|
537
546
|
void PosixEventEngine::PosixDNSResolver::LookupTXT(LookupTXTCallback on_resolve,
|
538
547
|
absl::string_view name) {
|
539
|
-
|
548
|
+
dns_resolver_->LookupTXT(std::move(on_resolve), name);
|
540
549
|
}
|
541
550
|
|
542
|
-
#endif // GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_TCP)
|
543
|
-
|
544
551
|
absl::StatusOr<std::unique_ptr<EventEngine::DNSResolver>>
|
545
552
|
PosixEventEngine::GetDNSResolver(
|
546
|
-
const EventEngine::DNSResolver::ResolverOptions& options) {
|
547
|
-
#
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
if (
|
553
|
-
|
553
|
+
GRPC_UNUSED const EventEngine::DNSResolver::ResolverOptions& options) {
|
554
|
+
#ifndef GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
555
|
+
grpc_core::Crash("Unable to get DNS resolver for this platform.");
|
556
|
+
#else // GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
557
|
+
// If c-ares is supported on the platform, build according to user's
|
558
|
+
// configuration.
|
559
|
+
if (ShouldUseAresDnsResolver()) {
|
560
|
+
#if GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_ARES_EV_DRIVER)
|
561
|
+
GRPC_EVENT_ENGINE_DNS_TRACE("PosixEventEngine:%p creating AresResolver",
|
562
|
+
this);
|
563
|
+
auto ares_resolver = AresResolver::CreateAresResolver(
|
564
|
+
options.dns_server,
|
565
|
+
std::make_unique<GrpcPolledFdFactoryPosix>(poller_manager_->Poller()),
|
566
|
+
shared_from_this());
|
567
|
+
if (!ares_resolver.ok()) {
|
568
|
+
return ares_resolver.status();
|
569
|
+
}
|
570
|
+
return std::make_unique<PosixEventEngine::PosixDNSResolver>(
|
571
|
+
std::move(*ares_resolver));
|
572
|
+
#endif // GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_ARES_EV_DRIVER)
|
554
573
|
}
|
574
|
+
GRPC_EVENT_ENGINE_DNS_TRACE(
|
575
|
+
"PosixEventEngine:%p creating NativePosixDNSResolver", this);
|
555
576
|
return std::make_unique<PosixEventEngine::PosixDNSResolver>(
|
556
|
-
|
557
|
-
#
|
558
|
-
// TODO(yijiem): Implement a basic A/AAAA-only native resolver in
|
559
|
-
// PosixEventEngine.
|
560
|
-
(void)options;
|
561
|
-
grpc_core::Crash("unimplemented");
|
562
|
-
#endif // GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET_TCP)
|
577
|
+
grpc_core::MakeOrphanable<NativePosixDNSResolver>(shared_from_this()));
|
578
|
+
#endif // GRPC_POSIX_SOCKET_RESOLVE_ADDRESS
|
563
579
|
}
|
564
580
|
|
565
581
|
bool PosixEventEngine::IsWorkerThread() { grpc_core::Crash("unimplemented"); }
|