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
@@ -54,46 +54,91 @@ void grpc_auth_refresh_token_destruct(grpc_auth_refresh_token* refresh_token);
54
54
  // This object is a base for credentials that need to acquire an oauth2 token
55
55
  // from an http service.
56
56
 
57
- typedef void (*grpc_fetch_oauth2_func)(grpc_credentials_metadata_request* req,
58
- grpc_httpcli_context* http_context,
59
- grpc_polling_entity* pollent,
60
- grpc_iomgr_cb_func cb,
61
- grpc_millis deadline);
62
-
63
- typedef struct grpc_oauth2_pending_get_request_metadata {
57
+ struct grpc_oauth2_pending_get_request_metadata {
64
58
  grpc_credentials_mdelem_array* md_array;
65
59
  grpc_closure* on_request_metadata;
66
60
  grpc_polling_entity* pollent;
67
61
  struct grpc_oauth2_pending_get_request_metadata* next;
68
- } grpc_oauth2_pending_get_request_metadata;
69
-
70
- typedef struct {
71
- grpc_call_credentials base;
72
- gpr_mu mu;
73
- grpc_mdelem access_token_md;
74
- gpr_timespec token_expiration;
75
- bool token_fetch_pending;
76
- grpc_oauth2_pending_get_request_metadata* pending_requests;
77
- grpc_httpcli_context httpcli_context;
78
- grpc_fetch_oauth2_func fetch_func;
79
- grpc_polling_entity pollent;
80
- } grpc_oauth2_token_fetcher_credentials;
62
+ };
63
+
64
+ class grpc_oauth2_token_fetcher_credentials : public grpc_call_credentials {
65
+ public:
66
+ grpc_oauth2_token_fetcher_credentials();
67
+ ~grpc_oauth2_token_fetcher_credentials() override;
68
+
69
+ bool get_request_metadata(grpc_polling_entity* pollent,
70
+ grpc_auth_metadata_context context,
71
+ grpc_credentials_mdelem_array* md_array,
72
+ grpc_closure* on_request_metadata,
73
+ grpc_error** error) override;
74
+
75
+ void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
76
+ grpc_error* error) override;
77
+
78
+ void on_http_response(grpc_credentials_metadata_request* r,
79
+ grpc_error* error);
80
+
81
+ GRPC_ABSTRACT_BASE_CLASS
82
+
83
+ protected:
84
+ virtual void fetch_oauth2(grpc_credentials_metadata_request* req,
85
+ grpc_httpcli_context* httpcli_context,
86
+ grpc_polling_entity* pollent, grpc_iomgr_cb_func cb,
87
+ grpc_millis deadline) GRPC_ABSTRACT;
88
+
89
+ private:
90
+ gpr_mu mu_;
91
+ grpc_mdelem access_token_md_ = GRPC_MDNULL;
92
+ gpr_timespec token_expiration_;
93
+ bool token_fetch_pending_ = false;
94
+ grpc_oauth2_pending_get_request_metadata* pending_requests_ = nullptr;
95
+ grpc_httpcli_context httpcli_context_;
96
+ grpc_polling_entity pollent_;
97
+ };
81
98
 
82
99
  // Google refresh token credentials.
83
- typedef struct {
84
- grpc_oauth2_token_fetcher_credentials base;
85
- grpc_auth_refresh_token refresh_token;
86
- } grpc_google_refresh_token_credentials;
100
+ class grpc_google_refresh_token_credentials final
101
+ : public grpc_oauth2_token_fetcher_credentials {
102
+ public:
103
+ grpc_google_refresh_token_credentials(grpc_auth_refresh_token refresh_token);
104
+ ~grpc_google_refresh_token_credentials() override;
105
+
106
+ const grpc_auth_refresh_token& refresh_token() const {
107
+ return refresh_token_;
108
+ }
109
+
110
+ protected:
111
+ void fetch_oauth2(grpc_credentials_metadata_request* req,
112
+ grpc_httpcli_context* httpcli_context,
113
+ grpc_polling_entity* pollent, grpc_iomgr_cb_func cb,
114
+ grpc_millis deadline) override;
115
+
116
+ private:
117
+ grpc_auth_refresh_token refresh_token_;
118
+ };
87
119
 
88
120
  // Access token credentials.
