grpc 1.78.0 → 1.80.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (431) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +22 -8
  3. data/include/grpc/credentials.h +47 -37
  4. data/include/grpc/credentials_cpp.h +39 -0
  5. data/include/grpc/event_engine/event_engine.h +8 -3
  6. data/include/grpc/grpc.h +4 -0
  7. data/include/grpc/impl/call.h +9 -0
  8. data/include/grpc/impl/channel_arg_names.h +7 -0
  9. data/include/grpc/module.modulemap +2 -0
  10. data/include/grpc/private_key_signer.h +104 -0
  11. data/include/grpc/support/port_platform.h +6 -0
  12. data/src/core/call/call_filters.h +101 -78
  13. data/src/core/call/call_spine.h +91 -68
  14. data/src/core/call/call_state.h +60 -4
  15. data/src/core/call/client_call.cc +9 -9
  16. data/src/core/call/client_call.h +1 -1
  17. data/src/core/call/metadata_batch.cc +2 -0
  18. data/src/core/call/metadata_batch.h +48 -1
  19. data/src/core/call/metadata_info.cc +35 -0
  20. data/src/core/call/metadata_info.h +2 -0
  21. data/src/core/call/simple_slice_based_metadata.h +2 -1
  22. data/src/core/channelz/channelz.cc +9 -6
  23. data/src/core/channelz/channelz.h +7 -4
  24. data/src/core/channelz/property_list.h +5 -0
  25. data/src/core/channelz/v2tov1/convert.cc +1 -1
  26. data/src/core/channelz/v2tov1/legacy_api.cc +164 -307
  27. data/src/core/client_channel/buffered_call.cc +7 -3
  28. data/src/core/client_channel/buffered_call.h +11 -5
  29. data/src/core/client_channel/client_channel.cc +106 -44
  30. data/src/core/client_channel/client_channel.h +3 -6
  31. data/src/core/client_channel/client_channel_filter.cc +90 -64
  32. data/src/core/client_channel/client_channel_filter.h +3 -6
  33. data/src/core/client_channel/client_channel_internal.h +5 -0
  34. data/src/core/client_channel/config_selector.h +17 -12
  35. data/src/core/client_channel/dynamic_filters.cc +8 -7
  36. data/src/core/client_channel/dynamic_filters.h +7 -5
  37. data/src/core/client_channel/retry_filter.cc +1 -1
  38. data/src/core/client_channel/retry_filter.h +2 -2
  39. data/src/core/client_channel/subchannel.cc +1682 -266
  40. data/src/core/client_channel/subchannel.h +411 -134
  41. data/src/core/client_channel/subchannel_stream_client.cc +22 -18
  42. data/src/core/client_channel/subchannel_stream_client.h +8 -9
  43. data/src/core/client_channel/subchannel_stream_limiter.cc +76 -0
  44. data/src/core/client_channel/subchannel_stream_limiter.h +51 -0
  45. data/src/core/config/config_vars.cc +9 -1
  46. data/src/core/config/config_vars.h +6 -0
  47. data/src/core/credentials/call/call_creds_registry.h +51 -22
  48. data/src/core/credentials/call/call_creds_registry_init.cc +86 -2
  49. data/src/core/credentials/call/external/aws_external_account_credentials.cc +2 -2
  50. data/src/core/credentials/call/external/external_account_credentials.cc +11 -4
  51. data/src/core/credentials/call/external/file_external_account_credentials.cc +2 -2
  52. data/src/core/credentials/transport/channel_creds_registry.h +71 -20
  53. data/src/core/credentials/transport/channel_creds_registry_init.cc +338 -29
  54. data/src/core/credentials/transport/ssl/ssl_credentials.cc +43 -24
  55. data/src/core/credentials/transport/ssl/ssl_credentials.h +7 -1
  56. data/src/core/credentials/transport/ssl/ssl_security_connector.cc +2 -8
  57. data/src/core/credentials/transport/ssl/ssl_security_connector.h +4 -3
  58. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.cc +25 -5
  59. data/src/core/credentials/transport/tls/grpc_tls_certificate_distributor.h +7 -5
  60. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.cc +181 -109
  61. data/src/core/credentials/transport/tls/grpc_tls_certificate_provider.h +55 -42
  62. data/src/core/credentials/transport/tls/grpc_tls_credentials_options.cc +28 -23
  63. data/src/core/credentials/transport/tls/grpc_tls_credentials_options.h +26 -23
  64. data/src/core/credentials/transport/tls/spiffe_utils.cc +2 -2
  65. data/src/core/credentials/transport/tls/ssl_utils.cc +18 -18
  66. data/src/core/credentials/transport/tls/ssl_utils.h +12 -10
  67. data/src/core/credentials/transport/tls/tls_security_connector.cc +106 -74
  68. data/src/core/credentials/transport/tls/tls_security_connector.h +12 -8
  69. data/src/core/credentials/transport/xds/xds_credentials.cc +76 -32
  70. data/src/core/credentials/transport/xds/xds_credentials.h +4 -2
  71. data/src/core/ext/filters/fault_injection/fault_injection_filter.cc +117 -35
  72. data/src/core/ext/filters/fault_injection/fault_injection_filter.h +42 -4
  73. data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.cc +58 -29
  74. data/src/core/ext/filters/gcp_authentication/gcp_authentication_filter.h +19 -11
  75. data/src/core/ext/filters/stateful_session/stateful_session_filter.cc +82 -25
  76. data/src/core/ext/filters/stateful_session/stateful_session_filter.h +28 -3
  77. data/src/core/ext/filters/stateful_session/stateful_session_service_config_parser.cc +9 -7
  78. data/src/core/ext/filters/stateful_session/stateful_session_service_config_parser.h +1 -1
  79. data/src/core/ext/transport/chttp2/transport/call_tracer_wrapper.h +7 -1
  80. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +117 -67
  81. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +2 -0
  82. data/src/core/ext/transport/chttp2/transport/flow_control.h +11 -1
  83. data/src/core/ext/transport/chttp2/transport/frame.cc +2 -15
  84. data/src/core/ext/transport/chttp2/transport/frame.h +0 -4
  85. data/src/core/ext/transport/chttp2/transport/goaway.cc +17 -2
  86. data/src/core/ext/transport/chttp2/transport/goaway.h +27 -6
  87. data/src/core/ext/transport/chttp2/transport/header_assembler.h +8 -21
  88. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +101 -40
  89. data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +95 -0
  90. data/src/core/ext/transport/chttp2/transport/http2_client_transport.cc +923 -772
  91. data/src/core/ext/transport/chttp2/transport/http2_client_transport.h +406 -423
  92. data/src/core/ext/transport/chttp2/transport/http2_settings.cc +1 -0
  93. data/src/core/ext/transport/chttp2/transport/http2_settings.h +8 -1
  94. data/src/core/ext/transport/chttp2/transport/http2_settings_promises.h +25 -13
  95. data/src/core/ext/transport/chttp2/transport/http2_transport.cc +71 -24
  96. data/src/core/ext/transport/chttp2/transport/http2_transport.h +25 -49
  97. data/src/core/ext/transport/chttp2/transport/http2_ztrace_collector.h +2 -2
  98. data/src/core/ext/transport/chttp2/transport/incoming_metadata_tracker.h +29 -9
  99. data/src/core/ext/transport/chttp2/transport/internal.h +6 -2
  100. data/src/core/ext/transport/chttp2/transport/keepalive.cc +14 -20
  101. data/src/core/ext/transport/chttp2/transport/keepalive.h +9 -6
  102. data/src/core/ext/transport/chttp2/transport/parsing.cc +11 -0
  103. data/src/core/ext/transport/chttp2/transport/ping_promise.cc +34 -74
  104. data/src/core/ext/transport/chttp2/transport/ping_promise.h +123 -79
  105. data/src/core/ext/transport/chttp2/transport/security_frame.h +233 -3
  106. data/src/core/ext/transport/chttp2/transport/stream.h +152 -73
  107. data/src/core/ext/transport/chttp2/transport/stream_data_queue.h +155 -85
  108. data/src/core/ext/transport/chttp2/transport/transport_common.h +0 -5
  109. data/src/core/ext/transport/chttp2/transport/writable_streams.h +8 -7
  110. data/src/core/ext/transport/chttp2/transport/write_cycle.cc +86 -0
  111. data/src/core/ext/transport/chttp2/transport/write_cycle.h +355 -0
  112. data/src/core/ext/transport/chttp2/transport/writing.cc +31 -29
  113. data/src/core/ext/upb-gen/cel/expr/checked.upb.h +1875 -0
  114. data/src/core/ext/upb-gen/cel/expr/checked.upb_minitable.c +409 -0
  115. data/src/core/ext/upb-gen/cel/expr/checked.upb_minitable.h +56 -0
  116. data/src/core/ext/upb-gen/cel/expr/syntax.upb.h +2223 -0
  117. data/src/core/ext/upb-gen/cel/expr/syntax.upb_minitable.c +489 -0
  118. data/src/core/ext/upb-gen/cel/expr/syntax.upb_minitable.h +60 -0
  119. data/src/core/ext/upb-gen/envoy/config/accesslog/v3/accesslog.upb.h +2 -1
  120. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb.h +130 -18
  121. data/src/core/ext/upb-gen/envoy/config/bootstrap/v3/bootstrap.upb_minitable.c +18 -13
  122. data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb.h +70 -38
  123. data/src/core/ext/upb-gen/envoy/config/cluster/v3/cluster.upb_minitable.c +20 -17
  124. data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb.h +26 -10
  125. data/src/core/ext/upb-gen/envoy/config/common/matcher/v3/matcher.upb_minitable.c +8 -7
  126. data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb.h +495 -0
  127. data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb_minitable.c +114 -0
  128. data/src/core/ext/upb-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upb_minitable.h +36 -0
  129. data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb.h +26 -10
  130. data/src/core/ext/upb-gen/envoy/config/core/v3/address.upb_minitable.c +8 -7
  131. data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb.h +121 -0
  132. data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb_minitable.c +54 -0
  133. data/src/core/ext/upb-gen/envoy/config/core/v3/cel.upb_minitable.h +32 -0
  134. data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb.h +143 -9
  135. data/src/core/ext/upb-gen/envoy/config/core/v3/grpc_service.upb_minitable.c +18 -6
  136. data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb.h +112 -11
  137. data/src/core/ext/upb-gen/envoy/config/core/v3/protocol.upb_minitable.c +22 -9
  138. data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb.h +276 -0
  139. data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb_minitable.c +60 -5
  140. data/src/core/ext/upb-gen/envoy/config/core/v3/proxy_protocol.upb_minitable.h +4 -0
  141. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb.h +72 -0
  142. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb_minitable.c +23 -2
  143. data/src/core/ext/upb-gen/envoy/config/endpoint/v3/endpoint_components.upb_minitable.h +2 -0
  144. data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb.h +129 -13
  145. data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.c +36 -10
  146. data/src/core/ext/upb-gen/envoy/config/listener/v3/listener.upb_minitable.h +2 -0
  147. data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb.h +30 -0
  148. data/src/core/ext/upb-gen/envoy/config/listener/v3/quic_config.upb_minitable.c +5 -3
  149. data/src/core/ext/upb-gen/envoy/config/metrics/v3/metrics_service.upb.h +16 -0
  150. data/src/core/ext/upb-gen/envoy/config/metrics/v3/metrics_service.upb_minitable.c +4 -3
  151. data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb.h +31 -0
  152. data/src/core/ext/upb-gen/envoy/config/metrics/v3/stats.upb_minitable.c +5 -3
  153. data/src/core/ext/upb-gen/envoy/config/overload/v3/overload.upb.h +2 -1
  154. data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb.h +63 -0
  155. data/src/core/ext/upb-gen/envoy/config/rbac/v3/rbac.upb_minitable.c +12 -7
  156. data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb.h +97 -81
  157. data/src/core/ext/upb-gen/envoy/config/route/v3/route.upb_minitable.c +40 -23
  158. data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb.h +604 -228
  159. data/src/core/ext/upb-gen/envoy/config/route/v3/route_components.upb_minitable.c +146 -100
  160. data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb.h +30 -0
  161. data/src/core/ext/upb-gen/envoy/config/tap/v3/common.upb_minitable.c +5 -3
  162. data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb.h +35 -3
  163. data/src/core/ext/upb-gen/envoy/config/trace/v3/opentelemetry.upb_minitable.c +7 -4
  164. data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb.h +66 -14
  165. data/src/core/ext/upb-gen/envoy/config/trace/v3/zipkin.upb_minitable.c +22 -11
  166. data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb.h +87 -0
  167. data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb_minitable.c +29 -2
  168. data/src/core/ext/upb-gen/envoy/extensions/clusters/aggregate/v3/cluster.upb_minitable.h +2 -0
  169. data/src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb.h +0 -1
  170. data/src/core/ext/upb-gen/envoy/extensions/filters/http/rbac/v3/rbac.upb_minitable.c +0 -1
  171. data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb.h +20 -4
  172. data/src/core/ext/upb-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upb_minitable.c +5 -4
  173. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb.h +239 -60
  174. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.c +59 -28
  175. data/src/core/ext/upb-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upb_minitable.h +2 -0
  176. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb.h +89 -0
  177. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb_minitable.c +50 -0
  178. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/call_credentials/access_token/v3/access_token_credentials.upb_minitable.h +32 -0
  179. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb.h +135 -0
  180. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb_minitable.c +53 -0
  181. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/tls/v3/tls_credentials.upb_minitable.h +32 -0
  182. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb.h +105 -0
  183. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb_minitable.c +51 -0
  184. data/src/core/ext/upb-gen/envoy/extensions/grpc_service/channel_credentials/xds/v3/xds_credentials.upb_minitable.h +32 -0
  185. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb.h +32 -0
  186. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/client_side_weighted_round_robin/v3/client_side_weighted_round_robin.upb_minitable.c +6 -3
  187. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb.h +206 -0
  188. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.c +41 -8
  189. data/src/core/ext/upb-gen/envoy/extensions/load_balancing_policies/common/v3/common.upb_minitable.h +2 -0
  190. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb.h +64 -0
  191. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/common.upb_minitable.c +4 -3
  192. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb.h +64 -0
  193. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb_minitable.c +31 -5
  194. data/src/core/ext/upb-gen/envoy/extensions/transport_sockets/tls/v3/secret.upb_minitable.h +2 -0
  195. data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb.h +283 -14
  196. data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.c +48 -11
  197. data/src/core/ext/upb-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upb_minitable.h +2 -0
  198. data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb.h +144 -6
  199. data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb_minitable.c +35 -7
  200. data/src/core/ext/upb-gen/envoy/type/http/v3/cookie.upb_minitable.h +2 -0
  201. data/src/core/ext/upb-gen/envoy/type/tracing/v3/custom_tag.upb.h +42 -21
  202. data/src/core/ext/upb-gen/envoy/type/tracing/v3/custom_tag.upb_minitable.c +9 -8
  203. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb.h +164 -1
  204. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.c +37 -6
  205. data/src/core/ext/upb-gen/src/proto/grpc/channelz/v2/promise.upb_minitable.h +2 -0
  206. data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb.h +0 -1
  207. data/src/core/ext/upb-gen/xds/type/matcher/v3/cel.upb_minitable.c +0 -1
  208. data/src/core/ext/upb-gen/xds/type/matcher/v3/http_inputs.upb.h +0 -1
  209. data/src/core/ext/upb-gen/xds/type/matcher/v3/http_inputs.upb_minitable.c +0 -1
  210. data/src/core/ext/upb-gen/xds/type/matcher/v3/matcher.upb.h +26 -11
  211. data/src/core/ext/upb-gen/xds/type/matcher/v3/matcher.upb_minitable.c +8 -8
  212. data/src/core/ext/upb-gen/xds/type/matcher/v3/string.upb.h +33 -0
  213. data/src/core/ext/upb-gen/xds/type/matcher/v3/string.upb_minitable.c +14 -3
  214. data/src/core/ext/upb-gen/xds/type/v3/cel.upb.h +90 -10
  215. data/src/core/ext/upb-gen/xds/type/v3/cel.upb_minitable.c +18 -7
  216. data/src/core/ext/upbdefs-gen/cel/expr/checked.upbdefs.c +248 -0
  217. data/src/core/ext/upbdefs-gen/cel/expr/checked.upbdefs.h +97 -0
  218. data/src/core/ext/upbdefs-gen/cel/expr/syntax.upbdefs.c +283 -0
  219. data/src/core/ext/upbdefs-gen/cel/expr/syntax.upbdefs.h +107 -0
  220. data/src/core/ext/upbdefs-gen/envoy/config/accesslog/v3/accesslog.upbdefs.c +213 -211
  221. data/src/core/ext/upbdefs-gen/envoy/config/bootstrap/v3/bootstrap.upbdefs.c +635 -614
  222. data/src/core/ext/upbdefs-gen/envoy/config/cluster/v3/cluster.upbdefs.c +1012 -1000
  223. data/src/core/ext/upbdefs-gen/envoy/config/common/matcher/v3/matcher.upbdefs.c +276 -273
  224. data/src/core/ext/upbdefs-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upbdefs.c +152 -0
  225. data/src/core/ext/upbdefs-gen/envoy/config/common/mutation_rules/v3/mutation_rules.upbdefs.h +47 -0
  226. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/address.upbdefs.c +149 -144
  227. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/base.upbdefs.c +367 -370
  228. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/cel.upbdefs.c +63 -0
  229. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/cel.upbdefs.h +37 -0
  230. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/grpc_service.upbdefs.c +297 -284
  231. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/protocol.upbdefs.c +492 -469
  232. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.c +74 -43
  233. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/proxy_protocol.upbdefs.h +10 -0
  234. data/src/core/ext/upbdefs-gen/envoy/config/core/v3/substitution_format_string.upbdefs.c +60 -59
  235. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.c +202 -184
  236. data/src/core/ext/upbdefs-gen/envoy/config/endpoint/v3/endpoint_components.upbdefs.h +5 -0
  237. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.c +354 -339
  238. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/listener.upbdefs.h +5 -0
  239. data/src/core/ext/upbdefs-gen/envoy/config/listener/v3/quic_config.upbdefs.c +28 -19
  240. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/metrics_service.upbdefs.c +30 -27
  241. data/src/core/ext/upbdefs-gen/envoy/config/metrics/v3/stats.upbdefs.c +71 -66
  242. data/src/core/ext/upbdefs-gen/envoy/config/overload/v3/overload.upbdefs.c +94 -91
  243. data/src/core/ext/upbdefs-gen/envoy/config/rbac/v3/rbac.upbdefs.c +386 -369
  244. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route.upbdefs.c +60 -57
  245. data/src/core/ext/upbdefs-gen/envoy/config/route/v3/route_components.upbdefs.c +1974 -1884
  246. data/src/core/ext/upbdefs-gen/envoy/config/tap/v3/common.upbdefs.c +119 -112
  247. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/opentelemetry.upbdefs.c +62 -51
  248. data/src/core/ext/upbdefs-gen/envoy/config/trace/v3/zipkin.upbdefs.c +109 -88
  249. data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.c +54 -36
  250. data/src/core/ext/upbdefs-gen/envoy/extensions/clusters/aggregate/v3/cluster.upbdefs.h +5 -0
  251. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/rbac/v3/rbac.upbdefs.c +78 -84
  252. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/http/stateful_session/v3/stateful_session.upbdefs.c +48 -46
  253. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.c +1041 -984
  254. data/src/core/ext/upbdefs-gen/envoy/extensions/filters/network/http_connection_manager/v3/http_connection_manager.upbdefs.h +5 -0
  255. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/common.upbdefs.c +304 -290
  256. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.c +94 -77
  257. data/src/core/ext/upbdefs-gen/envoy/extensions/transport_sockets/tls/v3/secret.upbdefs.h +5 -0
  258. data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.c +246 -193
  259. data/src/core/ext/upbdefs-gen/envoy/extensions/upstreams/http/v3/http_protocol_options.upbdefs.h +5 -0
  260. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.c +37 -23
  261. data/src/core/ext/upbdefs-gen/envoy/type/http/v3/cookie.upbdefs.h +5 -0
  262. data/src/core/ext/upbdefs-gen/envoy/type/tracing/v3/custom_tag.upbdefs.c +5 -3
  263. data/src/core/ext/upbdefs-gen/google/api/http.upbdefs.c +4 -4
  264. data/src/core/ext/upbdefs-gen/google/api/httpbody.upbdefs.c +4 -5
  265. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/promise.upbdefs.c +113 -87
  266. data/src/core/ext/upbdefs-gen/src/proto/grpc/channelz/v2/promise.upbdefs.h +5 -0
  267. data/src/core/ext/upbdefs-gen/udpa/annotations/migrate.upbdefs.c +5 -5
  268. data/src/core/ext/upbdefs-gen/udpa/annotations/security.upbdefs.c +6 -5
  269. data/src/core/ext/upbdefs-gen/udpa/annotations/sensitive.upbdefs.c +5 -5
  270. data/src/core/ext/upbdefs-gen/udpa/annotations/status.upbdefs.c +5 -5
  271. data/src/core/ext/upbdefs-gen/udpa/annotations/versioning.upbdefs.c +5 -5
  272. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/cel.upbdefs.c +25 -30
  273. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/http_inputs.upbdefs.c +14 -20
  274. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/matcher.upbdefs.c +180 -183
  275. data/src/core/ext/upbdefs-gen/xds/type/matcher/v3/string.upbdefs.c +56 -47
  276. data/src/core/ext/upbdefs-gen/xds/type/v3/cel.upbdefs.c +69 -47
  277. data/src/core/filter/filter_chain.h +95 -0
  278. data/src/core/handshaker/http_connect/{http_connect_handshaker.cc → http_connect_client_handshaker.cc} +32 -31
  279. data/src/core/handshaker/http_connect/{http_connect_handshaker.h → http_connect_client_handshaker.h} +4 -4
  280. data/src/core/handshaker/http_connect/http_proxy_mapper.cc +1 -1
  281. data/src/core/handshaker/http_connect/xds_http_proxy_mapper.cc +1 -1
  282. data/src/core/handshaker/security/pipelined_secure_endpoint.cc +14 -13
  283. data/src/core/handshaker/security/secure_endpoint.cc +282 -68
  284. data/src/core/handshaker/security/secure_endpoint.h +0 -7
  285. data/src/core/lib/channel/channel_args.h +1 -1
  286. data/src/core/lib/channel/promise_based_filter.cc +17 -4
  287. data/src/core/lib/channel/promise_based_filter.h +3 -2
  288. data/src/core/lib/debug/trace_flags.cc +2 -0
  289. data/src/core/lib/debug/trace_flags.h +1 -0
  290. data/src/core/lib/event_engine/cf_engine/cfstream_endpoint.cc +35 -8
  291. data/src/core/lib/event_engine/cf_engine/dns_service_resolver.h +1 -2
  292. data/src/core/lib/event_engine/event_engine.cc +9 -0
  293. data/src/core/lib/event_engine/extensions/tcp_trace.h +0 -3
  294. data/src/core/lib/event_engine/posix_engine/ev_poll_posix.cc +2 -2
  295. data/src/core/lib/event_engine/posix_engine/posix_endpoint.h +1 -1
  296. data/src/core/lib/event_engine/posix_engine/posix_engine.cc +34 -9
  297. data/src/core/lib/event_engine/posix_engine/posix_engine.h +24 -2
  298. data/src/core/lib/event_engine/posix_engine/posix_engine_listener.cc +1 -3
  299. data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.cc +141 -14
  300. data/src/core/lib/event_engine/posix_engine/posix_engine_listener_utils.h +19 -2
  301. data/src/core/lib/event_engine/posix_engine/posix_interface.h +7 -0
  302. data/src/core/lib/event_engine/posix_engine/posix_interface_posix.cc +21 -3
  303. data/src/core/lib/event_engine/posix_engine/posix_interface_windows.cc +16 -0
  304. data/src/core/lib/experiments/experiments.cc +309 -201
  305. data/src/core/lib/experiments/experiments.h +141 -80
  306. data/src/core/lib/iomgr/event_engine_shims/endpoint.cc +2 -2
  307. data/src/core/lib/iomgr/resolve_address.h +0 -2
  308. data/src/core/lib/iomgr/resolved_address.h +0 -2
  309. data/src/core/lib/iomgr/tcp_posix.cc +13 -5
  310. data/src/core/lib/iomgr/tcp_server.cc +0 -5
  311. data/src/core/lib/iomgr/tcp_server.h +0 -7
  312. data/src/core/lib/iomgr/tcp_server_posix.cc +0 -17
  313. data/src/core/lib/iomgr/tcp_server_utils_posix.h +0 -3
  314. data/src/core/lib/iomgr/tcp_server_windows.cc +12 -51
  315. data/src/core/lib/promise/all_ok.h +17 -12
  316. data/src/core/lib/promise/cancel_callback.h +12 -13
  317. data/src/core/lib/promise/detail/join_state.h +626 -0
  318. data/src/core/lib/promise/detail/promise_factory.h +14 -14
  319. data/src/core/lib/promise/for_each.h +32 -8
  320. data/src/core/lib/promise/if.h +9 -7
  321. data/src/core/lib/promise/loop.h +18 -16
  322. data/src/core/lib/promise/map.h +54 -47
  323. data/src/core/lib/promise/mpsc.h +11 -10
  324. data/src/core/lib/promise/observable.h +6 -6
  325. data/src/core/lib/promise/party.h +25 -19
  326. data/src/core/lib/promise/poll.h +5 -5
  327. data/src/core/lib/promise/prioritized_race.h +10 -7
  328. data/src/core/lib/promise/promise.h +16 -11
  329. data/src/core/lib/promise/race.h +6 -5
  330. data/src/core/lib/promise/seq.h +109 -74
  331. data/src/core/lib/promise/try_join.h +14 -6
  332. data/src/core/lib/promise/try_seq.h +76 -60
  333. data/src/core/lib/resource_quota/api.cc +7 -0
  334. data/src/core/lib/resource_quota/arena.h +1 -1
  335. data/src/core/lib/resource_quota/memory_quota.cc +4 -1
  336. data/src/core/lib/resource_quota/resource_quota.cc +2 -1
  337. data/src/core/lib/resource_quota/resource_quota.h +3 -0
  338. data/src/core/lib/resource_quota/stream_quota.cc +77 -1
  339. data/src/core/lib/resource_quota/stream_quota.h +64 -1
  340. data/src/core/lib/resource_quota/telemetry.h +1 -1
  341. data/src/core/lib/surface/call.cc +13 -0
  342. data/src/core/lib/surface/call_utils.h +58 -43
  343. data/src/core/lib/surface/channel.h +1 -4
  344. data/src/core/lib/surface/completion_queue.cc +13 -6
  345. data/src/core/lib/surface/validate_metadata.cc +20 -15
  346. data/src/core/lib/surface/validate_metadata.h +3 -1
  347. data/src/core/lib/surface/version.cc +2 -2
  348. data/src/core/lib/transport/promise_endpoint.cc +1 -1
  349. data/src/core/lib/transport/promise_endpoint.h +1 -1
  350. data/src/core/lib/transport/transport.h +5 -0
  351. data/src/core/load_balancing/health_check_client.cc +1 -15
  352. data/src/core/load_balancing/health_check_client_internal.h +0 -2
  353. data/src/core/load_balancing/oob_backend_metric.cc +1 -5
  354. data/src/core/load_balancing/oob_backend_metric_internal.h +0 -1
  355. data/src/core/load_balancing/xds/xds_cluster_impl.cc +12 -9
  356. data/src/core/plugin_registry/grpc_plugin_registry.cc +3 -2
  357. data/src/core/resolver/xds/xds_resolver.cc +162 -116
  358. data/src/core/server/server.cc +18 -1
  359. data/src/core/server/server.h +2 -0
  360. data/src/core/server/xds_server_config_fetcher.cc +4 -4
  361. data/src/core/telemetry/call_tracer.cc +87 -2
  362. data/src/core/telemetry/call_tracer.h +46 -8
  363. data/src/core/telemetry/instrument.cc +102 -40
  364. data/src/core/telemetry/instrument.h +246 -65
  365. data/src/core/tsi/fake_transport_security.cc +3 -1
  366. data/src/core/tsi/ssl_transport_security.cc +516 -137
  367. data/src/core/tsi/ssl_transport_security.h +28 -22
  368. data/src/core/tsi/ssl_transport_security_utils.cc +2 -2
  369. data/src/core/tsi/ssl_transport_security_utils.h +2 -2
  370. data/src/core/util/bitset.h +6 -0
  371. data/src/core/util/function_signature.h +3 -1
  372. data/src/core/util/http_client/httpcli_security_connector.cc +2 -1
  373. data/src/core/util/json/json_reader.cc +0 -4
  374. data/src/core/xds/grpc/certificate_provider_store.cc +2 -1
  375. data/src/core/xds/grpc/certificate_provider_store.h +3 -17
  376. data/src/core/xds/grpc/certificate_provider_store_interface.h +61 -0
  377. data/src/core/xds/grpc/xds_bootstrap_grpc.cc +48 -0
  378. data/src/core/xds/grpc/xds_bootstrap_grpc.h +18 -0
  379. data/src/core/xds/grpc/xds_certificate_provider.cc +7 -2
  380. data/src/core/xds/grpc/xds_certificate_provider.h +13 -2
  381. data/src/core/xds/grpc/xds_client_grpc.cc +13 -6
  382. data/src/core/xds/grpc/xds_client_grpc.h +10 -7
  383. data/src/core/xds/grpc/xds_cluster.cc +18 -4
  384. data/src/core/xds/grpc/xds_cluster.h +17 -2
  385. data/src/core/xds/grpc/xds_cluster_parser.cc +36 -11
  386. data/src/core/xds/grpc/xds_common_types.cc +45 -0
  387. data/src/core/xds/grpc/xds_common_types.h +31 -0
  388. data/src/core/xds/grpc/xds_common_types_parser.cc +274 -16
  389. data/src/core/xds/grpc/xds_common_types_parser.h +12 -0
  390. data/src/core/xds/grpc/xds_http_fault_filter.cc +128 -24
  391. data/src/core/xds/grpc/xds_http_fault_filter.h +19 -10
  392. data/src/core/xds/grpc/xds_http_filter.cc +38 -0
  393. data/src/core/xds/grpc/xds_http_filter.h +70 -47
  394. data/src/core/xds/grpc/xds_http_filter_registry.cc +48 -14
  395. data/src/core/xds/grpc/xds_http_filter_registry.h +29 -15
  396. data/src/core/xds/grpc/xds_http_gcp_authn_filter.cc +88 -22
  397. data/src/core/xds/grpc/xds_http_gcp_authn_filter.h +22 -11
  398. data/src/core/xds/grpc/xds_http_rbac_filter.cc +36 -20
  399. data/src/core/xds/grpc/xds_http_rbac_filter.h +19 -10
  400. data/src/core/xds/grpc/xds_http_stateful_session_filter.cc +143 -26
  401. data/src/core/xds/grpc/xds_http_stateful_session_filter.h +19 -10
  402. data/src/core/xds/grpc/xds_listener.cc +4 -1
  403. data/src/core/xds/grpc/xds_listener.h +10 -2
  404. data/src/core/xds/grpc/xds_listener_parser.cc +23 -18
  405. data/src/core/xds/grpc/xds_matcher.cc +40 -5
  406. data/src/core/xds/grpc/xds_matcher.h +13 -0
  407. data/src/core/xds/grpc/xds_matcher_action.h +1 -1
  408. data/src/core/xds/grpc/xds_matcher_parse.cc +60 -40
  409. data/src/core/xds/grpc/xds_matcher_parse.h +2 -1
  410. data/src/core/xds/grpc/xds_route_config.cc +12 -1
  411. data/src/core/xds/grpc/xds_route_config.h +15 -2
  412. data/src/core/xds/grpc/xds_route_config_parser.cc +11 -5
  413. data/src/core/xds/grpc/xds_routing.cc +181 -6
  414. data/src/core/xds/grpc/xds_routing.h +57 -0
  415. data/src/core/xds/grpc/xds_server_grpc.cc +55 -43
  416. data/src/core/xds/grpc/xds_server_grpc.h +13 -6
  417. data/src/core/xds/grpc/xds_server_grpc_interface.h +3 -2
  418. data/src/core/xds/grpc/xds_transport_grpc.cc +12 -6
  419. data/src/core/xds/grpc/xds_transport_grpc.h +5 -1
  420. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +12 -8
  421. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +18 -12
  422. data/src/ruby/lib/grpc/grpc.rb +7 -9
  423. data/src/ruby/lib/grpc/version.rb +1 -1
  424. data/src/ruby/pb/generate_proto_ruby.sh +1 -1
  425. data/src/ruby/spec/client_server_spec.rb +1 -1
  426. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +1 -1
  427. data/src/ruby/spec/generic/rpc_server_spec.rb +3 -4
  428. data/src/ruby/spec/spec_helper.rb +1 -1
  429. metadata +64 -14
  430. data/src/core/ext/transport/chttp2/transport/security_frame.cc +0 -31
  431. data/src/core/handshaker/security/legacy_secure_endpoint.cc +0 -597
