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
@@ -36,12 +36,13 @@
36
36
  * - sc: address of ALTS channel security connector instance to be returned from
37
37
  * the method.
38
38
  *
39
- * It returns GRPC_SECURITY_OK on success, and an error stauts code on failure.
39
+ * It returns nullptr on failure.
40
40
  */
41
- grpc_security_status grpc_alts_channel_security_connector_create(
42
- grpc_channel_credentials* channel_creds,
43
- grpc_call_credentials* request_metadata_creds, const char* target_name,
44
- grpc_channel_security_connector** sc);
41
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
42
+ grpc_alts_channel_security_connector_create(
43
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
44
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
45
+ const char* target_name);
45
46
 
46
47
  /**
47
48
  * This method creates an ALTS server security connector.
@@ -50,17 +51,18 @@ grpc_security_status grpc_alts_channel_security_connector_create(
50
51
  * - sc: address of ALTS server security connector instance to be returned from
51
52
  * the method.
52
53
  *
53
- * It returns GRPC_SECURITY_OK on success, and an error status code on failure.
54
+ * It returns nullptr on failure.
54
55
  */
55
- grpc_security_status grpc_alts_server_security_connector_create(
56
- grpc_server_credentials* server_creds, grpc_server_security_connector** sc);
56
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
57
+ grpc_alts_server_security_connector_create(
58
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds);
57
59
 
58
60
  namespace grpc_core {
59
61
  namespace internal {
60
62
 
61
63
  /* Exposed only for testing. */
62
- grpc_security_status grpc_alts_auth_context_from_tsi_peer(
63
- const tsi_peer* peer, grpc_auth_context** ctx);
64
+ grpc_core::RefCountedPtr<grpc_auth_context>
65
+ grpc_alts_auth_context_from_tsi_peer(const tsi_peer* peer);
64
66
 
65
67
  } // namespace internal
66
68
  } // namespace grpc_core
@@ -31,6 +31,7 @@
31
31
  #include "src/core/lib/channel/handshaker.h"
32
32
  #include "src/core/lib/gpr/host_port.h"
33
33
  #include "src/core/lib/gpr/string.h"
34
+ #include "src/core/lib/gprpp/ref_counted_ptr.h"
34
35
  #include "src/core/lib/security/context/security_context.h"
35
36
  #include "src/core/lib/security/credentials/credentials.h"
36
37
  #include "src/core/lib/security/credentials/fake/fake_credentials.h"
@@ -38,91 +39,183 @@
38
39
  #include "src/core/lib/security/transport/target_authority_table.h"
39
40
  #include "src/core/tsi/fake_transport_security.h"
40
41
 
