wearefair-grpc 1.3.1.pre.c → 1.4.0.fair

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +418 -126
  3. data/include/grpc/grpc.h +15 -69
  4. data/include/grpc/grpc_security.h +1 -1
  5. data/include/grpc/impl/codegen/compression_types.h +3 -4
  6. data/include/grpc/impl/codegen/gpr_types.h +0 -1
  7. data/include/grpc/impl/codegen/grpc_types.h +69 -3
  8. data/include/grpc/impl/codegen/port_platform.h +6 -0
  9. data/include/grpc/impl/codegen/slice.h +2 -1
  10. data/include/grpc/load_reporting.h +6 -6
  11. data/include/grpc/slice.h +25 -3
  12. data/include/grpc/slice_buffer.h +4 -0
  13. data/src/core/ext/census/context.c +1 -1
  14. data/src/core/ext/census/resource.c +3 -1
  15. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  16. data/src/core/ext/filters/client_channel/client_channel.c +158 -100
  17. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  18. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  19. data/src/core/ext/filters/client_channel/lb_policy.h +5 -6
  20. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  21. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +344 -88
  23. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  24. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  25. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +47 -5
  26. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +6 -0
  27. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  29. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  30. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +13 -12
  31. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  32. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  33. data/src/core/ext/filters/client_channel/parse_address.c +37 -7
  34. data/src/core/ext/filters/client_channel/parse_address.h +11 -8
  35. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  36. data/src/core/ext/filters/client_channel/subchannel.c +19 -16
  37. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  38. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  39. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  40. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  41. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  42. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  43. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  44. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  45. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  46. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  47. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  48. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  49. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  50. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  51. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  52. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  53. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  54. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  55. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  56. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  57. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  58. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +296 -172
  59. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  60. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  61. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  62. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  63. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  64. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  65. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  66. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  67. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  68. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  69. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  70. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  71. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  72. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  73. data/src/core/lib/channel/channel_args.c +28 -9
  74. data/src/core/lib/channel/channel_args.h +5 -1
  75. data/src/core/lib/channel/channel_stack.c +1 -1
  76. data/src/core/lib/channel/channel_stack.h +2 -2
  77. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  78. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  79. data/src/core/lib/channel/connected_channel.c +3 -1
  80. data/src/core/lib/channel/context.h +2 -2
  81. data/src/core/lib/compression/message_compress.c +2 -2
  82. data/src/core/lib/debug/trace.c +13 -6
  83. data/src/core/lib/debug/trace.h +27 -1
  84. data/src/core/lib/http/httpcli.c +1 -1
  85. data/src/core/lib/http/httpcli_security_connector.c +6 -10
  86. data/src/core/lib/http/parser.c +2 -2
  87. data/src/core/lib/http/parser.h +2 -1
  88. data/src/core/lib/iomgr/combiner.c +6 -6
  89. data/src/core/lib/iomgr/combiner.h +2 -1
  90. data/src/core/lib/iomgr/error.c +12 -5
  91. data/src/core/lib/iomgr/error.h +13 -13
  92. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  93. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  94. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  95. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  96. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  97. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  98. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  99. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  100. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +24 -31
  101. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  102. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  103. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  104. data/src/core/lib/iomgr/ev_posix.c +22 -8
  105. data/src/core/lib/iomgr/ev_posix.h +4 -3
  106. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  107. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  108. data/src/core/lib/iomgr/iomgr.c +4 -0
  109. data/src/core/lib/iomgr/iomgr.h +3 -0
  110. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  111. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  112. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  113. data/src/core/lib/iomgr/pollset.h +2 -5
  114. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  115. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  116. data/src/core/lib/iomgr/resource_quota.c +9 -8
  117. data/src/core/lib/iomgr/resource_quota.h +2 -1
  118. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  119. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  120. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  121. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  122. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  123. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  124. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  125. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  126. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  127. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  128. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  129. data/src/core/lib/iomgr/timer_generic.c +24 -25
  130. data/src/core/lib/iomgr/timer_manager.c +276 -0
  131. data/src/core/lib/iomgr/timer_manager.h +52 -0
  132. data/src/core/lib/iomgr/timer_uv.c +6 -0
  133. data/src/core/lib/iomgr/udp_server.c +42 -9
  134. data/src/core/lib/iomgr/udp_server.h +3 -1
  135. data/src/core/lib/security/credentials/credentials.c +0 -1
  136. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  137. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  138. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  139. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  140. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  141. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  142. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  143. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  144. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  145. data/src/core/lib/security/transport/security_connector.c +32 -51
  146. data/src/core/lib/security/transport/security_connector.h +10 -14
  147. data/src/core/lib/slice/b64.c +1 -1
  148. data/src/core/lib/slice/percent_encoding.c +3 -3
  149. data/src/core/lib/slice/slice.c +66 -33
  150. data/src/core/lib/slice/slice_buffer.c +25 -6
  151. data/src/core/lib/slice/slice_hash_table.c +33 -35
  152. data/src/core/lib/slice/slice_hash_table.h +7 -12
  153. data/src/core/lib/support/atomic.h +45 -0
  154. data/src/core/lib/support/atomic_with_atm.h +70 -0
  155. data/src/core/lib/support/atomic_with_std.h +48 -0
  156. data/src/core/lib/support/avl.c +14 -14
  157. data/src/core/lib/support/memory.h +74 -0
  158. data/src/core/lib/support/mpscq.c +12 -1
  159. data/src/core/lib/support/mpscq.h +4 -0
  160. data/src/core/lib/support/stack_lockfree.c +3 -36
  161. data/src/core/lib/support/time_posix.c +8 -0
  162. data/src/core/lib/support/tmpfile_posix.c +10 -10
  163. data/src/core/lib/surface/alarm.c +3 -1
  164. data/src/core/lib/surface/api_trace.c +2 -1
  165. data/src/core/lib/surface/api_trace.h +2 -2
  166. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  167. data/src/core/lib/surface/call.c +65 -22
  168. data/src/core/lib/surface/call.h +4 -2
  169. data/src/core/lib/surface/channel_init.c +2 -19
  170. data/src/core/lib/surface/channel_stack_type.c +18 -0
  171. data/src/core/lib/surface/channel_stack_type.h +2 -0
  172. data/src/core/lib/surface/completion_queue.c +249 -83
  173. data/src/core/lib/surface/completion_queue.h +18 -13
  174. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  175. data/src/core/lib/surface/init.c +1 -52
  176. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  177. data/src/core/lib/surface/server.c +50 -27
  178. data/src/core/lib/surface/server.h +2 -1
  179. data/src/core/lib/surface/version.c +2 -2
  180. data/src/core/lib/transport/bdp_estimator.c +20 -9
  181. data/src/core/lib/transport/bdp_estimator.h +5 -1
  182. data/src/core/lib/transport/byte_stream.c +23 -9
  183. data/src/core/lib/transport/byte_stream.h +15 -6
  184. data/src/core/lib/transport/connectivity_state.c +6 -6
  185. data/src/core/lib/transport/connectivity_state.h +2 -1
  186. data/src/core/lib/transport/service_config.c +6 -13
  187. data/src/core/lib/transport/service_config.h +2 -2
  188. data/src/core/lib/transport/static_metadata.c +403 -389
  189. data/src/core/lib/transport/static_metadata.h +127 -114
  190. data/src/core/plugin_registry/grpc_plugin_registry.c +12 -0
  191. data/src/core/tsi/fake_transport_security.c +5 -4
  192. data/src/core/tsi/ssl_transport_security.c +71 -82
  193. data/src/core/tsi/ssl_transport_security.h +39 -61
  194. data/src/core/tsi/transport_security.c +83 -2
  195. data/src/core/tsi/transport_security.h +27 -2
  196. data/src/core/tsi/transport_security_adapter.c +236 -0
  197. data/src/core/tsi/transport_security_adapter.h +62 -0
  198. data/src/core/tsi/transport_security_interface.h +179 -66
  199. data/src/ruby/ext/grpc/extconf.rb +2 -1
  200. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  201. data/src/ruby/ext/grpc/rb_call.c +56 -48
  202. data/src/ruby/ext/grpc/rb_call.h +3 -4
  203. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  204. data/src/ruby/ext/grpc/rb_channel.c +45 -29
  205. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  206. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  207. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  208. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  209. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  210. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  211. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  212. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  213. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +14 -6
  214. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +22 -10
  215. data/src/ruby/ext/grpc/rb_server.c +26 -28
  216. data/src/ruby/lib/grpc/version.rb +1 -1
  217. metadata +40 -18
  218. data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
  219. data/src/ruby/lib/grpc/grpc_c.so +0 -0
