grpc 1.17.1 → 1.18.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 +1228 -988
- data/etc/roots.pem +242 -30
- data/include/grpc/grpc.h +2 -1
- data/include/grpc/grpc_security_constants.h +3 -3
- data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
- data/include/grpc/impl/codegen/atm_windows.h +2 -0
- data/include/grpc/impl/codegen/compression_types.h +2 -1
- data/include/grpc/impl/codegen/grpc_types.h +1 -1
- data/include/grpc/impl/codegen/port_platform.h +9 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
- 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 +49 -52
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
- data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
- data/src/core/ext/filters/client_channel/request_routing.h +177 -0
- data/src/core/ext/filters/client_channel/resolver.cc +1 -1
- data/src/core/ext/filters/client_channel/resolver.h +1 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
- data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
- data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
- data/src/core/ext/filters/client_channel/server_address.cc +103 -0
- data/src/core/ext/filters/client_channel/server_address.h +108 -0
- data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
- data/src/core/ext/filters/client_channel/subchannel.h +9 -6
- data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
- data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
- data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
- data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
- data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
- data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
- data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
- data/src/core/lib/channel/channelz.cc +19 -18
- data/src/core/lib/channel/channelz.h +7 -1
- data/src/core/lib/channel/channelz_registry.cc +3 -2
- data/src/core/lib/debug/trace.cc +3 -0
- data/src/core/lib/debug/trace.h +5 -3
- data/src/core/lib/gpr/sync_posix.cc +96 -4
- data/src/core/lib/gprpp/inlined_vector.h +25 -19
- data/src/core/lib/gprpp/memory.h +2 -11
- data/src/core/lib/gprpp/orphanable.h +18 -82
- data/src/core/lib/gprpp/ref_counted.h +75 -84
- data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
- data/src/core/lib/http/httpcli_security_connector.cc +101 -94
- data/src/core/lib/http/parser.h +5 -5
- data/src/core/lib/iomgr/buffer_list.cc +16 -5
- data/src/core/lib/iomgr/buffer_list.h +10 -3
- data/src/core/lib/iomgr/call_combiner.cc +50 -2
- data/src/core/lib/iomgr/call_combiner.h +29 -2
- data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
- data/src/core/lib/iomgr/endpoint.cc +4 -0
- data/src/core/lib/iomgr/endpoint.h +3 -0
- data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
- data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.cc +15 -7
- data/src/core/lib/iomgr/ev_posix.h +10 -0
- data/src/core/lib/iomgr/exec_ctx.cc +13 -0
- data/src/core/lib/iomgr/fork_posix.cc +1 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
- data/src/core/lib/iomgr/internal_errqueue.h +7 -1
- data/src/core/lib/iomgr/iomgr.cc +7 -0
- data/src/core/lib/iomgr/iomgr.h +4 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
- data/src/core/lib/iomgr/port.h +1 -2
- data/src/core/lib/iomgr/resource_quota.cc +1 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
- data/src/core/lib/iomgr/tcp_custom.cc +4 -1
- data/src/core/lib/iomgr/tcp_posix.cc +95 -35
- data/src/core/lib/iomgr/tcp_windows.cc +4 -1
- data/src/core/lib/iomgr/timer_manager.cc +6 -0
- data/src/core/lib/security/context/security_context.cc +75 -108
- data/src/core/lib/security/context/security_context.h +59 -35
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
- data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
- data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
- data/src/core/lib/security/credentials/credentials.cc +18 -142
- data/src/core/lib/security/credentials/credentials.h +119 -95
- data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
- data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
- data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
- data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
- data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
- data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
- data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
- data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
- data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
- data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
- data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
- data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
- data/src/core/lib/security/security_connector/security_connector.cc +41 -124
- data/src/core/lib/security/security_connector/security_connector.h +102 -105
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
- data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
- data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
- data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
- data/src/core/lib/security/transport/security_handshaker.cc +82 -66
- data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
- data/src/core/lib/surface/init.cc +1 -0
- data/src/core/lib/surface/server.cc +13 -11
- data/src/core/lib/surface/server.h +6 -6
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +1 -0
- data/src/core/lib/transport/static_metadata.cc +228 -221
- data/src/core/lib/transport/static_metadata.h +75 -71
- data/src/core/lib/transport/transport.cc +2 -1
- data/src/core/lib/transport/transport.h +5 -1
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
- data/src/core/tsi/ssl_transport_security.cc +35 -24
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
- data/src/ruby/lib/grpc/generic/service.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/checker.rb +2 -3
- data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
- data/src/ruby/spec/support/services.rb +1 -0
- metadata +37 -32
- data/src/core/ext/filters/client_channel/lb_policy_factory.cc +0 -163
@@ -488,6 +488,8 @@ static grpc_resource_user* win_get_resource_user(grpc_endpoint* ep) {
|
|
488
488
|
|
489
489
|
static int win_get_fd(grpc_endpoint* ep) { return -1; }
|
490
490
|
|
491
|
+
static bool win_can_track_err(grpc_endpoint* ep) { return false; }
|
492
|
+
|
491
493
|
static grpc_endpoint_vtable vtable = {win_read,
|
492
494
|
win_write,
|
493
495
|
win_add_to_pollset,
|
@@ -497,7 +499,8 @@ static grpc_endpoint_vtable vtable = {win_read,
|
|
497
499
|
win_destroy,
|
498
500
|
win_get_resource_user,
|
499
501
|
win_get_peer,
|
500
|
-
win_get_fd
|
502
|
+
win_get_fd,
|
503
|
+
win_can_track_err};
|
501
504
|
|
502
505
|
grpc_endpoint* grpc_tcp_create(grpc_winsocket* socket,
|
503
506
|
grpc_channel_args* channel_args,
|
@@ -67,6 +67,7 @@ static void timer_thread(void* completed_thread_ptr);
|
|
67
67
|
extern int64_t g_timer_manager_init_count;
|
68
68
|
extern int64_t g_timer_manager_shutdown_count;
|
69
69
|
extern int64_t g_fork_count;
|
70
|
+
extern int64_t g_next_value;
|
70
71
|
#endif // GRPC_DEBUG_TIMER_MANAGER
|
71
72
|
|
72
73
|
static void gc_completed_threads(void) {
|
@@ -193,6 +194,11 @@ static bool wait_until(grpc_millis next) {
|
|
193
194
|
gpr_log(GPR_INFO, "sleep until kicked");
|
194
195
|
}
|
195
196
|
|
197
|
+
// For debug of the timer manager crash only.
|
198
|
+
// TODO (mxyan): remove after bug is fixed.
|
199
|
+
#ifdef GRPC_DEBUG_TIMER_MANAGER
|
200
|
+
g_next_value = next;
|
201
|
+
#endif
|
196
202
|
gpr_cv_wait(&g_cv_wait, &g_mu,
|
197
203
|
grpc_millis_to_timespec(next, GPR_CLOCK_MONOTONIC));
|
198
204
|
|
@@ -23,6 +23,8 @@
|
|
23
23
|
#include "src/core/lib/channel/channel_args.h"
|
24
24
|
#include "src/core/lib/gpr/arena.h"
|
25
25
|
#include "src/core/lib/gpr/string.h"
|
26
|
+
#include "src/core/lib/gprpp/ref_counted.h"
|
27
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
26
28
|
#include "src/core/lib/security/context/security_context.h"
|
27
29
|
#include "src/core/lib/surface/api_trace.h"
|
28
30
|
#include "src/core/lib/surface/call.h"
|
@@ -50,13 +52,11 @@ grpc_call_error grpc_call_set_credentials(grpc_call* call,
|
|
50
52
|
ctx = static_cast<grpc_client_security_context*>(
|
51
53
|
grpc_call_context_get(call, GRPC_CONTEXT_SECURITY));
|
52
54
|
if (ctx == nullptr) {
|
53
|
-
ctx = grpc_client_security_context_create(grpc_call_get_arena(call));
|
54
|
-
ctx->creds = grpc_call_credentials_ref(creds);
|
55
|
+
ctx = grpc_client_security_context_create(grpc_call_get_arena(call), creds);
|
55
56
|
grpc_call_context_set(call, GRPC_CONTEXT_SECURITY, ctx,
|
56
57
|
grpc_client_security_context_destroy);
|
57
58
|
} else {
|
58
|
-
|
59
|
-
ctx->creds = grpc_call_credentials_ref(creds);
|
59
|
+
ctx->creds = creds != nullptr ? creds->Ref() : nullptr;
|
60
60
|
}
|
61
61
|
|
62
62
|
return GRPC_CALL_OK;
|
@@ -66,33 +66,45 @@ grpc_auth_context* grpc_call_auth_context(grpc_call* call) {
|
|
66
66
|
void* sec_ctx = grpc_call_context_get(call, GRPC_CONTEXT_SECURITY);
|
67
67
|
GRPC_API_TRACE("grpc_call_auth_context(call=%p)", 1, (call));
|
68
68
|
if (sec_ctx == nullptr) return nullptr;
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
if (grpc_call_is_client(call)) {
|
70
|
+
auto* sc = static_cast<grpc_client_security_context*>(sec_ctx);
|
71
|
+
if (sc->auth_context == nullptr) {
|
72
|
+
return nullptr;
|
73
|
+
} else {
|
74
|
+
return sc->auth_context
|
75
|
+
->Ref(DEBUG_LOCATION, "grpc_call_auth_context client")
|
76
|
+
.release();
|
77
|
+
}
|
78
|
+
} else {
|
79
|
+
auto* sc = static_cast<grpc_server_security_context*>(sec_ctx);
|
80
|
+
if (sc->auth_context == nullptr) {
|
81
|
+
return nullptr;
|
82
|
+
} else {
|
83
|
+
return sc->auth_context
|
84
|
+
->Ref(DEBUG_LOCATION, "grpc_call_auth_context server")
|
85
|
+
.release();
|
86
|
+
}
|
87
|
+
}
|
76
88
|
}
|
77
89
|
|
78
90
|
void grpc_auth_context_release(grpc_auth_context* context) {
|
79
91
|
GRPC_API_TRACE("grpc_auth_context_release(context=%p)", 1, (context));
|
80
|
-
|
92
|
+
if (context == nullptr) return;
|
93
|
+
context->Unref(DEBUG_LOCATION, "grpc_auth_context_unref");
|
81
94
|
}
|
82
95
|
|
83
96
|
/* --- grpc_client_security_context --- */
|
84
97
|
grpc_client_security_context::~grpc_client_security_context() {
|
85
|
-
|
86
|
-
GRPC_AUTH_CONTEXT_UNREF(auth_context, "client_security_context");
|
98
|
+
auth_context.reset(DEBUG_LOCATION, "client_security_context");
|
87
99
|
if (extension.instance != nullptr && extension.destroy != nullptr) {
|
88
100
|
extension.destroy(extension.instance);
|
89
101
|
}
|
90
102
|
}
|
91
103
|
|
92
104
|
grpc_client_security_context* grpc_client_security_context_create(
|
93
|
-
gpr_arena* arena) {
|
105
|
+
gpr_arena* arena, grpc_call_credentials* creds) {
|
94
106
|
return new (gpr_arena_alloc(arena, sizeof(grpc_client_security_context)))
|
95
|
-
grpc_client_security_context();
|
107
|
+
grpc_client_security_context(creds != nullptr ? creds->Ref() : nullptr);
|
96
108
|
}
|
97
109
|
|
98
110
|
void grpc_client_security_context_destroy(void* ctx) {
|
@@ -104,7 +116,7 @@ void grpc_client_security_context_destroy(void* ctx) {
|
|
104
116
|
|
105
117
|
/* --- grpc_server_security_context --- */
|
106
118
|
grpc_server_security_context::~grpc_server_security_context() {
|
107
|
-
|
119
|
+
auth_context.reset(DEBUG_LOCATION, "server_security_context");
|
108
120
|
if (extension.instance != nullptr && extension.destroy != nullptr) {
|
109
121
|
extension.destroy(extension.instance);
|
110
122
|
}
|
@@ -126,69 +138,11 @@ void grpc_server_security_context_destroy(void* ctx) {
|
|
126
138
|
|
127
139
|
static grpc_auth_property_iterator empty_iterator = {nullptr, 0, nullptr};
|
128
140
|
|
129
|
-
grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained) {
|
130
|
-
grpc_auth_context* ctx =
|
131
|
-
static_cast<grpc_auth_context*>(gpr_zalloc(sizeof(grpc_auth_context)));
|
132
|
-
gpr_ref_init(&ctx->refcount, 1);
|
133
|
-
if (chained != nullptr) {
|
134
|
-
ctx->chained = GRPC_AUTH_CONTEXT_REF(chained, "chained");
|
135
|
-
ctx->peer_identity_property_name =
|
136
|
-
ctx->chained->peer_identity_property_name;
|
137
|
-
}
|
138
|
-
return ctx;
|
139
|
-
}
|
140
|
-
|
141
|
-
#ifndef NDEBUG
|
142
|
-
grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx,
|
143
|
-
const char* file, int line,
|
144
|
-
const char* reason) {
|
145
|
-
if (ctx == nullptr) return nullptr;
|
146
|
-
if (grpc_trace_auth_context_refcount.enabled()) {
|
147
|
-
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
|
148
|
-
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
149
|
-
"AUTH_CONTEXT:%p ref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val,
|
150
|
-
val + 1, reason);
|
151
|
-
}
|
152
|
-
#else
|
153
|
-
grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* ctx) {
|
154
|
-
if (ctx == nullptr) return nullptr;
|
155
|
-
#endif
|
156
|
-
gpr_ref(&ctx->refcount);
|
157
|
-
return ctx;
|
158
|
-
}
|
159
|
-
|
160
|
-
#ifndef NDEBUG
|
161
|
-
void grpc_auth_context_unref(grpc_auth_context* ctx, const char* file, int line,
|
162
|
-
const char* reason) {
|
163
|
-
if (ctx == nullptr) return;
|
164
|
-
if (grpc_trace_auth_context_refcount.enabled()) {
|
165
|
-
gpr_atm val = gpr_atm_no_barrier_load(&ctx->refcount.count);
|
166
|
-
gpr_log(file, line, GPR_LOG_SEVERITY_DEBUG,
|
167
|
-
"AUTH_CONTEXT:%p unref %" PRIdPTR " -> %" PRIdPTR " %s", ctx, val,
|
168
|
-
val - 1, reason);
|
169
|
-
}
|
170
|
-
#else
|
171
|
-
void grpc_auth_context_unref(grpc_auth_context* ctx) {
|
172
|
-
if (ctx == nullptr) return;
|
173
|
-
#endif
|
174
|
-
if (gpr_unref(&ctx->refcount)) {
|
175
|
-
size_t i;
|
176
|
-
GRPC_AUTH_CONTEXT_UNREF(ctx->chained, "chained");
|
177
|
-
if (ctx->properties.array != nullptr) {
|
178
|
-
for (i = 0; i < ctx->properties.count; i++) {
|
179
|
-
grpc_auth_property_reset(&ctx->properties.array[i]);
|
180
|
-
}
|
181
|
-
gpr_free(ctx->properties.array);
|
182
|
-
}
|
183
|
-
gpr_free(ctx);
|
184
|
-
}
|
185
|
-
}
|
186
|
-
|
187
141
|
const char* grpc_auth_context_peer_identity_property_name(
|
188
142
|
const grpc_auth_context* ctx) {
|
189
143
|
GRPC_API_TRACE("grpc_auth_context_peer_identity_property_name(ctx=%p)", 1,
|
190
144
|
(ctx));
|
191
|
-
return ctx->peer_identity_property_name;
|
145
|
+
return ctx->peer_identity_property_name();
|
192
146
|
}
|
193
147
|
|
194
148
|
int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx,
|
@@ -204,13 +158,13 @@ int grpc_auth_context_set_peer_identity_property_name(grpc_auth_context* ctx,
|
|
204
158
|
name != nullptr ? name : "NULL");
|
205
159
|
return 0;
|
206
160
|
}
|
207
|
-
ctx->
|
161
|
+
ctx->set_peer_identity_property_name(prop->name);
|
208
162
|
return 1;
|
209
163
|
}
|
210
164
|
|
211
165
|
int grpc_auth_context_peer_is_authenticated(const grpc_auth_context* ctx) {
|
212
166
|
GRPC_API_TRACE("grpc_auth_context_peer_is_authenticated(ctx=%p)", 1, (ctx));
|
213
|
-
return ctx->
|
167
|
+
return ctx->is_authenticated();
|
214
168
|
}
|
215
169
|
|
216
170
|
grpc_auth_property_iterator grpc_auth_context_property_iterator(
|
@@ -226,16 +180,17 @@ const grpc_auth_property* grpc_auth_property_iterator_next(
|
|
226
180
|
grpc_auth_property_iterator* it) {
|
227
181
|
GRPC_API_TRACE("grpc_auth_property_iterator_next(it=%p)", 1, (it));
|
228
182
|
if (it == nullptr || it->ctx == nullptr) return nullptr;
|
229
|
-
while (it->index == it->ctx->properties.count) {
|
230
|
-
if (it->ctx->chained == nullptr) return nullptr;
|
231
|
-
it->ctx = it->ctx->chained;
|
183
|
+
while (it->index == it->ctx->properties().count) {
|
184
|
+
if (it->ctx->chained() == nullptr) return nullptr;
|
185
|
+
it->ctx = it->ctx->chained();
|
232
186
|
it->index = 0;
|
233
187
|
}
|
234
188
|
if (it->name == nullptr) {
|
235
|
-
return &it->ctx->properties.array[it->index++];
|
189
|
+
return &it->ctx->properties().array[it->index++];
|
236
190
|
} else {
|
237
|
-
while (it->index < it->ctx->properties.count) {
|
238
|
-
const grpc_auth_property* prop =
|
191
|
+
while (it->index < it->ctx->properties().count) {
|
192
|
+
const grpc_auth_property* prop =
|
193
|
+
&it->ctx->properties().array[it->index++];
|
239
194
|
GPR_ASSERT(prop->name != nullptr);
|
240
195
|
if (strcmp(it->name, prop->name) == 0) {
|
241
196
|
return prop;
|
@@ -262,49 +217,56 @@ grpc_auth_property_iterator grpc_auth_context_peer_identity(
|
|
262
217
|
GRPC_API_TRACE("grpc_auth_context_peer_identity(ctx=%p)", 1, (ctx));
|
263
218
|
if (ctx == nullptr) return empty_iterator;
|
264
219
|
return grpc_auth_context_find_properties_by_name(
|
265
|
-
ctx, ctx->peer_identity_property_name);
|
220
|
+
ctx, ctx->peer_identity_property_name());
|
266
221
|
}
|
267
222
|
|
268
|
-
|
269
|
-
if (
|
270
|
-
|
271
|
-
GPR_MAX(
|
272
|
-
|
273
|
-
|
274
|
-
ctx->properties.capacity * sizeof(grpc_auth_property)));
|
223
|
+
void grpc_auth_context::ensure_capacity() {
|
224
|
+
if (properties_.count == properties_.capacity) {
|
225
|
+
properties_.capacity =
|
226
|
+
GPR_MAX(properties_.capacity + 8, properties_.capacity * 2);
|
227
|
+
properties_.array = static_cast<grpc_auth_property*>(gpr_realloc(
|
228
|
+
properties_.array, properties_.capacity * sizeof(grpc_auth_property)));
|
275
229
|
}
|
276
230
|
}
|
277
231
|
|
232
|
+
void grpc_auth_context::add_property(const char* name, const char* value,
|
233
|
+
size_t value_length) {
|
234
|
+
ensure_capacity();
|
235
|
+
grpc_auth_property* prop = &properties_.array[properties_.count++];
|
236
|
+
prop->name = gpr_strdup(name);
|
237
|
+
prop->value = static_cast<char*>(gpr_malloc(value_length + 1));
|
238
|
+
memcpy(prop->value, value, value_length);
|
239
|
+
prop->value[value_length] = '\0';
|
240
|
+
prop->value_length = value_length;
|
241
|
+
}
|
242
|
+
|
278
243
|
void grpc_auth_context_add_property(grpc_auth_context* ctx, const char* name,
|
279
244
|
const char* value, size_t value_length) {
|
280
|
-
grpc_auth_property* prop;
|
281
245
|
GRPC_API_TRACE(
|
282
246
|
"grpc_auth_context_add_property(ctx=%p, name=%s, value=%*.*s, "
|
283
247
|
"value_length=%lu)",
|
284
248
|
6,
|
285
249
|
(ctx, name, (int)value_length, (int)value_length, value,
|
286
250
|
(unsigned long)value_length));
|
287
|
-
|
288
|
-
|
251
|
+
ctx->add_property(name, value, value_length);
|
252
|
+
}
|
253
|
+
|
254
|
+
void grpc_auth_context::add_cstring_property(const char* name,
|
255
|
+
const char* value) {
|
256
|
+
ensure_capacity();
|
257
|
+
grpc_auth_property* prop = &properties_.array[properties_.count++];
|
289
258
|
prop->name = gpr_strdup(name);
|
290
|
-
prop->value =
|
291
|
-
|
292
|
-
prop->value[value_length] = '\0';
|
293
|
-
prop->value_length = value_length;
|
259
|
+
prop->value = gpr_strdup(value);
|
260
|
+
prop->value_length = strlen(value);
|
294
261
|
}
|
295
262
|
|
296
263
|
void grpc_auth_context_add_cstring_property(grpc_auth_context* ctx,
|
297
264
|
const char* name,
|
298
265
|
const char* value) {
|
299
|
-
grpc_auth_property* prop;
|
300
266
|
GRPC_API_TRACE(
|
301
267
|
"grpc_auth_context_add_cstring_property(ctx=%p, name=%s, value=%s)", 3,
|
302
268
|
(ctx, name, value));
|
303
|
-
|
304
|
-
prop = &ctx->properties.array[ctx->properties.count++];
|
305
|
-
prop->name = gpr_strdup(name);
|
306
|
-
prop->value = gpr_strdup(value);
|
307
|
-
prop->value_length = strlen(value);
|
269
|
+
ctx->add_cstring_property(name, value);
|
308
270
|
}
|
309
271
|
|
310
272
|
void grpc_auth_property_reset(grpc_auth_property* property) {
|
@@ -314,12 +276,17 @@ void grpc_auth_property_reset(grpc_auth_property* property) {
|
|
314
276
|
}
|
315
277
|
|
316
278
|
static void auth_context_pointer_arg_destroy(void* p) {
|
317
|
-
|
279
|
+
if (p != nullptr) {
|
280
|
+
static_cast<grpc_auth_context*>(p)->Unref(DEBUG_LOCATION,
|
281
|
+
"auth_context_pointer_arg");
|
282
|
+
}
|
318
283
|
}
|
319
284
|
|
320
285
|
static void* auth_context_pointer_arg_copy(void* p) {
|
321
|
-
|
322
|
-
|
286
|
+
auto* ctx = static_cast<grpc_auth_context*>(p);
|
287
|
+
return ctx == nullptr
|
288
|
+
? nullptr
|
289
|
+
: ctx->Ref(DEBUG_LOCATION, "auth_context_pointer_arg").release();
|
323
290
|
}
|
324
291
|
|
325
292
|
static int auth_context_pointer_cmp(void* a, void* b) { return GPR_ICMP(a, b); }
|
@@ -21,6 +21,8 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
+
#include "src/core/lib/gprpp/ref_counted.h"
|
25
|
+
#include "src/core/lib/gprpp/ref_counted_ptr.h"
|
24
26
|
#include "src/core/lib/iomgr/pollset.h"
|
25
27
|
#include "src/core/lib/security/credentials/credentials.h"
|
26
28
|
|
@@ -40,39 +42,59 @@ struct grpc_auth_property_array {
|
|
40
42
|
size_t capacity = 0;
|
41
43
|
};
|
42
44
|
|
43
|
-
|
44
|
-
grpc_auth_context() { gpr_ref_init(&refcount, 0); }
|
45
|
+
void grpc_auth_property_reset(grpc_auth_property* property);
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
// This type is forward declared as a C struct and we cannot define it as a
|
48
|
+
// class. Otherwise, compiler will complain about type mismatch due to
|
49
|
+
// -Wmismatched-tags.
|
50
|
+
struct grpc_auth_context
|
51
|
+
: public grpc_core::RefCounted<grpc_auth_context,
|
52
|
+
grpc_core::NonPolymorphicRefCount> {
|
53
|
+
public:
|
54
|
+
explicit grpc_auth_context(
|
55
|
+
grpc_core::RefCountedPtr<grpc_auth_context> chained)
|
56
|
+
: grpc_core::RefCounted<grpc_auth_context,
|
57
|
+
grpc_core::NonPolymorphicRefCount>(
|
58
|
+
&grpc_trace_auth_context_refcount),
|
59
|
+
chained_(std::move(chained)) {
|
60
|
+
if (chained_ != nullptr) {
|
61
|
+
peer_identity_property_name_ = chained_->peer_identity_property_name_;
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
~grpc_auth_context() {
|
66
|
+
chained_.reset(DEBUG_LOCATION, "chained");
|
67
|
+
if (properties_.array != nullptr) {
|
68
|
+
for (size_t i = 0; i < properties_.count; i++) {
|
69
|
+
grpc_auth_property_reset(&properties_.array[i]);
|
70
|
+
}
|
71
|
+
gpr_free(properties_.array);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
const grpc_auth_context* chained() const { return chained_.get(); }
|
76
|
+
const grpc_auth_property_array& properties() const { return properties_; }
|
77
|
+
|
78
|
+
bool is_authenticated() const {
|
79
|
+
return peer_identity_property_name_ != nullptr;
|
80
|
+
}
|
81
|
+
const char* peer_identity_property_name() const {
|
82
|
+
return peer_identity_property_name_;
|
83
|
+
}
|
84
|
+
void set_peer_identity_property_name(const char* name) {
|
85
|
+
peer_identity_property_name_ = name;
|
86
|
+
}
|
87
|
+
|
88
|
+
void ensure_capacity();
|
89
|
+
void add_property(const char* name, const char* value, size_t value_length);
|
90
|
+
void add_cstring_property(const char* name, const char* value);
|
91
|
+
|
92
|
+
private:
|
93
|
+
grpc_core::RefCountedPtr<grpc_auth_context> chained_;
|
94
|
+
grpc_auth_property_array properties_;
|
95
|
+
const char* peer_identity_property_name_ = nullptr;
|
51
96
|
};
|
52
97
|
|
53
|
-
/* Creation. */
|
54
|
-
grpc_auth_context* grpc_auth_context_create(grpc_auth_context* chained);
|
55
|
-
|
56
|
-
/* Refcounting. */
|
57
|
-
#ifndef NDEBUG
|
58
|
-
#define GRPC_AUTH_CONTEXT_REF(p, r) \
|
59
|
-
grpc_auth_context_ref((p), __FILE__, __LINE__, (r))
|
60
|
-
#define GRPC_AUTH_CONTEXT_UNREF(p, r) \
|
61
|
-
grpc_auth_context_unref((p), __FILE__, __LINE__, (r))
|
62
|
-
grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* policy,
|
63
|
-
const char* file, int line,
|
64
|
-
const char* reason);
|
65
|
-
void grpc_auth_context_unref(grpc_auth_context* policy, const char* file,
|
66
|
-
int line, const char* reason);
|
67
|
-
#else
|
68
|
-
#define GRPC_AUTH_CONTEXT_REF(p, r) grpc_auth_context_ref((p))
|
69
|
-
#define GRPC_AUTH_CONTEXT_UNREF(p, r) grpc_auth_context_unref((p))
|
70
|
-
grpc_auth_context* grpc_auth_context_ref(grpc_auth_context* policy);
|
71
|
-
void grpc_auth_context_unref(grpc_auth_context* policy);
|
72
|
-
#endif
|
73
|
-
|
74
|
-
void grpc_auth_property_reset(grpc_auth_property* property);
|
75
|
-
|
76
98
|
/* --- grpc_security_context_extension ---
|
77
99
|
|
78
100
|
Extension to the security context that may be set in a filter and accessed
|
@@ -88,16 +110,18 @@ struct grpc_security_context_extension {
|
|
88
110
|
Internal client-side security context. */
|
89
111
|
|
90
112
|
struct grpc_client_security_context {
|
91
|
-
grpc_client_security_context(
|
113
|
+
explicit grpc_client_security_context(
|
114
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> creds)
|
115
|
+
: creds(std::move(creds)) {}
|
92
116
|
~grpc_client_security_context();
|
93
117
|
|
94
|
-
grpc_call_credentials
|
95
|
-
grpc_auth_context
|
118
|
+
grpc_core::RefCountedPtr<grpc_call_credentials> creds;
|
119
|
+
grpc_core::RefCountedPtr<grpc_auth_context> auth_context;
|
96
120
|
grpc_security_context_extension extension;
|
97
121
|
};
|
98
122
|
|
99
123
|
grpc_client_security_context* grpc_client_security_context_create(
|
100
|
-
gpr_arena* arena);
|
124
|
+
gpr_arena* arena, grpc_call_credentials* creds);
|
101
125
|
void grpc_client_security_context_destroy(void* ctx);
|
102
126
|
|
103
127
|
/* --- grpc_server_security_context ---
|
@@ -108,7 +132,7 @@ struct grpc_server_security_context {
|
|
108
132
|
grpc_server_security_context() = default;
|
109
133
|
~grpc_server_security_context();
|
110
134
|
|
111
|
-
grpc_auth_context
|
135
|
+
grpc_core::RefCountedPtr<grpc_auth_context> auth_context;
|
112
136
|
grpc_security_context_extension extension;
|
113
137
|
};
|
114
138
|
|