grpc 1.1.2 → 1.2.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 (255) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1257 -404
  3. data/etc/roots.pem +189 -102
  4. data/include/grpc/census.h +7 -7
  5. data/include/grpc/compression.h +4 -4
  6. data/include/grpc/grpc.h +13 -7
  7. data/include/grpc/impl/codegen/atm_gcc_atomic.h +26 -9
  8. data/include/grpc/impl/codegen/grpc_types.h +39 -30
  9. data/include/grpc/impl/codegen/slice.h +24 -6
  10. data/include/grpc/impl/codegen/sync.h +8 -0
  11. data/include/grpc/load_reporting.h +63 -0
  12. data/include/grpc/slice.h +37 -1
  13. data/include/grpc/slice_buffer.h +7 -0
  14. data/include/grpc/support/alloc.h +3 -0
  15. data/include/grpc/support/useful.h +3 -0
  16. data/src/core/ext/census/gen/census.pb.h +1 -1
  17. data/src/core/ext/census/gen/trace_context.pb.c +9 -36
  18. data/src/core/ext/census/gen/trace_context.pb.h +20 -26
  19. data/src/core/ext/census/grpc_filter.c +3 -5
  20. data/src/core/ext/census/trace_context.c +1 -1
  21. data/src/core/ext/census/trace_context.h +3 -0
  22. data/src/core/ext/census/trace_label.h +61 -0
  23. data/src/core/ext/census/trace_propagation.h +63 -0
  24. data/src/core/ext/census/trace_status.h +45 -0
  25. data/src/core/ext/census/trace_string.h +50 -0
  26. data/src/core/ext/census/tracing.c +31 -11
  27. data/src/core/ext/census/tracing.h +124 -0
  28. data/src/core/ext/client_channel/client_channel.c +456 -368
  29. data/src/core/ext/client_channel/client_channel.h +4 -0
  30. data/src/core/ext/client_channel/client_channel_plugin.c +6 -1
  31. data/src/core/ext/client_channel/connector.c +3 -3
  32. data/src/core/ext/client_channel/connector.h +4 -3
  33. data/src/core/ext/client_channel/http_connect_handshaker.c +62 -72
  34. data/src/core/ext/client_channel/http_connect_handshaker.h +7 -10
  35. data/src/core/ext/client_channel/http_proxy.c +125 -0
  36. data/src/core/ext/client_channel/http_proxy.h +39 -0
  37. data/src/core/ext/client_channel/lb_policy.c +56 -35
  38. data/src/core/ext/client_channel/lb_policy.h +46 -39
  39. data/src/core/ext/client_channel/lb_policy_factory.h +1 -0
  40. data/src/core/ext/client_channel/parse_address.c +32 -6
  41. data/src/core/ext/client_channel/proxy_mapper.c +63 -0
  42. data/src/core/ext/client_channel/proxy_mapper.h +89 -0
  43. data/src/core/ext/client_channel/proxy_mapper_registry.c +133 -0
  44. data/src/core/ext/client_channel/proxy_mapper_registry.h +59 -0
  45. data/src/core/ext/client_channel/resolver.c +16 -9
  46. data/src/core/ext/client_channel/resolver.h +23 -12
  47. data/src/core/ext/client_channel/resolver_factory.h +1 -0
  48. data/src/core/ext/client_channel/resolver_registry.c +15 -11
  49. data/src/core/ext/client_channel/resolver_registry.h +5 -3
  50. data/src/core/ext/client_channel/subchannel.c +44 -27
  51. data/src/core/ext/client_channel/subchannel.h +6 -2
  52. data/src/core/ext/client_channel/uri_parser.c +26 -14
  53. data/src/core/ext/client_channel/uri_parser.h +3 -1
  54. data/src/core/ext/lb_policy/grpclb/grpclb.c +220 -209
  55. data/src/core/ext/lb_policy/grpclb/grpclb_channel.h +56 -0
  56. data/src/core/ext/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
  57. data/src/core/ext/lb_policy/grpclb/load_balancer_api.c +3 -6
  58. data/src/core/ext/lb_policy/pick_first/pick_first.c +71 -116
  59. data/src/core/ext/lb_policy/round_robin/round_robin.c +52 -67
  60. data/src/core/ext/load_reporting/load_reporting.c +20 -0
  61. data/src/core/ext/load_reporting/load_reporting.h +1 -16
  62. data/src/core/ext/load_reporting/load_reporting_filter.c +28 -54
  63. data/src/core/ext/resolver/dns/native/dns_resolver.c +31 -45
  64. data/src/core/ext/resolver/sockaddr/sockaddr_resolver.c +20 -29
  65. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +11 -8
  66. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +11 -2
  67. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +143 -46
  68. data/src/core/ext/transport/chttp2/server/chttp2_server.c +12 -50
  69. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +1 -1
  70. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +1 -1
  71. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +7 -7
  72. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +1 -2
  73. data/src/core/ext/transport/chttp2/transport/bin_encoder.h +1 -2
  74. data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +0 -3
  75. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +606 -374
  76. data/src/core/ext/transport/chttp2/transport/frame_ping.c +17 -5
  77. data/src/core/ext/transport/chttp2/transport/frame_ping.h +2 -2
  78. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +9 -13
  79. data/src/core/ext/transport/chttp2/transport/frame_settings.c +12 -11
  80. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -1
  81. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +5 -6
  82. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +100 -53
  83. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +2 -2
  84. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +126 -70
  85. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +13 -7
  86. data/src/core/ext/transport/chttp2/transport/hpack_table.c +22 -19
  87. data/src/core/ext/transport/chttp2/transport/hpack_table.h +6 -6
  88. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +23 -11
  89. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +6 -2
  90. data/src/core/ext/transport/chttp2/transport/internal.h +169 -42
  91. data/src/core/ext/transport/chttp2/transport/parsing.c +98 -41
  92. data/src/core/ext/transport/chttp2/transport/stream_lists.c +29 -14
  93. data/src/core/ext/transport/chttp2/transport/writing.c +137 -15
  94. data/src/core/lib/channel/channel_stack.c +14 -44
  95. data/src/core/lib/channel/channel_stack.h +10 -17
  96. data/src/core/lib/channel/channel_stack_builder.c +2 -3
  97. data/src/core/lib/channel/compress_filter.c +54 -46
  98. data/src/core/lib/channel/connected_channel.c +4 -4
  99. data/src/core/lib/channel/connected_channel.h +5 -0
  100. data/src/core/lib/channel/context.h +3 -0
  101. data/src/core/lib/channel/deadline_filter.c +61 -61
  102. data/src/core/lib/channel/deadline_filter.h +8 -5
  103. data/src/core/lib/channel/handshaker.c +47 -7
  104. data/src/core/lib/channel/handshaker.h +21 -3
  105. data/src/core/lib/channel/http_client_filter.c +149 -99
  106. data/src/core/lib/channel/http_server_filter.c +163 -147
  107. data/src/core/lib/channel/message_size_filter.c +15 -10
  108. data/src/core/lib/compression/algorithm_metadata.h +4 -4
  109. data/src/core/lib/compression/compression.c +17 -23
  110. data/src/core/lib/http/httpcli.c +3 -2
  111. data/src/core/lib/http/httpcli.h +2 -1
  112. data/src/core/lib/http/httpcli_security_connector.c +2 -3
  113. data/src/core/lib/http/parser.c +2 -2
  114. data/src/core/lib/iomgr/closure.c +6 -3
  115. data/src/core/lib/iomgr/closure.h +4 -2
  116. data/src/core/lib/iomgr/combiner.c +35 -5
  117. data/src/core/lib/iomgr/combiner.h +21 -2
  118. data/src/core/lib/iomgr/endpoint.c +3 -2
  119. data/src/core/lib/iomgr/endpoint.h +3 -2
  120. data/src/core/lib/iomgr/error.c +60 -94
  121. data/src/core/lib/iomgr/error.h +7 -10
  122. data/src/core/lib/iomgr/error_internal.h +54 -0
  123. data/src/core/lib/iomgr/ev_epoll_linux.c +253 -109
  124. data/src/core/lib/iomgr/ev_poll_posix.c +61 -29
  125. data/src/core/lib/iomgr/ev_posix.c +7 -8
  126. data/src/core/lib/iomgr/ev_posix.h +4 -4
  127. data/src/core/lib/iomgr/exec_ctx.c +11 -6
  128. data/src/core/lib/iomgr/exec_ctx.h +11 -14
  129. data/src/core/lib/iomgr/executor.c +2 -2
  130. data/src/core/lib/iomgr/load_file.c +1 -1
  131. data/src/core/lib/iomgr/network_status_tracker.c +5 -81
  132. data/src/core/lib/iomgr/pollset.h +1 -3
  133. data/src/core/lib/iomgr/pollset_set.h +2 -1
  134. data/src/core/lib/iomgr/pollset_set_uv.c +2 -1
  135. data/src/core/lib/iomgr/pollset_set_windows.c +2 -1
  136. data/src/core/lib/iomgr/pollset_uv.c +25 -11
  137. data/src/core/lib/iomgr/pollset_windows.c +0 -11
  138. data/src/core/lib/iomgr/resolve_address_uv.c +50 -2
  139. data/src/core/lib/iomgr/resource_quota.c +41 -11
  140. data/src/core/lib/iomgr/resource_quota.h +6 -0
  141. data/src/core/lib/iomgr/sockaddr_utils.c +33 -17
  142. data/src/core/lib/iomgr/sockaddr_utils.h +4 -0
  143. data/src/core/lib/iomgr/tcp_client_posix.c +2 -3
  144. data/src/core/lib/iomgr/tcp_client_uv.c +1 -3
  145. data/src/core/lib/iomgr/tcp_client_windows.c +21 -6
  146. data/src/core/lib/iomgr/tcp_posix.c +4 -5
  147. data/src/core/lib/iomgr/tcp_server_posix.c +269 -94
  148. data/src/core/lib/iomgr/tcp_server_windows.c +1 -1
  149. data/src/core/lib/iomgr/tcp_uv.c +11 -5
  150. data/src/core/lib/iomgr/tcp_windows.c +20 -7
  151. data/src/core/lib/iomgr/timer_generic.c +15 -22
  152. data/src/core/lib/iomgr/timer_generic.h +1 -1
  153. data/src/core/lib/iomgr/timer_uv.c +10 -6
  154. data/src/core/lib/iomgr/timer_uv.h +1 -1
  155. data/src/core/lib/iomgr/udp_server.c +45 -6
  156. data/src/core/lib/iomgr/udp_server.h +7 -1
  157. data/src/core/lib/iomgr/unix_sockets_posix.c +11 -1
  158. data/src/core/lib/json/json.c +1 -2
  159. data/src/core/lib/profiling/basic_timers.c +17 -3
  160. data/src/core/lib/security/context/security_context.c +3 -10
  161. data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -8
  162. data/src/core/lib/security/credentials/credentials.c +48 -2
  163. data/src/core/lib/security/credentials/credentials.h +13 -0
  164. data/src/core/lib/security/credentials/credentials_metadata.c +1 -2
  165. data/src/core/lib/security/credentials/fake/fake_credentials.c +6 -8
  166. data/src/core/lib/security/credentials/fake/fake_credentials.h +15 -0
  167. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +3 -3
  168. data/src/core/lib/security/credentials/iam/iam_credentials.c +1 -2
  169. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -2
  170. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +5 -8
  171. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +2 -1
  172. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +3 -5
  173. data/src/core/lib/security/credentials/plugin/plugin_credentials.c +15 -13
  174. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +2 -4
  175. data/src/core/lib/security/transport/client_auth_filter.c +72 -47
  176. data/src/core/lib/security/transport/lb_targets_info.c +70 -0
  177. data/src/core/lib/security/transport/lb_targets_info.h +47 -0
  178. data/src/core/lib/security/transport/secure_endpoint.c +3 -3
  179. data/src/core/lib/security/transport/security_connector.c +125 -28
  180. data/src/core/lib/security/transport/security_connector.h +4 -3
  181. data/src/core/lib/security/transport/security_handshaker.c +13 -9
  182. data/src/core/lib/security/transport/server_auth_filter.c +31 -40
  183. data/src/core/lib/security/util/b64.c +1 -1
  184. data/src/core/lib/slice/slice.c +110 -20
  185. data/src/core/lib/slice/slice_buffer.c +92 -39
  186. data/src/core/lib/{transport/mdstr_hash_table.c → slice/slice_hash_table.c} +40 -33
  187. data/src/core/lib/{transport/mdstr_hash_table.h → slice/slice_hash_table.h} +21 -21
  188. data/src/core/lib/slice/slice_intern.c +346 -0
  189. data/src/core/lib/slice/slice_internal.h +15 -0
  190. data/src/core/lib/slice/slice_string_helpers.c +5 -0
  191. data/src/core/lib/slice/slice_string_helpers.h +5 -0
  192. data/src/core/lib/support/alloc.c +26 -1
  193. data/src/core/lib/support/cmdline.c +2 -4
  194. data/src/core/lib/support/cpu_posix.c +2 -7
  195. data/src/core/lib/support/histogram.c +1 -2
  196. data/src/core/lib/support/log_posix.c +8 -4
  197. data/src/core/lib/support/spinlock.h +52 -0
  198. data/src/core/lib/support/subprocess_posix.c +1 -2
  199. data/src/core/lib/support/sync.c +7 -1
  200. data/src/core/lib/support/sync_posix.c +9 -0
  201. data/src/core/lib/support/time_windows.c +7 -1
  202. data/src/core/lib/surface/call.c +647 -629
  203. data/src/core/lib/surface/call.h +4 -1
  204. data/src/core/lib/surface/call_details.c +8 -2
  205. data/src/core/lib/surface/call_log_batch.c +17 -6
  206. data/src/core/lib/surface/channel.c +49 -59
  207. data/src/core/lib/surface/channel.h +5 -6
  208. data/src/core/lib/surface/completion_queue.c +16 -45
  209. data/src/core/lib/surface/completion_queue.h +0 -3
  210. data/src/core/lib/surface/init.c +6 -2
  211. data/src/core/lib/surface/init_secure.c +1 -1
  212. data/src/core/lib/surface/lame_client.c +14 -4
  213. data/src/core/lib/surface/server.c +79 -82
  214. data/src/core/lib/surface/validate_metadata.c +46 -15
  215. data/src/core/lib/surface/validate_metadata.h +43 -0
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.c +104 -0
  218. data/src/core/lib/transport/bdp_estimator.h +76 -0
  219. data/src/core/lib/transport/connectivity_state.c +33 -13
  220. data/src/core/lib/transport/connectivity_state.h +15 -5
  221. data/src/core/lib/transport/error_utils.c +124 -0
  222. data/src/core/lib/transport/error_utils.h +56 -0
  223. data/src/core/{ext/transport/chttp2 → lib}/transport/http2_errors.h +18 -18
  224. data/src/core/lib/transport/metadata.c +259 -503
  225. data/src/core/lib/transport/metadata.h +69 -68
  226. data/src/core/lib/transport/metadata_batch.c +183 -63
  227. data/src/core/lib/transport/metadata_batch.h +50 -26
  228. data/src/core/lib/transport/pid_controller.c +28 -8
  229. data/src/core/lib/transport/pid_controller.h +15 -2
  230. data/src/core/lib/transport/service_config.c +21 -18
  231. data/src/core/lib/transport/service_config.h +5 -5
  232. data/src/core/lib/transport/static_metadata.c +753 -112
  233. data/src/core/lib/transport/static_metadata.h +403 -264
  234. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.c +18 -20
  235. data/src/core/{ext/transport/chttp2 → lib}/transport/status_conversion.h +9 -10
  236. data/src/core/lib/transport/timeout_encoding.c +11 -9
  237. data/src/core/lib/transport/timeout_encoding.h +3 -1
  238. data/src/core/lib/transport/transport.c +47 -87
  239. data/src/core/lib/transport/transport.h +20 -25
  240. data/src/core/lib/transport/transport_op_string.c +7 -19
  241. data/src/core/lib/tsi/fake_transport_security.c +2 -4
  242. data/src/core/lib/tsi/ssl_transport_security.c +7 -16
  243. data/src/core/lib/tsi/transport_security.c +2 -4
  244. data/src/ruby/ext/grpc/extconf.rb +4 -1
  245. data/src/ruby/ext/grpc/rb_byte_buffer.c +7 -0
  246. data/src/ruby/ext/grpc/rb_byte_buffer.h +3 -0
  247. data/src/ruby/ext/grpc/rb_call.c +47 -46
  248. data/src/ruby/ext/grpc/rb_channel.c +21 -6
  249. data/src/ruby/ext/grpc/rb_compression_options.c +9 -6
  250. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +36 -2
  251. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +59 -8
  252. data/src/ruby/ext/grpc/rb_server.c +6 -4
  253. data/src/ruby/lib/grpc/generic/client_stub.rb +1 -1
  254. data/src/ruby/lib/grpc/version.rb +1 -1
  255. metadata +33 -9
