grpc 1.18.0 → 1.19.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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/Makefile +301 -33
  3. data/include/grpc/grpc_security.h +195 -0
  4. data/include/grpc/impl/codegen/grpc_types.h +17 -1
  5. data/include/grpc/impl/codegen/port_platform.h +36 -0
  6. data/include/grpc/impl/codegen/slice.h +1 -1
  7. data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
  8. data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
  9. data/src/core/ext/filters/client_channel/client_channel.h +2 -2
  10. data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
  11. data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
  12. data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
  13. data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
  14. data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
  15. data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
  16. data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
  17. data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
  18. data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
  19. data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
  20. data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
  21. data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
  22. data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
  23. data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
  24. data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
  25. data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
  26. data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
  27. data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
  28. data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
  29. data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
  30. data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
  31. data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
  32. data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
  33. data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
  34. data/src/core/ext/filters/client_channel/request_routing.h +5 -1
  35. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
  36. data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
  37. data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
  38. data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
  39. data/src/core/ext/filters/client_channel/subchannel.h +213 -123
  40. data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
  41. data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
  42. data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
  43. data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
  44. data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
  45. data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
  46. data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
  47. data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
  48. data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
  49. data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
  50. data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
  51. data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
  52. data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
  53. data/src/core/lib/channel/handshaker.cc +141 -214
  54. data/src/core/lib/channel/handshaker.h +110 -101
  55. data/src/core/lib/channel/handshaker_factory.h +11 -19
  56. data/src/core/lib/channel/handshaker_registry.cc +64 -52
  57. data/src/core/lib/channel/handshaker_registry.h +21 -16
  58. data/src/core/lib/gpr/log_posix.cc +2 -1
  59. data/src/core/lib/gpr/time.cc +8 -0
  60. data/src/core/lib/gpr/time_posix.cc +8 -2
  61. data/src/core/lib/gprpp/optional.h +47 -0
  62. data/src/core/lib/http/httpcli_security_connector.cc +13 -14
  63. data/src/core/lib/iomgr/buffer_list.cc +182 -24
  64. data/src/core/lib/iomgr/buffer_list.h +70 -8
  65. data/src/core/lib/iomgr/combiner.cc +11 -3
  66. data/src/core/lib/iomgr/error.cc +9 -5
  67. data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
  68. data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
  69. data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
  70. data/src/core/lib/iomgr/ev_posix.cc +4 -0
  71. data/src/core/lib/iomgr/ev_posix.h +4 -0
  72. data/src/core/lib/iomgr/exec_ctx.cc +1 -0
  73. data/src/core/lib/iomgr/exec_ctx.h +137 -8
  74. data/src/core/lib/iomgr/executor.cc +122 -87
  75. data/src/core/lib/iomgr/executor.h +53 -48
  76. data/src/core/lib/iomgr/fork_posix.cc +6 -4
  77. data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
  78. data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
  79. data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
  80. data/src/core/lib/iomgr/internal_errqueue.h +105 -3
  81. data/src/core/lib/iomgr/iomgr.cc +6 -5
  82. data/src/core/lib/iomgr/iomgr.h +8 -0
  83. data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
  84. data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
  85. data/src/core/lib/iomgr/iomgr_internal.h +4 -0
  86. data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
  87. data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
  88. data/src/core/lib/iomgr/port.h +1 -0
  89. data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
  90. data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
  91. data/src/core/lib/iomgr/tcp_custom.cc +0 -4
  92. data/src/core/lib/iomgr/tcp_posix.cc +58 -44
  93. data/src/core/lib/iomgr/tcp_uv.cc +0 -1
  94. data/src/core/lib/iomgr/tcp_windows.cc +0 -4
  95. data/src/core/lib/iomgr/timer_manager.cc +8 -0
  96. data/src/core/lib/iomgr/udp_server.cc +6 -4
  97. data/src/core/lib/json/json.cc +1 -4
  98. data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
  99. data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
  100. data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
  101. data/src/core/lib/security/credentials/credentials.h +9 -1
  102. data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
  103. data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
  104. data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
  105. data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
  106. data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
  107. data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
  108. data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
  109. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
  110. data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
  111. data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
  112. data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
  113. data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
  114. data/src/core/lib/security/security_connector/security_connector.h +2 -2
  115. data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
  116. data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
  117. data/src/core/lib/security/transport/security_handshaker.cc +267 -300
  118. data/src/core/lib/security/transport/security_handshaker.h +11 -2
  119. data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
  120. data/src/core/lib/surface/call.cc +5 -1
  121. data/src/core/lib/surface/channel_init.h +5 -0
  122. data/src/core/lib/surface/completion_queue.cc +4 -7
  123. data/src/core/lib/surface/init.cc +5 -3
  124. data/src/core/lib/surface/init_secure.cc +1 -1
  125. data/src/core/lib/surface/server.cc +19 -17
  126. data/src/core/lib/surface/version.cc +1 -1
  127. data/src/core/lib/transport/service_config.h +1 -0
  128. data/src/core/lib/transport/static_metadata.cc +279 -279
  129. data/src/core/lib/transport/transport.cc +5 -3
  130. data/src/core/tsi/ssl_transport_security.cc +10 -4
  131. data/src/ruby/ext/grpc/extconf.rb +12 -4
  132. data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
  133. data/src/ruby/ext/grpc/rb_channel.c +14 -10
  134. data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
  135. data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
  136. data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
  137. data/src/ruby/ext/grpc/rb_grpc.c +22 -23
  138. data/src/ruby/ext/grpc/rb_grpc.h +4 -2
  139. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
  140. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
  141. data/src/ruby/ext/grpc/rb_server.c +8 -4
  142. data/src/ruby/lib/grpc/version.rb +1 -1
  143. metadata +46 -39
  144. data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
  145. data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
  146. data/src/core/lib/channel/handshaker_factory.cc +0 -42