89
- typedef struct {
90
- grpc_call_credentials base;
91
- grpc_mdelem access_token_md;
92
- } grpc_access_token_credentials;
121
+ class grpc_access_token_credentials final : public grpc_call_credentials {
122
+ public:
123
+ grpc_access_token_credentials(const char* access_token);
124
+ ~grpc_access_token_credentials() override;
125
+
126
+ bool get_request_metadata(grpc_polling_entity* pollent,
127
+ grpc_auth_metadata_context context,
128
+ grpc_credentials_mdelem_array* md_array,
129
+ grpc_closure* on_request_metadata,
130
+ grpc_error** error) override;
131
+
132
+ void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
133
+ grpc_error* error) override;
134
+
135
+ private:
136
+ grpc_mdelem access_token_md_;
137
+ };
93
138
 
94
139
  // Private constructor for refresh token credentials from an already parsed
95
140
  // refresh token. Takes ownership of the refresh token.
96
- grpc_call_credentials*
141
+ grpc_core::RefCountedPtr<grpc_call_credentials>
97
142
  grpc_refresh_token_credentials_create_from_auth_refresh_token(
98
143
  grpc_auth_refresh_token token);
99
144
 
@@ -35,20 +35,17 @@
35
35
 
36
36
  grpc_core::TraceFlag grpc_plugin_credentials_trace(false, "plugin_credentials");
37
37
 
