grpc 1.26.0 → 1.27.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 +1654 -1519
- data/etc/roots.pem +44 -0
- data/include/grpc/grpc_security.h +37 -15
- data/include/grpc/grpc_security_constants.h +27 -0
- data/include/grpc/impl/codegen/grpc_types.h +14 -0
- data/include/grpc/impl/codegen/port_platform.h +1 -1
- data/src/core/ext/filters/client_channel/client_channel.cc +0 -20
- data/src/core/ext/filters/client_channel/http_proxy.cc +4 -4
- data/src/core/ext/filters/client_channel/lb_policy.cc +4 -3
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +191 -201
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.cc +89 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h +40 -0
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +3 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +88 -121
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +28 -57
- data/src/core/ext/filters/client_channel/lb_policy/subchannel_list.h +0 -7
- data/src/core/ext/filters/client_channel/lb_policy/xds/cds.cc +8 -9
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +53 -34
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/dns_resolver_ares.cc +18 -5
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.cc +24 -19
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper.h +2 -1
- data/src/core/ext/filters/client_channel/resolver/dns/c_ares/grpc_ares_wrapper_fallback.cc +4 -2
- data/src/core/ext/filters/client_channel/server_address.cc +6 -9
- data/src/core/ext/filters/client_channel/server_address.h +3 -10
- data/src/core/ext/filters/client_channel/xds/xds_api.cc +394 -150
- data/src/core/ext/filters/client_channel/xds/xds_api.h +75 -35
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.cc +59 -22
- data/src/core/ext/filters/client_channel/xds/xds_bootstrap.h +13 -9
- data/src/core/ext/filters/client_channel/xds/xds_channel_secure.cc +8 -6
- data/src/core/ext/filters/client_channel/xds/xds_client.cc +456 -175
- data/src/core/ext/filters/client_channel/xds/xds_client.h +33 -21
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.cc +5 -8
- data/src/core/ext/filters/client_channel/xds/xds_client_stats.h +18 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +2 -2
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +13 -5
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +34 -0
- data/src/core/lib/channel/channelz.h +11 -1
- data/src/core/lib/gpr/time_precise.cc +1 -1
- data/src/core/lib/gprpp/optional.h +26 -0
- data/src/core/lib/gprpp/string_view.h +14 -10
- data/src/core/lib/iomgr/executor.cc +1 -1
- data/src/core/lib/iomgr/fork_posix.cc +4 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.cc +87 -0
- data/src/core/lib/iomgr/poller/eventmanager_libuv.h +88 -0
- data/src/core/lib/iomgr/socket_utils_common_posix.cc +14 -0
- data/src/core/lib/iomgr/socket_utils_posix.h +12 -0
- data/src/core/lib/iomgr/tcp_custom.h +3 -0
- data/src/core/lib/iomgr/tcp_posix.cc +607 -56
- data/src/core/lib/iomgr/tcp_server_custom.cc +15 -2
- data/src/core/lib/iomgr/tcp_server_utils_posix_common.cc +8 -0
- data/src/core/lib/json/json.h +11 -1
- data/src/core/lib/json/json_reader.cc +206 -28
- data/src/core/lib/json/json_writer.cc +111 -24
- data/src/core/lib/security/credentials/composite/composite_credentials.cc +7 -0
- data/src/core/lib/security/credentials/composite/composite_credentials.h +5 -1
- data/src/core/lib/security/credentials/credentials.h +10 -1
- data/src/core/lib/security/credentials/fake/fake_credentials.h +2 -1
- data/src/core/lib/security/credentials/oauth2/oauth2_credentials.cc +1 -1
- data/src/core/lib/security/credentials/plugin/plugin_credentials.cc +6 -4
- data/src/core/lib/security/credentials/plugin/plugin_credentials.h +2 -1
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +20 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +8 -0
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.cc → tls_credentials.cc} +23 -24
- data/src/core/lib/security/credentials/tls/{spiffe_credentials.h → tls_credentials.h} +9 -9
- data/src/core/lib/security/security_connector/alts/alts_security_connector.cc +13 -0
- data/src/core/lib/security/security_connector/fake/fake_security_connector.cc +22 -2
- data/src/core/lib/security/security_connector/load_system_roots_fallback.cc +2 -2
- data/src/core/lib/security/security_connector/load_system_roots_linux.cc +2 -2
- data/src/core/lib/security/security_connector/local/local_security_connector.cc +30 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +45 -3
- data/src/core/lib/security/security_connector/ssl_utils.h +12 -0
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.cc → tls_security_connector.cc} +82 -69
- data/src/core/lib/security/security_connector/tls/{spiffe_security_connector.h → tls_security_connector.h} +17 -18
- data/src/core/lib/security/transport/client_auth_filter.cc +33 -0
- data/src/core/lib/surface/completion_queue.cc +22 -1
- data/src/core/lib/surface/version.cc +1 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +11 -1
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +1 -1
- data/src/core/tsi/alts/zero_copy_frame_protector/alts_zero_copy_grpc_protector.cc +3 -3
- data/src/core/tsi/fake_transport_security.cc +7 -3
- data/src/core/tsi/fake_transport_security.h +2 -0
- data/src/core/tsi/ssl_transport_security.cc +144 -8
- data/src/core/tsi/ssl_transport_security.h +15 -1
- data/src/core/tsi/transport_security.cc +13 -0
- data/src/core/tsi/transport_security_grpc.cc +2 -2
- data/src/core/tsi/transport_security_grpc.h +2 -2
- data/src/core/tsi/transport_security_interface.h +12 -0
- data/src/ruby/bin/math_pb.rb +5 -5
- data/src/ruby/ext/grpc/rb_call_credentials.c +4 -1
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +2 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +4 -1
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +3 -3
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +1 -1
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +23 -13
- data/third_party/abseil-cpp/absl/algorithm/algorithm.h +159 -0
- data/third_party/abseil-cpp/absl/base/attributes.h +609 -0
- data/third_party/abseil-cpp/absl/base/call_once.h +226 -0
- data/third_party/abseil-cpp/absl/base/casts.h +184 -0
- data/third_party/abseil-cpp/absl/base/config.h +622 -0
- data/third_party/abseil-cpp/absl/base/const_init.h +76 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.cc +129 -0
- data/third_party/abseil-cpp/absl/base/dynamic_annotations.h +389 -0
- data/third_party/abseil-cpp/absl/base/internal/atomic_hook.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/bits.h +218 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.cc +107 -0
- data/third_party/abseil-cpp/absl/base/internal/cycleclock.h +94 -0
- data/third_party/abseil-cpp/absl/base/internal/endian.h +266 -0
- data/third_party/abseil-cpp/absl/base/internal/hide_ptr.h +51 -0
- data/third_party/abseil-cpp/absl/base/internal/identity.h +37 -0
- data/third_party/abseil-cpp/absl/base/internal/inline_variable.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/invoke.h +187 -0
- data/third_party/abseil-cpp/absl/base/internal/low_level_scheduling.h +107 -0
- data/third_party/abseil-cpp/absl/base/internal/per_thread_tls.h +52 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.cc +237 -0
- data/third_party/abseil-cpp/absl/base/internal/raw_logging.h +179 -0
- data/third_party/abseil-cpp/absl/base/internal/scheduling_mode.h +58 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.cc +233 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock.h +243 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_akaros.inc +35 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_linux.inc +67 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_posix.inc +46 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.cc +81 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_wait.h +93 -0
- data/third_party/abseil-cpp/absl/base/internal/spinlock_win32.inc +37 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.cc +414 -0
- data/third_party/abseil-cpp/absl/base/internal/sysinfo.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_annotations.h +271 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.cc +140 -0
- data/third_party/abseil-cpp/absl/base/internal/thread_identity.h +250 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.cc +108 -0
- data/third_party/abseil-cpp/absl/base/internal/throw_delegate.h +75 -0
- data/third_party/abseil-cpp/absl/base/internal/tsan_mutex_interface.h +66 -0
- data/third_party/abseil-cpp/absl/base/internal/unaligned_access.h +158 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.cc +103 -0
- data/third_party/abseil-cpp/absl/base/internal/unscaledcycleclock.h +124 -0
- data/third_party/abseil-cpp/absl/base/log_severity.cc +27 -0
- data/third_party/abseil-cpp/absl/base/log_severity.h +121 -0
- data/third_party/abseil-cpp/absl/base/macros.h +220 -0
- data/third_party/abseil-cpp/absl/base/optimization.h +181 -0
- data/third_party/abseil-cpp/absl/base/options.h +214 -0
- data/third_party/abseil-cpp/absl/base/policy_checks.h +111 -0
- data/third_party/abseil-cpp/absl/base/port.h +26 -0
- data/third_party/abseil-cpp/absl/base/thread_annotations.h +280 -0
- data/third_party/abseil-cpp/absl/container/inlined_vector.h +848 -0
- data/third_party/abseil-cpp/absl/container/internal/compressed_tuple.h +265 -0
- data/third_party/abseil-cpp/absl/container/internal/inlined_vector.h +892 -0
- data/third_party/abseil-cpp/absl/memory/memory.h +695 -0
- data/third_party/abseil-cpp/absl/meta/type_traits.h +759 -0
- data/third_party/abseil-cpp/absl/numeric/int128.cc +404 -0
- data/third_party/abseil-cpp/absl/numeric/int128.h +1091 -0
- data/third_party/abseil-cpp/absl/numeric/int128_have_intrinsic.inc +302 -0
- data/third_party/abseil-cpp/absl/numeric/int128_no_intrinsic.inc +308 -0
- data/third_party/abseil-cpp/absl/strings/ascii.cc +200 -0
- data/third_party/abseil-cpp/absl/strings/ascii.h +241 -0
- data/third_party/abseil-cpp/absl/strings/charconv.cc +985 -0
- data/third_party/abseil-cpp/absl/strings/charconv.h +119 -0
- data/third_party/abseil-cpp/absl/strings/escaping.cc +949 -0
- data/third_party/abseil-cpp/absl/strings/escaping.h +164 -0
- data/third_party/abseil-cpp/absl/strings/internal/char_map.h +156 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.cc +359 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_bigint.h +421 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.cc +504 -0
- data/third_party/abseil-cpp/absl/strings/internal/charconv_parse.h +99 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.cc +180 -0
- data/third_party/abseil-cpp/absl/strings/internal/escaping.h +58 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.cc +112 -0
- data/third_party/abseil-cpp/absl/strings/internal/memutil.h +148 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.cc +36 -0
- data/third_party/abseil-cpp/absl/strings/internal/ostringstream.h +89 -0
- data/third_party/abseil-cpp/absl/strings/internal/resize_uninitialized.h +73 -0
- data/third_party/abseil-cpp/absl/strings/internal/stl_type_traits.h +248 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_join_internal.h +314 -0
- data/third_party/abseil-cpp/absl/strings/internal/str_split_internal.h +455 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.cc +53 -0
- data/third_party/abseil-cpp/absl/strings/internal/utf8.h +50 -0
- data/third_party/abseil-cpp/absl/strings/match.cc +40 -0
- data/third_party/abseil-cpp/absl/strings/match.h +90 -0
- data/third_party/abseil-cpp/absl/strings/numbers.cc +916 -0
- data/third_party/abseil-cpp/absl/strings/numbers.h +263 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.cc +246 -0
- data/third_party/abseil-cpp/absl/strings/str_cat.h +408 -0
- data/third_party/abseil-cpp/absl/strings/str_join.h +293 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.cc +82 -0
- data/third_party/abseil-cpp/absl/strings/str_replace.h +219 -0
- data/third_party/abseil-cpp/absl/strings/str_split.cc +139 -0
- data/third_party/abseil-cpp/absl/strings/str_split.h +513 -0
- data/third_party/abseil-cpp/absl/strings/string_view.cc +235 -0
- data/third_party/abseil-cpp/absl/strings/string_view.h +615 -0
- data/third_party/abseil-cpp/absl/strings/strip.h +91 -0
- data/third_party/abseil-cpp/absl/strings/substitute.cc +171 -0
- data/third_party/abseil-cpp/absl/strings/substitute.h +693 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.cc +48 -0
- data/third_party/abseil-cpp/absl/types/bad_optional_access.h +78 -0
- data/third_party/abseil-cpp/absl/types/internal/optional.h +396 -0
- data/third_party/abseil-cpp/absl/types/internal/span.h +128 -0
- data/third_party/abseil-cpp/absl/types/optional.h +776 -0
- data/third_party/abseil-cpp/absl/types/span.h +713 -0
- data/third_party/abseil-cpp/absl/utility/utility.h +350 -0
- data/third_party/upb/upb/decode.c +4 -0
- data/third_party/upb/upb/port.c +0 -1
- data/third_party/upb/upb/port_def.inc +1 -3
- data/third_party/upb/upb/table.c +2 -1
- metadata +147 -43
- data/src/core/lib/json/json_common.h +0 -34
- data/src/core/lib/json/json_reader.h +0 -146
- data/src/core/lib/json/json_string.cc +0 -367
- data/src/core/lib/json/json_writer.h +0 -84
@@ -0,0 +1,89 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2019 gRPC authors.
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
//
|
16
|
+
|
17
|
+
#include <grpc/support/port_platform.h>
|
18
|
+
|
19
|
+
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h"
|
20
|
+
|
21
|
+
#include "src/core/lib/channel/channel_args.h"
|
22
|
+
#include "src/core/lib/gpr/useful.h"
|
23
|
+
|
24
|
+
// Channel arg key for the list of balancer addresses.
|
25
|
+
#define GRPC_ARG_GRPCLB_BALANCER_ADDRESSES "grpc.grpclb_balancer_addresses"
|
26
|
+
// Channel arg key for a string indicating an address's balancer name.
|
27
|
+
#define GRPC_ARG_ADDRESS_BALANCER_NAME "grpc.address_balancer_name"
|
28
|
+
|
29
|
+
namespace grpc_core {
|
30
|
+
|
31
|
+
namespace {
|
32
|
+
|
33
|
+
void* BalancerAddressesArgCopy(void* p) {
|
34
|
+
ServerAddressList* address_list = static_cast<ServerAddressList*>(p);
|
35
|
+
return new ServerAddressList(*address_list);
|
36
|
+
}
|
37
|
+
|
38
|
+
void BalancerAddressesArgDestroy(void* p) {
|
39
|
+
ServerAddressList* address_list = static_cast<ServerAddressList*>(p);
|
40
|
+
delete address_list;
|
41
|
+
}
|
42
|
+
|
43
|
+
int BalancerAddressesArgCmp(void* p, void* q) {
|
44
|
+
ServerAddressList* address_list1 = static_cast<ServerAddressList*>(p);
|
45
|
+
ServerAddressList* address_list2 = static_cast<ServerAddressList*>(q);
|
46
|
+
if (address_list1 == nullptr || address_list2 == nullptr) {
|
47
|
+
return GPR_ICMP(address_list1, address_list2);
|
48
|
+
}
|
49
|
+
if (address_list1->size() > address_list2->size()) return 1;
|
50
|
+
if (address_list1->size() < address_list2->size()) return -1;
|
51
|
+
for (size_t i = 0; i < address_list1->size(); ++i) {
|
52
|
+
int retval = (*address_list1)[i].Cmp((*address_list2)[i]);
|
53
|
+
if (retval != 0) return retval;
|
54
|
+
}
|
55
|
+
return 0;
|
56
|
+
}
|
57
|
+
|
58
|
+
const grpc_arg_pointer_vtable kBalancerAddressesArgVtable = {
|
59
|
+
BalancerAddressesArgCopy, BalancerAddressesArgDestroy,
|
60
|
+
BalancerAddressesArgCmp};
|
61
|
+
|
62
|
+
} // namespace
|
63
|
+
|
64
|
+
grpc_arg CreateGrpclbBalancerAddressesArg(
|
65
|
+
const ServerAddressList* address_list) {
|
66
|
+
return grpc_channel_arg_pointer_create(
|
67
|
+
const_cast<char*>(GRPC_ARG_GRPCLB_BALANCER_ADDRESSES),
|
68
|
+
const_cast<ServerAddressList*>(address_list),
|
69
|
+
&kBalancerAddressesArgVtable);
|
70
|
+
}
|
71
|
+
|
72
|
+
const ServerAddressList* FindGrpclbBalancerAddressesInChannelArgs(
|
73
|
+
const grpc_channel_args& args) {
|
74
|
+
return grpc_channel_args_find_pointer<const ServerAddressList>(
|
75
|
+
&args, const_cast<char*>(GRPC_ARG_GRPCLB_BALANCER_ADDRESSES));
|
76
|
+
}
|
77
|
+
|
78
|
+
grpc_arg CreateGrpclbBalancerNameArg(const char* balancer_name) {
|
79
|
+
return grpc_channel_arg_string_create(
|
80
|
+
const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME),
|
81
|
+
const_cast<char*>(balancer_name));
|
82
|
+
}
|
83
|
+
|
84
|
+
const char* FindGrpclbBalancerNameInChannelArgs(const grpc_channel_args& args) {
|
85
|
+
return grpc_channel_args_find_string(
|
86
|
+
&args, const_cast<char*>(GRPC_ARG_ADDRESS_BALANCER_NAME));
|
87
|
+
}
|
88
|
+
|
89
|
+
} // namespace grpc_core
|
@@ -0,0 +1,40 @@
|
|
1
|
+
//
|
2
|
+
// Copyright 2019 gRPC authors.
|
3
|
+
//
|
4
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
// you may not use this file except in compliance with the License.
|
6
|
+
// You may obtain a copy of the License at
|
7
|
+
//
|
8
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
//
|
10
|
+
// Unless required by applicable law or agreed to in writing, software
|
11
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
// See the License for the specific language governing permissions and
|
14
|
+
// limitations under the License.
|
15
|
+
//
|
16
|
+
|
17
|
+
#ifndef GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_BALANCER_ADDRESSES_H
|
18
|
+
#define GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_BALANCER_ADDRESSES_H
|
19
|
+
|
20
|
+
#include <grpc/support/port_platform.h>
|
21
|
+
|
22
|
+
#include <grpc/impl/codegen/grpc_types.h>
|
23
|
+
|
24
|
+
#include "src/core/ext/filters/client_channel/server_address.h"
|
25
|
+
|
26
|
+
namespace grpc_core {
|
27
|
+
|
28
|
+
grpc_arg CreateGrpclbBalancerAddressesArg(
|
29
|
+
const ServerAddressList* address_list);
|
30
|
+
const ServerAddressList* FindGrpclbBalancerAddressesInChannelArgs(
|
31
|
+
const grpc_channel_args& args);
|
32
|
+
|
33
|
+
grpc_arg CreateGrpclbBalancerNameArg(const char* balancer_name);
|
34
|
+
const char* FindGrpclbBalancerNameInChannelArgs(const grpc_channel_args& args);
|
35
|
+
|
36
|
+
} // namespace grpc_core
|
37
|
+
|
38
|
+
#endif /* \
|
39
|
+
GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_BALANCER_ADDRESSES_H \
|
40
|
+
*/
|
@@ -27,6 +27,7 @@
|
|
27
27
|
#include <grpc/support/string_util.h>
|
28
28
|
|
29
29
|
#include "src/core/ext/filters/client_channel/client_channel.h"
|
30
|
+
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_balancer_addresses.h"
|
30
31
|
#include "src/core/ext/filters/client_channel/server_address.h"
|
31
32
|
#include "src/core/lib/channel/channel_args.h"
|
32
33
|
#include "src/core/lib/gpr/string.h"
|
@@ -55,8 +56,8 @@ RefCountedPtr<TargetAuthorityTable> CreateTargetAuthorityTable(
|
|
55
56
|
grpc_sockaddr_to_string(&addr_str, &addresses[i].address(), true) > 0);
|
56
57
|
target_authority_entries[i].key = grpc_slice_from_copied_string(addr_str);
|
57
58
|
gpr_free(addr_str);
|
58
|
-
char* balancer_name =
|
59
|
-
addresses[i].args()
|
59
|
+
const char* balancer_name =
|
60
|
+
FindGrpclbBalancerNameInChannelArgs(*addresses[i].args());
|
60
61
|
target_authority_entries[i].value.reset(gpr_strdup(balancer_name));
|
61
62
|
}
|
62
63
|
RefCountedPtr<TargetAuthorityTable> target_authority_table =
|
@@ -28,16 +28,38 @@
|
|
28
28
|
|
29
29
|
namespace grpc_core {
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
bool GrpcLbServer::operator==(const GrpcLbServer& other) const {
|
32
|
+
if (ip_size != other.ip_size) return false;
|
33
|
+
int r = memcmp(ip_addr, other.ip_addr, ip_size);
|
34
|
+
if (r != 0) return false;
|
35
|
+
if (port != other.port) return false;
|
36
|
+
r = strncmp(load_balance_token, other.load_balance_token,
|
37
|
+
sizeof(load_balance_token));
|
38
|
+
if (r != 0) return false;
|
39
|
+
return drop == other.drop;
|
40
|
+
}
|
41
|
+
|
42
|
+
namespace {
|
43
|
+
|
44
|
+
grpc_slice grpc_grpclb_request_encode(
|
45
|
+
const grpc_lb_v1_LoadBalanceRequest* request, upb_arena* arena) {
|
46
|
+
size_t buf_length;
|
47
|
+
char* buf =
|
48
|
+
grpc_lb_v1_LoadBalanceRequest_serialize(request, arena, &buf_length);
|
49
|
+
return grpc_slice_from_copied_buffer(buf, buf_length);
|
50
|
+
}
|
51
|
+
|
52
|
+
} // namespace
|
53
|
+
|
54
|
+
grpc_slice GrpcLbRequestCreate(const char* lb_service_name, upb_arena* arena) {
|
55
|
+
grpc_lb_v1_LoadBalanceRequest* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
|
34
56
|
grpc_lb_v1_InitialLoadBalanceRequest* initial_request =
|
35
57
|
grpc_lb_v1_LoadBalanceRequest_mutable_initial_request(req, arena);
|
36
58
|
size_t name_len =
|
37
59
|
GPR_MIN(strlen(lb_service_name), GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH);
|
38
60
|
grpc_lb_v1_InitialLoadBalanceRequest_set_name(
|
39
61
|
initial_request, upb_strview_make(lb_service_name, name_len));
|
40
|
-
return req;
|
62
|
+
return grpc_grpclb_request_encode(req, arena);
|
41
63
|
}
|
42
64
|
|
43
65
|
namespace {
|
@@ -50,23 +72,18 @@ void google_protobuf_Timestamp_assign(google_protobuf_Timestamp* timestamp,
|
|
50
72
|
|
51
73
|
} // namespace
|
52
74
|
|
53
|
-
|
54
|
-
|
55
|
-
|
75
|
+
grpc_slice GrpcLbLoadReportRequestCreate(
|
76
|
+
int64_t num_calls_started, int64_t num_calls_finished,
|
77
|
+
int64_t num_calls_finished_with_client_failed_to_send,
|
78
|
+
int64_t num_calls_finished_known_received,
|
79
|
+
const GrpcLbClientStats::DroppedCallCounts* drop_token_counts,
|
80
|
+
upb_arena* arena) {
|
81
|
+
grpc_lb_v1_LoadBalanceRequest* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
|
56
82
|
grpc_lb_v1_ClientStats* req_stats =
|
57
83
|
grpc_lb_v1_LoadBalanceRequest_mutable_client_stats(req, arena);
|
58
84
|
google_protobuf_Timestamp_assign(
|
59
85
|
grpc_lb_v1_ClientStats_mutable_timestamp(req_stats, arena),
|
60
86
|
gpr_now(GPR_CLOCK_REALTIME));
|
61
|
-
|
62
|
-
int64_t num_calls_started;
|
63
|
-
int64_t num_calls_finished;
|
64
|
-
int64_t num_calls_finished_with_client_failed_to_send;
|
65
|
-
int64_t num_calls_finished_known_received;
|
66
|
-
std::unique_ptr<GrpcLbClientStats::DroppedCallCounts> drop_token_counts;
|
67
|
-
client_stats->Get(&num_calls_started, &num_calls_finished,
|
68
|
-
&num_calls_finished_with_client_failed_to_send,
|
69
|
-
&num_calls_finished_known_received, &drop_token_counts);
|
70
87
|
grpc_lb_v1_ClientStats_set_num_calls_started(req_stats, num_calls_started);
|
71
88
|
grpc_lb_v1_ClientStats_set_num_calls_finished(req_stats, num_calls_finished);
|
72
89
|
grpc_lb_v1_ClientStats_set_num_calls_finished_with_client_failed_to_send(
|
@@ -75,152 +92,102 @@ grpc_grpclb_request* grpc_grpclb_load_report_request_create(
|
|
75
92
|
req_stats, num_calls_finished_known_received);
|
76
93
|
if (drop_token_counts != nullptr) {
|
77
94
|
for (size_t i = 0; i < drop_token_counts->size(); ++i) {
|
78
|
-
GrpcLbClientStats::DropTokenCount& cur = (*drop_token_counts)[i];
|
95
|
+
const GrpcLbClientStats::DropTokenCount& cur = (*drop_token_counts)[i];
|
79
96
|
grpc_lb_v1_ClientStatsPerToken* cur_msg =
|
80
97
|
grpc_lb_v1_ClientStats_add_calls_finished_with_drop(req_stats, arena);
|
81
|
-
|
82
98
|
const size_t token_len = strlen(cur.token.get());
|
83
99
|
char* token = reinterpret_cast<char*>(upb_arena_malloc(arena, token_len));
|
84
100
|
memcpy(token, cur.token.get(), token_len);
|
85
|
-
|
86
101
|
grpc_lb_v1_ClientStatsPerToken_set_load_balance_token(
|
87
102
|
cur_msg, upb_strview_make(token, token_len));
|
88
103
|
grpc_lb_v1_ClientStatsPerToken_set_num_calls(cur_msg, cur.count);
|
89
104
|
}
|
90
105
|
}
|
91
|
-
return req;
|
106
|
+
return grpc_grpclb_request_encode(req, arena);
|
92
107
|
}
|
93
108
|
|
94
|
-
|
95
|
-
upb_arena* arena) {
|
96
|
-
size_t buf_length;
|
97
|
-
char* buf =
|
98
|
-
grpc_lb_v1_LoadBalanceRequest_serialize(request, arena, &buf_length);
|
99
|
-
return grpc_slice_from_copied_buffer(buf, buf_length);
|
100
|
-
}
|
101
|
-
|
102
|
-
const grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse(
|
103
|
-
const grpc_slice& encoded_grpc_grpclb_response, upb_arena* arena) {
|
104
|
-
grpc_lb_v1_LoadBalanceResponse* response =
|
105
|
-
grpc_lb_v1_LoadBalanceResponse_parse(
|
106
|
-
reinterpret_cast<const char*>(
|
107
|
-
GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
|
108
|
-
GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena);
|
109
|
-
if (response == nullptr) {
|
110
|
-
gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error");
|
111
|
-
return nullptr;
|
112
|
-
}
|
113
|
-
return grpc_lb_v1_LoadBalanceResponse_initial_response(response);
|
114
|
-
}
|
109
|
+
namespace {
|
115
110
|
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
grpc_lb_v1_LoadBalanceResponse* response =
|
120
|
-
grpc_lb_v1_LoadBalanceResponse_parse(
|
121
|
-
reinterpret_cast<const char*>(
|
122
|
-
GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
|
123
|
-
GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena.ptr());
|
124
|
-
if (response == nullptr) {
|
125
|
-
gpr_log(GPR_ERROR, "grpc_lb_v1_LoadBalanceResponse parse error");
|
126
|
-
return nullptr;
|
127
|
-
}
|
128
|
-
grpc_grpclb_serverlist* server_list = static_cast<grpc_grpclb_serverlist*>(
|
129
|
-
gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
|
130
|
-
// First pass: count number of servers.
|
111
|
+
bool ParseServerList(const grpc_lb_v1_LoadBalanceResponse& response,
|
112
|
+
std::vector<GrpcLbServer>* server_list) {
|
113
|
+
// Determine the number of servers.
|
131
114
|
const grpc_lb_v1_ServerList* server_list_msg =
|
132
|
-
grpc_lb_v1_LoadBalanceResponse_server_list(response);
|
115
|
+
grpc_lb_v1_LoadBalanceResponse_server_list(&response);
|
116
|
+
if (server_list_msg == nullptr) return false;
|
133
117
|
size_t server_count = 0;
|
134
|
-
const grpc_lb_v1_Server* const* servers =
|
135
|
-
|
136
|
-
|
137
|
-
}
|
138
|
-
// Second pass: populate servers.
|
118
|
+
const grpc_lb_v1_Server* const* servers =
|
119
|
+
grpc_lb_v1_ServerList_servers(server_list_msg, &server_count);
|
120
|
+
// Populate servers.
|
139
121
|
if (server_count > 0) {
|
140
|
-
server_list->
|
141
|
-
gpr_zalloc(sizeof(grpc_grpclb_server*) * server_count));
|
142
|
-
server_list->num_servers = server_count;
|
122
|
+
server_list->reserve(server_count);
|
143
123
|
for (size_t i = 0; i < server_count; ++i) {
|
144
|
-
|
145
|
-
static_cast<grpc_grpclb_server*>(
|
146
|
-
gpr_zalloc(sizeof(grpc_grpclb_server)));
|
124
|
+
GrpcLbServer& cur = *server_list->emplace(server_list->end());
|
147
125
|
upb_strview address = grpc_lb_v1_Server_ip_address(servers[i]);
|
148
126
|
if (address.size == 0) {
|
149
127
|
; // Nothing to do because cur->ip_address is an empty string.
|
150
128
|
} else if (address.size <= GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE) {
|
151
|
-
cur
|
152
|
-
memcpy(cur
|
129
|
+
cur.ip_size = static_cast<int32_t>(address.size);
|
130
|
+
memcpy(cur.ip_addr, address.data, address.size);
|
153
131
|
}
|
154
|
-
cur
|
132
|
+
cur.port = grpc_lb_v1_Server_port(servers[i]);
|
155
133
|
upb_strview token = grpc_lb_v1_Server_load_balance_token(servers[i]);
|
156
134
|
if (token.size == 0) {
|
157
135
|
; // Nothing to do because cur->load_balance_token is an empty string.
|
158
136
|
} else if (token.size <= GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE) {
|
159
|
-
memcpy(cur
|
137
|
+
memcpy(cur.load_balance_token, token.data, token.size);
|
160
138
|
} else {
|
161
139
|
gpr_log(GPR_ERROR,
|
162
140
|
"grpc_lb_v1_LoadBalanceResponse has too long token. len=%zu",
|
163
141
|
token.size);
|
164
142
|
}
|
165
|
-
cur
|
143
|
+
cur.drop = grpc_lb_v1_Server_drop(servers[i]);
|
166
144
|
}
|
167
145
|
}
|
168
|
-
return
|
146
|
+
return true;
|
169
147
|
}
|
170
148
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
gpr_free(serverlist->servers[i]);
|
177
|
-
}
|
178
|
-
gpr_free(serverlist->servers);
|
179
|
-
gpr_free(serverlist);
|
149
|
+
grpc_millis grpc_grpclb_duration_to_millis(
|
150
|
+
const google_protobuf_Duration* duration_pb) {
|
151
|
+
return static_cast<grpc_millis>(
|
152
|
+
(google_protobuf_Duration_seconds(duration_pb) * GPR_MS_PER_SEC) +
|
153
|
+
(google_protobuf_Duration_nanos(duration_pb) / GPR_NS_PER_MS));
|
180
154
|
}
|
181
155
|
|
182
|
-
|
183
|
-
const grpc_grpclb_serverlist* server_list) {
|
184
|
-
grpc_grpclb_serverlist* copy = static_cast<grpc_grpclb_serverlist*>(
|
185
|
-
gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
|
186
|
-
copy->num_servers = server_list->num_servers;
|
187
|
-
copy->servers = static_cast<grpc_grpclb_server**>(
|
188
|
-
gpr_malloc(sizeof(grpc_grpclb_server*) * server_list->num_servers));
|
189
|
-
for (size_t i = 0; i < server_list->num_servers; i++) {
|
190
|
-
copy->servers[i] = static_cast<grpc_grpclb_server*>(
|
191
|
-
gpr_malloc(sizeof(grpc_grpclb_server)));
|
192
|
-
memcpy(copy->servers[i], server_list->servers[i],
|
193
|
-
sizeof(grpc_grpclb_server));
|
194
|
-
}
|
195
|
-
return copy;
|
196
|
-
}
|
156
|
+
} // namespace
|
197
157
|
|
198
|
-
bool
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
158
|
+
bool GrpcLbResponseParse(const grpc_slice& encoded_grpc_grpclb_response,
|
159
|
+
upb_arena* arena, GrpcLbResponse* result) {
|
160
|
+
grpc_lb_v1_LoadBalanceResponse* response =
|
161
|
+
grpc_lb_v1_LoadBalanceResponse_parse(
|
162
|
+
reinterpret_cast<const char*>(
|
163
|
+
GRPC_SLICE_START_PTR(encoded_grpc_grpclb_response)),
|
164
|
+
GRPC_SLICE_LENGTH(encoded_grpc_grpclb_response), arena);
|
165
|
+
// Handle serverlist responses.
|
166
|
+
if (ParseServerList(*response, &result->serverlist)) {
|
167
|
+
result->type = result->SERVERLIST;
|
168
|
+
return true;
|
205
169
|
}
|
206
|
-
|
207
|
-
|
208
|
-
|
170
|
+
// Handle initial responses.
|
171
|
+
auto* initial_response =
|
172
|
+
grpc_lb_v1_LoadBalanceResponse_initial_response(response);
|
173
|
+
if (initial_response != nullptr) {
|
174
|
+
result->type = result->INITIAL;
|
175
|
+
const google_protobuf_Duration* client_stats_report_interval =
|
176
|
+
grpc_lb_v1_InitialLoadBalanceResponse_client_stats_report_interval(
|
177
|
+
initial_response);
|
178
|
+
if (client_stats_report_interval != nullptr) {
|
179
|
+
result->client_stats_report_interval =
|
180
|
+
grpc_grpclb_duration_to_millis(client_stats_report_interval);
|
209
181
|
}
|
182
|
+
return true;
|
210
183
|
}
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
grpc_millis grpc_grpclb_duration_to_millis(
|
220
|
-
const grpc_grpclb_duration* duration_pb) {
|
221
|
-
return static_cast<grpc_millis>(
|
222
|
-
google_protobuf_Duration_seconds(duration_pb) * GPR_MS_PER_SEC +
|
223
|
-
google_protobuf_Duration_nanos(duration_pb) / GPR_NS_PER_MS);
|
184
|
+
// Handle fallback.
|
185
|
+
if (grpc_lb_v1_LoadBalanceResponse_has_fallback_response(response)) {
|
186
|
+
result->type = result->FALLBACK;
|
187
|
+
return true;
|
188
|
+
}
|
189
|
+
// Unknown response type.
|
190
|
+
return false;
|
224
191
|
}
|
225
192
|
|
226
193
|
} // namespace grpc_core
|
@@ -21,6 +21,8 @@
|
|
21
21
|
|
22
22
|
#include <grpc/support/port_platform.h>
|
23
23
|
|
24
|
+
#include <vector>
|
25
|
+
|
24
26
|
#include <grpc/slice_buffer.h>
|
25
27
|
|
26
28
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_client_stats.h"
|
@@ -33,69 +35,38 @@
|
|
33
35
|
|
34
36
|
namespace grpc_core {
|
35
37
|
|
36
|
-
typedef grpc_lb_v1_LoadBalanceRequest grpc_grpclb_request;
|
37
|
-
typedef grpc_lb_v1_LoadBalanceResponse grpc_grpclb_response;
|
38
|
-
typedef grpc_lb_v1_InitialLoadBalanceResponse grpc_grpclb_initial_response;
|
39
|
-
typedef google_protobuf_Duration grpc_grpclb_duration;
|
40
|
-
typedef google_protobuf_Timestamp grpc_grpclb_timestamp;
|
41
|
-
|
42
|
-
typedef struct {
|
43
|
-
int32_t size;
|
44
|
-
char data[GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE];
|
45
|
-
} grpc_grpclb_server_ip_address;
|
46
|
-
|
47
38
|
// Contains server information. When the drop field is not true, use the other
|
48
39
|
// fields.
|
49
|
-
|
50
|
-
|
40
|
+
struct GrpcLbServer {
|
41
|
+
int32_t ip_size;
|
42
|
+
char ip_addr[GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE];
|
51
43
|
int32_t port;
|
52
44
|
char load_balance_token[GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE];
|
53
45
|
bool drop;
|
54
|
-
} grpc_grpclb_server;
|
55
|
-
|
56
|
-
typedef struct {
|
57
|
-
grpc_grpclb_server** servers;
|
58
|
-
size_t num_servers;
|
59
|
-
} grpc_grpclb_serverlist;
|
60
|
-
|
61
|
-
/**
|
62
|
-
* Create a request for a gRPC LB service under \a lb_service_name.
|
63
|
-
* \a lb_service_name should be alive when returned request is being used.
|
64
|
-
*/
|
65
|
-
grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name,
|
66
|
-
upb_arena* arena);
|
67
|
-
grpc_grpclb_request* grpc_grpclb_load_report_request_create(
|
68
|
-
grpc_core::GrpcLbClientStats* client_stats, upb_arena* arena);
|
69
|
-
|
70
|
-
/** Protocol Buffers v3-encode \a request */
|
71
|
-
grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request,
|
72
|
-
upb_arena* arena);
|
73
|
-
|
74
|
-
/** Parse (ie, decode) the bytes in \a encoded_grpc_grpclb_response as a \a
|
75
|
-
* grpc_grpclb_initial_response */
|
76
|
-
const grpc_grpclb_initial_response* grpc_grpclb_initial_response_parse(
|
77
|
-
const grpc_slice& encoded_grpc_grpclb_response, upb_arena* arena);
|
78
|
-
|
79
|
-
/** Parse the list of servers from an encoded \a grpc_grpclb_response */
|
80
|
-
grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist(
|
81
|
-
const grpc_slice& encoded_grpc_grpclb_response);
|
82
|
-
|
83
|
-
/** Return a copy of \a sl. The caller is responsible for calling \a
|
84
|
-
* grpc_grpclb_destroy_serverlist on the returned copy. */
|
85
|
-
grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy(
|
86
|
-
const grpc_grpclb_serverlist* sl);
|
87
|
-
|
88
|
-
bool grpc_grpclb_serverlist_equals(const grpc_grpclb_serverlist* lhs,
|
89
|
-
const grpc_grpclb_serverlist* rhs);
|
90
|
-
|
91
|
-
bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs,
|
92
|
-
const grpc_grpclb_server* rhs);
|
93
|
-
|
94
|
-
/** Destroy \a serverlist */
|
95
|
-
void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist);
|
96
46
|
|
97
|
-
|
98
|
-
|
47
|
+
bool operator==(const GrpcLbServer& other) const;
|
48
|
+
};
|
49
|
+
|
50
|
+
struct GrpcLbResponse {
|
51
|
+
enum { INITIAL, SERVERLIST, FALLBACK } type;
|
52
|
+
grpc_millis client_stats_report_interval = 0;
|
53
|
+
std::vector<GrpcLbServer> serverlist;
|
54
|
+
};
|
55
|
+
|
56
|
+
// Creates a serialized grpclb request.
|
57
|
+
grpc_slice GrpcLbRequestCreate(const char* lb_service_name, upb_arena* arena);
|
58
|
+
|
59
|
+
// Creates a serialized grpclb load report request.
|
60
|
+
grpc_slice GrpcLbLoadReportRequestCreate(
|
61
|
+
int64_t num_calls_started, int64_t num_calls_finished,
|
62
|
+
int64_t num_calls_finished_with_client_failed_to_send,
|
63
|
+
int64_t num_calls_finished_known_received,
|
64
|
+
const GrpcLbClientStats::DroppedCallCounts* drop_token_counts,
|
65
|
+
upb_arena* arena);
|
66
|
+
|
67
|
+
// Deserialize a grpclb response.
|
68
|
+
bool GrpcLbResponseParse(const grpc_slice& serialized_response,
|
69
|
+
upb_arena* arena, GrpcLbResponse* response);
|
99
70
|
|
100
71
|
} // namespace grpc_core
|
101
72
|
|