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.

Files changed (166) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +1228 -988
  3. data/etc/roots.pem +242 -30
  4. data/include/grpc/grpc.h +2 -1
  5. data/include/grpc/grpc_security_constants.h +3 -3
  6. data/include/grpc/impl/codegen/atm_gcc_sync.h +2 -0
  7. data/include/grpc/impl/codegen/atm_windows.h +2 -0
  8. data/include/grpc/impl/codegen/compression_types.h +2 -1
  9. data/include/grpc/impl/codegen/grpc_types.h +1 -1
  10. data/include/grpc/impl/codegen/port_platform.h +9 -0
  11. data/src/core/ext/filters/client_channel/client_channel.cc +163 -882
  12. data/src/core/ext/filters/client_channel/health/health_check_client.cc +2 -4
  13. data/src/core/ext/filters/client_channel/health/health_check_client.h +2 -3
  14. data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
  15. data/src/core/ext/filters/client_channel/lb_policy.h +8 -17
  16. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +176 -216
  17. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +1 -1
  18. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +20 -23
  19. data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
  20. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +49 -52
  21. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +13 -35
  22. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +31 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +69 -225
  24. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +1 -1
  25. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +20 -23
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +1 -1
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +2 -84
  28. data/src/core/ext/filters/client_channel/request_routing.cc +936 -0
  29. data/src/core/ext/filters/client_channel/request_routing.h +177 -0
  30. data/src/core/ext/filters/client_channel/resolver.cc +1 -1
  31. data/src/core/ext/filters/client_channel/resolver.h +1 -1
  32. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +37 -26
  33. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +30 -18
  34. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +119 -100
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +8 -5
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +5 -4
  37. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +2 -1
  38. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +12 -14
  39. data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +5 -9
  40. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.cc +2 -1
  41. data/src/core/ext/filters/client_channel/resolver/fake/fake_resolver.h +1 -2
  42. data/src/core/ext/filters/client_channel/resolver/sockaddr/sockaddr_resolver.cc +17 -17
  43. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +45 -52
  44. data/src/core/ext/filters/client_channel/resolver_result_parsing.h +13 -17
  45. data/src/core/ext/filters/client_channel/server_address.cc +103 -0
  46. data/src/core/ext/filters/client_channel/server_address.h +108 -0
  47. data/src/core/ext/filters/client_channel/subchannel.cc +10 -8
  48. data/src/core/ext/filters/client_channel/subchannel.h +9 -6
  49. data/src/core/ext/filters/client_channel/subchannel_index.cc +20 -27
  50. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +3 -2
  51. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +8 -9
  52. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
  53. data/src/core/ext/transport/chttp2/server/insecure/server_chttp2_posix.cc +1 -1
  54. data/src/core/ext/transport/chttp2/server/secure/server_secure_chttp2.cc +8 -11
  55. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +24 -54
  56. data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +3 -1
  57. data/src/core/ext/transport/chttp2/transport/context_list.cc +67 -0
  58. data/src/core/ext/transport/chttp2/transport/context_list.h +53 -0
  59. data/src/core/ext/transport/chttp2/transport/internal.h +38 -11
  60. data/src/core/ext/transport/chttp2/transport/writing.cc +5 -0
  61. data/src/core/ext/transport/inproc/inproc_transport.cc +1 -1
  62. data/src/core/lib/channel/channelz.cc +19 -18
  63. data/src/core/lib/channel/channelz.h +7 -1
  64. data/src/core/lib/channel/channelz_registry.cc +3 -2
  65. data/src/core/lib/debug/trace.cc +3 -0
  66. data/src/core/lib/debug/trace.h +5 -3
  67. data/src/core/lib/gpr/sync_posix.cc +96 -4
  68. data/src/core/lib/gprpp/inlined_vector.h +25 -19
  69. data/src/core/lib/gprpp/memory.h +2 -11
  70. data/src/core/lib/gprpp/orphanable.h +18 -82
  71. data/src/core/lib/gprpp/ref_counted.h +75 -84
  72. data/src/core/lib/gprpp/ref_counted_ptr.h +22 -17
  73. data/src/core/lib/http/httpcli_security_connector.cc +101 -94
  74. data/src/core/lib/http/parser.h +5 -5
  75. data/src/core/lib/iomgr/buffer_list.cc +16 -5
  76. data/src/core/lib/iomgr/buffer_list.h +10 -3
  77. data/src/core/lib/iomgr/call_combiner.cc +50 -2
  78. data/src/core/lib/iomgr/call_combiner.h +29 -2
  79. data/src/core/lib/iomgr/dynamic_annotations.h +67 -0
  80. data/src/core/lib/iomgr/endpoint.cc +4 -0
  81. data/src/core/lib/iomgr/endpoint.h +3 -0
  82. data/src/core/lib/iomgr/endpoint_pair_posix.cc +2 -2
  83. data/src/core/lib/iomgr/ev_epoll1_linux.cc +4 -0
  84. data/src/core/lib/iomgr/ev_epollex_linux.cc +4 -0
  85. data/src/core/lib/iomgr/ev_poll_posix.cc +4 -0
  86. data/src/core/lib/iomgr/ev_posix.cc +15 -7
  87. data/src/core/lib/iomgr/ev_posix.h +10 -0
  88. data/src/core/lib/iomgr/exec_ctx.cc +13 -0
  89. data/src/core/lib/iomgr/fork_posix.cc +1 -1
  90. data/src/core/lib/iomgr/internal_errqueue.cc +36 -3
  91. data/src/core/lib/iomgr/internal_errqueue.h +7 -1
  92. data/src/core/lib/iomgr/iomgr.cc +7 -0
  93. data/src/core/lib/iomgr/iomgr.h +4 -0
  94. data/src/core/lib/iomgr/iomgr_custom.cc +3 -1
  95. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  96. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  97. data/src/core/lib/iomgr/iomgr_posix.cc +6 -1
  98. data/src/core/lib/iomgr/iomgr_windows.cc +4 -1
  99. data/src/core/lib/iomgr/port.h +1 -2
  100. data/src/core/lib/iomgr/resource_quota.cc +1 -0
  101. data/src/core/lib/iomgr/sockaddr_utils.cc +1 -0
  102. data/src/core/lib/iomgr/tcp_custom.cc +4 -1
  103. data/src/core/lib/iomgr/tcp_posix.cc +95 -35
  104. data/src/core/lib/iomgr/tcp_windows.cc +4 -1
  105. data/src/core/lib/iomgr/timer_manager.cc +6 -0
  106. data/src/core/lib/security/context/security_context.cc +75 -108
  107. data/src/core/lib/security/context/security_context.h +59 -35
  108. data/src/core/lib/security/credentials/alts/alts_credentials.cc +36 -48
  109. data/src/core/lib/security/credentials/alts/alts_credentials.h +37 -10
  110. data/src/core/lib/security/credentials/composite/composite_credentials.cc +97 -157
  111. data/src/core/lib/security/credentials/composite/composite_credentials.h +60 -24
  112. data/src/core/lib/security/credentials/credentials.cc +18 -142
  113. data/src/core/lib/security/credentials/credentials.h +119 -95
  114. data/src/core/lib/security/credentials/fake/fake_credentials.cc +46 -71
  115. data/src/core/lib/security/credentials/fake/fake_credentials.h +23 -5
  116. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +144 -51
  117. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +28 -5
  118. data/src/core/lib/security/credentials/iam/iam_credentials.cc +27 -35
  119. data/src/core/lib/security/credentials/iam/iam_credentials.h +18 -4
  120. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +60 -69
  121. data/src/core/lib/security/credentials/jwt/jwt_credentials.h +29 -10
  122. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -0
  123. data/src/core/lib/security/credentials/local/local_credentials.cc +19 -32
  124. data/src/core/lib/security/credentials/local/local_credentials.h +32 -11
  125. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +130 -149
  126. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.h +74 -29
  127. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +59 -77
  128. data/src/core/lib/security/credentials/plugin/plugin_credentials.h +40 -17
  129. data/src/core/lib/security/credentials/ssl/ssl_credentials.cc +66 -83
  130. data/src/core/lib/security/credentials/ssl/ssl_credentials.h +58 -15
  131. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +152 -177
  132. data/src/core/lib/security/security_connector/alts/alts_security_connector.h +12 -10
  133. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +210 -215
  134. data/src/core/lib/security/security_connector/fake/fake_security_connector.h +9 -6
  135. data/src/core/lib/security/security_connector/local/local_security_connector.cc +176 -169
  136. data/src/core/lib/security/security_connector/local/local_security_connector.h +10 -9
  137. data/src/core/lib/security/security_connector/security_connector.cc +41 -124
  138. data/src/core/lib/security/security_connector/security_connector.h +102 -105
  139. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +348 -370
  140. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.h +14 -12
  141. data/src/core/lib/security/security_connector/ssl_utils.cc +13 -9
  142. data/src/core/lib/security/security_connector/ssl_utils.h +3 -1
  143. data/src/core/lib/security/transport/client_auth_filter.cc +50 -50
  144. data/src/core/lib/security/transport/secure_endpoint.cc +7 -1
  145. data/src/core/lib/security/transport/security_handshaker.cc +82 -66
  146. data/src/core/lib/security/transport/server_auth_filter.cc +15 -13
  147. data/src/core/lib/surface/init.cc +1 -0
  148. data/src/core/lib/surface/server.cc +13 -11
  149. data/src/core/lib/surface/server.h +6 -6
  150. data/src/core/lib/surface/version.cc +2 -2
  151. data/src/core/lib/transport/metadata.cc +1 -0
  152. data/src/core/lib/transport/static_metadata.cc +228 -221
  153. data/src/core/lib/transport/static_metadata.h +75 -71
  154. data/src/core/lib/transport/transport.cc +2 -1
  155. data/src/core/lib/transport/transport.h +5 -1
  156. data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +9 -2
  157. data/src/core/tsi/ssl_transport_security.cc +35 -24
  158. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +1 -1
  159. data/src/ruby/lib/grpc/generic/rpc_server.rb +61 -0
  160. data/src/ruby/lib/grpc/generic/service.rb +1 -1
  161. data/src/ruby/lib/grpc/version.rb +1 -1
  162. data/src/ruby/pb/grpc/health/checker.rb +2 -3
  163. data/src/ruby/spec/generic/rpc_server_spec.rb +22 -0
  164. data/src/ruby/spec/support/services.rb +1 -0
  165. metadata +37 -32
  166. 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