@@ -27,7 +27,7 @@
27
27
  #include <cstdint>
28
28
  #include <memory>
29
29
  #include <optional>
30
- #include <string>
30
+ #include <type_traits>
31
31
  #include <utility>
32
32
  #include <vector>
33
33
 
@@ -46,73 +46,58 @@
46
46
  #include "src/core/ext/transport/chttp2/transport/incoming_metadata_tracker.h"
47
47
  #include "src/core/ext/transport/chttp2/transport/keepalive.h"
48
48
  #include "src/core/ext/transport/chttp2/transport/ping_promise.h"
49
+ #include "src/core/ext/transport/chttp2/transport/security_frame.h"
49
50
  #include "src/core/ext/transport/chttp2/transport/stream.h"
50
51
  #include "src/core/ext/transport/chttp2/transport/stream_data_queue.h"
51
52
  #include "src/core/ext/transport/chttp2/transport/writable_streams.h"
53
+ #include "src/core/ext/transport/chttp2/transport/write_cycle.h"
52
54
  #include "src/core/lib/channel/channel_args.h"
53
- #include "src/core/lib/iomgr/closure.h"
54
55
  #include "src/core/lib/iomgr/iomgr_fwd.h"
55
56
  #include "src/core/lib/promise/activity.h"
56
57
  #include "src/core/lib/promise/context.h"
