grpc 1.40.0 → 1.41.0

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

Potentially problematic release.


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

Files changed (827) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +27 -36
  3. data/include/grpc/byte_buffer.h +1 -1
  4. data/include/grpc/byte_buffer_reader.h +1 -1
  5. data/include/grpc/event_engine/endpoint_config.h +6 -11
  6. data/include/grpc/event_engine/event_engine.h +63 -58
  7. data/include/grpc/event_engine/port.h +1 -3
  8. data/include/grpc/event_engine/slice_allocator.h +6 -1
  9. data/include/grpc/fork.h +1 -1
  10. data/include/grpc/grpc.h +10 -4
  11. data/include/grpc/grpc_posix.h +5 -2
  12. data/include/grpc/impl/codegen/atm.h +5 -3
  13. data/include/grpc/impl/codegen/atm_gcc_atomic.h +2 -0
  14. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  15. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  16. data/include/grpc/impl/codegen/byte_buffer.h +2 -0
  17. data/include/grpc/impl/codegen/byte_buffer_reader.h +2 -0
  18. data/include/grpc/impl/codegen/compression_types.h +2 -0
  19. data/include/grpc/impl/codegen/connectivity_state.h +2 -0
  20. data/include/grpc/impl/codegen/fork.h +2 -0
  21. data/include/grpc/impl/codegen/gpr_slice.h +2 -0
  22. data/include/grpc/impl/codegen/gpr_types.h +2 -0
  23. data/include/grpc/impl/codegen/grpc_types.h +4 -5
  24. data/include/grpc/impl/codegen/log.h +2 -0
  25. data/include/grpc/impl/codegen/port_platform.h +26 -22
  26. data/include/grpc/impl/codegen/propagation_bits.h +2 -0
  27. data/include/grpc/impl/codegen/slice.h +2 -0
  28. data/include/grpc/impl/codegen/status.h +2 -0
  29. data/include/grpc/impl/codegen/sync.h +8 -5
  30. data/include/grpc/impl/codegen/sync_abseil.h +2 -0
  31. data/include/grpc/impl/codegen/sync_custom.h +2 -0
  32. data/include/grpc/impl/codegen/sync_generic.h +3 -0
  33. data/include/grpc/impl/codegen/sync_posix.h +4 -2
  34. data/include/grpc/impl/codegen/sync_windows.h +2 -0
  35. data/include/grpc/slice.h +1 -1
  36. data/include/grpc/status.h +1 -1
  37. data/include/grpc/support/atm.h +1 -1
  38. data/include/grpc/support/atm_gcc_atomic.h +1 -1
  39. data/include/grpc/support/atm_gcc_sync.h +1 -1
  40. data/include/grpc/support/atm_windows.h +1 -1
  41. data/include/grpc/support/log.h +1 -1
  42. data/include/grpc/support/port_platform.h +1 -1
  43. data/include/grpc/support/sync.h +1 -1
  44. data/include/grpc/support/sync_abseil.h +1 -1
  45. data/include/grpc/support/sync_custom.h +1 -1
  46. data/include/grpc/support/sync_generic.h +1 -1
  47. data/include/grpc/support/sync_posix.h +1 -1
  48. data/include/grpc/support/sync_windows.h +1 -1
  49. data/include/grpc/support/time.h +2 -2
  50. data/src/core/ext/filters/census/grpc_context.cc +1 -0
  51. data/src/core/ext/filters/client_channel/backend_metric.cc +0 -1
  52. data/src/core/ext/filters/client_channel/backup_poller.h +1 -0
  53. data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -2
  54. data/src/core/ext/filters/client_channel/client_channel.cc +24 -52
  55. data/src/core/ext/filters/client_channel/client_channel.h +3 -3
  56. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +6 -5
  57. data/src/core/ext/filters/client_channel/client_channel_channelz.h +1 -1
  58. data/src/core/ext/filters/client_channel/client_channel_factory.cc +1 -0
  59. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +8 -1
  60. data/src/core/ext/filters/client_channel/config_selector.cc +1 -0
  61. data/src/core/ext/filters/client_channel/health/health_check_client.cc +7 -6
  62. data/src/core/ext/filters/client_channel/health/health_check_client.h +4 -3
  63. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +8 -7
  64. data/src/core/ext/filters/client_channel/http_connect_handshaker.h +10 -2
  65. data/src/core/ext/filters/client_channel/lb_policy/child_policy_handler.cc +2 -2
  66. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +2 -8
  67. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +1 -2
  68. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +2 -2
  69. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +2 -2
  70. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -1
  71. data/src/core/ext/filters/client_channel/lb_policy/priority/priority.cc +14 -23
  72. data/src/core/ext/filters/client_channel/lb_policy/ring_hash/ring_hash.cc +1 -0
  73. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +2 -2
  74. data/src/core/ext/filters/client_channel/lb_policy/weighted_target/weighted_target.cc +2 -8
  75. data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +15 -18
  76. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_impl.cc +10 -7
  77. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_manager.cc +2 -8
  78. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_cluster_resolver.cc +2 -3
  79. data/src/core/ext/filters/client_channel/lb_policy.h +11 -44
  80. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +4 -7
  81. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +2 -10
  82. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +1 -0
  83. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.cc +4 -3
  84. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +6 -5
  85. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +14 -19
  86. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +1 -0
  87. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -2
  88. data/src/core/ext/filters/client_channel/resolver/google_c2p/google_c2p_resolver.cc +5 -5
  89. data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +5 -8
  90. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +2 -3
  91. data/src/core/ext/filters/client_idle/client_idle_filter.cc +36 -30
  92. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +8 -6
  93. data/src/core/ext/filters/fault_injection/service_config_parser.cc +6 -13
  94. data/src/core/ext/filters/http/client/http_client_filter.cc +3 -2
  95. data/src/core/ext/filters/http/client_authority_filter.cc +2 -1
  96. data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +2 -1
  97. data/src/core/ext/filters/http/message_compress/message_decompress_filter.cc +7 -8
  98. data/src/core/ext/filters/http/server/http_server_filter.cc +5 -3
  99. data/src/core/ext/filters/message_size/message_size_filter.cc +9 -13
  100. data/src/core/ext/transport/chttp2/alpn/alpn.cc +2 -1
  101. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +29 -12
  102. data/src/core/ext/transport/chttp2/client/chttp2_connector.h +2 -0
  103. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +2 -3
  104. data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.cc +10 -6
  105. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +2 -3
  106. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +60 -37
  107. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.cc +0 -1
  108. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +12 -6
  109. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +5 -9
  110. data/src/core/ext/transport/chttp2/transport/bin_decoder.cc +3 -1
  111. data/src/core/ext/transport/chttp2/transport/bin_decoder.h +2 -1
  112. data/src/core/ext/transport/chttp2/transport/bin_encoder.cc +1 -0
  113. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.cc +4 -3
  114. data/src/core/ext/transport/chttp2/transport/chttp2_slice_allocator.h +2 -2
  115. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -30
  116. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +4 -1
  117. data/src/core/ext/transport/chttp2/transport/context_list.h +1 -2
  118. data/src/core/ext/transport/chttp2/transport/flow_control.cc +39 -23
  119. data/src/core/ext/transport/chttp2/transport/flow_control.h +9 -3
  120. data/src/core/ext/transport/chttp2/transport/frame_data.cc +7 -7
  121. data/src/core/ext/transport/chttp2/transport/frame_data.h +1 -0
  122. data/src/core/ext/transport/chttp2/transport/frame_goaway.cc +4 -3
  123. data/src/core/ext/transport/chttp2/transport/frame_goaway.h +1 -0
  124. data/src/core/ext/transport/chttp2/transport/frame_ping.cc +4 -4
  125. data/src/core/ext/transport/chttp2/transport/frame_ping.h +1 -0
  126. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.cc +3 -5
  127. data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +1 -0
  128. data/src/core/ext/transport/chttp2/transport/frame_settings.cc +36 -5
  129. data/src/core/ext/transport/chttp2/transport/frame_settings.h +1 -0
  130. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +12 -7
  131. data/src/core/ext/transport/chttp2/transport/frame_window_update.h +1 -0
  132. data/src/core/ext/transport/chttp2/transport/hpack_constants.h +41 -0
  133. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +272 -666
  134. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +236 -70
  135. data/src/core/ext/transport/chttp2/transport/hpack_encoder_index.h +107 -0
  136. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.cc +86 -0
  137. data/src/core/ext/transport/chttp2/transport/hpack_encoder_table.h +69 -0
  138. data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +776 -1037
  139. data/src/core/ext/transport/chttp2/transport/hpack_parser.h +48 -169
  140. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.cc +159 -0
  141. data/src/core/ext/transport/chttp2/transport/hpack_parser_table.h +130 -0
  142. data/src/core/ext/transport/chttp2/transport/hpack_utils.cc +46 -0
  143. data/src/core/ext/transport/chttp2/transport/hpack_utils.h +30 -0
  144. data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -2
  145. data/src/core/ext/transport/chttp2/transport/internal.h +2 -2
  146. data/src/core/ext/transport/chttp2/transport/parsing.cc +20 -30
  147. data/src/core/ext/transport/chttp2/transport/popularity_count.h +60 -0
  148. data/src/core/ext/transport/chttp2/transport/stream_lists.cc +2 -2
  149. data/src/core/ext/transport/chttp2/transport/varint.cc +7 -3
  150. data/src/core/ext/transport/chttp2/transport/varint.h +39 -28
  151. data/src/core/ext/transport/chttp2/transport/writing.cc +32 -28
  152. data/src/core/ext/transport/inproc/inproc_transport.cc +6 -4
  153. data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.c +96 -96
  154. data/src/core/ext/upb-generated/envoy/admin/v3/config_dump.upb.h +221 -89
  155. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.c +1 -1
  156. data/src/core/ext/upb-generated/envoy/annotations/deprecation.upb.h +1 -1
  157. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.c +3 -3
  158. data/src/core/ext/upb-generated/envoy/annotations/resource.upb.h +11 -5
  159. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.c +48 -48
  160. data/src/core/ext/upb-generated/envoy/config/accesslog/v3/accesslog.upb.h +151 -61
  161. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.c +99 -99
  162. data/src/core/ext/upb-generated/envoy/config/bootstrap/v3/bootstrap.upb.h +171 -69
  163. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.c +15 -15
  164. data/src/core/ext/upb-generated/envoy/config/cluster/v3/circuit_breaker.upb.h +31 -13
  165. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.c +126 -127
  166. data/src/core/ext/upb-generated/envoy/config/cluster/v3/cluster.upb.h +229 -101
  167. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.c +4 -4
  168. data/src/core/ext/upb-generated/envoy/config/cluster/v3/filter.upb.h +11 -5
  169. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.c +23 -23
  170. data/src/core/ext/upb-generated/envoy/config/cluster/v3/outlier_detection.upb.h +11 -5
  171. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.c +28 -28
  172. data/src/core/ext/upb-generated/envoy/config/core/v3/address.upb.h +71 -29
  173. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.c +4 -4
  174. data/src/core/ext/upb-generated/envoy/config/core/v3/backoff.upb.h +11 -5
  175. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.c +82 -82
  176. data/src/core/ext/upb-generated/envoy/config/core/v3/base.upb.h +201 -81
  177. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.c +24 -24
  178. data/src/core/ext/upb-generated/envoy/config/core/v3/config_source.upb.h +51 -21
  179. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.c +3 -3
  180. data/src/core/ext/upb-generated/envoy/config/core/v3/event_service_config.upb.h +11 -5
  181. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.c +9 -9
  182. data/src/core/ext/upb-generated/envoy/config/core/v3/extension.upb.h +21 -9
  183. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.c +62 -62
  184. data/src/core/ext/upb-generated/envoy/config/core/v3/grpc_service.upb.h +131 -53
  185. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.c +51 -51
  186. data/src/core/ext/upb-generated/envoy/config/core/v3/health_check.upb.h +81 -33
  187. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.c +5 -5
  188. data/src/core/ext/upb-generated/envoy/config/core/v3/http_uri.upb.h +11 -5
  189. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.c +62 -62
  190. data/src/core/ext/upb-generated/envoy/config/core/v3/protocol.upb.h +141 -57
  191. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.c +3 -3
  192. data/src/core/ext/upb-generated/envoy/config/core/v3/proxy_protocol.upb.h +11 -5
  193. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.c +7 -7
  194. data/src/core/ext/upb-generated/envoy/config/core/v3/resolver.upb.h +21 -9
  195. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.c +8 -8
  196. data/src/core/ext/upb-generated/envoy/config/core/v3/socket_option.upb.h +11 -5
  197. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.c +8 -8
  198. data/src/core/ext/upb-generated/envoy/config/core/v3/substitution_format_string.upb.h +11 -5
  199. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.c +4 -4
  200. data/src/core/ext/upb-generated/envoy/config/core/v3/udp_socket_config.upb.h +11 -5
  201. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.c +16 -16
  202. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint.upb.h +31 -13
  203. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.c +57 -22
  204. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/endpoint_components.upb.h +174 -17
  205. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.c +32 -32
  206. data/src/core/ext/upb-generated/envoy/config/endpoint/v3/load_report.upb.h +51 -21
  207. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.c +3 -3
  208. data/src/core/ext/upb-generated/envoy/config/listener/v3/api_listener.upb.h +11 -5
  209. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.c +37 -37
  210. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener.upb.h +61 -25
  211. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.c +40 -40
  212. data/src/core/ext/upb-generated/envoy/config/listener/v3/listener_components.upb.h +71 -29
  213. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.c +9 -9
  214. data/src/core/ext/upb-generated/envoy/config/listener/v3/quic_config.upb.h +11 -5
  215. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.c +5 -5
  216. data/src/core/ext/upb-generated/envoy/config/listener/v3/udp_listener_config.upb.h +21 -9
  217. data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.c +30 -30
  218. data/src/core/ext/upb-generated/envoy/config/metrics/v3/stats.upb.h +81 -33
  219. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.c +41 -29
  220. data/src/core/ext/upb-generated/envoy/config/overload/v3/overload.upb.h +141 -43
  221. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.c +46 -43
  222. data/src/core/ext/upb-generated/envoy/config/rbac/v3/rbac.upb.h +88 -29
  223. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.c +18 -18
  224. data/src/core/ext/upb-generated/envoy/config/route/v3/route.upb.h +31 -13
  225. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.c +281 -277
  226. data/src/core/ext/upb-generated/envoy/config/route/v3/route_components.upb.h +569 -248
  227. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.c +10 -10
  228. data/src/core/ext/upb-generated/envoy/config/route/v3/scoped_route.upb.h +31 -13
  229. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.c +6 -6
  230. data/src/core/ext/upb-generated/envoy/config/trace/v3/http_tracer.upb.h +21 -9
  231. data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.c +3 -3
  232. data/src/core/ext/upb-generated/envoy/extensions/clusters/aggregate/v3/cluster.upb.h +11 -5
  233. data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.c +13 -13
  234. data/src/core/ext/upb-generated/envoy/extensions/filters/common/fault/v3/fault.upb.h +51 -21
  235. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.c +23 -23
  236. data/src/core/ext/upb-generated/envoy/extensions/filters/http/fault/v3/fault.upb.h +31 -13
  237. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.c +9 -9
  238. data/src/core/ext/upb-generated/envoy/extensions/filters/http/router/v3/router.upb.h +11 -5
  239. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.c +115 -116
  240. data/src/core/ext/upb-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +191 -77
  241. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.c +1 -1
  242. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/cert.upb.h +1 -1
  243. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.c +46 -32
  244. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/common.upb.h +118 -34
  245. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.c +12 -12
  246. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +31 -13
  247. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.c +44 -42
  248. data/src/core/ext/upb-generated/envoy/extensions/transport_sockets/tls/v3/tls.upb.h +108 -55
  249. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.c +2 -2
  250. data/src/core/ext/upb-generated/envoy/service/cluster/v3/cds.upb.h +11 -5
  251. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.c +2 -2
  252. data/src/core/ext/upb-generated/envoy/service/discovery/v3/ads.upb.h +11 -5
  253. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.c +42 -42
  254. data/src/core/ext/upb-generated/envoy/service/discovery/v3/discovery.upb.h +61 -25
  255. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.c +2 -2
  256. data/src/core/ext/upb-generated/envoy/service/endpoint/v3/eds.upb.h +11 -5
  257. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.c +2 -2
  258. data/src/core/ext/upb-generated/envoy/service/listener/v3/lds.upb.h +11 -5
  259. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.c +9 -9
  260. data/src/core/ext/upb-generated/envoy/service/load_stats/v3/lrs.upb.h +21 -9
  261. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.c +2 -2
  262. data/src/core/ext/upb-generated/envoy/service/route/v3/rds.upb.h +11 -5
  263. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.c +2 -2
  264. data/src/core/ext/upb-generated/envoy/service/route/v3/srds.upb.h +11 -5
  265. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.c +28 -28
  266. data/src/core/ext/upb-generated/envoy/service/status/v3/csds.upb.h +51 -21
  267. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.c +8 -8
  268. data/src/core/ext/upb-generated/envoy/type/http/v3/path_transformation.upb.h +41 -17
  269. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.c +9 -8
  270. data/src/core/ext/upb-generated/envoy/type/matcher/v3/metadata.upb.h +25 -9
  271. data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.c +4 -4
  272. data/src/core/ext/upb-generated/envoy/type/matcher/v3/node.upb.h +11 -5
  273. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.c +4 -4
  274. data/src/core/ext/upb-generated/envoy/type/matcher/v3/number.upb.h +11 -5
  275. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.c +3 -3
  276. data/src/core/ext/upb-generated/envoy/type/matcher/v3/path.upb.h +11 -5
  277. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.c +9 -9
  278. data/src/core/ext/upb-generated/envoy/type/matcher/v3/regex.upb.h +31 -13
  279. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.c +10 -10
  280. data/src/core/ext/upb-generated/envoy/type/matcher/v3/string.upb.h +21 -9
  281. data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.c +6 -6
  282. data/src/core/ext/upb-generated/envoy/type/matcher/v3/struct.upb.h +21 -9
  283. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.c +11 -11
  284. data/src/core/ext/upb-generated/envoy/type/matcher/v3/value.upb.h +31 -13
  285. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.c +15 -15
  286. data/src/core/ext/upb-generated/envoy/type/metadata/v3/metadata.upb.h +71 -29
  287. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.c +19 -19
  288. data/src/core/ext/upb-generated/envoy/type/tracing/v3/custom_tag.upb.h +51 -21
  289. data/src/core/ext/upb-generated/envoy/type/v3/http.upb.c +1 -1
  290. data/src/core/ext/upb-generated/envoy/type/v3/http.upb.h +1 -1
  291. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.c +6 -6
  292. data/src/core/ext/upb-generated/envoy/type/v3/percent.upb.h +21 -9
  293. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.c +10 -10
  294. data/src/core/ext/upb-generated/envoy/type/v3/range.upb.h +31 -13
  295. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.c +5 -5
  296. data/src/core/ext/upb-generated/envoy/type/v3/semantic_version.upb.h +11 -5
  297. data/src/core/ext/upb-generated/google/api/annotations.upb.c +1 -1
  298. data/src/core/ext/upb-generated/google/api/annotations.upb.h +1 -1
  299. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.c +58 -58
  300. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/checked.upb.h +111 -45
  301. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.c +68 -68
  302. data/src/core/ext/upb-generated/google/api/expr/v1alpha1/syntax.upb.h +121 -49
  303. data/src/core/ext/upb-generated/google/api/http.upb.c +18 -18
  304. data/src/core/ext/upb-generated/google/api/http.upb.h +31 -13
  305. data/src/core/ext/upb-generated/google/protobuf/any.upb.c +4 -4
  306. data/src/core/ext/upb-generated/google/protobuf/any.upb.h +11 -5
  307. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +153 -153
  308. data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +271 -109
  309. data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +4 -4
  310. data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +11 -5
  311. data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +2 -2
  312. data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +11 -5
  313. data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +15 -15
  314. data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +31 -13
  315. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +4 -4
  316. data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +11 -5
  317. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +19 -19
  318. data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +91 -37
  319. data/src/core/ext/upb-generated/google/rpc/status.upb.c +5 -5
  320. data/src/core/ext/upb-generated/google/rpc/status.upb.h +11 -5
  321. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +12 -12
  322. data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +11 -5
  323. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +60 -60
  324. data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +101 -41
  325. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +7 -7
  326. data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +21 -9
  327. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +5 -5
  328. data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +21 -9
  329. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +31 -31
  330. data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +91 -37
  331. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.c +8 -8
  332. data/src/core/ext/upb-generated/udpa/annotations/migrate.upb.h +31 -13
  333. data/src/core/ext/upb-generated/udpa/annotations/security.upb.c +4 -4
  334. data/src/core/ext/upb-generated/udpa/annotations/security.upb.h +11 -5
  335. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.c +1 -1
  336. data/src/core/ext/upb-generated/udpa/annotations/sensitive.upb.h +1 -1
  337. data/src/core/ext/upb-generated/udpa/annotations/status.upb.c +4 -4
  338. data/src/core/ext/upb-generated/udpa/annotations/status.upb.h +11 -5
  339. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.c +3 -3
  340. data/src/core/ext/upb-generated/udpa/annotations/versioning.upb.h +11 -5
  341. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +13 -13
  342. data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +11 -5
  343. data/src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.c +4 -4
  344. data/src/core/ext/upb-generated/udpa/type/v1/typed_struct.upb.h +11 -5
  345. data/src/core/ext/upb-generated/validate/validate.upb.c +220 -220
  346. data/src/core/ext/upb-generated/validate/validate.upb.h +231 -93
  347. data/src/core/ext/upb-generated/xds/core/v3/authority.upb.c +3 -3
  348. data/src/core/ext/upb-generated/xds/core/v3/authority.upb.h +11 -5
  349. data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.c +8 -8
  350. data/src/core/ext/upb-generated/xds/core/v3/collection_entry.upb.h +21 -9
  351. data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.c +6 -6
  352. data/src/core/ext/upb-generated/xds/core/v3/context_params.upb.h +11 -5
  353. data/src/core/ext/upb-generated/xds/core/v3/resource.upb.c +5 -5
  354. data/src/core/ext/upb-generated/xds/core/v3/resource.upb.h +11 -5
  355. data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.c +11 -11
  356. data/src/core/ext/upb-generated/xds/core/v3/resource_locator.upb.h +21 -9
  357. data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.c +6 -6
  358. data/src/core/ext/upb-generated/xds/core/v3/resource_name.upb.h +11 -5
  359. data/src/core/ext/upbdefs-generated/envoy/config/cluster/v3/cluster.upbdefs.c +384 -382
  360. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +94 -63
  361. data/src/core/ext/upbdefs-generated/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +10 -0
  362. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.c +30 -19
  363. data/src/core/ext/upbdefs-generated/envoy/config/overload/v3/overload.upbdefs.h +5 -0
  364. data/src/core/ext/upbdefs-generated/envoy/config/route/v3/route_components.upbdefs.c +791 -780
  365. data/src/core/ext/upbdefs-generated/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +96 -100
  366. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +133 -115
  367. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.h +5 -0
  368. data/src/core/ext/upbdefs-generated/envoy/extensions/transport_sockets/tls/v3/tls.upbdefs.c +178 -173
  369. data/src/core/ext/upbdefs-generated/envoy/type/matcher/v3/metadata.upbdefs.c +14 -13
  370. data/src/core/ext/upbdefs-generated/google/protobuf/descriptor.upbdefs.c +103 -103
  371. data/src/core/ext/xds/certificate_provider_registry.cc +2 -2
  372. data/src/core/ext/xds/xds_api.cc +788 -910
  373. data/src/core/ext/xds/xds_api.h +16 -33
  374. data/src/core/ext/xds/xds_bootstrap.cc +27 -52
  375. data/src/core/ext/xds/xds_client.cc +69 -30
  376. data/src/core/ext/xds/xds_client_stats.cc +16 -15
  377. data/src/core/ext/xds/xds_client_stats.h +6 -6
  378. data/src/core/ext/xds/xds_http_fault_filter.cc +4 -3
  379. data/src/core/ext/xds/xds_http_fault_filter.h +3 -2
  380. data/src/core/ext/xds/xds_http_filters.cc +1 -0
  381. data/src/core/ext/xds/xds_server_config_fetcher.cc +10 -10
  382. data/src/core/lib/address_utils/parse_address.cc +4 -8
  383. data/src/core/lib/address_utils/sockaddr_utils.cc +2 -2
  384. data/src/core/lib/channel/channel_args.cc +2 -1
  385. data/src/core/lib/channel/channel_stack.cc +5 -3
  386. data/src/core/lib/channel/channel_stack_builder.cc +1 -11
  387. data/src/core/lib/channel/channel_stack_builder.h +0 -8
  388. data/src/core/lib/channel/channel_trace.cc +4 -3
  389. data/src/core/lib/channel/channel_trace.h +1 -0
  390. data/src/core/lib/channel/channelz.cc +40 -36
  391. data/src/core/lib/channel/channelz.h +27 -27
  392. data/src/core/lib/channel/channelz_registry.cc +7 -6
  393. data/src/core/lib/channel/connected_channel.cc +1 -0
  394. data/src/core/lib/channel/handshaker.cc +2 -1
  395. data/src/core/lib/channel/handshaker.h +1 -2
  396. data/src/core/lib/channel/handshaker_factory.h +10 -2
  397. data/src/core/lib/channel/handshaker_registry.cc +15 -70
  398. data/src/core/lib/channel/handshaker_registry.h +29 -12
  399. data/src/core/lib/channel/status_util.h +2 -2
  400. data/src/core/lib/compression/algorithm_metadata.h +1 -0
  401. data/src/core/lib/compression/compression_args.cc +2 -1
  402. data/src/core/lib/compression/compression_internal.cc +2 -4
  403. data/src/core/lib/compression/message_compress.cc +2 -2
  404. data/src/core/lib/compression/stream_compression.cc +2 -1
  405. data/src/core/lib/compression/stream_compression.h +2 -1
  406. data/src/core/lib/compression/stream_compression_gzip.cc +2 -1
  407. data/src/core/lib/compression/stream_compression_identity.cc +2 -1
  408. data/src/core/lib/config/core_configuration.cc +54 -0
  409. data/src/core/lib/config/core_configuration.h +108 -0
  410. data/src/core/lib/debug/stats.h +1 -0
  411. data/src/core/lib/debug/stats_data.cc +2 -1
  412. data/src/core/lib/debug/stats_data.h +1 -0
  413. data/src/core/lib/debug/trace.cc +1 -0
  414. data/src/core/lib/debug/trace.h +2 -1
  415. data/src/core/lib/event_engine/endpoint_config.cc +0 -1
  416. data/src/core/lib/event_engine/event_engine.cc +3 -3
  417. data/src/core/lib/event_engine/sockaddr.cc +3 -3
  418. data/src/core/lib/gpr/alloc.cc +4 -3
  419. data/src/core/lib/gpr/env_linux.cc +1 -2
  420. data/src/core/lib/gpr/env_posix.cc +2 -3
  421. data/src/core/lib/gpr/log.cc +3 -3
  422. data/src/core/lib/gpr/log_android.cc +3 -2
  423. data/src/core/lib/gpr/log_linux.cc +7 -4
  424. data/src/core/lib/gpr/log_posix.cc +6 -3
  425. data/src/core/lib/gpr/string.h +2 -2
  426. data/src/core/lib/gpr/sync.cc +2 -2
  427. data/src/core/lib/gpr/sync_abseil.cc +7 -6
  428. data/src/core/lib/gpr/sync_posix.cc +3 -3
  429. data/src/core/lib/gpr/time.cc +3 -2
  430. data/src/core/lib/gpr/time_windows.cc +3 -2
  431. data/src/core/lib/gpr/tls.h +120 -41
  432. data/src/core/lib/gpr/tmpfile_posix.cc +1 -2
  433. data/src/core/lib/gprpp/arena.cc +2 -1
  434. data/src/core/lib/gprpp/arena.h +5 -5
  435. data/src/core/lib/gprpp/atomic_utils.h +47 -0
  436. data/src/core/lib/gprpp/bitset.h +166 -0
  437. data/src/core/lib/gprpp/construct_destruct.h +39 -0
  438. data/src/core/lib/gprpp/dual_ref_counted.h +25 -26
  439. data/src/core/lib/gprpp/fork.cc +14 -12
  440. data/src/core/lib/gprpp/fork.h +4 -4
  441. data/src/core/lib/gprpp/global_config.h +1 -2
  442. data/src/core/lib/gprpp/global_config_env.cc +7 -7
  443. data/src/core/lib/gprpp/global_config_generic.h +2 -2
  444. data/src/core/lib/gprpp/manual_constructor.h +8 -5
  445. data/src/core/lib/gprpp/match.h +73 -0
  446. data/src/core/lib/gprpp/memory.h +3 -3
  447. data/src/core/lib/gprpp/mpscq.cc +7 -7
  448. data/src/core/lib/gprpp/mpscq.h +6 -5
  449. data/src/core/lib/gprpp/orphanable.h +3 -3
  450. data/src/core/lib/gprpp/overload.h +59 -0
  451. data/src/core/lib/gprpp/ref_counted.h +18 -18
  452. data/src/core/lib/gprpp/status_helper.cc +4 -4
  453. data/src/core/lib/gprpp/sync.h +3 -1
  454. data/src/core/lib/gprpp/thd_posix.cc +5 -5
  455. data/src/core/lib/gprpp/thd_windows.cc +4 -11
  456. data/src/core/lib/gprpp/time_util.cc +2 -2
  457. data/src/core/lib/gprpp/time_util.h +2 -2
  458. data/src/core/lib/http/format_request.cc +1 -0
  459. data/src/core/lib/http/format_request.h +1 -0
  460. data/src/core/lib/http/httpcli.cc +9 -9
  461. data/src/core/lib/http/httpcli.h +3 -0
  462. data/src/core/lib/http/httpcli_security_connector.cc +5 -8
  463. data/src/core/lib/http/parser.h +1 -0
  464. data/src/core/lib/iomgr/buffer_list.cc +2 -1
  465. data/src/core/lib/iomgr/buffer_list.h +1 -2
  466. data/src/core/lib/iomgr/call_combiner.cc +1 -0
  467. data/src/core/lib/iomgr/cfstream_handle.cc +1 -1
  468. data/src/core/lib/iomgr/combiner.cc +3 -2
  469. data/src/core/lib/iomgr/combiner.h +1 -0
  470. data/src/core/lib/iomgr/dualstack_socket_posix.cc +1 -0
  471. data/src/core/lib/iomgr/endpoint.cc +0 -4
  472. data/src/core/lib/iomgr/endpoint.h +1 -3
  473. data/src/core/lib/iomgr/endpoint_cfstream.cc +9 -20
  474. data/src/core/lib/iomgr/endpoint_cfstream.h +1 -1
  475. data/src/core/lib/iomgr/endpoint_pair.h +1 -0
  476. data/src/core/lib/iomgr/endpoint_pair_event_engine.cc +1 -2
  477. data/src/core/lib/iomgr/endpoint_pair_posix.cc +15 -11
  478. data/src/core/lib/iomgr/endpoint_pair_windows.cc +17 -9
  479. data/src/core/lib/iomgr/error.h +23 -9
  480. data/src/core/lib/iomgr/error_cfstream.cc +2 -2
  481. data/src/core/lib/iomgr/error_internal.h +1 -0
  482. data/src/core/lib/iomgr/ev_epoll1_linux.cc +14 -22
  483. data/src/core/lib/iomgr/ev_epollex_linux.cc +15 -22
  484. data/src/core/lib/iomgr/ev_poll_posix.cc +13 -25
  485. data/src/core/lib/iomgr/ev_posix.cc +1 -2
  486. data/src/core/lib/iomgr/event_engine/endpoint.cc +3 -22
  487. data/src/core/lib/iomgr/event_engine/endpoint.h +1 -2
  488. data/src/core/lib/iomgr/event_engine/iomgr.cc +17 -18
  489. data/src/core/lib/iomgr/event_engine/iomgr.h +20 -2
  490. data/src/core/lib/iomgr/event_engine/resolver.cc +2 -1
  491. data/src/core/lib/iomgr/event_engine/tcp.cc +53 -24
  492. data/src/core/lib/iomgr/exec_ctx.cc +3 -4
  493. data/src/core/lib/iomgr/exec_ctx.h +11 -19
  494. data/src/core/lib/iomgr/executor/mpmcqueue.cc +10 -9
  495. data/src/core/lib/iomgr/executor/mpmcqueue.h +4 -3
  496. data/src/core/lib/iomgr/executor/threadpool.cc +2 -2
  497. data/src/core/lib/iomgr/executor/threadpool.h +2 -1
  498. data/src/core/lib/iomgr/executor.cc +5 -6
  499. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +2 -2
  500. data/src/core/lib/iomgr/grpc_if_nametoindex_unsupported.cc +2 -2
  501. data/src/core/lib/iomgr/internal_errqueue.cc +3 -2
  502. data/src/core/lib/iomgr/iocp_windows.cc +1 -0
  503. data/src/core/lib/iomgr/iomgr.h +2 -2
  504. data/src/core/lib/iomgr/iomgr_custom.cc +2 -2
  505. data/src/core/lib/iomgr/iomgr_custom.h +2 -2
  506. data/src/core/lib/iomgr/iomgr_internal.cc +2 -1
  507. data/src/core/lib/iomgr/iomgr_windows.cc +1 -2
  508. data/src/core/lib/iomgr/is_epollexclusive_available.cc +4 -4
  509. data/src/core/lib/iomgr/polling_entity.cc +2 -2
  510. data/src/core/lib/iomgr/pollset_custom.cc +3 -4
  511. data/src/core/lib/iomgr/pollset_custom.h +2 -2
  512. data/src/core/lib/iomgr/pollset_set_custom.cc +1 -2
  513. data/src/core/lib/iomgr/pollset_set_windows.cc +1 -0
  514. data/src/core/lib/iomgr/port.h +0 -5
  515. data/src/core/lib/iomgr/python_util.h +1 -0
  516. data/src/core/lib/iomgr/resolve_address.cc +2 -1
  517. data/src/core/lib/iomgr/resolve_address.h +0 -4
  518. data/src/core/lib/iomgr/resolve_address_custom.cc +4 -4
  519. data/src/core/lib/iomgr/resolve_address_custom.h +0 -1
  520. data/src/core/lib/iomgr/resolve_address_posix.cc +2 -4
  521. data/src/core/lib/iomgr/resolve_address_windows.cc +6 -8
  522. data/src/core/lib/iomgr/resource_quota.cc +127 -42
  523. data/src/core/lib/iomgr/resource_quota.h +66 -17
  524. data/src/core/lib/iomgr/sockaddr.h +1 -1
  525. data/src/core/lib/iomgr/socket_factory_posix.cc +3 -3
  526. data/src/core/lib/iomgr/socket_factory_posix.h +1 -0
  527. data/src/core/lib/iomgr/socket_mutator.h +2 -2
  528. data/src/core/lib/iomgr/socket_utils_common_posix.cc +3 -3
  529. data/src/core/lib/iomgr/socket_utils_linux.cc +4 -4
  530. data/src/core/lib/iomgr/socket_utils_posix.cc +2 -2
  531. data/src/core/lib/iomgr/socket_utils_posix.h +2 -2
  532. data/src/core/lib/iomgr/socket_utils_windows.cc +2 -2
  533. data/src/core/lib/iomgr/tcp_client.cc +4 -2
  534. data/src/core/lib/iomgr/tcp_client.h +4 -0
  535. data/src/core/lib/iomgr/tcp_client_cfstream.cc +9 -19
  536. data/src/core/lib/iomgr/tcp_client_custom.cc +9 -17
  537. data/src/core/lib/iomgr/tcp_client_posix.cc +24 -9
  538. data/src/core/lib/iomgr/tcp_client_posix.h +5 -2
  539. data/src/core/lib/iomgr/tcp_client_windows.cc +14 -6
  540. data/src/core/lib/iomgr/tcp_custom.cc +11 -23
  541. data/src/core/lib/iomgr/tcp_custom.h +2 -1
  542. data/src/core/lib/iomgr/tcp_posix.cc +29 -59
  543. data/src/core/lib/iomgr/tcp_posix.h +11 -12
  544. data/src/core/lib/iomgr/tcp_server.cc +6 -4
  545. data/src/core/lib/iomgr/tcp_server.h +12 -9
  546. data/src/core/lib/iomgr/tcp_server_custom.cc +15 -33
  547. data/src/core/lib/iomgr/tcp_server_posix.cc +20 -13
  548. data/src/core/lib/iomgr/tcp_server_utils_posix.h +3 -0
  549. data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +1 -2
  550. data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.cc +3 -4
  551. data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.cc +4 -4
  552. data/src/core/lib/iomgr/tcp_server_windows.cc +13 -9
  553. data/src/core/lib/iomgr/tcp_windows.cc +6 -25
  554. data/src/core/lib/iomgr/tcp_windows.h +2 -1
  555. data/src/core/lib/iomgr/timer.cc +1 -0
  556. data/src/core/lib/iomgr/timer.h +1 -2
  557. data/src/core/lib/iomgr/timer_custom.cc +2 -2
  558. data/src/core/lib/iomgr/timer_generic.cc +8 -38
  559. data/src/core/lib/iomgr/timer_generic.h +1 -0
  560. data/src/core/lib/iomgr/timer_heap.cc +1 -2
  561. data/src/core/lib/iomgr/udp_server.cc +1 -2
  562. data/src/core/lib/iomgr/unix_sockets_posix.cc +3 -5
  563. data/src/core/lib/iomgr/unix_sockets_posix.h +2 -3
  564. data/src/core/lib/iomgr/wakeup_fd_nospecial.cc +1 -0
  565. data/src/core/lib/iomgr/wakeup_fd_pipe.cc +2 -3
  566. data/src/core/lib/iomgr/wakeup_fd_posix.cc +1 -0
  567. data/src/core/lib/iomgr/work_serializer.cc +4 -4
  568. data/src/core/lib/iomgr/work_serializer.h +1 -1
  569. data/src/core/lib/json/json_reader.cc +9 -17
  570. data/src/core/lib/json/json_util.h +18 -26
  571. data/src/core/lib/matchers/matchers.h +0 -1
  572. data/src/core/lib/profiling/basic_timers.cc +8 -6
  573. data/src/core/lib/profiling/stap_timers.cc +2 -2
  574. data/src/core/lib/security/authorization/authorization_policy_provider.h +5 -4
  575. data/src/core/lib/security/authorization/evaluate_args.cc +2 -0
  576. data/src/core/lib/security/authorization/sdk_server_authz_filter.cc +159 -0
  577. data/src/core/lib/security/authorization/sdk_server_authz_filter.h +67 -0
  578. data/src/core/lib/security/context/security_context.cc +7 -6
  579. data/src/core/lib/security/credentials/alts/check_gcp_environment_linux.cc +2 -2
  580. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  581. data/src/core/lib/security/credentials/alts/check_gcp_environment_windows.cc +2 -2
  582. data/src/core/lib/security/credentials/composite/composite_credentials.cc +4 -3
  583. data/src/core/lib/security/credentials/credentials.cc +6 -6
  584. data/src/core/lib/security/credentials/credentials.h +1 -1
  585. data/src/core/lib/security/credentials/credentials_metadata.cc +2 -3
  586. data/src/core/lib/security/credentials/external/aws_external_account_credentials.cc +13 -26
  587. data/src/core/lib/security/credentials/external/aws_external_account_credentials.h +1 -2
  588. data/src/core/lib/security/credentials/external/aws_request_signer.cc +3 -3
  589. data/src/core/lib/security/credentials/external/external_account_credentials.cc +13 -22
  590. data/src/core/lib/security/credentials/external/url_external_account_credentials.cc +2 -4
  591. data/src/core/lib/security/credentials/google_default/credentials_generic.cc +1 -2
  592. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +55 -3
  593. data/src/core/lib/security/credentials/iam/iam_credentials.cc +2 -1
  594. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  595. data/src/core/lib/security/credentials/jwt/json_token.h +2 -1
  596. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +31 -14
  597. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +11 -3
  598. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +0 -2
  599. data/src/core/lib/security/credentials/jwt/jwt_verifier.h +3 -3
  600. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +3 -7
  601. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +1 -0
  602. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +2 -4
  603. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +4 -4
  604. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +0 -1
  605. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.cc +3 -2
  606. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_distributor.h +10 -6
  607. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.cc +2 -1
  608. data/src/core/lib/security/credentials/tls/grpc_tls_certificate_provider.h +7 -5
  609. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +2 -2
  610. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +4 -6
  611. data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +1 -0
  612. data/src/core/lib/security/security_connector/load_system_roots_linux.cc +3 -3
  613. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -7
  614. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +1 -2
  615. data/src/core/lib/security/security_connector/ssl_utils.cc +2 -3
  616. data/src/core/lib/security/security_connector/tls/tls_security_connector.cc +9 -14
  617. data/src/core/lib/security/transport/auth_filters.h +1 -0
  618. data/src/core/lib/security/transport/client_auth_filter.cc +4 -6
  619. data/src/core/lib/security/transport/secure_endpoint.cc +4 -14
  620. data/src/core/lib/security/transport/secure_endpoint.h +1 -0
  621. data/src/core/lib/security/transport/security_handshaker.cc +5 -4
  622. data/src/core/lib/security/transport/security_handshaker.h +2 -1
  623. data/src/core/lib/security/util/json_util.cc +6 -8
  624. data/src/core/lib/slice/percent_encoding.cc +73 -30
  625. data/src/core/lib/slice/percent_encoding.h +29 -28
  626. data/src/core/lib/slice/slice.cc +2 -3
  627. data/src/core/lib/slice/slice_buffer.cc +1 -2
  628. data/src/core/lib/slice/slice_intern.cc +2 -3
  629. data/src/core/lib/slice/slice_internal.h +2 -2
  630. data/src/core/lib/surface/api_trace.cc +2 -1
  631. data/src/core/lib/surface/api_trace.h +1 -0
  632. data/src/core/lib/surface/byte_buffer_reader.cc +1 -1
  633. data/src/core/lib/surface/call.cc +9 -8
  634. data/src/core/lib/surface/call.h +3 -3
  635. data/src/core/lib/surface/call_details.cc +2 -2
  636. data/src/core/lib/surface/call_log_batch.cc +2 -2
  637. data/src/core/lib/surface/channel.cc +22 -9
  638. data/src/core/lib/surface/channel.h +14 -2
  639. data/src/core/lib/surface/channel_ping.cc +1 -2
  640. data/src/core/lib/surface/channel_stack_type.cc +2 -1
  641. data/src/core/lib/surface/completion_queue.cc +54 -64
  642. data/src/core/lib/surface/completion_queue_factory.cc +2 -1
  643. data/src/core/lib/surface/completion_queue_factory.h +1 -0
  644. data/src/core/lib/surface/event_string.cc +1 -0
  645. data/src/core/lib/surface/init.cc +4 -9
  646. data/src/core/lib/surface/init.h +0 -1
  647. data/src/core/lib/surface/init_secure.cc +23 -4
  648. data/src/core/lib/surface/lame_client.cc +6 -5
  649. data/src/core/lib/surface/metadata_array.cc +2 -2
  650. data/src/core/lib/surface/server.cc +17 -33
  651. data/src/core/lib/surface/server.h +11 -13
  652. data/src/core/lib/surface/validate_metadata.cc +44 -16
  653. data/src/core/lib/surface/version.cc +2 -2
  654. data/src/core/lib/transport/byte_stream.h +1 -0
  655. data/src/core/lib/transport/connectivity_state.cc +8 -5
  656. data/src/core/lib/transport/connectivity_state.h +2 -2
  657. data/src/core/lib/transport/error_utils.cc +1 -0
  658. data/src/core/lib/transport/metadata.cc +10 -10
  659. data/src/core/lib/transport/metadata.h +13 -11
  660. data/src/core/lib/transport/metadata_batch.h +8 -0
  661. data/src/core/lib/transport/transport_op_string.cc +2 -2
  662. data/src/core/plugin_registry/grpc_plugin_registry.cc +14 -0
  663. data/src/core/tsi/alts/crypt/aes_gcm.cc +3 -2
  664. data/src/core/tsi/alts/crypt/gsec.h +2 -3
  665. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +2 -2
  666. data/src/core/tsi/alts/handshaker/alts_handshaker_client.h +2 -3
  667. data/src/core/tsi/alts/zero_copy_frame_protector/alts_grpc_integrity_only_record_protocol.cc +2 -2
  668. data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +4 -3
  669. data/src/core/tsi/ssl/session_cache/ssl_session_openssl.cc +2 -2
  670. data/src/core/tsi/ssl_transport_security.cc +11 -9
  671. data/src/core/tsi/ssl_transport_security.h +3 -1
  672. data/src/core/tsi/transport_security.cc +3 -3
  673. data/src/core/tsi/transport_security_grpc.h +1 -0
  674. data/src/ruby/ext/grpc/extconf.rb +1 -1
  675. data/src/ruby/ext/grpc/rb_byte_buffer.c +2 -1
  676. data/src/ruby/ext/grpc/rb_call.c +5 -5
  677. data/src/ruby/ext/grpc/rb_call_credentials.c +5 -5
  678. data/src/ruby/ext/grpc/rb_channel.c +10 -8
  679. data/src/ruby/ext/grpc/rb_channel_args.c +2 -2
  680. data/src/ruby/ext/grpc/rb_channel_credentials.c +4 -4
  681. data/src/ruby/ext/grpc/rb_channel_credentials.h +1 -0
  682. data/src/ruby/ext/grpc/rb_completion_queue.c +3 -2
  683. data/src/ruby/ext/grpc/rb_compression_options.c +5 -4
  684. data/src/ruby/ext/grpc/rb_event_thread.c +4 -4
  685. data/src/ruby/ext/grpc/rb_grpc.c +5 -4
  686. data/src/ruby/ext/grpc/rb_grpc.h +1 -0
  687. data/src/ruby/ext/grpc/rb_server.c +6 -5
  688. data/src/ruby/ext/grpc/rb_server_credentials.c +3 -3
  689. data/src/ruby/ext/grpc/rb_server_credentials.h +1 -0
  690. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +8 -5
  691. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +3 -1
  692. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +6 -5
  693. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +3 -1
  694. data/src/ruby/lib/grpc/version.rb +1 -1
  695. data/third_party/boringssl-with-bazel/err_data.c +294 -292
  696. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_bitstr.c +52 -47
  697. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_gentm.c +1 -1
  698. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_mbstr.c +1 -1
  699. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_object.c +1 -0
  700. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_time.c +1 -1
  701. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_type.c +1 -1
  702. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utctm.c +1 -1
  703. data/third_party/boringssl-with-bazel/src/crypto/asn1/a_utf8.c +1 -1
  704. data/third_party/boringssl-with-bazel/src/crypto/asn1/{asn1_locl.h → internal.h} +20 -1
  705. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_dec.c +1 -1
  706. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_enc.c +1 -1
  707. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_fre.c +1 -1
  708. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_new.c +1 -1
  709. data/third_party/boringssl-with-bazel/src/crypto/asn1/tasn_utl.c +1 -1
  710. data/third_party/boringssl-with-bazel/src/crypto/asn1/time_support.c +1 -1
  711. data/third_party/boringssl-with-bazel/src/crypto/conf/conf.c +14 -3
  712. data/third_party/boringssl-with-bazel/src/crypto/digest_extra/digest_extra.c +5 -3
  713. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/bn/div.c +5 -6
  714. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/digest.c +2 -0
  715. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/internal.h +5 -9
  716. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/rand.c +1 -1
  717. data/third_party/boringssl-with-bazel/src/crypto/fipsmodule/rand/urandom.c +4 -6
  718. data/third_party/boringssl-with-bazel/src/crypto/hpke/hpke.c +34 -0
  719. data/third_party/boringssl-with-bazel/src/crypto/hrss/hrss.c +219 -121
  720. data/third_party/boringssl-with-bazel/src/crypto/hrss/internal.h +9 -2
  721. data/third_party/boringssl-with-bazel/src/crypto/internal.h +23 -2
  722. data/third_party/boringssl-with-bazel/src/crypto/lhash/internal.h +253 -0
  723. data/third_party/boringssl-with-bazel/src/crypto/lhash/lhash.c +28 -23
  724. data/third_party/boringssl-with-bazel/src/crypto/mem.c +2 -0
  725. data/third_party/boringssl-with-bazel/src/crypto/obj/obj.c +7 -3
  726. data/third_party/boringssl-with-bazel/src/crypto/poly1305/poly1305.c +1 -1
  727. data/third_party/boringssl-with-bazel/src/crypto/pool/pool.c +1 -0
  728. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/deterministic.c +4 -0
  729. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/fuchsia.c +4 -0
  730. data/third_party/boringssl-with-bazel/src/crypto/rand_extra/windows.c +4 -0
  731. data/third_party/boringssl-with-bazel/src/crypto/x509/a_strex.c +2 -2
  732. data/third_party/boringssl-with-bazel/src/crypto/x509/a_verify.c +15 -11
  733. data/third_party/boringssl-with-bazel/src/crypto/x509/algorithm.c +1 -1
  734. data/third_party/boringssl-with-bazel/src/crypto/x509/by_dir.c +1 -0
  735. data/third_party/boringssl-with-bazel/src/crypto/x509/internal.h +45 -2
  736. data/third_party/boringssl-with-bazel/src/crypto/x509/rsa_pss.c +4 -2
  737. data/third_party/boringssl-with-bazel/src/crypto/x509/t_crl.c +10 -3
  738. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_att.c +6 -23
  739. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_ext.c +2 -2
  740. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_lu.c +1 -0
  741. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_v3.c +25 -22
  742. data/third_party/boringssl-with-bazel/src/crypto/x509/x509_vfy.c +0 -4
  743. data/third_party/boringssl-with-bazel/src/crypto/x509/x509cset.c +1 -0
  744. data/third_party/boringssl-with-bazel/src/crypto/x509/x_algor.c +1 -3
  745. data/third_party/boringssl-with-bazel/src/crypto/x509/x_crl.c +9 -11
  746. data/third_party/boringssl-with-bazel/src/crypto/x509/x_exten.c +2 -0
  747. data/third_party/boringssl-with-bazel/src/crypto/x509/x_name.c +1 -3
  748. data/third_party/boringssl-with-bazel/src/crypto/x509/x_x509.c +1 -3
  749. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_conf.c +1 -0
  750. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_crld.c +0 -2
  751. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_lib.c +2 -0
  752. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_prn.c +14 -11
  753. data/third_party/boringssl-with-bazel/src/crypto/x509v3/v3_utl.c +5 -5
  754. data/third_party/boringssl-with-bazel/src/include/openssl/asn1.h +160 -74
  755. data/third_party/boringssl-with-bazel/src/include/openssl/base.h +0 -1
  756. data/third_party/boringssl-with-bazel/src/include/openssl/conf.h +8 -5
  757. data/third_party/boringssl-with-bazel/src/include/openssl/digest.h +3 -0
  758. data/third_party/boringssl-with-bazel/src/include/openssl/evp.h +6 -0
  759. data/third_party/boringssl-with-bazel/src/include/openssl/hpke.h +25 -0
  760. data/third_party/boringssl-with-bazel/src/include/openssl/hrss.h +14 -12
  761. data/third_party/boringssl-with-bazel/src/include/openssl/lhash.h +4 -205
  762. data/third_party/boringssl-with-bazel/src/include/openssl/mem.h +3 -0
  763. data/third_party/boringssl-with-bazel/src/include/openssl/obj.h +5 -4
  764. data/third_party/boringssl-with-bazel/src/include/openssl/ssl.h +58 -6
  765. data/third_party/boringssl-with-bazel/src/include/openssl/x509.h +184 -55
  766. data/third_party/boringssl-with-bazel/src/include/openssl/x509v3.h +0 -5
  767. data/third_party/boringssl-with-bazel/src/ssl/d1_both.cc +9 -16
  768. data/third_party/boringssl-with-bazel/src/ssl/encrypted_client_hello.cc +44 -2
  769. data/third_party/boringssl-with-bazel/src/ssl/{t1_lib.cc → extensions.cc} +24 -11
  770. data/third_party/boringssl-with-bazel/src/ssl/handshake.cc +9 -0
  771. data/third_party/boringssl-with-bazel/src/ssl/handshake_client.cc +75 -68
  772. data/third_party/boringssl-with-bazel/src/ssl/handshake_server.cc +17 -9
  773. data/third_party/boringssl-with-bazel/src/ssl/internal.h +25 -6
  774. data/third_party/boringssl-with-bazel/src/ssl/s3_lib.cc +1 -2
  775. data/third_party/boringssl-with-bazel/src/ssl/ssl_key_share.cc +11 -5
  776. data/third_party/boringssl-with-bazel/src/ssl/ssl_lib.cc +0 -49
  777. data/third_party/boringssl-with-bazel/src/ssl/ssl_session.cc +121 -65
  778. data/third_party/boringssl-with-bazel/src/ssl/ssl_x509.cc +14 -6
  779. data/third_party/boringssl-with-bazel/src/ssl/tls13_client.cc +9 -11
  780. data/third_party/boringssl-with-bazel/src/ssl/tls13_server.cc +2 -2
  781. data/third_party/upb/upb/decode.c +129 -60
  782. data/third_party/upb/upb/decode.h +32 -4
  783. data/third_party/upb/upb/decode_fast.c +513 -500
  784. data/third_party/upb/upb/decode_fast.h +27 -0
  785. data/third_party/upb/upb/{decode.int.h → decode_internal.h} +38 -8
  786. data/third_party/upb/upb/def.c +171 -181
  787. data/third_party/upb/upb/def.h +41 -19
  788. data/third_party/upb/upb/def.hpp +29 -0
  789. data/third_party/upb/upb/encode.c +49 -16
  790. data/third_party/upb/upb/encode.h +29 -2
  791. data/third_party/upb/upb/msg.c +169 -28
  792. data/third_party/upb/upb/msg.h +75 -580
  793. data/third_party/upb/upb/msg_internal.h +687 -0
  794. data/third_party/upb/upb/port_def.inc +85 -24
  795. data/third_party/upb/upb/port_undef.inc +38 -1
  796. data/third_party/upb/upb/reflection.c +29 -37
  797. data/third_party/upb/upb/reflection.h +36 -8
  798. data/third_party/upb/upb/reflection.hpp +37 -0
  799. data/third_party/upb/upb/table.c +211 -86
  800. data/third_party/upb/upb/{table.int.h → table_internal.h} +56 -180
  801. data/third_party/upb/upb/text_encode.c +32 -4
  802. data/third_party/upb/upb/text_encode.h +26 -0
  803. data/third_party/upb/upb/upb.c +59 -8
  804. data/third_party/upb/upb/upb.h +36 -6
  805. data/third_party/upb/upb/upb.hpp +24 -0
  806. data/third_party/upb/upb/upb_internal.h +58 -0
  807. metadata +58 -56
  808. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +0 -179
  809. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +0 -38
  810. data/src/core/ext/transport/chttp2/transport/hpack_table.cc +0 -243
  811. data/src/core/ext/transport/chttp2/transport/hpack_table.h +0 -148
  812. data/src/core/lib/gpr/tls_gcc.h +0 -52
  813. data/src/core/lib/gpr/tls_msvc.h +0 -54
  814. data/src/core/lib/gpr/tls_pthread.cc +0 -30
  815. data/src/core/lib/gpr/tls_pthread.h +0 -56
  816. data/src/core/lib/gpr/tls_stdcpp.h +0 -48
  817. data/src/core/lib/gprpp/atomic.h +0 -104
  818. data/src/core/lib/iomgr/endpoint_pair_uv.cc +0 -40
  819. data/src/core/lib/iomgr/iomgr_uv.cc +0 -43
  820. data/src/core/lib/iomgr/pollset_uv.cc +0 -95
  821. data/src/core/lib/iomgr/pollset_uv.h +0 -36
  822. data/src/core/lib/iomgr/sockaddr_custom.h +0 -54
  823. data/src/core/lib/iomgr/socket_utils_uv.cc +0 -49
  824. data/src/core/lib/iomgr/tcp_uv.cc +0 -421
  825. data/src/core/lib/iomgr/timer_uv.cc +0 -66
  826. data/third_party/upb/third_party/wyhash/wyhash.h +0 -145
  827. data/third_party/upb/upb/upb.int.h +0 -29
