grpc 1.3.4 → 1.4.0

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

Potentially problematic release.


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

Files changed (286) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +581 -450
  3. data/include/grpc/census.h +49 -49
  4. data/include/grpc/grpc.h +16 -70
  5. data/include/grpc/grpc_security.h +59 -59
  6. data/include/grpc/grpc_security_constants.h +9 -9
  7. data/include/grpc/impl/codegen/atm.h +1 -1
  8. data/include/grpc/impl/codegen/atm_windows.h +4 -4
  9. data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -2
  10. data/include/grpc/impl/codegen/compression_types.h +4 -5
  11. data/include/grpc/impl/codegen/gpr_slice.h +5 -5
  12. data/include/grpc/impl/codegen/gpr_types.h +6 -7
  13. data/include/grpc/impl/codegen/grpc_types.h +128 -59
  14. data/include/grpc/impl/codegen/port_platform.h +6 -0
  15. data/include/grpc/impl/codegen/propagation_bits.h +2 -2
  16. data/include/grpc/impl/codegen/slice.h +13 -12
  17. data/include/grpc/impl/codegen/status.h +23 -18
  18. data/include/grpc/impl/codegen/sync.h +1 -1
  19. data/include/grpc/load_reporting.h +6 -6
  20. data/include/grpc/slice.h +47 -25
  21. data/include/grpc/slice_buffer.h +18 -14
  22. data/include/grpc/support/alloc.h +7 -7
  23. data/include/grpc/support/cmdline.h +10 -10
  24. data/include/grpc/support/cpu.h +3 -3
  25. data/include/grpc/support/histogram.h +1 -1
  26. data/include/grpc/support/host_port.h +2 -2
  27. data/include/grpc/support/log.h +9 -9
  28. data/include/grpc/support/log_windows.h +1 -1
  29. data/include/grpc/support/string_util.h +3 -3
  30. data/include/grpc/support/subprocess.h +3 -3
  31. data/include/grpc/support/sync.h +31 -31
  32. data/include/grpc/support/thd.h +11 -11
  33. data/include/grpc/support/time.h +12 -12
  34. data/include/grpc/support/tls.h +1 -1
  35. data/include/grpc/support/tls_gcc.h +2 -2
  36. data/include/grpc/support/tls_msvc.h +1 -1
  37. data/include/grpc/support/tls_pthread.h +1 -1
  38. data/include/grpc/support/useful.h +2 -2
  39. data/include/grpc/support/workaround_list.h +46 -0
  40. data/src/core/ext/census/context.c +1 -1
  41. data/src/core/ext/census/intrusive_hash_map.c +319 -0
  42. data/src/core/ext/census/intrusive_hash_map.h +167 -0
  43. data/src/core/ext/census/intrusive_hash_map_internal.h +63 -0
  44. data/src/core/ext/census/resource.c +3 -1
  45. data/src/core/ext/filters/client_channel/channel_connectivity.c +1 -1
  46. data/src/core/ext/filters/client_channel/client_channel.c +173 -103
  47. data/src/core/ext/filters/client_channel/client_channel_plugin.c +3 -2
  48. data/src/core/ext/filters/client_channel/lb_policy.c +2 -1
  49. data/src/core/ext/filters/client_channel/lb_policy.h +8 -7
  50. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +153 -0
  51. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.h +42 -0
  52. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +405 -102
  53. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +133 -0
  54. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +65 -0
  55. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +90 -51
  56. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +7 -1
  57. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +19 -8
  58. data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +63 -34
  59. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +2 -1
  60. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +188 -294
  61. data/src/core/ext/filters/client_channel/lb_policy_factory.c +28 -5
  62. data/src/core/ext/filters/client_channel/lb_policy_factory.h +18 -4
  63. data/src/core/ext/filters/client_channel/parse_address.c +90 -59
  64. data/src/core/ext/filters/client_channel/parse_address.h +17 -8
  65. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +11 -7
  66. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +59 -14
  67. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +6 -0
  68. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +3 -3
  69. data/src/core/ext/filters/client_channel/subchannel.c +20 -17
  70. data/src/core/ext/filters/client_channel/subchannel.h +1 -0
  71. data/src/core/ext/filters/client_channel/subchannel_index.c +11 -1
  72. data/src/core/ext/filters/client_channel/uri_parser.c +36 -22
  73. data/src/core/ext/filters/client_channel/uri_parser.h +1 -1
  74. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.c +42 -17
  75. data/src/core/{lib/channel → ext/filters/deadline}/deadline_filter.h +8 -9
  76. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.c +19 -11
  77. data/src/core/{lib/channel → ext/filters/http/client}/http_client_filter.h +3 -6
  78. data/src/core/ext/filters/http/http_filters_plugin.c +104 -0
  79. data/src/core/{lib/channel/compress_filter.c → ext/filters/http/message_compress/message_compress_filter.c} +124 -23
  80. data/src/core/{lib/channel/compress_filter.h → ext/filters/http/message_compress/message_compress_filter.h} +5 -6
  81. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.c +4 -6
  82. data/src/core/{lib/channel → ext/filters/http/server}/http_server_filter.h +3 -3
  83. data/src/core/ext/filters/load_reporting/load_reporting.c +2 -25
  84. data/src/core/ext/filters/load_reporting/load_reporting_filter.c +26 -1
  85. data/src/core/ext/filters/max_age/max_age_filter.c +14 -14
  86. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.c +91 -47
  87. data/src/core/{lib/channel → ext/filters/message_size}/message_size_filter.h +3 -3
  88. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +223 -0
  89. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.h +40 -0
  90. data/src/core/ext/filters/workarounds/workaround_utils.c +65 -0
  91. data/src/core/ext/filters/workarounds/workaround_utils.h +52 -0
  92. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
  93. data/src/core/ext/transport/chttp2/server/chttp2_server.c +3 -2
  94. data/src/core/ext/transport/chttp2/transport/bin_decoder.c +2 -2
  95. data/src/core/ext/transport/chttp2/transport/bin_encoder.c +3 -3
  96. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +319 -175
  97. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -2
  98. data/src/core/ext/transport/chttp2/transport/frame_data.c +203 -164
  99. data/src/core/ext/transport/chttp2/transport/frame_data.h +8 -14
  100. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +1 -1
  101. data/src/core/ext/transport/chttp2/transport/frame_ping.c +1 -1
  102. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
  103. data/src/core/ext/transport/chttp2/transport/frame_settings.c +5 -5
  104. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +1 -1
  105. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +4 -4
  106. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +2 -4
  107. data/src/core/ext/transport/chttp2/transport/hpack_table.c +4 -3
  108. data/src/core/ext/transport/chttp2/transport/internal.h +50 -33
  109. data/src/core/ext/transport/chttp2/transport/parsing.c +10 -11
  110. data/src/core/ext/transport/chttp2/transport/writing.c +32 -13
  111. data/src/core/lib/channel/channel_args.c +30 -9
  112. data/src/core/lib/channel/channel_args.h +5 -1
  113. data/src/core/lib/channel/channel_stack.c +1 -1
  114. data/src/core/lib/channel/channel_stack.h +2 -2
  115. data/src/core/lib/channel/channel_stack_builder.c +13 -1
  116. data/src/core/lib/channel/channel_stack_builder.h +5 -1
  117. data/src/core/lib/channel/connected_channel.c +3 -1
  118. data/src/core/lib/channel/context.h +2 -2
  119. data/src/core/lib/compression/message_compress.c +2 -2
  120. data/src/core/lib/debug/trace.c +13 -6
  121. data/src/core/lib/debug/trace.h +27 -1
  122. data/src/core/lib/http/httpcli.c +1 -1
  123. data/src/core/lib/http/httpcli_security_connector.c +9 -11
  124. data/src/core/lib/http/parser.c +2 -2
  125. data/src/core/lib/http/parser.h +2 -1
  126. data/src/core/lib/iomgr/combiner.c +6 -6
  127. data/src/core/lib/iomgr/combiner.h +2 -1
  128. data/src/core/lib/iomgr/error.c +12 -5
  129. data/src/core/lib/iomgr/error.h +13 -13
  130. data/src/core/lib/iomgr/ev_epoll1_linux.c +984 -0
  131. data/src/core/lib/iomgr/ev_epoll1_linux.h +44 -0
  132. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +2146 -0
  133. data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.h +43 -0
  134. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +1337 -0
  135. data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.h +43 -0
  136. data/src/core/lib/iomgr/ev_epollex_linux.c +1511 -0
  137. data/src/core/lib/iomgr/ev_epollex_linux.h +43 -0
  138. data/src/core/lib/iomgr/{ev_epoll_linux.c → ev_epollsig_linux.c} +41 -33
  139. data/src/core/lib/iomgr/{ev_epoll_linux.h → ev_epollsig_linux.h} +4 -4
  140. data/src/core/lib/iomgr/ev_poll_posix.c +12 -27
  141. data/src/core/lib/iomgr/ev_poll_posix.h +2 -2
  142. data/src/core/lib/iomgr/ev_posix.c +22 -8
  143. data/src/core/lib/iomgr/ev_posix.h +4 -3
  144. data/src/core/lib/iomgr/ev_windows.c +43 -0
  145. data/src/core/lib/iomgr/exec_ctx.c +5 -0
  146. data/src/core/lib/iomgr/exec_ctx.h +2 -0
  147. data/src/core/lib/iomgr/iomgr.c +4 -0
  148. data/src/core/lib/iomgr/iomgr.h +3 -0
  149. data/src/core/lib/iomgr/is_epollexclusive_available.c +116 -0
  150. data/src/core/lib/iomgr/is_epollexclusive_available.h +41 -0
  151. data/src/core/lib/iomgr/lockfree_event.c +16 -0
  152. data/src/core/lib/iomgr/pollset.h +2 -5
  153. data/src/core/lib/iomgr/pollset_uv.c +1 -1
  154. data/src/core/lib/iomgr/pollset_windows.c +3 -3
  155. data/src/core/lib/iomgr/resource_quota.c +9 -8
  156. data/src/core/lib/iomgr/resource_quota.h +2 -1
  157. data/src/core/lib/iomgr/sockaddr_utils.h +1 -1
  158. data/src/core/lib/iomgr/socket_mutator.h +2 -0
  159. data/src/core/lib/iomgr/sys_epoll_wrapper.h +43 -0
  160. data/src/core/lib/iomgr/tcp_client_posix.c +6 -6
  161. data/src/core/lib/iomgr/tcp_client_uv.c +3 -3
  162. data/src/core/lib/iomgr/tcp_posix.c +7 -7
  163. data/src/core/lib/iomgr/tcp_posix.h +2 -1
  164. data/src/core/lib/iomgr/tcp_server_posix.c +1 -1
  165. data/src/core/lib/iomgr/tcp_uv.c +6 -6
  166. data/src/core/lib/iomgr/tcp_uv.h +2 -1
  167. data/src/core/lib/iomgr/tcp_windows.c +1 -1
  168. data/src/core/lib/iomgr/timer_generic.c +24 -25
  169. data/src/core/lib/iomgr/timer_manager.c +276 -0
  170. data/src/core/lib/iomgr/timer_manager.h +52 -0
  171. data/src/core/lib/iomgr/timer_uv.c +6 -0
  172. data/src/core/lib/iomgr/udp_server.c +42 -9
  173. data/src/core/lib/iomgr/udp_server.h +3 -1
  174. data/src/core/lib/security/credentials/credentials.c +0 -1
  175. data/src/core/lib/security/credentials/fake/fake_credentials.c +23 -0
  176. data/src/core/lib/security/credentials/fake/fake_credentials.h +12 -9
  177. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +1 -1
  178. data/src/core/lib/security/credentials/jwt/jwt_credentials.c +1 -1
  179. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +1 -1
  180. data/src/core/lib/security/credentials/ssl/ssl_credentials.c +24 -53
  181. data/src/core/lib/security/transport/client_auth_filter.c +9 -3
  182. data/src/core/lib/security/transport/secure_endpoint.c +7 -7
  183. data/src/core/lib/security/transport/secure_endpoint.h +1 -1
  184. data/src/core/lib/security/transport/security_connector.c +45 -57
  185. data/src/core/lib/security/transport/security_connector.h +10 -14
  186. data/src/core/lib/security/transport/security_handshaker.c +123 -97
  187. data/src/core/lib/slice/b64.c +1 -1
  188. data/src/core/lib/slice/percent_encoding.c +3 -3
  189. data/src/core/lib/slice/slice.c +66 -33
  190. data/src/core/lib/slice/slice_buffer.c +25 -6
  191. data/src/core/lib/slice/slice_hash_table.c +33 -35
  192. data/src/core/lib/slice/slice_hash_table.h +7 -12
  193. data/src/core/lib/support/atomic.h +45 -0
  194. data/src/core/lib/support/atomic_with_atm.h +70 -0
  195. data/src/core/lib/support/atomic_with_std.h +48 -0
  196. data/src/core/lib/support/avl.c +14 -14
  197. data/src/core/lib/support/cmdline.c +3 -3
  198. data/src/core/lib/support/histogram.c +2 -2
  199. data/src/core/lib/support/host_port.c +1 -1
  200. data/src/core/lib/support/memory.h +74 -0
  201. data/src/core/lib/support/mpscq.c +36 -2
  202. data/src/core/lib/support/mpscq.h +28 -1
  203. data/src/core/lib/support/stack_lockfree.c +3 -36
  204. data/src/core/lib/support/string.c +12 -12
  205. data/src/core/lib/support/string_posix.c +1 -1
  206. data/src/core/lib/support/subprocess_posix.c +2 -2
  207. data/src/core/lib/support/thd_posix.c +1 -1
  208. data/src/core/lib/support/time_posix.c +8 -0
  209. data/src/core/lib/support/tmpfile_posix.c +10 -10
  210. data/src/core/lib/surface/alarm.c +3 -1
  211. data/src/core/lib/surface/api_trace.c +2 -1
  212. data/src/core/lib/surface/api_trace.h +2 -2
  213. data/src/core/lib/surface/byte_buffer_reader.c +1 -1
  214. data/src/core/lib/surface/call.c +65 -22
  215. data/src/core/lib/surface/call.h +4 -2
  216. data/src/core/lib/surface/channel_init.c +2 -19
  217. data/src/core/lib/surface/channel_stack_type.c +18 -0
  218. data/src/core/lib/surface/channel_stack_type.h +2 -0
  219. data/src/core/lib/surface/completion_queue.c +694 -247
  220. data/src/core/lib/surface/completion_queue.h +30 -13
  221. data/src/core/lib/surface/completion_queue_factory.c +24 -9
  222. data/src/core/lib/surface/init.c +1 -52
  223. data/src/core/lib/surface/{lame_client.c → lame_client.cc} +37 -26
  224. data/src/core/lib/surface/server.c +79 -110
  225. data/src/core/lib/surface/server.h +2 -1
  226. data/src/core/lib/surface/version.c +2 -2
  227. data/src/core/lib/transport/bdp_estimator.c +25 -9
  228. data/src/core/lib/transport/bdp_estimator.h +7 -1
  229. data/src/core/lib/transport/byte_stream.c +23 -9
  230. data/src/core/lib/transport/byte_stream.h +15 -6
  231. data/src/core/lib/transport/connectivity_state.c +6 -6
  232. data/src/core/lib/transport/connectivity_state.h +2 -1
  233. data/src/core/lib/transport/service_config.c +6 -13
  234. data/src/core/lib/transport/service_config.h +2 -2
  235. data/src/core/lib/transport/static_metadata.c +403 -389
  236. data/src/core/lib/transport/static_metadata.h +127 -114
  237. data/src/core/plugin_registry/grpc_plugin_registry.c +16 -0
  238. data/src/core/tsi/fake_transport_security.c +5 -4
  239. data/src/core/tsi/ssl_transport_security.c +71 -82
  240. data/src/core/tsi/ssl_transport_security.h +39 -61
  241. data/src/core/tsi/transport_security.c +83 -2
  242. data/src/core/tsi/transport_security.h +27 -2
  243. data/src/core/tsi/transport_security_adapter.c +236 -0
  244. data/src/core/tsi/transport_security_adapter.h +62 -0
  245. data/src/core/tsi/transport_security_interface.h +179 -66
  246. data/src/ruby/ext/grpc/extconf.rb +2 -1
  247. data/src/ruby/ext/grpc/rb_byte_buffer.c +8 -6
  248. data/src/ruby/ext/grpc/rb_call.c +56 -48
  249. data/src/ruby/ext/grpc/rb_call.h +3 -4
  250. data/src/ruby/ext/grpc/rb_call_credentials.c +23 -22
  251. data/src/ruby/ext/grpc/rb_channel.c +2 -3
  252. data/src/ruby/ext/grpc/rb_channel_args.c +11 -9
  253. data/src/ruby/ext/grpc/rb_channel_credentials.c +16 -12
  254. data/src/ruby/ext/grpc/rb_completion_queue.c +7 -9
  255. data/src/ruby/ext/grpc/rb_compression_options.c +7 -6
  256. data/src/ruby/ext/grpc/rb_event_thread.c +10 -12
  257. data/src/ruby/ext/grpc/rb_event_thread.h +1 -2
  258. data/src/ruby/ext/grpc/rb_grpc.c +11 -15
  259. data/src/ruby/ext/grpc/rb_grpc.h +2 -2
  260. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +16 -6
  261. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +25 -10
  262. data/src/ruby/ext/grpc/rb_server.c +26 -28
  263. data/src/ruby/lib/grpc/grpc.rb +1 -1
  264. data/src/ruby/lib/grpc/version.rb +1 -1
  265. data/third_party/cares/config_linux/ares_config.h +36 -2
  266. data/third_party/zlib/adler32.c +14 -7
  267. data/third_party/zlib/compress.c +24 -18
  268. data/third_party/zlib/crc32.c +29 -12
  269. data/third_party/zlib/deflate.c +499 -303
  270. data/third_party/zlib/deflate.h +19 -16
  271. data/third_party/zlib/gzguts.h +16 -7
  272. data/third_party/zlib/gzlib.c +17 -14
  273. data/third_party/zlib/gzread.c +108 -48
  274. data/third_party/zlib/gzwrite.c +210 -122
  275. data/third_party/zlib/infback.c +2 -2
  276. data/third_party/zlib/inffast.c +34 -51
  277. data/third_party/zlib/inflate.c +86 -37
  278. data/third_party/zlib/inflate.h +7 -4
  279. data/third_party/zlib/inftrees.c +12 -14
  280. data/third_party/zlib/trees.c +38 -61
  281. data/third_party/zlib/uncompr.c +66 -32
  282. data/third_party/zlib/zconf.h +32 -9
  283. data/third_party/zlib/zlib.h +298 -154
  284. data/third_party/zlib/zutil.c +25 -24
  285. data/third_party/zlib/zutil.h +35 -17
  286. metadata +63 -30
