grpc 1.15.0 → 1.16.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 (138) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +158 -80
  3. data/etc/roots.pem +23 -0
  4. data/include/grpc/grpc.h +13 -1
  5. data/include/grpc/grpc_security.h +2 -2
  6. data/include/grpc/grpc_security_constants.h +24 -19
  7. data/include/grpc/impl/codegen/grpc_types.h +23 -5
  8. data/include/grpc/impl/codegen/port_platform.h +1 -0
  9. data/src/core/ext/filters/client_channel/client_channel.cc +95 -10
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +71 -0
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +45 -11
  12. data/src/core/ext/filters/client_channel/connector.h +3 -0
  13. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -1
  14. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +5 -3
  15. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +12 -32
  16. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +6 -5
  17. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +20 -15
  18. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -4
  19. data/src/core/ext/filters/client_channel/parse_address.cc +27 -4
  20. data/src/core/ext/filters/client_channel/parse_address.h +3 -0
  21. data/src/core/ext/filters/client_channel/resolver.h +1 -12
  22. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +1 -11
  23. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -19
  24. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +9 -3
  25. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +5 -0
  26. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +70 -0
  27. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -11
  28. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -16
  29. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +2 -1
  30. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +0 -7
  31. data/src/core/ext/filters/client_channel/subchannel.cc +45 -7
  32. data/src/core/ext/filters/client_channel/subchannel.h +16 -1
  33. data/src/core/ext/filters/client_channel/subchannel_index.cc +2 -1
  34. data/src/core/ext/filters/client_channel/subchannel_index.h +1 -4
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +32 -3
  36. data/src/core/ext/filters/http/server/http_server_filter.cc +59 -1
  37. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -2
  38. data/src/core/ext/filters/message_size/message_size_filter.cc +59 -3
  39. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +2 -0
  40. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +1 -1
  41. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +286 -228
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
  44. data/src/core/ext/transport/chttp2/transport/frame_data.cc +4 -0
  45. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +14 -3
  46. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +29 -0
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.h +9 -0
  48. data/src/core/ext/transport/chttp2/transport/internal.h +10 -0
  49. data/src/core/ext/transport/chttp2/transport/parsing.cc +85 -54
  50. data/src/core/ext/transport/chttp2/transport/writing.cc +6 -0
  51. data/src/core/lib/channel/channel_trace.cc +51 -56
  52. data/src/core/lib/channel/channel_trace.h +30 -25
  53. data/src/core/lib/channel/channelz.cc +235 -61
  54. data/src/core/lib/channel/channelz.h +179 -48
  55. data/src/core/lib/channel/channelz_registry.cc +95 -23
  56. data/src/core/lib/channel/channelz_registry.h +15 -42
  57. data/src/core/lib/gpr/sync_posix.cc +42 -0
  58. data/src/core/lib/http/httpcli.cc +1 -1
  59. data/src/core/lib/iomgr/buffer_list.cc +134 -0
  60. data/src/core/lib/iomgr/buffer_list.h +96 -0
  61. data/src/core/lib/iomgr/endpoint.cc +2 -2
  62. data/src/core/lib/iomgr/endpoint.h +6 -2
  63. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  64. data/src/core/lib/iomgr/error.cc +29 -18
  65. data/src/core/lib/iomgr/error.h +8 -0
  66. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  67. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  68. data/src/core/lib/iomgr/ev_posix.cc +16 -10
  69. data/src/core/lib/iomgr/exec_ctx.h +0 -7
  70. data/src/core/lib/iomgr/{ev_epollsig_linux.h → internal_errqueue.cc} +13 -12
  71. data/src/core/lib/iomgr/internal_errqueue.h +83 -0
  72. data/src/core/lib/iomgr/port.h +11 -2
  73. data/src/core/lib/iomgr/socket_utils_common_posix.cc +90 -0
  74. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  75. data/src/core/lib/iomgr/tcp_client_posix.cc +4 -1
  76. data/src/core/lib/iomgr/tcp_custom.cc +1 -1
  77. data/src/core/lib/iomgr/tcp_posix.cc +306 -13
  78. data/src/core/lib/iomgr/tcp_posix.h +3 -0
  79. data/src/core/lib/iomgr/tcp_server_posix.cc +2 -2
  80. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +4 -1
  81. data/src/core/lib/iomgr/tcp_windows.cc +1 -1
  82. data/src/core/lib/iomgr/timer_generic.cc +13 -12
  83. data/src/core/lib/iomgr/timer_heap.cc +2 -2
  84. data/src/core/lib/iomgr/timer_heap.h +3 -3
  85. data/src/core/lib/iomgr/timer_manager.cc +28 -3
  86. data/src/core/lib/iomgr/timer_manager.h +2 -2
  87. data/src/core/lib/iomgr/udp_server.cc +1 -1
  88. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_client_options.cc +2 -1
  89. data/src/core/lib/security/credentials/alts/grpc_alts_credentials_server_options.cc +2 -1
  90. data/src/core/lib/security/security_connector/security_connector.cc +7 -7
  91. data/src/core/lib/security/transport/secure_endpoint.cc +2 -2
  92. data/src/core/lib/security/transport/security_handshaker.cc +1 -1
  93. data/src/core/lib/security/transport/server_auth_filter.cc +53 -4
  94. data/src/core/lib/slice/slice.cc +8 -0
  95. data/src/core/lib/slice/slice_internal.h +5 -0
  96. data/src/core/lib/surface/call.cc +149 -253
  97. data/src/core/lib/surface/call.h +1 -0
  98. data/src/core/lib/surface/channel.cc +17 -13
  99. data/src/core/lib/surface/completion_queue.cc +21 -17
  100. data/src/core/lib/surface/completion_queue.h +1 -18
  101. data/src/core/lib/surface/completion_queue_factory.cc +3 -3
  102. data/src/core/lib/surface/init_secure.cc +1 -1
  103. data/src/core/lib/surface/server.cc +77 -4
  104. data/src/core/lib/surface/server.h +4 -0
  105. data/src/core/lib/surface/version.cc +2 -2
  106. data/src/core/lib/transport/metadata.cc +0 -18
  107. data/src/core/lib/transport/metadata.h +0 -3
  108. data/src/core/lib/transport/metadata_batch.cc +2 -2
  109. data/src/core/lib/transport/metadata_batch.h +2 -0
  110. data/src/core/lib/transport/static_metadata.cc +220 -249
  111. data/src/core/lib/transport/static_metadata.h +189 -191
  112. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  113. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +3 -1
  114. data/src/core/tsi/alts/handshaker/alts_tsi_event.cc +4 -2
  115. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +6 -5
  116. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +3 -1
  117. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_privacy_integrity_record_protocol.cc +2 -2
  118. data/src/core/tsi/alts_transport_security.cc +3 -1
  119. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +2 -1
  120. data/src/ruby/ext/grpc/rb_call.c +1 -0
  121. data/src/ruby/ext/grpc/rb_channel.c +3 -0
  122. data/src/ruby/ext/grpc/rb_grpc.c +31 -1
  123. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  124. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  125. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +12 -3
  126. data/src/ruby/ext/grpc/rb_server.c +2 -0
  127. data/src/ruby/lib/grpc/errors.rb +0 -1
  128. data/src/ruby/lib/grpc/generic/rpc_desc.rb +3 -3
  129. data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
  130. data/src/ruby/lib/grpc/version.rb +1 -1
  131. data/src/ruby/spec/channel_spec.rb +44 -0
  132. data/src/ruby/spec/client_auth_spec.rb +5 -5
  133. data/src/ruby/spec/generic/client_stub_spec.rb +13 -9
  134. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -3
  135. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -0
  136. data/src/ruby/spec/support/services.rb +28 -22
  137. metadata +35 -31
  138. data/src/core/lib/iomgr/ev_epollsig_linux.cc +0 -1743
