grpc 1.2.5 → 1.3.4

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 (327) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1434 -399
  3. data/etc/roots.pem +34 -150
  4. data/include/grpc/grpc.h +71 -0
  5. data/include/grpc/impl/codegen/atm.h +5 -0
  6. data/include/grpc/impl/codegen/atm_gcc_atomic.h +6 -0
  7. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  8. data/include/grpc/impl/codegen/atm_windows.h +11 -0
  9. data/include/grpc/impl/codegen/grpc_types.h +54 -13
  10. data/include/grpc/impl/codegen/port_platform.h +15 -1
  11. data/include/grpc/support/alloc.h +2 -1
  12. data/include/grpc/support/sync.h +4 -0
  13. data/include/grpc/support/tls.h +1 -1
  14. data/src/core/ext/census/gen/trace_context.pb.h +1 -1
  15. data/src/core/ext/census/grpc_filter.c +14 -10
  16. data/src/core/ext/census/grpc_plugin.c +3 -1
  17. data/src/core/ext/census/trace_label.h +1 -1
  18. data/src/core/ext/census/trace_propagation.h +1 -1
  19. data/src/core/ext/census/trace_status.h +1 -1
  20. data/src/core/ext/census/trace_string.h +1 -1
  21. data/src/core/ext/census/tracing.h +1 -1
  22. data/src/core/ext/{client_channel → filters/client_channel}/channel_connectivity.c +56 -27
  23. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.c +407 -202
  24. data/src/core/ext/{client_channel → filters/client_channel}/client_channel.h +10 -6
  25. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.c +1 -1
  26. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_factory.h +4 -4
  27. data/src/core/ext/{client_channel → filters/client_channel}/client_channel_plugin.c +12 -7
  28. data/src/core/ext/{client_channel → filters/client_channel}/connector.c +1 -1
  29. data/src/core/ext/{client_channel → filters/client_channel}/connector.h +3 -5
  30. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.c +6 -6
  31. data/src/core/ext/{client_channel → filters/client_channel}/http_connect_handshaker.h +3 -3
  32. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.c +4 -4
  33. data/src/core/ext/{client_channel → filters/client_channel}/http_proxy.h +3 -3
  34. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.c +1 -1
  35. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy.h +4 -4
  36. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.c +22 -20
  37. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb.h +4 -4
  38. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel.h +5 -4
  39. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/grpclb_channel_secure.c +2 -2
  40. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.c +1 -1
  41. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/load_balancer_api.h +6 -5
  42. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +1 -1
  43. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -0
  44. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/pick_first/pick_first.c +20 -15
  45. data/src/core/ext/{lb_policy → filters/client_channel/lb_policy}/round_robin/round_robin.c +21 -16
  46. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.c +1 -1
  47. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_factory.h +5 -5
  48. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.c +1 -1
  49. data/src/core/ext/{client_channel → filters/client_channel}/lb_policy_registry.h +4 -4
  50. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.c +1 -1
  51. data/src/core/ext/{client_channel → filters/client_channel}/parse_address.h +4 -4
  52. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.c +1 -1
  53. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper.h +3 -3
  54. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.c +10 -4
  55. data/src/core/ext/{client_channel → filters/client_channel}/proxy_mapper_registry.h +4 -4
  56. data/src/core/ext/{client_channel → filters/client_channel}/resolver.c +1 -1
  57. data/src/core/ext/{client_channel → filters/client_channel}/resolver.h +4 -4
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
  59. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
  60. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
  61. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
  62. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
  63. data/src/core/ext/{resolver → filters/client_channel/resolver}/dns/native/dns_resolver.c +21 -5
  64. data/src/core/ext/{resolver → filters/client_channel/resolver}/sockaddr/sockaddr_resolver.c +3 -3
  65. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.c +1 -1
  66. data/src/core/ext/{client_channel → filters/client_channel}/resolver_factory.h +6 -6
  67. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.c +1 -2
  68. data/src/core/ext/{client_channel → filters/client_channel}/resolver_registry.h +4 -4
  69. data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
  70. data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
  71. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.c +49 -43
  72. data/src/core/ext/{client_channel → filters/client_channel}/subchannel.h +21 -7
  73. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.c +1 -1
  74. data/src/core/ext/{client_channel → filters/client_channel}/subchannel_index.h +5 -5
  75. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.c +1 -1
  76. data/src/core/ext/{client_channel → filters/client_channel}/uri_parser.h +3 -3
  77. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.c +4 -2
  78. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting.h +3 -3
  79. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.c +17 -14
  80. data/src/core/ext/{load_reporting → filters/load_reporting}/load_reporting_filter.h +4 -4
  81. data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
  82. data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
  83. data/src/core/ext/transport/chttp2/client/chttp2_connector.c +6 -41
  84. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +1 -1
  85. data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +2 -2
  86. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +3 -3
  87. data/src/core/ext/transport/chttp2/server/chttp2_server.c +2 -2
  88. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +2 -5
  89. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +2 -2
  90. data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +449 -204
  91. data/src/core/ext/transport/chttp2/transport/frame_data.c +10 -7
  92. data/src/core/ext/transport/chttp2/transport/frame_goaway.c +3 -2
  93. data/src/core/ext/transport/chttp2/transport/frame_ping.c +37 -7
  94. data/src/core/ext/transport/chttp2/transport/frame_ping.h +3 -0
  95. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +4 -3
  96. data/src/core/ext/transport/chttp2/transport/frame_settings.c +18 -38
  97. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -29
  98. data/src/core/ext/transport/chttp2/transport/frame_window_update.c +2 -2
  99. data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +64 -37
  100. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +11 -4
  101. data/src/core/ext/transport/chttp2/transport/hpack_parser.c +60 -39
  102. data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
  103. data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
  104. data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
  105. data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +22 -43
  106. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +8 -10
  107. data/src/core/ext/transport/chttp2/transport/internal.h +24 -2
  108. data/src/core/ext/transport/chttp2/transport/parsing.c +33 -15
  109. data/src/core/ext/transport/chttp2/transport/writing.c +56 -10
  110. data/src/core/lib/channel/channel_args.c +7 -0
  111. data/src/core/lib/channel/channel_args.h +2 -0
  112. data/src/core/lib/channel/channel_stack.c +20 -27
  113. data/src/core/lib/channel/channel_stack.h +18 -16
  114. data/src/core/lib/channel/compress_filter.c +20 -18
  115. data/src/core/lib/channel/connected_channel.c +9 -8
  116. data/src/core/lib/channel/deadline_filter.c +28 -24
  117. data/src/core/lib/channel/deadline_filter.h +3 -3
  118. data/src/core/lib/channel/handshaker.c +3 -2
  119. data/src/core/lib/channel/http_client_filter.c +119 -61
  120. data/src/core/lib/channel/http_server_filter.c +124 -69
  121. data/src/core/lib/channel/message_size_filter.c +23 -19
  122. data/src/core/lib/http/httpcli.c +8 -6
  123. data/src/core/lib/http/httpcli_security_connector.c +5 -5
  124. data/src/core/lib/http/parser.c +57 -31
  125. data/src/core/lib/iomgr/closure.c +15 -0
  126. data/src/core/lib/iomgr/closure.h +4 -0
  127. data/src/core/lib/iomgr/combiner.c +8 -0
  128. data/src/core/lib/iomgr/endpoint_pair.h +2 -3
  129. data/src/core/lib/iomgr/endpoint_pair_posix.c +10 -7
  130. data/src/core/lib/iomgr/endpoint_pair_uv.c +2 -3
  131. data/src/core/lib/iomgr/endpoint_pair_windows.c +9 -6
  132. data/src/core/lib/iomgr/error.c +360 -177
  133. data/src/core/lib/iomgr/error.h +31 -33
  134. data/src/core/lib/iomgr/error_internal.h +30 -9
  135. data/src/core/lib/iomgr/ev_epoll_linux.c +25 -239
  136. data/src/core/lib/iomgr/ev_poll_posix.c +11 -7
  137. data/src/core/lib/iomgr/ev_posix.c +6 -0
  138. data/src/core/lib/iomgr/ev_posix.h +3 -0
  139. data/src/core/lib/iomgr/exec_ctx.c +6 -0
  140. data/src/core/lib/iomgr/executor.c +8 -2
  141. data/src/core/lib/iomgr/load_file.c +6 -3
  142. data/src/core/lib/iomgr/lockfree_event.c +238 -0
  143. data/src/core/{ext/client_channel/initial_connect_string.h → lib/iomgr/lockfree_event.h} +17 -13
  144. data/src/core/lib/iomgr/pollset.h +4 -0
  145. data/src/core/lib/iomgr/pollset_windows.c +2 -2
  146. data/src/core/lib/iomgr/port.h +9 -0
  147. data/src/core/lib/iomgr/resolve_address_posix.c +15 -9
  148. data/src/core/lib/iomgr/resolve_address_uv.c +8 -6
  149. data/src/core/lib/iomgr/resolve_address_windows.c +2 -2
  150. data/src/core/lib/iomgr/resource_quota.c +19 -4
  151. data/src/core/lib/iomgr/resource_quota.h +2 -0
  152. data/src/core/lib/iomgr/sockaddr_utils.c +3 -1
  153. data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
  154. data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
  155. data/src/core/lib/iomgr/socket_utils_common_posix.c +25 -9
  156. data/src/core/lib/iomgr/socket_utils_posix.h +7 -0
  157. data/src/core/lib/iomgr/tcp_client.h +0 -4
  158. data/src/core/lib/iomgr/tcp_client_posix.c +15 -31
  159. data/src/core/lib/iomgr/tcp_client_uv.c +10 -6
  160. data/src/core/lib/iomgr/tcp_client_windows.c +9 -19
  161. data/src/core/lib/iomgr/tcp_posix.c +111 -22
  162. data/src/core/lib/iomgr/tcp_posix.h +3 -4
  163. data/src/core/lib/iomgr/tcp_server_posix.c +39 -417
  164. data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
  165. data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
  166. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
  167. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
  168. data/src/core/lib/iomgr/tcp_server_uv.c +43 -16
  169. data/src/core/lib/iomgr/tcp_server_windows.c +10 -22
  170. data/src/core/lib/iomgr/tcp_uv.c +16 -13
  171. data/src/core/lib/iomgr/tcp_windows.c +24 -12
  172. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  173. data/src/core/lib/iomgr/timer.h +3 -0
  174. data/src/core/lib/iomgr/timer_generic.c +257 -72
  175. data/src/core/lib/iomgr/timer_generic.h +1 -1
  176. data/src/core/lib/iomgr/timer_heap.c +8 -8
  177. data/src/core/lib/iomgr/udp_server.c +54 -24
  178. data/src/core/lib/iomgr/udp_server.h +7 -7
  179. data/src/core/lib/iomgr/unix_sockets_posix.c +1 -1
  180. data/src/core/lib/iomgr/unix_sockets_posix_noop.c +2 -1
  181. data/src/core/lib/iomgr/wakeup_fd_posix.h +1 -1
  182. data/src/core/lib/profiling/basic_timers.c +1 -1
  183. data/src/core/lib/security/credentials/credentials.h +1 -1
  184. data/src/core/lib/security/credentials/google_default/google_default_credentials.c +10 -9
  185. data/src/core/lib/security/credentials/jwt/json_token.c +1 -1
  186. data/src/core/lib/security/credentials/jwt/jwt_verifier.c +2 -2
  187. data/src/core/lib/security/transport/client_auth_filter.c +33 -26
  188. data/src/core/lib/security/transport/secure_endpoint.c +8 -5
  189. data/src/core/lib/security/transport/security_connector.c +37 -37
  190. data/src/core/lib/security/transport/security_connector.h +1 -1
  191. data/src/core/lib/security/transport/security_handshaker.c +15 -12
  192. data/src/core/lib/security/transport/server_auth_filter.c +20 -18
  193. data/src/core/lib/security/transport/tsi_error.c +5 -3
  194. data/src/core/lib/security/transport/tsi_error.h +1 -1
  195. data/src/core/lib/{security/util → slice}/b64.c +21 -6
  196. data/src/core/lib/{security/util → slice}/b64.h +16 -4
  197. data/src/core/lib/slice/slice.c +4 -2
  198. data/src/core/lib/slice/slice_buffer.c +16 -14
  199. data/src/core/lib/support/arena.c +98 -0
  200. data/src/core/{ext/client_channel/initial_connect_string.c → lib/support/arena.h} +17 -15
  201. data/src/core/{ext/client_channel/default_initial_connect_string.c → lib/support/atm.c} +14 -5
  202. data/src/core/lib/support/cpu_linux.c +5 -0
  203. data/src/core/lib/support/sync.c +4 -0
  204. data/src/core/lib/support/time.c +4 -10
  205. data/src/core/lib/support/wrap_memcpy.c +3 -1
  206. data/src/core/lib/surface/call.c +252 -221
  207. data/src/core/lib/surface/channel.c +72 -21
  208. data/src/core/lib/surface/channel.h +8 -0
  209. data/src/core/lib/surface/completion_queue.c +2 -3
  210. data/src/core/lib/surface/completion_queue_factory.c +77 -0
  211. data/src/core/lib/surface/completion_queue_factory.h +51 -0
  212. data/src/core/lib/surface/init_secure.c +3 -1
  213. data/src/core/lib/surface/lame_client.c +18 -14
  214. data/src/core/lib/surface/server.c +43 -41
  215. data/src/core/lib/surface/validate_metadata.c +8 -4
  216. data/src/core/lib/surface/version.c +2 -2
  217. data/src/core/lib/transport/bdp_estimator.h +1 -1
  218. data/src/core/lib/transport/connectivity_state.c +2 -1
  219. data/src/core/lib/transport/error_utils.c +17 -17
  220. data/src/core/lib/transport/error_utils.h +1 -1
  221. data/src/core/lib/transport/metadata_batch.c +6 -7
  222. data/src/core/lib/transport/pid_controller.c +1 -0
  223. data/src/core/lib/transport/service_config.c +12 -0
  224. data/src/core/lib/transport/service_config.h +6 -0
  225. data/src/core/lib/transport/transport.c +29 -17
  226. data/src/core/lib/transport/transport.h +85 -42
  227. data/src/core/lib/transport/transport_impl.h +5 -3
  228. data/src/core/lib/transport/transport_op_string.c +20 -14
  229. data/src/core/plugin_registry/grpc_plugin_registry.c +8 -0
  230. data/src/core/{lib/tsi → tsi}/fake_transport_security.c +2 -2
  231. data/src/core/{lib/tsi → tsi}/fake_transport_security.h +4 -4
  232. data/src/core/{lib/tsi → tsi}/ssl_transport_security.c +40 -79
  233. data/src/core/{lib/tsi → tsi}/ssl_transport_security.h +44 -21
  234. data/src/core/{lib/tsi → tsi}/ssl_types.h +3 -3
  235. data/src/core/{lib/tsi → tsi}/transport_security.c +2 -2
  236. data/src/core/{lib/tsi → tsi}/transport_security.h +4 -4
  237. data/src/core/{lib/tsi → tsi}/transport_security_interface.h +3 -3
  238. data/src/ruby/ext/grpc/extconf.rb +1 -0
  239. data/src/ruby/ext/grpc/rb_call_credentials.c +2 -2
  240. data/src/ruby/ext/grpc/rb_channel.c +520 -93
  241. data/src/ruby/ext/grpc/rb_channel.h +2 -0
  242. data/src/ruby/ext/grpc/rb_channel_credentials.c +3 -0
  243. data/src/ruby/ext/grpc/rb_compression_options.c +5 -2
  244. data/src/ruby/ext/grpc/rb_event_thread.c +6 -6
  245. data/src/ruby/ext/grpc/rb_grpc.c +29 -7
  246. data/src/ruby/ext/grpc/rb_grpc.h +2 -0
  247. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +10 -0
  248. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +15 -0
  249. data/src/ruby/ext/grpc/rb_server.c +5 -3
  250. data/src/ruby/lib/grpc/version.rb +1 -1
  251. data/src/ruby/spec/channel_connection_spec.rb +173 -0
  252. data/src/ruby/spec/channel_spec.rb +29 -0
  253. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +27 -17
  254. data/third_party/cares/ares_build.h +264 -0
  255. data/third_party/cares/cares/ares.h +636 -0
  256. data/third_party/cares/cares/ares__close_sockets.c +61 -0
  257. data/third_party/cares/cares/ares__get_hostent.c +261 -0
  258. data/third_party/cares/cares/ares__read_line.c +73 -0
  259. data/third_party/cares/cares/ares__timeval.c +111 -0
  260. data/third_party/cares/cares/ares_cancel.c +63 -0
  261. data/third_party/cares/cares/ares_create_query.c +202 -0
  262. data/third_party/cares/cares/ares_data.c +221 -0
  263. data/third_party/cares/cares/ares_data.h +72 -0
  264. data/third_party/cares/cares/ares_destroy.c +108 -0
  265. data/third_party/cares/cares/ares_dns.h +103 -0
  266. data/third_party/cares/cares/ares_expand_name.c +205 -0
  267. data/third_party/cares/cares/ares_expand_string.c +70 -0
  268. data/third_party/cares/cares/ares_fds.c +59 -0
  269. data/third_party/cares/cares/ares_free_hostent.c +41 -0
  270. data/third_party/cares/cares/ares_free_string.c +25 -0
  271. data/third_party/cares/cares/ares_getenv.c +30 -0
  272. data/third_party/cares/cares/ares_getenv.h +26 -0
  273. data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
  274. data/third_party/cares/cares/ares_gethostbyname.c +518 -0
  275. data/third_party/cares/cares/ares_getnameinfo.c +422 -0
  276. data/third_party/cares/cares/ares_getopt.c +122 -0
  277. data/third_party/cares/cares/ares_getopt.h +53 -0
  278. data/third_party/cares/cares/ares_getsock.c +66 -0
  279. data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
  280. data/third_party/cares/cares/ares_init.c +2146 -0
  281. data/third_party/cares/cares/ares_iphlpapi.h +221 -0
  282. data/third_party/cares/cares/ares_ipv6.h +78 -0
  283. data/third_party/cares/cares/ares_library_init.c +167 -0
  284. data/third_party/cares/cares/ares_library_init.h +42 -0
  285. data/third_party/cares/cares/ares_llist.c +63 -0
  286. data/third_party/cares/cares/ares_llist.h +39 -0
  287. data/third_party/cares/cares/ares_mkquery.c +24 -0
  288. data/third_party/cares/cares/ares_nowarn.c +260 -0
  289. data/third_party/cares/cares/ares_nowarn.h +61 -0
  290. data/third_party/cares/cares/ares_options.c +402 -0
  291. data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
  292. data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
  293. data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
  294. data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
  295. data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
  296. data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
  297. data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
  298. data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
  299. data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
  300. data/third_party/cares/cares/ares_platform.c +11035 -0
  301. data/third_party/cares/cares/ares_platform.h +43 -0
  302. data/third_party/cares/cares/ares_private.h +363 -0
  303. data/third_party/cares/cares/ares_process.c +1359 -0
  304. data/third_party/cares/cares/ares_query.c +186 -0
  305. data/third_party/cares/cares/ares_rules.h +125 -0
  306. data/third_party/cares/cares/ares_search.c +316 -0
  307. data/third_party/cares/cares/ares_send.c +131 -0
  308. data/third_party/cares/cares/ares_setup.h +217 -0
  309. data/third_party/cares/cares/ares_strcasecmp.c +66 -0
  310. data/third_party/cares/cares/ares_strcasecmp.h +30 -0
  311. data/third_party/cares/cares/ares_strdup.c +49 -0
  312. data/third_party/cares/cares/ares_strdup.h +24 -0
  313. data/third_party/cares/cares/ares_strerror.c +56 -0
  314. data/third_party/cares/cares/ares_timeout.c +88 -0
  315. data/third_party/cares/cares/ares_version.c +11 -0
  316. data/third_party/cares/cares/ares_version.h +24 -0
  317. data/third_party/cares/cares/ares_writev.c +79 -0
  318. data/third_party/cares/cares/bitncmp.c +59 -0
  319. data/third_party/cares/cares/bitncmp.h +26 -0
  320. data/third_party/cares/cares/config-win32.h +377 -0
  321. data/third_party/cares/cares/inet_net_pton.c +450 -0
  322. data/third_party/cares/cares/inet_ntop.c +208 -0
  323. data/third_party/cares/cares/setup_once.h +554 -0
  324. data/third_party/cares/cares/windows_port.c +22 -0
  325. data/third_party/cares/config_darwin/ares_config.h +523 -0
  326. data/third_party/cares/config_linux/ares_config.h +524 -0
  327. metadata +164 -68
