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
@@ -99,7 +99,4 @@ bool grpc_cq_is_non_listening_server_cq(grpc_completion_queue *cc);
99
99
  void grpc_cq_mark_server_cq(grpc_completion_queue *cc);
100
100
  int grpc_cq_is_server_cq(grpc_completion_queue *cc);
101
101
 
102
- void grpc_cq_global_init(void);
103
- void grpc_cq_global_shutdown(void);
104
-
105
102
  #endif /* GRPC_CORE_LIB_SURFACE_COMPLETION_QUEUE_H */
@@ -55,6 +55,7 @@
55
55
  #include "src/core/lib/iomgr/iomgr.h"
56
56
  #include "src/core/lib/iomgr/resource_quota.h"
57
57
  #include "src/core/lib/profiling/timers.h"
58
+ #include "src/core/lib/slice/slice_internal.h"
58
59
  #include "src/core/lib/surface/api_trace.h"
59
60
  #include "src/core/lib/surface/call.h"
60
61
  #include "src/core/lib/surface/channel_init.h"
@@ -62,6 +63,7 @@
62
63
  #include "src/core/lib/surface/init.h"
63
64
  #include "src/core/lib/surface/lame_client.h"
64
65
  #include "src/core/lib/surface/server.h"
66
+ #include "src/core/lib/transport/bdp_estimator.h"
65
67
  #include "src/core/lib/transport/connectivity_state.h"
66
68
  #include "src/core/lib/transport/transport_impl.h"
67
69
 
