Merge remote-tracking branch 'upstream/master' into spiffe1

pull/19778/head
Matthew Stevenson 6 years ago
commit 3b5973c187
  1. 2
      .github/ISSUE_TEMPLATE/bug_report.md
  2. 2
      .github/ISSUE_TEMPLATE/cleanup_request.md
  3. 2
      .github/ISSUE_TEMPLATE/feature_request.md
  4. 2
      .github/pull_request_template.md
  5. 9
      BUILD
  6. 1
      Rakefile
  7. 3
      bazel/grpc_build_system.bzl
  8. 9
      include/grpc/impl/codegen/port_platform.h
  9. 5
      src/core/ext/filters/client_channel/client_channel.cc
  10. 4
      src/core/ext/filters/client_channel/client_channel_factory.h
  11. 6
      src/core/ext/filters/client_channel/lb_policy.h
  12. 18
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb.cc
  13. 15
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.cc
  14. 11
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h
  15. 52
      src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel_secure.cc
  16. 29
      src/core/ext/filters/client_channel/lb_policy/xds/xds.cc
  17. 14
      src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.cc
  18. 10
      src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h
  19. 45
      src/core/ext/filters/client_channel/lb_policy/xds/xds_channel_secure.cc
  20. 8
      src/core/ext/filters/client_channel/lb_policy/xds/xds_client_stats.cc
  21. 8
      src/core/ext/filters/client_channel/lb_policy/xds/xds_load_balancer_api.cc
  22. 7
      src/core/ext/filters/client_channel/resolving_lb_policy.cc
  23. 43
      src/core/ext/transport/chttp2/client/insecure/channel_create.cc
  24. 45
      src/core/ext/transport/chttp2/client/secure/secure_channel_create.cc
  25. 7
      src/core/ext/transport/chttp2/transport/chttp2_transport.cc
  26. 6
      src/core/lib/gpr/log_linux.cc
  27. 4
      src/core/lib/gpr/log_posix.cc
  28. 10
      src/core/lib/gprpp/abstract.h
  29. 16
      src/core/lib/gprpp/map.h
  30. 4
      src/core/lib/iomgr/ev_epollex_linux.cc
  31. 2
      src/core/lib/iomgr/tcp_server_custom.cc
  32. 10
      src/core/lib/security/credentials/credentials.h
  33. 2
      src/core/lib/slice/slice_utils.h
  34. 2
      src/cpp/client/secure_credentials.cc
  35. 2
      src/csharp/experimental/README.md
  36. 1
      src/objective-c/BUILD
  37. 9
      src/objective-c/ProtoRPC/ProtoService.h
  38. 3
      src/python/grpcio_testing/grpc_testing/_server/_servicer_context.py
  39. 5
      src/python/grpcio_tests/tests/unit/_local_credentials_test.py
  40. 2
      test/core/end2end/tests/max_connection_age.cc
  41. 4
      test/core/end2end/tests/shutdown_finishes_calls.cc
  42. 9
      test/core/gprpp/map_test.cc
  43. 5
      test/core/util/test_lb_policies.cc
  44. 10
      test/cpp/end2end/generic_end2end_test.cc
  45. 4
      test/cpp/microbenchmarks/bm_call_create.cc
  46. 1
      tools/internal_ci/linux/grpc_bazel_build_in_docker.sh
  47. 6
      tools/run_tests/run_tests_matrix.py

@ -2,7 +2,7 @@
name: Report a bug
about: Create a report to help us improve
labels: kind/bug, priority/P2
assignees: AspirinSJL
assignees: mhaidrygoog
---

@ -2,7 +2,7 @@
name: Request a cleanup
about: Suggest a cleanup in our repository
labels: kind/internal cleanup
assignees: AspirinSJL
assignees: mhaidrygoog
---

@ -2,7 +2,7 @@
name: Request a feature
about: Suggest an idea for this project
labels: kind/enhancement
assignees: AspirinSJL
assignees: mhaidrygoog
---

@ -8,4 +8,4 @@ If you know who should review your pull request, please remove the mentioning be
-->
@AspirinSJL
@mhaidrygoog

@ -73,6 +73,11 @@ config_setting(
values = {"cpu": "darwin"},
)
config_setting(
name = "grpc_use_cpp_std_lib",
values = {"define": "GRPC_USE_CPP_STD_LIB=1"},
)
# This should be updated along with build.yaml
g_stands_for = "ganges"
@ -1219,6 +1224,7 @@ grpc_cc_library(
"grpc_client_channel",
"grpc_lb_upb",
"grpc_resolver_fake",
"grpc_transport_chttp2_client_insecure",
],
)
@ -1245,6 +1251,7 @@ grpc_cc_library(
"grpc_lb_upb",
"grpc_resolver_fake",
"grpc_secure",
"grpc_transport_chttp2_client_secure",
],
)
@ -1268,6 +1275,7 @@ grpc_cc_library(
"grpc_base",
"grpc_client_channel",
"grpc_resolver_fake",
"grpc_transport_chttp2_client_insecure",
],
)
@ -1292,6 +1300,7 @@ grpc_cc_library(
"grpc_client_channel",
"grpc_resolver_fake",
"grpc_secure",
"grpc_transport_chttp2_client_secure",
],
)

