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.
- checksums.yaml +4 -4
- data/Makefile +301 -33
- data/include/grpc/grpc_security.h +195 -0
- data/include/grpc/impl/codegen/grpc_types.h +17 -1
- data/include/grpc/impl/codegen/port_platform.h +36 -0
- data/include/grpc/impl/codegen/slice.h +1 -1
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +2 -0
- data/src/core/ext/filters/client_channel/client_channel.cc +74 -69
- data/src/core/ext/filters/client_channel/client_channel.h +2 -2
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +5 -6
- data/src/core/ext/filters/client_channel/client_channel_channelz.h +5 -4
- data/src/core/ext/filters/client_channel/client_channel_factory.cc +2 -2
- data/src/core/ext/filters/client_channel/client_channel_factory.h +4 -4
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +3 -3
- data/src/core/ext/filters/client_channel/global_subchannel_pool.cc +176 -0
- data/src/core/ext/filters/client_channel/global_subchannel_pool.h +68 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +10 -8
- data/src/core/ext/filters/client_channel/health/health_check_client.h +1 -1
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +146 -156
- data/src/core/ext/filters/client_channel/lb_policy.cc +30 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +28 -30
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +5 -8
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +5 -8
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +23 -24
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +80 -15
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +6 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +1 -1
- data/src/core/ext/filters/client_channel/local_subchannel_pool.cc +96 -0
- data/src/core/ext/filters/client_channel/local_subchannel_pool.h +56 -0
- data/src/core/ext/filters/client_channel/parse_address.cc +24 -5
- data/src/core/ext/filters/client_channel/request_routing.cc +13 -3
- data/src/core/ext/filters/client_channel/request_routing.h +5 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +11 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +7 -35
- data/src/core/ext/filters/client_channel/subchannel.cc +698 -791
- data/src/core/ext/filters/client_channel/subchannel.h +213 -123
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.cc +97 -0
- data/src/core/ext/filters/client_channel/subchannel_pool_interface.h +94 -0
- data/src/core/ext/filters/http/client_authority_filter.cc +5 -2
- data/src/core/ext/filters/max_age/max_age_filter.cc +1 -1
- data/src/core/ext/transport/chttp2/client/chttp2_connector.cc +13 -12
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +5 -7
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +19 -27
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +18 -19
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +27 -6
- data/src/core/ext/transport/chttp2/transport/flow_control.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_window_update.cc +3 -2
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/writing.cc +8 -5
- data/src/core/lib/channel/handshaker.cc +141 -214
- data/src/core/lib/channel/handshaker.h +110 -101
- data/src/core/lib/channel/handshaker_factory.h +11 -19
- data/src/core/lib/channel/handshaker_registry.cc +64 -52
- data/src/core/lib/channel/handshaker_registry.h +21 -16
- data/src/core/lib/gpr/log_posix.cc +2 -1
- data/src/core/lib/gpr/time.cc +8 -0
- data/src/core/lib/gpr/time_posix.cc +8 -2
- data/src/core/lib/gprpp/optional.h +47 -0
- data/src/core/lib/http/httpcli_security_connector.cc +13 -14
- data/src/core/lib/iomgr/buffer_list.cc +182 -24
- data/src/core/lib/iomgr/buffer_list.h +70 -8
- data/src/core/lib/iomgr/combiner.cc +11 -3
- data/src/core/lib/iomgr/error.cc +9 -5
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +3 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +136 -162
- data/src/core/lib/iomgr/ev_poll_posix.cc +3 -0
- data/src/core/lib/iomgr/ev_posix.cc +4 -0
- data/src/core/lib/iomgr/ev_posix.h +4 -0
- data/src/core/lib/iomgr/exec_ctx.cc +1 -0
- data/src/core/lib/iomgr/exec_ctx.h +137 -8
- data/src/core/lib/iomgr/executor.cc +122 -87
- data/src/core/lib/iomgr/executor.h +53 -48
- data/src/core/lib/iomgr/fork_posix.cc +6 -4
- data/src/core/lib/iomgr/{network_status_tracker.cc → grpc_if_nametoindex.h} +8 -14
- data/src/core/lib/iomgr/grpc_if_nametoindex_posix.cc +42 -0
- data/src/core/lib/iomgr/{network_status_tracker.h → grpc_if_nametoindex_unsupported.cc} +15 -9
- data/src/core/lib/iomgr/internal_errqueue.h +105 -3
- data/src/core/lib/iomgr/iomgr.cc +6 -5
- data/src/core/lib/iomgr/iomgr.h +8 -0
- data/src/core/lib/iomgr/iomgr_custom.cc +6 -2
- data/src/core/lib/iomgr/iomgr_internal.cc +4 -0
- data/src/core/lib/iomgr/iomgr_internal.h +4 -0
- data/src/core/lib/iomgr/iomgr_posix.cc +10 -1
- data/src/core/lib/iomgr/iomgr_windows.cc +8 -1
- data/src/core/lib/iomgr/port.h +1 -0
- data/src/core/lib/iomgr/resolve_address_posix.cc +4 -3
- data/src/core/lib/iomgr/resolve_address_windows.cc +2 -1
- data/src/core/lib/iomgr/tcp_custom.cc +0 -4
- data/src/core/lib/iomgr/tcp_posix.cc +58 -44
- data/src/core/lib/iomgr/tcp_uv.cc +0 -1
- data/src/core/lib/iomgr/tcp_windows.cc +0 -4
- data/src/core/lib/iomgr/timer_manager.cc +8 -0
- data/src/core/lib/iomgr/udp_server.cc +6 -4
- data/src/core/lib/json/json.cc +1 -4
- data/src/core/lib/security/credentials/alts/alts_credentials.cc +1 -1
- data/src/core/lib/security/credentials/alts/check_gcp_environment_no_op.cc +2 -2
- data/src/core/lib/security/credentials/composite/composite_credentials.h +4 -0
- data/src/core/lib/security/credentials/credentials.h +9 -1
- data/src/core/lib/security/credentials/google_default/google_default_credentials.cc +15 -2
- data/src/core/lib/security/credentials/google_default/google_default_credentials.h +2 -0
- data/src/core/lib/security/credentials/jwt/json_token.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -0
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +3 -2
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +2 -2
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +1 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +192 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +213 -0
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +10 -8
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +6 -10
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +10 -8
- data/src/core/lib/security/security_connector/security_connector.h +2 -2
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +4 -6
- data/src/core/lib/security/security_connector/ssl_utils.h +33 -0
- data/src/core/lib/security/transport/security_handshaker.cc +267 -300
- data/src/core/lib/security/transport/security_handshaker.h +11 -2
- data/src/core/lib/security/transport/server_auth_filter.cc +1 -0
- data/src/core/lib/surface/call.cc +5 -1
- data/src/core/lib/surface/channel_init.h +5 -0
- data/src/core/lib/surface/completion_queue.cc +4 -7
- data/src/core/lib/surface/init.cc +5 -3
- data/src/core/lib/surface/init_secure.cc +1 -1
- data/src/core/lib/surface/server.cc +19 -17
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/service_config.h +1 -0
- data/src/core/lib/transport/static_metadata.cc +279 -279
- data/src/core/lib/transport/transport.cc +5 -3
- data/src/core/tsi/ssl_transport_security.cc +10 -4
- data/src/ruby/ext/grpc/extconf.rb +12 -4
- data/src/ruby/ext/grpc/rb_call_credentials.c +8 -5
- data/src/ruby/ext/grpc/rb_channel.c +14 -10
- data/src/ruby/ext/grpc/rb_channel_credentials.c +8 -4
- data/src/ruby/ext/grpc/rb_compression_options.c +9 -7
- data/src/ruby/ext/grpc/rb_event_thread.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc.c +22 -23
- data/src/ruby/ext/grpc/rb_grpc.h +4 -2
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +18 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +27 -0
- data/src/ruby/ext/grpc/rb_server.c +8 -4
- data/src/ruby/lib/grpc/version.rb +1 -1
- metadata +46 -39
- data/src/core/ext/filters/client_channel/subchannel_index.cc +0 -248
- data/src/core/ext/filters/client_channel/subchannel_index.h +0 -76
- 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
|
-
|
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
|
-
}
|
70
|
+
void* user_data = nullptr;
|
71
|
+
};
|
69
72
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
+
///
|
74
|
+
/// Handshaker
|
75
|
+
///
|
73
76
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
-
|
98
|
-
|
99
|
-
|
88
|
+
//
|
89
|
+
// HandshakeManager
|
90
|
+
//
|
100
91
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
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
|
-
///
|
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
|
-
|
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
|
-
///
|
116
|
-
|
110
|
+
/// Adds a handshaker to the handshake manager.
|
111
|
+
/// Takes ownership of \a handshaker.
|
112
|
+
void Add(RefCountedPtr<Handshaker> handshaker);
|
117
113
|
|
118
|
-
///
|
119
|
-
///
|
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
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
45
|
-
|
46
|
-
grpc_pollset_set* interested_parties,
|
47
|
-
grpc_handshake_manager* handshake_mgr);
|
39
|
+
GRPC_ABSTRACT_BASE_CLASS
|
40
|
+
};
|
48
41
|
|
49
|
-
|
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
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
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
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
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
|
82
|
-
|
83
|
-
|
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
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
-
}
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
///
|
38
|
-
///
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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 */
|