@@ -41,7 +41,7 @@
41
41
 
42
42
  /* --- Tracing. --- */
43
43
 
44
- int tsi_tracing_enabled = 0;
44
+ grpc_tracer_flag tsi_tracing_enabled = GRPC_TRACER_INITIALIZER(false);
45
45
 
46
46
  /* --- tsi_result common implementation. --- */
47
47
 
@@ -73,6 +73,8 @@ const char *tsi_result_to_string(tsi_result result) {
73
73
  return "TSI_HANDSHAKE_IN_PROGRESS";
74
74
  case TSI_OUT_OF_RESOURCES:
75
75
  return "TSI_OUT_OF_RESOURCES";
76
+ case TSI_ASYNC:
77
+ return "TSI_ASYNC";
76
78
  default:
77
79
  return "UNKNOWN";
78
80
  }
@@ -92,6 +94,9 @@ tsi_result tsi_frame_protector_protect(tsi_frame_protector *self,
92
94
  protected_output_frames_size == NULL) {
93
95
  return TSI_INVALID_ARGUMENT;
94
96
  }
97
+ if (self->vtable == NULL || self->vtable->protect == NULL) {
98
+ return TSI_UNIMPLEMENTED;
99
+ }
95
100
  return self->vtable->protect(self, unprotected_bytes, unprotected_bytes_size,
96
101
  protected_output_frames,
97
102
  protected_output_frames_size);