@@ -54,7 +54,8 @@ void grpc_chttp2_data_parser_destroy(grpc_exec_ctx *exec_ctx,
54
54
  grpc_chttp2_data_parser *parser) {
55
55
  if (parser->parsing_frame != NULL) {
56
56
  grpc_chttp2_incoming_byte_stream_finished(
57
- exec_ctx, parser->parsing_frame, GRPC_ERROR_CREATE("Parser destroyed"));
57
+ exec_ctx, parser->parsing_frame,
58
+ GRPC_ERROR_CREATE_FROM_STATIC_STRING("Parser destroyed"));
58
59
  }
59
60
  GRPC_ERROR_UNREF(parser->error);
60
61
  }
@@ -65,8 +66,9 @@ grpc_error *grpc_chttp2_data_parser_begin_frame(grpc_chttp2_data_parser *parser,
65
66
  if (flags & ~GRPC_CHTTP2_DATA_FLAG_END_STREAM) {
66
67
  char *msg;
67
68
  gpr_asprintf(&msg, "unsupported data flags: 0x%02x", flags);
68
- grpc_error *err = grpc_error_set_int(
69
- GRPC_ERROR_CREATE(msg), GRPC_ERROR_INT_STREAM_ID, (intptr_t)stream_id);
69
+ grpc_error *err =
70
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg),
71
+ GRPC_ERROR_INT_STREAM_ID, (intptr_t)stream_id);
70
72
  gpr_free(msg);