41
- typedef struct {
42
- grpc_channel_security_connector base;
43
- char* target;
44
- char* expected_targets;
45
- bool is_lb_channel;
46
- char* target_name_override;
47
- } grpc_fake_channel_security_connector;
42
+ namespace {
43
+ class grpc_fake_channel_security_connector final
44
+ : public grpc_channel_security_connector {
45
+ public:
46
+ grpc_fake_channel_security_connector(
47
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
48
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
49
+ const char* target, const grpc_channel_args* args)
50
+ : grpc_channel_security_connector(GRPC_FAKE_SECURITY_URL_SCHEME,
51
+ std::move(channel_creds),
52
+ std::move(request_metadata_creds)),
53
+ target_(gpr_strdup(target)),
54
+ expected_targets_(
55
+ gpr_strdup(grpc_fake_transport_get_expected_targets(args))),
56
+ is_lb_channel_(grpc_core::FindTargetAuthorityTableInArgs(args) !=
57
+ nullptr) {
58
+ const grpc_arg* target_name_override_arg =
59
+ grpc_channel_args_find(args, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
60
+ if (target_name_override_arg != nullptr) {
61
+ target_name_override_ =
62
+ gpr_strdup(grpc_channel_arg_get_string(target_name_override_arg));
63
+ } else {
64
+ target_name_override_ = nullptr;
65
+ }
66
+ }
48
67
 
49
- static void fake_channel_destroy(grpc_security_connector* sc) {
50
- grpc_fake_channel_security_connector* c =
51
- reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
52
- grpc_call_credentials_unref(c->base.request_metadata_creds);
53
- gpr_free(c->target);
54
- gpr_free(c->expected_targets);
55
- gpr_free(c->target_name_override);
56
- gpr_free(c);
57
- }
68
+ ~grpc_fake_channel_security_connector() override {
69
+ gpr_free(target_);
70
+ gpr_free(expected_targets_);
71
+ if (target_name_override_ != nullptr) gpr_free(target_name_override_);
72
+ }
58
73
 
59
- static void fake_server_destroy(grpc_security_connector* sc) { gpr_free(sc); }
74
+ void check_peer(tsi_peer peer, grpc_endpoint* ep,
75
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
76
+ grpc_closure* on_peer_checked) override;
60
77
 
61
- static bool fake_check_target(const char* target_type, const char* target,
62
- const char* set_str) {
63
- GPR_ASSERT(target_type != nullptr);
64
- GPR_ASSERT(target != nullptr);
65
- char** set = nullptr;
66
- size_t set_size = 0;
67
- gpr_string_split(set_str, ",", &set, &set_size);
68
- bool found = false;
69
- for (size_t i = 0; i < set_size; ++i) {
70
- if (set[i] != nullptr && strcmp(target, set[i]) == 0) found = true;
78
+ int cmp(const grpc_security_connector* other_sc) const override {
79
+ auto* other =
80
+ reinterpret_cast<const grpc_fake_channel_security_connector*>(other_sc);
81
+ int c = channel_security_connector_cmp(other);
82
+ if (c != 0) return c;
83
+ c = strcmp(target_, other->target_);
84
+ if (c != 0) return c;
85
+ if (expected_targets_ == nullptr || other->expected_targets_ == nullptr) {
86
+ c = GPR_ICMP(expected_targets_, other->expected_targets_);
87
+ } else {
88
+ c = strcmp(expected_targets_, other->expected_targets_);
89
+ }
90
+ if (c != 0) return c;
91
+ return GPR_ICMP(is_lb_channel_, other->is_lb_channel_);
71
92
  }
72
- for (size_t i = 0; i < set_size; ++i) {
73
- gpr_free(set[i]);
93
+
94
+ void add_handshakers(grpc_pollset_set* interested_parties,
95
+ grpc_handshake_manager* handshake_mgr) override {
96
+ grpc_handshake_manager_add(
97
+ handshake_mgr,
98
+ grpc_security_handshaker_create(
99
+ tsi_create_fake_handshaker(/*is_client=*/true), this));
74
100
  }
75
- gpr_free(set);
76
- return found;
77
- }
78
101
 
79
- static void fake_secure_name_check(const char* target,
80
- const char* expected_targets,
81
- bool is_lb_channel) {
82
- if (expected_targets == nullptr) return;
83
- char** lbs_and_backends = nullptr;
84
- size_t lbs_and_backends_size = 0;
85
- bool success = false;
86
- gpr_string_split(expected_targets, ";", &lbs_and_backends,
87
- &lbs_and_backends_size);
88
- if (lbs_and_backends_size > 2 || lbs_and_backends_size == 0) {
89
- gpr_log(GPR_ERROR, "Invalid expected targets arg value: '%s'",
90
- expected_targets);
91
- goto done;
102
+ bool check_call_host(const char* host, grpc_auth_context* auth_context,
103
+ grpc_closure* on_call_host_checked,
104
+ grpc_error** error) override {
105
+ char* authority_hostname = nullptr;
106
+ char* authority_ignored_port = nullptr;
107
+ char* target_hostname = nullptr;
108
+ char* target_ignored_port = nullptr;
109
+ gpr_split_host_port(host, &authority_hostname, &authority_ignored_port);
110
+ gpr_split_host_port(target_, &target_hostname, &target_ignored_port);
111
+ if (target_name_override_ != nullptr) {
112
+ char* fake_security_target_name_override_hostname = nullptr;
113
+ char* fake_security_target_name_override_ignored_port = nullptr;
114
+ gpr_split_host_port(target_name_override_,
115
+ &fake_security_target_name_override_hostname,
116
+ &fake_security_target_name_override_ignored_port);
117
+ if (strcmp(authority_hostname,
118
+ fake_security_target_name_override_hostname) != 0) {
119
+ gpr_log(GPR_ERROR,
120
+ "Authority (host) '%s' != Fake Security Target override '%s'",
121
+ host, fake_security_target_name_override_hostname);
122
+ abort();
123
+ }
124
+ gpr_free(fake_security_target_name_override_hostname);
125
+ gpr_free(fake_security_target_name_override_ignored_port);
126
+ } else if (strcmp(authority_hostname, target_hostname) != 0) {
127
+ gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'",
128
+ authority_hostname, target_hostname);
129
+ abort();
130
+ }
131
+ gpr_free(authority_hostname);
132
+ gpr_free(authority_ignored_port);
133
+ gpr_free(target_hostname);
134
+ gpr_free(target_ignored_port);
135
+ return true;
92
136
  }
93
- if (is_lb_channel) {
94
- if (lbs_and_backends_size != 2) {
95
- gpr_log(GPR_ERROR,
96
- "Invalid expected targets arg value: '%s'. Expectations for LB "
97
- "channels must be of the form 'be1,be2,be3,...;lb1,lb2,...",
98
- expected_targets);
99
- goto done;
137
+
138
+ void cancel_check_call_host(grpc_closure* on_call_host_checked,
139
+ grpc_error* error) override {
140
+ GRPC_ERROR_UNREF(error);
141
+ }
142
+
143
+ char* target() const { return target_; }
144
+ char* expected_targets() const { return expected_targets_; }
145
+ bool is_lb_channel() const { return is_lb_channel_; }
146
+ char* target_name_override() const { return target_name_override_; }
147
+
148
+ private:
149
+ bool fake_check_target(const char* target_type, const char* target,
150
+ const char* set_str) const {
151
+ GPR_ASSERT(target_type != nullptr);
152
+ GPR_ASSERT(target != nullptr);
153
+ char** set = nullptr;
154
+ size_t set_size = 0;
155
+ gpr_string_split(set_str, ",", &set, &set_size);
156
+ bool found = false;
157
+ for (size_t i = 0; i < set_size; ++i) {
158
+ if (set[i] != nullptr && strcmp(target, set[i]) == 0) found = true;
100
159
  }
101
- if (!fake_check_target("LB", target, lbs_and_backends[1])) {
102
- gpr_log(GPR_ERROR, "LB target '%s' not found in expected set '%s'",
103
- target, lbs_and_backends[1]);
104
- goto done;
160
+ for (size_t i = 0; i < set_size; ++i) {
161
+ gpr_free(set[i]);
105
162
  }
106
- success = true;
107
- } else {
108
- if (!fake_check_target("Backend", target, lbs_and_backends[0])) {
109
- gpr_log(GPR_ERROR, "Backend target '%s' not found in expected set '%s'",
110
- target, lbs_and_backends[0]);
163
+ gpr_free(set);
164
+ return found;
165
+ }
166
+
167
+ void fake_secure_name_check() const {
168
+ if (expected_targets_ == nullptr) return;
169
+ char** lbs_and_backends = nullptr;
170
+ size_t lbs_and_backends_size = 0;
171
+ bool success = false;
172
+ gpr_string_split(expected_targets_, ";", &lbs_and_backends,
173
+ &lbs_and_backends_size);
174
+ if (lbs_and_backends_size > 2 || lbs_and_backends_size == 0) {
175
+ gpr_log(GPR_ERROR, "Invalid expected targets arg value: '%s'",
176
+ expected_targets_);
111
177
  goto done;
112
178
  }
113
- success = true;
114
- }
115
- done:
116
- for (size_t i = 0; i < lbs_and_backends_size; ++i) {
117
- gpr_free(lbs_and_backends[i]);
179
+ if (is_lb_channel_) {
180
+ if (lbs_and_backends_size != 2) {
181
+ gpr_log(GPR_ERROR,
182
+ "Invalid expected targets arg value: '%s'. Expectations for LB "
183
+ "channels must be of the form 'be1,be2,be3,...;lb1,lb2,...",
184
+ expected_targets_);
185
+ goto done;
186
+ }
187
+ if (!fake_check_target("LB", target_, lbs_and_backends[1])) {
188
+ gpr_log(GPR_ERROR, "LB target '%s' not found in expected set '%s'",
189
+ target_, lbs_and_backends[1]);
190
+ goto done;
191
+ }
192
+ success = true;
193
+ } else {
194
+ if (!fake_check_target("Backend", target_, lbs_and_backends[0])) {
195
+ gpr_log(GPR_ERROR, "Backend target '%s' not found in expected set '%s'",
196
+ target_, lbs_and_backends[0]);
197
+ goto done;
198
+ }
199
+ success = true;
200
+ }
201
+ done:
202
+ for (size_t i = 0; i < lbs_and_backends_size; ++i) {
203
+ gpr_free(lbs_and_backends[i]);
204
+ }
205
+ gpr_free(lbs_and_backends);
206
+ if (!success) abort();
118
207
  }
119
- gpr_free(lbs_and_backends);
120
- if (!success) abort();
121
- }
122
208
 
123
- static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer,
124
- grpc_auth_context** auth_context,
125
- grpc_closure* on_peer_checked) {
209
+ char* target_;
210
+ char* expected_targets_;
211
+ bool is_lb_channel_;
212
+ char* target_name_override_;
213
+ };
214
+
215
+ static void fake_check_peer(
216
+ grpc_security_connector* sc, tsi_peer peer,
217
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
218
+ grpc_closure* on_peer_checked) {
126
219
  const char* prop_name;
127
220
  grpc_error* error = GRPC_ERROR_NONE;
128
221
  *auth_context = nullptr;
@@ -147,164 +240,66 @@ static void fake_check_peer(grpc_security_connector* sc, tsi_peer peer,
147
240
  "Invalid value for cert type property.");
148
241
  goto end;
149
242
  }
150
- *auth_context = grpc_auth_context_create(nullptr);
243
+ *auth_context = grpc_core::MakeRefCounted<grpc_auth_context>(nullptr);
151
244
  grpc_auth_context_add_cstring_property(
152
- *auth_context, GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
245
+ auth_context->get(), GRPC_TRANSPORT_SECURITY_TYPE_PROPERTY_NAME,
153
246
  GRPC_FAKE_TRANSPORT_SECURITY_TYPE);
154
247
  end:
155
248
  GRPC_CLOSURE_SCHED(on_peer_checked, error);
156
249
  tsi_peer_destruct(&peer);
157
250
  }
158
251
 
159
- static void fake_channel_check_peer(grpc_security_connector* sc, tsi_peer peer,
160
- grpc_auth_context** auth_context,
161
- grpc_closure* on_peer_checked) {
162
- fake_check_peer(sc, peer, auth_context, on_peer_checked);
163
- grpc_fake_channel_security_connector* c =
164
- reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
165
- fake_secure_name_check(c->target, c->expected_targets, c->is_lb_channel);
252
+ void grpc_fake_channel_security_connector::check_peer(
253
+ tsi_peer peer, grpc_endpoint* ep,
254
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
255
+ grpc_closure* on_peer_checked) {
256
+ fake_check_peer(this, peer, auth_context, on_peer_checked);
257
+ fake_secure_name_check();
166
258
  }
167
259
 
168
- static void fake_server_check_peer(grpc_security_connector* sc, tsi_peer peer,
169
- grpc_auth_context** auth_context,
170
- grpc_closure* on_peer_checked) {
171
- fake_check_peer(sc, peer, auth_context, on_peer_checked);
172
- }
260
+ class grpc_fake_server_security_connector
261
+ : public grpc_server_security_connector {
262
+ public:
263
+ grpc_fake_server_security_connector(
264
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds)
265
+ : grpc_server_security_connector(GRPC_FAKE_SECURITY_URL_SCHEME,
266
+ std::move(server_creds)) {}
267
+ ~grpc_fake_server_security_connector() override = default;
173
268
 
174
- static int fake_channel_cmp(grpc_security_connector* sc1,
175
- grpc_security_connector* sc2) {
176
- grpc_fake_channel_security_connector* c1 =
177
- reinterpret_cast<grpc_fake_channel_security_connector*>(sc1);
178
- grpc_fake_channel_security_connector* c2 =
179
- reinterpret_cast<grpc_fake_channel_security_connector*>(sc2);
180
- int c = grpc_channel_security_connector_cmp(&c1->base, &c2->base);
181
- if (c != 0) return c;
182
- c = strcmp(c1->target, c2->target);
183
- if (c != 0) return c;
184
- if (c1->expected_targets == nullptr || c2->expected_targets == nullptr) {
185
- c = GPR_ICMP(c1->expected_targets, c2->expected_targets);
186
- } else {
187
- c = strcmp(c1->expected_targets, c2->expected_targets);
269
+ void check_peer(tsi_peer peer, grpc_endpoint* ep,
270
+ grpc_core::RefCountedPtr<grpc_auth_context>* auth_context,
271
+ grpc_closure* on_peer_checked) override {
272
+ fake_check_peer(this, peer, auth_context, on_peer_checked);
188
273
  }
189
- if (c != 0) return c;
190
- return GPR_ICMP(c1->is_lb_channel, c2->is_lb_channel);
191
- }
192
274
 
193
- static int fake_server_cmp(grpc_security_connector* sc1,
194
- grpc_security_connector* sc2) {
195
- return grpc_server_security_connector_cmp(
196
- reinterpret_cast<grpc_server_security_connector*>(sc1),
197
- reinterpret_cast<grpc_server_security_connector*>(sc2));
198
- }
199
-
200
- static bool fake_channel_check_call_host(grpc_channel_security_connector* sc,
201
- const char* host,
202
- grpc_auth_context* auth_context,
203
- grpc_closure* on_call_host_checked,
204
- grpc_error** error) {
205
- grpc_fake_channel_security_connector* c =
206
- reinterpret_cast<grpc_fake_channel_security_connector*>(sc);
207
- char* authority_hostname = nullptr;
208
- char* authority_ignored_port = nullptr;
209
- char* target_hostname = nullptr;
210
- char* target_ignored_port = nullptr;
211
- gpr_split_host_port(host, &authority_hostname, &authority_ignored_port);
212
- gpr_split_host_port(c->target, &target_hostname, &target_ignored_port);
213
- if (c->target_name_override != nullptr) {
214
- char* fake_security_target_name_override_hostname = nullptr;
215
- char* fake_security_target_name_override_ignored_port = nullptr;
216
- gpr_split_host_port(c->target_name_override,
217
- &fake_security_target_name_override_hostname,
218
- &fake_security_target_name_override_ignored_port);
219
- if (strcmp(authority_hostname,
220
- fake_security_target_name_override_hostname) != 0) {
221
- gpr_log(GPR_ERROR,
222
- "Authority (host) '%s' != Fake Security Target override '%s'",
223
- host, fake_security_target_name_override_hostname);
224
- abort();
225
- }
226
- gpr_free(fake_security_target_name_override_hostname);
227
- gpr_free(fake_security_target_name_override_ignored_port);
228
- } else if (strcmp(authority_hostname, target_hostname) != 0) {
229
- gpr_log(GPR_ERROR, "Authority (host) '%s' != Target '%s'",
230
- authority_hostname, target_hostname);
231
- abort();
275
+ void add_handshakers(grpc_pollset_set* interested_parties,
276
+ grpc_handshake_manager* handshake_mgr) override {
277
+ grpc_handshake_manager_add(
278
+ handshake_mgr,
279
+ grpc_security_handshaker_create(
280
+ tsi_create_fake_handshaker(/*=is_client*/ false), this));
232
281
  }
233
- gpr_free(authority_hostname);
234
- gpr_free(authority_ignored_port);
235
- gpr_free(target_hostname);
236
- gpr_free(target_ignored_port);
237
- return true;
238
- }
239
282
 
240
- static void fake_channel_cancel_check_call_host(
241
- grpc_channel_security_connector* sc, grpc_closure* on_call_host_checked,
242
- grpc_error* error) {
243
- GRPC_ERROR_UNREF(error);
244
- }
245
-
246
- static void fake_channel_add_handshakers(
247
- grpc_channel_security_connector* sc, grpc_pollset_set* interested_parties,
248
- grpc_handshake_manager* handshake_mgr) {
249
- grpc_handshake_manager_add(
250
- handshake_mgr,
251
- grpc_security_handshaker_create(
252
- tsi_create_fake_handshaker(true /* is_client */), &sc->base));
253
- }
254
-
255
- static void fake_server_add_handshakers(grpc_server_security_connector* sc,
256
- grpc_pollset_set* interested_parties,
257
- grpc_handshake_manager* handshake_mgr) {
258
- grpc_handshake_manager_add(
259
- handshake_mgr,
260
- grpc_security_handshaker_create(
261
- tsi_create_fake_handshaker(false /* is_client */), &sc->base));
262
- }
263
-
264
- static grpc_security_connector_vtable fake_channel_vtable = {
265
- fake_channel_destroy, fake_channel_check_peer, fake_channel_cmp};
266
-
267
- static grpc_security_connector_vtable fake_server_vtable = {
268
- fake_server_destroy, fake_server_check_peer, fake_server_cmp};
269
-
270
- grpc_channel_security_connector* grpc_fake_channel_security_connector_create(
271
- grpc_channel_credentials* channel_creds,
272
- grpc_call_credentials* request_metadata_creds, const char* target,
273
- const grpc_channel_args* args) {
274
- grpc_fake_channel_security_connector* c =
275
- static_cast<grpc_fake_channel_security_connector*>(
276
- gpr_zalloc(sizeof(*c)));
277
- gpr_ref_init(&c->base.base.refcount, 1);
278
- c->base.base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
279
- c->base.base.vtable = &fake_channel_vtable;
280
- c->base.channel_creds = channel_creds;
281
- c->base.request_metadata_creds =
282
- grpc_call_credentials_ref(request_metadata_creds);
283
- c->base.check_call_host = fake_channel_check_call_host;
284
- c->base.cancel_check_call_host = fake_channel_cancel_check_call_host;
285
- c->base.add_handshakers = fake_channel_add_handshakers;
286
- c->target = gpr_strdup(target);
287
- const char* expected_targets = grpc_fake_transport_get_expected_targets(args);
288
- c->expected_targets = gpr_strdup(expected_targets);
289
- c->is_lb_channel = grpc_core::FindTargetAuthorityTableInArgs(args) != nullptr;
290
- const grpc_arg* target_name_override_arg =
291
- grpc_channel_args_find(args, GRPC_SSL_TARGET_NAME_OVERRIDE_ARG);
292
- if (target_name_override_arg != nullptr) {
293
- c->target_name_override =
294
- gpr_strdup(grpc_channel_arg_get_string(target_name_override_arg));
283
+ int cmp(const grpc_security_connector* other) const override {
284
+ return server_security_connector_cmp(
285
+ static_cast<const grpc_server_security_connector*>(other));
295
286
  }
296
- return &c->base;
287
+ };
288
+ } // namespace
289
+
290
+ grpc_core::RefCountedPtr<grpc_channel_security_connector>
291
+ grpc_fake_channel_security_connector_create(
292
+ grpc_core::RefCountedPtr<grpc_channel_credentials> channel_creds,
293
+ grpc_core::RefCountedPtr<grpc_call_credentials> request_metadata_creds,
294
+ const char* target, const grpc_channel_args* args) {
295
+ return grpc_core::MakeRefCounted<grpc_fake_channel_security_connector>(
296
+ std::move(channel_creds), std::move(request_metadata_creds), target,
297
+ args);
297
298
  }
298
299
 
299
- grpc_server_security_connector* grpc_fake_server_security_connector_create(
300
- grpc_server_credentials* server_creds) {
301
- grpc_server_security_connector* c =
302
- static_cast<grpc_server_security_connector*>(
303
- gpr_zalloc(sizeof(grpc_server_security_connector)));
304
- gpr_ref_init(&c->base.refcount, 1);
305
- c->base.vtable = &fake_server_vtable;
306
- c->base.url_scheme = GRPC_FAKE_SECURITY_URL_SCHEME;
307
- c->server_creds = server_creds;
308
- c->add_handshakers = fake_server_add_handshakers;
309
- return c;
300
+ grpc_core::RefCountedPtr<grpc_server_security_connector>
301
+ grpc_fake_server_security_connector_create(
302
+ grpc_core::RefCountedPtr<grpc_server_credentials> server_creds) {
303
+ return grpc_core::MakeRefCounted<grpc_fake_server_security_connector>(
304
+ std::move(server_creds));
310
305
  }