grpc 1.23.0 → 1.24.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 +765 -485
- data/include/grpc/grpc.h +3 -1
- data/include/grpc/grpc_security.h +20 -4
- data/include/grpc/impl/codegen/grpc_types.h +6 -5
- data/include/grpc/impl/codegen/port_platform.h +25 -0
- data/src/core/ext/filters/client_channel/backend_metric.cc +78 -0
- data/src/core/ext/filters/client_channel/backend_metric.h +36 -0
- data/src/core/ext/filters/client_channel/channel_connectivity.cc +16 -2
- data/src/core/ext/filters/client_channel/client_channel.cc +325 -267
- data/src/core/ext/filters/client_channel/client_channel_factory.h +0 -4
- data/src/core/ext/filters/client_channel/health/health_check_client.cc +23 -32
- data/src/core/ext/filters/client_channel/http_proxy.cc +7 -3
- data/src/core/ext/filters/client_channel/lb_policy.cc +1 -1
- data/src/core/ext/filters/client_channel/lb_policy.h +58 -34
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc +46 -50
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h +9 -2
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc +35 -17
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.cc +130 -215
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h +34 -21
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds.cc +1120 -802
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h +8 -2
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc +33 -12
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc +151 -40
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.h +184 -26
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc +389 -245
- data/src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.h +98 -60
- data/src/core/ext/filters/client_channel/lb_policy_registry.cc +6 -1
- data/src/core/ext/filters/client_channel/resolver/xds/xds_resolver.cc +89 -0
- data/src/core/ext/filters/client_channel/resolving_lb_policy.cc +3 -8
- data/src/core/ext/filters/client_channel/server_address.cc +1 -3
- data/src/core/ext/filters/client_channel/server_address.h +1 -1
- data/src/core/ext/filters/client_channel/subchannel.h +2 -1
- data/src/core/ext/filters/client_idle/client_idle_filter.cc +207 -29
- data/src/core/ext/filters/http/client/http_client_filter.cc +10 -8
- data/src/core/ext/filters/http/client_authority_filter.cc +1 -1
- data/src/core/ext/filters/http/message_compress/message_compress_filter.cc +10 -7
- data/src/core/ext/filters/http/server/http_server_filter.cc +52 -26
- data/src/core/ext/transport/chttp2/client/insecure/channel_create.cc +23 -20
- data/src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc +24 -21
- data/src/core/ext/transport/chttp2/server/chttp2_server.cc +1 -1
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.cc +37 -24
- data/src/core/ext/transport/chttp2/transport/chttp2_transport.h +1 -0
- data/src/core/ext/transport/chttp2/transport/hpack_encoder.cc +237 -191
- data/src/core/ext/transport/chttp2/transport/hpack_parser.cc +29 -27
- data/src/core/ext/transport/chttp2/transport/hpack_parser.h +1 -1
- data/src/core/ext/transport/chttp2/transport/hpack_table.cc +19 -4
- data/src/core/ext/transport/chttp2/transport/hpack_table.h +13 -4
- data/src/core/ext/transport/chttp2/transport/incoming_metadata.cc +2 -1
- data/src/core/ext/transport/chttp2/transport/internal.h +0 -2
- data/src/core/ext/transport/chttp2/transport/parsing.cc +99 -71
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.c +222 -0
- data/src/core/ext/upb-generated/envoy/api/v2/auth/cert.upb.h +818 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.c +314 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cds.upb.h +1142 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.c +53 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/circuit_breaker.upb.h +158 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.c +34 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/filter.upb.h +69 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.c +49 -0
- data/src/core/ext/upb-generated/envoy/api/v2/cluster/outlier_detection.upb.h +240 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.c +110 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/address.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.c +235 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/base.upb.h +661 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.c +84 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/config_source.upb.h +274 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.c +175 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/grpc_service.upb.h +572 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.c +150 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/health_check.upb.h +596 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.c +35 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/http_uri.upb.h +80 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.c +95 -0
- data/src/core/ext/upb-generated/envoy/api/v2/core/protocol.upb.h +308 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.c +128 -0
- data/src/core/ext/upb-generated/envoy/api/v2/discovery.upb.h +392 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.c +91 -0
- data/src/core/ext/upb-generated/envoy/api/v2/eds.upb.h +236 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.c +88 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/endpoint.upb.h +258 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.c +111 -0
- data/src/core/ext/upb-generated/envoy/api/v2/endpoint/load_report.upb.h +324 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.c +23 -0
- data/src/core/ext/upb-generated/envoy/service/discovery/v2/ads.upb.h +50 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.c +52 -0
- data/src/core/ext/upb-generated/envoy/service/load_stats/v2/lrs.upb.h +130 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/percent.upb.h +87 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.c +39 -0
- data/src/core/ext/upb-generated/envoy/type/range.upb.h +85 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.c +17 -0
- data/src/core/ext/upb-generated/gogoproto/gogo.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.c +18 -0
- data/src/core/ext/upb-generated/google/api/annotations.upb.h +30 -0
- data/src/core/ext/upb-generated/google/api/http.upb.c +66 -0
- data/src/core/ext/upb-generated/google/api/http.upb.h +190 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/any.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.c +485 -0
- data/src/core/ext/upb-generated/google/protobuf/descriptor.upb.h +1690 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/duration.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.c +22 -0
- data/src/core/ext/upb-generated/google/protobuf/empty.upb.h +50 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.c +79 -0
- data/src/core/ext/upb-generated/google/protobuf/struct.upb.h +215 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.c +27 -0
- data/src/core/ext/upb-generated/google/protobuf/timestamp.upb.h +58 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.c +106 -0
- data/src/core/ext/upb-generated/google/protobuf/wrappers.upb.h +238 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.c +33 -0
- data/src/core/ext/upb-generated/google/rpc/status.upb.h +74 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.c +49 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/altscontext.upb.h +126 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.c +209 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/handshaker.upb.h +681 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.c +42 -0
- data/src/core/ext/upb-generated/src/proto/grpc/gcp/transport_security_common.upb.h +109 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.c +36 -0
- data/src/core/ext/upb-generated/src/proto/grpc/health/v1/health.upb.h +84 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.c +133 -0
- data/src/core/ext/upb-generated/src/proto/grpc/lb/v1/load_balancer.upb.h +359 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.c +58 -0
- data/src/core/ext/upb-generated/udpa/data/orca/v1/orca_load_report.upb.h +144 -0
- data/src/core/ext/upb-generated/validate/validate.upb.c +443 -0
- data/src/core/ext/upb-generated/validate/validate.upb.h +2037 -0
- data/src/core/lib/channel/channel_args.cc +21 -0
- data/src/core/lib/channel/channel_args.h +16 -2
- data/src/core/lib/channel/channel_stack.h +2 -1
- data/src/core/lib/channel/channelz.cc +54 -56
- data/src/core/lib/channel/channelz.h +29 -12
- data/src/core/lib/compression/compression.cc +2 -1
- data/src/core/lib/compression/compression_internal.h +8 -0
- data/src/core/lib/gpr/log_linux.cc +2 -2
- data/src/core/lib/gpr/log_posix.cc +2 -2
- data/src/core/lib/gpr/time_precise.cc +123 -36
- data/src/core/lib/gpr/time_precise.h +37 -0
- data/src/core/lib/gprpp/abstract.h +10 -0
- data/src/core/lib/gprpp/atomic.h +4 -0
- data/src/core/lib/gprpp/inlined_vector.h +20 -4
- data/src/core/lib/gprpp/map.h +109 -6
- data/src/core/lib/gprpp/memory.h +6 -0
- data/src/core/lib/gprpp/ref_counted_ptr.h +2 -0
- data/src/core/lib/iomgr/ev_epollex_linux.cc +29 -54
- data/src/core/lib/iomgr/exec_ctx.cc +27 -17
- data/src/core/lib/iomgr/exec_ctx.h +3 -0
- data/src/core/lib/iomgr/sockaddr_utils.cc +1 -3
- data/src/core/lib/iomgr/tcp_posix.cc +16 -25
- data/src/core/lib/iomgr/tcp_server_custom.cc +1 -1
- data/src/core/lib/iomgr/timer_manager.cc +8 -1
- data/src/core/lib/iomgr/timer_manager.h +2 -0
- data/src/core/lib/security/credentials/credentials.h +8 -2
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.cc +23 -0
- data/src/core/lib/security/credentials/tls/grpc_tls_credentials_options.h +3 -0
- data/src/core/lib/security/credentials/tls/spiffe_credentials.cc +3 -3
- data/src/core/lib/security/security_connector/ssl_utils.cc +1 -12
- data/src/core/lib/security/security_connector/ssl_utils.h +10 -6
- data/src/core/lib/security/security_connector/ssl_utils_config.cc +32 -0
- data/src/core/lib/security/security_connector/ssl_utils_config.h +30 -0
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.cc +161 -49
- data/src/core/lib/security/security_connector/tls/spiffe_security_connector.h +34 -1
- data/src/core/lib/slice/slice_intern.cc +17 -9
- data/src/core/lib/slice/slice_internal.h +34 -7
- data/src/core/lib/slice/slice_utils.h +7 -3
- data/src/core/lib/surface/call.cc +97 -57
- data/src/core/lib/surface/channel.cc +2 -2
- data/src/core/lib/surface/completion_queue.cc +10 -16
- data/src/core/lib/surface/init.cc +3 -0
- data/src/core/lib/surface/server.cc +11 -14
- data/src/core/lib/surface/validate_metadata.cc +4 -0
- data/src/core/lib/surface/version.cc +2 -2
- data/src/core/lib/transport/metadata.cc +4 -4
- data/src/core/lib/transport/metadata_batch.cc +72 -16
- data/src/core/lib/transport/metadata_batch.h +38 -0
- data/src/core/lib/transport/static_metadata.cc +814 -1023
- data/src/core/lib/transport/static_metadata.h +271 -213
- data/src/core/lib/transport/transport.h +12 -0
- data/src/core/plugin_registry/grpc_plugin_registry.cc +4 -0
- data/src/core/tsi/alts/handshaker/alts_handshaker_client.cc +104 -76
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.cc +34 -16
- data/src/core/tsi/alts/handshaker/alts_tsi_handshaker.h +2 -2
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.cc +10 -6
- data/src/core/tsi/alts/handshaker/alts_tsi_utils.h +4 -3
- data/src/core/tsi/alts/handshaker/transport_security_common_api.cc +74 -48
- data/src/core/tsi/alts/handshaker/transport_security_common_api.h +34 -26
- data/src/core/tsi/ssl_transport_security.cc +14 -6
- data/src/core/tsi/ssl_transport_security.h +4 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +5 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +1 -42
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +4 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +6 -0
- data/src/ruby/lib/grpc.rb +2 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/errors.rb +4 -7
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +9 -4
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +1 -1
- data/src/ruby/spec/errors_spec.rb +1 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +34 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +53 -29
- data/third_party/upb/upb/decode.c +604 -0
- data/third_party/upb/upb/decode.h +21 -0
- data/third_party/upb/upb/encode.c +378 -0
- data/third_party/upb/upb/encode.h +21 -0
- data/third_party/upb/upb/generated_util.h +105 -0
- data/third_party/upb/upb/msg.c +111 -0
- data/third_party/upb/upb/msg.h +69 -0
- data/third_party/upb/upb/port.c +27 -0
- data/third_party/upb/upb/port_def.inc +152 -0
- data/third_party/upb/upb/port_undef.inc +21 -0
- data/third_party/upb/upb/table.c +911 -0
- data/third_party/upb/upb/table.int.h +507 -0
- data/third_party/upb/upb/upb.c +261 -0
- data/third_party/upb/upb/upb.h +364 -0
- metadata +129 -50
- data/src/core/ext/filters/client_channel/health/health.pb.c +0 -23
- data/src/core/ext/filters/client_channel/health/health.pb.h +0 -73
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/duration.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.c +0 -19
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/google/protobuf/timestamp.pb.h +0 -54
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.c +0 -89
- data/src/core/ext/filters/client_channel/lb_policy/grpclb/proto/grpc/lb/v1/load_balancer.pb.h +0 -164
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.cc +0 -520
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api.h +0 -323
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.cc +0 -145
- data/src/core/tsi/alts/handshaker/alts_handshaker_service_api_util.h +0 -149
- data/src/core/tsi/alts/handshaker/altscontext.pb.c +0 -47
- data/src/core/tsi/alts/handshaker/altscontext.pb.h +0 -63
- data/src/core/tsi/alts/handshaker/handshaker.pb.c +0 -122
- data/src/core/tsi/alts/handshaker/handshaker.pb.h +0 -254
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.c +0 -49
- data/src/core/tsi/alts/handshaker/transport_security_common.pb.h +0 -78
- data/third_party/nanopb/pb.h +0 -579
- data/third_party/nanopb/pb_common.c +0 -97
- data/third_party/nanopb/pb_common.h +0 -42
- data/third_party/nanopb/pb_decode.c +0 -1347
- data/third_party/nanopb/pb_decode.h +0 -149
- data/third_party/nanopb/pb_encode.c +0 -696
- data/third_party/nanopb/pb_encode.h +0 -154
@@ -25,14 +25,21 @@
|
|
25
25
|
|
26
26
|
#include "src/core/ext/filters/client_channel/server_address.h"
|
27
27
|
|
28
|
+
namespace grpc_core {
|
29
|
+
|
28
30
|
/// Makes any necessary modifications to \a args for use in the grpclb
|
29
31
|
/// balancer channel.
|
30
32
|
///
|
31
33
|
/// Takes ownership of \a args.
|
32
34
|
///
|
33
35
|
/// Caller takes ownership of the returned args.
|
34
|
-
grpc_channel_args*
|
35
|
-
const
|
36
|
+
grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
|
37
|
+
const ServerAddressList& addresses, grpc_channel_args* args);
|
38
|
+
|
39
|
+
grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
|
40
|
+
const grpc_channel_args& args);
|
41
|
+
|
42
|
+
} // namespace grpc_core
|
36
43
|
|
37
44
|
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H \
|
38
45
|
*/
|
@@ -22,6 +22,7 @@
|
|
22
22
|
|
23
23
|
#include <string.h>
|
24
24
|
|
25
|
+
#include <grpc/grpc_security.h>
|
25
26
|
#include <grpc/support/alloc.h>
|
26
27
|
#include <grpc/support/string_util.h>
|
27
28
|
|
@@ -35,6 +36,7 @@
|
|
35
36
|
#include "src/core/lib/slice/slice_internal.h"
|
36
37
|
|
37
38
|
namespace grpc_core {
|
39
|
+
|
38
40
|
namespace {
|
39
41
|
|
40
42
|
int BalancerNameCmp(const grpc_core::UniquePtr<char>& a,
|
@@ -65,37 +67,53 @@ RefCountedPtr<TargetAuthorityTable> CreateTargetAuthorityTable(
|
|
65
67
|
}
|
66
68
|
|
67
69
|
} // namespace
|
68
|
-
} // namespace grpc_core
|
69
70
|
|
70
|
-
grpc_channel_args*
|
71
|
-
const
|
72
|
-
const char
|
73
|
-
|
74
|
-
grpc_arg args_to_add[2];
|
75
|
-
size_t num_args_to_add = 0;
|
71
|
+
grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
|
72
|
+
const ServerAddressList& addresses, grpc_channel_args* args) {
|
73
|
+
InlinedVector<const char*, 1> args_to_remove;
|
74
|
+
InlinedVector<grpc_arg, 2> args_to_add;
|
76
75
|
// Add arg for targets info table.
|
77
|
-
|
78
|
-
|
79
|
-
args_to_add
|
80
|
-
|
81
|
-
target_authority_table.get());
|
76
|
+
RefCountedPtr<TargetAuthorityTable> target_authority_table =
|
77
|
+
CreateTargetAuthorityTable(addresses);
|
78
|
+
args_to_add.emplace_back(
|
79
|
+
CreateTargetAuthorityTableChannelArg(target_authority_table.get()));
|
82
80
|
// Substitute the channel credentials with a version without call
|
83
81
|
// credentials: the load balancer is not necessarily trusted to handle
|
84
82
|
// bearer token credentials.
|
85
83
|
grpc_channel_credentials* channel_credentials =
|
86
84
|
grpc_channel_credentials_find_in_args(args);
|
87
|
-
|
85
|
+
RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
|
88
86
|
if (channel_credentials != nullptr) {
|
89
87
|
creds_sans_call_creds =
|
90
88
|
channel_credentials->duplicate_without_call_credentials();
|
91
89
|
GPR_ASSERT(creds_sans_call_creds != nullptr);
|
92
|
-
args_to_remove
|
93
|
-
args_to_add
|
94
|
-
grpc_channel_credentials_to_arg(creds_sans_call_creds.get());
|
90
|
+
args_to_remove.emplace_back(GRPC_ARG_CHANNEL_CREDENTIALS);
|
91
|
+
args_to_add.emplace_back(
|
92
|
+
grpc_channel_credentials_to_arg(creds_sans_call_creds.get()));
|
95
93
|
}
|
96
94
|
grpc_channel_args* result = grpc_channel_args_copy_and_add_and_remove(
|
97
|
-
args, args_to_remove,
|
95
|
+
args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
|
96
|
+
args_to_add.size());
|
98
97
|
// Clean up.
|
99
98
|
grpc_channel_args_destroy(args);
|
100
99
|
return result;
|
101
100
|
}
|
101
|
+
|
102
|
+
grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
|
103
|
+
const grpc_channel_args& args) {
|
104
|
+
grpc_channel_credentials* creds =
|
105
|
+
grpc_channel_credentials_find_in_args(&args);
|
106
|
+
if (creds == nullptr) {
|
107
|
+
// Build with security but parent channel is insecure.
|
108
|
+
return grpc_insecure_channel_create(target_uri, &args, nullptr);
|
109
|
+
}
|
110
|
+
const char* arg_to_remove = GRPC_ARG_CHANNEL_CREDENTIALS;
|
111
|
+
grpc_channel_args* new_args =
|
112
|
+
grpc_channel_args_copy_and_remove(&args, &arg_to_remove, 1);
|
113
|
+
grpc_channel* channel =
|
114
|
+
grpc_secure_channel_create(creds, target_uri, new_args, nullptr);
|
115
|
+
grpc_channel_args_destroy(new_args);
|
116
|
+
return channel;
|
117
|
+
}
|
118
|
+
|
119
|
+
} // namespace grpc_core
|
@@ -18,213 +18,154 @@
|
|
18
18
|
|
19
19
|
#include <grpc/support/port_platform.h>
|
20
20
|
|
21
|
-
#include "pb_decode.h"
|
22
|
-
#include "pb_encode.h"
|
23
21
|
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/load_balancer_api.h"
|
22
|
+
#include "src/core/lib/gpr/useful.h"
|
24
23
|
|
25
|
-
#include
|
26
|
-
|
27
|
-
/* invoked once for every Server in ServerList */
|
28
|
-
static bool count_serverlist(pb_istream_t* stream, const pb_field_t* field,
|
29
|
-
void** arg) {
|
30
|
-
grpc_grpclb_serverlist* sl = static_cast<grpc_grpclb_serverlist*>(*arg);
|
31
|
-
grpc_grpclb_server server;
|
32
|
-
if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, &server))) {
|
33
|
-
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
|
34
|
-
return false;
|
35
|
-
}
|
36
|
-
++sl->num_servers;
|
37
|
-
return true;
|
38
|
-
}
|
39
|
-
|
40
|
-
typedef struct decode_serverlist_arg {
|
41
|
-
/* The decoding callback is invoked once per server in serverlist. Remember
|
42
|
-
* which index of the serverlist are we currently decoding */
|
43
|
-
size_t decoding_idx;
|
44
|
-
/* The decoded serverlist */
|
45
|
-
grpc_grpclb_serverlist* serverlist;
|
46
|
-
} decode_serverlist_arg;
|
24
|
+
#include "google/protobuf/duration.upb.h"
|
25
|
+
#include "google/protobuf/timestamp.upb.h"
|
47
26
|
|
48
|
-
|
49
|
-
static bool decode_serverlist(pb_istream_t* stream, const pb_field_t* field,
|
50
|
-
void** arg) {
|
51
|
-
decode_serverlist_arg* dec_arg = static_cast<decode_serverlist_arg*>(*arg);
|
52
|
-
GPR_ASSERT(dec_arg->serverlist->num_servers >= dec_arg->decoding_idx);
|
53
|
-
grpc_grpclb_server* server =
|
54
|
-
static_cast<grpc_grpclb_server*>(gpr_zalloc(sizeof(grpc_grpclb_server)));
|
55
|
-
if (GPR_UNLIKELY(!pb_decode(stream, grpc_lb_v1_Server_fields, server))) {
|
56
|
-
gpr_free(server);
|
57
|
-
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(stream));
|
58
|
-
return false;
|
59
|
-
}
|
60
|
-
dec_arg->serverlist->servers[dec_arg->decoding_idx++] = server;
|
61
|
-
return true;
|
62
|
-
}
|
27
|
+
#include <grpc/support/alloc.h>
|
63
28
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
req
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH));
|
29
|
+
namespace grpc_core {
|
30
|
+
|
31
|
+
grpc_grpclb_request* grpc_grpclb_request_create(const char* lb_service_name,
|
32
|
+
upb_arena* arena) {
|
33
|
+
grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
|
34
|
+
grpc_lb_v1_InitialLoadBalanceRequest* initial_request =
|
35
|
+
grpc_lb_v1_LoadBalanceRequest_mutable_initial_request(req, arena);
|
36
|
+
size_t name_len =
|
37
|
+
GPR_MIN(strlen(lb_service_name), GRPC_GRPCLB_SERVICE_NAME_MAX_LENGTH);
|
38
|
+
grpc_lb_v1_InitialLoadBalanceRequest_set_name(
|
39
|
+
initial_request, upb_strview_make(lb_service_name, name_len));
|
76
40
|
return req;
|
77
41
|
}
|
78
42
|
|
79
|
-
|
80
|
-
grpc_grpclb_timestamp* timestamp_pb) {
|
81
|
-
timestamp_pb->has_seconds = true;
|
82
|
-
timestamp_pb->seconds = timestamp.tv_sec;
|
83
|
-
timestamp_pb->has_nanos = true;
|
84
|
-
timestamp_pb->nanos = timestamp.tv_nsec;
|
85
|
-
}
|
43
|
+
namespace {
|
86
44
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
return pb_encode_string(stream, reinterpret_cast<uint8_t*>(str), strlen(str));
|
45
|
+
void google_protobuf_Timestamp_assign(google_protobuf_Timestamp* timestamp,
|
46
|
+
const gpr_timespec& value) {
|
47
|
+
google_protobuf_Timestamp_set_seconds(timestamp, value.tv_sec);
|
48
|
+
google_protobuf_Timestamp_set_nanos(timestamp, value.tv_nsec);
|
92
49
|
}
|
93
50
|
|
94
|
-
|
95
|
-
void* const* arg) {
|
96
|
-
grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries =
|
97
|
-
static_cast<grpc_core::GrpcLbClientStats::DroppedCallCounts*>(*arg);
|
98
|
-
if (drop_entries == nullptr) return true;
|
99
|
-
for (size_t i = 0; i < drop_entries->size(); ++i) {
|
100
|
-
if (!pb_encode_tag_for_field(stream, field)) return false;
|
101
|
-
grpc_lb_v1_ClientStatsPerToken drop_message;
|
102
|
-
drop_message.load_balance_token.funcs.encode = encode_string;
|
103
|
-
drop_message.load_balance_token.arg = (*drop_entries)[i].token.get();
|
104
|
-
drop_message.has_num_calls = true;
|
105
|
-
drop_message.num_calls = (*drop_entries)[i].count;
|
106
|
-
if (!pb_encode_submessage(stream, grpc_lb_v1_ClientStatsPerToken_fields,
|
107
|
-
&drop_message)) {
|
108
|
-
return false;
|
109
|
-
}
|
110
|
-
}
|
111
|
-
return true;
|
112
|
-
}
|
51
|
+
} // namespace
|
113
52
|
|
114
53
|
grpc_grpclb_request* grpc_grpclb_load_report_request_create(
|
115
|
-
|
116
|
-
grpc_grpclb_request* req =
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
54
|
+
GrpcLbClientStats* client_stats, upb_arena* arena) {
|
55
|
+
grpc_grpclb_request* req = grpc_lb_v1_LoadBalanceRequest_new(arena);
|
56
|
+
grpc_lb_v1_ClientStats* req_stats =
|
57
|
+
grpc_lb_v1_LoadBalanceRequest_mutable_client_stats(req, arena);
|
58
|
+
google_protobuf_Timestamp_assign(
|
59
|
+
grpc_lb_v1_ClientStats_mutable_timestamp(req_stats, arena),
|
60
|
+
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
|
+
UniquePtr<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
|
+
grpc_lb_v1_ClientStats_set_num_calls_started(req_stats, num_calls_started);
|
71
|
+
grpc_lb_v1_ClientStats_set_num_calls_finished(req_stats, num_calls_finished);
|
72
|
+
grpc_lb_v1_ClientStats_set_num_calls_finished_with_client_failed_to_send(
|
73
|
+
req_stats, num_calls_finished_with_client_failed_to_send);
|
74
|
+
grpc_lb_v1_ClientStats_set_num_calls_finished_known_received(
|
75
|
+
req_stats, num_calls_finished_known_received);
|
76
|
+
if (drop_token_counts != nullptr) {
|
77
|
+
for (size_t i = 0; i < drop_token_counts->size(); ++i) {
|
78
|
+
GrpcLbClientStats::DropTokenCount& cur = (*drop_token_counts)[i];
|
79
|
+
grpc_lb_v1_ClientStatsPerToken* cur_msg =
|
80
|
+
grpc_lb_v1_ClientStats_add_calls_finished_with_drop(req_stats, arena);
|
81
|
+
|
82
|
+
const size_t token_len = strlen(cur.token.get());
|
83
|
+
char* token = reinterpret_cast<char*>(upb_arena_malloc(arena, token_len));
|
84
|
+
memcpy(token, cur.token.get(), token_len);
|
85
|
+
|
86
|
+
grpc_lb_v1_ClientStatsPerToken_set_load_balance_token(
|
87
|
+
cur_msg, upb_strview_make(token, token_len));
|
88
|
+
grpc_lb_v1_ClientStatsPerToken_set_num_calls(cur_msg, cur.count);
|
89
|
+
}
|
90
|
+
}
|
136
91
|
return req;
|
137
92
|
}
|
138
93
|
|
139
|
-
grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
pb_encode(&sizestream, grpc_lb_v1_LoadBalanceRequest_fields, request);
|
146
|
-
encoded_length = sizestream.bytes_written;
|
147
|
-
|
148
|
-
slice = GRPC_SLICE_MALLOC(encoded_length);
|
149
|
-
outputstream =
|
150
|
-
pb_ostream_from_buffer(GRPC_SLICE_START_PTR(slice), encoded_length);
|
151
|
-
GPR_ASSERT(pb_encode(&outputstream, grpc_lb_v1_LoadBalanceRequest_fields,
|
152
|
-
request) != 0);
|
153
|
-
return slice;
|
154
|
-
}
|
155
|
-
|
156
|
-
void grpc_grpclb_request_destroy(grpc_grpclb_request* request) {
|
157
|
-
if (request->has_client_stats) {
|
158
|
-
grpc_core::GrpcLbClientStats::DroppedCallCounts* drop_entries =
|
159
|
-
static_cast<grpc_core::GrpcLbClientStats::DroppedCallCounts*>(
|
160
|
-
request->client_stats.calls_finished_with_drop.arg);
|
161
|
-
grpc_core::Delete(drop_entries);
|
162
|
-
}
|
163
|
-
gpr_free(request);
|
94
|
+
grpc_slice grpc_grpclb_request_encode(const grpc_grpclb_request* request,
|
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);
|
164
100
|
}
|
165
101
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
!pb_decode(&stream, grpc_lb_v1_LoadBalanceResponse_fields, &res))) {
|
176
|
-
gpr_log(GPR_ERROR, "nanopb error: %s", PB_GET_ERROR(&stream));
|
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");
|
177
111
|
return nullptr;
|
178
112
|
}
|
179
|
-
|
180
|
-
if (!res.has_initial_response) return nullptr;
|
181
|
-
|
182
|
-
grpc_grpclb_initial_response* initial_res =
|
183
|
-
static_cast<grpc_grpclb_initial_response*>(
|
184
|
-
gpr_malloc(sizeof(grpc_grpclb_initial_response)));
|
185
|
-
memcpy(initial_res, &res.initial_response,
|
186
|
-
sizeof(grpc_grpclb_initial_response));
|
187
|
-
|
188
|
-
return initial_res;
|
113
|
+
return grpc_lb_v1_LoadBalanceResponse_initial_response(response);
|
189
114
|
}
|
190
115
|
|
191
116
|
grpc_grpclb_serverlist* grpc_grpclb_response_parse_serverlist(
|
192
117
|
const grpc_slice& encoded_grpc_grpclb_response) {
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
118
|
+
upb::Arena arena;
|
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*>(
|
198
129
|
gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
|
199
|
-
grpc_grpclb_response res;
|
200
|
-
memset(&res, 0, sizeof(grpc_grpclb_response));
|
201
130
|
// First pass: count number of servers.
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
return nullptr;
|
131
|
+
const grpc_lb_v1_ServerList* server_list_msg =
|
132
|
+
grpc_lb_v1_LoadBalanceResponse_server_list(response);
|
133
|
+
size_t server_count = 0;
|
134
|
+
const grpc_lb_v1_Server* const* servers = nullptr;
|
135
|
+
if (server_list_msg != nullptr) {
|
136
|
+
servers = grpc_lb_v1_ServerList_servers(server_list_msg, &server_count);
|
209
137
|
}
|
210
138
|
// Second pass: populate servers.
|
211
|
-
if (
|
212
|
-
|
213
|
-
gpr_zalloc(sizeof(grpc_grpclb_server*) *
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
139
|
+
if (server_count > 0) {
|
140
|
+
server_list->servers = static_cast<grpc_grpclb_server**>(
|
141
|
+
gpr_zalloc(sizeof(grpc_grpclb_server*) * server_count));
|
142
|
+
server_list->num_servers = server_count;
|
143
|
+
for (size_t i = 0; i < server_count; ++i) {
|
144
|
+
grpc_grpclb_server* cur = server_list->servers[i] =
|
145
|
+
static_cast<grpc_grpclb_server*>(
|
146
|
+
gpr_zalloc(sizeof(grpc_grpclb_server)));
|
147
|
+
upb_strview address = grpc_lb_v1_Server_ip_address(servers[i]);
|
148
|
+
if (address.size == 0) {
|
149
|
+
; // Nothing to do because cur->ip_address is an empty string.
|
150
|
+
} else if (address.size <= GRPC_GRPCLB_SERVER_IP_ADDRESS_MAX_SIZE) {
|
151
|
+
cur->ip_address.size = static_cast<int32_t>(address.size);
|
152
|
+
memcpy(cur->ip_address.data, address.data, address.size);
|
153
|
+
}
|
154
|
+
cur->port = grpc_lb_v1_Server_port(servers[i]);
|
155
|
+
upb_strview token = grpc_lb_v1_Server_load_balance_token(servers[i]);
|
156
|
+
if (token.size == 0) {
|
157
|
+
; // Nothing to do because cur->load_balance_token is an empty string.
|
158
|
+
} else if (token.size <= GRPC_GRPCLB_SERVER_LOAD_BALANCE_TOKEN_MAX_SIZE) {
|
159
|
+
memcpy(cur->load_balance_token, token.data, token.size);
|
160
|
+
} else {
|
161
|
+
gpr_log(GPR_ERROR,
|
162
|
+
"grpc_lb_v1_LoadBalanceResponse has too long token. len=%zu",
|
163
|
+
token.size);
|
164
|
+
}
|
165
|
+
cur->drop = grpc_lb_v1_Server_drop(servers[i]);
|
225
166
|
}
|
226
167
|
}
|
227
|
-
return
|
168
|
+
return server_list;
|
228
169
|
}
|
229
170
|
|
230
171
|
void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) {
|
@@ -239,16 +180,17 @@ void grpc_grpclb_destroy_serverlist(grpc_grpclb_serverlist* serverlist) {
|
|
239
180
|
}
|
240
181
|
|
241
182
|
grpc_grpclb_serverlist* grpc_grpclb_serverlist_copy(
|
242
|
-
const grpc_grpclb_serverlist*
|
183
|
+
const grpc_grpclb_serverlist* server_list) {
|
243
184
|
grpc_grpclb_serverlist* copy = static_cast<grpc_grpclb_serverlist*>(
|
244
185
|
gpr_zalloc(sizeof(grpc_grpclb_serverlist)));
|
245
|
-
copy->num_servers =
|
186
|
+
copy->num_servers = server_list->num_servers;
|
246
187
|
copy->servers = static_cast<grpc_grpclb_server**>(
|
247
|
-
gpr_malloc(sizeof(grpc_grpclb_server*) *
|
248
|
-
for (size_t i = 0; i <
|
188
|
+
gpr_malloc(sizeof(grpc_grpclb_server*) * server_list->num_servers));
|
189
|
+
for (size_t i = 0; i < server_list->num_servers; i++) {
|
249
190
|
copy->servers[i] = static_cast<grpc_grpclb_server*>(
|
250
191
|
gpr_malloc(sizeof(grpc_grpclb_server)));
|
251
|
-
memcpy(copy->servers[i],
|
192
|
+
memcpy(copy->servers[i], server_list->servers[i],
|
193
|
+
sizeof(grpc_grpclb_server));
|
252
194
|
}
|
253
195
|
return copy;
|
254
196
|
}
|
@@ -274,38 +216,11 @@ bool grpc_grpclb_server_equals(const grpc_grpclb_server* lhs,
|
|
274
216
|
return memcmp(lhs, rhs, sizeof(grpc_grpclb_server)) == 0;
|
275
217
|
}
|
276
218
|
|
277
|
-
|
278
|
-
|
279
|
-
GPR_ASSERT(lhs && rhs);
|
280
|
-
if (lhs->has_seconds && rhs->has_seconds) {
|
281
|
-
if (lhs->seconds < rhs->seconds) return -1;
|
282
|
-
if (lhs->seconds > rhs->seconds) return 1;
|
283
|
-
} else if (lhs->has_seconds) {
|
284
|
-
return 1;
|
285
|
-
} else if (rhs->has_seconds) {
|
286
|
-
return -1;
|
287
|
-
}
|
288
|
-
|
289
|
-
GPR_ASSERT(lhs->seconds == rhs->seconds);
|
290
|
-
if (lhs->has_nanos && rhs->has_nanos) {
|
291
|
-
if (lhs->nanos < rhs->nanos) return -1;
|
292
|
-
if (lhs->nanos > rhs->nanos) return 1;
|
293
|
-
} else if (lhs->has_nanos) {
|
294
|
-
return 1;
|
295
|
-
} else if (rhs->has_nanos) {
|
296
|
-
return -1;
|
297
|
-
}
|
298
|
-
|
299
|
-
return 0;
|
300
|
-
}
|
301
|
-
|
302
|
-
grpc_millis grpc_grpclb_duration_to_millis(grpc_grpclb_duration* duration_pb) {
|
219
|
+
grpc_millis grpc_grpclb_duration_to_millis(
|
220
|
+
const grpc_grpclb_duration* duration_pb) {
|
303
221
|
return static_cast<grpc_millis>(
|
304
|
-
(duration_pb
|
305
|
-
(duration_pb
|
222
|
+
google_protobuf_Duration_seconds(duration_pb) * GPR_MS_PER_SEC +
|
223
|
+
google_protobuf_Duration_nanos(duration_pb) / GPR_NS_PER_MS);
|
306
224
|
}
|
307
225
|
|
308
|
-
|
309
|
-
grpc_grpclb_initial_response* response) {
|
310
|
-
gpr_free(response);
|
311
|
-
}
|
226
|
+
} // namespace grpc_core
|