@@ -0,0 +1,62 @@
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
+ #ifndef GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H
35
+ #define GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H
36
+
37
+ #include "src/core/tsi/transport_security_interface.h"
38
+
39
+ #ifdef __cplusplus
40
+ extern "C" {
41
+ #endif
42
+
43
+ /* Create a tsi handshaker that takes an implementation of old interface and
44
+ converts into an implementation of new interface. In the old interface,
45
+ there are get_bytes_to_send_to_peer, process_bytes_from_peer, get_result,
46
+ extract_peer, and create_frame_protector. In the new interface, only next
47
+ method is needed. See transport_security_interface.h for details. Note that
48
+ this tsi adapter handshaker is temporary. It will be removed once TSI has
49
+ been fully migrated to the new interface.
50
+ Ownership of input tsi_handshaker is transferred to this new adapter. */
51
+ tsi_handshaker *tsi_create_adapter_handshaker(tsi_handshaker *wrapped);
52
+
53
+ /* Given a tsi adapter handshaker, return the original wrapped handshaker. The
54
+ adapter still owns the wrapped handshaker which should not be destroyed by
55
+ the caller. */
56
+ tsi_handshaker *tsi_adapter_handshaker_get_wrapped(tsi_handshaker *adapter);
57
+
58
+ #ifdef __cplusplus
59
+ }
60
+ #endif
61
+
62
+ #endif /* GRPC_CORE_TSI_TRANSPORT_SECURITY_ADAPTER_H */
@@ -37,6 +37,8 @@
37
37
  #include <stdint.h>
38
38
  #include <stdlib.h>
39
39
 
40
+ #include "src/core/lib/debug/trace.h"
41
+
40
42
  #ifdef __cplusplus
