grpc 1.83.1 → 1.84.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Makefile +21 -17
- data/include/grpc/credentials.h +10 -0
- data/include/grpc/grpc_security_constants.h +2 -0
- data/include/grpc/impl/channel_arg_names.h +9 -0
- data/src/core/call/call_filters.h +4 -2
- data/src/core/call/client_call.cc +20 -8
- data/src/core/call/client_call.h +4 -0
- data/src/core/call/interception_chain.cc +2 -0
- data/src/core/call/interception_chain.h +14 -1
- data/src/core/call/metadata.cc +1 -3
- data/src/core/call/metadata_batch.h +13 -5
- data/src/core/call/server_call.cc +31 -14
- data/src/core/call/server_call.h +4 -0
- data/src/core/channelz/text_encode.cc +9 -4
- data/src/core/channelz/v2tov1/convert.cc +2 -2
- data/src/core/client_channel/backup_poller.cc +1 -2
- data/src/core/client_channel/client_channel.cc +6 -33
- data/src/core/client_channel/client_channel_filter.cc +22 -55
- data/src/core/client_channel/client_channel_filter.h +2 -2
- data/src/core/client_channel/client_channel_service_config.cc +3 -19
- data/src/core/client_channel/direct_channel.cc +7 -1
- data/src/core/client_channel/direct_channel.h +2 -2
- data/src/core/client_channel/load_balanced_call_destination.cc +5 -3
- data/src/core/client_channel/retry_filter_legacy_call_data.cc +5 -12
- data/src/core/client_channel/subchannel.cc +310 -1058
- data/src/core/client_channel/subchannel.h +44 -329
- data/src/core/client_channel/subchannel_metrics.cc +48 -0
- data/src/core/client_channel/subchannel_metrics.h +60 -0
- data/src/core/credentials/call/external/file_external_account_credentials.cc +1 -1
- data/src/core/credentials/call/external/url_external_account_credentials.cc +2 -3
- data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.cc +8 -24
- data/src/core/credentials/call/gcp_service_account_identity/gcp_service_account_identity_credentials.h +3 -6
- data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.cc +525 -0
- data/src/core/credentials/call/gdch_service_account/gdch_service_account_credentials.h +138 -0
- data/src/core/credentials/call/json_util.h +1 -0
- data/src/core/credentials/call/jwt/json_token.cc +10 -2
- data/src/core/credentials/call/jwt/jwt_verifier.cc +15 -1
- data/src/core/credentials/call/jwt_token_file/jwt_token_file_call_credentials.cc +1 -1
- data/src/core/credentials/call/oauth2/oauth2_credentials.cc +42 -79
- data/src/core/credentials/call/oauth2/oauth2_credentials.h +2 -5
- data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.cc +52 -31
- data/src/core/credentials/call/token_fetcher/token_fetcher_credentials.h +21 -8
- data/src/core/credentials/transport/google_default/google_default_credentials.cc +3 -4
- data/src/core/credentials/transport/ssl/ssl_credentials.cc +59 -72
- data/src/core/credentials/transport/ssl/ssl_credentials.h +9 -8
- data/src/core/credentials/transport/ssl/ssl_security_connector.cc +12 -6
- data/src/core/credentials/transport/ssl/ssl_security_connector.h +4 -4
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +29 -18
- data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +9 -6
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +45 -56
- data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +5 -4
- data/src/core/credentials/transport/tls/grpc_tls_certificate_selector.h +26 -0
- data/src/core/credentials/transport/tls/grpc_tls_crl_provider.cc +1 -1
- data/src/core/credentials/transport/tls/load_system_roots.h +2 -6
- data/src/core/credentials/transport/tls/load_system_roots_fallback.cc +2 -4
- data/src/core/credentials/transport/tls/load_system_roots_supported.cc +13 -15
- data/src/core/credentials/transport/tls/load_system_roots_supported.h +3 -2
- data/src/core/credentials/transport/tls/load_system_roots_windows.cc +5 -8
- data/src/core/credentials/transport/tls/spiffe_utils.cc +1 -1
- data/src/core/credentials/transport/tls/ssl_utils.cc +39 -28
- data/src/core/credentials/transport/tls/ssl_utils.h +12 -49
- data/src/core/credentials/transport/tls/tls_security_connector.cc +48 -33
- data/src/core/credentials/transport/tls/tls_security_connector.h +31 -10
- data/src/core/ext/filters/channel_idle/legacy_channel_idle_filter.cc +15 -11
- data/src/core/ext/filters/http/http_filters_plugin.cc +20 -9
- data/src/core/ext/filters/rbac/rbac_filter.cc +43 -21
- data/src/core/ext/filters/rbac/rbac_filter.h +21 -3
- data/src/core/ext/filters/rbac/rbac_service_config_parser.cc +2 -2
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +6 -20
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +32 -67
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +2 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.h +78 -4
- data/src/core/ext/transport/chttp2/transport/frame.h +2 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.cc +3 -4
- data/src/core/ext/transport/chttp2/transport/goaway.h +7 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +5 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +3 -1
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +141 -130
- data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +22 -22
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.cc +402 -269
- data/src/core/ext/transport/chttp2/transport/http2_server_transport.h +80 -49
- data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +1 -2
- data/src/core/ext/transport/chttp2/transport/http2_status.h +38 -37
- data/src/core/ext/transport/chttp2/transport/http2_transport.cc +178 -5
- data/src/core/ext/transport/chttp2/transport/http2_transport.h +345 -5
- data/src/core/ext/transport/chttp2/transport/parsing.cc +5 -5
- data/src/core/ext/transport/chttp2/transport/ping_promise.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/ping_promise.h +25 -5
- data/src/core/ext/transport/chttp2/transport/ping_rate_policy.cc +3 -4
- data/src/core/ext/transport/chttp2/transport/read_context.h +30 -3
- data/src/core/ext/transport/chttp2/transport/stream.h +65 -23
- data/src/core/ext/transport/chttp2/transport/writing.cc +0 -3
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -5
- data/src/core/ext/transport/inproc/legacy_inproc_transport.cc +4 -17
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb.h +1912 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.c +300 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upb_minitable.h +37 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb.h +187 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.c +64 -0
- data/src/core/ext/upb-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upb_minitable.h +31 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb.h +2362 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.c +556 -0
- data/src/core/ext/upb-gen/envoy/service/ext_proc/v3/external_processor.upb_minitable.h +47 -0
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb.h +5 -5
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.c +3 -3
- data/src/core/ext/upb-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upb_minitable.h +5 -5
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.c +453 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/ext_proc.upbdefs.h +67 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.c +142 -0
- data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/ext_proc/v3/processing_mode.upbdefs.h +37 -0
- data/src/core/ext/upbdefs-gen/grpc/channelz/v1/channelz.upbdefs.c +715 -0
- data/src/core/ext/upbdefs-gen/{src/proto/grpc/channelz → grpc/channelz/v1}/channelz.upbdefs.h +44 -44
- data/src/core/filter/auth/server_auth_filter.cc +2 -3
- data/src/core/filter/composite/composite_filter.cc +45 -33
- data/src/core/filter/composite/composite_filter.h +5 -4
- data/src/core/filter/ext_proc/ext_proc_filter.cc +224 -0
- data/src/core/filter/ext_proc/ext_proc_filter.h +155 -0
- data/src/core/filter/ext_proc/ext_proc_messages.cc +701 -0
- data/src/core/filter/ext_proc/ext_proc_messages.h +297 -0
- data/src/core/filter/filter_args.h +13 -2
- data/src/core/handshaker/http_connect/http_proxy_mapper.cc +30 -3
- data/src/core/handshaker/security/security_handshaker.cc +9 -6
- data/src/core/lib/channel/channel_stack.cc +3 -0
- data/src/core/lib/channel/channel_stack.h +2 -0
- data/src/core/lib/channel/channel_stack_builder_impl.cc +1 -2
- data/src/core/lib/channel/promise_based_filter.cc +132 -20
- data/src/core/lib/channel/promise_based_filter.h +42 -12
- data/src/core/lib/compression/compression_internal.cc +4 -5
- data/src/core/lib/debug/trace_flags.cc +8 -0
- data/src/core/lib/debug/trace_flags.h +3 -0
- data/src/core/lib/event_engine/ares_resolver.cc +54 -50
- data/src/core/lib/event_engine/ares_resolver.h +3 -2
- data/src/core/lib/event_engine/posix_engine/ev_epoll1_linux.cc +3 -3
- data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +4 -10
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.cc +74 -33
- data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +4 -4
- data/src/core/lib/event_engine/posix_engine/posix_engine.cc +6 -2
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.cc +3 -0
- data/src/core/lib/event_engine/posix_engine/tcp_socket_utils.h +3 -0
- data/src/core/lib/event_engine/windows/windows_endpoint.cc +1 -3
- data/src/core/lib/experiments/experiments.cc +60 -96
- data/src/core/lib/experiments/experiments.h +34 -50
- data/src/core/lib/iomgr/cfstream_handle.cc +2 -6
- data/src/core/lib/iomgr/endpoint_cfstream.cc +3 -10
- data/src/core/lib/iomgr/error.cc +2 -6
- data/src/core/lib/iomgr/error_cfstream.cc +1 -1
- data/src/core/lib/iomgr/ev_poll_posix.cc +5 -9
- data/src/core/lib/iomgr/event_engine_shims/closure.cc +1 -1
- data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +1 -2
- data/src/core/lib/iomgr/event_engine_shims/tcp_client.cc +1 -2
- data/src/core/lib/iomgr/iomgr_posix.cc +0 -4
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +0 -4
- data/src/core/lib/iomgr/iomgr_windows.cc +0 -4
- data/src/core/lib/iomgr/socket_factory_posix.h +1 -1
- data/src/core/lib/iomgr/socket_utils_posix.cc +3 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +3 -0
- data/src/core/lib/iomgr/systemd_utils.cc +0 -1
- data/src/core/lib/iomgr/tcp_client.h +1 -1
- data/src/core/lib/iomgr/tcp_posix.cc +23 -15
- data/src/core/lib/iomgr/tcp_server.h +1 -1
- data/src/core/lib/iomgr/tcp_server_posix.cc +2 -3
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +0 -1
- data/src/core/lib/iomgr/tcp_windows.cc +5 -10
- data/src/core/lib/iomgr/unix_sockets_posix.cc +2 -4
- data/src/core/lib/iomgr/unix_sockets_posix.h +3 -1
- data/src/core/lib/iomgr/vsock.h +3 -1
- data/src/core/lib/resource_quota/memory_quota.cc +1 -1
- data/src/core/lib/security/authorization/rbac_policy.cc +139 -56
- data/src/core/lib/security/authorization/rbac_policy.h +21 -3
- data/src/core/lib/surface/call.cc +3 -9
- data/src/core/lib/surface/call_utils.h +113 -0
- data/src/core/lib/surface/channel_create.cc +1 -1
- data/src/core/lib/surface/channel_create.h +0 -2
- data/src/core/lib/surface/channel_init.cc +77 -38
- data/src/core/lib/surface/channel_init.h +30 -16
- data/src/core/lib/surface/filter_stack_call.cc +5 -10
- data/src/core/lib/surface/init.cc +13 -27
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/error_utils.cc +0 -27
- data/src/core/lib/transport/error_utils.h +0 -16
- data/src/core/lib/transport/transport.h +7 -5
- data/src/core/load_balancing/pick_first/pick_first.cc +2 -0
- data/src/core/load_balancing/rls/rls.cc +28 -11
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.cc +33 -42
- data/src/core/load_balancing/weighted_round_robin/weighted_round_robin.h +0 -2
- data/src/core/load_balancing/xds/cds.cc +3 -1
- data/src/core/load_balancing/xds/xds_cluster_impl.cc +0 -1
- data/src/core/mitigation_engine/mitigation.h +14 -5
- data/src/core/mitigation_engine/mitigation_engine.h +7 -3
- data/src/core/mitigation_engine/mitigation_provider.h +2 -1
- data/src/core/plugin_registry/grpc_plugin_registry.cc +39 -8
- data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.cc → dns_resolver.cc} +42 -41
- data/src/core/resolver/dns/{event_engine/event_engine_client_channel_resolver.h → dns_resolver.h} +8 -5
- data/src/core/resolver/dns/{event_engine/service_config_helper.cc → service_config_helper.cc} +1 -1
- data/src/core/resolver/dns/{event_engine/service_config_helper.h → service_config_helper.h} +3 -3
- data/src/core/resolver/endpoint_addresses.h +3 -0
- data/src/core/resolver/google_c2p/google_c2p_resolver.cc +2 -1
- data/src/core/resolver/xds/xds_resolver.cc +35 -9
- data/src/core/server/server.cc +2 -6
- data/src/core/server/server_config_selector.h +18 -3
- data/src/core/server/server_config_selector_filter.cc +178 -91
- data/src/core/server/server_config_selector_filter.h +58 -3
- data/src/core/server/xds_server_config_fetcher.cc +196 -129
- data/src/core/server/xds_server_config_fetcher.h +49 -0
- data/src/core/server/xds_server_config_fetcher_legacy.cc +41 -37
- data/src/core/telemetry/histogram.h +94 -14
- data/src/core/telemetry/instrument.cc +179 -74
- data/src/core/telemetry/instrument.h +78 -30
- data/src/core/telemetry/metrics.h +5 -0
- data/src/core/{resolver/dns/dns_resolver_plugin.h → telemetry/telemetry_label.h} +12 -8
- data/src/core/tsi/alts/crypt/aes_gcm.cc +10 -13
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +3 -1
- data/src/core/tsi/ssl_telemetry_utils.cc +216 -259
- data/src/core/tsi/ssl_telemetry_utils.h +12 -2
- data/src/core/tsi/ssl_transport_security.cc +238 -80
- data/src/core/tsi/ssl_transport_security.h +63 -33
- data/src/core/tsi/tls_telemetry.cc +31 -0
- data/src/core/tsi/tls_telemetry.h +47 -0
- data/src/core/tsi/transport_security.cc +2 -2
- data/src/core/tsi/transport_security.h +1 -1
- data/src/core/tsi/transport_security_interface.h +1 -1
- data/src/core/{resolver/dns/native/dns_resolver.h → util/address_sorting_init.cc} +21 -8
- data/src/core/{resolver/dns/c_ares/grpc_ares_wrapper_posix.cc → util/address_sorting_init.h} +7 -8
- data/src/core/util/http_client/httpcli.cc +16 -53
- data/src/core/util/http_client/httpcli.h +0 -7
- data/src/core/util/http_client/httpcli_security_connector.cc +13 -8
- data/src/core/util/linux/cpu.cc +1 -1
- data/src/core/util/load_file.cc +3 -9
- data/src/core/util/load_file.h +3 -4
- data/src/core/util/matchers.h +8 -0
- data/src/core/util/posix/cpu.cc +1 -1
- data/src/core/util/status_helper.cc +0 -20
- data/src/core/util/status_helper.h +3 -14
- data/src/core/xds/grpc/xds_audit_logger_registry.cc +51 -31
- data/src/core/xds/grpc/xds_audit_logger_registry.h +17 -3
- data/src/core/xds/grpc/xds_bootstrap_grpc.cc +2 -10
- data/src/core/xds/grpc/xds_bootstrap_grpc.h +8 -6
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.cc +488 -0
- data/src/core/xds/grpc/xds_bootstrap_grpc_builder.h +97 -0
- data/src/core/xds/grpc/xds_certificate_provider.cc +7 -7
- data/src/core/xds/grpc/xds_client_grpc.cc +4 -8
- data/src/core/xds/grpc/xds_client_grpc.h +0 -4
- data/src/core/xds/grpc/xds_cluster.h +1 -0
- data/src/core/xds/grpc/xds_cluster_parser.cc +1 -5
- data/src/core/xds/grpc/xds_cluster_parser.h +0 -2
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.cc +0 -2
- data/src/core/xds/grpc/xds_cluster_specifier_plugin.h +0 -2
- data/src/core/xds/grpc/xds_common_types.cc +0 -91
- data/src/core/xds/grpc/xds_common_types.h +1 -47
- data/src/core/xds/grpc/xds_common_types_parser.cc +84 -378
- data/src/core/xds/grpc/xds_common_types_parser.h +9 -11
- data/src/core/xds/grpc/xds_endpoint_parser.cc +0 -2
- data/src/core/xds/grpc/xds_grpc_service_parser.cc +177 -0
- data/src/core/{resolver/dns/c_ares/dns_resolver_ares.h → xds/grpc/xds_grpc_service_parser.h} +14 -9
- data/src/core/xds/grpc/xds_http_composite_filter.cc +26 -21
- data/src/core/xds/grpc/xds_http_composite_filter.h +4 -3
- data/src/core/xds/grpc/xds_http_ext_proc_filter.cc +418 -0
- data/src/core/xds/grpc/xds_http_ext_proc_filter.h +89 -0
- data/src/core/xds/grpc/xds_http_fault_filter.cc +9 -12
- data/src/core/xds/grpc/xds_http_fault_filter.h +1 -4
- data/src/core/xds/grpc/xds_http_filter.cc +2 -1
- data/src/core/xds/grpc/xds_http_filter.h +6 -5
- data/src/core/xds/grpc/xds_http_filter_registry.cc +10 -127
- data/src/core/xds/grpc/xds_http_filter_registry.h +7 -59
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +13 -14
- data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +3 -2
- data/src/core/xds/grpc/xds_http_rbac_filter.cc +403 -25
- data/src/core/xds/grpc/xds_http_rbac_filter.h +1 -3
- data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +8 -13
- data/src/core/xds/grpc/xds_http_stateful_session_filter.h +1 -4
- data/src/core/xds/grpc/xds_lb_policy_registry.cc +0 -292
- data/src/core/xds/grpc/xds_lb_policy_registry.h +7 -3
- data/src/core/xds/grpc/xds_listener.cc +2 -0
- data/src/core/xds/grpc/xds_listener.h +5 -0
- data/src/core/xds/grpc/xds_listener_parser.cc +16 -11
- data/src/core/xds/grpc/xds_matcher_parse.h +3 -1
- data/src/core/xds/grpc/xds_metadata_parser.cc +6 -1
- data/src/core/xds/grpc/xds_metadata_parser.h +2 -0
- data/src/core/xds/grpc/xds_route_config.cc +2 -0
- data/src/core/xds/grpc/xds_route_config.h +3 -1
- data/src/core/xds/grpc/xds_route_config_parser.cc +13 -79
- data/src/core/xds/grpc/xds_route_config_parser.h +0 -3
- data/src/core/xds/grpc/xds_routing.cc +116 -69
- data/src/core/xds/grpc/xds_routing.h +19 -8
- data/src/core/xds/grpc/xds_tls_context.cc +117 -0
- data/src/core/xds/grpc/xds_tls_context.h +76 -0
- data/src/core/xds/grpc/xds_tls_context_parser.cc +275 -0
- data/src/core/xds/grpc/xds_tls_context_parser.h +35 -0
- data/src/core/xds/grpc/xds_transport_grpc.cc +41 -38
- data/src/core/xds/grpc/xds_transport_grpc.h +4 -2
- data/src/ruby/ext/grpc/rb_call.c +26 -15
- data/src/ruby/ext/grpc/rb_completion_queue.c +6 -5
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +3 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/test/client.rb +5 -4
- data/src/ruby/spec/call_spec.rb +14 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +3 -6
- metadata +50 -35
- data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/channelz.upbdefs.c +0 -716
- data/src/core/lib/iomgr/resolve_address.cc +0 -59
- data/src/core/lib/iomgr/resolve_address.h +0 -125
- data/src/core/lib/iomgr/resolve_address_impl.h +0 -58
- data/src/core/lib/iomgr/resolve_address_posix.cc +0 -184
- data/src/core/lib/iomgr/resolve_address_posix.h +0 -78
- data/src/core/lib/iomgr/resolve_address_windows.cc +0 -169
- data/src/core/lib/iomgr/resolve_address_windows.h +0 -76
- data/src/core/resolver/dns/c_ares/dns_resolver_ares.cc +0 -781
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h +0 -93
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +0 -203
- data/src/core/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +0 -838
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.cc +0 -1237
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper.h +0 -130
- data/src/core/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +0 -35
- data/src/core/resolver/dns/dns_resolver_plugin.cc +0 -64
- data/src/core/resolver/dns/native/dns_resolver.cc +0 -173
- data/src/core/util/json/json_util.cc +0 -101
- data/src/core/util/json/json_util.h +0 -163
|
@@ -1,838 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2016 gRPC authors.
|
|
4
|
-
//
|
|
5
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
// you may not use this file except in compliance with the License.
|
|
7
|
-
// You may obtain a copy of the License at
|
|
8
|
-
//
|
|
9
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
//
|
|
11
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
// See the License for the specific language governing permissions and
|
|
15
|
-
// limitations under the License.
|
|
16
|
-
//
|
|
17
|
-
//
|
|
18
|
-
#include <grpc/support/port_platform.h>
|
|
19
|
-
|
|
20
|
-
#include "src/core/lib/iomgr/port.h" // IWYU pragma: keep
|
|
21
|
-
#if GRPC_ARES == 1 && defined(GRPC_WINDOWS_SOCKET_ARES_EV_DRIVER)
|
|
22
|
-
|
|
23
|
-
#include <grpc/support/alloc.h>
|
|
24
|
-
#include <grpc/support/log_windows.h>
|
|
25
|
-
#include <grpc/support/string_util.h>
|
|
26
|
-
#include <grpc/support/time.h>
|
|
27
|
-
#include <string.h>
|
|
28
|
-
|
|
29
|
-
#include <map>
|
|
30
|
-
#include <memory>
|
|
31
|
-
#include <unordered_set>
|
|
32
|
-
|
|
33
|
-
#include "src/core/lib/address_utils/sockaddr_utils.h"
|
|
34
|
-
#include "src/core/lib/iomgr/iocp_windows.h"
|
|
35
|
-
#include "src/core/lib/iomgr/sockaddr_windows.h"
|
|
36
|
-
#include "src/core/lib/iomgr/socket_windows.h"
|
|
37
|
-
#include "src/core/lib/iomgr/tcp_windows.h"
|
|
38
|
-
#include "src/core/lib/slice/slice.h"
|
|
39
|
-
#include "src/core/lib/slice/slice_internal.h"
|
|
40
|
-
#include "absl/functional/any_invocable.h"
|
|
41
|
-
#include "absl/strings/str_format.h"
|
|
42
|
-
// We pull in ares.h transitively here, ares.h is not self-contained
|
|
43
|
-
// w.r.t. windows headers though, so make sure pull them in above.
|
|
44
|
-
#include "src/core/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
|
45
|
-
#include "src/core/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
|
46
|
-
#include "src/core/util/crash.h"
|
|
47
|
-
#include "src/core/util/grpc_check.h"
|
|
48
|
-
#include "src/core/util/memory.h"
|
|
49
|
-
#include "src/core/util/string.h"
|
|
50
|
-
|
|
51
|
-
// TODO(apolcyn): remove this hack after fixing upstream.
|
|
52
|
-
// Our grpc/c-ares code on Windows uses the ares_set_socket_functions API,
|
|
53
|
-
// which uses "struct iovec" type, which on Windows is defined inside of
|
|
54
|
-
// a c-ares header that is not public.
|
|
55
|
-
// See https://github.com/c-ares/c-ares/issues/206.
|
|
56
|
-
struct iovec {
|
|
57
|
-
void* iov_base;
|
|
58
|
-
size_t iov_len;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
namespace grpc_core {
|
|
62
|
-
|
|
63
|
-
namespace {
|
|
64
|
-
|
|
65
|
-
// c-ares reads and takes action on the error codes of the
|
|
66
|
-
// "virtual socket operations" in this file, via the WSAGetLastError
|
|
67
|
-
// APIs. If code in this file wants to set a specific WSA error that
|
|
68
|
-
// c-ares should read, it must do so by calling SetWSAError() on the
|
|
69
|
-
// WSAErrorContext instance passed to it. A WSAErrorContext must only be
|
|
70
|
-
// instantiated at the top of the virtual socket function callstack.
|
|
71
|
-
class WSAErrorContext final {
|
|
72
|
-
public:
|
|
73
|
-
explicit WSAErrorContext() {};
|
|
74
|
-
|
|
75
|
-
~WSAErrorContext() {
|
|
76
|
-
if (error_ != 0) {
|
|
77
|
-
WSASetLastError(error_);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// Disallow copy and assignment operators
|
|
82
|
-
WSAErrorContext(const WSAErrorContext&) = delete;
|
|
83
|
-
WSAErrorContext& operator=(const WSAErrorContext&) = delete;
|
|
84
|
-
|
|
85
|
-
void SetWSAError(int error) { error_ = error; }
|
|
86
|
-
|
|
87
|
-
private:
|
|
88
|
-
int error_ = 0;
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
// c-ares creates its own sockets and is meant to read them when readable and
|
|
92
|
-
// write them when writeable. To fit this socket usage model into the grpc
|
|
93
|
-
// windows poller (which gives notifications when attempted reads and writes are
|
|
94
|
-
// actually fulfilled rather than possible), this GrpcPolledFdWindows class
|
|
95
|
-
// takes advantage of the ares_set_socket_functions API and acts as a virtual
|
|
96
|
-
// socket. It holds its own read and write buffers which are written to and read
|
|
97
|
-
// from c-ares and are used with the grpc windows poller, and it, e.g.,
|
|
98
|
-
// manufactures virtual socket error codes when it e.g. needs to tell the c-ares
|
|
99
|
-
// library to wait for an async read.
|
|
100
|
-
class GrpcPolledFdWindows final : public GrpcPolledFd {
|
|
101
|
-
public:
|
|
102
|
-
enum WriteState {
|
|
103
|
-
WRITE_IDLE,
|
|
104
|
-
WRITE_REQUESTED,
|
|
105
|
-
WRITE_PENDING,
|
|
106
|
-
WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY,
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
GrpcPolledFdWindows(ares_socket_t as, Mutex* mu, int address_family,
|
|
110
|
-
int socket_type,
|
|
111
|
-
absl::AnyInvocable<void()> on_shutdown_locked)
|
|
112
|
-
: mu_(mu),
|
|
113
|
-
read_buf_(grpc_empty_slice()),
|
|
114
|
-
write_buf_(grpc_empty_slice()),
|
|
115
|
-
name_(absl::StrFormat("c-ares socket: %" PRIdPTR, as)),
|
|
116
|
-
address_family_(address_family),
|
|
117
|
-
socket_type_(socket_type),
|
|
118
|
-
on_shutdown_locked_(std::move(on_shutdown_locked)) {
|
|
119
|
-
// Closure Initialization
|
|
120
|
-
GRPC_CLOSURE_INIT(&outer_read_closure_,
|
|
121
|
-
&GrpcPolledFdWindows::OnIocpReadable, this,
|
|
122
|
-
grpc_schedule_on_exec_ctx);
|
|
123
|
-
GRPC_CLOSURE_INIT(&outer_write_closure_,
|
|
124
|
-
&GrpcPolledFdWindows::OnIocpWriteable, this,
|
|
125
|
-
grpc_schedule_on_exec_ctx);
|
|
126
|
-
GRPC_CLOSURE_INIT(&on_tcp_connect_locked_,
|
|
127
|
-
&GrpcPolledFdWindows::OnTcpConnect, this,
|
|
128
|
-
grpc_schedule_on_exec_ctx);
|
|
129
|
-
winsocket_ = grpc_winsocket_create(as, name_.c_str());
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
~GrpcPolledFdWindows() override {
|
|
133
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
134
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
135
|
-
<< "| ~GrpcPolledFdWindows shutdown_called_: " << shutdown_called_;
|
|
136
|
-
CSliceUnref(read_buf_);
|
|
137
|
-
CSliceUnref(write_buf_);
|
|
138
|
-
GRPC_CHECK_EQ(read_closure_, nullptr);
|
|
139
|
-
GRPC_CHECK_EQ(write_closure_, nullptr);
|
|
140
|
-
if (!shutdown_called_) {
|
|
141
|
-
// This can happen if the socket was never seen by grpc ares wrapper
|
|
142
|
-
// code, i.e. if we never started I/O polling on it.
|
|
143
|
-
grpc_winsocket_shutdown(winsocket_);
|
|
144
|
-
}
|
|
145
|
-
grpc_winsocket_destroy(winsocket_);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
void ScheduleAndNullReadClosure(grpc_error_handle error) {
|
|
149
|
-
ExecCtx::Run(DEBUG_LOCATION, read_closure_, error);
|
|
150
|
-
read_closure_ = nullptr;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
void ScheduleAndNullWriteClosure(grpc_error_handle error) {
|
|
154
|
-
ExecCtx::Run(DEBUG_LOCATION, write_closure_, error);
|
|
155
|
-
write_closure_ = nullptr;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
void RegisterForOnReadableLocked(grpc_closure* read_closure) override {
|
|
159
|
-
GRPC_CHECK_EQ(read_closure_, nullptr);
|
|
160
|
-
read_closure_ = read_closure;
|
|
161
|
-
GRPC_CHECK_EQ(GRPC_SLICE_LENGTH(read_buf_), 0);
|
|
162
|
-
CSliceUnref(read_buf_);
|
|
163
|
-
GRPC_CHECK(!read_buf_has_data_);
|
|
164
|
-
read_buf_ = GRPC_SLICE_MALLOC(4192);
|
|
165
|
-
if (connect_done_) {
|
|
166
|
-
ContinueRegisterForOnReadableLocked();
|
|
167
|
-
} else {
|
|
168
|
-
GRPC_CHECK(pending_continue_register_for_on_readable_locked_ == false);
|
|
169
|
-
pending_continue_register_for_on_readable_locked_ = true;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
void ContinueRegisterForOnReadableLocked() {
|
|
174
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
175
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
176
|
-
<< "| ContinueRegisterForOnReadableLocked "
|
|
177
|
-
<< "wsa_connect_error_:" << wsa_connect_error_;
|
|
178
|
-
GRPC_CHECK(connect_done_);
|
|
179
|
-
if (wsa_connect_error_ != 0) {
|
|
180
|
-
ScheduleAndNullReadClosure(GRPC_WSA_ERROR(wsa_connect_error_, "connect"));
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
WSABUF buffer;
|
|
184
|
-
buffer.buf = (char*)GRPC_SLICE_START_PTR(read_buf_);
|
|
185
|
-
buffer.len = GRPC_SLICE_LENGTH(read_buf_);
|
|
186
|
-
memset(&winsocket_->read_info.overlapped, 0, sizeof(OVERLAPPED));
|
|
187
|
-
recv_from_source_addr_len_ = sizeof(recv_from_source_addr_);
|
|
188
|
-
DWORD flags = 0;
|
|
189
|
-
if (WSARecvFrom(grpc_winsocket_wrapped_socket(winsocket_), &buffer, 1,
|
|
190
|
-
nullptr, &flags, (sockaddr*)recv_from_source_addr_,
|
|
191
|
-
&recv_from_source_addr_len_,
|
|
192
|
-
&winsocket_->read_info.overlapped, nullptr)) {
|
|
193
|
-
int wsa_last_error = WSAGetLastError();
|
|
194
|
-
char* msg = gpr_format_message(wsa_last_error);
|
|
195
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
196
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
197
|
-
<< "| RegisterForOnReadableLocked WSARecvFrom error code:|"
|
|
198
|
-
<< wsa_last_error << "| msg:|" << msg << "|";
|
|
199
|
-
gpr_free(msg);
|
|
200
|
-
if (wsa_last_error != WSA_IO_PENDING) {
|
|
201
|
-
ScheduleAndNullReadClosure(
|
|
202
|
-
GRPC_WSA_ERROR(wsa_last_error, "WSARecvFrom"));
|
|
203
|
-
return;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
grpc_socket_notify_on_read(winsocket_, &outer_read_closure_);
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
void RegisterForOnWriteableLocked(grpc_closure* write_closure) override {
|
|
210
|
-
if (socket_type_ == SOCK_DGRAM) {
|
|
211
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
212
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
213
|
-
<< "| RegisterForOnWriteableLocked called";
|
|
214
|
-
} else {
|
|
215
|
-
GRPC_CHECK(socket_type_ == SOCK_STREAM);
|
|
216
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
217
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
218
|
-
<< "| RegisterForOnWriteableLocked called tcp_write_state_: "
|
|
219
|
-
<< tcp_write_state_ << " connect_done_: " << connect_done_;
|
|
220
|
-
}
|
|
221
|
-
GRPC_CHECK_EQ(write_closure_, nullptr);
|
|
222
|
-
write_closure_ = write_closure;
|
|
223
|
-
if (!connect_done_) {
|
|
224
|
-
GRPC_CHECK(!pending_continue_register_for_on_writeable_locked_);
|
|
225
|
-
pending_continue_register_for_on_writeable_locked_ = true;
|
|
226
|
-
// Register an async OnTcpConnect callback here rather than when the
|
|
227
|
-
// connect was initiated, since we are now guaranteed to hold a ref of the
|
|
228
|
-
// c-ares wrapper before write_closure_ is called.
|
|
229
|
-
grpc_socket_notify_on_write(winsocket_, &on_tcp_connect_locked_);
|
|
230
|
-
} else {
|
|
231
|
-
ContinueRegisterForOnWriteableLocked();
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
void ContinueRegisterForOnWriteableLocked() {
|
|
236
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
237
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
238
|
-
<< "| ContinueRegisterForOnWriteableLocked "
|
|
239
|
-
<< "wsa_connect_error_:" << wsa_connect_error_;
|
|
240
|
-
GRPC_CHECK(connect_done_);
|
|
241
|
-
if (wsa_connect_error_ != 0) {
|
|
242
|
-
ScheduleAndNullWriteClosure(
|
|
243
|
-
GRPC_WSA_ERROR(wsa_connect_error_, "connect"));
|
|
244
|
-
return;
|
|
245
|
-
}
|
|
246
|
-
if (socket_type_ == SOCK_DGRAM) {
|
|
247
|
-
ScheduleAndNullWriteClosure(absl::OkStatus());
|
|
248
|
-
} else {
|
|
249
|
-
GRPC_CHECK(socket_type_ == SOCK_STREAM);
|
|
250
|
-
int wsa_error_code = 0;
|
|
251
|
-
switch (tcp_write_state_) {
|
|
252
|
-
case WRITE_IDLE:
|
|
253
|
-
ScheduleAndNullWriteClosure(absl::OkStatus());
|
|
254
|
-
break;
|
|
255
|
-
case WRITE_REQUESTED:
|
|
256
|
-
tcp_write_state_ = WRITE_PENDING;
|
|
257
|
-
if (SendWriteBuf(nullptr, &winsocket_->write_info.overlapped,
|
|
258
|
-
&wsa_error_code) != 0) {
|
|
259
|
-
ScheduleAndNullWriteClosure(
|
|
260
|
-
GRPC_WSA_ERROR(wsa_error_code, "WSASend (overlapped)"));
|
|
261
|
-
} else {
|
|
262
|
-
grpc_socket_notify_on_write(winsocket_, &outer_write_closure_);
|
|
263
|
-
}
|
|
264
|
-
break;
|
|
265
|
-
case WRITE_PENDING:
|
|
266
|
-
case WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY:
|
|
267
|
-
abort();
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
bool IsFdStillReadableLocked() override { return read_buf_has_data_; }
|
|
273
|
-
|
|
274
|
-
void ShutdownLocked(grpc_error_handle /* error */) override {
|
|
275
|
-
GRPC_CHECK(!shutdown_called_);
|
|
276
|
-
shutdown_called_ = true;
|
|
277
|
-
on_shutdown_locked_();
|
|
278
|
-
grpc_winsocket_shutdown(winsocket_);
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
ares_socket_t GetWrappedAresSocketLocked() override {
|
|
282
|
-
return grpc_winsocket_wrapped_socket(winsocket_);
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
const char* GetName() const override { return name_.c_str(); }
|
|
286
|
-
|
|
287
|
-
ares_ssize_t RecvFrom(WSAErrorContext* wsa_error_ctx, void* data,
|
|
288
|
-
ares_socket_t data_len, int /* flags */,
|
|
289
|
-
struct sockaddr* from, ares_socklen_t* from_len) {
|
|
290
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
291
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
292
|
-
<< " RecvFrom called read_buf_has_data:" << read_buf_has_data_
|
|
293
|
-
<< " Current read buf length:" << GRPC_SLICE_LENGTH(read_buf_);
|
|
294
|
-
if (!read_buf_has_data_) {
|
|
295
|
-
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
|
|
296
|
-
return -1;
|
|
297
|
-
}
|
|
298
|
-
ares_ssize_t bytes_read = 0;
|
|
299
|
-
for (size_t i = 0; i < GRPC_SLICE_LENGTH(read_buf_) && i < data_len; i++) {
|
|
300
|
-
((char*)data)[i] = GRPC_SLICE_START_PTR(read_buf_)[i];
|
|
301
|
-
bytes_read++;
|
|
302
|
-
}
|
|
303
|
-
read_buf_ = grpc_slice_sub_no_ref(read_buf_, bytes_read,
|
|
304
|
-
GRPC_SLICE_LENGTH(read_buf_));
|
|
305
|
-
if (GRPC_SLICE_LENGTH(read_buf_) == 0) {
|
|
306
|
-
read_buf_has_data_ = false;
|
|
307
|
-
}
|
|
308
|
-
// c-ares overloads this recv_from virtual socket function to receive
|
|
309
|
-
// data on both UDP and TCP sockets, and from is nullptr for TCP.
|
|
310
|
-
if (from != nullptr) {
|
|
311
|
-
GRPC_CHECK(*from_len >= recv_from_source_addr_len_);
|
|
312
|
-
memcpy(from, &recv_from_source_addr_, recv_from_source_addr_len_);
|
|
313
|
-
*from_len = recv_from_source_addr_len_;
|
|
314
|
-
}
|
|
315
|
-
return bytes_read;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
grpc_slice FlattenIovec(const struct iovec* iov, int iov_count) {
|
|
319
|
-
int total = 0;
|
|
320
|
-
for (int i = 0; i < iov_count; i++) {
|
|
321
|
-
total += iov[i].iov_len;
|
|
322
|
-
}
|
|
323
|
-
grpc_slice out = GRPC_SLICE_MALLOC(total);
|
|
324
|
-
size_t cur = 0;
|
|
325
|
-
for (int i = 0; i < iov_count; i++) {
|
|
326
|
-
for (size_t k = 0; k < iov[i].iov_len; k++) {
|
|
327
|
-
GRPC_SLICE_START_PTR(out)[cur++] = ((char*)iov[i].iov_base)[k];
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
return out;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
int SendWriteBuf(LPDWORD bytes_sent_ptr, LPWSAOVERLAPPED overlapped,
|
|
334
|
-
int* wsa_error_code) {
|
|
335
|
-
WSABUF buf;
|
|
336
|
-
buf.len = GRPC_SLICE_LENGTH(write_buf_);
|
|
337
|
-
buf.buf = (char*)GRPC_SLICE_START_PTR(write_buf_);
|
|
338
|
-
DWORD flags = 0;
|
|
339
|
-
int out = WSASend(grpc_winsocket_wrapped_socket(winsocket_), &buf, 1,
|
|
340
|
-
bytes_sent_ptr, flags, overlapped, nullptr);
|
|
341
|
-
*wsa_error_code = WSAGetLastError();
|
|
342
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
343
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
344
|
-
<< " SendWriteBuf WSASend buf.len:" << buf.len << " *bytes_sent_ptr:"
|
|
345
|
-
<< (bytes_sent_ptr != nullptr ? *bytes_sent_ptr : 0)
|
|
346
|
-
<< " overlapped:" << overlapped << " return:" << out
|
|
347
|
-
<< " *wsa_error_code:" << *wsa_error_code;
|
|
348
|
-
return out;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
ares_ssize_t SendV(WSAErrorContext* wsa_error_ctx, const struct iovec* iov,
|
|
352
|
-
int iov_count) {
|
|
353
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
354
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
355
|
-
<< " SendV called connect_done_:" << connect_done_
|
|
356
|
-
<< " wsa_connect_error_:" << wsa_connect_error_;
|
|
357
|
-
if (!connect_done_) {
|
|
358
|
-
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
|
|
359
|
-
return -1;
|
|
360
|
-
}
|
|
361
|
-
if (wsa_connect_error_ != 0) {
|
|
362
|
-
wsa_error_ctx->SetWSAError(wsa_connect_error_);
|
|
363
|
-
return -1;
|
|
364
|
-
}
|
|
365
|
-
switch (socket_type_) {
|
|
366
|
-
case SOCK_DGRAM:
|
|
367
|
-
return SendVUDP(wsa_error_ctx, iov, iov_count);
|
|
368
|
-
case SOCK_STREAM:
|
|
369
|
-
return SendVTCP(wsa_error_ctx, iov, iov_count);
|
|
370
|
-
default:
|
|
371
|
-
abort();
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
ares_ssize_t SendVUDP(WSAErrorContext* wsa_error_ctx, const struct iovec* iov,
|
|
376
|
-
int iov_count) {
|
|
377
|
-
// c-ares doesn't handle retryable errors on writes of UDP sockets.
|
|
378
|
-
// Therefore, the sendv handler for UDP sockets must only attempt
|
|
379
|
-
// to write everything inline.
|
|
380
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
381
|
-
<< "(c-ares resolver) fd:" << GetName() << " SendVUDP called";
|
|
382
|
-
GRPC_CHECK_EQ(GRPC_SLICE_LENGTH(write_buf_), 0);
|
|
383
|
-
CSliceUnref(write_buf_);
|
|
384
|
-
write_buf_ = FlattenIovec(iov, iov_count);
|
|
385
|
-
DWORD bytes_sent = 0;
|
|
386
|
-
int wsa_error_code = 0;
|
|
387
|
-
if (SendWriteBuf(&bytes_sent, nullptr, &wsa_error_code) != 0) {
|
|
388
|
-
CSliceUnref(write_buf_);
|
|
389
|
-
write_buf_ = grpc_empty_slice();
|
|
390
|
-
wsa_error_ctx->SetWSAError(wsa_error_code);
|
|
391
|
-
char* msg = gpr_format_message(wsa_error_code);
|
|
392
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
393
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
394
|
-
<< " SendVUDP SendWriteBuf error code:" << wsa_error_code
|
|
395
|
-
<< " msg:" << msg;
|
|
396
|
-
gpr_free(msg);
|
|
397
|
-
return -1;
|
|
398
|
-
}
|
|
399
|
-
write_buf_ = grpc_slice_sub_no_ref(write_buf_, bytes_sent,
|
|
400
|
-
GRPC_SLICE_LENGTH(write_buf_));
|
|
401
|
-
return bytes_sent;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
ares_ssize_t SendVTCP(WSAErrorContext* wsa_error_ctx, const struct iovec* iov,
|
|
405
|
-
int iov_count) {
|
|
406
|
-
// The "sendv" handler on TCP sockets buffers up write
|
|
407
|
-
// requests and returns an artificial WSAEWOULDBLOCK. Writing that buffer
|
|
408
|
-
// out in the background, and making further send progress in general, will
|
|
409
|
-
// happen as long as c-ares continues to show interest in writeability on
|
|
410
|
-
// this fd.
|
|
411
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
412
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
413
|
-
<< " SendVTCP called tcp_write_state_:" << tcp_write_state_;
|
|
414
|
-
switch (tcp_write_state_) {
|
|
415
|
-
case WRITE_IDLE:
|
|
416
|
-
tcp_write_state_ = WRITE_REQUESTED;
|
|
417
|
-
GRPC_CHECK_EQ(GRPC_SLICE_LENGTH(write_buf_), 0);
|
|
418
|
-
CSliceUnref(write_buf_);
|
|
419
|
-
write_buf_ = FlattenIovec(iov, iov_count);
|
|
420
|
-
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
|
|
421
|
-
return -1;
|
|
422
|
-
case WRITE_REQUESTED:
|
|
423
|
-
case WRITE_PENDING:
|
|
424
|
-
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
|
|
425
|
-
return -1;
|
|
426
|
-
case WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY:
|
|
427
|
-
// c-ares is retrying a send on data that we previously returned
|
|
428
|
-
// WSAEWOULDBLOCK for, but then subsequently wrote out in the
|
|
429
|
-
// background. Right now, we assume that c-ares is retrying the same
|
|
430
|
-
// send again. If c-ares still needs to send even more data, we'll get
|
|
431
|
-
// to it eventually.
|
|
432
|
-
grpc_slice currently_attempted = FlattenIovec(iov, iov_count);
|
|
433
|
-
GRPC_CHECK(GRPC_SLICE_LENGTH(currently_attempted) >=
|
|
434
|
-
GRPC_SLICE_LENGTH(write_buf_));
|
|
435
|
-
ares_ssize_t total_sent = 0;
|
|
436
|
-
for (size_t i = 0; i < GRPC_SLICE_LENGTH(write_buf_); i++) {
|
|
437
|
-
GRPC_CHECK(GRPC_SLICE_START_PTR(currently_attempted)[i] ==
|
|
438
|
-
GRPC_SLICE_START_PTR(write_buf_)[i]);
|
|
439
|
-
total_sent++;
|
|
440
|
-
}
|
|
441
|
-
CSliceUnref(currently_attempted);
|
|
442
|
-
tcp_write_state_ = WRITE_IDLE;
|
|
443
|
-
return total_sent;
|
|
444
|
-
}
|
|
445
|
-
abort();
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
static void OnTcpConnect(void* arg, grpc_error_handle error) {
|
|
449
|
-
GrpcPolledFdWindows* grpc_polled_fd =
|
|
450
|
-
static_cast<GrpcPolledFdWindows*>(arg);
|
|
451
|
-
MutexLock lock(grpc_polled_fd->mu_);
|
|
452
|
-
grpc_polled_fd->OnTcpConnectLocked(error);
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
void OnTcpConnectLocked(grpc_error_handle error) {
|
|
456
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
457
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
458
|
-
<< " InnerOnTcpConnectLocked error:" << StatusToString(error)
|
|
459
|
-
<< " pending_register_for_readable:"
|
|
460
|
-
<< pending_continue_register_for_on_readable_locked_
|
|
461
|
-
<< " pending_register_for_writeable:"
|
|
462
|
-
<< pending_continue_register_for_on_writeable_locked_;
|
|
463
|
-
GRPC_CHECK(!connect_done_);
|
|
464
|
-
connect_done_ = true;
|
|
465
|
-
GRPC_CHECK_EQ(wsa_connect_error_, 0);
|
|
466
|
-
if (!error.ok() || shutdown_called_) {
|
|
467
|
-
wsa_connect_error_ = WSA_OPERATION_ABORTED;
|
|
468
|
-
} else {
|
|
469
|
-
DWORD transferred_bytes = 0;
|
|
470
|
-
DWORD flags;
|
|
471
|
-
BOOL wsa_success =
|
|
472
|
-
WSAGetOverlappedResult(grpc_winsocket_wrapped_socket(winsocket_),
|
|
473
|
-
&winsocket_->write_info.overlapped,
|
|
474
|
-
&transferred_bytes, FALSE, &flags);
|
|
475
|
-
GRPC_CHECK_EQ(transferred_bytes, 0);
|
|
476
|
-
if (!wsa_success) {
|
|
477
|
-
wsa_connect_error_ = WSAGetLastError();
|
|
478
|
-
char* msg = gpr_format_message(wsa_connect_error_);
|
|
479
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
480
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
481
|
-
<< " InnerOnTcpConnectLocked WSA overlapped result code:"
|
|
482
|
-
<< wsa_connect_error_ << " msg:" << msg;
|
|
483
|
-
gpr_free(msg);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
if (pending_continue_register_for_on_readable_locked_) {
|
|
487
|
-
ContinueRegisterForOnReadableLocked();
|
|
488
|
-
}
|
|
489
|
-
if (pending_continue_register_for_on_writeable_locked_) {
|
|
490
|
-
ContinueRegisterForOnWriteableLocked();
|
|
491
|
-
}
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
int Connect(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target,
|
|
495
|
-
ares_socklen_t target_len) {
|
|
496
|
-
switch (socket_type_) {
|
|
497
|
-
case SOCK_DGRAM:
|
|
498
|
-
return ConnectUDP(wsa_error_ctx, target, target_len);
|
|
499
|
-
case SOCK_STREAM:
|
|
500
|
-
return ConnectTCP(wsa_error_ctx, target, target_len);
|
|
501
|
-
default:
|
|
502
|
-
abort();
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
int ConnectUDP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target,
|
|
507
|
-
ares_socklen_t target_len) {
|
|
508
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
509
|
-
<< "(c-ares resolver) fd:" << GetName() << " ConnectUDP";
|
|
510
|
-
GRPC_CHECK(!connect_done_);
|
|
511
|
-
GRPC_CHECK_EQ(wsa_connect_error_, 0);
|
|
512
|
-
SOCKET s = grpc_winsocket_wrapped_socket(winsocket_);
|
|
513
|
-
int out =
|
|
514
|
-
WSAConnect(s, target, target_len, nullptr, nullptr, nullptr, nullptr);
|
|
515
|
-
wsa_connect_error_ = WSAGetLastError();
|
|
516
|
-
wsa_error_ctx->SetWSAError(wsa_connect_error_);
|
|
517
|
-
connect_done_ = true;
|
|
518
|
-
char* msg = gpr_format_message(wsa_connect_error_);
|
|
519
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
520
|
-
<< "(c-ares resolver) fd:" << GetName() << " WSAConnect error code:|"
|
|
521
|
-
<< wsa_connect_error_ << "| msg:|" << msg << "|";
|
|
522
|
-
gpr_free(msg);
|
|
523
|
-
// c-ares expects a posix-style connect API
|
|
524
|
-
return out == 0 ? 0 : -1;
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
int ConnectTCP(WSAErrorContext* wsa_error_ctx, const struct sockaddr* target,
|
|
528
|
-
ares_socklen_t target_len) {
|
|
529
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
530
|
-
<< "(c-ares resolver) fd:" << GetName() << " ConnectTCP";
|
|
531
|
-
LPFN_CONNECTEX ConnectEx;
|
|
532
|
-
GUID guid = WSAID_CONNECTEX;
|
|
533
|
-
DWORD ioctl_num_bytes;
|
|
534
|
-
SOCKET s = grpc_winsocket_wrapped_socket(winsocket_);
|
|
535
|
-
if (WSAIoctl(s, SIO_GET_EXTENSION_FUNCTION_POINTER, &guid, sizeof(guid),
|
|
536
|
-
&ConnectEx, sizeof(ConnectEx), &ioctl_num_bytes, nullptr,
|
|
537
|
-
nullptr) != 0) {
|
|
538
|
-
int wsa_last_error = WSAGetLastError();
|
|
539
|
-
wsa_error_ctx->SetWSAError(wsa_last_error);
|
|
540
|
-
char* msg = gpr_format_message(wsa_last_error);
|
|
541
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
542
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
543
|
-
<< " WSAIoctl(SIO_GET_EXTENSION_FUNCTION_POINTER) error code:"
|
|
544
|
-
<< wsa_last_error << " msg:|" << msg << "|";
|
|
545
|
-
gpr_free(msg);
|
|
546
|
-
connect_done_ = true;
|
|
547
|
-
wsa_connect_error_ = wsa_last_error;
|
|
548
|
-
return -1;
|
|
549
|
-
}
|
|
550
|
-
grpc_resolved_address wildcard4_addr;
|
|
551
|
-
grpc_resolved_address wildcard6_addr;
|
|
552
|
-
grpc_sockaddr_make_wildcards(0, &wildcard4_addr, &wildcard6_addr);
|
|
553
|
-
grpc_resolved_address* local_address = nullptr;
|
|
554
|
-
if (address_family_ == AF_INET) {
|
|
555
|
-
local_address = &wildcard4_addr;
|
|
556
|
-
} else {
|
|
557
|
-
local_address = &wildcard6_addr;
|
|
558
|
-
}
|
|
559
|
-
if (bind(s, (struct sockaddr*)local_address->addr,
|
|
560
|
-
(int)local_address->len) != 0) {
|
|
561
|
-
int wsa_last_error = WSAGetLastError();
|
|
562
|
-
wsa_error_ctx->SetWSAError(wsa_last_error);
|
|
563
|
-
char* msg = gpr_format_message(wsa_last_error);
|
|
564
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
565
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
566
|
-
<< " bind error code:" << wsa_last_error << " msg:|" << msg << "|";
|
|
567
|
-
gpr_free(msg);
|
|
568
|
-
connect_done_ = true;
|
|
569
|
-
wsa_connect_error_ = wsa_last_error;
|
|
570
|
-
return -1;
|
|
571
|
-
}
|
|
572
|
-
int out = 0;
|
|
573
|
-
if (ConnectEx(s, target, target_len, nullptr, 0, nullptr,
|
|
574
|
-
&winsocket_->write_info.overlapped) == 0) {
|
|
575
|
-
out = -1;
|
|
576
|
-
int wsa_last_error = WSAGetLastError();
|
|
577
|
-
wsa_error_ctx->SetWSAError(wsa_last_error);
|
|
578
|
-
char* msg = gpr_format_message(wsa_last_error);
|
|
579
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
580
|
-
<< "(c-ares resolver) fd:" << GetName()
|
|
581
|
-
<< " ConnectEx error code:" << wsa_last_error << " msg:|" << msg
|
|
582
|
-
<< "|";
|
|
583
|
-
gpr_free(msg);
|
|
584
|
-
if (wsa_last_error == WSA_IO_PENDING) {
|
|
585
|
-
// c-ares only understands WSAEINPROGRESS and EWOULDBLOCK error codes on
|
|
586
|
-
// connect, but an async connect on IOCP socket will give
|
|
587
|
-
// WSA_IO_PENDING, so we need to convert.
|
|
588
|
-
wsa_error_ctx->SetWSAError(WSAEWOULDBLOCK);
|
|
589
|
-
} else {
|
|
590
|
-
// By returning a non-retryable error to c-ares at this point,
|
|
591
|
-
// we're aborting the possibility of any future operations on this fd.
|
|
592
|
-
connect_done_ = true;
|
|
593
|
-
wsa_connect_error_ = wsa_last_error;
|
|
594
|
-
return -1;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
// RegisterForOnWriteable will register for an async notification
|
|
598
|
-
return out;
|
|
599
|
-
}
|
|
600
|
-
|
|
601
|
-
static void OnIocpReadable(void* arg, grpc_error_handle error) {
|
|
602
|
-
GrpcPolledFdWindows* polled_fd = static_cast<GrpcPolledFdWindows*>(arg);
|
|
603
|
-
MutexLock lock(polled_fd->mu_);
|
|
604
|
-
polled_fd->OnIocpReadableLocked(error);
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
// TODO(apolcyn): improve this error handling to be less conversative.
|
|
608
|
-
// An e.g. ECONNRESET error here should result in errors when
|
|
609
|
-
// c-ares reads from this socket later, but it shouldn't necessarily cancel
|
|
610
|
-
// the entire resolution attempt. Doing so will allow the "inject broken
|
|
611
|
-
// nameserver list" test to pass on Windows.
|
|
612
|
-
void OnIocpReadableLocked(grpc_error_handle error) {
|
|
613
|
-
if (error.ok()) {
|
|
614
|
-
if (winsocket_->read_info.wsa_error != 0) {
|
|
615
|
-
// WSAEMSGSIZE would be due to receiving more data
|
|
616
|
-
// than our read buffer's fixed capacity. Assume that
|
|
617
|
-
// the connection is TCP and read the leftovers
|
|
618
|
-
// in subsequent c-ares reads.
|
|
619
|
-
if (winsocket_->read_info.wsa_error != WSAEMSGSIZE) {
|
|
620
|
-
error = GRPC_WSA_ERROR(winsocket_->read_info.wsa_error,
|
|
621
|
-
"OnIocpReadableInner");
|
|
622
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
623
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
624
|
-
<< "| OnIocpReadableInner winsocket_->read_info.wsa_error "
|
|
625
|
-
"code:|"
|
|
626
|
-
<< winsocket_->read_info.wsa_error << "| msg:|"
|
|
627
|
-
<< StatusToString(error) << "|";
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
if (error.ok()) {
|
|
632
|
-
read_buf_ = grpc_slice_sub_no_ref(
|
|
633
|
-
read_buf_, 0, winsocket_->read_info.bytes_transferred);
|
|
634
|
-
read_buf_has_data_ = true;
|
|
635
|
-
} else {
|
|
636
|
-
CSliceUnref(read_buf_);
|
|
637
|
-
read_buf_ = grpc_empty_slice();
|
|
638
|
-
}
|
|
639
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
640
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
641
|
-
<< "| OnIocpReadable finishing. read buf length now:|"
|
|
642
|
-
<< GRPC_SLICE_LENGTH(read_buf_) << "|";
|
|
643
|
-
ScheduleAndNullReadClosure(error);
|
|
644
|
-
}
|
|
645
|
-
|
|
646
|
-
static void OnIocpWriteable(void* arg, grpc_error_handle error) {
|
|
647
|
-
GrpcPolledFdWindows* polled_fd = static_cast<GrpcPolledFdWindows*>(arg);
|
|
648
|
-
MutexLock lock(polled_fd->mu_);
|
|
649
|
-
polled_fd->OnIocpWriteableLocked(error);
|
|
650
|
-
}
|
|
651
|
-
|
|
652
|
-
void OnIocpWriteableLocked(grpc_error_handle error) {
|
|
653
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
654
|
-
<< "(c-ares resolver) OnIocpWriteableInner. fd:|" << GetName() << "|";
|
|
655
|
-
GRPC_CHECK(socket_type_ == SOCK_STREAM);
|
|
656
|
-
if (error.ok()) {
|
|
657
|
-
if (winsocket_->write_info.wsa_error != 0) {
|
|
658
|
-
error = GRPC_WSA_ERROR(winsocket_->write_info.wsa_error,
|
|
659
|
-
"OnIocpWriteableInner");
|
|
660
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
661
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
662
|
-
<< "| OnIocpWriteableInner. winsocket_->write_info.wsa_error "
|
|
663
|
-
"code:|"
|
|
664
|
-
<< winsocket_->write_info.wsa_error << "| msg:|"
|
|
665
|
-
<< StatusToString(error) << "|";
|
|
666
|
-
}
|
|
667
|
-
}
|
|
668
|
-
GRPC_CHECK(tcp_write_state_ == WRITE_PENDING);
|
|
669
|
-
if (error.ok()) {
|
|
670
|
-
tcp_write_state_ = WRITE_WAITING_FOR_VERIFICATION_UPON_RETRY;
|
|
671
|
-
write_buf_ = grpc_slice_sub_no_ref(
|
|
672
|
-
write_buf_, 0, winsocket_->write_info.bytes_transferred);
|
|
673
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
674
|
-
<< "(c-ares resolver) fd:|" << GetName()
|
|
675
|
-
<< "| OnIocpWriteableInner. bytes transferred:"
|
|
676
|
-
<< winsocket_->write_info.bytes_transferred;
|
|
677
|
-
} else {
|
|
678
|
-
CSliceUnref(write_buf_);
|
|
679
|
-
write_buf_ = grpc_empty_slice();
|
|
680
|
-
}
|
|
681
|
-
ScheduleAndNullWriteClosure(error);
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
private:
|
|
685
|
-
Mutex* mu_;
|
|
686
|
-
char recv_from_source_addr_[200];
|
|
687
|
-
ares_socklen_t recv_from_source_addr_len_;
|
|
688
|
-
grpc_slice read_buf_;
|
|
689
|
-
bool read_buf_has_data_ = false;
|
|
690
|
-
grpc_slice write_buf_;
|
|
691
|
-
grpc_closure* read_closure_ = nullptr;
|
|
692
|
-
grpc_closure* write_closure_ = nullptr;
|
|
693
|
-
grpc_closure outer_read_closure_;
|
|
694
|
-
grpc_closure outer_write_closure_;
|
|
695
|
-
grpc_winsocket* winsocket_;
|
|
696
|
-
const std::string name_;
|
|
697
|
-
bool shutdown_called_ = false;
|
|
698
|
-
int address_family_;
|
|
699
|
-
int socket_type_;
|
|
700
|
-
// State related to TCP sockets
|
|
701
|
-
grpc_closure on_tcp_connect_locked_;
|
|
702
|
-
bool connect_done_ = false;
|
|
703
|
-
int wsa_connect_error_ = 0;
|
|
704
|
-
WriteState tcp_write_state_ = WRITE_IDLE;
|
|
705
|
-
// We don't run register_for_{readable,writeable} logic until
|
|
706
|
-
// a socket is connected. In the interim, we queue readable/writeable
|
|
707
|
-
// registrations with the following state.
|
|
708
|
-
bool pending_continue_register_for_on_readable_locked_ = false;
|
|
709
|
-
bool pending_continue_register_for_on_writeable_locked_ = false;
|
|
710
|
-
absl::AnyInvocable<void()> on_shutdown_locked_;
|
|
711
|
-
};
|
|
712
|
-
|
|
713
|
-
class GrpcPolledFdFactoryWindows final : public GrpcPolledFdFactory {
|
|
714
|
-
public:
|
|
715
|
-
explicit GrpcPolledFdFactoryWindows(Mutex* mu) : mu_(mu) {}
|
|
716
|
-
|
|
717
|
-
~GrpcPolledFdFactoryWindows() override {
|
|
718
|
-
// We might still have a socket -> polled fd mappings if the socket
|
|
719
|
-
// was never seen by the grpc ares wrapper code, i.e. if we never
|
|
720
|
-
// initiated I/O polling for them.
|
|
721
|
-
for (auto& it : sockets_) {
|
|
722
|
-
delete it.second;
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
GrpcPolledFd* NewGrpcPolledFdLocked(
|
|
727
|
-
ares_socket_t as, grpc_pollset_set* /* driver_pollset_set */) override {
|
|
728
|
-
auto it = sockets_.find(as);
|
|
729
|
-
GRPC_CHECK(it != sockets_.end());
|
|
730
|
-
return it->second;
|
|
731
|
-
}
|
|
732
|
-
|
|
733
|
-
void ConfigureAresChannelLocked(ares_channel channel) override {
|
|
734
|
-
ares_set_socket_functions(channel, &kCustomSockFuncs, this);
|
|
735
|
-
}
|
|
736
|
-
|
|
737
|
-
private:
|
|
738
|
-
// These virtual socket functions are called from within the c-ares
|
|
739
|
-
// library. These methods generally dispatch those socket calls to the
|
|
740
|
-
// appropriate methods. The virtual "socket" and "close" methods are
|
|
741
|
-
// special and instead create/add and remove/destroy GrpcPolledFdWindows
|
|
742
|
-
// objects.
|
|
743
|
-
//
|
|
744
|
-
static ares_socket_t Socket(int af, int type, int protocol, void* user_data) {
|
|
745
|
-
if (type != SOCK_DGRAM && type != SOCK_STREAM) {
|
|
746
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
747
|
-
<< "(c-ares resolver) Socket called with invalid socket type:"
|
|
748
|
-
<< type;
|
|
749
|
-
return INVALID_SOCKET;
|
|
750
|
-
}
|
|
751
|
-
GrpcPolledFdFactoryWindows* self =
|
|
752
|
-
static_cast<GrpcPolledFdFactoryWindows*>(user_data);
|
|
753
|
-
SOCKET s = WSASocket(af, type, protocol, nullptr, 0,
|
|
754
|
-
grpc_get_default_wsa_socket_flags());
|
|
755
|
-
if (s == INVALID_SOCKET) {
|
|
756
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
757
|
-
<< "(c-ares resolver) WSASocket failed with params af:" << af
|
|
758
|
-
<< " type:" << type << " protocol:" << protocol;
|
|
759
|
-
return s;
|
|
760
|
-
}
|
|
761
|
-
grpc_error_handle error = grpc_tcp_set_non_block(s);
|
|
762
|
-
if (!error.ok()) {
|
|
763
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
764
|
-
<< "(c-ares resolver) WSAIoctl failed with error: "
|
|
765
|
-
<< StatusToString(error);
|
|
766
|
-
return INVALID_SOCKET;
|
|
767
|
-
}
|
|
768
|
-
auto on_shutdown_locked = [self, s]() {
|
|
769
|
-
// grpc_winsocket_shutdown calls closesocket which invalidates our
|
|
770
|
-
// socket -> polled_fd mapping because the socket handle can be henceforth
|
|
771
|
-
// reused.
|
|
772
|
-
self->sockets_.erase(s);
|
|
773
|
-
};
|
|
774
|
-
auto polled_fd = new GrpcPolledFdWindows(s, self->mu_, af, type,
|
|
775
|
-
std::move(on_shutdown_locked));
|
|
776
|
-
GRPC_TRACE_VLOG(cares_resolver, 2)
|
|
777
|
-
<< "(c-ares resolver) fd:" << polled_fd->GetName()
|
|
778
|
-
<< " created with params af:" << af << " type:" << type
|
|
779
|
-
<< " protocol:" << protocol;
|
|
780
|
-
GRPC_CHECK(self->sockets_.insert({s, polled_fd}).second);
|
|
781
|
-
return s;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
static int Connect(ares_socket_t as, const struct sockaddr* target,
|
|
785
|
-
ares_socklen_t target_len, void* user_data) {
|
|
786
|
-
WSAErrorContext wsa_error_ctx;
|
|
787
|
-
GrpcPolledFdFactoryWindows* self =
|
|
788
|
-
static_cast<GrpcPolledFdFactoryWindows*>(user_data);
|
|
789
|
-
auto it = self->sockets_.find(as);
|
|
790
|
-
GRPC_CHECK(it != self->sockets_.end());
|
|
791
|
-
return it->second->Connect(&wsa_error_ctx, target, target_len);
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
static ares_ssize_t SendV(ares_socket_t as, const struct iovec* iov,
|
|
795
|
-
int iovec_count, void* user_data) {
|
|
796
|
-
WSAErrorContext wsa_error_ctx;
|
|
797
|
-
GrpcPolledFdFactoryWindows* self =
|
|
798
|
-
static_cast<GrpcPolledFdFactoryWindows*>(user_data);
|
|
799
|
-
auto it = self->sockets_.find(as);
|
|
800
|
-
GRPC_CHECK(it != self->sockets_.end());
|
|
801
|
-
return it->second->SendV(&wsa_error_ctx, iov, iovec_count);
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
static ares_ssize_t RecvFrom(ares_socket_t as, void* data, size_t data_len,
|
|
805
|
-
int flags, struct sockaddr* from,
|
|
806
|
-
ares_socklen_t* from_len, void* user_data) {
|
|
807
|
-
WSAErrorContext wsa_error_ctx;
|
|
808
|
-
GrpcPolledFdFactoryWindows* self =
|
|
809
|
-
static_cast<GrpcPolledFdFactoryWindows*>(user_data);
|
|
810
|
-
auto it = self->sockets_.find(as);
|
|
811
|
-
GRPC_CHECK(it != self->sockets_.end());
|
|
812
|
-
return it->second->RecvFrom(&wsa_error_ctx, data, data_len, flags, from,
|
|
813
|
-
from_len);
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
static int CloseSocket(SOCKET /* s */, void* /* user_data */) { return 0; }
|
|
817
|
-
|
|
818
|
-
const struct ares_socket_functions kCustomSockFuncs = {
|
|
819
|
-
&GrpcPolledFdFactoryWindows::Socket /* socket */,
|
|
820
|
-
&GrpcPolledFdFactoryWindows::CloseSocket /* close */,
|
|
821
|
-
&GrpcPolledFdFactoryWindows::Connect /* connect */,
|
|
822
|
-
&GrpcPolledFdFactoryWindows::RecvFrom /* recvfrom */,
|
|
823
|
-
&GrpcPolledFdFactoryWindows::SendV /* sendv */,
|
|
824
|
-
};
|
|
825
|
-
|
|
826
|
-
Mutex* mu_;
|
|
827
|
-
std::map<SOCKET, GrpcPolledFdWindows*> sockets_;
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
} // namespace
|
|
831
|
-
|
|
832
|
-
std::unique_ptr<GrpcPolledFdFactory> NewGrpcPolledFdFactory(Mutex* mu) {
|
|
833
|
-
return std::make_unique<GrpcPolledFdFactoryWindows>(mu);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
} // namespace grpc_core
|
|
837
|
-
|
|
838
|
-
#endif // GRPC_ARES == 1 && defined(GPR_WINDOWS)
|