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
@@ -34,7 +34,7 @@
|
|
34
34
|
#include "src/core/lib/slice/slice_internal.h"
|
35
35
|
#include "src/core/lib/slice/slice_string_helpers.h"
|
36
36
|
#include "src/core/lib/support/string.h"
|
37
|
-
#include "src/core/tsi/
|
37
|
+
#include "src/core/tsi/transport_security_grpc.h"
|
38
38
|
|
39
39
|
#define STAGING_BUFFER_SIZE 8192
|
40
40
|
|
@@ -42,6 +42,7 @@ typedef struct {
|
|
42
42
|
grpc_endpoint base;
|
43
43
|
grpc_endpoint *wrapped_ep;
|
44
44
|
struct tsi_frame_protector *protector;
|
45
|
+
struct tsi_zero_copy_grpc_protector *zero_copy_protector;
|
45
46
|
gpr_mu protector_mu;
|
46
47
|
/* saved upper level callbacks and user_data. */
|
47
48
|
grpc_closure *read_cb;
|
@@ -67,6 +68,7 @@ static void destroy(grpc_exec_ctx *exec_ctx, secure_endpoint *secure_ep) {
|
|
67
68
|
secure_endpoint *ep = secure_ep;
|
68
69
|
grpc_endpoint_destroy(exec_ctx, ep->wrapped_ep);
|
69
70
|
tsi_frame_protector_destroy(ep->protector);
|
71
|
+
tsi_zero_copy_grpc_protector_destroy(exec_ctx, ep->zero_copy_protector);
|
70
72
|
grpc_slice_buffer_destroy_internal(exec_ctx, &ep->leftover_bytes);
|
71
73
|
grpc_slice_unref_internal(exec_ctx, ep->read_staging_buffer);
|
72
74
|
grpc_slice_unref_internal(exec_ctx, ep->write_staging_buffer);
|
@@ -159,51 +161,58 @@ static void on_read(grpc_exec_ctx *exec_ctx, void *user_data,
|
|
159
161
|
return;
|
160
162
|
}
|
161
163
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
164
|
+
if (ep->zero_copy_protector != NULL) {
|
165
|
+
// Use zero-copy grpc protector to unprotect.
|
166
|
+
result = tsi_zero_copy_grpc_protector_unprotect(
|
167
|
+
exec_ctx, ep->zero_copy_protector, &ep->source_buffer, ep->read_buffer);
|
168
|
+
} else {
|
169
|
+
// Use frame protector to unprotect.
|
170
|
+
/* TODO(yangg) check error, maybe bail out early */
|
171
|
+
for (i = 0; i < ep->source_buffer.count; i++) {
|
172
|
+
grpc_slice encrypted = ep->source_buffer.slices[i];
|
173
|
+
uint8_t *message_bytes = GRPC_SLICE_START_PTR(encrypted);
|
174
|
+
size_t message_size = GRPC_SLICE_LENGTH(encrypted);
|
175
|
+
|
176
|
+
while (message_size > 0 || keep_looping) {
|
177
|
+
size_t unprotected_buffer_size_written = (size_t)(end - cur);
|
178
|
+
size_t processed_message_size = message_size;
|
179
|
+
gpr_mu_lock(&ep->protector_mu);
|
180
|
+
result = tsi_frame_protector_unprotect(
|
181
|
+
ep->protector, message_bytes, &processed_message_size, cur,
|
182
|
+
&unprotected_buffer_size_written);
|
183
|
+
gpr_mu_unlock(&ep->protector_mu);
|
184
|
+
if (result != TSI_OK) {
|
185
|
+
gpr_log(GPR_ERROR, "Decryption error: %s",
|
186
|
+
tsi_result_to_string(result));
|
187
|
+
break;
|
188
|
+
}
|
189
|
+
message_bytes += processed_message_size;
|
190
|
+
message_size -= processed_message_size;
|
191
|
+
cur += unprotected_buffer_size_written;
|
192
|
+
|
193
|
+
if (cur == end) {
|
194
|
+
flush_read_staging_buffer(ep, &cur, &end);
|
195
|
+
/* Force to enter the loop again to extract buffered bytes in
|
196
|
+
protector. The bytes could be buffered because of running out of
|
197
|
+
staging_buffer. If this happens at the end of all slices, doing
|
198
|
+
another unprotect avoids leaving data in the protector. */
|
199
|
+
keep_looping = 1;
|
200
|
+
} else if (unprotected_buffer_size_written > 0) {
|
201
|
+
keep_looping = 1;
|
202
|
+
} else {
|
203
|
+
keep_looping = 0;
|
204
|
+
}
|
196
205
|
}
|
206
|
+
if (result != TSI_OK) break;
|
197
207
|
}
|
198
|
-
if (result != TSI_OK) break;
|
199
|
-
}
|
200
208
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
209
|
+
if (cur != GRPC_SLICE_START_PTR(ep->read_staging_buffer)) {
|
210
|
+
grpc_slice_buffer_add(
|
211
|
+
ep->read_buffer,
|
212
|
+
grpc_slice_split_head(
|
213
|
+
&ep->read_staging_buffer,
|
214
|
+
(size_t)(cur - GRPC_SLICE_START_PTR(ep->read_staging_buffer))));
|
215
|
+
}
|
207
216
|
}
|
208
217
|
|
209
218
|
/* TODO(yangg) experiment with moving this block after read_cb to see if it
|
@@ -270,54 +279,62 @@ static void endpoint_write(grpc_exec_ctx *exec_ctx, grpc_endpoint *secure_ep,
|
|
270
279
|
}
|
271
280
|
}
|
272
281
|
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
282
|
+
if (ep->zero_copy_protector != NULL) {
|
283
|
+
// Use zero-copy grpc protector to protect.
|
284
|
+
result = tsi_zero_copy_grpc_protector_protect(
|
285
|
+
exec_ctx, ep->zero_copy_protector, slices, &ep->output_buffer);
|
286
|
+
} else {
|
287
|
+
// Use frame protector to protect.
|
288
|
+
for (i = 0; i < slices->count; i++) {
|
289
|
+
grpc_slice plain = slices->slices[i];
|
290
|
+
uint8_t *message_bytes = GRPC_SLICE_START_PTR(plain);
|
291
|
+
size_t message_size = GRPC_SLICE_LENGTH(plain);
|
292
|
+
while (message_size > 0) {
|
293
|
+
size_t protected_buffer_size_to_send = (size_t)(end - cur);
|
294
|
+
size_t processed_message_size = message_size;
|
295
|
+
gpr_mu_lock(&ep->protector_mu);
|
296
|
+
result = tsi_frame_protector_protect(ep->protector, message_bytes,
|
297
|
+
&processed_message_size, cur,
|
298
|
+
&protected_buffer_size_to_send);
|
299
|
+
gpr_mu_unlock(&ep->protector_mu);
|
300
|
+
if (result != TSI_OK) {
|
301
|
+
gpr_log(GPR_ERROR, "Encryption error: %s",
|
302
|
+
tsi_result_to_string(result));
|
303
|
+
break;
|
304
|
+
}
|
305
|
+
message_bytes += processed_message_size;
|
306
|
+
message_size -= processed_message_size;
|
307
|
+
cur += protected_buffer_size_to_send;
|
308
|
+
|
309
|
+
if (cur == end) {
|
310
|
+
flush_write_staging_buffer(ep, &cur, &end);
|
311
|
+
}
|
296
312
|
}
|
297
|
-
}
|
298
|
-
if (result != TSI_OK) break;
|
299
|
-
}
|
300
|
-
if (result == TSI_OK) {
|
301
|
-
size_t still_pending_size;
|
302
|
-
do {
|
303
|
-
size_t protected_buffer_size_to_send = (size_t)(end - cur);
|
304
|
-
gpr_mu_lock(&ep->protector_mu);
|
305
|
-
result = tsi_frame_protector_protect_flush(ep->protector, cur,
|
306
|
-
&protected_buffer_size_to_send,
|
307
|
-
&still_pending_size);
|
308
|
-
gpr_mu_unlock(&ep->protector_mu);
|
309
313
|
if (result != TSI_OK) break;
|
310
|
-
|
311
|
-
|
312
|
-
|
314
|
+
}
|
315
|
+
if (result == TSI_OK) {
|
316
|
+
size_t still_pending_size;
|
317
|
+
do {
|
318
|
+
size_t protected_buffer_size_to_send = (size_t)(end - cur);
|
319
|
+
gpr_mu_lock(&ep->protector_mu);
|
320
|
+
result = tsi_frame_protector_protect_flush(
|
321
|
+
ep->protector, cur, &protected_buffer_size_to_send,
|
322
|
+
&still_pending_size);
|
323
|
+
gpr_mu_unlock(&ep->protector_mu);
|
324
|
+
if (result != TSI_OK) break;
|
325
|
+
cur += protected_buffer_size_to_send;
|
326
|
+
if (cur == end) {
|
327
|
+
flush_write_staging_buffer(ep, &cur, &end);
|
328
|
+
}
|
329
|
+
} while (still_pending_size > 0);
|
330
|
+
if (cur != GRPC_SLICE_START_PTR(ep->write_staging_buffer)) {
|
331
|
+
grpc_slice_buffer_add(
|
332
|
+
&ep->output_buffer,
|
333
|
+
grpc_slice_split_head(
|
334
|
+
&ep->write_staging_buffer,
|
335
|
+
(size_t)(cur -
|
336
|
+
GRPC_SLICE_START_PTR(ep->write_staging_buffer))));
|
313
337
|
}
|
314
|
-
} while (still_pending_size > 0);
|
315
|
-
if (cur != GRPC_SLICE_START_PTR(ep->write_staging_buffer)) {
|
316
|
-
grpc_slice_buffer_add(
|
317
|
-
&ep->output_buffer,
|
318
|
-
grpc_slice_split_head(
|
319
|
-
&ep->write_staging_buffer,
|
320
|
-
(size_t)(cur - GRPC_SLICE_START_PTR(ep->write_staging_buffer))));
|
321
338
|
}
|
322
339
|
}
|
323
340
|
|
@@ -389,13 +406,16 @@ static const grpc_endpoint_vtable vtable = {endpoint_read,
|
|
389
406
|
endpoint_get_fd};
|
390
407
|
|
391
408
|
grpc_endpoint *grpc_secure_endpoint_create(
|
392
|
-
struct tsi_frame_protector *protector,
|
393
|
-
|
409
|
+
struct tsi_frame_protector *protector,
|
410
|
+
struct tsi_zero_copy_grpc_protector *zero_copy_protector,
|
411
|
+
grpc_endpoint *transport, grpc_slice *leftover_slices,
|
412
|
+
size_t leftover_nslices) {
|
394
413
|
size_t i;
|
395
414
|
secure_endpoint *ep = (secure_endpoint *)gpr_malloc(sizeof(secure_endpoint));
|
396
415
|
ep->base.vtable = &vtable;
|
397
416
|
ep->wrapped_ep = transport;
|
398
417
|
ep->protector = protector;
|
418
|
+
ep->zero_copy_protector = zero_copy_protector;
|
399
419
|
grpc_slice_buffer_init(&ep->leftover_bytes);
|
400
420
|
for (i = 0; i < leftover_nslices; i++) {
|
401
421
|
grpc_slice_buffer_add(&ep->leftover_bytes,
|
@@ -23,12 +23,17 @@
|
|
23
23
|
#include "src/core/lib/iomgr/endpoint.h"
|
24
24
|
|
25
25
|
struct tsi_frame_protector;
|
26
|
+
struct tsi_zero_copy_grpc_protector;
|
26
27
|
|
27
28
|
extern grpc_tracer_flag grpc_trace_secure_endpoint;
|
28
29
|
|
29
|
-
/* Takes ownership of protector and to_wrap, and refs
|
30
|
+
/* Takes ownership of protector, zero_copy_protector, and to_wrap, and refs
|
31
|
+
* leftover_slices. If zero_copy_protector is not NULL, protector will never be
|
32
|
+
* used. */
|
30
33
|
grpc_endpoint *grpc_secure_endpoint_create(
|
31
|
-
struct tsi_frame_protector *protector,
|
32
|
-
|
34
|
+
struct tsi_frame_protector *protector,
|
35
|
+
struct tsi_zero_copy_grpc_protector *zero_copy_protector,
|
36
|
+
grpc_endpoint *to_wrap, grpc_slice *leftover_slices,
|
37
|
+
size_t leftover_nslices);
|
33
38
|
|
34
39
|
#endif /* GRPC_CORE_LIB_SECURITY_TRANSPORT_SECURE_ENDPOINT_H */
|
@@ -455,14 +455,14 @@ grpc_server_security_connector *grpc_fake_server_security_connector_create(
|
|
455
455
|
|
456
456
|
typedef struct {
|
457
457
|
grpc_channel_security_connector base;
|
458
|
-
tsi_ssl_client_handshaker_factory *
|
458
|
+
tsi_ssl_client_handshaker_factory *client_handshaker_factory;
|
459
459
|
char *target_name;
|
460
460
|
char *overridden_target_name;
|
461
461
|
} grpc_ssl_channel_security_connector;
|
462
462
|
|
463
463
|
typedef struct {
|
464
464
|
grpc_server_security_connector base;
|
465
|
-
tsi_ssl_server_handshaker_factory *
|
465
|
+
tsi_ssl_server_handshaker_factory *server_handshaker_factory;
|
466
466
|
} grpc_ssl_server_security_connector;
|
467
467
|
|
468
468
|
static void ssl_channel_destroy(grpc_exec_ctx *exec_ctx,
|
@@ -470,9 +470,8 @@ static void ssl_channel_destroy(grpc_exec_ctx *exec_ctx,
|
|
470
470
|
grpc_ssl_channel_security_connector *c =
|
471
471
|
(grpc_ssl_channel_security_connector *)sc;
|
472
472
|
grpc_call_credentials_unref(exec_ctx, c->base.request_metadata_creds);
|
473
|
-
|
474
|
-
|
475
|
-
}
|
473
|
+
tsi_ssl_client_handshaker_factory_unref(c->client_handshaker_factory);
|
474
|
+
c->client_handshaker_factory = NULL;
|
476
475
|
if (c->target_name != NULL) gpr_free(c->target_name);
|
477
476
|
if (c->overridden_target_name != NULL) gpr_free(c->overridden_target_name);
|
478
477
|
gpr_free(sc);
|
@@ -482,9 +481,8 @@ static void ssl_server_destroy(grpc_exec_ctx *exec_ctx,
|
|
482
481
|
grpc_security_connector *sc) {
|
483
482
|
grpc_ssl_server_security_connector *c =
|
484
483
|
(grpc_ssl_server_security_connector *)sc;
|
485
|
-
|
486
|
-
|
487
|
-
}
|
484
|
+
tsi_ssl_server_handshaker_factory_unref(c->server_handshaker_factory);
|
485
|
+
c->server_handshaker_factory = NULL;
|
488
486
|
gpr_free(sc);
|
489
487
|
}
|
490
488
|
|
@@ -496,7 +494,7 @@ static void ssl_channel_add_handshakers(grpc_exec_ctx *exec_ctx,
|
|
496
494
|
// Instantiate TSI handshaker.
|
497
495
|
tsi_handshaker *tsi_hs = NULL;
|
498
496
|
tsi_result result = tsi_ssl_client_handshaker_factory_create_handshaker(
|
499
|
-
c->
|
497
|
+
c->client_handshaker_factory,
|
500
498
|
c->overridden_target_name != NULL ? c->overridden_target_name
|
501
499
|
: c->target_name,
|
502
500
|
&tsi_hs);
|
@@ -521,7 +519,7 @@ static void ssl_server_add_handshakers(grpc_exec_ctx *exec_ctx,
|
|
521
519
|
// Instantiate TSI handshaker.
|
522
520
|
tsi_handshaker *tsi_hs = NULL;
|
523
521
|
tsi_result result = tsi_ssl_server_handshaker_factory_create_handshaker(
|
524
|
-
c->
|
522
|
+
c->server_handshaker_factory, &tsi_hs);
|
525
523
|
if (result != TSI_OK) {
|
526
524
|
gpr_log(GPR_ERROR, "Handshaker creation failed with error %s.",
|
527
525
|
tsi_result_to_string(result));
|
@@ -852,7 +850,7 @@ grpc_security_status grpc_ssl_channel_security_connector_create(
|
|
852
850
|
result = tsi_create_ssl_client_handshaker_factory(
|
853
851
|
has_key_cert_pair ? &config->pem_key_cert_pair : NULL, pem_root_certs,
|
854
852
|
ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
|
855
|
-
&c->
|
853
|
+
&c->client_handshaker_factory);
|
856
854
|
if (result != TSI_OK) {
|
857
855
|
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
|
858
856
|
tsi_result_to_string(result));
|
@@ -897,7 +895,7 @@ grpc_security_status grpc_ssl_server_security_connector_create(
|
|
897
895
|
config->pem_root_certs, get_tsi_client_certificate_request_type(
|
898
896
|
config->client_certificate_request),
|
899
897
|
ssl_cipher_suites(), alpn_protocol_strings, (uint16_t)num_alpn_protocols,
|
900
|
-
&c->
|
898
|
+
&c->server_handshaker_factory);
|
901
899
|
if (result != TSI_OK) {
|
902
900
|
gpr_log(GPR_ERROR, "Handshaker factory creation failed with %s.",
|
903
901
|
tsi_result_to_string(result));
|
@@ -32,6 +32,7 @@
|
|
32
32
|
#include "src/core/lib/security/transport/secure_endpoint.h"
|
33
33
|
#include "src/core/lib/security/transport/tsi_error.h"
|
34
34
|
#include "src/core/lib/slice/slice_internal.h"
|
35
|
+
#include "src/core/tsi/transport_security_grpc.h"
|
35
36
|
|
36
37
|
#define GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE 256
|
37
38
|
|
@@ -127,24 +128,36 @@ static void security_handshake_failed_locked(grpc_exec_ctx *exec_ctx,
|
|
127
128
|
GRPC_CLOSURE_SCHED(exec_ctx, h->on_handshake_done, error);
|
128
129
|
}
|
129
130
|
|
130
|
-
static void
|
131
|
-
|
132
|
-
security_handshaker *h = arg;
|
133
|
-
gpr_mu_lock(&h->mu);
|
131
|
+
static void on_peer_checked_inner(grpc_exec_ctx *exec_ctx,
|
132
|
+
security_handshaker *h, grpc_error *error) {
|
134
133
|
if (error != GRPC_ERROR_NONE || h->shutdown) {
|
135
134
|
security_handshake_failed_locked(exec_ctx, h, GRPC_ERROR_REF(error));
|
136
|
-
|
135
|
+
return;
|
137
136
|
}
|
138
|
-
// Create frame protector.
|
139
|
-
|
140
|
-
tsi_result result =
|
141
|
-
h->handshaker_result, NULL, &
|
142
|
-
if (result != TSI_OK) {
|
137
|
+
// Create zero-copy frame protector, if implemented.
|
138
|
+
tsi_zero_copy_grpc_protector *zero_copy_protector = NULL;
|
139
|
+
tsi_result result = tsi_handshaker_result_create_zero_copy_grpc_protector(
|
140
|
+
exec_ctx, h->handshaker_result, NULL, &zero_copy_protector);
|
141
|
+
if (result != TSI_OK && result != TSI_UNIMPLEMENTED) {
|
143
142
|
error = grpc_set_tsi_error_result(
|
144
|
-
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
143
|
+
GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
144
|
+
"Zero-copy frame protector creation failed"),
|
145
145
|
result);
|
146
146
|
security_handshake_failed_locked(exec_ctx, h, error);
|
147
|
-
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
// Create frame protector if zero-copy frame protector is NULL.
|
150
|
+
tsi_frame_protector *protector = NULL;
|
151
|
+
if (zero_copy_protector == NULL) {
|
152
|
+
result = tsi_handshaker_result_create_frame_protector(h->handshaker_result,
|
153
|
+
NULL, &protector);
|
154
|
+
if (result != TSI_OK) {
|
155
|
+
error = grpc_set_tsi_error_result(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|
156
|
+
"Frame protector creation failed"),
|
157
|
+
result);
|
158
|
+
security_handshake_failed_locked(exec_ctx, h, error);
|
159
|
+
return;
|
160
|
+
}
|
148
161
|
}
|
149
162
|
// Get unused bytes.
|
150
163
|
const unsigned char *unused_bytes = NULL;
|
@@ -155,12 +168,12 @@ static void on_peer_checked(grpc_exec_ctx *exec_ctx, void *arg,
|
|
155
168
|
if (unused_bytes_size > 0) {
|
156
169
|
grpc_slice slice =
|
157
170
|
grpc_slice_from_copied_buffer((char *)unused_bytes, unused_bytes_size);
|
158
|
-
h->args->endpoint =
|
159
|
-
|
171
|
+
h->args->endpoint = grpc_secure_endpoint_create(
|
172
|
+
protector, zero_copy_protector, h->args->endpoint, &slice, 1);
|
160
173
|
grpc_slice_unref_internal(exec_ctx, slice);
|
161
174
|
} else {
|
162
|
-
h->args->endpoint =
|
163
|
-
|
175
|
+
h->args->endpoint = grpc_secure_endpoint_create(
|
176
|
+
protector, zero_copy_protector, h->args->endpoint, NULL, 0);
|
164
177
|
}
|
165
178
|
tsi_handshaker_result_destroy(h->handshaker_result);
|
166
179
|
h->handshaker_result = NULL;
|
@@ -177,7 +190,13 @@ static void on_peer_checked(grpc_exec_ctx *exec_ctx, void *arg,
|
|
177
190
|
// Set shutdown to true so that subsequent calls to
|
178
191
|
// security_handshaker_shutdown() do nothing.
|
179
192
|
h->shutdown = true;
|
180
|
-
|
193
|
+
}
|
194
|
+
|
195
|
+
static void on_peer_checked(grpc_exec_ctx *exec_ctx, void *arg,
|
196
|
+
grpc_error *error) {
|
197
|
+
security_handshaker *h = (security_handshaker *)arg;
|
198
|
+
gpr_mu_lock(&h->mu);
|
199
|
+
on_peer_checked_inner(exec_ctx, h, error);
|
181
200
|
gpr_mu_unlock(&h->mu);
|
182
201
|
security_handshaker_unref(exec_ctx, h);
|
183
202
|
}
|
@@ -239,7 +258,7 @@ static grpc_error *on_handshake_next_done_locked(
|
|
239
258
|
static void on_handshake_next_done_grpc_wrapper(
|
240
259
|
tsi_result result, void *user_data, const unsigned char *bytes_to_send,
|
241
260
|
size_t bytes_to_send_size, tsi_handshaker_result *handshaker_result) {
|
242
|
-
security_handshaker *h = user_data;
|
261
|
+
security_handshaker *h = (security_handshaker *)user_data;
|
243
262
|
// This callback will be invoked by TSI in a non-grpc thread, so it's
|
244
263
|
// safe to create our own exec_ctx here.
|
245
264
|
grpc_exec_ctx exec_ctx = GRPC_EXEC_CTX_INIT;
|
@@ -281,7 +300,7 @@ static grpc_error *do_handshaker_next_locked(
|
|
281
300
|
|
282
301
|
static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
|
283
302
|
void *arg, grpc_error *error) {
|
284
|
-
security_handshaker *h = arg;
|
303
|
+
security_handshaker *h = (security_handshaker *)arg;
|
285
304
|
gpr_mu_lock(&h->mu);
|
286
305
|
if (error != GRPC_ERROR_NONE || h->shutdown) {
|
287
306
|
security_handshake_failed_locked(
|
@@ -298,7 +317,8 @@ static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
|
|
298
317
|
bytes_received_size += GRPC_SLICE_LENGTH(h->args->read_buffer->slices[i]);
|
299
318
|
}
|
300
319
|
if (bytes_received_size > h->handshake_buffer_size) {
|
301
|
-
h->handshake_buffer =
|
320
|
+
h->handshake_buffer =
|
321
|
+
(uint8_t *)gpr_realloc(h->handshake_buffer, bytes_received_size);
|
302
322
|
h->handshake_buffer_size = bytes_received_size;
|
303
323
|
}
|
304
324
|
size_t offset = 0;
|
@@ -323,7 +343,7 @@ static void on_handshake_data_received_from_peer(grpc_exec_ctx *exec_ctx,
|
|
323
343
|
|
324
344
|
static void on_handshake_data_sent_to_peer(grpc_exec_ctx *exec_ctx, void *arg,
|
325
345
|
grpc_error *error) {
|
326
|
-
security_handshaker *h = arg;
|
346
|
+
security_handshaker *h = (security_handshaker *)arg;
|
327
347
|
gpr_mu_lock(&h->mu);
|
328
348
|
if (error != GRPC_ERROR_NONE || h->shutdown) {
|
329
349
|
security_handshake_failed_locked(
|
@@ -400,14 +420,15 @@ static const grpc_handshaker_vtable security_handshaker_vtable = {
|
|
400
420
|
static grpc_handshaker *security_handshaker_create(
|
401
421
|
grpc_exec_ctx *exec_ctx, tsi_handshaker *handshaker,
|
402
422
|
grpc_security_connector *connector) {
|
403
|
-
security_handshaker *h =
|
423
|
+
security_handshaker *h =
|
424
|
+
(security_handshaker *)gpr_zalloc(sizeof(security_handshaker));
|
404
425
|
grpc_handshaker_init(&security_handshaker_vtable, &h->base);
|
405
426
|
h->handshaker = handshaker;
|
406
427
|
h->connector = GRPC_SECURITY_CONNECTOR_REF(connector, "handshake");
|
407
428
|
gpr_mu_init(&h->mu);
|
408
429
|
gpr_ref_init(&h->refs, 1);
|
409
430
|
h->handshake_buffer_size = GRPC_INITIAL_HANDSHAKE_BUFFER_SIZE;
|
410
|
-
h->handshake_buffer = gpr_malloc(h->handshake_buffer_size);
|
431
|
+
h->handshake_buffer = (uint8_t *)gpr_malloc(h->handshake_buffer_size);
|
411
432
|
GRPC_CLOSURE_INIT(&h->on_handshake_data_sent_to_peer,
|
412
433
|
on_handshake_data_sent_to_peer, h,
|
413
434
|
grpc_schedule_on_exec_ctx);
|
@@ -450,7 +471,7 @@ static const grpc_handshaker_vtable fail_handshaker_vtable = {
|
|
450
471
|
fail_handshaker_do_handshake};
|
451
472
|
|
452
473
|
static grpc_handshaker *fail_handshaker_create() {
|
453
|
-
grpc_handshaker *h = gpr_malloc(sizeof(*h));
|
474
|
+
grpc_handshaker *h = (grpc_handshaker *)gpr_malloc(sizeof(*h));
|
454
475
|
grpc_handshaker_init(&fail_handshaker_vtable, h);
|
455
476
|
return h;
|
456
477
|
}
|