@ -105,6 +105,7 @@ task 'dlls' do
env_comp = "CC=#{opt[:cross]}-gcc "
env_comp += "CXX=#{opt[:cross]}-g++ "
env_comp += "LD=#{opt[:cross]}-gcc "
env_comp += "LDXX=#{opt[:cross]}-g++ "
docker_for_windows "gem update --system --no-document && #{env} #{env_comp} make -j #{out} && #{opt[:cross]}-strip -x -S #{out} && cp #{out} #{opt[:out]}"
end

@ -98,6 +98,9 @@ def grpc_cc_library(
"//:grpc_allow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=1"],
"//:grpc_disallow_exceptions": ["GRPC_ALLOW_EXCEPTIONS=0"],
"//conditions:default": [],
}) + select({
"//:grpc_use_cpp_std_lib": ["GRPC_USE_CPP_STD_LIB=1"],
"//conditions:default": [],
}),
hdrs = hdrs + public_hdrs,
deps = deps + _get_external_deps(external_deps),

@ -27,6 +27,15 @@
* - some syscalls to be made directly
*/
/*
* Defines GRPC_USE_CPP_STD_LIB to use standard C++ library instead of
* in-house library if possible. (e.g. std::map)
*/
#ifndef GRPC_USE_CPP_STD_LIB
/* Default value will be 1 once all tests become green. */
#define GRPC_USE_CPP_STD_LIB 0
#endif
/* Get windows.h included everywhere (we need it) */
#if defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32)
#ifndef WIN32_LEAN_AND_MEAN