38
- static void plugin_destruct(grpc_call_credentials* creds) {
39
- grpc_plugin_credentials* c =
40
- reinterpret_cast<grpc_plugin_credentials*>(creds);
41
- gpr_mu_destroy(&c->mu);
42
- if (c->plugin.state != nullptr && c->plugin.destroy != nullptr) {
43
- c->plugin.destroy(c->plugin.state);
38
+ grpc_plugin_credentials::~grpc_plugin_credentials() {
39
+ gpr_mu_destroy(&mu_);
40
+ if (plugin_.state != nullptr && plugin_.destroy != nullptr) {
41
+ plugin_.destroy(plugin_.state);
44
42
  }
45
43
  }
46
44
 
47
- static void pending_request_remove_locked(
48
- grpc_plugin_credentials* c,
49
- grpc_plugin_credentials_pending_request* pending_request) {
45
+ void grpc_plugin_credentials::pending_request_remove_locked(
46
+ pending_request* pending_request) {
50
47
  if (pending_request->prev == nullptr) {
51
- c->pending_requests = pending_request->next;
48
+ pending_requests_ = pending_request->next;
52
49
  } else {
53
50
  pending_request->prev->next = pending_request->next;
54
51
  }
@@ -62,17 +59,17 @@ static void pending_request_remove_locked(
62
59
  // cancelled out from under us.
63
60
  // When this returns, r->cancelled indicates whether the request was
64
61
  // cancelled before completion.
65
- static void pending_request_complete(
66
- grpc_plugin_credentials_pending_request* r) {
67
- gpr_mu_lock(&r->creds->mu);
68
- if (!r->cancelled) pending_request_remove_locked(r->creds, r);
69
- gpr_mu_unlock(&r->creds->mu);
62
+ void grpc_plugin_credentials::pending_request_complete(pending_request* r) {
63
+ GPR_DEBUG_ASSERT(r->creds == this);
64
+ gpr_mu_lock(&mu_);
65
+ if (!r->cancelled) pending_request_remove_locked(r);
66
+ gpr_mu_unlock(&mu_);
70
67
  // Ref to credentials not needed anymore.
71
- grpc_call_credentials_unref(&r->creds->base);
68
+ Unref();
72
69
  }
73
70
 
74
71
  static grpc_error* process_plugin_result(
75
- grpc_plugin_credentials_pending_request* r, const grpc_metadata* md,
72
+ grpc_plugin_credentials::pending_request* r, const grpc_metadata* md,
76
73
  size_t num_md, grpc_status_code status, const char* error_details) {
77
74
  grpc_error* error = GRPC_ERROR_NONE;
78
75
  if (status != GRPC_STATUS_OK) {
@@ -119,8 +116,8 @@ static void plugin_md_request_metadata_ready(void* request,
119
116
  /* called from application code */
120
117
  grpc_core::ExecCtx exec_ctx(GRPC_EXEC_CTX_FLAG_IS_FINISHED |
121
118
  GRPC_EXEC_CTX_FLAG_THREAD_RESOURCE_LOOP);
122
- grpc_plugin_credentials_pending_request* r =
123
- static_cast<grpc_plugin_credentials_pending_request*>(request);
119
+ grpc_plugin_credentials::pending_request* r =
120
+ static_cast<grpc_plugin_credentials::pending_request*>(request);
124
121
  if (grpc_plugin_credentials_trace.enabled()) {
125
122
  gpr_log(GPR_INFO,
126
123
  "plugin_credentials[%p]: request %p: plugin returned "
@@ -128,7 +125,7 @@ static void plugin_md_request_metadata_ready(void* request,
128
125
  r->creds, r);
129
126
  }
130
127
  // Remove request from pending list if not previously cancelled.
131
- pending_request_complete(r);
128
+ r->creds->pending_request_complete(r);
132
129
  // If it has not been cancelled, process it.
133
130
  if (!r->cancelled) {
134
131
  grpc_error* error =
@@ -143,65 +140,59 @@ static void plugin_md_request_metadata_ready(void* request,
143
140
  gpr_free(r);
144
141
  }
145
142
 
146
- static bool plugin_get_request_metadata(grpc_call_credentials* creds,
147
- grpc_polling_entity* pollent,
148
- grpc_auth_metadata_context context,
149
- grpc_credentials_mdelem_array* md_array,
150
- grpc_closure* on_request_metadata,
151
- grpc_error** error) {
152
- grpc_plugin_credentials* c =
153
- reinterpret_cast<grpc_plugin_credentials*>(creds);
143
+ bool grpc_plugin_credentials::get_request_metadata(
144
+ grpc_polling_entity* pollent, grpc_auth_metadata_context context,
145
+ grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
146
+ grpc_error** error) {
154
147
  bool retval = true; // Synchronous return.
155
- if (c->plugin.get_metadata != nullptr) {
148
+ if (plugin_.get_metadata != nullptr) {
156
149
  // Create pending_request object.
157
- grpc_plugin_credentials_pending_request* pending_request =
158
- static_cast<grpc_plugin_credentials_pending_request*>(
159
- gpr_zalloc(sizeof(*pending_request)));
160
- pending_request->creds = c;
161
- pending_request->md_array = md_array;
162
- pending_request->on_request_metadata = on_request_metadata;
150
+ pending_request* request =
151
+ static_cast<pending_request*>(gpr_zalloc(sizeof(*request)));
152
+ request->creds = this;
153
+ request->md_array = md_array;
154
+ request->on_request_metadata = on_request_metadata;
163
155
  // Add it to the pending list.
164
- gpr_mu_lock(&c->mu);
165
- if (c->pending_requests != nullptr) {
166
- c->pending_requests->prev = pending_request;
156
+ gpr_mu_lock(&mu_);
157
+ if (pending_requests_ != nullptr) {
158
+ pending_requests_->prev = request;
167
159
  }
168
- pending_request->next = c->pending_requests;
169
- c->pending_requests = pending_request;
170
- gpr_mu_unlock(&c->mu);
160
+ request->next = pending_requests_;
161
+ pending_requests_ = request;
162
+ gpr_mu_unlock(&mu_);
171
163
  // Invoke the plugin. The callback holds a ref to us.
172
164
  if (grpc_plugin_credentials_trace.enabled()) {
173
165
  gpr_log(GPR_INFO, "plugin_credentials[%p]: request %p: invoking plugin",
174
- c, pending_request);
166
+ this, request);
175
167
  }
176
- grpc_call_credentials_ref(creds);
168
+ Ref().release();
177
169
  grpc_metadata creds_md[GRPC_METADATA_CREDENTIALS_PLUGIN_SYNC_MAX];
178
170
  size_t num_creds_md = 0;
179
171
  grpc_status_code status = GRPC_STATUS_OK;
180
172
  const char* error_details = nullptr;
181
- if (!c->plugin.get_metadata(c->plugin.state, context,
182
- plugin_md_request_metadata_ready,
183
- pending_request, creds_md, &num_creds_md,
184
- &status, &error_details)) {
173
+ if (!plugin_.get_metadata(
174
+ plugin_.state, context, plugin_md_request_metadata_ready, request,
175
+ creds_md, &num_creds_md, &status, &error_details)) {
185
176
  if (grpc_plugin_credentials_trace.enabled()) {
186
177
  gpr_log(GPR_INFO,
187
178
  "plugin_credentials[%p]: request %p: plugin will return "
188
179
  "asynchronously",
189
- c, pending_request);
180
+ this, request);
190
181
  }
191
182
  return false; // Asynchronous return.
192
183
  }
193
184
  // Returned synchronously.
194
185
  // Remove request from pending list if not previously cancelled.
195
- pending_request_complete(pending_request);
186
+ request->creds->pending_request_complete(request);
196
187
  // If the request was cancelled, the error will have been returned
197
188
  // asynchronously by plugin_cancel_get_request_metadata(), so return
198
189
  // false. Otherwise, process the result.
199
- if (pending_request->cancelled) {
190
+ if (request->cancelled) {
200
191
  if (grpc_plugin_credentials_trace.enabled()) {
201
192
  gpr_log(GPR_INFO,
202
193
  "plugin_credentials[%p]: request %p was cancelled, error "
203
194
  "will be returned asynchronously",
204
- c, pending_request);
195
+ this, request);
205
196
  }
206
197
  retval = false;
207
198
  } else {
@@ -209,10 +200,10 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
209
200
  gpr_log(GPR_INFO,
210
201
  "plugin_credentials[%p]: request %p: plugin returned "
211
202
  "synchronously",
212
- c, pending_request);
203
+ this, request);
213
204
  }
214
- *error = process_plugin_result(pending_request, creds_md, num_creds_md,
215
- status, error_details);
205
+ *error = process_plugin_result(request, creds_md, num_creds_md, status,
206
+ error_details);
216
207
  }
217
208
  // Clean up.
218
209
  for (size_t i = 0; i < num_creds_md; ++i) {
@@ -220,51 +211,42 @@ static bool plugin_get_request_metadata(grpc_call_credentials* creds,
220
211
  grpc_slice_unref_internal(creds_md[i].value);
221
212
  }
222
213
  gpr_free((void*)error_details);
223
- gpr_free(pending_request);
214
+ gpr_free(request);
224
215
  }
225
216
  return retval;
226
217
  }
227
218
 
228
- static void plugin_cancel_get_request_metadata(
229
- grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
230
- grpc_error* error) {
231
- grpc_plugin_credentials* c =
232
- reinterpret_cast<grpc_plugin_credentials*>(creds);
233
- gpr_mu_lock(&c->mu);
234
- for (grpc_plugin_credentials_pending_request* pending_request =
235
- c->pending_requests;
219
+ void grpc_plugin_credentials::cancel_get_request_metadata(
220
+ grpc_credentials_mdelem_array* md_array, grpc_error* error) {
221
+ gpr_mu_lock(&mu_);
222
+ for (pending_request* pending_request = pending_requests_;
236
223
  pending_request != nullptr; pending_request = pending_request->next) {
237
224
  if (pending_request->md_array == md_array) {
238
225
  if (grpc_plugin_credentials_trace.enabled()) {
239
- gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", c,
226
+ gpr_log(GPR_INFO, "plugin_credentials[%p]: cancelling request %p", this,
240
227
  pending_request);
241
228
  }
242
229
  pending_request->cancelled = true;
243
230
  GRPC_CLOSURE_SCHED(pending_request->on_request_metadata,
244
231
  GRPC_ERROR_REF(error));
245
- pending_request_remove_locked(c, pending_request);
232
+ pending_request_remove_locked(pending_request);
246
233
  break;
247
234
  }
248
235
  }
249
- gpr_mu_unlock(&c->mu);
236
+ gpr_mu_unlock(&mu_);
250
237
  GRPC_ERROR_UNREF(error);
251
238
  }
252
239
 
253
- static grpc_call_credentials_vtable plugin_vtable = {
254
- plugin_destruct, plugin_get_request_metadata,
255
- plugin_cancel_get_request_metadata};
240
+ grpc_plugin_credentials::grpc_plugin_credentials(
241
+ grpc_metadata_credentials_plugin plugin)
242
+ : grpc_call_credentials(plugin.type), plugin_(plugin) {
243
+ gpr_mu_init(&mu_);
244
+ }
256
245
 
257
246
  grpc_call_credentials* grpc_metadata_credentials_create_from_plugin(
258
247
  grpc_metadata_credentials_plugin plugin, void* reserved) {
259
- grpc_plugin_credentials* c =
260
- static_cast<grpc_plugin_credentials*>(gpr_zalloc(sizeof(*c)));
261
248
  GRPC_API_TRACE("grpc_metadata_credentials_create_from_plugin(reserved=%p)", 1,
262
249
  (reserved));
263
250
  GPR_ASSERT(reserved == nullptr);
264
- c->base.type = plugin.type;
265
- c->base.vtable = &plugin_vtable;
266
- gpr_ref_init(&c->base.refcount, 1);
267
- c->plugin = plugin;
268
- gpr_mu_init(&c->mu);
269
- return &c->base;
251
+ return grpc_core::New<grpc_plugin_credentials>(plugin);
270
252
  }
@@ -25,22 +25,45 @@
25
25
 
26
26
  extern grpc_core::TraceFlag grpc_plugin_credentials_trace;
27
27
 
28
- struct grpc_plugin_credentials;
29
-
30
- typedef struct grpc_plugin_credentials_pending_request {
31
- bool cancelled;
32
- struct grpc_plugin_credentials* creds;
33
- grpc_credentials_mdelem_array* md_array;
34
- grpc_closure* on_request_metadata;
35
- struct grpc_plugin_credentials_pending_request* prev;
36
- struct grpc_plugin_credentials_pending_request* next;
37
- } grpc_plugin_credentials_pending_request;
38
-
39
- typedef struct grpc_plugin_credentials {
40
- grpc_call_credentials base;
41
- grpc_metadata_credentials_plugin plugin;
42
- gpr_mu mu;
43
- grpc_plugin_credentials_pending_request* pending_requests;
44
- } grpc_plugin_credentials;
28
+ // This type is forward declared as a C struct and we cannot define it as a
29
+ // class. Otherwise, compiler will complain about type mismatch due to
30
+ // -Wmismatched-tags.
31
+ struct grpc_plugin_credentials final : public grpc_call_credentials {
32
+ public:
33
+ struct pending_request {
34
+ bool cancelled;
35
+ struct grpc_plugin_credentials* creds;
36
+ grpc_credentials_mdelem_array* md_array;
37
+ grpc_closure* on_request_metadata;
38
+ struct pending_request* prev;
39
+ struct pending_request* next;
40
+ };
41
+
42
+ explicit grpc_plugin_credentials(grpc_metadata_credentials_plugin plugin);
43
+ ~grpc_plugin_credentials() override;
44
+
45
+ bool get_request_metadata(grpc_polling_entity* pollent,
46
+ grpc_auth_metadata_context context,
47
+ grpc_credentials_mdelem_array* md_array,
48
+ grpc_closure* on_request_metadata,
49
+ grpc_error** error) override;
50
+
51
+ void cancel_get_request_metadata(grpc_credentials_mdelem_array* md_array,
52
+ grpc_error* error) override;
53
+
54
+ // Checks if the request has been cancelled.
55
+ // If not, removes it from the pending list, so that it cannot be
56
+ // cancelled out from under us.
57
+ // When this returns, r->cancelled indicates whether the request was
58
+ // cancelled before completion.
59
+ void pending_request_complete(pending_request* r);
60
+
61
+ private:
62
+ void pending_request_remove_locked(pending_request* pending_request);
63
+
64
+ grpc_metadata_credentials_plugin plugin_;
65
+ gpr_mu mu_;
66
+ pending_request* pending_requests_ = nullptr;
67
+ };
45
68
 
46
69
  #endif /* GRPC_CORE_LIB_SECURITY_CREDENTIALS_PLUGIN_PLUGIN_CREDENTIALS_H */
@@ -44,22 +44,27 @@ void grpc_tsi_ssl_pem_key_cert_pairs_destroy(tsi_ssl_pem_key_cert_pair* kp,
44
44
  gpr_free(kp);
45
45
  }
46
46
 
47
- static void ssl_destruct(grpc_channel_credentials* creds) {
48
- grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
49
- gpr_free(c->config.pem_root_certs);
50
- grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pair, 1);
51
- if (c->config.verify_options.verify_peer_destruct != nullptr) {
52
- c->config.verify_options.verify_peer_destruct(
53
- c->config.verify_options.verify_peer_callback_userdata);
47
+ grpc_ssl_credentials::grpc_ssl_credentials(
48
+ const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
49
+ const verify_peer_options* verify_options)
50
+ : grpc_channel_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_SSL) {
51
+ build_config(pem_root_certs, pem_key_cert_pair, verify_options);
52
+ }
53
+
54
+ grpc_ssl_credentials::~grpc_ssl_credentials() {
55
+ gpr_free(config_.pem_root_certs);
56
+ grpc_tsi_ssl_pem_key_cert_pairs_destroy(config_.pem_key_cert_pair, 1);
57
+ if (config_.verify_options.verify_peer_destruct != nullptr) {
58
+ config_.verify_options.verify_peer_destruct(
59
+ config_.verify_options.verify_peer_callback_userdata);
54
60
  }
55
61
  }
56
62
 
57
- static grpc_security_status ssl_create_security_connector(
58
- grpc_channel_credentials* creds, grpc_call_credentials* call_creds,
63
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
64
+ grpc_ssl_credentials::create_security_connector(
65
+ grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
59
66
  const char* target, const grpc_channel_args* args,
60
- grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
61
- grpc_ssl_credentials* c = reinterpret_cast<grpc_ssl_credentials*>(creds);
62
- grpc_security_status status = GRPC_SECURITY_OK;
67
+ grpc_channel_args** new_args) {
63
68
  const char* overridden_target_name = nullptr;
64
69
  tsi_ssl_session_cache* ssl_session_cache = nullptr;
65
70
  for (size_t i = 0; args && i < args->num_args; i++) {
@@ -74,52 +79,47 @@ static grpc_security_status ssl_create_security_connector(
74
79
  static_cast<tsi_ssl_session_cache*>(arg->value.pointer.p);
75
80
  }
76
81
  }
77
- status = grpc_ssl_channel_security_connector_create(
78
- creds, call_creds, &c->config, target, overridden_target_name,
79
- ssl_session_cache, sc);
80
- if (status != GRPC_SECURITY_OK) {
81
- return status;
82
+ grpc_core::RefCountedPtr<grpc_channel_security_connector> sc =
83
+ grpc_ssl_channel_security_connector_create(
84
+ this->Ref(), std::move(call_creds), &config_, target,
85
+ overridden_target_name, ssl_session_cache);
86
+ if (sc == nullptr) {
87
+ return sc;
82
88
  }
83
89
  grpc_arg new_arg = grpc_channel_arg_string_create(
84
90
  (char*)GRPC_ARG_HTTP2_SCHEME, (char*)"https");
85
91
  *new_args = grpc_channel_args_copy_and_add(args, &new_arg, 1);
86
- return status;
92
+ return sc;
87
93
  }
88
94
 
89
- static grpc_channel_credentials_vtable ssl_vtable = {
90
- ssl_destruct, ssl_create_security_connector, nullptr};
91
-
92
- static void ssl_build_config(const char* pem_root_certs,
93
- grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
94
- const verify_peer_options* verify_options,
95
- grpc_ssl_config* config) {
96
- if (pem_root_certs != nullptr) {
97
- config->pem_root_certs = gpr_strdup(pem_root_certs);
98
- }
95
+ void grpc_ssl_credentials::build_config(
96
+ const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
97
+ const verify_peer_options* verify_options) {
98
+ config_.pem_root_certs = gpr_strdup(pem_root_certs);
99
99
  if (pem_key_cert_pair != nullptr) {
100
100
  GPR_ASSERT(pem_key_cert_pair->private_key != nullptr);
101
101
  GPR_ASSERT(pem_key_cert_pair->cert_chain != nullptr);
102
- config->pem_key_cert_pair = static_cast<tsi_ssl_pem_key_cert_pair*>(
102
+ config_.pem_key_cert_pair = static_cast<tsi_ssl_pem_key_cert_pair*>(
103
103
  gpr_zalloc(sizeof(tsi_ssl_pem_key_cert_pair)));
104
- config->pem_key_cert_pair->cert_chain =
104
+ config_.pem_key_cert_pair->cert_chain =
105
105
  gpr_strdup(pem_key_cert_pair->cert_chain);
106
- config->pem_key_cert_pair->private_key =
106
+ config_.pem_key_cert_pair->private_key =
107
107
  gpr_strdup(pem_key_cert_pair->private_key);
108
+ } else {
109
+ config_.pem_key_cert_pair = nullptr;
108
110
  }
109
111
  if (verify_options != nullptr) {
110
- memcpy(&config->verify_options, verify_options,
112
+ memcpy(&config_.verify_options, verify_options,
111
113
  sizeof(verify_peer_options));
112
114
  } else {
113
115
  // Otherwise set all options to default values
114
- memset(&config->verify_options, 0, sizeof(verify_peer_options));
116
+ memset(&config_.verify_options, 0, sizeof(verify_peer_options));
115
117
  }
116
118
  }
117
119
 
118
120
  grpc_channel_credentials* grpc_ssl_credentials_create(
119
121
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pair,
120
122
  const verify_peer_options* verify_options, void* reserved) {
121
- grpc_ssl_credentials* c = static_cast<grpc_ssl_credentials*>(
122
- gpr_zalloc(sizeof(grpc_ssl_credentials)));
123
123
  GRPC_API_TRACE(
124
124
  "grpc_ssl_credentials_create(pem_root_certs=%s, "
125
125
  "pem_key_cert_pair=%p, "
@@ -127,12 +127,9 @@ grpc_channel_credentials* grpc_ssl_credentials_create(
127
127
  "reserved=%p)",
128
128
  4, (pem_root_certs, pem_key_cert_pair, verify_options, reserved));
129
129
  GPR_ASSERT(reserved == nullptr);
130
- c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
131
- c->base.vtable = &ssl_vtable;
132
- gpr_ref_init(&c->base.refcount, 1);
133
- ssl_build_config(pem_root_certs, pem_key_cert_pair, verify_options,
134
- &c->config);
135
- return &c->base;
130
+
131
+ return grpc_core::New<grpc_ssl_credentials>(pem_root_certs, pem_key_cert_pair,
132
+ verify_options);
136
133
  }
137
134
 
138
135
  //
@@ -145,21 +142,29 @@ struct grpc_ssl_server_credentials_options {
145
142
  grpc_ssl_server_certificate_config_fetcher* certificate_config_fetcher;
146
143
  };
147
144
 
148
- static void ssl_server_destruct(grpc_server_credentials* creds) {
149
- grpc_ssl_server_credentials* c =
150
- reinterpret_cast<grpc_ssl_server_credentials*>(creds);
151
- grpc_tsi_ssl_pem_key_cert_pairs_destroy(c->config.pem_key_cert_pairs,
152
- c->config.num_key_cert_pairs);
153
- gpr_free(c->config.pem_root_certs);
145
+ grpc_ssl_server_credentials::grpc_ssl_server_credentials(
146
+ const grpc_ssl_server_credentials_options& options)
147
+ : grpc_server_credentials(GRPC_CHANNEL_CREDENTIALS_TYPE_SSL) {
148
+ if (options.certificate_config_fetcher != nullptr) {
149
+ config_.client_certificate_request = options.client_certificate_request;
150
+ certificate_config_fetcher_ = *options.certificate_config_fetcher;
151
+ } else {
152
+ build_config(options.certificate_config->pem_root_certs,
153
+ options.certificate_config->pem_key_cert_pairs,
154
+ options.certificate_config->num_key_cert_pairs,
155
+ options.client_certificate_request);
156
+ }
154
157
  }
155
158
 
156
- static grpc_security_status ssl_server_create_security_connector(
157
- grpc_server_credentials* creds, grpc_server_security_connector** sc) {
158
- return grpc_ssl_server_security_connector_create(creds, sc);
159
+ grpc_ssl_server_credentials::~grpc_ssl_server_credentials() {
160
+ grpc_tsi_ssl_pem_key_cert_pairs_destroy(config_.pem_key_cert_pairs,
161
+ config_.num_key_cert_pairs);
162
+ gpr_free(config_.pem_root_certs);
163
+ }
164
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
165
+ grpc_ssl_server_credentials::create_security_connector() {
166
+ return grpc_ssl_server_security_connector_create(this->Ref());
159
167
  }
160
-
161
- static grpc_server_credentials_vtable ssl_server_vtable = {
162
- ssl_server_destruct, ssl_server_create_security_connector};
163
168
 
164
169
  tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
165
170
  const grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
@@ -179,18 +184,15 @@ tsi_ssl_pem_key_cert_pair* grpc_convert_grpc_to_tsi_cert_pairs(
179
184
  return tsi_pairs;
180
185
  }
181
186
 
182
- static void ssl_build_server_config(
187
+ void grpc_ssl_server_credentials::build_config(
183
188
  const char* pem_root_certs, grpc_ssl_pem_key_cert_pair* pem_key_cert_pairs,
184
189
  size_t num_key_cert_pairs,
185
- grpc_ssl_client_certificate_request_type client_certificate_request,
186
- grpc_ssl_server_config* config) {
187
- config->client_certificate_request = client_certificate_request;
188
- if (pem_root_certs != nullptr) {
189
- config->pem_root_certs = gpr_strdup(pem_root_certs);
190
- }
191
- config->pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs(
190
+ grpc_ssl_client_certificate_request_type client_certificate_request) {
191
+ config_.client_certificate_request = client_certificate_request;
192
+ config_.pem_root_certs = gpr_strdup(pem_root_certs);
193
+ config_.pem_key_cert_pairs = grpc_convert_grpc_to_tsi_cert_pairs(
192
194
  pem_key_cert_pairs, num_key_cert_pairs);
193
- config->num_key_cert_pairs = num_key_cert_pairs;
195
+ config_.num_key_cert_pairs = num_key_cert_pairs;
194
196
  }
195
197
 
196
198
  grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
@@ -200,9 +202,7 @@ grpc_ssl_server_certificate_config* grpc_ssl_server_certificate_config_create(
200
202
  grpc_ssl_server_certificate_config* config =
201
203
  static_cast<grpc_ssl_server_certificate_config*>(
202
204
  gpr_zalloc(sizeof(grpc_ssl_server_certificate_config)));
203
- if (pem_root_certs != nullptr) {
204
- config->pem_root_certs = gpr_strdup(pem_root_certs);
205
- }
205
+ config->pem_root_certs = gpr_strdup(pem_root_certs);
206
206
  if (num_key_cert_pairs > 0) {
207
207
  GPR_ASSERT(pem_key_cert_pairs != nullptr);
208
208
  config->pem_key_cert_pairs = static_cast<grpc_ssl_pem_key_cert_pair*>(
@@ -311,7 +311,6 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_ex(
311
311
  grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
312
312
  grpc_ssl_server_credentials_options* options) {
313
313
  grpc_server_credentials* retval = nullptr;
314
- grpc_ssl_server_credentials* c = nullptr;
315
314
 
316
315
  if (options == nullptr) {
317
316
  gpr_log(GPR_ERROR,
@@ -331,23 +330,7 @@ grpc_server_credentials* grpc_ssl_server_credentials_create_with_options(
331
330
  goto done;
332
331
  }
333
332
 
334
- c = static_cast<grpc_ssl_server_credentials*>(
335
- gpr_zalloc(sizeof(grpc_ssl_server_credentials)));
336
- c->base.type = GRPC_CHANNEL_CREDENTIALS_TYPE_SSL;
337
- gpr_ref_init(&c->base.refcount, 1);
338
- c->base.vtable = &ssl_server_vtable;
339
-
340
- if (options->certificate_config_fetcher != nullptr) {
341
- c->config.client_certificate_request = options->client_certificate_request;
342
- c->certificate_config_fetcher = *options->certificate_config_fetcher;
343
- } else {
344
- ssl_build_server_config(options->certificate_config->pem_root_certs,
345
- options->certificate_config->pem_key_cert_pairs,
346
- options->certificate_config->num_key_cert_pairs,
347
- options->client_certificate_request, &c->config);
348
- }
349
-
350
- retval = &c->base;
333
+ retval = grpc_core::New<grpc_ssl_server_credentials>(*options);
351
334
 
352
335
  done:
353
336
  grpc_ssl_server_credentials_options_destroy(options);