@@ -104,6 +109,9 @@ tsi_result tsi_frame_protector_protect_flush(
104
109
  protected_output_frames_size == NULL || still_pending_size == NULL) {
105
110
  return TSI_INVALID_ARGUMENT;
106
111
  }
112
+ if (self->vtable == NULL || self->vtable->protect_flush == NULL) {
113
+ return TSI_UNIMPLEMENTED;
114
+ }
107
115
  return self->vtable->protect_flush(self, protected_output_frames,
108
116
  protected_output_frames_size,
109
117
  still_pending_size);
@@ -118,6 +126,9 @@ tsi_result tsi_frame_protector_unprotect(
118
126
  unprotected_bytes_size == NULL) {
119
127
  return TSI_INVALID_ARGUMENT;
120
128
  }
129
+ if (self->vtable == NULL || self->vtable->unprotect == NULL) {
130
+ return TSI_UNIMPLEMENTED;
131
+ }
121
132
  return self->vtable->unprotect(self, protected_frames_bytes,
122
133
  protected_frames_bytes_size, unprotected_bytes,
123
134
  unprotected_bytes_size);
@@ -139,6 +150,9 @@ tsi_result tsi_handshaker_get_bytes_to_send_to_peer(tsi_handshaker *self,
139
150
  return TSI_INVALID_ARGUMENT;
140
151
  }