@@ -178,6 +180,7 @@ void grpc_init(void) {
178
180
  gpr_mu_lock(&g_init_mu);
179
181
  if (++g_initializations == 1) {
180
182
  gpr_time_init();
183
+ grpc_slice_intern_init();
181
184
  grpc_mdctx_global_init();
182
185
  grpc_channel_init_init();
183
186
  grpc_register_tracer("api", &grpc_api_trace);
@@ -190,6 +193,7 @@ void grpc_init(void) {
190
193
  grpc_register_tracer("queue_pluck", &grpc_cq_pluck_trace);
191
194
  grpc_register_tracer("combiner", &grpc_combiner_trace);
192
195
  grpc_register_tracer("server_channel", &grpc_server_channel_trace);
196
+ grpc_register_tracer("bdp_estimator", &grpc_bdp_estimator_trace);
193
197
  // Default pluck trace to 1
194
198
  grpc_cq_pluck_trace = 1;
195
199
  grpc_register_tracer("queue_timeout", &grpc_cq_event_timeout_trace);
@@ -197,6 +201,7 @@ void grpc_init(void) {
197
201
  grpc_cq_event_timeout_trace = 1;
198
202
  grpc_register_tracer("op_failure", &grpc_trace_operation_failures);
199
203
  grpc_register_tracer("resource_quota", &grpc_resource_quota_trace);
204
+ grpc_register_tracer("call_error", &grpc_call_error_trace);
200
205
  #ifndef NDEBUG
201
206
  grpc_register_tracer("pending_tags", &grpc_trace_pending_tags);
202
207
  #endif
@@ -204,7 +209,6 @@ void grpc_init(void) {
204
209
  grpc_iomgr_init();
205
210
  grpc_executor_init();
206
211
  gpr_timers_global_init();
207
- grpc_cq_global_init();
208
212
  grpc_handshaker_factory_registry_init();
209
213
  grpc_security_init();
210
214
  for (i = 0; i < g_number_of_plugins; i++) {
@@ -231,7 +235,6 @@ void grpc_shutdown(void) {
231
235
  gpr_mu_lock(&g_init_mu);
232
236
  if (--g_initializations == 0) {
233
237
  grpc_executor_shutdown(&exec_ctx);
234
- grpc_cq_global_shutdown();
235
238
  grpc_iomgr_shutdown(&exec_ctx);
236
239
  gpr_timers_global_destroy();
237
240
  grpc_tracer_shutdown();
@@ -242,6 +245,7 @@ void grpc_shutdown(void) {
242
245
  }
243
246
  grpc_mdctx_global_shutdown(&exec_ctx);
244
247
  grpc_handshaker_factory_registry_shutdown(&exec_ctx);
248
+ grpc_slice_intern_shutdown();
245
249
  }
246
250
  gpr_mu_unlock(&g_init_mu);
247
251
  grpc_exec_ctx_finish(&exec_ctx);
@@ -56,7 +56,7 @@ static bool maybe_prepend_client_auth_filter(
56
56
  grpc_channel_stack_builder_get_channel_arguments(builder);
57
57
  if (args) {
58
58
  for (size_t i = 0; i < args->num_args; i++) {
59
- if (0 == strcmp(GRPC_SECURITY_CONNECTOR_ARG, args->args[i].key)) {
59
+ if (0 == strcmp(GRPC_ARG_SECURITY_CONNECTOR, args->args[i].key)) {
60
60
  return grpc_channel_stack_builder_prepend_filter(
61
61
  builder, &grpc_client_auth_filter, NULL, NULL);
62
62
  }
@@ -44,10 +44,12 @@
44
44
  #include "src/core/lib/surface/api_trace.h"
45
45
  #include "src/core/lib/surface/call.h"
46
46
  #include "src/core/lib/surface/channel.h"
47
+ #include "src/core/lib/transport/static_metadata.h"
47
48
 
48
49
  typedef struct {
49
50
  grpc_linked_mdelem status;
50
51
  grpc_linked_mdelem details;
52
+ gpr_atm filled_metadata;
51
53
  } call_data;
52
54
 
53
55
  typedef struct {
@@ -58,17 +60,23 @@ typedef struct {
58
60
  static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
59
61
  grpc_metadata_batch *mdb) {
60
62
  call_data *calld = elem->call_data;
63
+ if (!gpr_atm_no_barrier_cas(&calld->filled_metadata, 0, 1)) {
64
+ return;
65
+ }
61
66
  channel_data *chand = elem->channel_data;
62
67
  char tmp[GPR_LTOA_MIN_BUFSIZE];
63
68
  gpr_ltoa(chand->error_code, tmp);
64
- calld->status.md = grpc_mdelem_from_strings(exec_ctx, "grpc-status", tmp);
65
- calld->details.md =
66
- grpc_mdelem_from_strings(exec_ctx, "grpc-message", chand->error_message);
69
+ calld->status.md = grpc_mdelem_from_slices(
70
+ exec_ctx, GRPC_MDSTR_GRPC_STATUS, grpc_slice_from_copied_string(tmp));
71
+ calld->details.md = grpc_mdelem_from_slices(
72
+ exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
73
+ grpc_slice_from_copied_string(chand->error_message));
67
74
  calld->status.prev = calld->details.next = NULL;
68
75
  calld->status.next = &calld->details;
69
76
  calld->details.prev = &calld->status;
70
77
  mdb->list.head = &calld->status;
71
78
  mdb->list.tail = &calld->details;
79
+ mdb->list.count = 2;
72
80
  mdb->deadline = gpr_inf_future(GPR_CLOCK_REALTIME);
73
81
  }
74
82
 
@@ -114,7 +122,9 @@ static void lame_start_transport_op(grpc_exec_ctx *exec_ctx,
114
122
 
115
123
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
116
124
  grpc_call_element *elem,
117
- grpc_call_element_args *args) {
125
+ const grpc_call_element_args *args) {
126
+ call_data *calld = elem->call_data;
127
+ gpr_atm_no_barrier_store(&calld->filled_metadata, 0);
118
128
  return GRPC_ERROR_NONE;
119
129
  }
120
130
 
@@ -98,8 +98,9 @@ typedef struct requested_call {
98
98
  typedef struct channel_registered_method {
99
99
  registered_method *server_registered_method;
100
100
  uint32_t flags;
101
- grpc_mdstr *method;
102
- grpc_mdstr *host;
101
+ bool has_host;
102
+ grpc_slice method;
103
+ grpc_slice host;
103
104
  } channel_registered_method;
104
105
 
105
106
  struct channel_data {
@@ -144,8 +145,10 @@ struct call_data {
144
145
  /** the current state of a call - see call_state */
145
146
  call_state state;
146
147
 
147
- grpc_mdstr *path;
148
- grpc_mdstr *host;
148
+ bool path_set;
149
+ bool host_set;
150
+ grpc_slice path;
151
+ grpc_slice host;
149
152
  gpr_timespec deadline;
150
153
 
151
154
  grpc_completion_queue *cq_new;
@@ -277,18 +280,20 @@ static void shutdown_cleanup(grpc_exec_ctx *exec_ctx, void *arg,
277
280
  }
278
281
 
279
282
  static void send_shutdown(grpc_exec_ctx *exec_ctx, grpc_channel *channel,
280
- int send_goaway, grpc_error *send_disconnect) {
283
+ bool send_goaway, grpc_error *send_disconnect) {
281
284
  struct shutdown_cleanup_args *sc = gpr_malloc(sizeof(*sc));
282
285
  grpc_closure_init(&sc->closure, shutdown_cleanup, sc,
283
286
  grpc_schedule_on_exec_ctx);
284
287
  grpc_transport_op *op = grpc_make_transport_op(&sc->closure);
285
288
  grpc_channel_element *elem;
286
289
 
287
- op->send_goaway = send_goaway;
290
+ op->goaway_error =
291
+ send_goaway
292
+ ? grpc_error_set_int(GRPC_ERROR_CREATE("Server shutdown"),
293
+ GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_OK)
294
+ : GRPC_ERROR_NONE;
288
295
  op->set_accept_stream = true;
289
296
  sc->slice = grpc_slice_from_copied_string("Server shutdown");
290
- op->goaway_message = &sc->slice;
291
- op->goaway_status = GRPC_STATUS_OK;
292
297
  op->disconnect_with_error = send_disconnect;
293
298
 
294
299
  elem = grpc_channel_stack_element(grpc_channel_get_channel_stack(channel), 0);
@@ -448,7 +453,6 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
448
453
  if (grpc_server_channel_trace && error != GRPC_ERROR_NONE) {
449
454
  const char *msg = grpc_error_string(error);
450
455
  gpr_log(GPR_INFO, "Disconnected client: %s", msg);
451
- grpc_error_free_string(msg);
452
456
  }
453
457
  GRPC_ERROR_UNREF(error);
454
458
 
@@ -461,17 +465,6 @@ static void destroy_channel(grpc_exec_ctx *exec_ctx, channel_data *chand,
461
465
  op);
462
466
  }
463
467
 
464
- static void cpstr(char **dest, size_t *capacity, grpc_mdstr *value) {
465
- grpc_slice slice = value->slice;
466
- size_t len = GRPC_SLICE_LENGTH(slice);
467
-
468
- if (len + 1 > *capacity) {
469
- *capacity = GPR_MAX(len + 1, *capacity * 2);
470
- *dest = gpr_realloc(*dest, *capacity);
471
- }
472
- memcpy(*dest, grpc_mdstr_as_c_string(value), len + 1);
473
- }
474
-
475
468
  static void done_request_event(grpc_exec_ctx *exec_ctx, void *req,
476
469
  grpc_cq_completion *c) {
477
470
  requested_call *rc = req;
@@ -500,12 +493,10 @@ static void publish_call(grpc_exec_ctx *exec_ctx, grpc_server *server,
500
493
  GPR_SWAP(grpc_metadata_array, *rc->initial_metadata, calld->initial_metadata);
501
494
  switch (rc->type) {
502
495
  case BATCH_CALL:
503
- GPR_ASSERT(calld->host != NULL);
504
- GPR_ASSERT(calld->path != NULL);
505
- cpstr(&rc->data.batch.details->host,
506
- &rc->data.batch.details->host_capacity, calld->host);
507
- cpstr(&rc->data.batch.details->method,
508
- &rc->data.batch.details->method_capacity, calld->path);
496
+ GPR_ASSERT(calld->host_set);
497
+ GPR_ASSERT(calld->path_set);
498
+ rc->data.batch.details->host = grpc_slice_ref_internal(calld->host);
499
+ rc->data.batch.details->method = grpc_slice_ref_internal(calld->path);
509
500
  rc->data.batch.details->deadline = calld->deadline;
510
501
  rc->data.batch.details->flags =
511
502
  (calld->recv_idempotent_request
@@ -549,7 +540,8 @@ static void publish_new_rpc(grpc_exec_ctx *exec_ctx, void *arg,
549
540
  &calld->kill_zombie_closure, kill_zombie,
550
541
  grpc_call_stack_element(grpc_call_get_call_stack(calld->call), 0),
551
542
  grpc_schedule_on_exec_ctx);
552
- grpc_closure_sched(exec_ctx, &calld->kill_zombie_closure, error);
543
+ grpc_closure_sched(exec_ctx, &calld->kill_zombie_closure,
544
+ GRPC_ERROR_REF(error));
553
545
  return;
554
546
  }
555
547
 
@@ -627,35 +619,39 @@ static void start_new_rpc(grpc_exec_ctx *exec_ctx, grpc_call_element *elem) {
627
619
  uint32_t hash;
628
620
  channel_registered_method *rm;
629
621
 
630
- if (chand->registered_methods && calld->path && calld->host) {
622
+ if (chand->registered_methods && calld->path_set && calld->host_set) {
631
623
  /* TODO(ctiller): unify these two searches */
632
624
  /* check for an exact match with host */
633
- hash = GRPC_MDSTR_KV_HASH(calld->host->hash, calld->path->hash);
625
+ hash = GRPC_MDSTR_KV_HASH(grpc_slice_hash(calld->host),
626
+ grpc_slice_hash(calld->path));
634
627
  for (i = 0; i <= chand->registered_method_max_probes; i++) {
635
628
  rm = &chand->registered_methods[(hash + i) %
636
629
  chand->registered_method_slots];
637
630
  if (!rm) break;
638
- if (rm->host != calld->host) continue;
639
- if (rm->method != calld->path) continue;
631
+ if (!rm->has_host) continue;
632
+ if (!grpc_slice_eq(rm->host, calld->host)) continue;
633
+ if (!grpc_slice_eq(rm->method, calld->path)) continue;
640
634
  if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
641
- !calld->recv_idempotent_request)
635
+ !calld->recv_idempotent_request) {
642
636
  continue;
637
+ }
643
638
  finish_start_new_rpc(exec_ctx, server, elem,
644
639
  &rm->server_registered_method->request_matcher,
645
640
  rm->server_registered_method->payload_handling);
646
641
  return;
647
642
  }
648
643
  /* check for a wildcard method definition (no host set) */
649
- hash = GRPC_MDSTR_KV_HASH(0, calld->path->hash);
644
+ hash = GRPC_MDSTR_KV_HASH(0, grpc_slice_hash(calld->path));
650
645
  for (i = 0; i <= chand->registered_method_max_probes; i++) {
651
646
  rm = &chand->registered_methods[(hash + i) %
652
647
  chand->registered_method_slots];
653
648
  if (!rm) break;
654
- if (rm->host != NULL) continue;
655
- if (rm->method != calld->path) continue;
649
+ if (rm->has_host) continue;
650
+ if (!grpc_slice_eq(rm->method, calld->path)) continue;
656
651
  if ((rm->flags & GRPC_INITIAL_METADATA_IDEMPOTENT_REQUEST) &&
657
- !calld->recv_idempotent_request)
652
+ !calld->recv_idempotent_request) {
658
653
  continue;
654
+ }
659
655
  finish_start_new_rpc(exec_ctx, server, elem,
660
656
  &rm->server_registered_method->request_matcher,
661
657
  rm->server_registered_method->payload_handling);
@@ -744,43 +740,40 @@ static void maybe_finish_shutdown(grpc_exec_ctx *exec_ctx,
744
740
  }
745
741
  }
746
742
 
747
- static grpc_mdelem *server_filter(grpc_exec_ctx *exec_ctx, void *user_data,
748
- grpc_mdelem *md) {
749
- grpc_call_element *elem = user_data;
750
- call_data *calld = elem->call_data;
751
- if (md->key == GRPC_MDSTR_PATH) {
752
- if (calld->path == NULL) {
753
- calld->path = GRPC_MDSTR_REF(md->value);
754
- }
755
- return NULL;
756
- } else if (md->key == GRPC_MDSTR_AUTHORITY) {
757
- if (calld->host == NULL) {
758
- calld->host = GRPC_MDSTR_REF(md->value);
759
- }
760
- return NULL;
761
- }
762
- return md;
763
- }
764
-
765
743
  static void server_on_recv_initial_metadata(grpc_exec_ctx *exec_ctx, void *ptr,
766
744
  grpc_error *error) {
767
745
  grpc_call_element *elem = ptr;
768
746
  call_data *calld = elem->call_data;
769
747
  gpr_timespec op_deadline;
770
748
 
771
- GRPC_ERROR_REF(error);
772
- grpc_metadata_batch_filter(exec_ctx, calld->recv_initial_metadata,
773
- server_filter, elem);
749
+ if (error == GRPC_ERROR_NONE) {
750
+ GPR_ASSERT(calld->recv_initial_metadata->idx.named.path != NULL);
751
+ GPR_ASSERT(calld->recv_initial_metadata->idx.named.authority != NULL);
752
+ calld->path = grpc_slice_ref_internal(
753
+ GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.path->md));
754
+ calld->host = grpc_slice_ref_internal(
755
+ GRPC_MDVALUE(calld->recv_initial_metadata->idx.named.authority->md));
756
+ calld->path_set = true;
757
+ calld->host_set = true;
758
+ grpc_metadata_batch_remove(exec_ctx, calld->recv_initial_metadata,
759
+ calld->recv_initial_metadata->idx.named.path);
760
+ grpc_metadata_batch_remove(
761
+ exec_ctx, calld->recv_initial_metadata,
762
+ calld->recv_initial_metadata->idx.named.authority);
763
+ } else {
764
+ GRPC_ERROR_REF(error);
765
+ }
774
766
  op_deadline = calld->recv_initial_metadata->deadline;
775
767
  if (0 != gpr_time_cmp(op_deadline, gpr_inf_future(op_deadline.clock_type))) {
776
768
  calld->deadline = op_deadline;
777
769
  }
778
- if (calld->host && calld->path) {
770
+ if (calld->host_set && calld->path_set) {
779
771
  /* do nothing */
780
772
  } else {
781
- GRPC_ERROR_UNREF(error);
773
+ grpc_error *src_error = error;
782
774
  error =
783
775
  GRPC_ERROR_CREATE_REFERENCING("Missing :authority or :path", &error, 1);
776
+ GRPC_ERROR_UNREF(src_error);
784
777
  }
785
778
 
786
779
  grpc_closure_run(exec_ctx, calld->on_done_recv_initial_metadata, error);
@@ -887,7 +880,7 @@ static void channel_connectivity_changed(grpc_exec_ctx *exec_ctx, void *cd,
887
880
 
888
881
  static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
889
882
  grpc_call_element *elem,
890
- grpc_call_element_args *args) {
883
+ const grpc_call_element_args *args) {
891
884
  call_data *calld = elem->call_data;
892
885
  channel_data *chand = elem->channel_data;
893
886
  memset(calld, 0, sizeof(call_data));
@@ -911,11 +904,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
911
904
 
912
905
  GPR_ASSERT(calld->state != PENDING);
913
906
 
914
- if (calld->host) {
915
- GRPC_MDSTR_UNREF(exec_ctx, calld->host);
907
+ if (calld->host_set) {
908
+ grpc_slice_unref_internal(exec_ctx, calld->host);
916
909
  }
917
- if (calld->path) {
918
- GRPC_MDSTR_UNREF(exec_ctx, calld->path);
910
+ if (calld->path_set) {
911
+ grpc_slice_unref_internal(exec_ctx, calld->path);
919
912
  }
920
913
  grpc_metadata_array_destroy(&calld->initial_metadata);
921
914
 
@@ -947,11 +940,9 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
947
940
  channel_data *chand = elem->channel_data;
948
941
  if (chand->registered_methods) {
949
942
  for (i = 0; i < chand->registered_method_slots; i++) {
950
- if (chand->registered_methods[i].method) {
951
- GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].method);
952
- }
953
- if (chand->registered_methods[i].host) {
954
- GRPC_MDSTR_UNREF(exec_ctx, chand->registered_methods[i].host);
943
+ grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].method);
944
+ if (chand->registered_methods[i].has_host) {
945
+ grpc_slice_unref_internal(exec_ctx, chand->registered_methods[i].host);
955
946
  }
956
947
  }
957
948
  gpr_free(chand->registered_methods);
@@ -1025,12 +1016,10 @@ void grpc_server_register_non_listening_completion_queue(
1025
1016
  grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved) {
1026
1017
  GRPC_API_TRACE("grpc_server_create(%p, %p)", 2, (args, reserved));
1027
1018
 
1028
- grpc_server *server = gpr_malloc(sizeof(grpc_server));
1019
+ grpc_server *server = gpr_zalloc(sizeof(grpc_server));
1029
1020
 
1030
1021
  GPR_ASSERT(grpc_is_initialized() && "call grpc_init()");
1031
1022
 
1032
- memset(server, 0, sizeof(grpc_server));
1033
-
1034
1023
  gpr_mu_init(&server->mu_global);
1035
1024
  gpr_mu_init(&server->mu_call);
1036
1025
 
@@ -1079,8 +1068,7 @@ void *grpc_server_register_method(
1079
1068
  flags);
1080
1069
  return NULL;
1081
1070
  }
1082
- m = gpr_malloc(sizeof(registered_method));
1083
- memset(m, 0, sizeof(*m));
1071
+ m = gpr_zalloc(sizeof(registered_method));
1084
1072
  m->method = gpr_strdup(method);
1085
1073
  m->host = gpr_strdup(host);
1086
1074
  m->next = server->registered_methods;
@@ -1149,8 +1137,6 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s,
1149
1137
  channel_registered_method *crm;
1150
1138
  grpc_channel *channel;
1151
1139
  channel_data *chand;
1152
- grpc_mdstr *host;
1153
- grpc_mdstr *method;
1154
1140
  uint32_t hash;
1155
1141
  size_t slots;
1156
1142
  uint32_t probes;
@@ -1186,12 +1172,20 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s,
1186
1172
  if (num_registered_methods > 0) {
1187
1173
  slots = 2 * num_registered_methods;
1188
1174
  alloc = sizeof(channel_registered_method) * slots;
1189
- chand->registered_methods = gpr_malloc(alloc);
1190
- memset(chand->registered_methods, 0, alloc);
1175
+ chand->registered_methods = gpr_zalloc(alloc);
1191
1176
  for (rm = s->registered_methods; rm; rm = rm->next) {
1192
- host = rm->host ? grpc_mdstr_from_string(rm->host) : NULL;
1193
- method = grpc_mdstr_from_string(rm->method);
1194
- hash = GRPC_MDSTR_KV_HASH(host ? host->hash : 0, method->hash);
1177
+ grpc_slice host;
1178
+ bool has_host;
1179
+ grpc_slice method;
1180
+ if (rm->host != NULL) {
1181
+ host = grpc_slice_intern(grpc_slice_from_static_string(rm->host));
1182
+ has_host = true;
1183
+ } else {
1184
+ has_host = false;
1185
+ }
1186
+ method = grpc_slice_intern(grpc_slice_from_static_string(rm->method));
1187
+ hash = GRPC_MDSTR_KV_HASH(has_host ? grpc_slice_hash(host) : 0,
1188
+ grpc_slice_hash(method));
1195
1189
  for (probes = 0; chand->registered_methods[(hash + probes) % slots]
1196
1190
  .server_registered_method != NULL;
1197
1191
  probes++)
@@ -1200,7 +1194,10 @@ void grpc_server_setup_transport(grpc_exec_ctx *exec_ctx, grpc_server *s,
1200
1194
  crm = &chand->registered_methods[(hash + probes) % slots];
1201
1195
  crm->server_registered_method = rm;
1202
1196
  crm->flags = rm->flags;
1203
- crm->host = host;
1197
+ crm->has_host = has_host;
1198
+ if (has_host) {
1199
+ crm->host = host;
1200
+ }
1204
1201
  crm->method = method;
1205
1202
  }
1206
1203
  GPR_ASSERT(slots <= UINT32_MAX);
@@ -34,40 +34,71 @@
34
34
  #include <stdlib.h>
35
35
  #include <string.h>
36
36
 
37
+ #include <grpc/grpc.h>
38
+ #include <grpc/support/alloc.h>
37
39
  #include <grpc/support/port_platform.h>
38
40
 
39
- static int conforms_to(const char *s, size_t len, const uint8_t *legal_bits) {
40
- const char *p = s;
41
- const char *e = s + len;
41
+ #include "src/core/lib/iomgr/error.h"
42
+ #include "src/core/lib/slice/slice_string_helpers.h"
43
+
44
+ static grpc_error *conforms_to(grpc_slice slice, const uint8_t *legal_bits,
45
+ const char *err_desc) {
46
+ const uint8_t *p = GRPC_SLICE_START_PTR(slice);
47
+ const uint8_t *e = GRPC_SLICE_END_PTR(slice);
42
48
  for (; p != e; p++) {
43
- int idx = (uint8_t)*p;
49
+ int idx = *p;
44
50
  int byte = idx / 8;
45
51
  int bit = idx % 8;
46
- if ((legal_bits[byte] & (1 << bit)) == 0) return 0;
52
+ if ((legal_bits[byte] & (1 << bit)) == 0) {
53
+ char *dump = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
54
+ grpc_error *error = grpc_error_set_str(
55
+ grpc_error_set_int(GRPC_ERROR_CREATE(err_desc), GRPC_ERROR_INT_OFFSET,
56
+ p - GRPC_SLICE_START_PTR(slice)),
57
+ GRPC_ERROR_STR_RAW_BYTES, dump);
58
+ gpr_free(dump);
59
+ return error;
60
+ }
47
61
  }
48
- return 1;
62
+ return GRPC_ERROR_NONE;
63
+ }
64
+
65
+ static int error2int(grpc_error *error) {
66
+ int r = (error == GRPC_ERROR_NONE);
67
+ GRPC_ERROR_UNREF(error);
68
+ return r;
49
69
  }
50
70
 
51
- int grpc_header_key_is_legal(const char *key, size_t length) {
71
+ grpc_error *grpc_validate_header_key_is_legal(grpc_slice slice) {
52
72
  static const uint8_t legal_header_bits[256 / 8] = {
53
73
  0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0xff, 0x03, 0x00, 0x00, 0x00,
54
74
  0x80, 0xfe, 0xff, 0xff, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
55
75
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
56
- if (length == 0 || key[0] == ':') {
57
- return 0;
76
+ if (GRPC_SLICE_LENGTH(slice) == 0) {
77
+ return GRPC_ERROR_CREATE("Metadata keys cannot be zero length");
78
+ }
79
+ if (GRPC_SLICE_START_PTR(slice)[0] == ':') {
80
+ return GRPC_ERROR_CREATE("Metadata keys cannot start with :");
58
81
  }
59
- return conforms_to(key, length, legal_header_bits);
82
+ return conforms_to(slice, legal_header_bits, "Illegal header key");
60
83
  }
61
84
 
62
- int grpc_header_nonbin_value_is_legal(const char *value, size_t length) {
85
+ int grpc_header_key_is_legal(grpc_slice slice) {
86
+ return error2int(grpc_validate_header_key_is_legal(slice));
87
+ }
88
+
89
+ grpc_error *grpc_validate_header_nonbin_value_is_legal(grpc_slice slice) {
63
90
  static const uint8_t legal_header_bits[256 / 8] = {
64
91
  0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
65
92
  0xff, 0xff, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
66
93
  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
67
- return conforms_to(value, length, legal_header_bits);
94
+ return conforms_to(slice, legal_header_bits, "Illegal header value");
95
+ }
96
+
97
+ int grpc_header_nonbin_value_is_legal(grpc_slice slice) {
98
+ return error2int(grpc_validate_header_nonbin_value_is_legal(slice));
68
99
  }
69
100
 
70
- int grpc_is_binary_header(const char *key, size_t length) {
71
- if (length < 5) return 0;
72
- return 0 == memcmp(key + length - 4, "-bin", 4);
101
+ int grpc_is_binary_header(grpc_slice slice) {
102
+ if (GRPC_SLICE_LENGTH(slice) < 5) return 0;
103
+ return 0 == memcmp(GRPC_SLICE_END_PTR(slice) - 4, "-bin", 4);
73
104
  }