grpc 1.17.1 → 1.18.0.pre1
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 +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -37,12 +37,16 @@
|
|
37
37
|
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
38
38
|
#include "src/core/lib/gpr/host_port.h"
|
39
39
|
#include "src/core/lib/gpr/string.h"
|
40
|
+
#include "src/core/lib/iomgr/combiner.h"
|
40
41
|
#include "src/core/lib/iomgr/error.h"
|
41
42
|
#include "src/core/lib/iomgr/executor.h"
|
42
43
|
#include "src/core/lib/iomgr/iomgr_internal.h"
|
43
44
|
#include "src/core/lib/iomgr/nameser.h"
|
44
45
|
#include "src/core/lib/iomgr/sockaddr_utils.h"
|
45
46
|
|
47
|
+
using grpc_core::ServerAddress;
|
48
|
+
using grpc_core::ServerAddressList;
|
49
|
+
|
46
50
|
static gpr_once g_basic_init = GPR_ONCE_INIT;
|
47
51
|
static gpr_mu g_init_mu;
|
48
52
|
|
@@ -58,7 +62,7 @@ struct grpc_ares_request {
|
|
58
62
|
/** closure to call when the request completes */
|
59
63
|
grpc_closure* on_done;
|
60
64
|
/** the pointer to receive the resolved addresses */
|
61
|
-
|
65
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses_out;
|
62
66
|
/** the pointer to receive the service config in JSON */
|
63
67
|
char** service_config_json_out;
|
64
68
|
/** the evernt driver used by this request */
|
@@ -87,46 +91,44 @@ typedef struct grpc_ares_hostbyname_request {
|
|
87
91
|
|
88
92
|
static void do_basic_init(void) { gpr_mu_init(&g_init_mu); }
|
89
93
|
|
90
|
-
static void log_address_sorting_list(
|
94
|
+
static void log_address_sorting_list(const ServerAddressList& addresses,
|
91
95
|
const char* input_output_str) {
|
92
|
-
for (size_t i = 0; i <
|
96
|
+
for (size_t i = 0; i < addresses.size(); i++) {
|
93
97
|
char* addr_str;
|
94
|
-
if (grpc_sockaddr_to_string(&addr_str, &
|
95
|
-
|
96
|
-
gpr_log(GPR_DEBUG, "c-ares address sorting: %s[%" PRIuPTR "]=%s",
|
98
|
+
if (grpc_sockaddr_to_string(&addr_str, &addresses[i].address(), true)) {
|
99
|
+
gpr_log(GPR_INFO, "c-ares address sorting: %s[%" PRIuPTR "]=%s",
|
97
100
|
input_output_str, i, addr_str);
|
98
101
|
gpr_free(addr_str);
|
99
102
|
} else {
|
100
|
-
gpr_log(
|
103
|
+
gpr_log(GPR_INFO,
|
101
104
|
"c-ares address sorting: %s[%" PRIuPTR "]=<unprintable>",
|
102
105
|
input_output_str, i);
|
103
106
|
}
|
104
107
|
}
|
105
108
|
}
|
106
109
|
|
107
|
-
void grpc_cares_wrapper_address_sorting_sort(
|
110
|
+
void grpc_cares_wrapper_address_sorting_sort(ServerAddressList* addresses) {
|
108
111
|
if (grpc_trace_cares_address_sorting.enabled()) {
|
109
|
-
log_address_sorting_list(
|
112
|
+
log_address_sorting_list(*addresses, "input");
|
110
113
|
}
|
111
114
|
address_sorting_sortable* sortables = (address_sorting_sortable*)gpr_zalloc(
|
112
|
-
sizeof(address_sorting_sortable) *
|
113
|
-
for (size_t i = 0; i <
|
114
|
-
sortables[i].user_data = &
|
115
|
-
memcpy(&sortables[i].dest_addr.addr, &
|
116
|
-
|
117
|
-
sortables[i].dest_addr.len =
|
115
|
+
sizeof(address_sorting_sortable) * addresses->size());
|
116
|
+
for (size_t i = 0; i < addresses->size(); ++i) {
|
117
|
+
sortables[i].user_data = &(*addresses)[i];
|
118
|
+
memcpy(&sortables[i].dest_addr.addr, &(*addresses)[i].address().addr,
|
119
|
+
(*addresses)[i].address().len);
|
120
|
+
sortables[i].dest_addr.len = (*addresses)[i].address().len;
|
118
121
|
}
|
119
|
-
address_sorting_rfc_6724_sort(sortables,
|
120
|
-
|
121
|
-
|
122
|
-
for (size_t i = 0; i <
|
123
|
-
|
122
|
+
address_sorting_rfc_6724_sort(sortables, addresses->size());
|
123
|
+
ServerAddressList sorted;
|
124
|
+
sorted.reserve(addresses->size());
|
125
|
+
for (size_t i = 0; i < addresses->size(); ++i) {
|
126
|
+
sorted.emplace_back(*static_cast<ServerAddress*>(sortables[i].user_data));
|
124
127
|
}
|
125
128
|
gpr_free(sortables);
|
126
|
-
|
127
|
-
lb_addrs->addresses = sorted_lb_addrs;
|
129
|
+
*addresses = std::move(sorted);
|
128
130
|
if (grpc_trace_cares_address_sorting.enabled()) {
|
129
|
-
log_address_sorting_list(
|
131
|
+
log_address_sorting_list(*addresses, "output");
|
130
132
|
}
|
131
133
|
}
|
132
134
|
|
@@ -145,9 +147,9 @@ void grpc_ares_complete_request_locked(grpc_ares_request* r) {
|
|
145
147
|
/* Invoke on_done callback and destroy the
|
146
148
|
request */
|
147
149
|
r->ev_driver = nullptr;
|
148
|
-
|
149
|
-
if (
|
150
|
-
grpc_cares_wrapper_address_sorting_sort(
|
150
|
+
ServerAddressList* addresses = r->addresses_out->get();
|
151
|
+
if (addresses != nullptr) {
|
152
|
+
grpc_cares_wrapper_address_sorting_sort(addresses);
|
151
153
|
}
|
152
154
|
GRPC_CLOSURE_SCHED(r->on_done, r->error);
|
153
155
|
}
|
@@ -181,60 +183,53 @@ static void on_hostbyname_done_locked(void* arg, int status, int timeouts,
|
|
181
183
|
GRPC_ERROR_UNREF(r->error);
|
182
184
|
r->error = GRPC_ERROR_NONE;
|
183
185
|
r->success = true;
|
184
|
-
|
185
|
-
|
186
|
-
*lb_addresses = grpc_lb_addresses_create(0, nullptr);
|
187
|
-
}
|
188
|
-
size_t prev_naddr = (*lb_addresses)->num_addresses;
|
189
|
-
size_t i;
|
190
|
-
for (i = 0; hostent->h_addr_list[i] != nullptr; i++) {
|
186
|
+
if (*r->addresses_out == nullptr) {
|
187
|
+
*r->addresses_out = grpc_core::MakeUnique<ServerAddressList>();
|
191
188
|
}
|
192
|
-
|
193
|
-
(
|
194
|
-
|
195
|
-
|
196
|
-
|
189
|
+
ServerAddressList& addresses = **r->addresses_out;
|
190
|
+
for (size_t i = 0; hostent->h_addr_list[i] != nullptr; ++i) {
|
191
|
+
grpc_core::InlinedVector<grpc_arg, 2> args_to_add;
|
192
|
+
if (hr->is_balancer) {
|
193
|
+
args_to_add.emplace_back(grpc_channel_arg_integer_create(
|
194
|
+
const_cast<char*>(GRPC_ARG_ADDRESS_IS_BALANCER), 1));
|
195
|
+
args_to_add.emplace_back(grpc_channel_arg_string_create(
|
196
|
+
const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME), hr->host));
|
197
|
+
}
|
198
|
+
grpc_channel_args* args = grpc_channel_args_copy_and_add(
|
199
|
+
nullptr, args_to_add.data(), args_to_add.size());
|
197
200
|
switch (hostent->h_addrtype) {
|
198
201
|
case AF_INET6: {
|
199
202
|
size_t addr_len = sizeof(struct sockaddr_in6);
|
200
203
|
struct sockaddr_in6 addr;
|
201
204
|
memset(&addr, 0, addr_len);
|
202
|
-
memcpy(&addr.sin6_addr, hostent->h_addr_list[i
|
205
|
+
memcpy(&addr.sin6_addr, hostent->h_addr_list[i],
|
203
206
|
sizeof(struct in6_addr));
|
204
207
|
addr.sin6_family = static_cast<unsigned char>(hostent->h_addrtype);
|
205
208
|
addr.sin6_port = hr->port;
|
206
|
-
|
207
|
-
*lb_addresses, i, &addr, addr_len,
|
208
|
-
hr->is_balancer /* is_balancer */,
|
209
|
-
hr->is_balancer ? hr->host : nullptr /* balancer_name */,
|
210
|
-
nullptr /* user_data */);
|
209
|
+
addresses.emplace_back(&addr, addr_len, args);
|
211
210
|
char output[INET6_ADDRSTRLEN];
|
212
211
|
ares_inet_ntop(AF_INET6, &addr.sin6_addr, output, INET6_ADDRSTRLEN);
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
212
|
+
GRPC_CARES_TRACE_LOG(
|
213
|
+
"request:%p c-ares resolver gets a AF_INET6 result: \n"
|
214
|
+
" addr: %s\n port: %d\n sin6_scope_id: %d\n",
|
215
|
+
r, output, ntohs(hr->port), addr.sin6_scope_id);
|
217
216
|
break;
|
218
217
|
}
|
219
218
|
case AF_INET: {
|
220
219
|
size_t addr_len = sizeof(struct sockaddr_in);
|
221
220
|
struct sockaddr_in addr;
|
222
221
|
memset(&addr, 0, addr_len);
|
223
|
-
memcpy(&addr.sin_addr, hostent->h_addr_list[i
|
222
|
+
memcpy(&addr.sin_addr, hostent->h_addr_list[i],
|
224
223
|
sizeof(struct in_addr));
|
225
224
|
addr.sin_family = static_cast<unsigned char>(hostent->h_addrtype);
|
226
225
|
addr.sin_port = hr->port;
|
227
|
-
|
228
|
-
*lb_addresses, i, &addr, addr_len,
|
229
|
-
hr->is_balancer /* is_balancer */,
|
230
|
-
hr->is_balancer ? hr->host : nullptr /* balancer_name */,
|
231
|
-
nullptr /* user_data */);
|
226
|
+
addresses.emplace_back(&addr, addr_len, args);
|
232
227
|
char output[INET_ADDRSTRLEN];
|
233
228
|
ares_inet_ntop(AF_INET, &addr.sin_addr, output, INET_ADDRSTRLEN);
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
229
|
+
GRPC_CARES_TRACE_LOG(
|
230
|
+
"request:%p c-ares resolver gets a AF_INET result: \n"
|
231
|
+
" addr: %s\n port: %d\n",
|
232
|
+
r, output, ntohs(hr->port));
|
238
233
|
break;
|
239
234
|
}
|
240
235
|
}
|
@@ -257,9 +252,9 @@ static void on_hostbyname_done_locked(void* arg, int status, int timeouts,
|
|
257
252
|
static void on_srv_query_done_locked(void* arg, int status, int timeouts,
|
258
253
|
unsigned char* abuf, int alen) {
|
259
254
|
grpc_ares_request* r = static_cast<grpc_ares_request*>(arg);
|
260
|
-
|
255
|
+
GRPC_CARES_TRACE_LOG("request:%p on_query_srv_done_locked", r);
|
261
256
|
if (status == ARES_SUCCESS) {
|
262
|
-
|
257
|
+
GRPC_CARES_TRACE_LOG("request:%p on_query_srv_done_locked ARES_SUCCESS", r);
|
263
258
|
struct ares_srv_reply* reply;
|
264
259
|
const int parse_status = ares_parse_srv_reply(abuf, alen, &reply);
|
265
260
|
if (parse_status == ARES_SUCCESS) {
|
@@ -302,9 +297,9 @@ static const char g_service_config_attribute_prefix[] = "grpc_config=";
|
|
302
297
|
|
303
298
|
static void on_txt_done_locked(void* arg, int status, int timeouts,
|
304
299
|
unsigned char* buf, int len) {
|
305
|
-
gpr_log(GPR_DEBUG, "on_txt_done_locked");
|
306
300
|
char* error_msg;
|
307
301
|
grpc_ares_request* r = static_cast<grpc_ares_request*>(arg);
|
302
|
+
GRPC_CARES_TRACE_LOG("request:%p on_txt_done_locked", r);
|
308
303
|
const size_t prefix_len = sizeof(g_service_config_attribute_prefix) - 1;
|
309
304
|
struct ares_txt_ext* result = nullptr;
|
310
305
|
struct ares_txt_ext* reply = nullptr;
|
@@ -337,7 +332,8 @@ static void on_txt_done_locked(void* arg, int status, int timeouts,
|
|
337
332
|
service_config_len += result->length;
|
338
333
|
}
|
339
334
|
(*r->service_config_json_out)[service_config_len] = '\0';
|
340
|
-
|
335
|
+
GRPC_CARES_TRACE_LOG("request:%p found service config: %s", r,
|
336
|
+
*r->service_config_json_out);
|
341
337
|
}
|
342
338
|
// Clean up.
|
343
339
|
ares_free_data(reply);
|
@@ -363,12 +359,6 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|
363
359
|
grpc_error* error = GRPC_ERROR_NONE;
|
364
360
|
grpc_ares_hostbyname_request* hr = nullptr;
|
365
361
|
ares_channel* channel = nullptr;
|
366
|
-
/* TODO(zyc): Enable tracing after #9603 is checked in */
|
367
|
-
/* if (grpc_dns_trace) {
|
368
|
-
gpr_log(GPR_DEBUG, "resolve_address (blocking): name=%s, default_port=%s",
|
369
|
-
name, default_port);
|
370
|
-
} */
|
371
|
-
|
372
362
|
/* parse name, splitting it into host and port parts */
|
373
363
|
char* host;
|
374
364
|
char* port;
|
@@ -393,7 +383,7 @@ void grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
|
393
383
|
channel = grpc_ares_ev_driver_get_channel_locked(r->ev_driver);
|
394
384
|
// If dns_server is specified, use it.
|
395
385
|
if (dns_server != nullptr) {
|
396
|
-
|
386
|
+
GRPC_CARES_TRACE_LOG("request:%p Using DNS server %s", r, dns_server);
|
397
387
|
grpc_resolved_address addr;
|
398
388
|
if (grpc_parse_ipv4_hostport(dns_server, &addr, false /* log_errors */)) {
|
399
389
|
r->dns_server_addr.family = AF_INET;
|
@@ -467,11 +457,10 @@ error_cleanup:
|
|
467
457
|
gpr_free(port);
|
468
458
|
}
|
469
459
|
|
470
|
-
static bool inner_resolve_as_ip_literal_locked(
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
char** hostport) {
|
460
|
+
static bool inner_resolve_as_ip_literal_locked(
|
461
|
+
const char* name, const char* default_port,
|
462
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
|
463
|
+
char** port, char** hostport) {
|
475
464
|
gpr_split_host_port(name, host, port);
|
476
465
|
if (*host == nullptr) {
|
477
466
|
gpr_log(GPR_ERROR,
|
@@ -495,18 +484,16 @@ static bool inner_resolve_as_ip_literal_locked(const char* name,
|
|
495
484
|
if (grpc_parse_ipv4_hostport(*hostport, &addr, false /* log errors */) ||
|
496
485
|
grpc_parse_ipv6_hostport(*hostport, &addr, false /* log errors */)) {
|
497
486
|
GPR_ASSERT(*addrs == nullptr);
|
498
|
-
*addrs =
|
499
|
-
|
500
|
-
*addrs, 0, addr.addr, addr.len, false /* is_balancer */,
|
501
|
-
nullptr /* balancer_name */, nullptr /* user_data */);
|
487
|
+
*addrs = grpc_core::MakeUnique<ServerAddressList>();
|
488
|
+
(*addrs)->emplace_back(addr.addr, addr.len, nullptr /* args */);
|
502
489
|
return true;
|
503
490
|
}
|
504
491
|
return false;
|
505
492
|
}
|
506
493
|
|
507
|
-
static bool resolve_as_ip_literal_locked(
|
508
|
-
|
509
|
-
|
494
|
+
static bool resolve_as_ip_literal_locked(
|
495
|
+
const char* name, const char* default_port,
|
496
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
|
510
497
|
char* host = nullptr;
|
511
498
|
char* port = nullptr;
|
512
499
|
char* hostport = nullptr;
|
@@ -518,20 +505,47 @@ static bool resolve_as_ip_literal_locked(const char* name,
|
|
518
505
|
return out;
|
519
506
|
}
|
520
507
|
|
508
|
+
static bool target_matches_localhost_inner(const char* name, char** host,
|
509
|
+
char** port) {
|
510
|
+
if (!gpr_split_host_port(name, host, port)) {
|
511
|
+
gpr_log(GPR_ERROR, "Unable to split host and port for name: %s", name);
|
512
|
+
return false;
|
513
|
+
}
|
514
|
+
if (gpr_stricmp(*host, "localhost") == 0) {
|
515
|
+
return true;
|
516
|
+
} else {
|
517
|
+
return false;
|
518
|
+
}
|
519
|
+
}
|
520
|
+
|
521
|
+
static bool target_matches_localhost(const char* name) {
|
522
|
+
char* host = nullptr;
|
523
|
+
char* port = nullptr;
|
524
|
+
bool out = target_matches_localhost_inner(name, &host, &port);
|
525
|
+
gpr_free(host);
|
526
|
+
gpr_free(port);
|
527
|
+
return out;
|
528
|
+
}
|
529
|
+
|
521
530
|
static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
|
522
531
|
const char* dns_server, const char* name, const char* default_port,
|
523
532
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
524
|
-
|
525
|
-
|
533
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
|
534
|
+
bool check_grpclb, char** service_config_json, int query_timeout_ms,
|
535
|
+
grpc_combiner* combiner) {
|
526
536
|
grpc_ares_request* r =
|
527
537
|
static_cast<grpc_ares_request*>(gpr_zalloc(sizeof(grpc_ares_request)));
|
528
538
|
r->ev_driver = nullptr;
|
529
539
|
r->on_done = on_done;
|
530
|
-
r->
|
540
|
+
r->addresses_out = addrs;
|
531
541
|
r->service_config_json_out = service_config_json;
|
532
542
|
r->success = false;
|
533
543
|
r->error = GRPC_ERROR_NONE;
|
534
544
|
r->pending_queries = 0;
|
545
|
+
GRPC_CARES_TRACE_LOG(
|
546
|
+
"request:%p c-ares grpc_dns_lookup_ares_locked_impl name=%s, "
|
547
|
+
"default_port=%s",
|
548
|
+
r, name, default_port);
|
535
549
|
// Early out if the target is an ipv4 or ipv6 literal.
|
536
550
|
if (resolve_as_ip_literal_locked(name, default_port, addrs)) {
|
537
551
|
GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
|
@@ -543,6 +557,13 @@ static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
|
|
543
557
|
GRPC_CLOSURE_SCHED(on_done, GRPC_ERROR_NONE);
|
544
558
|
return r;
|
545
559
|
}
|
560
|
+
// Don't query for SRV and TXT records if the target is "localhost", so
|
561
|
+
// as to cut down on lookups over the network, especially in tests:
|
562
|
+
// https://github.com/grpc/proposal/pull/79
|
563
|
+
if (target_matches_localhost(name)) {
|
564
|
+
check_grpclb = false;
|
565
|
+
r->service_config_json_out = nullptr;
|
566
|
+
}
|
546
567
|
// Look up name using c-ares lib.
|
547
568
|
grpc_dns_lookup_ares_continue_after_check_localhost_and_ip_literals_locked(
|
548
569
|
r, dns_server, name, default_port, interested_parties, check_grpclb,
|
@@ -553,8 +574,8 @@ static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
|
|
553
574
|
grpc_ares_request* (*grpc_dns_lookup_ares_locked)(
|
554
575
|
const char* dns_server, const char* name, const char* default_port,
|
555
576
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
556
|
-
|
557
|
-
int query_timeout_ms,
|
577
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs,
|
578
|
+
bool check_grpclb, char** service_config_json, int query_timeout_ms,
|
558
579
|
grpc_combiner* combiner) = grpc_dns_lookup_ares_locked_impl;
|
559
580
|
|
560
581
|
static void grpc_cancel_ares_request_locked_impl(grpc_ares_request* r) {
|
@@ -599,8 +620,8 @@ typedef struct grpc_resolve_address_ares_request {
|
|
599
620
|
grpc_combiner* combiner;
|
600
621
|
/** the pointer to receive the resolved addresses */
|
601
622
|
grpc_resolved_addresses** addrs_out;
|
602
|
-
/** currently resolving
|
603
|
-
|
623
|
+
/** currently resolving addresses */
|
624
|
+
grpc_core::UniquePtr<ServerAddressList> addresses;
|
604
625
|
/** closure to call when the resolve_address_ares request completes */
|
605
626
|
grpc_closure* on_resolve_address_done;
|
606
627
|
/** a closure wrapping on_resolve_address_done, which should be invoked when
|
@@ -613,7 +634,7 @@ typedef struct grpc_resolve_address_ares_request {
|
|
613
634
|
/* pollset_set to be driven by */
|
614
635
|
grpc_pollset_set* interested_parties;
|
615
636
|
/* underlying ares_request that the query is performed on */
|
616
|
-
grpc_ares_request* ares_request;
|
637
|
+
grpc_ares_request* ares_request = nullptr;
|
617
638
|
} grpc_resolve_address_ares_request;
|
618
639
|
|
619
640
|
static void on_dns_lookup_done_locked(void* arg, grpc_error* error) {
|
@@ -621,25 +642,24 @@ static void on_dns_lookup_done_locked(void* arg, grpc_error* error) {
|
|
621
642
|
static_cast<grpc_resolve_address_ares_request*>(arg);
|
622
643
|
gpr_free(r->ares_request);
|
623
644
|
grpc_resolved_addresses** resolved_addresses = r->addrs_out;
|
624
|
-
if (r->
|
645
|
+
if (r->addresses == nullptr || r->addresses->empty()) {
|
625
646
|
*resolved_addresses = nullptr;
|
626
647
|
} else {
|
627
648
|
*resolved_addresses = static_cast<grpc_resolved_addresses*>(
|
628
649
|
gpr_zalloc(sizeof(grpc_resolved_addresses)));
|
629
|
-
(*resolved_addresses)->naddrs = r->
|
650
|
+
(*resolved_addresses)->naddrs = r->addresses->size();
|
630
651
|
(*resolved_addresses)->addrs =
|
631
652
|
static_cast<grpc_resolved_address*>(gpr_zalloc(
|
632
653
|
sizeof(grpc_resolved_address) * (*resolved_addresses)->naddrs));
|
633
|
-
for (size_t i = 0; i < (*resolved_addresses)->naddrs; i
|
634
|
-
GPR_ASSERT(!r->
|
635
|
-
memcpy(&(*resolved_addresses)->addrs[i],
|
636
|
-
|
654
|
+
for (size_t i = 0; i < (*resolved_addresses)->naddrs; ++i) {
|
655
|
+
GPR_ASSERT(!(*r->addresses)[i].IsBalancer());
|
656
|
+
memcpy(&(*resolved_addresses)->addrs[i], &(*r->addresses)[i].address(),
|
657
|
+
sizeof(grpc_resolved_address));
|
637
658
|
}
|
638
659
|
}
|
639
660
|
GRPC_CLOSURE_SCHED(r->on_resolve_address_done, GRPC_ERROR_REF(error));
|
640
|
-
if (r->lb_addrs != nullptr) grpc_lb_addresses_destroy(r->lb_addrs);
|
641
661
|
GRPC_COMBINER_UNREF(r->combiner, "on_dns_lookup_done_cb");
|
642
|
-
|
662
|
+
grpc_core::Delete(r);
|
643
663
|
}
|
644
664
|
|
645
665
|
static void grpc_resolve_address_invoke_dns_lookup_ares_locked(
|
@@ -648,7 +668,7 @@ static void grpc_resolve_address_invoke_dns_lookup_ares_locked(
|
|
648
668
|
static_cast<grpc_resolve_address_ares_request*>(arg);
|
649
669
|
r->ares_request = grpc_dns_lookup_ares_locked(
|
650
670
|
nullptr /* dns_server */, r->name, r->default_port, r->interested_parties,
|
651
|
-
&r->on_dns_lookup_done_locked, &r->
|
671
|
+
&r->on_dns_lookup_done_locked, &r->addresses, false /* check_grpclb */,
|
652
672
|
nullptr /* service_config_json */, GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS,
|
653
673
|
r->combiner);
|
654
674
|
}
|
@@ -659,8 +679,7 @@ static void grpc_resolve_address_ares_impl(const char* name,
|
|
659
679
|
grpc_closure* on_done,
|
660
680
|
grpc_resolved_addresses** addrs) {
|
661
681
|
grpc_resolve_address_ares_request* r =
|
662
|
-
|
663
|
-
gpr_zalloc(sizeof(grpc_resolve_address_ares_request)));
|
682
|
+
grpc_core::New<grpc_resolve_address_ares_request>();
|
664
683
|
r->combiner = grpc_combiner_create();
|
665
684
|
r->addrs_out = addrs;
|
666
685
|
r->on_resolve_address_done = on_done;
|
@@ -21,7 +21,7 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
-
#include "src/core/ext/filters/client_channel/
|
24
|
+
#include "src/core/ext/filters/client_channel/server_address.h"
|
25
25
|
#include "src/core/lib/iomgr/iomgr.h"
|
26
26
|
#include "src/core/lib/iomgr/polling_entity.h"
|
27
27
|
#include "src/core/lib/iomgr/resolve_address.h"
|
@@ -61,8 +61,9 @@ extern void (*grpc_resolve_address_ares)(const char* name,
|
|
61
61
|
extern grpc_ares_request* (*grpc_dns_lookup_ares_locked)(
|
62
62
|
const char* dns_server, const char* name, const char* default_port,
|
63
63
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
64
|
-
|
65
|
-
char** service_config_json, int query_timeout_ms,
|
64
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addresses,
|
65
|
+
bool check_grpclb, char** service_config_json, int query_timeout_ms,
|
66
|
+
grpc_combiner* combiner);
|
66
67
|
|
67
68
|
/* Cancel the pending grpc_ares_request \a request */
|
68
69
|
extern void (*grpc_cancel_ares_request_locked)(grpc_ares_request* request);
|
@@ -89,10 +90,12 @@ bool grpc_ares_query_ipv6();
|
|
89
90
|
* Returns a bool indicating whether or not such an action was performed.
|
90
91
|
* See https://github.com/grpc/grpc/issues/15158. */
|
91
92
|
bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
92
|
-
const char* name, const char* default_port,
|
93
|
+
const char* name, const char* default_port,
|
94
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs);
|
93
95
|
|
94
96
|
/* Sorts destinations in lb_addrs according to RFC 6724. */
|
95
|
-
void grpc_cares_wrapper_address_sorting_sort(
|
97
|
+
void grpc_cares_wrapper_address_sorting_sort(
|
98
|
+
grpc_core::ServerAddressList* addresses);
|
96
99
|
|
97
100
|
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_RESOLVER_DNS_C_ARES_GRPC_ARES_WRAPPER_H \
|
98
101
|
*/
|