grpc 1.20.0 → 1.21.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of grpc might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/Makefile +500 -29
- data/etc/roots.pem +146 -0
- data/include/grpc/grpc_security.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +10 -7
- data/include/grpc/impl/codegen/port_platform.h +11 -1
- data/include/grpc/impl/codegen/slice.h +1 -21
- data/include/grpc/impl/codegen/status.h +2 -1
- data/include/grpc/slice.h +1 -1
- data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
- data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
- data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
- data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
- data/src/core/ext/filters/client_channel/service_config.cc +247 -27
- data/src/core/ext/filters/client_channel/service_config.h +119 -166
- data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
- data/src/core/ext/filters/client_channel/subchannel.h +7 -7
- data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
- data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
- data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
- data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
- data/src/core/lib/channel/channel_args.cc +0 -101
- data/src/core/lib/channel/channel_args.h +0 -37
- data/src/core/lib/channel/channel_stack.h +9 -5
- data/src/core/lib/channel/channelz_registry.cc +1 -1
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/handshaker.cc +4 -4
- data/src/core/lib/channel/handshaker.h +1 -1
- data/src/core/lib/compression/compression_args.cc +127 -0
- data/src/core/lib/compression/compression_args.h +55 -0
- data/src/core/lib/debug/trace.cc +13 -7
- data/src/core/lib/debug/trace.h +12 -0
- data/src/core/lib/gpr/arena.h +13 -9
- data/src/core/lib/gpr/env.h +2 -5
- data/src/core/lib/gpr/env_linux.cc +6 -1
- data/src/core/lib/gpr/env_posix.cc +5 -0
- data/src/core/lib/gpr/env_windows.cc +7 -5
- data/src/core/lib/gpr/log.cc +9 -13
- data/src/core/lib/gpr/string.cc +12 -6
- data/src/core/lib/gpr/string.h +4 -2
- data/src/core/lib/gpr/time_posix.cc +13 -0
- data/src/core/lib/gprpp/arena.cc +103 -0
- data/src/core/lib/gprpp/arena.h +121 -0
- data/src/core/lib/gprpp/fork.cc +12 -29
- data/src/core/lib/gprpp/global_config.h +87 -0
- data/src/core/lib/gprpp/global_config_custom.h +29 -0
- data/src/core/lib/gprpp/global_config_env.cc +135 -0
- data/src/core/lib/gprpp/global_config_env.h +131 -0
- data/src/core/lib/gprpp/global_config_generic.h +44 -0
- data/src/core/lib/gprpp/map.h +419 -0
- data/src/core/lib/gprpp/optional.h +1 -0
- data/src/core/lib/gprpp/orphanable.h +2 -2
- data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
- data/src/core/lib/gprpp/ref_counted.h +18 -2
- data/src/core/lib/gprpp/sync.h +126 -0
- data/src/core/lib/http/parser.cc +1 -1
- data/src/core/lib/iomgr/call_combiner.cc +84 -90
- data/src/core/lib/iomgr/call_combiner.h +75 -82
- data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
- data/src/core/lib/iomgr/cfstream_handle.h +82 -0
- data/src/core/lib/iomgr/combiner.h +1 -1
- data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
- data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
- data/src/core/lib/iomgr/error.h +23 -0
- data/src/core/lib/iomgr/error_cfstream.cc +52 -0
- data/src/core/lib/iomgr/error_cfstream.h +31 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
- data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
- data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
- data/src/core/lib/iomgr/ev_posix.cc +15 -13
- data/src/core/lib/iomgr/ev_posix.h +4 -1
- data/src/core/lib/iomgr/executor.cc +13 -9
- data/src/core/lib/iomgr/fork_posix.cc +0 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
- data/src/core/lib/iomgr/iomgr.cc +6 -5
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
- data/src/core/lib/iomgr/iomgr_custom.h +2 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
- data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
- data/src/core/lib/iomgr/lockfree_event.cc +3 -3
- data/src/core/lib/iomgr/port.h +11 -0
- data/src/core/lib/iomgr/resource_quota.cc +40 -37
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
- data/src/core/lib/iomgr/socket_windows.cc +19 -0
- data/src/core/lib/iomgr/socket_windows.h +8 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_custom.cc +9 -9
- data/src/core/lib/iomgr/tcp_posix.cc +41 -41
- data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
- data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_windows.cc +7 -9
- data/src/core/lib/iomgr/timer_generic.cc +16 -16
- data/src/core/lib/iomgr/timer_manager.cc +12 -11
- data/src/core/lib/profiling/basic_timers.cc +10 -4
- data/src/core/lib/security/context/security_context.cc +6 -7
- data/src/core/lib/security/context/security_context.h +3 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
- data/src/core/lib/security/security_connector/security_connector.cc +0 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
- data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
- data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
- data/src/core/lib/slice/slice.cc +99 -116
- data/src/core/lib/slice/slice_buffer.cc +5 -0
- data/src/core/lib/slice/slice_intern.cc +38 -95
- data/src/core/lib/slice/slice_internal.h +200 -2
- data/src/core/lib/surface/api_trace.h +1 -1
- data/src/core/lib/surface/call.cc +41 -35
- data/src/core/lib/surface/call.h +7 -2
- data/src/core/lib/surface/call_details.cc +0 -1
- data/src/core/lib/surface/completion_queue.cc +36 -27
- data/src/core/lib/surface/init.cc +3 -4
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/server.cc +18 -25
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/bdp_estimator.cc +3 -3
- data/src/core/lib/transport/bdp_estimator.h +2 -2
- data/src/core/lib/transport/connectivity_state.cc +10 -40
- data/src/core/lib/transport/connectivity_state.h +0 -8
- data/src/core/lib/transport/error_utils.cc +12 -0
- data/src/core/lib/transport/metadata.cc +206 -278
- data/src/core/lib/transport/metadata.h +205 -10
- data/src/core/lib/transport/static_metadata.cc +108 -116
- data/src/core/lib/transport/static_metadata.h +1 -2
- data/src/core/lib/transport/status_metadata.cc +3 -3
- data/src/core/lib/transport/transport.cc +29 -66
- data/src/core/lib/transport/transport.h +36 -8
- data/src/core/lib/transport/transport_impl.h +1 -1
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/lib/grpc/errors.rb +22 -3
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +141 -0
- metadata +57 -33
- data/src/core/lib/gpr/arena.cc +0 -192
@@ -459,7 +459,7 @@ grpc_call_credentials* grpc_google_refresh_token_credentials_create(
|
|
459
459
|
const char* json_refresh_token, void* reserved) {
|
460
460
|
grpc_auth_refresh_token token =
|
461
461
|
grpc_auth_refresh_token_create_from_string(json_refresh_token);
|
462
|
-
if (grpc_api_trace
|
462
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_api_trace)) {
|
463
463
|
char* loggable_token = create_loggable_refresh_token(&token);
|
464
464
|
gpr_log(GPR_INFO,
|
465
465
|
"grpc_refresh_token_credentials_create(json_refresh_token=%s, "
|
@@ -119,7 +119,7 @@ static void plugin_md_request_metadata_ready(void* request,
|
|
119
119
|
GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
|
120
120
|
grpc_plugin_credentials::pending_request* r =
|
121
121
|
static_cast<grpc_plugin_credentials::pending_request*>(request);
|
122
|
-
if (grpc_plugin_credentials_trace
|
122
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
123
123
|
gpr_log(GPR_INFO,
|
124
124
|
"plugin_credentials[%p]: request %p: plugin returned "
|
125
125
|
"asynchronously",
|
@@ -132,7 +132,7 @@ static void plugin_md_request_metadata_ready(void* request,
|
|
132
132
|
grpc_error* error =
|
133
133
|
process_plugin_result(r, md, num_md, status, error_details);
|
134
134
|
GRPC_CLOSURE_SCHED(r->on_request_metadata, error);
|
135
|
-
} else if (grpc_plugin_credentials_trace
|
135
|
+
} else if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
136
136
|
gpr_log(GPR_INFO,
|
137
137
|
"plugin_credentials[%p]: request %p: plugin was previously "
|
138
138
|
"cancelled",
|
@@ -162,7 +162,7 @@ bool grpc_plugin_credentials::get_request_metadata(
|
|
162
162
|
pending_requests_ = request;
|
163
163
|
gpr_mu_unlock(&mu_);
|
164
164
|
// Invoke the plugin. The callback holds a ref to us.
|
165
|
-
if (grpc_plugin_credentials_trace
|
165
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
166
166
|
gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
|
167
167
|
this, request);
|
168
168
|
}
|
@@ -174,7 +174,7 @@ bool grpc_plugin_credentials::get_request_metadata(
|
|
174
174
|
if (!plugin_.get_metadata(
|
175
175
|
plugin_.state, context, plugin_md_request_metadata_ready, request,
|
176
176
|
creds_md, &num_creds_md, &status, &error_details)) {
|
177
|
-
if (grpc_plugin_credentials_trace
|
177
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
178
178
|
gpr_log(GPR_INFO,
|
179
179
|
"plugin_credentials[%p]: request %p: plugin will return "
|
180
180
|
"asynchronously",
|
@@ -189,7 +189,7 @@ bool grpc_plugin_credentials::get_request_metadata(
|
|
189
189
|
// asynchronously by plugin_cancel_get_request_metadata(), so return
|
190
190
|
// false. Otherwise, process the result.
|
191
191
|
if (request->cancelled) {
|
192
|
-
if (grpc_plugin_credentials_trace
|
192
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
193
193
|
gpr_log(GPR_INFO,
|
194
194
|
"plugin_credentials[%p]: request %p was cancelled, error "
|
195
195
|
"will be returned asynchronously",
|
@@ -197,7 +197,7 @@ bool grpc_plugin_credentials::get_request_metadata(
|
|
197
197
|
}
|
198
198
|
retval = false;
|
199
199
|
} else {
|
200
|
-
if (grpc_plugin_credentials_trace
|
200
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
201
201
|
gpr_log(GPR_INFO,
|
202
202
|
"plugin_credentials[%p]: request %p: plugin returned "
|
203
203
|
"synchronously",
|
@@ -223,7 +223,7 @@ void grpc_plugin_credentials::cancel_get_request_metadata(
|
|
223
223
|
for (pending_request* pending_request = pending_requests_;
|
224
224
|
pending_request != nullptr; pending_request = pending_request->next) {
|
225
225
|
if (pending_request->md_array == md_array) {
|
226
|
-
if (grpc_plugin_credentials_trace
|
226
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_plugin_credentials_trace)) {
|
227
227
|
gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", this,
|
228
228
|
pending_request);
|
229
229
|
}
|
@@ -38,12 +38,15 @@
|
|
38
38
|
#include <grpc/support/log.h>
|
39
39
|
#include <grpc/support/string_util.h>
|
40
40
|
|
41
|
-
#include "src/core/lib/gpr/env.h"
|
42
41
|
#include "src/core/lib/gpr/string.h"
|
43
42
|
#include "src/core/lib/gpr/useful.h"
|
43
|
+
#include "src/core/lib/gprpp/global_config.h"
|
44
44
|
#include "src/core/lib/gprpp/inlined_vector.h"
|
45
45
|
#include "src/core/lib/iomgr/load_file.h"
|
46
46
|
|
47
|
+
GPR_GLOBAL_CONFIG_DEFINE_STRING(grpc_system_ssl_roots_dir, "",
|
48
|
+
"Custom directory to SSL Roots");
|
49
|
+
|
47
50
|
namespace grpc_core {
|
48
51
|
namespace {
|
49
52
|
|
@@ -139,10 +142,9 @@ grpc_slice CreateRootCertsBundle(const char* certs_directory) {
|
|
139
142
|
grpc_slice LoadSystemRootCerts() {
|
140
143
|
grpc_slice result = grpc_empty_slice();
|
141
144
|
// Prioritize user-specified custom directory if flag is set.
|
142
|
-
char
|
143
|
-
if (custom_dir
|
144
|
-
result = CreateRootCertsBundle(custom_dir);
|
145
|
-
gpr_free(custom_dir);
|
145
|
+
UniquePtr<char> custom_dir = GPR_GLOBAL_CONFIG_GET(grpc_system_ssl_roots_dir);
|
146
|
+
if (strlen(custom_dir.get()) > 0) {
|
147
|
+
result = CreateRootCertsBundle(custom_dir.get());
|
146
148
|
}
|
147
149
|
// If the custom directory is empty/invalid/not specified, fallback to
|
148
150
|
// distribution-specific directory.
|
@@ -28,7 +28,6 @@
|
|
28
28
|
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
29
29
|
#include "src/core/lib/channel/channel_args.h"
|
30
30
|
#include "src/core/lib/channel/handshaker.h"
|
31
|
-
#include "src/core/lib/gpr/env.h"
|
32
31
|
#include "src/core/lib/gpr/host_port.h"
|
33
32
|
#include "src/core/lib/gpr/string.h"
|
34
33
|
#include "src/core/lib/iomgr/load_file.h"
|
@@ -314,7 +314,6 @@ class grpc_ssl_server_security_connector
|
|
314
314
|
bool try_fetch_ssl_server_credentials() {
|
315
315
|
grpc_ssl_server_certificate_config* certificate_config = nullptr;
|
316
316
|
bool status;
|
317
|
-
|
318
317
|
if (!has_cert_config_fetcher()) return false;
|
319
318
|
|
320
319
|
grpc_ssl_server_credentials* server_creds =
|
@@ -374,7 +373,9 @@ class grpc_ssl_server_security_connector
|
|
374
373
|
options.num_alpn_protocols = static_cast<uint16_t>(num_alpn_protocols);
|
375
374
|
tsi_result result = tsi_create_ssl_server_handshaker_factory_with_options(
|
376
375
|
&options, &new_handshaker_factory);
|
377
|
-
|
376
|
+
grpc_tsi_ssl_pem_key_cert_pairs_destroy(
|
377
|
+
const_cast<tsi_ssl_pem_key_cert_pair*>(options.pem_key_cert_pairs),
|
378
|
+
options.num_key_cert_pairs);
|
378
379
|
gpr_free((void*)alpn_protocol_strings);
|
379
380
|
|
380
381
|
if (result != TSI_OK) {
|
@@ -27,9 +27,9 @@
|
|
27
27
|
|
28
28
|
#include "src/core/ext/transport/chttp2/alpn/alpn.h"
|
29
29
|
#include "src/core/lib/channel/channel_args.h"
|
30
|
-
#include "src/core/lib/gpr/env.h"
|
31
30
|
#include "src/core/lib/gpr/host_port.h"
|
32
31
|
#include "src/core/lib/gpr/string.h"
|
32
|
+
#include "src/core/lib/gprpp/global_config.h"
|
33
33
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
34
34
|
#include "src/core/lib/iomgr/load_file.h"
|
35
35
|
#include "src/core/lib/security/context/security_context.h"
|
@@ -45,11 +45,16 @@ static const char* installed_roots_path =
|
|
45
45
|
INSTALL_PREFIX "/share/grpc/roots.pem";
|
46
46
|
#endif
|
47
47
|
|
48
|
-
/**
|
48
|
+
/** Config variable that points to the default SSL roots file. This file
|
49
|
+
must be a PEM encoded file with all the roots such as the one that can be
|
50
|
+
downloaded from https://pki.google.com/roots.pem. */
|
51
|
+
GPR_GLOBAL_CONFIG_DEFINE_STRING(grpc_default_ssl_roots_file_path, "",
|
52
|
+
"Path to the default SSL roots file.");
|
53
|
+
|
54
|
+
/** Config variable used as a flag to enable/disable loading system root
|
49
55
|
certificates from the OS trust store. */
|
50
|
-
|
51
|
-
|
52
|
-
#endif
|
56
|
+
GPR_GLOBAL_CONFIG_DEFINE_BOOL(grpc_not_use_system_ssl_roots, false,
|
57
|
+
"Disable loading system root certificates.");
|
53
58
|
|
54
59
|
#ifndef TSI_OPENSSL_ALPN_SUPPORT
|
55
60
|
#define TSI_OPENSSL_ALPN_SUPPORT 1
|
@@ -65,20 +70,22 @@ void grpc_set_ssl_roots_override_callback(grpc_ssl_roots_override_callback cb) {
|
|
65
70
|
|
66
71
|
/* -- Cipher suites. -- */
|
67
72
|
|
68
|
-
/* Defines the cipher suites that we accept by default. All these cipher suites
|
69
|
-
are compliant with HTTP2. */
|
70
|
-
#define GRPC_SSL_CIPHER_SUITES \
|
71
|
-
"ECDHE-ECDSA-AES128-GCM-SHA256:" \
|
72
|
-
"ECDHE-ECDSA-AES256-GCM-SHA384:" \
|
73
|
-
"ECDHE-RSA-AES128-GCM-SHA256:" \
|
74
|
-
"ECDHE-RSA-AES256-GCM-SHA384"
|
75
|
-
|
76
73
|
static gpr_once cipher_suites_once = GPR_ONCE_INIT;
|
77
74
|
static const char* cipher_suites = nullptr;
|
78
75
|
|
76
|
+
// All cipher suites for default are compliant with HTTP2.
|
77
|
+
GPR_GLOBAL_CONFIG_DEFINE_STRING(
|
78
|
+
grpc_ssl_cipher_suites,
|
79
|
+
"ECDHE-ECDSA-AES128-GCM-SHA256:"
|
80
|
+
"ECDHE-ECDSA-AES256-GCM-SHA384:"
|
81
|
+
"ECDHE-RSA-AES128-GCM-SHA256:"
|
82
|
+
"ECDHE-RSA-AES256-GCM-SHA384",
|
83
|
+
"A colon separated list of cipher suites to use with OpenSSL")
|
84
|
+
|
79
85
|
static void init_cipher_suites(void) {
|
80
|
-
char
|
81
|
-
|
86
|
+
grpc_core::UniquePtr<char> value =
|
87
|
+
GPR_GLOBAL_CONFIG_GET(grpc_ssl_cipher_suites);
|
88
|
+
cipher_suites = value.release();
|
82
89
|
}
|
83
90
|
|
84
91
|
/* --- Util --- */
|
@@ -428,17 +435,14 @@ const char* DefaultSslRootStore::GetPemRootCerts() {
|
|
428
435
|
|
429
436
|
grpc_slice DefaultSslRootStore::ComputePemRootCerts() {
|
430
437
|
grpc_slice result = grpc_empty_slice();
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
GRPC_LOG_IF_ERROR("load_file",
|
440
|
-
grpc_load_file(default_root_certs_path, 1, &result));
|
441
|
-
gpr_free(default_root_certs_path);
|
438
|
+
const bool not_use_system_roots =
|
439
|
+
GPR_GLOBAL_CONFIG_GET(grpc_not_use_system_ssl_roots);
|
440
|
+
// First try to load the roots from the configuration.
|
441
|
+
UniquePtr<char> default_root_certs_path =
|
442
|
+
GPR_GLOBAL_CONFIG_GET(grpc_default_ssl_roots_file_path);
|
443
|
+
if (strlen(default_root_certs_path.get()) > 0) {
|
444
|
+
GRPC_LOG_IF_ERROR(
|
445
|
+
"load_file", grpc_load_file(default_root_certs_path.get(), 1, &result));
|
442
446
|
}
|
443
447
|
// Try overridden roots if needed.
|
444
448
|
grpc_ssl_roots_override_result ovrd_res = GRPC_SSL_ROOTS_OVERRIDE_FAIL;
|
@@ -26,6 +26,7 @@
|
|
26
26
|
#include <grpc/grpc_security.h>
|
27
27
|
#include <grpc/slice_buffer.h>
|
28
28
|
|
29
|
+
#include "src/core/lib/gprpp/global_config.h"
|
29
30
|
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
30
31
|
#include "src/core/lib/iomgr/error.h"
|
31
32
|
#include "src/core/lib/security/security_connector/security_connector.h"
|
@@ -33,7 +34,10 @@
|
|
33
34
|
#include "src/core/tsi/transport_security.h"
|
34
35
|
#include "src/core/tsi/transport_security_interface.h"
|
35
36
|
|
36
|
-
|
37
|
+
GPR_GLOBAL_CONFIG_DECLARE_STRING(grpc_default_ssl_roots_file_path);
|
38
|
+
GPR_GLOBAL_CONFIG_DECLARE_BOOL(grpc_not_use_system_ssl_roots);
|
39
|
+
|
40
|
+
/* --- Util --- */
|
37
41
|
|
38
42
|
/* --- URL schemes. --- */
|
39
43
|
#define GRPC_SSL_URL_SCHEME "https"
|
@@ -92,7 +92,7 @@ struct call_data {
|
|
92
92
|
}
|
93
93
|
|
94
94
|
grpc_call_stack* owning_call;
|
95
|
-
|
95
|
+
grpc_core::CallCombiner* call_combiner;
|
96
96
|
grpc_core::RefCountedPtr<grpc_call_credentials> creds;
|
97
97
|
grpc_slice host = grpc_empty_slice();
|
98
98
|
grpc_slice method = grpc_empty_slice();
|
@@ -270,11 +270,9 @@ static void send_security_metadata(grpc_call_element* elem,
|
|
270
270
|
GRPC_ERROR_UNREF(error);
|
271
271
|
} else {
|
272
272
|
// Async return; register cancellation closure with call combiner.
|
273
|
-
|
274
|
-
calld->
|
275
|
-
|
276
|
-
cancel_get_request_metadata, elem,
|
277
|
-
grpc_schedule_on_exec_ctx));
|
273
|
+
calld->call_combiner->SetNotifyOnCancel(GRPC_CLOSURE_INIT(
|
274
|
+
&calld->get_request_metadata_cancel_closure,
|
275
|
+
cancel_get_request_metadata, elem, grpc_schedule_on_exec_ctx));
|
278
276
|
}
|
279
277
|
}
|
280
278
|
|
@@ -345,11 +343,9 @@ static void auth_start_transport_stream_op_batch(
|
|
345
343
|
GRPC_ERROR_UNREF(error);
|
346
344
|
} else {
|
347
345
|
// Async return; register cancellation closure with call combiner.
|
348
|
-
|
349
|
-
calld->
|
350
|
-
|
351
|
-
cancel_check_call_host, elem,
|
352
|
-
grpc_schedule_on_exec_ctx));
|
346
|
+
calld->call_combiner->SetNotifyOnCancel(GRPC_CLOSURE_INIT(
|
347
|
+
&calld->check_call_host_cancel_closure, cancel_check_call_host,
|
348
|
+
elem, grpc_schedule_on_exec_ctx));
|
353
349
|
}
|
354
350
|
gpr_free(call_host);
|
355
351
|
return; /* early exit */
|
@@ -113,7 +113,7 @@ static void destroy(secure_endpoint* ep) { grpc_core::Delete(ep); }
|
|
113
113
|
secure_endpoint_ref((ep), (reason), __FILE__, __LINE__)
|
114
114
|
static void secure_endpoint_unref(secure_endpoint* ep, const char* reason,
|
115
115
|
const char* file, int line) {
|
116
|
-
if (grpc_trace_secure_endpoint
|
116
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_secure_endpoint)) {
|
117
117
|
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
|
118
118
|
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
119
119
|
"SECENDP unref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
|
@@ -126,7 +126,7 @@ static void secure_endpoint_unref(secure_endpoint* ep, const char* reason,
|
|
126
126
|
|
127
127
|
static void secure_endpoint_ref(secure_endpoint* ep, const char* reason,
|
128
128
|
const char* file, int line) {
|
129
|
-
if (grpc_trace_secure_endpoint
|
129
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_secure_endpoint)) {
|
130
130
|
gpr_atm val = gpr_atm_no_barrier_load(&ep->ref.count);
|
131
131
|
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
132
132
|
"SECENDP ref %p : %s %" PRIdPTR " -> %" PRIdPTR, ep, reason, val,
|
@@ -155,7 +155,7 @@ static void flush_read_staging_buffer(secure_endpoint* ep, uint8_t** cur,
|
|
155
155
|
}
|
156
156
|
|
157
157
|
static void call_read_cb(secure_endpoint* ep, grpc_error* error) {
|
158
|
-
if (grpc_trace_secure_endpoint
|
158
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_secure_endpoint)) {
|
159
159
|
size_t i;
|
160
160
|
for (i = 0; i < ep->read_buffer->count; i++) {
|
161
161
|
char* data = grpc_dump_slice(ep->read_buffer->slices[i],
|
@@ -292,7 +292,7 @@ static void endpoint_write(grpc_endpoint* secure_ep, grpc_slice_buffer* slices,
|
|
292
292
|
|
293
293
|
grpc_slice_buffer_reset_and_unref_internal(&ep->output_buffer);
|
294
294
|
|
295
|
-
if (grpc_trace_secure_endpoint
|
295
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_secure_endpoint)) {
|
296
296
|
for (i = 0; i < slices->count; i++) {
|
297
297
|
char* data =
|
298
298
|
grpc_dump_slice(slices->slices[i], GPR_DUMP_HEX | GPR_DUMP_ASCII);
|
@@ -74,7 +74,7 @@ struct call_data {
|
|
74
74
|
|
75
75
|
~call_data() { GRPC_ERROR_UNREF(recv_initial_metadata_error); }
|
76
76
|
|
77
|
-
|
77
|
+
grpc_core::CallCombiner* call_combiner;
|
78
78
|
grpc_call_stack* owning_call;
|
79
79
|
grpc_transport_stream_op_batch* recv_initial_metadata_batch;
|
80
80
|
grpc_closure* original_recv_initial_metadata_ready;
|
@@ -219,8 +219,7 @@ static void recv_initial_metadata_ready(void* arg, grpc_error* error) {
|
|
219
219
|
// to drop the call combiner early if we get cancelled.
|
220
220
|
GRPC_CLOSURE_INIT(&calld->cancel_closure, cancel_call, elem,
|
221
221
|
grpc_schedule_on_exec_ctx);
|
222
|
-
|
223
|
-
&calld->cancel_closure);
|
222
|
+
calld->call_combiner->SetNotifyOnCancel(&calld->cancel_closure);
|
224
223
|
GRPC_CALL_STACK_REF(calld->owning_call, "server_auth_metadata");
|
225
224
|
calld->md = metadata_batch_to_md_array(
|
226
225
|
batch->payload->recv_initial_metadata.recv_initial_metadata);
|
data/src/core/lib/slice/slice.cc
CHANGED
@@ -26,6 +26,7 @@
|
|
26
26
|
|
27
27
|
#include <string.h>
|
28
28
|
|
29
|
+
#include "src/core/lib/gprpp/memory.h"
|
29
30
|
#include "src/core/lib/gprpp/ref_counted.h"
|
30
31
|
#include "src/core/lib/iomgr/exec_ctx.h"
|
31
32
|
|
@@ -67,17 +68,10 @@ void grpc_slice_unref(grpc_slice slice) {
|
|
67
68
|
|
68
69
|
/* grpc_slice_from_static_string support structure - a refcount that does
|
69
70
|
nothing */
|
70
|
-
static
|
71
|
-
static void noop_unref(void* unused) {}
|
72
|
-
|
73
|
-
static const grpc_slice_refcount_vtable noop_refcount_vtable = {
|
74
|
-
noop_ref, noop_unref, grpc_slice_default_eq_impl,
|
75
|
-
grpc_slice_default_hash_impl};
|
76
|
-
static grpc_slice_refcount noop_refcount = {&noop_refcount_vtable,
|
77
|
-
&noop_refcount};
|
71
|
+
static grpc_slice_refcount NoopRefcount;
|
78
72
|
|
79
73
|
size_t grpc_slice_memory_usage(grpc_slice s) {
|
80
|
-
if (s.refcount == nullptr || s.refcount == &
|
74
|
+
if (s.refcount == nullptr || s.refcount == &NoopRefcount) {
|
81
75
|
return 0;
|
82
76
|
} else {
|
83
77
|
return s.data.refcounted.length;
|
@@ -86,7 +80,7 @@ size_t grpc_slice_memory_usage(grpc_slice s) {
|
|
86
80
|
|
87
81
|
grpc_slice grpc_slice_from_static_buffer(const void* s, size_t len) {
|
88
82
|
grpc_slice slice;
|
89
|
-
slice.refcount = &
|
83
|
+
slice.refcount = &NoopRefcount;
|
90
84
|
slice.data.refcounted.bytes = (uint8_t*)s;
|
91
85
|
slice.data.refcounted.length = len;
|
92
86
|
return slice;
|
@@ -96,45 +90,43 @@ grpc_slice grpc_slice_from_static_string(const char* s) {
|
|
96
90
|
return grpc_slice_from_static_buffer(s, strlen(s));
|
97
91
|
}
|
98
92
|
|
93
|
+
namespace grpc_core {
|
94
|
+
|
99
95
|
/* grpc_slice_new support structures - we create a refcount object extended
|
100
96
|
with the user provided data pointer & destroy function */
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
void* user_data;
|
106
|
-
} new_slice_refcount;
|
107
|
-
|
108
|
-
static void new_slice_ref(void* p) {
|
109
|
-
new_slice_refcount* r = static_cast<new_slice_refcount*>(p);
|
110
|
-
gpr_ref(&r->refs);
|
111
|
-
}
|
112
|
-
|
113
|
-
static void new_slice_unref(void* p) {
|
114
|
-
new_slice_refcount* r = static_cast<new_slice_refcount*>(p);
|
115
|
-
if (gpr_unref(&r->refs)) {
|
116
|
-
r->user_destroy(r->user_data);
|
117
|
-
gpr_free(r);
|
97
|
+
class NewSliceRefcount {
|
98
|
+
public:
|
99
|
+
static void Destroy(void* arg) {
|
100
|
+
Delete(static_cast<NewSliceRefcount*>(arg));
|
118
101
|
}
|
119
|
-
}
|
120
102
|
|
121
|
-
|
122
|
-
|
123
|
-
|
103
|
+
NewSliceRefcount(void (*destroy)(void*), void* user_data)
|
104
|
+
: rc_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this, &rc_),
|
105
|
+
user_destroy_(destroy),
|
106
|
+
user_data_(user_data) {}
|
107
|
+
|
108
|
+
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
|
109
|
+
|
110
|
+
grpc_slice_refcount* base_refcount() { return &rc_; }
|
111
|
+
|
112
|
+
private:
|
113
|
+
~NewSliceRefcount() { user_destroy_(user_data_); }
|
114
|
+
|
115
|
+
grpc_slice_refcount rc_;
|
116
|
+
RefCount refs_;
|
117
|
+
void (*user_destroy_)(void*);
|
118
|
+
void* user_data_;
|
119
|
+
};
|
120
|
+
|
121
|
+
} // namespace grpc_core
|
124
122
|
|
125
123
|
grpc_slice grpc_slice_new_with_user_data(void* p, size_t len,
|
126
124
|
void (*destroy)(void*),
|
127
125
|
void* user_data) {
|
128
126
|
grpc_slice slice;
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
rc->rc.vtable = &new_slice_vtable;
|
133
|
-
rc->rc.sub_refcount = &rc->rc;
|
134
|
-
rc->user_destroy = destroy;
|
135
|
-
rc->user_data = user_data;
|
136
|
-
|
137
|
-
slice.refcount = &rc->rc;
|
127
|
+
slice.refcount =
|
128
|
+
grpc_core::New<grpc_core::NewSliceRefcount>(destroy, user_data)
|
129
|
+
->base_refcount();
|
138
130
|
slice.data.refcounted.bytes = static_cast<uint8_t*>(p);
|
139
131
|
slice.data.refcounted.length = len;
|
140
132
|
return slice;
|
@@ -145,46 +137,45 @@ grpc_slice grpc_slice_new(void* p, size_t len, void (*destroy)(void*)) {
|
|
145
137
|
return grpc_slice_new_with_user_data(p, len, destroy, p);
|
146
138
|
}
|
147
139
|
|
140
|
+
namespace grpc_core {
|
148
141
|
/* grpc_slice_new_with_len support structures - we create a refcount object
|
149
142
|
extended with the user provided data pointer & destroy function */
|
150
|
-
typedef struct new_with_len_slice_refcount {
|
151
|
-
grpc_slice_refcount rc;
|
152
|
-
gpr_refcount refs;
|
153
|
-
void* user_data;
|
154
|
-
size_t user_length;
|
155
|
-
void (*user_destroy)(void*, size_t);
|
156
|
-
} new_with_len_slice_refcount;
|
157
|
-
|
158
|
-
static void new_with_len_ref(void* p) {
|
159
|
-
new_with_len_slice_refcount* r = static_cast<new_with_len_slice_refcount*>(p);
|
160
|
-
gpr_ref(&r->refs);
|
161
|
-
}
|
162
143
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
gpr_free(r);
|
144
|
+
class NewWithLenSliceRefcount {
|
145
|
+
public:
|
146
|
+
static void Destroy(void* arg) {
|
147
|
+
Delete(static_cast<NewWithLenSliceRefcount*>(arg));
|
168
148
|
}
|
169
|
-
}
|
170
149
|
|
171
|
-
|
172
|
-
|
173
|
-
|
150
|
+
NewWithLenSliceRefcount(void (*destroy)(void*, size_t), void* user_data,
|
151
|
+
size_t user_length)
|
152
|
+
: rc_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this, &rc_),
|
153
|
+
user_data_(user_data),
|
154
|
+
user_length_(user_length),
|
155
|
+
user_destroy_(destroy) {}
|
156
|
+
|
157
|
+
GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE
|
158
|
+
|
159
|
+
grpc_slice_refcount* base_refcount() { return &rc_; }
|
160
|
+
|
161
|
+
private:
|
162
|
+
~NewWithLenSliceRefcount() { user_destroy_(user_data_, user_length_); }
|
163
|
+
|
164
|
+
grpc_slice_refcount rc_;
|
165
|
+
RefCount refs_;
|
166
|
+
void* user_data_;
|
167
|
+
size_t user_length_;
|
168
|
+
void (*user_destroy_)(void*, size_t);
|
169
|
+
};
|
170
|
+
|
171
|
+
} // namespace grpc_core
|
174
172
|
|
175
173
|
grpc_slice grpc_slice_new_with_len(void* p, size_t len,
|
176
174
|
void (*destroy)(void*, size_t)) {
|
177
175
|
grpc_slice slice;
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
rc->rc.vtable = &new_with_len_vtable;
|
182
|
-
rc->rc.sub_refcount = &rc->rc;
|
183
|
-
rc->user_destroy = destroy;
|
184
|
-
rc->user_data = p;
|
185
|
-
rc->user_length = len;
|
186
|
-
|
187
|
-
slice.refcount = &rc->rc;
|
176
|
+
slice.refcount =
|
177
|
+
grpc_core::New<grpc_core::NewWithLenSliceRefcount>(destroy, p, len)
|
178
|
+
->base_refcount();
|
188
179
|
slice.data.refcounted.bytes = static_cast<uint8_t*>(p);
|
189
180
|
slice.data.refcounted.length = len;
|
190
181
|
return slice;
|
@@ -203,39 +194,28 @@ grpc_slice grpc_slice_from_copied_string(const char* source) {
|
|
203
194
|
|
204
195
|
namespace {
|
205
196
|
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
197
|
+
class MallocRefCount {
|
198
|
+
public:
|
199
|
+
static void Destroy(void* arg) {
|
200
|
+
MallocRefCount* r = static_cast<MallocRefCount*>(arg);
|
201
|
+
r->~MallocRefCount();
|
202
|
+
gpr_free(r);
|
210
203
|
}
|
211
204
|
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
}
|
205
|
+
MallocRefCount()
|
206
|
+
: base_(grpc_slice_refcount::Type::REGULAR, &refs_, Destroy, this,
|
207
|
+
&base_) {}
|
208
|
+
~MallocRefCount() = default;
|
209
|
+
|
210
|
+
grpc_slice_refcount* base_refcount() { return &base_; }
|
218
211
|
|
219
|
-
|
220
|
-
|
212
|
+
private:
|
213
|
+
grpc_slice_refcount base_;
|
214
|
+
grpc_core::RefCount refs_;
|
221
215
|
};
|
222
216
|
|
223
217
|
} // namespace
|
224
218
|
|
225
|
-
static void malloc_ref(void* p) {
|
226
|
-
MallocRefCount* r = static_cast<MallocRefCount*>(p);
|
227
|
-
r->Ref();
|
228
|
-
}
|
229
|
-
|
230
|
-
static void malloc_unref(void* p) {
|
231
|
-
MallocRefCount* r = static_cast<MallocRefCount*>(p);
|
232
|
-
r->Unref();
|
233
|
-
}
|
234
|
-
|
235
|
-
static const grpc_slice_refcount_vtable malloc_vtable = {
|
236
|
-
malloc_ref, malloc_unref, grpc_slice_default_eq_impl,
|
237
|
-
grpc_slice_default_hash_impl};
|
238
|
-
|
239
219
|
grpc_slice grpc_slice_malloc_large(size_t length) {
|
240
220
|
grpc_slice slice;
|
241
221
|
|
@@ -248,14 +228,16 @@ grpc_slice grpc_slice_malloc_large(size_t length) {
|
|
248
228
|
refcount is a malloc_refcount
|
249
229
|
bytes is an array of bytes of the requested length
|
250
230
|
Both parts are placed in the same allocation returned from gpr_malloc */
|
251
|
-
|
231
|
+
auto* rc =
|
252
232
|
static_cast<MallocRefCount*>(gpr_malloc(sizeof(MallocRefCount) + length));
|
253
233
|
|
254
|
-
|
234
|
+
/* Initial refcount on rc is 1 - and it's up to the caller to release
|
235
|
+
this reference. */
|
236
|
+
new (rc) MallocRefCount();
|
255
237
|
|
256
238
|
/* Build up the slice to be returned. */
|
257
239
|
/* The slices refcount points back to the allocated block. */
|
258
|
-
slice.refcount =
|
240
|
+
slice.refcount = rc->base_refcount();
|
259
241
|
/* The data bytes are placed immediately after the refcount struct */
|
260
242
|
slice.data.refcounted.bytes = reinterpret_cast<uint8_t*>(rc + 1);
|
261
243
|
/* And the length of the block is set to the requested length */
|
@@ -286,7 +268,7 @@ grpc_slice grpc_slice_sub_no_ref(grpc_slice source, size_t begin, size_t end) {
|
|
286
268
|
GPR_ASSERT(source.data.refcounted.length >= end);
|
287
269
|
|
288
270
|
/* Build the result */
|
289
|
-
subset.refcount = source.refcount->sub_refcount;
|
271
|
+
subset.refcount = source.refcount->sub_refcount();
|
290
272
|
/* Point into the source array */
|
291
273
|
subset.data.refcounted.bytes = source.data.refcounted.bytes + begin;
|
292
274
|
subset.data.refcounted.length = end - begin;
|
@@ -312,7 +294,7 @@ grpc_slice grpc_slice_sub(grpc_slice source, size_t begin, size_t end) {
|
|
312
294
|
} else {
|
313
295
|
subset = grpc_slice_sub_no_ref(source, begin, end);
|
314
296
|
/* Bump the refcount */
|
315
|
-
subset.refcount->
|
297
|
+
subset.refcount->Ref();
|
316
298
|
}
|
317
299
|
return subset;
|
318
300
|
}
|
@@ -340,23 +322,23 @@ grpc_slice grpc_slice_split_tail_maybe_ref(grpc_slice* source, size_t split,
|
|
340
322
|
tail.data.inlined.length = static_cast<uint8_t>(tail_length);
|
341
323
|
memcpy(tail.data.inlined.bytes, source->data.refcounted.bytes + split,
|
342
324
|
tail_length);
|
343
|
-
source->refcount = source->refcount->sub_refcount;
|
325
|
+
source->refcount = source->refcount->sub_refcount();
|
344
326
|
} else {
|
345
327
|
/* Build the result */
|
346
328
|
switch (ref_whom) {
|
347
329
|
case GRPC_SLICE_REF_TAIL:
|
348
|
-
tail.refcount = source->refcount->sub_refcount;
|
349
|
-
source->refcount = &
|
330
|
+
tail.refcount = source->refcount->sub_refcount();
|
331
|
+
source->refcount = &NoopRefcount;
|
350
332
|
break;
|
351
333
|
case GRPC_SLICE_REF_HEAD:
|
352
|
-
tail.refcount = &
|
353
|
-
source->refcount = source->refcount->sub_refcount;
|
334
|
+
tail.refcount = &NoopRefcount;
|
335
|
+
source->refcount = source->refcount->sub_refcount();
|
354
336
|
break;
|
355
337
|
case GRPC_SLICE_REF_BOTH:
|
356
|
-
tail.refcount = source->refcount->sub_refcount;
|
357
|
-
source->refcount = source->refcount->sub_refcount;
|
338
|
+
tail.refcount = source->refcount->sub_refcount();
|
339
|
+
source->refcount = source->refcount->sub_refcount();
|
358
340
|
/* Bump the refcount */
|
359
|
-
tail.refcount->
|
341
|
+
tail.refcount->Ref();
|
360
342
|
break;
|
361
343
|
}
|
362
344
|
/* Point into the source array */
|
@@ -392,20 +374,20 @@ grpc_slice grpc_slice_split_head(grpc_slice* source, size_t split) {
|
|
392
374
|
head.refcount = nullptr;
|
393
375
|
head.data.inlined.length = static_cast<uint8_t>(split);
|
394
376
|
memcpy(head.data.inlined.bytes, source->data.refcounted.bytes, split);
|
395
|
-
source->refcount = source->refcount->sub_refcount;
|
377
|
+
source->refcount = source->refcount->sub_refcount();
|
396
378
|
source->data.refcounted.bytes += split;
|
397
379
|
source->data.refcounted.length -= split;
|
398
380
|
} else {
|
399
381
|
GPR_ASSERT(source->data.refcounted.length >= split);
|
400
382
|
|
401
383
|
/* Build the result */
|
402
|
-
head.refcount = source->refcount->sub_refcount;
|
384
|
+
head.refcount = source->refcount->sub_refcount();
|
403
385
|
/* Bump the refcount */
|
404
|
-
head.refcount->
|
386
|
+
head.refcount->Ref();
|
405
387
|
/* Point into the source array */
|
406
388
|
head.data.refcounted.bytes = source->data.refcounted.bytes;
|
407
389
|
head.data.refcounted.length = split;
|
408
|
-
source->refcount = source->refcount->sub_refcount;
|
390
|
+
source->refcount = source->refcount->sub_refcount();
|
409
391
|
source->data.refcounted.bytes += split;
|
410
392
|
source->data.refcounted.length -= split;
|
411
393
|
}
|
@@ -421,8 +403,9 @@ int grpc_slice_default_eq_impl(grpc_slice a, grpc_slice b) {
|
|
421
403
|
}
|
422
404
|
|
423
405
|
int grpc_slice_eq(grpc_slice a, grpc_slice b) {
|
424
|
-
if (a.refcount && b.refcount &&
|
425
|
-
|
406
|
+
if (a.refcount && b.refcount &&
|
407
|
+
a.refcount->GetType() == b.refcount->GetType()) {
|
408
|
+
return a.refcount->Eq(a, b);
|
426
409
|
}
|
427
410
|
return grpc_slice_default_eq_impl(a, b);
|
428
411
|
}
|