71
73
  return err;
72
74
  }
@@ -173,13 +175,13 @@ static grpc_error *parse_inner(grpc_exec_ctx *exec_ctx,
173
175
  break;
174
176
  default:
175
177
  gpr_asprintf(&msg, "Bad GRPC frame type 0x%02x", p->frame_type);
176
- p->error = GRPC_ERROR_CREATE(msg);
178
+ p->error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
177
179
  p->error = grpc_error_set_int(p->error, GRPC_ERROR_INT_STREAM_ID,
178
180
  (intptr_t)s->id);
179
181
  gpr_free(msg);
180
182
  msg = grpc_dump_slice(slice, GPR_DUMP_HEX | GPR_DUMP_ASCII);
181
- p->error =
182
- grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES, msg);
183
+ p->error = grpc_error_set_str(p->error, GRPC_ERROR_STR_RAW_BYTES,
184
+ grpc_slice_from_copied_string(msg));
183
185
  gpr_free(msg);
184
186
  p->error =
185
187
  grpc_error_set_int(p->error, GRPC_ERROR_INT_OFFSET, cur - beg);
@@ -265,7 +267,8 @@ static grpc_error *parse_inner(grpc_exec_ctx *exec_ctx,
265
267
  }
266
268
  }
267
269
 
268
- GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
270
+ GPR_UNREACHABLE_CODE(
271
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
269
272
  }