57
- #include "src/core/lib/promise/if.h"
58
58
  #include "src/core/lib/promise/latch.h"
59
59
  #include "src/core/lib/promise/map.h"
60
60
  #include "src/core/lib/promise/party.h"
61
61
  #include "src/core/lib/promise/poll.h"
62
62
  #include "src/core/lib/promise/promise.h"
63
63
  #include "src/core/lib/promise/race.h"
64
- #include "src/core/lib/promise/try_seq.h"
65
64
  #include "src/core/lib/resource_quota/memory_quota.h"
66
- #include "src/core/lib/slice/slice.h"
67
65
  #include "src/core/lib/slice/slice_buffer.h"
68
66
  #include "src/core/lib/transport/connectivity_state.h"
69
67
  #include "src/core/lib/transport/promise_endpoint.h"
70
68
  #include "src/core/lib/transport/transport.h"
71
- #include "src/core/util/check_class_size.h"
72
69
  #include "src/core/util/debug_location.h"
73
- #include "src/core/util/grpc_check.h"
74
70
  #include "src/core/util/orphanable.h"
75
71
  #include "src/core/util/ref_counted_ptr.h"
76
72
  #include "src/core/util/sync.h"
77
73
  #include "src/core/util/time.h"
78
74
  #include "absl/base/thread_annotations.h"
