grpc 1.18.0 → 1.19.0
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 +40 -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/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.cc +30 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +29 -1
- 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_ev_driver_windows.cc +9 -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 +45 -38
- 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
@@ -30,302 +30,229 @@
|
|
30
30
|
#include "src/core/lib/iomgr/timer.h"
|
31
31
|
#include "src/core/lib/slice/slice_internal.h"
|
32
32
|
|
33
|
-
grpc_core
|
33
|
+
namespace grpc_core {
|
34
34
|
|
35
|
-
|
36
|
-
// grpc_handshaker
|
37
|
-
//
|
35
|
+
TraceFlag grpc_handshaker_trace(false, "handshaker");
|
38
36
|
|
39
|
-
|
40
|
-
grpc_handshaker* handshaker) {
|
41
|
-
handshaker->vtable = vtable;
|
42
|
-
}
|
43
|
-
|
44
|
-
void grpc_handshaker_destroy(grpc_handshaker* handshaker) {
|
45
|
-
handshaker->vtable->destroy(handshaker);
|
46
|
-
}
|
47
|
-
|
48
|
-
void grpc_handshaker_shutdown(grpc_handshaker* handshaker, grpc_error* why) {
|
49
|
-
handshaker->vtable->shutdown(handshaker, why);
|
50
|
-
}
|
51
|
-
|
52
|
-
void grpc_handshaker_do_handshake(grpc_handshaker* handshaker,
|
53
|
-
grpc_tcp_server_acceptor* acceptor,
|
54
|
-
grpc_closure* on_handshake_done,
|
55
|
-
grpc_handshaker_args* args) {
|
56
|
-
handshaker->vtable->do_handshake(handshaker, acceptor, on_handshake_done,
|
57
|
-
args);
|
58
|
-
}
|
37
|
+
namespace {
|
59
38
|
|
60
|
-
|
61
|
-
|
39
|
+
char* HandshakerArgsString(HandshakerArgs* args) {
|
40
|
+
char* args_str = grpc_channel_args_string(args->args);
|
41
|
+
size_t num_args = args->args != nullptr ? args->args->num_args : 0;
|
42
|
+
size_t read_buffer_length =
|
43
|
+
args->read_buffer != nullptr ? args->read_buffer->length : 0;
|
44
|
+
char* str;
|
45
|
+
gpr_asprintf(&str,
|
46
|
+
"{endpoint=%p, args=%p {size=%" PRIuPTR
|
47
|
+
": %s}, read_buffer=%p (length=%" PRIuPTR "), exit_early=%d}",
|
48
|
+
args->endpoint, args->args, num_args, args_str,
|
49
|
+
args->read_buffer, read_buffer_length, args->exit_early);
|
50
|
+
gpr_free(args_str);
|
51
|
+
return str;
|
62
52
|
}
|
63
53
|
|
64
|
-
//
|
65
|
-
// grpc_handshake_manager
|
66
|
-
//
|
54
|
+
} // namespace
|
67
55
|
|
68
|
-
|
69
|
-
gpr_mu mu;
|
70
|
-
gpr_refcount refs;
|
71
|
-
bool shutdown;
|
72
|
-
// An array of handshakers added via grpc_handshake_manager_add().
|
73
|
-
size_t count;
|
74
|
-
grpc_handshaker** handshakers;
|
75
|
-
// The index of the handshaker to invoke next and closure to invoke it.
|
76
|
-
size_t index;
|
77
|
-
grpc_closure call_next_handshaker;
|
78
|
-
// The acceptor to call the handshakers with.
|
79
|
-
grpc_tcp_server_acceptor* acceptor;
|
80
|
-
// Deadline timer across all handshakers.
|
81
|
-
grpc_timer deadline_timer;
|
82
|
-
grpc_closure on_timeout;
|
83
|
-
// The final callback and user_data to invoke after the last handshaker.
|
84
|
-
grpc_closure on_handshake_done;
|
85
|
-
void* user_data;
|
86
|
-
// Handshaker args.
|
87
|
-
grpc_handshaker_args args;
|
88
|
-
// Links to the previous and next managers in a list of all pending handshakes
|
89
|
-
// Used at server side only.
|
90
|
-
grpc_handshake_manager* prev;
|
91
|
-
grpc_handshake_manager* next;
|
92
|
-
};
|
56
|
+
HandshakeManager::HandshakeManager() { gpr_mu_init(&mu_); }
|
93
57
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
void grpc_handshake_manager_pending_list_add(grpc_handshake_manager** head,
|
103
|
-
grpc_handshake_manager* mgr) {
|
104
|
-
GPR_ASSERT(mgr->prev == nullptr);
|
105
|
-
GPR_ASSERT(mgr->next == nullptr);
|
106
|
-
mgr->next = *head;
|
58
|
+
/// Add \a mgr to the server side list of all pending handshake managers, the
|
59
|
+
/// list starts with \a *head.
|
60
|
+
// Not thread-safe. Caller needs to synchronize.
|
61
|
+
void HandshakeManager::AddToPendingMgrList(HandshakeManager** head) {
|
62
|
+
GPR_ASSERT(prev_ == nullptr);
|
63
|
+
GPR_ASSERT(next_ == nullptr);
|
64
|
+
next_ = *head;
|
107
65
|
if (*head) {
|
108
|
-
(*head)->
|
66
|
+
(*head)->prev_ = this;
|
109
67
|
}
|
110
|
-
*head =
|
68
|
+
*head = this;
|
111
69
|
}
|
112
70
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
71
|
+
/// Remove \a mgr from the server side list of all pending handshake managers.
|
72
|
+
// Not thread-safe. Caller needs to synchronize.
|
73
|
+
void HandshakeManager::RemoveFromPendingMgrList(HandshakeManager** head) {
|
74
|
+
if (next_ != nullptr) {
|
75
|
+
next_->prev_ = prev_;
|
117
76
|
}
|
118
|
-
if (
|
119
|
-
|
77
|
+
if (prev_ != nullptr) {
|
78
|
+
prev_->next_ = next_;
|
120
79
|
} else {
|
121
|
-
GPR_ASSERT(*head ==
|
122
|
-
*head =
|
80
|
+
GPR_ASSERT(*head == this);
|
81
|
+
*head = next_;
|
123
82
|
}
|
124
83
|
}
|
125
84
|
|
126
|
-
|
127
|
-
|
85
|
+
/// Shutdown all pending handshake managers starting at head on the server
|
86
|
+
/// side. Not thread-safe. Caller needs to synchronize.
|
87
|
+
void HandshakeManager::ShutdownAllPending(grpc_error* why) {
|
88
|
+
auto* head = this;
|
128
89
|
while (head != nullptr) {
|
129
|
-
|
130
|
-
head = head->
|
90
|
+
head->Shutdown(GRPC_ERROR_REF(why));
|
91
|
+
head = head->next_;
|
131
92
|
}
|
132
93
|
GRPC_ERROR_UNREF(why);
|
133
94
|
}
|
134
95
|
|
135
|
-
|
136
|
-
|
137
|
-
void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
|
138
|
-
grpc_handshaker* handshaker) {
|
96
|
+
void HandshakeManager::Add(RefCountedPtr<Handshaker> handshaker) {
|
139
97
|
if (grpc_handshaker_trace.enabled()) {
|
140
98
|
gpr_log(
|
141
99
|
GPR_INFO,
|
142
100
|
"handshake_manager %p: adding handshaker %s [%p] at index %" PRIuPTR,
|
143
|
-
|
144
|
-
}
|
145
|
-
gpr_mu_lock(&mgr->mu);
|
146
|
-
// To avoid allocating memory for each handshaker we add, we double
|
147
|
-
// the number of elements every time we need more.
|
148
|
-
size_t realloc_count = 0;
|
149
|
-
if (mgr->count == 0) {
|
150
|
-
realloc_count = 2;
|
151
|
-
} else if (mgr->count >= 2 && is_power_of_2(mgr->count)) {
|
152
|
-
realloc_count = mgr->count * 2;
|
153
|
-
}
|
154
|
-
if (realloc_count > 0) {
|
155
|
-
mgr->handshakers = static_cast<grpc_handshaker**>(gpr_realloc(
|
156
|
-
mgr->handshakers, realloc_count * sizeof(grpc_handshaker*)));
|
101
|
+
this, handshaker->name(), handshaker.get(), handshakers_.size());
|
157
102
|
}
|
158
|
-
|
159
|
-
|
103
|
+
MutexLock lock(&mu_);
|
104
|
+
handshakers_.push_back(std::move(handshaker));
|
160
105
|
}
|
161
106
|
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
grpc_handshaker_destroy(mgr->handshakers[i]);
|
166
|
-
}
|
167
|
-
gpr_free(mgr->handshakers);
|
168
|
-
gpr_mu_destroy(&mgr->mu);
|
169
|
-
gpr_free(mgr);
|
170
|
-
}
|
171
|
-
}
|
172
|
-
|
173
|
-
void grpc_handshake_manager_destroy(grpc_handshake_manager* mgr) {
|
174
|
-
grpc_handshake_manager_unref(mgr);
|
107
|
+
HandshakeManager::~HandshakeManager() {
|
108
|
+
handshakers_.clear();
|
109
|
+
gpr_mu_destroy(&mu_);
|
175
110
|
}
|
176
111
|
|
177
|
-
void
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
112
|
+
void HandshakeManager::Shutdown(grpc_error* why) {
|
113
|
+
{
|
114
|
+
MutexLock lock(&mu_);
|
115
|
+
// Shutdown the handshaker that's currently in progress, if any.
|
116
|
+
if (!is_shutdown_ && index_ > 0) {
|
117
|
+
is_shutdown_ = true;
|
118
|
+
handshakers_[index_ - 1]->Shutdown(GRPC_ERROR_REF(why));
|
119
|
+
}
|
185
120
|
}
|
186
|
-
gpr_mu_unlock(&mgr->mu);
|
187
121
|
GRPC_ERROR_UNREF(why);
|
188
122
|
}
|
189
123
|
|
190
|
-
static char* handshaker_args_string(grpc_handshaker_args* args) {
|
191
|
-
char* args_str = grpc_channel_args_string(args->args);
|
192
|
-
size_t num_args = args->args != nullptr ? args->args->num_args : 0;
|
193
|
-
size_t read_buffer_length =
|
194
|
-
args->read_buffer != nullptr ? args->read_buffer->length : 0;
|
195
|
-
char* str;
|
196
|
-
gpr_asprintf(&str,
|
197
|
-
"{endpoint=%p, args=%p {size=%" PRIuPTR
|
198
|
-
": %s}, read_buffer=%p (length=%" PRIuPTR "), exit_early=%d}",
|
199
|
-
args->endpoint, args->args, num_args, args_str,
|
200
|
-
args->read_buffer, read_buffer_length, args->exit_early);
|
201
|
-
gpr_free(args_str);
|
202
|
-
return str;
|
203
|
-
}
|
204
|
-
|
205
124
|
// Helper function to call either the next handshaker or the
|
206
125
|
// on_handshake_done callback.
|
207
126
|
// Returns true if we've scheduled the on_handshake_done callback.
|
208
|
-
|
209
|
-
grpc_error* error) {
|
127
|
+
bool HandshakeManager::CallNextHandshakerLocked(grpc_error* error) {
|
210
128
|
if (grpc_handshaker_trace.enabled()) {
|
211
|
-
char* args_str =
|
129
|
+
char* args_str = HandshakerArgsString(&args_);
|
212
130
|
gpr_log(GPR_INFO,
|
213
131
|
"handshake_manager %p: error=%s shutdown=%d index=%" PRIuPTR
|
214
132
|
", args=%s",
|
215
|
-
|
133
|
+
this, grpc_error_string(error), is_shutdown_, index_, args_str);
|
216
134
|
gpr_free(args_str);
|
217
135
|
}
|
218
|
-
GPR_ASSERT(
|
136
|
+
GPR_ASSERT(index_ <= handshakers_.size());
|
219
137
|
// If we got an error or we've been shut down or we're exiting early or
|
220
138
|
// we've finished the last handshaker, invoke the on_handshake_done
|
221
139
|
// callback. Otherwise, call the next handshaker.
|
222
|
-
if (error != GRPC_ERROR_NONE ||
|
223
|
-
|
224
|
-
if (error == GRPC_ERROR_NONE &&
|
140
|
+
if (error != GRPC_ERROR_NONE || is_shutdown_ || args_.exit_early ||
|
141
|
+
index_ == handshakers_.size()) {
|
142
|
+
if (error == GRPC_ERROR_NONE && is_shutdown_) {
|
225
143
|
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("handshaker shutdown");
|
226
144
|
// It is possible that the endpoint has already been destroyed by
|
227
145
|
// a shutdown call while this callback was sitting on the ExecCtx
|
228
146
|
// with no error.
|
229
|
-
if (
|
147
|
+
if (args_.endpoint != nullptr) {
|
230
148
|
// TODO(roth): It is currently necessary to shutdown endpoints
|
231
149
|
// before destroying then, even when we know that there are no
|
232
150
|
// pending read/write callbacks. This should be fixed, at which
|
233
151
|
// point this can be removed.
|
234
|
-
grpc_endpoint_shutdown(
|
235
|
-
grpc_endpoint_destroy(
|
236
|
-
|
237
|
-
grpc_channel_args_destroy(
|
238
|
-
|
239
|
-
grpc_slice_buffer_destroy_internal(
|
240
|
-
gpr_free(
|
241
|
-
|
152
|
+
grpc_endpoint_shutdown(args_.endpoint, GRPC_ERROR_REF(error));
|
153
|
+
grpc_endpoint_destroy(args_.endpoint);
|
154
|
+
args_.endpoint = nullptr;
|
155
|
+
grpc_channel_args_destroy(args_.args);
|
156
|
+
args_.args = nullptr;
|
157
|
+
grpc_slice_buffer_destroy_internal(args_.read_buffer);
|
158
|
+
gpr_free(args_.read_buffer);
|
159
|
+
args_.read_buffer = nullptr;
|
242
160
|
}
|
243
161
|
}
|
244
162
|
if (grpc_handshaker_trace.enabled()) {
|
245
163
|
gpr_log(GPR_INFO,
|
246
164
|
"handshake_manager %p: handshaking complete -- scheduling "
|
247
165
|
"on_handshake_done with error=%s",
|
248
|
-
|
166
|
+
this, grpc_error_string(error));
|
249
167
|
}
|
250
168
|
// Cancel deadline timer, since we're invoking the on_handshake_done
|
251
169
|
// callback now.
|
252
|
-
grpc_timer_cancel(&
|
253
|
-
GRPC_CLOSURE_SCHED(&
|
254
|
-
|
170
|
+
grpc_timer_cancel(&deadline_timer_);
|
171
|
+
GRPC_CLOSURE_SCHED(&on_handshake_done_, error);
|
172
|
+
is_shutdown_ = true;
|
255
173
|
} else {
|
174
|
+
auto handshaker = handshakers_[index_];
|
256
175
|
if (grpc_handshaker_trace.enabled()) {
|
257
176
|
gpr_log(
|
258
177
|
GPR_INFO,
|
259
178
|
"handshake_manager %p: calling handshaker %s [%p] at index %" PRIuPTR,
|
260
|
-
|
261
|
-
mgr->handshakers[mgr->index], mgr->index);
|
179
|
+
this, handshaker->name(), handshaker.get(), index_);
|
262
180
|
}
|
263
|
-
|
264
|
-
&mgr->call_next_handshaker, &mgr->args);
|
181
|
+
handshaker->DoHandshake(acceptor_, &call_next_handshaker_, &args_);
|
265
182
|
}
|
266
|
-
++
|
267
|
-
return
|
183
|
+
++index_;
|
184
|
+
return is_shutdown_;
|
268
185
|
}
|
269
186
|
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
187
|
+
void HandshakeManager::CallNextHandshakerFn(void* arg, grpc_error* error) {
|
188
|
+
auto* mgr = static_cast<HandshakeManager*>(arg);
|
189
|
+
bool done;
|
190
|
+
{
|
191
|
+
MutexLock lock(&mgr->mu_);
|
192
|
+
done = mgr->CallNextHandshakerLocked(GRPC_ERROR_REF(error));
|
193
|
+
}
|
277
194
|
// If we're invoked the final callback, we won't be coming back
|
278
195
|
// to this function, so we can release our reference to the
|
279
196
|
// handshake manager.
|
280
197
|
if (done) {
|
281
|
-
|
198
|
+
mgr->Unref();
|
282
199
|
}
|
283
200
|
}
|
284
201
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
grpc_handshake_manager_shutdown(
|
290
|
-
mgr, GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out"));
|
202
|
+
void HandshakeManager::OnTimeoutFn(void* arg, grpc_error* error) {
|
203
|
+
auto* mgr = static_cast<HandshakeManager*>(arg);
|
204
|
+
if (error == GRPC_ERROR_NONE) { // Timer fired, rather than being cancelled
|
205
|
+
mgr->Shutdown(GRPC_ERROR_CREATE_FROM_STATIC_STRING("Handshake timed out"));
|
291
206
|
}
|
292
|
-
|
207
|
+
mgr->Unref();
|
293
208
|
}
|
294
209
|
|
295
|
-
void
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
210
|
+
void HandshakeManager::DoHandshake(grpc_endpoint* endpoint,
|
211
|
+
const grpc_channel_args* channel_args,
|
212
|
+
grpc_millis deadline,
|
213
|
+
grpc_tcp_server_acceptor* acceptor,
|
214
|
+
grpc_iomgr_cb_func on_handshake_done,
|
215
|
+
void* user_data) {
|
216
|
+
bool done;
|
217
|
+
{
|
218
|
+
MutexLock lock(&mu_);
|
219
|
+
GPR_ASSERT(index_ == 0);
|
220
|
+
GPR_ASSERT(!is_shutdown_);
|
221
|
+
// Construct handshaker args. These will be passed through all
|
222
|
+
// handshakers and eventually be freed by the on_handshake_done callback.
|
223
|
+
args_.endpoint = endpoint;
|
224
|
+
args_.args = grpc_channel_args_copy(channel_args);
|
225
|
+
args_.user_data = user_data;
|
226
|
+
args_.read_buffer =
|
227
|
+
static_cast<grpc_slice_buffer*>(gpr_malloc(sizeof(*args_.read_buffer)));
|
228
|
+
grpc_slice_buffer_init(args_.read_buffer);
|
229
|
+
// Initialize state needed for calling handshakers.
|
230
|
+
acceptor_ = acceptor;
|
231
|
+
GRPC_CLOSURE_INIT(&call_next_handshaker_,
|
232
|
+
&HandshakeManager::CallNextHandshakerFn, this,
|
233
|
+
grpc_schedule_on_exec_ctx);
|
234
|
+
GRPC_CLOSURE_INIT(&on_handshake_done_, on_handshake_done, &args_,
|
235
|
+
grpc_schedule_on_exec_ctx);
|
236
|
+
// Start deadline timer, which owns a ref.
|
237
|
+
Ref().release();
|
238
|
+
GRPC_CLOSURE_INIT(&on_timeout_, &HandshakeManager::OnTimeoutFn, this,
|
239
|
+
grpc_schedule_on_exec_ctx);
|
240
|
+
grpc_timer_init(&deadline_timer_, deadline, &on_timeout_);
|
241
|
+
// Start first handshaker, which also owns a ref.
|
242
|
+
Ref().release();
|
243
|
+
done = CallNextHandshakerLocked(GRPC_ERROR_NONE);
|
244
|
+
}
|
328
245
|
if (done) {
|
329
|
-
|
246
|
+
Unref();
|
330
247
|
}
|
331
248
|
}
|
249
|
+
|
250
|
+
} // namespace grpc_core
|
251
|
+
|
252
|
+
void grpc_handshake_manager_add(grpc_handshake_manager* mgr,
|
253
|
+
grpc_handshaker* handshaker) {
|
254
|
+
// This is a transition method to aid the API change for handshakers.
|
255
|
+
using namespace grpc_core;
|
256
|
+
RefCountedPtr<Handshaker> refd_hs(static_cast<Handshaker*>(handshaker));
|
257
|
+
mgr->Add(refd_hs);
|
258
|
+
}
|