41
43
  extern "C" {
42
44
  #endif
@@ -56,7 +58,8 @@ typedef enum {
56
58
  TSI_NOT_FOUND = 9,
57
59
  TSI_PROTOCOL_FAILURE = 10,
58
60
  TSI_HANDSHAKE_IN_PROGRESS = 11,
59
- TSI_OUT_OF_RESOURCES = 12
61
+ TSI_OUT_OF_RESOURCES = 12,
62
+ TSI_ASYNC = 13
60
63
  } tsi_result;
61
64
 
62
65
  typedef enum {
@@ -72,8 +75,7 @@ const char *tsi_result_to_string(tsi_result result);
72
75
 
73
76
  /* --- tsi tracing --- */
74
77
 
75
- /* Set this early to avoid races */
76
- extern int tsi_tracing_enabled;
78
+ extern grpc_tracer_flag tsi_tracing_enabled;
77
79
 
78
80
  /* --- tsi_frame_protector object ---
79
81
 
@@ -208,76 +210,138 @@ typedef struct {
208
210
  /* Destructs the tsi_peer object. */
209
211
  void tsi_peer_destruct(tsi_peer *self);
210
212
 
213
+ /* --- tsi_handshaker_result object ---
214
+
215
+ This object contains all necessary handshake results and data such as peer
216
+ info, negotiated keys, unused handshake bytes, when the handshake completes.
217
+ Implementations of this object must be thread compatible. */
218
+
219
+ typedef struct tsi_handshaker_result tsi_handshaker_result;
220
+
221
+ /* This method extracts tsi peer. It returns TSI_OK assuming there is no fatal
222
+ error.
223
+ The caller is responsible for destructing the peer. */
224
+ tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self,
225
+ tsi_peer *peer);
226
+
227
+ /* This method creates a tsi_frame_protector object. It returns TSI_OK assuming
228
+ there is no fatal error.
229
+ The caller is responsible for destroying the protector. */
230
+ tsi_result tsi_handshaker_result_create_frame_protector(
231
+ const tsi_handshaker_result *self, size_t *max_output_protected_frame_size,
232
+ tsi_frame_protector **protector);
233
+
234
+ /* This method returns the unused bytes from the handshake. It returns TSI_OK
235
+ assuming there is no fatal error.
236
+ Ownership of the bytes is retained by the handshaker result. As a
237
+ consequence, the caller must not free the bytes. */
238
+ tsi_result tsi_handshaker_result_get_unused_bytes(
239
+ const tsi_handshaker_result *self, unsigned char **bytes,
240
+ size_t *byte_size);
241
+
242
+ /* This method releases the tsi_handshaker_handshaker object. After this method
243
+ is called, no other method can be called on the object. */
244
+ void tsi_handshaker_result_destroy(tsi_handshaker_result *self);
245
+
211
246
  /* --- tsi_handshaker objects ----
212
247
 
213
248
  Implementations of this object must be thread compatible.
214
249
 
215
- A typical usage of this object would be:
250
+ ------------------------------------------------------------------------
251
+
252
+ A typical usage supporting both synchronous and asynchronous TSI handshaker
253
+ implementations would be:
216
254
 
217
255
  ------------------------------------------------------------------------
218
- tsi_result result = TSI_OK;
219
- unsigned char buf[4096];
220
- size_t buf_offset;
221
- size_t buf_size;
222
- while (1) {
223
- // See if we need to send some bytes to the peer.
224
- do {
225
- size_t buf_size_to_send = sizeof(buf);
226
- result = tsi_handshaker_get_bytes_to_send_to_peer(handshaker, buf,
227
- &buf_size_to_send);
228
- if (buf_size_to_send > 0) send_bytes_to_peer(buf, buf_size_to_send);
229
- } while (result == TSI_INCOMPLETE_DATA);
230
- if (result != TSI_OK) return result;
231
- if (!tsi_handshaker_is_in_progress(handshaker)) break;
232
-
233
- do {
234
- // Read bytes from the peer.
235
- buf_size = sizeof(buf);
236
- buf_offset = 0;
237
- read_bytes_from_peer(buf, &buf_size);
238
- if (buf_size == 0) break;
239
-
240
- // Process the bytes from the peer. We have to be careful as these bytes
241
- // may contain non-handshake data (protected data). If this is the case,
242
- // we will exit from the loop with buf_size > 0.
243
- size_t consumed_by_handshaker = buf_size;
244
- result = tsi_handshaker_process_bytes_from_peer(
245
- handshaker, buf, &consumed_by_handshaker);
246
- buf_size -= consumed_by_handshaker;
247
- buf_offset += consumed_by_handshaker;
248
- } while (result == TSI_INCOMPLETE_DATA);
249
-
250
- if (result != TSI_OK) return result;
251
- if (!tsi_handshaker_is_in_progress(handshaker)) break;
256
+
257
+ typedef struct {
258
+ tsi_handshaker *handshaker;
259
+ tsi_handshaker_result *handshaker_result;
260
+ unsigned char *handshake_buffer;
261
+ size_t handshake_buffer_size;
262
+ ...
263
+ } security_handshaker;
264
+
265
+ void do_handshake(security_handshaker *h, ...) {
266
+ // Start the handshake by the calling do_handshake_next.
267
+ do_handshake_next(h, NULL, 0);
268
+ ...
252
269
  }
253
270
 
254
- // Check the Peer.
255
- tsi_peer peer;
256
- do {
257
- result = tsi_handshaker_extract_peer(handshaker, &peer);
258
- if (result != TSI_OK) break;
259
- result = check_peer(&peer);
260
- } while (0);
261
- tsi_peer_destruct(&peer);
262
- if (result != TSI_OK) return result;
263
-
264
- // Create the protector.
265
- tsi_frame_protector* protector = NULL;
266
- result = tsi_handshaker_create_frame_protector(handshaker, NULL,
267
- &protector);
268
- if (result != TSI_OK) return result;
269
-
270
- // Do not forget to unprotect outstanding data if any.
271
- if (buf_size > 0) {
272
- result = tsi_frame_protector_unprotect(protector, buf + buf_offset,
273
- buf_size, ..., ...);
274
- ....
271
+ // This method is the callback function when data is received from the
272
+ // peer. This method will read bytes into the handshake buffer and call
273
+ // do_handshake_next.
274
+ void on_handshake_data_received_from_peer(void *user_data) {
275
+ security_handshaker *h = (security_handshaker *)user_data;
276
+ size_t bytes_received_size = h->handshake_buffer_size;
277
+ read_bytes_from_peer(h->handshake_buffer, &bytes_received_size);
278
+ do_handshake_next(h, h->handshake_buffer, bytes_received_size);
279
+ }
280
+
281
+ // This method processes a step of handshake, calling tsi_handshaker_next.
282
+ void do_handshake_next(security_handshaker *h,
283
+ const unsigned char* bytes_received,
284
+ size_t bytes_received_size) {
285
+ tsi_result status = TSI_OK;
286
+ unsigned char *bytes_to_send = NULL;
287
+ size_t bytes_to_send_size = 0;
288
+ tsi_handshaker_result *result = NULL;
289
+ status = tsi_handshaker_next(
290
+ handshaker, bytes_received, bytes_received_size, &bytes_to_send,
291
+ &bytes_to_send_size, &result, on_handshake_next_done, h);
292
+ // If TSI handshaker is asynchronous, on_handshake_next_done will be
293
+ // executed inside tsi_handshaker_next.
294
+ if (status == TSI_ASYNC) return;
295
+ // If TSI handshaker is synchronous, invoke callback directly in this
296
+ // thread.
297
+ on_handshake_next_done(status, (void *)h, bytes_to_send,
298
+ bytes_to_send_size, result);
299
+ }
300
+
301
+ // This is the callback function to execute after tsi_handshaker_next.
302
+ // It is passed to tsi_handshaker_next as a function parameter.
303
+ void on_handshake_next_done(
304
+ tsi_result status, void *user_data, const unsigned char *bytes_to_send,
305
+ size_t bytes_to_send_size, tsi_handshaker_result *result) {
306
+ security_handshaker *h = (security_handshaker *)user_data;
307
+ if (status == TSI_INCOMPLETE_DATA) {
308
+ // Schedule an asynchronous read from the peer. If handshake data are
309
+ // received, on_handshake_data_received_from_peer will be called.
310
+ async_read_from_peer(..., ..., on_handshake_data_received_from_peer);
311
+ return;
312
+ }
313
+ if (status != TSI_OK) return;
314
+
315
+ if (bytes_to_send_size > 0) {
316
+ send_bytes_to_peer(bytes_to_send, bytes_to_send_size);
317
+ }
318
+
319
+ if (result != NULL) {
320
+ // Handshake completed.
321
+ h->result = result;
322
+ // Check the Peer.
323
+ tsi_peer peer;
324
+ status = tsi_handshaker_result_extract_peer(result, &peer);
325
+ if (status != TSI_OK) return;
326
+ status = check_peer(&peer);
327
+ tsi_peer_destruct(&peer);
328
+ if (status != TSI_OK) return;
329
+
330
+ // Create the protector.
331
+ tsi_frame_protector* protector = NULL;
332
+ status = tsi_handshaker_result_create_frame_protector(result, NULL,
333
+ &protector);
334
+ if (status != TSI_OK) return;
335
+
336
+ // Do not forget to unprotect outstanding data if any.
337
+ ....
338
+ }
275
339
  }
276
- ...
277
340
  ------------------------------------------------------------------------ */
278
341
  typedef struct tsi_handshaker tsi_handshaker;
279
342
 
280
- /* Gets bytes that need to be sent to the peer.
343
+ /* TO BE DEPRECATED SOON. Use tsi_handshaker_next instead.
344
+ Gets bytes that need to be sent to the peer.
281
345
  - bytes is the buffer that will be written with the data to be sent to the
282
346
  peer.
283
347
  - bytes_size is an input/output parameter specifying the capacity of the
@@ -292,7 +356,8 @@ tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self,
292
356
  unsigned char *bytes,
293
357
  size_t *bytes_size);
294
358
 
295
- /* Processes bytes received from the peer.
359
+ /* TO BE DEPRECATED SOON. Use tsi_handshaker_next instead.
360
+ Processes bytes received from the peer.
296
361
  - bytes is the buffer containing the data.
297
362
  - bytes_size is an input/output parameter specifying the size of the data as
298
363
  input and the number of bytes consumed as output.
@@ -305,24 +370,29 @@ tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self,
305
370
  const unsigned char *bytes,
306
371
  size_t *bytes_size);
307
372
 
308
- /* Gets the result of the handshaker.
373
+ /* TO BE DEPRECATED SOON.
374
+ Gets the result of the handshaker.
309
375
  Returns TSI_OK if the hanshake completed successfully and there has been no
310
376
  errors. Returns TSI_HANDSHAKE_IN_PROGRESS if the handshaker is not done yet
311
377
  but no error has been encountered so far. Otherwise the handshaker failed
312
378
  with the returned error. */
313
379
  tsi_result tsi_handshaker_get_result(tsi_handshaker *self);
314
380
 
315
- /* Returns 1 if the handshake is in progress, 0 otherwise. */
381
+ /* TO BE DEPRECATED SOON.
382
+ Returns 1 if the handshake is in progress, 0 otherwise. */
316
383
  #define tsi_handshaker_is_in_progress(h) \
317
384
  (tsi_handshaker_get_result((h)) == TSI_HANDSHAKE_IN_PROGRESS)
318
385
 
319
- /* This method may return TSI_FAILED_PRECONDITION if
386
+ /* TO BE DEPRECATED SOON. Use tsi_handshaker_result_extract_peer instead.
387
+ This method may return TSI_FAILED_PRECONDITION if
320
388
  tsi_handshaker_is_in_progress returns 1, it returns TSI_OK otherwise
321
389
  assuming the handshaker is not in a fatal error state.
322
390
  The caller is responsible for destructing the peer. */
323
391
  tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer);
