grpc 1.18.0 → 1.19.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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +301 -33
  3. data/include/grpc/grpc_security.h +195 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +17 -1
  5. data/include/grpc/impl/codegen/port_platform.h +36 -0
  6. data/include/grpc/impl/codegen/slice.h +1 -1
  7. data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
  8. data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
  9. data/src/core/ext/filters/client_channel/client_channel.h +2 -2
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
  12. data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
  13. data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
  14. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
  15. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
  16. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  17. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
  18. data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
  21. data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
  25. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  30. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  31. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  32. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  33. data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
  34. data/src/core/ext/filters/client_channel/request_routing.h +5 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
  38. data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
  39. data/src/core/ext/filters/client_channel/subchannel.h +213 -123
  40. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  41. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
  43. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  44. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  45. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
  46. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
  47. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
  48. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
  49. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  50. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
  51. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
  53. data/src/core/lib/channel/handshaker.cc +141 -214
  54. data/src/core/lib/channel/handshaker.h +110 -101
  55. data/src/core/lib/channel/handshaker_factory.h +11 -19
  56. data/src/core/lib/channel/handshaker_registry.cc +64 -52
  57. data/src/core/lib/channel/handshaker_registry.h +21 -16
  58. data/src/core/lib/gpr/log_posix.cc +2 -1
  59. data/src/core/lib/gpr/time.cc +8 -0
  60. data/src/core/lib/gpr/time_posix.cc +8 -2
  61. data/src/core/lib/gprpp/optional.h +47 -0
  62. data/src/core/lib/http/httpcli_security_connector.cc +13 -14
  63. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  64. data/src/core/lib/iomgr/buffer_list.h +70 -8
  65. data/src/core/lib/iomgr/combiner.cc +11 -3
  66. data/src/core/lib/iomgr/error.cc +9 -5
  67. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
  68. data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
  69. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
  70. data/src/core/lib/iomgr/ev_posix.cc +4 -0
  71. data/src/core/lib/iomgr/ev_posix.h +4 -0
  72. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  73. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  74. data/src/core/lib/iomgr/executor.cc +122 -87
  75. data/src/core/lib/iomgr/executor.h +53 -48
  76. data/src/core/lib/iomgr/fork_posix.cc +6 -4
  77. data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
  78. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  79. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  80. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  81. data/src/core/lib/iomgr/iomgr.cc +6 -5
  82. data/src/core/lib/iomgr/iomgr.h +8 -0
  83. data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
  84. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  85. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  86. data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
  87. data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
  88. data/src/core/lib/iomgr/port.h +1 -0
  89. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  90. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  91. data/src/core/lib/iomgr/tcp_custom.cc +0 -4
  92. data/src/core/lib/iomgr/tcp_posix.cc +58 -44
  93. data/src/core/lib/iomgr/tcp_uv.cc +0 -1
  94. data/src/core/lib/iomgr/tcp_windows.cc +0 -4
  95. data/src/core/lib/iomgr/timer_manager.cc +8 -0
  96. data/src/core/lib/iomgr/udp_server.cc +6 -4
  97. data/src/core/lib/json/json.cc +1 -4
  98. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  99. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  100. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  101. data/src/core/lib/security/credentials/credentials.h +9 -1
  102. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
  103. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  104. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  105. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
  106. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  107. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  108. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
  109. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  110. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
  111. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  112. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  113. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  114. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  115. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
  116. data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
  117. data/src/core/lib/security/transport/security_handshaker.cc +267 -300
  118. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  119. data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
  120. data/src/core/lib/surface/call.cc +5 -1
  121. data/src/core/lib/surface/channel_init.h +5 -0
  122. data/src/core/lib/surface/completion_queue.cc +4 -7
  123. data/src/core/lib/surface/init.cc +5 -3
  124. data/src/core/lib/surface/init_secure.cc +1 -1
  125. data/src/core/lib/surface/server.cc +19 -17
  126. data/src/core/lib/surface/version.cc +1 -1
  127. data/src/core/lib/transport/service_config.h +1 -0
  128. data/src/core/lib/transport/static_metadata.cc +279 -279
  129. data/src/core/lib/transport/transport.cc +5 -3
  130. data/src/core/tsi/ssl_transport_security.cc +10 -4
  131. data/src/ruby/ext/grpc/extconf.rb +12 -4
  132. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  133. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  134. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  135. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  136. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  137. data/src/ruby/ext/grpc/rb_grpc.c +22 -23
  138. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
  140. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
  141. data/src/ruby/ext/grpc/rb_server.c +8 -4
  142. data/src/ruby/lib/grpc/version.rb +1 -1
  143. metadata +46 -39
  144. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  145. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  146. data/src/core/lib/channel/handshaker_factory.cc +0 -42