141
152
  if (self->frame_protector_created) return TSI_FAILED_PRECONDITION;
153
+ if (self->vtable == NULL || self->vtable->get_bytes_to_send_to_peer == NULL) {
154
+ return TSI_UNIMPLEMENTED;
155
+ }
142
156
  return self->vtable->get_bytes_to_send_to_peer(self, bytes, bytes_size);
143
157
  }
144
158
 
@@ -149,12 +163,18 @@ tsi_result tsi_handshaker_process_bytes_from_peer(tsi_handshaker *self,
149
163
  return TSI_INVALID_ARGUMENT;
150
164
  }
151
165
  if (self->frame_protector_created) return TSI_FAILED_PRECONDITION;
166
+ if (self->vtable == NULL || self->vtable->process_bytes_from_peer == NULL) {
167
+ return TSI_UNIMPLEMENTED;
168
+ }
152
169
  return self->vtable->process_bytes_from_peer(self, bytes, bytes_size);
153
170
  }
154
171
 
155
172
  tsi_result tsi_handshaker_get_result(tsi_handshaker *self) {
156
173
  if (self == NULL) return TSI_INVALID_ARGUMENT;
157
174
  if (self->frame_protector_created) return TSI_FAILED_PRECONDITION;
175
+ if (self->vtable == NULL || self->vtable->get_result == NULL) {
176
+ return TSI_UNIMPLEMENTED;
177
+ }
158
178
  return self->vtable->get_result(self);
159
179
  }