@@ -21,12 +21,21 @@
21
21
 
22
22
  #include <grpc/support/port_platform.h>
23
23
 
24
+ #include <grpc/support/string_util.h>
25
+
24
26
  #include <grpc/impl/codegen/grpc_types.h>
25
27
 
28
+ #include "src/core/lib/channel/channel_args.h"
29
+ #include "src/core/lib/gprpp/inlined_vector.h"
30
+ #include "src/core/lib/gprpp/mutex_lock.h"
31
+ #include "src/core/lib/gprpp/ref_counted.h"
26
32
  #include "src/core/lib/iomgr/closure.h"
27
33
  #include "src/core/lib/iomgr/endpoint.h"
28
34
  #include "src/core/lib/iomgr/exec_ctx.h"
29
35
  #include "src/core/lib/iomgr/tcp_server.h"
36
+ #include "src/core/lib/iomgr/timer.h"
37
+
38
+ namespace grpc_core {
30
39
 
31
40
  /// Handshakers are used to perform initial handshakes on a connection
32
41
  /// before the client sends the initial request. Some examples of what
@@ -35,12 +44,6 @@
35
44
  ///
36
45
  /// In general, handshakers should be used via a handshake manager.
37
46
 
38
- ///
39
- /// grpc_handshaker
40
- ///
41
-
42
- typedef struct grpc_handshaker grpc_handshaker;
43
-
44
47
  /// Arguments passed through handshakers and to the on_handshake_done callback.
45
48
  ///
46
49
  /// For handshakers, all members are input/output parameters; for
@@ -55,115 +58,121 @@ typedef struct grpc_handshaker grpc_handshaker;
55
58
  ///
56
59
  /// For the on_handshake_done callback, all members are input arguments,
57
60
  /// which the callback takes ownership of.
58
- typedef struct {
59
- grpc_endpoint* endpoint;
60
- grpc_channel_args* args;
61
- grpc_slice_buffer* read_buffer;
61
+ struct HandshakerArgs {
62
+ grpc_endpoint* endpoint = nullptr;
63
+ grpc_channel_args* args = nullptr;
64
+ grpc_slice_buffer* read_buffer = nullptr;
62
65
  // A handshaker may set this to true before invoking on_handshake_done
63
66
  // to indicate that subsequent handshakers should be skipped.
64
- bool exit_early;
67
+ bool exit_early = false;
65
68
  // User data passed through the handshake manager. Not used by
66
69
  // individual handshakers.
67
- void* user_data;
68
- } grpc_handshaker_args;
70
+ void* user_data = nullptr;
71
+ };
69
72
 
70
- typedef struct {
71
- /// Destroys the handshaker.
72
- void (*destroy)(grpc_handshaker* handshaker);
73
+ ///
74
+ /// Handshaker
75
+ ///
73
76
 
74
- /// Shuts down the handshaker (e.g., to clean up when the operation is
75
- /// aborted in the middle).
76
- void (*shutdown)(grpc_handshaker* handshaker, grpc_error* why);
77
-
78
- /// Performs handshaking, modifying \a args as needed (e.g., to
79
- /// replace \a endpoint with a wrapped endpoint).
80
- /// When finished, invokes \a on_handshake_done.
81
- /// \a acceptor will be NULL for client-side handshakers.
82
- void (*do_handshake)(grpc_handshaker* handshaker,
83
- grpc_tcp_server_acceptor* acceptor,
84
- grpc_closure* on_handshake_done,
85
- grpc_handshaker_args* args);
86
-
87
- /// The name of the handshaker, for debugging purposes.
88
- const char* name;
89
- } grpc_handshaker_vtable;
90
-
91
- /// Base struct. To subclass, make this the first member of the
92
- /// implementation struct.
93
- struct grpc_handshaker {
94
- const grpc_handshaker_vtable* vtable;
77
+ class Handshaker : public RefCounted<Handshaker> {
78
+ public:
79
+ virtual ~Handshaker() = default;
80
+ virtual void Shutdown(grpc_error* why) GRPC_ABSTRACT;
81
+ virtual void DoHandshake(grpc_tcp_server_acceptor* acceptor,
82
+ grpc_closure* on_handshake_done,
83
+ HandshakerArgs* args) GRPC_ABSTRACT;
84
+ virtual const char* name() const GRPC_ABSTRACT;
85
+ GRPC_ABSTRACT_BASE_CLASS
95
86
  };
96
87
 
97
- /// Called by concrete implementations to initialize the base struct.
98
- void grpc_handshaker_init(const grpc_handshaker_vtable* vtable,
99
- grpc_handshaker* handshaker);
88
+ //
89
+ // HandshakeManager
90
+ //
100
91
 
101
- void grpc_handshaker_destroy(grpc_handshaker* handshaker);
102
- void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why);
103
- void grpc_handshaker_do_handshake(grpc_handshaker* handshaker,
104
- grpc_tcp_server_acceptor* acceptor,
105
- grpc_closure* on_handshake_done,
106
- grpc_handshaker_args* args);
107
- const char* grpc_handshaker_name(grpc_handshaker* handshaker);
92
+ class HandshakeManager : public RefCounted<HandshakeManager> {
93
+ public:
94
+ HandshakeManager();
95
+ ~HandshakeManager();
108
96
 
109
- ///
110
- /// grpc_handshake_manager
111
- ///
97
+ /// Add \a mgr to the server side list of all pending handshake managers, the
98
+ /// list starts with \a *head.
99
+ // Not thread-safe. Caller needs to synchronize.
100
+ void AddToPendingMgrList(HandshakeManager** head);
101
+
102
+ /// Remove \a mgr from the server side list of all pending handshake managers.
103
+ // Not thread-safe. Caller needs to synchronize.
104
+ void RemoveFromPendingMgrList(HandshakeManager** head);
112
105
 
113
- typedef struct grpc_handshake_manager grpc_handshake_manager;
106
+ /// Shutdown all pending handshake managers starting at head on the server
107
+ /// side. Not thread-safe. Caller needs to synchronize.
108
+ void ShutdownAllPending(grpc_error* why);
114
109
 
115
- /// Creates a new handshake manager. Caller takes ownership.
116
- grpc_handshake_manager* grpc_handshake_manager_create();
110
+ /// Adds a handshaker to the handshake manager.
111
+ /// Takes ownership of \a handshaker.
112
+ void Add(RefCountedPtr<Handshaker> handshaker);
117
113
 
118
- /// Adds a handshaker to the handshake manager.
119
- /// Takes ownership of \a handshaker.
114
+ /// Shuts down the handshake manager (e.g., to clean up when the operation is
115
+ /// aborted in the middle).
116
+ void Shutdown(grpc_error* why);
117
+
118
+ /// Invokes handshakers in the order they were added.
119
+ /// Takes ownership of \a endpoint, and then passes that ownership to
120
+ /// the \a on_handshake_done callback.
121
+ /// Does NOT take ownership of \a channel_args. Instead, makes a copy before
122
+ /// invoking the first handshaker.
123
+ /// \a acceptor will be nullptr for client-side handshakers.
124
+ ///
125
+ /// When done, invokes \a on_handshake_done with a HandshakerArgs
126
+ /// object as its argument. If the callback is invoked with error !=
127
+ /// GRPC_ERROR_NONE, then handshaking failed and the handshaker has done
128
+ /// the necessary clean-up. Otherwise, the callback takes ownership of
129
+ /// the arguments.
130
+ void DoHandshake(grpc_endpoint* endpoint,
131
+ const grpc_channel_args* channel_args, grpc_millis deadline,
132
+ grpc_tcp_server_acceptor* acceptor,
133
+ grpc_iomgr_cb_func on_handshake_done, void* user_data);
134
+
135
+ private:
136
+ bool CallNextHandshakerLocked(grpc_error* error);
137
+
138
+ // A function used as the handshaker-done callback when chaining
139
+ // handshakers together.
140
+ static void CallNextHandshakerFn(void* arg, grpc_error* error);
141
+
142
+ // Callback invoked when deadline is exceeded.
143
+ static void OnTimeoutFn(void* arg, grpc_error* error);
144
+
145
+ static const size_t HANDSHAKERS_INIT_SIZE = 2;
146
+
147
+ gpr_mu mu_;
148
+ bool is_shutdown_ = false;
149
+ // An array of handshakers added via grpc_handshake_manager_add().
150
+ InlinedVector<RefCountedPtr<Handshaker>, HANDSHAKERS_INIT_SIZE> handshakers_;
151
+ // The index of the handshaker to invoke next and closure to invoke it.
152
+ size_t index_ = 0;
153
+ grpc_closure call_next_handshaker_;
154
+ // The acceptor to call the handshakers with.
155
+ grpc_tcp_server_acceptor* acceptor_;
156
+ // Deadline timer across all handshakers.
157
+ grpc_timer deadline_timer_;
158
+ grpc_closure on_timeout_;
159
+ // The final callback and user_data to invoke after the last handshaker.
160
+ grpc_closure on_handshake_done_;
161
+ // Handshaker args.
162
+ HandshakerArgs args_;
163
+ // Links to the previous and next managers in a list of all pending handshakes
164
+ // Used at server side only.
165
+ HandshakeManager* prev_ = nullptr;
166
+ HandshakeManager* next_ = nullptr;
167
+ };
168
+
169
+ } // namespace grpc_core
170
+
171
+ // TODO(arjunroy): These are transitional to account for the new handshaker API
172
+ // and will eventually be removed entirely.
173
+ typedef grpc_core::HandshakeManager grpc_handshake_manager;
174
+ typedef grpc_core::Handshaker grpc_handshaker;
120
175
  void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