270
273
 
271
274
  grpc_error *grpc_chttp2_data_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
@@ -54,7 +54,7 @@ grpc_error *grpc_chttp2_goaway_parser_begin_frame(grpc_chttp2_goaway_parser *p,
54
54
  if (length < 8) {
55
55
  char *msg;
56
56
  gpr_asprintf(&msg, "goaway frame too short (%d bytes)", length);
57
- grpc_error *err = GRPC_ERROR_CREATE(msg);
57
+ grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
58
58
  gpr_free(msg);
59
59
  return err;
60
60
  }
@@ -156,7 +156,8 @@ grpc_error *grpc_chttp2_goaway_parser_parse(grpc_exec_ctx *exec_ctx,
156
156
  }
157
157
  return GRPC_ERROR_NONE;
158
158
  }
159
- GPR_UNREACHABLE_CODE(return GRPC_ERROR_CREATE("Should never reach here"));
159
+ GPR_UNREACHABLE_CODE(
160
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here"));
160
161
  }
161
162
 
162
163
  void grpc_chttp2_goaway_append(uint32_t last_stream_id, uint32_t error_code,
@@ -40,6 +40,8 @@
40
40
  #include <grpc/support/log.h>
41
41
  #include <grpc/support/string_util.h>
42
42
 
43
+ static bool g_disable_ping_ack = false;
44
+
43
45
  grpc_slice grpc_chttp2_ping_create(uint8_t ack, uint64_t opaque_8bytes) {
44
46
  grpc_slice slice = grpc_slice_malloc(9 + 8);
45
47
  uint8_t *p = GRPC_SLICE_START_PTR(slice);
@@ -71,7 +73,7 @@ grpc_error *grpc_chttp2_ping_parser_begin_frame(grpc_chttp2_ping_parser *parser,
71
73
  if (flags & 0xfe || length != 8) {
72
74
  char *msg;
73
75
  gpr_asprintf(&msg, "invalid ping: length=%d, flags=%02x", length, flags);
74
- grpc_error *error = GRPC_ERROR_CREATE(msg);
76
+ grpc_error *error = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
75
77
  gpr_free(msg);
76
78
  return error;
77
79
  }
@@ -101,15 +103,43 @@ grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
101
103
  if (p->is_ack) {
102
104
  grpc_chttp2_ack_ping(exec_ctx, t, p->opaque_8bytes);
103
105
  } else {
104
- if (t->ping_ack_count == t->ping_ack_capacity) {
105
- t->ping_ack_capacity = GPR_MAX(t->ping_ack_capacity * 3 / 2, 3);
106
- t->ping_acks = gpr_realloc(
107
- t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks));
106
+ if (!t->is_client) {
107
+ gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
108
+ gpr_timespec next_allowed_ping =
109
+ gpr_time_add(t->ping_recv_state.last_ping_recv_time,
110
+ t->ping_policy.min_ping_interval_without_data);
111
+
112
+ if (t->keepalive_permit_without_calls == 0 &&
113
+ grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
114
+ /* According to RFC1122, the interval of TCP Keep-Alive is default to
115
+ no less than two hours. When there is no outstanding streams, we
116
+ restrict the number of PINGS equivalent to TCP Keep-Alive. */
117
+ next_allowed_ping =
118
+ gpr_time_add(t->ping_recv_state.last_ping_recv_time,
119
+ gpr_time_from_seconds(7200, GPR_TIMESPAN));
120
+ }
121
+
122
+ if (gpr_time_cmp(next_allowed_ping, now) > 0) {
123
+ grpc_chttp2_add_ping_strike(exec_ctx, t);
124
+ }
125
+
126
+ t->ping_recv_state.last_ping_recv_time = now;
127
+ }
128
+ if (!g_disable_ping_ack) {
129
+ if (t->ping_ack_count == t->ping_ack_capacity) {
130
+ t->ping_ack_capacity = GPR_MAX(t->ping_ack_capacity * 3 / 2, 3);
131
+ t->ping_acks = gpr_realloc(
132
+ t->ping_acks, t->ping_ack_capacity * sizeof(*t->ping_acks));
133
+ }
134
+ t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes;
135
+ grpc_chttp2_initiate_write(exec_ctx, t, false, "ping response");
108
136
  }
109
- t->ping_acks[t->ping_ack_count++] = p->opaque_8bytes;
110
- grpc_chttp2_initiate_write(exec_ctx, t, false, "ping response");
111
137
  }
112
138
  }
113
139
 
114
140
  return GRPC_ERROR_NONE;
115
141
  }
142
+
143
+ void grpc_set_disable_ping_ack(bool disable_ping_ack) {
144
+ g_disable_ping_ack = disable_ping_ack;
145
+ }
@@ -53,4 +53,7 @@ grpc_error *grpc_chttp2_ping_parser_parse(grpc_exec_ctx *exec_ctx, void *parser,
53
53
  grpc_chttp2_stream *s,
54
54
  grpc_slice slice, int is_last);
55
55
 
56
+ /* Test-only function for disabling ping ack */
57
+ void grpc_set_disable_ping_ack(bool disable_ping_ack);
58
+
56
59
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_PING_H */
@@ -76,7 +76,7 @@ grpc_error *grpc_chttp2_rst_stream_parser_begin_frame(
76
76
  char *msg;
77
77
  gpr_asprintf(&msg, "invalid rst_stream: length=%d, flags=%02x", length,
78
78
  flags);
79
- grpc_error *err = GRPC_ERROR_CREATE(msg);
79
+ grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
80
80
  gpr_free(msg);
81
81
  return err;
82
82
  }
@@ -112,8 +112,9 @@ grpc_error *grpc_chttp2_rst_stream_parser_parse(grpc_exec_ctx *exec_ctx,
112
112
  char *message;
113
113
  gpr_asprintf(&message, "Received RST_STREAM with error code %d", reason);
114
114
  error = grpc_error_set_int(
115
- grpc_error_set_str(GRPC_ERROR_CREATE("RST_STREAM"),
116
- GRPC_ERROR_STR_GRPC_MESSAGE, message),
115
+ grpc_error_set_str(GRPC_ERROR_CREATE_FROM_STATIC_STRING("RST_STREAM"),
116
+ GRPC_ERROR_STR_GRPC_MESSAGE,
117
+ grpc_slice_from_copied_string(message)),
117
118
  GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)reason);
118
119
  gpr_free(message);
119
120
  }
