grpc 1.23.0 → 1.24.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (245) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +765 -485
  3. data/include/grpc/grpc.h +3 -1
  4. data/include/grpc/grpc_security.h +20 -4
  5. data/include/grpc/impl/codegen/grpc_types.h +6 -5
  6. data/include/grpc/impl/codegen/port_platform.h +25 -0
  7. data/src/core/ext/filters/client_channel/backend_metric.cc +78 -0
  8. data/src/core/ext/filters/client_channel/backend_metric.h +36 -0
  9. data/src/core/ext/filters/client_channel/channel_connectivity.cc +16 -2
  10. data/src/core/ext/filters/client_channel/client_channel.cc +325 -267
  11. data/src/core/ext/filters/client_channel/client_channel_factory.h +0 -4
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +23 -32
  13. data/src/core/ext/filters/client_channel/http_proxy.cc +7 -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 +58 -34
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -50
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -2
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +35 -17
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +130 -215
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +34 -21
  21. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1120 -802
  22. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +8 -2
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +33 -12
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +151 -40
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +184 -26
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +389 -245
  27. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +98 -60
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -1
  29. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +89 -0
  30. data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +3 -8
  31. data/src/core/ext/filters/client_channel/server_address.cc +1 -3
  32. data/src/core/ext/filters/client_channel/server_address.h +1 -1
  33. data/src/core/ext/filters/client_channel/subchannel.h +2 -1
  34. data/src/core/ext/filters/client_idle/client_idle_filter.cc +207 -29
  35. data/src/core/ext/filters/http/client/http_client_filter.cc +10 -8
  36. data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
  37. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +10 -7
  38. data/src/core/ext/filters/http/server/http_server_filter.cc +52 -26
  39. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +23 -20
  40. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +24 -21
  41. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  42. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -24
  43. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
  44. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +237 -191
  45. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +29 -27
  46. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +1 -1
  47. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +19 -4
  48. data/src/core/ext/transport/chttp2/transport/hpack_table.h +13 -4
  49. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -1
  50. data/src/core/ext/transport/chttp2/transport/internal.h +0 -2
  51. data/src/core/ext/transport/chttp2/transport/parsing.cc +99 -71
  52. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +222 -0
  53. data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +818 -0
  54. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +314 -0
  55. data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1142 -0
  56. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +53 -0
  57. data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +158 -0
  58. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +34 -0
  59. data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +69 -0
  60. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +49 -0
  61. data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +240 -0
  62. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +110 -0
  63. data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +324 -0
  64. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +235 -0
  65. data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +661 -0
  66. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +84 -0
  67. data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +274 -0
  68. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +175 -0
  69. data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +572 -0
  70. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +150 -0
  71. data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +596 -0
  72. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +35 -0
  73. data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +80 -0
  74. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +95 -0
  75. data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +308 -0
  76. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +128 -0
  77. data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +392 -0
  78. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +91 -0
  79. data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +236 -0
  80. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +88 -0
  81. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +258 -0
  82. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +111 -0
  83. data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +324 -0
  84. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +23 -0
  85. data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +50 -0
  86. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +52 -0
  87. data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +130 -0
  88. data/src/core/ext/upb-generated/envoy/type/percent.upb.c +39 -0
  89. data/src/core/ext/upb-generated/envoy/type/percent.upb.h +87 -0
  90. data/src/core/ext/upb-generated/envoy/type/range.upb.c +39 -0
  91. data/src/core/ext/upb-generated/envoy/type/range.upb.h +85 -0
  92. data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +17 -0
  93. data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +30 -0
  94. data/src/core/ext/upb-generated/google/api/annotations.upb.c +18 -0
  95. data/src/core/ext/upb-generated/google/api/annotations.upb.h +30 -0
  96. data/src/core/ext/upb-generated/google/api/http.upb.c +66 -0
  97. data/src/core/ext/upb-generated/google/api/http.upb.h +190 -0
  98. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +27 -0
  99. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +58 -0
  100. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +485 -0
  101. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1690 -0
  102. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +27 -0
  103. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +58 -0
  104. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +22 -0
  105. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +50 -0
  106. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +79 -0
  107. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +215 -0
  108. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +27 -0
  109. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +58 -0
  110. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +106 -0
  111. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +238 -0
  112. data/src/core/ext/upb-generated/google/rpc/status.upb.c +33 -0
  113. data/src/core/ext/upb-generated/google/rpc/status.upb.h +74 -0
  114. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +49 -0
  115. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +126 -0
  116. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +209 -0
  117. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +681 -0
  118. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +42 -0
  119. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +109 -0
  120. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +36 -0
  121. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +84 -0
  122. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +133 -0
  123. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +359 -0
  124. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +58 -0
  125. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +144 -0
  126. data/src/core/ext/upb-generated/validate/validate.upb.c +443 -0
  127. data/src/core/ext/upb-generated/validate/validate.upb.h +2037 -0
  128. data/src/core/lib/channel/channel_args.cc +21 -0
  129. data/src/core/lib/channel/channel_args.h +16 -2
  130. data/src/core/lib/channel/channel_stack.h +2 -1
  131. data/src/core/lib/channel/channelz.cc +54 -56
  132. data/src/core/lib/channel/channelz.h +29 -12
  133. data/src/core/lib/compression/compression.cc +2 -1
  134. data/src/core/lib/compression/compression_internal.h +8 -0
  135. data/src/core/lib/gpr/log_linux.cc +2 -2
  136. data/src/core/lib/gpr/log_posix.cc +2 -2
  137. data/src/core/lib/gpr/time_precise.cc +123 -36
  138. data/src/core/lib/gpr/time_precise.h +37 -0
  139. data/src/core/lib/gprpp/abstract.h +10 -0
  140. data/src/core/lib/gprpp/atomic.h +4 -0
  141. data/src/core/lib/gprpp/inlined_vector.h +20 -4
  142. data/src/core/lib/gprpp/map.h +109 -6
  143. data/src/core/lib/gprpp/memory.h +6 -0
  144. data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
  145. data/src/core/lib/iomgr/ev_epollex_linux.cc +29 -54
  146. data/src/core/lib/iomgr/exec_ctx.cc +27 -17
  147. data/src/core/lib/iomgr/exec_ctx.h +3 -0
  148. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -3
  149. data/src/core/lib/iomgr/tcp_posix.cc +16 -25
  150. data/src/core/lib/iomgr/tcp_server_custom.cc +1 -1
  151. data/src/core/lib/iomgr/timer_manager.cc +8 -1
  152. data/src/core/lib/iomgr/timer_manager.h +2 -0
  153. data/src/core/lib/security/credentials/credentials.h +8 -2
  154. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -0
  155. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -0
  156. data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +3 -3
  157. data/src/core/lib/security/security_connector/ssl_utils.cc +1 -12
  158. data/src/core/lib/security/security_connector/ssl_utils.h +10 -6
  159. data/src/core/lib/security/security_connector/ssl_utils_config.cc +32 -0
  160. data/src/core/lib/security/security_connector/ssl_utils_config.h +30 -0
  161. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +161 -49
  162. data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +34 -1
  163. data/src/core/lib/slice/slice_intern.cc +17 -9
  164. data/src/core/lib/slice/slice_internal.h +34 -7
  165. data/src/core/lib/slice/slice_utils.h +7 -3
  166. data/src/core/lib/surface/call.cc +97 -57
  167. data/src/core/lib/surface/channel.cc +2 -2
  168. data/src/core/lib/surface/completion_queue.cc +10 -16
  169. data/src/core/lib/surface/init.cc +3 -0
  170. data/src/core/lib/surface/server.cc +11 -14
  171. data/src/core/lib/surface/validate_metadata.cc +4 -0
  172. data/src/core/lib/surface/version.cc +2 -2
  173. data/src/core/lib/transport/metadata.cc +4 -4
  174. data/src/core/lib/transport/metadata_batch.cc +72 -16
  175. data/src/core/lib/transport/metadata_batch.h +38 -0
  176. data/src/core/lib/transport/static_metadata.cc +814 -1023
  177. data/src/core/lib/transport/static_metadata.h +271 -213
  178. data/src/core/lib/transport/transport.h +12 -0
  179. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  180. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +104 -76
  181. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -16
  182. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
  183. data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +10 -6
  184. data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +4 -3
  185. data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +74 -48
  186. data/src/core/tsi/alts/handshaker/transport_security_common_api.h +34 -26
  187. data/src/core/tsi/ssl_transport_security.cc +14 -6
  188. data/src/core/tsi/ssl_transport_security.h +4 -0
  189. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  190. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  191. data/src/ruby/ext/grpc/extconf.rb +5 -0
  192. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  193. data/src/ruby/ext/grpc/rb_grpc.c +1 -42
  194. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
  195. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
  196. data/src/ruby/lib/grpc.rb +2 -0
  197. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  198. data/src/ruby/lib/grpc/errors.rb +4 -7
  199. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +9 -4
  200. data/src/ruby/lib/grpc/structs.rb +15 -0
  201. data/src/ruby/lib/grpc/version.rb +1 -1
  202. data/src/ruby/spec/errors_spec.rb +1 -0
  203. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  204. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +34 -0
  205. data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -29
  206. data/third_party/upb/upb/decode.c +604 -0
  207. data/third_party/upb/upb/decode.h +21 -0
  208. data/third_party/upb/upb/encode.c +378 -0
  209. data/third_party/upb/upb/encode.h +21 -0
  210. data/third_party/upb/upb/generated_util.h +105 -0
  211. data/third_party/upb/upb/msg.c +111 -0
  212. data/third_party/upb/upb/msg.h +69 -0
  213. data/third_party/upb/upb/port.c +27 -0
  214. data/third_party/upb/upb/port_def.inc +152 -0
  215. data/third_party/upb/upb/port_undef.inc +21 -0
  216. data/third_party/upb/upb/table.c +911 -0
  217. data/third_party/upb/upb/table.int.h +507 -0
  218. data/third_party/upb/upb/upb.c +261 -0
  219. data/third_party/upb/upb/upb.h +364 -0
  220. metadata +129 -50
  221. data/src/core/ext/filters/client_channel/health/health.pb.c +0 -23
  222. data/src/core/ext/filters/client_channel/health/health.pb.h +0 -73
  223. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +0 -19
  224. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +0 -54
  225. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +0 -19
  226. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +0 -54
  227. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +0 -89
  228. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -164
  229. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +0 -520
  230. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +0 -323
  231. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +0 -145
  232. data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +0 -149
  233. data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -47
  234. data/src/core/tsi/alts/handshaker/altscontext.pb.h +0 -63
  235. data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -122
  236. data/src/core/tsi/alts/handshaker/handshaker.pb.h +0 -254
  237. data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -49
  238. data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +0 -78
  239. data/third_party/nanopb/pb.h +0 -579
  240. data/third_party/nanopb/pb_common.c +0 -97
  241. data/third_party/nanopb/pb_common.h +0 -42
  242. data/third_party/nanopb/pb_decode.c +0 -1347
  243. data/third_party/nanopb/pb_decode.h +0 -149
  244. data/third_party/nanopb/pb_encode.c +0 -696
  245. data/third_party/nanopb/pb_encode.h +0 -154