324
392
 
325
- /* This method creates a tsi_frame_protector object after the handshake phase
393
+ /* TO BE DEPRECATED SOON. Use tsi_handshaker_result_create_frame_protector
394
+ instead.
395
+ This method creates a tsi_frame_protector object after the handshake phase
326
396
  is done. After this method has been called successfully, the only method
327
397
  that can be called on this object is Destroy.
328
398
  - max_output_protected_frame_size is an input/output parameter specifying the
@@ -342,10 +412,53 @@ tsi_result tsi_handshaker_create_frame_protector(
342
412
  tsi_handshaker *self, size_t *max_output_protected_frame_size,
343
413
  tsi_frame_protector **protector);
344
414
 
415
+ /* Callback function definition for tsi_handshaker_next.
416
+ - status indicates the status of the next operation.
417
+ - user_data is the argument to callback function passed from the caller.
418
+ - bytes_to_send is the data buffer to be sent to the peer.
419
+ - bytes_to_send_size is the size of data buffer to be sent to the peer.
420
+ - handshaker_result is the result of handshake when the handshake completes,
421
+ is NULL otherwise. */
422
+ typedef void (*tsi_handshaker_on_next_done_cb)(
423
+ tsi_result status, void *user_data, const unsigned char *bytes_to_send,
424
+ size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result);
425
+
426
+ /* Conduct a next step of the handshake.
427
+ - received_bytes is the buffer containing the data received from the peer.
428
+ - received_bytes_size is the size of the data received from the peer.
429
+ - bytes_to_send is the data buffer to be sent to the peer.
430
+ - bytes_to_send_size is the size of data buffer to be sent to the peer.
431
+ - handshaker_result is the result of handshake if the handshake completes.
432
+ - cb is the callback function defined above. It can be NULL for synchronous
433
+ TSI handshaker implementation.
434
+ - user_data is the argument to callback function passed from the caller.
435
+ This method returns TSI_ASYNC if the TSI handshaker implementation is
436
+ asynchronous, and in this case, the callback is guaranteed to run in another
437
+ thread owned by TSI. It returns TSI_OK if the handshake completes or if
438
+ there are data to send to the peer, otherwise returns TSI_INCOMPLETE_DATA
439
+ which indicates that this method needs to be called again with more data
440
+ from the peer. In case of a fatal error in the handshake, another specific
441
+ error code is returned.
442
+ The caller is responsible for destroying the handshaker_result. However,
443
+ the caller should not free bytes_to_send, as the buffer is owned by the
444
+ tsi_handshaker object. */
445
+ tsi_result tsi_handshaker_next(
446
+ tsi_handshaker *self, const unsigned char *received_bytes,
447
+ size_t received_bytes_size, unsigned char **bytes_to_send,
448
+ size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result,
449
+ tsi_handshaker_on_next_done_cb cb, void *user_data);
450
+
345
451
  /* This method releases the tsi_handshaker object. After this method is called,
346
452
  no other method can be called on the object. */
