grpc 1.3.4 → 1.4.0
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 +581 -450
- data/include/grpc/census.h +49 -49
- data/include/grpc/grpc.h +16 -70
- data/include/grpc/grpc_security.h +59 -59
- data/include/grpc/grpc_security_constants.h +9 -9
- data/include/grpc/impl/codegen/atm.h +1 -1
- data/include/grpc/impl/codegen/atm_windows.h +4 -4
- data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
- data/include/grpc/impl/codegen/compression_types.h +4 -5
- data/include/grpc/impl/codegen/gpr_slice.h +5 -5
- data/include/grpc/impl/codegen/gpr_types.h +6 -7
- data/include/grpc/impl/codegen/grpc_types.h +128 -59
- data/include/grpc/impl/codegen/port_platform.h +6 -0
- data/include/grpc/impl/codegen/propagation_bits.h +2 -2
- data/include/grpc/impl/codegen/slice.h +13 -12
- data/include/grpc/impl/codegen/status.h +23 -18
- data/include/grpc/impl/codegen/sync.h +1 -1
- data/include/grpc/load_reporting.h +6 -6
- data/include/grpc/slice.h +47 -25
- data/include/grpc/slice_buffer.h +18 -14
- data/include/grpc/support/alloc.h +7 -7
- data/include/grpc/support/cmdline.h +10 -10
- data/include/grpc/support/cpu.h +3 -3
- data/include/grpc/support/histogram.h +1 -1
- data/include/grpc/support/host_port.h +2 -2
- data/include/grpc/support/log.h +9 -9
- data/include/grpc/support/log_windows.h +1 -1
- data/include/grpc/support/string_util.h +3 -3
- data/include/grpc/support/subprocess.h +3 -3
- data/include/grpc/support/sync.h +31 -31
- data/include/grpc/support/thd.h +11 -11
- data/include/grpc/support/time.h +12 -12
- data/include/grpc/support/tls.h +1 -1
- data/include/grpc/support/tls_gcc.h +2 -2
- data/include/grpc/support/tls_msvc.h +1 -1
- data/include/grpc/support/tls_pthread.h +1 -1
- data/include/grpc/support/useful.h +2 -2
- data/include/grpc/support/workaround_list.h +46 -0
- data/src/core/ext/census/context.c +1 -1
- data/src/core/ext/census/intrusive_hash_map.c +319 -0
- data/src/core/ext/census/intrusive_hash_map.h +167 -0
- data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
- data/src/core/ext/census/resource.c +3 -1
- data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
- data/src/core/ext/filters/client_channel/client_channel.c +173 -103
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
- data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
- data/src/core/ext/filters/client_channel/parse_address.c +90 -59
- data/src/core/ext/filters/client_channel/parse_address.h +17 -8
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
- data/src/core/ext/filters/client_channel/subchannel.c +20 -17
- data/src/core/ext/filters/client_channel/subchannel.h +1 -0
- data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
- data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
- data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
- data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
- data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
- data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
- data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
- data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
- data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
- data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
- data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
- data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
- data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
- data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
- data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
- data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
- data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
- data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
- data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
- data/src/core/lib/channel/channel_args.c +30 -9
- data/src/core/lib/channel/channel_args.h +5 -1
- data/src/core/lib/channel/channel_stack.c +1 -1
- data/src/core/lib/channel/channel_stack.h +2 -2
- data/src/core/lib/channel/channel_stack_builder.c +13 -1
- data/src/core/lib/channel/channel_stack_builder.h +5 -1
- data/src/core/lib/channel/connected_channel.c +3 -1
- data/src/core/lib/channel/context.h +2 -2
- data/src/core/lib/compression/message_compress.c +2 -2
- data/src/core/lib/debug/trace.c +13 -6
- data/src/core/lib/debug/trace.h +27 -1
- data/src/core/lib/http/httpcli.c +1 -1
- data/src/core/lib/http/httpcli_security_connector.c +9 -11
- data/src/core/lib/http/parser.c +2 -2
- data/src/core/lib/http/parser.h +2 -1
- data/src/core/lib/iomgr/combiner.c +6 -6
- data/src/core/lib/iomgr/combiner.h +2 -1
- data/src/core/lib/iomgr/error.c +12 -5
- data/src/core/lib/iomgr/error.h +13 -13
- data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
- data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
- data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
- data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
- data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
- data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
- data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
- data/src/core/lib/iomgr/ev_posix.c +22 -8
- data/src/core/lib/iomgr/ev_posix.h +4 -3
- data/src/core/lib/iomgr/ev_windows.c +43 -0
- data/src/core/lib/iomgr/exec_ctx.c +5 -0
- data/src/core/lib/iomgr/exec_ctx.h +2 -0
- data/src/core/lib/iomgr/iomgr.c +4 -0
- data/src/core/lib/iomgr/iomgr.h +3 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
- data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
- data/src/core/lib/iomgr/lockfree_event.c +16 -0
- data/src/core/lib/iomgr/pollset.h +2 -5
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/resource_quota.c +9 -8
- data/src/core/lib/iomgr/resource_quota.h +2 -1
- data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
- data/src/core/lib/iomgr/socket_mutator.h +2 -0
- data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
- data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
- data/src/core/lib/iomgr/tcp_posix.c +7 -7
- data/src/core/lib/iomgr/tcp_posix.h +2 -1
- data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
- data/src/core/lib/iomgr/tcp_uv.c +6 -6
- data/src/core/lib/iomgr/tcp_uv.h +2 -1
- data/src/core/lib/iomgr/tcp_windows.c +1 -1
- data/src/core/lib/iomgr/timer_generic.c +24 -25
- data/src/core/lib/iomgr/timer_manager.c +276 -0
- data/src/core/lib/iomgr/timer_manager.h +52 -0
- data/src/core/lib/iomgr/timer_uv.c +6 -0
- data/src/core/lib/iomgr/udp_server.c +42 -9
- data/src/core/lib/iomgr/udp_server.h +3 -1
- data/src/core/lib/security/credentials/credentials.c +0 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
- data/src/core/lib/security/transport/client_auth_filter.c +9 -3
- data/src/core/lib/security/transport/secure_endpoint.c +7 -7
- data/src/core/lib/security/transport/secure_endpoint.h +1 -1
- data/src/core/lib/security/transport/security_connector.c +45 -57
- data/src/core/lib/security/transport/security_connector.h +10 -14
- data/src/core/lib/security/transport/security_handshaker.c +123 -97
- data/src/core/lib/slice/b64.c +1 -1
- data/src/core/lib/slice/percent_encoding.c +3 -3
- data/src/core/lib/slice/slice.c +66 -33
- data/src/core/lib/slice/slice_buffer.c +25 -6
- data/src/core/lib/slice/slice_hash_table.c +33 -35
- data/src/core/lib/slice/slice_hash_table.h +7 -12
- data/src/core/lib/support/atomic.h +45 -0
- data/src/core/lib/support/atomic_with_atm.h +70 -0
- data/src/core/lib/support/atomic_with_std.h +48 -0
- data/src/core/lib/support/avl.c +14 -14
- data/src/core/lib/support/cmdline.c +3 -3
- data/src/core/lib/support/histogram.c +2 -2
- data/src/core/lib/support/host_port.c +1 -1
- data/src/core/lib/support/memory.h +74 -0
- data/src/core/lib/support/mpscq.c +36 -2
- data/src/core/lib/support/mpscq.h +28 -1
- data/src/core/lib/support/stack_lockfree.c +3 -36
- data/src/core/lib/support/string.c +12 -12
- data/src/core/lib/support/string_posix.c +1 -1
- data/src/core/lib/support/subprocess_posix.c +2 -2
- data/src/core/lib/support/thd_posix.c +1 -1
- data/src/core/lib/support/time_posix.c +8 -0
- data/src/core/lib/support/tmpfile_posix.c +10 -10
- data/src/core/lib/surface/alarm.c +3 -1
- data/src/core/lib/surface/api_trace.c +2 -1
- data/src/core/lib/surface/api_trace.h +2 -2
- data/src/core/lib/surface/byte_buffer_reader.c +1 -1
- data/src/core/lib/surface/call.c +65 -22
- data/src/core/lib/surface/call.h +4 -2
- data/src/core/lib/surface/channel_init.c +2 -19
- data/src/core/lib/surface/channel_stack_type.c +18 -0
- data/src/core/lib/surface/channel_stack_type.h +2 -0
- data/src/core/lib/surface/completion_queue.c +694 -247
- data/src/core/lib/surface/completion_queue.h +30 -13
- data/src/core/lib/surface/completion_queue_factory.c +24 -9
- data/src/core/lib/surface/init.c +1 -52
- data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
- data/src/core/lib/surface/server.c +79 -110
- data/src/core/lib/surface/server.h +2 -1
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/bdp_estimator.c +25 -9
- data/src/core/lib/transport/bdp_estimator.h +7 -1
- data/src/core/lib/transport/byte_stream.c +23 -9
- data/src/core/lib/transport/byte_stream.h +15 -6
- data/src/core/lib/transport/connectivity_state.c +6 -6
- data/src/core/lib/transport/connectivity_state.h +2 -1
- data/src/core/lib/transport/service_config.c +6 -13
- data/src/core/lib/transport/service_config.h +2 -2
- data/src/core/lib/transport/static_metadata.c +403 -389
- data/src/core/lib/transport/static_metadata.h +127 -114
- data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
- data/src/core/tsi/fake_transport_security.c +5 -4
- data/src/core/tsi/ssl_transport_security.c +71 -82
- data/src/core/tsi/ssl_transport_security.h +39 -61
- data/src/core/tsi/transport_security.c +83 -2
- data/src/core/tsi/transport_security.h +27 -2
- data/src/core/tsi/transport_security_adapter.c +236 -0
- data/src/core/tsi/transport_security_adapter.h +62 -0
- data/src/core/tsi/transport_security_interface.h +179 -66
- data/src/ruby/ext/grpc/extconf.rb +2 -1
- data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
- data/src/ruby/ext/grpc/rb_call.c +56 -48
- data/src/ruby/ext/grpc/rb_call.h +3 -4
- data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
- data/src/ruby/ext/grpc/rb_channel.c +2 -3
- data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
- data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
- data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
- data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
- data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
- data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
- data/src/ruby/ext/grpc/rb_grpc.c +11 -15
- data/src/ruby/ext/grpc/rb_grpc.h +2 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
- data/src/ruby/ext/grpc/rb_server.c +26 -28
- data/src/ruby/lib/grpc/grpc.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/third_party/cares/config_linux/ares_config.h +36 -2
- data/third_party/zlib/adler32.c +14 -7
- data/third_party/zlib/compress.c +24 -18
- data/third_party/zlib/crc32.c +29 -12
- data/third_party/zlib/deflate.c +499 -303
- data/third_party/zlib/deflate.h +19 -16
- data/third_party/zlib/gzguts.h +16 -7
- data/third_party/zlib/gzlib.c +17 -14
- data/third_party/zlib/gzread.c +108 -48
- data/third_party/zlib/gzwrite.c +210 -122
- data/third_party/zlib/infback.c +2 -2
- data/third_party/zlib/inffast.c +34 -51
- data/third_party/zlib/inflate.c +86 -37
- data/third_party/zlib/inflate.h +7 -4
- data/third_party/zlib/inftrees.c +12 -14
- data/third_party/zlib/trees.c +38 -61
- data/third_party/zlib/uncompr.c +66 -32
- data/third_party/zlib/zconf.h +32 -9
- data/third_party/zlib/zlib.h +298 -154
- data/third_party/zlib/zutil.c +25 -24
- data/third_party/zlib/zutil.h +35 -17
- metadata +63 -30
@@ -36,16 +36,18 @@
|
|
36
36
|
#include <grpc/support/alloc.h>
|
37
37
|
#include <grpc/support/string_util.h>
|
38
38
|
|
39
|
+
#include "src/core/lib/channel/channel_args.h"
|
40
|
+
|
39
41
|
#include "src/core/ext/filters/client_channel/lb_policy_factory.h"
|
42
|
+
#include "src/core/ext/filters/client_channel/parse_address.h"
|
40
43
|
|
41
44
|
grpc_lb_addresses* grpc_lb_addresses_create(
|
42
45
|
size_t num_addresses, const grpc_lb_user_data_vtable* user_data_vtable) {
|
43
|
-
grpc_lb_addresses* addresses =
|
46
|
+
grpc_lb_addresses* addresses = gpr_zalloc(sizeof(grpc_lb_addresses));
|
44
47
|
addresses->num_addresses = num_addresses;
|
45
48
|
addresses->user_data_vtable = user_data_vtable;
|
46
49
|
const size_t addresses_size = sizeof(grpc_lb_address) * num_addresses;
|
47
|
-
addresses->addresses =
|
48
|
-
memset(addresses->addresses, 0, addresses_size);
|
50
|
+
addresses->addresses = gpr_zalloc(addresses_size);
|
49
51
|
return addresses;
|
50
52
|
}
|
51
53
|
|
@@ -69,7 +71,7 @@ grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses) {
|
|
69
71
|
|
70
72
|
void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index,
|
71
73
|
void* address, size_t address_len,
|
72
|
-
bool is_balancer, char* balancer_name,
|
74
|
+
bool is_balancer, const char* balancer_name,
|
73
75
|
void* user_data) {
|
74
76
|
GPR_ASSERT(index < addresses->num_addresses);
|
75
77
|
if (user_data != NULL) GPR_ASSERT(addresses->user_data_vtable != NULL);
|
@@ -77,10 +79,22 @@ void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index,
|
|
77
79
|
memcpy(target->address.addr, address, address_len);
|
78
80
|
target->address.len = address_len;
|
79
81
|
target->is_balancer = is_balancer;
|
80
|
-
target->balancer_name = balancer_name;
|
82
|
+
target->balancer_name = gpr_strdup(balancer_name);
|
81
83
|
target->user_data = user_data;
|
82
84
|
}
|
83
85
|
|
86
|
+
bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses* addresses,
|
87
|
+
size_t index, const grpc_uri* uri,
|
88
|
+
bool is_balancer,
|
89
|
+
const char* balancer_name,
|
90
|
+
void* user_data) {
|
91
|
+
grpc_resolved_address address;
|
92
|
+
if (!grpc_parse_uri(uri, &address)) return false;
|
93
|
+
grpc_lb_addresses_set_address(addresses, index, address.addr, address.len,
|
94
|
+
is_balancer, balancer_name, user_data);
|
95
|
+
return true;
|
96
|
+
}
|
97
|
+
|
84
98
|
int grpc_lb_addresses_cmp(const grpc_lb_addresses* addresses1,
|
85
99
|
const grpc_lb_addresses* addresses2) {
|
86
100
|
if (addresses1->num_addresses > addresses2->num_addresses) return 1;
|
@@ -147,6 +161,15 @@ grpc_arg grpc_lb_addresses_create_channel_arg(
|
|
147
161
|
return arg;
|
148
162
|
}
|
149
163
|
|
164
|
+
grpc_lb_addresses* grpc_lb_addresses_find_channel_arg(
|
165
|
+
const grpc_channel_args* channel_args) {
|
166
|
+
const grpc_arg* lb_addresses_arg =
|
167
|
+
grpc_channel_args_find(channel_args, GRPC_ARG_LB_ADDRESSES);
|
168
|
+
if (lb_addresses_arg == NULL || lb_addresses_arg->type != GRPC_ARG_POINTER)
|
169
|
+
return NULL;
|
170
|
+
return lb_addresses_arg->value.pointer.p;
|
171
|
+
}
|
172
|
+
|
150
173
|
void grpc_lb_policy_factory_ref(grpc_lb_policy_factory* factory) {
|
151
174
|
factory->vtable->ref(factory);
|
152
175
|
}
|
@@ -34,12 +34,13 @@
|
|
34
34
|
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_FACTORY_H
|
35
35
|
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_FACTORY_H
|
36
36
|
|
37
|
-
#include "src/core/ext/filters/client_channel/client_channel_factory.h"
|
38
|
-
#include "src/core/ext/filters/client_channel/lb_policy.h"
|
39
|
-
|
40
37
|
#include "src/core/lib/iomgr/exec_ctx.h"
|
41
38
|
#include "src/core/lib/iomgr/resolve_address.h"
|
42
39
|
|
40
|
+
#include "src/core/ext/filters/client_channel/client_channel_factory.h"
|
41
|
+
#include "src/core/ext/filters/client_channel/lb_policy.h"
|
42
|
+
#include "src/core/ext/filters/client_channel/uri_parser.h"
|
43
|
+
|
43
44
|
// Channel arg key for grpc_lb_addresses.
|
44
45
|
#define GRPC_ARG_LB_ADDRESSES "grpc.lb_addresses"
|
45
46
|
|
@@ -88,9 +89,18 @@ grpc_lb_addresses *grpc_lb_addresses_copy(const grpc_lb_addresses *addresses);
|
|
88
89
|
* Takes ownership of \a balancer_name. */
|
89
90
|
void grpc_lb_addresses_set_address(grpc_lb_addresses *addresses, size_t index,
|
90
91
|
void *address, size_t address_len,
|
91
|
-
bool is_balancer, char *balancer_name,
|
92
|
+
bool is_balancer, const char *balancer_name,
|
92
93
|
void *user_data);
|
93
94
|
|
95
|
+
/** Sets the value of the address at index \a index of \a addresses from \a uri.
|
96
|
+
* Returns true upon success, false otherwise. Takes ownership of \a
|
97
|
+
* balancer_name. */
|
98
|
+
bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses *addresses,
|
99
|
+
size_t index, const grpc_uri *uri,
|
100
|
+
bool is_balancer,
|
101
|
+
const char *balancer_name,
|
102
|
+
void *user_data);
|
103
|
+
|
94
104
|
/** Compares \a addresses1 and \a addresses2. */
|
95
105
|
int grpc_lb_addresses_cmp(const grpc_lb_addresses *addresses1,
|
96
106
|
const grpc_lb_addresses *addresses2);
|
@@ -103,6 +113,10 @@ void grpc_lb_addresses_destroy(grpc_exec_ctx *exec_ctx,
|
|
103
113
|
grpc_arg grpc_lb_addresses_create_channel_arg(
|
104
114
|
const grpc_lb_addresses *addresses);
|
105
115
|
|
116
|
+
/** Returns the \a grpc_lb_addresses instance in \a channel_args or NULL */
|
117
|
+
grpc_lb_addresses *grpc_lb_addresses_find_channel_arg(
|
118
|
+
const grpc_channel_args *channel_args);
|
119
|
+
|
106
120
|
/** Arguments passed to LB policies. */
|
107
121
|
typedef struct grpc_lb_policy_args {
|
108
122
|
grpc_client_channel_factory *client_channel_factory;
|
@@ -48,81 +48,90 @@
|
|
48
48
|
|
49
49
|
#ifdef GRPC_HAVE_UNIX_SOCKET
|
50
50
|
|
51
|
-
|
51
|
+
bool grpc_parse_unix(const grpc_uri *uri,
|
52
|
+
grpc_resolved_address *resolved_addr) {
|
53
|
+
if (strcmp("unix", uri->scheme) != 0) {
|
54
|
+
gpr_log(GPR_ERROR, "Expected 'unix' scheme, got '%s'", uri->scheme);
|
55
|
+
return false;
|
56
|
+
}
|
52
57
|
struct sockaddr_un *un = (struct sockaddr_un *)resolved_addr->addr;
|
53
58
|
const size_t maxlen = sizeof(un->sun_path);
|
54
59
|
const size_t path_len = strnlen(uri->path, maxlen);
|
55
|
-
if (path_len == maxlen) return
|
60
|
+
if (path_len == maxlen) return false;
|
56
61
|
un->sun_family = AF_UNIX;
|
57
62
|
strcpy(un->sun_path, uri->path);
|
58
63
|
resolved_addr->len = sizeof(*un);
|
59
|
-
return
|
64
|
+
return true;
|
60
65
|
}
|
61
66
|
|
62
67
|
#else /* GRPC_HAVE_UNIX_SOCKET */
|
63
68
|
|
64
|
-
|
69
|
+
bool grpc_parse_unix(const grpc_uri *uri,
|
70
|
+
grpc_resolved_address *resolved_addr) {
|
71
|
+
abort();
|
72
|
+
}
|
65
73
|
|
66
74
|
#endif /* GRPC_HAVE_UNIX_SOCKET */
|
67
75
|
|
68
|
-
|
69
|
-
|
76
|
+
bool grpc_parse_ipv4_hostport(const char *hostport, grpc_resolved_address *addr,
|
77
|
+
bool log_errors) {
|
78
|
+
bool success = false;
|
79
|
+
// Split host and port.
|
70
80
|
char *host;
|
71
81
|
char *port;
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
if (!gpr_split_host_port(host_port, &host, &port)) {
|
78
|
-
return 0;
|
79
|
-
}
|
80
|
-
|
81
|
-
memset(resolved_addr, 0, sizeof(grpc_resolved_address));
|
82
|
-
resolved_addr->len = sizeof(struct sockaddr_in);
|
82
|
+
if (!gpr_split_host_port(hostport, &host, &port)) return false;
|
83
|
+
// Parse IP address.
|
84
|
+
memset(addr, 0, sizeof(*addr));
|
85
|
+
addr->len = sizeof(struct sockaddr_in);
|
86
|
+
struct sockaddr_in *in = (struct sockaddr_in *)addr->addr;
|
83
87
|
in->sin_family = AF_INET;
|
84
88
|
if (inet_pton(AF_INET, host, &in->sin_addr) == 0) {
|
85
|
-
gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host);
|
89
|
+
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 address: '%s'", host);
|
86
90
|
goto done;
|
87
91
|
}
|
88
|
-
|
89
|
-
if (port
|
90
|
-
if (
|
91
|
-
port_num > 65535) {
|
92
|
-
gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
|
93
|
-
goto done;
|
94
|
-
}
|
95
|
-
in->sin_port = htons((uint16_t)port_num);
|
96
|
-
} else {
|
97
|
-
gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
|
92
|
+
// Parse port.
|
93
|
+
if (port == NULL) {
|
94
|
+
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv4 scheme");
|
98
95
|
goto done;
|
99
96
|
}
|
100
|
-
|
101
|
-
|
97
|
+
int port_num;
|
98
|
+
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
|
99
|
+
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv4 port: '%s'", port);
|
100
|
+
goto done;
|
101
|
+
}
|
102
|
+
in->sin_port = htons((uint16_t)port_num);
|
103
|
+
success = true;
|
102
104
|
done:
|
103
105
|
gpr_free(host);
|
104
106
|
gpr_free(port);
|
105
|
-
return
|
107
|
+
return success;
|
106
108
|
}
|
107
109
|
|
108
|
-
|
110
|
+
bool grpc_parse_ipv4(const grpc_uri *uri,
|
111
|
+
grpc_resolved_address *resolved_addr) {
|
112
|
+
if (strcmp("ipv4", uri->scheme) != 0) {
|
113
|
+
gpr_log(GPR_ERROR, "Expected 'ipv4' scheme, got '%s'", uri->scheme);
|
114
|
+
return false;
|
115
|
+
}
|
109
116
|
const char *host_port = uri->path;
|
110
|
-
char *host;
|
111
|
-
char *port;
|
112
|
-
int port_num;
|
113
|
-
int result = 0;
|
114
|
-
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)resolved_addr->addr;
|
115
|
-
|
116
117
|
if (*host_port == '/') ++host_port;
|
117
|
-
|
118
|
-
|
119
|
-
|
118
|
+
return grpc_parse_ipv4_hostport(host_port, resolved_addr,
|
119
|
+
true /* log_errors */);
|
120
|
+
}
|
120
121
|
|
121
|
-
|
122
|
-
|
122
|
+
bool grpc_parse_ipv6_hostport(const char *hostport, grpc_resolved_address *addr,
|
123
|
+
bool log_errors) {
|
124
|
+
bool success = false;
|
125
|
+
// Split host and port.
|
126
|
+
char *host;
|
127
|
+
char *port;
|
128
|
+
if (!gpr_split_host_port(hostport, &host, &port)) return false;
|
129
|
+
// Parse IP address.
|
130
|
+
memset(addr, 0, sizeof(*addr));
|
131
|
+
addr->len = sizeof(struct sockaddr_in6);
|
132
|
+
struct sockaddr_in6 *in6 = (struct sockaddr_in6 *)addr->addr;
|
123
133
|
in6->sin6_family = AF_INET6;
|
124
|
-
|
125
|
-
/* Handle the RFC6874 syntax for IPv6 zone identifiers. */
|
134
|
+
// Handle the RFC6874 syntax for IPv6 zone identifiers.
|
126
135
|
char *host_end = (char *)gpr_memrchr(host, '%', strlen(host));
|
127
136
|
if (host_end != NULL) {
|
128
137
|
GPR_ASSERT(host_end >= host);
|
@@ -141,7 +150,7 @@ int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr) {
|
|
141
150
|
gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
|
142
151
|
goto done;
|
143
152
|
}
|
144
|
-
// Handle "sin6_scope_id" being type "u_long". See grpc issue
|
153
|
+
// Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
|
145
154
|
in6->sin6_scope_id = sin6_scope_id;
|
146
155
|
} else {
|
147
156
|
if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
|
@@ -149,22 +158,44 @@ int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr) {
|
|
149
158
|
goto done;
|
150
159
|
}
|
151
160
|
}
|
152
|
-
|
153
|
-
if (port
|
154
|
-
if (
|
155
|
-
port_num > 65535) {
|
156
|
-
gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
|
157
|
-
goto done;
|
158
|
-
}
|
159
|
-
in6->sin6_port = htons((uint16_t)port_num);
|
160
|
-
} else {
|
161
|
-
gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
|
161
|
+
// Parse port.
|
162
|
+
if (port == NULL) {
|
163
|
+
if (log_errors) gpr_log(GPR_ERROR, "no port given for ipv6 scheme");
|
162
164
|
goto done;
|
163
165
|
}
|
164
|
-
|
165
|
-
|
166
|
+
int port_num;
|
167
|
+
if (sscanf(port, "%d", &port_num) != 1 || port_num < 0 || port_num > 65535) {
|
168
|
+
if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 port: '%s'", port);
|
169
|
+
goto done;
|
170
|
+
}
|
171
|
+
in6->sin6_port = htons((uint16_t)port_num);
|
172
|
+
success = true;
|
166
173
|
done:
|
167
174
|
gpr_free(host);
|
168
175
|
gpr_free(port);
|
169
|
-
return
|
176
|
+
return success;
|
177
|
+
}
|
178
|
+
|
179
|
+
bool grpc_parse_ipv6(const grpc_uri *uri,
|
180
|
+
grpc_resolved_address *resolved_addr) {
|
181
|
+
if (strcmp("ipv6", uri->scheme) != 0) {
|
182
|
+
gpr_log(GPR_ERROR, "Expected 'ipv6' scheme, got '%s'", uri->scheme);
|
183
|
+
return false;
|
184
|
+
}
|
185
|
+
const char *host_port = uri->path;
|
186
|
+
if (*host_port == '/') ++host_port;
|
187
|
+
return grpc_parse_ipv6_hostport(host_port, resolved_addr,
|
188
|
+
true /* log_errors */);
|
189
|
+
}
|
190
|
+
|
191
|
+
bool grpc_parse_uri(const grpc_uri *uri, grpc_resolved_address *resolved_addr) {
|
192
|
+
if (strcmp("unix", uri->scheme) == 0) {
|
193
|
+
return grpc_parse_unix(uri, resolved_addr);
|
194
|
+
} else if (strcmp("ipv4", uri->scheme) == 0) {
|
195
|
+
return grpc_parse_ipv4(uri, resolved_addr);
|
196
|
+
} else if (strcmp("ipv6", uri->scheme) == 0) {
|
197
|
+
return grpc_parse_ipv6(uri, resolved_addr);
|
198
|
+
}
|
199
|
+
gpr_log(GPR_ERROR, "Can't parse scheme '%s'", uri->scheme);
|
200
|
+
return false;
|
170
201
|
}
|
@@ -39,16 +39,25 @@
|
|
39
39
|
#include "src/core/ext/filters/client_channel/uri_parser.h"
|
40
40
|
#include "src/core/lib/iomgr/resolve_address.h"
|
41
41
|
|
42
|
-
/** Populate \a
|
42
|
+
/** Populate \a resolved_addr from \a uri, whose path is expected to contain a
|
43
43
|
* unix socket path. Returns true upon success. */
|
44
|
-
|
44
|
+
bool grpc_parse_unix(const grpc_uri *uri, grpc_resolved_address *resolved_addr);
|
45
45
|
|
46
|
-
/** Populate
|
47
|
-
* host:port pair. Returns true upon success. */
|
48
|
-
|
46
|
+
/** Populate \a resolved_addr from \a uri, whose path is expected to contain an
|
47
|
+
* IPv4 host:port pair. Returns true upon success. */
|
48
|
+
bool grpc_parse_ipv4(const grpc_uri *uri, grpc_resolved_address *resolved_addr);
|
49
49
|
|
50
|
-
/** Populate
|
51
|
-
* host:port pair. Returns true upon success. */
|
52
|
-
|
50
|
+
/** Populate \a resolved_addr from \a uri, whose path is expected to contain an
|
51
|
+
* IPv6 host:port pair. Returns true upon success. */
|
52
|
+
bool grpc_parse_ipv6(const grpc_uri *uri, grpc_resolved_address *resolved_addr);
|
53
|
+
|
54
|
+
/** Populate \a resolved_addr from \a uri. Returns true upon success. */
|
55
|
+
bool grpc_parse_uri(const grpc_uri *uri, grpc_resolved_address *resolved_addr);
|
56
|
+
|
57
|
+
/** Parse bare IPv4 or IPv6 "IP:port" strings. */
|
58
|
+
bool grpc_parse_ipv4_hostport(const char *hostport, grpc_resolved_address *addr,
|
59
|
+
bool log_errors);
|
60
|
+
bool grpc_parse_ipv6_hostport(const char *hostport, grpc_resolved_address *addr,
|
61
|
+
bool log_errors);
|
53
62
|
|
54
63
|
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_PARSE_ADDRESS_H */
|
@@ -61,6 +61,8 @@
|
|
61
61
|
typedef struct {
|
62
62
|
/** base class: must be first */
|
63
63
|
grpc_resolver base;
|
64
|
+
/** DNS server to use (if not system default) */
|
65
|
+
char *dns_server;
|
64
66
|
/** name to resolve (usually the same as target_name) */
|
65
67
|
char *name_to_resolve;
|
66
68
|
/** default port to use */
|
@@ -172,6 +174,8 @@ static void dns_ares_on_resolved_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
|
172
174
|
grpc_resolved_addresses_destroy(r->addresses);
|
173
175
|
grpc_lb_addresses_destroy(exec_ctx, addresses);
|
174
176
|
} else {
|
177
|
+
const char *msg = grpc_error_string(error);
|
178
|
+
gpr_log(GPR_DEBUG, "dns resolution failed: %s", msg);
|
175
179
|
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
|
176
180
|
gpr_timespec next_try = gpr_backoff_step(&r->backoff_state, now);
|
177
181
|
gpr_timespec timeout = gpr_time_sub(next_try, now);
|
@@ -221,9 +225,9 @@ static void dns_ares_start_resolving_locked(grpc_exec_ctx *exec_ctx,
|
|
221
225
|
GPR_ASSERT(!r->resolving);
|
222
226
|
r->resolving = true;
|
223
227
|
r->addresses = NULL;
|
224
|
-
|
225
|
-
r->
|
226
|
-
&r->addresses);
|
228
|
+
grpc_dns_lookup_ares(exec_ctx, r->dns_server, r->name_to_resolve,
|
229
|
+
r->default_port, r->interested_parties,
|
230
|
+
&r->dns_ares_on_resolved_locked, &r->addresses);
|
227
231
|
}
|
228
232
|
|
229
233
|
static void dns_ares_maybe_finish_next_locked(grpc_exec_ctx *exec_ctx,
|
@@ -246,6 +250,7 @@ static void dns_ares_destroy(grpc_exec_ctx *exec_ctx, grpc_resolver *gr) {
|
|
246
250
|
grpc_channel_args_destroy(exec_ctx, r->resolved_result);
|
247
251
|
}
|
248
252
|
grpc_pollset_set_destroy(exec_ctx, r->interested_parties);
|
253
|
+
gpr_free(r->dns_server);
|
249
254
|
gpr_free(r->name_to_resolve);
|
250
255
|
gpr_free(r->default_port);
|
251
256
|
grpc_channel_args_destroy(exec_ctx, r->channel_args);
|
@@ -257,14 +262,13 @@ static grpc_resolver *dns_ares_create(grpc_exec_ctx *exec_ctx,
|
|
257
262
|
const char *default_port) {
|
258
263
|
// Get name from args.
|
259
264
|
const char *path = args->uri->path;
|
260
|
-
if (0 != strcmp(args->uri->authority, "")) {
|
261
|
-
gpr_log(GPR_ERROR, "authority based dns uri's not supported");
|
262
|
-
return NULL;
|
263
|
-
}
|
264
265
|
if (path[0] == '/') ++path;
|
265
266
|
// Create resolver.
|
266
267
|
ares_dns_resolver *r = gpr_zalloc(sizeof(ares_dns_resolver));
|
267
268
|
grpc_resolver_init(&r->base, &dns_ares_resolver_vtable, args->combiner);
|
269
|
+
if (0 != strcmp(args->uri->authority, "")) {
|
270
|
+
r->dns_server = gpr_strdup(args->uri->authority);
|
271
|
+
}
|
268
272
|
r->name_to_resolve = gpr_strdup(path);
|
269
273
|
r->default_port = gpr_strdup(default_port);
|
270
274
|
r->channel_args = grpc_channel_args_copy(args->args);
|
@@ -48,7 +48,10 @@
|
|
48
48
|
#include <grpc/support/string_util.h>
|
49
49
|
#include <grpc/support/time.h>
|
50
50
|
#include <grpc/support/useful.h>
|
51
|
+
|
52
|
+
#include "src/core/ext/filters/client_channel/parse_address.h"
|
51
53
|
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
54
|
+
#include "src/core/lib/iomgr/error.h"
|
52
55
|
#include "src/core/lib/iomgr/executor.h"
|
53
56
|
#include "src/core/lib/iomgr/iomgr_internal.h"
|
54
57
|
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
@@ -58,6 +61,8 @@ static gpr_once g_basic_init = GPR_ONCE_INIT;
|
|
58
61
|
static gpr_mu g_init_mu;
|
59
62
|
|
60
63
|
typedef struct grpc_ares_request {
|
64
|
+
/** indicates the DNS server to use, if specified */
|
65
|
+
struct ares_addr_port_node dns_server_addr;
|
61
66
|
/** following members are set in grpc_resolve_address_ares_impl */
|
62
67
|
/** host to resolve, parsed from the name to resolve */
|
63
68
|
char *host;
|
@@ -192,11 +197,12 @@ static void on_done_cb(void *arg, int status, int timeouts,
|
|
192
197
|
grpc_ares_request_unref(NULL, r);
|
193
198
|
}
|
194
199
|
|
195
|
-
void
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
+
void grpc_dns_lookup_ares(grpc_exec_ctx *exec_ctx, const char *dns_server,
|
201
|
+
const char *name, const char *default_port,
|
202
|
+
grpc_pollset_set *interested_parties,
|
203
|
+
grpc_closure *on_done,
|
204
|
+
grpc_resolved_addresses **addrs) {
|
205
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
200
206
|
/* TODO(zyc): Enable tracing after #9603 is checked in */
|
201
207
|
/* if (grpc_dns_trace) {
|
202
208
|
gpr_log(GPR_DEBUG, "resolve_address (blocking): name=%s, default_port=%s",
|
@@ -208,28 +214,23 @@ void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
|
208
214
|
char *port;
|
209
215
|
gpr_split_host_port(name, &host, &port);
|
210
216
|
if (host == NULL) {
|
211
|
-
|
217
|
+
error = grpc_error_set_str(
|
212
218
|
GRPC_ERROR_CREATE_FROM_STATIC_STRING("unparseable host:port"),
|
213
219
|
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
214
|
-
grpc_closure_sched(exec_ctx, on_done, err);
|
215
220
|
goto error_cleanup;
|
216
221
|
} else if (port == NULL) {
|
217
222
|
if (default_port == NULL) {
|
218
|
-
|
223
|
+
error = grpc_error_set_str(
|
219
224
|
GRPC_ERROR_CREATE_FROM_STATIC_STRING("no port in name"),
|
220
225
|
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
221
|
-
grpc_closure_sched(exec_ctx, on_done, err);
|
222
226
|
goto error_cleanup;
|
223
227
|
}
|
224
228
|
port = gpr_strdup(default_port);
|
225
229
|
}
|
226
230
|
|
227
231
|
grpc_ares_ev_driver *ev_driver;
|
228
|
-
|
229
|
-
if (
|
230
|
-
GRPC_LOG_IF_ERROR("grpc_ares_ev_driver_create() failed", err);
|
231
|
-
goto error_cleanup;
|
232
|
-
}
|
232
|
+
error = grpc_ares_ev_driver_create(&ev_driver, interested_parties);
|
233
|
+
if (error != GRPC_ERROR_NONE) goto error_cleanup;
|
233
234
|
|
234
235
|
grpc_ares_request *r = gpr_malloc(sizeof(grpc_ares_request));
|
235
236
|
gpr_mu_init(&r->mu);
|
@@ -242,6 +243,40 @@ void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
|
242
243
|
r->success = false;
|
243
244
|
r->error = GRPC_ERROR_NONE;
|
244
245
|
ares_channel *channel = grpc_ares_ev_driver_get_channel(r->ev_driver);
|
246
|
+
|
247
|
+
// If dns_server is specified, use it.
|
248
|
+
if (dns_server != NULL) {
|
249
|
+
gpr_log(GPR_INFO, "Using DNS server %s", dns_server);
|
250
|
+
grpc_resolved_address addr;
|
251
|
+
if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) {
|
252
|
+
r->dns_server_addr.family = AF_INET;
|
253
|
+
memcpy(&r->dns_server_addr.addr.addr4, addr.addr, addr.len);
|
254
|
+
r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr);
|
255
|
+
r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr);
|
256
|
+
} else if (grpc_parse_ipv6_hostport(dns_server, &addr,
|
257
|
+
false /* log_errors */)) {
|
258
|
+
r->dns_server_addr.family = AF_INET6;
|
259
|
+
memcpy(&r->dns_server_addr.addr.addr6, addr.addr, addr.len);
|
260
|
+
r->dns_server_addr.tcp_port = grpc_sockaddr_get_port(&addr);
|
261
|
+
r->dns_server_addr.udp_port = grpc_sockaddr_get_port(&addr);
|
262
|
+
} else {
|
263
|
+
error = grpc_error_set_str(
|
264
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("cannot parse authority"),
|
265
|
+
GRPC_ERROR_STR_TARGET_ADDRESS, grpc_slice_from_copied_string(name));
|
266
|
+
goto error_cleanup;
|
267
|
+
}
|
268
|
+
int status = ares_set_servers_ports(*channel, &r->dns_server_addr);
|
269
|
+
if (status != ARES_SUCCESS) {
|
270
|
+
char *error_msg;
|
271
|
+
gpr_asprintf(&error_msg, "C-ares status is not ARES_SUCCESS: %s",
|
272
|
+
ares_strerror(status));
|
273
|
+
error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(error_msg);
|
274
|
+
gpr_free(error_msg);
|
275
|
+
goto error_cleanup;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
// An extra reference is put here to avoid destroying the request in
|
279
|
+
// on_done_cb before calling grpc_ares_ev_driver_start.
|
245
280
|
gpr_ref_init(&r->pending_queries, 2);
|
246
281
|
if (grpc_ipv6_loopback_available()) {
|
247
282
|
gpr_ref(&r->pending_queries);
|
@@ -254,10 +289,20 @@ void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
|
254
289
|
return;
|
255
290
|
|
256
291
|
error_cleanup:
|
292
|
+
grpc_closure_sched(exec_ctx, on_done, error);
|
257
293
|
gpr_free(host);
|
258
294
|
gpr_free(port);
|
259
295
|
}
|
260
296
|
|
297
|
+
void grpc_resolve_address_ares_impl(grpc_exec_ctx *exec_ctx, const char *name,
|
298
|
+
const char *default_port,
|
299
|
+
grpc_pollset_set *interested_parties,
|
300
|
+
grpc_closure *on_done,
|
301
|
+
grpc_resolved_addresses **addrs) {
|
302
|
+
grpc_dns_lookup_ares(exec_ctx, NULL /* dns_server */, name, default_port,
|
303
|
+
interested_parties, on_done, addrs);
|
304
|
+
}
|
305
|
+
|
261
306
|
void (*grpc_resolve_address_ares)(
|
262
307
|
grpc_exec_ctx *exec_ctx, const char *name, const char *default_port,
|
263
308
|
grpc_pollset_set *interested_parties, grpc_closure *on_done,
|