@@ -25,14 +25,21 @@
25
25
 
26
26
  #include "src/core/ext/filters/client_channel/server_address.h"
27
27
 
28
+ namespace grpc_core {
29
+
28
30
  /// Makes any necessary modifications to \a args for use in the grpclb
29
31
  /// balancer channel.
30
32
  ///
31
33
  /// Takes ownership of \a args.
32
34
  ///
33
35
  /// Caller takes ownership of the returned args.
34
- grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
35
- const grpc_core::ServerAddressList& addresses, grpc_channel_args* args);
36
+ grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
37
+ const ServerAddressList& addresses, grpc_channel_args* args);
38
+
39
+ grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
40
+ const grpc_channel_args& args);
41
+
42
+ } // namespace grpc_core
36
43
 
37
44
  #endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H \
38
45
  */
@@ -22,6 +22,7 @@
22
22
 
23
23
  #include <string.h>
24
24
 
25
+ #include <grpc/grpc_security.h>
25
26
  #include <grpc/support/alloc.h>
26
27
  #include <grpc/support/string_util.h>
27
28
 
@@ -35,6 +36,7 @@
35
36
  #include "src/core/lib/slice/slice_internal.h"
36
37
 
37
38
  namespace grpc_core {
39
+
38
40
  namespace {
39
41
 
40
42
  int BalancerNameCmp(const grpc_core::UniquePtr<char>& a,
@@ -65,37 +67,53 @@ RefCountedPtr<TargetAuthorityTable> CreateTargetAuthorityTable(
65
67
  }
66
68
 
67
69
  } // namespace
68
- } // namespace grpc_core
69
70
 
70
- grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
71
- const grpc_core::ServerAddressList& addresses, grpc_channel_args* args) {
72
- const char* args_to_remove[1];
73
- size_t num_args_to_remove = 0;
74
- grpc_arg args_to_add[2];
75
- size_t num_args_to_add = 0;
71
+ grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
72
+ const ServerAddressList& addresses, grpc_channel_args* args) {
73
+ InlinedVector<const char*, 1> args_to_remove;
74
+ InlinedVector<grpc_arg, 2> args_to_add;
76
75
  // Add arg for targets info table.
77
- grpc_core::RefCountedPtr<grpc_core::TargetAuthorityTable>
78
- target_authority_table = grpc_core::CreateTargetAuthorityTable(addresses);
79
- args_to_add[num_args_to_add++] =
80
- grpc_core::CreateTargetAuthorityTableChannelArg(
81
- target_authority_table.get());
76
+ RefCountedPtr<TargetAuthorityTable> target_authority_table =
77
+ CreateTargetAuthorityTable(addresses);
78
+ args_to_add.emplace_back(
79
+ CreateTargetAuthorityTableChannelArg(target_authority_table.get()));
82
80
  // Substitute the channel credentials with a version without call
83
81
  // credentials: the load balancer is not necessarily trusted to handle
84
82
  // bearer token credentials.
85
83
  grpc_channel_credentials* channel_credentials =
86
84
  grpc_channel_credentials_find_in_args(args);
87
- grpc_core::RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
85
+ RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
88
86
  if (channel_credentials != nullptr) {
89
87
  creds_sans_call_creds =
90
88
  channel_credentials->duplicate_without_call_credentials();
91
89
  GPR_ASSERT(creds_sans_call_creds != nullptr);
92
- args_to_remove[num_args_to_remove++] = GRPC_ARG_CHANNEL_CREDENTIALS;
93
- args_to_add[num_args_to_add++] =
94
- grpc_channel_credentials_to_arg(creds_sans_call_creds.get());
90
+ args_to_remove.emplace_back(GRPC_ARG_CHANNEL_CREDENTIALS);
91
+ args_to_add.emplace_back(
92
+ grpc_channel_credentials_to_arg(creds_sans_call_creds.get()));
95
93
  }
96
94
  grpc_channel_args* result = grpc_channel_args_copy_and_add_and_remove(
97
- args, args_to_remove, num_args_to_remove, args_to_add, num_args_to_add);
95
+ args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
96
+ args_to_add.size());
98
97
  // Clean up.
