grpc 1.37.1 → 1.40.0.pre1

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

Potentially problematic release.


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

Files changed (738) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +112 -59
  3. data/include/grpc/event_engine/README.md +38 -0
  4. data/include/grpc/event_engine/endpoint_config.h +48 -0
  5. data/include/grpc/event_engine/event_engine.h +330 -0
  6. data/include/grpc/event_engine/port.h +41 -0
  7. data/include/grpc/event_engine/slice_allocator.h +66 -0
  8. data/include/grpc/grpc.h +11 -4
  9. data/include/grpc/grpc_security.h +32 -0
  10. data/include/grpc/grpc_security_constants.h +15 -0
  11. data/include/grpc/impl/codegen/grpc_types.h +44 -19
  12. data/include/grpc/impl/codegen/port_platform.h +46 -0
  13. data/include/grpc/module.modulemap +14 -14
  14. data/src/core/ext/filters/client_channel/backup_poller.cc +3 -3
  15. data/src/core/ext/filters/client_channel/channel_connectivity.cc +177 -202
  16. data/src/core/ext/filters/client_channel/client_channel.cc +975 -3282
  17. data/src/core/ext/filters/client_channel/client_channel.h +513 -55
  18. data/src/core/ext/filters/client_channel/client_channel_channelz.h +1 -1
  19. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -1
  20. data/src/core/ext/filters/client_channel/config_selector.h +20 -7
  21. data/src/core/ext/filters/client_channel/connector.h +1 -1
  22. data/src/core/ext/filters/client_channel/dynamic_filters.cc +9 -10
  23. data/src/core/ext/filters/client_channel/dynamic_filters.h +3 -3
  24. data/src/core/ext/filters/client_channel/health/health_check_client.cc +28 -27
  25. data/src/core/ext/filters/client_channel/health/health_check_client.h +30 -29
  26. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +24 -21
  27. data/src/core/ext/filters/client_channel/http_proxy.cc +16 -1
  28. data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.cc +6 -6
  29. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +53 -51
  30. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -1
  31. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +2 -1
  32. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +14 -23
  33. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +16 -16
  34. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +734 -0
  35. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.h +10 -0
  36. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +10 -17
  37. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +1 -1
  38. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +17 -20
  39. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +53 -65
  40. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +36 -44
  41. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +33 -55
  42. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +151 -163
  43. data/src/core/ext/filters/client_channel/lb_policy.cc +2 -16
  44. data/src/core/ext/filters/client_channel/lb_policy.h +70 -46
  45. data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
  46. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -4
  47. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  48. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +24 -18
  49. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -1
  50. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_event_engine.cc +31 -0
  51. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +3 -3
  52. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +2 -2
  53. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +14 -14
  54. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +33 -24
  55. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +1 -1
  56. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_event_engine.cc +28 -0
  57. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +1 -1
  58. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +1 -1
  59. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +18 -12
  60. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +20 -28
  61. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +7 -5
  62. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +20 -13
  63. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +1 -1
  64. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +158 -102
  65. data/src/core/ext/filters/client_channel/resolver.h +2 -2
  66. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +32 -239
  67. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +20 -49
  68. data/src/core/ext/filters/client_channel/retry_filter.cc +2598 -0
  69. data/src/core/ext/filters/client_channel/retry_filter.h +30 -0
  70. data/src/core/ext/filters/client_channel/retry_service_config.cc +316 -0
  71. data/src/core/ext/filters/client_channel/retry_service_config.h +96 -0
  72. data/src/core/ext/filters/client_channel/server_address.cc +1 -1
  73. data/src/core/ext/filters/client_channel/service_config.cc +15 -14
  74. data/src/core/ext/filters/client_channel/service_config.h +7 -6
  75. data/src/core/ext/filters/client_channel/service_config_call_data.h +45 -5
  76. data/src/core/ext/filters/client_channel/service_config_channel_arg_filter.cc +5 -4
  77. data/src/core/ext/filters/client_channel/service_config_parser.cc +6 -6
  78. data/src/core/ext/filters/client_channel/service_config_parser.h +7 -4
  79. data/src/core/ext/filters/client_channel/subchannel.cc +17 -16
  80. data/src/core/ext/filters/client_channel/subchannel.h +7 -6
  81. data/src/core/ext/filters/client_idle/client_idle_filter.cc +17 -16
  82. data/src/core/ext/filters/deadline/deadline_filter.cc +10 -10
  83. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +19 -18
  84. data/src/core/ext/filters/fault_injection/service_config_parser.cc +5 -5
  85. data/src/core/ext/filters/fault_injection/service_config_parser.h +1 -1
  86. data/src/core/ext/filters/http/client/http_client_filter.cc +33 -23
  87. data/src/core/ext/filters/http/client_authority_filter.cc +3 -3
  88. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +23 -22
  89. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +21 -21
  90. data/src/core/ext/filters/http/server/http_server_filter.cc +27 -23
  91. data/src/core/ext/filters/max_age/max_age_filter.cc +12 -10
  92. data/src/core/ext/filters/message_size/message_size_filter.cc +14 -11
  93. data/src/core/ext/filters/message_size/message_size_filter.h +1 -1
  94. data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.cc +4 -3
  95. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +7 -7
  96. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +7 -7
  97. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +2 -2
  98. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +3 -2
  99. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +3 -3
  100. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +49 -46
  101. data/src/core/ext/transport/chttp2/server/chttp2_server.h +2 -2
  102. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +3 -4
  103. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +5 -4
  104. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +3 -4
  105. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +1 -1
  106. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.cc +66 -0
  107. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +74 -0
  108. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +141 -126
  109. data/src/core/ext/transport/chttp2/transport/context_list.cc +4 -5
  110. data/src/core/ext/transport/chttp2/transport/context_list.h +4 -4
  111. data/src/core/ext/transport/chttp2/transport/flow_control.cc +3 -3
  112. data/src/core/ext/transport/chttp2/transport/flow_control.h +9 -9
  113. data/src/core/ext/transport/chttp2/transport/frame_data.cc +12 -12
  114. data/src/core/ext/transport/chttp2/transport/frame_data.h +10 -10
  115. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +15 -16
  116. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +6 -6
  117. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +7 -8
  118. data/src/core/ext/transport/chttp2/transport/frame_ping.h +7 -6
  119. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +7 -7
  120. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +6 -6
  121. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +11 -10
  122. data/src/core/ext/transport/chttp2/transport/frame_settings.h +6 -6
  123. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +4 -6
  124. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +4 -6
  125. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +652 -736
  126. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +195 -74
  127. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +4 -3
  128. data/src/core/ext/transport/chttp2/transport/hpack_table.h +4 -4
  129. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
  130. data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +2 -2
  131. data/src/core/ext/transport/chttp2/transport/internal.h +33 -28
  132. data/src/core/ext/transport/chttp2/transport/parsing.cc +129 -106
  133. data/src/core/ext/transport/chttp2/transport/varint.cc +6 -4
  134. data/src/core/ext/transport/chttp2/transport/writing.cc +7 -3
  135. data/src/core/ext/transport/inproc/inproc_transport.cc +72 -60
  136. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +56 -35
  137. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +180 -76
  138. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +35 -27
  139. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +97 -48
  140. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +45 -9
  141. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +67 -7
  142. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +66 -9
  143. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +227 -0
  144. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +46 -0
  145. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +121 -0
  146. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +1 -0
  147. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +35 -0
  148. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +90 -0
  149. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +32 -24
  150. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +120 -73
  151. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +4 -2
  152. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +15 -0
  153. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +48 -0
  154. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +171 -0
  155. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +8 -6
  156. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +27 -19
  157. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +1 -0
  158. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +24 -7
  159. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +57 -0
  160. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +29 -17
  161. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +72 -0
  162. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +3 -2
  163. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +4 -0
  164. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +6 -5
  165. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +15 -11
  166. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +85 -43
  167. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +274 -91
  168. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +11 -8
  169. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +30 -13
  170. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +33 -5
  171. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +115 -0
  172. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +60 -0
  173. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +181 -0
  174. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +1 -0
  175. data/src/core/ext/upb-generated/validate/validate.upb.c +82 -66
  176. data/src/core/ext/upb-generated/validate/validate.upb.h +220 -124
  177. data/src/core/ext/upbdefs-generated/envoy/annotations/deprecation.upbdefs.c +15 -7
  178. data/src/core/ext/upbdefs-generated/envoy/config/accesslog/v3/accesslog.upbdefs.c +53 -52
  179. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +318 -277
  180. data/src/core/ext/upbdefs-generated/envoy/config/bootstrap/v3/bootstrap.upbdefs.h +5 -0
  181. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +437 -410
  182. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.c +198 -170
  183. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/base.upbdefs.h +10 -0
  184. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/config_source.upbdefs.c +9 -8
  185. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.c +219 -163
  186. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/protocol.upbdefs.h +15 -0
  187. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.c +59 -0
  188. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/resolver.upbdefs.h +40 -0
  189. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/substitution_format_string.upbdefs.c +29 -25
  190. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.c +52 -0
  191. data/src/core/ext/upbdefs-generated/envoy/config/core/v3/udp_socket_config.upbdefs.h +35 -0
  192. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.c +135 -125
  193. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  194. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/listener_components.upbdefs.c +131 -123
  195. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.c +90 -0
  196. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/quic_config.upbdefs.h +35 -0
  197. data/src/core/ext/upbdefs-generated/envoy/config/listener/v3/udp_listener_config.upbdefs.c +32 -24
  198. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.c +69 -55
  199. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route.upbdefs.h +5 -0
  200. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +684 -664
  201. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.h +5 -0
  202. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/fault/v3/fault.upbdefs.c +13 -10
  203. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/http/router/v3/router.upbdefs.c +13 -10
  204. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +441 -375
  205. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +10 -0
  206. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +122 -114
  207. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +1 -1
  208. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.c +112 -79
  209. data/src/core/ext/upbdefs-generated/envoy/service/status/v3/csds.upbdefs.h +5 -0
  210. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.c +64 -0
  211. data/src/core/ext/upbdefs-generated/envoy/type/http/v3/path_transformation.upbdefs.h +50 -0
  212. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/regex.upbdefs.c +35 -32
  213. data/src/core/ext/upbdefs-generated/google/rpc/status.upbdefs.c +4 -4
  214. data/src/core/ext/upbdefs-generated/validate/validate.upbdefs.c +182 -160
  215. data/src/core/ext/xds/certificate_provider_factory.h +1 -1
  216. data/src/core/ext/xds/certificate_provider_store.h +3 -3
  217. data/src/core/ext/xds/file_watcher_certificate_provider_factory.cc +3 -3
  218. data/src/core/ext/xds/file_watcher_certificate_provider_factory.h +2 -2
  219. data/src/core/ext/xds/xds_api.cc +665 -317
  220. data/src/core/ext/xds/xds_api.h +52 -14
  221. data/src/core/ext/xds/xds_bootstrap.cc +101 -160
  222. data/src/core/ext/xds/xds_bootstrap.h +19 -24
  223. data/src/core/ext/xds/xds_certificate_provider.cc +4 -4
  224. data/src/core/ext/xds/xds_certificate_provider.h +4 -4
  225. data/src/core/ext/xds/xds_channel_args.h +5 -2
  226. data/src/core/ext/xds/xds_client.cc +370 -215
  227. data/src/core/ext/xds/xds_client.h +38 -28
  228. data/src/core/ext/xds/xds_client_stats.h +3 -2
  229. data/src/core/ext/xds/xds_http_filters.cc +3 -2
  230. data/src/core/ext/xds/xds_http_filters.h +3 -0
  231. data/src/core/ext/xds/xds_server_config_fetcher.cc +34 -20
  232. data/src/core/lib/{iomgr → address_utils}/parse_address.cc +17 -17
  233. data/src/core/lib/{iomgr → address_utils}/parse_address.h +7 -7
  234. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.cc +16 -20
  235. data/src/core/lib/{iomgr → address_utils}/sockaddr_utils.h +16 -11
  236. data/src/core/lib/channel/call_tracer.h +85 -0
  237. data/src/core/lib/channel/channel_stack.cc +10 -9
  238. data/src/core/lib/channel/channel_stack.h +11 -10
  239. data/src/core/lib/channel/channel_stack_builder.cc +2 -2
  240. data/src/core/lib/channel/channel_stack_builder.h +1 -1
  241. data/src/core/lib/channel/channelz.cc +21 -13
  242. data/src/core/lib/channel/channelz.h +3 -0
  243. data/src/core/lib/channel/connected_channel.cc +4 -4
  244. data/src/core/lib/channel/context.h +3 -0
  245. data/src/core/lib/channel/handshaker.cc +7 -6
  246. data/src/core/lib/channel/handshaker.h +5 -5
  247. data/src/core/lib/channel/status_util.h +4 -0
  248. data/src/core/lib/compression/stream_compression.h +1 -1
  249. data/src/core/lib/compression/stream_compression_gzip.h +1 -1
  250. data/src/core/lib/compression/stream_compression_identity.h +1 -1
  251. data/src/core/lib/debug/stats.h +1 -1
  252. data/src/core/lib/event_engine/endpoint_config.cc +46 -0
  253. data/src/core/lib/event_engine/endpoint_config_internal.h +42 -0
  254. data/src/core/lib/event_engine/event_engine.cc +50 -0
  255. data/src/core/lib/event_engine/sockaddr.cc +40 -0
  256. data/src/core/lib/event_engine/sockaddr.h +44 -0
  257. data/src/core/lib/gpr/murmur_hash.cc +4 -2
  258. data/src/core/lib/gpr/wrap_memcpy.cc +2 -1
  259. data/src/core/lib/gprpp/manual_constructor.h +1 -1
  260. data/src/core/lib/gprpp/orphanable.h +3 -3
  261. data/src/core/lib/gprpp/ref_counted.h +28 -14
  262. data/src/core/lib/gprpp/status_helper.cc +407 -0
  263. data/src/core/lib/gprpp/status_helper.h +183 -0
  264. data/src/core/lib/gprpp/sync.h +2 -30
  265. data/src/core/lib/http/httpcli.cc +11 -11
  266. data/src/core/lib/http/httpcli_security_connector.cc +11 -7
  267. data/src/core/lib/http/parser.cc +16 -16
  268. data/src/core/lib/http/parser.h +4 -4
  269. data/src/core/lib/iomgr/buffer_list.cc +8 -10
  270. data/src/core/lib/iomgr/buffer_list.h +4 -5
  271. data/src/core/lib/iomgr/call_combiner.cc +15 -12
  272. data/src/core/lib/iomgr/call_combiner.h +12 -14
  273. data/src/core/lib/iomgr/cfstream_handle.cc +3 -3
  274. data/src/core/lib/iomgr/cfstream_handle.h +1 -1
  275. data/src/core/lib/iomgr/closure.h +7 -6
  276. data/src/core/lib/iomgr/combiner.cc +14 -12
  277. data/src/core/lib/iomgr/combiner.h +2 -2
  278. data/src/core/lib/iomgr/endpoint.cc +1 -1
  279. data/src/core/lib/iomgr/endpoint.h +2 -2
  280. data/src/core/lib/iomgr/endpoint_cfstream.cc +11 -13
  281. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +33 -0
  282. data/src/core/lib/iomgr/endpoint_pair_windows.cc +1 -1
  283. data/src/core/lib/iomgr/error.cc +168 -61
  284. data/src/core/lib/iomgr/error.h +217 -106
  285. data/src/core/lib/iomgr/error_cfstream.cc +3 -2
  286. data/src/core/lib/iomgr/error_cfstream.h +2 -2
  287. data/src/core/lib/iomgr/error_internal.h +5 -1
  288. data/src/core/lib/iomgr/ev_apple.cc +5 -5
  289. data/src/core/lib/iomgr/ev_apple.h +1 -1
  290. data/src/core/lib/iomgr/ev_epoll1_linux.cc +19 -19
  291. data/src/core/lib/iomgr/ev_epollex_linux.cc +48 -45
  292. data/src/core/lib/iomgr/ev_poll_posix.cc +26 -23
  293. data/src/core/lib/iomgr/ev_posix.cc +9 -8
  294. data/src/core/lib/iomgr/ev_posix.h +9 -9
  295. data/src/core/lib/iomgr/event_engine/closure.cc +54 -0
  296. data/src/core/lib/iomgr/event_engine/closure.h +33 -0
  297. data/src/core/lib/iomgr/event_engine/endpoint.cc +192 -0
  298. data/src/core/lib/iomgr/event_engine/endpoint.h +53 -0
  299. data/src/core/lib/iomgr/event_engine/iomgr.cc +105 -0
  300. data/src/core/lib/iomgr/event_engine/iomgr.h +24 -0
  301. data/src/core/lib/iomgr/event_engine/pollset.cc +87 -0
  302. data/src/core/lib/iomgr/event_engine/pollset.h +25 -0
  303. data/src/core/lib/iomgr/event_engine/promise.h +51 -0
  304. data/src/core/lib/iomgr/event_engine/resolved_address_internal.cc +41 -0
  305. data/src/core/lib/iomgr/event_engine/resolved_address_internal.h +35 -0
  306. data/src/core/lib/iomgr/event_engine/resolver.cc +110 -0
  307. data/src/core/lib/iomgr/event_engine/tcp.cc +263 -0
  308. data/src/core/lib/iomgr/event_engine/timer.cc +57 -0
  309. data/src/core/lib/iomgr/exec_ctx.cc +12 -4
  310. data/src/core/lib/iomgr/exec_ctx.h +4 -5
  311. data/src/core/lib/iomgr/executor/threadpool.cc +2 -3
  312. data/src/core/lib/iomgr/executor/threadpool.h +2 -2
  313. data/src/core/lib/iomgr/executor.cc +8 -8
  314. data/src/core/lib/iomgr/executor.h +2 -2
  315. data/src/core/lib/iomgr/iomgr.cc +2 -2
  316. data/src/core/lib/iomgr/iomgr.h +1 -1
  317. data/src/core/lib/iomgr/iomgr_custom.cc +1 -1
  318. data/src/core/lib/iomgr/iomgr_internal.cc +2 -2
  319. data/src/core/lib/iomgr/iomgr_internal.h +3 -3
  320. data/src/core/lib/iomgr/iomgr_posix.cc +3 -1
  321. data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +42 -12
  322. data/src/core/lib/iomgr/iomgr_windows.cc +1 -1
  323. data/src/core/lib/iomgr/load_file.cc +4 -4
  324. data/src/core/lib/iomgr/load_file.h +2 -2
  325. data/src/core/lib/iomgr/lockfree_event.cc +5 -5
  326. data/src/core/lib/iomgr/lockfree_event.h +1 -1
  327. data/src/core/lib/iomgr/pollset.cc +5 -5
  328. data/src/core/lib/iomgr/pollset.h +9 -9
  329. data/src/core/lib/iomgr/pollset_custom.cc +7 -7
  330. data/src/core/lib/iomgr/pollset_custom.h +3 -1
  331. data/src/core/lib/iomgr/pollset_uv.cc +3 -1
  332. data/src/core/lib/iomgr/pollset_uv.h +5 -1
  333. data/src/core/lib/iomgr/pollset_windows.cc +5 -5
  334. data/src/core/lib/iomgr/port.h +7 -5
  335. data/src/core/lib/iomgr/python_util.h +2 -2
  336. data/src/core/lib/iomgr/resolve_address.cc +8 -4
  337. data/src/core/lib/iomgr/resolve_address.h +12 -6
  338. data/src/core/lib/iomgr/resolve_address_custom.cc +10 -9
  339. data/src/core/lib/iomgr/resolve_address_custom.h +3 -3
  340. data/src/core/lib/iomgr/resolve_address_posix.cc +3 -3
  341. data/src/core/lib/iomgr/resolve_address_windows.cc +4 -4
  342. data/src/core/lib/iomgr/resource_quota.cc +13 -10
  343. data/src/core/lib/iomgr/sockaddr.h +1 -0
  344. data/src/core/lib/iomgr/socket_mutator.cc +15 -2
  345. data/src/core/lib/iomgr/socket_mutator.h +26 -2
  346. data/src/core/lib/iomgr/socket_utils_common_posix.cc +24 -22
  347. data/src/core/lib/iomgr/socket_utils_posix.h +20 -20
  348. data/src/core/lib/iomgr/tcp_client_cfstream.cc +4 -4
  349. data/src/core/lib/iomgr/tcp_client_custom.cc +5 -6
  350. data/src/core/lib/iomgr/tcp_client_posix.cc +22 -19
  351. data/src/core/lib/iomgr/tcp_client_posix.h +3 -4
  352. data/src/core/lib/iomgr/tcp_client_windows.cc +7 -5
  353. data/src/core/lib/iomgr/tcp_custom.cc +14 -16
  354. data/src/core/lib/iomgr/tcp_custom.h +13 -12
  355. data/src/core/lib/iomgr/tcp_posix.cc +78 -73
  356. data/src/core/lib/iomgr/tcp_posix.h +8 -0
  357. data/src/core/lib/iomgr/tcp_server.cc +6 -6
  358. data/src/core/lib/iomgr/tcp_server.h +12 -11
  359. data/src/core/lib/iomgr/tcp_server_custom.cc +26 -25
  360. data/src/core/lib/iomgr/tcp_server_posix.cc +29 -21
  361. data/src/core/lib/iomgr/tcp_server_utils_posix.h +13 -12
  362. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +21 -18
  363. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +9 -9
  364. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc +4 -4
  365. data/src/core/lib/iomgr/tcp_server_windows.cc +26 -25
  366. data/src/core/lib/iomgr/tcp_uv.cc +25 -23
  367. data/src/core/lib/iomgr/tcp_windows.cc +13 -13
  368. data/src/core/lib/iomgr/tcp_windows.h +2 -2
  369. data/src/core/lib/iomgr/timer.h +6 -1
  370. data/src/core/lib/iomgr/timer_custom.cc +2 -1
  371. data/src/core/lib/iomgr/timer_custom.h +1 -1
  372. data/src/core/lib/iomgr/timer_generic.cc +6 -6
  373. data/src/core/lib/iomgr/timer_manager.cc +1 -1
  374. data/src/core/lib/iomgr/udp_server.cc +21 -20
  375. data/src/core/lib/iomgr/unix_sockets_posix.cc +3 -3
  376. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -2
  377. data/src/core/lib/iomgr/unix_sockets_posix_noop.cc +10 -7
  378. data/src/core/lib/iomgr/wakeup_fd_eventfd.cc +3 -3
  379. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +4 -4
  380. data/src/core/lib/iomgr/wakeup_fd_posix.cc +3 -3
  381. data/src/core/lib/iomgr/wakeup_fd_posix.h +8 -6
  382. data/src/core/lib/iomgr/work_serializer.h +17 -1
  383. data/src/core/lib/json/json.h +1 -1
  384. data/src/core/lib/json/json_reader.cc +5 -6
  385. data/src/core/lib/matchers/matchers.cc +46 -58
  386. data/src/core/lib/matchers/matchers.h +30 -29
  387. data/src/core/lib/security/authorization/authorization_engine.h +44 -0
  388. data/src/core/lib/security/authorization/authorization_policy_provider.h +32 -0
  389. data/src/core/lib/security/authorization/authorization_policy_provider_vtable.cc +46 -0
  390. data/src/core/lib/security/authorization/evaluate_args.cc +209 -0
  391. data/src/core/lib/security/authorization/evaluate_args.h +91 -0
  392. data/src/core/lib/security/credentials/composite/composite_credentials.cc +4 -4
  393. data/src/core/lib/security/credentials/composite/composite_credentials.h +2 -2
  394. data/src/core/lib/security/credentials/credentials.h +2 -2
  395. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +17 -13
  396. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +13 -11
  397. data/src/core/lib/security/credentials/external/aws_request_signer.cc +2 -1
  398. data/src/core/lib/security/credentials/external/aws_request_signer.h +1 -1
  399. data/src/core/lib/security/credentials/external/external_account_credentials.cc +15 -12
  400. data/src/core/lib/security/credentials/external/external_account_credentials.h +9 -8
  401. data/src/core/lib/security/credentials/external/file_external_account_credentials.cc +5 -4
  402. data/src/core/lib/security/credentials/external/file_external_account_credentials.h +4 -3
  403. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +8 -8
  404. data/src/core/lib/security/credentials/external/url_external_account_credentials.h +9 -7
  405. data/src/core/lib/security/credentials/fake/fake_credentials.cc +2 -2
  406. data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -2
  407. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +12 -10
  408. data/src/core/lib/security/credentials/iam/iam_credentials.cc +2 -2
  409. data/src/core/lib/security/credentials/iam/iam_credentials.h +2 -2
  410. data/src/core/lib/security/credentials/jwt/json_token.cc +2 -2
  411. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +3 -3
  412. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +2 -2
  413. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +7 -5
  414. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +21 -19
  415. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +5 -5
  416. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +5 -5
  417. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -2
  418. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +8 -7
  419. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +9 -9
  420. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +68 -13
  421. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -0
  422. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +4 -0
  423. data/src/core/lib/security/credentials/tls/tls_utils.cc +32 -0
  424. data/src/core/lib/security/credentials/tls/tls_utils.h +13 -0
  425. data/src/core/lib/security/credentials/xds/xds_credentials.cc +3 -3
  426. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -3
  427. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +13 -3
  428. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.cc +2 -2
  429. data/src/core/lib/security/security_connector/insecure/insecure_security_connector.h +12 -2
  430. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +1 -1
  431. data/src/core/lib/security/security_connector/local/local_security_connector.cc +22 -9
  432. data/src/core/lib/security/security_connector/security_connector.h +9 -4
  433. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +16 -6
  434. data/src/core/lib/security/security_connector/ssl_utils.cc +27 -4
  435. data/src/core/lib/security/security_connector/ssl_utils.h +4 -4
  436. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +60 -76
  437. data/src/core/lib/security/security_connector/tls/tls_security_connector.h +66 -48
  438. data/src/core/lib/security/transport/client_auth_filter.cc +18 -10
  439. data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
  440. data/src/core/lib/security/transport/security_handshaker.cc +45 -36
  441. data/src/core/lib/security/transport/server_auth_filter.cc +17 -18
  442. data/src/core/lib/security/transport/tsi_error.cc +2 -1
  443. data/src/core/lib/security/transport/tsi_error.h +2 -1
  444. data/src/core/lib/security/util/json_util.cc +2 -2
  445. data/src/core/lib/security/util/json_util.h +1 -1
  446. data/src/core/lib/slice/slice_internal.h +1 -0
  447. data/src/core/lib/surface/call.cc +72 -52
  448. data/src/core/lib/surface/call.h +13 -2
  449. data/src/core/lib/surface/channel.cc +6 -6
  450. data/src/core/lib/surface/channel.h +3 -2
  451. data/src/core/lib/surface/channel_ping.cc +1 -1
  452. data/src/core/lib/surface/completion_queue.cc +68 -69
  453. data/src/core/lib/surface/completion_queue.h +3 -2
  454. data/src/core/lib/surface/completion_queue_factory.cc +1 -2
  455. data/src/core/lib/surface/init.cc +1 -3
  456. data/src/core/lib/surface/init.h +10 -1
  457. data/src/core/lib/surface/lame_client.cc +11 -11
  458. data/src/core/lib/surface/lame_client.h +1 -1
  459. data/src/core/lib/surface/server.cc +31 -23
  460. data/src/core/lib/surface/server.h +19 -18
  461. data/src/core/lib/surface/validate_metadata.cc +7 -7
  462. data/src/core/lib/surface/validate_metadata.h +3 -2
  463. data/src/core/lib/surface/version.cc +2 -2
  464. data/src/core/lib/transport/byte_stream.cc +5 -5
  465. data/src/core/lib/transport/byte_stream.h +8 -8
  466. data/src/core/lib/transport/connectivity_state.cc +1 -1
  467. data/src/core/lib/transport/error_utils.cc +21 -10
  468. data/src/core/lib/transport/error_utils.h +11 -5
  469. data/src/core/lib/transport/metadata_batch.cc +37 -37
  470. data/src/core/lib/transport/metadata_batch.h +19 -18
  471. data/src/core/lib/transport/transport.cc +4 -3
  472. data/src/core/lib/transport/transport.h +6 -4
  473. data/src/core/lib/transport/transport_op_string.cc +6 -6
  474. data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
  475. data/src/core/tsi/alts/crypt/gsec.h +6 -0
  476. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +5 -4
  477. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +7 -6
  478. data/src/core/tsi/alts/handshaker/alts_tsi_handshaker_private.h +2 -1
  479. data/src/core/tsi/ssl_transport_security.cc +32 -14
  480. data/src/core/tsi/ssl_transport_security.h +3 -4
  481. data/src/ruby/bin/math_services_pb.rb +1 -1
  482. data/src/ruby/ext/grpc/extconf.rb +2 -0
  483. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +6 -0
  484. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +11 -2
  485. data/src/ruby/lib/grpc/version.rb +1 -1
  486. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +1 -1
  487. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +6 -6
  488. data/third_party/abseil-cpp/absl/algorithm/container.h +3 -3
  489. data/third_party/abseil-cpp/absl/base/attributes.h +24 -4
  490. data/third_party/abseil-cpp/absl/base/call_once.h +2 -9
  491. data/third_party/abseil-cpp/absl/base/config.h +37 -9
  492. data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +24 -10
  493. data/third_party/abseil-cpp/absl/base/internal/direct_mmap.h +4 -1
  494. data/third_party/abseil-cpp/absl/base/internal/endian.h +61 -0
  495. data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +2 -3
  496. data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +34 -32
  497. data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +16 -6
  498. data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +11 -2
  499. data/third_party/abseil-cpp/absl/base/internal/spinlock.h +14 -5
  500. data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +2 -2
  501. data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +3 -3
  502. data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +2 -2
  503. data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +11 -11
  504. data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +5 -5
  505. data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +1 -1
  506. data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +5 -2
  507. data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +43 -42
  508. data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +111 -7
  509. data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +0 -76
  510. data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +1 -3
  511. data/third_party/abseil-cpp/absl/base/log_severity.h +4 -4
  512. data/third_party/abseil-cpp/absl/base/macros.h +11 -0
  513. data/third_party/abseil-cpp/absl/base/optimization.h +10 -7
  514. data/third_party/abseil-cpp/absl/base/options.h +1 -1
  515. data/third_party/abseil-cpp/absl/base/port.h +0 -1
  516. data/third_party/abseil-cpp/absl/base/thread_annotations.h +1 -1
  517. data/third_party/abseil-cpp/absl/container/fixed_array.h +2 -2
  518. data/third_party/abseil-cpp/absl/container/inlined_vector.h +5 -3
  519. data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +1 -1
  520. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.cc +5 -1
  521. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler.h +2 -1
  522. data/third_party/abseil-cpp/absl/container/internal/hashtablez_sampler_force_weak_definition.cc +2 -1
  523. data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +141 -66
  524. data/third_party/abseil-cpp/absl/container/internal/layout.h +4 -4
  525. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.cc +14 -1
  526. data/third_party/abseil-cpp/absl/container/internal/raw_hash_set.h +136 -136
  527. data/third_party/abseil-cpp/absl/debugging/internal/demangle.cc +16 -12
  528. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_aarch64-inl.inc +5 -2
  529. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_config.h +3 -12
  530. data/third_party/abseil-cpp/absl/debugging/internal/stacktrace_powerpc-inl.inc +6 -1
  531. data/third_party/abseil-cpp/absl/debugging/internal/symbolize.h +3 -5
  532. data/third_party/abseil-cpp/absl/debugging/symbolize_darwin.inc +2 -2
  533. data/third_party/abseil-cpp/absl/debugging/symbolize_elf.inc +2 -2
  534. data/third_party/abseil-cpp/absl/hash/internal/city.cc +15 -12
  535. data/third_party/abseil-cpp/absl/hash/internal/city.h +1 -19
  536. data/third_party/abseil-cpp/absl/hash/internal/hash.cc +25 -10
  537. data/third_party/abseil-cpp/absl/hash/internal/hash.h +86 -37
  538. data/third_party/abseil-cpp/absl/hash/internal/wyhash.cc +111 -0
  539. data/third_party/abseil-cpp/absl/hash/internal/wyhash.h +48 -0
  540. data/third_party/abseil-cpp/absl/meta/type_traits.h +16 -2
  541. data/third_party/abseil-cpp/absl/numeric/bits.h +177 -0
  542. data/third_party/abseil-cpp/absl/numeric/int128.cc +3 -3
  543. data/third_party/abseil-cpp/absl/numeric/internal/bits.h +358 -0
  544. data/third_party/abseil-cpp/absl/numeric/internal/representation.h +55 -0
  545. data/third_party/abseil-cpp/absl/status/internal/status_internal.h +18 -0
  546. data/third_party/abseil-cpp/absl/status/internal/statusor_internal.h +4 -7
  547. data/third_party/abseil-cpp/absl/status/status.cc +29 -22
  548. data/third_party/abseil-cpp/absl/status/status.h +81 -20
  549. data/third_party/abseil-cpp/absl/status/statusor.h +3 -3
  550. data/third_party/abseil-cpp/absl/strings/charconv.cc +5 -5
  551. data/third_party/abseil-cpp/absl/strings/cord.cc +326 -371
  552. data/third_party/abseil-cpp/absl/strings/cord.h +182 -64
  553. data/third_party/abseil-cpp/absl/strings/escaping.cc +4 -4
  554. data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +6 -6
  555. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.cc +83 -0
  556. data/third_party/abseil-cpp/absl/strings/internal/cord_internal.h +387 -17
  557. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_flat.h +146 -0
  558. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.cc +897 -0
  559. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring.h +589 -0
  560. data/third_party/abseil-cpp/absl/strings/internal/cord_rep_ring_reader.h +114 -0
  561. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.cc +14 -0
  562. data/third_party/abseil-cpp/absl/strings/internal/str_format/arg.h +14 -0
  563. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.cc +15 -1
  564. data/third_party/abseil-cpp/absl/strings/internal/str_format/bind.h +19 -4
  565. data/third_party/abseil-cpp/absl/strings/internal/str_format/checker.h +14 -0
  566. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.cc +36 -18
  567. data/third_party/abseil-cpp/absl/strings/internal/str_format/float_conversion.h +14 -0
  568. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.cc +14 -0
  569. data/third_party/abseil-cpp/absl/strings/internal/str_format/parser.h +14 -0
  570. data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +15 -40
  571. data/third_party/abseil-cpp/absl/strings/internal/string_constant.h +64 -0
  572. data/third_party/abseil-cpp/absl/strings/match.cc +6 -3
  573. data/third_party/abseil-cpp/absl/strings/match.h +16 -6
  574. data/third_party/abseil-cpp/absl/strings/numbers.cc +132 -4
  575. data/third_party/abseil-cpp/absl/strings/numbers.h +10 -10
  576. data/third_party/abseil-cpp/absl/strings/str_join.h +1 -1
  577. data/third_party/abseil-cpp/absl/strings/str_split.h +38 -4
  578. data/third_party/abseil-cpp/absl/synchronization/internal/futex.h +154 -0
  579. data/third_party/abseil-cpp/absl/synchronization/internal/kernel_timeout.h +2 -1
  580. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.cc +2 -2
  581. data/third_party/abseil-cpp/absl/synchronization/internal/per_thread_sem.h +4 -4
  582. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.cc +1 -65
  583. data/third_party/abseil-cpp/absl/synchronization/internal/waiter.h +2 -6
  584. data/third_party/abseil-cpp/absl/synchronization/mutex.cc +71 -59
  585. data/third_party/abseil-cpp/absl/synchronization/mutex.h +79 -62
  586. data/third_party/abseil-cpp/absl/time/clock.cc +146 -130
  587. data/third_party/abseil-cpp/absl/time/clock.h +2 -2
  588. data/third_party/abseil-cpp/absl/time/duration.cc +3 -2
  589. data/third_party/abseil-cpp/absl/time/internal/cctz/include/cctz/civil_time_detail.h +7 -11
  590. data/third_party/abseil-cpp/absl/time/internal/cctz/src/time_zone_libc.cc +7 -1
  591. data/third_party/abseil-cpp/absl/time/internal/cctz/src/tzfile.h +4 -4
  592. data/third_party/abseil-cpp/absl/time/time.cc +4 -3
  593. data/third_party/abseil-cpp/absl/time/time.h +26 -24
  594. data/third_party/abseil-cpp/absl/types/internal/variant.h +1 -1
  595. data/third_party/abseil-cpp/absl/types/variant.h +9 -4
  596. data/third_party/boringssl-with-bazel/err_data.c +483 -461
  597. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bool.c +1 -1
  598. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +9 -7
  599. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +18 -8
  600. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_lib.c +1 -2
  601. data/third_party/boringssl-with-bazel/src/crypto/asn1/asn1_locl.h +5 -0
  602. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -1
  603. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +1 -1
  604. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/cipher_extra.c +4 -0
  605. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/e_tls.c +1 -88
  606. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/internal.h +14 -3
  607. data/third_party/boringssl-with-bazel/src/crypto/cipher_extra/tls_cbc.c +119 -273
  608. data/third_party/boringssl-with-bazel/src/crypto/curve25519/curve25519.c +1 -1
  609. data/third_party/boringssl-with-bazel/src/crypto/curve25519/internal.h +1 -1
  610. data/third_party/boringssl-with-bazel/src/crypto/err/err.c +87 -80
  611. data/third_party/boringssl-with-bazel/src/crypto/evp/evp.c +9 -0
  612. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bcm.c +1 -0
  613. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/internal.h +1 -1
  614. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/prime.c +0 -4
  615. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/cipher.c +11 -3
  616. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/cipher/e_aes.c +25 -2
  617. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +7 -0
  618. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digests.c +10 -2
  619. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/md32_common.h +87 -160
  620. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec.c +4 -0
  621. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/ec_key.c +0 -1
  622. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ec/internal.h +0 -4
  623. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/ecdsa.c +104 -93
  624. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/ecdsa/internal.h +39 -0
  625. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md4/md4.c +52 -65
  626. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/md5/md5.c +52 -66
  627. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cbc.c +33 -22
  628. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/cfb.c +9 -8
  629. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ctr.c +9 -8
  630. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/gcm.c +17 -13
  631. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/internal.h +1 -22
  632. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/modes/ofb.c +2 -1
  633. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +1 -4
  634. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +0 -13
  635. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +26 -7
  636. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa.c +26 -24
  637. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rsa/rsa_impl.c +10 -7
  638. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/fips.c +79 -0
  639. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/self_check/self_check.c +14 -9
  640. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha1.c +61 -75
  641. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha256.c +80 -103
  642. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/sha/sha512.c +40 -49
  643. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +367 -315
  644. data/third_party/boringssl-with-bazel/src/crypto/internal.h +65 -0
  645. data/third_party/boringssl-with-bazel/src/crypto/mem.c +14 -0
  646. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +3 -3
  647. data/third_party/boringssl-with-bazel/src/crypto/pkcs7/pkcs7_x509.c +5 -3
  648. data/third_party/boringssl-with-bazel/src/crypto/pkcs8/pkcs8_x509.c +95 -48
  649. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/passive.c +2 -2
  650. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/rand_extra.c +1 -1
  651. data/third_party/boringssl-with-bazel/src/crypto/rsa_extra/rsa_asn1.c +1 -2
  652. data/third_party/boringssl-with-bazel/src/crypto/thread_pthread.c +0 -28
  653. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +120 -11
  654. data/third_party/boringssl-with-bazel/src/crypto/x509/t_req.c +2 -0
  655. data/third_party/boringssl-with-bazel/src/crypto/x509/t_x509a.c +3 -0
  656. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +19 -25
  657. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_cmp.c +3 -2
  658. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_req.c +42 -89
  659. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_set.c +9 -16
  660. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_trs.c +2 -0
  661. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +14 -15
  662. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vpm.c +53 -73
  663. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +31 -0
  664. data/third_party/boringssl-with-bazel/src/crypto/x509/x509rset.c +3 -0
  665. data/third_party/boringssl-with-bazel/src/crypto/x509/x_algor.c +21 -17
  666. data/third_party/boringssl-with-bazel/src/crypto/x509/x_all.c +3 -0
  667. data/third_party/boringssl-with-bazel/src/crypto/x509/x_attrib.c +7 -25
  668. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +5 -0
  669. data/third_party/boringssl-with-bazel/src/crypto/x509/x_pubkey.c +25 -22
  670. data/third_party/boringssl-with-bazel/src/crypto/x509/x_req.c +5 -8
  671. data/third_party/boringssl-with-bazel/src/crypto/x509/x_sig.c +5 -0
  672. data/third_party/boringssl-with-bazel/src/crypto/x509/x_val.c +2 -0
  673. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509a.c +3 -0
  674. data/third_party/boringssl-with-bazel/src/crypto/x509v3/internal.h +7 -0
  675. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_cpols.c +2 -4
  676. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_purp.c +1 -1
  677. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_skey.c +1 -0
  678. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -8
  679. data/third_party/boringssl-with-bazel/src/include/openssl/aead.h +1 -4
  680. data/third_party/boringssl-with-bazel/src/include/openssl/arm_arch.h +66 -1
  681. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +120 -41
  682. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +47 -7
  683. data/third_party/boringssl-with-bazel/src/include/openssl/bytestring.h +1 -0
  684. data/third_party/boringssl-with-bazel/src/include/openssl/chacha.h +1 -1
  685. data/third_party/boringssl-with-bazel/src/include/openssl/cipher.h +0 -8
  686. data/third_party/boringssl-with-bazel/src/include/openssl/crypto.h +24 -4
  687. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +6 -2
  688. data/third_party/boringssl-with-bazel/src/include/openssl/ec.h +5 -2
  689. data/third_party/boringssl-with-bazel/src/include/openssl/ecdsa.h +33 -0
  690. data/third_party/boringssl-with-bazel/src/include/openssl/err.h +3 -2
  691. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +20 -49
  692. data/third_party/boringssl-with-bazel/src/{crypto/x509/x509_r2x.c → include/openssl/evp_errors.h} +41 -58
  693. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +325 -0
  694. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +24 -5
  695. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs7.h +25 -7
  696. data/third_party/boringssl-with-bazel/src/include/openssl/pkcs8.h +9 -1
  697. data/third_party/boringssl-with-bazel/src/include/openssl/rand.h +2 -2
  698. data/third_party/boringssl-with-bazel/src/include/openssl/rsa.h +99 -63
  699. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +283 -85
  700. data/third_party/boringssl-with-bazel/src/include/openssl/tls1.h +13 -19
  701. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +445 -152
  702. data/third_party/boringssl-with-bazel/src/include/openssl/x509_vfy.h +451 -435
  703. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +2 -1
  704. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +7 -2
  705. data/third_party/boringssl-with-bazel/src/ssl/d1_srtp.cc +1 -1
  706. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +1133 -0
  707. data/third_party/boringssl-with-bazel/src/ssl/handoff.cc +298 -22
  708. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +66 -30
  709. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +189 -86
  710. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +154 -24
  711. data/third_party/boringssl-with-bazel/src/ssl/internal.h +414 -135
  712. data/third_party/boringssl-with-bazel/src/ssl/s3_both.cc +9 -3
  713. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +2 -2
  714. data/third_party/boringssl-with-bazel/src/ssl/s3_pkt.cc +14 -19
  715. data/third_party/boringssl-with-bazel/src/ssl/ssl_cert.cc +4 -6
  716. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +23 -26
  717. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +51 -60
  718. data/third_party/boringssl-with-bazel/src/ssl/ssl_privkey.cc +2 -0
  719. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +8 -31
  720. data/third_party/boringssl-with-bazel/src/ssl/ssl_stat.cc +3 -0
  721. data/third_party/boringssl-with-bazel/src/ssl/ssl_transcript.cc +4 -3
  722. data/third_party/boringssl-with-bazel/src/ssl/ssl_versions.cc +7 -3
  723. data/third_party/boringssl-with-bazel/src/ssl/t1_lib.cc +664 -702
  724. data/third_party/boringssl-with-bazel/src/ssl/tls13_both.cc +65 -7
  725. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +98 -39
  726. data/third_party/boringssl-with-bazel/src/ssl/tls13_enc.cc +141 -94
  727. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +213 -118
  728. data/third_party/boringssl-with-bazel/src/ssl/tls_method.cc +4 -2
  729. data/third_party/xxhash/xxhash.h +77 -195
  730. metadata +116 -51
  731. data/src/core/lib/gpr/arena.h +0 -47
  732. data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +0 -88
  733. data/src/core/lib/iomgr/poller/eventmanager_libuv.h +0 -88
  734. data/third_party/abseil-cpp/absl/base/internal/bits.h +0 -219
  735. data/third_party/abseil-cpp/absl/synchronization/internal/mutex_nonprod.inc +0 -249
  736. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/is_fips.c +0 -29
  737. data/third_party/boringssl-with-bazel/src/crypto/hpke/internal.h +0 -246
  738. data/third_party/boringssl-with-bazel/src/crypto/x509/vpm_int.h +0 -71