@@ -80,7 +80,6 @@
80
80
  #include "src/core/ext/filters/client_channel/parse_address.h"
81
81
  #include "src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h"
82
82
  #include "src/core/ext/filters/client_channel/server_address.h"
83
- #include "src/core/ext/filters/client_channel/subchannel_index.h"
84
83
  #include "src/core/lib/backoff/backoff.h"
85
84
  #include "src/core/lib/channel/channel_args.h"
86
85
  #include "src/core/lib/channel/channel_stack.h"
@@ -101,6 +100,7 @@
101
100
  #include "src/core/lib/surface/call.h"
102
101
  #include "src/core/lib/surface/channel.h"
103
102
  #include "src/core/lib/surface/channel_init.h"
103
+ #include "src/core/lib/transport/service_config.h"
104
104
  #include "src/core/lib/transport/static_metadata.h"
105
105
 
106
106
  #define GRPC_XDS_INITIAL_CONNECT_BACKOFF_SECONDS 1
@@ -119,7 +119,7 @@ constexpr char kXds[] = "xds_experimental";
119
119
 
120
120
  class XdsLb : public LoadBalancingPolicy {
121
121
  public:
122
- explicit XdsLb(const Args& args);
122
+ explicit XdsLb(Args args);
123
123
 
124
124
  const char* name() const override { return kXds; }
125
125
 
@@ -248,6 +248,12 @@ class XdsLb : public LoadBalancingPolicy {
248
248
  // Helper function used in ctor and UpdateLocked().
249
249
  void ProcessChannelArgsLocked(const grpc_channel_args& args);
250
250
 
251
+ // Parses the xds config given the JSON node of the first child of XdsConfig.
252
+ // If parsing succeeds, updates \a balancer_name, and updates \a
253
+ // child_policy_json_dump_ and \a fallback_policy_json_dump_ if they are also
254
+ // found. Does nothing upon failure.
255
+ void ParseLbConfig(grpc_json* xds_config_json);
256
+
251
257
  // Methods for dealing with the balancer channel and call.
252
258
  void StartPickingLocked();
253
259
  void StartBalancerCallLocked();
@@ -266,7 +272,7 @@ class XdsLb : public LoadBalancingPolicy {
266
272
  // Methods for dealing with the child policy.
267
273
  void CreateOrUpdateChildPolicyLocked();
268
274
  grpc_channel_args* CreateChildPolicyArgsLocked();
269
- void CreateChildPolicyLocked(const Args& args);
275
+ void CreateChildPolicyLocked(const char* name, Args args);
270
276
  bool PickFromChildPolicyLocked(bool force_async, PendingPick* pp,
271
277
  grpc_error** error);
272
278
  void UpdateConnectivityStateFromChildPolicyLocked(
@@ -279,6 +285,9 @@ class XdsLb : public LoadBalancingPolicy {
279
285
  // Who the client is trying to communicate with.
280
286
  const char* server_name_ = nullptr;
281
287
 
288
+ // Name of the balancer to connect to.
289
+ UniquePtr<char> balancer_name_;
290
+
282
291
  // Current channel args from the resolver.
283
292
  grpc_channel_args* args_ = nullptr;
284
293
 
@@ -319,6 +328,7 @@ class XdsLb : public LoadBalancingPolicy {
319
328
 
320
329
  // Timeout in milliseconds for before using fallback backend addresses.
321
330
  // 0 means not using fallback.
331
+ UniquePtr<char> fallback_policy_json_string_;
322
332
  int lb_fallback_timeout_ms_ = 0;
323
333
  // The backend addresses from the resolver.
324
334
  UniquePtr<ServerAddressList> fallback_backend_addresses_;
@@ -332,6 +342,7 @@ class XdsLb : public LoadBalancingPolicy {
332
342
 
333
343
  // The policy to use for the backends.
334
344
  OrphanablePtr<LoadBalancingPolicy> child_policy_;
345
+ UniquePtr<char> child_policy_json_string_;
335
346
  grpc_connectivity_state child_connectivity_state_;
336
347
  grpc_closure on_child_connectivity_changed_;
337
348
  grpc_closure on_child_request_reresolution_;
@@ -893,8 +904,8 @@ grpc_channel_args* BuildBalancerChannelArgs(
893
904
  //
894
905
 
895
906
  // TODO(vishalpowar): Use lb_config in args to configure LB policy.
896
- XdsLb::XdsLb(const LoadBalancingPolicy::Args& args)
897
- : LoadBalancingPolicy(args),
907
+ XdsLb::XdsLb(LoadBalancingPolicy::Args args)
908
+ : LoadBalancingPolicy(std::move(args)),
898
909
  response_generator_(MakeRefCounted<FakeResolverResponseGenerator>()),
899
910
  lb_call_backoff_(
900
911
  BackOff::Options()
@@ -905,7 +916,6 @@ XdsLb::XdsLb(const LoadBalancingPolicy::Args& args)
905
916
  .set_max_backoff(GRPC_XDS_RECONNECT_MAX_BACKOFF_SECONDS * 1000)) {
906
917
  // Initialization.
907
918
  gpr_mu_init(&lb_channel_mu_);
908
- grpc_subchannel_index_ref();
909
919
  GRPC_CLOSURE_INIT(&lb_channel_on_connectivity_changed_,
910
920
  &XdsLb::OnBalancerChannelConnectivityChangedLocked, this,
911
921
  grpc_combiner_scheduler(args.combiner));
@@ -936,6 +946,8 @@ XdsLb::XdsLb(const LoadBalancingPolicy::Args& args)
936
946
  arg = grpc_channel_args_find(args.args, GRPC_ARG_GRPCLB_FALLBACK_TIMEOUT_MS);
937
947
  lb_fallback_timeout_ms_ = grpc_channel_arg_get_integer(
938
948
  arg, {GRPC_XDS_DEFAULT_FALLBACK_TIMEOUT_MS, 0, INT_MAX});
949
+ // Parse the LB config.
950
+ ParseLbConfig(args.lb_config);
939
951
  // Process channel args.
940
952
  ProcessChannelArgsLocked(*args.args);
941
953
  }
@@ -949,7 +961,6 @@ XdsLb::~XdsLb() {
949
961
  if (serverlist_ != nullptr) {
950
962
  xds_grpclb_destroy_serverlist(serverlist_);
951
963
  }
952
- grpc_subchannel_index_unref();
953
964
  }
954
965
 
955
966
  void XdsLb::ShutdownLocked() {
@@ -1187,8 +1198,44 @@ void XdsLb::ProcessChannelArgsLocked(const grpc_channel_args& args) {
1187
1198
  grpc_channel_args_destroy(lb_channel_args);
1188
1199
  }
1189
1200
 
1190
- // TODO(vishalpowar): Use lb_config to configure LB policy.
1201
+ void XdsLb::ParseLbConfig(grpc_json* xds_config_json) {
1202
+ const char* balancer_name = nullptr;
1203
+ grpc_json* child_policy = nullptr;
1204
+ grpc_json* fallback_policy = nullptr;
1205
+ for (grpc_json* field = xds_config_json; field != nullptr;
1206
+ field = field->next) {
1207
+ if (field->key == nullptr) return;
1208
+ if (strcmp(field->key, "balancerName") == 0) {
1209
+ if (balancer_name != nullptr) return; // Duplicate.
1210
+ if (field->type != GRPC_JSON_STRING) return;
1211
+ balancer_name = field->value;
1212
+ } else if (strcmp(field->key, "childPolicy") == 0) {
1213
+ if (child_policy != nullptr) return; // Duplicate.
1214
+ child_policy = ParseLoadBalancingConfig(field);
1215
+ } else if (strcmp(field->key, "fallbackPolicy") == 0) {
1216
+ if (fallback_policy != nullptr) return; // Duplicate.
1217
+ fallback_policy = ParseLoadBalancingConfig(field);
1218
+ }
1219
+ }
1220
+ if (balancer_name == nullptr) return; // Required field.
1221
+ if (child_policy != nullptr) {
1222
+ child_policy_json_string_ =
1223
+ UniquePtr<char>(grpc_json_dump_to_string(child_policy, 0 /* indent */));
1224
+ }
1225
+ if (fallback_policy != nullptr) {
1226
+ fallback_policy_json_string_ = UniquePtr<char>(
1227
+ grpc_json_dump_to_string(fallback_policy, 0 /* indent */));
1228
+ }
1229
+ balancer_name_ = UniquePtr<char>(gpr_strdup(balancer_name));
1230
+ }
1231
+
1191
1232
  void XdsLb::UpdateLocked(const grpc_channel_args& args, grpc_json* lb_config) {
1233
+ ParseLbConfig(lb_config);
1234
+ // TODO(juanlishen): Pass fallback policy config update after fallback policy
1235
+ // is added.
1236
+ if (balancer_name_ == nullptr) {
1237
+ gpr_log(GPR_ERROR, "[xdslb %p] LB config parsing fails.", this);
1238
+ }
1192
1239
  ProcessChannelArgsLocked(args);
1193
1240
  // Update the existing child policy.
1194
1241
  // Note: We have disabled fallback mode in the code, so this child policy must
@@ -1439,10 +1486,10 @@ bool XdsLb::PickFromChildPolicyLocked(bool force_async, PendingPick* pp,
1439
1486
  return pick_done;
1440
1487
  }
1441
1488
 
1442
- void XdsLb::CreateChildPolicyLocked(const Args& args) {
1489
+ void XdsLb::CreateChildPolicyLocked(const char* name, Args args) {
1443
1490
  GPR_ASSERT(child_policy_ == nullptr);
1444
1491
  child_policy_ = LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
1445
- "round_robin", args);
1492
+ name, std::move(args));
1446
1493
  if (GPR_UNLIKELY(child_policy_ == nullptr)) {
1447
1494
  gpr_log(GPR_ERROR, "[xdslb %p] Failure creating a child policy", this);
1448
1495
  return;
@@ -1515,25 +1562,43 @@ void XdsLb::CreateOrUpdateChildPolicyLocked() {
1515
1562
  if (shutting_down_) return;
1516
1563
  grpc_channel_args* args = CreateChildPolicyArgsLocked();
1517
1564
  GPR_ASSERT(args != nullptr);
1565
+ const char* child_policy_name = nullptr;
1566
+ grpc_json* child_policy_config = nullptr;
1567
+ grpc_json* child_policy_json =
1568
+ grpc_json_parse_string(child_policy_json_string_.get());
1569
+ // TODO(juanlishen): If the child policy is not configured via service config,
1570
+ // use whatever algorithm is specified by the balancer.
1571
+ if (child_policy_json != nullptr) {
1572
+ child_policy_name = child_policy_json->key;
1573
+ child_policy_config = child_policy_json->child;
1574
+ } else {
1575
+ if (grpc_lb_xds_trace.enabled()) {
1576
+ gpr_log(GPR_INFO, "[xdslb %p] No valid child policy LB config", this);
1577
+ }
1578
+ child_policy_name = "round_robin";
1579
+ }
1580
+ // TODO(juanlishen): Switch policy according to child_policy_config->key.
1518
1581
  if (child_policy_ != nullptr) {
1519
1582
  if (grpc_lb_xds_trace.enabled()) {
1520
1583
  gpr_log(GPR_INFO, "[xdslb %p] Updating the child policy %p", this,
1521
1584
  child_policy_.get());
1522
1585
  }
1523
- // TODO(vishalpowar): Pass the correct LB config.
1524
- child_policy_->UpdateLocked(*args, nullptr);
1586
+ child_policy_->UpdateLocked(*args, child_policy_config);
1525
1587
  } else {
1526
1588
  LoadBalancingPolicy::Args lb_policy_args;
1527
1589
  lb_policy_args.combiner = combiner();
1528
1590
  lb_policy_args.client_channel_factory = client_channel_factory();
1591
+ lb_policy_args.subchannel_pool = subchannel_pool()->Ref();
1529
1592
  lb_policy_args.args = args;
1530
- CreateChildPolicyLocked(lb_policy_args);
1593
+ lb_policy_args.lb_config = child_policy_config;
1594
+ CreateChildPolicyLocked(child_policy_name, std::move(lb_policy_args));
1531
1595
  if (grpc_lb_xds_trace.enabled()) {
1532
1596
  gpr_log(GPR_INFO, "[xdslb %p] Created a new child policy %p", this,
1533
1597
  child_policy_.get());
1534
1598
  }
1535
1599
  }
1536
1600
  grpc_channel_args_destroy(args);
1601
+ grpc_json_destroy(child_policy_json);
1537
1602
  }
1538
1603
 
1539
1604
  void XdsLb::OnChildPolicyRequestReresolutionLocked(void* arg,
@@ -1639,7 +1704,7 @@ void XdsLb::OnChildPolicyConnectivityChangedLocked(void* arg,
1639
1704
  class XdsFactory : public LoadBalancingPolicyFactory {
1640
1705
  public:
1641
1706
  OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
1642
- const LoadBalancingPolicy::Args& args) const override {
1707
+ LoadBalancingPolicy::Args args) const override {
1643
1708
  /* Count the number of gRPC-LB addresses. There must be at least one. */
1644
1709
  const ServerAddressList* addresses =
1645
1710
  FindServerAddressListChannelArg(args.args);
@@ -1652,7 +1717,7 @@ class XdsFactory : public LoadBalancingPolicyFactory {
1652
1717
  }
1653
1718
  }
1654
1719
  if (!found_balancer_address) return nullptr;
1655
- return OrphanablePtr<LoadBalancingPolicy>(New<XdsLb>(args));
1720
+ return OrphanablePtr<LoadBalancingPolicy>(New<XdsLb>(std::move(args)));
1656
1721
  }
1657
1722
 
1658
1723
  const char* name() const override { return kXds; }
@@ -31,7 +31,12 @@ class LoadBalancingPolicyFactory {
31
31
  public:
32
32
  /// Returns a new LB policy instance.
33
33
  virtual OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
34
- const LoadBalancingPolicy::Args& args) const GRPC_ABSTRACT;
34
+ LoadBalancingPolicy::Args args) const {
35
+ std::move(args); // Suppress clang-tidy complaint.
36
+ // The rest of this is copied from the GRPC_ABSTRACT macro.
37
+ gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented");
38
+ GPR_ASSERT(false);
39
+ }
35
40
 
36
41
  /// Returns the LB policy name that this factory provides.
37
42
  /// Caller does NOT take ownership of result.
@@ -84,14 +84,14 @@ void LoadBalancingPolicyRegistry::Builder::RegisterLoadBalancingPolicyFactory(
84
84
 
85
85
  OrphanablePtr<LoadBalancingPolicy>
86
86
  LoadBalancingPolicyRegistry::CreateLoadBalancingPolicy(
87
- const char* name, const LoadBalancingPolicy::Args& args) {
87
+ const char* name, LoadBalancingPolicy::Args args) {
88
88
  GPR_ASSERT(g_state != nullptr);
89
89
  // Find factory.
90
90
  LoadBalancingPolicyFactory* factory =
91
91
  g_state->GetLoadBalancingPolicyFactory(name);
92
92
  if (factory == nullptr) return nullptr; // Specified name not found.
93
93
  // Create policy via factory.
94
- return factory->CreateLoadBalancingPolicy(args);
94
+ return factory->CreateLoadBalancingPolicy(std::move(args));
95
95
  }
96
96
 
97
97
  bool LoadBalancingPolicyRegistry::LoadBalancingPolicyExists(const char* name) {
@@ -46,7 +46,7 @@ class LoadBalancingPolicyRegistry {
46
46
 
47
47
  /// Creates an LB policy of the type specified by \a name.
48
48
  static OrphanablePtr<LoadBalancingPolicy> CreateLoadBalancingPolicy(
49
- const char* name, const LoadBalancingPolicy::Args& args);
49
+ const char* name, LoadBalancingPolicy::Args args);
50
50
 
51
51
  /// Returns true if the LB policy factory specified by \a name exists in this
52
52
  /// registry.
@@ -0,0 +1,96 @@
1
+ //
2
+ //
3
+ // Copyright 2018 gRPC authors.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 (the "License");
6
+ // you may not use this file except in compliance with the License.
7
+ // You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing, software
12
+ // distributed under the License is distributed on an "AS IS" BASIS,
13
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ // See the License for the specific language governing permissions and
15
+ // limitations under the License.
16
+ //
17
+ //
18
+
19
+ #include <grpc/support/port_platform.h>
20
+
21
+ #include "src/core/ext/filters/client_channel/local_subchannel_pool.h"
22
+
23
+ #include "src/core/ext/filters/client_channel/subchannel.h"
24
+
25
+ namespace grpc_core {
26
+
27
+ LocalSubchannelPool::LocalSubchannelPool() {
28
+ subchannel_map_ = grpc_avl_create(&subchannel_avl_vtable_);
29
+ }
30
+
31
+ LocalSubchannelPool::~LocalSubchannelPool() {
32
+ grpc_avl_unref(subchannel_map_, nullptr);
33
+ }
34
+
35
+ Subchannel* LocalSubchannelPool::RegisterSubchannel(SubchannelKey* key,
36
+ Subchannel* constructed) {
37
+ // Check to see if a subchannel already exists.
38
+ Subchannel* c =
39
+ static_cast<Subchannel*>(grpc_avl_get(subchannel_map_, key, nullptr));
40
+ if (c != nullptr) {
41
+ // The subchannel already exists. Reuse it.
42
+ c = GRPC_SUBCHANNEL_REF(c, "subchannel_register+reuse");
43
+ GRPC_SUBCHANNEL_UNREF(constructed, "subchannel_register+found_existing");
44
+ } else {
45
+ // There hasn't been such subchannel. Add one.
46
+ subchannel_map_ = grpc_avl_add(subchannel_map_, New<SubchannelKey>(*key),
47
+ constructed, nullptr);
48
+ c = constructed;
49
+ }
50
+ return c;
51
+ }
52
+
53
+ void LocalSubchannelPool::UnregisterSubchannel(SubchannelKey* key) {
54
+ subchannel_map_ = grpc_avl_remove(subchannel_map_, key, nullptr);
55
+ }
56
+
57
+ Subchannel* LocalSubchannelPool::FindSubchannel(SubchannelKey* key) {
58
+ Subchannel* c =
59
+ static_cast<Subchannel*>(grpc_avl_get(subchannel_map_, key, nullptr));
60
+ return c == nullptr ? c : GRPC_SUBCHANNEL_REF(c, "found_from_pool");
61
+ }
62
+
63
+ namespace {
64
+
65
+ void sck_avl_destroy(void* p, void* user_data) {
66
+ SubchannelKey* key = static_cast<SubchannelKey*>(p);
67
+ Delete(key);
68
+ }
69
+
70
+ void* sck_avl_copy(void* p, void* unused) {
71
+ const SubchannelKey* key = static_cast<const SubchannelKey*>(p);
72
+ auto new_key = New<SubchannelKey>(*key);
73
+ return static_cast<void*>(new_key);
74
+ }
75
+
76
+ long sck_avl_compare(void* a, void* b, void* unused) {
77
+ const SubchannelKey* key_a = static_cast<const SubchannelKey*>(a);
78
+ const SubchannelKey* key_b = static_cast<const SubchannelKey*>(b);
79
+ return key_a->Cmp(*key_b);
80
+ }
81
+
82
+ void scv_avl_destroy(void* p, void* user_data) {}
83
+
84
+ void* scv_avl_copy(void* p, void* unused) { return p; }
85
+
86
+ } // namespace
87
+
88
+ const grpc_avl_vtable LocalSubchannelPool::subchannel_avl_vtable_ = {
89
+ sck_avl_destroy, // destroy_key
90
+ sck_avl_copy, // copy_key
91
+ sck_avl_compare, // compare_keys
92
+ scv_avl_destroy, // destroy_value
93
+ scv_avl_copy // copy_value
94
+ };
95
+
96
+ } // namespace grpc_core
@@ -0,0 +1,56 @@
1
+ /*
2
+ *
3
+ * Copyright 2018 gRPC authors.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ *
17
+ */
18
+
19
+ #ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LOCAL_SUBCHANNEL_POOL_H
20
+ #define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LOCAL_SUBCHANNEL_POOL_H
21
+
22
+ #include <grpc/support/port_platform.h>
23
+
24
+ #include "src/core/ext/filters/client_channel/subchannel_pool_interface.h"
25
+
26
+ namespace grpc_core {
27
+
28
+ // The local subchannel pool that is owned by a single channel. It doesn't
29
+ // support subchannel sharing with other channels by nature. Nor does it support
30
+ // subchannel retention when a subchannel is not used. The only real purpose of
31
+ // using this subchannel pool is to allow subchannel reuse within the channel
32
+ // when an incoming resolver update contains some addresses for which the
33
+ // channel has already created subchannels.
34
+ // Thread-unsafe.
35
+ class LocalSubchannelPool final : public SubchannelPoolInterface {
36
+ public:
37
+ LocalSubchannelPool();
38
+ ~LocalSubchannelPool() override;
39
+
40
+ // Implements interface methods.
41
+ // Thread-unsafe. Intended to be invoked within the client_channel combiner.
42
+ Subchannel* RegisterSubchannel(SubchannelKey* key,
43
+ Subchannel* constructed) override;
44
+ void UnregisterSubchannel(SubchannelKey* key) override;
45
+ Subchannel* FindSubchannel(SubchannelKey* key) override;
46
+
47
+ private:
48
+ // The vtable for subchannel operations in an AVL tree.
49
+ static const grpc_avl_vtable subchannel_avl_vtable_;
50
+ // A map from subchannel key to subchannel.
51
+ grpc_avl subchannel_map_;
52
+ };
53
+
54
+ } // namespace grpc_core
55
+
56
+ #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LOCAL_SUBCHANNEL_POOL_H */
@@ -19,6 +19,7 @@
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
21
  #include "src/core/ext/filters/client_channel/parse_address.h"
22
+ #include "src/core/lib/iomgr/grpc_if_nametoindex.h"
22
23
  #include "src/core/lib/iomgr/sockaddr.h"
23
24
  #include "src/core/lib/iomgr/socket_utils.h"
24
25
 
@@ -35,6 +36,11 @@
35
36
  #include "src/core/lib/gpr/host_port.h"
36
37
  #include "src/core/lib/gpr/string.h"
37
38
 
39
+ #ifdef GRPC_POSIX_SOCKET
40
+ #include <errno.h>
41
+ #include <net/if.h>
42
+ #endif
43
+
38
44
  #ifdef GRPC_HAVE_UNIX_SOCKET
39
45
 
40
46
  bool grpc_parse_unix(const grpc_uri* uri,
@@ -69,7 +75,12 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
69
75
  // Split host and port.
70
76
  char* host;
71
77
  char* port;
72
- if (!gpr_split_host_port(hostport, &host, &port)) return false;
78
+ if (!gpr_split_host_port(hostport, &host, &port)) {
79
+ if (log_errors) {
80
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
81
+ }
82
+ return false;
83
+ }
73
84
  // Parse IP address.
74
85
  memset(addr, 0, sizeof(*addr));
75
86
  addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in));
@@ -115,7 +126,12 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
115
126
  // Split host and port.
116
127
  char* host;
117
128
  char* port;
118
- if (!gpr_split_host_port(hostport, &host, &port)) return false;
129
+ if (!gpr_split_host_port(hostport, &host, &port)) {
130
+ if (log_errors) {
131
+ gpr_log(GPR_ERROR, "Failed gpr_split_host_port(%s, ...)", hostport);
132
+ }
133
+ return false;
134
+ }
119
135
  // Parse IP address.
120
136
  memset(addr, 0, sizeof(*addr));
121
137
  addr->len = static_cast<socklen_t>(sizeof(grpc_sockaddr_in6));
@@ -150,10 +166,13 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
150
166
  if (gpr_parse_bytes_to_uint32(host_end + 1,
151
167
  strlen(host) - host_without_scope_len - 1,
152
168
  &sin6_scope_id) == 0) {
153
- if (log_errors) {
154
- gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
169
+ if ((sin6_scope_id = grpc_if_nametoindex(host_end + 1)) == 0) {
170
+ gpr_log(GPR_ERROR,
171
+ "Invalid interface name: '%s'. "
172
+ "Non-numeric and failed if_nametoindex.",
173
+ host_end + 1);
174
+ goto done;
155
175
  }
156
- goto done;
157
176
  }
158
177
  // Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
159
178
  in6->sin6_scope_id = sin6_scope_id;