160
180
 
@@ -165,6 +185,9 @@ tsi_result tsi_handshaker_extract_peer(tsi_handshaker *self, tsi_peer *peer) {
165
185
  if (tsi_handshaker_get_result(self) != TSI_OK) {
166
186
  return TSI_FAILED_PRECONDITION;
167
187
  }
188
+ if (self->vtable == NULL || self->vtable->extract_peer == NULL) {
189
+ return TSI_UNIMPLEMENTED;
190
+ }
168
191
  return self->vtable->extract_peer(self, peer);
169
192
  }
170
193
 
@@ -177,19 +200,77 @@ tsi_result tsi_handshaker_create_frame_protector(
177
200
  if (tsi_handshaker_get_result(self) != TSI_OK) {
178
201
  return TSI_FAILED_PRECONDITION;
179
202
  }
203
+ if (self->vtable == NULL || self->vtable->create_frame_protector == NULL) {
204
+ return TSI_UNIMPLEMENTED;
205
+ }
180
206
  result = self->vtable->create_frame_protector(self, max_protected_frame_size,
181
207
  protector);
182
208
  if (result == TSI_OK) {
183
- self->frame_protector_created = 1;
209
+ self->frame_protector_created = true;
184
210
  }
185
211
  return result;
186
212
  }
187
213
 
214
+ tsi_result tsi_handshaker_next(
215
+ tsi_handshaker *self, const unsigned char *received_bytes,
216
+ size_t received_bytes_size, unsigned char **bytes_to_send,
217
+ size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result,
218
+ tsi_handshaker_on_next_done_cb cb, void *user_data) {
219
+ if (self == NULL) return TSI_INVALID_ARGUMENT;
220
+ if (self->handshaker_result_created) return TSI_FAILED_PRECONDITION;
221
+ if (self->vtable == NULL || self->vtable->next == NULL) {
222
+ return TSI_UNIMPLEMENTED;
223
+ }
224
+ return self->vtable->next(self, received_bytes, received_bytes_size,
225
+ bytes_to_send, bytes_to_send_size,
226
+ handshaker_result, cb, user_data);
227
+ }
228
+
188
229
  void tsi_handshaker_destroy(tsi_handshaker *self) {
189
230
  if (self == NULL) return;
190
231
  self->vtable->destroy(self);
191
232
  }