@@ -19,7 +19,6 @@
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
21
  #include "src/core/ext/transport/chttp2/transport/hpack_parser.h"
22
- #include "src/core/ext/transport/chttp2/transport/internal.h"
23
22
 
24
23
  #include <assert.h>
25
24
  #include <stddef.h>
@@ -32,8 +31,10 @@
32
31
  #include <grpc/support/log.h>
33
32
 
34
33
  #include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
34
+ #include "src/core/ext/transport/chttp2/transport/internal.h"
35
35
  #include "src/core/lib/debug/stats.h"
36
36
  #include "src/core/lib/gpr/string.h"
37
+ #include "src/core/lib/gprpp/match.h"
37
38
  #include "src/core/lib/profiling/timers.h"
38
39
  #include "src/core/lib/slice/slice_internal.h"
39
40
  #include "src/core/lib/slice/slice_string_helpers.h"
@@ -52,20 +53,6 @@ namespace grpc_core {
52
53
 
53
54
  DebugOnlyTraceFlag grpc_trace_chttp2_hpack_parser(false, "chttp2_hpack_parser");
54
55
 
55
- /* How parsing works:
56
-
57
- The parser object keeps track of a function pointer which represents the
58
- current parse state.
59
-
60
- Each time new bytes are presented, we call into the current state, which
61
- recursively parses until all bytes in the given chunk are exhausted.
62
-
63
- The parse state that terminates then saves its function pointer to be the
64
- current state so that it can resume when more bytes are available.
65
-
66
- It's expected that most optimizing compilers will turn this code into
67
- a set of indirect jumps, and so not waste stack space. */
68
-
69
56
  /* state table for huffman decoding: given a state, gives an index/16 into
70
57
  next_sub_tbl. Taking that index and adding the value of the nibble being
71
58
  considered returns the next state.
@@ -464,1121 +451,877 @@ struct Base64InverseTable {
464
451
  static GRPC_HPACK_CONSTEXPR_VALUE Base64InverseTable kBase64InverseTable;
465
452
  } // namespace
466
453
 
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) {
473
- char* k = grpc_slice_to_c_string(GRPC_MDKEY(md));
474
- char* v = nullptr;
475
- if (grpc_is_binary_header_internal(GRPC_MDKEY(md))) {
476
- v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX);
477
- } else {
478
- v = grpc_slice_to_c_string(GRPC_MDVALUE(md));
454
+ // Input tracks the current byte through the input data and provides it
455
+ // via a simple stream interface.
456
+ class HPackParser::Input {
457
+ public:
458
+ Input(grpc_slice_refcount* current_slice_refcount, const uint8_t* begin,
459
+ const uint8_t* end)
460
+ : current_slice_refcount_(current_slice_refcount),
461
+ begin_(begin),
462
+ end_(end),
463
+ frontier_(begin) {}
464
+
465
+ // If input is backed by a slice, retrieve its refcount. If not, return
466
+ // nullptr.
467
+ grpc_slice_refcount* slice_refcount() { return current_slice_refcount_; }
468
+
469
+ // Have we reached the end of input?
470
+ bool end_of_stream() const { return begin_ == end_; }
471
+ // How many bytes until end of input
472
+ size_t remaining() const { return end_ - begin_; }
473
+ // Current position, as a pointer
474
+ const uint8_t* cur_ptr() const { return begin_; }
475
+ // End position, as a pointer
476
+ const uint8_t* end_ptr() const { return end_; }
477
+ // Move read position forward by n, unchecked
478
+ void Advance(size_t n) { begin_ += n; }
479
+
480
+ // Retrieve the current character, or nullopt if end of stream
481
+ // Do not advance
482
+ absl::optional<uint8_t> peek() const {
483
+ if (end_of_stream()) {
484
+ return {};
485
+ }
486
+ return *begin_;
479
487
  }
480
- gpr_log(
481
- GPR_INFO,
482
- "Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d",
483
- k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md),
484
- grpc_slice_is_interned(GRPC_MDKEY(md)),
485
- grpc_slice_is_interned(GRPC_MDVALUE(md)));
486
- gpr_free(k);
487
- gpr_free(v);
488
- }
489
488
 
490
- /* emission helpers */
491
- template <HPackParser::TableAction action>
492
- grpc_error_handle HPackParser::FinishHeader(grpc_mdelem md) {
493
- if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
494
- LogHeader(md);
495
- }
496
- if (action == TableAction::kAddToTable) {
497
- GPR_DEBUG_ASSERT(GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_INTERNED ||
498
- GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC);
499
- grpc_error_handle err = grpc_chttp2_hptbl_add(&table_, md);
500
- if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) return err;
489
+ // Retrieve and advance past the current character, or return nullopt if end
490
+ // of stream
491
+ absl::optional<uint8_t> Next() {
492
+ if (end_of_stream()) {
493
+ return UnexpectedEOF(absl::optional<uint8_t>());
494
+ }
495
+ return *begin_++;
501
496
  }
502
- return sink_(md);
503
- }
504
497
 
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();
512
- } else {
513
- s = UnmanagedMemorySlice(data_.copied.str, data_.copied.length);
498
+ // Helper to parse a varint delta on top of value, return nullopt on failure
499
+ // (setting error)
500
+ absl::optional<uint32_t> ParseVarint(uint32_t value) {
501
+ // TODO(ctiller): break out a variant of this when we know there are at
502
+ // least 5 bytes in input_
503
+ auto cur = Next();
504
+ if (!cur) return {};
505
+ value += *cur & 0x7f;
506
+ if ((*cur & 0x80) == 0) return value;
507
+
508
+ cur = Next();
509
+ if (!cur) return {};
510
+ value += (*cur & 0x7f) << 7;
511
+ if ((*cur & 0x80) == 0) return value;
512
+
513
+ cur = Next();
514
+ if (!cur) return {};
515
+ value += (*cur & 0x7f) << 14;
516
+ if ((*cur & 0x80) == 0) return value;
517
+
518
+ cur = Next();
519
+ if (!cur) return {};
520
+ value += (*cur & 0x7f) << 21;
521
+ if ((*cur & 0x80) == 0) return value;
522
+
523
+ cur = Next();
524
+ if (!cur) return {};
525
+ uint32_t c = (*cur) & 0x7f;
526
+ // We might overflow here, so we need to be a little careful about the
527
+ // addition
528
+ if (c > 0xf) return ParseVarintOutOfRange(value, *cur);
529
+ const uint32_t add = c << 28;
530
+ if (add > 0xffffffffu - value) {
531
+ return ParseVarintOutOfRange(value, *cur);
532
+ }
533
+ value += add;
534
+ if ((*cur & 0x80) == 0) return value;
535
+
536
+ // Spec weirdness: we can add an infinite stream of 0x80 at the end of a
537
+ // varint and still end up with a correctly encoded varint.
538
+ do {
539
+ cur = Next();
540
+ if (!cur.has_value()) return {};
541
+ } while (*cur == 0x80);
542
+
543
+ // BUT... the last byte needs to be 0x00 or we'll overflow dramatically!
544
+ if (*cur == 0) return value;
545
+ return ParseVarintOutOfRange(value, *cur);
514
546
  }
515
- data_.copied.length = 0;
516
- return s;
517
- }
518
547
 
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();
526
- } else {
527
- s = ManagedMemorySlice(data_.copied.str, data_.copied.length);
548
+ // Prefix for a string
549
+ struct StringPrefix {
550
+ // Number of bytes in input for string
551
+ uint32_t length;
552
+ // Is it huffman compressed
553
+ bool huff;
554
+ };
555
+
556
+ // Parse a string prefix
557
+ absl::optional<StringPrefix> ParseStringPrefix() {
558
+ auto cur = Next();
559
+ if (!cur.has_value()) return {};
560
+ // Huffman if the top bit is 1
561
+ const bool huff = (*cur & 0x80) != 0;
562
+ // String length
563
+ uint32_t strlen = (*cur & 0x7f);
564
+ if (strlen == 0x7f) {
565
+ // all ones ==> varint string length
566
+ auto v = ParseVarint(0x7f);
567
+ if (!v.has_value()) return {};
568
+ strlen = *v;
569
+ }
570
+ return StringPrefix{strlen, huff};
528
571
  }
529
- data_.copied.length = 0;
530
- return s;
531
- }
532
572
 
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);
537
- }
573
+ // Check if we saw an EOF.. must be verified before looking at TakeError
574
+ bool eof_error() const { return eof_error_; }
538
575
 
