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
@@ -33,40 +33,47 @@
33
33
  #define GRPC_CREDENTIALS_TYPE_ALTS "Alts"
34
34
  #define GRPC_ALTS_HANDSHAKER_SERVICE_URL "metadata.google.internal:8080"
35
35
 
36
- static void alts_credentials_destruct(grpc_channel_credentials* creds) {
37
- grpc_alts_credentials* alts_creds =
38
- reinterpret_cast<grpc_alts_credentials*>(creds);
39
- grpc_alts_credentials_options_destroy(alts_creds->options);
40
- gpr_free(alts_creds->handshaker_service_url);
41
- }
42
-
43
- static void alts_server_credentials_destruct(grpc_server_credentials* creds) {
44
- grpc_alts_server_credentials* alts_creds =
45
- reinterpret_cast<grpc_alts_server_credentials*>(creds);
46
- grpc_alts_credentials_options_destroy(alts_creds->options);
47
- gpr_free(alts_creds->handshaker_service_url);
36
+ grpc_alts_credentials::grpc_alts_credentials(
37
+ const grpc_alts_credentials_options* options,
38
+ const char* handshaker_service_url)
39
+ : grpc_channel_credentials(GRPC_CREDENTIALS_TYPE_ALTS),
40
+ options_(grpc_alts_credentials_options_copy(options)),
41
+ handshaker_service_url_(handshaker_service_url == nullptr
42
+ ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL)
43
+ : gpr_strdup(handshaker_service_url)) {}
44
+
45
+ grpc_alts_credentials::~grpc_alts_credentials() {
46
+ grpc_alts_credentials_options_destroy(options_);
47
+ gpr_free(handshaker_service_url_);
48
48
  }
49
49
 
50
- static grpc_security_status alts_create_security_connector(
51
- grpc_channel_credentials* creds,
52
- grpc_call_credentials* request_metadata_creds, const char* target_name,
53
- const grpc_channel_args* args, grpc_channel_security_connector** sc,
50
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
51
+ grpc_alts_credentials::create_security_connector(
52
+ grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
53
+ const char* target_name, const grpc_channel_args* args,
54
54
  grpc_channel_args** new_args) {
55
55
  return grpc_alts_channel_security_connector_create(
56
- creds, request_metadata_creds, target_name, sc);
56
+ this->Ref(), std::move(call_creds), target_name);
57
57
  }
58
58
 
59
- static grpc_security_status alts_server_create_security_connector(
60
- grpc_server_credentials* creds, grpc_server_security_connector** sc) {
61
- return grpc_alts_server_security_connector_create(creds, sc);
59
+ grpc_alts_server_credentials::grpc_alts_server_credentials(
60
+ const grpc_alts_credentials_options* options,
61
+ const char* handshaker_service_url)
62
+ : grpc_server_credentials(GRPC_CREDENTIALS_TYPE_ALTS),
63
+ options_(grpc_alts_credentials_options_copy(options)),
64
+ handshaker_service_url_(handshaker_service_url == nullptr
65
+ ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL)
66
+ : gpr_strdup(handshaker_service_url)) {}
67
+
68
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
69
+ grpc_alts_server_credentials::create_security_connector() {
70
+ return grpc_alts_server_security_connector_create(this->Ref());
62
71
  }
63
72
 
64
- static const grpc_channel_credentials_vtable alts_credentials_vtable = {
65
- alts_credentials_destruct, alts_create_security_connector,
66
- /*duplicate_without_call_credentials=*/nullptr};
67
-
68
- static const grpc_server_credentials_vtable alts_server_credentials_vtable = {
69
- alts_server_credentials_destruct, alts_server_create_security_connector};
73
+ grpc_alts_server_credentials::~grpc_alts_server_credentials() {
74
+ grpc_alts_credentials_options_destroy(options_);
75
+ gpr_free(handshaker_service_url_);
76
+ }
70
77
 
71
78
  grpc_channel_credentials* grpc_alts_credentials_create_customized(
72
79
  const grpc_alts_credentials_options* options,
@@ -74,17 +81,7 @@ grpc_channel_credentials* grpc_alts_credentials_create_customized(
74
81
  if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) {
75
82
  return nullptr;
76
83
  }
77
- auto creds = static_cast<grpc_alts_credentials*>(
78
- gpr_zalloc(sizeof(grpc_alts_credentials)));
79
- creds->options = grpc_alts_credentials_options_copy(options);
80
- creds->handshaker_service_url =
81
- handshaker_service_url == nullptr
82
- ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL)
83
- : gpr_strdup(handshaker_service_url);
84
- creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS;
85
- creds->base.vtable = &alts_credentials_vtable;
86
- gpr_ref_init(&creds->base.refcount, 1);
87
- return &creds->base;
84
+ return grpc_core::New<grpc_alts_credentials>(options, handshaker_service_url);
88
85
  }