121
176
  grpc_handshaker* handshaker);
122
177
 
123
- /// Destroys the handshake manager.
124
- void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr);
125
-
126
- /// Shuts down the handshake manager (e.g., to clean up when the operation is
127
- /// aborted in the middle).
128
- /// The caller must still call grpc_handshake_manager_destroy() after
129
- /// calling this function.
130
- void grpc_handshake_manager_shutdown(grpc_handshake_manager* mgr,
131
- grpc_error* why);
132
-
133
- /// Invokes handshakers in the order they were added.
134
- /// Takes ownership of \a endpoint, and then passes that ownership to
135
- /// the \a on_handshake_done callback.
136
- /// Does NOT take ownership of \a channel_args. Instead, makes a copy before
137
- /// invoking the first handshaker.
138
- /// \a acceptor will be nullptr for client-side handshakers.
139
- ///
140
- /// When done, invokes \a on_handshake_done with a grpc_handshaker_args
141
- /// object as its argument. If the callback is invoked with error !=
142
- /// GRPC_ERROR_NONE, then handshaking failed and the handshaker has done
143
- /// the necessary clean-up. Otherwise, the callback takes ownership of
144
- /// the arguments.
145
- void grpc_handshake_manager_do_handshake(grpc_handshake_manager* mgr,
146
- grpc_endpoint* endpoint,
147
- const grpc_channel_args* channel_args,
148
- grpc_millis deadline,
149
- grpc_tcp_server_acceptor* acceptor,
150
- grpc_iomgr_cb_func on_handshake_done,
151
- void* user_data);
152
-
153
- /// Add \a mgr to the server side list of all pending handshake managers, the
154
- /// list starts with \a *head.
155
- // Not thread-safe. Caller needs to synchronize.
156
- void grpc_handshake_manager_pending_list_add(grpc_handshake_manager** head,
157
- grpc_handshake_manager* mgr);
158
-
159
- /// Remove \a mgr from the server side list of all pending handshake managers.
160
- // Not thread-safe. Caller needs to synchronize.
161
- void grpc_handshake_manager_pending_list_remove(grpc_handshake_manager** head,
162
- grpc_handshake_manager* mgr);
163
-
164
- /// Shutdown all pending handshake managers on the server side.
165
- // Not thread-safe. Caller needs to synchronize.
166
- void grpc_handshake_manager_pending_list_shutdown_all(
167
- grpc_handshake_manager* head, grpc_error* why);
168
-
169
178
  #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_H */
