grpc 1.20.0 → 1.21.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 +500 -29
- data/etc/roots.pem +146 -0
- data/include/grpc/grpc_security.h +1 -1
- data/include/grpc/impl/codegen/grpc_types.h +10 -7
- data/include/grpc/impl/codegen/port_platform.h +11 -1
- data/include/grpc/impl/codegen/slice.h +1 -21
- data/include/grpc/impl/codegen/status.h +2 -1
- data/include/grpc/slice.h +1 -1
- data/src/core/ext/filters/client_channel/backup_poller.cc +19 -13
- data/src/core/ext/filters/client_channel/backup_poller.h +3 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +2084 -1673
- data/src/core/ext/filters/client_channel/client_channel_channelz.cc +2 -3
- data/src/core/ext/filters/client_channel/client_channel_plugin.cc +4 -0
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +54 -49
- data/src/core/ext/filters/client_channel/health/health_check_client.h +20 -9
- data/src/core/ext/filters/client_channel/http_connect_handshaker.cc +1 -2
- data/src/core/ext/filters/client_channel/http_connect_handshaker.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.cc +3 -30
- data/src/core/ext/filters/client_channel/lb_policy.h +16 -25
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +106 -81
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.cc +6 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h +8 -12
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +2 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +1 -1
- data/src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc +57 -49
- data/src/core/ext/filters/client_channel/lb_policy/round_robin/round_robin.cc +47 -41
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +24 -20
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +989 -284
- data/src/core/ext/filters/client_channel/lb_policy_factory.h +4 -1
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +105 -2
- data/src/core/ext/filters/client_channel/lb_policy_registry.h +9 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +79 -36
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.cc +84 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h +3 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_libuv.cc +179 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver_windows.cc +15 -3
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +80 -4
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +7 -13
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +2 -2
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_libuv.cc +39 -0
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_posix.cc +0 -6
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_windows.cc +2 -64
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.cc +28 -0
- data/src/core/ext/filters/client_channel/resolver/dns/dns_resolver_selection.h +29 -0
- data/src/core/ext/filters/client_channel/resolver/dns/native/dns_resolver.cc +4 -4
- data/src/core/ext/filters/client_channel/resolver_result_parsing.cc +367 -232
- data/src/core/ext/filters/client_channel/resolver_result_parsing.h +55 -76
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +50 -39
- data/src/core/ext/filters/client_channel/resolving_lb_policy.h +18 -12
- data/src/core/ext/filters/client_channel/service_config.cc +247 -27
- data/src/core/ext/filters/client_channel/service_config.h +119 -166
- data/src/core/ext/filters/client_channel/subchannel.cc +46 -84
- data/src/core/ext/filters/client_channel/subchannel.h +7 -7
- data/src/core/ext/filters/deadline/deadline_filter.cc +3 -4
- data/src/core/ext/filters/deadline/deadline_filter.h +3 -2
- data/src/core/ext/filters/http/client/http_client_filter.cc +7 -5
- data/src/core/ext/filters/http/client/http_client_filter.h +1 -1
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +4 -3
- data/src/core/ext/filters/http/server/http_server_filter.cc +18 -12
- data/src/core/ext/filters/message_size/message_size_filter.cc +118 -76
- data/src/core/ext/filters/message_size/message_size_filter.h +33 -0
- data/src/core/ext/transport/chttp2/alpn/alpn.h +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_plugin.cc +9 -7
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +93 -60
- data/src/core/ext/transport/chttp2/transport/flow_control.h +1 -1
- data/src/core/ext/transport/chttp2/transport/frame_settings.cc +4 -3
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +8 -2
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +2 -2
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.h +3 -2
- data/src/core/ext/transport/chttp2/transport/internal.h +35 -23
- data/src/core/ext/transport/chttp2/transport/parsing.cc +4 -4
- data/src/core/ext/transport/chttp2/transport/stream_lists.cc +3 -3
- data/src/core/ext/transport/chttp2/transport/writing.cc +61 -27
- data/src/core/ext/transport/inproc/inproc_transport.cc +18 -18
- data/src/core/lib/channel/channel_args.cc +0 -101
- data/src/core/lib/channel/channel_args.h +0 -37
- data/src/core/lib/channel/channel_stack.h +9 -5
- data/src/core/lib/channel/channelz_registry.cc +1 -1
- data/src/core/lib/channel/connected_channel.cc +2 -2
- data/src/core/lib/channel/context.h +3 -0
- data/src/core/lib/channel/handshaker.cc +4 -4
- data/src/core/lib/channel/handshaker.h +1 -1
- data/src/core/lib/compression/compression_args.cc +127 -0
- data/src/core/lib/compression/compression_args.h +55 -0
- data/src/core/lib/debug/trace.cc +13 -7
- data/src/core/lib/debug/trace.h +12 -0
- data/src/core/lib/gpr/arena.h +13 -9
- data/src/core/lib/gpr/env.h +2 -5
- data/src/core/lib/gpr/env_linux.cc +6 -1
- data/src/core/lib/gpr/env_posix.cc +5 -0
- data/src/core/lib/gpr/env_windows.cc +7 -5
- data/src/core/lib/gpr/log.cc +9 -13
- data/src/core/lib/gpr/string.cc +12 -6
- data/src/core/lib/gpr/string.h +4 -2
- data/src/core/lib/gpr/time_posix.cc +13 -0
- data/src/core/lib/gprpp/arena.cc +103 -0
- data/src/core/lib/gprpp/arena.h +121 -0
- data/src/core/lib/gprpp/fork.cc +12 -29
- data/src/core/lib/gprpp/global_config.h +87 -0
- data/src/core/lib/gprpp/global_config_custom.h +29 -0
- data/src/core/lib/gprpp/global_config_env.cc +135 -0
- data/src/core/lib/gprpp/global_config_env.h +131 -0
- data/src/core/lib/gprpp/global_config_generic.h +44 -0
- data/src/core/lib/gprpp/map.h +419 -0
- data/src/core/lib/gprpp/optional.h +1 -0
- data/src/core/lib/gprpp/orphanable.h +2 -2
- data/src/core/lib/gprpp/{mutex_lock.h → pair.h} +15 -19
- data/src/core/lib/gprpp/ref_counted.h +18 -2
- data/src/core/lib/gprpp/sync.h +126 -0
- data/src/core/lib/http/parser.cc +1 -1
- data/src/core/lib/iomgr/call_combiner.cc +84 -90
- data/src/core/lib/iomgr/call_combiner.h +75 -82
- data/src/core/lib/iomgr/cfstream_handle.cc +202 -0
- data/src/core/lib/iomgr/cfstream_handle.h +82 -0
- data/src/core/lib/iomgr/combiner.h +1 -1
- data/src/core/lib/iomgr/endpoint_cfstream.cc +375 -0
- data/src/core/lib/iomgr/endpoint_cfstream.h +49 -0
- data/src/core/lib/iomgr/endpoint_pair_windows.cc +2 -2
- data/src/core/lib/iomgr/error.h +23 -0
- data/src/core/lib/iomgr/error_cfstream.cc +52 -0
- data/src/core/lib/iomgr/error_cfstream.h +31 -0
- data/src/core/lib/iomgr/ev_epoll1_linux.cc +34 -27
- data/src/core/lib/iomgr/ev_epollex_linux.cc +33 -33
- data/src/core/lib/iomgr/ev_poll_posix.cc +7 -7
- data/src/core/lib/iomgr/ev_posix.cc +15 -13
- data/src/core/lib/iomgr/ev_posix.h +4 -1
- data/src/core/lib/iomgr/executor.cc +13 -9
- data/src/core/lib/iomgr/fork_posix.cc +0 -1
- data/src/core/lib/iomgr/internal_errqueue.cc +1 -1
- data/src/core/lib/iomgr/iomgr.cc +6 -5
- data/src/core/lib/iomgr/iomgr_custom.cc +3 -0
- data/src/core/lib/iomgr/iomgr_custom.h +2 -0
- data/src/core/lib/iomgr/iomgr_posix_cfstream.cc +93 -0
- data/src/core/lib/iomgr/iomgr_windows.cc +1 -0
- data/src/core/lib/iomgr/lockfree_event.cc +3 -3
- data/src/core/lib/iomgr/port.h +11 -0
- data/src/core/lib/iomgr/resource_quota.cc +40 -37
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +6 -2
- data/src/core/lib/iomgr/socket_windows.cc +19 -0
- data/src/core/lib/iomgr/socket_windows.h +8 -0
- data/src/core/lib/iomgr/tcp_client_cfstream.cc +216 -0
- data/src/core/lib/iomgr/tcp_client_custom.cc +2 -2
- data/src/core/lib/iomgr/tcp_client_posix.cc +3 -3
- data/src/core/lib/iomgr/tcp_client_windows.cc +1 -1
- data/src/core/lib/iomgr/tcp_custom.cc +9 -9
- data/src/core/lib/iomgr/tcp_posix.cc +41 -41
- data/src/core/lib/iomgr/tcp_server_custom.cc +3 -3
- data/src/core/lib/iomgr/tcp_server_posix.cc +14 -1
- data/src/core/lib/iomgr/tcp_server_windows.cc +2 -2
- data/src/core/lib/iomgr/tcp_windows.cc +7 -9
- data/src/core/lib/iomgr/timer_generic.cc +16 -16
- data/src/core/lib/iomgr/timer_manager.cc +12 -11
- data/src/core/lib/profiling/basic_timers.cc +10 -4
- data/src/core/lib/security/context/security_context.cc +6 -7
- data/src/core/lib/security/context/security_context.h +3 -4
- data/src/core/lib/security/credentials/jwt/jwt_credentials.cc +1 -1
- data/src/core/lib/security/credentials/jwt/jwt_verifier.cc +2 -3
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +7 -7
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +7 -5
- data/src/core/lib/security/security_connector/security_connector.cc +0 -1
- data/src/core/lib/security/security_connector/ssl/ssl_security_connector.cc +3 -2
- data/src/core/lib/security/security_connector/ssl_utils.cc +30 -26
- data/src/core/lib/security/security_connector/ssl_utils.h +5 -1
- data/src/core/lib/security/transport/client_auth_filter.cc +7 -11
- data/src/core/lib/security/transport/secure_endpoint.cc +4 -4
- data/src/core/lib/security/transport/server_auth_filter.cc +2 -3
- data/src/core/lib/slice/slice.cc +99 -116
- data/src/core/lib/slice/slice_buffer.cc +5 -0
- data/src/core/lib/slice/slice_intern.cc +38 -95
- data/src/core/lib/slice/slice_internal.h +200 -2
- data/src/core/lib/surface/api_trace.h +1 -1
- data/src/core/lib/surface/call.cc +41 -35
- data/src/core/lib/surface/call.h +7 -2
- data/src/core/lib/surface/call_details.cc +0 -1
- data/src/core/lib/surface/completion_queue.cc +36 -27
- data/src/core/lib/surface/init.cc +3 -4
- data/src/core/lib/surface/lame_client.cc +1 -1
- data/src/core/lib/surface/server.cc +18 -25
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/lib/transport/bdp_estimator.cc +3 -3
- data/src/core/lib/transport/bdp_estimator.h +2 -2
- data/src/core/lib/transport/connectivity_state.cc +10 -40
- data/src/core/lib/transport/connectivity_state.h +0 -8
- data/src/core/lib/transport/error_utils.cc +12 -0
- data/src/core/lib/transport/metadata.cc +206 -278
- data/src/core/lib/transport/metadata.h +205 -10
- data/src/core/lib/transport/static_metadata.cc +108 -116
- data/src/core/lib/transport/static_metadata.h +1 -2
- data/src/core/lib/transport/status_metadata.cc +3 -3
- data/src/core/lib/transport/transport.cc +29 -66
- data/src/core/lib/transport/transport.h +36 -8
- data/src/core/lib/transport/transport_impl.h +1 -1
- data/src/core/tsi/fake_transport_security.cc +4 -4
- data/src/core/tsi/ssl/session_cache/ssl_session_cache.cc +1 -1
- data/src/core/tsi/ssl_transport_security.cc +1 -1
- data/src/ruby/ext/grpc/rb_grpc.c +1 -1
- data/src/ruby/lib/grpc/errors.rb +22 -3
- data/src/ruby/lib/grpc/generic/bidi_call.rb +1 -1
- data/src/ruby/lib/grpc/generic/rpc_server.rb +1 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +141 -0
- metadata +57 -33
- data/src/core/lib/gpr/arena.cc +0 -192
@@ -54,6 +54,9 @@ void grpc_ares_ev_driver_on_queries_complete_locked(
|
|
54
54
|
/* Shutdown all the grpc_fds used by \a ev_driver */
|
55
55
|
void grpc_ares_ev_driver_shutdown_locked(grpc_ares_ev_driver* ev_driver);
|
56
56
|
|
57
|
+
/* Exposed in this header for C-core tests only */
|
58
|
+
extern void (*grpc_ares_test_only_inject_config)(ares_channel channel);
|
59
|
+
|
57
60
|
namespace grpc_core {
|
58
61
|
|
59
62
|
/* A wrapped fd that integrates with the grpc iomgr of the current platform.
|
@@ -0,0 +1,179 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2019 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
|
+
#include <grpc/support/port_platform.h>
|
19
|
+
|
20
|
+
#include "src/core/lib/iomgr/port.h"
|
21
|
+
#if GRPC_ARES == 1 && defined(GRPC_UV)
|
22
|
+
|
23
|
+
#include <ares.h>
|
24
|
+
#include <uv.h>
|
25
|
+
|
26
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_ev_driver.h"
|
27
|
+
|
28
|
+
#include <grpc/support/alloc.h>
|
29
|
+
#include <grpc/support/log.h>
|
30
|
+
#include <grpc/support/string_util.h>
|
31
|
+
#include <grpc/support/time.h>
|
32
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
33
|
+
#include "src/core/lib/gpr/string.h"
|
34
|
+
#include "src/core/lib/iomgr/combiner.h"
|
35
|
+
|
36
|
+
namespace grpc_core {
|
37
|
+
|
38
|
+
void ares_uv_poll_cb(uv_poll_t* handle, int status, int events);
|
39
|
+
|
40
|
+
void ares_uv_poll_close_cb(uv_handle_t* handle) { Delete(handle); }
|
41
|
+
|
42
|
+
class GrpcPolledFdLibuv : public GrpcPolledFd {
|
43
|
+
public:
|
44
|
+
GrpcPolledFdLibuv(ares_socket_t as, grpc_combiner* combiner)
|
45
|
+
: as_(as), combiner_(combiner) {
|
46
|
+
gpr_asprintf(&name_, "c-ares socket: %" PRIdPTR, (intptr_t)as);
|
47
|
+
handle_ = New<uv_poll_t>();
|
48
|
+
uv_poll_init_socket(uv_default_loop(), handle_, as);
|
49
|
+
handle_->data = this;
|
50
|
+
GRPC_COMBINER_REF(combiner_, "libuv ares event driver");
|
51
|
+
}
|
52
|
+
|
53
|
+
~GrpcPolledFdLibuv() {
|
54
|
+
gpr_free(name_);
|
55
|
+
GRPC_COMBINER_UNREF(combiner_, "libuv ares event driver");
|
56
|
+
}
|
57
|
+
|
58
|
+
void RegisterForOnReadableLocked(grpc_closure* read_closure) override {
|
59
|
+
GPR_ASSERT(read_closure_ == nullptr);
|
60
|
+
GPR_ASSERT((poll_events_ & UV_READABLE) == 0);
|
61
|
+
read_closure_ = read_closure;
|
62
|
+
poll_events_ |= UV_READABLE;
|
63
|
+
uv_poll_start(handle_, poll_events_, ares_uv_poll_cb);
|
64
|
+
}
|
65
|
+
|
66
|
+
void RegisterForOnWriteableLocked(grpc_closure* write_closure) override {
|
67
|
+
GPR_ASSERT(write_closure_ == nullptr);
|
68
|
+
GPR_ASSERT((poll_events_ & UV_WRITABLE) == 0);
|
69
|
+
write_closure_ = write_closure;
|
70
|
+
poll_events_ |= UV_WRITABLE;
|
71
|
+
uv_poll_start(handle_, poll_events_, ares_uv_poll_cb);
|
72
|
+
}
|
73
|
+
|
74
|
+
bool IsFdStillReadableLocked() override {
|
75
|
+
/* uv_poll_t is based on poll, which is level triggered. So, if cares
|
76
|
+
* leaves some data unread, the event will trigger again. */
|
77
|
+
return false;
|
78
|
+
}
|
79
|
+
|
80
|
+
void ShutdownInternalLocked(grpc_error* error) {
|
81
|
+
uv_poll_stop(handle_);
|
82
|
+
uv_close(reinterpret_cast<uv_handle_t*>(handle_), ares_uv_poll_close_cb);
|
83
|
+
if (read_closure_ != nullptr) {
|
84
|
+
GRPC_CLOSURE_SCHED(read_closure_, GRPC_ERROR_CANCELLED);
|
85
|
+
}
|
86
|
+
if (write_closure_ != nullptr) {
|
87
|
+
GRPC_CLOSURE_SCHED(write_closure_, GRPC_ERROR_CANCELLED);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
void ShutdownLocked(grpc_error* error) override {
|
92
|
+
if (grpc_core::ExecCtx::Get() == nullptr) {
|
93
|
+
grpc_core::ExecCtx exec_ctx;
|
94
|
+
ShutdownInternalLocked(error);
|
95
|
+
} else {
|
96
|
+
ShutdownInternalLocked(error);
|
97
|
+
}
|
98
|
+
}
|
99
|
+
|
100
|
+
ares_socket_t GetWrappedAresSocketLocked() override { return as_; }
|
101
|
+
|
102
|
+
const char* GetName() override { return name_; }
|
103
|
+
|
104
|
+
char* name_;
|
105
|
+
ares_socket_t as_;
|
106
|
+
uv_poll_t* handle_;
|
107
|
+
grpc_closure* read_closure_ = nullptr;
|
108
|
+
grpc_closure* write_closure_ = nullptr;
|
109
|
+
int poll_events_ = 0;
|
110
|
+
grpc_combiner* combiner_;
|
111
|
+
};
|
112
|
+
|
113
|
+
struct AresUvPollCbArg {
|
114
|
+
AresUvPollCbArg(uv_poll_t* handle, int status, int events)
|
115
|
+
: handle(handle), status(status), events(events) {}
|
116
|
+
|
117
|
+
uv_poll_t* handle;
|
118
|
+
int status;
|
119
|
+
int events;
|
120
|
+
};
|
121
|
+
|
122
|
+
static void ares_uv_poll_cb_locked(void* arg, grpc_error* error) {
|
123
|
+
grpc_core::UniquePtr<AresUvPollCbArg> arg_struct(
|
124
|
+
reinterpret_cast<AresUvPollCbArg*>(arg));
|
125
|
+
uv_poll_t* handle = arg_struct->handle;
|
126
|
+
int status = arg_struct->status;
|
127
|
+
int events = arg_struct->events;
|
128
|
+
GrpcPolledFdLibuv* polled_fd =
|
129
|
+
reinterpret_cast<GrpcPolledFdLibuv*>(handle->data);
|
130
|
+
if (status < 0) {
|
131
|
+
error = GRPC_ERROR_CREATE_FROM_STATIC_STRING("cares polling error");
|
132
|
+
error =
|
133
|
+
grpc_error_set_str(error, GRPC_ERROR_STR_OS_ERROR,
|
134
|
+
grpc_slice_from_static_string(uv_strerror(status)));
|
135
|
+
}
|
136
|
+
if (events & UV_READABLE) {
|
137
|
+
GPR_ASSERT(polled_fd->read_closure_ != nullptr);
|
138
|
+
GRPC_CLOSURE_SCHED(polled_fd->read_closure_, error);
|
139
|
+
polled_fd->read_closure_ = nullptr;
|
140
|
+
polled_fd->poll_events_ &= ~UV_READABLE;
|
141
|
+
}
|
142
|
+
if (events & UV_WRITABLE) {
|
143
|
+
GPR_ASSERT(polled_fd->write_closure_ != nullptr);
|
144
|
+
GRPC_CLOSURE_SCHED(polled_fd->write_closure_, error);
|
145
|
+
polled_fd->write_closure_ = nullptr;
|
146
|
+
polled_fd->poll_events_ &= ~UV_WRITABLE;
|
147
|
+
}
|
148
|
+
uv_poll_start(handle, polled_fd->poll_events_, ares_uv_poll_cb);
|
149
|
+
}
|
150
|
+
|
151
|
+
void ares_uv_poll_cb(uv_poll_t* handle, int status, int events) {
|
152
|
+
grpc_core::ExecCtx exec_ctx;
|
153
|
+
GrpcPolledFdLibuv* polled_fd =
|
154
|
+
reinterpret_cast<GrpcPolledFdLibuv*>(handle->data);
|
155
|
+
AresUvPollCbArg* arg = New<AresUvPollCbArg>(handle, status, events);
|
156
|
+
GRPC_CLOSURE_SCHED(
|
157
|
+
GRPC_CLOSURE_CREATE(ares_uv_poll_cb_locked, arg,
|
158
|
+
grpc_combiner_scheduler(polled_fd->combiner_)),
|
159
|
+
GRPC_ERROR_NONE);
|
160
|
+
}
|
161
|
+
|
162
|
+
class GrpcPolledFdFactoryLibuv : public GrpcPolledFdFactory {
|
163
|
+
public:
|
164
|
+
GrpcPolledFd* NewGrpcPolledFdLocked(ares_socket_t as,
|
165
|
+
grpc_pollset_set* driver_pollset_set,
|
166
|
+
grpc_combiner* combiner) override {
|
167
|
+
return New<GrpcPolledFdLibuv>(as, combiner);
|
168
|
+
}
|
169
|
+
|
170
|
+
void ConfigureAresChannelLocked(ares_channel channel) override {}
|
171
|
+
};
|
172
|
+
|
173
|
+
UniquePtr<GrpcPolledFdFactory> NewGrpcPolledFdFactory(grpc_combiner* combiner) {
|
174
|
+
return UniquePtr<GrpcPolledFdFactory>(New<GrpcPolledFdFactoryLibuv>());
|
175
|
+
}
|
176
|
+
|
177
|
+
} // namespace grpc_core
|
178
|
+
|
179
|
+
#endif /* GRPC_ARES == 1 && defined(GRPC_UV) */
|
@@ -18,7 +18,7 @@
|
|
18
18
|
#include <grpc/support/port_platform.h>
|
19
19
|
|
20
20
|
#include "src/core/lib/iomgr/port.h"
|
21
|
-
#if GRPC_ARES == 1 && defined(
|
21
|
+
#if GRPC_ARES == 1 && defined(GRPC_WINDOWS_SOCKET_ARES_EV_DRIVER)
|
22
22
|
|
23
23
|
#include <ares.h>
|
24
24
|
|
@@ -109,6 +109,7 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
109
109
|
read_closure_ = read_closure;
|
110
110
|
GPR_ASSERT(GRPC_SLICE_LENGTH(read_buf_) == 0);
|
111
111
|
grpc_slice_unref_internal(read_buf_);
|
112
|
+
GPR_ASSERT(!read_buf_has_data_);
|
112
113
|
read_buf_ = GRPC_SLICE_MALLOC(4192);
|
113
114
|
WSABUF buffer;
|
114
115
|
buffer.buf = (char*)GRPC_SLICE_START_PTR(read_buf_);
|
@@ -175,7 +176,7 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
175
176
|
GRPC_CARES_TRACE_LOG(
|
176
177
|
"RecvFrom called on fd:|%s|. Current read buf length:|%d|", GetName(),
|
177
178
|
GRPC_SLICE_LENGTH(read_buf_));
|
178
|
-
if (
|
179
|
+
if (!read_buf_has_data_) {
|
179
180
|
WSASetLastError(WSAEWOULDBLOCK);
|
180
181
|
return -1;
|
181
182
|
}
|
@@ -186,6 +187,9 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
186
187
|
}
|
187
188
|
read_buf_ = grpc_slice_sub_no_ref(read_buf_, bytes_read,
|
188
189
|
GRPC_SLICE_LENGTH(read_buf_));
|
190
|
+
if (GRPC_SLICE_LENGTH(read_buf_) == 0) {
|
191
|
+
read_buf_has_data_ = false;
|
192
|
+
}
|
189
193
|
/* c-ares overloads this recv_from virtual socket function to receive
|
190
194
|
* data on both UDP and TCP sockets, and from is nullptr for TCP. */
|
191
195
|
if (from != nullptr) {
|
@@ -302,6 +306,11 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
302
306
|
polled_fd->OnIocpReadableInner(error);
|
303
307
|
}
|
304
308
|
|
309
|
+
// TODO(apolcyn): improve this error handling to be less conversative.
|
310
|
+
// An e.g. ECONNRESET error here should result in errors when
|
311
|
+
// c-ares reads from this socket later, but it shouldn't necessarily cancel
|
312
|
+
// the entire resolution attempt. Doing so will allow the "inject broken
|
313
|
+
// nameserver list" test to pass on Windows.
|
305
314
|
void OnIocpReadableInner(grpc_error* error) {
|
306
315
|
if (error == GRPC_ERROR_NONE) {
|
307
316
|
if (winsocket_->read_info.wsa_error != 0) {
|
@@ -323,6 +332,7 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
323
332
|
if (error == GRPC_ERROR_NONE) {
|
324
333
|
read_buf_ = grpc_slice_sub_no_ref(read_buf_, 0,
|
325
334
|
winsocket_->read_info.bytes_transfered);
|
335
|
+
read_buf_has_data_ = true;
|
326
336
|
} else {
|
327
337
|
grpc_slice_unref_internal(read_buf_);
|
328
338
|
read_buf_ = grpc_empty_slice();
|
@@ -370,6 +380,7 @@ class GrpcPolledFdWindows : public GrpcPolledFd {
|
|
370
380
|
char recv_from_source_addr_[200];
|
371
381
|
ares_socklen_t recv_from_source_addr_len_;
|
372
382
|
grpc_slice read_buf_;
|
383
|
+
bool read_buf_has_data_ = false;
|
373
384
|
grpc_slice write_buf_;
|
374
385
|
grpc_closure* read_closure_ = nullptr;
|
375
386
|
grpc_closure* write_closure_ = nullptr;
|
@@ -445,7 +456,8 @@ class SockToPolledFdMap {
|
|
445
456
|
*/
|
446
457
|
static ares_socket_t Socket(int af, int type, int protocol, void* user_data) {
|
447
458
|
SockToPolledFdMap* map = static_cast<SockToPolledFdMap*>(user_data);
|
448
|
-
SOCKET s = WSASocket(af, type, protocol, nullptr, 0,
|
459
|
+
SOCKET s = WSASocket(af, type, protocol, nullptr, 0,
|
460
|
+
grpc_get_default_wsa_socket_flags());
|
449
461
|
if (s == INVALID_SOCKET) {
|
450
462
|
return s;
|
451
463
|
}
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
#include <grpc/support/port_platform.h>
|
20
20
|
|
21
|
-
#if GRPC_ARES == 1
|
21
|
+
#if GRPC_ARES == 1
|
22
22
|
|
23
23
|
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
24
24
|
#include "src/core/lib/iomgr/sockaddr.h"
|
@@ -101,7 +101,7 @@ static void log_address_sorting_list(const ServerAddressList& addresses,
|
|
101
101
|
}
|
102
102
|
|
103
103
|
void grpc_cares_wrapper_address_sorting_sort(ServerAddressList* addresses) {
|
104
|
-
if (grpc_trace_cares_address_sorting
|
104
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_address_sorting)) {
|
105
105
|
log_address_sorting_list(*addresses, "input");
|
106
106
|
}
|
107
107
|
address_sorting_sortable* sortables = (address_sorting_sortable*)gpr_zalloc(
|
@@ -120,7 +120,7 @@ void grpc_cares_wrapper_address_sorting_sort(ServerAddressList* addresses) {
|
|
120
120
|
}
|
121
121
|
gpr_free(sortables);
|
122
122
|
*addresses = std::move(sorted);
|
123
|
-
if (grpc_trace_cares_address_sorting
|
123
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_address_sorting)) {
|
124
124
|
log_address_sorting_list(*addresses, "output");
|
125
125
|
}
|
126
126
|
}
|
@@ -154,6 +154,10 @@ void grpc_ares_complete_request_locked(grpc_ares_request* r) {
|
|
154
154
|
static grpc_ares_hostbyname_request* create_hostbyname_request_locked(
|
155
155
|
grpc_ares_request* parent_request, char* host, uint16_t port,
|
156
156
|
bool is_balancer) {
|
157
|
+
GRPC_CARES_TRACE_LOG(
|
158
|
+
"request:%p create_hostbyname_request_locked host:%s port:%d "
|
159
|
+
"is_balancer:%d",
|
160
|
+
parent_request, host, port, is_balancer);
|
157
161
|
grpc_ares_hostbyname_request* hr = static_cast<grpc_ares_hostbyname_request*>(
|
158
162
|
gpr_zalloc(sizeof(grpc_ares_hostbyname_request)));
|
159
163
|
hr->parent_request = parent_request;
|
@@ -251,6 +255,8 @@ static void on_srv_query_done_locked(void* arg, int status, int timeouts,
|
|
251
255
|
GRPC_CARES_TRACE_LOG("request:%p on_srv_query_done_locked ARES_SUCCESS", r);
|
252
256
|
struct ares_srv_reply* reply;
|
253
257
|
const int parse_status = ares_parse_srv_reply(abuf, alen, &reply);
|
258
|
+
GRPC_CARES_TRACE_LOG("request:%p ares_parse_srv_reply: %d", r,
|
259
|
+
parse_status);
|
254
260
|
if (parse_status == ARES_SUCCESS) {
|
255
261
|
ares_channel* channel =
|
256
262
|
grpc_ares_ev_driver_get_channel_locked(r->ev_driver);
|
@@ -516,6 +522,76 @@ static bool target_matches_localhost(const char* name) {
|
|
516
522
|
return out;
|
517
523
|
}
|
518
524
|
|
525
|
+
#ifdef GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY
|
526
|
+
static bool inner_maybe_resolve_localhost_manually_locked(
|
527
|
+
const char* name, const char* default_port,
|
528
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs, char** host,
|
529
|
+
char** port) {
|
530
|
+
gpr_split_host_port(name, host, port);
|
531
|
+
if (*host == nullptr) {
|
532
|
+
gpr_log(GPR_ERROR,
|
533
|
+
"Failed to parse %s into host:port during manual localhost "
|
534
|
+
"resolution check.",
|
535
|
+
name);
|
536
|
+
return false;
|
537
|
+
}
|
538
|
+
if (*port == nullptr) {
|
539
|
+
if (default_port == nullptr) {
|
540
|
+
gpr_log(GPR_ERROR,
|
541
|
+
"No port or default port for %s during manual localhost "
|
542
|
+
"resolution check.",
|
543
|
+
name);
|
544
|
+
return false;
|
545
|
+
}
|
546
|
+
*port = gpr_strdup(default_port);
|
547
|
+
}
|
548
|
+
if (gpr_stricmp(*host, "localhost") == 0) {
|
549
|
+
GPR_ASSERT(*addrs == nullptr);
|
550
|
+
*addrs = grpc_core::MakeUnique<grpc_core::ServerAddressList>();
|
551
|
+
uint16_t numeric_port = grpc_strhtons(*port);
|
552
|
+
// Append the ipv6 loopback address.
|
553
|
+
struct sockaddr_in6 ipv6_loopback_addr;
|
554
|
+
memset(&ipv6_loopback_addr, 0, sizeof(ipv6_loopback_addr));
|
555
|
+
((char*)&ipv6_loopback_addr.sin6_addr)[15] = 1;
|
556
|
+
ipv6_loopback_addr.sin6_family = AF_INET6;
|
557
|
+
ipv6_loopback_addr.sin6_port = numeric_port;
|
558
|
+
(*addrs)->emplace_back(&ipv6_loopback_addr, sizeof(ipv6_loopback_addr),
|
559
|
+
nullptr /* args */);
|
560
|
+
// Append the ipv4 loopback address.
|
561
|
+
struct sockaddr_in ipv4_loopback_addr;
|
562
|
+
memset(&ipv4_loopback_addr, 0, sizeof(ipv4_loopback_addr));
|
563
|
+
((char*)&ipv4_loopback_addr.sin_addr)[0] = 0x7f;
|
564
|
+
((char*)&ipv4_loopback_addr.sin_addr)[3] = 0x01;
|
565
|
+
ipv4_loopback_addr.sin_family = AF_INET;
|
566
|
+
ipv4_loopback_addr.sin_port = numeric_port;
|
567
|
+
(*addrs)->emplace_back(&ipv4_loopback_addr, sizeof(ipv4_loopback_addr),
|
568
|
+
nullptr /* args */);
|
569
|
+
// Let the address sorter figure out which one should be tried first.
|
570
|
+
grpc_cares_wrapper_address_sorting_sort(addrs->get());
|
571
|
+
return true;
|
572
|
+
}
|
573
|
+
return false;
|
574
|
+
}
|
575
|
+
|
576
|
+
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
577
|
+
const char* name, const char* default_port,
|
578
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
|
579
|
+
char* host = nullptr;
|
580
|
+
char* port = nullptr;
|
581
|
+
bool out = inner_maybe_resolve_localhost_manually_locked(name, default_port,
|
582
|
+
addrs, &host, &port);
|
583
|
+
gpr_free(host);
|
584
|
+
gpr_free(port);
|
585
|
+
return out;
|
586
|
+
}
|
587
|
+
#else /* GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY */
|
588
|
+
static bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
589
|
+
const char* name, const char* default_port,
|
590
|
+
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs) {
|
591
|
+
return false;
|
592
|
+
}
|
593
|
+
#endif /* GRPC_ARES_RESOLVE_LOCALHOST_MANUALLY */
|
594
|
+
|
519
595
|
static grpc_ares_request* grpc_dns_lookup_ares_locked_impl(
|
520
596
|
const char* dns_server, const char* name, const char* default_port,
|
521
597
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
@@ -687,4 +763,4 @@ void (*grpc_resolve_address_ares)(
|
|
687
763
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
688
764
|
grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl;
|
689
765
|
|
690
|
-
#endif /* GRPC_ARES == 1
|
766
|
+
#endif /* GRPC_ARES == 1 */
|
@@ -26,16 +26,18 @@
|
|
26
26
|
#include "src/core/lib/iomgr/polling_entity.h"
|
27
27
|
#include "src/core/lib/iomgr/resolve_address.h"
|
28
28
|
|
29
|
-
#define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS
|
29
|
+
#define GRPC_DNS_ARES_DEFAULT_QUERY_TIMEOUT_MS 120000
|
30
30
|
|
31
31
|
extern grpc_core::TraceFlag grpc_trace_cares_address_sorting;
|
32
32
|
|
33
33
|
extern grpc_core::TraceFlag grpc_trace_cares_resolver;
|
34
34
|
|
35
|
-
#define GRPC_CARES_TRACE_LOG(format, ...)
|
36
|
-
|
37
|
-
|
38
|
-
|
35
|
+
#define GRPC_CARES_TRACE_LOG(format, ...) \
|
36
|
+
do { \
|
37
|
+
if (GRPC_TRACE_FLAG_ENABLED(grpc_trace_cares_resolver)) { \
|
38
|
+
gpr_log(GPR_DEBUG, "(c-ares resolver) " format, __VA_ARGS__); \
|
39
|
+
} \
|
40
|
+
} while (0)
|
39
41
|
|
40
42
|
typedef struct grpc_ares_request grpc_ares_request;
|
41
43
|
|
@@ -85,14 +87,6 @@ void grpc_ares_complete_request_locked(grpc_ares_request* request);
|
|
85
87
|
/* E.g., return false if ipv6 is known to not be available. */
|
86
88
|
bool grpc_ares_query_ipv6();
|
87
89
|
|
88
|
-
/* Maybe (depending on the current platform) checks if "name" matches
|
89
|
-
* "localhost" and if so fills in addrs with the correct sockaddr structures.
|
90
|
-
* Returns a bool indicating whether or not such an action was performed.
|
91
|
-
* See https://github.com/grpc/grpc/issues/15158. */
|
92
|
-
bool grpc_ares_maybe_resolve_localhost_manually_locked(
|
93
|
-
const char* name, const char* default_port,
|
94
|
-
grpc_core::UniquePtr<grpc_core::ServerAddressList>* addrs);
|
95
|
-
|
96
90
|
/* Sorts destinations in lb_addrs according to RFC 6724. */
|
97
91
|
void grpc_cares_wrapper_address_sorting_sort(
|
98
92
|
grpc_core::ServerAddressList* addresses);
|
@@ -18,7 +18,7 @@
|
|
18
18
|
|
19
19
|
#include <grpc/support/port_platform.h>
|
20
20
|
|
21
|
-
#if GRPC_ARES != 1
|
21
|
+
#if GRPC_ARES != 1
|
22
22
|
|
23
23
|
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
24
24
|
|
@@ -62,4 +62,4 @@ void (*grpc_resolve_address_ares)(
|
|
62
62
|
grpc_pollset_set* interested_parties, grpc_closure* on_done,
|
63
63
|
grpc_resolved_addresses** addrs) = grpc_resolve_address_ares_impl;
|
64
64
|
|
65
|
-
#endif /* GRPC_ARES != 1
|
65
|
+
#endif /* GRPC_ARES != 1 */
|
@@ -0,0 +1,39 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright 2016 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
|
+
#include <grpc/support/port_platform.h>
|
20
|
+
|
21
|
+
#include "src/core/lib/iomgr/port.h"
|
22
|
+
#if GRPC_ARES == 1 && defined(GRPC_UV)
|
23
|
+
|
24
|
+
#include <grpc/support/string_util.h>
|
25
|
+
|
26
|
+
#include "src/core/ext/filters/client_channel/parse_address.h"
|
27
|
+
#include "src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h"
|
28
|
+
#include "src/core/ext/filters/client_channel/server_address.h"
|
29
|
+
#include "src/core/lib/gpr/host_port.h"
|
30
|
+
#include "src/core/lib/gpr/string.h"
|
31
|
+
|
32
|
+
bool grpc_ares_query_ipv6() {
|
33
|
+
/* The libuv grpc code currently does not have the code to probe for this,
|
34
|
+
* so we assume for now that IPv6 is always available in contexts where this
|
35
|
+
* code will be used. */
|
36
|
+
return true;
|
37
|
+
}
|
38
|
+
|
39
|
+
#endif /* GRPC_ARES == 1 && defined(GRPC_UV) */
|