347
453
  void tsi_handshaker_destroy(tsi_handshaker *self);
348
454
 
455
+ /* This method initializes the necessary shared objects used for tsi
456
+ implementation. */
457
+ void tsi_init();
458
+
459
+ /* This method destroys the shared objects created by tsi_init. */
460
+ void tsi_destroy();
461
+
349
462
  #ifdef __cplusplus
350
463
  }
351
464
  #endif
@@ -65,6 +65,7 @@ ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.7'
65
65
 
66
66
  ENV['AR'] = RbConfig::CONFIG['AR'] + ' rcs'
67
67
  ENV['CC'] = RbConfig::CONFIG['CC']
68
+ ENV['CXX'] = RbConfig::CONFIG['CXX']
68
69
  ENV['LD'] = ENV['CC']
69
70
 
70
71
  ENV['AR'] = 'libtool -o' if RUBY_PLATFORM =~ /darwin/
@@ -84,7 +85,7 @@ unless windows
84
85
  puts 'Building internal gRPC into ' + grpc_lib_dir
85
86
  nproc = 4
86
87
  nproc = Etc.nprocessors * 2 if Etc.respond_to? :nprocessors
87
- system("make -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config}")
88
+ system("make -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config} Q=")
88
89
  exit 1 unless $? == 0
89
90
  end
90
91
 
@@ -33,15 +33,15 @@
33
33
 
34
34
  #include <ruby/ruby.h>
35
35
 
36
- #include "rb_grpc_imports.generated.h"
37
36
  #include "rb_byte_buffer.h"
37
+ #include "rb_grpc_imports.generated.h"
38
38
 
39
- #include <grpc/grpc.h>
40
39
  #include <grpc/byte_buffer_reader.h>
40
+ #include <grpc/grpc.h>
41
41
  #include <grpc/slice.h>
42
42
  #include "rb_grpc.h"
43
43
 