79
75
  #include "absl/container/flat_hash_map.h"
80
- #include "absl/container/flat_hash_set.h"
81
76
  #include "absl/functional/any_invocable.h"
82
77
  #include "absl/log/log.h"
78
+ #include "absl/meta/type_traits.h"
83
79
  #include "absl/status/status.h"
84
80
  #include "absl/status/statusor.h"
85
81
  #include "absl/strings/string_view.h"
86
- #include "absl/types/span.h"
87
82
 
88
83
  namespace grpc_core {
89
84
  namespace http2 {
90
85
 
91
- // Http2 Client Transport Spawns Overview
92
-
93
- // | Promise Spawn | Max Duration | Promise Resolution | Max Spawns |
94
- // | | for Spawn | | |
95
- // |---------------------|--------------|-----------------------|------------|
96
- // | Endpoint Read Loop | Infinite | On transport close | One |
97
- // | Endpoint Write Loop | Infinite | On transport close | One |
98
- // | Stream Multiplexer | Infinite | On transport close | One |
99
- // | Close Transport | CloseTimeout | On transport close | One |
100
-
101
- // Max Party Slots (Always): 3
102
- // Max Promise Slots (Worst Case): 4
103
-
104
86
  // Experimental : The code will be written iteratively.
105
87
  // Do not use or edit any of these functions unless you are
106
88
  // familiar with the PH2 project (Moving chttp2 to promises.)
107
- // TODO(tjagtap) : [PH2][P3] : Update the experimental status of the code before
108
- // http2 rollout begins.
89
+ // TODO(tjagtap) : [PH2][P5] : Update the experimental status of the code when
90
+ // http2 rollout is completed.
109
91
  class Http2ClientTransport final : public ClientTransport,
110
92
  public channelz::DataSource {
111
- // TODO(akshitpatel) [PH2][P1] : Functions that need a mutex to be held should
112
- // have "locked" suffix in function name.
93
+ // TODO(tjagtap) : [PH2][P3] Move the definitions to the header for better
94
+ // inlining. For now definitions are in the cc file to
95
+ // reduce cognitive load in the header.
113
96
  public:
97
+ //////////////////////////////////////////////////////////////////////////////
98
+ // Constructor, Destructor etc.
114
99
  Http2ClientTransport(
115
- PromiseEndpoint endpoint, GRPC_UNUSED const ChannelArgs& channel_args,
100
+ PromiseEndpoint endpoint, const ChannelArgs& channel_args,
116
101
  std::shared_ptr<grpc_event_engine::experimental::EventEngine>
117
102
  event_engine,
118
103
  absl::AnyInvocable<void(absl::StatusOr<uint32_t>)> on_receive_settings);
@@ -128,97 +113,158 @@ class Http2ClientTransport final : public ClientTransport,
128
113
  ServerTransport* server_transport() override { return nullptr; }
129
114
  absl::string_view GetTransportName() const override { return "http2"; }
130
115
 
131
- // TODO(tjagtap) : [PH2][EXT] : These can be removed when event engine rollout
132
- // is complete.
116
+ //////////////////////////////////////////////////////////////////////////////
117
+ // Deprecated Stuff
118
+
119
+ // TODO(tjagtap) : [PH2][EXT] : Remove after event engine rollout
133
120
  void SetPollset(grpc_stream*, grpc_pollset*) override {}
134
121
  void SetPollsetSet(grpc_stream*, grpc_pollset_set*) override {}
135
122
 
123
+ //////////////////////////////////////////////////////////////////////////////
124
+ // Transport Functions
125
+
136
126
  // Called at the start of a stream.
137
127
  void StartCall(CallHandler call_handler) override;
138
128
 
139
129
  void PerformOp(grpc_transport_op*) override;
140
- void StartConnectivityWatch(
141
- grpc_connectivity_state state,
142
- OrphanablePtr<ConnectivityStateWatcherInterface> watcher);
143
- void StopConnectivityWatch(ConnectivityStateWatcherInterface* watcher);
144
-
145
- void StartWatch(RefCountedPtr<StateWatcher> watcher) override;
146
- void StopWatch(RefCountedPtr<StateWatcher> watcher) override;
147
130
 
148
131
  void Orphan() override;
149
132
 
150
- RefCountedPtr<channelz::SocketNode> GetSocketNode() const override {
151
- return const_cast<channelz::BaseNode*>(
152
- channelz::DataSource::channelz_node())
153
- ->RefAsSubclass<channelz::SocketNode>();
133
+ bool AreTransportFlowControlTokensAvailable() {
134
+ return flow_control_.remote_window() > 0;
154
135
  }
155
136
 
137
+ void SpawnTransportLoops();
138
+
139
+ //////////////////////////////////////////////////////////////////////////////
140
+ // Channelz and ZTrace
141
+
156
142
  std::unique_ptr<channelz::ZTrace> GetZTrace(absl::string_view name) override {
157
143
  if (name == "transport_frames") return ztrace_collector_->MakeZTrace();
158
144
  return nullptr;
159
145
  }
160
146
 
147
+ RefCountedPtr<channelz::SocketNode> GetSocketNode() const override;
148
+
161
149
  void AddData(channelz::DataSink sink) override;
162
150
  void SpawnAddChannelzData(RefCountedPtr<Party> party,
163
151
  channelz::DataSink sink);
164
152
 
165
- auto TestOnlyTriggerWriteCycle() {
166
- return Immediate(writable_stream_list_.ForceReadyForWrite());
153
+ //////////////////////////////////////////////////////////////////////////////
154
+ // Watchers
155
+
156
+ void StartWatch(RefCountedPtr<StateWatcher> watcher) override;
157
+ void StopWatch(RefCountedPtr<StateWatcher> watcher) override;
158
+
159
+ //////////////////////////////////////////////////////////////////////////////
160
+ // Test Only Functions
161
+
162
+ template <typename Factory>
163
+ void TestOnlySpawnPromise(absl::string_view name, Factory&& factory) {
164
+ SpawnInfallible(general_party_, name, std::forward<Factory>(factory));
167
165
  }
168
166
 
167
+ absl::Status TestOnlyTriggerWriteCycle() { return TriggerWriteCycle(); }
168
+
169
169
  auto TestOnlySendPing(absl::AnyInvocable<void()> on_initiate,
170
170
  bool important = false) {
171
171
  return ping_manager_->RequestPing(std::move(on_initiate), important);
172
172
  }
173
173
 
174
- template <typename Factory>
175
- void TestOnlySpawnPromise(absl::string_view name, Factory&& factory) {
176
- general_party_->Spawn(name, std::forward<Factory>(factory), [](Empty) {});
174
+ int64_t TestOnlyTransportFlowControlWindow();
175
+ int64_t TestOnlyGetStreamFlowControlWindow(const uint32_t stream_id);
176
+
177
+ private:
178
+ //////////////////////////////////////////////////////////////////////////////
179
+ // Endpoint Helpers
180
+
181
+ // Callers MUST ensure that the transport is not destroyed till the promise is
182
+ // resolved or cancelled.
183
+ GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION auto EndpointReadSlice(
184
+ const size_t num_bytes) {
185
+ return Map(endpoint_.ReadSlice(num_bytes),
186
+ [this, num_bytes](absl::StatusOr<Slice> status) {
187
+ OnEndpointRead(status.ok(), num_bytes);
188
+ return status;
189
+ });
177
190
  }
178
191
 
179
- int64_t TestOnlyTransportFlowControlWindow() {
180
- return flow_control_.remote_window();
192
+ // Callers MUST ensure that the transport is not destroyed till the promise is
193
+ // resolved or cancelled.
194
+ GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION auto EndpointRead(
195
+ const size_t num_bytes) {
196
+ return Map(endpoint_.Read(num_bytes),
197
+ [this, num_bytes](absl::StatusOr<SliceBuffer> status) {
198
+ OnEndpointRead(status.ok(), num_bytes);
199
+ return status;
200
+ });
181
201
  }
182
202
 
183
- int64_t TestOnlyGetStreamFlowControlWindow(const uint32_t stream_id) {
184
- RefCountedPtr<Stream> stream = LookupStream(stream_id);
185
- if (stream == nullptr) {
186
- return -1;
203
+ void OnEndpointRead(const bool is_ok, const size_t num_bytes) {
204
+ if (is_ok) {
205
+ keepalive_manager_->GotData();
206
+ ztrace_collector_->Append(PromiseEndpointReadTrace{num_bytes});
187
207
  }
188
- return stream->flow_control.remote_window_delta();
189
208
  }
190
209
 
191
- bool AreTransportFlowControlTokensAvailable() {
192
- return flow_control_.remote_window() > 0;
193
- }
194
- void SpawnTransportLoops();
210
+ auto EndpointWrite(SliceBuffer&& output_buf);
211
+
212
+ // Serialize and write the frames in the write cycle to the endpoint.
213
+ auto SerializeAndWrite();
214
+
215
+ //////////////////////////////////////////////////////////////////////////////
216
+ // Watchers
217
+
218
+ void StartConnectivityWatch(
219
+ grpc_connectivity_state state,
220
+ OrphanablePtr<ConnectivityStateWatcherInterface> watcher);
221
+
222
+ void StopConnectivityWatch(ConnectivityStateWatcherInterface* watcher);
223
+
224
+ void NotifyStateWatcherOnDisconnectLocked(
225
+ absl::Status status, StateWatcher::DisconnectInfo disconnect_info)
226
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(&transport_mutex_);
227
+
228
+ //////////////////////////////////////////////////////////////////////////////
229
+ // Transport Read Path
230
+
231
+ // Synchronous functions for processing each type of frame
232
+ Http2Status ProcessIncomingFrame(Http2DataFrame&& frame);
233
+ Http2Status ProcessIncomingFrame(Http2HeaderFrame&& frame);
234
+ Http2Status ProcessIncomingFrame(Http2RstStreamFrame&& frame);
235
+ Http2Status ProcessIncomingFrame(Http2SettingsFrame&& frame);
236
+ Http2Status ProcessIncomingFrame(Http2PingFrame&& frame);
237
+ Http2Status ProcessIncomingFrame(Http2GoawayFrame&& frame);
238
+ Http2Status ProcessIncomingFrame(Http2WindowUpdateFrame&& frame);
239
+ Http2Status ProcessIncomingFrame(Http2ContinuationFrame&& frame);
240
+ Http2Status ProcessIncomingFrame(Http2SecurityFrame&& frame);
241
+ Http2Status ProcessIncomingFrame(Http2UnknownFrame&& frame);
242
+ Http2Status ProcessIncomingFrame(Http2EmptyFrame&& frame);
195
243
 
196
- private:
197
- // Promise factory for processing each type of frame
198
- Http2Status ProcessHttp2DataFrame(Http2DataFrame frame);
199
- Http2Status ProcessHttp2HeaderFrame(Http2HeaderFrame frame);
200
- Http2Status ProcessHttp2RstStreamFrame(Http2RstStreamFrame frame);
201
- Http2Status ProcessHttp2SettingsFrame(Http2SettingsFrame frame);
202
- auto ProcessHttp2PingFrame(Http2PingFrame frame);
203
- Http2Status ProcessHttp2GoawayFrame(Http2GoawayFrame frame);
204
- Http2Status ProcessHttp2WindowUpdateFrame(Http2WindowUpdateFrame frame);
205
- Http2Status ProcessHttp2ContinuationFrame(Http2ContinuationFrame frame);
206
- Http2Status ProcessHttp2SecurityFrame(Http2SecurityFrame frame);
207
244
  Http2Status ProcessMetadata(RefCountedPtr<Stream> stream);
208
245
 
209
- // Reading from the endpoint.
246
+ Http2Status ParseAndDiscardHeaders(SliceBuffer&& buffer, bool is_end_headers,
247
+ Stream* stream,
248
+ Http2Status&& original_status,
249
+ DebugLocation whence = {});
210
250
 
211
- // Returns a promise to keep reading in a Loop till a fail/close is
212
- // received.
213
- auto ReadLoop();
251
+ GPR_ATTRIBUTE_ALWAYS_INLINE_FUNCTION Http2Status
252
+ ProcessOneIncomingFrame(Http2Frame&& frame) {
253
+ GRPC_HTTP2_CLIENT_DLOG << "Http2ClientTransport::ProcessOneIncomingFrame";
254
+ return std::visit(
255
+ [this](auto&& frame) {
256
+ return ProcessIncomingFrame(std::forward<decltype(frame)>(frame));
257
+ },
258
+ std::forward<Http2Frame>(frame));
259
+ }
214
260
 
215
- // Returns a promise that will read and process one HTTP2 frame.
216
261
  auto ReadAndProcessOneFrame();
217
262
 
218
- // Returns a promise that will process one HTTP2 frame.
219
- auto ProcessOneFrame(Http2Frame frame);
263
+ // Returns a promise to keep reading in a Loop till a fail/close is received.
264
+ auto ReadLoop();
220
265
 
221
- // Writing to the endpoint.
266
+ //////////////////////////////////////////////////////////////////////////////
267
+ // Transport Write Path
222
268
 
223
269
  // Write time sensitive control frames to the endpoint. Frames sent from here
224
270
  // will be GOAWAY, SETTINGS, PING and PING acks, WINDOW_UPDATE and
@@ -227,10 +273,30 @@ class Http2ClientTransport final : public ClientTransport,
227
273
  // module needs to take action after the write (for cases like spawning
228
274
  // timeout promises), they MUST plug the call in the
229
275
  // NotifyControlFramesWriteDone.
230
- auto ProcessAndWriteControlFrames();
231
276
 
232
- // Notify the control frames modules that the endpoint write is done.
233
- void NotifyControlFramesWriteDone();
277
+ // Prepares all the HTTP2 control frames that are to be sent out in this write
278
+ // cycle. The modules can choose to either trigger an endpoint write for the
279
+ // frames or defer the write with the stream specific frames. In most cases,
280
+ // the frames are deferred and a single write is triggered for all the
281
+ // frames.
282
+ absl::Status PrepareControlFrames();
283
+
284
+ // If there are any urgent frames this would trigger an additional endpoint
285
+ // write. CAUTION: This will add significant overhead if used for non-urgent
286
+ // frames.
287
+ auto MaybeWriteUrgentFrames();
288
+
289
+ // Notify the modules that an endpoint write is done. This corresponds to the
290
+ // generic endpoint write that happens in the MultiplexerLoop.
291
+ void NotifyFramesWriteDone();
292
+
293
+ // Notify the modules that an urgent endpoint write is done. If some module
294
+ // add frames to this buffer in PrepareControlFrames, they can use this to
295
+ // do post processing after the write is done.
296
+ void NotifyUrgentFramesWriteDone();
297
+
298
+ absl::Status DequeueStreamFrames(RefCountedPtr<Stream> stream,
299
+ WriteCycle& write_cycle);
234
300
 
235
301
  // Returns a promise to keep draining control frames and data frames from all
236
302
  // the writable streams and write to the endpoint.
@@ -238,165 +304,102 @@ class Http2ClientTransport final : public ClientTransport,
238
304
 
239
305
  // Returns a promise to fetch data from the callhandler and pass it further
240
306
  // down towards the endpoint.
241
- auto CallOutboundLoop(CallHandler call_handler, RefCountedPtr<Stream> stream,
242
- ClientMetadataHandle metadata);
307
+ auto CallOutboundLoop(RefCountedPtr<Stream> stream);
243
308
 
244
- // TODO(akshitpatel) : [PH2][P1] : Make this a synchronous function.
245
309
  // Force triggers a transport write cycle
246
- auto TriggerWriteCycle() {
247
- return Immediate(writable_stream_list_.ForceReadyForWrite());
310
+ absl::Status TriggerWriteCycle(DebugLocation whence = {}) {
311
+ GRPC_HTTP2_CLIENT_DLOG
312
+ << "Http2ClientTransport::TriggerWriteCycle invoked from "
313
+ << whence.file() << ":" << whence.line();
314
+ return writable_stream_list_.ForceReadyForWrite();
248
315
  }
249
316
 
250
- auto FlowControlPeriodicUpdateLoop();
251
- // TODO(tjagtap) [PH2][P2][BDP] Remove this when the BDP code is done.
252
- void AddPeriodicUpdatePromiseWaker() {
253
- periodic_updates_waker_ = GetContext<Activity>()->MakeNonOwningWaker();
317
+ // Triggers a write cycle. If successful, returns true.
318
+ // If failed, calls HandleError and returns false.
319
+ bool TriggerWriteCycleOrHandleError(DebugLocation whence = {}) {
320
+ absl::Status status = TriggerWriteCycle(whence);
321
+ if (GPR_LIKELY(status.ok())) return true;
322
+ GRPC_HTTP2_CLIENT_DLOG
323
+ << "Http2ClientTransport::TriggerWriteCycleOrHandleError failed with "
324
+ "status: "
325
+ << status << " at " << whence.file() << ":" << whence.line();
326
+ GRPC_UNUSED absl::Status unused_status =
327
+ HandleError(std::nullopt, ToHttpOkOrConnError(status), whence);
328
+ return false;
254
329
  }
255
- // TODO(tjagtap) [PH2][P2][BDP] Remove this when the BDP code is done.
256
- void WakeupPeriodicUpdatePromise() { periodic_updates_waker_.Wakeup(); }
257
330
 
258
- // Processes the flow control action and take necessary steps.
259
- void ActOnFlowControlAction(const chttp2::FlowControlAction& action,
260
- RefCountedPtr<Stream> stream);
331
+ absl::Status InitializeStream(Stream& stream);
261
332
 
262
- void NotifyStateWatcherOnDisconnectLocked(
263
- absl::Status status, StateWatcher::DisconnectInfo disconnect_info)
264
- ABSL_EXCLUSIVE_LOCKS_REQUIRED(&transport_mutex_);
265
-
266
- RefCountedPtr<Party> general_party_;
267
- std::shared_ptr<grpc_event_engine::experimental::EventEngine> event_engine_;
268
-
269
- PromiseEndpoint endpoint_;
270
- RefCountedPtr<SettingsPromiseManager> settings_;
333
+ //////////////////////////////////////////////////////////////////////////////
334
+ // Spawn Helpers and Promise Helpers
271
335
 
272
- Http2FrameHeader current_frame_header_;
273
- // Returns the number of active streams. A stream is removed from the `active`
274
- // list once both client and server agree to close the stream. The count of
275
- // stream_list_(even though stream list represents streams open for reads)
276
- // works here because of the following cases where the stream is closed:
277
- // 1. Reading a RST stream frame: In this case, the stream is immediately
278
- // closed for reads and writes and removed from the stream_list_
279
- // (effectively tracking the number of active streams).
280
- // 2. Reading a Trailing Metadata frame: In this case, the stream MAY be
281
- // closed for reads and writes immediately which follows the above case. In
282
- // other cases, the transport either reads RST stream frame from the server
283
- // (and follows case 1) or sends a half close frame and closes the stream
284
- // for reads and writes (in the multiplexer loop).
285
- // 3. Hitting error condition in the transport: In this case, RST stream is
286
- // is enqueued and the stream is closed for reads immediately. This means
287
- // we effectively reduce the number of active streams inline (because we
288
- // remove the stream from the stream_list_). This is fine because the
289
- // priority logic in list of writable streams ensures that the RST stream
290
- // frame is given priority over any new streams being created by the
291
- // client.
292
- // 4. Application abort: In this case, multiplexer loop will write RST stream
293
- // frame to the endpoint and close the stream from reads and writes. This
294
- // then follows the same reasoning as case 1.
295
- inline uint32_t GetActiveStreamCountLocked() const
296
- ABSL_EXCLUSIVE_LOCKS_REQUIRED(transport_mutex_) {
297
- return stream_list_.size();
298
- }
299
-
300
- // Returns the next stream id. If the next stream id is not available, it
301
- // returns std::nullopt. MUST be called from the transport party.
302
- absl::StatusOr<uint32_t> NextStreamId() {
303
- if (next_stream_id_ > GetMaxAllowedStreamId()) {
304
- // TODO(tjagtap) : [PH2][P3] : Handle case if transport runs out of stream
305
- // ids
306
- // RFC9113 : Stream identifiers cannot be reused. Long-lived connections
307
- // can result in an endpoint exhausting the available range of stream
308
- // identifiers. A client that is unable to establish a new stream
309
- // identifier can establish a new connection for new streams. A server
310
- // that is unable to establish a new stream identifier can send a GOAWAY
311
- // frame so that the client is forced to open a new connection for new
312
- // streams.
313
- return absl::ResourceExhaustedError("No more stream ids available");
314
- }
315
- // TODO(akshitpatel) : [PH2][P3] : There is a channel arg to delay
316
- // starting new streams instead of failing them. This needs to be
317
- // implemented.
318
- {
319
- MutexLock lock(&transport_mutex_);
320
- if (GetActiveStreamCountLocked() >=
321
- settings_->peer().max_concurrent_streams()) {
322
- return absl::ResourceExhaustedError("Reached max concurrent streams");
323
- }
324
- }
325
-
326
- // RFC9113 : Streams initiated by a client MUST use odd-numbered stream
327
- // identifiers.
328
- uint32_t new_stream_id =
329
- std::exchange(next_stream_id_, next_stream_id_ + 2);
330
- if (GPR_UNLIKELY(next_stream_id_ > GetMaxAllowedStreamId())) {
331
- ReportDisconnection(
332
- absl::ResourceExhaustedError("Transport Stream IDs exhausted"),
333
- {}, // TODO(tjagtap) : [PH2][P2] : Report better disconnect info.
334
- "no_more_stream_ids");
335
- }
336
- return new_stream_id;
337
- }
338
-
339
- // Returns the next stream id without incrementing it. MUST be called from the
340
- // transport party.
341
- uint32_t PeekNextStreamId() const { return next_stream_id_; }
342
-
343
- // Returns the last stream id sent by the transport. If no streams were sent,
344
- // returns 0. MUST be called from the transport party.
345
- uint32_t GetLastStreamId() const {
346
- const uint32_t next_stream_id = PeekNextStreamId();
347
- return (next_stream_id > 1) ? (next_stream_id - 2) : 0;
336
+ template <typename Promise,
337
+ std::enable_if_t<std::is_same_v<decltype(std::declval<Promise>()()),
338
+ Poll<absl::Status>>,
339
+ bool> = true>
340
+ auto UntilTransportClosed(Promise&& promise) {
341
+ return Race(Map(transport_closed_latch_.Wait(),
342
+ [self = RefAsSubclass<Http2ClientTransport>()](Empty) {
343
+ GRPC_HTTP2_CLIENT_DLOG << "Transport closed";
344
+ return absl::CancelledError("Transport closed");
345
+ }),
346
+ std::forward<Promise>(promise));
348
347
  }
349
348
 
350
- absl::Status InitializeStream(RefCountedPtr<Stream> stream);
351
-
352
- void AddToStreamList(RefCountedPtr<Stream> stream);
353
-
354
- Mutex transport_mutex_;
355
-
356
- absl::flat_hash_map<uint32_t, RefCountedPtr<Stream>> stream_list_
357
- ABSL_GUARDED_BY(transport_mutex_);
358
-
359
- uint32_t next_stream_id_;
360
- HPackCompressor encoder_;
361
- HPackParser parser_;
362
- bool is_transport_closed_ ABSL_GUARDED_BY(transport_mutex_) = false;
363
- Latch<void> transport_closed_latch_;
364
-
365
- template <typename Promise>
366
- auto UntilTransportClosed(Promise promise) {
349
+ template <typename Promise,
350
+ std::enable_if_t<std::is_same_v<decltype(std::declval<Promise>()()),
351
+ Poll<Empty>>,
352
+ bool> = true>
353
+ auto UntilTransportClosed(Promise&& promise) {
367
354
  return Race(Map(transport_closed_latch_.Wait(),
368
- [](Empty) {
355
+ [self = RefAsSubclass<Http2ClientTransport>()](Empty) {
369
356
  GRPC_HTTP2_CLIENT_DLOG << "Transport closed";
370
- return absl::CancelledError("Transport closed");
357
+ return Empty{};
371
358
  }),
372
- std::move(promise));
359
+ std::forward<Promise>(promise));
373
360
  }
374
361
 
375
362
  // Spawns an infallible promise on the given party.
376
363
  template <typename Factory>
377
364
  void SpawnInfallible(RefCountedPtr<Party> party, absl::string_view name,
378
- Factory&& factory);
365
+ Factory&& factory) {
366
+ party->Spawn(name, std::forward<Factory>(factory), [](Empty) {});
367
+ }
379
368
 
380
369
  // Spawns an infallible promise on the transport party.
381
370
  template <typename Factory>
382
- void SpawnInfallibleTransportParty(absl::string_view name, Factory&& factory);
371
+ void SpawnInfallibleTransportParty(absl::string_view name,
372
+ Factory&& factory) {
373
+ SpawnInfallible(general_party_, name, std::forward<Factory>(factory));
374
+ }
383
375
 
384
376
  // Spawns a promise on the transport party. If the promise returns a non-ok
385
377
  // status, it is handled by closing the transport with the corresponding
386
378
  // status.
387
379
  template <typename Factory>
388
- void SpawnGuardedTransportParty(absl::string_view name, Factory&& factory);
389
-
390
- ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(transport_mutex_){
391
- "http2_client", GRPC_CHANNEL_READY};
380
+ void SpawnGuardedTransportParty(absl::string_view name, Factory&& factory) {
381
+ general_party_->Spawn(
382
+ name, std::forward<Factory>(factory),
383
+ [self = RefAsSubclass<Http2ClientTransport>()](absl::Status status) {
384
+ if (!status.ok()) {
385
+ GRPC_UNUSED absl::Status error = self->HandleError(
386
+ /*stream_id=*/std::nullopt, ToHttpOkOrConnError(status));
387
+ }
388
+ });
389
+ }
392
390
 
393
- RefCountedPtr<StateWatcher> watcher_ ABSL_GUARDED_BY(transport_mutex_);
391
+ template <typename Factory, typename OnDone>
392
+ void SpawnWithOnDoneTransportParty(absl::string_view name, Factory&& factory,
393
+ OnDone&& on_done) {
394
+ general_party_->Spawn(name, std::forward<Factory>(factory),
395
+ std::forward<OnDone>(on_done));
396
+ }
394
397
 
395
398
  // Runs on the call party.
396
399
  std::optional<RefCountedPtr<Stream>> MakeStream(CallHandler call_handler);
397
400
 
398
401
  // This function MUST be idempotent.
399
- void CloseStream(RefCountedPtr<Stream> stream, CloseStreamArgs args,
402
+ void CloseStream(Stream& stream, CloseStreamArgs args,
400
403
  DebugLocation whence = {});
401
404
 
402
405
  void BeginCloseStream(RefCountedPtr<Stream> stream,
@@ -404,83 +407,94 @@ class Http2ClientTransport final : public ClientTransport,
404
407
  ServerMetadataHandle&& metadata,
405
408
  DebugLocation whence = {});
406
409
 
407
- RefCountedPtr<Stream> LookupStream(uint32_t stream_id);
408
-
409
- auto EndpointReadSlice(const size_t num_bytes);
410
- auto EndpointRead(const size_t num_bytes);
410
+ //////////////////////////////////////////////////////////////////////////////
411
+ // Settings
411
412
 
412
- // HTTP2 Settings
413
413
  auto WaitForSettingsTimeoutOnDone();
414
414
  void MaybeSpawnWaitForSettingsTimeout();
415
415
  void EnforceLatestIncomingSettings();
416
416
 
417
- // This function MUST run on the transport party.
418
- void CloseTransport();
417
+ //////////////////////////////////////////////////////////////////////////////
418
+ // Flow Control and BDP
419
419
 
420
- void MaybeSpawnCloseTransport(Http2Status http2_status,
421
- DebugLocation whence = {});
420
+ // Processes the flow control action and take necessary steps.
421
+ void ActOnFlowControlAction(const chttp2::FlowControlAction& action,
422
+ Stream* stream);
422
423
 
423
- // Handles the error status and returns the corresponding absl status. Absl
424
- // Status is returned so that the error can be gracefully handled
425
- // by promise primitives.
426
- // If the error is a stream error, it closes the stream and returns an ok
427
- // status. Ok status is returned because the calling transport promise loops
428
- // should not be cancelled in case of stream errors.
429
- // If the error is a connection error, it closes the transport and returns the
430
- // corresponding (failed) absl status.
431
- absl::Status HandleError(const std::optional<uint32_t> stream_id,
432
- Http2Status status, DebugLocation whence = {}) {
433
- auto error_type = status.GetType();
434
- GRPC_DCHECK(error_type != Http2Status::Http2ErrorType::kOk);
435
-
436
- if (error_type == Http2Status::Http2ErrorType::kStreamError) {
437
- GRPC_HTTP2_CLIENT_ERROR_DLOG << "Stream Error: " << status.DebugString();
438
- GRPC_DCHECK(stream_id.has_value());
439
- // Passing a cancelled server metadata handle to propagate the error
440
- // to the upper layers.
441
- BeginCloseStream(
442
- LookupStream(stream_id.value()),
443
- Http2ErrorCodeToFrameErrorCode(status.GetStreamErrorCode()),
444
- CancelledServerMetadataFromStatus(status.GetAbslStreamError()),
445
- whence);
446
- return absl::OkStatus();
447
- } else if (error_type == Http2Status::Http2ErrorType::kConnectionError) {
448
- GRPC_HTTP2_CLIENT_ERROR_DLOG << "Connection Error: "
449
- << status.DebugString();
450
- absl::Status absl_status = status.GetAbslConnectionError();
451
- MaybeSpawnCloseTransport(std::move(status), whence);
452
- return absl_status;
453
- }
454
- GPR_UNREACHABLE_CODE(return absl::InternalError("Invalid error type"));
424
+ void MaybeGetWindowUpdateFrames(FrameSender& frame_sender);
425
+
426
+ auto FlowControlPeriodicUpdateLoop();
427
+
428
+ // TODO(tjagtap) [PH2][P2][BDP] Remove this when the BDP code is done.
429
+ void AddPeriodicUpdatePromiseWaker() {
430
+ periodic_updates_waker_ = GetContext<Activity>()->MakeNonOwningWaker();
455
431
  }
456
432
 
457
- bool should_reset_ping_clock_;
458
- bool is_first_write_;
459
- IncomingMetadataTracker incoming_headers_;
433
+ // TODO(tjagtap) [PH2][P2][BDP] Remove this when the BDP code is done.
434
+ void WakeupPeriodicUpdatePromise() { periodic_updates_waker_.Wakeup(); }
435
+
436
+ //////////////////////////////////////////////////////////////////////////////
437
+ // Stream List Operations
438
+
439
+ RefCountedPtr<Stream> LookupStream(uint32_t stream_id);
440
+
441
+ void AddToStreamList(RefCountedPtr<Stream> stream);
442
+
443
+ absl::Status MaybeAddStreamToWritableStreamList(
444
+ const RefCountedPtr<Stream> stream,
445
+ const StreamDataQueue<ClientMetadataHandle>::StreamWritabilityUpdate
446
+ result);
447
+
448
+ // Returns the next stream id. If the next stream id is not available, it
449
+ // returns std::nullopt. MUST be called from the transport party.
450
+ absl::StatusOr<uint32_t> NextStreamId();
451
+
452
+ // Returns the next stream id without incrementing it. MUST be called from the
453
+ // transport party.
454
+ uint32_t PeekNextStreamId() const { return next_stream_id_; }
455
+
456
+ // Returns the last stream id sent by the transport. If no streams were sent,
457
+ // returns 0. MUST be called from the transport party.
458
+ uint32_t GetLastStreamId() const {
459
+ const uint32_t next_stream_id = PeekNextStreamId();
460
+ return (next_stream_id > 1) ? (next_stream_id - 2) : 0;
461
+ }
460
462
 
461
- // The target number of bytes to write in a single write cycle. We may not
462
- // always honour this max_write_size. We MAY overshoot it at most once per
463
- // write cycle.
464
- size_t max_write_size_;
465
- // The number of bytes remaining to be written in the current write cycle.
466
- size_t write_bytes_remaining_;
467
-
468
- // The max_write_size will be decided dynamically based on the available
469
- // bandwidth on the wire. We aim to keep the time spent in the write loop to
470
- // about 100ms.
471
- void SetMaxWriteSize(const size_t max_write_size) {
472
- GRPC_HTTP2_CLIENT_DLOG << "Http2ClientTransport SetMaxWriteSize "
473
- << " max_write_size changed: " << max_write_size_
474
- << " -> " << max_write_size;
475
- max_write_size_ = max_write_size;
463
+ // Returns the number of active streams. A stream is removed from the `active`
464
+ // list once both client and server agree to close the stream. The count of
465
+ // stream_list_(even though stream list represents streams open for reads)
466
+ // works here because of the following cases where the stream is closed:
467
+ // 1. Reading a RST_STREAM frame: In this case, the stream is immediately
468
+ // closed for reads and writes and removed from the stream_list_
469
+ // (effectively tracking the number of active streams).
470
+ // 2. Reading a Trailing Metadata frame: In this case, the stream MAY be
471
+ // closed for reads and writes immediately which follows the above case. In
472
+ // other cases, the transport either reads RST_STREAM frame from the server
473
+ // (and follows case 1) or sends a half close frame and closes the stream
474
+ // for reads and writes (in the multiplexer loop).
475
+ // 3. Hitting error condition in the transport: In this case, RST_STREAM is
476
+ // is enqueued and the stream is closed for reads immediately. This means
477
+ // we effectively reduce the number of active streams inline (because we
478
+ // remove the stream from the stream_list_). This is fine because the
479
+ // priority logic in list of writable streams ensures that the RST_STREAM
480
+ // frame is given priority over any new streams being created by the
481
+ // client.
482
+ // 4. Application abort: In this case, multiplexer loop will write RST_STREAM
483
+ // frame to the endpoint and close the stream from reads and writes. This
484
+ // then follows the same reasoning as case 1.
485
+ inline uint32_t GetActiveStreamCountLocked() const
486
+ ABSL_EXCLUSIVE_LOCKS_REQUIRED(transport_mutex_) {
487
+ return stream_list_.size();
476
488
  }
477
489
 
478
- size_t GetMaxWriteSize() const { return max_write_size_; }
490
+ //////////////////////////////////////////////////////////////////////////////
491
+ // Stream Operations
479
492
 
480
- auto SerializeAndWrite(std::vector<Http2Frame>&& frames);
481
- // Tracks the max allowed stream id. Currently this is only set on receiving a
482
- // graceful GOAWAY frame.
483
- uint32_t max_allowed_stream_id_ = RFC9113::kMaxStreamId31Bit;
493
+ // This function MUST run on the transport party.
494
+ void CloseTransport();
495
+
496
+ void MaybeSpawnCloseTransport(Http2Status http2_status,
497
+ DebugLocation whence = {});
484
498
 
485
499
  uint32_t GetMaxAllowedStreamId() const;
486
500
 
@@ -489,23 +503,46 @@ class Http2ClientTransport final : public ClientTransport,
489
503
  bool CanCloseTransportLocked() const
490
504
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(transport_mutex_);
491
505
 
492
- // Ping related members
506
+ //////////////////////////////////////////////////////////////////////////////
507
+ // Ping Keepalive and Goaway
493
508
 
494
- // Duration between two consecutive keepalive pings.
495
- Duration keepalive_time_;
496
- bool test_only_ack_pings_;
497
- std::optional<PingManager> ping_manager_;
498
- std::optional<KeepaliveManager> keepalive_manager_;
499
-
500
- // Flags
501
- bool keepalive_permit_without_calls_;
509
+ void MaybeSpawnPingTimeout(std::optional<uint64_t> opaque_data);
510
+ void MaybeSpawnDelayedPing(std::optional<Duration> delayed_ping_wait);
511
+ void MaybeSpawnKeepaliveLoop();
502
512
 
503
513
  auto SendPing(absl::AnyInvocable<void()> on_initiate, bool important) {
504
514
  return ping_manager_->RequestPing(std::move(on_initiate), important);
505
515
  }
516
+
506
517
  auto WaitForPingAck() { return ping_manager_->WaitForPingAck(); }
507
518
 
508
- void MaybeGetWindowUpdateFrames(SliceBuffer& output_buf);
519
+ // Ping Helper functions
520
+ Duration NextAllowedPingInterval() {
521
+ MutexLock lock(&transport_mutex_);
522
+ return (!keepalive_permit_without_calls_ &&
523
+ GetActiveStreamCountLocked() == 0)
524
+ ? Duration::Hours(2)
525
+ : Duration::Seconds(1);
526
+ }
527
+
528
+ absl::Status AckPing(uint64_t opaque_data);
529
+
530
+ //////////////////////////////////////////////////////////////////////////////
531
+ // Error Path and Close Path
532
+
533
+ // Handles the error status and returns the corresponding absl status. Absl
534
+ // Status is returned so that the error can be gracefully handled
535
+ // by promise primitives.
536
+ // If the error is a stream error, it closes the stream and returns an ok
537
+ // status. Ok status is returned because the calling transport promise loops
538
+ // should not be cancelled in case of stream errors.
539
+ // If the error is a connection error, it closes the transport and returns the
540
+ // corresponding (failed) absl status.
541
+ absl::Status HandleError(const std::optional<uint32_t> stream_id,
542
+ Http2Status status, DebugLocation whence = {});
543
+
544
+ //////////////////////////////////////////////////////////////////////////////
545
+ // Misc Transport Stuff
509
546
 
510
547
  void ReportDisconnection(const absl::Status& status,
511
548
  StateWatcher::DisconnectInfo disconnect_info,
@@ -516,70 +553,42 @@ class Http2ClientTransport final : public ClientTransport,
516
553
  const char* reason)
517
554
  ABSL_EXCLUSIVE_LOCKS_REQUIRED(&transport_mutex_);
518
555
 
519
- // Ping Helper functions
520
- Duration NextAllowedPingInterval() {
521
- MutexLock lock(&transport_mutex_);
522
- return (!keepalive_permit_without_calls_ &&
523
- GetActiveStreamCountLocked() == 0)
524
- ? Duration::Hours(2)
525
- : Duration::Seconds(1);
526
- }
527
-
528
- auto AckPing(uint64_t opaque_data) {
529
- bool valid_ping_ack_received = true;
556
+ bool SetOnDone(CallHandler call_handler, RefCountedPtr<Stream> stream);
530
557
 
531
- if (!ping_manager_->AckPing(opaque_data)) {
532
- GRPC_HTTP2_CLIENT_DLOG << "Unknown ping response received for ping id="
533
- << opaque_data;
534
- valid_ping_ack_received = false;
535
- }
558
+ void ReadChannelArgs(const ChannelArgs& channel_args,
559
+ TransportChannelArgs& args);
536
560
 
537
- return If(
538
- // It is possible that the PingRatePolicy may decide to not send a ping
539
- // request (in cases like the number of inflight pings is too high).
540
- // When this happens, it becomes important to ensure that if a ping ack
541
- // is received and there is an "important" outstanding ping request, we
542
- // should retry to send it out now.
543
- valid_ping_ack_received && ping_manager_->ImportantPingRequested(),
544
- [self = RefAsSubclass<Http2ClientTransport>()] {
545
- return Map(self->TriggerWriteCycle(), [](const absl::Status status) {
546
- return ToHttpOkOrConnError(status);
547
- });
548
- },
549
- [] { return Immediate(Http2Status::Ok()); });
561
+ auto SecurityFrameLoop() {
562
+ GRPC_HTTP2_CLIENT_DLOG << "Http2ClientTransport::SecurityFrameLoop Factory";
563
+ return AssertResultType<Empty>(Loop([this]() {
564
+ return Map(security_frame_handler_->WaitForSecurityFrameSending(),
565
+ [this](Empty) -> LoopCtl<Empty> {
566
+ if (security_frame_handler_->TriggerWriteSecurityFrame()
567
+ .terminate) {
568
+ return Empty{};
569
+ }
570
+
571
+ if (!TriggerWriteCycleOrHandleError()) {
572
+ return Empty{};
573
+ }
574
+ return Continue();
575
+ });
576
+ }));
550
577
  }
551
578
 
579
+ //////////////////////////////////////////////////////////////////////////////
580
+ // Inner Classes and Structs
581
+
552
582
  class PingSystemInterfaceImpl : public PingInterface {
553
583
  public:
554
- static std::unique_ptr<PingInterface> Make(
555
- Http2ClientTransport* transport) {
556
- return std::make_unique<PingSystemInterfaceImpl>(
557
- PingSystemInterfaceImpl(transport));
558
- }
559
-
560
- Promise<absl::Status> TriggerWrite() override {
561
- return transport_->TriggerWriteCycle();
562
- }
563
-
564
- Promise<absl::Status> PingTimeout() override {
565
- GRPC_HTTP2_CLIENT_DLOG << "Ping timeout at time: " << Timestamp::Now();
566
-
567
- // TODO(akshitpatel) : [PH2][P2] : The error code here has been chosen
568
- // based on CHTTP2's usage of GRPC_STATUS_UNAVAILABLE (which corresponds
569
- // to kRefusedStream). However looking at RFC9113, definition of
570
- // kRefusedStream doesn't seem to fit this case. We should revisit this
571
- // and update the error code.
572
- return Immediate(transport_->HandleError(
573
- std::nullopt,
574
- Http2Status::Http2ConnectionError(Http2ErrorCode::kRefusedStream,
575
- GRPC_CHTTP2_PING_TIMEOUT_STR)));
576
- }
584
+ static std::unique_ptr<PingInterface> Make(Http2ClientTransport* transport);
585
+ absl::Status TriggerWrite() override;
586
+ Promise<absl::Status> PingTimeout() override;
577
587
 
578
588
  private:
579
- // TODO(akshitpatel) : [PH2][P2] : Eventually there should be a separate ref
580
- // counted struct/class passed to all the transport promises/members. This
581
- // will help removing back references from the transport members to
582
- // transport and greatly simpilfy the cleanup path.
589
+ // Holding a raw pointer to transport works because all the promises
590
+ // invoking the methods of this class are invoked while holding a ref to the
591
+ // transport.
583
592
  Http2ClientTransport* transport_;
584
593
  explicit PingSystemInterfaceImpl(Http2ClientTransport* transport)
585
594
  : transport_(transport) {}
@@ -588,135 +597,109 @@ class Http2ClientTransport final : public ClientTransport,
588
597
  class KeepAliveInterfaceImpl : public KeepAliveInterface {
589
598
  public:
590
599
  static std::unique_ptr<KeepAliveInterface> Make(
591
- Http2ClientTransport* transport) {
592
- return std::make_unique<KeepAliveInterfaceImpl>(
593
- KeepAliveInterfaceImpl(transport));
594
- }
600
+ Http2ClientTransport* transport);
595
601
 
596
602
  private:
597
603
  explicit KeepAliveInterfaceImpl(Http2ClientTransport* transport)
598
604
  : transport_(transport) {}
599
- Promise<absl::Status> SendPingAndWaitForAck() override {
600
- return TrySeq(transport_->TriggerWriteCycle(), [transport = transport_] {
601
- return transport->WaitForPingAck();
602
- });
603
- }
604
- Promise<absl::Status> OnKeepAliveTimeout() override {
605
- GRPC_HTTP2_CLIENT_DLOG << "Keepalive timeout triggered";
606
-
607
- // TODO(akshitpatel) : [PH2][P2] : The error code here has been chosen
608
- // based on CHTTP2's usage of GRPC_STATUS_UNAVAILABLE (which corresponds
609
- // to kRefusedStream). However looking at RFC9113, definition of
610
- // kRefusedStream doesn't seem to fit this case. We should revisit this
611
- // and update the error code.
612
- return Immediate(transport_->HandleError(
613
- std::nullopt, Http2Status::Http2ConnectionError(
614
- Http2ErrorCode::kRefusedStream,
615
- GRPC_CHTTP2_KEEPALIVE_TIMEOUT_STR)));
616
- }
617
-
618
- bool NeedToSendKeepAlivePing() override {
619
- bool need_to_send_ping = false;
620
- {
621
- MutexLock lock(&transport_->transport_mutex_);
622
- need_to_send_ping = (transport_->keepalive_permit_without_calls_ ||
623
- transport_->GetActiveStreamCountLocked() > 0);
624
- }
625
- return need_to_send_ping;
626
- }
627
-
628
- // TODO(akshitpatel) : [PH2][P2] : Eventually there should be a separate ref
629
- // counted struct/class passed to all the transport promises/members. This
630
- // will help removing back references from the transport members to
631
- // transport and greatly simpilfy the cleanup path.
605
+ Promise<absl::Status> SendPingAndWaitForAck() override;
606
+ Promise<absl::Status> OnKeepAliveTimeout() override;
607
+ bool NeedToSendKeepAlivePing() override;
608
+ // Holding a raw pointer to transport works because all the promises
609
+ // invoking the methods of this class are invoked while holding a ref to the
610
+ // transport.
632
611
  Http2ClientTransport* transport_;
633
612
  };
634
613
 
635
614
  class GoawayInterfaceImpl : public GoawayInterface {
636
615
  public:
637
616
  static std::unique_ptr<GoawayInterface> Make(
638
- Http2ClientTransport* transport) {
639
- return std::make_unique<GoawayInterfaceImpl>(
640
- GoawayInterfaceImpl(transport));
641
- }
617
+ Http2ClientTransport* transport);
642
618
 
643
619
  Promise<absl::Status> SendPingAndWaitForAck() override {
644
620
  return transport_->ping_manager_->RequestPing(/*on_initiate=*/[] {},
645
621
  /*important=*/true);
646
622
  }
647
623
 
648
- void TriggerWriteCycle() override { transport_->TriggerWriteCycle(); }
649
-
650
- uint32_t GetLastAcceptedStreamId() override {
651
- GRPC_DCHECK(false)
652
- << "GetLastAcceptedStreamId is not implemented for client transport.";
653
- LOG(ERROR) << "GetLastAcceptedStreamId is not implemented for client "
654
- "transport.";
655
- return 0;
624
+ absl::Status TriggerWriteCycle() override {
625
+ return transport_->TriggerWriteCycle();
656
626
  }
627
+ uint32_t GetLastAcceptedStreamId() override;
657
628
 
658
629
  private:
659
630
  explicit GoawayInterfaceImpl(Http2ClientTransport* transport)
660
631
  : transport_(transport) {}
661
-
632
+ // Holding a raw pointer to transport works because all the promises
633
+ // invoking the methods of this class are invoked while holding a ref to the
634
+ // transport.
662
635
  Http2ClientTransport* transport_;
663
636
  };
664
637
 
638
+ //////////////////////////////////////////////////////////////////////////////
639
+ // All Data Members
640
+
641
+ RefCountedPtr<Party> general_party_; // Refer Gemini.md for party slot usage
642
+ std::shared_ptr<grpc_event_engine::experimental::EventEngine> event_engine_;
643
+
644
+ PromiseEndpoint endpoint_;
645
+ RefCountedPtr<SettingsPromiseManager> settings_;
646
+
647
+ Http2FrameHeader current_frame_header_;
648
+
649
+ Mutex transport_mutex_;
650
+
651
+ absl::flat_hash_map<uint32_t, RefCountedPtr<Stream>> stream_list_
652
+ ABSL_GUARDED_BY(transport_mutex_);
653
+
654
+ uint32_t next_stream_id_;
655
+ HPackCompressor encoder_;
656
+ HPackParser parser_;
657
+ bool is_transport_closed_ ABSL_GUARDED_BY(transport_mutex_) = false;
658
+ Latch<void> transport_closed_latch_;
659
+
660
+ ConnectivityStateTracker state_tracker_ ABSL_GUARDED_BY(transport_mutex_){
661
+ "http2_client", GRPC_CHANNEL_READY};
662
+
663
+ RefCountedPtr<StateWatcher> watcher_ ABSL_GUARDED_BY(transport_mutex_);
664
+
665
+ bool should_reset_ping_clock_;
666
+ IncomingMetadataTracker incoming_headers_;
667
+
668
+ // Transport wide write context. This is used to track the state of the
669
+ // transport during write cycles.
670
+ TransportWriteContext transport_write_context_;
671
+
672
+ // Tracks the max allowed stream id. Currently this is only set on receiving a
673
+ // graceful GOAWAY frame.
674
+ uint32_t max_allowed_stream_id_ = RFC9113::kMaxStreamId31Bit;
675
+
676
+ // Duration between two consecutive keepalive pings.
677
+ Duration keepalive_time_;
678
+ bool test_only_ack_pings_;
679
+ std::optional<PingManager> ping_manager_;
680
+ std::optional<KeepaliveManager> keepalive_manager_;
681
+
682
+ // Flags
683
+ bool keepalive_permit_without_calls_;
684
+
665
685
  GoawayManager goaway_manager_;
666
686
 
667
687
  WritableStreams<RefCountedPtr<Stream>> writable_stream_list_;
668
688
 
669
- absl::Status MaybeAddStreamToWritableStreamList(
670
- const RefCountedPtr<Stream> stream,
671
- const StreamDataQueue<ClientMetadataHandle>::StreamWritabilityUpdate
672
- result) {
673
- if (result.became_writable) {
674
- GRPC_HTTP2_CLIENT_DLOG
675
- << "Http2ClientTransport MaybeAddStreamToWritableStreamList "
676
- " Stream id: "
677
- << stream->GetStreamId() << " became writable";
678
- absl::Status status =
679
- writable_stream_list_.Enqueue(stream, result.priority);
680
- if (!status.ok()) {
681
- return HandleError(
682
- std::nullopt,
683
- Http2Status::Http2ConnectionError(
684
- Http2ErrorCode::kRefusedStream,
685
- "Failed to enqueue stream to writable stream list"));
686
- }
687
- }
688
- return absl::OkStatus();
689
- }
690
- bool SetOnDone(CallHandler call_handler, RefCountedPtr<Stream> stream);
691
- absl::StatusOr<std::vector<Http2Frame>> DequeueStreamFrames(
692
- RefCountedPtr<Stream> stream);
693
-
694
689
  /// Based on channel args, preferred_rx_crypto_frame_sizes are advertised to
695
690
  /// the peer
696
691
  bool enable_preferred_rx_crypto_frame_advertisement_;
692
+ RefCountedPtr<SecurityFrameHandler> security_frame_handler_;
697
693
  MemoryOwner memory_owner_;
698
694
  chttp2::TransportFlowControl flow_control_;
699
695
  std::shared_ptr<PromiseHttp2ZTraceCollector> ztrace_collector_;
700
- absl::flat_hash_set<uint32_t> window_update_list_;
701
696
 
702
697
  // TODO(tjagtap) [PH2][P2][BDP] Remove this when the BDP code is done.
703
698
  Waker periodic_updates_waker_;
704
699
 
705
700
  Http2ReadContext reader_state_;
706
- Http2Status ParseAndDiscardHeaders(SliceBuffer&& buffer, bool is_end_headers,
707
- RefCountedPtr<Stream> stream,
708
- Http2Status&& original_status,
709
- DebugLocation whence = {});
710
- void ReadChannelArgs(const ChannelArgs& channel_args,
711
- TransportChannelArgs& args);
712
701
  };
713
702
 
714
- // Since the corresponding class in CHTTP2 is about 3.9KB, our goal is to
715
- // remain within that range. When this check fails, please update it to size
716
- // (current size + 32) to make sure that it does not fail each time we add a
717
- // small variable to the class.
718
- GRPC_CHECK_CLASS_SIZE(Http2ClientTransport, 600);
719
-
720
703
  } // namespace http2
721
704
  } // namespace grpc_core
722
705