@@ -0,0 +1,39 @@
1
+ /*
2
+ *
3
+ * Copyright 2016, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #ifndef GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H
35
+ #define GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H
36
+
37
+ void grpc_register_http_proxy_mapper();
38
+
39
+ #endif /* GRPC_CORE_EXT_CLIENT_CHANNEL_HTTP_PROXY_H */
@@ -32,14 +32,17 @@
32
32
  */
33
33
 
34
34
  #include "src/core/ext/client_channel/lb_policy.h"
35
+ #include "src/core/lib/iomgr/combiner.h"
35
36
 
36
37
  #define WEAK_REF_BITS 16
37
38
 
38
39
  void grpc_lb_policy_init(grpc_lb_policy *policy,
39
- const grpc_lb_policy_vtable *vtable) {
40
+ const grpc_lb_policy_vtable *vtable,
41
+ grpc_combiner *combiner) {
40
42
  policy->vtable = vtable;
41
43
  gpr_atm_no_barrier_store(&policy->ref_pair, 1 << WEAK_REF_BITS);
42
44
  policy->interested_parties = grpc_pollset_set_create();
45
+ policy->combiner = GRPC_COMBINER_REF(combiner, "lb_policy");
43
46
  }
44
47
 
45
48
  #ifdef GRPC_LB_POLICY_REFCOUNT_DEBUG