192
233
 
234
+ /* --- tsi_handshaker_result implementation. --- */
235
+
236
+ tsi_result tsi_handshaker_result_extract_peer(const tsi_handshaker_result *self,
237
+ tsi_peer *peer) {
238
+ if (self == NULL || peer == NULL) return TSI_INVALID_ARGUMENT;
239
+ memset(peer, 0, sizeof(tsi_peer));
240
+ if (self->vtable == NULL || self->vtable->extract_peer == NULL) {
241
+ return TSI_UNIMPLEMENTED;
242
+ }
243
+ return self->vtable->extract_peer(self, peer);
244
+ }
245
+
246
+ tsi_result tsi_handshaker_result_create_frame_protector(
247
+ const tsi_handshaker_result *self, size_t *max_protected_frame_size,
248
+ tsi_frame_protector **protector) {
249
+ if (self == NULL || protector == NULL) return TSI_INVALID_ARGUMENT;
250
+ if (self->vtable == NULL || self->vtable->create_frame_protector == NULL) {
251
+ return TSI_UNIMPLEMENTED;
252
+ }
253
+ return self->vtable->create_frame_protector(self, max_protected_frame_size,
254
+ protector);
255
+ }
256
+
257
+ tsi_result tsi_handshaker_result_get_unused_bytes(
258
+ const tsi_handshaker_result *self, unsigned char **bytes,
259
+ size_t *bytes_size) {
260
+ if (self == NULL || bytes == NULL || bytes_size == NULL) {
261
+ return TSI_INVALID_ARGUMENT;
262
+ }
263
+ if (self->vtable == NULL || self->vtable->get_unused_bytes == NULL) {
264
+ return TSI_UNIMPLEMENTED;
265
+ }
266
+ return self->vtable->get_unused_bytes(self, bytes, bytes_size);
267
+ }
268
+
269
+ void tsi_handshaker_result_destroy(tsi_handshaker_result *self) {
270
+ if (self == NULL) return;
271
+ self->vtable->destroy(self);
272
+ }
273
+
193
274
  /* --- tsi_peer implementation. --- */
194
275
 