99
98
  grpc_channel_args_destroy(args);
100
99
  return result;
101
100
  }
101
+
102
+ grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
103
+ const grpc_channel_args& args) {
104
+ grpc_channel_credentials* creds =
105
+ grpc_channel_credentials_find_in_args(&args);
106
+ if (creds == nullptr) {
107
+ // Build with security but parent channel is insecure.
108
+ return grpc_insecure_channel_create(target_uri, &args, nullptr);
109
+ }
110
+ const char* arg_to_remove = GRPC_ARG_CHANNEL_CREDENTIALS;
111
+ grpc_channel_args* new_args =
112
+ grpc_channel_args_copy_and_remove(&args, &arg_to_remove, 1);
113
+ grpc_channel* channel =
114
+ grpc_secure_channel_create(creds, target_uri, new_args, nullptr);
115
+ grpc_channel_args_destroy(new_args);
116
+ return channel;
117
+ }
118
+
119
+ } // namespace grpc_core
@@ -18,213 +18,154 @@
18
18
 
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
- #include "pb_decode.h"
22
- #include "pb_encode.h"
23
21
  #include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h"
22
+ #include "src/core/lib/gpr/useful.h"
24
23
 
25
- #include <grpc/support/alloc.h>
26
-
27
- /* invoked once for every Server in ServerList */
28
- static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field,
29
- void** arg) {
30
- grpc_grpclb_serverlist* sl = static_cast<grpc_grpclb_serverlist*>(*arg);
31
- grpc_grpclb_server server;
32
- if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, &server))) {
33
- gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
34
- return false;
35
- }
36
- ++sl->num_servers;
37
- return true;
38
- }
39
-
40
- typedef struct decode_serverlist_arg {
41
- /* The decoding callback is invoked once per server in serverlist. Remember
42
- * which index of the serverlist are we currently decoding */
43
- size_t decoding_idx;
44
- /* The decoded serverlist */
45
- grpc_grpclb_serverlist* serverlist;
46
- } decode_serverlist_arg;
24
+ #include "google/protobuf/duration.upb.h"
25
+ #include "google/protobuf/timestamp.upb.h"
47
26
 
