grpc 1.6.7 → 1.7.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +579 -77
- data/include/grpc/byte_buffer.h +1 -63
- data/include/grpc/compression.h +27 -5
- data/include/grpc/fork.h +24 -0
- data/include/grpc/grpc.h +12 -6
- data/include/grpc/grpc_security.h +28 -7
- data/include/grpc/impl/codegen/atm.h +1 -0
- data/include/grpc/impl/codegen/byte_buffer.h +86 -0
- data/include/grpc/impl/codegen/compression_types.h +63 -5
- data/include/grpc/impl/codegen/fork.h +48 -0
- data/include/grpc/impl/codegen/grpc_types.h +26 -9
- data/include/grpc/impl/codegen/port_platform.h +11 -4
- data/include/grpc/impl/codegen/slice.h +6 -1
- data/include/grpc/impl/codegen/sync.h +3 -1
- data/include/grpc/impl/codegen/sync_custom.h +36 -0
- data/include/grpc/module.modulemap +75 -3
- data/include/grpc/slice.h +1 -5
- data/include/grpc/support/sync_custom.h +24 -0
- data/src/core/ext/census/base_resources.c +14 -14
- data/src/core/ext/census/context.c +7 -5
- data/src/core/ext/census/grpc_filter.c +12 -14
- data/src/core/ext/census/mlog.c +2 -1
- data/src/core/ext/census/resource.c +13 -9
- data/src/core/ext/filters/client_channel/channel_connectivity.c +15 -8
- data/src/core/ext/filters/client_channel/client_channel.c +418 -439
- data/src/core/ext/filters/client_channel/client_channel_factory.c +4 -5
- data/src/core/ext/filters/client_channel/client_channel_plugin.c +2 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.c +7 -5
- data/src/core/ext/filters/client_channel/http_proxy.c +17 -21
- data/src/core/ext/filters/client_channel/lb_policy.c +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/client_load_reporting_filter.c +7 -7
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.c +371 -257
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.c +7 -5
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.c +25 -14
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.c +16 -16
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.c +33 -28
- data/src/core/ext/filters/client_channel/lb_policy_factory.c +10 -8
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +1 -1
- data/src/core/ext/filters/client_channel/proxy_mapper_registry.c +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.c +7 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_posix.c +62 -28
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.c +29 -23
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.c +25 -14
- data/src/core/ext/filters/client_channel/retry_throttle.c +9 -6
- data/src/core/ext/filters/client_channel/subchannel.c +30 -30
- data/src/core/ext/filters/client_channel/subchannel.h +1 -4
- data/src/core/ext/filters/client_channel/subchannel_index.c +31 -15
- data/src/core/ext/filters/client_channel/subchannel_index.h +7 -0
- data/src/core/ext/filters/client_channel/uri_parser.c +4 -3
- data/src/core/ext/filters/deadline/deadline_filter.c +78 -39
- data/src/core/ext/filters/deadline/deadline_filter.h +7 -1
- data/src/core/ext/filters/http/client/http_client_filter.c +14 -14
- data/src/core/ext/filters/http/http_filters_plugin.c +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.c +240 -175
- data/src/core/ext/filters/http/server/http_server_filter.c +48 -36
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.c → server_load_reporting_filter.c} +11 -12
- data/src/core/ext/filters/load_reporting/{load_reporting_filter.h → server_load_reporting_filter.h} +6 -5
- data/src/core/ext/filters/load_reporting/{load_reporting.c → server_load_reporting_plugin.c} +19 -13
- data/src/core/ext/filters/load_reporting/{load_reporting.h → server_load_reporting_plugin.h} +4 -3
- data/src/core/ext/filters/max_age/max_age_filter.c +2 -3
- data/src/core/ext/filters/message_size/message_size_filter.c +4 -2
- data/src/core/ext/filters/workarounds/workaround_cronet_compression_filter.c +0 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.c +5 -5
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.c +1 -1
- data/src/core/ext/transport/chttp2/client/insecure/channel_create_posix.c +1 -1
- data/src/core/ext/transport/chttp2/server/chttp2_server.c +20 -18
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.c +1 -0
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.c +493 -210
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/flow_control.c +9 -8
- data/src/core/ext/transport/chttp2/transport/frame_data.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_goaway.c +2 -2
- data/src/core/ext/transport/chttp2/transport/frame_ping.c +5 -4
- data/src/core/ext/transport/chttp2/transport/frame_rst_stream.c +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.c +10 -9
- data/src/core/ext/transport/chttp2/transport/frame_window_update.c +9 -5
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.c +62 -41
- data/src/core/ext/transport/chttp2/transport/hpack_parser.c +52 -8
- data/src/core/ext/transport/chttp2/transport/hpack_table.c +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.c +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +60 -30
- data/src/core/ext/transport/chttp2/transport/parsing.c +16 -5
- data/src/core/ext/transport/chttp2/transport/stream_lists.c +36 -16
- data/src/core/ext/transport/chttp2/transport/stream_map.c +6 -4
- data/src/core/ext/transport/chttp2/transport/writing.c +133 -105
- data/src/core/ext/transport/inproc/inproc_transport.c +61 -65
- data/src/core/lib/channel/channel_args.c +112 -12
- data/src/core/lib/channel/channel_args.h +31 -0
- data/src/core/lib/channel/channel_stack.c +1 -15
- data/src/core/lib/channel/channel_stack.h +3 -10
- data/src/core/lib/channel/channel_stack_builder.c +41 -10
- data/src/core/lib/channel/channel_stack_builder.h +10 -0
- data/src/core/lib/channel/connected_channel.c +94 -23
- data/src/core/lib/channel/handshaker.c +8 -6
- data/src/core/lib/channel/handshaker_registry.c +1 -1
- data/src/core/lib/compression/algorithm_metadata.h +14 -0
- data/src/core/lib/compression/compression.c +101 -1
- data/src/core/lib/compression/stream_compression.c +32 -146
- data/src/core/lib/compression/stream_compression.h +28 -4
- data/src/core/lib/compression/stream_compression_gzip.c +228 -0
- data/src/core/lib/{iomgr/ev_epoll_thread_pool_linux.h → compression/stream_compression_gzip.h} +5 -7
- data/src/core/lib/compression/stream_compression_identity.c +94 -0
- data/src/core/lib/{iomgr/ev_epoll_limited_pollers_linux.h → compression/stream_compression_identity.h} +7 -8
- data/src/core/lib/debug/stats.c +174 -0
- data/src/core/lib/debug/stats.h +61 -0
- data/src/core/lib/debug/stats_data.c +687 -0
- data/src/core/lib/debug/stats_data.h +470 -0
- data/src/core/lib/debug/trace.c +3 -3
- data/src/core/lib/debug/trace.h +1 -1
- data/src/core/lib/http/format_request.c +1 -1
- data/src/core/lib/http/httpcli.c +8 -7
- data/src/core/lib/http/httpcli_security_connector.c +2 -1
- data/src/core/lib/http/parser.c +4 -3
- data/src/core/lib/iomgr/call_combiner.c +202 -0
- data/src/core/lib/iomgr/call_combiner.h +121 -0
- data/src/core/lib/iomgr/closure.c +18 -4
- data/src/core/lib/iomgr/combiner.c +11 -4
- data/src/core/lib/iomgr/error.c +26 -24
- data/src/core/lib/iomgr/ev_epoll1_linux.c +395 -212
- data/src/core/lib/iomgr/ev_epollex_linux.c +141 -128
- data/src/core/lib/iomgr/ev_epollsig_linux.c +44 -41
- data/src/core/lib/iomgr/ev_poll_posix.c +99 -75
- data/src/core/lib/iomgr/ev_posix.c +5 -9
- data/src/core/lib/iomgr/ev_posix.h +1 -1
- data/src/core/lib/iomgr/exec_ctx.h +6 -1
- data/src/core/lib/iomgr/executor.c +142 -36
- data/src/core/lib/iomgr/executor.h +6 -1
- data/src/core/lib/iomgr/fork_posix.c +88 -0
- data/src/core/lib/iomgr/fork_windows.c +39 -0
- data/src/core/lib/iomgr/iocp_windows.c +2 -0
- data/src/core/lib/iomgr/iomgr.c +2 -8
- data/src/core/lib/iomgr/is_epollexclusive_available.c +6 -6
- data/src/core/lib/iomgr/load_file.c +2 -1
- data/src/core/lib/iomgr/polling_entity.c +9 -9
- data/src/core/lib/iomgr/polling_entity.h +7 -1
- data/src/core/lib/iomgr/pollset.h +1 -1
- data/src/core/lib/iomgr/pollset_uv.c +1 -1
- data/src/core/lib/iomgr/pollset_windows.c +3 -3
- data/src/core/lib/iomgr/port.h +4 -0
- data/src/core/lib/iomgr/resolve_address_posix.c +8 -7
- data/src/core/lib/iomgr/resolve_address_windows.c +1 -1
- data/src/core/lib/iomgr/resource_quota.c +24 -19
- data/src/core/lib/iomgr/socket_factory_posix.c +4 -4
- data/src/core/lib/iomgr/socket_mutator.c +4 -4
- data/src/core/lib/iomgr/socket_utils_windows.c +0 -4
- data/src/core/lib/iomgr/tcp_client_posix.c +5 -4
- data/src/core/lib/iomgr/tcp_posix.c +181 -20
- data/src/core/lib/iomgr/tcp_server_posix.c +8 -7
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.c +1 -1
- data/src/core/lib/iomgr/timer.h +4 -0
- data/src/core/lib/iomgr/timer_generic.c +138 -3
- data/src/core/lib/iomgr/timer_generic.h +3 -0
- data/src/core/lib/iomgr/timer_heap.c +4 -4
- data/src/core/lib/iomgr/timer_manager.c +2 -2
- data/src/core/lib/iomgr/timer_uv.c +2 -0
- data/src/core/lib/iomgr/udp_server.c +10 -8
- data/src/core/lib/iomgr/unix_sockets_posix.c +4 -2
- data/src/core/lib/iomgr/wakeup_fd_cv.c +9 -8
- data/src/core/lib/iomgr/wakeup_fd_cv.h +2 -2
- data/src/core/lib/json/json.c +1 -1
- data/src/core/lib/json/json_string.c +13 -13
- data/src/core/lib/profiling/timers.h +18 -8
- data/src/core/lib/security/credentials/composite/composite_credentials.c +4 -10
- data/src/core/lib/security/credentials/google_default/google_default_credentials.c +2 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.c +11 -6
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.c +4 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.c +132 -50
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -0
- data/src/core/lib/security/transport/client_auth_filter.c +68 -135
- data/src/core/lib/security/transport/secure_endpoint.c +110 -90
- data/src/core/lib/security/transport/secure_endpoint.h +8 -3
- data/src/core/lib/security/transport/security_connector.c +10 -12
- data/src/core/lib/security/transport/security_handshaker.c +45 -24
- data/src/core/lib/security/transport/server_auth_filter.c +71 -20
- data/src/core/lib/slice/b64.c +2 -2
- data/src/core/lib/slice/slice.c +16 -14
- data/src/core/lib/slice/slice_buffer.c +5 -4
- data/src/core/lib/slice/slice_hash_table.c +3 -2
- data/src/core/lib/slice/slice_intern.c +8 -5
- data/src/core/lib/support/block_annotate.h +22 -0
- data/src/core/lib/support/fork.c +62 -0
- data/src/core/lib/support/fork.h +35 -0
- data/src/core/lib/support/log_linux.c +1 -1
- data/src/core/lib/support/string.c +15 -1
- data/src/core/lib/support/string.h +3 -0
- data/src/core/lib/support/thd_internal.h +6 -0
- data/src/core/lib/support/thd_posix.c +56 -0
- data/src/core/lib/support/thd_windows.c +2 -0
- data/src/core/lib/surface/alarm.c +22 -15
- data/src/core/lib/surface/byte_buffer.c +4 -2
- data/src/core/lib/surface/call.c +442 -141
- data/src/core/lib/surface/call.h +6 -6
- data/src/core/lib/surface/call_log_batch.c +1 -1
- data/src/core/lib/surface/call_test_only.h +12 -0
- data/src/core/lib/surface/channel.c +39 -4
- data/src/core/lib/surface/channel_init.c +6 -6
- data/src/core/lib/surface/channel_ping.c +2 -2
- data/src/core/lib/surface/completion_queue.c +56 -57
- data/src/core/lib/surface/init.c +17 -3
- data/src/core/lib/surface/init_secure.c +5 -1
- data/src/core/lib/surface/lame_client.cc +9 -10
- data/src/core/lib/surface/server.c +81 -72
- data/src/core/lib/surface/version.c +2 -2
- data/src/core/lib/transport/byte_stream.c +1 -0
- data/src/core/lib/transport/byte_stream.h +3 -1
- data/src/core/lib/transport/connectivity_state.c +2 -1
- data/src/core/lib/transport/metadata.c +7 -4
- data/src/core/lib/transport/metadata_batch.c +18 -16
- data/src/core/lib/transport/metadata_batch.h +1 -0
- data/src/core/lib/transport/service_config.c +5 -3
- data/src/core/lib/transport/static_metadata.c +395 -614
- data/src/core/lib/transport/static_metadata.h +165 -133
- data/src/core/lib/transport/status_conversion.c +1 -1
- data/src/core/lib/transport/transport.c +20 -20
- data/src/core/lib/transport/transport.h +8 -5
- data/src/core/lib/transport/transport_impl.h +0 -3
- data/src/core/lib/transport/transport_op_string.c +8 -1
- data/src/core/plugin_registry/grpc_plugin_registry.c +4 -4
- data/src/core/tsi/fake_transport_security.c +133 -2
- data/src/core/tsi/fake_transport_security.h +5 -0
- data/src/core/tsi/ssl_transport_security.c +105 -8
- data/src/core/tsi/ssl_transport_security.h +30 -7
- data/src/core/tsi/transport_security.h +8 -2
- data/src/core/tsi/transport_security_grpc.c +20 -13
- data/src/core/tsi/transport_security_grpc.h +13 -9
- data/src/ruby/ext/grpc/rb_call_credentials.c +6 -2
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +30 -20
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +50 -35
- data/src/ruby/lib/grpc.rb +1 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +34 -9
- data/src/ruby/lib/grpc/generic/bidi_call.rb +19 -10
- data/src/ruby/lib/grpc/generic/client_stub.rb +95 -38
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +66 -20
- data/src/ruby/lib/grpc/generic/rpc_server.rb +15 -3
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +1 -2
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +1 -0
- data/src/ruby/spec/channel_connection_spec.rb +1 -34
- data/src/ruby/spec/client_server_spec.rb +188 -82
- data/src/ruby/spec/generic/active_call_spec.rb +65 -11
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +38 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +1 -34
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/spec_helper.rb +4 -0
- data/src/ruby/spec/support/helpers.rb +73 -0
- data/src/ruby/spec/support/services.rb +147 -0
- data/third_party/cares/ares_build.h +21 -62
- data/third_party/cares/cares/ares.h +23 -1
- data/third_party/cares/cares/ares__close_sockets.c +2 -2
- data/third_party/cares/cares/ares_create_query.c +3 -3
- data/third_party/cares/cares/ares_expand_name.c +6 -2
- data/third_party/cares/cares/ares_expand_string.c +1 -1
- data/third_party/cares/cares/ares_getnameinfo.c +27 -7
- data/third_party/cares/cares/ares_init.c +407 -39
- data/third_party/cares/cares/ares_library_init.c +10 -0
- data/third_party/cares/cares/ares_library_init.h +2 -1
- data/third_party/cares/cares/ares_nowarn.c +6 -6
- data/third_party/cares/cares/ares_nowarn.h +2 -2
- data/third_party/cares/cares/ares_parse_naptr_reply.c +6 -1
- data/third_party/cares/cares/ares_private.h +11 -0
- data/third_party/cares/cares/ares_process.c +126 -37
- data/third_party/cares/cares/ares_version.h +2 -2
- data/third_party/cares/cares/ares_writev.c +2 -2
- data/third_party/cares/cares/config-win32.h +8 -34
- data/third_party/cares/cares/inet_net_pton.c +2 -2
- data/third_party/cares/cares/setup_once.h +5 -5
- data/third_party/cares/config_darwin/ares_config.h +98 -196
- data/third_party/cares/config_linux/ares_config.h +103 -203
- metadata +47 -20
- data/src/core/lib/iomgr/ev_epoll_limited_pollers_linux.c +0 -1957
- data/src/core/lib/iomgr/ev_epoll_thread_pool_linux.c +0 -1182
data/src/ruby/lib/grpc.rb
CHANGED
@@ -24,6 +24,7 @@ require_relative 'grpc/generic/active_call'
|
|
24
24
|
require_relative 'grpc/generic/client_stub'
|
25
25
|
require_relative 'grpc/generic/service'
|
26
26
|
require_relative 'grpc/generic/rpc_server'
|
27
|
+
require_relative 'grpc/generic/interceptors'
|
27
28
|
|
28
29
|
begin
|
29
30
|
file = File.open(ssl_roots_path)
|
@@ -154,6 +154,15 @@ module GRPC
|
|
154
154
|
Operation.new(self)
|
155
155
|
end
|
156
156
|
|
157
|
+
##
|
158
|
+
# Returns a restricted view of this ActiveCall for use in interceptors
|
159
|
+
#
|
160
|
+
# @return [InterceptableView]
|
161
|
+
#
|
162
|
+
def interceptable
|
163
|
+
InterceptableView.new(self)
|
164
|
+
end
|
165
|
+
|
157
166
|
def receive_and_check_status
|
158
167
|
batch_result = @call.run_batch(RECV_STATUS_ON_CLIENT => nil)
|
159
168
|
set_input_stream_done
|
@@ -515,15 +524,27 @@ module GRPC
|
|
515
524
|
# This does not mean that must necessarily be one. E.g, the replies
|
516
525
|
# produced by gen_each_reply could ignore the received_msgs
|
517
526
|
#
|
518
|
-
# @param
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
+
# @param mth [Proc] generates the BiDi stream replies
|
528
|
+
# @param interception_ctx [InterceptionContext]
|
529
|
+
#
|
530
|
+
def run_server_bidi(mth, interception_ctx)
|
531
|
+
view = multi_req_view
|
532
|
+
bidi_call = BidiCall.new(
|
533
|
+
@call,
|
534
|
+
@marshal,
|
535
|
+
@unmarshal,
|
536
|
+
metadata_received: @metadata_received,
|
537
|
+
req_view: view
|
538
|
+
)
|
539
|
+
requests = bidi_call.read_next_loop(proc { set_input_stream_done }, false)
|
540
|
+
interception_ctx.intercept!(
|
541
|
+
:bidi_streamer,
|
542
|
+
call: view,
|
543
|
+
method: mth,
|
544
|
+
requests: requests
|
545
|
+
) do
|
546
|
+
bidi_call.run_on_server(mth, requests)
|
547
|
+
end
|
527
548
|
end
|
528
549
|
|
529
550
|
# Waits till an operation completes
|
@@ -645,5 +666,9 @@ module GRPC
|
|
645
666
|
Operation = view_class(:cancel, :cancelled?, :deadline, :execute,
|
646
667
|
:metadata, :status, :start_call, :wait, :write_flag,
|
647
668
|
:write_flag=, :trailing_metadata)
|
669
|
+
|
670
|
+
# InterceptableView further limits access to an ActiveCall's methods
|
671
|
+
# for use in interceptors on the client, exposing only the deadline
|
672
|
+
InterceptableView = view_class(:deadline)
|
648
673
|
end
|
649
674
|
end
|
@@ -87,23 +87,32 @@ module GRPC
|
|
87
87
|
# This does not mean that must necessarily be one. E.g, the replies
|
88
88
|
# produced by gen_each_reply could ignore the received_msgs
|
89
89
|
#
|
90
|
-
# @param
|
91
|
-
# @param
|
92
|
-
|
93
|
-
|
90
|
+
# @param [Proc] gen_each_reply generates the BiDi stream replies.
|
91
|
+
# @param [Enumerable] requests The enumerable of requests to run
|
92
|
+
def run_on_server(gen_each_reply, requests)
|
93
|
+
replies = nil
|
94
|
+
|
94
95
|
# Pass in the optional call object parameter if possible
|
95
96
|
if gen_each_reply.arity == 1
|
96
|
-
|
97
|
-
read_loop(set_input_stream_done, is_client: false))
|
97
|
+
replies = gen_each_reply.call(requests)
|
98
98
|
elsif gen_each_reply.arity == 2
|
99
|
-
|
100
|
-
read_loop(set_input_stream_done, is_client: false),
|
101
|
-
@req_view)
|
99
|
+
replies = gen_each_reply.call(requests, @req_view)
|
102
100
|
else
|
103
101
|
fail 'Illegal arity of reply generator'
|
104
102
|
end
|
105
103
|
|
106
|
-
write_loop(
|
104
|
+
write_loop(replies, is_client: false)
|
105
|
+
end
|
106
|
+
|
107
|
+
##
|
108
|
+
# Read the next stream iteration
|
109
|
+
#
|
110
|
+
# @param [Proc] finalize_stream callback to call when the reads have been
|
111
|
+
# completely read through.
|
112
|
+
# @param [Boolean] is_client If this is a client or server request
|
113
|
+
#
|
114
|
+
def read_next_loop(finalize_stream, is_client = false)
|
115
|
+
read_loop(finalize_stream, is_client: is_client)
|
107
116
|
end
|
108
117
|
|
109
118
|
private
|
@@ -89,17 +89,23 @@ module GRPC
|
|
89
89
|
# used within a gRPC server.
|
90
90
|
# @param channel_args [Hash] the channel arguments. Note: this argument is
|
91
91
|
# ignored if the channel_override argument is provided.
|
92
|
+
# @param interceptors [Array<GRPC::ClientInterceptor>] An array of
|
93
|
+
# GRPC::ClientInterceptor objects that will be used for
|
94
|
+
# intercepting calls before they are executed
|
95
|
+
# Interceptors are an EXPERIMENTAL API.
|
92
96
|
def initialize(host, creds,
|
93
97
|
channel_override: nil,
|
94
98
|
timeout: nil,
|
95
99
|
propagate_mask: nil,
|
96
|
-
channel_args: {}
|
100
|
+
channel_args: {},
|
101
|
+
interceptors: [])
|
97
102
|
@ch = ClientStub.setup_channel(channel_override, host, creds,
|
98
103
|
channel_args)
|
99
104
|
alt_host = channel_args[Core::Channel::SSL_TARGET]
|
100
105
|
@host = alt_host.nil? ? host : alt_host
|
101
106
|
@propagate_mask = propagate_mask
|
102
107
|
@timeout = timeout.nil? ? DEFAULT_TIMEOUT : timeout
|
108
|
+
@interceptors = InterceptorRegistry.new(interceptors)
|
103
109
|
end
|
104
110
|
|
105
111
|
# request_response sends a request to a GRPC server, and returns the
|
@@ -149,16 +155,29 @@ module GRPC
|
|
149
155
|
deadline: deadline,
|
150
156
|
parent: parent,
|
151
157
|
credentials: credentials)
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
158
|
+
interception_context = @interceptors.build_context
|
159
|
+
intercept_args = {
|
160
|
+
method: method,
|
161
|
+
request: req,
|
162
|
+
call: c.interceptable,
|
163
|
+
metadata: metadata
|
164
|
+
}
|
165
|
+
if return_op
|
166
|
+
# return the operation view of the active_call; define #execute as a
|
167
|
+
# new method for this instance that invokes #request_response.
|
168
|
+
c.merge_metadata_to_send(metadata)
|
169
|
+
op = c.operation
|
170
|
+
op.define_singleton_method(:execute) do
|
171
|
+
interception_context.intercept!(:request_response, intercept_args) do
|
172
|
+
c.request_response(req, metadata: metadata)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
op
|
176
|
+
else
|
177
|
+
interception_context.intercept!(:request_response, intercept_args) do
|
178
|
+
c.request_response(req, metadata: metadata)
|
179
|
+
end
|
160
180
|
end
|
161
|
-
op
|
162
181
|
end
|
163
182
|
|
164
183
|
# client_streamer sends a stream of requests to a GRPC server, and
|
@@ -213,16 +232,29 @@ module GRPC
|
|
213
232
|
deadline: deadline,
|
214
233
|
parent: parent,
|
215
234
|
credentials: credentials)
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
235
|
+
interception_context = @interceptors.build_context
|
236
|
+
intercept_args = {
|
237
|
+
method: method,
|
238
|
+
requests: requests,
|
239
|
+
call: c.interceptable,
|
240
|
+
metadata: metadata
|
241
|
+
}
|
242
|
+
if return_op
|
243
|
+
# return the operation view of the active_call; define #execute as a
|
244
|
+
# new method for this instance that invokes #client_streamer.
|
245
|
+
c.merge_metadata_to_send(metadata)
|
246
|
+
op = c.operation
|
247
|
+
op.define_singleton_method(:execute) do
|
248
|
+
interception_context.intercept!(:client_streamer, intercept_args) do
|
249
|
+
c.client_streamer(requests)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
op
|
253
|
+
else
|
254
|
+
interception_context.intercept!(:client_streamer, intercept_args) do
|
255
|
+
c.client_streamer(requests, metadata: metadata)
|
256
|
+
end
|
224
257
|
end
|
225
|
-
op
|
226
258
|
end
|
227
259
|
|
228
260
|
# server_streamer sends one request to the GRPC server, which yields a
|
@@ -292,16 +324,29 @@ module GRPC
|
|
292
324
|
deadline: deadline,
|
293
325
|
parent: parent,
|
294
326
|
credentials: credentials)
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
327
|
+
interception_context = @interceptors.build_context
|
328
|
+
intercept_args = {
|
329
|
+
method: method,
|
330
|
+
request: req,
|
331
|
+
call: c.interceptable,
|
332
|
+
metadata: metadata
|
333
|
+
}
|
334
|
+
if return_op
|
335
|
+
# return the operation view of the active_call; define #execute
|
336
|
+
# as a new method for this instance that invokes #server_streamer
|
337
|
+
c.merge_metadata_to_send(metadata)
|
338
|
+
op = c.operation
|
339
|
+
op.define_singleton_method(:execute) do
|
340
|
+
interception_context.intercept!(:server_streamer, intercept_args) do
|
341
|
+
c.server_streamer(req, &blk)
|
342
|
+
end
|
343
|
+
end
|
344
|
+
op
|
345
|
+
else
|
346
|
+
interception_context.intercept!(:server_streamer, intercept_args) do
|
347
|
+
c.server_streamer(req, metadata: metadata, &blk)
|
348
|
+
end
|
303
349
|
end
|
304
|
-
op
|
305
350
|
end
|
306
351
|
|
307
352
|
# bidi_streamer sends a stream of requests to the GRPC server, and yields
|
@@ -405,17 +450,29 @@ module GRPC
|
|
405
450
|
deadline: deadline,
|
406
451
|
parent: parent,
|
407
452
|
credentials: credentials)
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
453
|
+
interception_context = @interceptors.build_context
|
454
|
+
intercept_args = {
|
455
|
+
method: method,
|
456
|
+
requests: requests,
|
457
|
+
call: c.interceptable,
|
458
|
+
metadata: metadata
|
459
|
+
}
|
460
|
+
if return_op
|
461
|
+
# return the operation view of the active_call; define #execute
|
462
|
+
# as a new method for this instance that invokes #bidi_streamer
|
463
|
+
c.merge_metadata_to_send(metadata)
|
464
|
+
op = c.operation
|
465
|
+
op.define_singleton_method(:execute) do
|
466
|
+
interception_context.intercept!(:bidi_streamer, intercept_args) do
|
467
|
+
c.bidi_streamer(requests, &blk)
|
468
|
+
end
|
469
|
+
end
|
470
|
+
op
|
471
|
+
else
|
472
|
+
interception_context.intercept!(:bidi_streamer, intercept_args) do
|
473
|
+
c.bidi_streamer(requests, metadata: metadata, &blk)
|
474
|
+
end
|
417
475
|
end
|
418
|
-
op
|
419
476
|
end
|
420
477
|
|
421
478
|
private
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# Copyright 2017 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
# GRPC contains the General RPC module.
|
16
|
+
module GRPC
|
17
|
+
##
|
18
|
+
# Represents a registry of added interceptors available for enumeration.
|
19
|
+
# The registry can be used for both server and client interceptors.
|
20
|
+
# This class is internal to gRPC and not meant for public usage.
|
21
|
+
#
|
22
|
+
class InterceptorRegistry
|
23
|
+
##
|
24
|
+
# An error raised when an interceptor is attempted to be added
|
25
|
+
# that does not extend GRPC::Interceptor
|
26
|
+
#
|
27
|
+
class DescendantError < StandardError; end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Initialize the registry with an empty interceptor list
|
31
|
+
# This is an EXPERIMENTAL API.
|
32
|
+
#
|
33
|
+
def initialize(interceptors = [])
|
34
|
+
@interceptors = []
|
35
|
+
interceptors.each do |i|
|
36
|
+
base = GRPC::Interceptor
|
37
|
+
unless i.class.ancestors.include?(base)
|
38
|
+
fail DescendantError, "Interceptors must descend from #{base}"
|
39
|
+
end
|
40
|
+
@interceptors << i
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# Builds an interception context from this registry
|
46
|
+
#
|
47
|
+
# @return [InterceptionContext]
|
48
|
+
#
|
49
|
+
def build_context
|
50
|
+
InterceptionContext.new(@interceptors)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
# Copyright 2017 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
require_relative 'interceptor_registry'
|
15
|
+
|
16
|
+
# GRPC contains the General RPC module.
|
17
|
+
module GRPC
|
18
|
+
##
|
19
|
+
# Base class for interception in GRPC
|
20
|
+
#
|
21
|
+
class Interceptor
|
22
|
+
##
|
23
|
+
# @param [Hash] options A hash of options that will be used
|
24
|
+
# by the interceptor. This is an EXPERIMENTAL API.
|
25
|
+
#
|
26
|
+
def initialize(options = {})
|
27
|
+
@options = options || {}
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
##
|
32
|
+
# ClientInterceptor allows for wrapping outbound gRPC client stub requests.
|
33
|
+
# This is an EXPERIMENTAL API.
|
34
|
+
#
|
35
|
+
class ClientInterceptor < Interceptor
|
36
|
+
##
|
37
|
+
# Intercept a unary request response call
|
38
|
+
#
|
39
|
+
# @param [Object] request
|
40
|
+
# @param [GRPC::ActiveCall] call
|
41
|
+
# @param [Method] method
|
42
|
+
# @param [Hash] metadata
|
43
|
+
#
|
44
|
+
def request_response(request:, call:, method:, metadata:)
|
45
|
+
GRPC.logger.debug "Intercepting request response method #{method}" \
|
46
|
+
" for request #{request} with call #{call} and metadata: #{metadata}"
|
47
|
+
yield
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Intercept a client streaming call
|
52
|
+
#
|
53
|
+
# @param [Enumerable] requests
|
54
|
+
# @param [GRPC::ActiveCall] call
|
55
|
+
# @param [Method] method
|
56
|
+
# @param [Hash] metadata
|
57
|
+
#
|
58
|
+
def client_streamer(requests:, call:, method:, metadata:)
|
59
|
+
GRPC.logger.debug "Intercepting client streamer method #{method}" \
|
60
|
+
" for requests #{requests} with call #{call} and metadata: #{metadata}"
|
61
|
+
yield
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Intercept a server streaming call
|
66
|
+
#
|
67
|
+
# @param [Object] request
|
68
|
+
# @param [GRPC::ActiveCall] call
|
69
|
+
# @param [Method] method
|
70
|
+
# @param [Hash] metadata
|
71
|
+
#
|
72
|
+
def server_streamer(request:, call:, method:, metadata:)
|
73
|
+
GRPC.logger.debug "Intercepting server streamer method #{method}" \
|
74
|
+
" for request #{request} with call #{call} and metadata: #{metadata}"
|
75
|
+
yield
|
76
|
+
end
|
77
|
+
|
78
|
+
##
|
79
|
+
# Intercept a BiDi streaming call
|
80
|
+
#
|
81
|
+
# @param [Enumerable] requests
|
82
|
+
# @param [GRPC::ActiveCall] call
|
83
|
+
# @param [Method] method
|
84
|
+
# @param [Hash] metadata
|
85
|
+
#
|
86
|
+
def bidi_streamer(requests:, call:, method:, metadata:)
|
87
|
+
GRPC.logger.debug "Intercepting bidi streamer method #{method}" \
|
88
|
+
" for requests #{requests} with call #{call} and metadata: #{metadata}"
|
89
|
+
yield
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# ServerInterceptor allows for wrapping gRPC server execution handling.
|
95
|
+
# This is an EXPERIMENTAL API.
|
96
|
+
#
|
97
|
+
class ServerInterceptor < Interceptor
|
98
|
+
##
|
99
|
+
# Intercept a unary request response call.
|
100
|
+
#
|
101
|
+
# @param [Object] request
|
102
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
103
|
+
# @param [Method] method
|
104
|
+
#
|
105
|
+
def request_response(request:, call:, method:)
|
106
|
+
GRPC.logger.debug "Intercepting request response method #{method}" \
|
107
|
+
" for request #{request} with call #{call}"
|
108
|
+
yield
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Intercept a client streaming call
|
113
|
+
#
|
114
|
+
# @param [GRPC::ActiveCall::MultiReqView] call
|
115
|
+
# @param [Method] method
|
116
|
+
#
|
117
|
+
def client_streamer(call:, method:)
|
118
|
+
GRPC.logger.debug "Intercepting client streamer method #{method}" \
|
119
|
+
" with call #{call}"
|
120
|
+
yield
|
121
|
+
end
|
122
|
+
|
123
|
+
##
|
124
|
+
# Intercept a server streaming call
|
125
|
+
#
|
126
|
+
# @param [Object] request
|
127
|
+
# @param [GRPC::ActiveCall::SingleReqView] call
|
128
|
+
# @param [Method] method
|
129
|
+
#
|
130
|
+
def server_streamer(request:, call:, method:)
|
131
|
+
GRPC.logger.debug "Intercepting server streamer method #{method}" \
|
132
|
+
" for request #{request} with call #{call}"
|
133
|
+
yield
|
134
|
+
end
|
135
|
+
|
136
|
+
##
|
137
|
+
# Intercept a BiDi streaming call
|
138
|
+
#
|
139
|
+
# @param [Enumerable<Object>] requests
|
140
|
+
# @param [GRPC::ActiveCall::MultiReqView] call
|
141
|
+
# @param [Method] method
|
142
|
+
#
|
143
|
+
def bidi_streamer(requests:, call:, method:)
|
144
|
+
GRPC.logger.debug "Intercepting bidi streamer method #{method}" \
|
145
|
+
" for requests #{requests} with call #{call}"
|
146
|
+
yield
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
##
|
151
|
+
# Represents the context in which an interceptor runs. Used to provide an
|
152
|
+
# injectable mechanism for handling interception. This is an EXPERIMENTAL API.
|
153
|
+
#
|
154
|
+
class InterceptionContext
|
155
|
+
##
|
156
|
+
# @param [Array<GRPC::Interceptor>]
|
157
|
+
#
|
158
|
+
def initialize(interceptors = [])
|
159
|
+
@interceptors = interceptors.dup
|
160
|
+
end
|
161
|
+
|
162
|
+
##
|
163
|
+
# Intercept the call and fire out to interceptors in a FIFO execution.
|
164
|
+
# This is an EXPERIMENTAL API.
|
165
|
+
#
|
166
|
+
# @param [Symbol] type The request type
|
167
|
+
# @param [Hash] args The arguments for the call
|
168
|
+
#
|
169
|
+
def intercept!(type, args = {})
|
170
|
+
return yield if @interceptors.none?
|
171
|
+
|
172
|
+
i = @interceptors.pop
|
173
|
+
return yield unless i
|
174
|
+
|
175
|
+
i.send(type, args) do
|
176
|
+
if @interceptors.any?
|
177
|
+
intercept!(type, args) do
|
178
|
+
yield
|
179
|
+
end
|
180
|
+
else
|
181
|
+
yield
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|