195
276
  tsi_peer_property tsi_init_peer_property(void) {
@@ -34,13 +34,16 @@
34
34
  #ifndef GRPC_CORE_TSI_TRANSPORT_SECURITY_H
35
35
  #define GRPC_CORE_TSI_TRANSPORT_SECURITY_H
36
36
 
37
+ #include <stdbool.h>
38
+
39
+ #include "src/core/lib/debug/trace.h"
37
40
  #include "src/core/tsi/transport_security_interface.h"
38
41
 
39
42
  #ifdef __cplusplus
40
43
  extern "C" {
41
44
  #endif
42
45
 
43
- extern int tsi_tracing_enabled;
46
+ extern grpc_tracer_flag tsi_tracing_enabled;
44
47
 
45
48
  /* Base for tsi_frame_protector implementations.
46
49
  See transport_security_interface.h for documentation. */
@@ -81,11 +84,33 @@ typedef struct {
81
84
  size_t *max_protected_frame_size,
82
85
  tsi_frame_protector **protector);
83
86
  void (*destroy)(tsi_handshaker *self);
87
+ tsi_result (*next)(tsi_handshaker *self, const unsigned char *received_bytes,
88
+ size_t received_bytes_size, unsigned char **bytes_to_send,
89
+ size_t *bytes_to_send_size,
90
+ tsi_handshaker_result **handshaker_result,
91
+ tsi_handshaker_on_next_done_cb cb, void *user_data);
84
92
  } tsi_handshaker_vtable;
85
93
 
86
94
  struct tsi_handshaker {
87
95
  const tsi_handshaker_vtable *vtable;
88
- int frame_protector_created;
96
+ bool frame_protector_created;
97
+ bool handshaker_result_created;
98
+ };
99
+
100
+ /* Base for tsi_handshaker_result implementations.
101
+ See transport_security_interface.h for documentation. */
102
+ typedef struct {
103
+ tsi_result (*extract_peer)(const tsi_handshaker_result *self, tsi_peer *peer);
104
+ tsi_result (*create_frame_protector)(const tsi_handshaker_result *self,
105
+ size_t *max_output_protected_frame_size,
106
+ tsi_frame_protector **protector);
107
+ tsi_result (*get_unused_bytes)(const tsi_handshaker_result *self,
108
+ unsigned char **bytes, size_t *bytes_size);
109
+ void (*destroy)(tsi_handshaker_result *self);
110
+ } tsi_handshaker_result_vtable;
111
+
112
+ struct tsi_handshaker_result {
113
+ const tsi_handshaker_result_vtable *vtable;
89
114
  };
90
115
 
91
116
  /* Peer and property construction/destruction functions. */
@@ -0,0 +1,236 @@
1
+ /*
2
+ *
3
+ * Copyright 2017, Google Inc.
4
+ * All rights reserved.
5
+ *
6
+ * Redistribution and use in source and binary forms, with or without
7
+ * modification, are permitted provided that the following conditions are
8
+ * met:
9
+ *
10
+ * * Redistributions of source code must retain the above copyright
11
+ * notice, this list of conditions and the following disclaimer.
12
+ * * Redistributions in binary form must reproduce the above
13
+ * copyright notice, this list of conditions and the following disclaimer
14
+ * in the documentation and/or other materials provided with the
15
+ * distribution.
16
+ * * Neither the name of Google Inc. nor the names of its
17
+ * contributors may be used to endorse or promote products derived from
18
+ * this software without specific prior written permission.
19
+ *
20
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
+ *
32
+ */
33
+
34
+ #include "src/core/tsi/transport_security_adapter.h"
35
+
36
+ #include <string.h>
37
+
38
+ #include <grpc/support/alloc.h>
39
+ #include <grpc/support/log.h>
40
+ #include "src/core/tsi/transport_security.h"
41
+
42
+ #define TSI_ADAPTER_INITIAL_BUFFER_SIZE 256
43
+
44
+ /* --- tsi_adapter_handshaker_result implementation ---*/
45
+
46
+ typedef struct {
47
+ tsi_handshaker_result base;
48
+ tsi_handshaker *wrapped;
49
+ unsigned char *unused_bytes;
50
+ size_t unused_bytes_size;
51
+ } tsi_adapter_handshaker_result;
52
+
53
+ static tsi_result adapter_result_extract_peer(const tsi_handshaker_result *self,
54
+ tsi_peer *peer) {
55
+ tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self;
56
+ return tsi_handshaker_extract_peer(impl->wrapped, peer);
57
+ }
58
+
59
+ static tsi_result adapter_result_create_frame_protector(
60
+ const tsi_handshaker_result *self, size_t *max_output_protected_frame_size,
61
+ tsi_frame_protector **protector) {
62
+ tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self;
63
+ return tsi_handshaker_create_frame_protector(
64
+ impl->wrapped, max_output_protected_frame_size, protector);
65
+ }
66
+
67
+ static tsi_result adapter_result_get_unused_bytes(
68
+ const tsi_handshaker_result *self, unsigned char **bytes,
69
+ size_t *byte_size) {
70
+ tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self;
71
+ *bytes = impl->unused_bytes;
72
+ *byte_size = impl->unused_bytes_size;
73
+ return TSI_OK;
74
+ }
75
+
76
+ static void adapter_result_destroy(tsi_handshaker_result *self) {
77
+ tsi_adapter_handshaker_result *impl = (tsi_adapter_handshaker_result *)self;
78
+ tsi_handshaker_destroy(impl->wrapped);
79
+ gpr_free(impl->unused_bytes);
80
+ gpr_free(self);
81
+ }
82
+
83
+ static const tsi_handshaker_result_vtable result_vtable = {
84
+ adapter_result_extract_peer, adapter_result_create_frame_protector,
85
+ adapter_result_get_unused_bytes, adapter_result_destroy,
86
+ };
87
+
88
+ /* Ownership of wrapped tsi_handshaker is transferred to the result object. */
89
+ static tsi_result tsi_adapter_create_handshaker_result(
90
+ tsi_handshaker *wrapped, const unsigned char *unused_bytes,
91
+ size_t unused_bytes_size, tsi_handshaker_result **handshaker_result) {
92
+ if (wrapped == NULL || (unused_bytes_size > 0 && unused_bytes == NULL)) {
93
+ return TSI_INVALID_ARGUMENT;
94
+ }
95
+ tsi_adapter_handshaker_result *impl = gpr_zalloc(sizeof(*impl));
96
+ impl->base.vtable = &result_vtable;
97
+ impl->wrapped = wrapped;
98
+ impl->unused_bytes_size = unused_bytes_size;
99
+ if (unused_bytes_size > 0) {
100
+ impl->unused_bytes = gpr_malloc(unused_bytes_size);
101
+ memcpy(impl->unused_bytes, unused_bytes, unused_bytes_size);
102
+ } else {
103
+ impl->unused_bytes = NULL;
104
+ }
105
+ *handshaker_result = &impl->base;
106
+ return TSI_OK;
107
+ }
108
+
109
+ /* --- tsi_adapter_handshaker implementation ---*/
110
+
111
+ typedef struct {
112
+ tsi_handshaker base;
113
+ tsi_handshaker *wrapped;
114
+ unsigned char *adapter_buffer;
115
+ size_t adapter_buffer_size;
116
+ } tsi_adapter_handshaker;
117
+
118
+ static tsi_result adapter_get_bytes_to_send_to_peer(tsi_handshaker *self,
119
+ unsigned char *bytes,
120
+ size_t *bytes_size) {
121
+ return tsi_handshaker_get_bytes_to_send_to_peer(
122
+ tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size);
123
+ }
124
+
125
+ static tsi_result adapter_process_bytes_from_peer(tsi_handshaker *self,
126
+ const unsigned char *bytes,
127
+ size_t *bytes_size) {
128
+ return tsi_handshaker_process_bytes_from_peer(
129
+ tsi_adapter_handshaker_get_wrapped(self), bytes, bytes_size);
130
+ }
131
+
132
+ static tsi_result adapter_get_result(tsi_handshaker *self) {
133
+ return tsi_handshaker_get_result(tsi_adapter_handshaker_get_wrapped(self));
134
+ }
135
+
136
+ static tsi_result adapter_extract_peer(tsi_handshaker *self, tsi_peer *peer) {
137
+ return tsi_handshaker_extract_peer(tsi_adapter_handshaker_get_wrapped(self),
138
+ peer);
139
+ }
140
+
141
+ static tsi_result adapter_create_frame_protector(
142
+ tsi_handshaker *self, size_t *max_protected_frame_size,
143
+ tsi_frame_protector **protector) {
144
+ return tsi_handshaker_create_frame_protector(
145
+ tsi_adapter_handshaker_get_wrapped(self), max_protected_frame_size,
146
+ protector);
147
+ }
148
+
149
+ static void adapter_destroy(tsi_handshaker *self) {
150
+ tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)self;
151
+ tsi_handshaker_destroy(impl->wrapped);
152
+ gpr_free(impl->adapter_buffer);
153
+ gpr_free(self);
154
+ }
155
+
156
+ static tsi_result adapter_next(
157
+ tsi_handshaker *self, const unsigned char *received_bytes,
158
+ size_t received_bytes_size, unsigned char **bytes_to_send,
159
+ size_t *bytes_to_send_size, tsi_handshaker_result **handshaker_result,
160
+ tsi_handshaker_on_next_done_cb cb, void *user_data) {
161
+ /* Input sanity check. */
162
+ if ((received_bytes_size > 0 && received_bytes == NULL) ||
163
+ bytes_to_send == NULL || bytes_to_send_size == NULL ||
164
+ handshaker_result == NULL) {
165
+ return TSI_INVALID_ARGUMENT;
166
+ }
167
+
168
+ /* If there are received bytes, process them first. */
169
+ tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)self;
170
+ tsi_result status = TSI_OK;
171
+ size_t bytes_consumed = received_bytes_size;
172
+ if (received_bytes_size > 0) {
173
+ status = tsi_handshaker_process_bytes_from_peer(
174
+ impl->wrapped, received_bytes, &bytes_consumed);
175
+ if (status != TSI_OK) return status;
176
+ }
177
+
178
+ /* Get bytes to send to the peer, if available. */
179
+ size_t offset = 0;
180
+ do {
181
+ size_t to_send_size = impl->adapter_buffer_size - offset;
182
+ status = tsi_handshaker_get_bytes_to_send_to_peer(
183
+ impl->wrapped, impl->adapter_buffer + offset, &to_send_size);
184
+ offset += to_send_size;
185
+ if (status == TSI_INCOMPLETE_DATA) {
186
+ impl->adapter_buffer_size *= 2;
187
+ impl->adapter_buffer =
188
+ gpr_realloc(impl->adapter_buffer, impl->adapter_buffer_size);
189
+ }
190
+ } while (status == TSI_INCOMPLETE_DATA);
191
+ if (status != TSI_OK) return status;
192
+ *bytes_to_send = impl->adapter_buffer;
193
+ *bytes_to_send_size = offset;
194
+
195
+ /* If handshake completes, create tsi_handshaker_result. */
196
+ if (tsi_handshaker_is_in_progress(impl->wrapped)) {
197
+ *handshaker_result = NULL;
198
+ } else {
199
+ size_t unused_bytes_size = received_bytes_size - bytes_consumed;
200
+ const unsigned char *unused_bytes =
201
+ unused_bytes_size == 0 ? NULL : received_bytes + bytes_consumed;
202
+ status = tsi_adapter_create_handshaker_result(
203
+ impl->wrapped, unused_bytes, unused_bytes_size, handshaker_result);
204
+ if (status == TSI_OK) {
205
+ impl->base.handshaker_result_created = true;
206
+ impl->wrapped = NULL;
207
+ }
208
+ }
209
+ return status;
210
+ }
211
+
212
+ static const tsi_handshaker_vtable handshaker_vtable = {
213
+ adapter_get_bytes_to_send_to_peer,
214
+ adapter_process_bytes_from_peer,
215
+ adapter_get_result,
216
+ adapter_extract_peer,
217
+ adapter_create_frame_protector,
218
+ adapter_destroy,
219
+ adapter_next,
220
+ };
221
+
222
+ tsi_handshaker *tsi_create_adapter_handshaker(tsi_handshaker *wrapped) {
223
+ GPR_ASSERT(wrapped != NULL);
224
+ tsi_adapter_handshaker *impl = gpr_zalloc(sizeof(*impl));
225
+ impl->base.vtable = &handshaker_vtable;
226
+ impl->wrapped = wrapped;
227
+ impl->adapter_buffer_size = TSI_ADAPTER_INITIAL_BUFFER_SIZE;
228
+ impl->adapter_buffer = gpr_malloc(impl->adapter_buffer_size);
229
+ return &impl->base;
230
+ }
231
+
232
+ tsi_handshaker *tsi_adapter_handshaker_get_wrapped(tsi_handshaker *adapter) {
233
+ if (adapter == NULL) return NULL;
234
+ tsi_adapter_handshaker *impl = (tsi_adapter_handshaker *)adapter;
235
+ return impl->wrapped;
236
+ }