539
- /* begin parsing a header: all functionality is encoded into lookup tables
540
- above */
541
- grpc_error_handle HPackParser::parse_begin(const uint8_t* cur,
542
- const uint8_t* end) {
543
- if (cur == end) {
544
- state_ = &HPackParser::parse_begin;
545
- return GRPC_ERROR_NONE;
576
+ // Extract the parse error, leaving the current error as NONE.
577
+ grpc_error_handle TakeError() {
578
+ grpc_error_handle out = error_;
579
+ error_ = GRPC_ERROR_NONE;
580
+ return out;
546
581
  }
547
582
 
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
- }
583
+ // Set the current error - allows the rest of the code not to need to pass
584
+ // around StatusOr<> which would be prohibitive here.
585
+ GPR_ATTRIBUTE_NOINLINE void SetError(grpc_error_handle error) {
586
+ if (error_ != GRPC_ERROR_NONE || eof_error_) {
587
+ GRPC_ERROR_UNREF(error);
588
+ return;
589
+ }
590
+ error_ = error;
591
+ begin_ = end_;
647
592
  }
648
- GPR_UNREACHABLE_CODE(abort());
649
- }
650
593
 
651
- /* stream dependency and prioritization data: we just skip it */
652
- grpc_error_handle HPackParser::parse_stream_weight(const uint8_t* cur,
653
- const uint8_t* end) {
654
- if (cur == end) {
655
- state_ = &HPackParser::parse_stream_weight;
656
- return GRPC_ERROR_NONE;
594
+ // If no error is set, set it to the value produced by error_factory.
595
+ // Return return_value unchanged.
596
+ template <typename F, typename T>
597
+ GPR_ATTRIBUTE_NOINLINE T MaybeSetErrorAndReturn(F error_factory,
598
+ T return_value) {
599
+ if (error_ != GRPC_ERROR_NONE || eof_error_) return return_value;
600
+ error_ = error_factory();
601
+ begin_ = end_;
602
+ return return_value;
657
603
  }
658
604
 
659
- return (this->*after_prioritization_)(cur + 1, end);
660
- }
661
-
662
- grpc_error_handle HPackParser::parse_stream_dep3(const uint8_t* cur,
663
- const uint8_t* end) {
664
- if (cur == end) {
665
- state_ = &HPackParser::parse_stream_dep3;
666
- return GRPC_ERROR_NONE;
605
+ // Set the error to an unexpected eof, and return result (code golfed as this
606
+ // is a common case)
607
+ template <typename T>
608
+ T UnexpectedEOF(T return_value) {
609
+ if (error_ != GRPC_ERROR_NONE) return return_value;
610
+ eof_error_ = true;
611
+ return return_value;
667
612
  }
668
613
 
669
- return parse_stream_weight(cur + 1, end);
670
- }
671
-
672
- grpc_error_handle HPackParser::parse_stream_dep2(const uint8_t* cur,
673
- const uint8_t* end) {
674
- if (cur == end) {
675
- state_ = &HPackParser::parse_stream_dep2;
676
- return GRPC_ERROR_NONE;
614
+ // Update the frontier - signifies we've successfully parsed another element
615
+ void UpdateFrontier() { frontier_ = begin_; }
616
+
617
+ // Get the frontier - for buffering should we fail due to eof
618
+ const uint8_t* frontier() const { return frontier_; }
619
+
620
+ private:
621
+ // Helper to set the error to out of range for ParseVarint
622
+ absl::optional<uint32_t> ParseVarintOutOfRange(uint32_t value,
623
+ uint8_t last_byte) {
624
+ return MaybeSetErrorAndReturn(
625
+ [value, last_byte] {
626
+ return GRPC_ERROR_CREATE_FROM_CPP_STRING(absl::StrFormat(
627
+ "integer overflow in hpack integer decoding: have 0x%08x, "
628
+ "got byte 0x%02x on byte 5",
629
+ value, last_byte));
630
+ },
631
+ absl::optional<uint32_t>());
677
632
  }
678
633
 
679
- return parse_stream_dep3(cur + 1, end);
680
- }
634
+ // Refcount if we are backed by a slice
635
+ grpc_slice_refcount* current_slice_refcount_;
636
+ // Current input point
637
+ const uint8_t* begin_;
638
+ // End of stream point
639
+ const uint8_t* const end_;
640
+ // Frontier denotes the first byte past successfully processed input
641
+ const uint8_t* frontier_;
642
+ // Current error
643
+ grpc_error_handle error_ = GRPC_ERROR_NONE;
644
+ // If the error was EOF, we flag it here..
645
+ bool eof_error_ = false;
646
+ };
681
647
 
682
- grpc_error_handle HPackParser::parse_stream_dep1(const uint8_t* cur,
683
- const uint8_t* end) {
684
- if (cur == end) {
685
- state_ = &HPackParser::parse_stream_dep1;
686
- return GRPC_ERROR_NONE;
648
+ // Helper to parse a string and turn it into a slice with appropriate memory
649
+ // management characteristics
650
+ class HPackParser::String {
651
+ public:
652
+ // Helper to specify a string should be internalized
653
+ struct Intern {};
654
+ // Helper to specify a string should be externalized
655
+ struct Extern {};
656
+
657
+ private:
658
+ // Forward declare take functions... we'll need them in the public interface
659
+ UnmanagedMemorySlice Take(Extern);
660
+ ManagedMemorySlice Take(Intern);
661
+
662
+ public:
663
+ // If a String is a Slice then unref
664
+ ~String() {
665
+ if (auto* p = absl::get_if<grpc_slice>(&value_)) {
666
+ grpc_slice_unref_internal(*p);
667
+ }
687
668
  }
688
669
 
689
- return parse_stream_dep2(cur + 1, end);
690
- }
691
-
692
- grpc_error_handle HPackParser::parse_stream_dep0(const uint8_t* cur,
693
- const uint8_t* end) {
694
- if (cur == end) {
695
- state_ = &HPackParser::parse_stream_dep0;
696
- return GRPC_ERROR_NONE;
670
+ // Take the value and leave this empty
671
+ // Use Intern/Extern to choose memory management
672
+ template <typename T>
673
+ auto Take() -> decltype(this->Take(T())) {
674
+ return Take(T());
697
675
  }
698
676
 
699
- return parse_stream_dep1(cur + 1, end);
700
- }
701
-
702
- grpc_error_handle HPackParser::InvalidHPackIndexError() {
703
- return grpc_error_set_int(
704
- grpc_error_set_int(
705
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Invalid HPACK index received"),
706
- GRPC_ERROR_INT_INDEX, static_cast<intptr_t>(index_)),
707
- GRPC_ERROR_INT_SIZE, static_cast<intptr_t>(table_.num_ents));
708
- }
709
-
710
- /* emit an indexed field; jumps to begin the next field on completion */
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_);
714
- if (GPR_UNLIKELY(GRPC_MDISNULL(md))) {
715
- return InvalidHPackIndexError();
677
+ String(const String&) = delete;
678
+ String& operator=(const String&) = delete;
679
+ String(String&& other) noexcept : value_(std::move(other.value_)) {
680
+ other.value_ = absl::Span<const uint8_t>();
716
681
  }
717
- GRPC_STATS_INC_HPACK_RECV_INDEXED();
718
- grpc_error_handle err = FinishHeader<TableAction::kOmitFromTable>(md);
719
- if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) return err;
720
- return parse_begin(cur, end);
721
- }
722
-
723
- /* parse an indexed field with index < 127 */
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);
730
- }
731
-
732
- /* parse an indexed field with index >= 127 */
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);
742
- }
743
-
744
- /* When finishing with a header, get the cached md element for this index.
745
- This is set in parse_value_string(). We ensure (in debug mode) that the
746
- cached metadata corresponds with the index we are examining. */
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_;
751
- GPR_DEBUG_ASSERT(!GRPC_MDISNULL(md)); /* handled in string parsing */
752
- md_for_index_.payload = 0; /* Invalidate cached md when index changes. */
753
- #ifndef NDEBUG
754
- precomputed_md_index_ = -1;
755
- #endif
756
- return md;
757
- }
758
-
759
- static const grpc_core::ManagedMemorySlice& get_indexed_key(grpc_mdelem md) {
760
- GPR_DEBUG_ASSERT(GRPC_MDELEM_IS_INTERNED(md));
761
- return static_cast<const grpc_core::ManagedMemorySlice&>(
762
- grpc_slice_ref_internal(GRPC_MDKEY(md)));
763
- }
764
-
765
- /* finish a literal header with incremental indexing */
766
- grpc_error_handle HPackParser::finish_lithdr_incidx(const uint8_t* cur,
767
- const uint8_t* end) {
768
- GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX();
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);
774
- }
775
-
776
- /* finish a literal header with incremental indexing with no index */
777
- grpc_error_handle HPackParser::finish_lithdr_incidx_v(const uint8_t* cur,
778
- const uint8_t* end) {
779
- GRPC_STATS_INC_HPACK_RECV_LITHDR_INCIDX_V();
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);
784
- }
785
-
786
- /* parse a literal header with incremental indexing; index < 63 */
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);
797
- }
798
-
799
- /* parse a literal header with incremental indexing; index >= 63 */
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);
812
- }
813
-
814
- /* parse a literal header with incremental indexing; index = 0 */
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);
824
- }
825
-
826
- /* finish a literal header without incremental indexing */
827
- grpc_error_handle HPackParser::finish_lithdr_notidx(const uint8_t* cur,
828
- const uint8_t* end) {
829
- GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX();
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);
835
- }
836
-
837
- /* finish a literal header without incremental indexing with index = 0 */
838
- grpc_error_handle HPackParser::finish_lithdr_notidx_v(const uint8_t* cur,
839
- const uint8_t* end) {
840
- GRPC_STATS_INC_HPACK_RECV_LITHDR_NOTIDX_V();
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);
845
- }
846
-
847
- /* parse a literal header without incremental indexing; index < 15 */
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);
858
- }
859
-
860
- /* parse a literal header without incremental indexing; index >= 15 */
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);
873
- }
874
-
875
- /* parse a literal header without incremental indexing; index == 0 */
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);
885
- }
886
-
887
- /* finish a literal header that is never indexed */
888
- grpc_error_handle HPackParser::finish_lithdr_nvridx(const uint8_t* cur,
889
- const uint8_t* end) {
890
- GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX();
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);
896
- }
897
-
898
- /* finish a literal header that is never indexed with an extra value */
899
- grpc_error_handle HPackParser::finish_lithdr_nvridx_v(const uint8_t* cur,
900
- const uint8_t* end) {
901
- GRPC_STATS_INC_HPACK_RECV_LITHDR_NVRIDX_V();
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);
906
- }
907
-
908
- /* parse a literal header that is never indexed; index < 15 */
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);
919
- }
920
-
921
- /* parse a literal header that is never indexed; index >= 15 */
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);
934
- }
935
-
936
- /* parse a literal header that is never indexed; index == 0 */
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);
946
- }
947
-
948
- /* finish parsing a max table size change */
949
- grpc_error_handle HPackParser::finish_max_tbl_size(const uint8_t* cur,
950
- const uint8_t* end) {
951
- if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
952
- gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", index_);
682
+ String& operator=(String&& other) noexcept {
683
+ value_ = std::move(other.value_);
684
+ other.value_ = absl::Span<const uint8_t>();
685
+ return *this;
953
686
  }
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);
958
- }
959
687
 