@@ -46,29 +46,6 @@
46
46
  #include "src/core/lib/debug/trace.h"
47
47
  #include "src/core/lib/transport/http2_errors.h"
48
48
 
49
- #define MAX_MAX_HEADER_LIST_SIZE (1024 * 1024 * 1024)
50
-
51
- /* HTTP/2 mandated initial connection settings */
52
- const grpc_chttp2_setting_parameters
53
- grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS] = {
54
- {NULL, 0, 0, 0, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE,
55
- GRPC_HTTP2_PROTOCOL_ERROR},
56
- {"HEADER_TABLE_SIZE", 4096, 0, 0xffffffff,
57
- GRPC_CHTTP2_CLAMP_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR},
58
- {"ENABLE_PUSH", 1, 0, 1, GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE,
59
- GRPC_HTTP2_PROTOCOL_ERROR},
60
- {"MAX_CONCURRENT_STREAMS", 0xffffffffu, 0, 0xffffffffu,
61
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR},
62
- {"INITIAL_WINDOW_SIZE", 65535, 0, 0x7fffffffu,
63
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE,
64
- GRPC_HTTP2_FLOW_CONTROL_ERROR},
65
- {"MAX_FRAME_SIZE", 16384, 16384, 16777215,
66
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE, GRPC_HTTP2_PROTOCOL_ERROR},
67
- {"MAX_HEADER_LIST_SIZE", MAX_MAX_HEADER_LIST_SIZE, 0,
68
- MAX_MAX_HEADER_LIST_SIZE, GRPC_CHTTP2_CLAMP_INVALID_VALUE,
69
- GRPC_HTTP2_PROTOCOL_ERROR},
70
- };
71
-
72
49
  static uint8_t *fill_header(uint8_t *out, uint32_t length, uint8_t flags) {
73
50
  *out++ = (uint8_t)(length >> 16);
74
51
  *out++ = (uint8_t)(length >> 8);
@@ -98,9 +75,8 @@ grpc_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *new,
98
75
 
99
76
  for (i = 0; i < count; i++) {
100
77
  if (new[i] != old[i] || (force_mask & (1u << i)) != 0) {
101
- GPR_ASSERT(i);
102
- *p++ = (uint8_t)(i >> 8);
103
- *p++ = (uint8_t)(i);
78
+ *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i] >> 8);
79
+ *p++ = (uint8_t)(grpc_setting_id_to_wire_id[i]);
104
80
  *p++ = (uint8_t)(new[i] >> 24);
105
81
  *p++ = (uint8_t)(new[i] >> 16);
106
82
  *p++ = (uint8_t)(new[i] >> 8);
@@ -131,13 +107,16 @@ grpc_error *grpc_chttp2_settings_parser_begin_frame(
131
107
  if (flags == GRPC_CHTTP2_FLAG_ACK) {
132
108
  parser->is_ack = 1;
133
109
  if (length != 0) {
134
- return GRPC_ERROR_CREATE("non-empty settings ack frame received");
110
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
111
+ "non-empty settings ack frame received");
135
112
  }
136
113
  return GRPC_ERROR_NONE;
137
114
  } else if (flags != 0) {
138
- return GRPC_ERROR_CREATE("invalid flags on settings frame");
115
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
116
+ "invalid flags on settings frame");
139
117
  } else if (length % 6 != 0) {
140
- return GRPC_ERROR_CREATE("settings frames must be a multiple of six bytes");
118
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
119
+ "settings frames must be a multiple of six bytes");
141
120
  } else {
142
121
  return GRPC_ERROR_NONE;
143
122
  }