@@ -23,9 +23,12 @@
23
23
 
24
24
  #include "src/core/lib/channel/channel_args.h"
25
25
  #include "src/core/lib/channel/channel_stack.h"
26
+ #include "src/core/lib/channel/channel_trace.h"
26
27
  #include "src/core/lib/channel/channelz.h"
27
28
  #include "src/core/lib/gprpp/inlined_vector.h"
28
29
 
30
+ typedef struct grpc_subchannel grpc_subchannel;
31
+
29
32
  namespace grpc_core {
30
33
 
31
34
  // TODO(ncteisen), this only contains the uuids of the children for now,
@@ -43,28 +46,59 @@ class ClientChannelNode : public ChannelNode {
43
46
  grpc_channel* channel, size_t channel_tracer_max_nodes,
44
47
  bool is_top_level_channel);
45
48
 
46
- // Override this functionality since client_channels have a notion of
47
- // channel connectivity.
48
- void PopulateConnectivityState(grpc_json* json) override;
49
+ ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
50
+ bool is_top_level_channel);
51
+ virtual ~ClientChannelNode() {}
49
52
 
50
- // Override this functionality since client_channels have subchannels
53
+ // Overriding template methods from ChannelNode to render information that
54
+ // only ClientChannelNode knows about.
55
+ void PopulateConnectivityState(grpc_json* json) override;
51
56
  void PopulateChildRefs(grpc_json* json) override;