960
- /* parse a max table size change, max size < 15 */
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) {
964
- return parse_error(
965
- cur, end,
966
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
967
- "More than two max table size changes in a single frame"));
688
+ // Parse a non-binary string
689
+ static absl::optional<String> Parse(Input* input) {
690
+ auto pfx = input->ParseStringPrefix();
691
+ if (!pfx.has_value()) return {};
692
+ if (pfx->huff) {
693
+ // Huffman coded
694
+ std::vector<uint8_t> output;
695
+ auto v = ParseHuff(input, pfx->length,
696
+ [&output](uint8_t c) { output.push_back(c); });
697
+ if (!v) return {};
698
+ return String(std::move(output));
699
+ }
700
+ return ParseUncompressed(input, pfx->length);
968
701
  }
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);
973
- }
974
702
 
975
- /* parse a max table size change, max size >= 15 */
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) {
980
- return parse_error(
981
- cur, end,
982
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
983
- "More than two max table size changes in a single frame"));
703
+ // Parse a binary string
704
+ static absl::optional<String> ParseBinary(Input* input) {
705
+ auto pfx = input->ParseStringPrefix();
706
+ if (!pfx.has_value()) return {};
707
+ if (!pfx->huff) {
708
+ if (pfx->length > 0 && input->peek() == 0) {
709
+ // 'true-binary'
710
+ input->Advance(1);
711
+ return ParseUncompressed(input, pfx->length - 1);
712
+ }
713
+ // Base64 encoded... pull out the string, then unbase64 it
714
+ auto base64 = ParseUncompressed(input, pfx->length);
715
+ if (!base64.has_value()) return {};
716
+ return Unbase64(input, std::move(*base64));
717
+ } else {
718
+ // Huffman encoded...
719
+ std::vector<uint8_t> decompressed;
720
+ // State here says either we don't know if it's base64 or binary, or we do
721
+ // and what is it.
722
+ enum class State { kUnsure, kBinary, kBase64 };
723
+ State state = State::kUnsure;
724
+ auto decompressed_ok =
725
+ ParseHuff(input, pfx->length, [&state, &decompressed](uint8_t c) {
726
+ if (state == State::kUnsure) {
727
+ // First byte... if it's zero it's binary
728
+ if (c == 0) {
729
+ // Save the type, and skip the zero
730
+ state = State::kBinary;
731
+ return;
732
+ } else {
733
+ // Flag base64, store this value
734
+ state = State::kBase64;
735
+ }
736
+ }
737
+ // Non-first byte, or base64 first byte
738
+ decompressed.push_back(c);
739
+ });
740
+ if (!decompressed_ok) return {};
741
+ switch (state) {
742
+ case State::kUnsure:
743
+ // No bytes, empty span
744
+ return String(absl::Span<const uint8_t>());
745
+ case State::kBinary:
746
+ // Binary, we're done
747
+ return String(std::move(decompressed));
748
+ case State::kBase64:
749
+ // Base64 - unpack it
750
+ return Unbase64(input, String(std::move(decompressed)));
751
+ }
752
+ GPR_UNREACHABLE_CODE(abort(););
753
+ }
984
754
  }
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);
991
- }
992
755
 