- grpc_call_credentials_unref(ctx->creds);
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
- return grpc_call_is_client(call)
70
- ? GRPC_AUTH_CONTEXT_REF(
71
- ((grpc_client_security_context*)sec_ctx)->auth_context,
72
- "grpc_call_auth_context client")
73
- : GRPC_AUTH_CONTEXT_REF(
74
- ((grpc_server_security_context*)sec_ctx)->auth_context,
75
- "grpc_call_auth_context server");
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
- GRPC_AUTH_CONTEXT_UNREF(context, "grpc_auth_context_unref");
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
- grpc_call_credentials_unref(creds);
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
- GRPC_AUTH_CONTEXT_UNREF(auth_context, "server_security_context");
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->peer_identity_property_name = prop->name;
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->peer_identity_property_name == nullptr ? 0 : 1;
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 = &it->ctx->properties.array[it->index++];
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
- static void ensure_auth_context_capacity(grpc_auth_context* ctx) {
269
- if (ctx->properties.count == ctx->properties.capacity) {
270
- ctx->properties.capacity =
271
- GPR_MAX(ctx->properties.capacity + 8, ctx->properties.capacity * 2);
272
- ctx->properties.array = static_cast<grpc_auth_property*>(
273
- gpr_realloc(ctx->properties.array,
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
- ensure_auth_context_capacity(ctx);
288
- prop = &ctx->properties.array[ctx->properties.count++];
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 = static_cast<char*>(gpr_malloc(value_length + 1));
291
- memcpy(prop->value, value, value_length);
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
- ensure_auth_context_capacity(ctx);
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
- GRPC_AUTH_CONTEXT_UNREF((grpc_auth_context*)p, "auth_context_pointer_arg");
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
- return GRPC_AUTH_CONTEXT_REF((grpc_auth_context*)p,
322
- "auth_context_pointer_arg");
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
- struct grpc_auth_context {
44
- grpc_auth_context() { gpr_ref_init(&refcount, 0); }
45
+ void grpc_auth_property_reset(grpc_auth_property* property);
45
46
 
46
- struct grpc_auth_context* chained = nullptr;
47
- grpc_auth_property_array properties;
48
- gpr_refcount refcount;
49
- const char* peer_identity_property_name = nullptr;
50
- grpc_pollset* pollset = nullptr;
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() = default;
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* creds = nullptr;
95
- grpc_auth_context* auth_context = nullptr;
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* auth_context = nullptr;
135
+ grpc_core::RefCountedPtr<grpc_auth_context> auth_context;
112
136
  grpc_security_context_extension extension;
113
137
  };
114
138