grpc 1.2.5 → 1.3.4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +1434 -399
- data/etc/roots.pem +34 -150
- data/include/grpc/grpc.h +71 -0
- data/include/grpc/impl/codegen/atm.h +5 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +11 -0
- data/include/grpc/impl/codegen/grpc_types.h +54 -13
- data/include/grpc/impl/codegen/port_platform.h +15 -1
- data/include/grpc/support/alloc.h +2 -1
- data/include/grpc/support/sync.h +4 -0
- data/include/grpc/support/tls.h +1 -1
- data/src/core/ext/census/gen/trace_context.pb.h +1 -1
- data/src/core/ext/census/grpc_filter.c +14 -10
- data/src/core/ext/census/grpc_plugin.c +3 -1
- data/src/core/ext/census/trace_label.h +1 -1
- data/src/core/ext/census/trace_propagation.h +1 -1
- data/src/core/ext/census/trace_status.h +1 -1
- data/src/core/ext/census/trace_string.h +1 -1
- data/src/core/ext/census/tracing.h +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
- data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
- data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
- data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
- data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
- data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
- data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
- data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
- data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
- data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
- data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
- data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
- data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
- data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
- data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
- data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
- data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
- data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
- data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
- data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
- data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
- data/src/core/lib/channel/channel_args.c +7 -0
- data/src/core/lib/channel/channel_args.h +2 -0
- data/src/core/lib/channel/channel_stack.c +20 -27
- data/src/core/lib/channel/channel_stack.h +18 -16
- data/src/core/lib/channel/compress_filter.c +20 -18
- data/src/core/lib/channel/connected_channel.c +9 -8
- data/src/core/lib/channel/deadline_filter.c +28 -24
- data/src/core/lib/channel/deadline_filter.h +3 -3
- data/src/core/lib/channel/handshaker.c +3 -2
- data/src/core/lib/channel/http_client_filter.c +119 -61
- data/src/core/lib/channel/http_server_filter.c +124 -69
- data/src/core/lib/channel/message_size_filter.c +23 -19
- data/src/core/lib/http/httpcli.c +8 -6
- data/src/core/lib/http/httpcli_security_connector.c +5 -5
- data/src/core/lib/http/parser.c +57 -31
- data/src/core/lib/iomgr/closure.c +15 -0
- data/src/core/lib/iomgr/closure.h +4 -0
- data/src/core/lib/iomgr/combiner.c +8 -0
- data/src/core/lib/iomgr/endpoint_pair.h +2 -3
- data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
- data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
- data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
- data/src/core/lib/iomgr/error.c +360 -177
- data/src/core/lib/iomgr/error.h +31 -33
- data/src/core/lib/iomgr/error_internal.h +30 -9
- data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
- data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
- data/src/core/lib/iomgr/ev_posix.c +6 -0
- data/src/core/lib/iomgr/ev_posix.h +3 -0
- data/src/core/lib/iomgr/exec_ctx.c +6 -0
- data/src/core/lib/iomgr/executor.c +8 -2
- data/src/core/lib/iomgr/load_file.c +6 -3
- data/src/core/lib/iomgr/lockfree_event.c +238 -0
- data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
- data/src/core/lib/iomgr/pollset.h +4 -0
- data/src/core/lib/iomgr/pollset_windows.c +2 -2
- data/src/core/lib/iomgr/port.h +9 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
- data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
- data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
- data/src/core/lib/iomgr/resource_quota.c +19 -4
- data/src/core/lib/iomgr/resource_quota.h +2 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
- data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
- data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
- data/src/core/lib/iomgr/tcp_client.h +0 -4
- data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
- data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
- data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
- data/src/core/lib/iomgr/tcp_posix.c +111 -22
- data/src/core/lib/iomgr/tcp_posix.h +3 -4
- data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
- data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
- data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
- data/src/core/lib/iomgr/tcp_uv.c +16 -13
- data/src/core/lib/iomgr/tcp_windows.c +24 -12
- data/src/core/lib/iomgr/tcp_windows.h +2 -2
- data/src/core/lib/iomgr/timer.h +3 -0
- data/src/core/lib/iomgr/timer_generic.c +257 -72
- data/src/core/lib/iomgr/timer_generic.h +1 -1
- data/src/core/lib/iomgr/timer_heap.c +8 -8
- data/src/core/lib/iomgr/udp_server.c +54 -24
- data/src/core/lib/iomgr/udp_server.h +7 -7
- data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
- data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
- data/src/core/lib/profiling/basic_timers.c +1 -1
- data/src/core/lib/security/credentials/credentials.h +1 -1
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
- data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
- data/src/core/lib/security/transport/client_auth_filter.c +33 -26
- data/src/core/lib/security/transport/secure_endpoint.c +8 -5
- data/src/core/lib/security/transport/security_connector.c +37 -37
- data/src/core/lib/security/transport/security_connector.h +1 -1
- data/src/core/lib/security/transport/security_handshaker.c +15 -12
- data/src/core/lib/security/transport/server_auth_filter.c +20 -18
- data/src/core/lib/security/transport/tsi_error.c +5 -3
- data/src/core/lib/security/transport/tsi_error.h +1 -1
- data/src/core/lib/{security/util → slice}/b64.c +21 -6
- data/src/core/lib/{security/util → slice}/b64.h +16 -4
- data/src/core/lib/slice/slice.c +4 -2
- data/src/core/lib/slice/slice_buffer.c +16 -14
- data/src/core/lib/support/arena.c +98 -0
- data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
- data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
- data/src/core/lib/support/cpu_linux.c +5 -0
- data/src/core/lib/support/sync.c +4 -0
- data/src/core/lib/support/time.c +4 -10
- data/src/core/lib/support/wrap_memcpy.c +3 -1
- data/src/core/lib/surface/call.c +252 -221
- data/src/core/lib/surface/channel.c +72 -21
- data/src/core/lib/surface/channel.h +8 -0
- data/src/core/lib/surface/completion_queue.c +2 -3
- data/src/core/lib/surface/completion_queue_factory.c +77 -0
- data/src/core/lib/surface/completion_queue_factory.h +51 -0
- data/src/core/lib/surface/init_secure.c +3 -1
- data/src/core/lib/surface/lame_client.c +18 -14
- data/src/core/lib/surface/server.c +43 -41
- data/src/core/lib/surface/validate_metadata.c +8 -4
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.h +1 -1
- data/src/core/lib/transport/connectivity_state.c +2 -1
- data/src/core/lib/transport/error_utils.c +17 -17
- data/src/core/lib/transport/error_utils.h +1 -1
- data/src/core/lib/transport/metadata_batch.c +6 -7
- data/src/core/lib/transport/pid_controller.c +1 -0
- data/src/core/lib/transport/service_config.c +12 -0
- data/src/core/lib/transport/service_config.h +6 -0
- data/src/core/lib/transport/transport.c +29 -17
- data/src/core/lib/transport/transport.h +85 -42
- data/src/core/lib/transport/transport_impl.h +5 -3
- data/src/core/lib/transport/transport_op_string.c +20 -14
- data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
- data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
- data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
- data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
- data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
- data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
- data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
- data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
- data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
- data/src/ruby/ext/grpc/extconf.rb +1 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
- data/src/ruby/ext/grpc/rb_channel.c +520 -93
- data/src/ruby/ext/grpc/rb_channel.h +2 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
- data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
- data/src/ruby/ext/grpc/rb_grpc.c +29 -7
- data/src/ruby/ext/grpc/rb_grpc.h +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
- data/src/ruby/ext/grpc/rb_server.c +5 -3
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/channel_connection_spec.rb +173 -0
- data/src/ruby/spec/channel_spec.rb +29 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
- data/third_party/cares/ares_build.h +264 -0
- data/third_party/cares/cares/ares.h +636 -0
- data/third_party/cares/cares/ares__close_sockets.c +61 -0
- data/third_party/cares/cares/ares__get_hostent.c +261 -0
- data/third_party/cares/cares/ares__read_line.c +73 -0
- data/third_party/cares/cares/ares__timeval.c +111 -0
- data/third_party/cares/cares/ares_cancel.c +63 -0
- data/third_party/cares/cares/ares_create_query.c +202 -0
- data/third_party/cares/cares/ares_data.c +221 -0
- data/third_party/cares/cares/ares_data.h +72 -0
- data/third_party/cares/cares/ares_destroy.c +108 -0
- data/third_party/cares/cares/ares_dns.h +103 -0
- data/third_party/cares/cares/ares_expand_name.c +205 -0
- data/third_party/cares/cares/ares_expand_string.c +70 -0
- data/third_party/cares/cares/ares_fds.c +59 -0
- data/third_party/cares/cares/ares_free_hostent.c +41 -0
- data/third_party/cares/cares/ares_free_string.c +25 -0
- data/third_party/cares/cares/ares_getenv.c +30 -0
- data/third_party/cares/cares/ares_getenv.h +26 -0
- data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
- data/third_party/cares/cares/ares_gethostbyname.c +518 -0
- data/third_party/cares/cares/ares_getnameinfo.c +422 -0
- data/third_party/cares/cares/ares_getopt.c +122 -0
- data/third_party/cares/cares/ares_getopt.h +53 -0
- data/third_party/cares/cares/ares_getsock.c +66 -0
- data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
- data/third_party/cares/cares/ares_init.c +2146 -0
- data/third_party/cares/cares/ares_iphlpapi.h +221 -0
- data/third_party/cares/cares/ares_ipv6.h +78 -0
- data/third_party/cares/cares/ares_library_init.c +167 -0
- data/third_party/cares/cares/ares_library_init.h +42 -0
- data/third_party/cares/cares/ares_llist.c +63 -0
- data/third_party/cares/cares/ares_llist.h +39 -0
- data/third_party/cares/cares/ares_mkquery.c +24 -0
- data/third_party/cares/cares/ares_nowarn.c +260 -0
- data/third_party/cares/cares/ares_nowarn.h +61 -0
- data/third_party/cares/cares/ares_options.c +402 -0
- data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
- data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
- data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
- data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
- data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
- data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
- data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
- data/third_party/cares/cares/ares_platform.c +11035 -0
- data/third_party/cares/cares/ares_platform.h +43 -0
- data/third_party/cares/cares/ares_private.h +363 -0
- data/third_party/cares/cares/ares_process.c +1359 -0
- data/third_party/cares/cares/ares_query.c +186 -0
- data/third_party/cares/cares/ares_rules.h +125 -0
- data/third_party/cares/cares/ares_search.c +316 -0
- data/third_party/cares/cares/ares_send.c +131 -0
- data/third_party/cares/cares/ares_setup.h +217 -0
- data/third_party/cares/cares/ares_strcasecmp.c +66 -0
- data/third_party/cares/cares/ares_strcasecmp.h +30 -0
- data/third_party/cares/cares/ares_strdup.c +49 -0
- data/third_party/cares/cares/ares_strdup.h +24 -0
- data/third_party/cares/cares/ares_strerror.c +56 -0
- data/third_party/cares/cares/ares_timeout.c +88 -0
- data/third_party/cares/cares/ares_version.c +11 -0
- data/third_party/cares/cares/ares_version.h +24 -0
- data/third_party/cares/cares/ares_writev.c +79 -0
- data/third_party/cares/cares/bitncmp.c +59 -0
- data/third_party/cares/cares/bitncmp.h +26 -0
- data/third_party/cares/cares/config-win32.h +377 -0
- data/third_party/cares/cares/inet_net_pton.c +450 -0
- data/third_party/cares/cares/inet_ntop.c +208 -0
- data/third_party/cares/cares/setup_once.h +554 -0
- data/third_party/cares/cares/windows_port.c +22 -0
- data/third_party/cares/config_darwin/ares_config.h +523 -0
- data/third_party/cares/config_linux/ares_config.h +524 -0
- metadata +164 -68
@@ -0,0 +1,66 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
|
35
|
+
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H
|
36
|
+
|
37
|
+
#include <ares.h>
|
38
|
+
|
39
|
+
#include "src/core/lib/iomgr/exec_ctx.h"
|
40
|
+
#include "src/core/lib/iomgr/pollset_set.h"
|
41
|
+
|
42
|
+
typedef struct grpc_ares_ev_driver grpc_ares_ev_driver;
|
43
|
+
|
44
|
+
/* Start \a ev_driver. It will keep working until all IO on its ares_channel is
|
45
|
+
done, or grpc_ares_ev_driver_destroy() is called. It may notify the callbacks
|
46
|
+
bound to its ares_channel when necessary. */
|
47
|
+
void grpc_ares_ev_driver_start(grpc_exec_ctx *exec_ctx,
|
48
|
+
grpc_ares_ev_driver *ev_driver);
|
49
|
+
|
50
|
+
/* Returns the ares_channel owned by \a ev_driver. To bind a c-ares query to
|
51
|
+
\a ev_driver, use the ares_channel owned by \a ev_driver as the arg of the
|
52
|
+
query. */
|
53
|
+
ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver);
|
54
|
+
|
55
|
+
/* Creates a new grpc_ares_ev_driver. Returns GRPC_ERROR_NONE if \a ev_driver is
|
56
|
+
created successfully. */
|
57
|
+
grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver,
|
58
|
+
grpc_pollset_set *pollset_set);
|
59
|
+
|
60
|
+
/* Destroys \a ev_driver asynchronously. Pending lookups made on \a ev_driver
|
61
|
+
will be cancelled and their on_done callbacks will be invoked with a status
|
62
|
+
of ARES_ECANCELLED. */
|
63
|
+
void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver);
|
64
|
+
|
65
|
+
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_EV_DRIVER_H \
|
66
|
+
*/
|
@@ -0,0 +1,319 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
#include <grpc/support/port_platform.h>
|
34
|
+
#include "src/core/lib/iomgr/port.h"
|
35
|
+
#if GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET)
|
36
|
+
|
37
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
38
|
+
|
39
|
+
#include <grpc/support/alloc.h>
|
40
|
+
#include <grpc/support/log.h>
|
41
|
+
#include <grpc/support/string_util.h>
|
42
|
+
#include <grpc/support/time.h>
|
43
|
+
#include <grpc/support/useful.h>
|
44
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
45
|
+
#include "src/core/lib/iomgr/ev_posix.h"
|
46
|
+
#include "src/core/lib/iomgr/iomgr_internal.h"
|
47
|
+
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
48
|
+
#include "src/core/lib/support/string.h"
|
49
|
+
|
50
|
+
typedef struct fd_node {
|
51
|
+
/** the owner of this fd node */
|
52
|
+
grpc_ares_ev_driver *ev_driver;
|
53
|
+
/** the grpc_fd owned by this fd node */
|
54
|
+
grpc_fd *grpc_fd;
|
55
|
+
/** a closure wrapping on_readable_cb, which should be invoked when the
|
56
|
+
grpc_fd in this node becomes readable. */
|
57
|
+
grpc_closure read_closure;
|
58
|
+
/** a closure wrapping on_writable_cb, which should be invoked when the
|
59
|
+
grpc_fd in this node becomes writable. */
|
60
|
+
grpc_closure write_closure;
|
61
|
+
/** next fd node in the list */
|
62
|
+
struct fd_node *next;
|
63
|
+
|
64
|
+
/** mutex guarding the rest of the state */
|
65
|
+
gpr_mu mu;
|
66
|
+
/** if the readable closure has been registered */
|
67
|
+
bool readable_registered;
|
68
|
+
/** if the writable closure has been registered */
|
69
|
+
bool writable_registered;
|
70
|
+
} fd_node;
|
71
|
+
|
72
|
+
struct grpc_ares_ev_driver {
|
73
|
+
/** the ares_channel owned by this event driver */
|
74
|
+
ares_channel channel;
|
75
|
+
/** pollset set for driving the IO events of the channel */
|
76
|
+
grpc_pollset_set *pollset_set;
|
77
|
+
/** refcount of the event driver */
|
78
|
+
gpr_refcount refs;
|
79
|
+
|
80
|
+
/** mutex guarding the rest of the state */
|
81
|
+
gpr_mu mu;
|
82
|
+
/** a list of grpc_fd that this event driver is currently using. */
|
83
|
+
fd_node *fds;
|
84
|
+
/** is this event driver currently working? */
|
85
|
+
bool working;
|
86
|
+
/** is this event driver being shut down */
|
87
|
+
bool shutting_down;
|
88
|
+
};
|
89
|
+
|
90
|
+
static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx,
|
91
|
+
grpc_ares_ev_driver *ev_driver);
|
92
|
+
|
93
|
+
static grpc_ares_ev_driver *grpc_ares_ev_driver_ref(
|
94
|
+
grpc_ares_ev_driver *ev_driver) {
|
95
|
+
gpr_log(GPR_DEBUG, "Ref ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
|
96
|
+
gpr_ref(&ev_driver->refs);
|
97
|
+
return ev_driver;
|
98
|
+
}
|
99
|
+
|
100
|
+
static void grpc_ares_ev_driver_unref(grpc_ares_ev_driver *ev_driver) {
|
101
|
+
gpr_log(GPR_DEBUG, "Unref ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
|
102
|
+
if (gpr_unref(&ev_driver->refs)) {
|
103
|
+
gpr_log(GPR_DEBUG, "destroy ev_driver %" PRIuPTR, (uintptr_t)ev_driver);
|
104
|
+
GPR_ASSERT(ev_driver->fds == NULL);
|
105
|
+
gpr_mu_destroy(&ev_driver->mu);
|
106
|
+
ares_destroy(ev_driver->channel);
|
107
|
+
gpr_free(ev_driver);
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
static void fd_node_destroy(grpc_exec_ctx *exec_ctx, fd_node *fdn) {
|
112
|
+
gpr_log(GPR_DEBUG, "delete fd: %d", grpc_fd_wrapped_fd(fdn->grpc_fd));
|
113
|
+
GPR_ASSERT(!fdn->readable_registered);
|
114
|
+
GPR_ASSERT(!fdn->writable_registered);
|
115
|
+
gpr_mu_destroy(&fdn->mu);
|
116
|
+
grpc_pollset_set_del_fd(exec_ctx, fdn->ev_driver->pollset_set, fdn->grpc_fd);
|
117
|
+
grpc_fd_shutdown(exec_ctx, fdn->grpc_fd,
|
118
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("fd node destroyed"));
|
119
|
+
grpc_fd_orphan(exec_ctx, fdn->grpc_fd, NULL, NULL, "c-ares query finished");
|
120
|
+
gpr_free(fdn);
|
121
|
+
}
|
122
|
+
|
123
|
+
grpc_error *grpc_ares_ev_driver_create(grpc_ares_ev_driver **ev_driver,
|
124
|
+
grpc_pollset_set *pollset_set) {
|
125
|
+
*ev_driver = gpr_malloc(sizeof(grpc_ares_ev_driver));
|
126
|
+
int status = ares_init(&(*ev_driver)->channel);
|
127
|
+
gpr_log(GPR_DEBUG, "grpc_ares_ev_driver_create");
|
128
|
+
if (status != ARES_SUCCESS) {
|
129
|
+
char *err_msg;
|
130
|
+
gpr_asprintf(&err_msg, "Failed to init ares channel. C-ares error: %s",
|
131
|
+
ares_strerror(status));
|
132
|
+
grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(err_msg);
|
133
|
+
gpr_free(err_msg);
|
134
|
+
gpr_free(*ev_driver);
|
135
|
+
return err;
|
136
|
+
}
|
137
|
+
gpr_mu_init(&(*ev_driver)->mu);
|
138
|
+
gpr_ref_init(&(*ev_driver)->refs, 1);
|
139
|
+
(*ev_driver)->pollset_set = pollset_set;
|
140
|
+
(*ev_driver)->fds = NULL;
|
141
|
+
(*ev_driver)->working = false;
|
142
|
+
(*ev_driver)->shutting_down = false;
|
143
|
+
return GRPC_ERROR_NONE;
|
144
|
+
}
|
145
|
+
|
146
|
+
void grpc_ares_ev_driver_destroy(grpc_ares_ev_driver *ev_driver) {
|
147
|
+
// It's not safe to shut down remaining fds here directly, becauses
|
148
|
+
// ares_host_callback does not provide an exec_ctx. We mark the event driver
|
149
|
+
// as being shut down. If the event driver is working,
|
150
|
+
// grpc_ares_notify_on_event_locked will shut down the fds; if it's not
|
151
|
+
// working, there are no fds to shut down.
|
152
|
+
gpr_mu_lock(&ev_driver->mu);
|
153
|
+
ev_driver->shutting_down = true;
|
154
|
+
gpr_mu_unlock(&ev_driver->mu);
|
155
|
+
grpc_ares_ev_driver_unref(ev_driver);
|
156
|
+
}
|
157
|
+
|
158
|
+
// Search fd in the fd_node list head. This is an O(n) search, the max possible
|
159
|
+
// value of n is ARES_GETSOCK_MAXNUM (16). n is typically 1 - 2 in our tests.
|
160
|
+
static fd_node *pop_fd_node(fd_node **head, int fd) {
|
161
|
+
fd_node dummy_head;
|
162
|
+
dummy_head.next = *head;
|
163
|
+
fd_node *node = &dummy_head;
|
164
|
+
while (node->next != NULL) {
|
165
|
+
if (grpc_fd_wrapped_fd(node->next->grpc_fd) == fd) {
|
166
|
+
fd_node *ret = node->next;
|
167
|
+
node->next = node->next->next;
|
168
|
+
*head = dummy_head.next;
|
169
|
+
return ret;
|
170
|
+
}
|
171
|
+
node = node->next;
|
172
|
+
}
|
173
|
+
return NULL;
|
174
|
+
}
|
175
|
+
|
176
|
+
static void on_readable_cb(grpc_exec_ctx *exec_ctx, void *arg,
|
177
|
+
grpc_error *error) {
|
178
|
+
fd_node *fdn = arg;
|
179
|
+
grpc_ares_ev_driver *ev_driver = fdn->ev_driver;
|
180
|
+
gpr_mu_lock(&fdn->mu);
|
181
|
+
fdn->readable_registered = false;
|
182
|
+
gpr_mu_unlock(&fdn->mu);
|
183
|
+
|
184
|
+
gpr_log(GPR_DEBUG, "readable on %d", grpc_fd_wrapped_fd(fdn->grpc_fd));
|
185
|
+
if (error == GRPC_ERROR_NONE) {
|
186
|
+
ares_process_fd(ev_driver->channel, grpc_fd_wrapped_fd(fdn->grpc_fd),
|
187
|
+
ARES_SOCKET_BAD);
|
188
|
+
} else {
|
189
|
+
// If error is not GRPC_ERROR_NONE, it means the fd has been shutdown or
|
190
|
+
// timed out. The pending lookups made on this ev_driver will be cancelled
|
191
|
+
// by the following ares_cancel() and the on_done callbacks will be invoked
|
192
|
+
// with a status of ARES_ECANCELLED. The remaining file descriptors in this
|
193
|
+
// ev_driver will be cleaned up in the follwing
|
194
|
+
// grpc_ares_notify_on_event_locked().
|
195
|
+
ares_cancel(ev_driver->channel);
|
196
|
+
}
|
197
|
+
gpr_mu_lock(&ev_driver->mu);
|
198
|
+
grpc_ares_notify_on_event_locked(exec_ctx, ev_driver);
|
199
|
+
gpr_mu_unlock(&ev_driver->mu);
|
200
|
+
grpc_ares_ev_driver_unref(ev_driver);
|
201
|
+
}
|
202
|
+
|
203
|
+
static void on_writable_cb(grpc_exec_ctx *exec_ctx, void *arg,
|
204
|
+
grpc_error *error) {
|
205
|
+
fd_node *fdn = arg;
|
206
|
+
grpc_ares_ev_driver *ev_driver = fdn->ev_driver;
|
207
|
+
gpr_mu_lock(&fdn->mu);
|
208
|
+
fdn->writable_registered = false;
|
209
|
+
gpr_mu_unlock(&fdn->mu);
|
210
|
+
|
211
|
+
gpr_log(GPR_DEBUG, "writable on %d", grpc_fd_wrapped_fd(fdn->grpc_fd));
|
212
|
+
if (error == GRPC_ERROR_NONE) {
|
213
|
+
ares_process_fd(ev_driver->channel, ARES_SOCKET_BAD,
|
214
|
+
grpc_fd_wrapped_fd(fdn->grpc_fd));
|
215
|
+
} else {
|
216
|
+
// If error is not GRPC_ERROR_NONE, it means the fd has been shutdown or
|
217
|
+
// timed out. The pending lookups made on this ev_driver will be cancelled
|
218
|
+
// by the following ares_cancel() and the on_done callbacks will be invoked
|
219
|
+
// with a status of ARES_ECANCELLED. The remaining file descriptors in this
|
220
|
+
// ev_driver will be cleaned up in the follwing
|
221
|
+
// grpc_ares_notify_on_event_locked().
|
222
|
+
ares_cancel(ev_driver->channel);
|
223
|
+
}
|
224
|
+
gpr_mu_lock(&ev_driver->mu);
|
225
|
+
grpc_ares_notify_on_event_locked(exec_ctx, ev_driver);
|
226
|
+
gpr_mu_unlock(&ev_driver->mu);
|
227
|
+
grpc_ares_ev_driver_unref(ev_driver);
|
228
|
+
}
|
229
|
+
|
230
|
+
ares_channel *grpc_ares_ev_driver_get_channel(grpc_ares_ev_driver *ev_driver) {
|
231
|
+
return &ev_driver->channel;
|
232
|
+
}
|
233
|
+
|
234
|
+
// Get the file descriptors used by the ev_driver's ares channel, register
|
235
|
+
// driver_closure with these filedescriptors.
|
236
|
+
static void grpc_ares_notify_on_event_locked(grpc_exec_ctx *exec_ctx,
|
237
|
+
grpc_ares_ev_driver *ev_driver) {
|
238
|
+
fd_node *new_list = NULL;
|
239
|
+
if (!ev_driver->shutting_down) {
|
240
|
+
ares_socket_t socks[ARES_GETSOCK_MAXNUM];
|
241
|
+
int socks_bitmask =
|
242
|
+
ares_getsock(ev_driver->channel, socks, ARES_GETSOCK_MAXNUM);
|
243
|
+
for (size_t i = 0; i < ARES_GETSOCK_MAXNUM; i++) {
|
244
|
+
if (ARES_GETSOCK_READABLE(socks_bitmask, i) ||
|
245
|
+
ARES_GETSOCK_WRITABLE(socks_bitmask, i)) {
|
246
|
+
fd_node *fdn = pop_fd_node(&ev_driver->fds, socks[i]);
|
247
|
+
// Create a new fd_node if sock[i] is not in the fd_node list.
|
248
|
+
if (fdn == NULL) {
|
249
|
+
char *fd_name;
|
250
|
+
gpr_asprintf(&fd_name, "ares_ev_driver-%" PRIuPTR, i);
|
251
|
+
fdn = gpr_malloc(sizeof(fd_node));
|
252
|
+
gpr_log(GPR_DEBUG, "new fd: %d", socks[i]);
|
253
|
+
fdn->grpc_fd = grpc_fd_create(socks[i], fd_name);
|
254
|
+
fdn->ev_driver = ev_driver;
|
255
|
+
fdn->readable_registered = false;
|
256
|
+
fdn->writable_registered = false;
|
257
|
+
gpr_mu_init(&fdn->mu);
|
258
|
+
grpc_closure_init(&fdn->read_closure, on_readable_cb, fdn,
|
259
|
+
grpc_schedule_on_exec_ctx);
|
260
|
+
grpc_closure_init(&fdn->write_closure, on_writable_cb, fdn,
|
261
|
+
grpc_schedule_on_exec_ctx);
|
262
|
+
grpc_pollset_set_add_fd(exec_ctx, ev_driver->pollset_set,
|
263
|
+
fdn->grpc_fd);
|
264
|
+
gpr_free(fd_name);
|
265
|
+
}
|
266
|
+
fdn->next = new_list;
|
267
|
+
new_list = fdn;
|
268
|
+
gpr_mu_lock(&fdn->mu);
|
269
|
+
// Register read_closure if the socket is readable and read_closure has
|
270
|
+
// not been registered with this socket.
|
271
|
+
if (ARES_GETSOCK_READABLE(socks_bitmask, i) &&
|
272
|
+
!fdn->readable_registered) {
|
273
|
+
grpc_ares_ev_driver_ref(ev_driver);
|
274
|
+
gpr_log(GPR_DEBUG, "notify read on: %d",
|
275
|
+
grpc_fd_wrapped_fd(fdn->grpc_fd));
|
276
|
+
grpc_fd_notify_on_read(exec_ctx, fdn->grpc_fd, &fdn->read_closure);
|
277
|
+
fdn->readable_registered = true;
|
278
|
+
}
|
279
|
+
// Register write_closure if the socket is writable and write_closure
|
280
|
+
// has not been registered with this socket.
|
281
|
+
if (ARES_GETSOCK_WRITABLE(socks_bitmask, i) &&
|
282
|
+
!fdn->writable_registered) {
|
283
|
+
gpr_log(GPR_DEBUG, "notify write on: %d",
|
284
|
+
grpc_fd_wrapped_fd(fdn->grpc_fd));
|
285
|
+
grpc_ares_ev_driver_ref(ev_driver);
|
286
|
+
grpc_fd_notify_on_write(exec_ctx, fdn->grpc_fd, &fdn->write_closure);
|
287
|
+
fdn->writable_registered = true;
|
288
|
+
}
|
289
|
+
gpr_mu_unlock(&fdn->mu);
|
290
|
+
}
|
291
|
+
}
|
292
|
+
}
|
293
|
+
// Any remaining fds in ev_driver->fds were not returned by ares_getsock() and
|
294
|
+
// are therefore no longer in use, so they can be shut down and removed from
|
295
|
+
// the list.
|
296
|
+
while (ev_driver->fds != NULL) {
|
297
|
+
fd_node *cur = ev_driver->fds;
|
298
|
+
ev_driver->fds = ev_driver->fds->next;
|
299
|
+
fd_node_destroy(exec_ctx, cur);
|
300
|
+
}
|
301
|
+
ev_driver->fds = new_list;
|
302
|
+
// If the ev driver has no working fd, all the tasks are done.
|
303
|
+
if (new_list == NULL) {
|
304
|
+
ev_driver->working = false;
|
305
|
+
gpr_log(GPR_DEBUG, "ev driver stop working");
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
void grpc_ares_ev_driver_start(grpc_exec_ctx *exec_ctx,
|
310
|
+
grpc_ares_ev_driver *ev_driver) {
|
311
|
+
gpr_mu_lock(&ev_driver->mu);
|
312
|
+
if (!ev_driver->working) {
|
313
|
+
ev_driver->working = true;
|
314
|
+
grpc_ares_notify_on_event_locked(exec_ctx, ev_driver);
|
315
|
+
}
|
316
|
+
gpr_mu_unlock(&ev_driver->mu);
|
317
|
+
}
|
318
|
+
|
319
|
+
#endif /* GRPC_ARES == 1 && defined(GRPC_POSIX_SOCKET) */
|
@@ -0,0 +1,289 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include <grpc/support/port_platform.h>
|
35
|
+
#if GRPC_ARES == 1 && !defined(GRPC_UV)
|
36
|
+
|
37
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
38
|
+
#include "src/core/lib/iomgr/sockaddr.h"
|
39
|
+
#include "src/core/lib/iomgr/socket_utils_posix.h"
|
40
|
+
|
41
|
+
#include <string.h>
|
42
|
+
#include <sys/types.h>
|
43
|
+
|
44
|
+
#include <ares.h>
|
45
|
+
#include <grpc/support/alloc.h>
|
46
|
+
#include <grpc/support/host_port.h>
|
47
|
+
#include <grpc/support/log.h>
|
48
|
+
#include <grpc/support/string_util.h>
|
49
|
+
#include <grpc/support/time.h>
|
50
|
+
#include <grpc/support/useful.h>
|
51
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
52
|
+
#include "src/core/lib/iomgr/executor.h"
|
53
|
+
#include "src/core/lib/iomgr/iomgr_internal.h"
|
54
|
+
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
55
|
+
#include "src/core/lib/support/string.h"
|
56
|
+
|
57
|
+
static gpr_once g_basic_init = GPR_ONCE_INIT;
|
58
|
+
static gpr_mu g_init_mu;
|
59
|
+
|
60
|
+
typedef struct grpc_ares_request {
|
61
|
+
/** following members are set in grpc_resolve_address_ares_impl */
|
62
|
+
/** host to resolve, parsed from the name to resolve */
|
63
|
+
char *host;
|
64
|
+
/** port to fill in sockaddr_in, parsed from the name to resolve */
|
65
|
+
char *port;
|
66
|
+
/** default port to use */
|
67
|
+
char *default_port;
|
68
|
+
/** closure to call when the request completes */
|
69
|
+
grpc_closure *on_done;
|
70
|
+
/** the pointer to receive the resolved addresses */
|
71
|
+
grpc_resolved_addresses **addrs_out;
|
72
|
+
/** the evernt driver used by this request */
|
73
|
+
grpc_ares_ev_driver *ev_driver;
|
74
|
+
/** number of ongoing queries */
|
75
|
+
gpr_refcount pending_queries;
|
76
|
+
|
77
|
+
/** mutex guarding the rest of the state */
|
78
|
+
gpr_mu mu;
|
79
|
+
/** is there at least one successful query, set in on_done_cb */
|
80
|
+
bool success;
|
81
|
+
/** the errors explaining the request failure, set in on_done_cb */
|
82
|
+
grpc_error *error;
|
83
|
+
} grpc_ares_request;
|
84
|
+
|
85
|
+
static void do_basic_init(void) { gpr_mu_init(&g_init_mu); }
|
86
|
+
|
87
|
+
static uint16_t strhtons(const char *port) {
|
88
|
+
if (strcmp(port, "http") == 0) {
|
89
|
+
return htons(80);
|
90
|
+
} else if (strcmp(port, "https") == 0) {
|
91
|
+
return htons(443);
|
92
|
+
}
|
93
|
+
return htons((unsigned short)atoi(port));
|
94
|
+
}
|
95
|
+
|
96
|
+
static void grpc_ares_request_unref(grpc_exec_ctx *exec_ctx,
|
97
|
+
grpc_ares_request *r) {
|
98
|
+
/* If there are no pending queries, invoke on_done callback and destroy the
|
99
|
+
request */
|
100
|
+
if (gpr_unref(&r->pending_queries)) {
|
101
|
+
/* TODO(zyc): Sort results with RFC6724 before invoking on_done. */
|
102
|
+
if (exec_ctx == NULL) {
|
103
|
+
/* A new exec_ctx is created here, as the c-ares interface does not
|
104
|
+
provide one in ares_host_callback. It's safe to schedule on_done with
|
105
|
+
the newly created exec_ctx, since the caller has been warned not to
|
106
|
+
acquire locks in on_done. ares_dns_resolver is using combiner to
|
107
|
+
protect resources needed by on_done. */
|
108
|
+
grpc_exec_ctx new_exec_ctx = GRPC_EXEC_CTX_INIT;
|
109
|
+
grpc_closure_sched(&new_exec_ctx, r->on_done, r->error);
|
110
|
+
grpc_exec_ctx_finish(&new_exec_ctx);
|
111
|
+
} else {
|
112
|
+
grpc_closure_sched(exec_ctx, r->on_done, r->error);
|
113
|
+
}
|
114
|
+
gpr_mu_destroy(&r->mu);
|
115
|
+
grpc_ares_ev_driver_destroy(r->ev_driver);
|
116
|
+
gpr_free(r->host);
|
117
|
+
gpr_free(r->port);
|
118
|
+
gpr_free(r->default_port);
|
119
|
+
gpr_free(r);
|
120
|
+
}
|
121
|
+
}
|
122
|
+
|
123
|
+
static void on_done_cb(void *arg, int status, int timeouts,
|
124
|
+
struct hostent *hostent) {
|
125
|
+
grpc_ares_request *r = (grpc_ares_request *)arg;
|
126
|
+
gpr_mu_lock(&r->mu);
|
127
|
+
if (status == ARES_SUCCESS) {
|
128
|
+
GRPC_ERROR_UNREF(r->error);
|
129
|
+
r->error = GRPC_ERROR_NONE;
|
130
|
+
r->success = true;
|
131
|
+
grpc_resolved_addresses **addresses = r->addrs_out;
|
132
|
+
if (*addresses == NULL) {
|
133
|
+
*addresses = gpr_malloc(sizeof(grpc_resolved_addresses));
|
134
|
+
(*addresses)->naddrs = 0;
|
135
|
+
(*addresses)->addrs = NULL;
|
136
|
+
}
|
137
|
+
size_t prev_naddr = (*addresses)->naddrs;
|
138
|
+
size_t i;
|
139
|
+
for (i = 0; hostent->h_addr_list[i] != NULL; i++) {
|
140
|
+
}
|
141
|
+
(*addresses)->naddrs += i;
|
142
|
+
(*addresses)->addrs =
|
143
|
+
gpr_realloc((*addresses)->addrs,
|
144
|
+
sizeof(grpc_resolved_address) * (*addresses)->naddrs);
|
145
|
+
for (i = prev_naddr; i < (*addresses)->naddrs; i++) {
|
146
|
+
memset(&(*addresses)->addrs[i], 0, sizeof(grpc_resolved_address));
|
147
|
+
if (hostent->h_addrtype == AF_INET6) {
|
148
|
+
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in6);
|
149
|
+
struct sockaddr_in6 *addr =
|
150
|
+
(struct sockaddr_in6 *)&(*addresses)->addrs[i].addr;
|
151
|
+
addr->sin6_family = (sa_family_t)hostent->h_addrtype;
|
152
|
+
addr->sin6_port = strhtons(r->port);
|
153
|
+
|
154
|
+
char output[INET6_ADDRSTRLEN];
|
155
|
+
memcpy(&addr->sin6_addr, hostent->h_addr_list[i - prev_naddr],
|
156
|
+
sizeof(struct in6_addr));
|
157
|
+
ares_inet_ntop(AF_INET6, &addr->sin6_addr, output, INET6_ADDRSTRLEN);
|
158
|
+
gpr_log(GPR_DEBUG,
|
159
|
+
"c-ares resolver gets a AF_INET6 result: \n"
|
160
|
+
" addr: %s\n port: %s\n sin6_scope_id: %d\n",
|
161
|
+
output, r->port, addr->sin6_scope_id);
|
162
|
+
} else {
|
163
|
+
(*addresses)->addrs[i].len = sizeof(struct sockaddr_in);
|
164
|
+
struct sockaddr_in *addr =
|
165
|
+
(struct sockaddr_in *)&(*addresses)->addrs[i].addr;
|
166
|
+
memcpy(&addr->sin_addr, hostent->h_addr_list[i - prev_naddr],
|
167
|
+
sizeof(struct in_addr));
|
168
|
+
addr->sin_family = (sa_family_t)hostent->h_addrtype;
|
169
|
+
addr->sin_port = strhtons(r->port);
|
170
|
+
|
171
|
+
char output[INET_ADDRSTRLEN];
|
172
|
+
ares_inet_ntop(AF_INET, &addr->sin_addr, output, INET_ADDRSTRLEN);
|
173
|
+
gpr_log(GPR_DEBUG,
|
174
|
+
"c-ares resolver gets a AF_INET result: \n"
|
175
|
+
" addr: %s\n port: %s\n",
|
176
|
+
output, r->port);
|
177
|
+
}
|
178
|
+
}
|
179
|
+
} else if (!r->success) {
|
180
|
+
char *error_msg;
|
181
|
+
gpr_asprintf(&error_msg, "C-ares status is not ARES_SUCCESS: %s",
|
182
|
+
ares_strerror(status));
|
183
|
+
grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
|
184
|
+
gpr_free(error_msg);
|
185
|
+
if (r->error == GRPC_ERROR_NONE) {
|
186
|
+
r->error = error;
|
187
|
+
} else {
|
188
|
+
r->error = grpc_error_add_child(error, r->error);
|
189
|
+
}
|
190
|
+
}
|
191
|
+
gpr_mu_unlock(&r->mu);
|
192
|
+
grpc_ares_request_unref(NULL, r);
|
193
|
+
}
|
194
|
+
|
195
|
+
void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
196
|
+
const char *default_port,
|
197
|
+
grpc_pollset_set *interested_parties,
|
198
|
+
grpc_closure *on_done,
|
199
|
+
grpc_resolved_addresses **addrs) {
|
200
|
+
/* TODO(zyc): Enable tracing after #9603 is checked in */
|
201
|
+
/* if (grpc_dns_trace) {
|
202
|
+
gpr_log(GPR_DEBUG, "resolve_address (blocking): name=%s, default_port=%s",
|
203
|
+
name, default_port);
|
204
|
+
} */
|
205
|
+
|
206
|
+
/* parse name, splitting it into host and port parts */
|
207
|
+
char *host;
|
208
|
+
char *port;
|
209
|
+
gpr_split_host_port(name, &host, &port);
|
210
|
+
if (host == NULL) {
|
211
|
+
grpc_error *err = grpc_error_set_str(
|
212
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
|
213
|
+
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
214
|
+
grpc_closure_sched(exec_ctx, on_done, err);
|
215
|
+
goto error_cleanup;
|
216
|
+
} else if (port == NULL) {
|
217
|
+
if (default_port == NULL) {
|
218
|
+
grpc_error *err = grpc_error_set_str(
|
219
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"),
|
220
|
+
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
221
|
+
grpc_closure_sched(exec_ctx, on_done, err);
|
222
|
+
goto error_cleanup;
|
223
|
+
}
|
224
|
+
port = gpr_strdup(default_port);
|
225
|
+
}
|
226
|
+
|
227
|
+
grpc_ares_ev_driver *ev_driver;
|
228
|
+
grpc_error *err = grpc_ares_ev_driver_create(&ev_driver, interested_parties);
|
229
|
+
if (err != GRPC_ERROR_NONE) {
|
230
|
+
GRPC_LOG_IF_ERROR("grpc_ares_ev_driver_create() failed", err);
|
231
|
+
goto error_cleanup;
|
232
|
+
}
|
233
|
+
|
234
|
+
grpc_ares_request *r = gpr_malloc(sizeof(grpc_ares_request));
|
235
|
+
gpr_mu_init(&r->mu);
|
236
|
+
r->ev_driver = ev_driver;
|
237
|
+
r->on_done = on_done;
|
238
|
+
r->addrs_out = addrs;
|
239
|
+
r->default_port = gpr_strdup(default_port);
|
240
|
+
r->port = port;
|
241
|
+
r->host = host;
|
242
|
+
r->success = false;
|
243
|
+
r->error = GRPC_ERROR_NONE;
|
244
|
+
ares_channel *channel = grpc_ares_ev_driver_get_channel(r->ev_driver);
|
245
|
+
gpr_ref_init(&r->pending_queries, 2);
|
246
|
+
if (grpc_ipv6_loopback_available()) {
|
247
|
+
gpr_ref(&r->pending_queries);
|
248
|
+
ares_gethostbyname(*channel, r->host, AF_INET6, on_done_cb, r);
|
249
|
+
}
|
250
|
+
ares_gethostbyname(*channel, r->host, AF_INET, on_done_cb, r);
|
251
|
+
/* TODO(zyc): Handle CNAME records here. */
|
252
|
+
grpc_ares_ev_driver_start(exec_ctx, r->ev_driver);
|
253
|
+
grpc_ares_request_unref(exec_ctx, r);
|
254
|
+
return;
|
255
|
+
|
256
|
+
error_cleanup:
|
257
|
+
gpr_free(host);
|
258
|
+
gpr_free(port);
|
259
|
+
}
|
260
|
+
|
261
|
+
void (*grpc_resolve_address_ares)(
|
262
|
+
grpc_exec_ctx *exec_ctx, const char *name, const char *default_port,
|
263
|
+
grpc_pollset_set *interested_parties, grpc_closure *on_done,
|
264
|
+
grpc_resolved_addresses **addrs) = grpc_resolve_address_ares_impl;
|
265
|
+
|
266
|
+
grpc_error *grpc_ares_init(void) {
|
267
|
+
gpr_once_init(&g_basic_init, do_basic_init);
|
268
|
+
gpr_mu_lock(&g_init_mu);
|
269
|
+
int status = ares_library_init(ARES_LIB_INIT_ALL);
|
270
|
+
gpr_mu_unlock(&g_init_mu);
|
271
|
+
|
272
|
+
if (status != ARES_SUCCESS) {
|
273
|
+
char *error_msg;
|
274
|
+
gpr_asprintf(&error_msg, "ares_library_init failed: %s",
|
275
|
+
ares_strerror(status));
|
276
|
+
grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
|
277
|
+
gpr_free(error_msg);
|
278
|
+
return error;
|
279
|
+
}
|
280
|
+
return GRPC_ERROR_NONE;
|
281
|
+
}
|
282
|
+
|
283
|
+
void grpc_ares_cleanup(void) {
|
284
|
+
gpr_mu_lock(&g_init_mu);
|
285
|
+
ares_library_cleanup();
|
286
|
+
gpr_mu_unlock(&g_init_mu);
|
287
|
+
}
|
288
|
+
|
289
|
+
#endif /* GRPC_ARES == 1 && !defined(GRPC_UV) */
|