993
- /* a parse error: jam the parse state into parse_error, and return error */
994
- grpc_error_handle HPackParser::parse_error(const uint8_t* /*cur*/,
995
- const uint8_t* /*end*/,
996
- grpc_error_handle err) {
997
- GPR_ASSERT(err != GRPC_ERROR_NONE);
998
- if (last_error_ == GRPC_ERROR_NONE) {
999
- last_error_ = GRPC_ERROR_REF(err);
756
+ private:
757
+ void AppendBytes(const uint8_t* data, size_t length);
758
+ explicit String(std::vector<uint8_t> v) : value_(std::move(v)) {}
759
+ explicit String(absl::Span<const uint8_t> v) : value_(v) {}
760
+ String(grpc_slice_refcount* r, const uint8_t* begin, const uint8_t* end)
761
+ : value_(MakeSlice(r, begin, end)) {}
762
+
763
+ // Given a refcount and a byte range, make a slice
764
+ static grpc_slice MakeSlice(grpc_slice_refcount* r, const uint8_t* begin,
765
+ const uint8_t* end) {
766
+ grpc_slice out;
767
+ out.refcount = r;
768
+ r->Ref();
769
+ out.data.refcounted.bytes = const_cast<uint8_t*>(begin);
770
+ out.data.refcounted.length = end - begin;
771
+ return out;
1000
772
  }
1001
- state_ = &HPackParser::still_parse_error;
1002
- return err;
1003
- }
1004
773
 
1005
- grpc_error_handle HPackParser::still_parse_error(const uint8_t* /*cur*/,
1006
- const uint8_t* /*end*/) {
1007
- return GRPC_ERROR_REF(last_error_);
1008
- }
1009
-
1010
- grpc_error_handle HPackParser::parse_illegal_op(const uint8_t* cur,
1011
- const uint8_t* end) {
1012
- GPR_ASSERT(cur != end);
1013
- grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1014
- absl::StrCat("Illegal hpack op code ", *cur).c_str());
1015
- return parse_error(cur, end, err);
1016
- }
1017
-
1018
- /* parse the 1st byte of a varint into parsing_.value
1019
- no overflow is possible */
1020
- grpc_error_handle HPackParser::parse_value0(const uint8_t* cur,
1021
- const uint8_t* end) {
1022
- if (cur == end) {
1023
- state_ = &HPackParser::parse_value0;
1024
- return GRPC_ERROR_NONE;
774
+ // Parse some huffman encoded bytes, using output(uint8_t b) to emit each
775
+ // decoded byte.
776
+ template <typename Out>
777
+ static bool ParseHuff(Input* input, uint32_t length, Out output) {
778
+ GRPC_STATS_INC_HPACK_RECV_HUFFMAN();
779
+ int16_t state = 0;
780
+ // Parse one half byte... we leverage some lookup tables to keep the logic
781
+ // here really simple.
782
+ auto nibble = [&output, &state](uint8_t nibble) {
783
+ int16_t emit = emit_sub_tbl[16 * emit_tbl[state] + nibble];
784
+ int16_t next = next_sub_tbl[16 * next_tbl[state] + nibble];
785
+ if (emit != -1) {
786
+ if (emit >= 0 && emit < 256) {
787
+ output(static_cast<uint8_t>(emit));
788
+ } else {
789
+ assert(emit == 256);
790
+ }
791
+ }
792
+ state = next;
793
+ };
794
+ // If there's insufficient bytes remaining, return now.
795
+ if (input->remaining() < length) {
796
+ return input->UnexpectedEOF(false);
797
+ }
798
+ // Grab the byte range, and iterate through it.
799
+ const uint8_t* p = input->cur_ptr();
800
+ input->Advance(length);
801
+ for (uint32_t i = 0; i < length; i++) {
802
+ nibble(p[i] >> 4);
803
+ nibble(p[i] & 0xf);
804
+ }
805
+ return true;
1025
806
  }
1026
807
 
1027
- *parsing_.value += (*cur) & 0x7f;
1028
-
1029
- if ((*cur) & 0x80) {
1030
- return parse_value1(cur + 1, end);
1031
- } else {
1032
- return parse_next(cur + 1, end);
808
+ // Parse some uncompressed string bytes.
809
+ static absl::optional<String> ParseUncompressed(Input* input,
810
+ uint32_t length) {
811
+ GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED();
812
+ // Check there's enough bytes
813
+ if (input->remaining() < length) {
814
+ return input->UnexpectedEOF(absl::optional<String>());
815
+ }
816
+ auto* refcount = input->slice_refcount();
817
+ auto* p = input->cur_ptr();
818
+ input->Advance(length);
819
+ if (refcount != nullptr) {
820
+ return String(refcount, p, p + length);
821
+ } else {
822
+ return String(absl::Span<const uint8_t>(p, length));
823
+ }
1033
824
  }
1034
- }
1035
825
 
1036
- /* parse the 2nd byte of a varint into parsing_.value
1037
- no overflow is possible */
1038
- grpc_error_handle HPackParser::parse_value1(const uint8_t* cur,
1039
- const uint8_t* end) {
1040
- if (cur == end) {
1041
- state_ = &HPackParser::parse_value1;
1042
- return GRPC_ERROR_NONE;
826
+ // Turn base64 encoded bytes into not base64 encoded bytes.
827
+ // Only takes input to set an error on failure.
828
+ static absl::optional<String> Unbase64(Input* input, String s) {
829
+ auto v = Match(
830
+ s.value_,
831
+ [](const grpc_slice& slice) {
832
+ return Unbase64Loop(GRPC_SLICE_START_PTR(slice),
833
+ GRPC_SLICE_END_PTR(slice));
834
+ },
835
+ [](absl::Span<const uint8_t> span) {
836
+ return Unbase64Loop(span.begin(), span.end());
837
+ },
838
+ [](const std::vector<uint8_t>& vec) {
839
+ return Unbase64Loop(vec.data(), vec.data() + vec.size());
840
+ });
841
+ if (!v.has_value()) {
842
+ return input->MaybeSetErrorAndReturn(
843
+ [] {
844
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
845
+ "illegal base64 encoding");
846
+ },
847
+ absl::optional<String>());
848
+ }
849
+ return String(std::move(*v));
1043
850
  }
1044
851
 
1045
- *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 7;
1046
-
1047
- if ((*cur) & 0x80) {
1048
- return parse_value2(cur + 1, end);
1049
- } else {
1050
- return parse_next(cur + 1, end);
1051
- }
1052
- }
852
+ // Main loop for Unbase64
853
+ static absl::optional<std::vector<uint8_t>> Unbase64Loop(const uint8_t* cur,
854
+ const uint8_t* end) {
855
+ while (cur != end && end[-1] == '=') {
856
+ --end;
857
+ }
1053
858
 
1054
- /* parse the 3rd byte of a varint into parsing_.value
1055
- no overflow is possible */
1056
- grpc_error_handle HPackParser::parse_value2(const uint8_t* cur,
1057
- const uint8_t* end) {
1058
- if (cur == end) {
1059
- state_ = &HPackParser::parse_value2;
1060
- return GRPC_ERROR_NONE;
1061
- }
859
+ std::vector<uint8_t> out;
860
+ out.reserve(3 * (end - cur) / 4 + 3);
1062
861
 
1063
- *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 14;
862
+ // Decode 4 bytes at a time while we can
863
+ while (end - cur >= 4) {
864
+ uint32_t bits = kBase64InverseTable.table[*cur];
865
+ if (bits > 63) return {};
866
+ uint32_t buffer = bits << 18;
867
+ ++cur;
1064
868
 
1065
- if ((*cur) & 0x80) {
1066
- return parse_value3(cur + 1, end);
1067
- } else {
1068
- return parse_next(cur + 1, end);
1069
- }
1070
- }
869
+ bits = kBase64InverseTable.table[*cur];
870
+ if (bits > 63) return {};
871
+ buffer |= bits << 12;
872
+ ++cur;
1071
873
 
1072
- /* parse the 4th byte of a varint into parsing_.value
1073
- no overflow is possible */
1074
- grpc_error_handle HPackParser::parse_value3(const uint8_t* cur,
1075
- const uint8_t* end) {
1076
- if (cur == end) {
1077
- state_ = &HPackParser::parse_value3;
1078
- return GRPC_ERROR_NONE;
1079
- }
874
+ bits = kBase64InverseTable.table[*cur];
875
+ if (bits > 63) return {};
876
+ buffer |= bits << 6;
877
+ ++cur;
1080
878
 
1081
- *parsing_.value += ((static_cast<uint32_t>(*cur)) & 0x7f) << 21;
879
+ bits = kBase64InverseTable.table[*cur];
880
+ if (bits > 63) return {};
881
+ buffer |= bits;
882
+ ++cur;
1082
883
 
1083
- if ((*cur) & 0x80) {
1084
- return parse_value4(cur + 1, end);
1085
- } else {
1086
- return parse_next(cur + 1, end);
1087
- }
1088
- }
884
+ out.insert(out.end(), {static_cast<uint8_t>(buffer >> 16),
885
+ static_cast<uint8_t>(buffer >> 8),
886
+ static_cast<uint8_t>(buffer)});
887
+ }
888
+ // Deal with the last 0, 1, 2, or 3 bytes.
889
+ switch (end - cur) {
890
+ case 0:
891
+ return out;
892
+ case 1:
893
+ return {};
894
+ case 2: {
895
+ uint32_t bits = kBase64InverseTable.table[*cur];
896
+ if (bits > 63) return {};
897
+ uint32_t buffer = bits << 18;
1089
898
 
1090
- /* parse the 5th byte of a varint into parsing_.value
1091
- depending on the byte, we may overflow, and care must be taken */
1092
- grpc_error_handle HPackParser::parse_value4(const uint8_t* cur,
1093
- const uint8_t* end) {
1094
- uint8_t c;
1095
- uint32_t cur_value;
1096
- uint32_t add_value;
899
+ ++cur;
900
+ bits = kBase64InverseTable.table[*cur];
901
+ if (bits > 63) return {};
902
+ buffer |= bits << 12;
1097
903
 
1098
- if (cur == end) {
1099
- state_ = &HPackParser::parse_value4;
1100
- return GRPC_ERROR_NONE;
1101
- }
904
+ if (buffer & 0xffff) return {};
905
+ out.push_back(static_cast<uint8_t>(buffer >> 16));
906
+ return out;
907
+ }
908
+ case 3: {
909
+ uint32_t bits = kBase64InverseTable.table[*cur];
910
+ if (bits > 63) return {};
911
+ uint32_t buffer = bits << 18;
1102
912
 
1103
- c = (*cur) & 0x7f;
1104
- if (c > 0xf) {
1105
- goto error;
1106
- }
913
+ ++cur;
914
+ bits = kBase64InverseTable.table[*cur];
915
+ if (bits > 63) return {};
916
+ buffer |= bits << 12;
1107
917
 
1108
- cur_value = *parsing_.value;
1109
- add_value = (static_cast<uint32_t>(c)) << 28;
1110
- if (add_value > 0xffffffffu - cur_value) {
1111
- goto error;
1112
- }
918
+ ++cur;
919
+ bits = kBase64InverseTable.table[*cur];
920
+ if (bits > 63) return {};
921
+ buffer |= bits << 6;
1113
922
 
1114
- *parsing_.value = cur_value + add_value;
923
+ ++cur;
924
+ if (buffer & 0xff) return {};
925
+ out.push_back(static_cast<uint8_t>(buffer >> 16));
926
+ out.push_back(static_cast<uint8_t>(buffer >> 8));
927
+ return out;
928
+ }
929
+ }
1115
930
 
1116
- if ((*cur) & 0x80) {
1117
- return parse_value5up(cur + 1, end);
1118
- } else {
1119
- return parse_next(cur + 1, end);
931
+ GPR_UNREACHABLE_CODE(return out;);
1120
932
  }
1121
933
 
1122
- error:
1123
- grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1124
- absl::StrFormat(
1125
- "integer overflow in hpack integer decoding: have 0x%08x, "
1126
- "got byte 0x%02x on byte 5",
1127
- *parsing_.value, *cur)
1128
- .c_str());
1129
- return parse_error(cur, end, err);
1130
- }
934
+ absl::variant<grpc_slice, absl::Span<const uint8_t>, std::vector<uint8_t>>
935
+ value_;
936
+ };
1131
937
 
1132
- /* parse any trailing bytes in a varint: it's possible to append an arbitrary
1133
- number of 0x80's and not affect the value - a zero will terminate - and
1134
- anything else will overflow */
1135
- grpc_error_handle HPackParser::parse_value5up(const uint8_t* cur,
1136
- const uint8_t* end) {
1137
- while (cur != end && *cur == 0x80) {
1138
- ++cur;
938
+ // Parser parses one frame + continuations worth of headers.
939
+ class HPackParser::Parser {
940
+ public:
941
+ Parser(Input* input, HPackParser::Sink* sink, HPackTable* table,
942
+ uint8_t* dynamic_table_updates_allowed)
943
+ : input_(input),
944
+ sink_(sink),
945
+ table_(table),
946
+ dynamic_table_updates_allowed_(dynamic_table_updates_allowed) {}
947
+
948
+ // Skip any priority bits, or return false on failure
949
+ bool SkipPriority() {
950
+ if (input_->remaining() < 5) return input_->UnexpectedEOF(false);
951
+ input_->Advance(5);
952
+ return true;
1139
953
  }
1140
954
 
1141
- if (cur == end) {
1142
- state_ = &HPackParser::parse_value5up;
1143
- return GRPC_ERROR_NONE;
955
+ bool Parse() {
956
+ auto cur = *input_->Next();
957
+ switch (cur >> 4) {
958
+ // Literal header not indexed - First byte format: 0000xxxx
959
+ // Literal header never indexed - First byte format: 0001xxxx
960
+ // Where xxxx:
961
+ // 0000 - literal key
962
+ // 1111 - indexed key, varint encoded index
963
+ // other - indexed key, inline encoded index
964
+ case 0:
965
+ case 1:
966
+ switch (cur & 0xf) {
967
+ case 0: // literal key
968
+ return FinishHeader<TableAction::kOmitFromTable>(
969
+ ParseLiteralKey<String::Extern>());
970
+ case 0xf: // varint encoded key index
971
+ return FinishHeader<TableAction::kOmitFromTable>(
972
+ ParseVarIdxKey<String::Extern>(0xf));
973
+ default: // inline encoded key index
974
+ return FinishHeader<TableAction::kOmitFromTable>(
975
+ ParseIdxKey<String::Extern>(cur & 0xf));
976
+ }
977
+ // Update max table size.
978
+ // First byte format: 001xxxxx
979
+ // Where xxxxx:
980
+ // 11111 - max size is varint encoded
981
+ // other - max size is stored inline
982
+ case 2:
983
+ // inline encoded max table size
984
+ return FinishMaxTableSize(cur & 0x1f);
985
+ case 3:
986
+ if (cur == 0x3f) {
987
+ // varint encoded max table size
988
+ return FinishMaxTableSize(input_->ParseVarint(0x1f));
989
+ } else {
990
+ // inline encoded max table size
991
+ return FinishMaxTableSize(cur & 0x1f);
992
+ }
993
+ // Literal header with incremental indexing.
994
+ // First byte format: 01xxxxxx
995
+ // Where xxxxxx:
996
+ // 000000 - literal key
997
+ // 111111 - indexed key, varint encoded index
998
+ // other - indexed key, inline encoded index
999
+ case 4:
1000
+ if (cur == 0x40) {
1001
+ // literal key
1002
+ return FinishHeader<TableAction::kAddToTable>(
1003
+ ParseLiteralKey<String::Intern>());
1004
+ }
1005
+ ABSL_FALLTHROUGH_INTENDED;
1006
+ case 5:
1007
+ case 6:
1008
+ // inline encoded key index
1009
+ return FinishHeader<TableAction::kAddToTable>(
1010
+ ParseIdxKey<String::Intern>(cur & 0x3f));
1011
+ case 7:
1012
+ if (cur == 0x7f) {
1013
+ // varint encoded key index
1014
+ return FinishHeader<TableAction::kAddToTable>(
1015
+ ParseVarIdxKey<String::Intern>(0x3f));
1016
+ } else {
1017
+ // inline encoded key index
1018
+ return FinishHeader<TableAction::kAddToTable>(
1019
+ ParseIdxKey<String::Intern>(cur & 0x3f));
1020
+ }
1021
+ // Indexed Header Field Representation
1022
+ // First byte format: 1xxxxxxx
1023
+ // Where xxxxxxx:
1024
+ // 0000000 - illegal
1025
+ // 1111111 - varint encoded field index
1026
+ // other - inline encoded field index
1027
+ case 8:
1028
+ if (cur == 0x80) {
1029
+ // illegal value.
1030
+ return input_->MaybeSetErrorAndReturn(
1031
+ [] {
1032
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1033
+ "Illegal hpack op code");
1034
+ },
1035
+ false);
1036
+ }
1037
+ ABSL_FALLTHROUGH_INTENDED;
1038
+ case 9:
1039
+ case 10:
1040
+ case 11:
1041
+ case 12:
1042
+ case 13:
1043
+ case 14:
1044
+ // inline encoded field index
1045
+ return FinishIndexed(cur & 0x7f);
1046
+ case 15:
1047
+ if (cur == 0xff) {
1048
+ // varint encoded field index
1049
+ return FinishIndexed(input_->ParseVarint(0x7f));
1050
+ } else {
1051
+ // inline encoded field index
1052
+ return FinishIndexed(cur & 0x7f);
1053
+ }
1054
+ }
1055
+ GPR_UNREACHABLE_CODE(abort());
1144
1056
  }
1145
1057
 
1146
- if (*cur == 0) {
1147
- return parse_next(cur + 1, end);
1058
+ private:
1059
+ void GPR_ATTRIBUTE_NOINLINE LogHeader(grpc_mdelem md) {
1060
+ char* k = grpc_slice_to_c_string(GRPC_MDKEY(md));
1061
+ char* v = nullptr;
1062
+ if (grpc_is_binary_header_internal(GRPC_MDKEY(md))) {
1063
+ v = grpc_dump_slice(GRPC_MDVALUE(md), GPR_DUMP_HEX);
1064
+ } else {
1065
+ v = grpc_slice_to_c_string(GRPC_MDVALUE(md));
1066
+ }
1067
+ gpr_log(
1068
+ GPR_INFO,
1069
+ "Decode: '%s: %s', elem_interned=%d [%d], k_interned=%d, v_interned=%d",
1070
+ k, v, GRPC_MDELEM_IS_INTERNED(md), GRPC_MDELEM_STORAGE(md),
1071
+ grpc_slice_is_interned(GRPC_MDKEY(md)),
1072
+ grpc_slice_is_interned(GRPC_MDVALUE(md)));
1073
+ gpr_free(k);
1074
+ gpr_free(v);
1148
1075
  }
1149
1076
 
1150
- grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1151
- absl::StrFormat(
1152
- "integer overflow in hpack integer decoding: have 0x%08x, "
1153
- "got byte 0x%02x sometime after byte 5",
1154
- *parsing_.value, *cur)
1155
- .c_str());
1156
- return parse_error(cur, end, err);
1157
- }
1158
-
1159
- /* parse a string prefix */
1160
- grpc_error_handle HPackParser::parse_string_prefix(const uint8_t* cur,
1161
- const uint8_t* end) {
1162
- if (cur == end) {
1163
- state_ = &HPackParser::parse_string_prefix;
1164
- return GRPC_ERROR_NONE;
1077
+ // During FinishHeader, how should the header be treated in the hpack table
1078
+ enum class TableAction {
1079
+ // Add to the table
1080
+ kAddToTable,
1081
+ // Do not add to the table
1082
+ kOmitFromTable,
1083
+ };
1084
+
1085
+ template <TableAction action>
1086
+ bool FinishHeader(grpc_mdelem md) {
1087
+ // Allow higher code to just pass in failures ... simplifies things a bit.
1088
+ if (GRPC_MDISNULL(md)) return false;
1089
+ // Log if desired
1090
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
1091
+ LogHeader(md);
1092
+ }
1093
+ // Add to the hpack table if needed
1094
+ if (action == TableAction::kAddToTable) {
1095
+ GPR_DEBUG_ASSERT(GRPC_MDELEM_STORAGE(md) ==
1096
+ GRPC_MDELEM_STORAGE_INTERNED ||
1097
+ GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC);
1098
+ grpc_error_handle err = table_->Add(md);
1099
+ if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) {
1100
+ input_->SetError(err);
1101
+ return false;
1102
+ };
1103
+ }
1104
+ // Pass up to the transport
1105
+ grpc_error_handle err = (*sink_)(md);
1106
+ if (GPR_UNLIKELY(err != GRPC_ERROR_NONE)) {
1107
+ input_->SetError(err);
1108
+ return false;
1109
+ }
1110
+ return true;
1165
1111
  }
1166
1112
 
1167
- strlen_ = (*cur) & 0x7f;
1168
- huff_ = (*cur) >> 7;
1169
- if (strlen_ == 0x7f) {
1170
- parsing_.value = &strlen_;
1171
- return parse_value0(cur + 1, end);
1172
- } else {
1173
- return parse_next(cur + 1, end);
1113
+ // Parse a string encoded key and a string encoded value
1114
+ template <typename TakeValueType>
1115
+ grpc_mdelem ParseLiteralKey() {
1116
+ auto key = String::Parse(input_);
1117
+ if (!key.has_value()) return GRPC_MDNULL;
1118
+ auto key_slice = key->Take<String::Intern>();
1119
+ auto value = ParseValueString(key_slice);
1120
+ if (GPR_UNLIKELY(!value.has_value())) {
1121
+ grpc_slice_unref_internal(key_slice);
1122
+ return GRPC_MDNULL;
1123
+ }
1124
+ return grpc_mdelem_from_slices(key_slice, value->Take<TakeValueType>());
1174
1125
  }
1175
- }
1176
1126
 
1177
- /* append some bytes to a string */
1178
- void HPackParser::String::AppendBytes(const uint8_t* data, size_t length) {
1179
- if (length == 0) return;
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));
1127
+ // Parse an index encoded key and a string encoded value
1128
+ template <typename TakeValueType>
1129
+ grpc_mdelem ParseIdxKey(uint32_t index) {
1130
+ auto elem = table_->Peek(index);
1131
+ if (GPR_UNLIKELY(GRPC_MDISNULL(elem))) {
1132
+ return InvalidHPackIndexError(index, elem);
1133
+ }
1134
+ GPR_DEBUG_ASSERT(GRPC_MDELEM_IS_INTERNED(elem));
1135
+ auto value = ParseValueString(GRPC_MDKEY(elem));
1136
+ if (GPR_UNLIKELY(!value.has_value())) return GRPC_MDNULL;
1137
+ return grpc_mdelem_from_slices(
1138
+ static_cast<const ManagedMemorySlice&>(
1139
+ grpc_slice_ref_internal(GRPC_MDKEY(elem))),
1140
+ value->Take<TakeValueType>());
1185
1141
  }
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);
1189
- }
1190
1142
 