@@ -39,12 +39,12 @@ void grpc_chttp2_add_rst_stream_to_next_write(
39
39
  grpc_chttp2_transport* t, uint32_t id, uint32_t code,
40
40
  grpc_transport_one_way_stats* stats);
41
41
 
42
- grpc_error* grpc_chttp2_rst_stream_parser_begin_frame(
42
+ grpc_error_handle grpc_chttp2_rst_stream_parser_begin_frame(
43
43
  grpc_chttp2_rst_stream_parser* parser, uint32_t length, uint8_t flags);
44
- grpc_error* grpc_chttp2_rst_stream_parser_parse(void* parser,
45
- grpc_chttp2_transport* t,
46
- grpc_chttp2_stream* s,
47
- const grpc_slice& slice,
48
- int is_last);
44
+ grpc_error_handle grpc_chttp2_rst_stream_parser_parse(void* parser,
45
+ grpc_chttp2_transport* t,
46
+ grpc_chttp2_stream* s,
47
+ const grpc_slice& slice,
48
+ int is_last);
49
49
 
50
50
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_RST_STREAM_H */
@@ -84,7 +84,7 @@ grpc_slice grpc_chttp2_settings_ack_create(void) {
84
84
  return output;
85
85
  }
86
86
 
87
- grpc_error* grpc_chttp2_settings_parser_begin_frame(
87
+ grpc_error_handle grpc_chttp2_settings_parser_begin_frame(
88
88
  grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags,
89
89
  uint32_t* settings) {
90
90
  parser->target_settings = settings;
@@ -110,10 +110,11 @@ grpc_error* grpc_chttp2_settings_parser_begin_frame(
110
110
  }
111
111
  }
112
112
 
113
- grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
114
- grpc_chttp2_stream* /*s*/,
115
- const grpc_slice& slice,
116
- int is_last) {
113
+ grpc_error_handle grpc_chttp2_settings_parser_parse(void* p,
114
+ grpc_chttp2_transport* t,
115
+ grpc_chttp2_stream* /*s*/,
116
+ const grpc_slice& slice,
117
+ int is_last) {
117
118
  grpc_chttp2_settings_parser* parser =
118
119
  static_cast<grpc_chttp2_settings_parser*>(p);
119
120
  const uint8_t* cur = GRPC_SLICE_START_PTR(slice);
@@ -145,7 +146,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
145
146
  }
146
147
  parser->id = static_cast<uint16_t>((static_cast<uint16_t>(*cur)) << 8);
147
148
  cur++;
148
- /* fallthrough */
149
+ ABSL_FALLTHROUGH_INTENDED;
149
150
  case GRPC_CHTTP2_SPS_ID1:
150
151
  if (cur == end) {
151
152
  parser->state = GRPC_CHTTP2_SPS_ID1;
@@ -153,7 +154,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
153
154
  }
154
155
  parser->id = static_cast<uint16_t>(parser->id | (*cur));
155
156
  cur++;
156
- /* fallthrough */
157
+ ABSL_FALLTHROUGH_INTENDED;
157
158
  case GRPC_CHTTP2_SPS_VAL0:
158
159
  if (cur == end) {
159
160
  parser->state = GRPC_CHTTP2_SPS_VAL0;
@@ -161,7 +162,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
161
162
  }
162
163
  parser->value = (static_cast<uint32_t>(*cur)) << 24;
163
164
  cur++;
164
- /* fallthrough */
165
+ ABSL_FALLTHROUGH_INTENDED;
165
166
  case GRPC_CHTTP2_SPS_VAL1:
166
167
  if (cur == end) {
167
168
  parser->state = GRPC_CHTTP2_SPS_VAL1;
@@ -169,7 +170,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
169
170
  }
170
171
  parser->value |= (static_cast<uint32_t>(*cur)) << 16;
171
172
  cur++;
172
- /* fallthrough */
173
+ ABSL_FALLTHROUGH_INTENDED;
173
174
  case GRPC_CHTTP2_SPS_VAL2:
174
175
  if (cur == end) {
175
176
  parser->state = GRPC_CHTTP2_SPS_VAL2;
@@ -177,7 +178,7 @@ grpc_error* grpc_chttp2_settings_parser_parse(void* p, grpc_chttp2_transport* t,
177
178
  }
178
179
  parser->value |= (static_cast<uint32_t>(*cur)) << 8;
179
180
  cur++;
180
- /* fallthrough */
181
+ ABSL_FALLTHROUGH_INTENDED;
181
182
  case GRPC_CHTTP2_SPS_VAL3:
182
183
  if (cur == end) {
183
184
  parser->state = GRPC_CHTTP2_SPS_VAL3;
@@ -49,13 +49,13 @@ grpc_slice grpc_chttp2_settings_create(uint32_t* old_settings,
49
49
  /* Create an ack settings frame */
50
50
  grpc_slice grpc_chttp2_settings_ack_create(void);
51
51
 
52
- grpc_error* grpc_chttp2_settings_parser_begin_frame(
52
+ grpc_error_handle grpc_chttp2_settings_parser_begin_frame(
53
53
  grpc_chttp2_settings_parser* parser, uint32_t length, uint8_t flags,
54
54
  uint32_t* settings);
55
- grpc_error* grpc_chttp2_settings_parser_parse(void* parser,
56
- grpc_chttp2_transport* t,
57
- grpc_chttp2_stream* s,
58
- const grpc_slice& slice,
59
- int is_last);
55
+ grpc_error_handle grpc_chttp2_settings_parser_parse(void* parser,
56
+ grpc_chttp2_transport* t,
57
+ grpc_chttp2_stream* s,
58
+ const grpc_slice& slice,
59
+ int is_last);
60
60
 
61
61
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_SETTINGS_H */
@@ -53,7 +53,7 @@ grpc_slice grpc_chttp2_window_update_create(
53
53
  return slice;
54
54
  }
55
55
 
56
- grpc_error* grpc_chttp2_window_update_parser_begin_frame(
56
+ grpc_error_handle grpc_chttp2_window_update_parser_begin_frame(
57
57
  grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags) {
58
58
  if (flags || length != 4) {
59
59
  return GRPC_ERROR_CREATE_FROM_COPIED_STRING(
@@ -66,11 +66,9 @@ grpc_error* grpc_chttp2_window_update_parser_begin_frame(
66
66
  return GRPC_ERROR_NONE;
67
67
  }
68
68
 
69
- grpc_error* grpc_chttp2_window_update_parser_parse(void* parser,
70
- grpc_chttp2_transport* t,
71
- grpc_chttp2_stream* s,
72
- const grpc_slice& slice,
73
- int is_last) {
69
+ grpc_error_handle grpc_chttp2_window_update_parser_parse(
70
+ void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s,
71
+ const grpc_slice& slice, int is_last) {
74
72
  const uint8_t* const beg = GRPC_SLICE_START_PTR(slice);
75
73
  const uint8_t* const end = GRPC_SLICE_END_PTR(slice);
76
74
  const uint8_t* cur = beg;
@@ -33,12 +33,10 @@ struct grpc_chttp2_window_update_parser {
33
33
  grpc_slice grpc_chttp2_window_update_create(
34
34
  uint32_t id, uint32_t window_delta, grpc_transport_one_way_stats* stats);
35
35
 
36
- grpc_error* grpc_chttp2_window_update_parser_begin_frame(
36
+ grpc_error_handle grpc_chttp2_window_update_parser_begin_frame(
37
37
  grpc_chttp2_window_update_parser* parser, uint32_t length, uint8_t flags);
38
- grpc_error* grpc_chttp2_window_update_parser_parse(void* parser,
39
- grpc_chttp2_transport* t,
40
- grpc_chttp2_stream* s,
41
- const grpc_slice& slice,
42
- int is_last);
38
+ grpc_error_handle grpc_chttp2_window_update_parser_parse(
39
+ void* parser, grpc_chttp2_transport* t, grpc_chttp2_stream* s,
40
+ const grpc_slice& slice, int is_last);
43
41
 
44
42
  #endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_FRAME_WINDOW_UPDATE_H */
@@ -40,17 +40,17 @@
40
40
  #include "src/core/lib/surface/validate_metadata.h"
41
41
  #include "src/core/lib/transport/http2_errors.h"
42
42
 
43
- grpc_core::DebugOnlyTraceFlag grpc_trace_chttp2_hpack_parser(
44
- false, "chttp2_hpack_parser");
45
-
46
- typedef enum {
47
- NOT_BINARY,
48
- BINARY_BEGIN,
49
- B64_BYTE0,
50
- B64_BYTE1,
51
- B64_BYTE2,
52
- B64_BYTE3
53
- } binary_state;
43
+ #if __cplusplus > 201103L
44
+ #define GRPC_HPACK_CONSTEXPR_FN constexpr
45
+ #define GRPC_HPACK_CONSTEXPR_VALUE constexpr
46
+ #else
47
+ #define GRPC_HPACK_CONSTEXPR_FN
48
+ #define GRPC_HPACK_CONSTEXPR_VALUE const
49
+ #endif
50
+
51
+ namespace grpc_core {
52
+
53
+ DebugOnlyTraceFlag grpc_trace_chttp2_hpack_parser(false, "chttp2_hpack_parser");
54
54
 
55
55
  /* How parsing works:
56
56
 
@@ -66,173 +66,6 @@ typedef enum {
66
66
  It's expected that most optimizing compilers will turn this code into
67
67
  a set of indirect jumps, and so not waste stack space. */
68
68
 
69
- /* forward declarations for parsing states */
70
- static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
71
- const uint8_t* end);
72
- static grpc_error* parse_error(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
73
- const uint8_t* end, grpc_error* error);
74
- static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p,
75
- const uint8_t* cur, const uint8_t* end);
76
- static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p,
77
- const uint8_t* cur, const uint8_t* end);
78
-
79
- static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p,
80
- const uint8_t* cur, const uint8_t* end);
81
- static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p,
82
- const uint8_t* cur, const uint8_t* end);
83
- static grpc_error* parse_value_string_with_indexed_key(
84
- grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end);
85
- static grpc_error* parse_value_string_with_literal_key(
86
- grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end);
87
-
88
- static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
89
- const uint8_t* end);
90
- static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
91
- const uint8_t* end);
92
- static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
93
- const uint8_t* end);
94
- static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
95
- const uint8_t* end);
96
- static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
97
- const uint8_t* end);
98
- static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p,
99
- const uint8_t* cur, const uint8_t* end);
100
-
101
- static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p,
102
- const uint8_t* cur, const uint8_t* end);
103
- static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p,
104
- const uint8_t* cur,
105
- const uint8_t* end);
106
- static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p,
107
- const uint8_t* cur, const uint8_t* end);
108
- static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p,
109
- const uint8_t* cur,
110
- const uint8_t* end);
111
- static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p,
112
- const uint8_t* cur,
113
- const uint8_t* end);
114
- static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p,
115
- const uint8_t* cur, const uint8_t* end);
116
- static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p,
117
- const uint8_t* cur,
118
- const uint8_t* end);
119
- static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p,
120
- const uint8_t* cur,
121
- const uint8_t* end);
122
- static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p,
123
- const uint8_t* cur, const uint8_t* end);
124
- static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p,
125
- const uint8_t* cur,
126
- const uint8_t* end);
127
- static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p,
128
- const uint8_t* cur,
129
- const uint8_t* end);
130
- static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p,
131
- const uint8_t* cur, const uint8_t* end);
132
- static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p,
133
- const uint8_t* cur, const uint8_t* end);
134
-
135
- /* we translate the first byte of a hpack field into one of these decoding
136
- cases, then use a lookup table to jump directly to the appropriate parser.
137
-
138
- _X => the integer index is all ones, meaning we need to do varint decoding
139
- _V => the integer index is all zeros, meaning we need to decode an additional
140
- string value */
141
- typedef enum {
142
- INDEXED_FIELD,
143
- INDEXED_FIELD_X,
144
- LITHDR_INCIDX,
145
- LITHDR_INCIDX_X,
146
- LITHDR_INCIDX_V,
147
- LITHDR_NOTIDX,
148
- LITHDR_NOTIDX_X,
149
- LITHDR_NOTIDX_V,
150
- LITHDR_NVRIDX,
151
- LITHDR_NVRIDX_X,
152
- LITHDR_NVRIDX_V,
153
- MAX_TBL_SIZE,
154
- MAX_TBL_SIZE_X,
155
- ILLEGAL
156
- } first_byte_type;
157
-
158
- /* jump table of parse state functions -- order must match first_byte_type
159
- above */
160
- static const grpc_chttp2_hpack_parser_state first_byte_action[] = {
161
- parse_indexed_field, parse_indexed_field_x, parse_lithdr_incidx,
162
- parse_lithdr_incidx_x, parse_lithdr_incidx_v, parse_lithdr_notidx,
163
- parse_lithdr_notidx_x, parse_lithdr_notidx_v, parse_lithdr_nvridx,
164
- parse_lithdr_nvridx_x, parse_lithdr_nvridx_v, parse_max_tbl_size,
165
- parse_max_tbl_size_x, parse_illegal_op};
166
-
167
- /* indexes the first byte to a parse state function - generated by
168
- gen_hpack_tables.c */
169
- static const uint8_t first_byte_lut[256] = {
170
- LITHDR_NOTIDX_V, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
171
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
172
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX,
173
- LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX, LITHDR_NOTIDX_X,
174
- LITHDR_NVRIDX_V, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
175
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
176
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX,
177
- LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX, LITHDR_NVRIDX_X,
178
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
179
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
180
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
181
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
182
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
183
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
184
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE,
185
- MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE, MAX_TBL_SIZE_X,
186
- LITHDR_INCIDX_V, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
187
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
188
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
189
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
190
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
191
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
192
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
193
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
194
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
195
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
196
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
197
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
198
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
199
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
200
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX,
201
- LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX, LITHDR_INCIDX_X,
202
- ILLEGAL, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
203
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
204
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
205
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
206
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
207
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
208
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
209
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
210
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
211
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
212
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
213
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
214
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
215
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
216
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
217
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
218
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
219
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
220
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
221
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
222
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
223
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
224
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
225
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
226
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
227
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
228
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
229
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
230
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
231
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
232
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD,
233
- INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD, INDEXED_FIELD_X,
234
- };
235
-
236
69
  /* state table for huffman decoding: given a state, gives an index/16 into
237
70
  next_sub_tbl. Taking that index and adding the value of the nibble being
238
71
  considered returns the next state.
@@ -606,28 +439,37 @@ static const int16_t emit_sub_tbl[249 * 16] = {
606
439
  13, 22, 22, 22, 22, 256, 256, 256, 256,
607
440
  };
608
441
 
609
- static const uint8_t inverse_base64[256] = {
610
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
611
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
612
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 62, 255,
613
- 255, 255, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 255, 255,
614
- 255, 64, 255, 255, 255, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
615
- 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
616
- 25, 255, 255, 255, 255, 255, 255, 26, 27, 28, 29, 30, 31, 32, 33,
617
- 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48,
618
- 49, 50, 51, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
619
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
620
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
621
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
622
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
623
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
624
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
625
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
626
- 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
627
- 255,
442
+ namespace {
443
+ // The alphabet used for base64 encoding binary metadata.
444
+ static constexpr char kBase64Alphabet[] =
445
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
446
+
447
+ // An inverted table: for each value in kBase64Alphabet, table contains the
448
+ // index with which it's stored, so we can quickly invert the encoding without
449
+ // any complicated runtime logic.
450
+ struct Base64InverseTable {
451
+ uint8_t table[256]{};
452
+ GRPC_HPACK_CONSTEXPR_FN Base64InverseTable() {
453
+ for (int i = 0; i < 256; i++) {
454
+ table[i] = 255;
455
+ }
456
+ for (const char* p = kBase64Alphabet; *p; p++) {
457
+ uint8_t idx = *p;
458
+ uint8_t ofs = p - kBase64Alphabet;
459
+ table[idx] = ofs;
460
+ }
461
+ }
628
462
  };
629
463
 
630
- static void GPR_ATTRIBUTE_NOINLINE on_hdr_log(grpc_mdelem md) {
464
+ static GRPC_HPACK_CONSTEXPR_VALUE Base64InverseTable kBase64InverseTable;
465
+ } // namespace
466
+
467
+ void HPackParser::FinishFrame() {
468
+ sink_ = Sink();
469
+ dynamic_table_updates_allowed_ = 2;
470
+ }
471
+
472
+ void GPR_ATTRIBUTE_NOINLINE HPackParser::LogHeader(grpc_mdelem md) {
631
473
  char* k = grpc_slice_to_c_string(GRPC_MDKEY(md));
632
474
  char* v = nullptr;
633
475
  if (grpc_is_binary_header_internal(GRPC_MDKEY(md))) {
@@ -646,179 +488,270 @@ static void GPR_ATTRIBUTE_NOINLINE on_hdr_log(grpc_mdelem md) {
646
488
  }
647
489
 
648
490
  /* emission helpers */