@@ -27,26 +27,18 @@
27
27
 
28
28
  // A handshaker factory is used to create handshakers.
29
29
 
30
- typedef struct grpc_handshaker_factory grpc_handshaker_factory;
31
-
32
- typedef struct {
33
- void (*add_handshakers)(grpc_handshaker_factory* handshaker_factory,
34
- const grpc_channel_args* args,
35
- grpc_pollset_set* interested_parties,
36
- grpc_handshake_manager* handshake_mgr);
37
- void (*destroy)(grpc_handshaker_factory* handshaker_factory);
38
- } grpc_handshaker_factory_vtable;
39
-
40
- struct grpc_handshaker_factory {
41
- const grpc_handshaker_factory_vtable* vtable;
42
- };
30
+ namespace grpc_core {
31
+
32
+ class HandshakerFactory {
33
+ public:
34
+ virtual void AddHandshakers(const grpc_channel_args* args,
35
+ grpc_pollset_set* interested_parties,
36
+ HandshakeManager* handshake_mgr) GRPC_ABSTRACT;
37
+ virtual ~HandshakerFactory() = default;
43
38
 
44
- void grpc_handshaker_factory_add_handshakers(
45
- grpc_handshaker_factory* handshaker_factory, const grpc_channel_args* args,
46
- grpc_pollset_set* interested_parties,
47
- grpc_handshake_manager* handshake_mgr);
39
+ GRPC_ABSTRACT_BASE_CLASS
40
+ };
48
41
 
49
- void grpc_handshaker_factory_destroy(
50
- grpc_handshaker_factory* handshaker_factory);
42
+ } // namespace grpc_core
51
43
 