1191
- grpc_error_handle HPackParser::AppendString(const uint8_t* cur,
1192
- const uint8_t* end) {
1193
- String* str = parsing_.str;
1194
- uint32_t bits;
1195
- uint8_t decoded[3];
1196
- switch (binary_) {
1197
- case BinaryState::kNotBinary:
1198
- str->AppendBytes(cur, static_cast<size_t>(end - cur));
1199
- return GRPC_ERROR_NONE;
1200
- case BinaryState::kBinaryBegin:
1201
- if (cur == end) {
1202
- binary_ = BinaryState::kBinaryBegin;
1203
- return GRPC_ERROR_NONE;
1204
- }
1205
- if (*cur == 0) {
1206
- /* 'true-binary' case */
1207
- ++cur;
1208
- binary_ = BinaryState::kNotBinary;
1209
- GRPC_STATS_INC_HPACK_RECV_BINARY();
1210
- str->AppendBytes(cur, static_cast<size_t>(end - cur));
1211
- return GRPC_ERROR_NONE;
1212
- }
1213
- GRPC_STATS_INC_HPACK_RECV_BINARY_BASE64();
1214
- b64_byte0:
1215
- ABSL_FALLTHROUGH_INTENDED;
1216
- case BinaryState::kBase64Byte0:
1217
- if (cur == end) {
1218
- binary_ = BinaryState::kBase64Byte0;
1219
- return GRPC_ERROR_NONE;
1220
- }
1221
- bits = kBase64InverseTable.table[*cur];
1222
- ++cur;
1223
- if (bits == 255) {
1224
- return parse_error(
1225
- cur, end,
1226
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1227
- } else if (bits == 64) {
1228
- goto b64_byte0;
1229
- }
1230
- base64_buffer_ = bits << 18;
1231
- b64_byte1:
1232
- ABSL_FALLTHROUGH_INTENDED;
1233
- case BinaryState::kBase64Byte1:
1234
- if (cur == end) {
1235
- binary_ = BinaryState::kBase64Byte1;
1236
- return GRPC_ERROR_NONE;
1237
- }
1238
- bits = kBase64InverseTable.table[*cur];
1239
- ++cur;
1240
- if (bits == 255) {
1241
- return parse_error(
1242
- cur, end,
1243
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1244
- } else if (bits == 64) {
1245
- goto b64_byte1;
1246
- }
1247
- base64_buffer_ |= bits << 12;
1248
- b64_byte2:
1249
- ABSL_FALLTHROUGH_INTENDED;
1250
- case BinaryState::kBase64Byte2:
1251
- if (cur == end) {
1252
- binary_ = BinaryState::kBase64Byte2;
1253
- return GRPC_ERROR_NONE;
1254
- }
1255
- bits = kBase64InverseTable.table[*cur];
1256
- ++cur;
1257
- if (bits == 255) {
1258
- return parse_error(
1259
- cur, end,
1260
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1261
- } else if (bits == 64) {
1262
- goto b64_byte2;
1263
- }
1264
- base64_buffer_ |= bits << 6;
1265
- b64_byte3:
1266
- ABSL_FALLTHROUGH_INTENDED;
1267
- case BinaryState::kBase64Byte3:
1268
- if (cur == end) {
1269
- binary_ = BinaryState::kBase64Byte3;
1270
- return GRPC_ERROR_NONE;
1271
- }
1272
- bits = kBase64InverseTable.table[*cur];
1273
- ++cur;
1274
- if (bits == 255) {
1275
- return parse_error(
1276
- cur, end,
1277
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Illegal base64 character"));
1278
- } else if (bits == 64) {
1279
- goto b64_byte3;
1280
- }
1281
- base64_buffer_ |= bits;
1282
- bits = base64_buffer_;
1283
- decoded[0] = static_cast<uint8_t>(bits >> 16);
1284
- decoded[1] = static_cast<uint8_t>(bits >> 8);
1285
- decoded[2] = static_cast<uint8_t>(bits);
1286
- str->AppendBytes(decoded, 3);
1287
- goto b64_byte0;
1143
+ // Parse a varint index encoded key and a string encoded value
1144
+ template <typename TakeValueType>
1145
+ grpc_mdelem ParseVarIdxKey(uint32_t offset) {
1146
+ auto index = input_->ParseVarint(offset);
1147
+ if (GPR_UNLIKELY(!index.has_value())) return GRPC_MDNULL;
1148
+ return ParseIdxKey<TakeValueType>(*index);
1288
1149
  }
1289
- GPR_UNREACHABLE_CODE(return parse_error(
1290
- cur, end,
1291
- GRPC_ERROR_CREATE_FROM_STATIC_STRING("Should never reach here")));
1292
- }
1293
1150
 
1294
- grpc_error_handle HPackParser::finish_str(const uint8_t* cur,
1295
- const uint8_t* end) {
1296
- uint8_t decoded[2];
1297
- uint32_t bits;
1298
- String* str = parsing_.str;
1299
- switch (binary_) {
1300
- case BinaryState::kNotBinary:
1301
- break;
1302
- case BinaryState::kBinaryBegin:
1303
- break;
1304
- case BinaryState::kBase64Byte0:
1305
- break;
1306
- case BinaryState::kBase64Byte1:
1307
- return parse_error(cur, end,
1308
- GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1309
- "illegal base64 encoding")); /* illegal encoding */
1310
- case BinaryState::kBase64Byte2:
1311
- bits = base64_buffer_;
1312
- if (bits & 0xffff) {
1313
- grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1314
- absl::StrFormat("trailing bits in base64 encoding: 0x%04x",
1315
- bits & 0xffff)
1316
- .c_str());
1317
- return parse_error(cur, end, err);
1318
- }
1319
- decoded[0] = static_cast<uint8_t>(bits >> 16);
1320
- str->AppendBytes(decoded, 1);
1321
- break;
1322
- case BinaryState::kBase64Byte3:
1323
- bits = base64_buffer_;
1324
- if (bits & 0xff) {
1325
- grpc_error_handle err = GRPC_ERROR_CREATE_FROM_COPIED_STRING(
1326
- absl::StrFormat("trailing bits in base64 encoding: 0x%02x",
1327
- bits & 0xff)
1328
- .c_str());
1329
- return parse_error(cur, end, err);
1330
- }
1331
- decoded[0] = static_cast<uint8_t>(bits >> 16);
1332
- decoded[1] = static_cast<uint8_t>(bits >> 8);
1333
- str->AppendBytes(decoded, 2);
1334
- break;
1335
- }
1336
- return GRPC_ERROR_NONE;
1337
- }
1338
-
1339
- /* decode a nibble from a huffman encoded stream */
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];
1343
- if (emit != -1) {
1344
- if (emit >= 0 && emit < 256) {
1345
- uint8_t c = static_cast<uint8_t>(emit);
1346
- grpc_error_handle err = AppendString(&c, (&c) + 1);
1347
- if (err != GRPC_ERROR_NONE) return err;
1151
+ // Parse a string, figuring out if it's binary or not by the key name.
1152
+ template <typename SliceType>
1153
+ absl::optional<String> ParseValueString(const SliceType& key) {
1154
+ if (grpc_is_refcounted_slice_binary_header(key)) {
1155
+ return String::ParseBinary(input_);
1348
1156
  } else {
1349
- assert(emit == 256);
1157
+ return String::Parse(input_);
1350
1158
  }
1351
1159
  }
1352
- huff_state_ = next;
1353
- return GRPC_ERROR_NONE;
1354
- }
1355
1160
 
1356
- /* decode full bytes from a huffman encoded stream */
1357
- grpc_error_handle HPackParser::AppendHuffBytes(const uint8_t* cur,
1358
- const uint8_t* end) {
1359
- for (; cur != end; ++cur) {
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);
1161
+ // Emit an indexed field
1162
+ bool FinishIndexed(absl::optional<uint32_t> index) {
1163
+ *dynamic_table_updates_allowed_ = 0;
1164
+ if (!index.has_value()) return false;
1165
+ grpc_mdelem md = table_->Fetch(*index);
1166
+ if (GPR_UNLIKELY(GRPC_MDISNULL(md))) {
1167
+ return InvalidHPackIndexError(*index, false);
1168
+ }
1169
+ GRPC_STATS_INC_HPACK_RECV_INDEXED();
1170
+ return FinishHeader<TableAction::kOmitFromTable>(md);
1364
1171
  }
1365
- return GRPC_ERROR_NONE;
1366
- }
1367
1172
 
1368
- /* decode some string bytes based on the current decoding mode
1369
- (huffman or not) */
1370
- grpc_error_handle HPackParser::AppendStrBytes(const uint8_t* cur,
1371
- const uint8_t* end) {
1372
- if (huff_) {
1373
- return AppendHuffBytes(cur, end);
1374
- } else {
1375
- return AppendString(cur, end);
1173
+ // finish parsing a max table size change
1174
+ bool FinishMaxTableSize(absl::optional<uint32_t> size) {
1175
+ if (!size.has_value()) return false;
1176
+ if (*dynamic_table_updates_allowed_ == 0) {
1177
+ return input_->MaybeSetErrorAndReturn(
1178
+ [] {
1179
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1180
+ "More than two max table size changes in a single frame");
1181
+ },
1182
+ false);
1183
+ }
1184
+ (*dynamic_table_updates_allowed_)--;
1185
+ if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_chttp2_hpack_parser)) {
1186
+ gpr_log(GPR_INFO, "MAX TABLE SIZE: %d", *size);
1187
+ }
1188
+ grpc_error_handle err = table_->SetCurrentTableSize(*size);
1189
+ if (err != GRPC_ERROR_NONE) {
1190
+ input_->SetError(err);
1191
+ return false;
1192
+ }
1193
+ return true;
1376
1194
  }
1377
- }
1378
1195
 
1379
- /* parse a string - tries to do large chunks at a time */
1380
- grpc_error_handle HPackParser::parse_string(const uint8_t* cur,
1381
- const uint8_t* end) {
1382
- size_t remaining = strlen_ - strgot_;
1383
- size_t given = static_cast<size_t>(end - cur);
1384
- if (remaining <= given) {
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);
1390
- } else {
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;
1396
- return GRPC_ERROR_NONE;
1196
+ // Set an invalid hpack index error if no error has been set. Returns result
1197
+ // unmodified.
1198
+ template <typename R>
1199
+ R InvalidHPackIndexError(uint32_t index, R result) {
1200
+ return input_->MaybeSetErrorAndReturn(
1201
+ [this, index] {
1202
+ return grpc_error_set_int(
1203
+ grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1204
+ "Invalid HPACK index received"),
1205
+ GRPC_ERROR_INT_INDEX,
1206
+ static_cast<intptr_t>(index)),
1207
+ GRPC_ERROR_INT_SIZE,
1208
+ static_cast<intptr_t>(this->table_->num_entries()));
1209
+ },
1210
+ result);
1397
1211
  }