649
- template <bool do_add>
650
- static grpc_error* on_hdr(grpc_chttp2_hpack_parser* p, grpc_mdelem md) {
491
+ template <HPackParser::TableAction action>
492
+ grpc_error_handle HPackParser::FinishHeader(grpc_mdelem md) {
651
493
  if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
652
- on_hdr_log(md);
494
+ LogHeader(md);
653
495
  }
654
- if (do_add) {
496
+ if (action == TableAction::kAddToTable) {
655
497
  GPR_DEBUG_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED ||
656
498
  GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC);
657
- grpc_error* err = grpc_chttp2_hptbl_add(&p->table, md);
499
+ grpc_error_handle err = grpc_chttp2_hptbl_add(&table_, md);
658
500
  if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) return err;
659
501
  }
660
- return p->on_header(p->on_header_user_data, md);
502
+ return sink_(md);
661
503
  }
662
504
 
663
- static grpc_core::UnmanagedMemorySlice take_string_extern(
664
- grpc_chttp2_hpack_parser* /*p*/, grpc_chttp2_hpack_parser_string* str) {
665
- grpc_core::UnmanagedMemorySlice s;
666
- if (!str->copied) {
667
- GPR_DEBUG_ASSERT(!grpc_slice_is_interned(str->data.referenced));
668
- s = static_cast<grpc_core::UnmanagedMemorySlice&>(str->data.referenced);
669
- str->copied = true;
670
- str->data.referenced = grpc_core::UnmanagedMemorySlice();
505
+ UnmanagedMemorySlice HPackParser::String::TakeExtern() {
506
+ UnmanagedMemorySlice s;
507
+ if (!copied_) {
508
+ GPR_DEBUG_ASSERT(!grpc_slice_is_interned(data_.referenced));
509
+ s = static_cast<UnmanagedMemorySlice&>(data_.referenced);
510
+ copied_ = true;
511
+ data_.referenced = UnmanagedMemorySlice();
671
512
  } else {
672
- s = grpc_core::UnmanagedMemorySlice(str->data.copied.str,
673
- str->data.copied.length);
513
+ s = UnmanagedMemorySlice(data_.copied.str, data_.copied.length);
674
514
  }
675
- str->data.copied.length = 0;
515
+ data_.copied.length = 0;
676
516
  return s;
677
517
  }
678
518
 
679
- static grpc_core::ManagedMemorySlice take_string_intern(
680
- grpc_chttp2_hpack_parser* /*p*/, grpc_chttp2_hpack_parser_string* str) {
681
- grpc_core::ManagedMemorySlice s;
682
- if (!str->copied) {
683
- s = grpc_core::ManagedMemorySlice(&str->data.referenced);
684
- grpc_slice_unref_internal(str->data.referenced);
685
- str->copied = true;
686
- str->data.referenced = grpc_empty_slice();
519
+ ManagedMemorySlice HPackParser::String::TakeIntern() {
520
+ ManagedMemorySlice s;
521
+ if (!copied_) {
522
+ s = ManagedMemorySlice(&data_.referenced);
523
+ grpc_slice_unref_internal(data_.referenced);
524
+ copied_ = true;
525
+ data_.referenced = grpc_empty_slice();
687
526
  } else {
688
- s = grpc_core::ManagedMemorySlice(str->data.copied.str,
689
- str->data.copied.length);
527
+ s = ManagedMemorySlice(data_.copied.str, data_.copied.length);
690
528
  }
691
- str->data.copied.length = 0;
529
+ data_.copied.length = 0;
692
530
  return s;
693
531
  }
694
532
 
695
- /* jump to the next state */
696
- static grpc_error* parse_next(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
697
- const uint8_t* end) {
698
- p->state = *p->next_state++;
699
- return p->state(p, cur, end);
533
+ grpc_error_handle HPackParser::parse_next(const uint8_t* cur,
534
+ const uint8_t* end) {
535
+ state_ = *next_state_++;
536
+ return (this->*state_)(cur, end);
700
537
  }
701
538
 
702
539
  /* begin parsing a header: all functionality is encoded into lookup tables
703
540
  above */
704
- static grpc_error* parse_begin(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
705
- const uint8_t* end) {
541
+ grpc_error_handle HPackParser::parse_begin(const uint8_t* cur,
542
+ const uint8_t* end) {
706
543
  if (cur == end) {
707
- p->state = parse_begin;
544
+ state_ = &HPackParser::parse_begin;
708
545
  return GRPC_ERROR_NONE;
709
546
  }
710
547
 
711
- return first_byte_action[first_byte_lut[*cur]](p, cur, end);
548
+ switch (*cur >> 4) {
549
+ // Literal header not indexed.
550
+ // First byte format: 0000xxxx
551
+ // Where xxxx:
552
+ // 0000 - literal key
553
+ // 1111 - indexed key, varint encoded index
554
+ // other - indexed key, inline encoded index
555
+ case 0:
556
+ switch (*cur & 0xf) {
557
+ case 0: // literal key
558
+ return parse_lithdr_notidx_v(cur, end);
559
+ case 0xf: // varint encoded key index
560
+ return parse_lithdr_notidx_x(cur, end);
561
+ default: // inline encoded key index
562
+ return parse_lithdr_notidx(cur, end);
563
+ }
564
+ // Literal header never indexed.
565
+ // First byte format: 0001xxxx
566
+ // Where xxxx:
567
+ // 0000 - literal key
568
+ // 1111 - indexed key, varint encoded index
569
+ // other - indexed key, inline encoded index
570
+ case 1:
571
+ switch (*cur & 0xf) {
572
+ case 0: // literal key
573
+ return parse_lithdr_nvridx_v(cur, end);
574
+ case 0xf: // varint encoded key index
575
+ return parse_lithdr_nvridx_x(cur, end);
576
+ default: // inline encoded key index
577
+ return parse_lithdr_nvridx(cur, end);
578
+ }
579
+ // Update max table size.
580
+ // First byte format: 001xxxxx
581
+ // Where xxxxx:
582
+ // 11111 - max size is varint encoded
583
+ // other - max size is stored inline
584
+ case 2:
585
+ // inline encoded max table size
586
+ return parse_max_tbl_size(cur, end);
587
+ case 3:
588
+ if (*cur == 0x3f) {
589
+ // varint encoded max table size
590
+ return parse_max_tbl_size_x(cur, end);
591
+ } else {
592
+ // inline encoded max table size
593
+ return parse_max_tbl_size(cur, end);
594
+ }
595
+ // Literal header with incremental indexing.
596
+ // First byte format: 01xxxxxx
597
+ // Where xxxxxx:
598
+ // 000000 - literal key
599
+ // 111111 - indexed key, varint encoded index
600
+ // other - indexed key, inline encoded index
601
+ case 4:
602
+ if (*cur == 0x40) {
603
+ // literal key
604
+ return parse_lithdr_incidx_v(cur, end);
605
+ }
606
+ ABSL_FALLTHROUGH_INTENDED;
607
+ case 5:
608
+ case 6:
609
+ // inline encoded key index
610
+ return parse_lithdr_incidx(cur, end);
611
+ case 7:
612
+ if (*cur == 0x7f) {
613
+ // varint encoded key index
614
+ return parse_lithdr_incidx_x(cur, end);
615
+ } else {
616
+ // inline encoded key index
617
+ return parse_lithdr_incidx(cur, end);
618
+ }
619
+ // Indexed Header Field Representation
620
+ // First byte format: 1xxxxxxx
621
+ // Where xxxxxxx:
622
+ // 0000000 - illegal
623
+ // 1111111 - varint encoded field index
624
+ // other - inline encoded field index
625
+ case 8:
626
+ if (*cur == 0x80) {
627
+ // illegal value.
628
+ return parse_illegal_op(cur, end);
629
+ }
630
+ ABSL_FALLTHROUGH_INTENDED;
631
+ case 9:
632
+ case 10:
633
+ case 11:
634
+ case 12:
635
+ case 13:
636
+ case 14:
637
+ // inline encoded field index
638
+ return parse_indexed_field(cur, end);
639
+ case 15:
640
+ if (*cur == 0xff) {
641
+ // varint encoded field index
642
+ return parse_indexed_field_x(cur, end);
643
+ } else {
644
+ // inline encoded field index
645
+ return parse_indexed_field(cur, end);
646
+ }
647
+ }
648
+ GPR_UNREACHABLE_CODE(abort());
712
649
  }
713
650
 
714
651
  /* stream dependency and prioritization data: we just skip it */
715
- static grpc_error* parse_stream_weight(grpc_chttp2_hpack_parser* p,
716
- const uint8_t* cur, const uint8_t* end) {
652
+ grpc_error_handle HPackParser::parse_stream_weight(const uint8_t* cur,
653
+ const uint8_t* end) {
717
654
  if (cur == end) {
718
- p->state = parse_stream_weight;
655
+ state_ = &HPackParser::parse_stream_weight;
719
656
  return GRPC_ERROR_NONE;
720
657
  }
721
658
 
722
- return p->after_prioritization(p, cur + 1, end);
659
+ return (this->*after_prioritization_)(cur + 1, end);
723
660
  }
724
661
 
725
- static grpc_error* parse_stream_dep3(grpc_chttp2_hpack_parser* p,
726
- const uint8_t* cur, const uint8_t* end) {
662
+ grpc_error_handle HPackParser::parse_stream_dep3(const uint8_t* cur,
663
+ const uint8_t* end) {
727
664
  if (cur == end) {
728
- p->state = parse_stream_dep3;
665
+ state_ = &HPackParser::parse_stream_dep3;
729
666
  return GRPC_ERROR_NONE;
730
667
  }
731
668
 
732
- return parse_stream_weight(p, cur + 1, end);
669
+ return parse_stream_weight(cur + 1, end);
733
670
  }
734
671
 
735
- static grpc_error* parse_stream_dep2(grpc_chttp2_hpack_parser* p,
736
- const uint8_t* cur, const uint8_t* end) {
672
+ grpc_error_handle HPackParser::parse_stream_dep2(const uint8_t* cur,
673
+ const uint8_t* end) {
737
674
  if (cur == end) {
738
- p->state = parse_stream_dep2;
675
+ state_ = &HPackParser::parse_stream_dep2;
739
676
  return GRPC_ERROR_NONE;
740
677
  }
741
678
 
742
- return parse_stream_dep3(p, cur + 1, end);
679
+ return parse_stream_dep3(cur + 1, end);
743
680
  }
744
681
 
745
- static grpc_error* parse_stream_dep1(grpc_chttp2_hpack_parser* p,
746
- const uint8_t* cur, const uint8_t* end) {
682
+ grpc_error_handle HPackParser::parse_stream_dep1(const uint8_t* cur,
683
+ const uint8_t* end) {
747
684
  if (cur == end) {
748
- p->state = parse_stream_dep1;
685
+ state_ = &HPackParser::parse_stream_dep1;
749
686
  return GRPC_ERROR_NONE;
750
687
  }
751
688
 
752
- return parse_stream_dep2(p, cur + 1, end);
689
+ return parse_stream_dep2(cur + 1, end);
753
690
  }
754
691
 
755
- static grpc_error* parse_stream_dep0(grpc_chttp2_hpack_parser* p,
756
- const uint8_t* cur, const uint8_t* end) {
692
+ grpc_error_handle HPackParser::parse_stream_dep0(const uint8_t* cur,
693
+ const uint8_t* end) {
757
694
  if (cur == end) {
758
- p->state = parse_stream_dep0;
695
+ state_ = &HPackParser::parse_stream_dep0;
759
696
  return GRPC_ERROR_NONE;
760
697
  }
761
698
 
762
- return parse_stream_dep1(p, cur + 1, end);
699
+ return parse_stream_dep1(cur + 1, end);
763
700
  }
764
701
 
765
- static grpc_error* GPR_ATTRIBUTE_NOINLINE
766
- on_invalid_hpack_idx(grpc_chttp2_hpack_parser* p) {
702
+ grpc_error_handle HPackParser::InvalidHPackIndexError() {
767
703
  return grpc_error_set_int(
768
704
  grpc_error_set_int(
769
705
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid HPACK index received"),
770
- GRPC_ERROR_INT_INDEX, static_cast<intptr_t>(p->index)),
771
- GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(p->table.num_ents));
706
+ GRPC_ERROR_INT_INDEX, static_cast<intptr_t>(index_)),
707
+ GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(table_.num_ents));
772
708
  }
773
709
 
774
710
  /* emit an indexed field; jumps to begin the next field on completion */
775
- static grpc_error* finish_indexed_field(grpc_chttp2_hpack_parser* p,
776
- const uint8_t* cur,
777
- const uint8_t* end) {
778
- grpc_mdelem md = grpc_chttp2_hptbl_lookup<true>(&p->table, p->index);
711
+ grpc_error_handle HPackParser::finish_indexed_field(const uint8_t* cur,
712
+ const uint8_t* end) {
713
+ grpc_mdelem md = grpc_chttp2_hptbl_lookup<true>(&table_, index_);
779
714
  if (GPR_UNLIKELY(GRPC_MDISNULL(md))) {
780
- return on_invalid_hpack_idx(p);
715
+ return InvalidHPackIndexError();
781
716
  }
782
717
  GRPC_STATS_INC_HPACK_RECV_INDEXED();
783
- grpc_error* err = on_hdr<false>(p, md);
718
+ grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(md);
784
719
  if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) return err;
785
- return parse_begin(p, cur, end);
720
+ return parse_begin(cur, end);
786
721
  }
787
722
 
788
723
  /* parse an indexed field with index < 127 */
789
- static grpc_error* parse_indexed_field(grpc_chttp2_hpack_parser* p,
790
- const uint8_t* cur, const uint8_t* end) {
791
- p->dynamic_table_update_allowed = 0;
792
- p->index = (*cur) & 0x7f;
793
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
794
- return finish_indexed_field(p, cur + 1, end);
724
+ grpc_error_handle HPackParser::parse_indexed_field(const uint8_t* cur,
725
+ const uint8_t* end) {
726
+ dynamic_table_updates_allowed_ = 0;
727
+ index_ = (*cur) & 0x7f;
728
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
729
+ return finish_indexed_field(cur + 1, end);
795
730
  }
796
731
 
797
732
  /* parse an indexed field with index >= 127 */
798
- static grpc_error* parse_indexed_field_x(grpc_chttp2_hpack_parser* p,
799
- const uint8_t* cur,
800
- const uint8_t* end) {
801
- static const grpc_chttp2_hpack_parser_state and_then[] = {
802
- finish_indexed_field};
803
- p->dynamic_table_update_allowed = 0;
804
- p->next_state = and_then;
805
- p->index = 0x7f;
806
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
807
- p->parsing.value = &p->index;
808
- return parse_value0(p, cur + 1, end);
733
+ grpc_error_handle HPackParser::parse_indexed_field_x(const uint8_t* cur,
734
+ const uint8_t* end) {
735
+ static const State and_then[] = {&HPackParser::finish_indexed_field};
736
+ dynamic_table_updates_allowed_ = 0;
737
+ next_state_ = and_then;
738
+ index_ = 0x7f;
739
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
740
+ parsing_.value = &index_;
741
+ return parse_value0(cur + 1, end);
809
742
  }
810
743
 
811
744
  /* When finishing with a header, get the cached md element for this index.
812
745
  This is set in parse_value_string(). We ensure (in debug mode) that the
813
746
  cached metadata corresponds with the index we are examining. */
814
- static grpc_mdelem get_precomputed_md_for_idx(grpc_chttp2_hpack_parser* p) {
815
- GPR_DEBUG_ASSERT(p->md_for_index.payload != 0);
816
- GPR_DEBUG_ASSERT(static_cast<int64_t>(p->index) == p->precomputed_md_index);
817
- grpc_mdelem md = p->md_for_index;
747
+ grpc_mdelem HPackParser::GetPrecomputedMDForIndex() {
748
+ GPR_DEBUG_ASSERT(md_for_index_.payload != 0);
749
+ GPR_DEBUG_ASSERT(static_cast<int64_t>(index_) == precomputed_md_index_);
750
+ grpc_mdelem md = md_for_index_;
818
751
  GPR_DEBUG_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */
819
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
752
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
820
753
  #ifndef NDEBUG
821
- p->precomputed_md_index = -1;
754
+ precomputed_md_index_ = -1;
822
755
  #endif
823
756
  return md;
824
757
  }
@@ -830,352 +763,340 @@ static const grpc_core::ManagedMemorySlice& get_indexed_key(grpc_mdelem md) {
830
763
  }
831
764
 
832
765
  /* finish a literal header with incremental indexing */
833
- static grpc_error* finish_lithdr_incidx(grpc_chttp2_hpack_parser* p,
834
- const uint8_t* cur,
835
- const uint8_t* end) {
766
+ grpc_error_handle HPackParser::finish_lithdr_incidx(const uint8_t* cur,
767
+ const uint8_t* end) {
836
768
  GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX();
837
- grpc_mdelem md = get_precomputed_md_for_idx(p);
838
- grpc_error* err = on_hdr<true>(
839
- p, grpc_mdelem_from_slices(get_indexed_key(md),
840
- take_string_intern(p, &p->value)));
841
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
842
- return parse_begin(p, cur, end);
769
+ grpc_mdelem md = GetPrecomputedMDForIndex();
770
+ grpc_error_handle err = FinishHeader<TableAction::kAddToTable>(
771
+ grpc_mdelem_from_slices(get_indexed_key(md), value_.TakeIntern()));
772
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
773
+ return parse_begin(cur, end);
843
774
  }
844
775
 
845
776
  /* finish a literal header with incremental indexing with no index */
846
- static grpc_error* finish_lithdr_incidx_v(grpc_chttp2_hpack_parser* p,
847
- const uint8_t* cur,
848
- const uint8_t* end) {
777
+ grpc_error_handle HPackParser::finish_lithdr_incidx_v(const uint8_t* cur,
778
+ const uint8_t* end) {
849
779
  GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V();
850
- grpc_error* err = on_hdr<true>(
851
- p, grpc_mdelem_from_slices(take_string_intern(p, &p->key),
852
- take_string_intern(p, &p->value)));
853
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
854
- return parse_begin(p, cur, end);
780
+ grpc_error_handle err = FinishHeader<TableAction::kAddToTable>(
781
+ grpc_mdelem_from_slices(key_.TakeIntern(), value_.TakeIntern()));
782
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
783
+ return parse_begin(cur, end);
855
784
  }
856
785
 
857
786
  /* parse a literal header with incremental indexing; index < 63 */
858
- static grpc_error* parse_lithdr_incidx(grpc_chttp2_hpack_parser* p,
859
- const uint8_t* cur, const uint8_t* end) {
860
- static const grpc_chttp2_hpack_parser_state and_then[] = {
861
- parse_value_string_with_indexed_key, finish_lithdr_incidx};
862
- p->dynamic_table_update_allowed = 0;
863
- p->next_state = and_then;
864
- p->index = (*cur) & 0x3f;
865
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
866
- return parse_string_prefix(p, cur + 1, end);
787
+ grpc_error_handle HPackParser::parse_lithdr_incidx(const uint8_t* cur,
788
+ const uint8_t* end) {
789
+ static const State and_then[] = {
790
+ &HPackParser::parse_value_string_with_indexed_key,
791
+ &HPackParser::finish_lithdr_incidx};
792
+ dynamic_table_updates_allowed_ = 0;
793
+ next_state_ = and_then;
794
+ index_ = (*cur) & 0x3f;
795
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
796
+ return parse_string_prefix(cur + 1, end);
867
797
  }
868
798
 
869
799
  /* parse a literal header with incremental indexing; index >= 63 */
870
- static grpc_error* parse_lithdr_incidx_x(grpc_chttp2_hpack_parser* p,
871
- const uint8_t* cur,
872
- const uint8_t* end) {
873
- static const grpc_chttp2_hpack_parser_state and_then[] = {
874
- parse_string_prefix, parse_value_string_with_indexed_key,
875
- finish_lithdr_incidx};
876
- p->dynamic_table_update_allowed = 0;
877
- p->next_state = and_then;
878
- p->index = 0x3f;
879
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
880
- p->parsing.value = &p->index;
881
- return parse_value0(p, cur + 1, end);
800
+ grpc_error_handle HPackParser::parse_lithdr_incidx_x(const uint8_t* cur,
801
+ const uint8_t* end) {
802
+ static const State and_then[] = {
803
+ &HPackParser::parse_string_prefix,
804
+ &HPackParser::parse_value_string_with_indexed_key,
805
+ &HPackParser::finish_lithdr_incidx};
806
+ dynamic_table_updates_allowed_ = 0;
807
+ next_state_ = and_then;
808
+ index_ = 0x3f;
809
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
810
+ parsing_.value = &index_;
811
+ return parse_value0(cur + 1, end);
882
812
  }
883
813
 
884
814
  /* parse a literal header with incremental indexing; index = 0 */
885
- static grpc_error* parse_lithdr_incidx_v(grpc_chttp2_hpack_parser* p,
886
- const uint8_t* cur,
887
- const uint8_t* end) {
888
- static const grpc_chttp2_hpack_parser_state and_then[] = {
889
- parse_key_string, parse_string_prefix,
890
- parse_value_string_with_literal_key, finish_lithdr_incidx_v};
891
- p->dynamic_table_update_allowed = 0;
892
- p->next_state = and_then;
893
- return parse_string_prefix(p, cur + 1, end);
815
+ grpc_error_handle HPackParser::parse_lithdr_incidx_v(const uint8_t* cur,
816
+ const uint8_t* end) {
817
+ static const State and_then[] = {
818
+ &HPackParser::parse_key_string, &HPackParser::parse_string_prefix,
819
+ &HPackParser::parse_value_string_with_literal_key,
820
+ &HPackParser::finish_lithdr_incidx_v};
821
+ dynamic_table_updates_allowed_ = 0;
822
+ next_state_ = and_then;
823
+ return parse_string_prefix(cur + 1, end);
894
824
  }
895
825
 
896
826
  /* finish a literal header without incremental indexing */
897
- static grpc_error* finish_lithdr_notidx(grpc_chttp2_hpack_parser* p,
898
- const uint8_t* cur,
899
- const uint8_t* end) {
827
+ grpc_error_handle HPackParser::finish_lithdr_notidx(const uint8_t* cur,
828
+ const uint8_t* end) {
900
829
  GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX();
901
- grpc_mdelem md = get_precomputed_md_for_idx(p);
902
- grpc_error* err = on_hdr<false>(
903
- p, grpc_mdelem_from_slices(get_indexed_key(md),
904
- take_string_extern(p, &p->value)));
905
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
906
- return parse_begin(p, cur, end);
830
+ grpc_mdelem md = GetPrecomputedMDForIndex();
831
+ grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(
832
+ grpc_mdelem_from_slices(get_indexed_key(md), value_.TakeExtern()));
833
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
834
+ return parse_begin(cur, end);
907
835
  }
908
836
 
909
837
  /* finish a literal header without incremental indexing with index = 0 */
910
- static grpc_error* finish_lithdr_notidx_v(grpc_chttp2_hpack_parser* p,
911
- const uint8_t* cur,
912
- const uint8_t* end) {
838
+ grpc_error_handle HPackParser::finish_lithdr_notidx_v(const uint8_t* cur,
839
+ const uint8_t* end) {
913
840
  GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V();
914
- grpc_error* err = on_hdr<false>(
915
- p, grpc_mdelem_from_slices(take_string_intern(p, &p->key),
916
- take_string_extern(p, &p->value)));
917
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
918
- return parse_begin(p, cur, end);
841
+ grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(
842
+ grpc_mdelem_from_slices(key_.TakeIntern(), value_.TakeExtern()));
843
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
844
+ return parse_begin(cur, end);
919
845
  }
920
846
 
921
847
  /* parse a literal header without incremental indexing; index < 15 */
922
- static grpc_error* parse_lithdr_notidx(grpc_chttp2_hpack_parser* p,
923
- const uint8_t* cur, const uint8_t* end) {
924
- static const grpc_chttp2_hpack_parser_state and_then[] = {
925
- parse_value_string_with_indexed_key, finish_lithdr_notidx};
926
- p->dynamic_table_update_allowed = 0;
927
- p->next_state = and_then;
928
- p->index = (*cur) & 0xf;
929
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
930
- return parse_string_prefix(p, cur + 1, end);
848
+ grpc_error_handle HPackParser::parse_lithdr_notidx(const uint8_t* cur,
849
+ const uint8_t* end) {
850
+ static const State and_then[] = {
851
+ &HPackParser::parse_value_string_with_indexed_key,
852
+ &HPackParser::finish_lithdr_notidx};
853
+ dynamic_table_updates_allowed_ = 0;
854
+ next_state_ = and_then;
855
+ index_ = (*cur) & 0xf;
856
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
857
+ return parse_string_prefix(cur + 1, end);
931
858
  }
932
859
 
933
860
  /* parse a literal header without incremental indexing; index >= 15 */
934
- static grpc_error* parse_lithdr_notidx_x(grpc_chttp2_hpack_parser* p,
935
- const uint8_t* cur,
936
- const uint8_t* end) {
937
- static const grpc_chttp2_hpack_parser_state and_then[] = {
938
- parse_string_prefix, parse_value_string_with_indexed_key,
939
- finish_lithdr_notidx};
940
- p->dynamic_table_update_allowed = 0;
941
- p->next_state = and_then;
942
- p->index = 0xf;
943
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
944
- p->parsing.value = &p->index;
945
- return parse_value0(p, cur + 1, end);
861
+ grpc_error_handle HPackParser::parse_lithdr_notidx_x(const uint8_t* cur,
862
+ const uint8_t* end) {
863
+ static const State and_then[] = {
864
+ &HPackParser::parse_string_prefix,
865
+ &HPackParser::parse_value_string_with_indexed_key,
866
+ &HPackParser::finish_lithdr_notidx};
867
+ dynamic_table_updates_allowed_ = 0;
868
+ next_state_ = and_then;
869
+ index_ = 0xf;
870
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
871
+ parsing_.value = &index_;
872
+ return parse_value0(cur + 1, end);
946
873
  }
947
874
 
948
875
  /* parse a literal header without incremental indexing; index == 0 */
949
- static grpc_error* parse_lithdr_notidx_v(grpc_chttp2_hpack_parser* p,
950
- const uint8_t* cur,
951
- const uint8_t* end) {
952
- static const grpc_chttp2_hpack_parser_state and_then[] = {
953
- parse_key_string, parse_string_prefix,
954
- parse_value_string_with_literal_key, finish_lithdr_notidx_v};
955
- p->dynamic_table_update_allowed = 0;
956
- p->next_state = and_then;
957
- return parse_string_prefix(p, cur + 1, end);
876
+ grpc_error_handle HPackParser::parse_lithdr_notidx_v(const uint8_t* cur,
877
+ const uint8_t* end) {
878
+ static const State and_then[] = {
879
+ &HPackParser::parse_key_string, &HPackParser::parse_string_prefix,
880
+ &HPackParser::parse_value_string_with_literal_key,
881
+ &HPackParser::finish_lithdr_notidx_v};
882
+ dynamic_table_updates_allowed_ = 0;
883
+ next_state_ = and_then;
884
+ return parse_string_prefix(cur + 1, end);
958
885
  }
959
886
 
960
887
  /* finish a literal header that is never indexed */
961
- static grpc_error* finish_lithdr_nvridx(grpc_chttp2_hpack_parser* p,
962
- const uint8_t* cur,
963
- const uint8_t* end) {
888
+ grpc_error_handle HPackParser::finish_lithdr_nvridx(const uint8_t* cur,
889
+ const uint8_t* end) {
964
890
  GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX();
965
- grpc_mdelem md = get_precomputed_md_for_idx(p);
966
- grpc_error* err = on_hdr<false>(
967
- p, grpc_mdelem_from_slices(get_indexed_key(md),
968
- take_string_extern(p, &p->value)));
969
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
970
- return parse_begin(p, cur, end);
891
+ grpc_mdelem md = GetPrecomputedMDForIndex();
892
+ grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(
893
+ grpc_mdelem_from_slices(get_indexed_key(md), value_.TakeExtern()));
894
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
895
+ return parse_begin(cur, end);
971
896
  }
972
897
 
973
898
  /* finish a literal header that is never indexed with an extra value */
974
- static grpc_error* finish_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p,
975
- const uint8_t* cur,
976
- const uint8_t* end) {
899
+ grpc_error_handle HPackParser::finish_lithdr_nvridx_v(const uint8_t* cur,
900
+ const uint8_t* end) {
977
901
  GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V();
978
- grpc_error* err = on_hdr<false>(
979
- p, grpc_mdelem_from_slices(take_string_intern(p, &p->key),
980
- take_string_extern(p, &p->value)));
981
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
982
- return parse_begin(p, cur, end);
902
+ grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(
903
+ grpc_mdelem_from_slices(key_.TakeIntern(), value_.TakeExtern()));
904
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
905
+ return parse_begin(cur, end);
983
906
  }
984
907
 
985
908
  /* parse a literal header that is never indexed; index < 15 */
986
- static grpc_error* parse_lithdr_nvridx(grpc_chttp2_hpack_parser* p,
987
- const uint8_t* cur, const uint8_t* end) {
988
- static const grpc_chttp2_hpack_parser_state and_then[] = {
989
- parse_value_string_with_indexed_key, finish_lithdr_nvridx};
990
- p->dynamic_table_update_allowed = 0;
991
- p->next_state = and_then;
992
- p->index = (*cur) & 0xf;
993
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
994
- return parse_string_prefix(p, cur + 1, end);
909
+ grpc_error_handle HPackParser::parse_lithdr_nvridx(const uint8_t* cur,
910
+ const uint8_t* end) {
911
+ static const State and_then[] = {
912
+ &HPackParser::parse_value_string_with_indexed_key,
913
+ &HPackParser::finish_lithdr_nvridx};
914
+ dynamic_table_updates_allowed_ = 0;
915
+ next_state_ = and_then;
916
+ index_ = (*cur) & 0xf;
917
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
918
+ return parse_string_prefix(cur + 1, end);
995
919
  }
996
920
 
997
921
  /* parse a literal header that is never indexed; index >= 15 */
998
- static grpc_error* parse_lithdr_nvridx_x(grpc_chttp2_hpack_parser* p,
999
- const uint8_t* cur,
1000
- const uint8_t* end) {
1001
- static const grpc_chttp2_hpack_parser_state and_then[] = {
1002
- parse_string_prefix, parse_value_string_with_indexed_key,
1003
- finish_lithdr_nvridx};
1004
- p->dynamic_table_update_allowed = 0;
1005
- p->next_state = and_then;
1006
- p->index = 0xf;
1007
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
1008
- p->parsing.value = &p->index;
1009
- return parse_value0(p, cur + 1, end);
922
+ grpc_error_handle HPackParser::parse_lithdr_nvridx_x(const uint8_t* cur,
923
+ const uint8_t* end) {
924
+ static const State and_then[] = {
925
+ &HPackParser::parse_string_prefix,
926
+ &HPackParser::parse_value_string_with_indexed_key,
927
+ &HPackParser::finish_lithdr_nvridx};
928
+ dynamic_table_updates_allowed_ = 0;
929
+ next_state_ = and_then;
930
+ index_ = 0xf;
931
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
932
+ parsing_.value = &index_;
933
+ return parse_value0(cur + 1, end);
1010
934
  }
1011
935
 
1012
936
  /* parse a literal header that is never indexed; index == 0 */
1013
- static grpc_error* parse_lithdr_nvridx_v(grpc_chttp2_hpack_parser* p,
1014
- const uint8_t* cur,
1015
- const uint8_t* end) {
1016
- static const grpc_chttp2_hpack_parser_state and_then[] = {
1017
- parse_key_string, parse_string_prefix,
1018
- parse_value_string_with_literal_key, finish_lithdr_nvridx_v};
1019
- p->dynamic_table_update_allowed = 0;
1020
- p->next_state = and_then;
1021
- return parse_string_prefix(p, cur + 1, end);
937
+ grpc_error_handle HPackParser::parse_lithdr_nvridx_v(const uint8_t* cur,
938
+ const uint8_t* end) {
939
+ static const State and_then[] = {
940
+ &HPackParser::parse_key_string, &HPackParser::parse_string_prefix,
941
+ &HPackParser::parse_value_string_with_literal_key,
942
+ &HPackParser::finish_lithdr_nvridx_v};
943
+ dynamic_table_updates_allowed_ = 0;
944
+ next_state_ = and_then;
945
+ return parse_string_prefix(cur + 1, end);
1022
946
  }
1023
947
 
1024
948
  /* finish parsing a max table size change */
1025
- static grpc_error* finish_max_tbl_size(grpc_chttp2_hpack_parser* p,
1026
- const uint8_t* cur, const uint8_t* end) {
949
+ grpc_error_handle HPackParser::finish_max_tbl_size(const uint8_t* cur,
950
+ const uint8_t* end) {
1027
951
  if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
1028
- gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", p->index);
952
+ gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", index_);
1029
953
  }
1030
- grpc_error* err =
1031
- grpc_chttp2_hptbl_set_current_table_size(&p->table, p->index);
1032
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1033
- return parse_begin(p, cur, end);
954
+ grpc_error_handle err =
955
+ grpc_chttp2_hptbl_set_current_table_size(&table_, index_);
956
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
957
+ return parse_begin(cur, end);
1034
958
  }
1035
959
 
1036
960
  /* parse a max table size change, max size < 15 */
1037
- static grpc_error* parse_max_tbl_size(grpc_chttp2_hpack_parser* p,
1038
- const uint8_t* cur, const uint8_t* end) {
1039
- if (p->dynamic_table_update_allowed == 0) {
961
+ grpc_error_handle HPackParser::parse_max_tbl_size(const uint8_t* cur,
962
+ const uint8_t* end) {
963
+ if (dynamic_table_updates_allowed_ == 0) {
1040
964
  return parse_error(
1041
- p, cur, end,
965
+ cur, end,
1042
966
  GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1043
967
  "More than two max table size changes in a single frame"));
1044
968
  }
1045
- p->dynamic_table_update_allowed--;
1046
- p->index = (*cur) & 0x1f;
1047
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
1048
- return finish_max_tbl_size(p, cur + 1, end);
969
+ dynamic_table_updates_allowed_--;
970
+ index_ = (*cur) & 0x1f;
971
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
972
+ return finish_max_tbl_size(cur + 1, end);
1049
973
  }
1050
974
 
1051
975
  /* parse a max table size change, max size >= 15 */
1052
- static grpc_error* parse_max_tbl_size_x(grpc_chttp2_hpack_parser* p,
1053
- const uint8_t* cur,
1054
- const uint8_t* end) {
1055
- static const grpc_chttp2_hpack_parser_state and_then[] = {
1056
- finish_max_tbl_size};
1057
- if (p->dynamic_table_update_allowed == 0) {
976
+ grpc_error_handle HPackParser::parse_max_tbl_size_x(const uint8_t* cur,
977
+ const uint8_t* end) {
978
+ static const State and_then[] = {&HPackParser::finish_max_tbl_size};
979
+ if (dynamic_table_updates_allowed_ == 0) {
1058
980
  return parse_error(
1059
- p, cur, end,
981
+ cur, end,
1060
982
  GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1061
983
  "More than two max table size changes in a single frame"));
1062
984
  }
1063
- p->dynamic_table_update_allowed--;
1064
- p->next_state = and_then;
1065
- p->index = 0x1f;
1066
- p->md_for_index.payload = 0; /* Invalidate cached md when index changes. */
1067
- p->parsing.value = &p->index;
1068
- return parse_value0(p, cur + 1, end);
985
+ dynamic_table_updates_allowed_--;
986
+ next_state_ = and_then;
987
+ index_ = 0x1f;
988
+ md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
989
+ parsing_.value = &index_;
990
+ return parse_value0(cur + 1, end);
1069
991
  }
1070
992
 
1071
993
  /* a parse error: jam the parse state into parse_error, and return error */
1072
- static grpc_error* parse_error(grpc_chttp2_hpack_parser* p,
1073
- const uint8_t* /*cur*/, const uint8_t* /*end*/,
1074
- grpc_error* err) {
994
+ grpc_error_handle HPackParser::parse_error(const uint8_t* /*cur*/,
995
+ const uint8_t* /*end*/,
996
+ grpc_error_handle err) {
1075
997
  GPR_ASSERT(err != GRPC_ERROR_NONE);
1076
- if (p->last_error == GRPC_ERROR_NONE) {
1077
- p->last_error = GRPC_ERROR_REF(err);
998
+ if (last_error_ == GRPC_ERROR_NONE) {
999
+ last_error_ = GRPC_ERROR_REF(err);
1078
1000
  }
1079
- p->state = still_parse_error;
1001
+ state_ = &HPackParser::still_parse_error;
1080
1002
  return err;
1081
1003
  }
1082
1004
 
1083
- static grpc_error* still_parse_error(grpc_chttp2_hpack_parser* p,
1084
- const uint8_t* /*cur*/,
1085
- const uint8_t* /*end*/) {
1086
- return GRPC_ERROR_REF(p->last_error);
1005
+ grpc_error_handle HPackParser::still_parse_error(const uint8_t* /*cur*/,
1006
+ const uint8_t* /*end*/) {
1007
+ return GRPC_ERROR_REF(last_error_);
1087
1008
  }
1088
1009
 
1089
- static grpc_error* parse_illegal_op(grpc_chttp2_hpack_parser* p,
1090
- const uint8_t* cur, const uint8_t* end) {
1010
+ grpc_error_handle HPackParser::parse_illegal_op(const uint8_t* cur,
1011
+ const uint8_t* end) {
1091
1012
  GPR_ASSERT(cur != end);
1092
- grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1013
+ grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1093
1014
  absl::StrCat("Illegal hpack op code ", *cur).c_str());
1094
- return parse_error(p, cur, end, err);
1015
+ return parse_error(cur, end, err);
1095
1016
  }
1096
1017
 
1097
- /* parse the 1st byte of a varint into p->parsing.value
1018
+ /* parse the 1st byte of a varint into parsing_.value
1098
1019
  no overflow is possible */
1099
- static grpc_error* parse_value0(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1100
- const uint8_t* end) {
1020
+ grpc_error_handle HPackParser::parse_value0(const uint8_t* cur,
1021
+ const uint8_t* end) {
1101
1022
  if (cur == end) {
1102
- p->state = parse_value0;
1023
+ state_ = &HPackParser::parse_value0;
1103
1024
  return GRPC_ERROR_NONE;
1104
1025
  }
1105
1026
 
1106
- *p->parsing.value += (*cur) & 0x7f;
1027
+ *parsing_.value += (*cur) & 0x7f;
1107
1028
 
1108
1029
  if ((*cur) & 0x80) {
1109
- return parse_value1(p, cur + 1, end);
1030
+ return parse_value1(cur + 1, end);
1110
1031
  } else {
1111
- return parse_next(p, cur + 1, end);
1032
+ return parse_next(cur + 1, end);
1112
1033
  }
1113
1034
  }
1114
1035
 
1115
- /* parse the 2nd byte of a varint into p->parsing.value
1036
+ /* parse the 2nd byte of a varint into parsing_.value
1116
1037
  no overflow is possible */
1117
- static grpc_error* parse_value1(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1118
- const uint8_t* end) {
1038
+ grpc_error_handle HPackParser::parse_value1(const uint8_t* cur,
1039
+ const uint8_t* end) {
1119
1040
  if (cur == end) {
1120
- p->state = parse_value1;
1041
+ state_ = &HPackParser::parse_value1;
1121
1042
  return GRPC_ERROR_NONE;
1122
1043
  }
1123
1044
 
1124
- *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 7;
1045
+ *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 7;
1125
1046
 
1126
1047
  if ((*cur) & 0x80) {
1127
- return parse_value2(p, cur + 1, end);
1048
+ return parse_value2(cur + 1, end);
1128
1049
  } else {
1129
- return parse_next(p, cur + 1, end);
1050
+ return parse_next(cur + 1, end);
1130
1051
  }
1131
1052
  }
1132
1053
 
1133
- /* parse the 3rd byte of a varint into p->parsing.value
1054
+ /* parse the 3rd byte of a varint into parsing_.value
1134
1055
  no overflow is possible */
1135
- static grpc_error* parse_value2(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1136
- const uint8_t* end) {
1056
+ grpc_error_handle HPackParser::parse_value2(const uint8_t* cur,
1057
+ const uint8_t* end) {
1137
1058
  if (cur == end) {
1138
- p->state = parse_value2;
1059
+ state_ = &HPackParser::parse_value2;
1139
1060
  return GRPC_ERROR_NONE;
1140
1061
  }
1141
1062
 
1142
- *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 14;
1063
+ *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 14;
1143
1064
 
1144
1065
  if ((*cur) & 0x80) {
1145
- return parse_value3(p, cur + 1, end);
1066
+ return parse_value3(cur + 1, end);
1146
1067
  } else {
1147
- return parse_next(p, cur + 1, end);
1068
+ return parse_next(cur + 1, end);
1148
1069
  }
1149
1070
  }
1150
1071
 
1151
- /* parse the 4th byte of a varint into p->parsing.value
1072
+ /* parse the 4th byte of a varint into parsing_.value
1152
1073
  no overflow is possible */
1153
- static grpc_error* parse_value3(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1154
- const uint8_t* end) {
1074
+ grpc_error_handle HPackParser::parse_value3(const uint8_t* cur,
1075
+ const uint8_t* end) {
1155
1076
  if (cur == end) {
1156
- p->state = parse_value3;
1077
+ state_ = &HPackParser::parse_value3;
1157
1078
  return GRPC_ERROR_NONE;
1158
1079
  }
1159
1080
 
1160
- *p->parsing.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 21;
1081
+ *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 21;
1161
1082
 
1162
1083
  if ((*cur) & 0x80) {
1163
- return parse_value4(p, cur + 1, end);
1084
+ return parse_value4(cur + 1, end);
1164
1085
  } else {
1165
- return parse_next(p, cur + 1, end);
1086
+ return parse_next(cur + 1, end);
1166
1087
  }
1167
1088
  }
1168
1089
 
1169
- /* parse the 5th byte of a varint into p->parsing.value
1090
+ /* parse the 5th byte of a varint into parsing_.value
1170
1091
  depending on the byte, we may overflow, and care must be taken */
1171
- static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1172
- const uint8_t* end) {
1092
+ grpc_error_handle HPackParser::parse_value4(const uint8_t* cur,
1093
+ const uint8_t* end) {
1173
1094
  uint8_t c;
1174
1095
  uint32_t cur_value;
1175
1096
  uint32_t add_value;
1176
1097
 
1177
1098
  if (cur == end) {
1178
- p->state = parse_value4;
1099
+ state_ = &HPackParser::parse_value4;
1179
1100
  return GRPC_ERROR_NONE;
1180
1101
  }
1181
1102
 
@@ -1184,369 +1105,366 @@ static grpc_error* parse_value4(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1184
1105
  goto error;
1185
1106
  }
1186
1107
 
1187
- cur_value = *p->parsing.value;
1108
+ cur_value = *parsing_.value;
1188
1109
  add_value = (static_cast<uint32_t>(c)) << 28;
1189
1110
  if (add_value > 0xffffffffu - cur_value) {
1190
1111
  goto error;
1191
1112
  }
1192
1113
 
1193
- *p->parsing.value = cur_value + add_value;
1114
+ *parsing_.value = cur_value + add_value;
1194
1115
 
1195
1116
  if ((*cur) & 0x80) {
1196
- return parse_value5up(p, cur + 1, end);
1117
+ return parse_value5up(cur + 1, end);
1197
1118
  } else {
1198
- return parse_next(p, cur + 1, end);
1119
+ return parse_next(cur + 1, end);
1199
1120
  }
1200
1121
 
1201
1122
  error:
1202
- grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1123
+ grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1203
1124
  absl::StrFormat(
1204
1125
  "integer overflow in hpack integer decoding: have 0x%08x, "
1205
1126
  "got byte 0x%02x on byte 5",
1206
- *p->parsing.value, *cur)
1127
+ *parsing_.value, *cur)
1207
1128
  .c_str());
1208
- return parse_error(p, cur, end, err);
1129
+ return parse_error(cur, end, err);
1209
1130
  }
1210
1131
 
1211
1132
  /* parse any trailing bytes in a varint: it's possible to append an arbitrary
1212
1133
  number of 0x80's and not affect the value - a zero will terminate - and
1213
1134
  anything else will overflow */
1214
- static grpc_error* parse_value5up(grpc_chttp2_hpack_parser* p,
1215
- const uint8_t* cur, const uint8_t* end) {
1135
+ grpc_error_handle HPackParser::parse_value5up(const uint8_t* cur,
1136
+ const uint8_t* end) {
1216
1137
  while (cur != end && *cur == 0x80) {
1217
1138
  ++cur;
1218
1139
  }
1219
1140
 
1220
1141
  if (cur == end) {
1221
- p->state = parse_value5up;
1142
+ state_ = &HPackParser::parse_value5up;
1222
1143
  return GRPC_ERROR_NONE;
1223
1144
  }
1224
1145
 
1225
1146
  if (*cur == 0) {
1226
- return parse_next(p, cur + 1, end);
1147
+ return parse_next(cur + 1, end);
1227
1148
  }
1228
1149
 
1229
- grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1150
+ grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1230
1151
  absl::StrFormat(
1231
1152
  "integer overflow in hpack integer decoding: have 0x%08x, "
1232
1153
  "got byte 0x%02x sometime after byte 5",
1233
- *p->parsing.value, *cur)
1154
+ *parsing_.value, *cur)
1234
1155
  .c_str());
1235
- return parse_error(p, cur, end, err);
1156
+ return parse_error(cur, end, err);
1236
1157
  }
1237
1158
 
1238
1159
  /* parse a string prefix */
1239
- static grpc_error* parse_string_prefix(grpc_chttp2_hpack_parser* p,
1240
- const uint8_t* cur, const uint8_t* end) {
1160
+ grpc_error_handle HPackParser::parse_string_prefix(const uint8_t* cur,
1161
+ const uint8_t* end) {
1241
1162
  if (cur == end) {
1242
- p->state = parse_string_prefix;
1163
+ state_ = &HPackParser::parse_string_prefix;
1243
1164
  return GRPC_ERROR_NONE;
1244
1165
  }
1245
1166
 
1246
- p->strlen = (*cur) & 0x7f;
1247
- p->huff = (*cur) >> 7;
1248
- if (p->strlen == 0x7f) {
1249
- p->parsing.value = &p->strlen;
1250
- return parse_value0(p, cur + 1, end);
1167
+ strlen_ = (*cur) & 0x7f;
1168
+ huff_ = (*cur) >> 7;
1169
+ if (strlen_ == 0x7f) {
1170
+ parsing_.value = &strlen_;
1171
+ return parse_value0(cur + 1, end);
1251
1172
  } else {
1252
- return parse_next(p, cur + 1, end);
1173
+ return parse_next(cur + 1, end);
1253
1174
  }
1254
1175
  }
1255
1176
 
1256
1177
  /* append some bytes to a string */
1257
- static void append_bytes(grpc_chttp2_hpack_parser_string* str,
1258
- const uint8_t* data, size_t length) {
1178
+ void HPackParser::String::AppendBytes(const uint8_t* data, size_t length) {
1259
1179
  if (length == 0) return;
1260
- if (length + str->data.copied.length > str->data.copied.capacity) {
1261
- GPR_ASSERT(str->data.copied.length + length <= UINT32_MAX);
1262
- str->data.copied.capacity =
1263
- static_cast<uint32_t>(str->data.copied.length + length);
1264
- str->data.copied.str = static_cast<char*>(
1265
- gpr_realloc(str->data.copied.str, str->data.copied.capacity));
1180
+ if (length + data_.copied.length > data_.copied.capacity) {
1181
+ GPR_ASSERT(data_.copied.length + length <= UINT32_MAX);
1182
+ data_.copied.capacity = static_cast<uint32_t>(data_.copied.length + length);
1183
+ data_.copied.str = static_cast<char*>(
1184
+ gpr_realloc(data_.copied.str, data_.copied.capacity));
1266
1185
  }
1267
- memcpy(str->data.copied.str + str->data.copied.length, data, length);
1268
- GPR_ASSERT(length <= UINT32_MAX - str->data.copied.length);
1269
- str->data.copied.length += static_cast<uint32_t>(length);
1186
+ memcpy(data_.copied.str + data_.copied.length, data, length);
1187
+ GPR_ASSERT(length <= UINT32_MAX - data_.copied.length);
1188
+ data_.copied.length += static_cast<uint32_t>(length);
1270
1189
  }
1271
1190
 
1272
- static grpc_error* append_string(grpc_chttp2_hpack_parser* p,
1273
- const uint8_t* cur, const uint8_t* end) {
1274
- grpc_chttp2_hpack_parser_string* str = p->parsing.str;
1191
+ grpc_error_handle HPackParser::AppendString(const uint8_t* cur,
1192
+ const uint8_t* end) {
1193
+ String* str = parsing_.str;
1275
1194
  uint32_t bits;
1276
1195
  uint8_t decoded[3];
1277
- switch (static_cast<binary_state>(p->binary)) {
1278
- case NOT_BINARY:
1279
- append_bytes(str, cur, static_cast<size_t>(end - cur));
1196
+ switch (binary_) {
1197
+ case BinaryState::kNotBinary:
1198
+ str->AppendBytes(cur, static_cast<size_t>(end - cur));
1280
1199
  return GRPC_ERROR_NONE;
1281
- case BINARY_BEGIN:
1200
+ case BinaryState::kBinaryBegin:
1282
1201
  if (cur == end) {
1283
- p->binary = BINARY_BEGIN;
1202
+ binary_ = BinaryState::kBinaryBegin;
1284
1203
  return GRPC_ERROR_NONE;
1285
1204
  }
1286
1205
  if (*cur == 0) {
1287
1206
  /* 'true-binary' case */
1288
1207
  ++cur;
1289
- p->binary = NOT_BINARY;
1208
+ binary_ = BinaryState::kNotBinary;
1290
1209
  GRPC_STATS_INC_HPACK_RECV_BINARY();
1291
- append_bytes(str, cur, static_cast<size_t>(end - cur));
1210
+ str->AppendBytes(cur, static_cast<size_t>(end - cur));
1292
1211
  return GRPC_ERROR_NONE;
1293
1212
  }
1294
1213
  GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64();
1295
- /* fallthrough */
1296
1214
  b64_byte0:
1297
- case B64_BYTE0:
1215
+ ABSL_FALLTHROUGH_INTENDED;
1216
+ case BinaryState::kBase64Byte0:
1298
1217
  if (cur == end) {
1299
- p->binary = B64_BYTE0;
1218
+ binary_ = BinaryState::kBase64Byte0;
1300
1219
  return GRPC_ERROR_NONE;
1301
1220
  }
1302
- bits = inverse_base64[*cur];
1221
+ bits = kBase64InverseTable.table[*cur];
1303
1222
  ++cur;
1304
1223
  if (bits == 255) {
1305
1224
  return parse_error(
1306
- p, cur, end,
1225
+ cur, end,
1307
1226
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1308
1227
  } else if (bits == 64) {
1309
1228
  goto b64_byte0;
1310
1229
  }
1311
- p->base64_buffer = bits << 18;
1312
- /* fallthrough */
1230
+ base64_buffer_ = bits << 18;
1313
1231
  b64_byte1:
1314
- case B64_BYTE1:
1232
+ ABSL_FALLTHROUGH_INTENDED;
1233
+ case BinaryState::kBase64Byte1:
1315
1234
  if (cur == end) {
1316
- p->binary = B64_BYTE1;
1235
+ binary_ = BinaryState::kBase64Byte1;
1317
1236
  return GRPC_ERROR_NONE;
1318
1237
  }
1319
- bits = inverse_base64[*cur];
1238
+ bits = kBase64InverseTable.table[*cur];
1320
1239
  ++cur;
1321
1240
  if (bits == 255) {
1322
1241
  return parse_error(
1323
- p, cur, end,
1242
+ cur, end,
1324
1243
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1325
1244
  } else if (bits == 64) {
1326
1245
  goto b64_byte1;
1327
1246
  }
1328
- p->base64_buffer |= bits << 12;
1329
- /* fallthrough */
1247
+ base64_buffer_ |= bits << 12;
1330
1248
  b64_byte2:
1331
- case B64_BYTE2:
1249
+ ABSL_FALLTHROUGH_INTENDED;
1250
+ case BinaryState::kBase64Byte2:
1332
1251
  if (cur == end) {
1333
- p->binary = B64_BYTE2;
1252
+ binary_ = BinaryState::kBase64Byte2;
1334
1253
  return GRPC_ERROR_NONE;
1335
1254
  }
1336
- bits = inverse_base64[*cur];
1255
+ bits = kBase64InverseTable.table[*cur];
1337
1256
  ++cur;
1338
1257
  if (bits == 255) {
1339
1258
  return parse_error(
1340
- p, cur, end,
1259
+ cur, end,
1341
1260
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1342
1261
  } else if (bits == 64) {
1343
1262
  goto b64_byte2;
1344
1263
  }
1345
- p->base64_buffer |= bits << 6;
1346
- /* fallthrough */
1264
+ base64_buffer_ |= bits << 6;
1347
1265
  b64_byte3:
1348
- case B64_BYTE3:
1266
+ ABSL_FALLTHROUGH_INTENDED;
1267
+ case BinaryState::kBase64Byte3:
1349
1268
  if (cur == end) {
1350
- p->binary = B64_BYTE3;
1269
+ binary_ = BinaryState::kBase64Byte3;
1351
1270
  return GRPC_ERROR_NONE;
1352
1271
  }
1353
- bits = inverse_base64[*cur];
1272
+ bits = kBase64InverseTable.table[*cur];
1354
1273
  ++cur;
1355
1274
  if (bits == 255) {
1356
1275
  return parse_error(
1357
- p, cur, end,
1276
+ cur, end,
1358
1277
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1359
1278
  } else if (bits == 64) {
1360
1279
  goto b64_byte3;
1361
1280
  }
1362
- p->base64_buffer |= bits;
1363
- bits = p->base64_buffer;
1281
+ base64_buffer_ |= bits;
1282
+ bits = base64_buffer_;
1364
1283
  decoded[0] = static_cast<uint8_t>(bits >> 16);
1365
1284
  decoded[1] = static_cast<uint8_t>(bits >> 8);
1366
1285
  decoded[2] = static_cast<uint8_t>(bits);
1367
- append_bytes(str, decoded, 3);
1286
+ str->AppendBytes(decoded, 3);
1368
1287
  goto b64_byte0;
1369
1288
  }
1370
1289
  GPR_UNREACHABLE_CODE(return parse_error(
1371
- p, cur, end,
1290
+ cur, end,
1372
1291
  GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here")));
1373
1292
  }
1374
1293
 
1375
- static grpc_error* finish_str(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1376
- const uint8_t* end) {
1294
+ grpc_error_handle HPackParser::finish_str(const uint8_t* cur,
1295
+ const uint8_t* end) {
1377
1296
  uint8_t decoded[2];
1378
1297
  uint32_t bits;
1379
- grpc_chttp2_hpack_parser_string* str = p->parsing.str;
1380
- switch (static_cast<binary_state>(p->binary)) {
1381
- case NOT_BINARY:
1298
+ String* str = parsing_.str;
1299
+ switch (binary_) {
1300
+ case BinaryState::kNotBinary:
1382
1301
  break;
1383
- case BINARY_BEGIN:
1302
+ case BinaryState::kBinaryBegin:
1384
1303
  break;
1385
- case B64_BYTE0:
1304
+ case BinaryState::kBase64Byte0:
1386
1305
  break;
1387
- case B64_BYTE1:
1388
- return parse_error(p, cur, end,
1306
+ case BinaryState::kBase64Byte1:
1307
+ return parse_error(cur, end,
1389
1308
  GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1390
1309
  "illegal base64 encoding")); /* illegal encoding */
1391
- case B64_BYTE2:
1392
- bits = p->base64_buffer;
1310
+ case BinaryState::kBase64Byte2:
1311
+ bits = base64_buffer_;
1393
1312
  if (bits & 0xffff) {
1394
- grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1313
+ grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1395
1314
  absl::StrFormat("trailing bits in base64 encoding: 0x%04x",
1396
1315
  bits & 0xffff)
1397
1316
  .c_str());
1398
- return parse_error(p, cur, end, err);
1317
+ return parse_error(cur, end, err);
1399
1318
  }
1400
1319
  decoded[0] = static_cast<uint8_t>(bits >> 16);
1401
- append_bytes(str, decoded, 1);
1320
+ str->AppendBytes(decoded, 1);
1402
1321
  break;
1403
- case B64_BYTE3:
1404
- bits = p->base64_buffer;
1322
+ case BinaryState::kBase64Byte3:
1323
+ bits = base64_buffer_;
1405
1324
  if (bits & 0xff) {
1406
- grpc_error* err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1325
+ grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1407
1326
  absl::StrFormat("trailing bits in base64 encoding: 0x%02x",
1408
1327
  bits & 0xff)
1409
1328
  .c_str());
1410
- return parse_error(p, cur, end, err);
1329
+ return parse_error(cur, end, err);
1411
1330
  }
1412
1331
  decoded[0] = static_cast<uint8_t>(bits >> 16);
1413
1332
  decoded[1] = static_cast<uint8_t>(bits >> 8);
1414
- append_bytes(str, decoded, 2);
1333
+ str->AppendBytes(decoded, 2);
1415
1334
  break;
1416
1335
  }
1417
1336
  return GRPC_ERROR_NONE;
1418
1337
  }
1419
1338
 
1420
1339
  /* decode a nibble from a huffman encoded stream */
1421
- static grpc_error* huff_nibble(grpc_chttp2_hpack_parser* p, uint8_t nibble) {
1422
- int16_t emit = emit_sub_tbl[16 * emit_tbl[p->huff_state] + nibble];
1423
- int16_t next = next_sub_tbl[16 * next_tbl[p->huff_state] + nibble];
1340
+ grpc_error_handle HPackParser::AppendHuffNibble(uint8_t nibble) {
1341
+ int16_t emit = emit_sub_tbl[16 * emit_tbl[huff_state_] + nibble];
1342
+ int16_t next = next_sub_tbl[16 * next_tbl[huff_state_] + nibble];
1424
1343
  if (emit != -1) {
1425
1344
  if (emit >= 0 && emit < 256) {
1426
1345
  uint8_t c = static_cast<uint8_t>(emit);
1427
- grpc_error* err = append_string(p, &c, (&c) + 1);
1346
+ grpc_error_handle err = AppendString(&c, (&c) + 1);
1428
1347
  if (err != GRPC_ERROR_NONE) return err;
1429
1348
  } else {
1430
1349
  assert(emit == 256);
1431
1350
  }
1432
1351
  }
1433
- p->huff_state = next;
1352
+ huff_state_ = next;
1434
1353
  return GRPC_ERROR_NONE;
1435
1354
  }
1436
1355
 
1437
1356
  /* decode full bytes from a huffman encoded stream */
1438
- static grpc_error* add_huff_bytes(grpc_chttp2_hpack_parser* p,
1439
- const uint8_t* cur, const uint8_t* end) {
1357
+ grpc_error_handle HPackParser::AppendHuffBytes(const uint8_t* cur,
1358
+ const uint8_t* end) {
1440
1359
  for (; cur != end; ++cur) {
1441
- grpc_error* err = huff_nibble(p, *cur >> 4);
1442
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1443
- err = huff_nibble(p, *cur & 0xf);
1444
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1360
+ grpc_error_handle err = AppendHuffNibble(*cur >> 4);
1361
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1362
+ err = AppendHuffNibble(*cur & 0xf);
1363
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1445
1364
  }
1446
1365
  return GRPC_ERROR_NONE;
1447
1366
  }
1448
1367
 
1449
1368
  /* decode some string bytes based on the current decoding mode
1450
1369
  (huffman or not) */
1451
- static grpc_error* add_str_bytes(grpc_chttp2_hpack_parser* p,
1452
- const uint8_t* cur, const uint8_t* end) {
1453
- if (p->huff) {
1454
- return add_huff_bytes(p, cur, end);
1370
+ grpc_error_handle HPackParser::AppendStrBytes(const uint8_t* cur,
1371
+ const uint8_t* end) {
1372
+ if (huff_) {
1373
+ return AppendHuffBytes(cur, end);
1455
1374
  } else {
1456
- return append_string(p, cur, end);
1375
+ return AppendString(cur, end);
1457
1376
  }
1458
1377
  }
1459
1378
 
1460
1379
  /* parse a string - tries to do large chunks at a time */
1461
- static grpc_error* parse_string(grpc_chttp2_hpack_parser* p, const uint8_t* cur,
1462
- const uint8_t* end) {
1463
- size_t remaining = p->strlen - p->strgot;
1380
+ grpc_error_handle HPackParser::parse_string(const uint8_t* cur,
1381
+ const uint8_t* end) {
1382
+ size_t remaining = strlen_ - strgot_;
1464
1383
  size_t given = static_cast<size_t>(end - cur);
1465
1384
  if (remaining <= given) {
1466
- grpc_error* err = add_str_bytes(p, cur, cur + remaining);
1467
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1468
- err = finish_str(p, cur + remaining, end);
1469
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1470
- return parse_next(p, cur + remaining, end);
1385
+ grpc_error_handle err = AppendStrBytes(cur, cur + remaining);
1386
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1387
+ err = finish_str(cur + remaining, end);
1388
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1389
+ return parse_next(cur + remaining, end);
1471
1390
  } else {
1472
- grpc_error* err = add_str_bytes(p, cur, cur + given);
1473
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1474
- GPR_ASSERT(given <= UINT32_MAX - p->strgot);
1475
- p->strgot += static_cast<uint32_t>(given);
1476
- p->state = parse_string;
1391
+ grpc_error_handle err = AppendStrBytes(cur, cur + given);
1392
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1393
+ GPR_ASSERT(given <= UINT32_MAX - strgot_);
1394
+ strgot_ += static_cast<uint32_t>(given);
1395
+ state_ = &HPackParser::parse_string;
1477
1396
  return GRPC_ERROR_NONE;
1478
1397
  }
1479
1398
  }
1480
1399
 
1481
1400
  /* begin parsing a string - performs setup, calls parse_string */
1482
- static grpc_error* begin_parse_string(grpc_chttp2_hpack_parser* p,
1483
- const uint8_t* cur, const uint8_t* end,
1484
- uint8_t binary,
1485
- grpc_chttp2_hpack_parser_string* str) {
1486
- if (!p->huff && binary == NOT_BINARY &&
1487
- static_cast<uint32_t>(end - cur) >= p->strlen &&
1488
- p->current_slice_refcount != nullptr) {
1401
+ grpc_error_handle HPackParser::begin_parse_string(const uint8_t* cur,
1402
+ const uint8_t* end,
1403
+ BinaryState binary,
1404
+ HPackParser::String* str) {
1405
+ if (!huff_ && binary == BinaryState::kNotBinary &&
1406
+ static_cast<uint32_t>(end - cur) >= strlen_ &&
1407
+ current_slice_refcount_ != nullptr) {
1489
1408
  GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED();
1490
- str->copied = false;
1491
- str->data.referenced.refcount = p->current_slice_refcount;
1492
- str->data.referenced.data.refcounted.bytes = const_cast<uint8_t*>(cur);
1493
- str->data.referenced.data.refcounted.length = p->strlen;
1494
- grpc_slice_ref_internal(str->data.referenced);
1495
- return parse_next(p, cur + p->strlen, end);
1409
+ str->copied_ = false;
1410
+ str->data_.referenced.refcount = current_slice_refcount_;
1411
+ str->data_.referenced.data.refcounted.bytes = const_cast<uint8_t*>(cur);
1412
+ str->data_.referenced.data.refcounted.length = strlen_;
1413
+ grpc_slice_ref_internal(str->data_.referenced);
1414
+ return parse_next(cur + strlen_, end);
1496
1415
  }
1497
- p->strgot = 0;
1498
- str->copied = true;
1499
- str->data.copied.length = 0;
1500
- p->parsing.str = str;
1501
- p->huff_state = 0;
1502
- p->binary = binary;
1503
- switch (p->binary) {
1504
- case NOT_BINARY:
1505
- if (p->huff) {
1416
+ strgot_ = 0;
1417
+ str->copied_ = true;
1418
+ str->data_.copied.length = 0;
1419
+ parsing_.str = str;
1420
+ huff_state_ = 0;
1421
+ binary_ = binary;
1422
+ switch (binary_) {
1423
+ case BinaryState::kNotBinary:
1424
+ if (huff_) {
1506
1425
  GRPC_STATS_INC_HPACK_RECV_HUFFMAN();
1507
1426
  } else {
1508
1427
  GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED();
1509
1428
  }
1510
1429
  break;
1511
- case BINARY_BEGIN:
1430
+ case BinaryState::kBinaryBegin:
1512
1431
  /* stats incremented later: don't know true binary or not */
1513
1432
  break;
1514
1433
  default:
1515
1434
  abort();
1516
1435
  }
1517
- return parse_string(p, cur, end);
1436
+ return parse_string(cur, end);
1518
1437
  }
1519
1438
 
1520
1439
  /* parse the key string */
1521
- static grpc_error* parse_key_string(grpc_chttp2_hpack_parser* p,
1522
- const uint8_t* cur, const uint8_t* end) {
1523
- return begin_parse_string(p, cur, end, NOT_BINARY, &p->key);
1440
+ grpc_error_handle HPackParser::parse_key_string(const uint8_t* cur,
1441
+ const uint8_t* end) {
1442
+ return begin_parse_string(cur, end, BinaryState::kNotBinary, &key_);
1524
1443
  }
1525
1444
 
1526
1445
  /* check if a key represents a binary header or not */
1527
1446
 
1528
- static bool is_binary_literal_header(grpc_chttp2_hpack_parser* p) {
1447
+ bool HPackParser::IsBinaryLiteralHeader() {
1529
1448
  /* We know that either argument here is a reference counter slice.
1530
1449
  * 1. If it is a grpc_core::StaticSlice, the refcount is set to kNoopRefcount.
1531
- * 2. If it's p->key.data.referenced, then p->key.copied was set to false,
1450
+ * 2. If it's key_.data.referenced, then key_.copied was set to false,
1532
1451
  * which occurs in begin_parse_string() - where the refcount is set to
1533
- * p->current_slice_refcount, which is not null. */
1452
+ * current_slice_refcount_, which is not null. */
1534
1453
  return grpc_is_refcounted_slice_binary_header(
1535
- p->key.copied ? grpc_core::ExternallyManagedSlice(
1536
- p->key.data.copied.str, p->key.data.copied.length)
1537
- : p->key.data.referenced);
1454
+ key_.copied_ ? grpc_core::ExternallyManagedSlice(key_.data_.copied.str,
1455
+ key_.data_.copied.length)
1456
+ : key_.data_.referenced);
1538
1457
  }
1539
1458
 
1540
1459
  /* Cache the metadata for the given index during initial parsing. This avoids a
1541
1460
  pointless recomputation of the metadata when finishing a header. We read the
1542
1461
  cached value in get_precomputed_md_for_idx(). */
1543
- static void set_precomputed_md_idx(grpc_chttp2_hpack_parser* p,
1544
- grpc_mdelem md) {
1545
- GPR_DEBUG_ASSERT(p->md_for_index.payload == 0);
1546
- GPR_DEBUG_ASSERT(p->precomputed_md_index == -1);
1547
- p->md_for_index = md;
1462
+ void HPackParser::SetPrecomputedMDIndex(grpc_mdelem md) {
1463
+ GPR_DEBUG_ASSERT(md_for_index_.payload == 0);
1464
+ GPR_DEBUG_ASSERT(precomputed_md_index_ == -1);
1465
+ md_for_index_ = md;
1548
1466
  #ifndef NDEBUG
1549
- p->precomputed_md_index = p->index;
1467
+ precomputed_md_index_ = index_;
1550
1468
  #endif
1551
1469
  }
1552
1470
 
@@ -1554,11 +1472,10 @@ static void set_precomputed_md_idx(grpc_chttp2_hpack_parser* p,
1554
1472
  is a binary indexed header during string parsing. We'll need to revisit this
1555
1473
  metadata when we're done parsing, so we cache the metadata for this index
1556
1474
  here using set_precomputed_md_idx(). */
1557
- static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p,
1558
- bool* is) {
1559
- grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&p->table, p->index);
1475
+ grpc_error_handle HPackParser::IsBinaryIndexedHeader(bool* is) {
1476
+ grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&table_, index_);
1560
1477
  if (GPR_UNLIKELY(GRPC_MDISNULL(elem))) {
1561
- return on_invalid_hpack_idx(p);
1478
+ return InvalidHPackIndexError();
1562
1479
  }
1563
1480
  /* We know that GRPC_MDKEY(elem) points to a reference counted slice since:
1564
1481
  * 1. elem was a result of grpc_chttp2_hptbl_lookup
@@ -1569,107 +1486,111 @@ static grpc_error* is_binary_indexed_header(grpc_chttp2_hpack_parser* p,
1569
1486
  * interned.
1570
1487
  * 4. Both static and interned element slices have non-null refcounts. */
1571
1488
  *is = grpc_is_refcounted_slice_binary_header(GRPC_MDKEY(elem));
1572
- set_precomputed_md_idx(p, elem);
1489
+ SetPrecomputedMDIndex(elem);
1573
1490
  return GRPC_ERROR_NONE;
1574
1491
  }
1575
1492
 
1576
1493
  /* parse the value string */
1577
- static grpc_error* parse_value_string(grpc_chttp2_hpack_parser* p,
1578
- const uint8_t* cur, const uint8_t* end,
1579
- bool is_binary) {
1580
- return begin_parse_string(p, cur, end, is_binary ? BINARY_BEGIN : NOT_BINARY,
1581
- &p->value);
1494
+ grpc_error_handle HPackParser::parse_value_string(const uint8_t* cur,
1495
+ const uint8_t* end,
1496
+ bool is_binary) {
1497
+ return begin_parse_string(
1498
+ cur, end, is_binary ? BinaryState::kBinaryBegin : BinaryState::kNotBinary,
1499
+ &value_);
1582
1500
  }
1583
1501
 
1584
- static grpc_error* parse_value_string_with_indexed_key(
1585
- grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) {
1502
+ grpc_error_handle HPackParser::parse_value_string_with_indexed_key(
1503
+ const uint8_t* cur, const uint8_t* end) {
1586
1504
  bool is_binary = false;
1587
- grpc_error* err = is_binary_indexed_header(p, &is_binary);
1588
- if (err != GRPC_ERROR_NONE) return parse_error(p, cur, end, err);
1589
- return parse_value_string(p, cur, end, is_binary);
1590
- }
1591
-
1592
- static grpc_error* parse_value_string_with_literal_key(
1593
- grpc_chttp2_hpack_parser* p, const uint8_t* cur, const uint8_t* end) {
1594
- return parse_value_string(p, cur, end, is_binary_literal_header(p));
1505
+ grpc_error_handle err = IsBinaryIndexedHeader(&is_binary);
1506
+ if (err != GRPC_ERROR_NONE) return parse_error(cur, end, err);
1507
+ return parse_value_string(cur, end, is_binary);
1595
1508
  }
1596
1509
 
1597
- /* "Uninitialized" header parser to save us a branch in on_hdr(). */
1598
- static grpc_error* on_header_uninitialized(void* /*user_data*/,
1599
- grpc_mdelem md) {
1600
- GRPC_MDELEM_UNREF(md);
1601
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING("on_header callback not set");
1510
+ grpc_error_handle HPackParser::parse_value_string_with_literal_key(
1511
+ const uint8_t* cur, const uint8_t* end) {
1512
+ return parse_value_string(cur, end, IsBinaryLiteralHeader());
1602
1513
  }
1603
1514
 
1604
1515
  /* PUBLIC INTERFACE */
1605
1516
 
1606
- void grpc_chttp2_hpack_parser_init(grpc_chttp2_hpack_parser* p) {
1607
- p->on_header = on_header_uninitialized;
1608
- p->on_header_user_data = nullptr;
1609
- p->state = parse_begin;
1610
- p->key.data.referenced = grpc_empty_slice();
1611
- p->key.data.copied.str = nullptr;
1612
- p->key.data.copied.capacity = 0;
1613
- p->key.data.copied.length = 0;
1614
- p->value.data.referenced = grpc_empty_slice();
1615
- p->value.data.copied.str = nullptr;
1616
- p->value.data.copied.capacity = 0;
1617
- p->value.data.copied.length = 0;
1517
+ HPackParser::HPackParser() {
1518
+ state_ = &HPackParser::parse_begin;
1519
+ key_.data_.referenced = grpc_empty_slice();
1520
+ key_.data_.copied.str = nullptr;
1521
+ key_.data_.copied.capacity = 0;
1522
+ key_.data_.copied.length = 0;
1523
+ value_.data_.referenced = grpc_empty_slice();
1524
+ value_.data_.copied.str = nullptr;
1525
+ value_.data_.copied.capacity = 0;
1526
+ value_.data_.copied.length = 0;
1618
1527
  /* Cached metadata for the current index the parser is handling. This is set
1619
1528
  to 0 initially, invalidated when the index changes, and invalidated when it
1620
1529
  is read (by get_precomputed_md_for_idx()). It is set during string parsing,
1621
1530
  by set_precomputed_md_idx() - which is called by parse_value_string().
1622
1531
  The goal here is to avoid recomputing the metadata for the index when
1623
1532
  finishing with a header as well as the initial parse. */
1624
- p->md_for_index.payload = 0;
1533
+ md_for_index_.payload = 0;
1625
1534
  #ifndef NDEBUG
1626
1535
  /* In debug mode, this ensures that the cached metadata we're reading is in
1627
1536
  * fact correct for the index we are examining. */
1628
- p->precomputed_md_index = -1;
1537
+ precomputed_md_index_ = -1;
1629
1538
  #endif
1630
- p->dynamic_table_update_allowed = 2;
1631
- p->last_error = GRPC_ERROR_NONE;
1539
+ dynamic_table_updates_allowed_ = 2;
1540
+ last_error_ = GRPC_ERROR_NONE;
1632
1541
  }
1633
1542
 
1634
- void grpc_chttp2_hpack_parser_set_has_priority(grpc_chttp2_hpack_parser* p) {
1635
- p->after_prioritization = p->state;
1636
- p->state = parse_stream_dep0;
1543
+ void HPackParser::BeginFrame(Sink sink, Boundary boundary, Priority priority) {
1544
+ sink_ = std::move(sink);
1545
+ boundary_ = boundary;
1546
+ switch (priority) {
1547
+ case Priority::Included:
1548
+ after_prioritization_ = state_;
1549
+ state_ = &HPackParser::parse_stream_dep0;
1550
+ break;
1551
+ case Priority::None:
1552
+ break;
1553
+ }
1637
1554
  }
1638
1555
 
1639
- void grpc_chttp2_hpack_parser_destroy(grpc_chttp2_hpack_parser* p) {
1640
- grpc_chttp2_hptbl_destroy(&p->table);
1641
- GRPC_ERROR_UNREF(p->last_error);
1642
- grpc_slice_unref_internal(p->key.data.referenced);
1643
- grpc_slice_unref_internal(p->value.data.referenced);
1644
- gpr_free(p->key.data.copied.str);
1645
- gpr_free(p->value.data.copied.str);
1556
+ HPackParser::~HPackParser() {
1557
+ grpc_chttp2_hptbl_destroy(&table_);
1558
+ GRPC_ERROR_UNREF(last_error_);
1559
+ grpc_slice_unref_internal(key_.data_.referenced);
1560
+ grpc_slice_unref_internal(value_.data_.referenced);
1561
+ gpr_free(key_.data_.copied.str);
1562
+ gpr_free(value_.data_.copied.str);
1646
1563
  }
1647
1564
 
1648
- grpc_error* grpc_chttp2_hpack_parser_parse(grpc_chttp2_hpack_parser* p,
1649
- const grpc_slice& slice) {
1565
+ grpc_error_handle HPackParser::Parse(const grpc_slice& slice) {
1650
1566
  /* max number of bytes to parse at a time... limits call stack depth on
1651
1567
  * compilers without TCO */
1652
1568
  #define MAX_PARSE_LENGTH 1024
1653
- p->current_slice_refcount = slice.refcount;
1569
+ current_slice_refcount_ = slice.refcount;
1654
1570
  const uint8_t* start = GRPC_SLICE_START_PTR(slice);
1655
1571
  const uint8_t* end = GRPC_SLICE_END_PTR(slice);
1656
- grpc_error* error = GRPC_ERROR_NONE;
1572
+ grpc_error_handle error = GRPC_ERROR_NONE;
1657
1573
  while (start != end && error == GRPC_ERROR_NONE) {
1658
1574
  const uint8_t* target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start);
1659
- error = p->state(p, start, target);
1575
+ error = (this->*state_)(start, target);
1660
1576
  start = target;
1661
1577
  }
1662
- p->current_slice_refcount = nullptr;
1578
+ current_slice_refcount_ = nullptr;
1663
1579
  return error;
1664
1580
  }
1665
1581
 
1582
+ } // namespace grpc_core
1583
+
1584
+ // TODO(ctiller): this serves as an eviction notice for the remainder of this
1585
+ // file... it belongs elsewhere!
1586
+
1666
1587
  typedef void (*maybe_complete_func_type)(grpc_chttp2_transport* t,
1667
1588
  grpc_chttp2_stream* s);
1668
1589
  static const maybe_complete_func_type maybe_complete_funcs[] = {
1669
1590
  grpc_chttp2_maybe_complete_recv_initial_metadata,
1670
1591
  grpc_chttp2_maybe_complete_recv_trailing_metadata};
1671
1592
 
1672
- static void force_client_rst_stream(void* sp, grpc_error* /*error*/) {
1593
+ static void force_client_rst_stream(void* sp, grpc_error_handle /*error*/) {
1673
1594
  grpc_chttp2_stream* s = static_cast<grpc_chttp2_stream*>(sp);
1674
1595
  grpc_chttp2_transport* t = s->t;
1675
1596
  if (!s->write_closed) {
@@ -1699,30 +1620,29 @@ static void parse_stream_compression_md(grpc_chttp2_transport* /*t*/,
1699
1620
  }
1700
1621
  }
1701
1622
 
1702
- grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser,
1703
- grpc_chttp2_transport* t,
1704
- grpc_chttp2_stream* s,
1705
- const grpc_slice& slice,
1706
- int is_last) {
1623
+ grpc_error_handle grpc_chttp2_header_parser_parse(void* hpack_parser,
1624
+ grpc_chttp2_transport* t,
1625
+ grpc_chttp2_stream* s,
1626
+ const grpc_slice& slice,
1627
+ int is_last) {
1707
1628
  GPR_TIMER_SCOPE("grpc_chttp2_header_parser_parse", 0);
1708
- grpc_chttp2_hpack_parser* parser =
1709
- static_cast<grpc_chttp2_hpack_parser*>(hpack_parser);
1629
+ auto* parser = static_cast<grpc_core::HPackParser*>(hpack_parser);
1710
1630
  if (s != nullptr) {
1711
1631
  s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice);
1712
1632
  }
1713
- grpc_error* error = grpc_chttp2_hpack_parser_parse(parser, slice);
1633
+ grpc_error_handle error = parser->Parse(slice);
1714
1634
  if (error != GRPC_ERROR_NONE) {
1715
1635
  return error;
1716
1636
  }
1717
1637
  if (is_last) {
1718
- if (parser->is_boundary && parser->state != parse_begin) {
1638
+ if (parser->is_boundary() && !parser->is_in_begin_state()) {
1719
1639
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1720
1640
  "end of header frame not aligned with a hpack record boundary");
1721
1641
  }
1722
1642
  /* need to check for null stream: this can occur if we receive an invalid
1723
1643
  stream id on a header */
1724
1644
  if (s != nullptr) {
1725
- if (parser->is_boundary) {
1645
+ if (parser->is_boundary()) {
1726
1646
  if (s->header_frames_received == GPR_ARRAY_SIZE(s->metadata_buffer)) {
1727
1647
  return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1728
1648
  "Too many trailer frames");
@@ -1737,7 +1657,7 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser,
1737
1657
  maybe_complete_funcs[s->header_frames_received](t, s);
1738
1658
  s->header_frames_received++;
1739
1659
  }
1740
- if (parser->is_eof) {
1660
+ if (parser->is_eof()) {
1741
1661
  if (t->is_client && !s->write_closed) {
1742
1662
  /* server eof ==> complete closure; we may need to forcefully close
1743
1663
  the stream. Wait until the combiner lock is ready to be released
@@ -1751,11 +1671,7 @@ grpc_error* grpc_chttp2_header_parser_parse(void* hpack_parser,
1751
1671
  grpc_chttp2_mark_stream_closed(t, s, true, false, GRPC_ERROR_NONE);
1752
1672
  }
1753
1673
  }
1754
- parser->on_header = on_header_uninitialized;
1755
- parser->on_header_user_data = nullptr;
1756
- parser->is_boundary = 0xde;
1757
- parser->is_eof = 0xde;
1758
- parser->dynamic_table_update_allowed = 2;
1674
+ parser->FinishFrame();
1759
1675
  }
1760
1676
  return GRPC_ERROR_NONE;
1761
1677
  }