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
@@ -0,0 +1,94 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2018 gRPC authors.
|
4
|
+
*
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
* you may not use this file except in compliance with the License.
|
7
|
+
* You may obtain a copy of the License at
|
8
|
+
*
|
9
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
*
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
* See the License for the specific language governing permissions and
|
15
|
+
* limitations under the License.
|
16
|
+
*
|
17
|
+
*/
|
18
|
+
|
19
|
+
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H
|
20
|
+
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H
|
21
|
+
|
22
|
+
#include <grpc/support/port_platform.h>
|
23
|
+
|
24
|
+
#include "src/core/lib/avl/avl.h"
|
25
|
+
#include "src/core/lib/channel/channel_args.h"
|
26
|
+
#include "src/core/lib/gprpp/abstract.h"
|
27
|
+
#include "src/core/lib/gprpp/ref_counted.h"
|
28
|
+
|
29
|
+
namespace grpc_core {
|
30
|
+
|
31
|
+
class Subchannel;
|
32
|
+
|
33
|
+
extern TraceFlag grpc_subchannel_pool_trace;
|
34
|
+
|
35
|
+
// A key that can uniquely identify a subchannel.
|
36
|
+
class SubchannelKey {
|
37
|
+
public:
|
38
|
+
explicit SubchannelKey(const grpc_channel_args* args);
|
39
|
+
~SubchannelKey();
|
40
|
+
|
41
|
+
// Copyable.
|
42
|
+
SubchannelKey(const SubchannelKey& other);
|
43
|
+
SubchannelKey& operator=(const SubchannelKey& other);
|
44
|
+
// Not movable.
|
45
|
+
SubchannelKey(SubchannelKey&&) = delete;
|
46
|
+
SubchannelKey& operator=(SubchannelKey&&) = delete;
|
47
|
+
|
48
|
+
int Cmp(const SubchannelKey& other) const;
|
49
|
+
|
50
|
+
private:
|
51
|
+
// Initializes the subchannel key with the given \a args and the function to
|
52
|
+
// copy channel args.
|
53
|
+
void Init(
|
54
|
+
const grpc_channel_args* args,
|
55
|
+
grpc_channel_args* (*copy_channel_args)(const grpc_channel_args* args));
|
56
|
+
|
57
|
+
const grpc_channel_args* args_;
|
58
|
+
};
|
59
|
+
|
60
|
+
// Interface for subchannel pool.
|
61
|
+
// TODO(juanlishen): This refcounting mechanism may lead to memory leak.
|
62
|
+
// To solve that, we should force polling to flush any pending callbacks, then
|
63
|
+
// shut down safely. See https://github.com/grpc/grpc/issues/12560.
|
64
|
+
class SubchannelPoolInterface : public RefCounted<SubchannelPoolInterface> {
|
65
|
+
public:
|
66
|
+
SubchannelPoolInterface() : RefCounted(&grpc_subchannel_pool_trace) {}
|
67
|
+
virtual ~SubchannelPoolInterface() {}
|
68
|
+
|
69
|
+
// Registers a subchannel against a key. Returns the subchannel registered
|
70
|
+
// with \a key, which may be different from \a constructed because we reuse
|
71
|
+
// (instead of update) any existing subchannel already registered with \a key.
|
72
|
+
virtual Subchannel* RegisterSubchannel(SubchannelKey* key,
|
73
|
+
Subchannel* constructed) GRPC_ABSTRACT;
|
74
|
+
|
75
|
+
// Removes the registered subchannel found by \a key.
|
76
|
+
virtual void UnregisterSubchannel(SubchannelKey* key) GRPC_ABSTRACT;
|
77
|
+
|
78
|
+
// Finds the subchannel registered for the given subchannel key. Returns NULL
|
79
|
+
// if no such channel exists. Thread-safe.
|
80
|
+
virtual Subchannel* FindSubchannel(SubchannelKey* key) GRPC_ABSTRACT;
|
81
|
+
|
82
|
+
// Creates a channel arg from \a subchannel pool.
|
83
|
+
static grpc_arg CreateChannelArg(SubchannelPoolInterface* subchannel_pool);
|
84
|
+
|
85
|
+
// Gets the subchannel pool from the channel args.
|
86
|
+
static SubchannelPoolInterface* GetSubchannelPoolFromChannelArgs(
|
87
|
+
const grpc_channel_args* args);
|
88
|
+
|
89
|
+
GRPC_ABSTRACT_BASE_CLASS
|
90
|
+
};
|
91
|
+
|
92
|
+
} // namespace grpc_core
|
93
|
+
|
94
|
+
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_SUBCHANNEL_POOL_INTERFACE_H */
|
@@ -45,6 +45,7 @@ struct call_data {
|
|
45
45
|
|
46
46
|
struct channel_data {
|
47
47
|
grpc_slice default_authority;
|
48
|
+
grpc_mdelem default_authority_mdelem;
|
48
49
|
};
|
49
50
|
|
50
51
|
void authority_start_transport_stream_op_batch(
|
@@ -59,8 +60,7 @@ void authority_start_transport_stream_op_batch(
|
|
59
60
|
initial_metadata->idx.named.authority == nullptr) {
|
60
61
|
grpc_error* error = grpc_metadata_batch_add_head(
|
61
62
|
initial_metadata, &calld->authority_storage,
|
62
|
-
|
63
|
-
nullptr));
|
63
|
+
GRPC_MDELEM_REF(chand->default_authority_mdelem));
|
64
64
|
if (error != GRPC_ERROR_NONE) {
|
65
65
|
grpc_transport_stream_op_batch_finish_with_failure(batch, error,
|
66
66
|
calld->call_combiner);
|
@@ -103,6 +103,8 @@ grpc_error* init_channel_elem(grpc_channel_element* elem,
|
|
103
103
|
}
|
104
104
|
chand->default_authority =
|
105
105
|
grpc_slice_intern(grpc_slice_from_static_string(default_authority_str));
|
106
|
+
chand->default_authority_mdelem = grpc_mdelem_create(
|
107
|
+
GRPC_MDSTR_AUTHORITY, chand->default_authority, nullptr);
|
106
108
|
GPR_ASSERT(!args->is_last);
|
107
109
|
return GRPC_ERROR_NONE;
|
108
110
|
}
|
@@ -111,6 +113,7 @@ grpc_error* init_channel_elem(grpc_channel_element* elem,
|
|
111
113
|
void destroy_channel_elem(grpc_channel_element* elem) {
|
112
114
|
channel_data* chand = static_cast<channel_data*>(elem->channel_data);
|
113
115
|
grpc_slice_unref_internal(chand->default_authority);
|
116
|
+
GRPC_MDELEM_UNREF(chand->default_authority_mdelem);
|
114
117
|
}
|
115
118
|
} // namespace
|
116
119
|
|
@@ -106,7 +106,7 @@ struct channel_data {
|
|
106
106
|
+--------------------------------+----------------+---------+
|
107
107
|
|
108
108
|
MAX_IDLE_STATE_INIT: The initial and final state of 'idle_state'. The
|
109
|
-
channel has 1 or 1+ active calls, and the
|
109
|
+
channel has 1 or 1+ active calls, and the timer is not set. Note that
|
110
110
|
we may put a virtual call to hold this state at channel initialization or
|
111
111
|
shutdown, so that the channel won't enter other states.
|
112
112
|
|
@@ -55,7 +55,7 @@ typedef struct {
|
|
55
55
|
|
56
56
|
grpc_closure connected;
|
57
57
|
|
58
|
-
|
58
|
+
grpc_core::RefCountedPtr<grpc_core::HandshakeManager> handshake_mgr;
|
59
59
|
} chttp2_connector;
|
60
60
|
|
61
61
|
static void chttp2_connector_ref(grpc_connector* con) {
|
@@ -79,7 +79,7 @@ static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) {
|
|
79
79
|
gpr_mu_lock(&c->mu);
|
80
80
|
c->shutdown = true;
|
81
81
|
if (c->handshake_mgr != nullptr) {
|
82
|
-
|
82
|
+
c->handshake_mgr->Shutdown(GRPC_ERROR_REF(why));
|
83
83
|
}
|
84
84
|
// If handshaking is not yet in progress, shutdown the endpoint.
|
85
85
|
// Otherwise, the handshaker will do this for us.
|
@@ -91,7 +91,7 @@ static void chttp2_connector_shutdown(grpc_connector* con, grpc_error* why) {
|
|
91
91
|
}
|
92
92
|
|
93
93
|
static void on_handshake_done(void* arg, grpc_error* error) {
|
94
|
-
|
94
|
+
auto* args = static_cast<grpc_core::HandshakerArgs*>(arg);
|
95
95
|
chttp2_connector* c = static_cast<chttp2_connector*>(args->user_data);
|
96
96
|
gpr_mu_lock(&c->mu);
|
97
97
|
if (error != GRPC_ERROR_NONE || c->shutdown) {
|
@@ -152,20 +152,20 @@ static void on_handshake_done(void* arg, grpc_error* error) {
|
|
152
152
|
grpc_closure* notify = c->notify;
|
153
153
|
c->notify = nullptr;
|
154
154
|
GRPC_CLOSURE_SCHED(notify, error);
|
155
|
-
|
156
|
-
c->handshake_mgr = nullptr;
|
155
|
+
c->handshake_mgr.reset();
|
157
156
|
gpr_mu_unlock(&c->mu);
|
158
157
|
chttp2_connector_unref(reinterpret_cast<grpc_connector*>(c));
|
159
158
|
}
|
160
159
|
|
161
160
|
static void start_handshake_locked(chttp2_connector* c) {
|
162
|
-
c->handshake_mgr =
|
163
|
-
|
164
|
-
|
161
|
+
c->handshake_mgr = grpc_core::MakeRefCounted<grpc_core::HandshakeManager>();
|
162
|
+
grpc_core::HandshakerRegistry::AddHandshakers(
|
163
|
+
grpc_core::HANDSHAKER_CLIENT, c->args.channel_args,
|
164
|
+
c->args.interested_parties, c->handshake_mgr.get());
|
165
165
|
grpc_endpoint_add_to_pollset_set(c->endpoint, c->args.interested_parties);
|
166
|
-
|
167
|
-
|
168
|
-
|
166
|
+
c->handshake_mgr->DoHandshake(c->endpoint, c->args.channel_args,
|
167
|
+
c->args.deadline, nullptr /* acceptor */,
|
168
|
+
on_handshake_done, c);
|
169
169
|
c->endpoint = nullptr; // Endpoint handed off to handshake manager.
|
170
170
|
}
|
171
171
|
|
@@ -202,7 +202,8 @@ static void chttp2_connector_connect(grpc_connector* con,
|
|
202
202
|
grpc_closure* notify) {
|
203
203
|
chttp2_connector* c = reinterpret_cast<chttp2_connector*>(con);
|
204
204
|
grpc_resolved_address addr;
|
205
|
-
|
205
|
+
grpc_core::Subchannel::GetAddressFromSubchannelAddressArg(args->channel_args,
|
206
|
+
&addr);
|
206
207
|
gpr_mu_lock(&c->mu);
|
207
208
|
GPR_ASSERT(c->notify == nullptr);
|
208
209
|
c->notify = notify;
|
@@ -39,15 +39,13 @@ static void client_channel_factory_ref(
|
|
39
39
|
static void client_channel_factory_unref(
|
40
40
|
grpc_client_channel_factory* cc_factory) {}
|
41
41
|
|
42
|
-
static
|
43
|
-
grpc_client_channel_factory* cc_factory, const
|
44
|
-
|
45
|
-
memcpy(&final_sc_args, args, sizeof(*args));
|
46
|
-
final_sc_args.args = grpc_default_authority_add_if_not_present(args->args);
|
42
|
+
static grpc_core::Subchannel* client_channel_factory_create_subchannel(
|
43
|
+
grpc_client_channel_factory* cc_factory, const grpc_channel_args* args) {
|
44
|
+
grpc_channel_args* new_args = grpc_default_authority_add_if_not_present(args);
|
47
45
|
grpc_connector* connector = grpc_chttp2_connector_create();
|
48
|
-
|
46
|
+
grpc_core::Subchannel* s = grpc_core::Subchannel::Create(connector, new_args);
|
49
47
|
grpc_connector_unref(connector);
|
50
|
-
grpc_channel_args_destroy(
|
48
|
+
grpc_channel_args_destroy(new_args);
|
51
49
|
return s;
|
52
50
|
}
|
53
51
|
|
@@ -46,10 +46,10 @@ static void client_channel_factory_ref(
|
|
46
46
|
static void client_channel_factory_unref(
|
47
47
|
grpc_client_channel_factory* cc_factory) {}
|
48
48
|
|
49
|
-
static
|
50
|
-
const
|
49
|
+
static grpc_channel_args* get_secure_naming_channel_args(
|
50
|
+
const grpc_channel_args* args) {
|
51
51
|
grpc_channel_credentials* channel_credentials =
|
52
|
-
grpc_channel_credentials_find_in_args(args
|
52
|
+
grpc_channel_credentials_find_in_args(args);
|
53
53
|
if (channel_credentials == nullptr) {
|
54
54
|
gpr_log(GPR_ERROR,
|
55
55
|
"Can't create subchannel: channel credentials missing for secure "
|
@@ -57,7 +57,7 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
|
|
57
57
|
return nullptr;
|
58
58
|
}
|
59
59
|
// Make sure security connector does not already exist in args.
|
60
|
-
if (grpc_security_connector_find_in_args(args
|
60
|
+
if (grpc_security_connector_find_in_args(args) != nullptr) {
|
61
61
|
gpr_log(GPR_ERROR,
|
62
62
|
"Can't create subchannel: security connector already present in "
|
63
63
|
"channel args.");
|
@@ -65,19 +65,19 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
|
|
65
65
|
}
|
66
66
|
// To which address are we connecting? By default, use the server URI.
|
67
67
|
const grpc_arg* server_uri_arg =
|
68
|
-
grpc_channel_args_find(args
|
68
|
+
grpc_channel_args_find(args, GRPC_ARG_SERVER_URI);
|
69
69
|
const char* server_uri_str = grpc_channel_arg_get_string(server_uri_arg);
|
70
70
|
GPR_ASSERT(server_uri_str != nullptr);
|
71
71
|
grpc_uri* server_uri =
|
72
72
|
grpc_uri_parse(server_uri_str, true /* supress errors */);
|
73
73
|
GPR_ASSERT(server_uri != nullptr);
|
74
74
|
const grpc_core::TargetAuthorityTable* target_authority_table =
|
75
|
-
grpc_core::FindTargetAuthorityTableInArgs(args
|
75
|
+
grpc_core::FindTargetAuthorityTableInArgs(args);
|
76
76
|
grpc_core::UniquePtr<char> authority;
|
77
77
|
if (target_authority_table != nullptr) {
|
78
78
|
// Find the authority for the target.
|
79
79
|
const char* target_uri_str =
|
80
|
-
|
80
|
+
grpc_core::Subchannel::GetUriFromSubchannelAddressArg(args);
|
81
81
|
grpc_uri* target_uri =
|
82
82
|
grpc_uri_parse(target_uri_str, false /* suppress errors */);
|
83
83
|
GPR_ASSERT(target_uri != nullptr);
|
@@ -100,15 +100,14 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
|
|
100
100
|
}
|
101
101
|
grpc_arg args_to_add[2];
|
102
102
|
size_t num_args_to_add = 0;
|
103
|
-
if (grpc_channel_args_find(args
|
104
|
-
nullptr) {
|
103
|
+
if (grpc_channel_args_find(args, GRPC_ARG_DEFAULT_AUTHORITY) == nullptr) {
|
105
104
|
// If the channel args don't already contain GRPC_ARG_DEFAULT_AUTHORITY, add
|
106
105
|
// the arg, setting it to the value just obtained.
|
107
106
|
args_to_add[num_args_to_add++] = grpc_channel_arg_string_create(
|
108
107
|
const_cast<char*>(GRPC_ARG_DEFAULT_AUTHORITY), authority.get());
|
109
108
|
}
|
110
109
|
grpc_channel_args* args_with_authority =
|
111
|
-
grpc_channel_args_copy_and_add(args
|
110
|
+
grpc_channel_args_copy_and_add(args, args_to_add, num_args_to_add);
|
112
111
|
grpc_uri_destroy(server_uri);
|
113
112
|
// Create the security connector using the credentials and target name.
|
114
113
|
grpc_channel_args* new_args_from_connector = nullptr;
|
@@ -137,29 +136,21 @@ static grpc_subchannel_args* get_secure_naming_subchannel_args(
|
|
137
136
|
grpc_channel_args_destroy(new_args_from_connector);
|
138
137
|
}
|
139
138
|
grpc_channel_args_destroy(args_with_authority);
|
140
|
-
|
141
|
-
static_cast<grpc_subchannel_args*>(gpr_malloc(sizeof(*final_sc_args)));
|
142
|
-
memcpy(final_sc_args, args, sizeof(*args));
|
143
|
-
final_sc_args->args = new_args;
|
144
|
-
return final_sc_args;
|
139
|
+
return new_args;
|
145
140
|
}
|
146
141
|
|
147
|
-
static
|
148
|
-
grpc_client_channel_factory* cc_factory, const
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
GPR_ERROR,
|
154
|
-
"Failed to create subchannel arguments during subchannel creation.");
|
142
|
+
static grpc_core::Subchannel* client_channel_factory_create_subchannel(
|
143
|
+
grpc_client_channel_factory* cc_factory, const grpc_channel_args* args) {
|
144
|
+
grpc_channel_args* new_args = get_secure_naming_channel_args(args);
|
145
|
+
if (new_args == nullptr) {
|
146
|
+
gpr_log(GPR_ERROR,
|
147
|
+
"Failed to create channel args during subchannel creation.");
|
155
148
|
return nullptr;
|
156
149
|
}
|
157
150
|
grpc_connector* connector = grpc_chttp2_connector_create();
|
158
|
-
|
151
|
+
grpc_core::Subchannel* s = grpc_core::Subchannel::Create(connector, new_args);
|
159
152
|
grpc_connector_unref(connector);
|
160
|
-
grpc_channel_args_destroy(
|
161
|
-
const_cast<grpc_channel_args*>(subchannel_args->args));
|
162
|
-
gpr_free(subchannel_args);
|
153
|
+
grpc_channel_args_destroy(new_args);
|
163
154
|
return s;
|
164
155
|
}
|
165
156
|
|
@@ -215,6 +206,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds,
|
|
215
206
|
grpc_channel_credentials_to_arg(creds)};
|
216
207
|
grpc_channel_args* new_args = grpc_channel_args_copy_and_add(
|
217
208
|
args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
|
209
|
+
new_args = creds->update_arguments(new_args);
|
218
210
|
// Create channel.
|
219
211
|
channel = client_channel_factory_create_channel(
|
220
212
|
&client_channel_factory, target, GRPC_CLIENT_CHANNEL_TYPE_REGULAR,
|
@@ -54,7 +54,7 @@ typedef struct {
|
|
54
54
|
bool shutdown;
|
55
55
|
grpc_closure tcp_server_shutdown_complete;
|
56
56
|
grpc_closure* server_destroy_listener_done;
|
57
|
-
|
57
|
+
grpc_core::HandshakeManager* pending_handshake_mgrs;
|
58
58
|
grpc_core::RefCountedPtr<grpc_core::channelz::ListenSocketNode>
|
59
59
|
channelz_listen_socket;
|
60
60
|
} server_state;
|
@@ -64,7 +64,7 @@ typedef struct {
|
|
64
64
|
server_state* svr_state;
|
65
65
|
grpc_pollset* accepting_pollset;
|
66
66
|
grpc_tcp_server_acceptor* acceptor;
|
67
|
-
|
67
|
+
grpc_core::RefCountedPtr<grpc_core::HandshakeManager> handshake_mgr;
|
68
68
|
// State for enforcing handshake timeout on receiving HTTP/2 settings.
|
69
69
|
grpc_chttp2_transport* transport;
|
70
70
|
grpc_millis deadline;
|
@@ -112,7 +112,7 @@ static void on_receive_settings(void* arg, grpc_error* error) {
|
|
112
112
|
}
|
113
113
|
|
114
114
|
static void on_handshake_done(void* arg, grpc_error* error) {
|
115
|
-
|
115
|
+
auto* args = static_cast<grpc_core::HandshakerArgs*>(arg);
|
116
116
|
server_connection_state* connection_state =
|
117
117
|
static_cast<server_connection_state*>(args->user_data);
|
118
118
|
gpr_mu_lock(&connection_state->svr_state->mu);
|
@@ -175,11 +175,10 @@ static void on_handshake_done(void* arg, grpc_error* error) {
|
|
175
175
|
}
|
176
176
|
}
|
177
177
|
}
|
178
|
-
|
179
|
-
&connection_state->svr_state->pending_handshake_mgrs
|
180
|
-
connection_state->handshake_mgr);
|
178
|
+
connection_state->handshake_mgr->RemoveFromPendingMgrList(
|
179
|
+
&connection_state->svr_state->pending_handshake_mgrs);
|
181
180
|
gpr_mu_unlock(&connection_state->svr_state->mu);
|
182
|
-
|
181
|
+
connection_state->handshake_mgr.reset();
|
183
182
|
gpr_free(connection_state->acceptor);
|
184
183
|
grpc_tcp_server_unref(connection_state->svr_state->tcp_server);
|
185
184
|
server_connection_state_unref(connection_state);
|
@@ -211,9 +210,8 @@ static void on_accept(void* arg, grpc_endpoint* tcp,
|
|
211
210
|
gpr_free(acceptor);
|
212
211
|
return;
|
213
212
|
}
|
214
|
-
|
215
|
-
|
216
|
-
handshake_mgr);
|
213
|
+
auto handshake_mgr = grpc_core::MakeRefCounted<grpc_core::HandshakeManager>();
|
214
|
+
handshake_mgr->AddToPendingMgrList(&state->pending_handshake_mgrs);
|
217
215
|
grpc_tcp_server_ref(state->tcp_server);
|
218
216
|
gpr_mu_unlock(&state->mu);
|
219
217
|
server_connection_state* connection_state =
|
@@ -227,19 +225,19 @@ static void on_accept(void* arg, grpc_endpoint* tcp,
|
|
227
225
|
connection_state->interested_parties = grpc_pollset_set_create();
|
228
226
|
grpc_pollset_set_add_pollset(connection_state->interested_parties,
|
229
227
|
connection_state->accepting_pollset);
|
230
|
-
|
231
|
-
|
232
|
-
|
228
|
+
grpc_core::HandshakerRegistry::AddHandshakers(
|
229
|
+
grpc_core::HANDSHAKER_SERVER, state->args,
|
230
|
+
connection_state->interested_parties,
|
231
|
+
connection_state->handshake_mgr.get());
|
233
232
|
const grpc_arg* timeout_arg =
|
234
233
|
grpc_channel_args_find(state->args, GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS);
|
235
234
|
connection_state->deadline =
|
236
235
|
grpc_core::ExecCtx::Get()->Now() +
|
237
236
|
grpc_channel_arg_get_integer(timeout_arg,
|
238
237
|
{120 * GPR_MS_PER_SEC, 1, INT_MAX});
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
connection_state);
|
238
|
+
connection_state->handshake_mgr->DoHandshake(
|
239
|
+
tcp, state->args, connection_state->deadline, acceptor, on_handshake_done,
|
240
|
+
connection_state);
|
243
241
|
}
|
244
242
|
|
245
243
|
/* Server callback: start listening on our ports */
|
@@ -260,8 +258,9 @@ static void tcp_server_shutdown_complete(void* arg, grpc_error* error) {
|
|
260
258
|
gpr_mu_lock(&state->mu);
|
261
259
|
grpc_closure* destroy_done = state->server_destroy_listener_done;
|
262
260
|
GPR_ASSERT(state->shutdown);
|
263
|
-
|
264
|
-
|
261
|
+
if (state->pending_handshake_mgrs != nullptr) {
|
262
|
+
state->pending_handshake_mgrs->ShutdownAllPending(GRPC_ERROR_REF(error));
|
263
|
+
}
|
265
264
|
state->channelz_listen_socket.reset();
|
266
265
|
gpr_mu_unlock(&state->mu);
|
267
266
|
// Flush queued work before destroying handshaker factory, since that
|
@@ -43,6 +43,7 @@
|
|
43
43
|
#include "src/core/lib/gprpp/memory.h"
|
44
44
|
#include "src/core/lib/http/parser.h"
|
45
45
|
#include "src/core/lib/iomgr/executor.h"
|
46
|
+
#include "src/core/lib/iomgr/iomgr.h"
|
46
47
|
#include "src/core/lib/iomgr/timer.h"
|
47
48
|
#include "src/core/lib/profiling/timers.h"
|
48
49
|
#include "src/core/lib/slice/slice_internal.h"
|
@@ -963,24 +964,28 @@ void grpc_chttp2_mark_stream_writable(grpc_chttp2_transport* t,
|
|
963
964
|
static grpc_closure_scheduler* write_scheduler(grpc_chttp2_transport* t,
|
964
965
|
bool early_results_scheduled,
|
965
966
|
bool partial_write) {
|
967
|
+
// If we're already in a background poller, don't offload this to an executor
|
968
|
+
if (grpc_iomgr_is_any_background_poller_thread()) {
|
969
|
+
return grpc_schedule_on_exec_ctx;
|
970
|
+
}
|
966
971
|
/* if it's not the first write in a batch, always offload to the executor:
|
967
972
|
we'll probably end up queuing against the kernel anyway, so we'll likely
|
968
973
|
get better latency overall if we switch writing work elsewhere and continue
|
969
974
|
with application work above */
|
970
975
|
if (!t->is_first_write_in_batch) {
|
971
|
-
return
|
976
|
+
return grpc_core::Executor::Scheduler(grpc_core::ExecutorJobType::SHORT);
|
972
977
|
}
|
973
978
|
/* equivalently, if it's a partial write, we *know* we're going to be taking a
|
974
979
|
thread jump to write it because of the above, may as well do so
|
975
980
|
immediately */
|
976
981
|
if (partial_write) {
|
977
|
-
return
|
982
|
+
return grpc_core::Executor::Scheduler(grpc_core::ExecutorJobType::SHORT);
|
978
983
|
}
|
979
984
|
switch (t->opt_target) {
|
980
985
|
case GRPC_CHTTP2_OPTIMIZE_FOR_THROUGHPUT:
|
981
986
|
/* executor gives us the largest probability of being able to batch a
|
982
987
|
* write with others on this transport */
|
983
|
-
return
|
988
|
+
return grpc_core::Executor::Scheduler(grpc_core::ExecutorJobType::SHORT);
|
984
989
|
case GRPC_CHTTP2_OPTIMIZE_FOR_LATENCY:
|
985
990
|
return grpc_schedule_on_exec_ctx;
|
986
991
|
}
|
@@ -1114,9 +1119,6 @@ static void queue_setting_update(grpc_chttp2_transport* t,
|
|
1114
1119
|
void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
|
1115
1120
|
uint32_t goaway_error,
|
1116
1121
|
grpc_slice goaway_text) {
|
1117
|
-
// GRPC_CHTTP2_IF_TRACING(
|
1118
|
-
// gpr_log(GPR_INFO, "got goaway [%d]: %s", goaway_error, msg));
|
1119
|
-
|
1120
1122
|
// Discard the error from a previous goaway frame (if any)
|
1121
1123
|
if (t->goaway_error != GRPC_ERROR_NONE) {
|
1122
1124
|
GRPC_ERROR_UNREF(t->goaway_error);
|
@@ -1127,6 +1129,10 @@ void grpc_chttp2_add_incoming_goaway(grpc_chttp2_transport* t,
|
|
1127
1129
|
GRPC_ERROR_INT_HTTP2_ERROR, static_cast<intptr_t>(goaway_error)),
|
1128
1130
|
GRPC_ERROR_STR_RAW_BYTES, goaway_text);
|
1129
1131
|
|
1132
|
+
/* We want to log this irrespective of whether http tracing is enabled */
|
1133
|
+
gpr_log(GPR_INFO, "%s: Got goaway [%d] err=%s", t->peer_string, goaway_error,
|
1134
|
+
grpc_error_string(t->goaway_error));
|
1135
|
+
|
1130
1136
|
/* When a client receives a GOAWAY with error code ENHANCE_YOUR_CALM and debug
|
1131
1137
|
* data equal to "too_many_pings", it should log the occurrence at a log level
|
1132
1138
|
* that is enabled by default and double the configured KEEPALIVE_TIME used
|
@@ -1769,6 +1775,9 @@ void grpc_chttp2_ack_ping(grpc_chttp2_transport* t, uint64_t id) {
|
|
1769
1775
|
}
|
1770
1776
|
|
1771
1777
|
static void send_goaway(grpc_chttp2_transport* t, grpc_error* error) {
|
1778
|
+
/* We want to log this irrespective of whether http tracing is enabled */
|
1779
|
+
gpr_log(GPR_INFO, "%s: Sending goaway err=%s", t->peer_string,
|
1780
|
+
grpc_error_string(error));
|
1772
1781
|
t->sent_goaway_state = GRPC_CHTTP2_GOAWAY_SEND_SCHEDULED;
|
1773
1782
|
grpc_http2_error_code http_error;
|
1774
1783
|
grpc_slice slice;
|
@@ -2549,6 +2558,10 @@ static void read_action_locked(void* tp, grpc_error* error) {
|
|
2549
2558
|
} else if (t->closed_with_error == GRPC_ERROR_NONE) {
|
2550
2559
|
keep_reading = true;
|
2551
2560
|
GRPC_CHTTP2_REF_TRANSPORT(t, "keep_reading");
|
2561
|
+
/* Since we have read a byte, reset the keepalive timer */
|
2562
|
+
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_WAITING) {
|
2563
|
+
grpc_timer_cancel(&t->keepalive_ping_timer);
|
2564
|
+
}
|
2552
2565
|
}
|
2553
2566
|
grpc_slice_buffer_reset_and_unref_internal(&t->read_buffer);
|
2554
2567
|
|
@@ -2718,6 +2731,9 @@ static void start_keepalive_ping_locked(void* arg, grpc_error* error) {
|
|
2718
2731
|
if (t->channelz_socket != nullptr) {
|
2719
2732
|
t->channelz_socket->RecordKeepaliveSent();
|
2720
2733
|
}
|
2734
|
+
if (grpc_http_trace.enabled()) {
|
2735
|
+
gpr_log(GPR_INFO, "%s: Start keepalive ping", t->peer_string);
|
2736
|
+
}
|
2721
2737
|
GRPC_CHTTP2_REF_TRANSPORT(t, "keepalive watchdog");
|
2722
2738
|
grpc_timer_init(&t->keepalive_watchdog_timer,
|
2723
2739
|
grpc_core::ExecCtx::Get()->Now() + t->keepalive_timeout,
|
@@ -2728,6 +2744,9 @@ static void finish_keepalive_ping_locked(void* arg, grpc_error* error) {
|
|
2728
2744
|
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
|
2729
2745
|
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
|
2730
2746
|
if (error == GRPC_ERROR_NONE) {
|
2747
|
+
if (grpc_http_trace.enabled()) {
|
2748
|
+
gpr_log(GPR_INFO, "%s: Finish keepalive ping", t->peer_string);
|
2749
|
+
}
|
2731
2750
|
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_WAITING;
|
2732
2751
|
grpc_timer_cancel(&t->keepalive_watchdog_timer);
|
2733
2752
|
GRPC_CHTTP2_REF_TRANSPORT(t, "init keepalive ping");
|
@@ -2743,6 +2762,8 @@ static void keepalive_watchdog_fired_locked(void* arg, grpc_error* error) {
|
|
2743
2762
|
grpc_chttp2_transport* t = static_cast<grpc_chttp2_transport*>(arg);
|
2744
2763
|
if (t->keepalive_state == GRPC_CHTTP2_KEEPALIVE_STATE_PINGING) {
|
2745
2764
|
if (error == GRPC_ERROR_NONE) {
|
2765
|
+
gpr_log(GPR_ERROR, "%s: Keepalive watchdog fired. Closing transport.",
|
2766
|
+
t->peer_string);
|
2746
2767
|
t->keepalive_state = GRPC_CHTTP2_KEEPALIVE_STATE_DYING;
|
2747
2768
|
close_transport_locked(
|
2748
2769
|
t, grpc_error_set_int(GRPC_ERROR_CREATE_FROM_STATIC_STRING(
|