52
57
 
53
58
  // Helper to create a channel arg to ensure this type of ChannelNode is
54
59
  // created.
55
60
  static grpc_arg CreateChannelArg();
56
61
 
57
- protected:
58
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
59
- GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW
60
- ClientChannelNode(grpc_channel* channel, size_t channel_tracer_max_nodes,
61
- bool is_top_level_channel);
62
- virtual ~ClientChannelNode() {}
63
-
64
62
  private:
65
63
  grpc_channel_element* client_channel_;
66
64
  };
67
65
 
66
+ // Handles channelz bookkeeping for sockets
67
+ class SubchannelNode : public BaseNode {
68
+ public:
69
+ SubchannelNode(grpc_subchannel* subchannel, size_t channel_tracer_max_nodes);
70
+ ~SubchannelNode() override;
71
+
72
+ void MarkSubchannelDestroyed() {
73
+ GPR_ASSERT(subchannel_ != nullptr);
74
+ subchannel_ = nullptr;
75
+ }
76
+
77
+ grpc_json* RenderJson() override;
78
+
79
+ // proxy methods to composed classes.
80
+ void AddTraceEvent(ChannelTrace::Severity severity, grpc_slice data) {
81
+ trace_.AddTraceEvent(severity, data);
82
+ }
83
+ void AddTraceEventWithReference(ChannelTrace::Severity severity,
84
+ grpc_slice data,
85
+ RefCountedPtr<BaseNode> referenced_channel) {
86
+ trace_.AddTraceEventWithReference(severity, data,
87
+ std::move(referenced_channel));
88
+ }
89
+ void RecordCallStarted() { call_counter_.RecordCallStarted(); }
90
+ void RecordCallFailed() { call_counter_.RecordCallFailed(); }
91
+ void RecordCallSucceeded() { call_counter_.RecordCallSucceeded(); }
92
+
93
+ private:
94
+ grpc_subchannel* subchannel_;
95
+ UniquePtr<char> target_;
96
+ CallCountingHelper call_counter_;
97
+ ChannelTrace trace_;
98
+
99
+ void PopulateConnectivityState(grpc_json* json);
100
+ };
101
+
68
102
  } // namespace channelz
69
103
  } // namespace grpc_core
70
104
 