@@ -71,6 +74,13 @@ void grpc_lb_policy_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) {
71
74
  ref_mutate(policy, 1 << WEAK_REF_BITS, 0 REF_MUTATE_PASS_ARGS("STRONG_REF"));
72
75
  }
73
76
 
77
+ static void shutdown_locked(grpc_exec_ctx *exec_ctx, void *arg,
78
+ grpc_error *error) {
79
+ grpc_lb_policy *policy = arg;
80
+ policy->vtable->shutdown_locked(exec_ctx, policy);
81
+ GRPC_LB_POLICY_WEAK_UNREF(exec_ctx, policy, "strong-unref");
82
+ }
83
+
74
84
  void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx,
75
85
  grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) {
76
86
  gpr_atm old_val =
@@ -79,10 +89,15 @@ void grpc_lb_policy_unref(grpc_exec_ctx *exec_ctx,
79
89
  gpr_atm mask = ~(gpr_atm)((1 << WEAK_REF_BITS) - 1);
80
90
  gpr_atm check = 1 << WEAK_REF_BITS;
81
91
  if ((old_val & mask) == check) {
82
- policy->vtable->shutdown(exec_ctx, policy);
92
+ grpc_closure_sched(
93
+ exec_ctx,
94
+ grpc_closure_create(shutdown_locked, policy,
95
+ grpc_combiner_scheduler(policy->combiner, false)),
96
+ GRPC_ERROR_NONE);
97
+ } else {
98
+ grpc_lb_policy_weak_unref(exec_ctx,
99
+ policy REF_FUNC_PASS_ARGS("strong-unref"));
83
100
  }
84
- grpc_lb_policy_weak_unref(exec_ctx,
85
- policy REF_FUNC_PASS_ARGS("strong-unref"));
86
101
  }
87
102
 
88
103
  void grpc_lb_policy_weak_ref(grpc_lb_policy *policy REF_FUNC_EXTRA_ARGS) {
@@ -94,53 +109,59 @@ void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx,
94
109
  gpr_atm old_val =
95
110
  ref_mutate(policy, -(gpr_atm)1, 1 REF_MUTATE_PASS_ARGS("WEAK_UNREF"));
96
111
  if (old_val == 1) {
97
- grpc_pollset_set_destroy(policy->interested_parties);
112
+ grpc_pollset_set_destroy(exec_ctx, policy->interested_parties);
113
+ grpc_combiner *combiner = policy->combiner;
98
114
  policy->vtable->destroy(exec_ctx, policy);
115
+ GRPC_COMBINER_UNREF(exec_ctx, combiner, "lb_policy");
99
116
  }
100
117
  }
101
118
 
102
- int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
103
- const grpc_lb_policy_pick_args *pick_args,
104
- grpc_connected_subchannel **target, void **user_data,
105
- grpc_closure *on_complete) {
106
- return policy->vtable->pick(exec_ctx, policy, pick_args, target, user_data,
107
- on_complete);
119
+ int grpc_lb_policy_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
120
+ const grpc_lb_policy_pick_args *pick_args,
121
+ grpc_connected_subchannel **target,
122
+ void **user_data, grpc_closure *on_complete) {
123
+ return policy->vtable->pick_locked(exec_ctx, policy, pick_args, target,
124
+ user_data, on_complete);
108
125
  }