@@ -151,6 +130,7 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p,
151
130
  const uint8_t *cur = GRPC_SLICE_START_PTR(slice);
152
131
  const uint8_t *end = GRPC_SLICE_END_PTR(slice);
153
132
  char *msg;
133
+ grpc_chttp2_setting_id id;
154
134
 
155
135
  if (parser->is_ack) {
156
136
  return GRPC_ERROR_NONE;
@@ -213,9 +193,9 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p,
213
193
  parser->value |= *cur;
214
194
  cur++;
215
195
 
216
- if (parser->id > 0 && parser->id < GRPC_CHTTP2_NUM_SETTINGS) {
196
+ if (grpc_wire_id_to_setting_id(parser->id, &id)) {
217
197
  const grpc_chttp2_setting_parameters *sp =
218
- &grpc_chttp2_settings_parameters[parser->id];
198
+ &grpc_chttp2_settings_parameters[id];
219
199
  if (parser->value < sp->min_value || parser->value > sp->max_value) {
220
200
  switch (sp->invalid_value_behavior) {
221
201
  case GRPC_CHTTP2_CLAMP_INVALID_VALUE:
@@ -229,24 +209,24 @@ grpc_error *grpc_chttp2_settings_parser_parse(grpc_exec_ctx *exec_ctx, void *p,
229
209
  &t->qbuf);
230
210
  gpr_asprintf(&msg, "invalid value %u passed for %s",
231
211
  parser->value, sp->name);
232
- grpc_error *err = GRPC_ERROR_CREATE(msg);
212
+ grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
233
213
  gpr_free(msg);
234
214
  return err;
235
215
  }
236
216
  }
237
- if (parser->id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE &&
238
- parser->incoming_settings[parser->id] != parser->value) {
217
+ if (id == GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE &&
218
+ parser->incoming_settings[id] != parser->value) {
239
219
  t->initial_window_update +=
240
- (int64_t)parser->value - parser->incoming_settings[parser->id];
220
+ (int64_t)parser->value - parser->incoming_settings[id];
241
221
  if (grpc_http_trace) {
242
222
  gpr_log(GPR_DEBUG, "adding %d for initial_window change",
243
223
  (int)t->initial_window_update);
244
224
  }
245
225
  }
246
- parser->incoming_settings[parser->id] = parser->value;
226
+ parser->incoming_settings[id] = parser->value;
247
227
  if (grpc_http_trace) {
248
- gpr_log(GPR_DEBUG, "CHTTP2:%s:%s: got setting %d = %d",
249
- t->is_client ? "CLI" : "SVR", t->peer_string, parser->id,
228
+ gpr_log(GPR_DEBUG, "CHTTP2:%s:%s: got setting %s = %d",
229
+ t->is_client ? "CLI" : "SVR", t->peer_string, sp->name,
250
230
  parser->value);
251
231
  }
252
232
  } else if (grpc_http_trace) {
@@ -37,6 +37,7 @@
37
37
  #include <grpc/slice.h>
38
38
  #include <grpc/support/port_platform.h>
39
39
  #include "src/core/ext/transport/chttp2/transport/frame.h"
40
+ #include "src/core/ext/transport/chttp2/transport/http2_settings.h"
40
41
  #include "src/core/lib/iomgr/exec_ctx.h"
41
42
 
42
43
  typedef enum {
@@ -48,17 +49,6 @@ typedef enum {
48
49
  GRPC_CHTTP2_SPS_VAL3
49
50
  } grpc_chttp2_settings_parse_state;
50
51
 
51
- /* The things HTTP/2 defines as connection level settings */
52
- typedef enum {
53
- GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE = 1,
54
- GRPC_CHTTP2_SETTINGS_ENABLE_PUSH = 2,
55
- GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS = 3,
56
- GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE = 4,
57
- GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE = 5,
58
- GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE = 6,
59
- GRPC_CHTTP2_NUM_SETTINGS
60
- } grpc_chttp2_setting_id;
61
-
62
52
  typedef struct {
63
53
  grpc_chttp2_settings_parse_state state;
64
54
  uint32_t *target_settings;
@@ -68,24 +58,6 @@ typedef struct {
68
58
  uint32_t incoming_settings[GRPC_CHTTP2_NUM_SETTINGS];
69
59
  } grpc_chttp2_settings_parser;
70
60
 
71
- typedef enum {
72
- GRPC_CHTTP2_CLAMP_INVALID_VALUE,
73
- GRPC_CHTTP2_DISCONNECT_ON_INVALID_VALUE
74
- } grpc_chttp2_invalid_value_behavior;
75
-
76
- typedef struct {
77
- const char *name;
78
- uint32_t default_value;
79
- uint32_t min_value;
80
- uint32_t max_value;
81
- grpc_chttp2_invalid_value_behavior invalid_value_behavior;
82
- uint32_t error_value;
83
- } grpc_chttp2_setting_parameters;
84
-
85
- /* HTTP/2 mandated connection setting parameters */
86
- extern const grpc_chttp2_setting_parameters
87
- grpc_chttp2_settings_parameters[GRPC_CHTTP2_NUM_SETTINGS];
88
-
89
61
  /* Create a settings frame by diffing old & new, and updating old to be new */
90
62
  grpc_slice grpc_chttp2_settings_create(uint32_t *old, const uint32_t *newval,
91
63
  uint32_t force_mask, size_t count);
@@ -70,7 +70,7 @@ grpc_error *grpc_chttp2_window_update_parser_begin_frame(
70
70
  char *msg;
71
71
  gpr_asprintf(&msg, "invalid window update: length=%d, flags=%02x", length,
72
72
  flags);
73
- grpc_error *err = GRPC_ERROR_CREATE(msg);
73
+ grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
74
74
  gpr_free(msg);
75
75
  return err;
76
76
  }
@@ -102,7 +102,7 @@ grpc_error *grpc_chttp2_window_update_parser_parse(
102
102
  if (received_update == 0 || (received_update & 0x80000000u)) {
103
103
  char *msg;
104
104
  gpr_asprintf(&msg, "invalid window update bytes: %d", p->amount);
105
- grpc_error *err = GRPC_ERROR_CREATE(msg);
105
+ grpc_error *err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(msg);
106
106
  gpr_free(msg);
107
107
  return err;
108
108
  }
@@ -86,6 +86,7 @@ typedef struct {
86
86
  grpc_transport_one_way_stats *stats;
87
87
  /* maximum size of a frame */
88
88
  size_t max_frame_size;
89
+ bool use_true_binary_metadata;
89
90
  } framer_state;
90
91
 
91
92
  /* fills p (which is expected to be 9 bytes long) with a data frame header */
@@ -290,86 +291,113 @@ static void emit_indexed(grpc_chttp2_hpack_compressor *c, uint32_t elem_index,
290
291
  len);
291
292
  }
292
293
 
293
- static grpc_slice get_wire_value(grpc_mdelem elem, uint8_t *huffman_prefix) {
294
+ typedef struct {
295
+ grpc_slice data;
296
+ uint8_t huffman_prefix;
297
+ bool insert_null_before_wire_value;
298
+ } wire_value;
299
+
300
+ static wire_value get_wire_value(grpc_mdelem elem, bool true_binary_enabled) {
294
301
  if (grpc_is_binary_header(GRPC_MDKEY(elem))) {
295
- *huffman_prefix = 0x80;
296
- return grpc_chttp2_base64_encode_and_huffman_compress(GRPC_MDVALUE(elem));
302
+ if (true_binary_enabled) {
303
+ return (wire_value){
304
+ .huffman_prefix = 0x00,
305
+ .insert_null_before_wire_value = true,
306
+ .data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)),
307
+ };
308
+ } else {
309
+ return (wire_value){
310
+ .huffman_prefix = 0x80,
311
+ .insert_null_before_wire_value = false,
312
+ .data = grpc_chttp2_base64_encode_and_huffman_compress(
313
+ GRPC_MDVALUE(elem)),
314
+ };
315
+ }
316
+ } else {
317
+ /* TODO(ctiller): opportunistically compress non-binary headers */
318
+ return (wire_value){
319
+ .huffman_prefix = 0x00,
320
+ .insert_null_before_wire_value = false,
321
+ .data = grpc_slice_ref_internal(GRPC_MDVALUE(elem)),
322
+ };
297
323
  }
298
- /* TODO(ctiller): opportunistically compress non-binary headers */
299
- *huffman_prefix = 0x00;
300
- return grpc_slice_ref_internal(GRPC_MDVALUE(elem));
324
+ }
325
+
326
+ static size_t wire_value_length(wire_value v) {
327
+ return GPR_SLICE_LENGTH(v.data) + v.insert_null_before_wire_value;
328
+ }
329
+
330
+ static void add_wire_value(framer_state *st, wire_value v) {
331
+ if (v.insert_null_before_wire_value) *add_tiny_header_data(st, 1) = 0;
332
+ add_header_data(st, v.data);
301
333
  }
302
334
 
303
335
  static void emit_lithdr_incidx(grpc_chttp2_hpack_compressor *c,
304
336
  uint32_t key_index, grpc_mdelem elem,
305
337
  framer_state *st) {
306
338
  uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 2);
307
- uint8_t huffman_prefix;
308
- grpc_slice value_slice = get_wire_value(elem, &huffman_prefix);
309
- size_t len_val = GRPC_SLICE_LENGTH(value_slice);
339
+ wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
340
+ size_t len_val = wire_value_length(value);
310
341
  uint32_t len_val_len;
311
342
  GPR_ASSERT(len_val <= UINT32_MAX);
312
343
  len_val_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)len_val, 1);
313
344
  GRPC_CHTTP2_WRITE_VARINT(key_index, 2, 0x40,
314
345
  add_tiny_header_data(st, len_pfx), len_pfx);
315
- GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix,
346
+ GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, value.huffman_prefix,
316
347
  add_tiny_header_data(st, len_val_len), len_val_len);
317
- add_header_data(st, value_slice);
348
+ add_wire_value(st, value);
318
349
  }
319
350
 
320
351
  static void emit_lithdr_noidx(grpc_chttp2_hpack_compressor *c,
321
352
  uint32_t key_index, grpc_mdelem elem,
322
353
  framer_state *st) {
323
354
  uint32_t len_pfx = GRPC_CHTTP2_VARINT_LENGTH(key_index, 4);
324
- uint8_t huffman_prefix;
325
- grpc_slice value_slice = get_wire_value(elem, &huffman_prefix);
326
- size_t len_val = GRPC_SLICE_LENGTH(value_slice);
355
+ wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
356
+ size_t len_val = wire_value_length(value);
327
357
  uint32_t len_val_len;
328
358
  GPR_ASSERT(len_val <= UINT32_MAX);
329
359
  len_val_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)len_val, 1);
330
360
  GRPC_CHTTP2_WRITE_VARINT(key_index, 4, 0x00,
331
361
  add_tiny_header_data(st, len_pfx), len_pfx);
332
- GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, huffman_prefix,
362
+ GRPC_CHTTP2_WRITE_VARINT((uint32_t)len_val, 1, value.huffman_prefix,
333
363
  add_tiny_header_data(st, len_val_len), len_val_len);
334
- add_header_data(st, value_slice);
364
+ add_wire_value(st, value);
335
365
  }