@@ -47,6 +47,9 @@ typedef struct {
47
47
 
48
48
  /** channel arguments (to be passed to the filters) */
49
49
  grpc_channel_args* channel_args;
50
+
51
+ /** socket uuid of the connected transport. 0 if not available */
52
+ intptr_t socket_uuid;
50
53
  } grpc_connect_out_args;
51
54
 
52
55
  struct grpc_connector_vtable {
@@ -320,7 +320,7 @@ static void http_connect_handshaker_do_handshake(
320
320
  // Take a new ref to be held by the write callback.
321
321
  gpr_ref(&handshaker->refcount);
322
322
  grpc_endpoint_write(args->endpoint, &handshaker->write_buffer,
323
- &handshaker->request_done_closure);
323
+ &handshaker->request_done_closure, nullptr);
324
324
  gpr_mu_unlock(&handshaker->mu);
325
325
  }
326
326
 
@@ -852,10 +852,12 @@ void GrpcLb::BalancerCallState::OnBalancerMessageReceivedLocked(
852
852
  }
853
853
  } else {
854
854
  // No valid initial response or serverlist found.
855
+ char* response_slice_str =
856
+ grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX);
855
857
  gpr_log(GPR_ERROR,
856
858
  "[grpclb %p] Invalid LB response received: '%s'. Ignoring.",
857
- grpclb_policy,
858
- grpc_dump_slice(response_slice, GPR_DUMP_ASCII | GPR_DUMP_HEX));
859
+ grpclb_policy, response_slice_str);
860
+ gpr_free(response_slice_str);
859
861
  }
860
862
  grpc_slice_unref_internal(response_slice);
861
863
  if (!grpclb_policy->shutting_down_) {
@@ -1265,7 +1267,7 @@ void GrpcLb::FillChildRefsForChannelz(ChildRefsList* child_subchannels,
1265
1267
  grpc_core::channelz::ChannelNode* channel_node =
1266
1268
  grpc_channel_get_channelz_node(lb_channel_);
1267
1269
  if (channel_node != nullptr) {
1268
- child_channels->push_back(channel_node->channel_uuid());
1270
+ child_channels->push_back(channel_node->uuid());
1269
1271
  }
1270
1272
  }
1271
1273
  }