52
44
  #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_FACTORY_H */
@@ -19,8 +19,11 @@
19
19
  #include <grpc/support/port_platform.h>
20
20
 
21
21
  #include "src/core/lib/channel/handshaker_registry.h"
22
+ #include "src/core/lib/gprpp/inlined_vector.h"
23
+ #include "src/core/lib/gprpp/memory.h"
22
24
 
23
25
  #include <string.h>
26
+ #include <algorithm>
24
27
 
25
28
  #include <grpc/support/alloc.h>
26
29
 
@@ -28,74 +31,83 @@
28
31
  // grpc_handshaker_factory_list
29
32
  //
30
33
 
31
- typedef struct {
32
- grpc_handshaker_factory** list;
33
- size_t num_factories;
34
- } grpc_handshaker_factory_list;
35
-
36
- static void grpc_handshaker_factory_list_register(
37
- grpc_handshaker_factory_list* list, bool at_start,
38
- grpc_handshaker_factory* factory) {
39
- list->list = static_cast<grpc_handshaker_factory**>(gpr_realloc(
40
- list->list,
41
- (list->num_factories + 1) * sizeof(grpc_handshaker_factory*)));
42
- if (at_start) {
43
- memmove(list->list + 1, list->list,
44
- sizeof(grpc_handshaker_factory*) * list->num_factories);
45
- list->list[0] = factory;
46
- } else {
47
- list->list[list->num_factories] = factory;
48
- }
49
- ++list->num_factories;
50
- }
34
+ namespace grpc_core {
35
+
36
+ namespace {
37
+
38
+ class HandshakerFactoryList {
39
+ public:
40
+ void Register(bool at_start, UniquePtr<HandshakerFactory> factory);
41
+ void AddHandshakers(const grpc_channel_args* args,
42
+ grpc_pollset_set* interested_parties,
43
+ HandshakeManager* handshake_mgr);
44
+
45
+ private:
46
+ InlinedVector<UniquePtr<HandshakerFactory>, 2> factories_;
47
+ };
51
48
 
52
- static void grpc_handshaker_factory_list_add_handshakers(
53
- grpc_handshaker_factory_list* list, const grpc_channel_args* args,
54
- grpc_pollset_set* interested_parties,
55
- grpc_handshake_manager* handshake_mgr) {
56
- for (size_t i = 0; i < list->num_factories; ++i) {
57
- grpc_handshaker_factory_add_handshakers(list->list[i], args,
58
- interested_parties, handshake_mgr);
49
+ HandshakerFactoryList* g_handshaker_factory_lists = nullptr;
50
+
51
+ } // namespace
52
+
53
+ void HandshakerFactoryList::Register(bool at_start,
54
+ UniquePtr<HandshakerFactory> factory) {
55
+ factories_.push_back(std::move(factory));
56
+ if (at_start) {
57
+ auto* end = &factories_[factories_.size() - 1];
58
+ std::rotate(&factories_[0], end, end + 1);
59
59
  }
60
60
  }
61
61
 
62
- static void grpc_handshaker_factory_list_destroy(
63
- grpc_handshaker_factory_list* list) {
64
- for (size_t i = 0; i < list->num_factories; ++i) {
65
- grpc_handshaker_factory_destroy(list->list[i]);
62
+ void HandshakerFactoryList::AddHandshakers(const grpc_channel_args* args,
63
+ grpc_pollset_set* interested_parties,
64
+ HandshakeManager* handshake_mgr) {
65
+ for (size_t idx = 0; idx < factories_.size(); ++idx) {
66
+ auto& handshaker_factory = factories_[idx];
67
+ handshaker_factory->AddHandshakers(args, interested_parties, handshake_mgr);
66
68
  }
67
- gpr_free(list->list);
68
69
  }
69
70
 
70
71
  //
71
72
  // plugin
72
73
  //
73
74
 
74
- static grpc_handshaker_factory_list
75
- g_handshaker_factory_lists[NUM_HANDSHAKER_TYPES];
76
-
77
- void grpc_handshaker_factory_registry_init() {
78
- memset(g_handshaker_factory_lists, 0, sizeof(g_handshaker_factory_lists));
75
+ void HandshakerRegistry::Init() {
76
+ GPR_ASSERT(g_handshaker_factory_lists == nullptr);
77
+ g_handshaker_factory_lists = static_cast<HandshakerFactoryList*>(
78
+ gpr_malloc(sizeof(*g_handshaker_factory_lists) * NUM_HANDSHAKER_TYPES));
79
+ GPR_ASSERT(g_handshaker_factory_lists != nullptr);
80
+ for (auto idx = 0; idx < NUM_HANDSHAKER_TYPES; ++idx) {
81
+ auto factory_list = g_handshaker_factory_lists + idx;
82
+ new (factory_list) HandshakerFactoryList();
83
+ }
79
84
  }
80
85
 
81
- void grpc_handshaker_factory_registry_shutdown() {
82
- for (size_t i = 0; i < NUM_HANDSHAKER_TYPES; ++i) {
83
- grpc_handshaker_factory_list_destroy(&g_handshaker_factory_lists[i]);
86
+ void HandshakerRegistry::Shutdown() {
87
+ GPR_ASSERT(g_handshaker_factory_lists != nullptr);
88
+ for (auto idx = 0; idx < NUM_HANDSHAKER_TYPES; ++idx) {
89
+ auto factory_list = g_handshaker_factory_lists + idx;
90
+ factory_list->~HandshakerFactoryList();
84
91
  }
92
+ gpr_free(g_handshaker_factory_lists);
93
+ g_handshaker_factory_lists = nullptr;
85
94
  }
86
95
 
87
- void grpc_handshaker_factory_register(bool at_start,
88
- grpc_handshaker_type handshaker_type,
89
- grpc_handshaker_factory* factory) {
90
- grpc_handshaker_factory_list_register(
91
- &g_handshaker_factory_lists[handshaker_type], at_start, factory);
96
+ void HandshakerRegistry::RegisterHandshakerFactory(
97
+ bool at_start, HandshakerType handshaker_type,
98
+ UniquePtr<HandshakerFactory> factory) {
99
+ GPR_ASSERT(g_handshaker_factory_lists != nullptr);
100
+ auto& factory_list = g_handshaker_factory_lists[handshaker_type];
101
+ factory_list.Register(at_start, std::move(factory));
92
102
  }
93
103
 
94
- void grpc_handshakers_add(grpc_handshaker_type handshaker_type,
95
- const grpc_channel_args* args,
96
- grpc_pollset_set* interested_parties,
97
- grpc_handshake_manager* handshake_mgr) {
98
- grpc_handshaker_factory_list_add_handshakers(
99
- &g_handshaker_factory_lists[handshaker_type], args, interested_parties,
100
- handshake_mgr);
104
+ void HandshakerRegistry::AddHandshakers(HandshakerType handshaker_type,
105
+ const grpc_channel_args* args,
106
+ grpc_pollset_set* interested_parties,
107
+ HandshakeManager* handshake_mgr) {
108
+ GPR_ASSERT(g_handshaker_factory_lists != nullptr);
109
+ auto& factory_list = g_handshaker_factory_lists[handshaker_type];
110
+ factory_list.AddHandshakers(args, interested_parties, handshake_mgr);
101
111
  }
112
+
113
+ } // namespace grpc_core
@@ -25,25 +25,30 @@
25
25
 
26
26
  #include "src/core/lib/channel/handshaker_factory.h"
27
27
 
28
+ namespace grpc_core {
29
+
28
30
  typedef enum {
29
31
  HANDSHAKER_CLIENT = 0,
30
32
  HANDSHAKER_SERVER,
31
33
  NUM_HANDSHAKER_TYPES, // Must be last.
32
- } grpc_handshaker_type;
33
-
34
- void grpc_handshaker_factory_registry_init();
35
- void grpc_handshaker_factory_registry_shutdown();
36
-
37
- /// Registers a new handshaker factory. Takes ownership.
38
- /// If \a at_start is true, the new handshaker will be at the beginning of
39
- /// the list. Otherwise, it will be added to the end.
40
- void grpc_handshaker_factory_register(bool at_start,
41
- grpc_handshaker_type handshaker_type,
42
- grpc_handshaker_factory* factory);
43
-
44
- void grpc_handshakers_add(grpc_handshaker_type handshaker_type,
45
- const grpc_channel_args* args,
46
- grpc_pollset_set* interested_parties,
47
- grpc_handshake_manager* handshake_mgr);
34
+ } HandshakerType;
35
+
36
+ class HandshakerRegistry {
37
+ public:
38
+ /// Registers a new handshaker factory. Takes ownership.
39
+ /// If \a at_start is true, the new handshaker will be at the beginning of
40
+ /// the list. Otherwise, it will be added to the end.
41
+ static void RegisterHandshakerFactory(bool at_start,
42
+ HandshakerType handshaker_type,
43
+ UniquePtr<HandshakerFactory> factory);
44
+ static void AddHandshakers(HandshakerType handshaker_type,
45
+ const grpc_channel_args* args,
46
+ grpc_pollset_set* interested_parties,
47
+ HandshakeManager* handshake_mgr);
48
+ static void Init();
49
+ static void Shutdown();
50
+ };
51
+
52
+ } // namespace grpc_core
48
53
 
49
54
  #endif /* GRPC_CORE_LIB_CHANNEL_HANDSHAKER_REGISTRY_H */