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
@@ -75,7 +75,7 @@ typedef struct {
75
75
  gpr_refcount ref;
76
76
  } secure_endpoint;
77
77
 
78
- int grpc_trace_secure_endpoint = 0;
78
+ grpc_tracer_flag grpc_trace_secure_endpoint = GRPC_TRACER_INITIALIZER(false);
79
79
 
80
80
  static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
81
81
  secure_endpoint *ep = secure_ep;
@@ -130,14 +130,14 @@ static void secure_endpoint_ref(secure_endpoint *ep) { gpr_ref(&ep->ref); }
130
130
  static void flush_read_staging_buffer(secure_endpoint *ep, uint8_t **cur,
131
131
  uint8_t **end) {
132
132
  grpc_slice_buffer_add(ep->read_buffer, ep->read_staging_buffer);
133
- ep->read_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE);
133
+ ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
134
134
  *cur = GRPC_SLICE_START_PTR(ep->read_staging_buffer);
135
135
  *end = GRPC_SLICE_END_PTR(ep->read_staging_buffer);
136
136
  }
137
137
 
138
138
  static void call_read_cb(grpc_exec_ctx *exec_ctx, secure_endpoint *ep,
139
139
  grpc_error *error) {
140
- if (grpc_trace_secure_endpoint) {
140
+ if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
141
141
  size_t i;
142
142
  for (i = 0; i < ep->read_buffer->count; i++) {
143
143
  char *data = grpc_dump_slice(ep->read_buffer->slices[i],
@@ -252,7 +252,7 @@ static void endpoint_read(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
252
252
  static void flush_write_staging_buffer(secure_endpoint *ep, uint8_t **cur,
253
253
  uint8_t **end) {
254
254
  grpc_slice_buffer_add(&ep->output_buffer, ep->write_staging_buffer);
255
- ep->write_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE);
255
+ ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
256
256
  *cur = GRPC_SLICE_START_PTR(ep->write_staging_buffer);
257
257
  *end = GRPC_SLICE_END_PTR(ep->write_staging_buffer);
258
258
  }
@@ -269,7 +269,7 @@ static void endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
269
269
 
270
270
  grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &ep->output_buffer);
271
271
 
272
- if (grpc_trace_secure_endpoint) {
272
+ if (GRPC_TRACER_ON(grpc_trace_secure_endpoint)) {
273
273
  for (i = 0; i < slices->count; i++) {
274
274
  char *data =
275
275
  grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
@@ -415,8 +415,8 @@ grpc_endpoint *grpc_secure_endpoint_create(
415
415
  grpc_slice_buffer_add(&ep->leftover_bytes,
416
416
  grpc_slice_ref_internal(leftover_slices[i]));
417
417
  }
418
- ep->write_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE);
419
- ep->read_staging_buffer = grpc_slice_malloc(STAGING_BUFFER_SIZE);
418
+ ep->write_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
419
+ ep->read_staging_buffer = GRPC_SLICE_MALLOC(STAGING_BUFFER_SIZE);
420
420
  grpc_slice_buffer_init(&ep->output_buffer);
421
421
  grpc_slice_buffer_init(&ep->source_buffer);
422
422
  ep->read_buffer = NULL;
@@ -39,7 +39,7 @@
39
39
 
40
40
  struct tsi_frame_protector;
41
41
 
42
- extern int grpc_trace_secure_endpoint;
42
+ extern grpc_tracer_flag grpc_trace_secure_endpoint;
43
43
 
44
44
  /* Takes ownership of protector and to_wrap, and refs leftover_slices. */
45
45
  grpc_endpoint *grpc_secure_endpoint_create(
@@ -78,9 +78,8 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) {
78
78
 
79
79
  /* Defines the cipher suites that we accept by default. All these cipher suites
80
80
  are compliant with HTTP2. */
81
- #define GRPC_SSL_CIPHER_SUITES \
82
- "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-" \
83
- "SHA384:ECDHE-RSA-AES256-GCM-SHA384"
81
+ #define GRPC_SSL_CIPHER_SUITES \
82
+ "ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384"
84
83
 
85
84
  static gpr_once cipher_suites_once = GPR_ONCE_INIT;
86
85
  static const char *cipher_suites = NULL;
@@ -423,12 +422,8 @@ grpc_channel_security_connector *grpc_fake_channel_security_connector_create(
423
422
  c->base.check_call_host = fake_channel_check_call_host;
424
423
  c->base.add_handshakers = fake_channel_add_handshakers;
425
424
  c->target = gpr_strdup(target);
426
- const grpc_arg *expected_target_arg =
427
- grpc_channel_args_find(args, GRPC_ARG_FAKE_SECURITY_EXPECTED_TARGETS);
428
- if (expected_target_arg != NULL) {
429
- GPR_ASSERT(expected_target_arg->type == GRPC_ARG_STRING);
430
- c->expected_targets = gpr_strdup(expected_target_arg->value.string);
431
- }
425
+ const char *expected_targets = grpc_fake_transport_get_expected_targets(args);
426
+ c->expected_targets = gpr_strdup(expected_targets);
432
427
  c->is_lb_channel = (grpc_lb_targets_info_find_in_args(args) != NULL);
433
428
  return &c->base;
434
429
  }
@@ -699,6 +694,7 @@ static grpc_security_connector_vtable ssl_channel_vtable = {
699
694
  static grpc_security_connector_vtable ssl_server_vtable = {
700
695
  ssl_server_destroy, ssl_server_check_peer};
701
696
 
697
+ /* returns a NULL terminated slice. */
702
698
  static grpc_slice compute_default_pem_root_certs_once(void) {
703
699
  grpc_slice result = grpc_empty_slice();
704
700
 
@@ -707,7 +703,7 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
707
703
  gpr_getenv(GRPC_DEFAULT_SSL_ROOTS_FILE_PATH_ENV_VAR);
708
704
  if (default_root_certs_path != NULL) {
709
705
  GRPC_LOG_IF_ERROR("load_file",
710
- grpc_load_file(default_root_certs_path, 0, &result));
706
+ grpc_load_file(default_root_certs_path, 1, &result));
711
707
  gpr_free(default_root_certs_path);
712
708
  }
713
709
 
@@ -718,15 +714,18 @@ static grpc_slice compute_default_pem_root_certs_once(void) {
718
714
  ovrd_res = ssl_roots_override_cb(&pem_root_certs);
719
715
  if (ovrd_res == GRPC_SSL_ROOTS_OVERRIDE_OK) {
720
716
  GPR_ASSERT(pem_root_certs != NULL);
721
- result = grpc_slice_new(pem_root_certs, strlen(pem_root_certs), gpr_free);
717
+ result = grpc_slice_from_copied_buffer(
718
+ pem_root_certs,
719
+ strlen(pem_root_certs) + 1); // NULL terminator.
722
720
  }
721
+ gpr_free(pem_root_certs);
723
722
  }
724
723
 
725
724
  /* Fall back to installed certs if needed. */
726
725
  if (GRPC_SLICE_IS_EMPTY(result) &&
727
726
  ovrd_res != GRPC_SSL_ROOTS_OVERRIDE_FAIL_PERMANENTLY) {
728
727
  GRPC_LOG_IF_ERROR("load_file",
729
- grpc_load_file(installed_roots_path, 0, &result));
728
+ grpc_load_file(installed_roots_path, 1, &result));
730
729
  }
731
730
  return result;
732
731
  }
@@ -766,13 +765,14 @@ get_tsi_client_certificate_request_type(
766
765
  }
767
766
  }
768
767
 
769
- size_t grpc_get_default_ssl_roots(const unsigned char **pem_root_certs) {
768
+ const char *grpc_get_default_ssl_roots(void) {
770
769
  /* TODO(jboeuf@google.com): Maybe revisit the approach which consists in
771
770
  loading all the roots once for the lifetime of the process. */
772
771
  static gpr_once once = GPR_ONCE_INIT;
773
772
  gpr_once_init(&once, init_default_pem_root_certs);
774
- *pem_root_certs = GRPC_SLICE_START_PTR(default_pem_root_certs);
775
- return GRPC_SLICE_LENGTH(default_pem_root_certs);
773
+ return GRPC_SLICE_IS_EMPTY(default_pem_root_certs)
774
+ ? NULL
775
+ : (const char *)GRPC_SLICE_START_PTR(default_pem_root_certs);
776
776
  }
777
777
 
778
778
  grpc_security_status grpc_ssl_channel_security_connector_create(
@@ -780,22 +780,16 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
780
780
  const grpc_ssl_config *config, const char *target_name,
781
781
  const char *overridden_target_name, grpc_channel_security_connector **sc) {
782
782
  size_t num_alpn_protocols = grpc_chttp2_num_alpn_versions();
783
- const unsigned char **alpn_protocol_strings =
783
+ const char **alpn_protocol_strings =
784
784
  gpr_malloc(sizeof(const char *) * num_alpn_protocols);
785
- unsigned char *alpn_protocol_string_lengths =
786
- gpr_malloc(sizeof(unsigned char) * num_alpn_protocols);
787
785
  tsi_result result = TSI_OK;
788
786
  grpc_ssl_channel_security_connector *c;
789
787
  size_t i;
790
- const unsigned char *pem_root_certs;
791
- size_t pem_root_certs_size;
788
+ const char *pem_root_certs;
792
789
  char *port;
793
790
 
794
791
  for (i = 0; i < num_alpn_protocols; i++) {
795
- alpn_protocol_strings[i] =
796
- (const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
797
- alpn_protocol_string_lengths[i] =
798
- (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
792
+ alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
799
793
  }
800
794
 
801
795
  if (config == NULL || target_name == NULL) {
@@ -803,14 +797,13 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
803
797
  goto error;
804
798
  }
805
799
  if (config->pem_root_certs == NULL) {
806
- pem_root_certs_size = grpc_get_default_ssl_roots(&pem_root_certs);
807
- if (pem_root_certs == NULL || pem_root_certs_size == 0) {
800
+ pem_root_certs = grpc_get_default_ssl_roots();
801
+ if (pem_root_certs == NULL) {
808
802
  gpr_log(GPR_ERROR, "Could not get default pem root certs.");
809
803
  goto error;
810
804
  }
811
805
  } else {
812
806
  pem_root_certs = config->pem_root_certs;
813
- pem_root_certs_size = config->pem_root_certs_size;
814
807
  }
815
808
 
816
809
  c = gpr_zalloc(sizeof(grpc_ssl_channel_security_connector));
@@ -827,11 +820,12 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
827
820
  if (overridden_target_name != NULL) {
828
821
  c->overridden_target_name = gpr_strdup(overridden_target_name);
829
822
  }
823
+
824
+ bool has_key_cert_pair = config->pem_key_cert_pair.private_key != NULL &&
825
+ config->pem_key_cert_pair.cert_chain != NULL;
830
826
  result = tsi_create_ssl_client_handshaker_factory(
831
- config->pem_private_key, config->pem_private_key_size,
832
- config->pem_cert_chain, config->pem_cert_chain_size, pem_root_certs,
833
- pem_root_certs_size, ssl_cipher_suites(), alpn_protocol_strings,
834
- alpn_protocol_string_lengths, (uint16_t)num_alpn_protocols,
827
+ has_key_cert_pair ? &config->pem_key_cert_pair : NULL, pem_root_certs,
828
+ ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
835
829
  &c->handshaker_factory);
836
830
  if (result != TSI_OK) {
837
831
  gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
@@ -842,12 +836,10 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
842
836
  }
843
837
  *sc = &c->base;
844
838
  gpr_free((void *)alpn_protocol_strings);
845
- gpr_free(alpn_protocol_string_lengths);
846
839
  return GRPC_SECURITY_OK;
847
840
 
848
841
  error:
849
842
  gpr_free((void *)alpn_protocol_strings);
850
- gpr_free(alpn_protocol_string_lengths);
851
843
  return GRPC_SECURITY_ERROR;
852
844
  }
853
845
 
@@ -855,19 +847,14 @@ grpc_security_status grpc_ssl_server_security_connector_create(
855
847
  grpc_exec_ctx *exec_ctx, const grpc_ssl_server_config *config,
856
848
  grpc_server_security_connector **sc) {
857
849
  size_t num_alpn_protocols = grpc_chttp2_num_alpn_versions();
858
- const unsigned char **alpn_protocol_strings =
850
+ const char **alpn_protocol_strings =
859
851
  gpr_malloc(sizeof(const char *) * num_alpn_protocols);
860
- unsigned char *alpn_protocol_string_lengths =
861
- gpr_malloc(sizeof(unsigned char) * num_alpn_protocols);
862
852
  tsi_result result = TSI_OK;
863
853
  grpc_ssl_server_security_connector *c;
864
854
  size_t i;
865
855
 
866
856
  for (i = 0; i < num_alpn_protocols; i++) {
867
- alpn_protocol_strings[i] =
868
- (const unsigned char *)grpc_chttp2_get_alpn_version_index(i);
869
- alpn_protocol_string_lengths[i] =
870
- (unsigned char)strlen(grpc_chttp2_get_alpn_version_index(i));
857
+ alpn_protocol_strings[i] = grpc_chttp2_get_alpn_version_index(i);
871
858
  }
872
859
 
873
860
  if (config == NULL || config->num_key_cert_pairs == 0) {
@@ -880,15 +867,11 @@ grpc_security_status grpc_ssl_server_security_connector_create(
880
867
  c->base.base.url_scheme = GRPC_SSL_URL_SCHEME;
881
868
  c->base.base.vtable = &ssl_server_vtable;
882
869
  result = tsi_create_ssl_server_handshaker_factory_ex(
883
- (const unsigned char **)config->pem_private_keys,
884
- config->pem_private_keys_sizes,
885
- (const unsigned char **)config->pem_cert_chains,
886
- config->pem_cert_chains_sizes, config->num_key_cert_pairs,
887
- config->pem_root_certs, config->pem_root_certs_size,
888
- get_tsi_client_certificate_request_type(
889
- config->client_certificate_request),
890
- ssl_cipher_suites(), alpn_protocol_strings, alpn_protocol_string_lengths,
891
- (uint16_t)num_alpn_protocols, &c->handshaker_factory);
870
+ config->pem_key_cert_pairs, config->num_key_cert_pairs,
871
+ config->pem_root_certs, get_tsi_client_certificate_request_type(
872
+ config->client_certificate_request),
873
+ ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
874
+ &c->handshaker_factory);
892
875
  if (result != TSI_OK) {
893
876
  gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
894
877
  tsi_result_to_string(result));
@@ -899,11 +882,9 @@ grpc_security_status grpc_ssl_server_security_connector_create(
899
882
  c->base.add_handshakers = ssl_server_add_handshakers;
900
883
  *sc = &c->base;
901
884
  gpr_free((void *)alpn_protocol_strings);
902
- gpr_free(alpn_protocol_string_lengths);
903
885
  return GRPC_SECURITY_OK;
904
886
 
905
887
  error:
906
888
  gpr_free((void *)alpn_protocol_strings);
907
- gpr_free(alpn_protocol_string_lengths);
908
889
  return GRPC_SECURITY_ERROR;
909
890
  }
@@ -34,11 +34,14 @@
34
34
  #ifndef GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_CONNECTOR_H
35
35
  #define GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURITY_CONNECTOR_H
36
36
 
37
+ #include <stdbool.h>
38
+
37
39
  #include <grpc/grpc_security.h>
38
40
 
39
41
  #include "src/core/lib/channel/handshaker.h"
40
42
  #include "src/core/lib/iomgr/endpoint.h"
41
43
  #include "src/core/lib/iomgr/tcp_server.h"
44
+ #include "src/core/tsi/ssl_transport_security.h"
42
45
  #include "src/core/tsi/transport_security_interface.h"
43
46
 
44
47
  /* --- status enum. --- */
@@ -184,13 +187,10 @@ grpc_server_security_connector *grpc_fake_server_security_connector_create(
184
187
  void);
185
188
 
186
189
  /* Config for ssl clients. */
190
+
187
191
  typedef struct {
188
- unsigned char *pem_private_key;
189
- size_t pem_private_key_size;
190
- unsigned char *pem_cert_chain;
191
- size_t pem_cert_chain_size;
192
- unsigned char *pem_root_certs;
193
- size_t pem_root_certs_size;
192
+ tsi_ssl_pem_key_cert_pair pem_key_cert_pair;
193
+ char *pem_root_certs;
194
194
  } grpc_ssl_config;
195
195
 
196
196
  /* Creates an SSL channel_security_connector.
@@ -211,21 +211,17 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
211
211
  const grpc_ssl_config *config, const char *target_name,
212
212
  const char *overridden_target_name, grpc_channel_security_connector **sc);
213
213
 
214
- /* Gets the default ssl roots. */
215
- size_t grpc_get_default_ssl_roots(const unsigned char **pem_root_certs);
214
+ /* Gets the default ssl roots. Returns NULL if not found. */
215
+ const char *grpc_get_default_ssl_roots(void);
216
216
 
217
217
  /* Exposed for TESTING ONLY!. */
218
218
  grpc_slice grpc_get_default_ssl_roots_for_testing(void);
219
219
 
220
220
  /* Config for ssl servers. */
221
221
  typedef struct {
222
- unsigned char **pem_private_keys;
223
- size_t *pem_private_keys_sizes;
224
- unsigned char **pem_cert_chains;
225
- size_t *pem_cert_chains_sizes;
222
+ tsi_ssl_pem_key_cert_pair *pem_key_cert_pairs;
226
223
  size_t num_key_cert_pairs;
227
- unsigned char *pem_root_certs;
228
- size_t pem_root_certs_size;
224
+ char *pem_root_certs;
229
225
  grpc_ssl_client_certificate_request_type client_certificate_request;
230
226
  } grpc_ssl_server_config;
231
227
 
@@ -202,7 +202,7 @@ static int decode_group(const unsigned char *codes, size_t num_codes,
202
202
 
203
203
  grpc_slice grpc_base64_decode_with_len(grpc_exec_ctx *exec_ctx, const char *b64,
204
204
  size_t b64_len, int url_safe) {
205
- grpc_slice result = grpc_slice_malloc(b64_len);
205
+ grpc_slice result = GRPC_SLICE_MALLOC(b64_len);
206
206
  unsigned char *current = GRPC_SLICE_START_PTR(result);
207
207
  size_t result_size = 0;
208
208
  unsigned char codes[4];
@@ -71,7 +71,7 @@ grpc_slice grpc_percent_encode_slice(grpc_slice slice,
71
71
  return grpc_slice_ref_internal(slice);
72
72
  }
73
73
  // second pass: actually encode
74
- grpc_slice out = grpc_slice_malloc(output_length);
74
+ grpc_slice out = GRPC_SLICE_MALLOC(output_length);
75
75
  uint8_t *q = GRPC_SLICE_START_PTR(out);
76
76
  for (p = slice_start; p < slice_end; p++) {
77
77
  if (is_unreserved_character(*p, unreserved_bytes)) {
@@ -125,7 +125,7 @@ bool grpc_strict_percent_decode_slice(grpc_slice slice_in,
125
125
  return true;
126
126
  }
127
127
  p = GRPC_SLICE_START_PTR(slice_in);
128
- *slice_out = grpc_slice_malloc(out_length);
128
+ *slice_out = GRPC_SLICE_MALLOC(out_length);
129
129
  uint8_t *q = GRPC_SLICE_START_PTR(*slice_out);
130
130
  while (p != in_end) {
131
131
  if (*p == '%') {
@@ -163,7 +163,7 @@ grpc_slice grpc_permissive_percent_decode_slice(grpc_slice slice_in) {
163
163
  return grpc_slice_ref_internal(slice_in);
164
164
  }
165
165
  p = GRPC_SLICE_START_PTR(slice_in);
166
- grpc_slice out = grpc_slice_malloc(out_length);
166
+ grpc_slice out = GRPC_SLICE_MALLOC(out_length);
167
167
  uint8_t *q = GRPC_SLICE_START_PTR(out);
168
168
  while (p != in_end) {
169
169
  if (*p == '%') {
@@ -55,6 +55,13 @@ grpc_slice grpc_empty_slice(void) {
55
55
  return out;
56
56
  }
57
57
 
58
+ grpc_slice grpc_slice_copy(grpc_slice s) {
59
+ grpc_slice out = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(s));
60
+ memcpy(GRPC_SLICE_START_PTR(out), GRPC_SLICE_START_PTR(s),
61
+ GRPC_SLICE_LENGTH(s));
62
+ return out;
63
+ }
64
+
58
65
  grpc_slice grpc_slice_ref_internal(grpc_slice slice) {
59
66
  if (slice.refcount) {
60
67
  slice.refcount->vtable->ref(slice.refcount);
@@ -198,7 +205,7 @@ grpc_slice grpc_slice_new_with_len(void *p, size_t len,
198
205
 
199
206
  grpc_slice grpc_slice_from_copied_buffer(const char *source, size_t length) {
200
207
  if (length == 0) return grpc_empty_slice();
201
- grpc_slice slice = grpc_slice_malloc(length);
208
+ grpc_slice slice = GRPC_SLICE_MALLOC(length);
202
209
  memcpy(GRPC_SLICE_START_PTR(slice), source, length);
203
210
  return slice;
204
211
  }
@@ -228,35 +235,42 @@ static const grpc_slice_refcount_vtable malloc_vtable = {
228
235
  malloc_ref, malloc_unref, grpc_slice_default_eq_impl,
229
236
  grpc_slice_default_hash_impl};
230
237
 
238
+ grpc_slice grpc_slice_malloc_large(size_t length) {
239
+ grpc_slice slice;
240
+
241
+ /* Memory layout used by the slice created here:
242
+
243
+ +-----------+----------------------------------------------------------+
244
+ | refcount | bytes |
245
+ +-----------+----------------------------------------------------------+
246
+
247
+ refcount is a malloc_refcount
248
+ bytes is an array of bytes of the requested length
249
+ Both parts are placed in the same allocation returned from gpr_malloc */
250
+ malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
251
+
252
+ /* Initial refcount on rc is 1 - and it's up to the caller to release
253
+ this reference. */
254
+ gpr_ref_init(&rc->refs, 1);
255
+
256
+ rc->base.vtable = &malloc_vtable;
257
+ rc->base.sub_refcount = &rc->base;
258
+
259
+ /* Build up the slice to be returned. */
260
+ /* The slices refcount points back to the allocated block. */
261
+ slice.refcount = &rc->base;
262
+ /* The data bytes are placed immediately after the refcount struct */
263
+ slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
264
+ /* And the length of the block is set to the requested length */
265
+ slice.data.refcounted.length = length;
266
+ return slice;
267
+ }
268
+
231
269
  grpc_slice grpc_slice_malloc(size_t length) {
232
270
  grpc_slice slice;
233
271
 
234
272
  if (length > sizeof(slice.data.inlined.bytes)) {
235
- /* Memory layout used by the slice created here:
236
-
237
- +-----------+----------------------------------------------------------+
238
- | refcount | bytes |
239
- +-----------+----------------------------------------------------------+
240
-
241
- refcount is a malloc_refcount
242
- bytes is an array of bytes of the requested length
243
- Both parts are placed in the same allocation returned from gpr_malloc */
244
- malloc_refcount *rc = gpr_malloc(sizeof(malloc_refcount) + length);
245
-
246
- /* Initial refcount on rc is 1 - and it's up to the caller to release
247
- this reference. */
248
- gpr_ref_init(&rc->refs, 1);
249
-
250
- rc->base.vtable = &malloc_vtable;
251
- rc->base.sub_refcount = &rc->base;
252
-
253
- /* Build up the slice to be returned. */
254
- /* The slices refcount points back to the allocated block. */
255
- slice.refcount = &rc->base;
256
- /* The data bytes are placed immediately after the refcount struct */
257
- slice.data.refcounted.bytes = (uint8_t *)(rc + 1);
258
- /* And the length of the block is set to the requested length */
259
- slice.data.refcounted.length = length;
273
+ return grpc_slice_malloc_large(length);
260
274
  } else {
261
275
  /* small slice: just inline the data */
262
276
  slice.refcount = NULL;
@@ -306,7 +320,8 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) {
306
320
  return subset;
307
321
  }
308
322
 
309
- grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
323
+ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice *source, size_t split,
324
+ grpc_slice_ref_whom ref_whom) {
310
325
  grpc_slice tail;
311
326
 
312
327
  if (source->refcount == NULL) {
@@ -320,28 +335,46 @@ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
320
335
  } else {
321
336
  size_t tail_length = source->data.refcounted.length - split;
322
337
  GPR_ASSERT(source->data.refcounted.length >= split);
323
- if (tail_length < sizeof(tail.data.inlined.bytes)) {
338
+ if (tail_length < sizeof(tail.data.inlined.bytes) &&
339
+ ref_whom != GRPC_SLICE_REF_TAIL) {
324
340
  /* Copy out the bytes - it'll be cheaper than refcounting */
325
341
  tail.refcount = NULL;
326
342
  tail.data.inlined.length = (uint8_t)tail_length;
327
343
  memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
328
344
  tail_length);
345
+ source->refcount = source->refcount->sub_refcount;
329
346
  } else {
330
347
  /* Build the result */
331
- tail.refcount = source->refcount->sub_refcount;
332
- /* Bump the refcount */
333
- tail.refcount->vtable->ref(tail.refcount);
348
+ switch (ref_whom) {
349
+ case GRPC_SLICE_REF_TAIL:
350
+ tail.refcount = source->refcount->sub_refcount;
351
+ source->refcount = &noop_refcount;
352
+ break;
353
+ case GRPC_SLICE_REF_HEAD:
354
+ tail.refcount = &noop_refcount;
355
+ source->refcount = source->refcount->sub_refcount;
356
+ break;
357
+ case GRPC_SLICE_REF_BOTH:
358
+ tail.refcount = source->refcount->sub_refcount;
359
+ source->refcount = source->refcount->sub_refcount;
360
+ /* Bump the refcount */
361
+ tail.refcount->vtable->ref(tail.refcount);
362
+ break;
363
+ }
334
364
  /* Point into the source array */
335
365
  tail.data.refcounted.bytes = source->data.refcounted.bytes + split;
336
366
  tail.data.refcounted.length = tail_length;
337
367
  }
338
- source->refcount = source->refcount->sub_refcount;
339
368
  source->data.refcounted.length = split;
340
369
  }
341
370
 
342
371
  return tail;
343
372
  }
344
373
 
374
+ grpc_slice grpc_slice_split_tail(grpc_slice *source, size_t split) {
375
+ return grpc_slice_split_tail_maybe_ref(source, split, GRPC_SLICE_REF_BOTH);
376
+ }
377
+
345
378
  grpc_slice grpc_slice_split_head(grpc_slice *source, size_t split) {
346
379
  grpc_slice head;
347
380
 
@@ -459,7 +492,7 @@ int grpc_slice_slice(grpc_slice haystack, grpc_slice needle) {
459
492
  }
460
493
 
461
494
  grpc_slice grpc_slice_dup(grpc_slice a) {
462
- grpc_slice copy = grpc_slice_malloc(GRPC_SLICE_LENGTH(a));
495
+ grpc_slice copy = GRPC_SLICE_MALLOC(GRPC_SLICE_LENGTH(a));
463
496
  memcpy(GRPC_SLICE_START_PTR(copy), GRPC_SLICE_START_PTR(a),
464
497
  GRPC_SLICE_LENGTH(a));
465
498
  return copy;