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.

Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. 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
- grpc_lb_addresses** lb_addrs_out;
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(grpc_lb_addresses* lb_addrs,
94
+ static void log_address_sorting_list(const ServerAddressList& addresses,
91
95
  const char* input_output_str) {
92
- for (size_t i = 0; i < lb_addrs->num_addresses; i++) {
96
+ for (size_t i = 0; i < addresses.size(); i++) {
93
97
  char* addr_str;
94
- if (grpc_sockaddr_to_string(&addr_str, &lb_addrs->addresses[i].address,
95
- true)) {
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(GPR_DEBUG,
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(grpc_lb_addresses* lb_addrs) {
110
+ void grpc_cares_wrapper_address_sorting_sort(ServerAddressList* addresses) {
108
111
  if (grpc_trace_cares_address_sorting.enabled()) {
109
- log_address_sorting_list(lb_addrs, "input");
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) * lb_addrs->num_addresses);
113
- for (size_t i = 0; i < lb_addrs->num_addresses; i++) {
114
- sortables[i].user_data = &lb_addrs->addresses[i];
115
- memcpy(&sortables[i].dest_addr.addr, &lb_addrs->addresses[i].address.addr,
116
- lb_addrs->addresses[i].address.len);
117
- sortables[i].dest_addr.len = lb_addrs->addresses[i].address.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, lb_addrs->num_addresses);
120
- grpc_lb_address* sorted_lb_addrs = (grpc_lb_address*)gpr_zalloc(
121
- sizeof(grpc_lb_address) * lb_addrs->num_addresses);
122
- for (size_t i = 0; i < lb_addrs->num_addresses; i++) {
123
- sorted_lb_addrs[i] = *(grpc_lb_address*)sortables[i].user_data;
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
- gpr_free(lb_addrs->addresses);
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(lb_addrs, "output");
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
- grpc_lb_addresses* lb_addrs = *(r->lb_addrs_out);
149
- if (lb_addrs != nullptr) {
150
- grpc_cares_wrapper_address_sorting_sort(lb_addrs);
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
- grpc_lb_addresses** lb_addresses = r->lb_addrs_out;
185
- if (*lb_addresses == nullptr) {
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
- (*lb_addresses)->num_addresses += i;
193
- (*lb_addresses)->addresses = static_cast<grpc_lb_address*>(
194
- gpr_realloc((*lb_addresses)->addresses,
195
- sizeof(grpc_lb_address) * (*lb_addresses)->num_addresses));
196
- for (i = prev_naddr; i < (*lb_addresses)->num_addresses; i++) {
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 - prev_naddr],
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
- grpc_lb_addresses_set_address(
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
- gpr_log(GPR_DEBUG,
214
- "c-ares resolver gets a AF_INET6 result: \n"
215
- " addr: %s\n port: %d\n sin6_scope_id: %d\n",
216
- output, ntohs(hr->port), addr.sin6_scope_id);
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 - prev_naddr],
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
- grpc_lb_addresses_set_address(
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
- gpr_log(GPR_DEBUG,
235
- "c-ares resolver gets a AF_INET result: \n"
236
- " addr: %s\n port: %d\n",
237
- output, ntohs(hr->port));
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
- gpr_log(GPR_DEBUG, "on_query_srv_done_locked");
255
+ GRPC_CARES_TRACE_LOG("request:%p on_query_srv_done_locked", r);
261
256
  if (status == ARES_SUCCESS) {
262
- gpr_log(GPR_DEBUG, "on_query_srv_done_locked ARES_SUCCESS");
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
- gpr_log(GPR_INFO, "found service config: %s", *r->service_config_json_out);
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
- gpr_log(GPR_INFO, "Using DNS server %s", dns_server);
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(const char* name,
471
- const char* default_port,
472
- grpc_lb_addresses** addrs,
473
- char** host, char** port,
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 = grpc_lb_addresses_create(1, nullptr);
499
- grpc_lb_addresses_set_address(
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(const char* name,
508
- const char* default_port,
509
- grpc_lb_addresses** addrs) {
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
- grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json,
525
- int query_timeout_ms, grpc_combiner* combiner) {
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->lb_addrs_out = addrs;
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
- grpc_lb_addresses** addrs, bool check_grpclb, char** service_config_json,
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 lb addresses */
603
- grpc_lb_addresses* lb_addrs;
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->lb_addrs == nullptr || r->lb_addrs->num_addresses == 0) {
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->lb_addrs->num_addresses;
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->lb_addrs->addresses[i].is_balancer);
635
- memcpy(&(*resolved_addresses)->addrs[i],
636
- &r->lb_addrs->addresses[i].address, sizeof(grpc_resolved_address));
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
- gpr_free(r);
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->lb_addrs, false /* check_grpclb */,
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
- static_cast<grpc_resolve_address_ares_request*>(
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/lb_policy_factory.h"
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
- grpc_lb_addresses** addresses, bool check_grpclb,
65
- char** service_config_json, int query_timeout_ms, grpc_combiner* combiner);
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, grpc_lb_addresses** addrs);
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(grpc_lb_addresses* lb_addrs);
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
  */