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
@@ -30,18 +30,15 @@
30
30
  *
31
31
  */
32
32
 
33
- #ifndef GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H
34
- #define GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H
33
+ #ifndef GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H
34
+ #define GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H
35
35
 
36
36
  #include "src/core/lib/channel/channel_stack.h"
37
37
 
38
38
  /* Processes metadata on the client side for HTTP2 transports */
39
39
  extern const grpc_channel_filter grpc_http_client_filter;
40
40
 
41
- /* Channel arg to override the http2 :scheme header */
42
- #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
43
-
44
41
  /* Channel arg to determine maximum size of payload eligable for GET request */
45
42
  #define GRPC_ARG_MAX_PAYLOAD_SIZE_FOR_GET "grpc.max_payload_size_for_get"
46
43
 
47
- #endif /* GRPC_CORE_LIB_CHANNEL_HTTP_CLIENT_FILTER_H */
44
+ #endif /* GRPC_CORE_EXT_FILTERS_HTTP_CLIENT_HTTP_CLIENT_FILTER_H */
@@ -0,0 +1,104 @@
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 <string.h>
35
+
36
+ #include "src/core/ext/filters/http/client/http_client_filter.h"
37
+ #include "src/core/ext/filters/http/message_compress/message_compress_filter.h"
38
+ #include "src/core/ext/filters/http/server/http_server_filter.h"
39
+ #include "src/core/lib/channel/channel_stack_builder.h"
40
+ #include "src/core/lib/surface/call.h"
41
+ #include "src/core/lib/surface/channel_init.h"
42
+ #include "src/core/lib/transport/transport_impl.h"
43
+
44
+ typedef struct {
45
+ const grpc_channel_filter *filter;
46
+ const char *control_channel_arg;
47
+ } optional_filter;
48
+
49
+ static optional_filter compress_filter = {
50
+ &grpc_message_compress_filter, GRPC_ARG_ENABLE_PER_MESSAGE_COMPRESSION};
51
+
52
+ static bool is_building_http_like_transport(
53
+ grpc_channel_stack_builder *builder) {
54
+ grpc_transport *t = grpc_channel_stack_builder_get_transport(builder);
55
+ return t != NULL && strstr(t->vtable->name, "http");
56
+ }
57
+
58
+ static bool maybe_add_optional_filter(grpc_exec_ctx *exec_ctx,
59
+ grpc_channel_stack_builder *builder,
60
+ void *arg) {
61
+ if (!is_building_http_like_transport(builder)) return true;
62
+ optional_filter *filtarg = arg;
63
+ const grpc_channel_args *channel_args =
64
+ grpc_channel_stack_builder_get_channel_arguments(builder);
65
+ bool enable = grpc_channel_arg_get_bool(
66
+ grpc_channel_args_find(channel_args, filtarg->control_channel_arg),
67
+ !grpc_channel_args_want_minimal_stack(channel_args));
68
+ return enable ? grpc_channel_stack_builder_prepend_filter(
69
+ builder, filtarg->filter, NULL, NULL)
70
+ : true;
71
+ }
72
+
73
+ static bool maybe_add_required_filter(grpc_exec_ctx *exec_ctx,
74
+ grpc_channel_stack_builder *builder,
75
+ void *arg) {
76
+ return is_building_http_like_transport(builder)
77
+ ? grpc_channel_stack_builder_prepend_filter(
78
+ builder, (const grpc_channel_filter *)arg, NULL, NULL)
79
+ : true;
80
+ }
81
+
82
+ void grpc_http_filters_init(void) {
83
+ grpc_register_tracer("compression", &grpc_compression_trace);
84
+ grpc_channel_init_register_stage(GRPC_CLIENT_SUBCHANNEL,
85
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
86
+ maybe_add_optional_filter, &compress_filter);
87
+ grpc_channel_init_register_stage(GRPC_CLIENT_DIRECT_CHANNEL,
88
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
89
+ maybe_add_optional_filter, &compress_filter);
90
+ grpc_channel_init_register_stage(GRPC_SERVER_CHANNEL,
91
+ GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
92
+ maybe_add_optional_filter, &compress_filter);
93
+ grpc_channel_init_register_stage(
94
+ GRPC_CLIENT_SUBCHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
95
+ maybe_add_required_filter, (void *)&grpc_http_client_filter);
96
+ grpc_channel_init_register_stage(
97
+ GRPC_CLIENT_DIRECT_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
98
+ maybe_add_required_filter, (void *)&grpc_http_client_filter);
99
+ grpc_channel_init_register_stage(
100
+ GRPC_SERVER_CHANNEL, GRPC_CHANNEL_INIT_BUILTIN_PRIORITY,
101
+ maybe_add_required_filter, (void *)&grpc_http_server_filter);
102
+ }
103
+
104
+ void grpc_http_filters_shutdown(void) {}
@@ -39,17 +39,22 @@
39
39
  #include <grpc/support/alloc.h>