48
- /* invoked once for every Server in ServerList */
49
- static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field,
50
- void** arg) {
51
- decode_serverlist_arg* dec_arg = static_cast<decode_serverlist_arg*>(*arg);
52
- GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx);
53
- grpc_grpclb_server* server =
54
- static_cast<grpc_grpclb_server*>(gpr_zalloc(sizeof(grpc_grpclb_server)));
55
- if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, server))) {
56
- gpr_free(server);
57
- gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
58
- return false;
59
- }
60
- dec_arg->serverlist->servers[dec_arg->decoding_idx++] = server;
61
- return true;
62
- }
27
+ #include <grpc/support/alloc.h>
63
28
 
64
- grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name) {
65
- grpc_grpclb_request* req = static_cast<grpc_grpclb_request*>(
66
- gpr_malloc(sizeof(grpc_grpclb_request)));
67
- req->has_client_stats = false;
68
- req->has_initial_request = true;
69
- req->initial_request.has_name = true;
70
- // GCC warns (-Wstringop-truncation) because the destination
71
- // buffer size is identical to max-size, leading to a potential
72
- // char[] with no null terminator. nanopb can handle it fine,
73
- // and parantheses around strncpy silence that compiler warning.
74
- (strncpy(req->initial_request.name, lb_service_name,
75
- GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH));
29
+ namespace grpc_core {
30
+
31
+ grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name,
32
+ upb_arena* arena) {
33
+ grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
34
+ grpc_lb_v1_InitialLoadBalanceRequest* initial_request =
35
+ grpc_lb_v1_LoadBalanceRequest_mutable_initial_request(req, arena);
36
+ size_t name_len =
37
+ GPR_MIN(strlen(lb_service_name), GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH);
38
+ grpc_lb_v1_InitialLoadBalanceRequest_set_name(
39
+ initial_request, upb_strview_make(lb_service_name, name_len));
76
40
  return req;
77
41
  }
78
42
 
79
- static void populate_timestamp(gpr_timespec timestamp,
80
- grpc_grpclb_timestamp* timestamp_pb) {
81
- timestamp_pb->has_seconds = true;
82
- timestamp_pb->seconds = timestamp.tv_sec;
83
- timestamp_pb->has_nanos = true;
84
- timestamp_pb->nanos = timestamp.tv_nsec;
85
- }
43
+ namespace {
86
44
 
87
- static bool encode_string(pb_ostream_t* stream, const pb_field_t* field,
88
- void* const* arg) {
89
- char* str = static_cast<char*>(*arg);
90
- if (!pb_encode_tag_for_field(stream, field)) return false;
91
- return pb_encode_string(stream, reinterpret_cast<uint8_t*>(str), strlen(str));
45
+ void google_protobuf_Timestamp_assign(google_protobuf_Timestamp* timestamp,
46
+ const gpr_timespec& value) {
47
+ google_protobuf_Timestamp_set_seconds(timestamp, value.tv_sec);
48
+ google_protobuf_Timestamp_set_nanos(timestamp, value.tv_nsec);
92
49
  }
93
50
 
94
- static bool encode_drops(pb_ostream_t* stream, const pb_field_t* field,
95
- void* const* arg) {
96
- grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries =
97
- static_cast<grpc_core::GrpcLbClientStats::DroppedCallCounts*>(*arg);
98
- if (drop_entries == nullptr) return true;
99
- for (size_t i = 0; i < drop_entries->size(); ++i) {
100
- if (!pb_encode_tag_for_field(stream, field)) return false;
101
- grpc_lb_v1_ClientStatsPerToken drop_message;
102
- drop_message.load_balance_token.funcs.encode = encode_string;
103
- drop_message.load_balance_token.arg = (*drop_entries)[i].token.get();
104
- drop_message.has_num_calls = true;
105
- drop_message.num_calls = (*drop_entries)[i].count;
106
- if (!pb_encode_submessage(stream, grpc_lb_v1_ClientStatsPerToken_fields,
107
- &drop_message)) {
108
- return false;
109
- }
110
- }
111
- return true;
112
- }
51
+ } // namespace
113
52
 
114
53
  grpc_grpclb_request* grpc_grpclb_load_report_request_create(
115
- grpc_core::GrpcLbClientStats* client_stats) {
116
- grpc_grpclb_request* req = static_cast<grpc_grpclb_request*>(
117
- gpr_zalloc(sizeof(grpc_grpclb_request)));
118
- req->has_client_stats = true;
119
- req->client_stats.has_timestamp = true;
120
- populate_timestamp(gpr_now(GPR_CLOCK_REALTIME), &req->client_stats.timestamp);
121
- req->client_stats.has_num_calls_started = true;
122
- req->client_stats.has_num_calls_finished = true;
123
- req->client_stats.has_num_calls_finished_with_client_failed_to_send = true;
124
- req->client_stats.has_num_calls_finished_with_client_failed_to_send = true;
125
- req->client_stats.has_num_calls_finished_known_received = true;
126
- req->client_stats.calls_finished_with_drop.funcs.encode = encode_drops;
127
- grpc_core::UniquePtr<grpc_core::GrpcLbClientStats::DroppedCallCounts>
128
- drop_counts;
129
- client_stats->Get(
130
- &req->client_stats.num_calls_started,
131
- &req->client_stats.num_calls_finished,
132
- &req->client_stats.num_calls_finished_with_client_failed_to_send,
133
- &req->client_stats.num_calls_finished_known_received, &drop_counts);
134
- // Will be deleted in grpc_grpclb_request_destroy().
135
- req->client_stats.calls_finished_with_drop.arg = drop_counts.release();
54
+ GrpcLbClientStats* client_stats, upb_arena* arena) {
55
+ grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
56
+ grpc_lb_v1_ClientStats* req_stats =
57
+ grpc_lb_v1_LoadBalanceRequest_mutable_client_stats(req, arena);
58
+ google_protobuf_Timestamp_assign(
59
+ grpc_lb_v1_ClientStats_mutable_timestamp(req_stats, arena),
60
+ gpr_now(GPR_CLOCK_REALTIME));
61
+
62
+ int64_t num_calls_started;
63
+ int64_t num_calls_finished;
64
+ int64_t num_calls_finished_with_client_failed_to_send;
65
+ int64_t num_calls_finished_known_received;
66
+ UniquePtr<GrpcLbClientStats::DroppedCallCounts> drop_token_counts;
67
+ client_stats->Get(&num_calls_started, &num_calls_finished,
68
+ &num_calls_finished_with_client_failed_to_send,
69
+ &num_calls_finished_known_received, &drop_token_counts);
70
+ grpc_lb_v1_ClientStats_set_num_calls_started(req_stats, num_calls_started);
71
+ grpc_lb_v1_ClientStats_set_num_calls_finished(req_stats, num_calls_finished);
72
+ grpc_lb_v1_ClientStats_set_num_calls_finished_with_client_failed_to_send(
73
+ req_stats, num_calls_finished_with_client_failed_to_send);
74
+ grpc_lb_v1_ClientStats_set_num_calls_finished_known_received(
75
+ req_stats, num_calls_finished_known_received);
76
+ if (drop_token_counts != nullptr) {
77
+ for (size_t i = 0; i < drop_token_counts->size(); ++i) {
78
+ GrpcLbClientStats::DropTokenCount& cur = (*drop_token_counts)[i];
79
+ grpc_lb_v1_ClientStatsPerToken* cur_msg =
80
+ grpc_lb_v1_ClientStats_add_calls_finished_with_drop(req_stats, arena);
81
+
82
+ const size_t token_len = strlen(cur.token.get());
83
+ char* token = reinterpret_cast<char*>(upb_arena_malloc(arena, token_len));
84
+ memcpy(token, cur.token.get(), token_len);
85
+
86
+ grpc_lb_v1_ClientStatsPerToken_set_load_balance_token(
87
+ cur_msg, upb_strview_make(token, token_len));
88
+ grpc_lb_v1_ClientStatsPerToken_set_num_calls(cur_msg, cur.count);
89
+ }
90
+ }
136
91
  return req;
137
92
  }
138
93
 
139
- grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request) {
140
- size_t encoded_length;
141
- pb_ostream_t sizestream;
142
- pb_ostream_t outputstream;
143
- grpc_slice slice;
144
- memset(&sizestream, 0, sizeof(pb_ostream_t));
145
- pb_encode(&sizestream, grpc_lb_v1_LoadBalanceRequest_fields, request);
146
- encoded_length = sizestream.bytes_written;
147
-
148
- slice = GRPC_SLICE_MALLOC(encoded_length);
149
- outputstream =
150
- pb_ostream_from_buffer(GRPC_SLICE_START_PTR(slice), encoded_length);
151
- GPR_ASSERT(pb_encode(&outputstream, grpc_lb_v1_LoadBalanceRequest_fields,
152
- request) != 0);
153
- return slice;
154
- }
155
-
156
- void grpc_grpclb_request_destroy(grpc_grpclb_request* request) {
157
- if (request->has_client_stats) {
158
- grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries =
159
- static_cast<grpc_core::GrpcLbClientStats::DroppedCallCounts*>(
160
- request->client_stats.calls_finished_with_drop.arg);
161
- grpc_core::Delete(drop_entries);
162
- }
163
- gpr_free(request);
94
+ grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request,
95
+ upb_arena* arena) {
96
+ size_t buf_length;
97
+ char* buf =
98
+ grpc_lb_v1_LoadBalanceRequest_serialize(request, arena, &buf_length);
99
+ return grpc_slice_from_copied_buffer(buf, buf_length);
164
100
  }
165
101
 
166
- typedef grpc_lb_v1_LoadBalanceResponse grpc_grpclb_response;
167
- grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse(
168
- const grpc_slice& encoded_grpc_grpclb_response) {
169
- pb_istream_t stream = pb_istream_from_buffer(
170
- const_cast<uint8_t*>(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
171
- GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response));
172
- grpc_grpclb_response res;
173
- memset(&res, 0, sizeof(grpc_grpclb_response));
174
- if (GPR_UNLIKELY(
175
- !pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res))) {
176
- gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
102
+ const grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse(
103
+ const grpc_slice& encoded_grpc_grpclb_response, upb_arena* arena) {
104
+ grpc_lb_v1_LoadBalanceResponse* response =
105
+ grpc_lb_v1_LoadBalanceResponse_parse(
106
+ reinterpret_cast<const char*>(
107
+ GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
108
+ GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena);
109
+ if (response == nullptr) {
110
+ gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error");
177
111
  return nullptr;
178
112
  }
179
-
180
- if (!res.has_initial_response) return nullptr;
181
-
182
- grpc_grpclb_initial_response* initial_res =
183
- static_cast<grpc_grpclb_initial_response*>(
184
- gpr_malloc(sizeof(grpc_grpclb_initial_response)));
185
- memcpy(initial_res, &res.initial_response,
186
- sizeof(grpc_grpclb_initial_response));
187
-
188
- return initial_res;
113
+ return grpc_lb_v1_LoadBalanceResponse_initial_response(response);
189
114
  }
190
115
 
191
116
  grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist(
192
117
  const grpc_slice& encoded_grpc_grpclb_response) {
193
- pb_istream_t stream = pb_istream_from_buffer(
194
- const_cast<uint8_t*>(GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
195
- GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response));
196
- pb_istream_t stream_at_start = stream;
197
- grpc_grpclb_serverlist* sl = static_cast<grpc_grpclb_serverlist*>(
118
+ upb::Arena arena;
119
+ grpc_lb_v1_LoadBalanceResponse* response =
120
+ grpc_lb_v1_LoadBalanceResponse_parse(
121
+ reinterpret_cast<const char*>(
122
+ GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
123
+ GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena.ptr());
124
+ if (response == nullptr) {
125
+ gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error");
126
+ return nullptr;
127
+ }
128
+ grpc_grpclb_serverlist* server_list = static_cast<grpc_grpclb_serverlist*>(
198
129
  gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
199
- grpc_grpclb_response res;
200
- memset(&res, 0, sizeof(grpc_grpclb_response));
201
130
  // First pass: count number of servers.
202
- res.server_list.servers.funcs.decode = count_serverlist;
203
- res.server_list.servers.arg = sl;
204
- bool status = pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res);
205
- if (GPR_UNLIKELY(!status)) {
206
- gpr_free(sl);
207
- gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
208
- return nullptr;
131
+ const grpc_lb_v1_ServerList* server_list_msg =
132
+ grpc_lb_v1_LoadBalanceResponse_server_list(response);
133
+ size_t server_count = 0;
134
+ const grpc_lb_v1_Server* const* servers = nullptr;
135
+ if (server_list_msg != nullptr) {
136
+ servers = grpc_lb_v1_ServerList_servers(server_list_msg, &server_count);
209
137
  }
210
138
  // Second pass: populate servers.
211
- if (sl->num_servers > 0) {
212
- sl->servers = static_cast<grpc_grpclb_server**>(
213
- gpr_zalloc(sizeof(grpc_grpclb_server*) * sl->num_servers));
214
- decode_serverlist_arg decode_arg;
215
- memset(&decode_arg, 0, sizeof(decode_arg));
216
- decode_arg.serverlist = sl;
217
- res.server_list.servers.funcs.decode = decode_serverlist;
218
- res.server_list.servers.arg = &decode_arg;
219
- status = pb_decode(&stream_at_start, grpc_lb_v1_LoadBalanceResponse_fields,
220
- &res);
221
- if (GPR_UNLIKELY(!status)) {
222
- grpc_grpclb_destroy_serverlist(sl);
223
- gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
224
- return nullptr;
139
+ if (server_count > 0) {
140
+ server_list->servers = static_cast<grpc_grpclb_server**>(
141
+ gpr_zalloc(sizeof(grpc_grpclb_server*) * server_count));
142
+ server_list->num_servers = server_count;
143
+ for (size_t i = 0; i < server_count; ++i) {
144
+ grpc_grpclb_server* cur = server_list->servers[i] =
145
+ static_cast<grpc_grpclb_server*>(
146
+ gpr_zalloc(sizeof(grpc_grpclb_server)));
147
+ upb_strview address = grpc_lb_v1_Server_ip_address(servers[i]);
148
+ if (address.size == 0) {
149
+ ; // Nothing to do because cur->ip_address is an empty string.
150
+ } else if (address.size <= GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE) {
151
+ cur->ip_address.size = static_cast<int32_t>(address.size);
152
+ memcpy(cur->ip_address.data, address.data, address.size);
153
+ }
154
+ cur->port = grpc_lb_v1_Server_port(servers[i]);
155
+ upb_strview token = grpc_lb_v1_Server_load_balance_token(servers[i]);
156
+ if (token.size == 0) {
157
+ ; // Nothing to do because cur->load_balance_token is an empty string.
158
+ } else if (token.size <= GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE) {
159
+ memcpy(cur->load_balance_token, token.data, token.size);
160
+ } else {
161
+ gpr_log(GPR_ERROR,
162
+ "grpc_lb_v1_LoadBalanceResponse has too long token. len=%zu",
163
+ token.size);
164
+ }
165
+ cur->drop = grpc_lb_v1_Server_drop(servers[i]);
225
166
  }
226
167
  }
227
- return sl;
168
+ return server_list;
228
169
  }
229
170
 
230
171
  void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) {
@@ -239,16 +180,17 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) {
239
180
  }
240
181
 
241
182
  grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy(
242
- const grpc_grpclb_serverlist* sl) {
183
+ const grpc_grpclb_serverlist* server_list) {
243
184
  grpc_grpclb_serverlist* copy = static_cast<grpc_grpclb_serverlist*>(
244
185
  gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
245
- copy->num_servers = sl->num_servers;
186
+ copy->num_servers = server_list->num_servers;
246
187
  copy->servers = static_cast<grpc_grpclb_server**>(
247
- gpr_malloc(sizeof(grpc_grpclb_server*) * sl->num_servers));
248
- for (size_t i = 0; i < sl->num_servers; i++) {
188
+ gpr_malloc(sizeof(grpc_grpclb_server*) * server_list->num_servers));
189
+ for (size_t i = 0; i < server_list->num_servers; i++) {
249
190
  copy->servers[i] = static_cast<grpc_grpclb_server*>(
250
191
  gpr_malloc(sizeof(grpc_grpclb_server)));
251
- memcpy(copy->servers[i], sl->servers[i], sizeof(grpc_grpclb_server));
192
+ memcpy(copy->servers[i], server_list->servers[i],
193
+ sizeof(grpc_grpclb_server));
252
194
  }
253
195
  return copy;
254
196
  }
@@ -274,38 +216,11 @@ bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs,
274
216
  return memcmp(lhs, rhs, sizeof(grpc_grpclb_server)) == 0;
275
217
  }
276
218
 
277
- int grpc_grpclb_duration_compare(const grpc_grpclb_duration* lhs,
278
- const grpc_grpclb_duration* rhs) {
279
- GPR_ASSERT(lhs && rhs);
280
- if (lhs->has_seconds && rhs->has_seconds) {
281
- if (lhs->seconds < rhs->seconds) return -1;
282
- if (lhs->seconds > rhs->seconds) return 1;
283
- } else if (lhs->has_seconds) {
284
- return 1;
285
- } else if (rhs->has_seconds) {
286
- return -1;
287
- }
288
-
289
- GPR_ASSERT(lhs->seconds == rhs->seconds);
290
- if (lhs->has_nanos && rhs->has_nanos) {
291
- if (lhs->nanos < rhs->nanos) return -1;
292
- if (lhs->nanos > rhs->nanos) return 1;
293
- } else if (lhs->has_nanos) {
294
- return 1;
295
- } else if (rhs->has_nanos) {
296
- return -1;
297
- }
298
-
299
- return 0;
300
- }
301
-
302
- grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb) {
219
+ grpc_millis grpc_grpclb_duration_to_millis(
220
+ const grpc_grpclb_duration* duration_pb) {
303
221
  return static_cast<grpc_millis>(
304
- (duration_pb->has_seconds ? duration_pb->seconds : 0) * GPR_MS_PER_SEC +
305
- (duration_pb->has_nanos ? duration_pb->nanos : 0) / GPR_NS_PER_MS);
222
+ google_protobuf_Duration_seconds(duration_pb) * GPR_MS_PER_SEC +
223
+ google_protobuf_Duration_nanos(duration_pb) / GPR_NS_PER_MS);
306
224
  }
307
225
 
308
- void grpc_grpclb_initial_response_destroy(
309
- grpc_grpclb_initial_response* response) {
310
- gpr_free(response);
311
- }
226
+ } // namespace grpc_core