336
366
 
337
367
  static void emit_lithdr_incidx_v(grpc_chttp2_hpack_compressor *c,
338
368
  grpc_mdelem elem, framer_state *st) {
339
369
  uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem));
340
- uint8_t huffman_prefix;
341
- grpc_slice value_slice = get_wire_value(elem, &huffman_prefix);
342
- uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice);
370
+ wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
371
+ uint32_t len_val = (uint32_t)wire_value_length(value);
343
372
  uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
344
373
  uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
345
374
  GPR_ASSERT(len_key <= UINT32_MAX);
346
- GPR_ASSERT(GRPC_SLICE_LENGTH(value_slice) <= UINT32_MAX);
375
+ GPR_ASSERT(wire_value_length(value) <= UINT32_MAX);
347
376
  *add_tiny_header_data(st, 1) = 0x40;
348
377
  GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
349
378
  add_tiny_header_data(st, len_key_len), len_key_len);
350
379
  add_header_data(st, grpc_slice_ref_internal(GRPC_MDKEY(elem)));
351
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
380
+ GRPC_CHTTP2_WRITE_VARINT(len_val, 1, value.huffman_prefix,
352
381
  add_tiny_header_data(st, len_val_len), len_val_len);
353
- add_header_data(st, value_slice);
382
+ add_wire_value(st, value);
354
383
  }