@@ -71,11 +71,12 @@ class PickFirst : public LoadBalancingPolicy {
71
71
  : public SubchannelData<PickFirstSubchannelList,
72
72
  PickFirstSubchannelData> {
73
73
  public:
74
- PickFirstSubchannelData(PickFirstSubchannelList* subchannel_list,
75
- const grpc_lb_user_data_vtable* user_data_vtable,
76
- const grpc_lb_address& address,
77
- grpc_subchannel* subchannel,
78
- grpc_combiner* combiner)
74
+ PickFirstSubchannelData(
75
+ SubchannelList<PickFirstSubchannelList, PickFirstSubchannelData>*
76
+ subchannel_list,
77
+ const grpc_lb_user_data_vtable* user_data_vtable,
78
+ const grpc_lb_address& address, grpc_subchannel* subchannel,
79
+ grpc_combiner* combiner)
79
80
  : SubchannelData(subchannel_list, user_data_vtable, address, subchannel,
80
81
  combiner) {}
81
82
 
@@ -126,7 +127,6 @@ class PickFirst : public LoadBalancingPolicy {
126
127
  void ShutdownLocked() override;
127
128
 
128
129
  void StartPickingLocked();
129
- void DestroyUnselectedSubchannelsLocked();
130
130
  void UpdateChildRefsLocked();
131
131
 
132
132
  // All our subchannels.
@@ -250,14 +250,9 @@ void PickFirst::CancelMatchingPicksLocked(uint32_t initial_metadata_flags_mask,
250
250
 
251
251
  void PickFirst::StartPickingLocked() {
252
252
  started_picking_ = true;
253
- if (subchannel_list_ != nullptr) {
254
- for (size_t i = 0; i < subchannel_list_->num_subchannels(); ++i) {
255
- if (subchannel_list_->subchannel(i)->subchannel() != nullptr) {
256
- subchannel_list_->subchannel(i)
257
- ->CheckConnectivityStateAndStartWatchingLocked();
258
- break;
259
- }
260
- }
253
+ if (subchannel_list_ != nullptr && subchannel_list_->num_subchannels() > 0) {
254
+ subchannel_list_->subchannel(0)
255
+ ->CheckConnectivityStateAndStartWatchingLocked();
261
256
  }
262
257
  }
263
258
 
@@ -294,15 +289,6 @@ bool PickFirst::PickLocked(PickState* pick, grpc_error** error) {
294
289
  return false;
295
290
  }
296
291
 
297
- void PickFirst::DestroyUnselectedSubchannelsLocked() {
298
- for (size_t i = 0; i < subchannel_list_->num_subchannels(); ++i) {
299
- PickFirstSubchannelData* sd = subchannel_list_->subchannel(i);
300
- if (selected_ != sd) {
301
- sd->UnrefSubchannelLocked("selected_different_subchannel");
302
- }
303
- }
304
- }
305
-
306
292
  grpc_connectivity_state PickFirst::CheckConnectivityLocked(grpc_error** error) {
307
293
  return grpc_connectivity_state_get(&state_tracker_, error);
308
294
  }
@@ -419,7 +405,6 @@ void PickFirst::UpdateLocked(const grpc_channel_args& args) {
419
405
  if (sd->CheckConnectivityStateLocked(&error) == GRPC_CHANNEL_READY) {
420
406
  selected_ = sd;
421
407
  subchannel_list_ = std::move(subchannel_list);
422
- DestroyUnselectedSubchannelsLocked();
423
408
  sd->StartConnectivityWatchLocked();
424
409
  // If there was a previously pending update (which may or may
425
410
  // not have contained the currently selected subchannel), drop
@@ -504,7 +489,6 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
504
489
  p->TryReresolutionLocked(&grpc_lb_pick_first_trace, GRPC_ERROR_NONE);
505
490
  // In transient failure. Rely on re-resolution to recover.
506
491
  p->selected_ = nullptr;
507
- UnrefSubchannelLocked("pf_selected_shutdown");
508
492
  StopConnectivityWatchLocked();
509
493
  } else {
510
494
  grpc_connectivity_state_set(&p->state_tracker_, connectivity_state,
@@ -535,11 +519,9 @@ void PickFirst::PickFirstSubchannelData::ProcessConnectivityChangeLocked(
535
519
  case GRPC_CHANNEL_TRANSIENT_FAILURE: {
536
520
  StopConnectivityWatchLocked();
537
521
  PickFirstSubchannelData* sd = this;
538
- do {
539
- size_t next_index =
540
- (sd->Index() + 1) % subchannel_list()->num_subchannels();
541
- sd = subchannel_list()->subchannel(next_index);
542
- } while (sd->subchannel() == nullptr);
522
+ size_t next_index =
523
+ (sd->Index() + 1) % subchannel_list()->num_subchannels();
524
+ sd = subchannel_list()->subchannel(next_index);
543
525
  // Case 1: Only set state to TRANSIENT_FAILURE if we've tried
544
526
  // all subchannels.
545
527
  if (sd->Index() == 0 && subchannel_list() == p->subchannel_list_.get()) {
@@ -600,8 +582,6 @@ void PickFirst::PickFirstSubchannelData::ProcessUnselectedReadyLocked() {
600
582
  if (grpc_lb_pick_first_trace.enabled()) {
601
583
  gpr_log(GPR_INFO, "Pick First %p selected subchannel %p", p, subchannel());
602
584
  }
603
- // Drop all other subchannels, since we are now connected.
604
- p->DestroyUnselectedSubchannelsLocked();
605
585
  // Update any calls that were waiting for a pick.
606
586
  PickState* pick;
607
587
  while ((pick = p->pending_picks_)) {
@@ -89,11 +89,12 @@ class RoundRobin : public LoadBalancingPolicy {
89
89
  : public SubchannelData<RoundRobinSubchannelList,
90
90
  RoundRobinSubchannelData> {
91
91
  public:
92
- RoundRobinSubchannelData(RoundRobinSubchannelList* subchannel_list,
93
- const grpc_lb_user_data_vtable* user_data_vtable,
94
- const grpc_lb_address& address,
95
- grpc_subchannel* subchannel,
96
- grpc_combiner* combiner)
92
+ RoundRobinSubchannelData(
93
+ SubchannelList<RoundRobinSubchannelList, RoundRobinSubchannelData>*
94
+ subchannel_list,
95
+ const grpc_lb_user_data_vtable* user_data_vtable,
96
+ const grpc_lb_address& address, grpc_subchannel* subchannel,
97
+ grpc_combiner* combiner)
97
98
  : SubchannelData(subchannel_list, user_data_vtable, address, subchannel,
98
99
  combiner),
99
100
  user_data_vtable_(user_data_vtable),
@@ -65,6 +65,10 @@ class MySubchannelList
65
65
 
66
66
  namespace grpc_core {
67
67
 
68
+ // Forward declaration.
69
+ template <typename SubchannelListType, typename SubchannelDataType>
70
+ class SubchannelList;
71
+
68
72
  // Stores data for a particular subchannel in a subchannel list.
69
73
  // Callers must create a subclass that implements the
70
74
  // ProcessConnectivityChangeLocked() method.
@@ -72,7 +76,9 @@ template <typename SubchannelListType, typename SubchannelDataType>
72
76
  class SubchannelData {
73
77
  public:
74
78
  // Returns a pointer to the subchannel list containing this object.
75
- SubchannelListType* subchannel_list() const { return subchannel_list_; }
79
+ SubchannelListType* subchannel_list() const {
80
+ return static_cast<SubchannelListType*>(subchannel_list_);
81
+ }
76
82
 
77
83
  // Returns the index into the subchannel list of this object.
78
84
  size_t Index() const {
@@ -102,11 +108,6 @@ class SubchannelData {
102
108
  return pending_connectivity_state_unsafe_;
103
109
  }
104
110
 
105
- // Unrefs the subchannel. May be used if an individual subchannel is
106
- // no longer needed even though the subchannel list as a whole is not
107
- // being unreffed.
108
- virtual void UnrefSubchannelLocked(const char* reason);
109
-
110
111
  // Resets the connection backoff.
111
112
  // TODO(roth): This method should go away when we move the backoff
112
113
  // code out of the subchannel and into the LB policies.
@@ -138,10 +139,11 @@ class SubchannelData {
138
139
  GRPC_ABSTRACT_BASE_CLASS
139
140
 
140
141
  protected:
141
- SubchannelData(SubchannelListType* subchannel_list,
142
- const grpc_lb_user_data_vtable* user_data_vtable,
143
- const grpc_lb_address& address, grpc_subchannel* subchannel,
144
- grpc_combiner* combiner);
142
+ SubchannelData(
143
+ SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
144
+ const grpc_lb_user_data_vtable* user_data_vtable,
145
+ const grpc_lb_address& address, grpc_subchannel* subchannel,
146
+ grpc_combiner* combiner);
145
147
 
146
148
  virtual ~SubchannelData();
147
149
 
@@ -154,6 +156,10 @@ class SubchannelData {
154
156
  grpc_connectivity_state connectivity_state,
155
157
  grpc_error* error) GRPC_ABSTRACT;
156
158
 
159
+ // Unrefs the subchannel. May be overridden by subclasses that need
160
+ // to perform extra cleanup when unreffing the subchannel.
161
+ virtual void UnrefSubchannelLocked(const char* reason);
162
+
157
163
  private:
158
164
  // Updates connected_subchannel_ based on pending_connectivity_state_unsafe_.
159
165
  // Returns true if the connectivity state should be reported.
@@ -162,7 +168,7 @@ class SubchannelData {
162
168
  static void OnConnectivityChangedLocked(void* arg, grpc_error* error);
163
169
 
164
170
  // Backpointer to owning subchannel list. Not owned.
165
- SubchannelListType* subchannel_list_;
171
+ SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list_;
166
172
 
167
173
  // The subchannel and connected subchannel.
168
174
  grpc_subchannel* subchannel_;
@@ -201,7 +207,7 @@ class SubchannelList
201
207
  grpc_core::channelz::SubchannelNode* subchannel_node =
202
208
  grpc_subchannel_get_channelz_node(subchannels_[i].subchannel());
203
209
  if (subchannel_node != nullptr) {
204
- refs_list->push_back(subchannel_node->subchannel_uuid());
210
+ refs_list->push_back(subchannel_node->uuid());
205
211
  }
206
212
  }
207
213
  }
@@ -269,7 +275,7 @@ class SubchannelList
269
275
 
270
276
  template <typename SubchannelListType, typename SubchannelDataType>
271
277
  SubchannelData<SubchannelListType, SubchannelDataType>::SubchannelData(
272
- SubchannelListType* subchannel_list,
278
+ SubchannelList<SubchannelListType, SubchannelDataType>* subchannel_list,
273
279
  const grpc_lb_user_data_vtable* user_data_vtable,
274
280
  const grpc_lb_address& address, grpc_subchannel* subchannel,
275
281
  grpc_combiner* combiner)
@@ -533,8 +539,7 @@ SubchannelList<SubchannelListType, SubchannelDataType>::SubchannelList(
533
539
  address_uri);
534
540
  gpr_free(address_uri);
535
541
  }
536
- subchannels_.emplace_back(static_cast<SubchannelListType*>(this),
537
- addresses->user_data_vtable,
542
+ subchannels_.emplace_back(this, addresses->user_data_vtable,
538
543
  addresses->addresses[i], subchannel, combiner);
539
544
  }
540
545
  }
@@ -70,16 +70,14 @@ grpc_lb_addresses* grpc_lb_addresses_create(
70
70
  grpc_lb_addresses* grpc_lb_addresses_copy(const grpc_lb_addresses* addresses);
71
71
 
72
72
  /** Sets the value of the address at index \a index of \a addresses.
73
- * \a address is a socket address of length \a address_len.
74
- * Takes ownership of \a balancer_name. */
73
+ * \a address is a socket address of length \a address_len. */
75
74
  void grpc_lb_addresses_set_address(grpc_lb_addresses* addresses, size_t index,
76
75
  const void* address, size_t address_len,
77
76
  bool is_balancer, const char* balancer_name,
78
77
  void* user_data);
79
78
 
80
79
  /** Sets the value of the address at index \a index of \a addresses from \a uri.
81
- * Returns true upon success, false otherwise. Takes ownership of \a
82
- * balancer_name. */
80
+ * Returns true upon success, false otherwise. */
83
81
  bool grpc_lb_addresses_set_address_from_uri(grpc_lb_addresses* addresses,
84
82
  size_t index, const grpc_uri* uri,
85
83
  bool is_balancer,
@@ -125,27 +125,41 @@ bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
125
125
  char* host_end = static_cast<char*>(gpr_memrchr(host, '%', strlen(host)));
126
126
  if (host_end != nullptr) {
127
127
  GPR_ASSERT(host_end >= host);
128
- char host_without_scope[GRPC_INET6_ADDRSTRLEN];
128
+ char host_without_scope[GRPC_INET6_ADDRSTRLEN + 1];
129
129
  size_t host_without_scope_len = static_cast<size_t>(host_end - host);
130
130
  uint32_t sin6_scope_id = 0;
131
+ if (host_without_scope_len > GRPC_INET6_ADDRSTRLEN) {
132
+ if (log_errors) {
133
+ gpr_log(
134
+ GPR_ERROR,
135
+ "invalid ipv6 address length %zu. Length cannot be greater than "
136
+ "GRPC_INET6_ADDRSTRLEN i.e %d)",
137
+ host_without_scope_len, GRPC_INET6_ADDRSTRLEN);
138
+ }
139
+ goto done;
140
+ }
131
141
  strncpy(host_without_scope, host, host_without_scope_len);
132
142
  host_without_scope[host_without_scope_len] = '\0';
133
143
  if (grpc_inet_pton(GRPC_AF_INET6, host_without_scope, &in6->sin6_addr) ==
134
144
  0) {
135
- gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope);
145
+ if (log_errors) {
146
+ gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope);
147
+ }
136
148
  goto done;
137
149
  }
138
150
  if (gpr_parse_bytes_to_uint32(host_end + 1,
139
151
  strlen(host) - host_without_scope_len - 1,
140
152
  &sin6_scope_id) == 0) {
141
- gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
153
+ if (log_errors) {
154
+ gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
155
+ }
142
156
  goto done;
143
157
  }
144
158
  // Handle "sin6_scope_id" being type "u_long". See grpc issue #10027.
145
159
  in6->sin6_scope_id = sin6_scope_id;
146
160
  } else {
147
161
  if (grpc_inet_pton(GRPC_AF_INET6, host, &in6->sin6_addr) == 0) {
148
- gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
162
+ if (log_errors) gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
149
163
  goto done;
150
164
  }
151
165
  }
@@ -190,3 +204,12 @@ bool grpc_parse_uri(const grpc_uri* uri, grpc_resolved_address* resolved_addr) {
190
204
  gpr_log(GPR_ERROR, "Can't parse scheme '%s'", uri->scheme);
191
205
  return false;
192
206
  }
207
+
208
+ uint16_t grpc_strhtons(const char* port) {
209
+ if (strcmp(port, "http") == 0) {
210
+ return htons(80);
211
+ } else if (strcmp(port, "https") == 0) {
212
+ return htons(443);
213
+ }
214
+ return htons(static_cast<unsigned short>(atoi(port)));
215
+ }
@@ -47,4 +47,7 @@ bool grpc_parse_ipv4_hostport(const char* hostport, grpc_resolved_address* addr,
47
47
  bool grpc_parse_ipv6_hostport(const char* hostport, grpc_resolved_address* addr,
48
48
  bool log_errors);
49
49
 
50
+ /* Converts named or numeric port to a uint16 suitable for use in a sockaddr. */
51
+ uint16_t grpc_strhtons(const char* port);
52
+
50
53
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_PARSE_ADDRESS_H */
@@ -81,18 +81,7 @@ class Resolver : public InternallyRefCountedWithTracing<Resolver> {
81
81
  ///
82
82
  /// If this causes new data to become available, then the currently
83
83
  /// pending call to \a NextLocked() will return the new result.
84
- ///
85
- /// Note: Currently, all resolvers are required to return a new result
86
- /// shortly after this method is called. For pull-based mechanisms, if
87
- /// the implementation decides to delay querying the name service, it
88
- /// should immediately return a new copy of the previously returned
89
- /// result (and it can then return the updated data later, when it
90
- /// actually does query the name service). For push-based mechanisms,
91
- /// the implementation should immediately return a new copy of the
92
- /// last-seen result.
93
- /// TODO(roth): Remove this requirement once we fix pick_first to not
94
- /// throw away unselected subchannels.
95
- virtual void RequestReresolutionLocked() GRPC_ABSTRACT;
84
+ virtual void RequestReresolutionLocked() {}
96
85
 
97
86
  /// Resets the re-resolution backoff, if any.
98
87
  /// This needs to be implemented only by pull-based implementations;