@ -1318,11 +1318,6 @@ class ChannelData::ClientChannelControlHelper
chand_, subchannel, std::move(health_check_service_name));
}
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override {
return chand_->client_channel_factory_->CreateChannel(target, &args);
}
void UpdateState(
grpc_connectivity_state state,
UniquePtr<LoadBalancingPolicy::SubchannelPicker> picker) override {

@ -36,10 +36,6 @@ class ClientChannelFactory {
virtual Subchannel* CreateSubchannel(const grpc_channel_args* args)
GRPC_ABSTRACT;
// Creates a channel for the specified target with the specified args.
virtual grpc_channel* CreateChannel(
const char* target, const grpc_channel_args* args) GRPC_ABSTRACT;
// Returns a channel arg containing the specified factory.
static grpc_arg CreateChannelArg(ClientChannelFactory* factory);

@ -220,12 +220,6 @@ class LoadBalancingPolicy : public InternallyRefCounted<LoadBalancingPolicy> {
virtual RefCountedPtr<SubchannelInterface> CreateSubchannel(
const grpc_channel_args& args) GRPC_ABSTRACT;
/// Creates a channel with the specified target and channel args.
/// This can be used in cases where the LB policy needs to create a
/// channel for its own use (e.g., to talk to an external load balancer).
virtual grpc_channel* CreateChannel(
const char* target, const grpc_channel_args& args) GRPC_ABSTRACT;
/// Sets the connectivity state and returns a new picker to be used
/// by the client channel.
virtual void UpdateState(grpc_connectivity_state state,

@ -293,8 +293,6 @@ class GrpcLb : public LoadBalancingPolicy {
RefCountedPtr<SubchannelInterface> CreateSubchannel(
const grpc_channel_args& args) override;
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override;
void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) override;
void RequestReresolution() override;
@ -652,15 +650,6 @@ RefCountedPtr<SubchannelInterface> GrpcLb::Helper::CreateSubchannel(
return parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* GrpcLb::Helper::CreateChannel(const char* target,
const grpc_channel_args& args) {
if (parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return parent_->channel_control_helper()->CreateChannel(target, args);
}
void GrpcLb::Helper::UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) {
if (parent_->shutting_down_) return;
@ -1276,7 +1265,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
// the LB channel.
GRPC_ARG_FAKE_RESOLVER_RESPONSE_GENERATOR,
// The LB channel should use the authority indicated by the target
// authority table (see \a grpc_lb_policy_grpclb_modify_lb_channel_args),
// authority table (see \a ModifyGrpclbBalancerChannelArgs),
// as opposed to the authority from the parent channel.
GRPC_ARG_DEFAULT_AUTHORITY,
// Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the LB channel should be
@ -1312,7 +1301,7 @@ grpc_channel_args* BuildBalancerChannelArgs(
args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
args_to_add.size());
// Make any necessary modifications for security.
return grpc_lb_policy_grpclb_modify_lb_channel_args(addresses, new_args);
return ModifyGrpclbBalancerChannelArgs(addresses, new_args);
}
//
@ -1488,8 +1477,7 @@ void GrpcLb::ProcessAddressesAndChannelArgsLocked(
if (lb_channel_ == nullptr) {
char* uri_str;
gpr_asprintf(&uri_str, "fake:///%s", server_name_);
lb_channel_ =
channel_control_helper()->CreateChannel(uri_str, *lb_channel_args);
lb_channel_ = CreateGrpclbBalancerChannel(uri_str, *lb_channel_args);
GPR_ASSERT(lb_channel_ != nullptr);
gpr_free(uri_str);
}

@ -18,9 +18,20 @@
#include <grpc/support/port_platform.h>
#include <grpc/grpc.h>
#include "src/core/ext/filters/client_channel/lb_policy/grpclb/grpclb_channel.h"
grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
const grpc_core::ServerAddressList& addresses, grpc_channel_args* args) {
namespace grpc_core {
grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
const ServerAddressList& addresses, grpc_channel_args* args) {
return args;
}
grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
const grpc_channel_args& args) {
return grpc_insecure_channel_create(target_uri, &args, nullptr);
}
} // namespace grpc_core

@ -25,14 +25,21 @@
#include "src/core/ext/filters/client_channel/server_address.h"
namespace grpc_core {
/// Makes any necessary modifications to \a args for use in the grpclb
/// balancer channel.
///
/// Takes ownership of \a args.
///
/// Caller takes ownership of the returned args.
grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
const grpc_core::ServerAddressList& addresses, grpc_channel_args* args);
grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
const ServerAddressList& addresses, grpc_channel_args* args);
grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
const grpc_channel_args& args);
} // namespace grpc_core
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_GRPCLB_GRPCLB_CHANNEL_H \
*/

@ -22,6 +22,7 @@
#include <string.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
@ -35,6 +36,7 @@
#include "src/core/lib/slice/slice_internal.h"
namespace grpc_core {
namespace {
int BalancerNameCmp(const grpc_core::UniquePtr<char>& a,
@ -65,37 +67,53 @@ RefCountedPtr<TargetAuthorityTable> CreateTargetAuthorityTable(
}
} // namespace
} // namespace grpc_core
grpc_channel_args* grpc_lb_policy_grpclb_modify_lb_channel_args(
const grpc_core::ServerAddressList& addresses, grpc_channel_args* args) {
const char* args_to_remove[1];
size_t num_args_to_remove = 0;
grpc_arg args_to_add[2];
size_t num_args_to_add = 0;
grpc_channel_args* ModifyGrpclbBalancerChannelArgs(
const ServerAddressList& addresses, grpc_channel_args* args) {
InlinedVector<const char*, 1> args_to_remove;
InlinedVector<grpc_arg, 2> args_to_add;
// Add arg for targets info table.
grpc_core::RefCountedPtr<grpc_core::TargetAuthorityTable>
target_authority_table = grpc_core::CreateTargetAuthorityTable(addresses);
args_to_add[num_args_to_add++] =
grpc_core::CreateTargetAuthorityTableChannelArg(
target_authority_table.get());
RefCountedPtr<TargetAuthorityTable> target_authority_table =
CreateTargetAuthorityTable(addresses);
args_to_add.emplace_back(
CreateTargetAuthorityTableChannelArg(target_authority_table.get()));
// Substitute the channel credentials with a version without call
// credentials: the load balancer is not necessarily trusted to handle
// bearer token credentials.
grpc_channel_credentials* channel_credentials =
grpc_channel_credentials_find_in_args(args);
grpc_core::RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
if (channel_credentials != nullptr) {
creds_sans_call_creds =
channel_credentials->duplicate_without_call_credentials();
GPR_ASSERT(creds_sans_call_creds != nullptr);
args_to_remove[num_args_to_remove++] = GRPC_ARG_CHANNEL_CREDENTIALS;
args_to_add[num_args_to_add++] =
grpc_channel_credentials_to_arg(creds_sans_call_creds.get());
args_to_remove.emplace_back(GRPC_ARG_CHANNEL_CREDENTIALS);
args_to_add.emplace_back(
grpc_channel_credentials_to_arg(creds_sans_call_creds.get()));
}
grpc_channel_args* result = grpc_channel_args_copy_and_add_and_remove(
args, args_to_remove, num_args_to_remove, args_to_add, num_args_to_add);
args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
args_to_add.size());
// Clean up.
grpc_channel_args_destroy(args);
return result;
}
grpc_channel* CreateGrpclbBalancerChannel(const char* target_uri,
const grpc_channel_args& args) {
grpc_channel_credentials* creds =
grpc_channel_credentials_find_in_args(&args);
if (creds == nullptr) {
// Build with security but parent channel is insecure.
return grpc_insecure_channel_create(target_uri, &args, nullptr);
}
const char* arg_to_remove = GRPC_ARG_CHANNEL_CREDENTIALS;
grpc_channel_args* new_args =
grpc_channel_args_copy_and_remove(&args, &arg_to_remove, 1);
grpc_channel* channel =
grpc_secure_channel_create(creds, target_uri, new_args, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
}
} // namespace grpc_core

@ -431,8 +431,6 @@ class XdsLb : public LoadBalancingPolicy {
RefCountedPtr<SubchannelInterface> CreateSubchannel(
const grpc_channel_args& args) override;
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override;
void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) override;
void RequestReresolution() override;
@ -482,8 +480,6 @@ class XdsLb : public LoadBalancingPolicy {
RefCountedPtr<SubchannelInterface> CreateSubchannel(
const grpc_channel_args& args) override;
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override;
void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) override;
void RequestReresolution() override;
@ -723,15 +719,6 @@ RefCountedPtr<SubchannelInterface> XdsLb::FallbackHelper::CreateSubchannel(
return parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* XdsLb::FallbackHelper::CreateChannel(
const char* target, const grpc_channel_args& args) {
if (parent_->shutting_down_ ||
(!CalledByPendingFallback() && !CalledByCurrentFallback())) {
return nullptr;
}
return parent_->channel_control_helper()->CreateChannel(target, args);
}
void XdsLb::FallbackHelper::UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) {
if (parent_->shutting_down_) return;
@ -793,8 +780,7 @@ XdsLb::LbChannelState::LbChannelState(RefCountedPtr<XdsLb> xdslb_policy,
xdslb_policy_(std::move(xdslb_policy)) {
GRPC_CLOSURE_INIT(&on_connectivity_changed_, OnConnectivityChangedLocked,
this, grpc_combiner_scheduler(xdslb_policy_->combiner()));
channel_ = xdslb_policy_->channel_control_helper()->CreateChannel(
balancer_name, args);
channel_ = CreateXdsBalancerChannel(balancer_name, args);
GPR_ASSERT(channel_ != nullptr);
eds_calld_.reset(New<RetryableLbCall<EdsCallState>>(
Ref(DEBUG_LOCATION, "LbChannelState+eds")));
@ -1672,7 +1658,7 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) {
// factory will re-add this arg with the right value.
GRPC_ARG_SERVER_URI,
// The LB channel should use the authority indicated by the target
// authority table (see \a grpc_lb_policy_xds_modify_lb_channel_args),
// authority table (see \a ModifyXdsBalancerChannelArgs),
// as opposed to the authority from the parent channel.
GRPC_ARG_DEFAULT_AUTHORITY,
// Just as for \a GRPC_ARG_DEFAULT_AUTHORITY, the LB channel should be
@ -1703,7 +1689,7 @@ grpc_channel_args* BuildBalancerChannelArgs(const grpc_channel_args* args) {
args, args_to_remove, GPR_ARRAY_SIZE(args_to_remove), args_to_add.data(),
args_to_add.size());
// Make any necessary modifications for security.
return grpc_lb_policy_xds_modify_lb_channel_args(new_args);
return ModifyXdsBalancerChannelArgs(new_args);
}
//
@ -2440,15 +2426,6 @@ XdsLb::LocalityMap::LocalityEntry::Helper::CreateSubchannel(
return entry_->parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* XdsLb::LocalityMap::LocalityEntry::Helper::CreateChannel(
const char* target, const grpc_channel_args& args) {
if (entry_->parent_->shutting_down_ ||
(!CalledByPendingChild() && !CalledByCurrentChild())) {
return nullptr;
}
return entry_->parent_->channel_control_helper()->CreateChannel(target, args);
}
void XdsLb::LocalityMap::LocalityEntry::Helper::UpdateState(
grpc_connectivity_state state, UniquePtr<SubchannelPicker> picker) {
if (entry_->parent_->shutting_down_) return;

@ -18,9 +18,19 @@
#include <grpc/support/port_platform.h>
#include <grpc/grpc.h>
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h"
grpc_channel_args* grpc_lb_policy_xds_modify_lb_channel_args(
grpc_channel_args* args) {
namespace grpc_core {
grpc_channel_args* ModifyXdsBalancerChannelArgs(grpc_channel_args* args) {
return args;
}
grpc_channel* CreateXdsBalancerChannel(const char* target_uri,
const grpc_channel_args& args) {
return grpc_insecure_channel_create(target_uri, &args, nullptr);
}
} // namespace grpc_core

@ -23,14 +23,20 @@
#include <grpc/impl/codegen/grpc_types.h>
namespace grpc_core {
/// Makes any necessary modifications to \a args for use in the xds
/// balancer channel.
///
/// Takes ownership of \a args.
///
/// Caller takes ownership of the returned args.
grpc_channel_args* grpc_lb_policy_xds_modify_lb_channel_args(
grpc_channel_args* args);
grpc_channel_args* ModifyXdsBalancerChannelArgs(grpc_channel_args* args);
grpc_channel* CreateXdsBalancerChannel(const char* target_uri,
const grpc_channel_args& args);
} // namespace grpc_core
#endif /* GRPC_CORE_EXT_FILTERS_CLIENT_CHANNEL_LB_POLICY_XDS_XDS_CHANNEL_H \
*/

@ -20,9 +20,11 @@
#include "src/core/ext/filters/client_channel/lb_policy/xds/xds_channel.h"
#include <string.h>
#include <grpc/grpc_security.h>
#include <grpc/support/alloc.h>
#include <grpc/support/string_util.h>
#include <string.h>
#include "src/core/ext/filters/client_channel/client_channel.h"
#include "src/core/ext/filters/client_channel/server_address.h"
@ -33,29 +35,48 @@
#include "src/core/lib/security/transport/target_authority_table.h"
#include "src/core/lib/slice/slice_internal.h"
grpc_channel_args* grpc_lb_policy_xds_modify_lb_channel_args(
grpc_channel_args* args) {
const char* args_to_remove[1];
size_t num_args_to_remove = 0;
grpc_arg args_to_add[2];
size_t num_args_to_add = 0;
namespace grpc_core {
grpc_channel_args* ModifyXdsBalancerChannelArgs(grpc_channel_args* args) {
InlinedVector<const char*, 1> args_to_remove;
InlinedVector<grpc_arg, 2> args_to_add;
// Substitute the channel credentials with a version without call
// credentials: the load balancer is not necessarily trusted to handle
// bearer token credentials.
grpc_channel_credentials* channel_credentials =
grpc_channel_credentials_find_in_args(args);
grpc_core::RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
RefCountedPtr<grpc_channel_credentials> creds_sans_call_creds;
if (channel_credentials != nullptr) {
creds_sans_call_creds =
channel_credentials->duplicate_without_call_credentials();
GPR_ASSERT(creds_sans_call_creds != nullptr);
args_to_remove[num_args_to_remove++] = GRPC_ARG_CHANNEL_CREDENTIALS;
args_to_add[num_args_to_add++] =
grpc_channel_credentials_to_arg(creds_sans_call_creds.get());
args_to_remove.emplace_back(GRPC_ARG_CHANNEL_CREDENTIALS);
args_to_add.emplace_back(
grpc_channel_credentials_to_arg(creds_sans_call_creds.get()));
}
grpc_channel_args* result = grpc_channel_args_copy_and_add_and_remove(
args, args_to_remove, num_args_to_remove, args_to_add, num_args_to_add);
args, args_to_remove.data(), args_to_remove.size(), args_to_add.data(),
args_to_add.size());
// Clean up.
grpc_channel_args_destroy(args);
return result;
}
grpc_channel* CreateXdsBalancerChannel(const char* target_uri,
const grpc_channel_args& args) {
grpc_channel_credentials* creds =
grpc_channel_credentials_find_in_args(&args);
if (creds == nullptr) {
// Build with security but parent channel is insecure.
return grpc_insecure_channel_create(target_uri, &args, nullptr);
}
const char* arg_to_remove = GRPC_ARG_CHANNEL_CREDENTIALS;
grpc_channel_args* new_args =
grpc_channel_args_copy_and_remove(&args, &arg_to_remove, 1);
grpc_channel* channel =
grpc_secure_channel_create(creds, target_uri, new_args, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
}
} // namespace grpc_core

@ -143,7 +143,15 @@ XdsClientStats::Snapshot XdsClientStats::GetSnapshotAndReset() {
}
{
MutexLock lock(&dropped_requests_mu_);
#if GRPC_USE_CPP_STD_LIB
// This is a workaround for the case where some compilers cannot build
// move-assignment of map with non-copyable but movable key.
// https://stackoverflow.com/questions/36475497
std::swap(snapshot.dropped_requests, dropped_requests_);
dropped_requests_.clear();
#else
snapshot.dropped_requests = std::move(dropped_requests_);
#endif
}
return snapshot;
}

@ -315,7 +315,15 @@ grpc_slice XdsLrsRequestCreateAndEncode(const char* server_name) {
namespace {
void LocalityStatsPopulate(envoy_api_v2_endpoint_UpstreamLocalityStats* output,
#if GRPC_USE_CPP_STD_LIB
// TODO(veblush): Clean up this
// This is to address the difference between
// std::map and Map. #else block will be gone
// once using stdlib is enabled by default.
Pair<const RefCountedPtr<XdsLocalityName>,
#else
Pair<RefCountedPtr<XdsLocalityName>,
#endif
XdsClientStats::LocalityStats::Snapshot>& input,
upb_arena* arena) {
// Set sub_zone.

@ -113,13 +113,6 @@ class ResolvingLoadBalancingPolicy::ResolvingControlHelper
return parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override {
if (parent_->resolver_ == nullptr) return nullptr; // Shutting down.
if (!CalledByCurrentChild() && !CalledByPendingChild()) return nullptr;
return parent_->channel_control_helper()->CreateChannel(target, args);
}
void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) override {
if (parent_->resolver_ == nullptr) return; // Shutting down.

@ -46,27 +46,30 @@ class Chttp2InsecureClientChannelFactory : public ClientChannelFactory {
grpc_channel_args_destroy(new_args);
return s;
}
};
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args* args) override {
if (target == nullptr) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr;
}
// Add channel arg containing the server URI.
UniquePtr<char> canonical_target =
ResolverRegistry::AddDefaultPrefixIfNeeded(target);
grpc_arg arg = grpc_channel_arg_string_create(
const_cast<char*>(GRPC_ARG_SERVER_URI), canonical_target.get());
const char* to_remove[] = {GRPC_ARG_SERVER_URI};
grpc_channel_args* new_args =
grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
grpc_channel* channel =
grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
namespace {
grpc_channel* CreateChannel(const char* target, const grpc_channel_args* args) {
if (target == nullptr) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr;
}
};
// Add channel arg containing the server URI.
UniquePtr<char> canonical_target =
ResolverRegistry::AddDefaultPrefixIfNeeded(target);
grpc_arg arg = grpc_channel_arg_string_create(
const_cast<char*>(GRPC_ARG_SERVER_URI), canonical_target.get());
const char* to_remove[] = {GRPC_ARG_SERVER_URI};
grpc_channel_args* new_args =
grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
grpc_channel* channel =
grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
}
} // namespace
} // namespace grpc_core
@ -98,7 +101,7 @@ grpc_channel* grpc_insecure_channel_create(const char* target,
grpc_arg arg = grpc_core::ClientChannelFactory::CreateChannelArg(g_factory);
grpc_channel_args* new_args = grpc_channel_args_copy_and_add(args, &arg, 1);
// Create channel.
grpc_channel* channel = g_factory->CreateChannel(target, new_args);
grpc_channel* channel = grpc_core::CreateChannel(target, new_args);
// Clean up.
grpc_channel_args_destroy(new_args);
return channel != nullptr ? channel

@ -58,26 +58,6 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory {
return s;
}
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args* args) override {
if (target == nullptr) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr;
}
// Add channel arg containing the server URI.
UniquePtr<char> canonical_target =
ResolverRegistry::AddDefaultPrefixIfNeeded(target);
grpc_arg arg = grpc_channel_arg_string_create(
const_cast<char*>(GRPC_ARG_SERVER_URI), canonical_target.get());
const char* to_remove[] = {GRPC_ARG_SERVER_URI};
grpc_channel_args* new_args =
grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
grpc_channel* channel =
grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
}
private:
static grpc_channel_args* GetSecureNamingChannelArgs(
const grpc_channel_args* args) {
@ -170,6 +150,29 @@ class Chttp2SecureClientChannelFactory : public ClientChannelFactory {
}
};
namespace {
grpc_channel* CreateChannel(const char* target, const grpc_channel_args* args) {
if (target == nullptr) {
gpr_log(GPR_ERROR, "cannot create channel with NULL target name");
return nullptr;
}
// Add channel arg containing the server URI.
UniquePtr<char> canonical_target =
ResolverRegistry::AddDefaultPrefixIfNeeded(target);
grpc_arg arg = grpc_channel_arg_string_create(
const_cast<char*>(GRPC_ARG_SERVER_URI), canonical_target.get());
const char* to_remove[] = {GRPC_ARG_SERVER_URI};
grpc_channel_args* new_args =
grpc_channel_args_copy_and_add_and_remove(args, to_remove, 1, &arg, 1);
grpc_channel* channel =
grpc_channel_create(target, new_args, GRPC_CLIENT_CHANNEL, nullptr);
grpc_channel_args_destroy(new_args);
return channel;
}
} // namespace
} // namespace grpc_core
namespace {
@ -209,7 +212,7 @@ grpc_channel* grpc_secure_channel_create(grpc_channel_credentials* creds,
args, args_to_add, GPR_ARRAY_SIZE(args_to_add));
new_args = creds->update_arguments(new_args);
// Create channel.
channel = g_factory->CreateChannel(target, new_args);
channel = grpc_core::CreateChannel(target, new_args);
// Clean up.
grpc_channel_args_destroy(new_args);
}

@ -2465,6 +2465,13 @@ static void cancel_stream_cb(void* user_data, uint32_t key, void* stream) {
}
static void end_all_the_calls(grpc_chttp2_transport* t, grpc_error* error) {
intptr_t http2_error;
// If there is no explicit grpc or HTTP/2 error, set to UNAVAILABLE on server.
if (!t->is_client && !grpc_error_has_clear_grpc_status(error) &&
!grpc_error_get_int(error, GRPC_ERROR_INT_HTTP2_ERROR, &http2_error)) {
error = grpc_error_set_int(error, GRPC_ERROR_INT_GRPC_STATUS,
GRPC_STATUS_UNAVAILABLE);
}
cancel_stream_cb_args args = {error, t};
grpc_chttp2_stream_map_for_each(&t->stream_map, cancel_stream_cb, &args);
GRPC_ERROR_UNREF(error);

@ -40,9 +40,7 @@
#include <time.h>
#include <unistd.h>
// Not naming it as gettid() to avoid duplicate declarations when complied with
// GCC 9.1.
static long local_gettid(void) { return syscall(__NR_gettid); }
static long sys_gettid(void) { return syscall(__NR_gettid); }
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@ -72,7 +70,7 @@ void gpr_default_log(gpr_log_func_args* args) {
gpr_timespec now = gpr_now(GPR_CLOCK_REALTIME);
struct tm tm;
static __thread long tid = 0;
if (tid == 0) tid = local_gettid();
if (tid == 0) tid = sys_gettid();
timer = static_cast<time_t>(now.tv_sec);
final_slash = strrchr(args->file, '/');

@ -31,7 +31,7 @@
#include <string.h>
#include <time.h>
static intptr_t gettid(void) { return (intptr_t)pthread_self(); }
static intptr_t sys_gettid(void) { return (intptr_t)pthread_self(); }
void gpr_log(const char* file, int line, gpr_log_severity severity,
const char* format, ...) {
@ -86,7 +86,7 @@ void gpr_default_log(gpr_log_func_args* args) {
char* prefix;
gpr_asprintf(&prefix, "%s%s.%09d %7" PRIdPTR " %s:%d]",
gpr_log_severity_string(args->severity), time_buffer,
(int)(now.tv_nsec), gettid(), display_file, args->line);
(int)(now.tv_nsec), sys_gettid(), display_file, args->line);
fprintf(stderr, "%-70s %s\n", prefix, args->message);
gpr_free(prefix);

@ -19,6 +19,14 @@
#ifndef GRPC_CORE_LIB_GPRPP_ABSTRACT_H
#define GRPC_CORE_LIB_GPRPP_ABSTRACT_H
#if GRPC_USE_CPP_STD_LIB
#define GRPC_ABSTRACT_BASE_CLASS
#define GRPC_ABSTRACT = 0
#else
// This is needed to support abstract base classes in the c core. Since gRPC
// doesn't have a c++ runtime, it will hit a linker error on delete unless
// we define a virtual operator delete. See this blog for more info:
@ -34,4 +42,6 @@
GPR_ASSERT(false); \
}
#endif // GRPC_USE_CPP_STD_LIB
#endif /* GRPC_CORE_LIB_GPRPP_ABSTRACT_H */

@ -27,12 +27,17 @@
#include <functional>
#include <iterator>
#if GRPC_USE_CPP_STD_LIB
#include <map>
#endif
#include "src/core/lib/gpr/useful.h"
#include "src/core/lib/gprpp/memory.h"
#include "src/core/lib/gprpp/pair.h"
#include "src/core/lib/gprpp/ref_counted_ptr.h"
namespace grpc_core {
struct StringLess {
bool operator()(const char* a, const char* b) const {
return strcmp(a, b) < 0;
@ -50,6 +55,13 @@ struct RefCountedPtrLess {
}
};
#if GRPC_USE_CPP_STD_LIB
template <class Key, class T, class Compare = std::less<Key>>
using Map = std::map<Key, T, Compare>;
#else // GRPC_USE_CPP_STD_LIB
namespace testing {
class MapTest;
}
@ -537,5 +549,9 @@ int Map<Key, T, Compare>::CompareKeys(const key_type& lhs,
}
return left_comparison ? -1 : 1;
}
#endif // GRPC_USE_CPP_STD_LIB
} // namespace grpc_core
#endif /* GRPC_CORE_LIB_GPRPP_MAP_H */

@ -1077,7 +1077,7 @@ static void end_worker(grpc_pollset* pollset, grpc_pollset_worker* worker,
}
#ifndef NDEBUG
static long gettid(void) { return syscall(__NR_gettid); }
static long sys_gettid(void) { return syscall(__NR_gettid); }
#endif
/* pollset->mu lock must be held by the caller before calling this.
@ -1097,7 +1097,7 @@ static grpc_error* pollset_work(grpc_pollset* pollset,
#define WORKER_PTR (&worker)
#endif
#ifndef NDEBUG
WORKER_PTR->originator = gettid();
WORKER_PTR->originator = sys_gettid();
#endif
if (GRPC_TRACE_FLAG_ENABLED(grpc_polling_trace)) {
gpr_log(GPR_INFO,

@ -392,7 +392,7 @@ static grpc_error* tcp_server_add_port(grpc_tcp_server* s,
socket->endpoint = nullptr;
socket->listener = nullptr;
socket->connector = nullptr;
grpc_custom_socket_vtable->init(socket, family);
error = grpc_custom_socket_vtable->init(socket, family);
if (error == GRPC_ERROR_NONE) {
error = add_socket_to_server(s, socket, addr, port_index, &sp);

@ -110,11 +110,17 @@ struct grpc_channel_credentials
create_security_connector(
grpc_core::RefCountedPtr<grpc_call_credentials> call_creds,
const char* target, const grpc_channel_args* args,
grpc_channel_args** new_args) {
grpc_channel_args** new_args)
#if GRPC_USE_CPP_STD_LIB
= 0;
#else
{
// Tell clang-tidy that call_creds cannot be passed as const-ref.
call_creds.reset();
GRPC_ABSTRACT;
gpr_log(GPR_ERROR, "Function marked GRPC_ABSTRACT was not implemented");
GPR_ASSERT(false);
}
#endif
// Creates a version of the channel credentials without any attached call
// credentials. This can be used in order to open a channel to a non-trusted

@ -108,7 +108,7 @@ struct ManagedMemorySlice : public grpc_slice {
return !grpc_slice_differs_refcounted(other, *this);
}
bool Equals(const char* buf, const size_t len) const {
return data.refcounted.length == len &&
return data.refcounted.length == len && buf != nullptr &&
memcmp(buf, data.refcounted.bytes, len) == 0;
}
};

@ -414,7 +414,7 @@ int MetadataCredentialsPluginWrapper::GetMetadata(
*num_creds_md = 0;
*status = GRPC_STATUS_OK;
*error_details = nullptr;
return true;
return 1;
}
if (w->plugin_->IsBlocking()) {
// The internals of context may be destroyed if GetMetadata is cancelled.

@ -23,7 +23,7 @@ Unity and provide feedback!
How to test gRPC in a Unity project
1. Create a Unity project that targets .NET 4.x (Edit -> Project Settings -> Editor -> Scripting Runtime Version). gRPC uses APIs that are only available in .NET4.5+ so this is a requirement.
1. Create a Unity project that targets .NET 4.x Equivalent (Edit -> Project Settings -> Player -> Configuration -> Scripting Runtime Version). gRPC uses APIs that are only available in .NET4.5+ so this is a requirement.
2. Download the latest development build of `grpc_unity_package.VERSION.zip` from
[daily builds](https://packages.grpc.io/)

@ -232,6 +232,7 @@ grpc_objc_library(
],
hdrs = [
"ProtoRPC/ProtoMethod.h",
"ProtoRPC/ProtoRPC.h",
"ProtoRPC/ProtoRPCLegacy.h",
"ProtoRPC/ProtoService.h",
],

@ -18,15 +18,12 @@
#import <Foundation/Foundation.h>
@class GRPCProtoCall;
#import <GRPCClient/GRPCCallOptions.h>
#import "ProtoRPC.h"
@protocol GRXWriteable;
@class GRXWriter;
@class GRPCCallOptions;
@class GRPCProtoCall;
@class GRPCUnaryProtoCall;
@class GRPCStreamingProtoCall;
@protocol GRPCProtoResponseHandler;
@protocol GRXWriteable;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wnullability-completeness"

@ -74,7 +74,8 @@ class ServicerContext(grpc.ServicerContext):
_common.fuss_with_metadata(trailing_metadata))
def abort(self, code, details):
raise NotImplementedError()
with self._rpc._condition:
self._rpc._abort(code, details)
def abort_with_status(self, status):
raise NotImplementedError()

@ -14,6 +14,7 @@
"""Test of RPCs made using local credentials."""
import unittest
import os
from concurrent.futures import ThreadPoolExecutor
import grpc
@ -32,6 +33,8 @@ class LocalCredentialsTest(unittest.TestCase):
server.add_generic_rpc_handlers((_GenericHandler(),))
return server
@unittest.skipIf(os.name == 'nt',
'TODO(https://github.com/grpc/grpc/issues/20078)')
def test_local_tcp(self):
server_addr = 'localhost:{}'
channel_creds = grpc.local_channel_credentials(
@ -49,6 +52,8 @@ class LocalCredentialsTest(unittest.TestCase):
b'abc', wait_for_ready=True))
server.stop(None)
@unittest.skipIf(os.name == 'nt',
'Unix Domain Socket is not supported on Windows')
def test_uds(self):
server_addr = 'unix:/tmp/grpc_fullstack_test'
channel_creds = grpc.local_channel_credentials(

@ -204,7 +204,7 @@ static void test_max_age_forcibly_close(grpc_end2end_test_config config) {
/* The connection should be closed immediately after the max age grace period,
the in-progress RPC should fail. */
GPR_ASSERT(status == GRPC_STATUS_INTERNAL);
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
GPR_ASSERT(was_cancelled == 1);

@ -166,9 +166,7 @@ static void test_early_server_shutdown_finishes_inflight_calls(
grpc_server_destroy(f.server);
// new code should give INTERNAL, some older code will give UNAVAILABLE
GPR_ASSERT(status == GRPC_STATUS_INTERNAL ||
status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(status == GRPC_STATUS_UNAVAILABLE);
GPR_ASSERT(0 == grpc_slice_str_cmp(call_details.method, "/foo"));
GPR_ASSERT(was_cancelled == 1);

@ -29,6 +29,13 @@
namespace grpc_core {
namespace testing {
#if GRPC_USE_CPP_STD_LIB
TEST(MapTest, Nop) {}
#else
class Payload {
public:
Payload() : data_(-1) {}
@ -495,6 +502,8 @@ TEST_F(MapTest, CopyAssignment) {
EXPECT_EQ(test_map2.end(), test_map2.find("xxx"));
}
#endif
} // namespace testing
} // namespace grpc_core

@ -150,11 +150,6 @@ class InterceptRecvTrailingMetadataLoadBalancingPolicy
return parent_->channel_control_helper()->CreateSubchannel(args);
}
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args& args) override {
return parent_->channel_control_helper()->CreateChannel(target, args);
}
void UpdateState(grpc_connectivity_state state,
UniquePtr<SubchannelPicker> picker) override {
parent_->channel_control_helper()->UpdateState(

@ -130,8 +130,16 @@ class GenericEnd2endTest : public ::testing::Test {
cli_ctx.set_deadline(deadline);
}
// Rather than using the original kMethodName, make a short-lived
// copy to also confirm that we don't refer to this object beyond
// the initial call preparation
const grpc::string* method_name = new grpc::string(kMethodName);
std::unique_ptr<GenericClientAsyncReaderWriter> call =
generic_stub_->PrepareCall(&cli_ctx, kMethodName, &cli_cq_);
generic_stub_->PrepareCall(&cli_ctx, *method_name, &cli_cq_);
delete method_name; // Make sure that this is not needed after invocation
call->StartCall(tag(1));
client_ok(1);
std::unique_ptr<ByteBuffer> send_buffer =

@ -322,10 +322,6 @@ class FakeClientChannelFactory : public grpc_core::ClientChannelFactory {
const grpc_channel_args* args) override {
return nullptr;
}
grpc_channel* CreateChannel(const char* target,
const grpc_channel_args* args) override {
return nullptr;
}
};
static grpc_arg StringArg(const char* key, const char* value) {

@ -25,3 +25,4 @@ git clone /var/local/jenkins/grpc /var/local/git/grpc
${name}')
cd /var/local/git/grpc
bazel build --spawn_strategy=standalone --genrule_strategy=standalone :all test/... examples/...
bazel build --spawn_strategy=standalone --genrule_strategy=standalone --define=GRPC_USE_CPP_STD_LIB=1 :grpc

@ -403,13 +403,17 @@ def _create_portability_test_jobs(extra_args=[],
extra_args=extra_args,
inner_jobs=inner_jobs)
# TODO(jtattermusch): a large portion of the libuv tests is failing,
# which can end up killing the kokoro job due to gigabytes of error logs
# generated. Remove the --build_only flag
# once https://github.com/grpc/grpc/issues/17556 is fixed.
test_jobs += _generate_jobs(
languages=['c'],
configs=['dbg'],
platforms=['linux'],
iomgr_platforms=['uv'],
labels=['portability', 'corelang'],
extra_args=extra_args,
extra_args=extra_args + ['--build_only'],
inner_jobs=inner_jobs,
timeout_seconds=_CPP_RUNTESTS_TIMEOUT)

Loading…
Cancel
Save