wearefair-grpc 1.3.1.pre.a
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +1 -0
- data/Makefile +19484 -0
- data/etc/roots.pem +5288 -0
- data/include/grpc/byte_buffer.h +102 -0
- data/include/grpc/byte_buffer_reader.h +39 -0
- data/include/grpc/census.h +484 -0
- data/include/grpc/compression.h +85 -0
- data/include/grpc/grpc.h +509 -0
- data/include/grpc/grpc_cronet.h +51 -0
- data/include/grpc/grpc_posix.h +81 -0
- data/include/grpc/grpc_security.h +390 -0
- data/include/grpc/grpc_security_constants.h +114 -0
- data/include/grpc/impl/codegen/atm.h +100 -0
- data/include/grpc/impl/codegen/atm_gcc_atomic.h +97 -0
- data/include/grpc/impl/codegen/atm_gcc_sync.h +97 -0
- data/include/grpc/impl/codegen/atm_windows.h +140 -0
- data/include/grpc/impl/codegen/byte_buffer_reader.h +57 -0
- data/include/grpc/impl/codegen/compression_types.h +122 -0
- data/include/grpc/impl/codegen/connectivity_state.h +61 -0
- data/include/grpc/impl/codegen/exec_ctx_fwd.h +41 -0
- data/include/grpc/impl/codegen/gpr_slice.h +84 -0
- data/include/grpc/impl/codegen/gpr_types.h +75 -0
- data/include/grpc/impl/codegen/grpc_types.h +550 -0
- data/include/grpc/impl/codegen/port_platform.h +421 -0
- data/include/grpc/impl/codegen/propagation_bits.h +67 -0
- data/include/grpc/impl/codegen/slice.h +157 -0
- data/include/grpc/impl/codegen/status.h +163 -0
- data/include/grpc/impl/codegen/sync.h +75 -0
- data/include/grpc/impl/codegen/sync_generic.h +55 -0
- data/include/grpc/impl/codegen/sync_posix.h +47 -0
- data/include/grpc/impl/codegen/sync_windows.h +49 -0
- data/include/grpc/load_reporting.h +63 -0
- data/include/grpc/module.modulemap +13 -0
- data/include/grpc/slice.h +168 -0
- data/include/grpc/slice_buffer.h +94 -0
- data/include/grpc/status.h +39 -0
- data/include/grpc/support/alloc.h +82 -0
- data/include/grpc/support/atm.h +39 -0
- data/include/grpc/support/atm_gcc_atomic.h +39 -0
- data/include/grpc/support/atm_gcc_sync.h +39 -0
- data/include/grpc/support/atm_windows.h +39 -0
- data/include/grpc/support/avl.h +97 -0
- data/include/grpc/support/cmdline.h +103 -0
- data/include/grpc/support/cpu.h +59 -0
- data/include/grpc/support/histogram.h +79 -0
- data/include/grpc/support/host_port.h +66 -0
- data/include/grpc/support/log.h +118 -0
- data/include/grpc/support/log_windows.h +53 -0
- data/include/grpc/support/port_platform.h +39 -0
- data/include/grpc/support/string_util.h +64 -0
- data/include/grpc/support/subprocess.h +59 -0
- data/include/grpc/support/sync.h +295 -0
- data/include/grpc/support/sync_generic.h +39 -0
- data/include/grpc/support/sync_posix.h +39 -0
- data/include/grpc/support/sync_windows.h +39 -0
- data/include/grpc/support/thd.h +91 -0
- data/include/grpc/support/time.h +105 -0
- data/include/grpc/support/tls.h +77 -0
- data/include/grpc/support/tls_gcc.h +100 -0
- data/include/grpc/support/tls_msvc.h +56 -0
- data/include/grpc/support/tls_pthread.h +60 -0
- data/include/grpc/support/useful.h +80 -0
- data/src/boringssl/err_data.c +1270 -0
- data/src/core/ext/census/aggregation.h +66 -0
- data/src/core/ext/census/base_resources.c +71 -0
- data/src/core/ext/census/base_resources.h +39 -0
- data/src/core/ext/census/census_interface.h +76 -0
- data/src/core/ext/census/census_rpc_stats.h +101 -0
- data/src/core/ext/census/context.c +509 -0
- data/src/core/ext/census/gen/census.pb.c +176 -0
- data/src/core/ext/census/gen/census.pb.h +295 -0
- data/src/core/ext/census/gen/trace_context.pb.c +54 -0
- data/src/core/ext/census/gen/trace_context.pb.h +93 -0
- data/src/core/ext/census/grpc_context.c +53 -0
- data/src/core/ext/census/grpc_filter.c +213 -0
- data/src/core/ext/census/grpc_filter.h +44 -0
- data/src/core/ext/census/grpc_plugin.c +85 -0
- data/src/core/ext/census/initialize.c +66 -0
- data/src/core/ext/census/mlog.c +600 -0
- data/src/core/ext/census/mlog.h +95 -0
- data/src/core/ext/census/operation.c +63 -0
- data/src/core/ext/census/placeholders.c +64 -0
- data/src/core/ext/census/resource.c +312 -0
- data/src/core/ext/census/resource.h +63 -0
- data/src/core/ext/census/rpc_metric_id.h +51 -0
- data/src/core/ext/census/trace_context.c +86 -0
- data/src/core/ext/census/trace_context.h +71 -0
- data/src/core/ext/census/trace_label.h +61 -0
- data/src/core/ext/census/trace_propagation.h +63 -0
- data/src/core/ext/census/trace_status.h +45 -0
- data/src/core/ext/census/trace_string.h +50 -0
- data/src/core/ext/census/tracing.c +71 -0
- data/src/core/ext/census/tracing.h +124 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.c +226 -0
- data/src/core/ext/filters/client_channel/client_channel.c +1410 -0
- data/src/core/ext/filters/client_channel/client_channel.h +64 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.c +87 -0
- data/src/core/ext/filters/client_channel/client_channel_factory.h +92 -0
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +106 -0
- data/src/core/ext/filters/client_channel/connector.c +55 -0
- data/src/core/ext/filters/client_channel/connector.h +88 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +389 -0
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +49 -0
- data/src/core/ext/filters/client_channel/http_proxy.c +125 -0
- data/src/core/ext/filters/client_channel/http_proxy.h +39 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +1419 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.h +44 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +57 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.c +107 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +249 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +105 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +88 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +158 -0
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +476 -0
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +795 -0
- data/src/core/ext/filters/client_channel/lb_policy.c +167 -0
- data/src/core/ext/filters/client_channel/lb_policy.h +209 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +163 -0
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +134 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.c +85 -0
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +55 -0
- data/src/core/ext/filters/client_channel/parse_address.c +170 -0
- data/src/core/ext/filters/client_channel/parse_address.h +54 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.c +63 -0
- data/src/core/ext/filters/client_channel/proxy_mapper.h +89 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +139 -0
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.h +59 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +350 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +66 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +319 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +289 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +64 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.c +325 -0
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.c +234 -0
- data/src/core/ext/filters/client_channel/resolver.c +88 -0
- data/src/core/ext/filters/client_channel/resolver.h +101 -0
- data/src/core/ext/filters/client_channel/resolver_factory.c +56 -0
- data/src/core/ext/filters/client_channel/resolver_factory.h +85 -0
- data/src/core/ext/filters/client_channel/resolver_registry.c +174 -0
- data/src/core/ext/filters/client_channel/resolver_registry.h +84 -0
- data/src/core/ext/filters/client_channel/retry_throttle.c +210 -0
- data/src/core/ext/filters/client_channel/retry_throttle.h +65 -0
- data/src/core/ext/filters/client_channel/subchannel.c +835 -0
- data/src/core/ext/filters/client_channel/subchannel.h +203 -0
- data/src/core/ext/filters/client_channel/subchannel_index.c +262 -0
- data/src/core/ext/filters/client_channel/subchannel_index.h +77 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +315 -0
- data/src/core/ext/filters/client_channel/uri_parser.h +65 -0
- data/src/core/ext/filters/load_reporting/load_reporting.c +106 -0
- data/src/core/ext/filters/load_reporting/load_reporting.h +73 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.c +218 -0
- data/src/core/ext/filters/load_reporting/load_reporting_filter.h +42 -0
- data/src/core/ext/filters/max_age/max_age_filter.c +439 -0
- data/src/core/ext/filters/max_age/max_age_filter.h +39 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.c +56 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +49 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +221 -0
- data/src/core/ext/transport/chttp2/client/chttp2_connector.h +41 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +121 -0
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +95 -0
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.c +239 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +304 -0
- data/src/core/ext/transport/chttp2/server/chttp2_server.h +47 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2.c +59 -0
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.c +90 -0
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.c +101 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.c +236 -0
- data/src/core/ext/transport/chttp2/transport/bin_decoder.h +67 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.c +241 -0
- data/src/core/ext/transport/chttp2/transport/bin_encoder.h +54 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +43 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +2847 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +53 -0
- data/src/core/ext/transport/chttp2/transport/frame.h +61 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.c +287 -0
- data/src/core/ext/transport/chttp2/transport/frame_data.h +104 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +198 -0
- data/src/core/ext/transport/chttp2/transport/frame_goaway.h +78 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +145 -0
- data/src/core/ext/transport/chttp2/transport/frame_ping.h +59 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +125 -0
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.h +58 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +239 -0
- data/src/core/ext/transport/chttp2/transport/frame_settings.h +76 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +134 -0
- data/src/core/ext/transport/chttp2/transport/frame_window_update.h +57 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +661 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.h +107 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +1734 -0
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +129 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +383 -0
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +112 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.c +75 -0
- data/src/core/ext/transport/chttp2/transport/http2_settings.h +74 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.c +105 -0
- data/src/core/ext/transport/chttp2/transport/huffsyms.h +48 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +88 -0
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +63 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +852 -0
- data/src/core/ext/transport/chttp2/transport/parsing.c +825 -0
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +194 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.c +176 -0
- data/src/core/ext/transport/chttp2/transport/stream_map.h +83 -0
- data/src/core/ext/transport/chttp2/transport/varint.c +65 -0
- data/src/core/ext/transport/chttp2/transport/varint.h +75 -0
- data/src/core/ext/transport/chttp2/transport/writing.c +429 -0
- data/src/core/lib/channel/channel_args.c +355 -0
- data/src/core/lib/channel/channel_args.h +126 -0
- data/src/core/lib/channel/channel_stack.c +291 -0
- data/src/core/lib/channel/channel_stack.h +319 -0
- data/src/core/lib/channel/channel_stack_builder.c +284 -0
- data/src/core/lib/channel/channel_stack_builder.h +170 -0
- data/src/core/lib/channel/compress_filter.c +353 -0
- data/src/core/lib/channel/compress_filter.h +67 -0
- data/src/core/lib/channel/connected_channel.c +188 -0
- data/src/core/lib/channel/connected_channel.h +48 -0
- data/src/core/lib/channel/context.h +64 -0
- data/src/core/lib/channel/deadline_filter.c +348 -0
- data/src/core/lib/channel/deadline_filter.h +102 -0
- data/src/core/lib/channel/handshaker.c +281 -0
- data/src/core/lib/channel/handshaker.h +182 -0
- data/src/core/lib/channel/handshaker_factory.c +54 -0
- data/src/core/lib/channel/handshaker_factory.h +66 -0
- data/src/core/lib/channel/handshaker_registry.c +113 -0
- data/src/core/lib/channel/handshaker_registry.h +63 -0
- data/src/core/lib/channel/http_client_filter.c +601 -0
- data/src/core/lib/channel/http_client_filter.h +47 -0
- data/src/core/lib/channel/http_server_filter.c +445 -0
- data/src/core/lib/channel/http_server_filter.h +42 -0
- data/src/core/lib/channel/message_size_filter.c +270 -0
- data/src/core/lib/channel/message_size_filter.h +39 -0
- data/src/core/lib/compression/algorithm_metadata.h +53 -0
- data/src/core/lib/compression/compression.c +198 -0
- data/src/core/lib/compression/message_compress.c +204 -0
- data/src/core/lib/compression/message_compress.h +54 -0
- data/src/core/lib/debug/trace.c +140 -0
- data/src/core/lib/debug/trace.h +43 -0
- data/src/core/lib/http/format_request.c +135 -0
- data/src/core/lib/http/format_request.h +47 -0
- data/src/core/lib/http/httpcli.c +336 -0
- data/src/core/lib/http/httpcli.h +141 -0
- data/src/core/lib/http/httpcli_security_connector.c +199 -0
- data/src/core/lib/http/parser.c +379 -0
- data/src/core/lib/http/parser.h +126 -0
- data/src/core/lib/iomgr/closure.c +168 -0
- data/src/core/lib/iomgr/closure.h +153 -0
- data/src/core/lib/iomgr/combiner.c +460 -0
- data/src/core/lib/iomgr/combiner.h +83 -0
- data/src/core/lib/iomgr/endpoint.c +78 -0
- data/src/core/lib/iomgr/endpoint.h +117 -0
- data/src/core/lib/iomgr/endpoint_pair.h +47 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.c +87 -0
- data/src/core/lib/iomgr/endpoint_pair_uv.c +53 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.c +101 -0
- data/src/core/lib/iomgr/error.c +793 -0
- data/src/core/lib/iomgr/error.h +218 -0
- data/src/core/lib/iomgr/error_internal.h +75 -0
- data/src/core/lib/iomgr/ev_epoll_linux.c +1965 -0
- data/src/core/lib/iomgr/ev_epoll_linux.h +48 -0
- data/src/core/lib/iomgr/ev_poll_posix.c +1593 -0
- data/src/core/lib/iomgr/ev_poll_posix.h +42 -0
- data/src/core/lib/iomgr/ev_posix.c +287 -0
- data/src/core/lib/iomgr/ev_posix.h +189 -0
- data/src/core/lib/iomgr/exec_ctx.c +117 -0
- data/src/core/lib/iomgr/exec_ctx.h +117 -0
- data/src/core/lib/iomgr/executor.c +170 -0
- data/src/core/lib/iomgr/executor.h +51 -0
- data/src/core/lib/iomgr/iocp_windows.c +168 -0
- data/src/core/lib/iomgr/iocp_windows.h +55 -0
- data/src/core/lib/iomgr/iomgr.c +183 -0
- data/src/core/lib/iomgr/iomgr.h +47 -0
- data/src/core/lib/iomgr/iomgr_internal.h +58 -0
- data/src/core/lib/iomgr/iomgr_posix.c +56 -0
- data/src/core/lib/iomgr/iomgr_posix.h +39 -0
- data/src/core/lib/iomgr/iomgr_uv.c +49 -0
- data/src/core/lib/iomgr/iomgr_windows.c +76 -0
- data/src/core/lib/iomgr/load_file.c +92 -0
- data/src/core/lib/iomgr/load_file.h +56 -0
- data/src/core/lib/iomgr/lockfree_event.c +238 -0
- data/src/core/lib/iomgr/lockfree_event.h +54 -0
- data/src/core/lib/iomgr/network_status_tracker.c +48 -0
- data/src/core/lib/iomgr/network_status_tracker.h +45 -0
- data/src/core/lib/iomgr/polling_entity.c +104 -0
- data/src/core/lib/iomgr/polling_entity.h +81 -0
- data/src/core/lib/iomgr/pollset.h +97 -0
- data/src/core/lib/iomgr/pollset_set.h +62 -0
- data/src/core/lib/iomgr/pollset_set_uv.c +63 -0
- data/src/core/lib/iomgr/pollset_set_windows.c +64 -0
- data/src/core/lib/iomgr/pollset_set_windows.h +39 -0
- data/src/core/lib/iomgr/pollset_uv.c +156 -0
- data/src/core/lib/iomgr/pollset_uv.h +42 -0
- data/src/core/lib/iomgr/pollset_windows.c +232 -0
- data/src/core/lib/iomgr/pollset_windows.h +78 -0
- data/src/core/lib/iomgr/port.h +138 -0
- data/src/core/lib/iomgr/resolve_address.h +70 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +207 -0
- data/src/core/lib/iomgr/resolve_address_uv.c +284 -0
- data/src/core/lib/iomgr/resolve_address_windows.c +190 -0
- data/src/core/lib/iomgr/resource_quota.c +877 -0
- data/src/core/lib/iomgr/resource_quota.h +167 -0
- data/src/core/lib/iomgr/sockaddr.h +55 -0
- data/src/core/lib/iomgr/sockaddr_posix.h +44 -0
- data/src/core/lib/iomgr/sockaddr_utils.c +272 -0
- data/src/core/lib/iomgr/sockaddr_utils.h +93 -0
- data/src/core/lib/iomgr/sockaddr_windows.h +43 -0
- data/src/core/lib/iomgr/socket_factory_posix.c +110 -0
- data/src/core/lib/iomgr/socket_factory_posix.h +90 -0
- data/src/core/lib/iomgr/socket_mutator.c +98 -0
- data/src/core/lib/iomgr/socket_mutator.h +80 -0
- data/src/core/lib/iomgr/socket_utils.h +42 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.c +330 -0
- data/src/core/lib/iomgr/socket_utils_linux.c +57 -0
- data/src/core/lib/iomgr/socket_utils_posix.c +73 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +147 -0
- data/src/core/lib/iomgr/socket_utils_uv.c +49 -0
- data/src/core/lib/iomgr/socket_utils_windows.c +52 -0
- data/src/core/lib/iomgr/socket_windows.c +167 -0
- data/src/core/lib/iomgr/socket_windows.h +125 -0
- data/src/core/lib/iomgr/tcp_client.h +55 -0
- data/src/core/lib/iomgr/tcp_client_posix.c +368 -0
- data/src/core/lib/iomgr/tcp_client_posix.h +45 -0
- data/src/core/lib/iomgr/tcp_client_uv.c +192 -0
- data/src/core/lib/iomgr/tcp_client_windows.c +260 -0
- data/src/core/lib/iomgr/tcp_posix.c +677 -0
- data/src/core/lib/iomgr/tcp_posix.h +70 -0
- data/src/core/lib/iomgr/tcp_server.h +116 -0
- data/src/core/lib/iomgr/tcp_server_posix.c +579 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix.h +135 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +221 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_ifaddrs.c +196 -0
- data/src/core/lib/iomgr/tcp_server_utils_posix_noifaddrs.c +49 -0
- data/src/core/lib/iomgr/tcp_server_uv.c +393 -0
- data/src/core/lib/iomgr/tcp_server_windows.c +558 -0
- data/src/core/lib/iomgr/tcp_uv.c +374 -0
- data/src/core/lib/iomgr/tcp_uv.h +59 -0
- data/src/core/lib/iomgr/tcp_windows.c +462 -0
- data/src/core/lib/iomgr/tcp_windows.h +59 -0
- data/src/core/lib/iomgr/time_averaged_stats.c +77 -0
- data/src/core/lib/iomgr/time_averaged_stats.h +88 -0
- data/src/core/lib/iomgr/timer.h +111 -0
- data/src/core/lib/iomgr/timer_generic.c +567 -0
- data/src/core/lib/iomgr/timer_generic.h +49 -0
- data/src/core/lib/iomgr/timer_heap.c +152 -0
- data/src/core/lib/iomgr/timer_heap.h +57 -0
- data/src/core/lib/iomgr/timer_uv.c +103 -0
- data/src/core/lib/iomgr/timer_uv.h +47 -0
- data/src/core/lib/iomgr/udp_server.c +529 -0
- data/src/core/lib/iomgr/udp_server.h +89 -0
- data/src/core/lib/iomgr/unix_sockets_posix.c +108 -0
- data/src/core/lib/iomgr/unix_sockets_posix.h +56 -0
- data/src/core/lib/iomgr/unix_sockets_posix_noop.c +62 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.c +118 -0
- data/src/core/lib/iomgr/wakeup_fd_cv.h +80 -0
- data/src/core/lib/iomgr/wakeup_fd_eventfd.c +97 -0
- data/src/core/lib/iomgr/wakeup_fd_nospecial.c +51 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.c +112 -0
- data/src/core/lib/iomgr/wakeup_fd_pipe.h +41 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.c +101 -0
- data/src/core/lib/iomgr/wakeup_fd_posix.h +109 -0
- data/src/core/lib/iomgr/workqueue.h +87 -0
- data/src/core/lib/iomgr/workqueue_uv.c +65 -0
- data/src/core/lib/iomgr/workqueue_uv.h +37 -0
- data/src/core/lib/iomgr/workqueue_windows.c +63 -0
- data/src/core/lib/iomgr/workqueue_windows.h +37 -0
- data/src/core/lib/json/json.c +63 -0
- data/src/core/lib/json/json.h +88 -0
- data/src/core/lib/json/json_common.h +49 -0
- data/src/core/lib/json/json_reader.c +675 -0
- data/src/core/lib/json/json_reader.h +160 -0
- data/src/core/lib/json/json_string.c +379 -0
- data/src/core/lib/json/json_writer.c +258 -0
- data/src/core/lib/json/json_writer.h +97 -0
- data/src/core/lib/profiling/basic_timers.c +298 -0
- data/src/core/lib/profiling/stap_timers.c +65 -0
- data/src/core/lib/profiling/timers.h +121 -0
- data/src/core/lib/security/context/security_context.c +350 -0
- data/src/core/lib/security/context/security_context.h +134 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.c +274 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +72 -0
- data/src/core/lib/security/credentials/credentials.c +308 -0
- data/src/core/lib/security/credentials/credentials.h +268 -0
- data/src/core/lib/security/credentials/credentials_metadata.c +103 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.c +141 -0
- data/src/core/lib/security/credentials/fake/fake_credentials.h +71 -0
- data/src/core/lib/security/credentials/google_default/credentials_generic.c +54 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +337 -0
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +60 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.c +85 -0
- data/src/core/lib/security/credentials/iam/iam_credentials.h +44 -0
- data/src/core/lib/security/credentials/jwt/json_token.c +321 -0
- data/src/core/lib/security/credentials/jwt/json_token.h +88 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.c +195 -0
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +63 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +910 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.h +140 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +468 -0
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +109 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +153 -0
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +45 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.c +242 -0
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +48 -0
- data/src/core/lib/security/transport/auth_filters.h +42 -0
- data/src/core/lib/security/transport/client_auth_filter.c +384 -0
- data/src/core/lib/security/transport/lb_targets_info.c +70 -0
- data/src/core/lib/security/transport/lb_targets_info.h +47 -0
- data/src/core/lib/security/transport/secure_endpoint.c +427 -0
- data/src/core/lib/security/transport/secure_endpoint.h +49 -0
- data/src/core/lib/security/transport/security_connector.c +909 -0
- data/src/core/lib/security/transport/security_connector.h +252 -0
- data/src/core/lib/security/transport/security_handshaker.c +507 -0
- data/src/core/lib/security/transport/security_handshaker.h +49 -0
- data/src/core/lib/security/transport/server_auth_filter.c +277 -0
- data/src/core/lib/security/transport/tsi_error.c +42 -0
- data/src/core/lib/security/transport/tsi_error.h +42 -0
- data/src/core/lib/security/util/json_util.c +61 -0
- data/src/core/lib/security/util/json_util.h +55 -0
- data/src/core/lib/slice/b64.c +251 -0
- data/src/core/lib/slice/b64.h +65 -0
- data/src/core/lib/slice/percent_encoding.c +182 -0
- data/src/core/lib/slice/percent_encoding.h +78 -0
- data/src/core/lib/slice/slice.c +466 -0
- data/src/core/lib/slice/slice_buffer.c +355 -0
- data/src/core/lib/slice/slice_hash_table.c +125 -0
- data/src/core/lib/slice/slice_hash_table.h +77 -0
- data/src/core/lib/slice/slice_intern.c +346 -0
- data/src/core/lib/slice/slice_internal.h +64 -0
- data/src/core/lib/slice/slice_string_helpers.c +95 -0
- data/src/core/lib/slice/slice_string_helpers.h +63 -0
- data/src/core/lib/support/alloc.c +117 -0
- data/src/core/lib/support/arena.c +98 -0
- data/src/core/lib/support/arena.h +54 -0
- data/src/core/lib/support/atm.c +47 -0
- data/src/core/lib/support/avl.c +299 -0
- data/src/core/lib/support/backoff.c +87 -0
- data/src/core/lib/support/backoff.h +71 -0
- data/src/core/lib/support/block_annotate.h +48 -0
- data/src/core/lib/support/cmdline.c +345 -0
- data/src/core/lib/support/cpu_iphone.c +49 -0
- data/src/core/lib/support/cpu_linux.c +83 -0
- data/src/core/lib/support/cpu_posix.c +72 -0
- data/src/core/lib/support/cpu_windows.c +47 -0
- data/src/core/lib/support/env.h +58 -0
- data/src/core/lib/support/env_linux.c +89 -0
- data/src/core/lib/support/env_posix.c +57 -0
- data/src/core/lib/support/env_windows.c +79 -0
- data/src/core/lib/support/histogram.c +243 -0
- data/src/core/lib/support/host_port.c +110 -0
- data/src/core/lib/support/log.c +103 -0
- data/src/core/lib/support/log_android.c +87 -0
- data/src/core/lib/support/log_linux.c +105 -0
- data/src/core/lib/support/log_posix.c +106 -0
- data/src/core/lib/support/log_windows.c +112 -0
- data/src/core/lib/support/mpscq.c +83 -0
- data/src/core/lib/support/mpscq.h +65 -0
- data/src/core/lib/support/murmur_hash.c +94 -0
- data/src/core/lib/support/murmur_hash.h +44 -0
- data/src/core/lib/support/spinlock.h +52 -0
- data/src/core/lib/support/stack_lockfree.c +185 -0
- data/src/core/lib/support/stack_lockfree.h +53 -0
- data/src/core/lib/support/string.c +315 -0
- data/src/core/lib/support/string.h +128 -0
- data/src/core/lib/support/string_posix.c +86 -0
- data/src/core/lib/support/string_util_windows.c +94 -0
- data/src/core/lib/support/string_windows.c +83 -0
- data/src/core/lib/support/string_windows.h +47 -0
- data/src/core/lib/support/subprocess_posix.c +114 -0
- data/src/core/lib/support/subprocess_windows.c +141 -0
- data/src/core/lib/support/sync.c +137 -0
- data/src/core/lib/support/sync_posix.c +113 -0
- data/src/core/lib/support/sync_windows.c +133 -0
- data/src/core/lib/support/thd.c +64 -0
- data/src/core/lib/support/thd_internal.h +39 -0
- data/src/core/lib/support/thd_posix.c +95 -0
- data/src/core/lib/support/thd_windows.c +117 -0
- data/src/core/lib/support/time.c +262 -0
- data/src/core/lib/support/time_posix.c +176 -0
- data/src/core/lib/support/time_precise.c +89 -0
- data/src/core/lib/support/time_precise.h +42 -0
- data/src/core/lib/support/time_windows.c +116 -0
- data/src/core/lib/support/tls_pthread.c +45 -0
- data/src/core/lib/support/tmpfile.h +53 -0
- data/src/core/lib/support/tmpfile_msys.c +73 -0
- data/src/core/lib/support/tmpfile_posix.c +85 -0
- data/src/core/lib/support/tmpfile_windows.c +84 -0
- data/src/core/lib/support/wrap_memcpy.c +55 -0
- data/src/core/lib/surface/alarm.c +87 -0
- data/src/core/lib/surface/api_trace.c +36 -0
- data/src/core/lib/surface/api_trace.h +65 -0
- data/src/core/lib/surface/byte_buffer.c +103 -0
- data/src/core/lib/surface/byte_buffer_reader.c +140 -0
- data/src/core/lib/surface/call.c +1835 -0
- data/src/core/lib/surface/call.h +135 -0
- data/src/core/lib/surface/call_details.c +56 -0
- data/src/core/lib/surface/call_log_batch.c +131 -0
- data/src/core/lib/surface/call_test_only.h +64 -0
- data/src/core/lib/surface/channel.c +434 -0
- data/src/core/lib/surface/channel.h +99 -0
- data/src/core/lib/surface/channel_init.c +140 -0
- data/src/core/lib/surface/channel_init.h +96 -0
- data/src/core/lib/surface/channel_ping.c +80 -0
- data/src/core/lib/surface/channel_stack_type.c +54 -0
- data/src/core/lib/surface/channel_stack_type.h +58 -0
- data/src/core/lib/surface/completion_queue.c +692 -0
- data/src/core/lib/surface/completion_queue.h +102 -0
- data/src/core/lib/surface/completion_queue_factory.c +77 -0
- data/src/core/lib/surface/completion_queue_factory.h +51 -0
- data/src/core/lib/surface/event_string.c +81 -0
- data/src/core/lib/surface/event_string.h +42 -0
- data/src/core/lib/surface/init.c +261 -0
- data/src/core/lib/surface/init.h +42 -0
- data/src/core/lib/surface/init_secure.c +94 -0
- data/src/core/lib/surface/lame_client.c +188 -0
- data/src/core/lib/surface/lame_client.h +41 -0
- data/src/core/lib/surface/metadata_array.c +49 -0
- data/src/core/lib/surface/server.c +1529 -0
- data/src/core/lib/surface/server.h +71 -0
- data/src/core/lib/surface/validate_metadata.c +108 -0
- data/src/core/lib/surface/validate_metadata.h +43 -0
- data/src/core/lib/surface/version.c +41 -0
- data/src/core/lib/transport/bdp_estimator.c +104 -0
- data/src/core/lib/transport/bdp_estimator.h +76 -0
- data/src/core/lib/transport/byte_stream.c +81 -0
- data/src/core/lib/transport/byte_stream.h +85 -0
- data/src/core/lib/transport/connectivity_state.c +219 -0
- data/src/core/lib/transport/connectivity_state.h +101 -0
- data/src/core/lib/transport/error_utils.c +124 -0
- data/src/core/lib/transport/error_utils.h +56 -0
- data/src/core/lib/transport/http2_errors.h +56 -0
- data/src/core/lib/transport/metadata.c +529 -0
- data/src/core/lib/transport/metadata.h +186 -0
- data/src/core/lib/transport/metadata_batch.c +328 -0
- data/src/core/lib/transport/metadata_batch.h +166 -0
- data/src/core/lib/transport/pid_controller.c +78 -0
- data/src/core/lib/transport/pid_controller.h +77 -0
- data/src/core/lib/transport/service_config.c +266 -0
- data/src/core/lib/transport/service_config.h +77 -0
- data/src/core/lib/transport/static_metadata.c +801 -0
- data/src/core/lib/transport/static_metadata.h +557 -0
- data/src/core/lib/transport/status_conversion.c +113 -0
- data/src/core/lib/transport/status_conversion.h +49 -0
- data/src/core/lib/transport/timeout_encoding.c +190 -0
- data/src/core/lib/transport/timeout_encoding.h +49 -0
- data/src/core/lib/transport/transport.c +282 -0
- data/src/core/lib/transport/transport.h +354 -0
- data/src/core/lib/transport/transport_impl.h +90 -0
- data/src/core/lib/transport/transport_op_string.c +217 -0
- data/src/core/plugin_registry/grpc_plugin_registry.c +82 -0
- data/src/core/tsi/fake_transport_security.c +527 -0
- data/src/core/tsi/fake_transport_security.h +61 -0
- data/src/core/tsi/ssl_transport_security.c +1533 -0
- data/src/core/tsi/ssl_transport_security.h +214 -0
- data/src/core/tsi/ssl_types.h +55 -0
- data/src/core/tsi/transport_security.c +266 -0
- data/src/core/tsi/transport_security.h +111 -0
- data/src/core/tsi/transport_security_interface.h +353 -0
- data/src/ruby/bin/apis/google/protobuf/empty.rb +44 -0
- data/src/ruby/bin/apis/pubsub_demo.rb +256 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub.rb +174 -0
- data/src/ruby/bin/apis/tech/pubsub/proto/pubsub_services.rb +103 -0
- data/src/ruby/bin/math_client.rb +147 -0
- data/src/ruby/bin/math_pb.rb +32 -0
- data/src/ruby/bin/math_server.rb +206 -0
- data/src/ruby/bin/math_services_pb.rb +66 -0
- data/src/ruby/bin/noproto_client.rb +108 -0
- data/src/ruby/bin/noproto_server.rb +112 -0
- data/src/ruby/ext/grpc/extconf.rb +131 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +77 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +50 -0
- data/src/ruby/ext/grpc/rb_call.c +1009 -0
- data/src/ruby/ext/grpc/rb_call.h +66 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +295 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +46 -0
- data/src/ruby/ext/grpc/rb_channel.c +662 -0
- data/src/ruby/ext/grpc/rb_channel.h +49 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +168 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +53 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +268 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +47 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +117 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +51 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +472 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +44 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +158 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +37 -0
- data/src/ruby/ext/grpc/rb_grpc.c +343 -0
- data/src/ruby/ext/grpc/rb_grpc.h +87 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +634 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +955 -0
- data/src/ruby/ext/grpc/rb_loader.c +72 -0
- data/src/ruby/ext/grpc/rb_loader.h +40 -0
- data/src/ruby/ext/grpc/rb_server.c +359 -0
- data/src/ruby/ext/grpc/rb_server.h +47 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +47 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +71 -0
- data/src/ruby/lib/grpc/errors.rb +215 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +547 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +229 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +463 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +173 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +476 -0
- data/src/ruby/lib/grpc/generic/service.rb +225 -0
- data/src/ruby/lib/grpc/grpc.rb +39 -0
- data/src/ruby/lib/grpc/grpc_c.bundle +0 -0
- data/src/ruby/lib/grpc/logconfig.rb +59 -0
- data/src/ruby/lib/grpc/notifier.rb +60 -0
- data/src/ruby/lib/grpc/version.rb +33 -0
- data/src/ruby/lib/grpc.rb +49 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +58 -0
- data/src/ruby/pb/grpc/health/checker.rb +77 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +28 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +56 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +58 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +64 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +15 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +82 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +14 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +117 -0
- data/src/ruby/pb/test/client.rb +779 -0
- data/src/ruby/pb/test/server.rb +267 -0
- data/src/ruby/spec/call_credentials_spec.rb +57 -0
- data/src/ruby/spec/call_spec.rb +162 -0
- data/src/ruby/spec/channel_connection_spec.rb +141 -0
- data/src/ruby/spec/channel_credentials_spec.rb +97 -0
- data/src/ruby/spec/channel_spec.rb +205 -0
- data/src/ruby/spec/client_server_spec.rb +491 -0
- data/src/ruby/spec/compression_options_spec.rb +164 -0
- data/src/ruby/spec/error_sanity_spec.rb +64 -0
- data/src/ruby/spec/generic/active_call_spec.rb +632 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +556 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +351 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +142 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +524 -0
- data/src/ruby/spec/generic/service_spec.rb +276 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +71 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +222 -0
- data/src/ruby/spec/server_credentials_spec.rb +94 -0
- data/src/ruby/spec/server_spec.rb +205 -0
- data/src/ruby/spec/spec_helper.rb +71 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +15 -0
- data/src/ruby/spec/testdata/server1.key +16 -0
- data/src/ruby/spec/testdata/server1.pem +16 -0
- data/src/ruby/spec/time_consts_spec.rb +89 -0
- data/third_party/boringssl/crypto/aes/aes.c +1142 -0
- data/third_party/boringssl/crypto/aes/internal.h +87 -0
- data/third_party/boringssl/crypto/aes/mode_wrappers.c +112 -0
- data/third_party/boringssl/crypto/asn1/a_bitstr.c +263 -0
- data/third_party/boringssl/crypto/asn1/a_bool.c +110 -0
- data/third_party/boringssl/crypto/asn1/a_d2i_fp.c +282 -0
- data/third_party/boringssl/crypto/asn1/a_dup.c +111 -0
- data/third_party/boringssl/crypto/asn1/a_enum.c +181 -0
- data/third_party/boringssl/crypto/asn1/a_gentm.c +256 -0
- data/third_party/boringssl/crypto/asn1/a_i2d_fp.c +147 -0
- data/third_party/boringssl/crypto/asn1/a_int.c +460 -0
- data/third_party/boringssl/crypto/asn1/a_mbstr.c +409 -0
- data/third_party/boringssl/crypto/asn1/a_object.c +400 -0
- data/third_party/boringssl/crypto/asn1/a_octet.c +77 -0
- data/third_party/boringssl/crypto/asn1/a_print.c +121 -0
- data/third_party/boringssl/crypto/asn1/a_strnid.c +309 -0
- data/third_party/boringssl/crypto/asn1/a_time.c +206 -0
- data/third_party/boringssl/crypto/asn1/a_type.c +151 -0
- data/third_party/boringssl/crypto/asn1/a_utctm.c +304 -0
- data/third_party/boringssl/crypto/asn1/a_utf8.c +234 -0
- data/third_party/boringssl/crypto/asn1/asn1_lib.c +483 -0
- data/third_party/boringssl/crypto/asn1/asn1_locl.h +63 -0
- data/third_party/boringssl/crypto/asn1/asn1_par.c +80 -0
- data/third_party/boringssl/crypto/asn1/asn_pack.c +105 -0
- data/third_party/boringssl/crypto/asn1/f_enum.c +93 -0
- data/third_party/boringssl/crypto/asn1/f_int.c +97 -0
- data/third_party/boringssl/crypto/asn1/f_string.c +91 -0
- data/third_party/boringssl/crypto/asn1/t_bitst.c +103 -0
- data/third_party/boringssl/crypto/asn1/tasn_dec.c +1221 -0
- data/third_party/boringssl/crypto/asn1/tasn_enc.c +665 -0
- data/third_party/boringssl/crypto/asn1/tasn_fre.c +246 -0
- data/third_party/boringssl/crypto/asn1/tasn_new.c +381 -0
- data/third_party/boringssl/crypto/asn1/tasn_typ.c +131 -0
- data/third_party/boringssl/crypto/asn1/tasn_utl.c +266 -0
- data/third_party/boringssl/crypto/asn1/x_bignum.c +153 -0
- data/third_party/boringssl/crypto/asn1/x_long.c +197 -0
- data/third_party/boringssl/crypto/base64/base64.c +442 -0
- data/third_party/boringssl/crypto/bio/bio.c +598 -0
- data/third_party/boringssl/crypto/bio/bio_mem.c +328 -0
- data/third_party/boringssl/crypto/bio/buffer.c +496 -0
- data/third_party/boringssl/crypto/bio/connect.c +553 -0
- data/third_party/boringssl/crypto/bio/fd.c +277 -0
- data/third_party/boringssl/crypto/bio/file.c +313 -0
- data/third_party/boringssl/crypto/bio/hexdump.c +191 -0
- data/third_party/boringssl/crypto/bio/internal.h +111 -0
- data/third_party/boringssl/crypto/bio/pair.c +803 -0
- data/third_party/boringssl/crypto/bio/printf.c +119 -0
- data/third_party/boringssl/crypto/bio/socket.c +203 -0
- data/third_party/boringssl/crypto/bio/socket_helper.c +113 -0
- data/third_party/boringssl/crypto/bn/add.c +377 -0
- data/third_party/boringssl/crypto/bn/asm/x86_64-gcc.c +531 -0
- data/third_party/boringssl/crypto/bn/bn.c +379 -0
- data/third_party/boringssl/crypto/bn/bn_asn1.c +80 -0
- data/third_party/boringssl/crypto/bn/cmp.c +225 -0
- data/third_party/boringssl/crypto/bn/convert.c +599 -0
- data/third_party/boringssl/crypto/bn/ctx.c +311 -0
- data/third_party/boringssl/crypto/bn/div.c +671 -0
- data/third_party/boringssl/crypto/bn/exponentiation.c +1258 -0
- data/third_party/boringssl/crypto/bn/gcd.c +628 -0
- data/third_party/boringssl/crypto/bn/generic.c +703 -0
- data/third_party/boringssl/crypto/bn/internal.h +245 -0
- data/third_party/boringssl/crypto/bn/kronecker.c +175 -0
- data/third_party/boringssl/crypto/bn/montgomery.c +410 -0
- data/third_party/boringssl/crypto/bn/montgomery_inv.c +160 -0
- data/third_party/boringssl/crypto/bn/mul.c +869 -0
- data/third_party/boringssl/crypto/bn/prime.c +861 -0
- data/third_party/boringssl/crypto/bn/random.c +340 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.c +319 -0
- data/third_party/boringssl/crypto/bn/rsaz_exp.h +56 -0
- data/third_party/boringssl/crypto/bn/shift.c +299 -0
- data/third_party/boringssl/crypto/bn/sqrt.c +504 -0
- data/third_party/boringssl/crypto/buf/buf.c +239 -0
- data/third_party/boringssl/crypto/bytestring/asn1_compat.c +51 -0
- data/third_party/boringssl/crypto/bytestring/ber.c +263 -0
- data/third_party/boringssl/crypto/bytestring/cbb.c +473 -0
- data/third_party/boringssl/crypto/bytestring/cbs.c +439 -0
- data/third_party/boringssl/crypto/bytestring/internal.h +75 -0
- data/third_party/boringssl/crypto/chacha/chacha.c +167 -0
- data/third_party/boringssl/crypto/cipher/aead.c +156 -0
- data/third_party/boringssl/crypto/cipher/cipher.c +652 -0
- data/third_party/boringssl/crypto/cipher/derive_key.c +154 -0
- data/third_party/boringssl/crypto/cipher/e_aes.c +1717 -0
- data/third_party/boringssl/crypto/cipher/e_chacha20poly1305.c +300 -0
- data/third_party/boringssl/crypto/cipher/e_des.c +205 -0
- data/third_party/boringssl/crypto/cipher/e_null.c +85 -0
- data/third_party/boringssl/crypto/cipher/e_rc2.c +443 -0
- data/third_party/boringssl/crypto/cipher/e_rc4.c +87 -0
- data/third_party/boringssl/crypto/cipher/e_ssl3.c +403 -0
- data/third_party/boringssl/crypto/cipher/e_tls.c +602 -0
- data/third_party/boringssl/crypto/cipher/internal.h +162 -0
- data/third_party/boringssl/crypto/cipher/tls_cbc.c +553 -0
- data/third_party/boringssl/crypto/cmac/cmac.c +239 -0
- data/third_party/boringssl/crypto/conf/conf.c +788 -0
- data/third_party/boringssl/crypto/conf/conf_def.h +127 -0
- data/third_party/boringssl/crypto/conf/internal.h +31 -0
- data/third_party/boringssl/crypto/cpu-aarch64-linux.c +61 -0
- data/third_party/boringssl/crypto/cpu-arm-linux.c +360 -0
- data/third_party/boringssl/crypto/cpu-arm.c +38 -0
- data/third_party/boringssl/crypto/cpu-intel.c +263 -0
- data/third_party/boringssl/crypto/cpu-ppc64le.c +40 -0
- data/third_party/boringssl/crypto/crypto.c +164 -0
- data/third_party/boringssl/crypto/curve25519/curve25519.c +4944 -0
- data/third_party/boringssl/crypto/curve25519/internal.h +109 -0
- data/third_party/boringssl/crypto/curve25519/spake25519.c +464 -0
- data/third_party/boringssl/crypto/curve25519/x25519-x86_64.c +246 -0
- data/third_party/boringssl/crypto/des/des.c +771 -0
- data/third_party/boringssl/crypto/des/internal.h +212 -0
- data/third_party/boringssl/crypto/dh/check.c +218 -0
- data/third_party/boringssl/crypto/dh/dh.c +487 -0
- data/third_party/boringssl/crypto/dh/dh_asn1.c +160 -0
- data/third_party/boringssl/crypto/dh/params.c +253 -0
- data/third_party/boringssl/crypto/digest/digest.c +248 -0
- data/third_party/boringssl/crypto/digest/digests.c +321 -0
- data/third_party/boringssl/crypto/digest/internal.h +112 -0
- data/third_party/boringssl/crypto/digest/md32_common.h +262 -0
- data/third_party/boringssl/crypto/dsa/dsa.c +964 -0
- data/third_party/boringssl/crypto/dsa/dsa_asn1.c +339 -0
- data/third_party/boringssl/crypto/ec/ec.c +847 -0
- data/third_party/boringssl/crypto/ec/ec_asn1.c +549 -0
- data/third_party/boringssl/crypto/ec/ec_key.c +479 -0
- data/third_party/boringssl/crypto/ec/ec_montgomery.c +308 -0
- data/third_party/boringssl/crypto/ec/internal.h +276 -0
- data/third_party/boringssl/crypto/ec/oct.c +428 -0
- data/third_party/boringssl/crypto/ec/p224-64.c +1187 -0
- data/third_party/boringssl/crypto/ec/p256-64.c +1741 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64-table.h +9543 -0
- data/third_party/boringssl/crypto/ec/p256-x86_64.c +574 -0
- data/third_party/boringssl/crypto/ec/simple.c +1117 -0
- data/third_party/boringssl/crypto/ec/util-64.c +109 -0
- data/third_party/boringssl/crypto/ec/wnaf.c +449 -0
- data/third_party/boringssl/crypto/ecdh/ecdh.c +159 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa.c +478 -0
- data/third_party/boringssl/crypto/ecdsa/ecdsa_asn1.c +227 -0
- data/third_party/boringssl/crypto/engine/engine.c +96 -0
- data/third_party/boringssl/crypto/err/err.c +756 -0
- data/third_party/boringssl/crypto/evp/digestsign.c +159 -0
- data/third_party/boringssl/crypto/evp/evp.c +367 -0
- data/third_party/boringssl/crypto/evp/evp_asn1.c +337 -0
- data/third_party/boringssl/crypto/evp/evp_ctx.c +448 -0
- data/third_party/boringssl/crypto/evp/internal.h +237 -0
- data/third_party/boringssl/crypto/evp/p_dsa_asn1.c +268 -0
- data/third_party/boringssl/crypto/evp/p_ec.c +236 -0
- data/third_party/boringssl/crypto/evp/p_ec_asn1.c +257 -0
- data/third_party/boringssl/crypto/evp/p_rsa.c +673 -0
- data/third_party/boringssl/crypto/evp/p_rsa_asn1.c +200 -0
- data/third_party/boringssl/crypto/evp/pbkdf.c +151 -0
- data/third_party/boringssl/crypto/evp/print.c +520 -0
- data/third_party/boringssl/crypto/evp/sign.c +151 -0
- data/third_party/boringssl/crypto/ex_data.c +292 -0
- data/third_party/boringssl/crypto/hkdf/hkdf.c +110 -0
- data/third_party/boringssl/crypto/hmac/hmac.c +213 -0
- data/third_party/boringssl/crypto/internal.h +527 -0
- data/third_party/boringssl/crypto/lhash/lhash.c +342 -0
- data/third_party/boringssl/crypto/md4/md4.c +234 -0
- data/third_party/boringssl/crypto/md5/md5.c +275 -0
- data/third_party/boringssl/crypto/mem.c +200 -0
- data/third_party/boringssl/crypto/modes/cbc.c +216 -0
- data/third_party/boringssl/crypto/modes/cfb.c +230 -0
- data/third_party/boringssl/crypto/modes/ctr.c +219 -0
- data/third_party/boringssl/crypto/modes/gcm.c +1288 -0
- data/third_party/boringssl/crypto/modes/internal.h +358 -0
- data/third_party/boringssl/crypto/modes/ofb.c +95 -0
- data/third_party/boringssl/crypto/newhope/error_correction.c +131 -0
- data/third_party/boringssl/crypto/newhope/internal.h +71 -0
- data/third_party/boringssl/crypto/newhope/newhope.c +174 -0
- data/third_party/boringssl/crypto/newhope/ntt.c +148 -0
- data/third_party/boringssl/crypto/newhope/poly.c +183 -0
- data/third_party/boringssl/crypto/newhope/precomp.c +306 -0
- data/third_party/boringssl/crypto/newhope/reduce.c +42 -0
- data/third_party/boringssl/crypto/obj/obj.c +640 -0
- data/third_party/boringssl/crypto/obj/obj_dat.h +5254 -0
- data/third_party/boringssl/crypto/obj/obj_xref.c +124 -0
- data/third_party/boringssl/crypto/obj/obj_xref.h +96 -0
- data/third_party/boringssl/crypto/pem/pem_all.c +262 -0
- data/third_party/boringssl/crypto/pem/pem_info.c +381 -0
- data/third_party/boringssl/crypto/pem/pem_lib.c +778 -0
- data/third_party/boringssl/crypto/pem/pem_oth.c +88 -0
- data/third_party/boringssl/crypto/pem/pem_pk8.c +257 -0
- data/third_party/boringssl/crypto/pem/pem_pkey.c +227 -0
- data/third_party/boringssl/crypto/pem/pem_x509.c +65 -0
- data/third_party/boringssl/crypto/pem/pem_xaux.c +67 -0
- data/third_party/boringssl/crypto/pkcs8/internal.h +83 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbe.c +151 -0
- data/third_party/boringssl/crypto/pkcs8/p5_pbev2.c +441 -0
- data/third_party/boringssl/crypto/pkcs8/p8_pkey.c +85 -0
- data/third_party/boringssl/crypto/pkcs8/pkcs8.c +1219 -0
- data/third_party/boringssl/crypto/poly1305/internal.h +40 -0
- data/third_party/boringssl/crypto/poly1305/poly1305.c +324 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_arm.c +304 -0
- data/third_party/boringssl/crypto/poly1305/poly1305_vec.c +890 -0
- data/third_party/boringssl/crypto/rand/deterministic.c +47 -0
- data/third_party/boringssl/crypto/rand/internal.h +32 -0
- data/third_party/boringssl/crypto/rand/rand.c +244 -0
- data/third_party/boringssl/crypto/rand/urandom.c +221 -0
- data/third_party/boringssl/crypto/rand/windows.c +53 -0
- data/third_party/boringssl/crypto/rc4/rc4.c +98 -0
- data/third_party/boringssl/crypto/refcount_c11.c +67 -0
- data/third_party/boringssl/crypto/refcount_lock.c +53 -0
- data/third_party/boringssl/crypto/rsa/blinding.c +264 -0
- data/third_party/boringssl/crypto/rsa/internal.h +148 -0
- data/third_party/boringssl/crypto/rsa/padding.c +708 -0
- data/third_party/boringssl/crypto/rsa/rsa.c +830 -0
- data/third_party/boringssl/crypto/rsa/rsa_asn1.c +446 -0
- data/third_party/boringssl/crypto/rsa/rsa_impl.c +1139 -0
- data/third_party/boringssl/crypto/sha/sha1.c +337 -0
- data/third_party/boringssl/crypto/sha/sha256.c +327 -0
- data/third_party/boringssl/crypto/sha/sha512.c +607 -0
- data/third_party/boringssl/crypto/stack/stack.c +377 -0
- data/third_party/boringssl/crypto/thread.c +110 -0
- data/third_party/boringssl/crypto/thread_none.c +59 -0
- data/third_party/boringssl/crypto/thread_pthread.c +176 -0
- data/third_party/boringssl/crypto/thread_win.c +237 -0
- data/third_party/boringssl/crypto/time_support.c +206 -0
- data/third_party/boringssl/crypto/x509/a_digest.c +96 -0
- data/third_party/boringssl/crypto/x509/a_sign.c +135 -0
- data/third_party/boringssl/crypto/x509/a_strex.c +633 -0
- data/third_party/boringssl/crypto/x509/a_verify.c +127 -0
- data/third_party/boringssl/crypto/x509/algorithm.c +137 -0
- data/third_party/boringssl/crypto/x509/asn1_gen.c +818 -0
- data/third_party/boringssl/crypto/x509/by_dir.c +453 -0
- data/third_party/boringssl/crypto/x509/by_file.c +275 -0
- data/third_party/boringssl/crypto/x509/charmap.h +15 -0
- data/third_party/boringssl/crypto/x509/i2d_pr.c +83 -0
- data/third_party/boringssl/crypto/x509/internal.h +66 -0
- data/third_party/boringssl/crypto/x509/pkcs7.c +353 -0
- data/third_party/boringssl/crypto/x509/rsa_pss.c +385 -0
- data/third_party/boringssl/crypto/x509/t_crl.c +128 -0
- data/third_party/boringssl/crypto/x509/t_req.c +246 -0
- data/third_party/boringssl/crypto/x509/t_x509.c +506 -0
- data/third_party/boringssl/crypto/x509/t_x509a.c +111 -0
- data/third_party/boringssl/crypto/x509/vpm_int.h +70 -0
- data/third_party/boringssl/crypto/x509/x509.c +157 -0
- data/third_party/boringssl/crypto/x509/x509_att.c +381 -0
- data/third_party/boringssl/crypto/x509/x509_cmp.c +474 -0
- data/third_party/boringssl/crypto/x509/x509_d2.c +106 -0
- data/third_party/boringssl/crypto/x509/x509_def.c +98 -0
- data/third_party/boringssl/crypto/x509/x509_ext.c +206 -0
- data/third_party/boringssl/crypto/x509/x509_lu.c +690 -0
- data/third_party/boringssl/crypto/x509/x509_obj.c +197 -0
- data/third_party/boringssl/crypto/x509/x509_r2x.c +117 -0
- data/third_party/boringssl/crypto/x509/x509_req.c +322 -0
- data/third_party/boringssl/crypto/x509/x509_set.c +154 -0
- data/third_party/boringssl/crypto/x509/x509_trs.c +326 -0
- data/third_party/boringssl/crypto/x509/x509_txt.c +211 -0
- data/third_party/boringssl/crypto/x509/x509_v3.c +278 -0
- data/third_party/boringssl/crypto/x509/x509_vfy.c +2436 -0
- data/third_party/boringssl/crypto/x509/x509_vpm.c +647 -0
- data/third_party/boringssl/crypto/x509/x509cset.c +170 -0
- data/third_party/boringssl/crypto/x509/x509name.c +386 -0
- data/third_party/boringssl/crypto/x509/x509rset.c +81 -0
- data/third_party/boringssl/crypto/x509/x509spki.c +137 -0
- data/third_party/boringssl/crypto/x509/x509type.c +126 -0
- data/third_party/boringssl/crypto/x509/x_algor.c +151 -0
- data/third_party/boringssl/crypto/x509/x_all.c +501 -0
- data/third_party/boringssl/crypto/x509/x_attrib.c +111 -0
- data/third_party/boringssl/crypto/x509/x_crl.c +539 -0
- data/third_party/boringssl/crypto/x509/x_exten.c +75 -0
- data/third_party/boringssl/crypto/x509/x_info.c +98 -0
- data/third_party/boringssl/crypto/x509/x_name.c +534 -0
- data/third_party/boringssl/crypto/x509/x_pkey.c +103 -0
- data/third_party/boringssl/crypto/x509/x_pubkey.c +368 -0
- data/third_party/boringssl/crypto/x509/x_req.c +109 -0
- data/third_party/boringssl/crypto/x509/x_sig.c +69 -0
- data/third_party/boringssl/crypto/x509/x_spki.c +80 -0
- data/third_party/boringssl/crypto/x509/x_val.c +69 -0
- data/third_party/boringssl/crypto/x509/x_x509.c +289 -0
- data/third_party/boringssl/crypto/x509/x_x509a.c +205 -0
- data/third_party/boringssl/crypto/x509v3/ext_dat.h +135 -0
- data/third_party/boringssl/crypto/x509v3/pcy_cache.c +284 -0
- data/third_party/boringssl/crypto/x509v3/pcy_data.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_int.h +217 -0
- data/third_party/boringssl/crypto/x509v3/pcy_lib.c +164 -0
- data/third_party/boringssl/crypto/x509v3/pcy_map.c +130 -0
- data/third_party/boringssl/crypto/x509v3/pcy_node.c +188 -0
- data/third_party/boringssl/crypto/x509v3/pcy_tree.c +829 -0
- data/third_party/boringssl/crypto/x509v3/v3_akey.c +204 -0
- data/third_party/boringssl/crypto/x509v3/v3_akeya.c +72 -0
- data/third_party/boringssl/crypto/x509v3/v3_alt.c +614 -0
- data/third_party/boringssl/crypto/x509v3/v3_bcons.c +133 -0
- data/third_party/boringssl/crypto/x509v3/v3_bitst.c +141 -0
- data/third_party/boringssl/crypto/x509v3/v3_conf.c +462 -0
- data/third_party/boringssl/crypto/x509v3/v3_cpols.c +496 -0
- data/third_party/boringssl/crypto/x509v3/v3_crld.c +561 -0
- data/third_party/boringssl/crypto/x509v3/v3_enum.c +100 -0
- data/third_party/boringssl/crypto/x509v3/v3_extku.c +148 -0
- data/third_party/boringssl/crypto/x509v3/v3_genn.c +250 -0
- data/third_party/boringssl/crypto/x509v3/v3_ia5.c +119 -0
- data/third_party/boringssl/crypto/x509v3/v3_info.c +212 -0
- data/third_party/boringssl/crypto/x509v3/v3_int.c +91 -0
- data/third_party/boringssl/crypto/x509v3/v3_lib.c +362 -0
- data/third_party/boringssl/crypto/x509v3/v3_ncons.c +482 -0
- data/third_party/boringssl/crypto/x509v3/v3_pci.c +317 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcia.c +57 -0
- data/third_party/boringssl/crypto/x509v3/v3_pcons.c +139 -0
- data/third_party/boringssl/crypto/x509v3/v3_pku.c +110 -0
- data/third_party/boringssl/crypto/x509v3/v3_pmaps.c +154 -0
- data/third_party/boringssl/crypto/x509v3/v3_prn.c +229 -0
- data/third_party/boringssl/crypto/x509v3/v3_purp.c +874 -0
- data/third_party/boringssl/crypto/x509v3/v3_skey.c +152 -0
- data/third_party/boringssl/crypto/x509v3/v3_sxnet.c +274 -0
- data/third_party/boringssl/crypto/x509v3/v3_utl.c +1327 -0
- data/third_party/boringssl/include/openssl/aead.h +345 -0
- data/third_party/boringssl/include/openssl/aes.h +158 -0
- data/third_party/boringssl/include/openssl/arm_arch.h +121 -0
- data/third_party/boringssl/include/openssl/asn1.h +1038 -0
- data/third_party/boringssl/include/openssl/asn1_mac.h +18 -0
- data/third_party/boringssl/include/openssl/asn1t.h +896 -0
- data/third_party/boringssl/include/openssl/base.h +412 -0
- data/third_party/boringssl/include/openssl/base64.h +187 -0
- data/third_party/boringssl/include/openssl/bio.h +926 -0
- data/third_party/boringssl/include/openssl/blowfish.h +93 -0
- data/third_party/boringssl/include/openssl/bn.h +955 -0
- data/third_party/boringssl/include/openssl/buf.h +133 -0
- data/third_party/boringssl/include/openssl/buffer.h +18 -0
- data/third_party/boringssl/include/openssl/bytestring.h +437 -0
- data/third_party/boringssl/include/openssl/cast.h +96 -0
- data/third_party/boringssl/include/openssl/chacha.h +37 -0
- data/third_party/boringssl/include/openssl/cipher.h +588 -0
- data/third_party/boringssl/include/openssl/cmac.h +87 -0
- data/third_party/boringssl/include/openssl/conf.h +181 -0
- data/third_party/boringssl/include/openssl/cpu.h +181 -0
- data/third_party/boringssl/include/openssl/crypto.h +94 -0
- data/third_party/boringssl/include/openssl/curve25519.h +183 -0
- data/third_party/boringssl/include/openssl/des.h +177 -0
- data/third_party/boringssl/include/openssl/dh.h +297 -0
- data/third_party/boringssl/include/openssl/digest.h +285 -0
- data/third_party/boringssl/include/openssl/dsa.h +436 -0
- data/third_party/boringssl/include/openssl/dtls1.h +16 -0
- data/third_party/boringssl/include/openssl/ec.h +406 -0
- data/third_party/boringssl/include/openssl/ec_key.h +337 -0
- data/third_party/boringssl/include/openssl/ecdh.h +102 -0
- data/third_party/boringssl/include/openssl/ecdsa.h +217 -0
- data/third_party/boringssl/include/openssl/engine.h +109 -0
- data/third_party/boringssl/include/openssl/err.h +488 -0
- data/third_party/boringssl/include/openssl/evp.h +797 -0
- data/third_party/boringssl/include/openssl/ex_data.h +213 -0
- data/third_party/boringssl/include/openssl/hkdf.h +64 -0
- data/third_party/boringssl/include/openssl/hmac.h +174 -0
- data/third_party/boringssl/include/openssl/lhash.h +192 -0
- data/third_party/boringssl/include/openssl/lhash_macros.h +132 -0
- data/third_party/boringssl/include/openssl/md4.h +106 -0
- data/third_party/boringssl/include/openssl/md5.h +107 -0
- data/third_party/boringssl/include/openssl/mem.h +150 -0
- data/third_party/boringssl/include/openssl/newhope.h +158 -0
- data/third_party/boringssl/include/openssl/nid.h +4166 -0
- data/third_party/boringssl/include/openssl/obj.h +226 -0
- data/third_party/boringssl/include/openssl/obj_mac.h +18 -0
- data/third_party/boringssl/include/openssl/objects.h +18 -0
- data/third_party/boringssl/include/openssl/opensslconf.h +60 -0
- data/third_party/boringssl/include/openssl/opensslv.h +18 -0
- data/third_party/boringssl/include/openssl/ossl_typ.h +18 -0
- data/third_party/boringssl/include/openssl/pem.h +517 -0
- data/third_party/boringssl/include/openssl/pkcs12.h +18 -0
- data/third_party/boringssl/include/openssl/pkcs7.h +16 -0
- data/third_party/boringssl/include/openssl/pkcs8.h +236 -0
- data/third_party/boringssl/include/openssl/poly1305.h +51 -0
- data/third_party/boringssl/include/openssl/rand.h +122 -0
- data/third_party/boringssl/include/openssl/rc4.h +96 -0
- data/third_party/boringssl/include/openssl/ripemd.h +107 -0
- data/third_party/boringssl/include/openssl/rsa.h +699 -0
- data/third_party/boringssl/include/openssl/safestack.h +16 -0
- data/third_party/boringssl/include/openssl/sha.h +260 -0
- data/third_party/boringssl/include/openssl/srtp.h +18 -0
- data/third_party/boringssl/include/openssl/ssl.h +4826 -0
- data/third_party/boringssl/include/openssl/ssl3.h +434 -0
- data/third_party/boringssl/include/openssl/stack.h +293 -0
- data/third_party/boringssl/include/openssl/stack_macros.h +3902 -0
- data/third_party/boringssl/include/openssl/thread.h +191 -0
- data/third_party/boringssl/include/openssl/time_support.h +91 -0
- data/third_party/boringssl/include/openssl/tls1.h +657 -0
- data/third_party/boringssl/include/openssl/type_check.h +91 -0
- data/third_party/boringssl/include/openssl/x509.h +1299 -0
- data/third_party/boringssl/include/openssl/x509_vfy.h +618 -0
- data/third_party/boringssl/include/openssl/x509v3.h +819 -0
- data/third_party/boringssl/ssl/custom_extensions.c +255 -0
- data/third_party/boringssl/ssl/d1_both.c +845 -0
- data/third_party/boringssl/ssl/d1_lib.c +270 -0
- data/third_party/boringssl/ssl/d1_pkt.c +419 -0
- data/third_party/boringssl/ssl/d1_srtp.c +236 -0
- data/third_party/boringssl/ssl/dtls_method.c +203 -0
- data/third_party/boringssl/ssl/dtls_record.c +309 -0
- data/third_party/boringssl/ssl/handshake_client.c +2002 -0
- data/third_party/boringssl/ssl/handshake_server.c +1932 -0
- data/third_party/boringssl/ssl/internal.h +1551 -0
- data/third_party/boringssl/ssl/s3_both.c +745 -0
- data/third_party/boringssl/ssl/s3_enc.c +412 -0
- data/third_party/boringssl/ssl/s3_lib.c +336 -0
- data/third_party/boringssl/ssl/s3_pkt.c +497 -0
- data/third_party/boringssl/ssl/ssl_aead_ctx.c +329 -0
- data/third_party/boringssl/ssl/ssl_asn1.c +748 -0
- data/third_party/boringssl/ssl/ssl_buffer.c +311 -0
- data/third_party/boringssl/ssl/ssl_cert.c +814 -0
- data/third_party/boringssl/ssl/ssl_cipher.c +2062 -0
- data/third_party/boringssl/ssl/ssl_ecdh.c +610 -0
- data/third_party/boringssl/ssl/ssl_file.c +586 -0
- data/third_party/boringssl/ssl/ssl_lib.c +3063 -0
- data/third_party/boringssl/ssl/ssl_rsa.c +793 -0
- data/third_party/boringssl/ssl/ssl_session.c +985 -0
- data/third_party/boringssl/ssl/ssl_stat.c +509 -0
- data/third_party/boringssl/ssl/t1_enc.c +547 -0
- data/third_party/boringssl/ssl/t1_lib.c +3279 -0
- data/third_party/boringssl/ssl/tls13_both.c +440 -0
- data/third_party/boringssl/ssl/tls13_client.c +682 -0
- data/third_party/boringssl/ssl/tls13_enc.c +391 -0
- data/third_party/boringssl/ssl/tls13_server.c +672 -0
- data/third_party/boringssl/ssl/tls_method.c +245 -0
- data/third_party/boringssl/ssl/tls_record.c +461 -0
- data/third_party/cares/ares_build.h +264 -0
- data/third_party/cares/cares/ares.h +636 -0
- data/third_party/cares/cares/ares__close_sockets.c +61 -0
- data/third_party/cares/cares/ares__get_hostent.c +261 -0
- data/third_party/cares/cares/ares__read_line.c +73 -0
- data/third_party/cares/cares/ares__timeval.c +111 -0
- data/third_party/cares/cares/ares_cancel.c +63 -0
- data/third_party/cares/cares/ares_create_query.c +202 -0
- data/third_party/cares/cares/ares_data.c +221 -0
- data/third_party/cares/cares/ares_data.h +72 -0
- data/third_party/cares/cares/ares_destroy.c +108 -0
- data/third_party/cares/cares/ares_dns.h +103 -0
- data/third_party/cares/cares/ares_expand_name.c +205 -0
- data/third_party/cares/cares/ares_expand_string.c +70 -0
- data/third_party/cares/cares/ares_fds.c +59 -0
- data/third_party/cares/cares/ares_free_hostent.c +41 -0
- data/third_party/cares/cares/ares_free_string.c +25 -0
- data/third_party/cares/cares/ares_getenv.c +30 -0
- data/third_party/cares/cares/ares_getenv.h +26 -0
- data/third_party/cares/cares/ares_gethostbyaddr.c +294 -0
- data/third_party/cares/cares/ares_gethostbyname.c +518 -0
- data/third_party/cares/cares/ares_getnameinfo.c +422 -0
- data/third_party/cares/cares/ares_getopt.c +122 -0
- data/third_party/cares/cares/ares_getopt.h +53 -0
- data/third_party/cares/cares/ares_getsock.c +66 -0
- data/third_party/cares/cares/ares_inet_net_pton.h +25 -0
- data/third_party/cares/cares/ares_init.c +2146 -0
- data/third_party/cares/cares/ares_iphlpapi.h +221 -0
- data/third_party/cares/cares/ares_ipv6.h +78 -0
- data/third_party/cares/cares/ares_library_init.c +167 -0
- data/third_party/cares/cares/ares_library_init.h +42 -0
- data/third_party/cares/cares/ares_llist.c +63 -0
- data/third_party/cares/cares/ares_llist.h +39 -0
- data/third_party/cares/cares/ares_mkquery.c +24 -0
- data/third_party/cares/cares/ares_nowarn.c +260 -0
- data/third_party/cares/cares/ares_nowarn.h +61 -0
- data/third_party/cares/cares/ares_options.c +402 -0
- data/third_party/cares/cares/ares_parse_a_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_aaaa_reply.c +264 -0
- data/third_party/cares/cares/ares_parse_mx_reply.c +170 -0
- data/third_party/cares/cares/ares_parse_naptr_reply.c +188 -0
- data/third_party/cares/cares/ares_parse_ns_reply.c +183 -0
- data/third_party/cares/cares/ares_parse_ptr_reply.c +219 -0
- data/third_party/cares/cares/ares_parse_soa_reply.c +133 -0
- data/third_party/cares/cares/ares_parse_srv_reply.c +179 -0
- data/third_party/cares/cares/ares_parse_txt_reply.c +220 -0
- data/third_party/cares/cares/ares_platform.c +11035 -0
- data/third_party/cares/cares/ares_platform.h +43 -0
- data/third_party/cares/cares/ares_private.h +363 -0
- data/third_party/cares/cares/ares_process.c +1359 -0
- data/third_party/cares/cares/ares_query.c +186 -0
- data/third_party/cares/cares/ares_rules.h +125 -0
- data/third_party/cares/cares/ares_search.c +316 -0
- data/third_party/cares/cares/ares_send.c +131 -0
- data/third_party/cares/cares/ares_setup.h +217 -0
- data/third_party/cares/cares/ares_strcasecmp.c +66 -0
- data/third_party/cares/cares/ares_strcasecmp.h +30 -0
- data/third_party/cares/cares/ares_strdup.c +49 -0
- data/third_party/cares/cares/ares_strdup.h +24 -0
- data/third_party/cares/cares/ares_strerror.c +56 -0
- data/third_party/cares/cares/ares_timeout.c +88 -0
- data/third_party/cares/cares/ares_version.c +11 -0
- data/third_party/cares/cares/ares_version.h +24 -0
- data/third_party/cares/cares/ares_writev.c +79 -0
- data/third_party/cares/cares/bitncmp.c +59 -0
- data/third_party/cares/cares/bitncmp.h +26 -0
- data/third_party/cares/cares/config-win32.h +377 -0
- data/third_party/cares/cares/inet_net_pton.c +450 -0
- data/third_party/cares/cares/inet_ntop.c +208 -0
- data/third_party/cares/cares/setup_once.h +554 -0
- data/third_party/cares/cares/windows_port.c +22 -0
- data/third_party/cares/config_darwin/ares_config.h +523 -0
- data/third_party/cares/config_linux/ares_config.h +524 -0
- data/third_party/nanopb/pb.h +579 -0
- data/third_party/nanopb/pb_common.c +97 -0
- data/third_party/nanopb/pb_common.h +42 -0
- data/third_party/nanopb/pb_decode.c +1347 -0
- data/third_party/nanopb/pb_decode.h +149 -0
- data/third_party/nanopb/pb_encode.c +696 -0
- data/third_party/nanopb/pb_encode.h +154 -0
- data/third_party/zlib/adler32.c +179 -0
- data/third_party/zlib/compress.c +80 -0
- data/third_party/zlib/crc32.c +425 -0
- data/third_party/zlib/crc32.h +441 -0
- data/third_party/zlib/deflate.c +1967 -0
- data/third_party/zlib/deflate.h +346 -0
- data/third_party/zlib/gzclose.c +25 -0
- data/third_party/zlib/gzguts.h +209 -0
- data/third_party/zlib/gzlib.c +634 -0
- data/third_party/zlib/gzread.c +594 -0
- data/third_party/zlib/gzwrite.c +577 -0
- data/third_party/zlib/infback.c +640 -0
- data/third_party/zlib/inffast.c +340 -0
- data/third_party/zlib/inffast.h +11 -0
- data/third_party/zlib/inffixed.h +94 -0
- data/third_party/zlib/inflate.c +1512 -0
- data/third_party/zlib/inflate.h +122 -0
- data/third_party/zlib/inftrees.c +306 -0
- data/third_party/zlib/inftrees.h +62 -0
- data/third_party/zlib/trees.c +1226 -0
- data/third_party/zlib/trees.h +128 -0
- data/third_party/zlib/uncompr.c +59 -0
- data/third_party/zlib/zconf.h +511 -0
- data/third_party/zlib/zlib.h +1768 -0
- data/third_party/zlib/zutil.c +324 -0
- data/third_party/zlib/zutil.h +253 -0
- metadata +1397 -0
@@ -0,0 +1,67 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H
|
35
|
+
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H
|
36
|
+
|
37
|
+
#include <grpc/slice.h>
|
38
|
+
#include <stdbool.h>
|
39
|
+
|
40
|
+
struct grpc_base64_decode_context {
|
41
|
+
/* input/output: */
|
42
|
+
uint8_t *input_cur;
|
43
|
+
uint8_t *input_end;
|
44
|
+
uint8_t *output_cur;
|
45
|
+
uint8_t *output_end;
|
46
|
+
/* Indicate if the decoder should handle the tail of input data*/
|
47
|
+
bool contains_tail;
|
48
|
+
};
|
49
|
+
|
50
|
+
/* base64 decode a grpc_base64_decode_context util either input_end is reached
|
51
|
+
or output_end is reached. When input_end is reached, (input_end - input_cur)
|
52
|
+
is less than 4. When output_end is reached, (output_end - output_cur) is less
|
53
|
+
than 3. Returns false if decoding is failed. */
|
54
|
+
bool grpc_base64_decode_partial(struct grpc_base64_decode_context *ctx);
|
55
|
+
|
56
|
+
/* base64 decode a slice with pad chars. Returns a new slice, does not take
|
57
|
+
ownership of the input. Returns an empty slice if decoding is failed. */
|
58
|
+
grpc_slice grpc_chttp2_base64_decode(grpc_exec_ctx *exec_ctx, grpc_slice input);
|
59
|
+
|
60
|
+
/* base64 decode a slice without pad chars, data length is needed. Returns a new
|
61
|
+
slice, does not take ownership of the input. Returns an empty slice if
|
62
|
+
decoding is failed. */
|
63
|
+
grpc_slice grpc_chttp2_base64_decode_with_length(grpc_exec_ctx *exec_ctx,
|
64
|
+
grpc_slice input,
|
65
|
+
size_t output_length);
|
66
|
+
|
67
|
+
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_DECODER_H */
|
@@ -0,0 +1,241 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "src/core/ext/transport/chttp2/transport/bin_encoder.h"
|
35
|
+
|
36
|
+
#include <string.h>
|
37
|
+
|
38
|
+
#include <grpc/support/log.h>
|
39
|
+
#include "src/core/ext/transport/chttp2/transport/huffsyms.h"
|
40
|
+
|
41
|
+
static const char alphabet[] =
|
42
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
43
|
+
|
44
|
+
typedef struct {
|
45
|
+
uint16_t bits;
|
46
|
+
uint8_t length;
|
47
|
+
} b64_huff_sym;
|
48
|
+
|
49
|
+
static const b64_huff_sym huff_alphabet[64] = {
|
50
|
+
{0x21, 6}, {0x5d, 7}, {0x5e, 7}, {0x5f, 7}, {0x60, 7}, {0x61, 7},
|
51
|
+
{0x62, 7}, {0x63, 7}, {0x64, 7}, {0x65, 7}, {0x66, 7}, {0x67, 7},
|
52
|
+
{0x68, 7}, {0x69, 7}, {0x6a, 7}, {0x6b, 7}, {0x6c, 7}, {0x6d, 7},
|
53
|
+
{0x6e, 7}, {0x6f, 7}, {0x70, 7}, {0x71, 7}, {0x72, 7}, {0xfc, 8},
|
54
|
+
{0x73, 7}, {0xfd, 8}, {0x3, 5}, {0x23, 6}, {0x4, 5}, {0x24, 6},
|
55
|
+
{0x5, 5}, {0x25, 6}, {0x26, 6}, {0x27, 6}, {0x6, 5}, {0x74, 7},
|
56
|
+
{0x75, 7}, {0x28, 6}, {0x29, 6}, {0x2a, 6}, {0x7, 5}, {0x2b, 6},
|
57
|
+
{0x76, 7}, {0x2c, 6}, {0x8, 5}, {0x9, 5}, {0x2d, 6}, {0x77, 7},
|
58
|
+
{0x78, 7}, {0x79, 7}, {0x7a, 7}, {0x7b, 7}, {0x0, 5}, {0x1, 5},
|
59
|
+
{0x2, 5}, {0x19, 6}, {0x1a, 6}, {0x1b, 6}, {0x1c, 6}, {0x1d, 6},
|
60
|
+
{0x1e, 6}, {0x1f, 6}, {0x7fb, 11}, {0x18, 6}};
|
61
|
+
|
62
|
+
static const uint8_t tail_xtra[3] = {0, 2, 3};
|
63
|
+
|
64
|
+
grpc_slice grpc_chttp2_base64_encode(grpc_slice input) {
|
65
|
+
size_t input_length = GRPC_SLICE_LENGTH(input);
|
66
|
+
size_t input_triplets = input_length / 3;
|
67
|
+
size_t tail_case = input_length % 3;
|
68
|
+
size_t output_length = input_triplets * 4 + tail_xtra[tail_case];
|
69
|
+
grpc_slice output = grpc_slice_malloc(output_length);
|
70
|
+
uint8_t *in = GRPC_SLICE_START_PTR(input);
|
71
|
+
char *out = (char *)GRPC_SLICE_START_PTR(output);
|
72
|
+
size_t i;
|
73
|
+
|
74
|
+
/* encode full triplets */
|
75
|
+
for (i = 0; i < input_triplets; i++) {
|
76
|
+
out[0] = alphabet[in[0] >> 2];
|
77
|
+
out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)];
|
78
|
+
out[2] = alphabet[((in[1] & 0xf) << 2) | (in[2] >> 6)];
|
79
|
+
out[3] = alphabet[in[2] & 0x3f];
|
80
|
+
out += 4;
|
81
|
+
in += 3;
|
82
|
+
}
|
83
|
+
|
84
|
+
/* encode the remaining bytes */
|
85
|
+
switch (tail_case) {
|
86
|
+
case 0:
|
87
|
+
break;
|
88
|
+
case 1:
|
89
|
+
out[0] = alphabet[in[0] >> 2];
|
90
|
+
out[1] = alphabet[(in[0] & 0x3) << 4];
|
91
|
+
out += 2;
|
92
|
+
in += 1;
|
93
|
+
break;
|
94
|
+
case 2:
|
95
|
+
out[0] = alphabet[in[0] >> 2];
|
96
|
+
out[1] = alphabet[((in[0] & 0x3) << 4) | (in[1] >> 4)];
|
97
|
+
out[2] = alphabet[(in[1] & 0xf) << 2];
|
98
|
+
out += 3;
|
99
|
+
in += 2;
|
100
|
+
break;
|
101
|
+
}
|
102
|
+
|
103
|
+
GPR_ASSERT(out == (char *)GRPC_SLICE_END_PTR(output));
|
104
|
+
GPR_ASSERT(in == GRPC_SLICE_END_PTR(input));
|
105
|
+
return output;
|
106
|
+
}
|
107
|
+
|
108
|
+
grpc_slice grpc_chttp2_huffman_compress(grpc_slice input) {
|
109
|
+
size_t nbits;
|
110
|
+
uint8_t *in;
|
111
|
+
uint8_t *out;
|
112
|
+
grpc_slice output;
|
113
|
+
uint32_t temp = 0;
|
114
|
+
uint32_t temp_length = 0;
|
115
|
+
|
116
|
+
nbits = 0;
|
117
|
+
for (in = GRPC_SLICE_START_PTR(input); in != GRPC_SLICE_END_PTR(input);
|
118
|
+
++in) {
|
119
|
+
nbits += grpc_chttp2_huffsyms[*in].length;
|
120
|
+
}
|
121
|
+
|
122
|
+
output = grpc_slice_malloc(nbits / 8 + (nbits % 8 != 0));
|
123
|
+
out = GRPC_SLICE_START_PTR(output);
|
124
|
+
for (in = GRPC_SLICE_START_PTR(input); in != GRPC_SLICE_END_PTR(input);
|
125
|
+
++in) {
|
126
|
+
int sym = *in;
|
127
|
+
temp <<= grpc_chttp2_huffsyms[sym].length;
|
128
|
+
temp |= grpc_chttp2_huffsyms[sym].bits;
|
129
|
+
temp_length += grpc_chttp2_huffsyms[sym].length;
|
130
|
+
|
131
|
+
while (temp_length > 8) {
|
132
|
+
temp_length -= 8;
|
133
|
+
*out++ = (uint8_t)(temp >> temp_length);
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
if (temp_length) {
|
138
|
+
/* NB: the following integer arithmetic operation needs to be in its
|
139
|
+
* expanded form due to the "integral promotion" performed (see section
|
140
|
+
* 3.2.1.1 of the C89 draft standard). A cast to the smaller container type
|
141
|
+
* is then required to avoid the compiler warning */
|
142
|
+
*out++ = (uint8_t)((uint8_t)(temp << (8u - temp_length)) |
|
143
|
+
(uint8_t)(0xffu >> temp_length));
|
144
|
+
}
|
145
|
+
|
146
|
+
GPR_ASSERT(out == GRPC_SLICE_END_PTR(output));
|
147
|
+
|
148
|
+
return output;
|
149
|
+
}
|
150
|
+
|
151
|
+
typedef struct {
|
152
|
+
uint32_t temp;
|
153
|
+
uint32_t temp_length;
|
154
|
+
uint8_t *out;
|
155
|
+
} huff_out;
|
156
|
+
|
157
|
+
static void enc_flush_some(huff_out *out) {
|
158
|
+
while (out->temp_length > 8) {
|
159
|
+
out->temp_length -= 8;
|
160
|
+
*out->out++ = (uint8_t)(out->temp >> out->temp_length);
|
161
|
+
}
|
162
|
+
}
|
163
|
+
|
164
|
+
static void enc_add2(huff_out *out, uint8_t a, uint8_t b) {
|
165
|
+
b64_huff_sym sa = huff_alphabet[a];
|
166
|
+
b64_huff_sym sb = huff_alphabet[b];
|
167
|
+
out->temp = (out->temp << (sa.length + sb.length)) |
|
168
|
+
((uint32_t)sa.bits << sb.length) | sb.bits;
|
169
|
+
out->temp_length += (uint32_t)sa.length + (uint32_t)sb.length;
|
170
|
+
enc_flush_some(out);
|
171
|
+
}
|
172
|
+
|
173
|
+
static void enc_add1(huff_out *out, uint8_t a) {
|
174
|
+
b64_huff_sym sa = huff_alphabet[a];
|
175
|
+
out->temp = (out->temp << sa.length) | sa.bits;
|
176
|
+
out->temp_length += sa.length;
|
177
|
+
enc_flush_some(out);
|
178
|
+
}
|
179
|
+
|
180
|
+
grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input) {
|
181
|
+
size_t input_length = GRPC_SLICE_LENGTH(input);
|
182
|
+
size_t input_triplets = input_length / 3;
|
183
|
+
size_t tail_case = input_length % 3;
|
184
|
+
size_t output_syms = input_triplets * 4 + tail_xtra[tail_case];
|
185
|
+
size_t max_output_bits = 11 * output_syms;
|
186
|
+
size_t max_output_length = max_output_bits / 8 + (max_output_bits % 8 != 0);
|
187
|
+
grpc_slice output = grpc_slice_malloc(max_output_length);
|
188
|
+
uint8_t *in = GRPC_SLICE_START_PTR(input);
|
189
|
+
uint8_t *start_out = GRPC_SLICE_START_PTR(output);
|
190
|
+
huff_out out;
|
191
|
+
size_t i;
|
192
|
+
|
193
|
+
out.temp = 0;
|
194
|
+
out.temp_length = 0;
|
195
|
+
out.out = start_out;
|
196
|
+
|
197
|
+
/* encode full triplets */
|
198
|
+
for (i = 0; i < input_triplets; i++) {
|
199
|
+
const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4);
|
200
|
+
const uint8_t high_to_low = in[1] >> 4;
|
201
|
+
enc_add2(&out, in[0] >> 2, low_to_high | high_to_low);
|
202
|
+
|
203
|
+
const uint8_t a = (uint8_t)((in[1] & 0xf) << 2);
|
204
|
+
const uint8_t b = (in[2] >> 6);
|
205
|
+
enc_add2(&out, a | b, in[2] & 0x3f);
|
206
|
+
in += 3;
|
207
|
+
}
|
208
|
+
|
209
|
+
/* encode the remaining bytes */
|
210
|
+
switch (tail_case) {
|
211
|
+
case 0:
|
212
|
+
break;
|
213
|
+
case 1:
|
214
|
+
enc_add2(&out, in[0] >> 2, (uint8_t)((in[0] & 0x3) << 4));
|
215
|
+
in += 1;
|
216
|
+
break;
|
217
|
+
case 2: {
|
218
|
+
const uint8_t low_to_high = (uint8_t)((in[0] & 0x3) << 4);
|
219
|
+
const uint8_t high_to_low = in[1] >> 4;
|
220
|
+
enc_add2(&out, in[0] >> 2, low_to_high | high_to_low);
|
221
|
+
enc_add1(&out, (uint8_t)((in[1] & 0xf) << 2));
|
222
|
+
in += 2;
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
}
|
226
|
+
|
227
|
+
if (out.temp_length) {
|
228
|
+
/* NB: the following integer arithmetic operation needs to be in its
|
229
|
+
* expanded form due to the "integral promotion" performed (see section
|
230
|
+
* 3.2.1.1 of the C89 draft standard). A cast to the smaller container type
|
231
|
+
* is then required to avoid the compiler warning */
|
232
|
+
*out.out++ = (uint8_t)((uint8_t)(out.temp << (8u - out.temp_length)) |
|
233
|
+
(uint8_t)(0xffu >> out.temp_length));
|
234
|
+
}
|
235
|
+
|
236
|
+
GPR_ASSERT(out.out <= GRPC_SLICE_END_PTR(output));
|
237
|
+
GRPC_SLICE_SET_LENGTH(output, out.out - start_out);
|
238
|
+
|
239
|
+
GPR_ASSERT(in == GRPC_SLICE_END_PTR(input));
|
240
|
+
return output;
|
241
|
+
}
|
@@ -0,0 +1,54 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#ifndef GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_ENCODER_H
|
35
|
+
#define GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_ENCODER_H
|
36
|
+
|
37
|
+
#include <grpc/slice.h>
|
38
|
+
|
39
|
+
/* base64 encode a slice. Returns a new slice, does not take ownership of the
|
40
|
+
input */
|
41
|
+
grpc_slice grpc_chttp2_base64_encode(grpc_slice input);
|
42
|
+
|
43
|
+
/* Compress a slice with the static huffman encoder detailed in the hpack
|
44
|
+
standard. Returns a new slice, does not take ownership of the input */
|
45
|
+
grpc_slice grpc_chttp2_huffman_compress(grpc_slice input);
|
46
|
+
|
47
|
+
/* equivalent to:
|
48
|
+
grpc_slice x = grpc_chttp2_base64_encode(input);
|
49
|
+
grpc_slice y = grpc_chttp2_huffman_compress(x);
|
50
|
+
grpc_slice_unref_internal(exec_ctx, x);
|
51
|
+
return y; */
|
52
|
+
grpc_slice grpc_chttp2_base64_encode_and_huffman_compress(grpc_slice input);
|
53
|
+
|
54
|
+
#endif /* GRPC_CORE_EXT_TRANSPORT_CHTTP2_TRANSPORT_BIN_ENCODER_H */
|
@@ -0,0 +1,43 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
35
|
+
#include "src/core/lib/debug/trace.h"
|
36
|
+
#include "src/core/lib/transport/metadata.h"
|
37
|
+
|
38
|
+
void grpc_chttp2_plugin_init(void) {
|
39
|
+
grpc_register_tracer("http", &grpc_http_trace);
|
40
|
+
grpc_register_tracer("flowctl", &grpc_flowctl_trace);
|
41
|
+
}
|
42
|
+
|
43
|
+
void grpc_chttp2_plugin_shutdown(void) {}
|
@@ -0,0 +1,2847 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2015, Google Inc.
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* Redistribution and use in source and binary forms, with or without
|
7
|
+
* modification, are permitted provided that the following conditions are
|
8
|
+
* met:
|
9
|
+
*
|
10
|
+
* * Redistributions of source code must retain the above copyright
|
11
|
+
* notice, this list of conditions and the following disclaimer.
|
12
|
+
* * Redistributions in binary form must reproduce the above
|
13
|
+
* copyright notice, this list of conditions and the following disclaimer
|
14
|
+
* in the documentation and/or other materials provided with the
|
15
|
+
* distribution.
|
16
|
+
* * Neither the name of Google Inc. nor the names of its
|
17
|
+
* contributors may be used to endorse or promote products derived from
|
18
|
+
* this software without specific prior written permission.
|
19
|
+
*
|
20
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
21
|
+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
22
|
+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
23
|
+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
24
|
+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
25
|
+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
26
|
+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
27
|
+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
28
|
+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
29
|
+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
30
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
31
|
+
*
|
32
|
+
*/
|
33
|
+
|
34
|
+
#include "src/core/ext/transport/chttp2/transport/chttp2_transport.h"
|
35
|
+
|
36
|
+
#include <limits.h>
|
37
|
+
#include <math.h>
|
38
|
+
#include <stdio.h>
|
39
|
+
#include <string.h>
|
40
|
+
|
41
|
+
#include <grpc/slice_buffer.h>
|
42
|
+
#include <grpc/support/alloc.h>
|
43
|
+
#include <grpc/support/log.h>
|
44
|
+
#include <grpc/support/string_util.h>
|
45
|
+
#include <grpc/support/useful.h>
|
46
|
+
|
47
|
+
#include "src/core/ext/transport/chttp2/transport/internal.h"
|
48
|
+
#include "src/core/ext/transport/chttp2/transport/varint.h"
|
49
|
+
#include "src/core/lib/channel/channel_args.h"
|
50
|
+
#include "src/core/lib/http/parser.h"
|
51
|
+
#include "src/core/lib/iomgr/timer.h"
|
52
|
+
#include "src/core/lib/iomgr/workqueue.h"
|
53
|
+
#include "src/core/lib/profiling/timers.h"
|
54
|
+
#include "src/core/lib/slice/slice_internal.h"
|
55
|
+
#include "src/core/lib/slice/slice_string_helpers.h"
|
56
|
+
#include "src/core/lib/support/env.h"
|
57
|
+
#include "src/core/lib/support/string.h"
|
58
|
+
#include "src/core/lib/transport/error_utils.h"
|
59
|
+
#include "src/core/lib/transport/http2_errors.h"
|
60
|
+
#include "src/core/lib/transport/static_metadata.h"
|
61
|
+
#include "src/core/lib/transport/status_conversion.h"
|
62
|
+
#include "src/core/lib/transport/timeout_encoding.h"
|
63
|
+
#include "src/core/lib/transport/transport.h"
|
64
|
+
#include "src/core/lib/transport/transport_impl.h"
|
65
|
+
|
66
|
+
#define DEFAULT_WINDOW 65535
|
67
|
+
#define DEFAULT_CONNECTION_WINDOW_TARGET (1024 * 1024)
|
68
|
+
#define MAX_WINDOW 0x7fffffffu
|
69
|
+
#define MAX_WRITE_BUFFER_SIZE (64 * 1024 * 1024)
|
70
|
+
#define DEFAULT_MAX_HEADER_LIST_SIZE (16 * 1024)
|
71
|
+
|
72
|
+
#define DEFAULT_CLIENT_KEEPALIVE_TIME_MS INT_MAX
|
73
|
+
#define DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS 20000 /* 20 seconds */
|
74
|
+
#define DEFAULT_SERVER_KEEPALIVE_TIME_MS 7200000 /* 2 hours */
|
75
|
+
#define DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS 20000 /* 20 seconds */
|
76
|
+
#define DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS false
|
77
|
+
#define KEEPALIVE_TIME_BACKOFF_MULTIPLIER 2
|
78
|
+
|
79
|
+
static int g_default_client_keepalive_time_ms =
|
80
|
+
DEFAULT_CLIENT_KEEPALIVE_TIME_MS;
|
81
|
+
static int g_default_client_keepalive_timeout_ms =
|
82
|
+
DEFAULT_CLIENT_KEEPALIVE_TIMEOUT_MS;
|
83
|
+
static int g_default_server_keepalive_time_ms =
|
84
|
+
DEFAULT_SERVER_KEEPALIVE_TIME_MS;
|
85
|
+
static int g_default_server_keepalive_timeout_ms =
|
86
|
+
DEFAULT_SERVER_KEEPALIVE_TIMEOUT_MS;
|
87
|
+
static bool g_default_keepalive_permit_without_calls =
|
88
|
+
DEFAULT_KEEPALIVE_PERMIT_WITHOUT_CALLS;
|
89
|
+
|
90
|
+
#define MAX_CLIENT_STREAM_ID 0x7fffffffu
|
91
|
+
int grpc_http_trace = 0;
|
92
|
+
int grpc_flowctl_trace = 0;
|
93
|
+
|
94
|
+
static const grpc_transport_vtable vtable;
|
95
|
+
|
96
|
+
/* forward declarations of various callbacks that we'll build closures around */
|
97
|
+
static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *t,
|
98
|
+
grpc_error *error);
|
99
|
+
static void write_action(grpc_exec_ctx *exec_ctx, void *t, grpc_error *error);
|
100
|
+
static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *t,
|
101
|
+
grpc_error *error);
|
102
|
+
|
103
|
+
static void read_action_locked(grpc_exec_ctx *exec_ctx, void *t,
|
104
|
+
grpc_error *error);
|
105
|
+
|
106
|
+
static void complete_fetch_locked(grpc_exec_ctx *exec_ctx, void *gs,
|
107
|
+
grpc_error *error);
|
108
|
+
/** Set a transport level setting, and push it to our peer */
|
109
|
+
static void push_setting(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
110
|
+
grpc_chttp2_setting_id id, uint32_t value);
|
111
|
+
|
112
|
+
static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
113
|
+
grpc_chttp2_stream *s, grpc_error *error);
|
114
|
+
|
115
|
+
/** Start new streams that have been created if we can */
|
116
|
+
static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx,
|
117
|
+
grpc_chttp2_transport *t);
|
118
|
+
|
119
|
+
static void connectivity_state_set(grpc_exec_ctx *exec_ctx,
|
120
|
+
grpc_chttp2_transport *t,
|
121
|
+
grpc_connectivity_state state,
|
122
|
+
grpc_error *error, const char *reason);
|
123
|
+
|
124
|
+
static void incoming_byte_stream_update_flow_control(grpc_exec_ctx *exec_ctx,
|
125
|
+
grpc_chttp2_transport *t,
|
126
|
+
grpc_chttp2_stream *s,
|
127
|
+
size_t max_size_hint,
|
128
|
+
size_t have_already);
|
129
|
+
static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx,
|
130
|
+
void *byte_stream,
|
131
|
+
grpc_error *error_ignored);
|
132
|
+
|
133
|
+
static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *t,
|
134
|
+
grpc_error *error);
|
135
|
+
static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *t,
|
136
|
+
grpc_error *error);
|
137
|
+
|
138
|
+
static void post_benign_reclaimer(grpc_exec_ctx *exec_ctx,
|
139
|
+
grpc_chttp2_transport *t);
|
140
|
+
static void post_destructive_reclaimer(grpc_exec_ctx *exec_ctx,
|
141
|
+
grpc_chttp2_transport *t);
|
142
|
+
|
143
|
+
static void close_transport_locked(grpc_exec_ctx *exec_ctx,
|
144
|
+
grpc_chttp2_transport *t, grpc_error *error);
|
145
|
+
static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
146
|
+
grpc_error *error);
|
147
|
+
|
148
|
+
static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
149
|
+
grpc_error *error);
|
150
|
+
static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
151
|
+
grpc_error *error);
|
152
|
+
|
153
|
+
static void cancel_pings(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
154
|
+
grpc_error *error);
|
155
|
+
static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
156
|
+
grpc_chttp2_ping_type ping_type,
|
157
|
+
grpc_closure *on_initiate,
|
158
|
+
grpc_closure *on_complete);
|
159
|
+
static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
160
|
+
grpc_error *error);
|
161
|
+
|
162
|
+
#define DEFAULT_MIN_TIME_BETWEEN_PINGS_MS 0
|
163
|
+
#define DEFAULT_MAX_PINGS_BETWEEN_DATA 3
|
164
|
+
#define DEFAULT_MAX_PING_STRIKES 2
|
165
|
+
#define DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS 300000 /* 5 minutes */
|
166
|
+
|
167
|
+
/** keepalive-relevant functions */
|
168
|
+
static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
169
|
+
grpc_error *error);
|
170
|
+
static void start_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
171
|
+
grpc_error *error);
|
172
|
+
static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
173
|
+
grpc_error *error);
|
174
|
+
static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
175
|
+
grpc_error *error);
|
176
|
+
|
177
|
+
/*******************************************************************************
|
178
|
+
* CONSTRUCTION/DESTRUCTION/REFCOUNTING
|
179
|
+
*/
|
180
|
+
|
181
|
+
static void destruct_transport(grpc_exec_ctx *exec_ctx,
|
182
|
+
grpc_chttp2_transport *t) {
|
183
|
+
size_t i;
|
184
|
+
|
185
|
+
grpc_endpoint_destroy(exec_ctx, t->ep);
|
186
|
+
|
187
|
+
grpc_slice_buffer_destroy_internal(exec_ctx, &t->qbuf);
|
188
|
+
|
189
|
+
grpc_slice_buffer_destroy_internal(exec_ctx, &t->outbuf);
|
190
|
+
grpc_chttp2_hpack_compressor_destroy(exec_ctx, &t->hpack_compressor);
|
191
|
+
|
192
|
+
grpc_slice_buffer_destroy_internal(exec_ctx, &t->read_buffer);
|
193
|
+
grpc_chttp2_hpack_parser_destroy(exec_ctx, &t->hpack_parser);
|
194
|
+
grpc_chttp2_goaway_parser_destroy(&t->goaway_parser);
|
195
|
+
|
196
|
+
for (i = 0; i < STREAM_LIST_COUNT; i++) {
|
197
|
+
GPR_ASSERT(t->lists[i].head == NULL);
|
198
|
+
GPR_ASSERT(t->lists[i].tail == NULL);
|
199
|
+
}
|
200
|
+
|
201
|
+
GPR_ASSERT(grpc_chttp2_stream_map_size(&t->stream_map) == 0);
|
202
|
+
|
203
|
+
grpc_chttp2_stream_map_destroy(&t->stream_map);
|
204
|
+
grpc_connectivity_state_destroy(exec_ctx, &t->channel_callback.state_tracker);
|
205
|
+
|
206
|
+
GRPC_COMBINER_UNREF(exec_ctx, t->combiner, "chttp2_transport");
|
207
|
+
|
208
|
+
cancel_pings(exec_ctx, t,
|
209
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"));
|
210
|
+
|
211
|
+
while (t->write_cb_pool) {
|
212
|
+
grpc_chttp2_write_cb *next = t->write_cb_pool->next;
|
213
|
+
gpr_free(t->write_cb_pool);
|
214
|
+
t->write_cb_pool = next;
|
215
|
+
}
|
216
|
+
|
217
|
+
gpr_free(t->ping_acks);
|
218
|
+
gpr_free(t->peer_string);
|
219
|
+
gpr_free(t);
|
220
|
+
}
|
221
|
+
|
222
|
+
#ifdef GRPC_CHTTP2_REFCOUNTING_DEBUG
|
223
|
+
void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx,
|
224
|
+
grpc_chttp2_transport *t, const char *reason,
|
225
|
+
const char *file, int line) {
|
226
|
+
gpr_log(GPR_DEBUG, "chttp2:unref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", t,
|
227
|
+
t->refs.count, t->refs.count - 1, reason, file, line);
|
228
|
+
if (!gpr_unref(&t->refs)) return;
|
229
|
+
destruct_transport(exec_ctx, t);
|
230
|
+
}
|
231
|
+
|
232
|
+
void grpc_chttp2_ref_transport(grpc_chttp2_transport *t, const char *reason,
|
233
|
+
const char *file, int line) {
|
234
|
+
gpr_log(GPR_DEBUG, "chttp2: ref:%p %" PRIdPTR "->%" PRIdPTR " %s [%s:%d]", t,
|
235
|
+
t->refs.count, t->refs.count + 1, reason, file, line);
|
236
|
+
gpr_ref(&t->refs);
|
237
|
+
}
|
238
|
+
#else
|
239
|
+
void grpc_chttp2_unref_transport(grpc_exec_ctx *exec_ctx,
|
240
|
+
grpc_chttp2_transport *t) {
|
241
|
+
if (!gpr_unref(&t->refs)) return;
|
242
|
+
destruct_transport(exec_ctx, t);
|
243
|
+
}
|
244
|
+
|
245
|
+
void grpc_chttp2_ref_transport(grpc_chttp2_transport *t) { gpr_ref(&t->refs); }
|
246
|
+
#endif
|
247
|
+
|
248
|
+
static void init_transport(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
249
|
+
const grpc_channel_args *channel_args,
|
250
|
+
grpc_endpoint *ep, bool is_client) {
|
251
|
+
size_t i;
|
252
|
+
int j;
|
253
|
+
|
254
|
+
GPR_ASSERT(strlen(GRPC_CHTTP2_CLIENT_CONNECT_STRING) ==
|
255
|
+
GRPC_CHTTP2_CLIENT_CONNECT_STRLEN);
|
256
|
+
|
257
|
+
t->base.vtable = &vtable;
|
258
|
+
t->ep = ep;
|
259
|
+
/* one ref is for destroy */
|
260
|
+
gpr_ref_init(&t->refs, 1);
|
261
|
+
t->combiner = grpc_combiner_create(grpc_endpoint_get_workqueue(ep));
|
262
|
+
t->peer_string = grpc_endpoint_get_peer(ep);
|
263
|
+
t->endpoint_reading = 1;
|
264
|
+
t->next_stream_id = is_client ? 1 : 2;
|
265
|
+
t->is_client = is_client;
|
266
|
+
t->outgoing_window = DEFAULT_WINDOW;
|
267
|
+
t->incoming_window = DEFAULT_WINDOW;
|
268
|
+
t->deframe_state = is_client ? GRPC_DTS_FH_0 : GRPC_DTS_CLIENT_PREFIX_0;
|
269
|
+
t->is_first_frame = true;
|
270
|
+
grpc_connectivity_state_init(
|
271
|
+
&t->channel_callback.state_tracker, GRPC_CHANNEL_READY,
|
272
|
+
is_client ? "client_transport" : "server_transport");
|
273
|
+
|
274
|
+
grpc_slice_buffer_init(&t->qbuf);
|
275
|
+
|
276
|
+
grpc_slice_buffer_init(&t->outbuf);
|
277
|
+
grpc_chttp2_hpack_compressor_init(&t->hpack_compressor);
|
278
|
+
|
279
|
+
grpc_closure_init(&t->write_action, write_action, t,
|
280
|
+
grpc_schedule_on_exec_ctx);
|
281
|
+
grpc_closure_init(&t->read_action_locked, read_action_locked, t,
|
282
|
+
grpc_combiner_scheduler(t->combiner, false));
|
283
|
+
grpc_closure_init(&t->benign_reclaimer_locked, benign_reclaimer_locked, t,
|
284
|
+
grpc_combiner_scheduler(t->combiner, false));
|
285
|
+
grpc_closure_init(&t->destructive_reclaimer_locked,
|
286
|
+
destructive_reclaimer_locked, t,
|
287
|
+
grpc_combiner_scheduler(t->combiner, false));
|
288
|
+
grpc_closure_init(&t->retry_initiate_ping_locked, retry_initiate_ping_locked,
|
289
|
+
t, grpc_combiner_scheduler(t->combiner, false));
|
290
|
+
grpc_closure_init(&t->start_bdp_ping_locked, start_bdp_ping_locked, t,
|
291
|
+
grpc_combiner_scheduler(t->combiner, false));
|
292
|
+
grpc_closure_init(&t->finish_bdp_ping_locked, finish_bdp_ping_locked, t,
|
293
|
+
grpc_combiner_scheduler(t->combiner, false));
|
294
|
+
grpc_closure_init(&t->init_keepalive_ping_locked, init_keepalive_ping_locked,
|
295
|
+
t, grpc_combiner_scheduler(t->combiner, false));
|
296
|
+
grpc_closure_init(&t->start_keepalive_ping_locked,
|
297
|
+
start_keepalive_ping_locked, t,
|
298
|
+
grpc_combiner_scheduler(t->combiner, false));
|
299
|
+
grpc_closure_init(&t->finish_keepalive_ping_locked,
|
300
|
+
finish_keepalive_ping_locked, t,
|
301
|
+
grpc_combiner_scheduler(t->combiner, false));
|
302
|
+
grpc_closure_init(&t->keepalive_watchdog_fired_locked,
|
303
|
+
keepalive_watchdog_fired_locked, t,
|
304
|
+
grpc_combiner_scheduler(t->combiner, false));
|
305
|
+
|
306
|
+
grpc_bdp_estimator_init(&t->bdp_estimator, t->peer_string);
|
307
|
+
t->last_pid_update = gpr_now(GPR_CLOCK_MONOTONIC);
|
308
|
+
grpc_pid_controller_init(
|
309
|
+
&t->pid_controller,
|
310
|
+
(grpc_pid_controller_args){.gain_p = 4,
|
311
|
+
.gain_i = 8,
|
312
|
+
.gain_d = 0,
|
313
|
+
.initial_control_value = log2(DEFAULT_WINDOW),
|
314
|
+
.min_control_value = -1,
|
315
|
+
.max_control_value = 25,
|
316
|
+
.integral_range = 10});
|
317
|
+
|
318
|
+
grpc_chttp2_goaway_parser_init(&t->goaway_parser);
|
319
|
+
grpc_chttp2_hpack_parser_init(exec_ctx, &t->hpack_parser);
|
320
|
+
|
321
|
+
grpc_slice_buffer_init(&t->read_buffer);
|
322
|
+
|
323
|
+
/* 8 is a random stab in the dark as to a good initial size: it's small enough
|
324
|
+
that it shouldn't waste memory for infrequently used connections, yet
|
325
|
+
large enough that the exponential growth should happen nicely when it's
|
326
|
+
needed.
|
327
|
+
TODO(ctiller): tune this */
|
328
|
+
grpc_chttp2_stream_map_init(&t->stream_map, 8);
|
329
|
+
|
330
|
+
/* copy in initial settings to all setting sets */
|
331
|
+
for (i = 0; i < GRPC_CHTTP2_NUM_SETTINGS; i++) {
|
332
|
+
for (j = 0; j < GRPC_NUM_SETTING_SETS; j++) {
|
333
|
+
t->settings[j][i] = grpc_chttp2_settings_parameters[i].default_value;
|
334
|
+
}
|
335
|
+
}
|
336
|
+
t->dirtied_local_settings = 1;
|
337
|
+
/* Hack: it's common for implementations to assume 65536 bytes initial send
|
338
|
+
window -- this should by rights be 0 */
|
339
|
+
t->force_send_settings = 1 << GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE;
|
340
|
+
t->sent_local_settings = 0;
|
341
|
+
t->write_buffer_size = DEFAULT_WINDOW;
|
342
|
+
t->enable_bdp_probe = true;
|
343
|
+
|
344
|
+
if (is_client) {
|
345
|
+
grpc_slice_buffer_add(&t->outbuf, grpc_slice_from_copied_string(
|
346
|
+
GRPC_CHTTP2_CLIENT_CONNECT_STRING));
|
347
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "initial_write");
|
348
|
+
}
|
349
|
+
|
350
|
+
/* configure http2 the way we like it */
|
351
|
+
if (is_client) {
|
352
|
+
push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_ENABLE_PUSH, 0);
|
353
|
+
push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS, 0);
|
354
|
+
}
|
355
|
+
push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
|
356
|
+
DEFAULT_WINDOW);
|
357
|
+
push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
|
358
|
+
DEFAULT_MAX_HEADER_LIST_SIZE);
|
359
|
+
push_setting(exec_ctx, t,
|
360
|
+
GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA, 1);
|
361
|
+
|
362
|
+
t->ping_policy = (grpc_chttp2_repeated_ping_policy){
|
363
|
+
.max_pings_without_data = DEFAULT_MAX_PINGS_BETWEEN_DATA,
|
364
|
+
.min_time_between_pings =
|
365
|
+
gpr_time_from_millis(DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, GPR_TIMESPAN),
|
366
|
+
.max_ping_strikes = DEFAULT_MAX_PING_STRIKES,
|
367
|
+
.min_ping_interval_without_data = gpr_time_from_millis(
|
368
|
+
DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, GPR_TIMESPAN),
|
369
|
+
};
|
370
|
+
|
371
|
+
/* Keepalive setting */
|
372
|
+
if (t->is_client) {
|
373
|
+
t->keepalive_time =
|
374
|
+
g_default_client_keepalive_time_ms == INT_MAX
|
375
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
376
|
+
: gpr_time_from_millis(g_default_client_keepalive_time_ms,
|
377
|
+
GPR_TIMESPAN);
|
378
|
+
t->keepalive_timeout =
|
379
|
+
g_default_client_keepalive_timeout_ms == INT_MAX
|
380
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
381
|
+
: gpr_time_from_millis(g_default_client_keepalive_timeout_ms,
|
382
|
+
GPR_TIMESPAN);
|
383
|
+
} else {
|
384
|
+
t->keepalive_time =
|
385
|
+
g_default_server_keepalive_time_ms == INT_MAX
|
386
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
387
|
+
: gpr_time_from_millis(g_default_server_keepalive_time_ms,
|
388
|
+
GPR_TIMESPAN);
|
389
|
+
t->keepalive_timeout =
|
390
|
+
g_default_server_keepalive_timeout_ms == INT_MAX
|
391
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
392
|
+
: gpr_time_from_millis(g_default_server_keepalive_timeout_ms,
|
393
|
+
GPR_TIMESPAN);
|
394
|
+
}
|
395
|
+
t->keepalive_permit_without_calls = g_default_keepalive_permit_without_calls;
|
396
|
+
|
397
|
+
if (channel_args) {
|
398
|
+
for (i = 0; i < channel_args->num_args; i++) {
|
399
|
+
if (0 == strcmp(channel_args->args[i].key,
|
400
|
+
GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER)) {
|
401
|
+
const grpc_integer_options options = {-1, 0, INT_MAX};
|
402
|
+
const int value =
|
403
|
+
grpc_channel_arg_get_integer(&channel_args->args[i], options);
|
404
|
+
if (value >= 0) {
|
405
|
+
if ((t->next_stream_id & 1) != (value & 1)) {
|
406
|
+
gpr_log(GPR_ERROR, "%s: low bit must be %d on %s",
|
407
|
+
GRPC_ARG_HTTP2_INITIAL_SEQUENCE_NUMBER,
|
408
|
+
t->next_stream_id & 1, is_client ? "client" : "server");
|
409
|
+
} else {
|
410
|
+
t->next_stream_id = (uint32_t)value;
|
411
|
+
}
|
412
|
+
}
|
413
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
414
|
+
GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_ENCODER)) {
|
415
|
+
const grpc_integer_options options = {-1, 0, INT_MAX};
|
416
|
+
const int value =
|
417
|
+
grpc_channel_arg_get_integer(&channel_args->args[i], options);
|
418
|
+
if (value >= 0) {
|
419
|
+
grpc_chttp2_hpack_compressor_set_max_usable_size(&t->hpack_compressor,
|
420
|
+
(uint32_t)value);
|
421
|
+
}
|
422
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
423
|
+
GRPC_ARG_HTTP2_MAX_PINGS_WITHOUT_DATA)) {
|
424
|
+
t->ping_policy.max_pings_without_data = grpc_channel_arg_get_integer(
|
425
|
+
&channel_args->args[i],
|
426
|
+
(grpc_integer_options){DEFAULT_MAX_PINGS_BETWEEN_DATA, 0, INT_MAX});
|
427
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
428
|
+
GRPC_ARG_HTTP2_MAX_PING_STRIKES)) {
|
429
|
+
t->ping_policy.max_ping_strikes = grpc_channel_arg_get_integer(
|
430
|
+
&channel_args->args[i],
|
431
|
+
(grpc_integer_options){DEFAULT_MAX_PING_STRIKES, 0, INT_MAX});
|
432
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
433
|
+
GRPC_ARG_HTTP2_MIN_TIME_BETWEEN_PINGS_MS)) {
|
434
|
+
t->ping_policy.min_time_between_pings = gpr_time_from_millis(
|
435
|
+
grpc_channel_arg_get_integer(
|
436
|
+
&channel_args->args[i],
|
437
|
+
(grpc_integer_options){DEFAULT_MIN_TIME_BETWEEN_PINGS_MS, 0,
|
438
|
+
INT_MAX}),
|
439
|
+
GPR_TIMESPAN);
|
440
|
+
} else if (0 ==
|
441
|
+
strcmp(channel_args->args[i].key,
|
442
|
+
GRPC_ARG_HTTP2_MIN_PING_INTERVAL_WITHOUT_DATA_MS)) {
|
443
|
+
t->ping_policy.min_ping_interval_without_data = gpr_time_from_millis(
|
444
|
+
grpc_channel_arg_get_integer(
|
445
|
+
&channel_args->args[i],
|
446
|
+
(grpc_integer_options){
|
447
|
+
DEFAULT_MIN_PING_INTERVAL_WITHOUT_DATA_MS, 0, INT_MAX}),
|
448
|
+
GPR_TIMESPAN);
|
449
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
450
|
+
GRPC_ARG_HTTP2_WRITE_BUFFER_SIZE)) {
|
451
|
+
t->write_buffer_size = (uint32_t)grpc_channel_arg_get_integer(
|
452
|
+
&channel_args->args[i],
|
453
|
+
(grpc_integer_options){0, 0, MAX_WRITE_BUFFER_SIZE});
|
454
|
+
} else if (0 ==
|
455
|
+
strcmp(channel_args->args[i].key, GRPC_ARG_HTTP2_BDP_PROBE)) {
|
456
|
+
t->enable_bdp_probe = grpc_channel_arg_get_integer(
|
457
|
+
&channel_args->args[i], (grpc_integer_options){1, 0, 1});
|
458
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
459
|
+
GRPC_ARG_KEEPALIVE_TIME_MS)) {
|
460
|
+
const int value = grpc_channel_arg_get_integer(
|
461
|
+
&channel_args->args[i],
|
462
|
+
(grpc_integer_options){t->is_client
|
463
|
+
? g_default_client_keepalive_time_ms
|
464
|
+
: g_default_server_keepalive_time_ms,
|
465
|
+
1, INT_MAX});
|
466
|
+
t->keepalive_time = value == INT_MAX
|
467
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
468
|
+
: gpr_time_from_millis(value, GPR_TIMESPAN);
|
469
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
470
|
+
GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
|
471
|
+
const int value = grpc_channel_arg_get_integer(
|
472
|
+
&channel_args->args[i],
|
473
|
+
(grpc_integer_options){t->is_client
|
474
|
+
? g_default_client_keepalive_timeout_ms
|
475
|
+
: g_default_server_keepalive_timeout_ms,
|
476
|
+
0, INT_MAX});
|
477
|
+
t->keepalive_timeout = value == INT_MAX
|
478
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
479
|
+
: gpr_time_from_millis(value, GPR_TIMESPAN);
|
480
|
+
} else if (0 == strcmp(channel_args->args[i].key,
|
481
|
+
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
|
482
|
+
t->keepalive_permit_without_calls =
|
483
|
+
(uint32_t)grpc_channel_arg_get_integer(
|
484
|
+
&channel_args->args[i], (grpc_integer_options){0, 0, 1});
|
485
|
+
} else {
|
486
|
+
static const struct {
|
487
|
+
const char *channel_arg_name;
|
488
|
+
grpc_chttp2_setting_id setting_id;
|
489
|
+
grpc_integer_options integer_options;
|
490
|
+
bool availability[2] /* server, client */;
|
491
|
+
} settings_map[] = {
|
492
|
+
{GRPC_ARG_MAX_CONCURRENT_STREAMS,
|
493
|
+
GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS,
|
494
|
+
{-1, 0, INT32_MAX},
|
495
|
+
{true, false}},
|
496
|
+
{GRPC_ARG_HTTP2_HPACK_TABLE_SIZE_DECODER,
|
497
|
+
GRPC_CHTTP2_SETTINGS_HEADER_TABLE_SIZE,
|
498
|
+
{-1, 0, INT32_MAX},
|
499
|
+
{true, true}},
|
500
|
+
{GRPC_ARG_MAX_METADATA_SIZE,
|
501
|
+
GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE,
|
502
|
+
{-1, 0, INT32_MAX},
|
503
|
+
{true, true}},
|
504
|
+
{GRPC_ARG_HTTP2_MAX_FRAME_SIZE,
|
505
|
+
GRPC_CHTTP2_SETTINGS_MAX_FRAME_SIZE,
|
506
|
+
{-1, 16384, 16777215},
|
507
|
+
{true, true}},
|
508
|
+
{GRPC_ARG_HTTP2_ENABLE_TRUE_BINARY,
|
509
|
+
GRPC_CHTTP2_SETTINGS_GRPC_ALLOW_TRUE_BINARY_METADATA,
|
510
|
+
{1, 0, 1},
|
511
|
+
{true, true}},
|
512
|
+
{GRPC_ARG_HTTP2_STREAM_LOOKAHEAD_BYTES,
|
513
|
+
GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE,
|
514
|
+
{-1, 5, INT32_MAX},
|
515
|
+
{true, true}}};
|
516
|
+
for (j = 0; j < (int)GPR_ARRAY_SIZE(settings_map); j++) {
|
517
|
+
if (0 == strcmp(channel_args->args[i].key,
|
518
|
+
settings_map[j].channel_arg_name)) {
|
519
|
+
if (!settings_map[j].availability[is_client]) {
|
520
|
+
gpr_log(GPR_DEBUG, "%s is not available on %s",
|
521
|
+
settings_map[j].channel_arg_name,
|
522
|
+
is_client ? "clients" : "servers");
|
523
|
+
} else {
|
524
|
+
int value = grpc_channel_arg_get_integer(
|
525
|
+
&channel_args->args[i], settings_map[j].integer_options);
|
526
|
+
if (value >= 0) {
|
527
|
+
push_setting(exec_ctx, t, settings_map[j].setting_id,
|
528
|
+
(uint32_t)value);
|
529
|
+
}
|
530
|
+
}
|
531
|
+
break;
|
532
|
+
}
|
533
|
+
}
|
534
|
+
}
|
535
|
+
}
|
536
|
+
}
|
537
|
+
|
538
|
+
t->ping_state.pings_before_data_required =
|
539
|
+
t->ping_policy.max_pings_without_data;
|
540
|
+
t->ping_state.is_delayed_ping_timer_set = false;
|
541
|
+
|
542
|
+
t->ping_recv_state.last_ping_recv_time = gpr_inf_past(GPR_CLOCK_MONOTONIC);
|
543
|
+
t->ping_recv_state.ping_strikes = 0;
|
544
|
+
|
545
|
+
/* Start keepalive pings */
|
546
|
+
if (gpr_time_cmp(t->keepalive_time, gpr_inf_future(GPR_TIMESPAN)) != 0) {
|
547
|
+
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
|
548
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
|
549
|
+
grpc_timer_init(
|
550
|
+
exec_ctx, &t->keepalive_ping_timer,
|
551
|
+
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
|
552
|
+
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
|
553
|
+
}
|
554
|
+
|
555
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "init");
|
556
|
+
post_benign_reclaimer(exec_ctx, t);
|
557
|
+
}
|
558
|
+
|
559
|
+
static void destroy_transport_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
560
|
+
grpc_error *error) {
|
561
|
+
grpc_chttp2_transport *t = tp;
|
562
|
+
t->destroying = 1;
|
563
|
+
close_transport_locked(
|
564
|
+
exec_ctx, t,
|
565
|
+
grpc_error_set_int(
|
566
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport destroyed"),
|
567
|
+
GRPC_ERROR_INT_OCCURRED_DURING_WRITE, t->write_state));
|
568
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destroy");
|
569
|
+
}
|
570
|
+
|
571
|
+
static void destroy_transport(grpc_exec_ctx *exec_ctx, grpc_transport *gt) {
|
572
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
573
|
+
grpc_closure_sched(exec_ctx, grpc_closure_create(
|
574
|
+
destroy_transport_locked, t,
|
575
|
+
grpc_combiner_scheduler(t->combiner, false)),
|
576
|
+
GRPC_ERROR_NONE);
|
577
|
+
}
|
578
|
+
|
579
|
+
static void close_transport_locked(grpc_exec_ctx *exec_ctx,
|
580
|
+
grpc_chttp2_transport *t,
|
581
|
+
grpc_error *error) {
|
582
|
+
if (!t->closed) {
|
583
|
+
if (!grpc_error_has_clear_grpc_status(error)) {
|
584
|
+
error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS,
|
585
|
+
GRPC_STATUS_UNAVAILABLE);
|
586
|
+
}
|
587
|
+
if (t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE) {
|
588
|
+
if (t->close_transport_on_writes_finished == NULL) {
|
589
|
+
t->close_transport_on_writes_finished =
|
590
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
591
|
+
"Delayed close due to in-progress write");
|
592
|
+
}
|
593
|
+
t->close_transport_on_writes_finished =
|
594
|
+
grpc_error_add_child(t->close_transport_on_writes_finished, error);
|
595
|
+
return;
|
596
|
+
}
|
597
|
+
t->closed = 1;
|
598
|
+
connectivity_state_set(exec_ctx, t, GRPC_CHANNEL_SHUTDOWN,
|
599
|
+
GRPC_ERROR_REF(error), "close_transport");
|
600
|
+
grpc_endpoint_shutdown(exec_ctx, t->ep, GRPC_ERROR_REF(error));
|
601
|
+
if (t->is_client) {
|
602
|
+
switch (t->keepalive_state) {
|
603
|
+
case GRPC_CHTTP2_KEEPALIVE_STATE_WAITING: {
|
604
|
+
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
|
605
|
+
break;
|
606
|
+
}
|
607
|
+
case GRPC_CHTTP2_KEEPALIVE_STATE_PINGING: {
|
608
|
+
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
|
609
|
+
grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer);
|
610
|
+
break;
|
611
|
+
}
|
612
|
+
case GRPC_CHTTP2_KEEPALIVE_STATE_DYING: {
|
613
|
+
break;
|
614
|
+
}
|
615
|
+
}
|
616
|
+
}
|
617
|
+
|
618
|
+
/* flush writable stream list to avoid dangling references */
|
619
|
+
grpc_chttp2_stream *s;
|
620
|
+
while (grpc_chttp2_list_pop_writable_stream(t, &s)) {
|
621
|
+
GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:close");
|
622
|
+
}
|
623
|
+
end_all_the_calls(exec_ctx, t, GRPC_ERROR_REF(error));
|
624
|
+
cancel_pings(exec_ctx, t, GRPC_ERROR_REF(error));
|
625
|
+
}
|
626
|
+
GRPC_ERROR_UNREF(error);
|
627
|
+
}
|
628
|
+
|
629
|
+
#ifdef GRPC_STREAM_REFCOUNT_DEBUG
|
630
|
+
void grpc_chttp2_stream_ref(grpc_chttp2_stream *s, const char *reason) {
|
631
|
+
grpc_stream_ref(s->refcount, reason);
|
632
|
+
}
|
633
|
+
void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s,
|
634
|
+
const char *reason) {
|
635
|
+
grpc_stream_unref(exec_ctx, s->refcount, reason);
|
636
|
+
}
|
637
|
+
#else
|
638
|
+
void grpc_chttp2_stream_ref(grpc_chttp2_stream *s) {
|
639
|
+
grpc_stream_ref(s->refcount);
|
640
|
+
}
|
641
|
+
void grpc_chttp2_stream_unref(grpc_exec_ctx *exec_ctx, grpc_chttp2_stream *s) {
|
642
|
+
grpc_stream_unref(exec_ctx, s->refcount);
|
643
|
+
}
|
644
|
+
#endif
|
645
|
+
|
646
|
+
static int init_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
647
|
+
grpc_stream *gs, grpc_stream_refcount *refcount,
|
648
|
+
const void *server_data, gpr_arena *arena) {
|
649
|
+
GPR_TIMER_BEGIN("init_stream", 0);
|
650
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
651
|
+
grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
|
652
|
+
|
653
|
+
s->t = t;
|
654
|
+
s->refcount = refcount;
|
655
|
+
/* We reserve one 'active stream' that's dropped when the stream is
|
656
|
+
read-closed. The others are for incoming_byte_streams that are actively
|
657
|
+
reading */
|
658
|
+
gpr_ref_init(&s->active_streams, 1);
|
659
|
+
GRPC_CHTTP2_STREAM_REF(s, "chttp2");
|
660
|
+
|
661
|
+
grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[0], arena);
|
662
|
+
grpc_chttp2_incoming_metadata_buffer_init(&s->metadata_buffer[1], arena);
|
663
|
+
grpc_chttp2_data_parser_init(&s->data_parser);
|
664
|
+
grpc_slice_buffer_init(&s->flow_controlled_buffer);
|
665
|
+
s->deadline = gpr_inf_future(GPR_CLOCK_MONOTONIC);
|
666
|
+
grpc_closure_init(&s->complete_fetch_locked, complete_fetch_locked, s,
|
667
|
+
grpc_schedule_on_exec_ctx);
|
668
|
+
|
669
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "stream");
|
670
|
+
|
671
|
+
if (server_data) {
|
672
|
+
s->id = (uint32_t)(uintptr_t)server_data;
|
673
|
+
*t->accepting_stream = s;
|
674
|
+
grpc_chttp2_stream_map_add(&t->stream_map, s->id, s);
|
675
|
+
post_destructive_reclaimer(exec_ctx, t);
|
676
|
+
}
|
677
|
+
|
678
|
+
GPR_TIMER_END("init_stream", 0);
|
679
|
+
|
680
|
+
return 0;
|
681
|
+
}
|
682
|
+
|
683
|
+
static void destroy_stream_locked(grpc_exec_ctx *exec_ctx, void *sp,
|
684
|
+
grpc_error *error) {
|
685
|
+
grpc_byte_stream *bs;
|
686
|
+
grpc_chttp2_stream *s = sp;
|
687
|
+
grpc_chttp2_transport *t = s->t;
|
688
|
+
|
689
|
+
GPR_TIMER_BEGIN("destroy_stream", 0);
|
690
|
+
|
691
|
+
GPR_ASSERT((s->write_closed && s->read_closed) || s->id == 0);
|
692
|
+
if (s->id != 0) {
|
693
|
+
GPR_ASSERT(grpc_chttp2_stream_map_find(&t->stream_map, s->id) == NULL);
|
694
|
+
}
|
695
|
+
|
696
|
+
while ((bs = grpc_chttp2_incoming_frame_queue_pop(&s->incoming_frames))) {
|
697
|
+
incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE);
|
698
|
+
}
|
699
|
+
|
700
|
+
grpc_chttp2_list_remove_stalled_by_transport(t, s);
|
701
|
+
grpc_chttp2_list_remove_stalled_by_stream(t, s);
|
702
|
+
|
703
|
+
for (int i = 0; i < STREAM_LIST_COUNT; i++) {
|
704
|
+
if (s->included[i]) {
|
705
|
+
gpr_log(GPR_ERROR, "%s stream %d still included in list %d",
|
706
|
+
t->is_client ? "client" : "server", s->id, i);
|
707
|
+
abort();
|
708
|
+
}
|
709
|
+
}
|
710
|
+
|
711
|
+
GPR_ASSERT(s->send_initial_metadata_finished == NULL);
|
712
|
+
GPR_ASSERT(s->fetching_send_message == NULL);
|
713
|
+
GPR_ASSERT(s->send_trailing_metadata_finished == NULL);
|
714
|
+
GPR_ASSERT(s->recv_initial_metadata_ready == NULL);
|
715
|
+
GPR_ASSERT(s->recv_message_ready == NULL);
|
716
|
+
GPR_ASSERT(s->recv_trailing_metadata_finished == NULL);
|
717
|
+
grpc_chttp2_data_parser_destroy(exec_ctx, &s->data_parser);
|
718
|
+
grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx,
|
719
|
+
&s->metadata_buffer[0]);
|
720
|
+
grpc_chttp2_incoming_metadata_buffer_destroy(exec_ctx,
|
721
|
+
&s->metadata_buffer[1]);
|
722
|
+
grpc_slice_buffer_destroy_internal(exec_ctx, &s->flow_controlled_buffer);
|
723
|
+
GRPC_ERROR_UNREF(s->read_closed_error);
|
724
|
+
GRPC_ERROR_UNREF(s->write_closed_error);
|
725
|
+
|
726
|
+
if (s->incoming_window_delta > 0) {
|
727
|
+
GRPC_CHTTP2_FLOW_DEBIT_STREAM_INCOMING_WINDOW_DELTA(
|
728
|
+
"destroy", t, s, s->incoming_window_delta);
|
729
|
+
} else if (s->incoming_window_delta < 0) {
|
730
|
+
GRPC_CHTTP2_FLOW_CREDIT_STREAM_INCOMING_WINDOW_DELTA(
|
731
|
+
"destroy", t, s, -s->incoming_window_delta);
|
732
|
+
}
|
733
|
+
|
734
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "stream");
|
735
|
+
|
736
|
+
GPR_TIMER_END("destroy_stream", 0);
|
737
|
+
|
738
|
+
grpc_closure_sched(exec_ctx, s->destroy_stream_arg, GRPC_ERROR_NONE);
|
739
|
+
}
|
740
|
+
|
741
|
+
static void destroy_stream(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
742
|
+
grpc_stream *gs,
|
743
|
+
grpc_closure *then_schedule_closure) {
|
744
|
+
GPR_TIMER_BEGIN("destroy_stream", 0);
|
745
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
746
|
+
grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
|
747
|
+
|
748
|
+
s->destroy_stream_arg = then_schedule_closure;
|
749
|
+
grpc_closure_sched(
|
750
|
+
exec_ctx, grpc_closure_init(&s->destroy_stream, destroy_stream_locked, s,
|
751
|
+
grpc_combiner_scheduler(t->combiner, false)),
|
752
|
+
GRPC_ERROR_NONE);
|
753
|
+
GPR_TIMER_END("destroy_stream", 0);
|
754
|
+
}
|
755
|
+
|
756
|
+
grpc_chttp2_stream *grpc_chttp2_parsing_lookup_stream(grpc_chttp2_transport *t,
|
757
|
+
uint32_t id) {
|
758
|
+
return grpc_chttp2_stream_map_find(&t->stream_map, id);
|
759
|
+
}
|
760
|
+
|
761
|
+
grpc_chttp2_stream *grpc_chttp2_parsing_accept_stream(grpc_exec_ctx *exec_ctx,
|
762
|
+
grpc_chttp2_transport *t,
|
763
|
+
uint32_t id) {
|
764
|
+
if (t->channel_callback.accept_stream == NULL) {
|
765
|
+
return NULL;
|
766
|
+
}
|
767
|
+
grpc_chttp2_stream *accepting;
|
768
|
+
GPR_ASSERT(t->accepting_stream == NULL);
|
769
|
+
t->accepting_stream = &accepting;
|
770
|
+
t->channel_callback.accept_stream(exec_ctx,
|
771
|
+
t->channel_callback.accept_stream_user_data,
|
772
|
+
&t->base, (void *)(uintptr_t)id);
|
773
|
+
t->accepting_stream = NULL;
|
774
|
+
return accepting;
|
775
|
+
}
|
776
|
+
|
777
|
+
/*******************************************************************************
|
778
|
+
* OUTPUT PROCESSING
|
779
|
+
*/
|
780
|
+
|
781
|
+
static const char *write_state_name(grpc_chttp2_write_state st) {
|
782
|
+
switch (st) {
|
783
|
+
case GRPC_CHTTP2_WRITE_STATE_IDLE:
|
784
|
+
return "IDLE";
|
785
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING:
|
786
|
+
return "WRITING";
|
787
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE:
|
788
|
+
return "WRITING+MORE";
|
789
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER:
|
790
|
+
return "WRITING+MORE+COVERED";
|
791
|
+
}
|
792
|
+
GPR_UNREACHABLE_CODE(return "UNKNOWN");
|
793
|
+
}
|
794
|
+
|
795
|
+
static void set_write_state(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
796
|
+
grpc_chttp2_write_state st, const char *reason) {
|
797
|
+
GRPC_CHTTP2_IF_TRACING(gpr_log(GPR_DEBUG, "W:%p %s state %s -> %s [%s]", t,
|
798
|
+
t->is_client ? "CLIENT" : "SERVER",
|
799
|
+
write_state_name(t->write_state),
|
800
|
+
write_state_name(st), reason));
|
801
|
+
t->write_state = st;
|
802
|
+
if (st == GRPC_CHTTP2_WRITE_STATE_IDLE) {
|
803
|
+
grpc_closure_list_sched(exec_ctx, &t->run_after_write);
|
804
|
+
if (t->close_transport_on_writes_finished != NULL) {
|
805
|
+
grpc_error *err = t->close_transport_on_writes_finished;
|
806
|
+
t->close_transport_on_writes_finished = NULL;
|
807
|
+
close_transport_locked(exec_ctx, t, err);
|
808
|
+
}
|
809
|
+
}
|
810
|
+
}
|
811
|
+
|
812
|
+
void grpc_chttp2_initiate_write(grpc_exec_ctx *exec_ctx,
|
813
|
+
grpc_chttp2_transport *t,
|
814
|
+
bool covered_by_poller, const char *reason) {
|
815
|
+
GPR_TIMER_BEGIN("grpc_chttp2_initiate_write", 0);
|
816
|
+
|
817
|
+
switch (t->write_state) {
|
818
|
+
case GRPC_CHTTP2_WRITE_STATE_IDLE:
|
819
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING, reason);
|
820
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
|
821
|
+
grpc_closure_sched(
|
822
|
+
exec_ctx,
|
823
|
+
grpc_closure_init(
|
824
|
+
&t->write_action_begin_locked, write_action_begin_locked, t,
|
825
|
+
grpc_combiner_finally_scheduler(t->combiner, covered_by_poller)),
|
826
|
+
GRPC_ERROR_NONE);
|
827
|
+
break;
|
828
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING:
|
829
|
+
set_write_state(
|
830
|
+
exec_ctx, t,
|
831
|
+
covered_by_poller
|
832
|
+
? GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER
|
833
|
+
: GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE,
|
834
|
+
reason);
|
835
|
+
break;
|
836
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE:
|
837
|
+
if (covered_by_poller) {
|
838
|
+
set_write_state(
|
839
|
+
exec_ctx, t,
|
840
|
+
GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER,
|
841
|
+
reason);
|
842
|
+
}
|
843
|
+
break;
|
844
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER:
|
845
|
+
break;
|
846
|
+
}
|
847
|
+
GPR_TIMER_END("grpc_chttp2_initiate_write", 0);
|
848
|
+
}
|
849
|
+
|
850
|
+
void grpc_chttp2_become_writable(
|
851
|
+
grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s,
|
852
|
+
grpc_chttp2_stream_write_type stream_write_type, const char *reason) {
|
853
|
+
if (!t->closed && grpc_chttp2_list_add_writable_stream(t, s)) {
|
854
|
+
GRPC_CHTTP2_STREAM_REF(s, "chttp2_writing:become");
|
855
|
+
}
|
856
|
+
switch (stream_write_type) {
|
857
|
+
case GRPC_CHTTP2_STREAM_WRITE_PIGGYBACK:
|
858
|
+
break;
|
859
|
+
case GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED:
|
860
|
+
grpc_chttp2_initiate_write(exec_ctx, t, true, reason);
|
861
|
+
break;
|
862
|
+
case GRPC_CHTTP2_STREAM_WRITE_INITIATE_UNCOVERED:
|
863
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, reason);
|
864
|
+
break;
|
865
|
+
}
|
866
|
+
}
|
867
|
+
|
868
|
+
static void write_action_begin_locked(grpc_exec_ctx *exec_ctx, void *gt,
|
869
|
+
grpc_error *error_ignored) {
|
870
|
+
GPR_TIMER_BEGIN("write_action_begin_locked", 0);
|
871
|
+
grpc_chttp2_transport *t = gt;
|
872
|
+
GPR_ASSERT(t->write_state != GRPC_CHTTP2_WRITE_STATE_IDLE);
|
873
|
+
if (!t->closed && grpc_chttp2_begin_write(exec_ctx, t)) {
|
874
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING,
|
875
|
+
"begin writing");
|
876
|
+
grpc_closure_sched(exec_ctx, &t->write_action, GRPC_ERROR_NONE);
|
877
|
+
} else {
|
878
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE,
|
879
|
+
"begin writing nothing");
|
880
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing");
|
881
|
+
}
|
882
|
+
GPR_TIMER_END("write_action_begin_locked", 0);
|
883
|
+
}
|
884
|
+
|
885
|
+
static void write_action(grpc_exec_ctx *exec_ctx, void *gt, grpc_error *error) {
|
886
|
+
grpc_chttp2_transport *t = gt;
|
887
|
+
GPR_TIMER_BEGIN("write_action", 0);
|
888
|
+
grpc_endpoint_write(
|
889
|
+
exec_ctx, t->ep, &t->outbuf,
|
890
|
+
grpc_closure_init(&t->write_action_end_locked, write_action_end_locked, t,
|
891
|
+
grpc_combiner_scheduler(t->combiner, false)));
|
892
|
+
GPR_TIMER_END("write_action", 0);
|
893
|
+
}
|
894
|
+
|
895
|
+
static void write_action_end_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
896
|
+
grpc_error *error) {
|
897
|
+
GPR_TIMER_BEGIN("terminate_writing_with_lock", 0);
|
898
|
+
grpc_chttp2_transport *t = tp;
|
899
|
+
|
900
|
+
if (error != GRPC_ERROR_NONE) {
|
901
|
+
close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error));
|
902
|
+
}
|
903
|
+
|
904
|
+
if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED) {
|
905
|
+
t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SENT;
|
906
|
+
if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
|
907
|
+
close_transport_locked(
|
908
|
+
exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("goaway sent"));
|
909
|
+
}
|
910
|
+
}
|
911
|
+
|
912
|
+
switch (t->write_state) {
|
913
|
+
case GRPC_CHTTP2_WRITE_STATE_IDLE:
|
914
|
+
GPR_UNREACHABLE_CODE(break);
|
915
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING:
|
916
|
+
GPR_TIMER_MARK("state=writing", 0);
|
917
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_IDLE,
|
918
|
+
"finish writing");
|
919
|
+
break;
|
920
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE:
|
921
|
+
GPR_TIMER_MARK("state=writing_stale_no_poller", 0);
|
922
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING,
|
923
|
+
"continue writing [!covered]");
|
924
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
|
925
|
+
grpc_closure_run(
|
926
|
+
exec_ctx,
|
927
|
+
grpc_closure_init(
|
928
|
+
&t->write_action_begin_locked, write_action_begin_locked, t,
|
929
|
+
grpc_combiner_finally_scheduler(t->combiner, false)),
|
930
|
+
GRPC_ERROR_NONE);
|
931
|
+
break;
|
932
|
+
case GRPC_CHTTP2_WRITE_STATE_WRITING_WITH_MORE_AND_COVERED_BY_POLLER:
|
933
|
+
GPR_TIMER_MARK("state=writing_stale_with_poller", 0);
|
934
|
+
set_write_state(exec_ctx, t, GRPC_CHTTP2_WRITE_STATE_WRITING,
|
935
|
+
"continue writing [covered]");
|
936
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "writing");
|
937
|
+
grpc_closure_run(
|
938
|
+
exec_ctx,
|
939
|
+
grpc_closure_init(&t->write_action_begin_locked,
|
940
|
+
write_action_begin_locked, t,
|
941
|
+
grpc_combiner_finally_scheduler(t->combiner, true)),
|
942
|
+
GRPC_ERROR_NONE);
|
943
|
+
break;
|
944
|
+
}
|
945
|
+
|
946
|
+
grpc_chttp2_end_write(exec_ctx, t, GRPC_ERROR_REF(error));
|
947
|
+
|
948
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "writing");
|
949
|
+
GPR_TIMER_END("terminate_writing_with_lock", 0);
|
950
|
+
}
|
951
|
+
|
952
|
+
static void push_setting(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
953
|
+
grpc_chttp2_setting_id id, uint32_t value) {
|
954
|
+
const grpc_chttp2_setting_parameters *sp =
|
955
|
+
&grpc_chttp2_settings_parameters[id];
|
956
|
+
uint32_t use_value = GPR_CLAMP(value, sp->min_value, sp->max_value);
|
957
|
+
if (use_value != value) {
|
958
|
+
gpr_log(GPR_INFO, "Requested parameter %s clamped from %d to %d", sp->name,
|
959
|
+
value, use_value);
|
960
|
+
}
|
961
|
+
if (use_value != t->settings[GRPC_LOCAL_SETTINGS][id]) {
|
962
|
+
t->settings[GRPC_LOCAL_SETTINGS][id] = use_value;
|
963
|
+
t->dirtied_local_settings = 1;
|
964
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "push_setting");
|
965
|
+
}
|
966
|
+
}
|
967
|
+
|
968
|
+
void grpc_chttp2_add_incoming_goaway(grpc_exec_ctx *exec_ctx,
|
969
|
+
grpc_chttp2_transport *t,
|
970
|
+
uint32_t goaway_error,
|
971
|
+
grpc_slice goaway_text) {
|
972
|
+
// GRPC_CHTTP2_IF_TRACING(
|
973
|
+
// gpr_log(GPR_DEBUG, "got goaway [%d]: %s", goaway_error, msg));
|
974
|
+
t->seen_goaway = 1;
|
975
|
+
|
976
|
+
/* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug
|
977
|
+
* data equal to “too_many_pings”, it should log the occurrence at a log level
|
978
|
+
* that is enabled by default and double the configured KEEPALIVE_TIME used
|
979
|
+
* for new connections on that channel. */
|
980
|
+
if (t->is_client && goaway_error == GRPC_HTTP2_ENHANCE_YOUR_CALM &&
|
981
|
+
grpc_slice_str_cmp(goaway_text, "too_many_pings") == 0) {
|
982
|
+
gpr_log(GPR_ERROR,
|
983
|
+
"Received a GOAWAY with error code ENHANCE_YOUR_CALM and debug "
|
984
|
+
"data equal to \"too_many_pings\"");
|
985
|
+
double current_keepalive_time_ms =
|
986
|
+
gpr_timespec_to_micros(t->keepalive_time) / 1000;
|
987
|
+
t->keepalive_time =
|
988
|
+
current_keepalive_time_ms > INT_MAX / KEEPALIVE_TIME_BACKOFF_MULTIPLIER
|
989
|
+
? gpr_inf_future(GPR_TIMESPAN)
|
990
|
+
: gpr_time_from_millis((int64_t)(current_keepalive_time_ms *
|
991
|
+
KEEPALIVE_TIME_BACKOFF_MULTIPLIER),
|
992
|
+
GPR_TIMESPAN);
|
993
|
+
}
|
994
|
+
|
995
|
+
/* lie: use transient failure from the transport to indicate goaway has been
|
996
|
+
* received */
|
997
|
+
connectivity_state_set(
|
998
|
+
exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
|
999
|
+
grpc_error_set_str(
|
1000
|
+
grpc_error_set_int(
|
1001
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("GOAWAY received"),
|
1002
|
+
GRPC_ERROR_INT_HTTP2_ERROR, (intptr_t)goaway_error),
|
1003
|
+
GRPC_ERROR_STR_RAW_BYTES, goaway_text),
|
1004
|
+
"got_goaway");
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
static void maybe_start_some_streams(grpc_exec_ctx *exec_ctx,
|
1008
|
+
grpc_chttp2_transport *t) {
|
1009
|
+
grpc_chttp2_stream *s;
|
1010
|
+
/* start streams where we have free grpc_chttp2_stream ids and free
|
1011
|
+
* concurrency */
|
1012
|
+
while (t->next_stream_id <= MAX_CLIENT_STREAM_ID &&
|
1013
|
+
grpc_chttp2_stream_map_size(&t->stream_map) <
|
1014
|
+
t->settings[GRPC_PEER_SETTINGS]
|
1015
|
+
[GRPC_CHTTP2_SETTINGS_MAX_CONCURRENT_STREAMS] &&
|
1016
|
+
grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) {
|
1017
|
+
/* safe since we can't (legally) be parsing this stream yet */
|
1018
|
+
GRPC_CHTTP2_IF_TRACING(gpr_log(
|
1019
|
+
GPR_DEBUG, "HTTP:%s: Allocating new grpc_chttp2_stream %p to id %d",
|
1020
|
+
t->is_client ? "CLI" : "SVR", s, t->next_stream_id));
|
1021
|
+
|
1022
|
+
GPR_ASSERT(s->id == 0);
|
1023
|
+
s->id = t->next_stream_id;
|
1024
|
+
t->next_stream_id += 2;
|
1025
|
+
|
1026
|
+
if (t->next_stream_id >= MAX_CLIENT_STREAM_ID) {
|
1027
|
+
connectivity_state_set(
|
1028
|
+
exec_ctx, t, GRPC_CHANNEL_TRANSIENT_FAILURE,
|
1029
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"),
|
1030
|
+
"no_more_stream_ids");
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
grpc_chttp2_stream_map_add(&t->stream_map, s->id, s);
|
1034
|
+
post_destructive_reclaimer(exec_ctx, t);
|
1035
|
+
grpc_chttp2_become_writable(exec_ctx, t, s,
|
1036
|
+
GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED,
|
1037
|
+
"new_stream");
|
1038
|
+
}
|
1039
|
+
/* cancel out streams that will never be started */
|
1040
|
+
while (t->next_stream_id >= MAX_CLIENT_STREAM_ID &&
|
1041
|
+
grpc_chttp2_list_pop_waiting_for_concurrency(t, &s)) {
|
1042
|
+
grpc_chttp2_cancel_stream(
|
1043
|
+
exec_ctx, t, s,
|
1044
|
+
grpc_error_set_int(
|
1045
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Stream IDs exhausted"),
|
1046
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE));
|
1047
|
+
}
|
1048
|
+
}
|
1049
|
+
|
1050
|
+
/* Flag that this closure barrier wants stats to be updated before finishing */
|
1051
|
+
#define CLOSURE_BARRIER_STATS_BIT (1 << 0)
|
1052
|
+
/* Flag that this closure barrier may be covering a write in a pollset, and so
|
1053
|
+
we should not complete this closure until we can prove that the write got
|
1054
|
+
scheduled */
|
1055
|
+
#define CLOSURE_BARRIER_MAY_COVER_WRITE (1 << 1)
|
1056
|
+
/* First bit of the reference count, stored in the high order bits (with the low
|
1057
|
+
bits being used for flags defined above) */
|
1058
|
+
#define CLOSURE_BARRIER_FIRST_REF_BIT (1 << 16)
|
1059
|
+
|
1060
|
+
static grpc_closure *add_closure_barrier(grpc_closure *closure) {
|
1061
|
+
closure->next_data.scratch += CLOSURE_BARRIER_FIRST_REF_BIT;
|
1062
|
+
return closure;
|
1063
|
+
}
|
1064
|
+
|
1065
|
+
static void null_then_run_closure(grpc_exec_ctx *exec_ctx,
|
1066
|
+
grpc_closure **closure, grpc_error *error) {
|
1067
|
+
grpc_closure *c = *closure;
|
1068
|
+
*closure = NULL;
|
1069
|
+
grpc_closure_run(exec_ctx, c, error);
|
1070
|
+
}
|
1071
|
+
|
1072
|
+
void grpc_chttp2_complete_closure_step(grpc_exec_ctx *exec_ctx,
|
1073
|
+
grpc_chttp2_transport *t,
|
1074
|
+
grpc_chttp2_stream *s,
|
1075
|
+
grpc_closure **pclosure,
|
1076
|
+
grpc_error *error, const char *desc) {
|
1077
|
+
grpc_closure *closure = *pclosure;
|
1078
|
+
*pclosure = NULL;
|
1079
|
+
if (closure == NULL) {
|
1080
|
+
GRPC_ERROR_UNREF(error);
|
1081
|
+
return;
|
1082
|
+
}
|
1083
|
+
closure->next_data.scratch -= CLOSURE_BARRIER_FIRST_REF_BIT;
|
1084
|
+
if (grpc_http_trace) {
|
1085
|
+
const char *errstr = grpc_error_string(error);
|
1086
|
+
gpr_log(GPR_DEBUG,
|
1087
|
+
"complete_closure_step: %p refs=%d flags=0x%04x desc=%s err=%s",
|
1088
|
+
closure,
|
1089
|
+
(int)(closure->next_data.scratch / CLOSURE_BARRIER_FIRST_REF_BIT),
|
1090
|
+
(int)(closure->next_data.scratch % CLOSURE_BARRIER_FIRST_REF_BIT),
|
1091
|
+
desc, errstr);
|
1092
|
+
}
|
1093
|
+
if (error != GRPC_ERROR_NONE) {
|
1094
|
+
if (closure->error_data.error == GRPC_ERROR_NONE) {
|
1095
|
+
closure->error_data.error = GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1096
|
+
"Error in HTTP transport completing operation");
|
1097
|
+
closure->error_data.error = grpc_error_set_str(
|
1098
|
+
closure->error_data.error, GRPC_ERROR_STR_TARGET_ADDRESS,
|
1099
|
+
grpc_slice_from_copied_string(t->peer_string));
|
1100
|
+
}
|
1101
|
+
closure->error_data.error =
|
1102
|
+
grpc_error_add_child(closure->error_data.error, error);
|
1103
|
+
}
|
1104
|
+
if (closure->next_data.scratch < CLOSURE_BARRIER_FIRST_REF_BIT) {
|
1105
|
+
if (closure->next_data.scratch & CLOSURE_BARRIER_STATS_BIT) {
|
1106
|
+
grpc_transport_move_stats(&s->stats, s->collecting_stats);
|
1107
|
+
s->collecting_stats = NULL;
|
1108
|
+
}
|
1109
|
+
if ((t->write_state == GRPC_CHTTP2_WRITE_STATE_IDLE) ||
|
1110
|
+
!(closure->next_data.scratch & CLOSURE_BARRIER_MAY_COVER_WRITE)) {
|
1111
|
+
grpc_closure_run(exec_ctx, closure, closure->error_data.error);
|
1112
|
+
} else {
|
1113
|
+
grpc_closure_list_append(&t->run_after_write, closure,
|
1114
|
+
closure->error_data.error);
|
1115
|
+
}
|
1116
|
+
}
|
1117
|
+
}
|
1118
|
+
|
1119
|
+
static bool contains_non_ok_status(grpc_metadata_batch *batch) {
|
1120
|
+
if (batch->idx.named.grpc_status != NULL) {
|
1121
|
+
return !grpc_mdelem_eq(batch->idx.named.grpc_status->md,
|
1122
|
+
GRPC_MDELEM_GRPC_STATUS_0);
|
1123
|
+
}
|
1124
|
+
return false;
|
1125
|
+
}
|
1126
|
+
|
1127
|
+
static void maybe_become_writable_due_to_send_msg(grpc_exec_ctx *exec_ctx,
|
1128
|
+
grpc_chttp2_transport *t,
|
1129
|
+
grpc_chttp2_stream *s) {
|
1130
|
+
if (s->id != 0 && (!s->write_buffering ||
|
1131
|
+
s->flow_controlled_buffer.length > t->write_buffer_size)) {
|
1132
|
+
grpc_chttp2_become_writable(exec_ctx, t, s,
|
1133
|
+
GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED,
|
1134
|
+
"op.send_message");
|
1135
|
+
}
|
1136
|
+
}
|
1137
|
+
|
1138
|
+
static void add_fetched_slice_locked(grpc_exec_ctx *exec_ctx,
|
1139
|
+
grpc_chttp2_transport *t,
|
1140
|
+
grpc_chttp2_stream *s) {
|
1141
|
+
s->fetched_send_message_length +=
|
1142
|
+
(uint32_t)GRPC_SLICE_LENGTH(s->fetching_slice);
|
1143
|
+
grpc_slice_buffer_add(&s->flow_controlled_buffer, s->fetching_slice);
|
1144
|
+
maybe_become_writable_due_to_send_msg(exec_ctx, t, s);
|
1145
|
+
}
|
1146
|
+
|
1147
|
+
static void continue_fetching_send_locked(grpc_exec_ctx *exec_ctx,
|
1148
|
+
grpc_chttp2_transport *t,
|
1149
|
+
grpc_chttp2_stream *s) {
|
1150
|
+
for (;;) {
|
1151
|
+
if (s->fetching_send_message == NULL) {
|
1152
|
+
/* Stream was cancelled before message fetch completed */
|
1153
|
+
abort(); /* TODO(ctiller): what cleanup here? */
|
1154
|
+
return; /* early out */
|
1155
|
+
}
|
1156
|
+
if (s->fetched_send_message_length == s->fetching_send_message->length) {
|
1157
|
+
int64_t notify_offset = s->next_message_end_offset;
|
1158
|
+
if (notify_offset <= s->flow_controlled_bytes_written) {
|
1159
|
+
grpc_chttp2_complete_closure_step(
|
1160
|
+
exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_NONE,
|
1161
|
+
"fetching_send_message_finished");
|
1162
|
+
} else {
|
1163
|
+
grpc_chttp2_write_cb *cb = t->write_cb_pool;
|
1164
|
+
if (cb == NULL) {
|
1165
|
+
cb = gpr_malloc(sizeof(*cb));
|
1166
|
+
} else {
|
1167
|
+
t->write_cb_pool = cb->next;
|
1168
|
+
}
|
1169
|
+
cb->call_at_byte = notify_offset;
|
1170
|
+
cb->closure = s->fetching_send_message_finished;
|
1171
|
+
s->fetching_send_message_finished = NULL;
|
1172
|
+
cb->next = s->on_write_finished_cbs;
|
1173
|
+
s->on_write_finished_cbs = cb;
|
1174
|
+
}
|
1175
|
+
s->fetching_send_message = NULL;
|
1176
|
+
return; /* early out */
|
1177
|
+
} else if (grpc_byte_stream_next(exec_ctx, s->fetching_send_message,
|
1178
|
+
&s->fetching_slice, UINT32_MAX,
|
1179
|
+
&s->complete_fetch_locked)) {
|
1180
|
+
add_fetched_slice_locked(exec_ctx, t, s);
|
1181
|
+
}
|
1182
|
+
}
|
1183
|
+
}
|
1184
|
+
|
1185
|
+
static void complete_fetch_locked(grpc_exec_ctx *exec_ctx, void *gs,
|
1186
|
+
grpc_error *error) {
|
1187
|
+
grpc_chttp2_stream *s = gs;
|
1188
|
+
grpc_chttp2_transport *t = s->t;
|
1189
|
+
if (error == GRPC_ERROR_NONE) {
|
1190
|
+
add_fetched_slice_locked(exec_ctx, t, s);
|
1191
|
+
continue_fetching_send_locked(exec_ctx, t, s);
|
1192
|
+
} else {
|
1193
|
+
/* TODO(ctiller): what to do here */
|
1194
|
+
abort();
|
1195
|
+
}
|
1196
|
+
}
|
1197
|
+
|
1198
|
+
static void do_nothing(grpc_exec_ctx *exec_ctx, void *arg, grpc_error *error) {}
|
1199
|
+
|
1200
|
+
static void log_metadata(const grpc_metadata_batch *md_batch, uint32_t id,
|
1201
|
+
bool is_client, bool is_initial) {
|
1202
|
+
for (grpc_linked_mdelem *md = md_batch->list.head; md != md_batch->list.tail;
|
1203
|
+
md = md->next) {
|
1204
|
+
char *key = grpc_slice_to_c_string(GRPC_MDKEY(md->md));
|
1205
|
+
char *value = grpc_slice_to_c_string(GRPC_MDVALUE(md->md));
|
1206
|
+
gpr_log(GPR_INFO, "HTTP:%d:%s:%s: %s: %s", id, is_initial ? "HDR" : "TRL",
|
1207
|
+
is_client ? "CLI" : "SVR", key, value);
|
1208
|
+
gpr_free(key);
|
1209
|
+
gpr_free(value);
|
1210
|
+
}
|
1211
|
+
}
|
1212
|
+
|
1213
|
+
static void perform_stream_op_locked(grpc_exec_ctx *exec_ctx, void *stream_op,
|
1214
|
+
grpc_error *error_ignored) {
|
1215
|
+
GPR_TIMER_BEGIN("perform_stream_op_locked", 0);
|
1216
|
+
|
1217
|
+
grpc_transport_stream_op_batch *op = stream_op;
|
1218
|
+
grpc_chttp2_stream *s = op->handler_private.extra_arg;
|
1219
|
+
grpc_transport_stream_op_batch_payload *op_payload = op->payload;
|
1220
|
+
grpc_chttp2_transport *t = s->t;
|
1221
|
+
|
1222
|
+
if (grpc_http_trace) {
|
1223
|
+
char *str = grpc_transport_stream_op_batch_string(op);
|
1224
|
+
gpr_log(GPR_DEBUG, "perform_stream_op_locked: %s; on_complete = %p", str,
|
1225
|
+
op->on_complete);
|
1226
|
+
gpr_free(str);
|
1227
|
+
if (op->send_initial_metadata) {
|
1228
|
+
log_metadata(op_payload->send_initial_metadata.send_initial_metadata,
|
1229
|
+
s->id, t->is_client, true);
|
1230
|
+
}
|
1231
|
+
if (op->send_trailing_metadata) {
|
1232
|
+
log_metadata(op_payload->send_trailing_metadata.send_trailing_metadata,
|
1233
|
+
s->id, t->is_client, false);
|
1234
|
+
}
|
1235
|
+
}
|
1236
|
+
|
1237
|
+
grpc_closure *on_complete = op->on_complete;
|
1238
|
+
if (on_complete == NULL) {
|
1239
|
+
on_complete =
|
1240
|
+
grpc_closure_create(do_nothing, NULL, grpc_schedule_on_exec_ctx);
|
1241
|
+
}
|
1242
|
+
|
1243
|
+
/* use final_data as a barrier until enqueue time; the inital counter is
|
1244
|
+
dropped at the end of this function */
|
1245
|
+
on_complete->next_data.scratch = CLOSURE_BARRIER_FIRST_REF_BIT;
|
1246
|
+
on_complete->error_data.error = GRPC_ERROR_NONE;
|
1247
|
+
|
1248
|
+
if (op->collect_stats) {
|
1249
|
+
GPR_ASSERT(s->collecting_stats == NULL);
|
1250
|
+
s->collecting_stats = op_payload->collect_stats.collect_stats;
|
1251
|
+
on_complete->next_data.scratch |= CLOSURE_BARRIER_STATS_BIT;
|
1252
|
+
}
|
1253
|
+
|
1254
|
+
if (op->cancel_stream) {
|
1255
|
+
grpc_chttp2_cancel_stream(exec_ctx, t, s,
|
1256
|
+
op_payload->cancel_stream.cancel_error);
|
1257
|
+
}
|
1258
|
+
|
1259
|
+
if (op->send_initial_metadata) {
|
1260
|
+
GPR_ASSERT(s->send_initial_metadata_finished == NULL);
|
1261
|
+
on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
|
1262
|
+
s->send_initial_metadata_finished = add_closure_barrier(on_complete);
|
1263
|
+
s->send_initial_metadata =
|
1264
|
+
op_payload->send_initial_metadata.send_initial_metadata;
|
1265
|
+
const size_t metadata_size =
|
1266
|
+
grpc_metadata_batch_size(s->send_initial_metadata);
|
1267
|
+
const size_t metadata_peer_limit =
|
1268
|
+
t->settings[GRPC_PEER_SETTINGS]
|
1269
|
+
[GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
|
1270
|
+
if (t->is_client) {
|
1271
|
+
s->deadline =
|
1272
|
+
gpr_time_min(s->deadline, s->send_initial_metadata->deadline);
|
1273
|
+
}
|
1274
|
+
if (metadata_size > metadata_peer_limit) {
|
1275
|
+
grpc_chttp2_cancel_stream(
|
1276
|
+
exec_ctx, t, s,
|
1277
|
+
grpc_error_set_int(
|
1278
|
+
grpc_error_set_int(
|
1279
|
+
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1280
|
+
"to-be-sent initial metadata size "
|
1281
|
+
"exceeds peer limit"),
|
1282
|
+
GRPC_ERROR_INT_SIZE,
|
1283
|
+
(intptr_t)metadata_size),
|
1284
|
+
GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit),
|
1285
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
|
1286
|
+
} else {
|
1287
|
+
if (contains_non_ok_status(s->send_initial_metadata)) {
|
1288
|
+
s->seen_error = true;
|
1289
|
+
}
|
1290
|
+
if (!s->write_closed) {
|
1291
|
+
if (t->is_client) {
|
1292
|
+
if (!t->closed) {
|
1293
|
+
GPR_ASSERT(s->id == 0);
|
1294
|
+
grpc_chttp2_list_add_waiting_for_concurrency(t, s);
|
1295
|
+
maybe_start_some_streams(exec_ctx, t);
|
1296
|
+
} else {
|
1297
|
+
grpc_chttp2_cancel_stream(
|
1298
|
+
exec_ctx, t, s,
|
1299
|
+
grpc_error_set_int(
|
1300
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed"),
|
1301
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE));
|
1302
|
+
}
|
1303
|
+
} else {
|
1304
|
+
GPR_ASSERT(s->id != 0);
|
1305
|
+
grpc_chttp2_stream_write_type write_type =
|
1306
|
+
GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED;
|
1307
|
+
if (op->send_message &&
|
1308
|
+
(op->payload->send_message.send_message->flags &
|
1309
|
+
GRPC_WRITE_BUFFER_HINT)) {
|
1310
|
+
write_type = GRPC_CHTTP2_STREAM_WRITE_PIGGYBACK;
|
1311
|
+
}
|
1312
|
+
grpc_chttp2_become_writable(exec_ctx, t, s, write_type,
|
1313
|
+
"op.send_initial_metadata");
|
1314
|
+
}
|
1315
|
+
} else {
|
1316
|
+
s->send_initial_metadata = NULL;
|
1317
|
+
grpc_chttp2_complete_closure_step(
|
1318
|
+
exec_ctx, t, s, &s->send_initial_metadata_finished,
|
1319
|
+
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
|
1320
|
+
"Attempt to send initial metadata after stream was closed",
|
1321
|
+
&s->write_closed_error, 1),
|
1322
|
+
"send_initial_metadata_finished");
|
1323
|
+
}
|
1324
|
+
}
|
1325
|
+
}
|
1326
|
+
|
1327
|
+
if (op->send_message) {
|
1328
|
+
on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
|
1329
|
+
s->fetching_send_message_finished = add_closure_barrier(op->on_complete);
|
1330
|
+
if (s->write_closed) {
|
1331
|
+
grpc_chttp2_complete_closure_step(
|
1332
|
+
exec_ctx, t, s, &s->fetching_send_message_finished,
|
1333
|
+
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
|
1334
|
+
"Attempt to send message after stream was closed",
|
1335
|
+
&s->write_closed_error, 1),
|
1336
|
+
"fetching_send_message_finished");
|
1337
|
+
} else {
|
1338
|
+
GPR_ASSERT(s->fetching_send_message == NULL);
|
1339
|
+
uint8_t *frame_hdr =
|
1340
|
+
grpc_slice_buffer_tiny_add(&s->flow_controlled_buffer, 5);
|
1341
|
+
uint32_t flags = op_payload->send_message.send_message->flags;
|
1342
|
+
frame_hdr[0] = (flags & GRPC_WRITE_INTERNAL_COMPRESS) != 0;
|
1343
|
+
size_t len = op_payload->send_message.send_message->length;
|
1344
|
+
frame_hdr[1] = (uint8_t)(len >> 24);
|
1345
|
+
frame_hdr[2] = (uint8_t)(len >> 16);
|
1346
|
+
frame_hdr[3] = (uint8_t)(len >> 8);
|
1347
|
+
frame_hdr[4] = (uint8_t)(len);
|
1348
|
+
s->fetching_send_message = op_payload->send_message.send_message;
|
1349
|
+
s->fetched_send_message_length = 0;
|
1350
|
+
s->next_message_end_offset = s->flow_controlled_bytes_written +
|
1351
|
+
(int64_t)s->flow_controlled_buffer.length +
|
1352
|
+
(int64_t)len;
|
1353
|
+
s->complete_fetch_covered_by_poller = op->covered_by_poller;
|
1354
|
+
if (flags & GRPC_WRITE_BUFFER_HINT) {
|
1355
|
+
s->next_message_end_offset -= t->write_buffer_size;
|
1356
|
+
s->write_buffering = true;
|
1357
|
+
} else {
|
1358
|
+
s->write_buffering = false;
|
1359
|
+
}
|
1360
|
+
continue_fetching_send_locked(exec_ctx, t, s);
|
1361
|
+
maybe_become_writable_due_to_send_msg(exec_ctx, t, s);
|
1362
|
+
}
|
1363
|
+
}
|
1364
|
+
|
1365
|
+
if (op->send_trailing_metadata) {
|
1366
|
+
GPR_ASSERT(s->send_trailing_metadata_finished == NULL);
|
1367
|
+
on_complete->next_data.scratch |= CLOSURE_BARRIER_MAY_COVER_WRITE;
|
1368
|
+
s->send_trailing_metadata_finished = add_closure_barrier(on_complete);
|
1369
|
+
s->send_trailing_metadata =
|
1370
|
+
op_payload->send_trailing_metadata.send_trailing_metadata;
|
1371
|
+
s->write_buffering = false;
|
1372
|
+
const size_t metadata_size =
|
1373
|
+
grpc_metadata_batch_size(s->send_trailing_metadata);
|
1374
|
+
const size_t metadata_peer_limit =
|
1375
|
+
t->settings[GRPC_PEER_SETTINGS]
|
1376
|
+
[GRPC_CHTTP2_SETTINGS_MAX_HEADER_LIST_SIZE];
|
1377
|
+
if (metadata_size > metadata_peer_limit) {
|
1378
|
+
grpc_chttp2_cancel_stream(
|
1379
|
+
exec_ctx, t, s,
|
1380
|
+
grpc_error_set_int(
|
1381
|
+
grpc_error_set_int(
|
1382
|
+
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1383
|
+
"to-be-sent trailing metadata size "
|
1384
|
+
"exceeds peer limit"),
|
1385
|
+
GRPC_ERROR_INT_SIZE,
|
1386
|
+
(intptr_t)metadata_size),
|
1387
|
+
GRPC_ERROR_INT_LIMIT, (intptr_t)metadata_peer_limit),
|
1388
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_RESOURCE_EXHAUSTED));
|
1389
|
+
} else {
|
1390
|
+
if (contains_non_ok_status(s->send_trailing_metadata)) {
|
1391
|
+
s->seen_error = true;
|
1392
|
+
}
|
1393
|
+
if (s->write_closed) {
|
1394
|
+
s->send_trailing_metadata = NULL;
|
1395
|
+
grpc_chttp2_complete_closure_step(
|
1396
|
+
exec_ctx, t, s, &s->send_trailing_metadata_finished,
|
1397
|
+
grpc_metadata_batch_is_empty(
|
1398
|
+
op->payload->send_trailing_metadata.send_trailing_metadata)
|
1399
|
+
? GRPC_ERROR_NONE
|
1400
|
+
: GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
1401
|
+
"Attempt to send trailing metadata after "
|
1402
|
+
"stream was closed"),
|
1403
|
+
"send_trailing_metadata_finished");
|
1404
|
+
} else if (s->id != 0) {
|
1405
|
+
/* TODO(ctiller): check if there's flow control for any outstanding
|
1406
|
+
bytes before going writable */
|
1407
|
+
grpc_chttp2_become_writable(exec_ctx, t, s,
|
1408
|
+
GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED,
|
1409
|
+
"op.send_trailing_metadata");
|
1410
|
+
}
|
1411
|
+
}
|
1412
|
+
}
|
1413
|
+
|
1414
|
+
if (op->recv_initial_metadata) {
|
1415
|
+
GPR_ASSERT(s->recv_initial_metadata_ready == NULL);
|
1416
|
+
s->recv_initial_metadata_ready =
|
1417
|
+
op_payload->recv_initial_metadata.recv_initial_metadata_ready;
|
1418
|
+
s->recv_initial_metadata =
|
1419
|
+
op_payload->recv_initial_metadata.recv_initial_metadata;
|
1420
|
+
grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s);
|
1421
|
+
}
|
1422
|
+
|
1423
|
+
if (op->recv_message) {
|
1424
|
+
GPR_ASSERT(s->recv_message_ready == NULL);
|
1425
|
+
s->recv_message_ready = op_payload->recv_message.recv_message_ready;
|
1426
|
+
s->recv_message = op_payload->recv_message.recv_message;
|
1427
|
+
if (s->id != 0 &&
|
1428
|
+
(s->incoming_frames.head == NULL || s->incoming_frames.head->is_tail)) {
|
1429
|
+
incoming_byte_stream_update_flow_control(exec_ctx, t, s, 5, 0);
|
1430
|
+
}
|
1431
|
+
grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
|
1432
|
+
}
|
1433
|
+
|
1434
|
+
if (op->recv_trailing_metadata) {
|
1435
|
+
GPR_ASSERT(s->recv_trailing_metadata_finished == NULL);
|
1436
|
+
s->recv_trailing_metadata_finished = add_closure_barrier(on_complete);
|
1437
|
+
s->recv_trailing_metadata =
|
1438
|
+
op_payload->recv_trailing_metadata.recv_trailing_metadata;
|
1439
|
+
s->final_metadata_requested = true;
|
1440
|
+
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
|
1441
|
+
}
|
1442
|
+
|
1443
|
+
grpc_chttp2_complete_closure_step(exec_ctx, t, s, &on_complete,
|
1444
|
+
GRPC_ERROR_NONE, "op->on_complete");
|
1445
|
+
|
1446
|
+
GPR_TIMER_END("perform_stream_op_locked", 0);
|
1447
|
+
GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "perform_stream_op");
|
1448
|
+
}
|
1449
|
+
|
1450
|
+
static void perform_stream_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
1451
|
+
grpc_stream *gs,
|
1452
|
+
grpc_transport_stream_op_batch *op) {
|
1453
|
+
GPR_TIMER_BEGIN("perform_stream_op", 0);
|
1454
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
1455
|
+
grpc_chttp2_stream *s = (grpc_chttp2_stream *)gs;
|
1456
|
+
|
1457
|
+
if (grpc_http_trace) {
|
1458
|
+
char *str = grpc_transport_stream_op_batch_string(op);
|
1459
|
+
gpr_log(GPR_DEBUG, "perform_stream_op[s=%p/%d]: %s", s, s->id, str);
|
1460
|
+
gpr_free(str);
|
1461
|
+
}
|
1462
|
+
|
1463
|
+
op->handler_private.extra_arg = gs;
|
1464
|
+
GRPC_CHTTP2_STREAM_REF(s, "perform_stream_op");
|
1465
|
+
grpc_closure_sched(
|
1466
|
+
exec_ctx,
|
1467
|
+
grpc_closure_init(
|
1468
|
+
&op->handler_private.closure, perform_stream_op_locked, op,
|
1469
|
+
grpc_combiner_scheduler(t->combiner, op->covered_by_poller)),
|
1470
|
+
GRPC_ERROR_NONE);
|
1471
|
+
GPR_TIMER_END("perform_stream_op", 0);
|
1472
|
+
}
|
1473
|
+
|
1474
|
+
static void cancel_pings(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1475
|
+
grpc_error *error) {
|
1476
|
+
/* callback remaining pings: they're not allowed to call into the transpot,
|
1477
|
+
and maybe they hold resources that need to be freed */
|
1478
|
+
for (size_t i = 0; i < GRPC_CHTTP2_PING_TYPE_COUNT; i++) {
|
1479
|
+
grpc_chttp2_ping_queue *pq = &t->ping_queues[i];
|
1480
|
+
for (size_t j = 0; j < GRPC_CHTTP2_PCL_COUNT; j++) {
|
1481
|
+
grpc_closure_list_fail_all(&pq->lists[j], GRPC_ERROR_REF(error));
|
1482
|
+
grpc_closure_list_sched(exec_ctx, &pq->lists[j]);
|
1483
|
+
}
|
1484
|
+
}
|
1485
|
+
GRPC_ERROR_UNREF(error);
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
static void send_ping_locked(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1489
|
+
grpc_chttp2_ping_type ping_type,
|
1490
|
+
grpc_closure *on_initiate, grpc_closure *on_ack) {
|
1491
|
+
grpc_chttp2_ping_queue *pq = &t->ping_queues[ping_type];
|
1492
|
+
grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_INITIATE], on_initiate,
|
1493
|
+
GRPC_ERROR_NONE);
|
1494
|
+
if (grpc_closure_list_append(&pq->lists[GRPC_CHTTP2_PCL_NEXT], on_ack,
|
1495
|
+
GRPC_ERROR_NONE)) {
|
1496
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "send_ping");
|
1497
|
+
}
|
1498
|
+
}
|
1499
|
+
|
1500
|
+
static void retry_initiate_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
1501
|
+
grpc_error *error) {
|
1502
|
+
grpc_chttp2_transport *t = tp;
|
1503
|
+
t->ping_state.is_delayed_ping_timer_set = false;
|
1504
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "retry_send_ping");
|
1505
|
+
}
|
1506
|
+
|
1507
|
+
void grpc_chttp2_ack_ping(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1508
|
+
uint64_t id) {
|
1509
|
+
grpc_chttp2_ping_queue *pq =
|
1510
|
+
&t->ping_queues[id % GRPC_CHTTP2_PING_TYPE_COUNT];
|
1511
|
+
if (pq->inflight_id != id) {
|
1512
|
+
char *from = grpc_endpoint_get_peer(t->ep);
|
1513
|
+
gpr_log(GPR_DEBUG, "Unknown ping response from %s: %" PRIx64, from, id);
|
1514
|
+
gpr_free(from);
|
1515
|
+
return;
|
1516
|
+
}
|
1517
|
+
grpc_closure_list_sched(exec_ctx, &pq->lists[GRPC_CHTTP2_PCL_INFLIGHT]);
|
1518
|
+
if (!grpc_closure_list_empty(pq->lists[GRPC_CHTTP2_PCL_NEXT])) {
|
1519
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "continue_pings");
|
1520
|
+
}
|
1521
|
+
}
|
1522
|
+
|
1523
|
+
static void send_goaway(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1524
|
+
grpc_error *error) {
|
1525
|
+
t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED;
|
1526
|
+
grpc_http2_error_code http_error;
|
1527
|
+
grpc_slice slice;
|
1528
|
+
grpc_error_get_status(error, gpr_inf_future(GPR_CLOCK_MONOTONIC), NULL,
|
1529
|
+
&slice, &http_error);
|
1530
|
+
grpc_chttp2_goaway_append(t->last_new_stream_id, (uint32_t)http_error,
|
1531
|
+
grpc_slice_ref_internal(slice), &t->qbuf);
|
1532
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "goaway_sent");
|
1533
|
+
GRPC_ERROR_UNREF(error);
|
1534
|
+
}
|
1535
|
+
|
1536
|
+
void grpc_chttp2_add_ping_strike(grpc_exec_ctx *exec_ctx,
|
1537
|
+
grpc_chttp2_transport *t) {
|
1538
|
+
gpr_log(GPR_DEBUG, "PING strike");
|
1539
|
+
if (++t->ping_recv_state.ping_strikes > t->ping_policy.max_ping_strikes &&
|
1540
|
+
t->ping_policy.max_ping_strikes != 0) {
|
1541
|
+
send_goaway(exec_ctx, t,
|
1542
|
+
grpc_error_set_int(
|
1543
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("too_many_pings"),
|
1544
|
+
GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
|
1545
|
+
/*The transport will be closed after the write is done */
|
1546
|
+
close_transport_locked(
|
1547
|
+
exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many pings"));
|
1548
|
+
}
|
1549
|
+
}
|
1550
|
+
|
1551
|
+
static void perform_transport_op_locked(grpc_exec_ctx *exec_ctx,
|
1552
|
+
void *stream_op,
|
1553
|
+
grpc_error *error_ignored) {
|
1554
|
+
grpc_transport_op *op = stream_op;
|
1555
|
+
grpc_chttp2_transport *t = op->handler_private.extra_arg;
|
1556
|
+
grpc_error *close_transport = op->disconnect_with_error;
|
1557
|
+
|
1558
|
+
if (op->on_connectivity_state_change != NULL) {
|
1559
|
+
grpc_connectivity_state_notify_on_state_change(
|
1560
|
+
exec_ctx, &t->channel_callback.state_tracker, op->connectivity_state,
|
1561
|
+
op->on_connectivity_state_change);
|
1562
|
+
}
|
1563
|
+
|
1564
|
+
if (op->goaway_error) {
|
1565
|
+
send_goaway(exec_ctx, t, op->goaway_error);
|
1566
|
+
}
|
1567
|
+
|
1568
|
+
if (op->set_accept_stream) {
|
1569
|
+
t->channel_callback.accept_stream = op->set_accept_stream_fn;
|
1570
|
+
t->channel_callback.accept_stream_user_data =
|
1571
|
+
op->set_accept_stream_user_data;
|
1572
|
+
}
|
1573
|
+
|
1574
|
+
if (op->bind_pollset) {
|
1575
|
+
grpc_endpoint_add_to_pollset(exec_ctx, t->ep, op->bind_pollset);
|
1576
|
+
}
|
1577
|
+
|
1578
|
+
if (op->bind_pollset_set) {
|
1579
|
+
grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, op->bind_pollset_set);
|
1580
|
+
}
|
1581
|
+
|
1582
|
+
if (op->send_ping) {
|
1583
|
+
send_ping_locked(exec_ctx, t, GRPC_CHTTP2_PING_ON_NEXT_WRITE, NULL,
|
1584
|
+
op->send_ping);
|
1585
|
+
}
|
1586
|
+
|
1587
|
+
if (close_transport != GRPC_ERROR_NONE) {
|
1588
|
+
close_transport_locked(exec_ctx, t, close_transport);
|
1589
|
+
}
|
1590
|
+
|
1591
|
+
grpc_closure_run(exec_ctx, op->on_consumed, GRPC_ERROR_NONE);
|
1592
|
+
|
1593
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "transport_op");
|
1594
|
+
}
|
1595
|
+
|
1596
|
+
static void perform_transport_op(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
1597
|
+
grpc_transport_op *op) {
|
1598
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
1599
|
+
char *msg = grpc_transport_op_string(op);
|
1600
|
+
gpr_free(msg);
|
1601
|
+
op->handler_private.extra_arg = gt;
|
1602
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "transport_op");
|
1603
|
+
grpc_closure_sched(
|
1604
|
+
exec_ctx, grpc_closure_init(&op->handler_private.closure,
|
1605
|
+
perform_transport_op_locked, op,
|
1606
|
+
grpc_combiner_scheduler(t->combiner, false)),
|
1607
|
+
GRPC_ERROR_NONE);
|
1608
|
+
}
|
1609
|
+
|
1610
|
+
/*******************************************************************************
|
1611
|
+
* INPUT PROCESSING - GENERAL
|
1612
|
+
*/
|
1613
|
+
|
1614
|
+
void grpc_chttp2_maybe_complete_recv_initial_metadata(grpc_exec_ctx *exec_ctx,
|
1615
|
+
grpc_chttp2_transport *t,
|
1616
|
+
grpc_chttp2_stream *s) {
|
1617
|
+
grpc_byte_stream *bs;
|
1618
|
+
if (s->recv_initial_metadata_ready != NULL &&
|
1619
|
+
s->published_metadata[0] != GRPC_METADATA_NOT_PUBLISHED) {
|
1620
|
+
if (s->seen_error) {
|
1621
|
+
while ((bs = grpc_chttp2_incoming_frame_queue_pop(&s->incoming_frames)) !=
|
1622
|
+
NULL) {
|
1623
|
+
incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE);
|
1624
|
+
}
|
1625
|
+
}
|
1626
|
+
grpc_chttp2_incoming_metadata_buffer_publish(
|
1627
|
+
exec_ctx, &s->metadata_buffer[0], s->recv_initial_metadata);
|
1628
|
+
null_then_run_closure(exec_ctx, &s->recv_initial_metadata_ready,
|
1629
|
+
GRPC_ERROR_NONE);
|
1630
|
+
}
|
1631
|
+
}
|
1632
|
+
|
1633
|
+
void grpc_chttp2_maybe_complete_recv_message(grpc_exec_ctx *exec_ctx,
|
1634
|
+
grpc_chttp2_transport *t,
|
1635
|
+
grpc_chttp2_stream *s) {
|
1636
|
+
grpc_byte_stream *bs;
|
1637
|
+
if (s->recv_message_ready != NULL) {
|
1638
|
+
while (s->final_metadata_requested && s->seen_error &&
|
1639
|
+
(bs = grpc_chttp2_incoming_frame_queue_pop(&s->incoming_frames)) !=
|
1640
|
+
NULL) {
|
1641
|
+
incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE);
|
1642
|
+
}
|
1643
|
+
if (s->incoming_frames.head != NULL) {
|
1644
|
+
*s->recv_message =
|
1645
|
+
grpc_chttp2_incoming_frame_queue_pop(&s->incoming_frames);
|
1646
|
+
GPR_ASSERT(*s->recv_message != NULL);
|
1647
|
+
null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE);
|
1648
|
+
} else if (s->published_metadata[1] != GRPC_METADATA_NOT_PUBLISHED) {
|
1649
|
+
*s->recv_message = NULL;
|
1650
|
+
null_then_run_closure(exec_ctx, &s->recv_message_ready, GRPC_ERROR_NONE);
|
1651
|
+
}
|
1652
|
+
}
|
1653
|
+
}
|
1654
|
+
|
1655
|
+
void grpc_chttp2_maybe_complete_recv_trailing_metadata(grpc_exec_ctx *exec_ctx,
|
1656
|
+
grpc_chttp2_transport *t,
|
1657
|
+
grpc_chttp2_stream *s) {
|
1658
|
+
grpc_byte_stream *bs;
|
1659
|
+
grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
|
1660
|
+
if (s->recv_trailing_metadata_finished != NULL && s->read_closed &&
|
1661
|
+
s->write_closed) {
|
1662
|
+
if (s->seen_error) {
|
1663
|
+
while ((bs = grpc_chttp2_incoming_frame_queue_pop(&s->incoming_frames)) !=
|
1664
|
+
NULL) {
|
1665
|
+
incoming_byte_stream_destroy_locked(exec_ctx, bs, GRPC_ERROR_NONE);
|
1666
|
+
}
|
1667
|
+
}
|
1668
|
+
if (s->all_incoming_byte_streams_finished &&
|
1669
|
+
s->recv_trailing_metadata_finished != NULL) {
|
1670
|
+
grpc_chttp2_incoming_metadata_buffer_publish(
|
1671
|
+
exec_ctx, &s->metadata_buffer[1], s->recv_trailing_metadata);
|
1672
|
+
grpc_chttp2_complete_closure_step(
|
1673
|
+
exec_ctx, t, s, &s->recv_trailing_metadata_finished, GRPC_ERROR_NONE,
|
1674
|
+
"recv_trailing_metadata_finished");
|
1675
|
+
}
|
1676
|
+
}
|
1677
|
+
}
|
1678
|
+
|
1679
|
+
static void decrement_active_streams_locked(grpc_exec_ctx *exec_ctx,
|
1680
|
+
grpc_chttp2_transport *t,
|
1681
|
+
grpc_chttp2_stream *s) {
|
1682
|
+
if ((s->all_incoming_byte_streams_finished = gpr_unref(&s->active_streams))) {
|
1683
|
+
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
|
1684
|
+
}
|
1685
|
+
}
|
1686
|
+
|
1687
|
+
static void remove_stream(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1688
|
+
uint32_t id, grpc_error *error) {
|
1689
|
+
grpc_chttp2_stream *s = grpc_chttp2_stream_map_delete(&t->stream_map, id);
|
1690
|
+
GPR_ASSERT(s);
|
1691
|
+
if (t->incoming_stream == s) {
|
1692
|
+
t->incoming_stream = NULL;
|
1693
|
+
grpc_chttp2_parsing_become_skip_parser(exec_ctx, t);
|
1694
|
+
}
|
1695
|
+
if (s->data_parser.parsing_frame != NULL) {
|
1696
|
+
grpc_chttp2_incoming_byte_stream_finished(
|
1697
|
+
exec_ctx, s->data_parser.parsing_frame, GRPC_ERROR_REF(error));
|
1698
|
+
s->data_parser.parsing_frame = NULL;
|
1699
|
+
}
|
1700
|
+
|
1701
|
+
if (grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
|
1702
|
+
post_benign_reclaimer(exec_ctx, t);
|
1703
|
+
if (t->sent_goaway_state == GRPC_CHTTP2_GOAWAY_SENT) {
|
1704
|
+
close_transport_locked(
|
1705
|
+
exec_ctx, t,
|
1706
|
+
GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
|
1707
|
+
"Last stream closed after sending GOAWAY", &error, 1));
|
1708
|
+
}
|
1709
|
+
}
|
1710
|
+
if (grpc_chttp2_list_remove_writable_stream(t, s)) {
|
1711
|
+
GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2_writing:remove_stream");
|
1712
|
+
}
|
1713
|
+
|
1714
|
+
GRPC_ERROR_UNREF(error);
|
1715
|
+
|
1716
|
+
maybe_start_some_streams(exec_ctx, t);
|
1717
|
+
}
|
1718
|
+
|
1719
|
+
void grpc_chttp2_cancel_stream(grpc_exec_ctx *exec_ctx,
|
1720
|
+
grpc_chttp2_transport *t, grpc_chttp2_stream *s,
|
1721
|
+
grpc_error *due_to_error) {
|
1722
|
+
if (!t->is_client && !s->sent_trailing_metadata &&
|
1723
|
+
grpc_error_has_clear_grpc_status(due_to_error)) {
|
1724
|
+
close_from_api(exec_ctx, t, s, due_to_error);
|
1725
|
+
return;
|
1726
|
+
}
|
1727
|
+
|
1728
|
+
if (!s->read_closed || !s->write_closed) {
|
1729
|
+
if (s->id != 0) {
|
1730
|
+
grpc_http2_error_code http_error;
|
1731
|
+
grpc_error_get_status(due_to_error, s->deadline, NULL, NULL, &http_error);
|
1732
|
+
grpc_slice_buffer_add(
|
1733
|
+
&t->qbuf, grpc_chttp2_rst_stream_create(s->id, (uint32_t)http_error,
|
1734
|
+
&s->stats.outgoing));
|
1735
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "rst_stream");
|
1736
|
+
}
|
1737
|
+
}
|
1738
|
+
if (due_to_error != GRPC_ERROR_NONE && !s->seen_error) {
|
1739
|
+
s->seen_error = true;
|
1740
|
+
}
|
1741
|
+
grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, due_to_error);
|
1742
|
+
}
|
1743
|
+
|
1744
|
+
void grpc_chttp2_fake_status(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1745
|
+
grpc_chttp2_stream *s, grpc_error *error) {
|
1746
|
+
grpc_status_code status;
|
1747
|
+
grpc_slice slice;
|
1748
|
+
grpc_error_get_status(error, s->deadline, &status, &slice, NULL);
|
1749
|
+
|
1750
|
+
if (status != GRPC_STATUS_OK) {
|
1751
|
+
s->seen_error = true;
|
1752
|
+
}
|
1753
|
+
/* stream_global->recv_trailing_metadata_finished gives us a
|
1754
|
+
last chance replacement: we've received trailing metadata,
|
1755
|
+
but something more important has become available to signal
|
1756
|
+
to the upper layers - drop what we've got, and then publish
|
1757
|
+
what we want - which is safe because we haven't told anyone
|
1758
|
+
about the metadata yet */
|
1759
|
+
if (s->published_metadata[1] == GRPC_METADATA_NOT_PUBLISHED ||
|
1760
|
+
s->recv_trailing_metadata_finished != NULL) {
|
1761
|
+
char status_string[GPR_LTOA_MIN_BUFSIZE];
|
1762
|
+
gpr_ltoa(status, status_string);
|
1763
|
+
GRPC_LOG_IF_ERROR("add_status",
|
1764
|
+
grpc_chttp2_incoming_metadata_buffer_replace_or_add(
|
1765
|
+
exec_ctx, &s->metadata_buffer[1],
|
1766
|
+
grpc_mdelem_from_slices(
|
1767
|
+
exec_ctx, GRPC_MDSTR_GRPC_STATUS,
|
1768
|
+
grpc_slice_from_copied_string(status_string))));
|
1769
|
+
if (!GRPC_SLICE_IS_EMPTY(slice)) {
|
1770
|
+
GRPC_LOG_IF_ERROR(
|
1771
|
+
"add_status_message",
|
1772
|
+
grpc_chttp2_incoming_metadata_buffer_replace_or_add(
|
1773
|
+
exec_ctx, &s->metadata_buffer[1],
|
1774
|
+
grpc_mdelem_from_slices(exec_ctx, GRPC_MDSTR_GRPC_MESSAGE,
|
1775
|
+
grpc_slice_ref_internal(slice))));
|
1776
|
+
}
|
1777
|
+
s->published_metadata[1] = GRPC_METADATA_SYNTHESIZED_FROM_FAKE;
|
1778
|
+
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
|
1779
|
+
}
|
1780
|
+
|
1781
|
+
GRPC_ERROR_UNREF(error);
|
1782
|
+
}
|
1783
|
+
|
1784
|
+
static void add_error(grpc_error *error, grpc_error **refs, size_t *nrefs) {
|
1785
|
+
if (error == GRPC_ERROR_NONE) return;
|
1786
|
+
for (size_t i = 0; i < *nrefs; i++) {
|
1787
|
+
if (error == refs[i]) {
|
1788
|
+
return;
|
1789
|
+
}
|
1790
|
+
}
|
1791
|
+
refs[*nrefs] = error;
|
1792
|
+
++*nrefs;
|
1793
|
+
}
|
1794
|
+
|
1795
|
+
static grpc_error *removal_error(grpc_error *extra_error, grpc_chttp2_stream *s,
|
1796
|
+
const char *master_error_msg) {
|
1797
|
+
grpc_error *refs[3];
|
1798
|
+
size_t nrefs = 0;
|
1799
|
+
add_error(s->read_closed_error, refs, &nrefs);
|
1800
|
+
add_error(s->write_closed_error, refs, &nrefs);
|
1801
|
+
add_error(extra_error, refs, &nrefs);
|
1802
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
1803
|
+
if (nrefs > 0) {
|
1804
|
+
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(master_error_msg,
|
1805
|
+
refs, nrefs);
|
1806
|
+
}
|
1807
|
+
GRPC_ERROR_UNREF(extra_error);
|
1808
|
+
return error;
|
1809
|
+
}
|
1810
|
+
|
1811
|
+
void grpc_chttp2_fail_pending_writes(grpc_exec_ctx *exec_ctx,
|
1812
|
+
grpc_chttp2_transport *t,
|
1813
|
+
grpc_chttp2_stream *s, grpc_error *error) {
|
1814
|
+
error =
|
1815
|
+
removal_error(error, s, "Pending writes failed due to stream closure");
|
1816
|
+
s->send_initial_metadata = NULL;
|
1817
|
+
grpc_chttp2_complete_closure_step(
|
1818
|
+
exec_ctx, t, s, &s->send_initial_metadata_finished, GRPC_ERROR_REF(error),
|
1819
|
+
"send_initial_metadata_finished");
|
1820
|
+
|
1821
|
+
s->send_trailing_metadata = NULL;
|
1822
|
+
grpc_chttp2_complete_closure_step(
|
1823
|
+
exec_ctx, t, s, &s->send_trailing_metadata_finished,
|
1824
|
+
GRPC_ERROR_REF(error), "send_trailing_metadata_finished");
|
1825
|
+
|
1826
|
+
s->fetching_send_message = NULL;
|
1827
|
+
grpc_chttp2_complete_closure_step(
|
1828
|
+
exec_ctx, t, s, &s->fetching_send_message_finished, GRPC_ERROR_REF(error),
|
1829
|
+
"fetching_send_message_finished");
|
1830
|
+
while (s->on_write_finished_cbs) {
|
1831
|
+
grpc_chttp2_write_cb *cb = s->on_write_finished_cbs;
|
1832
|
+
s->on_write_finished_cbs = cb->next;
|
1833
|
+
grpc_chttp2_complete_closure_step(exec_ctx, t, s, &cb->closure,
|
1834
|
+
GRPC_ERROR_REF(error),
|
1835
|
+
"on_write_finished_cb");
|
1836
|
+
cb->next = t->write_cb_pool;
|
1837
|
+
t->write_cb_pool = cb;
|
1838
|
+
}
|
1839
|
+
GRPC_ERROR_UNREF(error);
|
1840
|
+
}
|
1841
|
+
|
1842
|
+
void grpc_chttp2_mark_stream_closed(grpc_exec_ctx *exec_ctx,
|
1843
|
+
grpc_chttp2_transport *t,
|
1844
|
+
grpc_chttp2_stream *s, int close_reads,
|
1845
|
+
int close_writes, grpc_error *error) {
|
1846
|
+
if (s->read_closed && s->write_closed) {
|
1847
|
+
/* already closed */
|
1848
|
+
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
|
1849
|
+
GRPC_ERROR_UNREF(error);
|
1850
|
+
return;
|
1851
|
+
}
|
1852
|
+
bool closed_read = false;
|
1853
|
+
bool became_closed = false;
|
1854
|
+
if (close_reads && !s->read_closed) {
|
1855
|
+
s->read_closed_error = GRPC_ERROR_REF(error);
|
1856
|
+
s->read_closed = true;
|
1857
|
+
closed_read = true;
|
1858
|
+
}
|
1859
|
+
if (close_writes && !s->write_closed) {
|
1860
|
+
s->write_closed_error = GRPC_ERROR_REF(error);
|
1861
|
+
s->write_closed = true;
|
1862
|
+
grpc_chttp2_fail_pending_writes(exec_ctx, t, s, GRPC_ERROR_REF(error));
|
1863
|
+
}
|
1864
|
+
if (s->read_closed && s->write_closed) {
|
1865
|
+
became_closed = true;
|
1866
|
+
grpc_error *overall_error =
|
1867
|
+
removal_error(GRPC_ERROR_REF(error), s, "Stream removed");
|
1868
|
+
if (s->id != 0) {
|
1869
|
+
remove_stream(exec_ctx, t, s->id, GRPC_ERROR_REF(overall_error));
|
1870
|
+
} else {
|
1871
|
+
/* Purge streams waiting on concurrency still waiting for id assignment */
|
1872
|
+
grpc_chttp2_list_remove_waiting_for_concurrency(t, s);
|
1873
|
+
}
|
1874
|
+
if (overall_error != GRPC_ERROR_NONE) {
|
1875
|
+
grpc_chttp2_fake_status(exec_ctx, t, s, overall_error);
|
1876
|
+
}
|
1877
|
+
}
|
1878
|
+
if (closed_read) {
|
1879
|
+
for (int i = 0; i < 2; i++) {
|
1880
|
+
if (s->published_metadata[i] == GRPC_METADATA_NOT_PUBLISHED) {
|
1881
|
+
s->published_metadata[i] = GPRC_METADATA_PUBLISHED_AT_CLOSE;
|
1882
|
+
}
|
1883
|
+
}
|
1884
|
+
decrement_active_streams_locked(exec_ctx, t, s);
|
1885
|
+
grpc_chttp2_maybe_complete_recv_initial_metadata(exec_ctx, t, s);
|
1886
|
+
grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
|
1887
|
+
}
|
1888
|
+
if (became_closed) {
|
1889
|
+
grpc_chttp2_maybe_complete_recv_trailing_metadata(exec_ctx, t, s);
|
1890
|
+
GRPC_CHTTP2_STREAM_UNREF(exec_ctx, s, "chttp2");
|
1891
|
+
}
|
1892
|
+
GRPC_ERROR_UNREF(error);
|
1893
|
+
}
|
1894
|
+
|
1895
|
+
static void close_from_api(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
1896
|
+
grpc_chttp2_stream *s, grpc_error *error) {
|
1897
|
+
grpc_slice hdr;
|
1898
|
+
grpc_slice status_hdr;
|
1899
|
+
grpc_slice http_status_hdr;
|
1900
|
+
grpc_slice content_type_hdr;
|
1901
|
+
grpc_slice message_pfx;
|
1902
|
+
uint8_t *p;
|
1903
|
+
uint32_t len = 0;
|
1904
|
+
grpc_status_code grpc_status;
|
1905
|
+
grpc_slice slice;
|
1906
|
+
grpc_error_get_status(error, s->deadline, &grpc_status, &slice, NULL);
|
1907
|
+
|
1908
|
+
GPR_ASSERT(grpc_status >= 0 && (int)grpc_status < 100);
|
1909
|
+
|
1910
|
+
/* Hand roll a header block.
|
1911
|
+
This is unnecessarily ugly - at some point we should find a more
|
1912
|
+
elegant solution.
|
1913
|
+
It's complicated by the fact that our send machinery would be dead by
|
1914
|
+
the time we got around to sending this, so instead we ignore HPACK
|
1915
|
+
compression and just write the uncompressed bytes onto the wire. */
|
1916
|
+
if (!s->sent_initial_metadata) {
|
1917
|
+
http_status_hdr = grpc_slice_malloc(13);
|
1918
|
+
p = GRPC_SLICE_START_PTR(http_status_hdr);
|
1919
|
+
*p++ = 0x00;
|
1920
|
+
*p++ = 7;
|
1921
|
+
*p++ = ':';
|
1922
|
+
*p++ = 's';
|
1923
|
+
*p++ = 't';
|
1924
|
+
*p++ = 'a';
|
1925
|
+
*p++ = 't';
|
1926
|
+
*p++ = 'u';
|
1927
|
+
*p++ = 's';
|
1928
|
+
*p++ = 3;
|
1929
|
+
*p++ = '2';
|
1930
|
+
*p++ = '0';
|
1931
|
+
*p++ = '0';
|
1932
|
+
GPR_ASSERT(p == GRPC_SLICE_END_PTR(http_status_hdr));
|
1933
|
+
len += (uint32_t)GRPC_SLICE_LENGTH(http_status_hdr);
|
1934
|
+
|
1935
|
+
content_type_hdr = grpc_slice_malloc(31);
|
1936
|
+
p = GRPC_SLICE_START_PTR(content_type_hdr);
|
1937
|
+
*p++ = 0x00;
|
1938
|
+
*p++ = 12;
|
1939
|
+
*p++ = 'c';
|
1940
|
+
*p++ = 'o';
|
1941
|
+
*p++ = 'n';
|
1942
|
+
*p++ = 't';
|
1943
|
+
*p++ = 'e';
|
1944
|
+
*p++ = 'n';
|
1945
|
+
*p++ = 't';
|
1946
|
+
*p++ = '-';
|
1947
|
+
*p++ = 't';
|
1948
|
+
*p++ = 'y';
|
1949
|
+
*p++ = 'p';
|
1950
|
+
*p++ = 'e';
|
1951
|
+
*p++ = 16;
|
1952
|
+
*p++ = 'a';
|
1953
|
+
*p++ = 'p';
|
1954
|
+
*p++ = 'p';
|
1955
|
+
*p++ = 'l';
|
1956
|
+
*p++ = 'i';
|
1957
|
+
*p++ = 'c';
|
1958
|
+
*p++ = 'a';
|
1959
|
+
*p++ = 't';
|
1960
|
+
*p++ = 'i';
|
1961
|
+
*p++ = 'o';
|
1962
|
+
*p++ = 'n';
|
1963
|
+
*p++ = '/';
|
1964
|
+
*p++ = 'g';
|
1965
|
+
*p++ = 'r';
|
1966
|
+
*p++ = 'p';
|
1967
|
+
*p++ = 'c';
|
1968
|
+
GPR_ASSERT(p == GRPC_SLICE_END_PTR(content_type_hdr));
|
1969
|
+
len += (uint32_t)GRPC_SLICE_LENGTH(content_type_hdr);
|
1970
|
+
}
|
1971
|
+
|
1972
|
+
status_hdr = grpc_slice_malloc(15 + (grpc_status >= 10));
|
1973
|
+
p = GRPC_SLICE_START_PTR(status_hdr);
|
1974
|
+
*p++ = 0x00; /* literal header, not indexed */
|
1975
|
+
*p++ = 11; /* len(grpc-status) */
|
1976
|
+
*p++ = 'g';
|
1977
|
+
*p++ = 'r';
|
1978
|
+
*p++ = 'p';
|
1979
|
+
*p++ = 'c';
|
1980
|
+
*p++ = '-';
|
1981
|
+
*p++ = 's';
|
1982
|
+
*p++ = 't';
|
1983
|
+
*p++ = 'a';
|
1984
|
+
*p++ = 't';
|
1985
|
+
*p++ = 'u';
|
1986
|
+
*p++ = 's';
|
1987
|
+
if (grpc_status < 10) {
|
1988
|
+
*p++ = 1;
|
1989
|
+
*p++ = (uint8_t)('0' + grpc_status);
|
1990
|
+
} else {
|
1991
|
+
*p++ = 2;
|
1992
|
+
*p++ = (uint8_t)('0' + (grpc_status / 10));
|
1993
|
+
*p++ = (uint8_t)('0' + (grpc_status % 10));
|
1994
|
+
}
|
1995
|
+
GPR_ASSERT(p == GRPC_SLICE_END_PTR(status_hdr));
|
1996
|
+
len += (uint32_t)GRPC_SLICE_LENGTH(status_hdr);
|
1997
|
+
|
1998
|
+
size_t msg_len = GRPC_SLICE_LENGTH(slice);
|
1999
|
+
GPR_ASSERT(msg_len <= UINT32_MAX);
|
2000
|
+
uint32_t msg_len_len = GRPC_CHTTP2_VARINT_LENGTH((uint32_t)msg_len, 1);
|
2001
|
+
message_pfx = grpc_slice_malloc(14 + msg_len_len);
|
2002
|
+
p = GRPC_SLICE_START_PTR(message_pfx);
|
2003
|
+
*p++ = 0x00; /* literal header, not indexed */
|
2004
|
+
*p++ = 12; /* len(grpc-message) */
|
2005
|
+
*p++ = 'g';
|
2006
|
+
*p++ = 'r';
|
2007
|
+
*p++ = 'p';
|
2008
|
+
*p++ = 'c';
|
2009
|
+
*p++ = '-';
|
2010
|
+
*p++ = 'm';
|
2011
|
+
*p++ = 'e';
|
2012
|
+
*p++ = 's';
|
2013
|
+
*p++ = 's';
|
2014
|
+
*p++ = 'a';
|
2015
|
+
*p++ = 'g';
|
2016
|
+
*p++ = 'e';
|
2017
|
+
GRPC_CHTTP2_WRITE_VARINT((uint32_t)msg_len, 1, 0, p, (uint32_t)msg_len_len);
|
2018
|
+
p += msg_len_len;
|
2019
|
+
GPR_ASSERT(p == GRPC_SLICE_END_PTR(message_pfx));
|
2020
|
+
len += (uint32_t)GRPC_SLICE_LENGTH(message_pfx);
|
2021
|
+
len += (uint32_t)msg_len;
|
2022
|
+
|
2023
|
+
hdr = grpc_slice_malloc(9);
|
2024
|
+
p = GRPC_SLICE_START_PTR(hdr);
|
2025
|
+
*p++ = (uint8_t)(len >> 16);
|
2026
|
+
*p++ = (uint8_t)(len >> 8);
|
2027
|
+
*p++ = (uint8_t)(len);
|
2028
|
+
*p++ = GRPC_CHTTP2_FRAME_HEADER;
|
2029
|
+
*p++ = GRPC_CHTTP2_DATA_FLAG_END_STREAM | GRPC_CHTTP2_DATA_FLAG_END_HEADERS;
|
2030
|
+
*p++ = (uint8_t)(s->id >> 24);
|
2031
|
+
*p++ = (uint8_t)(s->id >> 16);
|
2032
|
+
*p++ = (uint8_t)(s->id >> 8);
|
2033
|
+
*p++ = (uint8_t)(s->id);
|
2034
|
+
GPR_ASSERT(p == GRPC_SLICE_END_PTR(hdr));
|
2035
|
+
|
2036
|
+
grpc_slice_buffer_add(&t->qbuf, hdr);
|
2037
|
+
if (!s->sent_initial_metadata) {
|
2038
|
+
grpc_slice_buffer_add(&t->qbuf, http_status_hdr);
|
2039
|
+
grpc_slice_buffer_add(&t->qbuf, content_type_hdr);
|
2040
|
+
}
|
2041
|
+
grpc_slice_buffer_add(&t->qbuf, status_hdr);
|
2042
|
+
grpc_slice_buffer_add(&t->qbuf, message_pfx);
|
2043
|
+
grpc_slice_buffer_add(&t->qbuf, grpc_slice_ref_internal(slice));
|
2044
|
+
grpc_slice_buffer_add(
|
2045
|
+
&t->qbuf, grpc_chttp2_rst_stream_create(s->id, GRPC_HTTP2_NO_ERROR,
|
2046
|
+
&s->stats.outgoing));
|
2047
|
+
|
2048
|
+
grpc_chttp2_mark_stream_closed(exec_ctx, t, s, 1, 1, error);
|
2049
|
+
grpc_chttp2_initiate_write(exec_ctx, t, false, "close_from_api");
|
2050
|
+
}
|
2051
|
+
|
2052
|
+
typedef struct {
|
2053
|
+
grpc_exec_ctx *exec_ctx;
|
2054
|
+
grpc_error *error;
|
2055
|
+
grpc_chttp2_transport *t;
|
2056
|
+
} cancel_stream_cb_args;
|
2057
|
+
|
2058
|
+
static void cancel_stream_cb(void *user_data, uint32_t key, void *stream) {
|
2059
|
+
cancel_stream_cb_args *args = user_data;
|
2060
|
+
grpc_chttp2_stream *s = stream;
|
2061
|
+
grpc_chttp2_cancel_stream(args->exec_ctx, args->t, s,
|
2062
|
+
GRPC_ERROR_REF(args->error));
|
2063
|
+
}
|
2064
|
+
|
2065
|
+
static void end_all_the_calls(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
2066
|
+
grpc_error *error) {
|
2067
|
+
cancel_stream_cb_args args = {exec_ctx, error, t};
|
2068
|
+
grpc_chttp2_stream_map_for_each(&t->stream_map, cancel_stream_cb, &args);
|
2069
|
+
GRPC_ERROR_UNREF(error);
|
2070
|
+
}
|
2071
|
+
|
2072
|
+
/*******************************************************************************
|
2073
|
+
* INPUT PROCESSING - PARSING
|
2074
|
+
*/
|
2075
|
+
|
2076
|
+
static void update_bdp(grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t,
|
2077
|
+
double bdp_dbl) {
|
2078
|
+
uint32_t bdp;
|
2079
|
+
if (bdp_dbl <= 0) {
|
2080
|
+
bdp = 0;
|
2081
|
+
} else if (bdp_dbl > UINT32_MAX) {
|
2082
|
+
bdp = UINT32_MAX;
|
2083
|
+
} else {
|
2084
|
+
bdp = (uint32_t)(bdp_dbl);
|
2085
|
+
}
|
2086
|
+
int64_t delta =
|
2087
|
+
(int64_t)bdp -
|
2088
|
+
(int64_t)t->settings[GRPC_LOCAL_SETTINGS]
|
2089
|
+
[GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
|
2090
|
+
if (delta == 0 || (bdp != 0 && delta > -1024 && delta < 1024)) {
|
2091
|
+
return;
|
2092
|
+
}
|
2093
|
+
if (grpc_bdp_estimator_trace) {
|
2094
|
+
gpr_log(GPR_DEBUG, "%s: update initial window size to %d", t->peer_string,
|
2095
|
+
(int)bdp);
|
2096
|
+
}
|
2097
|
+
push_setting(exec_ctx, t, GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE, bdp);
|
2098
|
+
}
|
2099
|
+
|
2100
|
+
static grpc_error *try_http_parsing(grpc_exec_ctx *exec_ctx,
|
2101
|
+
grpc_chttp2_transport *t) {
|
2102
|
+
grpc_http_parser parser;
|
2103
|
+
size_t i = 0;
|
2104
|
+
grpc_error *error = GRPC_ERROR_NONE;
|
2105
|
+
grpc_http_response response;
|
2106
|
+
memset(&response, 0, sizeof(response));
|
2107
|
+
|
2108
|
+
grpc_http_parser_init(&parser, GRPC_HTTP_RESPONSE, &response);
|
2109
|
+
|
2110
|
+
grpc_error *parse_error = GRPC_ERROR_NONE;
|
2111
|
+
for (; i < t->read_buffer.count && parse_error == GRPC_ERROR_NONE; i++) {
|
2112
|
+
parse_error =
|
2113
|
+
grpc_http_parser_parse(&parser, t->read_buffer.slices[i], NULL);
|
2114
|
+
}
|
2115
|
+
if (parse_error == GRPC_ERROR_NONE &&
|
2116
|
+
(parse_error = grpc_http_parser_eof(&parser)) == GRPC_ERROR_NONE) {
|
2117
|
+
error = grpc_error_set_int(
|
2118
|
+
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
2119
|
+
"Trying to connect an http1.x server"),
|
2120
|
+
GRPC_ERROR_INT_HTTP_STATUS, response.status),
|
2121
|
+
GRPC_ERROR_INT_GRPC_STATUS, GRPC_STATUS_UNAVAILABLE);
|
2122
|
+
}
|
2123
|
+
GRPC_ERROR_UNREF(parse_error);
|
2124
|
+
|
2125
|
+
grpc_http_parser_destroy(&parser);
|
2126
|
+
grpc_http_response_destroy(&response);
|
2127
|
+
return error;
|
2128
|
+
}
|
2129
|
+
|
2130
|
+
static void read_action_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
2131
|
+
grpc_error *error) {
|
2132
|
+
GPR_TIMER_BEGIN("reading_action_locked", 0);
|
2133
|
+
|
2134
|
+
grpc_chttp2_transport *t = tp;
|
2135
|
+
bool need_bdp_ping = false;
|
2136
|
+
|
2137
|
+
GRPC_ERROR_REF(error);
|
2138
|
+
|
2139
|
+
grpc_error *err = error;
|
2140
|
+
if (err != GRPC_ERROR_NONE) {
|
2141
|
+
err = grpc_error_set_int(GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
|
2142
|
+
"Endpoint read failed", &err, 1),
|
2143
|
+
GRPC_ERROR_INT_OCCURRED_DURING_WRITE,
|
2144
|
+
t->write_state);
|
2145
|
+
}
|
2146
|
+
GPR_SWAP(grpc_error *, err, error);
|
2147
|
+
GRPC_ERROR_UNREF(err);
|
2148
|
+
if (!t->closed) {
|
2149
|
+
GPR_TIMER_BEGIN("reading_action.parse", 0);
|
2150
|
+
size_t i = 0;
|
2151
|
+
grpc_error *errors[3] = {GRPC_ERROR_REF(error), GRPC_ERROR_NONE,
|
2152
|
+
GRPC_ERROR_NONE};
|
2153
|
+
for (; i < t->read_buffer.count && errors[1] == GRPC_ERROR_NONE; i++) {
|
2154
|
+
if (grpc_bdp_estimator_add_incoming_bytes(
|
2155
|
+
&t->bdp_estimator,
|
2156
|
+
(int64_t)GRPC_SLICE_LENGTH(t->read_buffer.slices[i]))) {
|
2157
|
+
need_bdp_ping = true;
|
2158
|
+
}
|
2159
|
+
errors[1] =
|
2160
|
+
grpc_chttp2_perform_read(exec_ctx, t, t->read_buffer.slices[i]);
|
2161
|
+
}
|
2162
|
+
if (errors[1] != GRPC_ERROR_NONE) {
|
2163
|
+
errors[2] = try_http_parsing(exec_ctx, t);
|
2164
|
+
GRPC_ERROR_UNREF(error);
|
2165
|
+
error = GRPC_ERROR_CREATE_REFERENCING_FROM_STATIC_STRING(
|
2166
|
+
"Failed parsing HTTP/2", errors, GPR_ARRAY_SIZE(errors));
|
2167
|
+
}
|
2168
|
+
for (i = 0; i < GPR_ARRAY_SIZE(errors); i++) {
|
2169
|
+
GRPC_ERROR_UNREF(errors[i]);
|
2170
|
+
}
|
2171
|
+
GPR_TIMER_END("reading_action.parse", 0);
|
2172
|
+
|
2173
|
+
GPR_TIMER_BEGIN("post_parse_locked", 0);
|
2174
|
+
if (t->initial_window_update != 0) {
|
2175
|
+
if (t->initial_window_update > 0) {
|
2176
|
+
grpc_chttp2_stream *s;
|
2177
|
+
while (grpc_chttp2_list_pop_stalled_by_stream(t, &s)) {
|
2178
|
+
grpc_chttp2_become_writable(
|
2179
|
+
exec_ctx, t, s, GRPC_CHTTP2_STREAM_WRITE_INITIATE_UNCOVERED,
|
2180
|
+
"unstalled");
|
2181
|
+
}
|
2182
|
+
}
|
2183
|
+
t->initial_window_update = 0;
|
2184
|
+
}
|
2185
|
+
GPR_TIMER_END("post_parse_locked", 0);
|
2186
|
+
}
|
2187
|
+
|
2188
|
+
GPR_TIMER_BEGIN("post_reading_action_locked", 0);
|
2189
|
+
bool keep_reading = false;
|
2190
|
+
if (error == GRPC_ERROR_NONE && t->closed) {
|
2191
|
+
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Transport closed");
|
2192
|
+
}
|
2193
|
+
if (error != GRPC_ERROR_NONE) {
|
2194
|
+
close_transport_locked(exec_ctx, t, GRPC_ERROR_REF(error));
|
2195
|
+
t->endpoint_reading = 0;
|
2196
|
+
} else if (!t->closed) {
|
2197
|
+
keep_reading = true;
|
2198
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading");
|
2199
|
+
}
|
2200
|
+
grpc_slice_buffer_reset_and_unref_internal(exec_ctx, &t->read_buffer);
|
2201
|
+
|
2202
|
+
if (keep_reading) {
|
2203
|
+
grpc_endpoint_read(exec_ctx, t->ep, &t->read_buffer,
|
2204
|
+
&t->read_action_locked);
|
2205
|
+
|
2206
|
+
if (t->enable_bdp_probe) {
|
2207
|
+
if (need_bdp_ping) {
|
2208
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "bdp_ping");
|
2209
|
+
grpc_bdp_estimator_schedule_ping(&t->bdp_estimator);
|
2210
|
+
send_ping_locked(exec_ctx, t,
|
2211
|
+
GRPC_CHTTP2_PING_BEFORE_TRANSPORT_WINDOW_UPDATE,
|
2212
|
+
&t->start_bdp_ping_locked, &t->finish_bdp_ping_locked);
|
2213
|
+
}
|
2214
|
+
|
2215
|
+
int64_t estimate = -1;
|
2216
|
+
if (grpc_bdp_estimator_get_estimate(&t->bdp_estimator, &estimate)) {
|
2217
|
+
double target = 1 + log2((double)estimate);
|
2218
|
+
double memory_pressure = grpc_resource_quota_get_memory_pressure(
|
2219
|
+
grpc_resource_user_quota(grpc_endpoint_get_resource_user(t->ep)));
|
2220
|
+
if (memory_pressure > 0.8) {
|
2221
|
+
target *= 1 - GPR_MIN(1, (memory_pressure - 0.8) / 0.1);
|
2222
|
+
}
|
2223
|
+
double bdp_error =
|
2224
|
+
target - grpc_pid_controller_last(&t->pid_controller);
|
2225
|
+
gpr_timespec now = gpr_now(GPR_CLOCK_MONOTONIC);
|
2226
|
+
gpr_timespec dt_timespec = gpr_time_sub(now, t->last_pid_update);
|
2227
|
+
double dt = (double)dt_timespec.tv_sec + dt_timespec.tv_nsec * 1e-9;
|
2228
|
+
if (dt > 0.1) {
|
2229
|
+
dt = 0.1;
|
2230
|
+
}
|
2231
|
+
double log2_bdp_guess =
|
2232
|
+
grpc_pid_controller_update(&t->pid_controller, bdp_error, dt);
|
2233
|
+
update_bdp(exec_ctx, t, pow(2, log2_bdp_guess));
|
2234
|
+
t->last_pid_update = now;
|
2235
|
+
}
|
2236
|
+
}
|
2237
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keep_reading");
|
2238
|
+
} else {
|
2239
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "reading_action");
|
2240
|
+
}
|
2241
|
+
|
2242
|
+
GPR_TIMER_END("post_reading_action_locked", 0);
|
2243
|
+
|
2244
|
+
GRPC_ERROR_UNREF(error);
|
2245
|
+
|
2246
|
+
GPR_TIMER_END("reading_action_locked", 0);
|
2247
|
+
}
|
2248
|
+
|
2249
|
+
static void start_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
2250
|
+
grpc_error *error) {
|
2251
|
+
grpc_chttp2_transport *t = tp;
|
2252
|
+
if (grpc_http_trace) {
|
2253
|
+
gpr_log(GPR_DEBUG, "%s: Start BDP ping", t->peer_string);
|
2254
|
+
}
|
2255
|
+
/* Reset the keepalive ping timer */
|
2256
|
+
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
|
2257
|
+
grpc_timer_cancel(exec_ctx, &t->keepalive_ping_timer);
|
2258
|
+
}
|
2259
|
+
grpc_bdp_estimator_start_ping(&t->bdp_estimator);
|
2260
|
+
}
|
2261
|
+
|
2262
|
+
static void finish_bdp_ping_locked(grpc_exec_ctx *exec_ctx, void *tp,
|
2263
|
+
grpc_error *error) {
|
2264
|
+
grpc_chttp2_transport *t = tp;
|
2265
|
+
if (grpc_http_trace) {
|
2266
|
+
gpr_log(GPR_DEBUG, "%s: Complete BDP ping", t->peer_string);
|
2267
|
+
}
|
2268
|
+
grpc_bdp_estimator_complete_ping(&t->bdp_estimator);
|
2269
|
+
|
2270
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "bdp_ping");
|
2271
|
+
}
|
2272
|
+
|
2273
|
+
void grpc_chttp2_config_default_keepalive_args(grpc_channel_args *args,
|
2274
|
+
bool is_client) {
|
2275
|
+
size_t i;
|
2276
|
+
if (args) {
|
2277
|
+
for (i = 0; i < args->num_args; i++) {
|
2278
|
+
if (0 == strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_TIME_MS)) {
|
2279
|
+
const int value = grpc_channel_arg_get_integer(
|
2280
|
+
&args->args[i],
|
2281
|
+
(grpc_integer_options){g_default_client_keepalive_time_ms, 1,
|
2282
|
+
INT_MAX});
|
2283
|
+
if (is_client) {
|
2284
|
+
g_default_client_keepalive_time_ms = value;
|
2285
|
+
} else {
|
2286
|
+
g_default_server_keepalive_time_ms = value;
|
2287
|
+
}
|
2288
|
+
} else if (0 ==
|
2289
|
+
strcmp(args->args[i].key, GRPC_ARG_KEEPALIVE_TIMEOUT_MS)) {
|
2290
|
+
const int value = grpc_channel_arg_get_integer(
|
2291
|
+
&args->args[i],
|
2292
|
+
(grpc_integer_options){g_default_client_keepalive_timeout_ms, 0,
|
2293
|
+
INT_MAX});
|
2294
|
+
if (is_client) {
|
2295
|
+
g_default_client_keepalive_timeout_ms = value;
|
2296
|
+
} else {
|
2297
|
+
g_default_server_keepalive_timeout_ms = value;
|
2298
|
+
}
|
2299
|
+
} else if (0 == strcmp(args->args[i].key,
|
2300
|
+
GRPC_ARG_KEEPALIVE_PERMIT_WITHOUT_CALLS)) {
|
2301
|
+
g_default_keepalive_permit_without_calls =
|
2302
|
+
(uint32_t)grpc_channel_arg_get_integer(
|
2303
|
+
&args->args[i],
|
2304
|
+
(grpc_integer_options){g_default_keepalive_permit_without_calls,
|
2305
|
+
0, 1});
|
2306
|
+
}
|
2307
|
+
}
|
2308
|
+
}
|
2309
|
+
}
|
2310
|
+
|
2311
|
+
static void init_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2312
|
+
grpc_error *error) {
|
2313
|
+
grpc_chttp2_transport *t = arg;
|
2314
|
+
GPR_ASSERT(t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING);
|
2315
|
+
if (error == GRPC_ERROR_NONE && !(t->destroying || t->closed)) {
|
2316
|
+
if (t->keepalive_permit_without_calls ||
|
2317
|
+
grpc_chttp2_stream_map_size(&t->stream_map) > 0) {
|
2318
|
+
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_PINGING;
|
2319
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive ping end");
|
2320
|
+
send_ping_locked(exec_ctx, t, GRPC_CHTTP2_PING_ON_NEXT_WRITE,
|
2321
|
+
&t->start_keepalive_ping_locked,
|
2322
|
+
&t->finish_keepalive_ping_locked);
|
2323
|
+
} else {
|
2324
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
|
2325
|
+
grpc_timer_init(
|
2326
|
+
exec_ctx, &t->keepalive_ping_timer,
|
2327
|
+
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
|
2328
|
+
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
|
2329
|
+
}
|
2330
|
+
} else if (error == GRPC_ERROR_CANCELLED && !(t->destroying || t->closed)) {
|
2331
|
+
/* The keepalive ping timer may be cancelled by bdp */
|
2332
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
|
2333
|
+
grpc_timer_init(
|
2334
|
+
exec_ctx, &t->keepalive_ping_timer,
|
2335
|
+
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
|
2336
|
+
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
|
2337
|
+
}
|
2338
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "init keepalive ping");
|
2339
|
+
}
|
2340
|
+
|
2341
|
+
static void start_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2342
|
+
grpc_error *error) {
|
2343
|
+
grpc_chttp2_transport *t = arg;
|
2344
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
|
2345
|
+
grpc_timer_init(
|
2346
|
+
exec_ctx, &t->keepalive_watchdog_timer,
|
2347
|
+
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_timeout),
|
2348
|
+
&t->keepalive_watchdog_fired_locked, gpr_now(GPR_CLOCK_MONOTONIC));
|
2349
|
+
}
|
2350
|
+
|
2351
|
+
static void finish_keepalive_ping_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2352
|
+
grpc_error *error) {
|
2353
|
+
grpc_chttp2_transport *t = arg;
|
2354
|
+
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
|
2355
|
+
if (error == GRPC_ERROR_NONE) {
|
2356
|
+
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
|
2357
|
+
grpc_timer_cancel(exec_ctx, &t->keepalive_watchdog_timer);
|
2358
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
|
2359
|
+
grpc_timer_init(
|
2360
|
+
exec_ctx, &t->keepalive_ping_timer,
|
2361
|
+
gpr_time_add(gpr_now(GPR_CLOCK_MONOTONIC), t->keepalive_time),
|
2362
|
+
&t->init_keepalive_ping_locked, gpr_now(GPR_CLOCK_MONOTONIC));
|
2363
|
+
}
|
2364
|
+
}
|
2365
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive ping end");
|
2366
|
+
}
|
2367
|
+
|
2368
|
+
static void keepalive_watchdog_fired_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2369
|
+
grpc_error *error) {
|
2370
|
+
grpc_chttp2_transport *t = arg;
|
2371
|
+
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
|
2372
|
+
if (error == GRPC_ERROR_NONE) {
|
2373
|
+
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
|
2374
|
+
close_transport_locked(exec_ctx, t, GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
2375
|
+
"keepalive watchdog timeout"));
|
2376
|
+
}
|
2377
|
+
} else {
|
2378
|
+
/* The watchdog timer should have been cancelled by
|
2379
|
+
* finish_keepalive_ping_locked. */
|
2380
|
+
if (error != GRPC_ERROR_CANCELLED) {
|
2381
|
+
gpr_log(GPR_ERROR, "keepalive_ping_end state error: %d (expect: %d)",
|
2382
|
+
t->keepalive_state, GRPC_CHTTP2_KEEPALIVE_STATE_PINGING);
|
2383
|
+
}
|
2384
|
+
}
|
2385
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "keepalive watchdog");
|
2386
|
+
}
|
2387
|
+
|
2388
|
+
/*******************************************************************************
|
2389
|
+
* CALLBACK LOOP
|
2390
|
+
*/
|
2391
|
+
|
2392
|
+
static void connectivity_state_set(grpc_exec_ctx *exec_ctx,
|
2393
|
+
grpc_chttp2_transport *t,
|
2394
|
+
grpc_connectivity_state state,
|
2395
|
+
grpc_error *error, const char *reason) {
|
2396
|
+
GRPC_CHTTP2_IF_TRACING(
|
2397
|
+
gpr_log(GPR_DEBUG, "set connectivity_state=%d", state));
|
2398
|
+
grpc_connectivity_state_set(exec_ctx, &t->channel_callback.state_tracker,
|
2399
|
+
state, error, reason);
|
2400
|
+
}
|
2401
|
+
|
2402
|
+
/*******************************************************************************
|
2403
|
+
* POLLSET STUFF
|
2404
|
+
*/
|
2405
|
+
|
2406
|
+
static void set_pollset(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
2407
|
+
grpc_stream *gs, grpc_pollset *pollset) {
|
2408
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
2409
|
+
grpc_endpoint_add_to_pollset(exec_ctx, t->ep, pollset);
|
2410
|
+
}
|
2411
|
+
|
2412
|
+
static void set_pollset_set(grpc_exec_ctx *exec_ctx, grpc_transport *gt,
|
2413
|
+
grpc_stream *gs, grpc_pollset_set *pollset_set) {
|
2414
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)gt;
|
2415
|
+
grpc_endpoint_add_to_pollset_set(exec_ctx, t->ep, pollset_set);
|
2416
|
+
}
|
2417
|
+
|
2418
|
+
/*******************************************************************************
|
2419
|
+
* BYTE STREAM
|
2420
|
+
*/
|
2421
|
+
|
2422
|
+
static void incoming_byte_stream_unref(grpc_exec_ctx *exec_ctx,
|
2423
|
+
grpc_chttp2_incoming_byte_stream *bs) {
|
2424
|
+
if (gpr_unref(&bs->refs)) {
|
2425
|
+
GRPC_ERROR_UNREF(bs->error);
|
2426
|
+
grpc_slice_buffer_destroy_internal(exec_ctx, &bs->slices);
|
2427
|
+
gpr_mu_destroy(&bs->slice_mu);
|
2428
|
+
gpr_free(bs);
|
2429
|
+
}
|
2430
|
+
}
|
2431
|
+
|
2432
|
+
static void incoming_byte_stream_update_flow_control(grpc_exec_ctx *exec_ctx,
|
2433
|
+
grpc_chttp2_transport *t,
|
2434
|
+
grpc_chttp2_stream *s,
|
2435
|
+
size_t max_size_hint,
|
2436
|
+
size_t have_already) {
|
2437
|
+
uint32_t max_recv_bytes;
|
2438
|
+
uint32_t initial_window_size =
|
2439
|
+
t->settings[GRPC_SENT_SETTINGS][GRPC_CHTTP2_SETTINGS_INITIAL_WINDOW_SIZE];
|
2440
|
+
|
2441
|
+
/* clamp max recv hint to an allowable size */
|
2442
|
+
if (max_size_hint >= UINT32_MAX - initial_window_size) {
|
2443
|
+
max_recv_bytes = UINT32_MAX - initial_window_size;
|
2444
|
+
} else {
|
2445
|
+
max_recv_bytes = (uint32_t)max_size_hint;
|
2446
|
+
}
|
2447
|
+
|
2448
|
+
/* account for bytes already received but unknown to higher layers */
|
2449
|
+
if (max_recv_bytes >= have_already) {
|
2450
|
+
max_recv_bytes -= (uint32_t)have_already;
|
2451
|
+
} else {
|
2452
|
+
max_recv_bytes = 0;
|
2453
|
+
}
|
2454
|
+
|
2455
|
+
/* add some small lookahead to keep pipelines flowing */
|
2456
|
+
GPR_ASSERT(max_recv_bytes <= UINT32_MAX - initial_window_size);
|
2457
|
+
if (s->incoming_window_delta < max_recv_bytes && !s->read_closed) {
|
2458
|
+
uint32_t add_max_recv_bytes =
|
2459
|
+
(uint32_t)(max_recv_bytes - s->incoming_window_delta);
|
2460
|
+
grpc_chttp2_stream_write_type write_type =
|
2461
|
+
GRPC_CHTTP2_STREAM_WRITE_INITIATE_UNCOVERED;
|
2462
|
+
if (s->incoming_window_delta + initial_window_size <
|
2463
|
+
(int64_t)have_already) {
|
2464
|
+
write_type = GRPC_CHTTP2_STREAM_WRITE_INITIATE_COVERED;
|
2465
|
+
}
|
2466
|
+
GRPC_CHTTP2_FLOW_CREDIT_STREAM_INCOMING_WINDOW_DELTA("op", t, s,
|
2467
|
+
add_max_recv_bytes);
|
2468
|
+
GRPC_CHTTP2_FLOW_CREDIT_STREAM("op", t, s, announce_window,
|
2469
|
+
add_max_recv_bytes);
|
2470
|
+
if ((int64_t)s->incoming_window_delta + (int64_t)initial_window_size -
|
2471
|
+
(int64_t)s->announce_window >
|
2472
|
+
(int64_t)initial_window_size / 2) {
|
2473
|
+
write_type = GRPC_CHTTP2_STREAM_WRITE_PIGGYBACK;
|
2474
|
+
}
|
2475
|
+
grpc_chttp2_become_writable(exec_ctx, t, s, write_type,
|
2476
|
+
"read_incoming_stream");
|
2477
|
+
}
|
2478
|
+
}
|
2479
|
+
|
2480
|
+
static void incoming_byte_stream_next_locked(grpc_exec_ctx *exec_ctx,
|
2481
|
+
void *argp,
|
2482
|
+
grpc_error *error_ignored) {
|
2483
|
+
grpc_chttp2_incoming_byte_stream *bs = argp;
|
2484
|
+
grpc_chttp2_transport *t = bs->transport;
|
2485
|
+
grpc_chttp2_stream *s = bs->stream;
|
2486
|
+
|
2487
|
+
if (bs->is_tail) {
|
2488
|
+
gpr_mu_lock(&bs->slice_mu);
|
2489
|
+
size_t cur_length = bs->slices.length;
|
2490
|
+
gpr_mu_unlock(&bs->slice_mu);
|
2491
|
+
incoming_byte_stream_update_flow_control(
|
2492
|
+
exec_ctx, t, s, bs->next_action.max_size_hint, cur_length);
|
2493
|
+
}
|
2494
|
+
gpr_mu_lock(&bs->slice_mu);
|
2495
|
+
if (bs->slices.count > 0) {
|
2496
|
+
*bs->next_action.slice = grpc_slice_buffer_take_first(&bs->slices);
|
2497
|
+
grpc_closure_run(exec_ctx, bs->next_action.on_complete, GRPC_ERROR_NONE);
|
2498
|
+
} else if (bs->error != GRPC_ERROR_NONE) {
|
2499
|
+
grpc_closure_run(exec_ctx, bs->next_action.on_complete,
|
2500
|
+
GRPC_ERROR_REF(bs->error));
|
2501
|
+
} else {
|
2502
|
+
bs->on_next = bs->next_action.on_complete;
|
2503
|
+
bs->next = bs->next_action.slice;
|
2504
|
+
}
|
2505
|
+
gpr_mu_unlock(&bs->slice_mu);
|
2506
|
+
incoming_byte_stream_unref(exec_ctx, bs);
|
2507
|
+
}
|
2508
|
+
|
2509
|
+
static int incoming_byte_stream_next(grpc_exec_ctx *exec_ctx,
|
2510
|
+
grpc_byte_stream *byte_stream,
|
2511
|
+
grpc_slice *slice, size_t max_size_hint,
|
2512
|
+
grpc_closure *on_complete) {
|
2513
|
+
GPR_TIMER_BEGIN("incoming_byte_stream_next", 0);
|
2514
|
+
grpc_chttp2_incoming_byte_stream *bs =
|
2515
|
+
(grpc_chttp2_incoming_byte_stream *)byte_stream;
|
2516
|
+
gpr_ref(&bs->refs);
|
2517
|
+
bs->next_action.slice = slice;
|
2518
|
+
bs->next_action.max_size_hint = max_size_hint;
|
2519
|
+
bs->next_action.on_complete = on_complete;
|
2520
|
+
grpc_closure_sched(
|
2521
|
+
exec_ctx,
|
2522
|
+
grpc_closure_init(
|
2523
|
+
&bs->next_action.closure, incoming_byte_stream_next_locked, bs,
|
2524
|
+
grpc_combiner_scheduler(bs->transport->combiner, false)),
|
2525
|
+
GRPC_ERROR_NONE);
|
2526
|
+
GPR_TIMER_END("incoming_byte_stream_next", 0);
|
2527
|
+
return 0;
|
2528
|
+
}
|
2529
|
+
|
2530
|
+
static void incoming_byte_stream_destroy(grpc_exec_ctx *exec_ctx,
|
2531
|
+
grpc_byte_stream *byte_stream);
|
2532
|
+
|
2533
|
+
static void incoming_byte_stream_destroy_locked(grpc_exec_ctx *exec_ctx,
|
2534
|
+
void *byte_stream,
|
2535
|
+
grpc_error *error_ignored) {
|
2536
|
+
grpc_chttp2_incoming_byte_stream *bs = byte_stream;
|
2537
|
+
GPR_ASSERT(bs->base.destroy == incoming_byte_stream_destroy);
|
2538
|
+
decrement_active_streams_locked(exec_ctx, bs->transport, bs->stream);
|
2539
|
+
incoming_byte_stream_unref(exec_ctx, bs);
|
2540
|
+
}
|
2541
|
+
|
2542
|
+
static void incoming_byte_stream_destroy(grpc_exec_ctx *exec_ctx,
|
2543
|
+
grpc_byte_stream *byte_stream) {
|
2544
|
+
GPR_TIMER_BEGIN("incoming_byte_stream_destroy", 0);
|
2545
|
+
grpc_chttp2_incoming_byte_stream *bs =
|
2546
|
+
(grpc_chttp2_incoming_byte_stream *)byte_stream;
|
2547
|
+
grpc_closure_sched(
|
2548
|
+
exec_ctx,
|
2549
|
+
grpc_closure_init(
|
2550
|
+
&bs->destroy_action, incoming_byte_stream_destroy_locked, bs,
|
2551
|
+
grpc_combiner_scheduler(bs->transport->combiner, false)),
|
2552
|
+
GRPC_ERROR_NONE);
|
2553
|
+
GPR_TIMER_END("incoming_byte_stream_destroy", 0);
|
2554
|
+
}
|
2555
|
+
|
2556
|
+
static void incoming_byte_stream_publish_error(
|
2557
|
+
grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs,
|
2558
|
+
grpc_error *error) {
|
2559
|
+
GPR_ASSERT(error != GRPC_ERROR_NONE);
|
2560
|
+
grpc_closure_sched(exec_ctx, bs->on_next, GRPC_ERROR_REF(error));
|
2561
|
+
bs->on_next = NULL;
|
2562
|
+
GRPC_ERROR_UNREF(bs->error);
|
2563
|
+
grpc_chttp2_cancel_stream(exec_ctx, bs->transport, bs->stream,
|
2564
|
+
GRPC_ERROR_REF(error));
|
2565
|
+
bs->error = error;
|
2566
|
+
}
|
2567
|
+
|
2568
|
+
void grpc_chttp2_incoming_byte_stream_push(grpc_exec_ctx *exec_ctx,
|
2569
|
+
grpc_chttp2_incoming_byte_stream *bs,
|
2570
|
+
grpc_slice slice) {
|
2571
|
+
gpr_mu_lock(&bs->slice_mu);
|
2572
|
+
if (bs->remaining_bytes < GRPC_SLICE_LENGTH(slice)) {
|
2573
|
+
incoming_byte_stream_publish_error(
|
2574
|
+
exec_ctx, bs,
|
2575
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Too many bytes in stream"));
|
2576
|
+
} else {
|
2577
|
+
bs->remaining_bytes -= (uint32_t)GRPC_SLICE_LENGTH(slice);
|
2578
|
+
if (bs->on_next != NULL) {
|
2579
|
+
*bs->next = slice;
|
2580
|
+
grpc_closure_sched(exec_ctx, bs->on_next, GRPC_ERROR_NONE);
|
2581
|
+
bs->on_next = NULL;
|
2582
|
+
} else {
|
2583
|
+
grpc_slice_buffer_add(&bs->slices, slice);
|
2584
|
+
}
|
2585
|
+
}
|
2586
|
+
gpr_mu_unlock(&bs->slice_mu);
|
2587
|
+
}
|
2588
|
+
|
2589
|
+
void grpc_chttp2_incoming_byte_stream_finished(
|
2590
|
+
grpc_exec_ctx *exec_ctx, grpc_chttp2_incoming_byte_stream *bs,
|
2591
|
+
grpc_error *error) {
|
2592
|
+
if (error == GRPC_ERROR_NONE) {
|
2593
|
+
gpr_mu_lock(&bs->slice_mu);
|
2594
|
+
if (bs->remaining_bytes != 0) {
|
2595
|
+
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("Truncated message");
|
2596
|
+
}
|
2597
|
+
gpr_mu_unlock(&bs->slice_mu);
|
2598
|
+
}
|
2599
|
+
if (error != GRPC_ERROR_NONE) {
|
2600
|
+
incoming_byte_stream_publish_error(exec_ctx, bs, error);
|
2601
|
+
}
|
2602
|
+
incoming_byte_stream_unref(exec_ctx, bs);
|
2603
|
+
}
|
2604
|
+
|
2605
|
+
grpc_chttp2_incoming_byte_stream *grpc_chttp2_incoming_byte_stream_create(
|
2606
|
+
grpc_exec_ctx *exec_ctx, grpc_chttp2_transport *t, grpc_chttp2_stream *s,
|
2607
|
+
uint32_t frame_size, uint32_t flags) {
|
2608
|
+
grpc_chttp2_incoming_byte_stream *incoming_byte_stream =
|
2609
|
+
gpr_malloc(sizeof(*incoming_byte_stream));
|
2610
|
+
incoming_byte_stream->base.length = frame_size;
|
2611
|
+
incoming_byte_stream->remaining_bytes = frame_size;
|
2612
|
+
incoming_byte_stream->base.flags = flags;
|
2613
|
+
incoming_byte_stream->base.next = incoming_byte_stream_next;
|
2614
|
+
incoming_byte_stream->base.destroy = incoming_byte_stream_destroy;
|
2615
|
+
gpr_mu_init(&incoming_byte_stream->slice_mu);
|
2616
|
+
gpr_ref_init(&incoming_byte_stream->refs, 2);
|
2617
|
+
incoming_byte_stream->next_message = NULL;
|
2618
|
+
incoming_byte_stream->transport = t;
|
2619
|
+
incoming_byte_stream->stream = s;
|
2620
|
+
gpr_ref(&incoming_byte_stream->stream->active_streams);
|
2621
|
+
grpc_slice_buffer_init(&incoming_byte_stream->slices);
|
2622
|
+
incoming_byte_stream->on_next = NULL;
|
2623
|
+
incoming_byte_stream->is_tail = 1;
|
2624
|
+
incoming_byte_stream->error = GRPC_ERROR_NONE;
|
2625
|
+
grpc_chttp2_incoming_frame_queue *q = &s->incoming_frames;
|
2626
|
+
if (q->head == NULL) {
|
2627
|
+
q->head = incoming_byte_stream;
|
2628
|
+
} else {
|
2629
|
+
q->tail->is_tail = 0;
|
2630
|
+
q->tail->next_message = incoming_byte_stream;
|
2631
|
+
}
|
2632
|
+
q->tail = incoming_byte_stream;
|
2633
|
+
grpc_chttp2_maybe_complete_recv_message(exec_ctx, t, s);
|
2634
|
+
return incoming_byte_stream;
|
2635
|
+
}
|
2636
|
+
|
2637
|
+
/*******************************************************************************
|
2638
|
+
* RESOURCE QUOTAS
|
2639
|
+
*/
|
2640
|
+
|
2641
|
+
static void post_benign_reclaimer(grpc_exec_ctx *exec_ctx,
|
2642
|
+
grpc_chttp2_transport *t) {
|
2643
|
+
if (!t->benign_reclaimer_registered) {
|
2644
|
+
t->benign_reclaimer_registered = true;
|
2645
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "benign_reclaimer");
|
2646
|
+
grpc_resource_user_post_reclaimer(exec_ctx,
|
2647
|
+
grpc_endpoint_get_resource_user(t->ep),
|
2648
|
+
false, &t->benign_reclaimer_locked);
|
2649
|
+
}
|
2650
|
+
}
|
2651
|
+
|
2652
|
+
static void post_destructive_reclaimer(grpc_exec_ctx *exec_ctx,
|
2653
|
+
grpc_chttp2_transport *t) {
|
2654
|
+
if (!t->destructive_reclaimer_registered) {
|
2655
|
+
t->destructive_reclaimer_registered = true;
|
2656
|
+
GRPC_CHTTP2_REF_TRANSPORT(t, "destructive_reclaimer");
|
2657
|
+
grpc_resource_user_post_reclaimer(exec_ctx,
|
2658
|
+
grpc_endpoint_get_resource_user(t->ep),
|
2659
|
+
true, &t->destructive_reclaimer_locked);
|
2660
|
+
}
|
2661
|
+
}
|
2662
|
+
|
2663
|
+
static void benign_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2664
|
+
grpc_error *error) {
|
2665
|
+
grpc_chttp2_transport *t = arg;
|
2666
|
+
if (error == GRPC_ERROR_NONE &&
|
2667
|
+
grpc_chttp2_stream_map_size(&t->stream_map) == 0) {
|
2668
|
+
/* Channel with no active streams: send a goaway to try and make it
|
2669
|
+
* disconnect cleanly */
|
2670
|
+
if (grpc_resource_quota_trace) {
|
2671
|
+
gpr_log(GPR_DEBUG, "HTTP2: %s - send goaway to free memory",
|
2672
|
+
t->peer_string);
|
2673
|
+
}
|
2674
|
+
send_goaway(exec_ctx, t,
|
2675
|
+
grpc_error_set_int(
|
2676
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
|
2677
|
+
GRPC_ERROR_INT_HTTP2_ERROR, GRPC_HTTP2_ENHANCE_YOUR_CALM));
|
2678
|
+
} else if (error == GRPC_ERROR_NONE && grpc_resource_quota_trace) {
|
2679
|
+
gpr_log(GPR_DEBUG,
|
2680
|
+
"HTTP2: %s - skip benign reclamation, there are still %" PRIdPTR
|
2681
|
+
" streams",
|
2682
|
+
t->peer_string, grpc_chttp2_stream_map_size(&t->stream_map));
|
2683
|
+
}
|
2684
|
+
t->benign_reclaimer_registered = false;
|
2685
|
+
if (error != GRPC_ERROR_CANCELLED) {
|
2686
|
+
grpc_resource_user_finish_reclamation(
|
2687
|
+
exec_ctx, grpc_endpoint_get_resource_user(t->ep));
|
2688
|
+
}
|
2689
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "benign_reclaimer");
|
2690
|
+
}
|
2691
|
+
|
2692
|
+
static void destructive_reclaimer_locked(grpc_exec_ctx *exec_ctx, void *arg,
|
2693
|
+
grpc_error *error) {
|
2694
|
+
grpc_chttp2_transport *t = arg;
|
2695
|
+
size_t n = grpc_chttp2_stream_map_size(&t->stream_map);
|
2696
|
+
t->destructive_reclaimer_registered = false;
|
2697
|
+
if (error == GRPC_ERROR_NONE && n > 0) {
|
2698
|
+
grpc_chttp2_stream *s = grpc_chttp2_stream_map_rand(&t->stream_map);
|
2699
|
+
if (grpc_resource_quota_trace) {
|
2700
|
+
gpr_log(GPR_DEBUG, "HTTP2: %s - abandon stream id %d", t->peer_string,
|
2701
|
+
s->id);
|
2702
|
+
}
|
2703
|
+
grpc_chttp2_cancel_stream(
|
2704
|
+
exec_ctx, t, s,
|
2705
|
+
grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Buffers full"),
|
2706
|
+
GRPC_ERROR_INT_HTTP2_ERROR,
|
2707
|
+
GRPC_HTTP2_ENHANCE_YOUR_CALM));
|
2708
|
+
if (n > 1) {
|
2709
|
+
/* Since we cancel one stream per destructive reclamation, if
|
2710
|
+
there are more streams left, we can immediately post a new
|
2711
|
+
reclaimer in case the resource quota needs to free more
|
2712
|
+
memory */
|
2713
|
+
post_destructive_reclaimer(exec_ctx, t);
|
2714
|
+
}
|
2715
|
+
}
|
2716
|
+
if (error != GRPC_ERROR_CANCELLED) {
|
2717
|
+
grpc_resource_user_finish_reclamation(
|
2718
|
+
exec_ctx, grpc_endpoint_get_resource_user(t->ep));
|
2719
|
+
}
|
2720
|
+
GRPC_CHTTP2_UNREF_TRANSPORT(exec_ctx, t, "destructive_reclaimer");
|
2721
|
+
}
|
2722
|
+
|
2723
|
+
/*******************************************************************************
|
2724
|
+
* TRACING
|
2725
|
+
*/
|
2726
|
+
|
2727
|
+
static char *format_flowctl_context_var(const char *context, const char *var,
|
2728
|
+
int64_t val, uint32_t id) {
|
2729
|
+
char *name;
|
2730
|
+
if (context == NULL) {
|
2731
|
+
name = gpr_strdup(var);
|
2732
|
+
} else if (0 == strcmp(context, "t")) {
|
2733
|
+
GPR_ASSERT(id == 0);
|
2734
|
+
gpr_asprintf(&name, "TRANSPORT:%s", var);
|
2735
|
+
} else if (0 == strcmp(context, "s")) {
|
2736
|
+
GPR_ASSERT(id != 0);
|
2737
|
+
gpr_asprintf(&name, "STREAM[%d]:%s", id, var);
|
2738
|
+
} else {
|
2739
|
+
gpr_asprintf(&name, "BAD_CONTEXT[%s][%d]:%s", context, id, var);
|
2740
|
+
}
|
2741
|
+
char *name_fld = gpr_leftpad(name, ' ', 64);
|
2742
|
+
char *value;
|
2743
|
+
gpr_asprintf(&value, "%" PRId64, val);
|
2744
|
+
char *value_fld = gpr_leftpad(value, ' ', 8);
|
2745
|
+
char *result;
|
2746
|
+
gpr_asprintf(&result, "%s %s", name_fld, value_fld);
|
2747
|
+
gpr_free(name);
|
2748
|
+
gpr_free(name_fld);
|
2749
|
+
gpr_free(value);
|
2750
|
+
gpr_free(value_fld);
|
2751
|
+
return result;
|
2752
|
+
}
|
2753
|
+
|
2754
|
+
void grpc_chttp2_flowctl_trace(const char *file, int line, const char *phase,
|
2755
|
+
grpc_chttp2_flowctl_op op, const char *context1,
|
2756
|
+
const char *var1, const char *context2,
|
2757
|
+
const char *var2, int is_client,
|
2758
|
+
uint32_t stream_id, int64_t val1, int64_t val2) {
|
2759
|
+
char *tmp_phase;
|
2760
|
+
char *label1 = format_flowctl_context_var(context1, var1, val1, stream_id);
|
2761
|
+
char *label2 = format_flowctl_context_var(context2, var2, val2, stream_id);
|
2762
|
+
char *clisvr = is_client ? "client" : "server";
|
2763
|
+
char *prefix;
|
2764
|
+
|
2765
|
+
tmp_phase = gpr_leftpad(phase, ' ', 8);
|
2766
|
+
gpr_asprintf(&prefix, "FLOW %s: %s ", tmp_phase, clisvr);
|
2767
|
+
gpr_free(tmp_phase);
|
2768
|
+
|
2769
|
+
switch (op) {
|
2770
|
+
case GRPC_CHTTP2_FLOWCTL_MOVE:
|
2771
|
+
if (val2 != 0) {
|
2772
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
2773
|
+
"%sMOVE %s <- %s giving %" PRId64, prefix, label1, label2,
|
2774
|
+
val1 + val2);
|
2775
|
+
}
|
2776
|
+
break;
|
2777
|
+
case GRPC_CHTTP2_FLOWCTL_CREDIT:
|
2778
|
+
GPR_ASSERT(val2 >= 0);
|
2779
|
+
if (val2 != 0) {
|
2780
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
2781
|
+
"%sCREDIT %s by %s giving %" PRId64, prefix, label1, label2,
|
2782
|
+
val1 + val2);
|
2783
|
+
}
|
2784
|
+
break;
|
2785
|
+
case GRPC_CHTTP2_FLOWCTL_DEBIT:
|
2786
|
+
GPR_ASSERT(val2 >= 0);
|
2787
|
+
if (val2 != 0) {
|
2788
|
+
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
2789
|
+
"%sDEBIT %s by %s giving %" PRId64, prefix, label1, label2,
|
2790
|
+
val1 - val2);
|
2791
|
+
}
|
2792
|
+
break;
|
2793
|
+
}
|
2794
|
+
|
2795
|
+
gpr_free(label1);
|
2796
|
+
gpr_free(label2);
|
2797
|
+
gpr_free(prefix);
|
2798
|
+
}
|
2799
|
+
|
2800
|
+
/*******************************************************************************
|
2801
|
+
* INTEGRATION GLUE
|
2802
|
+
*/
|
2803
|
+
|
2804
|
+
static char *chttp2_get_peer(grpc_exec_ctx *exec_ctx, grpc_transport *t) {
|
2805
|
+
return gpr_strdup(((grpc_chttp2_transport *)t)->peer_string);
|
2806
|
+
}
|
2807
|
+
|
2808
|
+
/*******************************************************************************
|
2809
|
+
* MONITORING
|
2810
|
+
*/
|
2811
|
+
static grpc_endpoint *chttp2_get_endpoint(grpc_exec_ctx *exec_ctx,
|
2812
|
+
grpc_transport *t) {
|
2813
|
+
return ((grpc_chttp2_transport *)t)->ep;
|
2814
|
+
}
|
2815
|
+
|
2816
|
+
static const grpc_transport_vtable vtable = {sizeof(grpc_chttp2_stream),
|
2817
|
+
"chttp2",
|
2818
|
+
init_stream,
|
2819
|
+
set_pollset,
|
2820
|
+
set_pollset_set,
|
2821
|
+
perform_stream_op,
|
2822
|
+
perform_transport_op,
|
2823
|
+
destroy_stream,
|
2824
|
+
destroy_transport,
|
2825
|
+
chttp2_get_peer,
|
2826
|
+
chttp2_get_endpoint};
|
2827
|
+
|
2828
|
+
grpc_transport *grpc_create_chttp2_transport(
|
2829
|
+
grpc_exec_ctx *exec_ctx, const grpc_channel_args *channel_args,
|
2830
|
+
grpc_endpoint *ep, int is_client) {
|
2831
|
+
grpc_chttp2_transport *t = gpr_zalloc(sizeof(grpc_chttp2_transport));
|
2832
|
+
init_transport(exec_ctx, t, channel_args, ep, is_client != 0);
|
2833
|
+
return &t->base;
|
2834
|
+
}
|
2835
|
+
|
2836
|
+
void grpc_chttp2_transport_start_reading(grpc_exec_ctx *exec_ctx,
|
2837
|
+
grpc_transport *transport,
|
2838
|
+
grpc_slice_buffer *read_buffer) {
|
2839
|
+
grpc_chttp2_transport *t = (grpc_chttp2_transport *)transport;
|
2840
|
+
GRPC_CHTTP2_REF_TRANSPORT(
|
2841
|
+
t, "reading_action"); /* matches unref inside reading_action */
|
2842
|
+
if (read_buffer != NULL) {
|
2843
|
+
grpc_slice_buffer_move_into(read_buffer, &t->read_buffer);
|
2844
|
+
gpr_free(read_buffer);
|
2845
|
+
}
|
2846
|
+
grpc_closure_sched(exec_ctx, &t->read_action_locked, GRPC_ERROR_NONE);
|
2847
|
+
}
|