1398
- }
1399
1212
 
1400
- /* begin parsing a string - performs setup, calls parse_string */
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) {
1408
- GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED();
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);
1415
- }
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_) {
1425
- GRPC_STATS_INC_HPACK_RECV_HUFFMAN();
1426
- } else {
1427
- GRPC_STATS_INC_HPACK_RECV_UNCOMPRESSED();
1428
- }
1429
- break;
1430
- case BinaryState::kBinaryBegin:
1431
- /* stats incremented later: don't know true binary or not */
1432
- break;
1433
- default:
1434
- abort();
1435
- }
1436
- return parse_string(cur, end);
1437
- }
1213
+ Input* input_;
1214
+ HPackParser::Sink* sink_;
1215
+ HPackTable* const table_;
1216
+ uint8_t* dynamic_table_updates_allowed_;
1217
+ };
1438
1218
 
1439
- /* parse the key string */
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_);
1219
+ UnmanagedMemorySlice HPackParser::String::Take(Extern) {
1220
+ auto s = Match(
1221
+ value_,
1222
+ [](const grpc_slice& slice) {
1223
+ GPR_DEBUG_ASSERT(!grpc_slice_is_interned(slice));
1224
+ return static_cast<const UnmanagedMemorySlice&>(slice);
1225
+ },
1226
+ [](absl::Span<const uint8_t> span) {
1227
+ return UnmanagedMemorySlice(
1228
+ reinterpret_cast<char*>(const_cast<uint8_t*>(span.begin())),
1229
+ span.size());
1230
+ },
1231
+ [](const std::vector<uint8_t>& v) {
1232
+ return UnmanagedMemorySlice(reinterpret_cast<const char*>(v.data()),
1233
+ v.size());
1234
+ });
1235
+ value_ = absl::Span<const uint8_t>();
1236
+ return s;
1443
1237
  }