40
40
  #include <grpc/support/log.h>
41
41
 
42
+ #include "src/core/ext/filters/http/message_compress/message_compress_filter.h"
42
43
  #include "src/core/lib/channel/channel_args.h"
43
- #include "src/core/lib/channel/compress_filter.h"
44
44
  #include "src/core/lib/compression/algorithm_metadata.h"
45
45
  #include "src/core/lib/compression/message_compress.h"
46
46
  #include "src/core/lib/profiling/timers.h"
47
47
  #include "src/core/lib/slice/slice_internal.h"
48
48
  #include "src/core/lib/slice/slice_string_helpers.h"
49
49
  #include "src/core/lib/support/string.h"
50
+ #include "src/core/lib/surface/call.h"
50
51
  #include "src/core/lib/transport/static_metadata.h"
51
52
 
52
- int grpc_compression_trace = 0;
53
+ #define INITIAL_METADATA_UNSEEN 0
54
+ #define HAS_COMPRESSION_ALGORITHM 2
55
+ #define NO_COMPRESSION_ALGORITHM 4
56
+
57
+ #define CANCELLED_BIT ((gpr_atm)1)
53
58
 
54
59
  typedef struct call_data {
55
60
  grpc_slice_buffer slices; /**< Buffers up input slices to be compressed */
@@ -59,8 +64,17 @@ typedef struct call_data {
59
64
  /** Compression algorithm we'll try to use. It may be given by incoming
60
65
  * metadata, or by the channel's default compression settings. */
61
66
  grpc_compression_algorithm compression_algorithm;
62
- /** If true, contents of \a compression_algorithm are authoritative */
63
- int has_compression_algorithm;
67
+
68
+ /* Atomic recording the state of initial metadata; allowed values:
69
+ INITIAL_METADATA_UNSEEN - initial metadata op not seen
70
+ HAS_COMPRESSION_ALGORITHM - initial metadata seen; compression algorithm
71
+ set
72
+ NO_COMPRESSION_ALGORITHM - initial metadata seen; no compression algorithm
73
+ set
74
+ pointer - a stalled op containing a send_message that's waiting on initial
75
+ metadata
76
+ pointer | CANCELLED_BIT - request was cancelled with error pointed to */
77
+ gpr_atm send_initial_metadata_state;
64
78
 
65
79
  grpc_transport_stream_op_batch *send_op;
66
80
  uint32_t send_length;
@@ -81,14 +95,15 @@ typedef struct channel_data {
81
95
  uint32_t supported_compression_algorithms;
82
96
  } channel_data;
83
97
 
84
- static int skip_compression(grpc_call_element *elem, uint32_t flags) {
98
+ static bool skip_compression(grpc_call_element *elem, uint32_t flags,
99
+ bool has_compression_algorithm) {
85
100
  call_data *calld = elem->call_data;
86
101
  channel_data *channeld = elem->channel_data;
87
102
 
88
103
  if (flags & (GRPC_WRITE_NO_COMPRESS | GRPC_WRITE_INTERNAL_COMPRESS)) {
89
104
  return 1;
90
105
  }
91
- if (calld->has_compression_algorithm) {
106
+ if (has_compression_algorithm) {
92
107
  if (calld->compression_algorithm == GRPC_COMPRESS_NONE) {
93
108
  return 1;
94
109
  }
@@ -101,12 +116,14 @@ static int skip_compression(grpc_call_element *elem, uint32_t flags) {
101
116
  /** Filter initial metadata */
102
117
  static grpc_error *process_send_initial_metadata(
103
118
  grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
104
- grpc_metadata_batch *initial_metadata) GRPC_MUST_USE_RESULT;
119
+ grpc_metadata_batch *initial_metadata,
120
+ bool *has_compression_algorithm) GRPC_MUST_USE_RESULT;
105
121
  static grpc_error *process_send_initial_metadata(
106
122
  grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
107
- grpc_metadata_batch *initial_metadata) {
123
+ grpc_metadata_batch *initial_metadata, bool *has_compression_algorithm) {
108
124
  call_data *calld = elem->call_data;
109
125
  channel_data *channeld = elem->channel_data;
126
+ *has_compression_algorithm = false;
110
127
  /* Parse incoming request for compression. If any, it'll be available
111
128
  * at calld->compression_algorithm */
112
129
  if (initial_metadata->idx.named.grpc_internal_encoding_request != NULL) {
@@ -130,7 +147,7 @@ static grpc_error *process_send_initial_metadata(
130
147
  gpr_free(val);
131
148
  calld->compression_algorithm = GRPC_COMPRESS_NONE;
132
149
  }
133
- calld->has_compression_algorithm = 1;
150
+ *has_compression_algorithm = true;
134
151
 
135
152
  grpc_metadata_batch_remove(
136
153
  exec_ctx, initial_metadata,
@@ -140,7 +157,7 @@ static grpc_error *process_send_initial_metadata(
140
157
  * exceptionally skipping compression, fall back to the channel
141
158
  * default */
142
159
  calld->compression_algorithm = channeld->default_compression_algorithm;
143
- calld->has_compression_algorithm = 1; /* GPR_TRUE */
160
+ *has_compression_algorithm = true;
144
161
  }
145
162
 
146
163
  grpc_error *error = GRPC_ERROR_NONE;
@@ -181,7 +198,7 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
181
198
  did_compress = grpc_msg_compress(exec_ctx, calld->compression_algorithm,
182
199
  &calld->slices, &tmp);
183
200
  if (did_compress) {
184
- if (grpc_compression_trace) {
201
+ if (GRPC_TRACER_ON(grpc_compression_trace)) {
185
202
  char *algo_name;
186
203
  const size_t before_size = calld->slices.length;
187
204
  const size_t after_size = tmp.length;
@@ -195,7 +212,7 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
195
212
  grpc_slice_buffer_swap(&calld->slices, &tmp);
196
213
  calld->send_flags |= GRPC_WRITE_INTERNAL_COMPRESS;
197
214
  } else {
198
- if (grpc_compression_trace) {
215
+ if (GRPC_TRACER_ON(grpc_compression_trace)) {
199
216
  char *algo_name;
200
217
  GPR_ASSERT(grpc_compression_algorithm_name(calld->compression_algorithm,
201
218
  &algo_name));
@@ -221,6 +238,13 @@ static void finish_send_message(grpc_exec_ctx *exec_ctx,
221
238
  static void got_slice(grpc_exec_ctx *exec_ctx, void *elemp, grpc_error *error) {
222
239
  grpc_call_element *elem = elemp;
223
240
  call_data *calld = elem->call_data;
241
+ if (GRPC_ERROR_NONE !=
242
+ grpc_byte_stream_pull(exec_ctx,
243
+ calld->send_op->payload->send_message.send_message,
244
+ &calld->incoming_slice)) {
245
+ /* Should never reach here */
246
+ abort();
247
+ }
224
248
  grpc_slice_buffer_add(&calld->slices, calld->incoming_slice);
225
249
  if (calld->send_length == calld->slices.length) {
226
250
  finish_send_message(exec_ctx, elem);
@@ -233,8 +257,11 @@ static void continue_send_message(grpc_exec_ctx *exec_ctx,
233
257
  grpc_call_element *elem) {
234
258
  call_data *calld = elem->call_data;
235
259
  while (grpc_byte_stream_next(
236
- exec_ctx, calld->send_op->payload->send_message.send_message,
237
- &calld->incoming_slice, ~(size_t)0, &calld->got_slice)) {
260
+ exec_ctx, calld->send_op->payload->send_message.send_message, ~(size_t)0,
261
+ &calld->got_slice)) {
262
+ grpc_byte_stream_pull(exec_ctx,
263
+ calld->send_op->payload->send_message.send_message,
264
+ &calld->incoming_slice);
238
265
  grpc_slice_buffer_add(&calld->slices, calld->incoming_slice);
239
266
  if (calld->send_length == calld->slices.length) {
240
267
  finish_send_message(exec_ctx, elem);
@@ -250,21 +277,91 @@ static void compress_start_transport_stream_op_batch(
250
277
 
251
278
  GPR_TIMER_BEGIN("compress_start_transport_stream_op_batch", 0);
252
279
 
280
+ if (op->cancel_stream) {
281
+ GRPC_ERROR_REF(op->payload->cancel_stream.cancel_error);
282
+ gpr_atm cur = gpr_atm_full_xchg(
283
+ &calld->send_initial_metadata_state,
284
+ CANCELLED_BIT | (gpr_atm)op->payload->cancel_stream.cancel_error);
285
+ switch (cur) {
286
+ case HAS_COMPRESSION_ALGORITHM:
287
+ case NO_COMPRESSION_ALGORITHM:
288
+ case INITIAL_METADATA_UNSEEN:
289
+ break;
290
+ default:
291
+ if ((cur & CANCELLED_BIT) == 0) {
292
+ grpc_transport_stream_op_batch_finish_with_failure(
293
+ exec_ctx, (grpc_transport_stream_op_batch *)cur,
294
+ GRPC_ERROR_REF(op->payload->cancel_stream.cancel_error));
295
+ } else {
296
+ GRPC_ERROR_UNREF((grpc_error *)(cur & ~CANCELLED_BIT));
297
+ }
298
+ break;
299
+ }
300
+ }
301
+
253
302
  if (op->send_initial_metadata) {
303
+ bool has_compression_algorithm;
254
304
  grpc_error *error = process_send_initial_metadata(
255
305
  exec_ctx, elem,
256
- op->payload->send_initial_metadata.send_initial_metadata);
306
+ op->payload->send_initial_metadata.send_initial_metadata,
307
+ &has_compression_algorithm);
257
308
  if (error != GRPC_ERROR_NONE) {
258
309
  grpc_transport_stream_op_batch_finish_with_failure(exec_ctx, op, error);
259
310
  return;
260
311
  }
312
+ gpr_atm cur;
313
+ retry_send_im:
314
+ cur = gpr_atm_acq_load(&calld->send_initial_metadata_state);
315
+ GPR_ASSERT(cur != HAS_COMPRESSION_ALGORITHM &&
316
+ cur != NO_COMPRESSION_ALGORITHM);
317
+ if ((cur & CANCELLED_BIT) == 0) {
318
+ if (!gpr_atm_rel_cas(&calld->send_initial_metadata_state, cur,
319
+ has_compression_algorithm
320
+ ? HAS_COMPRESSION_ALGORITHM
321
+ : NO_COMPRESSION_ALGORITHM)) {
322
+ goto retry_send_im;
323
+ }
324
+ if (cur != INITIAL_METADATA_UNSEEN) {
325
+ grpc_call_next_op(exec_ctx, elem,
326
+ (grpc_transport_stream_op_batch *)cur);
327
+ }
328
+ }
261
329
  }
262
- if (op->send_message &&
263
- !skip_compression(elem, op->payload->send_message.send_message->flags)) {
264
- calld->send_op = op;
265
- calld->send_length = op->payload->send_message.send_message->length;
266
- calld->send_flags = op->payload->send_message.send_message->flags;
267
- continue_send_message(exec_ctx, elem);
330
+ if (op->send_message) {
331
+ gpr_atm cur;
332
+ retry_send:
333
+ cur = gpr_atm_acq_load(&calld->send_initial_metadata_state);
334
+ switch (cur) {
335
+ case INITIAL_METADATA_UNSEEN:
336
+ if (!gpr_atm_rel_cas(&calld->send_initial_metadata_state, cur,
337
+ (gpr_atm)op)) {
338
+ goto retry_send;
339
+ }
340
+ break;
341
+ case HAS_COMPRESSION_ALGORITHM:
342
+ case NO_COMPRESSION_ALGORITHM:
343
+ if (!skip_compression(elem,
344
+ op->payload->send_message.send_message->flags,
345
+ cur == HAS_COMPRESSION_ALGORITHM)) {
346
+ calld->send_op = op;
347
+ calld->send_length = op->payload->send_message.send_message->length;
348
+ calld->send_flags = op->payload->send_message.send_message->flags;
349
+ continue_send_message(exec_ctx, elem);
350
+ } else {
351
+ /* pass control down the stack */
352
+ grpc_call_next_op(exec_ctx, elem, op);
353
+ }
354
+ break;
355
+ default:
356
+ if (cur & CANCELLED_BIT) {
357
+ grpc_transport_stream_op_batch_finish_with_failure(
358
+ exec_ctx, op,
359
+ GRPC_ERROR_REF((grpc_error *)(cur & ~CANCELLED_BIT)));
360
+ } else {
361
+ /* >1 send_message concurrently */
362
+ GPR_UNREACHABLE_CODE(break);
363
+ }
364
+ }
268
365
  } else {
269
366
  /* pass control down the stack */
270
367
  grpc_call_next_op(exec_ctx, elem, op);
@@ -282,7 +379,6 @@ static grpc_error *init_call_elem(grpc_exec_ctx *exec_ctx,
282
379
 
283
380
  /* initialize members */
284
381
  grpc_slice_buffer_init(&calld->slices);
285
- calld->has_compression_algorithm = 0;
286
382
  grpc_closure_init(&calld->got_slice, got_slice, elem,
287
383
  grpc_schedule_on_exec_ctx);
288
384
  grpc_closure_init(&calld->send_done, send_done, elem,
@@ -298,6 +394,11 @@ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem,
298
394
  /* grab pointers to our data from the call element */
299
395
  call_data *calld = elem->call_data;
300
396
  grpc_slice_buffer_destroy_internal(exec_ctx, &calld->slices);
397
+ gpr_atm imstate =
398
+ gpr_atm_no_barrier_load(&calld->send_initial_metadata_state);
399
+ if (imstate & CANCELLED_BIT) {
400
+ GRPC_ERROR_UNREF((grpc_error *)(imstate & ~CANCELLED_BIT));
401
+ }
301
402
  }
302
403
 
303
404
  /* Constructor for channel_data */
@@ -338,7 +439,7 @@ static grpc_error *init_channel_elem(grpc_exec_ctx *exec_ctx,
338
439
  static void destroy_channel_elem(grpc_exec_ctx *exec_ctx,
339
440
  grpc_channel_element *elem) {}
340
441
 
341
- const grpc_channel_filter grpc_compress_filter = {
442
+ const grpc_channel_filter grpc_message_compress_filter = {
342
443
  compress_start_transport_stream_op_batch,
343
444
  grpc_channel_next_op,
344
445
  sizeof(call_data),
@@ -31,15 +31,13 @@
31
31
  *
32
32
  */
33
33
 
34
- #ifndef GRPC_CORE_LIB_CHANNEL_COMPRESS_FILTER_H
35
- #define GRPC_CORE_LIB_CHANNEL_COMPRESS_FILTER_H
34
+ #ifndef GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_COMPRESS_FILTER_H
35
+ #define GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_COMPRESS_FILTER_H
36
36
 
37
37
  #include <grpc/impl/codegen/compression_types.h>
38
38
 
39
39
  #include "src/core/lib/channel/channel_stack.h"
40
40
 
41
- extern int grpc_compression_trace;
42
-
43
41
  /** Compression filter for outgoing data.
44
42
  *
45
43
  * See <grpc/compression.h> for the available compression settings.
@@ -62,6 +60,7 @@ extern int grpc_compression_trace;
62
60
  * aforementioned 'grpc-encoding' metadata value, data will pass through
63
61
  * uncompressed. */
64
62
 
65
- extern const grpc_channel_filter grpc_compress_filter;
63
+ extern const grpc_channel_filter grpc_message_compress_filter;
66
64
 
67
- #endif /* GRPC_CORE_LIB_CHANNEL_COMPRESS_FILTER_H */
65
+ #endif /* GRPC_CORE_EXT_FILTERS_HTTP_MESSAGE_COMPRESS_MESSAGE_COMPRESS_FILTER_H \
66
+ */
@@ -31,7 +31,7 @@
31
31
  *
32
32
  */
33
33
 
34
- #include "src/core/lib/channel/http_server_filter.h"
34
+ #include "src/core/ext/filters/http/server/http_server_filter.h"
35
35
 
36
36
  #include <grpc/support/alloc.h>
37
37
  #include <grpc/support/log.h>
@@ -46,8 +46,6 @@
46
46
  #define EXPECTED_CONTENT_TYPE "application/grpc"
47
47
  #define EXPECTED_CONTENT_TYPE_LENGTH sizeof(EXPECTED_CONTENT_TYPE) - 1
48
48
 
49
- extern int grpc_http_trace;
50
-
51
49
  typedef struct call_data {
52
50
  grpc_linked_mdelem status;
53
51
  grpc_linked_mdelem content_type;
@@ -240,9 +238,9 @@ static grpc_error *server_filter_incoming_metadata(grpc_exec_ctx *exec_ctx,
240
238
  const int k_url_safe = 1;
241
239
  grpc_slice_buffer_add(
242
240
  &calld->read_slice_buffer,
243
- grpc_base64_decode(exec_ctx,
244
- (const char *)GRPC_SLICE_START_PTR(query_slice),
245
- k_url_safe));
241
+ grpc_base64_decode_with_len(
242
+ exec_ctx, (const char *)GRPC_SLICE_START_PTR(query_slice),
243
+ GRPC_SLICE_LENGTH(query_slice), k_url_safe));
246
244
  grpc_slice_buffer_stream_init(&calld->read_stream,
247
245
  &calld->read_slice_buffer, 0);
248
246
  calld->seen_path_with_query = true;