355
384
 
356
385
  static void emit_lithdr_noidx_v(grpc_chttp2_hpack_compressor *c,
357
386
  grpc_mdelem elem, framer_state *st) {
358
387
  uint32_t len_key = (uint32_t)GRPC_SLICE_LENGTH(GRPC_MDKEY(elem));
359
- uint8_t huffman_prefix;
360
- grpc_slice value_slice = get_wire_value(elem, &huffman_prefix);
361
- uint32_t len_val = (uint32_t)GRPC_SLICE_LENGTH(value_slice);
388
+ wire_value value = get_wire_value(elem, st->use_true_binary_metadata);
389
+ uint32_t len_val = (uint32_t)wire_value_length(value);
362
390
  uint32_t len_key_len = GRPC_CHTTP2_VARINT_LENGTH(len_key, 1);
363
391
  uint32_t len_val_len = GRPC_CHTTP2_VARINT_LENGTH(len_val, 1);
364
392
  GPR_ASSERT(len_key <= UINT32_MAX);
365
- GPR_ASSERT(GRPC_SLICE_LENGTH(value_slice) <= UINT32_MAX);
393
+ GPR_ASSERT(wire_value_length(value) <= UINT32_MAX);
366
394
  *add_tiny_header_data(st, 1) = 0x00;
367
395
  GRPC_CHTTP2_WRITE_VARINT(len_key, 1, 0x00,
368
396
  add_tiny_header_data(st, len_key_len), len_key_len);
369
397
  add_header_data(st, grpc_slice_ref_internal(GRPC_MDKEY(elem)));
370
- GRPC_CHTTP2_WRITE_VARINT(len_val, 1, huffman_prefix,
398
+ GRPC_CHTTP2_WRITE_VARINT(len_val, 1, value.huffman_prefix,
371
399
  add_tiny_header_data(st, len_val_len), len_val_len);
372
- add_header_data(st, value_slice);
400
+ add_wire_value(st, value);
373
401
  }
374
402
 
375
403
  static void emit_advertise_table_size_change(grpc_chttp2_hpack_compressor *c,
@@ -595,23 +623,22 @@ void grpc_chttp2_hpack_compressor_set_max_table_size(
595
623
 
596
624
  void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx,
597
625
  grpc_chttp2_hpack_compressor *c,
598
- uint32_t stream_id,
599
- grpc_metadata_batch *metadata, int is_eof,
600
- size_t max_frame_size,
601
- grpc_transport_one_way_stats *stats,
626
+ grpc_metadata_batch *metadata,
627
+ const grpc_encode_header_options *options,
602
628
  grpc_slice_buffer *outbuf) {
603
629
  framer_state st;
604
630
  grpc_linked_mdelem *l;
605
631
  gpr_timespec deadline;
606
632
 
607
- GPR_ASSERT(stream_id != 0);
633
+ GPR_ASSERT(options->stream_id != 0);
608
634
 
609
635
  st.seen_regular_header = 0;
610
- st.stream_id = stream_id;
636
+ st.stream_id = options->stream_id;
611
637
  st.output = outbuf;
612
638
  st.is_first_frame = 1;
613
- st.stats = stats;
614
- st.max_frame_size = max_frame_size;
639
+ st.stats = options->stats;
640
+ st.max_frame_size = options->max_frame_size;
641
+ st.use_true_binary_metadata = options->use_true_binary_metadata;
615
642
 
616
643
  /* Encode a metadata batch; store the returned values, representing
617
644
  a metadata element that needs to be unreffed back into the metadata
@@ -630,5 +657,5 @@ void grpc_chttp2_encode_header(grpc_exec_ctx *exec_ctx,
630
657
  deadline_enc(exec_ctx, c, deadline, &st);
631
658
  }
632
659
 
633
- finish_frame(&st, 1, is_eof);
660
+ finish_frame(&st, 1, options->is_eof);
634
661
  }