1444
1238
 
1445
- /* check if a key represents a binary header or not */
1446
-
1447
- bool HPackParser::IsBinaryLiteralHeader() {
1448
- /* We know that either argument here is a reference counter slice.
1449
- * 1. If it is a grpc_core::StaticSlice, the refcount is set to kNoopRefcount.
1450
- * 2. If it's key_.data.referenced, then key_.copied was set to false,
1451
- * which occurs in begin_parse_string() - where the refcount is set to
1452
- * current_slice_refcount_, which is not null. */
1453
- return grpc_is_refcounted_slice_binary_header(
1454
- key_.copied_ ? grpc_core::ExternallyManagedSlice(key_.data_.copied.str,
1455
- key_.data_.copied.length)
1456
- : key_.data_.referenced);
1239
+ ManagedMemorySlice HPackParser::String::Take(Intern) {
1240
+ auto s = Match(
1241
+ value_,
1242
+ [](const grpc_slice& slice) {
1243
+ ManagedMemorySlice s(&slice);
1244
+ grpc_slice_unref_internal(slice);
1245
+ return s;
1246
+ },
1247
+ [](absl::Span<const uint8_t> span) {
1248
+ return ManagedMemorySlice(
1249
+ reinterpret_cast<char*>(const_cast<uint8_t*>(span.data())),
1250
+ span.size());
1251
+ },
1252
+ [](const std::vector<uint8_t>& v) {
1253
+ return ManagedMemorySlice(reinterpret_cast<const char*>(v.data()),
1254
+ v.size());
1255
+ });
1256
+ value_ = absl::Span<const uint8_t>();
1257
+ return s;
1457
1258
  }
1458
1259
 
1459
- /* Cache the metadata for the given index during initial parsing. This avoids a
1460
- pointless recomputation of the metadata when finishing a header. We read the
1461
- cached value in get_precomputed_md_for_idx(). */
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;
1466
- #ifndef NDEBUG
1467
- precomputed_md_index_ = index_;
1468
- #endif
1469
- }
1260
+ /* PUBLIC INTERFACE */
1470
1261
 
1471
- /* Determines if a metadata element key associated with the current parser index
1472
- is a binary indexed header during string parsing. We'll need to revisit this
1473
- metadata when we're done parsing, so we cache the metadata for this index
1474
- here using set_precomputed_md_idx(). */
1475
- grpc_error_handle HPackParser::IsBinaryIndexedHeader(bool* is) {
1476
- grpc_mdelem elem = grpc_chttp2_hptbl_lookup(&table_, index_);
1477
- if (GPR_UNLIKELY(GRPC_MDISNULL(elem))) {
1478
- return InvalidHPackIndexError();
1479
- }
1480
- /* We know that GRPC_MDKEY(elem) points to a reference counted slice since:
1481
- * 1. elem was a result of grpc_chttp2_hptbl_lookup
1482
- * 2. An item in this table is either static (see entries with
1483
- * index < GRPC_CHTTP2_LAST_STATIC_ENTRY or added via
1484
- * grpc_chttp2_hptbl_add).
1485
- * 3. If added via grpc_chttp2_hptbl_add, the entry is either static or
1486
- * interned.
1487
- * 4. Both static and interned element slices have non-null refcounts. */
1488
- *is = grpc_is_refcounted_slice_binary_header(GRPC_MDKEY(elem));
1489
- SetPrecomputedMDIndex(elem);
1490
- return GRPC_ERROR_NONE;
1491
- }
1262
+ HPackParser::HPackParser() = default;
1492
1263
 
1493
- /* parse the value string */
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_);
1500
- }
1264
+ HPackParser::~HPackParser() = default;
1501
1265
 
1502
- grpc_error_handle HPackParser::parse_value_string_with_indexed_key(
1503
- const uint8_t* cur, const uint8_t* end) {
1504
- bool is_binary = false;
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);
1266
+ void HPackParser::BeginFrame(Sink sink, Boundary boundary, Priority priority) {
1267
+ sink_ = std::move(sink);
1268
+ boundary_ = boundary;
1269
+ priority_ = priority;
1270
+ dynamic_table_updates_allowed_ = 2;
1508
1271
  }
1509
1272
 
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());
1273
+ grpc_error_handle HPackParser::Parse(const grpc_slice& slice, bool is_last) {
1274
+ if (GPR_UNLIKELY(!unparsed_bytes_.empty())) {
1275
+ std::vector<uint8_t> buffer = std::move(unparsed_bytes_);
1276
+ buffer.insert(buffer.end(), GRPC_SLICE_START_PTR(slice),
1277
+ GRPC_SLICE_END_PTR(slice));
1278
+ return ParseInput(
1279
+ Input(nullptr, buffer.data(), buffer.data() + buffer.size()), is_last);
1280
+ }
1281
+ return ParseInput(Input(slice.refcount, GRPC_SLICE_START_PTR(slice),
1282
+ GRPC_SLICE_END_PTR(slice)),
1283
+ is_last);
1513
1284
  }
1514
1285
 
1515
- /* PUBLIC INTERFACE */
1516
-
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;
1527
- /* Cached metadata for the current index the parser is handling. This is set
1528
- to 0 initially, invalidated when the index changes, and invalidated when it
1529
- is read (by get_precomputed_md_for_idx()). It is set during string parsing,
1530
- by set_precomputed_md_idx() - which is called by parse_value_string().
1531
- The goal here is to avoid recomputing the metadata for the index when
1532
- finishing with a header as well as the initial parse. */
1533
- md_for_index_.payload = 0;
1534
- #ifndef NDEBUG
1535
- /* In debug mode, this ensures that the cached metadata we're reading is in
1536
- * fact correct for the index we are examining. */
1537
- precomputed_md_index_ = -1;
1538
- #endif
1539
- dynamic_table_updates_allowed_ = 2;
1540
- last_error_ = GRPC_ERROR_NONE;
1286
+ grpc_error_handle HPackParser::ParseInput(Input input, bool is_last) {
1287
+ if (ParseInputInner(&input)) {
1288
+ return GRPC_ERROR_NONE;
1289
+ }
1290
+ if (input.eof_error()) {
1291
+ if (GPR_UNLIKELY(is_last && is_boundary())) {
1292
+ return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1293
+ "Incomplete header at the end of a header/continuation sequence");
1294
+ }
1295
+ unparsed_bytes_ = std::vector<uint8_t>(input.frontier(), input.end_ptr());
1296
+ return GRPC_ERROR_NONE;
1297
+ }
1298
+ return input.TakeError();
1541
1299
  }
1542
1300
 
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;
1301
+ bool HPackParser::ParseInputInner(Input* input) {
1302
+ switch (priority_) {
1551
1303
  case Priority::None:
1552
1304
  break;
1305
+ case Priority::Included: {
1306
+ if (input->remaining() < 5) return input->UnexpectedEOF(false);
1307
+ input->Advance(5);
1308
+ input->UpdateFrontier();
1309
+ priority_ = Priority::None;
1310
+ }
1553
1311
  }
1554
- }
1555
-
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);
1563
- }
1564
-
1565
- grpc_error_handle HPackParser::Parse(const grpc_slice& slice) {
1566
- /* max number of bytes to parse at a time... limits call stack depth on
1567
- * compilers without TCO */
1568
- #define MAX_PARSE_LENGTH 1024
1569
- current_slice_refcount_ = slice.refcount;
1570
- const uint8_t* start = GRPC_SLICE_START_PTR(slice);
1571
- const uint8_t* end = GRPC_SLICE_END_PTR(slice);
1572
- grpc_error_handle error = GRPC_ERROR_NONE;
1573
- while (start != end && error == GRPC_ERROR_NONE) {
1574
- const uint8_t* target = start + GPR_MIN(MAX_PARSE_LENGTH, end - start);
1575
- error = (this->*state_)(start, target);
1576
- start = target;
1312
+ while (!input->end_of_stream()) {
1313
+ if (GPR_UNLIKELY(
1314
+ !Parser(input, &sink_, &table_, &dynamic_table_updates_allowed_)
1315
+ .Parse())) {
1316
+ return false;
1317
+ }
1318
+ input->UpdateFrontier();
1577
1319
  }
1578
- current_slice_refcount_ = nullptr;
1579
- return error;
1320
+ return true;
1580
1321
  }
1581
1322
 
1323
+ void HPackParser::FinishFrame() { sink_ = Sink(); }
1324
+
1582
1325
  } // namespace grpc_core
1583
1326
 
1584
1327
  // TODO(ctiller): this serves as an eviction notice for the remainder of this
@@ -1630,15 +1373,11 @@ grpc_error_handle grpc_chttp2_header_parser_parse(void* hpack_parser,
1630
1373
  if (s != nullptr) {
1631
1374
  s->stats.incoming.header_bytes += GRPC_SLICE_LENGTH(slice);
1632
1375
  }
1633
- grpc_error_handle error = parser->Parse(slice);
1376
+ grpc_error_handle error = parser->Parse(slice, is_last != 0);
1634
1377
  if (error != GRPC_ERROR_NONE) {
1635
1378
  return error;
1636
1379
  }
1637
1380
  if (is_last) {
1638
- if (parser->is_boundary() && !parser->is_in_begin_state()) {
1639
- return GRPC_ERROR_CREATE_FROM_STATIC_STRING(
1640
- "end of header frame not aligned with a hpack record boundary");
1641
- }
1642
1381
  /* need to check for null stream: this can occur if we receive an invalid
1643
1382
  stream id on a header */
1644
1383
  if (s != nullptr) {