89
86
 
90
87
  grpc_server_credentials* grpc_alts_server_credentials_create_customized(
@@ -93,17 +90,8 @@ grpc_server_credentials* grpc_alts_server_credentials_create_customized(
93
90
  if (!enable_untrusted_alts && !grpc_alts_is_running_on_gcp()) {
94
91
  return nullptr;
95
92
  }
96
- auto creds = static_cast<grpc_alts_server_credentials*>(
97
- gpr_zalloc(sizeof(grpc_alts_server_credentials)));
98
- creds->options = grpc_alts_credentials_options_copy(options);
99
- creds->handshaker_service_url =
100
- handshaker_service_url == nullptr
101
- ? gpr_strdup(GRPC_ALTS_HANDSHAKER_SERVICE_URL)
102
- : gpr_strdup(handshaker_service_url);
103
- creds->base.type = GRPC_CREDENTIALS_TYPE_ALTS;
104
- creds->base.vtable = &alts_server_credentials_vtable;
105
- gpr_ref_init(&creds->base.refcount, 1);
106
- return &creds->base;
93
+ return grpc_core::New<grpc_alts_server_credentials>(options,
94
+ handshaker_service_url);
107
95
  }
108
96
 
109
97
  grpc_channel_credentials* grpc_alts_credentials_create(
@@ -27,18 +27,45 @@
27
27
  #include "src/core/lib/security/credentials/credentials.h"
28
28
 
29
29
  /* Main struct for grpc ALTS channel credential. */
30
- typedef struct grpc_alts_credentials {
31
- grpc_channel_credentials base;
32
- grpc_alts_credentials_options* options;
33
- char* handshaker_service_url;
34
- } grpc_alts_credentials;
30
+ class grpc_alts_credentials final : public grpc_channel_credentials {
31
+ public:
32
+ grpc_alts_credentials(const grpc_alts_credentials_options* options,
33
+ const char* handshaker_service_url);
34
+ ~grpc_alts_credentials() override;
35
+
36
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
37
+ create_security_connector(
38
+ grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
39
+ const char* target_name, const grpc_channel_args* args,
40
+ grpc_channel_args** new_args) override;
41
+
42
+ const grpc_alts_credentials_options* options() const { return options_; }
43
+ grpc_alts_credentials_options* mutable_options() { return options_; }
44
+ const char* handshaker_service_url() const { return handshaker_service_url_; }
45
+
46
+ private:
47
+ grpc_alts_credentials_options* options_;
48
+ char* handshaker_service_url_;
49
+ };
35
50
 
36
51
  /* Main struct for grpc ALTS server credential. */
37
- typedef struct grpc_alts_server_credentials {
38
- grpc_server_credentials base;
39
- grpc_alts_credentials_options* options;
40
- char* handshaker_service_url;
41
- } grpc_alts_server_credentials;
52
+ class grpc_alts_server_credentials final : public grpc_server_credentials {
53
+ public:
54
+ grpc_alts_server_credentials(const grpc_alts_credentials_options* options,
55
+ const char* handshaker_service_url);
56
+ ~grpc_alts_server_credentials() override;
57
+
58
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
59
+ create_security_connector() override;
60
+
61
+ const grpc_alts_credentials_options* options() const { return options_; }
62
+ grpc_alts_credentials_options* mutable_options() { return options_; }
63
+ const char* handshaker_service_url() const { return handshaker_service_url_; }
64
+
65
+ private:
66
+ grpc_alts_credentials_options* options_;
67
+ char* handshaker_service_url_;
68
+ };
42
69
 
43
70
  /**
44
71
  * This method creates an ALTS channel credential object with customized
@@ -20,8 +20,10 @@
20
20
 
21
21
  #include "src/core/lib/security/credentials/composite/composite_credentials.h"
22
22
 
23
- #include <string.h>
23
+ #include <cstring>
24
+ #include <new>
24
25
 
26
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
25
27
  #include "src/core/lib/iomgr/polling_entity.h"
26
28
  #include "src/core/lib/surface/api_trace.h"
27
29
 
@@ -31,35 +33,44 @@
31
33
 
32
34
  /* -- Composite call credentials. -- */
33
35
 
34
- typedef struct {
36
+ static void composite_call_metadata_cb(void* arg, grpc_error* error);
37
+
38
+ namespace {
39
+ struct grpc_composite_call_credentials_metadata_context {
40
+ grpc_composite_call_credentials_metadata_context(
41
+ grpc_composite_call_credentials* composite_creds,
42
+ grpc_polling_entity* pollent, grpc_auth_metadata_context auth_md_context,
43
+ grpc_credentials_mdelem_array* md_array,
44
+ grpc_closure* on_request_metadata)
45
+ : composite_creds(composite_creds),
46
+ pollent(pollent),
47
+ auth_md_context(auth_md_context),
48
+ md_array(md_array),
49
+ on_request_metadata(on_request_metadata) {
50
+ GRPC_CLOSURE_INIT(&internal_on_request_metadata, composite_call_metadata_cb,
51
+ this, grpc_schedule_on_exec_ctx);
52
+ }
53
+
35
54
  grpc_composite_call_credentials* composite_creds;
36
- size_t creds_index;
55
+ size_t creds_index = 0;
37
56
  grpc_polling_entity* pollent;
38
57
  grpc_auth_metadata_context auth_md_context;
39
58
  grpc_credentials_mdelem_array* md_array;
40
59
  grpc_closure* on_request_metadata;
41
60
  grpc_closure internal_on_request_metadata;
42
- } grpc_composite_call_credentials_metadata_context;
43
-
44
- static void composite_call_destruct(grpc_call_credentials* creds) {
45
- grpc_composite_call_credentials* c =
46
- reinterpret_cast<grpc_composite_call_credentials*>(creds);
47
- for (size_t i = 0; i < c->inner.num_creds; i++) {
48
- grpc_call_credentials_unref(c->inner.creds_array[i]);
49
- }
50
- gpr_free(c->inner.creds_array);
51
- }
61
+ };
62
+ } // namespace
52
63
 
53
64
  static void composite_call_metadata_cb(void* arg, grpc_error* error) {
54
65
  grpc_composite_call_credentials_metadata_context* ctx =
55
66
  static_cast<grpc_composite_call_credentials_metadata_context*>(arg);
56
67
  if (error == GRPC_ERROR_NONE) {
68
+ const grpc_composite_call_credentials::CallCredentialsList& inner =
69
+ ctx->composite_creds->inner();
57
70
  /* See if we need to get some more metadata. */
58
- if (ctx->creds_index < ctx->composite_creds->inner.num_creds) {
59
- grpc_call_credentials* inner_creds =
60
- ctx->composite_creds->inner.creds_array[ctx->creds_index++];
61
- if (grpc_call_credentials_get_request_metadata(
62
- inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array,
71
+ if (ctx->creds_index < inner.size()) {
72
+ if (inner[ctx->creds_index++]->get_request_metadata(
73
+ ctx->pollent, ctx->auth_md_context, ctx->md_array,
63
74
  &ctx->internal_on_request_metadata, &error)) {
64
75
  // Synchronous response, so call ourselves recursively.
65
76
  composite_call_metadata_cb(arg, error);
@@ -73,29 +84,18 @@ static void composite_call_metadata_cb(void* arg, grpc_error* error) {
73
84
  gpr_free(ctx);
74
85
  }
75
86
 
76
- static bool composite_call_get_request_metadata(
77
- grpc_call_credentials* creds, grpc_polling_entity* pollent,
78
- grpc_auth_metadata_context auth_md_context,
87
+ bool grpc_composite_call_credentials::get_request_metadata(
88
+ grpc_polling_entity* pollent, grpc_auth_metadata_context auth_md_context,
79
89
  grpc_credentials_mdelem_array* md_array, grpc_closure* on_request_metadata,
80
90
  grpc_error** error) {
81
- grpc_composite_call_credentials* c =
82
- reinterpret_cast<grpc_composite_call_credentials*>(creds);
83
91
  grpc_composite_call_credentials_metadata_context* ctx;
84
- ctx = static_cast<grpc_composite_call_credentials_metadata_context*>(
85
- gpr_zalloc(sizeof(grpc_composite_call_credentials_metadata_context)));
86
- ctx->composite_creds = c;
87
- ctx->pollent = pollent;
88
- ctx->auth_md_context = auth_md_context;
89
- ctx->md_array = md_array;
90
- ctx->on_request_metadata = on_request_metadata;
91
- GRPC_CLOSURE_INIT(&ctx->internal_on_request_metadata,
92
- composite_call_metadata_cb, ctx, grpc_schedule_on_exec_ctx);
92
+ ctx = grpc_core::New<grpc_composite_call_credentials_metadata_context>(
93
+ this, pollent, auth_md_context, md_array, on_request_metadata);
93
94
  bool synchronous = true;
94
- while (ctx->creds_index < ctx->composite_creds->inner.num_creds) {
95
- grpc_call_credentials* inner_creds =
96
- ctx->composite_creds->inner.creds_array[ctx->creds_index++];
97
- if (grpc_call_credentials_get_request_metadata(
98
- inner_creds, ctx->pollent, ctx->auth_md_context, ctx->md_array,
95
+ const CallCredentialsList& inner = ctx->composite_creds->inner();
96
+ while (ctx->creds_index < inner.size()) {
97
+ if (inner[ctx->creds_index++]->get_request_metadata(
98
+ ctx->pollent, ctx->auth_md_context, ctx->md_array,
99
99
  &ctx->internal_on_request_metadata, error)) {
100
100
  if (*error != GRPC_ERROR_NONE) break;
101
101
  } else {
@@ -103,46 +103,66 @@ static bool composite_call_get_request_metadata(
103
103
  break;
104
104
  }
105
105
  }
106
- if (synchronous) gpr_free(ctx);
106
+ if (synchronous) grpc_core::Delete(ctx);
107
107
  return synchronous;
108
108
  }
109
109
 
110
- static void composite_call_cancel_get_request_metadata(
111
- grpc_call_credentials* creds, grpc_credentials_mdelem_array* md_array,
112
- grpc_error* error) {
113
- grpc_composite_call_credentials* c =
114
- reinterpret_cast<grpc_composite_call_credentials*>(creds);
115
- for (size_t i = 0; i < c->inner.num_creds; ++i) {
116
- grpc_call_credentials_cancel_get_request_metadata(
117
- c->inner.creds_array[i], md_array, GRPC_ERROR_REF(error));
110
+ void grpc_composite_call_credentials::cancel_get_request_metadata(
111
+ grpc_credentials_mdelem_array* md_array, grpc_error* error) {
112
+ for (size_t i = 0; i < inner_.size(); ++i) {
113
+ inner_[i]->cancel_get_request_metadata(md_array, GRPC_ERROR_REF(error));
118
114
  }
119
115
  GRPC_ERROR_UNREF(error);
120
116
  }
121
117
 
122
- static grpc_call_credentials_vtable composite_call_credentials_vtable = {
123
- composite_call_destruct, composite_call_get_request_metadata,
124
- composite_call_cancel_get_request_metadata};
118
+ static size_t get_creds_array_size(const grpc_call_credentials* creds,
119
+ bool is_composite) {
120
+ return is_composite
121
+ ? static_cast<const grpc_composite_call_credentials*>(creds)
122
+ ->inner()
123
+ .size()
124
+ : 1;
125
+ }
125
126
 
126
- static grpc_call_credentials_array get_creds_array(
127
- grpc_call_credentials** creds_addr) {
128
- grpc_call_credentials_array result;
129
- grpc_call_credentials* creds = *creds_addr;
130
- result.creds_array = creds_addr;
131
- result.num_creds = 1;
132
- if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) {
133
- result = *grpc_composite_call_credentials_get_credentials(creds);
127
+ void grpc_composite_call_credentials::push_to_inner(
128
+ grpc_core::RefCountedPtr<grpc_call_credentials> creds, bool is_composite) {
129
+ if (!is_composite) {
130
+ inner_.push_back(std::move(creds));
131
+ return;
132
+ }
133
+ auto composite_creds =
134
+ static_cast<grpc_composite_call_credentials*>(creds.get());
135
+ for (size_t i = 0; i < composite_creds->inner().size(); ++i) {
136
+ inner_.push_back(std::move(composite_creds->inner_[i]));
134
137
  }
135
- return result;
138
+ }
139
+
140
+ grpc_composite_call_credentials::grpc_composite_call_credentials(
141
+ grpc_core::RefCountedPtr<grpc_call_credentials> creds1,
142
+ grpc_core::RefCountedPtr<grpc_call_credentials> creds2)
143
+ : grpc_call_credentials(GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) {
144
+ const bool creds1_is_composite =
145
+ strcmp(creds1->type(), GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0;
146
+ const bool creds2_is_composite =
147
+ strcmp(creds2->type(), GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0;
148
+ const size_t size = get_creds_array_size(creds1.get(), creds1_is_composite) +
149
+ get_creds_array_size(creds2.get(), creds2_is_composite);
150
+ inner_.reserve(size);
151
+ push_to_inner(std::move(creds1), creds1_is_composite);
152
+ push_to_inner(std::move(creds2), creds2_is_composite);
153
+ }
154
+
155
+ static grpc_core::RefCountedPtr<grpc_call_credentials>
156
+ composite_call_credentials_create(
157
+ grpc_core::RefCountedPtr<grpc_call_credentials> creds1,
158
+ grpc_core::RefCountedPtr<grpc_call_credentials> creds2) {
159
+ return grpc_core::MakeRefCounted<grpc_composite_call_credentials>(
160
+ std::move(creds1), std::move(creds2));
136
161
  }
137
162
 
138
163
  grpc_call_credentials* grpc_composite_call_credentials_create(
139
164
  grpc_call_credentials* creds1, grpc_call_credentials* creds2,
140
165
  void* reserved) {
141
- size_t i;
142
- size_t creds_array_byte_size;
143
- grpc_call_credentials_array creds1_array;
144
- grpc_call_credentials_array creds2_array;
145
- grpc_composite_call_credentials* c;
146
166
  GRPC_API_TRACE(
147
167
  "grpc_composite_call_credentials_create(creds1=%p, creds2=%p, "
148
168
  "reserved=%p)",
@@ -150,120 +170,40 @@ grpc_call_credentials* grpc_composite_call_credentials_create(
150
170
  GPR_ASSERT(reserved == nullptr);
151
171
  GPR_ASSERT(creds1 != nullptr);
152
172
  GPR_ASSERT(creds2 != nullptr);
153
- c = static_cast<grpc_composite_call_credentials*>(
154
- gpr_zalloc(sizeof(grpc_composite_call_credentials)));
155
- c->base.type = GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE;
156
- c->base.vtable = &composite_call_credentials_vtable;
157
- gpr_ref_init(&c->base.refcount, 1);
158
- creds1_array = get_creds_array(&creds1);
159
- creds2_array = get_creds_array(&creds2);
160
- c->inner.num_creds = creds1_array.num_creds + creds2_array.num_creds;
161
- creds_array_byte_size = c->inner.num_creds * sizeof(grpc_call_credentials*);
162
- c->inner.creds_array =
163
- static_cast<grpc_call_credentials**>(gpr_zalloc(creds_array_byte_size));
164
- for (i = 0; i < creds1_array.num_creds; i++) {
165
- grpc_call_credentials* cur_creds = creds1_array.creds_array[i];
166
- c->inner.creds_array[i] = grpc_call_credentials_ref(cur_creds);
167
- }
168
- for (i = 0; i < creds2_array.num_creds; i++) {
169
- grpc_call_credentials* cur_creds = creds2_array.creds_array[i];
170
- c->inner.creds_array[i + creds1_array.num_creds] =
171
- grpc_call_credentials_ref(cur_creds);
172
- }
173
- return &c->base;
174
- }
175
-
176
- const grpc_call_credentials_array*
177
- grpc_composite_call_credentials_get_credentials(grpc_call_credentials* creds) {
178
- const grpc_composite_call_credentials* c =
179
- reinterpret_cast<const grpc_composite_call_credentials*>(creds);
180
- GPR_ASSERT(strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0);
181
- return &c->inner;
182
- }
183
173
 
184
- grpc_call_credentials* grpc_credentials_contains_type(
185
- grpc_call_credentials* creds, const char* type,
186
- grpc_call_credentials** composite_creds) {
187
- size_t i;
188
- if (strcmp(creds->type, type) == 0) {
189
- if (composite_creds != nullptr) *composite_creds = nullptr;
190
- return creds;
191
- } else if (strcmp(creds->type, GRPC_CALL_CREDENTIALS_TYPE_COMPOSITE) == 0) {
192
- const grpc_call_credentials_array* inner_creds_array =
193
- grpc_composite_call_credentials_get_credentials(creds);
194
- for (i = 0; i < inner_creds_array->num_creds; i++) {
195
- if (strcmp(type, inner_creds_array->creds_array[i]->type) == 0) {
196
- if (composite_creds != nullptr) *composite_creds = creds;
197
- return inner_creds_array->creds_array[i];
198
- }
199
- }
200
- }
201
- return nullptr;
174
+ return composite_call_credentials_create(creds1->Ref(), creds2->Ref())
175
+ .release();
202
176
  }
203
177
 
204
178
  /* -- Composite channel credentials. -- */
205
179
 
206
- static void composite_channel_destruct(grpc_channel_credentials* creds) {
207
- grpc_composite_channel_credentials* c =
208
- reinterpret_cast<grpc_composite_channel_credentials*>(creds);
209
- grpc_channel_credentials_unref(c->inner_creds);
210
- grpc_call_credentials_unref(c->call_creds);
211
- }
212
-
213
- static grpc_security_status composite_channel_create_security_connector(
214
- grpc_channel_credentials* creds, grpc_call_credentials* call_creds,
180
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
181
+ grpc_composite_channel_credentials::create_security_connector(
182
+ grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
215
183
  const char* target, const grpc_channel_args* args,
216
- grpc_channel_security_connector** sc, grpc_channel_args** new_args) {
217
- grpc_composite_channel_credentials* c =
218
- reinterpret_cast<grpc_composite_channel_credentials*>(creds);
219
- grpc_security_status status = GRPC_SECURITY_ERROR;
220
-
221
- GPR_ASSERT(c->inner_creds != nullptr && c->call_creds != nullptr &&
222
- c->inner_creds->vtable != nullptr &&
223
- c->inner_creds->vtable->create_security_connector != nullptr);
184
+ grpc_channel_args** new_args) {
185
+ GPR_ASSERT(inner_creds_ != nullptr && call_creds_ != nullptr);
224
186
  /* If we are passed a call_creds, create a call composite to pass it
225
187
  downstream. */
226
188
  if (call_creds != nullptr) {
227
- grpc_call_credentials* composite_call_creds =
228
- grpc_composite_call_credentials_create(c->call_creds, call_creds,
229
- nullptr);
230
- status = c->inner_creds->vtable->create_security_connector(
231
- c->inner_creds, composite_call_creds, target, args, sc, new_args);
232
- grpc_call_credentials_unref(composite_call_creds);
189
+ return inner_creds_->create_security_connector(
190
+ composite_call_credentials_create(call_creds_, std::move(call_creds)),
191
+ target, args, new_args);
233
192
  } else {
234
- status = c->inner_creds->vtable->create_security_connector(
235
- c->inner_creds, c->call_creds, target, args, sc, new_args);
193
+ return inner_creds_->create_security_connector(call_creds_, target, args,
194
+ new_args);
236
195
  }
237
- return status;
238
196
  }
239
197
 
240
- static grpc_channel_credentials*
241
- composite_channel_duplicate_without_call_credentials(
242
- grpc_channel_credentials* creds) {
243
- grpc_composite_channel_credentials* c =
244
- reinterpret_cast<grpc_composite_channel_credentials*>(creds);
245
- return grpc_channel_credentials_ref(c->inner_creds);
246
- }
247
-
248
- static grpc_channel_credentials_vtable composite_channel_credentials_vtable = {
249
- composite_channel_destruct, composite_channel_create_security_connector,
250
- composite_channel_duplicate_without_call_credentials};
251
-
252
198
  grpc_channel_credentials* grpc_composite_channel_credentials_create(
253
199
  grpc_channel_credentials* channel_creds, grpc_call_credentials* call_creds,
254
200
  void* reserved) {
255
- grpc_composite_channel_credentials* c =
256
- static_cast<grpc_composite_channel_credentials*>(gpr_zalloc(sizeof(*c)));
257
201
  GPR_ASSERT(channel_creds != nullptr && call_creds != nullptr &&
258
202
  reserved == nullptr);
259
203
  GRPC_API_TRACE(
260
204
  "grpc_composite_channel_credentials_create(channel_creds=%p, "
261
205
  "call_creds=%p, reserved=%p)",
262
206
  3, (channel_creds, call_creds, reserved));
263
- c->base.type = channel_creds->type;
264
- c->base.vtable = &composite_channel_credentials_vtable;
265
- gpr_ref_init(&c->base.refcount, 1);
266
- c->inner_creds = grpc_channel_credentials_ref(channel_creds);
267
- c->call_creds = grpc_call_credentials_ref(call_creds);
268
- return &c->base;
207
+ return grpc_core::New<grpc_composite_channel_credentials>(
208
+ channel_creds->Ref(), call_creds->Ref());
269
209
  }