109
126
 
110
- void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
111
- grpc_connected_subchannel **target,
112
- grpc_error *error) {
113
- policy->vtable->cancel_pick(exec_ctx, policy, target, error);
127
+ void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx *exec_ctx,
128
+ grpc_lb_policy *policy,
129
+ grpc_connected_subchannel **target,
130
+ grpc_error *error) {
131
+ policy->vtable->cancel_pick_locked(exec_ctx, policy, target, error);
114
132
  }
115
133
 
116
- void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx,
117
- grpc_lb_policy *policy,
118
- uint32_t initial_metadata_flags_mask,
119
- uint32_t initial_metadata_flags_eq,
120
- grpc_error *error) {
121
- policy->vtable->cancel_picks(exec_ctx, policy, initial_metadata_flags_mask,
122
- initial_metadata_flags_eq, error);
134
+ void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx *exec_ctx,
135
+ grpc_lb_policy *policy,
136
+ uint32_t initial_metadata_flags_mask,
137
+ uint32_t initial_metadata_flags_eq,
138
+ grpc_error *error) {
139
+ policy->vtable->cancel_picks_locked(exec_ctx, policy,
140
+ initial_metadata_flags_mask,
141
+ initial_metadata_flags_eq, error);
123
142
  }
124
143
 
125
- void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy) {
126
- policy->vtable->exit_idle(exec_ctx, policy);
144
+ void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx *exec_ctx,
145
+ grpc_lb_policy *policy) {
146
+ policy->vtable->exit_idle_locked(exec_ctx, policy);
127
147
  }