44
- grpc_byte_buffer* grpc_rb_s_to_byte_buffer(char *string, size_t length) {
44
+ grpc_byte_buffer *grpc_rb_s_to_byte_buffer(char *string, size_t length) {
45
45
  grpc_slice slice = grpc_slice_from_copied_buffer(string, length);
46
46
  grpc_byte_buffer *buffer = grpc_raw_byte_buffer_create(&slice, 1);
47
47
  grpc_slice_unref(slice);
@@ -61,7 +61,7 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) {
61
61
  return Qnil;
62
62
  }
63
63
  while (grpc_byte_buffer_reader_next(&reader, &next) != 0) {
64
- rb_str_cat(rb_string, (const char *) GRPC_SLICE_START_PTR(next),
64
+ rb_str_cat(rb_string, (const char *)GRPC_SLICE_START_PTR(next),
65
65
  GRPC_SLICE_LENGTH(next));
66
66
  grpc_slice_unref(next);
67
67
  }
@@ -71,7 +71,9 @@ VALUE grpc_rb_byte_buffer_to_s(grpc_byte_buffer *buffer) {
71
71
 
72
72
  VALUE grpc_rb_slice_to_ruby_string(grpc_slice slice) {
73
73
  if (GRPC_SLICE_START_PTR(slice) == NULL) {
74
- rb_raise(rb_eRuntimeError, "attempt to convert uninitialized grpc_slice to ruby string");
74
+ rb_raise(rb_eRuntimeError,
75
+ "attempt to convert uninitialized grpc_slice to ruby string");
75
76
  }
76
- return rb_str_new((char*)GRPC_SLICE_START_PTR(slice), GRPC_SLICE_LENGTH(slice));
77
+ return rb_str_new((char *)GRPC_SLICE_START_PTR(slice),
78
+ GRPC_SLICE_LENGTH(slice));
77
79
  }
@@ -33,12 +33,12 @@
33
33
 
34
34
  #include <ruby/ruby.h>
35
35
 
36
- #include "rb_grpc_imports.generated.h"
37
36
  #include "rb_call.h"
37
+ #include "rb_grpc_imports.generated.h"
38
38
 
39
39
  #include <grpc/grpc.h>
40
- #include <grpc/support/alloc.h>
41
40
  #include <grpc/impl/codegen/compression_types.h>
41
+ #include <grpc/support/alloc.h>
42
42
 
43
43
  #include "rb_byte_buffer.h"
44
44
  #include "rb_call_credentials.h"
@@ -101,7 +101,7 @@ typedef struct grpc_rb_call {
101
101
  static void destroy_call(grpc_rb_call *call) {
102
102
  /* Ensure that we only try to destroy the call once */
103
103
  if (call->wrapped != NULL) {
104
- grpc_call_destroy(call->wrapped);
104
+ grpc_call_unref(call->wrapped);
105
105
  call->wrapped = NULL;
106
106
  grpc_rb_completion_queue_destroy(call->queue);
107
107
  call->queue = NULL;
@@ -113,7 +113,7 @@ static void grpc_rb_call_destroy(void *p) {
113
113
  if (p == NULL) {
114
114
  return;
115
115
  }
116
- destroy_call((grpc_rb_call*)p);
116
+ destroy_call((grpc_rb_call *)p);
117
117
  }
118
118
 
119
119
  static size_t md_ary_datasize(const void *p) {
@@ -130,7 +130,9 @@ static size_t md_ary_datasize(const void *p) {
130
130
 
131
131
  static const rb_data_type_t grpc_rb_md_ary_data_type = {
132
132
  "grpc_metadata_array",
133
- {GRPC_RB_GC_NOT_MARKED, GRPC_RB_GC_DONT_FREE, md_ary_datasize,
133
+ {GRPC_RB_GC_NOT_MARKED,
134
+ GRPC_RB_GC_DONT_FREE,
135
+ md_ary_datasize,
134
136
  {NULL, NULL}},
135
137
  NULL,
136
138
  NULL,
@@ -140,19 +142,20 @@ static const rb_data_type_t grpc_rb_md_ary_data_type = {
140
142
  * touches a hash object.
141
143
  * TODO(yugui) Directly use st_table and call the free function earlier?
142
144
  */
143
- 0,
145
+ 0,
144
146
  #endif
145
147
  };
146
148
 
147
149
  /* Describes grpc_call struct for RTypedData */
148
- static const rb_data_type_t grpc_call_data_type = {
149
- "grpc_call",
150
- {GRPC_RB_GC_NOT_MARKED, grpc_rb_call_destroy, GRPC_RB_MEMSIZE_UNAVAILABLE,
151
- {NULL, NULL}},
152
- NULL,
153
- NULL,
150
+ static const rb_data_type_t grpc_call_data_type = {"grpc_call",
151
+ {GRPC_RB_GC_NOT_MARKED,
152
+ grpc_rb_call_destroy,
153
+ GRPC_RB_MEMSIZE_UNAVAILABLE,
154
+ {NULL, NULL}},
155
+ NULL,
156
+ NULL,
154
157
  #ifdef RUBY_TYPED_FREE_IMMEDIATELY
155
- RUBY_TYPED_FREE_IMMEDIATELY
158
+ RUBY_TYPED_FREE_IMMEDIATELY
156
159
  #endif
157
160
  };
158
161
 
@@ -175,7 +178,7 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
175
178
  grpc_rb_call *call = NULL;
176
179
  grpc_call_error err;
177
180
  if (RTYPEDDATA_DATA(self) == NULL) {
178
- //This call has been closed
181
+ // This call has been closed
179
182
  return Qnil;
180
183
  }
181
184
 
@@ -196,7 +199,7 @@ static VALUE grpc_rb_call_cancel(VALUE self) {
196
199
  static VALUE grpc_rb_call_close(VALUE self) {
197
200
  grpc_rb_call *call = NULL;
198
201
  TypedData_Get_Struct(self, grpc_rb_call, &grpc_call_data_type, call);
199
- if(call != NULL) {
202
+ if (call != NULL) {
200
203
  destroy_call(call);
201
204
  RTYPEDDATA_DATA(self) = NULL;
202
205
  }
@@ -238,8 +241,8 @@ static VALUE grpc_rb_call_get_peer_cert(VALUE self) {
238
241
  }
239
242
 
240
243
  {
241
- grpc_auth_property_iterator it =
242
- grpc_auth_context_find_properties_by_name(ctx, GRPC_X509_PEM_CERT_PROPERTY_NAME);
244
+ grpc_auth_property_iterator it = grpc_auth_context_find_properties_by_name(
245
+ ctx, GRPC_X509_PEM_CERT_PROPERTY_NAME);
243
246
  const grpc_auth_property *prop = grpc_auth_property_iterator_next(&it);
244
247
  if (prop == NULL) {
245
248
  return Qnil;
@@ -388,21 +391,22 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
388
391
  long i;
389
392
  grpc_slice key_slice;
390
393
  grpc_slice value_slice;
391
- char* tmp_str;
394
+ char *tmp_str;
392
395
 
393
396
  if (TYPE(key) == T_SYMBOL) {
394
397
  key_slice = grpc_slice_from_static_string(rb_id2name(SYM2ID(key)));
395
398
  } else if (TYPE(key) == T_STRING) {
396
- key_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(key), RSTRING_LEN(key));
399
+ key_slice =
400
+ grpc_slice_from_copied_buffer(RSTRING_PTR(key), RSTRING_LEN(key));
397
401
  } else {
398
- rb_raise(rb_eTypeError, "grpc_rb_md_ary_fill_hash_cb: bad type for key parameter");
402
+ rb_raise(rb_eTypeError,
403
+ "grpc_rb_md_ary_fill_hash_cb: bad type for key parameter");
399
404
  }
400
405
 
401
406
  if (!grpc_header_key_is_legal(key_slice)) {
402
407
  tmp_str = grpc_slice_to_c_string(key_slice);
403
408
  rb_raise(rb_eArgError,
404
- "'%s' is an invalid header key, must match [a-z0-9-_.]+",
405
- tmp_str);
409
+ "'%s' is an invalid header key, must match [a-z0-9-_.]+", tmp_str);
406
410
  return ST_STOP;
407
411
  }
408
412
 
@@ -414,13 +418,14 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
414
418
  array_length = RARRAY_LEN(val);
415
419
  /* If the value is an array, add capacity for each value in the array */
416
420
  for (i = 0; i < array_length; i++) {
417
- value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(rb_ary_entry(val, i)), RSTRING_LEN(rb_ary_entry(val, i)));
421
+ value_slice = grpc_slice_from_copied_buffer(
422
+ RSTRING_PTR(rb_ary_entry(val, i)), RSTRING_LEN(rb_ary_entry(val, i)));
418
423
  if (!grpc_is_binary_header(key_slice) &&
419
424
  !grpc_header_nonbin_value_is_legal(value_slice)) {
420
425
  // The value has invalid characters
421
426
  tmp_str = grpc_slice_to_c_string(value_slice);
422
- rb_raise(rb_eArgError,
423
- "Header value '%s' has invalid characters", tmp_str);
427
+ rb_raise(rb_eArgError, "Header value '%s' has invalid characters",
428
+ tmp_str);
424
429
  return ST_STOP;
425
430
  }
426
431
  md_ary->metadata[md_ary->count].key = key_slice;
@@ -428,21 +433,21 @@ static int grpc_rb_md_ary_fill_hash_cb(VALUE key, VALUE val, VALUE md_ary_obj) {
428
433
  md_ary->count += 1;
429
434
  }
430
435
  } else if (TYPE(val) == T_STRING) {
431
- value_slice = grpc_slice_from_copied_buffer(RSTRING_PTR(val), RSTRING_LEN(val));
436
+ value_slice =
437
+ grpc_slice_from_copied_buffer(RSTRING_PTR(val), RSTRING_LEN(val));
432
438
  if (!grpc_is_binary_header(key_slice) &&
433
439
  !grpc_header_nonbin_value_is_legal(value_slice)) {
434
440
  // The value has invalid characters
435
441
  tmp_str = grpc_slice_to_c_string(value_slice);
436
- rb_raise(rb_eArgError,
437
- "Header value '%s' has invalid characters", tmp_str);
442
+ rb_raise(rb_eArgError, "Header value '%s' has invalid characters",
443
+ tmp_str);
438
444
  return ST_STOP;
439
445
  }
440
446
  md_ary->metadata[md_ary->count].key = key_slice;
441
447
  md_ary->metadata[md_ary->count].value = value_slice;
442
448
  md_ary->count += 1;
443
449
  } else {
444
- rb_raise(rb_eArgError,
445
- "Header values must be of type string or array");
450
+ rb_raise(rb_eArgError, "Header values must be of type string or array");
446
451
  return ST_STOP;
447
452
  }
448
453
 
@@ -474,8 +479,7 @@ static int grpc_rb_md_ary_capacity_hash_cb(VALUE key, VALUE val,
474
479
  /* grpc_rb_md_ary_convert converts a ruby metadata hash into
475
480
  a grpc_metadata_array.
476
481
  */
477
- void grpc_rb_md_ary_convert(VALUE md_ary_hash,
478
- grpc_metadata_array *md_ary) {
482
+ void grpc_rb_md_ary_convert(VALUE md_ary_hash, grpc_metadata_array *md_ary) {
479
483
  VALUE md_ary_obj = Qnil;
480
484
  if (md_ary_hash == Qnil) {
481
485
  return; /* Do nothing if the expected has value is nil */
@@ -511,12 +515,14 @@ VALUE grpc_rb_md_ary_to_h(grpc_metadata_array *md_ary) {
511
515
  rb_hash_aset(result, key, value);
512
516
  } else if (TYPE(value) == T_ARRAY) {
513
517
  /* Add the string to the returned array */
514
- rb_ary_push(value, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value));
518
+ rb_ary_push(value,
519
+ grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value));
515
520
  } else {
516
521
  /* Add the current value with this key and the new one to an array */
517
522
  new_ary = rb_ary_new();
518
523
  rb_ary_push(new_ary, value);
519
- rb_ary_push(new_ary, grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value));
524
+ rb_ary_push(new_ary,
525
+ grpc_rb_slice_to_ruby_string(md_ary->metadata[i].value));
520
526
  rb_hash_aset(result, key, new_ary);
521
527
  }
522
528
  }
@@ -556,10 +562,9 @@ static int grpc_rb_call_check_op_keys_hash_cb(VALUE key, VALUE val,
556
562
  /* grpc_rb_op_update_status_from_server adds the values in a ruby status
557
563
  struct to the 'send_status_from_server' portion of an op.
558
564
  */
559
- static void grpc_rb_op_update_status_from_server(grpc_op *op,
560
- grpc_metadata_array *md_ary,
561
- grpc_slice *send_status_details,
562
- VALUE status) {
565
+ static void grpc_rb_op_update_status_from_server(
566
+ grpc_op *op, grpc_metadata_array *md_ary, grpc_slice *send_status_details,
567
+ VALUE status) {
563
568
  VALUE code = rb_struct_aref(status, sym_code);
564
569
  VALUE details = rb_struct_aref(status, sym_details);
565
570
  VALUE metadata_hash = rb_struct_aref(status, sym_metadata);
@@ -576,7 +581,8 @@ static void grpc_rb_op_update_status_from_server(grpc_op *op,
576
581
  return;
577
582
  }
578
583
 
579
- *send_status_details = grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details));
584
+ *send_status_details =
585
+ grpc_slice_from_copied_buffer(RSTRING_PTR(details), RSTRING_LEN(details));
580
586
 
581
587
  op->data.send_status_from_server.status = NUM2INT(code);
582
588
  op->data.send_status_from_server.status_details = send_status_details;
@@ -687,7 +693,8 @@ static void grpc_run_batch_stack_fill_ops(run_batch_stack *st, VALUE ops_hash) {
687
693
  /* N.B. later there is no need to explicitly delete the metadata keys
688
694
  * and values, they are references to data in ruby objects. */
689
695
  grpc_rb_op_update_status_from_server(
690
- &st->ops[st->op_num], &st->send_trailing_metadata, &st->send_status_details, this_value);
696
+ &st->ops[st->op_num], &st->send_trailing_metadata,
697
+ &st->send_status_details, this_value);
691
698
  break;
692
699
  case GRPC_OP_RECV_INITIAL_METADATA:
693
700
  st->ops[st->op_num].data.recv_initial_metadata.recv_initial_metadata =
@@ -749,12 +756,12 @@ static VALUE grpc_run_batch_stack_build_result(run_batch_stack *st) {
749
756
  case GRPC_OP_RECV_STATUS_ON_CLIENT:
750
757
  rb_struct_aset(
751
758
  result, sym_status,
752
- rb_struct_new(grpc_rb_sStatus, UINT2NUM(st->recv_status),
753
- (GRPC_SLICE_START_PTR(st->recv_status_details) == NULL
754
- ? Qnil
755
- : grpc_rb_slice_to_ruby_string(st->recv_status_details)),
756
- grpc_rb_md_ary_to_h(&st->recv_trailing_metadata),
757
- NULL));
759
+ rb_struct_new(
760
+ grpc_rb_sStatus, UINT2NUM(st->recv_status),
761
+ (GRPC_SLICE_START_PTR(st->recv_status_details) == NULL
762
+ ? Qnil
763
+ : grpc_rb_slice_to_ruby_string(st->recv_status_details)),
764
+ grpc_rb_md_ary_to_h(&st->recv_trailing_metadata), NULL));
758
765
  break;
759
766
  case GRPC_OP_RECV_CLOSE_ON_SERVER:
760
767
  rb_struct_aset(result, sym_send_close, Qtrue);
@@ -791,7 +798,7 @@ static VALUE grpc_rb_call_run_batch(VALUE self, VALUE ops_hash) {
791
798
  VALUE result = Qnil;
792
799
  VALUE rb_write_flag = rb_ivar_get(self, id_write_flag);
793
800
  unsigned write_flag = 0;
794
- void *tag = (void*)&st;
801
+ void *tag = (void *)&st;
795
802
 
796
803
  if (RTYPEDDATA_DATA(self) == NULL) {
797
804
  rb_raise(grpc_rb_eCallError, "Cannot run batch on closed call");
@@ -919,7 +926,8 @@ static void Init_grpc_op_codes() {
919
926
  }
920
927
 
921
928
  static void Init_grpc_metadata_keys() {
922
- VALUE grpc_rb_mMetadataKeys = rb_define_module_under(grpc_rb_mGrpcCore, "MetadataKeys");
929
+ VALUE grpc_rb_mMetadataKeys =
930
+ rb_define_module_under(grpc_rb_mGrpcCore, "MetadataKeys");
923
931
  rb_define_const(grpc_rb_mMetadataKeys, "COMPRESSION_REQUEST_ALGORITHM",
924
932
  rb_str_new2(GRPC_COMPRESSION_REQUEST_ALGORITHM_MD_KEY));
925
933
  }