128
148
 
129
- void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
130
- grpc_closure *closure) {
131
- policy->vtable->ping_one(exec_ctx, policy, closure);
149
+ void grpc_lb_policy_ping_one_locked(grpc_exec_ctx *exec_ctx,
150
+ grpc_lb_policy *policy,
151
+ grpc_closure *closure) {
152
+ policy->vtable->ping_one_locked(exec_ctx, policy, closure);
132
153
  }
133
154
 
134
- void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx,
135
- grpc_lb_policy *policy,
136
- grpc_connectivity_state *state,
137
- grpc_closure *closure) {
138
- policy->vtable->notify_on_state_change(exec_ctx, policy, state, closure);
155
+ void grpc_lb_policy_notify_on_state_change_locked(
156
+ grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
157
+ grpc_connectivity_state *state, grpc_closure *closure) {
158
+ policy->vtable->notify_on_state_change_locked(exec_ctx, policy, state,
159
+ closure);
139
160
  }
140
161
 
141
- grpc_connectivity_state grpc_lb_policy_check_connectivity(
162
+ grpc_connectivity_state grpc_lb_policy_check_connectivity_locked(
142
163
  grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
143
164
  grpc_error **connectivity_error) {
144
- return policy->vtable->check_connectivity(exec_ctx, policy,
145
- connectivity_error);
165
+ return policy->vtable->check_connectivity_locked(exec_ctx, policy,
166
+ connectivity_error);
146
167
  }
@@ -51,6 +51,8 @@ struct grpc_lb_policy {
51
51
  gpr_atm ref_pair;
52
52
  /* owned pointer to interested parties in load balancing decisions */
53
53
  grpc_pollset_set *interested_parties;
54
+ /* combiner under which lb_policy actions take place */
55
+ grpc_combiner *combiner;
54
56
  };
55
57
 
56
58
  /** Extra arguments for an LB pick */
@@ -69,42 +71,44 @@ typedef struct grpc_lb_policy_pick_args {
69
71
 
70
72
  struct grpc_lb_policy_vtable {
71
73
  void (*destroy)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
72
- void (*shutdown)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
74
+ void (*shutdown_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
73
75
 
74
76
  /** \see grpc_lb_policy_pick */
75
- int (*pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
76
- const grpc_lb_policy_pick_args *pick_args,
77
- grpc_connected_subchannel **target, void **user_data,
78
- grpc_closure *on_complete);
77
+ int (*pick_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
78
+ const grpc_lb_policy_pick_args *pick_args,
79
+ grpc_connected_subchannel **target, void **user_data,
80
+ grpc_closure *on_complete);
79
81
 
80
82
  /** \see grpc_lb_policy_cancel_pick */
81
- void (*cancel_pick)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
82
- grpc_connected_subchannel **target, grpc_error *error);
83
+ void (*cancel_pick_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
84
+ grpc_connected_subchannel **target,
85
+ grpc_error *error);
83
86
 
84
87
  /** \see grpc_lb_policy_cancel_picks */
85
- void (*cancel_picks)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
86
- uint32_t initial_metadata_flags_mask,
87
- uint32_t initial_metadata_flags_eq, grpc_error *error);
88
+ void (*cancel_picks_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
89
+ uint32_t initial_metadata_flags_mask,
90
+ uint32_t initial_metadata_flags_eq,
91
+ grpc_error *error);
88
92
 
89
93
  /** \see grpc_lb_policy_ping_one */
90
- void (*ping_one)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
91
- grpc_closure *closure);
94
+ void (*ping_one_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
95
+ grpc_closure *closure);
92
96
 
93
97
  /** Try to enter a READY connectivity state */
94
- void (*exit_idle)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
98
+ void (*exit_idle_locked)(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
95
99
 
96
100
  /** check the current connectivity of the lb_policy */
97
- grpc_connectivity_state (*check_connectivity)(
101
+ grpc_connectivity_state (*check_connectivity_locked)(
98
102
  grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
99
103
  grpc_error **connectivity_error);
100
104
 
101
105
  /** call notify when the connectivity state of a channel changes from *state.
102
106
  Updates *state with the new state of the policy. Calling with a NULL \a
103
107
  state cancels the subscription. */
104
- void (*notify_on_state_change)(grpc_exec_ctx *exec_ctx,
105
- grpc_lb_policy *policy,
106
- grpc_connectivity_state *state,
107
- grpc_closure *closure);
108
+ void (*notify_on_state_change_locked)(grpc_exec_ctx *exec_ctx,
109
+ grpc_lb_policy *policy,
110
+ grpc_connectivity_state *state,
111
+ grpc_closure *closure);
108
112
  };
109
113
 
110
114
  /*#define GRPC_LB_POLICY_REFCOUNT_DEBUG*/
@@ -144,7 +148,8 @@ void grpc_lb_policy_weak_unref(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
144
148
 
145
149
  /** called by concrete implementations to initialize the base struct */
146
150
  void grpc_lb_policy_init(grpc_lb_policy *policy,
147
- const grpc_lb_policy_vtable *vtable);
151
+ const grpc_lb_policy_vtable *vtable,
152
+ grpc_combiner *combiner);
148
153
 
149
154
  /** Finds an appropriate subchannel for a call, based on \a pick_args.
150
155
 
@@ -159,43 +164,45 @@ void grpc_lb_policy_init(grpc_lb_policy *policy,
159
164
 
160
165
  Any IO should be done under the \a interested_parties \a grpc_pollset_set
161
166
  in the \a grpc_lb_policy struct. */
162
- int grpc_lb_policy_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
163
- const grpc_lb_policy_pick_args *pick_args,
164
- grpc_connected_subchannel **target, void **user_data,
165
- grpc_closure *on_complete);
167
+ int grpc_lb_policy_pick_locked(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
168
+ const grpc_lb_policy_pick_args *pick_args,
169
+ grpc_connected_subchannel **target,
170
+ void **user_data, grpc_closure *on_complete);
166
171
 
167
172
  /** Perform a connected subchannel ping (see \a grpc_connected_subchannel_ping)
168
173
  against one of the connected subchannels managed by \a policy. */
169
- void grpc_lb_policy_ping_one(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
170
- grpc_closure *closure);
174
+ void grpc_lb_policy_ping_one_locked(grpc_exec_ctx *exec_ctx,
175
+ grpc_lb_policy *policy,
176
+ grpc_closure *closure);
171
177
 
172
178
  /** Cancel picks for \a target.
173
179
  The \a on_complete callback of the pending picks will be invoked with \a
174
180
  *target set to NULL. */
175
- void grpc_lb_policy_cancel_pick(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
176
- grpc_connected_subchannel **target,
177
- grpc_error *error);
181
+ void grpc_lb_policy_cancel_pick_locked(grpc_exec_ctx *exec_ctx,
182
+ grpc_lb_policy *policy,
183
+ grpc_connected_subchannel **target,
184
+ grpc_error *error);
178
185
 
179
186
  /** Cancel all pending picks for which their \a initial_metadata_flags (as given
180
187
  in the call to \a grpc_lb_policy_pick) matches \a initial_metadata_flags_eq
181
188
  when AND'd with \a initial_metadata_flags_mask */
182
- void grpc_lb_policy_cancel_picks(grpc_exec_ctx *exec_ctx,
183
- grpc_lb_policy *policy,
184
- uint32_t initial_metadata_flags_mask,
185
- uint32_t initial_metadata_flags_eq,
186
- grpc_error *error);
189
+ void grpc_lb_policy_cancel_picks_locked(grpc_exec_ctx *exec_ctx,
190
+ grpc_lb_policy *policy,
191
+ uint32_t initial_metadata_flags_mask,
192
+ uint32_t initial_metadata_flags_eq,
193
+ grpc_error *error);
187
194
 
188
195
  /** Try to enter a READY connectivity state */
189
- void grpc_lb_policy_exit_idle(grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy);
196
+ void grpc_lb_policy_exit_idle_locked(grpc_exec_ctx *exec_ctx,
197
+ grpc_lb_policy *policy);
190
198
 
191
199
  /* Call notify when the connectivity state of a channel changes from \a *state.
192
200
  * Updates \a *state with the new state of the policy */
193
- void grpc_lb_policy_notify_on_state_change(grpc_exec_ctx *exec_ctx,
194
- grpc_lb_policy *policy,
195
- grpc_connectivity_state *state,
196
- grpc_closure *closure);
201
+ void grpc_lb_policy_notify_on_state_change_locked(
202
+ grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
203
+ grpc_connectivity_state *state, grpc_closure *closure);
197
204
 
198
- grpc_connectivity_state grpc_lb_policy_check_connectivity(
205
+ grpc_connectivity_state grpc_lb_policy_check_connectivity_locked(
199
206
  grpc_exec_ctx *exec_ctx, grpc_lb_policy *policy,
200
207
  grpc_error **connectivity_error);
201
208
 
@@ -107,6 +107,7 @@ grpc_arg grpc_lb_addresses_create_channel_arg(
107
107
  typedef struct grpc_lb_policy_args {
108
108
  grpc_client_channel_factory *client_channel_factory;
109
109
  grpc_channel_args *args;
110
+ grpc_combiner *combiner;
110
111
  } grpc_lb_policy_args;
111
112
 
112
113
  struct grpc_lb_policy_factory_vtable {
@@ -44,16 +44,18 @@
44
44
  #include <grpc/support/host_port.h>
45
45
  #include <grpc/support/log.h>
46
46
  #include <grpc/support/string_util.h>
47
+ #include "src/core/lib/support/string.h"
47
48
 
48
49
  #ifdef GRPC_HAVE_UNIX_SOCKET
49
50
 
50
51
  int parse_unix(grpc_uri *uri, grpc_resolved_address *resolved_addr) {
51
52
  struct sockaddr_un *un = (struct sockaddr_un *)resolved_addr->addr;
52
-
53
+ const size_t maxlen = sizeof(un->sun_path);
54
+ const size_t path_len = strnlen(uri->path, maxlen);
55
+ if (path_len == maxlen) return 0;
53
56
  un->sun_family = AF_UNIX;
54
57
  strcpy(un->sun_path, uri->path);
55
- resolved_addr->len = strlen(un->sun_path) + sizeof(un->sun_family) + 1;
56
-
58
+ resolved_addr->len = sizeof(*un);
57
59
  return 1;
58
60
  }
59
61
 
@@ -119,9 +121,33 @@ int parse_ipv6(grpc_uri *uri, grpc_resolved_address *resolved_addr) {
119
121
  memset(in6, 0, sizeof(*in6));
120
122
  resolved_addr->len = sizeof(*in6);
121
123
  in6->sin6_family = AF_INET6;
122
- if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
123
- gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
124
- goto done;
124
+
125
+ /* Handle the RFC6874 syntax for IPv6 zone identifiers. */
126
+ char *host_end = (char *)gpr_memrchr(host, '%', strlen(host));
127
+ if (host_end != NULL) {
128
+ GPR_ASSERT(host_end >= host);
129
+ char host_without_scope[INET6_ADDRSTRLEN];
130
+ size_t host_without_scope_len = (size_t)(host_end - host);
131
+ uint32_t sin6_scope_id = 0;
132
+ strncpy(host_without_scope, host, host_without_scope_len);
133
+ host_without_scope[host_without_scope_len] = '\0';
134
+ if (inet_pton(AF_INET6, host_without_scope, &in6->sin6_addr) == 0) {
135
+ gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host_without_scope);
136
+ goto done;
137
+ }
138
+ if (gpr_parse_bytes_to_uint32(host_end + 1,
139
+ strlen(host) - host_without_scope_len - 1,
140
+ &sin6_scope_id) == 0) {
141
+ gpr_log(GPR_ERROR, "invalid ipv6 scope id: '%s'", host_end + 1);
142
+ goto done;
143
+ }
144
+ // Handle "sin6_scope_id" being type "u_long". See grpc issue ##10027.
145
+ in6->sin6_scope_id = sin6_scope_id;
146
+ } else {
147
+ if (inet_pton(AF_INET6, host, &in6->sin6_addr) == 0) {
148
+ gpr_log(GPR_ERROR, "invalid ipv6 address: '%s'", host);
149
+ goto done;
150
+ }
125
151
  }
126
152
 
127
153
  if (port != NULL) {
@@ -0,0 +1,63 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/ext/client_channel/proxy_mapper.h"
35
+
36
+ void grpc_proxy_mapper_init(const grpc_proxy_mapper_vtable* vtable,
37
+ grpc_proxy_mapper* mapper) {
38
+ mapper->vtable = vtable;
39
+ }
40
+
41
+ bool grpc_proxy_mapper_map_name(grpc_exec_ctx* exec_ctx,
42
+ grpc_proxy_mapper* mapper,
43
+ const char* server_uri,
44
+ const grpc_channel_args* args,
45
+ char** name_to_resolve,
46
+ grpc_channel_args** new_args) {
47
+ return mapper->vtable->map_name(exec_ctx, mapper, server_uri, args,
48
+ name_to_resolve, new_args);
49
+ }
50
+
51
+ bool grpc_proxy_mapper_map_address(grpc_exec_ctx* exec_ctx,
52
+ grpc_proxy_mapper* mapper,
53
+ const grpc_resolved_address* address,
54
+ const grpc_channel_args* args,
55
+ grpc_resolved_address** new_address,
56
+ grpc_channel_args** new_args) {
57
+ return mapper->vtable->map_address(exec_ctx, mapper, address, args,
58
+ new_address, new_args);
59
+ }
60
+
61
+ void grpc_proxy_mapper_destroy(grpc_proxy_mapper* mapper) {
62
+ mapper->vtable->destroy(mapper);
63
+ }